From me+list/python at ixokai.io Thu Jul 1 00:04:28 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 30 Jun 2010 21:04:28 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2C13CC.3000309@ixokai.io> On 6/30/10 8:50 PM, Mladen Gogala wrote: >>>> x="quick brown fox jumps over a lazy dog" >>>> y=''.join(list(x).reverse()) > Traceback (most recent call last): > File "", line 1, in > TypeError >>>> > > Why is TypeError being thrown? The reason for throwing the type error is > the fact that the internal expression evaluates to None and cannot, > therefore, be joined: The "reverse" method, like "sort" and a couple others, are in-place operations. Meaning, they do not return a new list but modify the existing list. All methods that are "in-place" modifications return None to indicate this. This way you can't make a mistake and think its returning a sorted / reversed copy but it isn't. However, you can easily get what you want by using the 'reversed' function (and similarly, the 'sorted' function), a la: >>> y = ''.join(reversed(list(x))) The 'reversed' and 'sorted' functions are generators that lazilly convert an iterable as needed. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From zubin.mithra at gmail.com Thu Jul 1 00:09:52 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 1 Jul 2010 09:39:52 +0530 Subject: Composition of functions In-Reply-To: References: Message-ID: Hello, >>> y=list(x).reverse() > >>> print y > None > >>> L = ["a", "b", "c"] >>> L.reverse() >>> L ["c", "b", "a"] As you can see, L.reverse() performs the operation on itself and returns nothing. Hence, the return type None. Instead of y=''.join(list(x).reverse()) you should probably do, >>> t = list(x).reverse() >>> y = ''.join(t) Cheers! Zubin -------------- next part -------------- An HTML attachment was scrubbed... URL: From mtigges at gmail.com Thu Jul 1 00:12:12 2010 From: mtigges at gmail.com (m) Date: Wed, 30 Jun 2010 21:12:12 -0700 (PDT) Subject: Very odd output from subprocess Message-ID: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> I have this function: def GetMakeOutput(make, rules, out=None): p = subprocess.Popen('%s %s' % (make,rules), shell=True, bufsize=1024, stderr=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=False) ret = [] line = p.stdout.readline() while len(line): if line[:5] not in ['make[','make:']: if out: out.write(line) out.flush() else: ret.append(line) line = p.stdout.readline() return string.join(map(string.strip,ret),'\n') Very simple ... it cleans any line that is output from make itself. Now, I have used it for quite awhile with no problem. But, I noticed today that it wasn't doing its job on my 64 bit machine. If I add the line: for l in line: print ord(l),'\t',l after the first readline, I get the following: 27  91 [ 48 0 48 0 109 m 27  91 [ 51 3 55 7 109 m before the codes begin for the string as it appears if I just print it. So, what is this sequence? They seem like some sort of escape codes, I've never seen this before at all. Can anyone enlighten me as to what is going on? And, can I safely strip sets of 5 characters from the front as long as they start with Escape (27)? Thanks, Mark. From clp2 at rebertia.com Thu Jul 1 00:16:43 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 21:16:43 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: On Wed, Jun 30, 2010 at 9:09 PM, Zubin Mithra wrote: > Hello, > >> >>> y=list(x).reverse() >> >>> print y >> None > >>>> L = ["a", "b", "c"] >>>> L.reverse() >>>> L > ["c", "b", "a"] > > As you can see, L.reverse() performs the operation on itself and returns > nothing. Hence, the return type None. > > Instead of > > y=''.join(list(x).reverse()) > > you should probably do, > >>>> t = list(x).reverse() >>>> y = ''.join(t) Er, I don't think you thought that one entirely through (/ tried it out): chris at morpheus ~ $ python Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = "hello" >>> t = list(x).reverse() >>> print t None >>> ''.join(t) Traceback (most recent call last): File "", line 1, in TypeError Cheers, Chris -- http://blog.rebertia.com From zubin.mithra at gmail.com Thu Jul 1 00:22:27 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 1 Jul 2010 09:52:27 +0530 Subject: Composition of functions In-Reply-To: References: Message-ID: > Er, I don't think you thought that one entirely through (/ tried it out): > > My Apologies. Here is a working one. >>> x="123" >>> t = list(x) >>> t.reverse() >>> print ''.join(t) 321 But of course, the method which was suggested earlier is far more elegant. >>> print ''.join(reversed(list(x))) Cheers! Zubin -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 1 00:27:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 21:27:41 -0700 Subject: Very odd output from subprocess In-Reply-To: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Wed, Jun 30, 2010 at 9:12 PM, m wrote: > I have this function: > > > def GetMakeOutput(make, rules, out=None): > ? ?p = subprocess.Popen('%s %s' % (make,rules), > ? ? ? ? ? ? ? ? ? ? ? ? shell=True, > ? ? ? ? ? ? ? ? ? ? ? ? bufsize=1024, > ? ? ? ? ? ? ? ? ? ? ? ? stderr=subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? stdout=subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? close_fds=False) > ? ?ret = [] > ? ?line = p.stdout.readline() > ? ?while len(line): > ? ? ? ?if line[:5] not in ['make[','make:']: > ? ? ? ? ? ?if out: > ? ? ? ? ? ? ? ?out.write(line) > ? ? ? ? ? ? ? ?out.flush() > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?ret.append(line) > ? ? ? ?line = p.stdout.readline() > ? ?return string.join(map(string.strip,ret),'\n') > > Very simple ... it cleans any line that is output from make itself. > > Now, I have used it for quite awhile with no problem. ?But, I noticed > today that it wasn't doing its job on my 64 bit machine. > > If I add the line: > ? ? for l in line: print ord(l),'\t',l > after the first readline, I get the following: > > > 27 > 91 ? ? ?[ > 48 ? ? ?0 > 48 ? ? ?0 > 109 ? ? m > 27 > 91 ? ? ?[ > 51 ? ? ?3 > 55 ? ? ?7 > 109 ? ? m > > before the codes begin for the string as it appears if I just print > it. ?So, what is this sequence? ?They seem like some sort of escape > codes, I've never seen this before at all. > > Can anyone enlighten me as to what is going on? http://en.wikipedia.org/wiki/ANSI_escape_code Running make directly, rather than through the shell, might disable the use of the codes in whatever program is outputting them. It's worth a try. Cheers, Chris -- http://blog.rebertia.com From gogala.mladen at gmail.com Thu Jul 1 00:32:57 2010 From: gogala.mladen at gmail.com (Mladen Gogala) Date: Thu, 1 Jul 2010 04:32:57 +0000 (UTC) Subject: Composition of functions References: Message-ID: On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: > On 6/30/10 8:50 PM, Mladen Gogala wrote: >>>>> x="quick brown fox jumps over a lazy dog" >>>>> y=''.join(list(x).reverse()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError >>>>> >>>>> >> >> Why is TypeError being thrown? The reason for throwing the type error >> is the fact that the internal expression evaluates to None and cannot, >> therefore, be joined: > > The "reverse" method, like "sort" and a couple others, are in-place > operations. Meaning, they do not return a new list but modify the > existing list. All methods that are "in-place" modifications return None > to indicate this. This way you can't make a mistake and think its > returning a sorted / reversed copy but it isn't. Thanks. > > However, you can easily get what you want by using the 'reversed' > function (and similarly, the 'sorted' function), a la: > > >>> y = ''.join(reversed(list(x))) > > The 'reversed' and 'sorted' functions are generators that lazilly > convert an iterable as needed. Ah, that is even better. Thanks. -- http://mgogala.byethost5.com From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 00:47:51 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 04:47:51 GMT Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> Message-ID: <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> But, honestly, is there anyone here, even the most heavy users of >> print, who would seriously expect that adding parentheses to print >> calls will do more than add a tiny fraction to the amount of typing >> effort already required to use Python? I suppose in principle those >> extra three key presses (shift-9 shift-0 vs space) could be the straw >> that breaks the camel's back, but I doubt it. > > There's also Fitt's Law to consider: the space bar is big and > easily-placed and hence easy to type in the middle of a stream of other > keystrokes. None of that is true for the parens. This is true, but there's nothing unique to print about that. Personally, I think that the parentheses should be where the square brackets are, square brackets should be moved to where curly brackets are, and curly brackets moved to shift-9 and shift-0. But I don't care enough to remap my keyboard. -- Steven From ben+python at benfinney.id.au Thu Jul 1 01:02:51 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 15:02:51 +1000 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> Message-ID: <87eifniykk.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: > > > Steven D'Aprano writes: > >> I suppose in principle those extra three key presses (shift-9 > >> shift-0 vs space) could be the straw that breaks the camel's back, > >> but I doubt it. > > > > There's also Fitt's Law to consider: the space bar is big and > > easily-placed and hence easy to type in the middle of a stream of > > other keystrokes. None of that is true for the parens. > > This is true, but there's nothing unique to print about that. Non sequitur. The issue is one of the *difference* being observed (from Python 2 to Python 3): between the use of spaces versus parens for delimiting an argument sequence. Merely counting keystrokes isn't enough, in light of Fitt's Law. > Personally, I think that the parentheses should be where the square > brackets are, square brackets should be moved to where curly brackets > are, and curly brackets moved to shift-9 and shift-0. But I don't care > enough to remap my keyboard. Right. I'm much more concerned about the position of my Ctrl key, to avoid hand injury from all the key chording done as a programmer. -- \ ?Books and opinions, no matter from whom they came, if they are | `\ in opposition to human rights, are nothing but dead letters.? | _o__) ?Ernestine Rose | Ben Finney From debatem1 at gmail.com Thu Jul 1 01:16:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 1 Jul 2010 01:16:57 -0400 Subject: I strongly dislike Python 3 In-Reply-To: <87eifniykk.fsf@benfinney.id.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> Message-ID: On Thu, Jul 1, 2010 at 1:02 AM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> >> I suppose in principle those extra three key presses (shift-9 >> >> shift-0 vs space) could be the straw that breaks the camel's back, >> >> but I doubt it. >> > >> > There's also Fitt's Law to consider: the space bar is big and >> > easily-placed and hence easy to type in the middle of a stream of >> > other keystrokes. None of that is true for the parens. >> >> This is true, but there's nothing unique to print about that. > > Non sequitur. The issue is one of the *difference* being observed (from > Python 2 to Python 3): between the use of spaces versus parens for > delimiting an argument sequence. > > Merely counting keystrokes isn't enough, in light of Fitt's Law. > >> Personally, I think that the parentheses should be where the square >> brackets are, square brackets should be moved to where curly brackets >> are, and curly brackets moved to shift-9 and shift-0. But I don't care >> enough to remap my keyboard. > > Right. I'm much more concerned about the position of my Ctrl key, to > avoid hand injury from all the key chording done as a programmer. Not saying its a cure-all, but I broke my hand pretty badly a few years ago and had a lot of luck with a homemade foot switch for each of the meta keys. Was pretty fun to do (all things considered) and worked pretty well. I'm sure if you're willing to do some shopping around you could get a prefab one fairly cheaply. Geremy Condra From aahz at pythoncraft.com Thu Jul 1 01:37:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Jun 2010 22:37:09 -0700 Subject: Python dynamic attribute creation References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: In article <4c29ad38$0$26210$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Aahz a ?crit : >> In article <4c285e7c$0$17371$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> Aahz a ?crit : >>>> In article <4c2747c1$0$4545$426a74cc at news.free.fr>, >>>> Bruno Desthuilliers wrote: >>>>> >>>>> Python has no pretention at "elegance". >>>> That's not true at all. More precisely, I would agree with you if the >>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >> >> ...and this implies that Python has no focus on elegance because...? > >Nope, that was an answer about where the emphasis was in my previous >statement. I don't mean Python don't care about or is devoid of >elegance, just that it's not the primary concern - hence the "has no >pretention at" part. It may not be "the" primary concern, but elegance certainly is *a* primary concern. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From torriem at gmail.com Thu Jul 1 01:40:06 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 30 Jun 2010 23:40:06 -0600 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4C2C2A36.2030507@gmail.com> On 06/30/2010 06:36 PM, Lawrence D'Oliveiro wrote: > In message , > Michael Torrie wrote: > >> Okay, I will. Your code passes a char** when a char* is expected. > > No it doesn?t. You're right; it doesn't. Your code passes char (*)[512]. warning: passing argument 1 of ?snprintf? from incompatible pointer type /usr/include/stdio.h:385: note: expected ?char * __restrict__? but argument is of type ?char (*)[512]? > And so you misunderstand the difference between a C array and a > pointer. You make a pretty big assumption. Given "char buf[512]", buf's type is char * according to the compiler and every C textbook I know of. With a static char array, there's no need to take it's address since it *is* the address of the first element. Taking the address can lead to problems if you ever substitute a dynamically-allocated buffer for the statically-allocated one. For one-dimensional arrays at least, static arrays and pointers are interchangeable when calling snprinf. You do not agree? Anyway, this is far enough away from Python. From wuwei23 at gmail.com Thu Jul 1 01:42:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 30 Jun 2010 22:42:06 -0700 (PDT) Subject: Need instruction on how to use isinstance References: <4C28045F.6020007@syslang.net> <4C280809.1080507@ixokai.io> <4C28113D.2000603@syslang.net> <777cb6f7-41ae-42f8-ae9a-0b700555545a@e12g2000prh.googlegroups.com> <4c2bd5c9$0$22936$e4fe514c@news.xs4all.nl> Message-ID: <8ad7db9e-1043-4155-8bd6-b69bf0d5b707@a30g2000yqn.googlegroups.com> Hans Mulder wrote: > There's also: hasattr(, '__call__'). ?It works in both 2.x and 3.x. Good work, Hans. I do find that to be a more pythonic approach, personally, being more concerned with an object's ability than its abstract type. From me+list/python at ixokai.io Thu Jul 1 01:49:57 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 30 Jun 2010 22:49:57 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4C2C2C85.2060805@ixokai.io> On 6/30/10 10:37 PM, Aahz wrote: > In article<4c29ad38$0$26210$426a74cc at news.free.fr>, > Bruno Desthuilliers wrote: >> Aahz a ?crit : >>> In article<4c285e7c$0$17371$426a74cc at news.free.fr>, >>> Bruno Desthuilliers wrote: >>>> Aahz a ?crit : >>>>> In article<4c2747c1$0$4545$426a74cc at news.free.fr>, >>>>> Bruno Desthuilliers wrote: >>>>>> >>>>>> Python has no pretention at "elegance". >>>>> That's not true at all. More precisely, I would agree with you if the >>>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >>> >>> ...and this implies that Python has no focus on elegance because...? >> >> Nope, that was an answer about where the emphasis was in my previous >> statement. I don't mean Python don't care about or is devoid of >> elegance, just that it's not the primary concern - hence the "has no >> pretention at" part. > > It may not be "the" primary concern, but elegance certainly is *a* > primary concern. I concur. Its not explicitly stated, but it is the Zen 0. This is further supported by its implied presence in many of the Axioms and Truths of the Bots. "Beautiful is better then ugly"; and then the praise of the explicit, of simplicity, of readability. Elegance is a prime concern of Python, as it is the natural result of the Doctrines of Pythonicity. It may not be stated as a rule, but it a the reward that we are given for following the path of enlightenment. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ P.S. Yes, my wording is intentionally silly-religious. Not meant to be taken as anything but tongue-in-cheek. From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 01:50:35 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 05:50:35 GMT Subject: Reversing backslashed escape sequences Message-ID: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> I have a byte-string which is an escape sequence, that is, it starts with a backslash, followed by either a single character, a hex or octal escape sequence. E.g. something like one of these in Python 2.5: '\\n' '\\xFF' '\\023' If s is such a string, what is the right way to un-escape them to single character byte strings? I could decode them to unicode first, then encode to ASCII: >>> s = '\\n' >>> assert len(s) == 2 >>> s.decode('unicode-escape').encode() '\n' but this fails for non-ASCII bytes: >>> '\\xFF'.decode('unicode-escape').encode() Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128) -- Steven From ben+python at benfinney.id.au Thu Jul 1 02:08:39 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 16:08:39 +1000 Subject: Solutions for hand injury from computer use (was: I strongly dislike Python 3) References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> Message-ID: <87aaqbiviw.fsf_-_@benfinney.id.au> geremy condra writes: > > Right. I'm much more concerned about the position of my Ctrl key, to > > avoid hand injury from all the key chording done as a programmer. > > Not saying its a cure-all, but I broke my hand pretty badly a few years > ago and had a lot of luck with a homemade foot switch for each of the > meta keys. Was pretty fun to do (all things considered) and worked > pretty well. I'm sure if you're willing to do some shopping around you > could get a prefab one fairly cheaply. My current solution is: * Never use a notepad on the couch, but only ever at a properly adjusted table/desk and chair. * Remap CapsLock as an additional Ctrl key, on every computer I use (nobody has ever minded this, because they don't use that key at all :-) * Use my left hand for operating the mouse, since this brings it much closer to the home position on the keyboard, and a standard keyboard design forces the right hand to do disproportionately more work. * Use a wrist support, consisting of two plastic discs that are separated and move freely against each other, that allows my whole arm to move for moving the mouse and hence avoid bending my wrist for that operation. Quite cheap and simple, and I've thereby had no recurrence of injury for the past 3 years. -- \ ?The way to build large Python applications is to componentize | `\ and loosely-couple the hell out of everything.? ?Aahz | _o__) | Ben Finney From clp2 at rebertia.com Thu Jul 1 02:11:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 23:11:59 -0700 Subject: Reversing backslashed escape sequences In-Reply-To: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jun 30, 2010 at 10:50 PM, Steven D'Aprano wrote: > I have a byte-string which is an escape sequence, that is, it starts with > a backslash, followed by either a single character, a hex or octal escape > sequence. E.g. something like one of these in Python 2.5: > > '\\n' > '\\xFF' > '\\023' > > If s is such a string, what is the right way to un-escape them to single > character byte strings? > > I could decode them to unicode first, then encode to ASCII: > >>>> s = '\\n' >>>> assert len(s) == 2 >>>> s.decode('unicode-escape').encode() > '\n' > > but this fails for non-ASCII bytes: > >>>> '\\xFF'.decode('unicode-escape').encode() > Traceback (most recent call last): > ?File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in > position 0: ordinal not in range(128) Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) >>> '\\xFF'.decode('string_escape') '\xff' Cheers, Chris -- http://blog.rebertia.com From ryan at rfk.id.au Thu Jul 1 02:16:23 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 01 Jul 2010 16:16:23 +1000 Subject: A question about the posibility of raise-yield in Python In-Reply-To: References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <4c2b7551$0$1672$742ec2ed@news.sonic.net> Message-ID: <1277964983.1798.1.camel@rambutan> On Wed, 2010-06-30 at 16:20 -0700, rurpy at yahoo.com wrote: > On Jun 30, 10:48 am, John Nagle wrote: > > On 6/30/2010 12:13 AM, ?????? ??????????? wrote: > > > > >> A 'raise-yield' expression would break the flow of a program just like > > >> an exception, going up the call stack until it would be handled, but > > >> also like yield it would be possible to continue the flow of the > > >> program from where it was raise-yield-ed. > > > > Bad idea. Continuing after an exception is generally troublesome. > > This was discussed during the design phase of Ada, and rejected. > > Since then, it's been accepted that continuing after an exception > > is a terrible idea. The stack has already been unwound, for example. > > > > What you want, in in the situation you describe, is an optional > > callback, to be called in case of a fixable problem. Then the > > caller gets control, but without stack unwinding. I've tried my hand at implementing the "condition/handler/restart" paradigm of common lisp, which is very similar to what you describe. You might find it useful: http://pypi.python.org/pypi/withrestart/ Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details From metolone+gmane at gmail.com Thu Jul 1 02:20:17 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 30 Jun 2010 23:20:17 -0700 Subject: Reversing backslashed escape sequences References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c2c2cab$0$14136$c3e8da3 at news.astraweb.com... >I have a byte-string which is an escape sequence, that is, it starts with > a backslash, followed by either a single character, a hex or octal escape > sequence. E.g. something like one of these in Python 2.5: > > '\\n' > '\\xFF' > '\\023' > > If s is such a string, what is the right way to un-escape them to single > character byte strings? > > I could decode them to unicode first, then encode to ASCII: > >>>> s = '\\n' >>>> assert len(s) == 2 >>>> s.decode('unicode-escape').encode() > '\n' > > but this fails for non-ASCII bytes: > >>>> '\\xFF'.decode('unicode-escape').encode() > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in > position 0: ordinal not in range(128) Use 'string-escape': >>> s=['\\n','\\xff','\\023'] >>> for n in s: n.decode('string-escape') ... '\n' '\xff' '\x13' -Mark From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 02:20:20 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 06:20:20 GMT Subject: Reversing backslashed escape sequences References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: <4c2c33a4$0$14136$c3e8da3@news.astraweb.com> On Wed, 30 Jun 2010 23:11:59 -0700, Chris Rebert wrote: > Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) >>>> '\\xFF'.decode('string_escape') > '\xff' I knew unicode-escape, obviously, and then I tried just 'escape', but never thought of 'string_escape'. Thanks for the quick answer. -- Steven From grahn+nntp at snipabacken.se Thu Jul 1 02:58:38 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 1 Jul 2010 06:58:38 GMT Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Wed, 2010-06-30, Steven D'Aprano wrote: > On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: > >> On Tue, 2010-06-29, Stephen Hansen wrote: >>> On 6/29/10 5:41 AM, Roy Smith wrote: >>>> Nobody wrote: >>>> >>>>>> And what about regular expressions? >>>>> >>>>> What about them? As the saying goes: >>>>> >>>>> Some people, when confronted with a problem, think "I know, I'll >>>>> use regular expressions." Now they have two problems. >>>> >>>> That's silly. RE is a good tool. Like all good tools, it is the >>>> right tool for some jobs and the wrong tool for others. >>> >>> There's nothing silly about it. >>> >>> It is an exaggeration though: but it does represent a good thing to >>> keep in mind. >> >> Not an exaggeration: it's an absolute. It literally says that any time >> you try to solve a problem with a regex, (A) it won't solve the problem >> and (B) it will in itself become a problem. And it doesn't tell you >> why: you're supposed to accept or reject this without thinking. > > It's a *two sentence* summary, not a reasoned and nuanced essay on the > pros and cons for REs. Well, perhaps you cannot say anything useful about REs in general in two sentences, and should use either more words, or not say anything at all. The way it was used in the quoted text above is one example of what I mean. (Unless other details have been trimmed -- I can't check right now.) If he meant to say "REs aren't really a good solution for this kind of problem, even though they look tempting", then he should have said that. > Sheesh, I can just imagine you as a child, arguing with your teacher on > being told not to run with scissors -- "but teacher, there may be > circumstances where running with scissors is the right thing to do, you > are guilty of over-simplifying a complex topic into a single simplified > sound-byte, instead of providing a detailed, rich heuristic for analysing > each and every situation in full before making the decision whether or > not to run with scissors". When I was a child I expected that kind of argumentation from adults. I expect something more as an adult. /Jorgen -- // Jorgen Grahn O o . From grahn+nntp at snipabacken.se Thu Jul 1 03:09:57 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 1 Jul 2010 07:09:57 GMT Subject: [OT] Re: Why Is Escaping Data Considered So Magical? References: <4C2AC27D.1040900@gmail.com> <4C2AC54D.4010700@gmail.com> Message-ID: On Wed, 2010-06-30, Michael Torrie wrote: > On 06/30/2010 03:00 AM, Jorgen Grahn wrote: >> On Wed, 2010-06-30, Michael Torrie wrote: >>> On 06/29/2010 10:17 PM, Michael Torrie wrote: >>>> On 06/29/2010 10:05 PM, Michael Torrie wrote: >>>>> #include >>>>> >>>>> int main(int argc, char ** argv) >>>>> { >>>>> char *buf = malloc(512 * sizeof(char)); >>>>> const int a = 2, b = 3; >>>>> snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); >>>> ^^^^^^^^^^ >>>> Make that 512*sizeof(buf) >>> >>> Sigh. Try again. How about "512 * sizeof(char)" ? Still doesn't make >>> a different. The code still crashes because the &buf is incorrect. >> >> I haven't tried to understand the rest ... but never write >> 'sizeof(char)' unless you might change the type later. 'sizeof(char)' >> is by definition 1 -- even on odd-ball architectures where a char is >> e.g. 16 bits. > > You're right. I normally don't use sizeof(char). This is obviously a > contrived example; I just wanted to make the example such that there's > no way the original poster could argue that the crash is caused by > something other than &buf. > > Then again, it's always a bad idea in C to make assumptions about > anything. There are some things you cannot assume, others which few fellow programmers can care to memorize, and others which you often can get away with (like assuming an int is more than 16 bits, when your code is tied to a modern Unix anyway). But sizeof(char) is always 1. > If you're on Windows and want to use the unicode versions of > everything, you'd need to do sizeof(). So using it here would remind > you that when you move to the 16-bit Microsoft unicode versions of > snprintf need to change the sizeof(char) lines as well to sizeof(wchar_t). Yes -- see "unless you might change the type later" above. /Jorgen -- // Jorgen Grahn O o . From animator333 at gmail.com Thu Jul 1 03:16:17 2010 From: animator333 at gmail.com (King) Date: Thu, 1 Jul 2010 00:16:17 -0700 (PDT) Subject: executable builder Message-ID: <26288884-27b8-4f48-8ee6-af4be4364f6e@d16g2000yqb.googlegroups.com> Hi, I am trying to build python a cross platform python executable builder to deploy python app. I tried various tools such as py2exe, pyinstaller, cx_freeze but some how they are not upto the mark except py2exe. Unfortunately py2exe is working only on windows based systems. The task is divide into 3 steps: 1. Collect all the modules(.pyo, .pyd, .dll, etc) required for your project. 2. set up temporary environment for python 3. run main.py using :python.exe main.py Initially I won't be creating an executable using main.py. I would be using shell scripting to execute the main.py. Q1. Which is most efficient way to fine all the modules required by your "main.py". Q2. For example, I have copied all the modules in "d:\project\lib\*.*" python.exe, python.dll, ms*.dll, main.py are copied to "d: \project". Before executing "python.exe main.py", I have to set up an environment var and point it to "d:\project\lib", so that python.exe can find the path for searching/loading modules. How do I do that? Q3. How do you convert your "main.py" into an executable? Prashant From me+list/python at ixokai.io Thu Jul 1 03:19:09 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 00:19:09 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2C416D.4010507@ixokai.io> On 6/30/10 11:58 PM, Jorgen Grahn wrote: > On Wed, 2010-06-30, Steven D'Aprano wrote: >> On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: >>> On Tue, 2010-06-29, Stephen Hansen wrote: >>>> >>>> There's nothing silly about it. >>>> >>>> It is an exaggeration though: but it does represent a good thing to >>>> keep in mind. >>> >>> Not an exaggeration: it's an absolute. It literally says that any time >>> you try to solve a problem with a regex, (A) it won't solve the problem >>> and (B) it will in itself become a problem. And it doesn't tell you >>> why: you're supposed to accept or reject this without thinking. >> >> It's a *two sentence* summary, not a reasoned and nuanced essay on the >> pros and cons for REs. > > Well, perhaps you cannot say anything useful about REs in general in > two sentences, and should use either more words, or not say anything > at all. > > The way it was used in the quoted text above is one example of what I > mean. (Unless other details have been trimmed -- I can't check right > now.) If he meant to say "REs aren't really a good solution for this > kind of problem, even though they look tempting", then he should have > said that. The way it is used above (Even with more stripping) is exactly where it is legitimate. Regular expressions are a powerful tool. The use of a powerful tool when a simple tool is available that achieves the same end is inappropriate, because power *always* has a cost. The entire point of the quote is that when you look at a problem, you should *begin* from the position that a complex, powerful tool is not what you need to solve it. You should always begin from a position that a simple tool will suffice to do what you need. The quote does not deny the power of regular expressions; it challenges widely held assumption and belief that comes from *somewhere* that they are the best way to approach any problem that is text related. Does it come off as negative towards regular expressions? Certainly. But not because of any fault of re's on their own, but because there is this widespread perception that they are the swiss army knife that can solve any problem by just flicking out the right little blade. Its about redefining perception. Regular expressions are not the go-to solution for anything to do with text. Regular expressions are the tool you reach for when nothing else will work. Its not your first step; its your last (or, at least, one that happens way later then most people come around expecting it to be). -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From nobody at nowhere.com Thu Jul 1 03:24:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 01 Jul 2010 08:24:06 +0100 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: > Given "char buf[512]", buf's type is char * according to the compiler > and every C textbook I know of. No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you use "buf" as an rvalue (rather than an lvalue), it will be implicitly converted to char*. If you take its address, you'll get a "pointer to array of 512 chars", i.e. a pointer to the array rather than to the first element. Converting this to a char* will yield a pointer to the first element. If buf was declared "char *buf", then taking its address will yield a char**, and converting this to a char* will produce a pointer to the first byte of the pointer, which is unlikely to be useful. From nobody at nowhere.com Thu Jul 1 03:42:03 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 01 Jul 2010 08:42:03 +0100 Subject: Very odd output from subprocess References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > If I add the line: > for l in line: print ord(l),'\t',l > after the first readline, I get the following: > > > 27  > 91 [ > 48 0 > 48 0 > 109 m > 27  > 91 [ > 51 3 > 55 7 > 109 m > > before the codes begin for the string as it appears if I just print > it. So, what is this sequence? They seem like some sort of escape > codes, I've never seen this before at all. [00m is the ANSI code to reset attributes to their default state. [37m is the ANSI code to set the foreground color to white. > Can anyone enlighten me as to what is going on? > > And, can I safely strip sets of 5 characters from the front as long as > they start with Escape (27)? No, escape sequences can be of arbitrary length. The first thing to try is: del os.environ['TERM'] Any correctly-written program uses the value of the TERM environment variable to select escape codes which are appropriate for the terminal being used. Unfortunately, there are many incorrectly written programs which assume that all terminals support certain escape sequences. The fact that the program is using escape sequences even when stdout/stderr isn't a tty indicates that it isn't correctly written, so it far from certain that clearing TERM will work. From tjreedy at udel.edu Thu Jul 1 03:45:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 03:45:51 -0400 Subject: Composition of functions In-Reply-To: References: Message-ID: On 7/1/2010 12:32 AM, Mladen Gogala wrote: > On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: >> However, you can easily get what you want by using the 'reversed' >> function (and similarly, the 'sorted' function), a la: >> >> >>> y = ''.join(reversed(list(x))) >> >> The 'reversed' and 'sorted' functions are generators that lazilly >> convert an iterable as needed. > > Ah, that is even better. Thanks. It is better if you do not mind making an unnecessary copy. If the list had 10 million elements, you might prefer your original. And by the way, sequential statements are a form of composition, even if strict functionalists do not like to see it that way. -- Terry Jan Reedy From lucaberto at libero.it Thu Jul 1 03:50:22 2010 From: lucaberto at libero.it (luca72) Date: Thu, 1 Jul 2010 00:50:22 -0700 (PDT) Subject: stupid question about html page Message-ID: hello with webbrowser i open the html or php etc page, how i can save the opened page with python? Thanks Luca From mithrandiragainwiki at mailinator.com Thu Jul 1 03:51:08 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 07:51:08 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> Message-ID: "D'Arcy J.M. Cain" wrote in news:mailman.46.1277931314.1673.python-list at python.org: > On Wed, 30 Jun 2010 13:10:43 -0700 (PDT) > garryTX wrote: >> On Jun 29, 5:31?pm, nanothermite911fbibustards > [...] >> you ignorant mf. stfu. > > You shouldn't be calling people ignorant for what they post if you are > just going to repost every word again. Everything that applies to him > applies to you. > > I have had it with GG. For the last few months I have been filtering > all mail from gmail.com that comes through the news gateway into a > separate folder to see where the spam and abuse comes from. Over that > time about 99% of all the useless crap has been caught in that filter. > It's unfortunate that there are some decent posts as well but I have > finally decided that the peace and quiet is worth more than the odd > missed gem. So, if you are accessing this list through GG and wonder > why I seem to be ignoring your brilliant arguments, this is why. > > If anyone is interested in the procmail recipe I will be using, here > it is in all it's glory. > >:0: Hir > * ^List-Id:.*python-list.python.org > * ^From:.*@gmail.com > * ^Newsgroups: > /dev/null > > Cheers. > I only use Google Groups for quick searchs in Usenet archives, but even then I still have to manually filter out all the spam. (Heck, I don't even have a "G-Account." I use news.ett.com.ua as my server and X-News as my reader.) I know spam has almost always been on Usenet, but it really picked up when G-Groups opened up. I really wish that Google would do something about it, but hey! It's not like anyone's interested in Usenet, right? Anyway, I'm glad I'm not the only "pissed customer" out there. And thanks for the code! :) (If you're as paranoid as I am about security and Google, try GoogleSharing for Firefox.) Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From me+list/python at ixokai.io Thu Jul 1 03:54:40 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 00:54:40 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2C49C0.5020900@ixokai.io> On 7/1/10 12:45 AM, Terry Reedy wrote: > On 7/1/2010 12:32 AM, Mladen Gogala wrote: >> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: > >>> However, you can easily get what you want by using the 'reversed' >>> function (and similarly, the 'sorted' function), a la: >>> >>> >>> y = ''.join(reversed(list(x))) >>> >>> The 'reversed' and 'sorted' functions are generators that lazilly >>> convert an iterable as needed. >> >> Ah, that is even better. Thanks. > > It is better if you do not mind making an unnecessary copy. If the list > had 10 million elements, you might prefer your original. The original that did not work? :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From no.email at nospam.invalid Thu Jul 1 04:07:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 01 Jul 2010 01:07:06 -0700 Subject: Composition of functions References: Message-ID: <7xy6dvbp79.fsf@ruckus.brouhaha.com> Terry Reedy writes: > sequential statements are a form of composition, even if > strict functionalists do not like to see it that way. They actually do like to see it that way: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html From mithrandiragainwiki at mailinator.com Thu Jul 1 04:16:05 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 08:16:05 +0000 (UTC) Subject: stupid question about html page References: Message-ID: luca72 wrote in news:abfb7720-6132-4b7b-8084- 5c1a481647e8 at y11g2000yqm.googlegroups.com: > hello > with webbrowser i open the html or php etc page, how i can save the > opened page with python? > > Thanks > > Luca Not sure of a way to capture info from a browser (like Firefox.) I know though that you can save the source of an page with: import urllib urllib.urlretrieve("http://www.example.com/", "Fun.html") You still need a web browser to read it formatted. (If you are on a web page in Firefox, and want to save it, click File>Save Page As...) If you want to save a picture from the Net see: http://www.daniweb.com/code/snippet216796.html Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From lucaberto at libero.it Thu Jul 1 04:31:48 2010 From: lucaberto at libero.it (luca72) Date: Thu, 1 Jul 2010 01:31:48 -0700 (PDT) Subject: stupid question about html page References: Message-ID: <62de7bae-d219-470b-b165-0142d741c1e8@w12g2000yqj.googlegroups.com> On 1 Lug, 10:16, Mithrandir wrote: > luca72 wrote in news:abfb7720-6132-4b7b-8084- > 5c1a48164... at y11g2000yqm.googlegroups.com: > > > hello > > with webbrowser i open the html or php etc page, how i can save the > > opened page with python? > > > Thanks > > > Luca > > Not sure of a way to capture info from a browser (like Firefox.) I know > though that you can save the source of an page with: > > import urllib > urllib.urlretrieve("http://www.example.com/", "Fun.html") > > You still need a web browser to read it formatted. (If you are on a web > page in Firefox, and want to save it, click File>Save Page As...) > > If you want to save a picture from the Net see: > > http://www.daniweb.com/code/snippet216796.html > > Good luck! > > -- > People should read more.https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain > "All that is gold does not glitter, > not all those who wander are lost; > the old that is strong does not wither, > deep roots are not reached by the frost. > From the ashes a fire shall be woken, > a light from the shadows shall spring; > renenwed shall be blade that was broken, > the crownless again shall be king." Thanks for your reply, the problem is that i don't want to save it with file-> save. there is any way to save the page by script. please note that when i save the page with firefox, it save the html page and also make a folder with the script used in the page, how i can make it also with python script? Thanks Luca From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:12:32 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:12:32 -0700 (PDT) Subject: Extract doc strings Message-ID: Hi all, when I have a PyCodeObject, is there any way to extract a doc string from the code? For instance the following script <---script----> """ Hello World! """ def main(): pass main() I would like to get "Hello World!". Any chance? Thanks in advance!! Bye, moerchendiser2k3 From ben+python at benfinney.id.au Thu Jul 1 05:27:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 19:27:20 +1000 Subject: Extract doc strings References: Message-ID: <871vbnimbr.fsf@benfinney.id.au> moerchendiser2k3 writes: > when I have a PyCodeObject, is there any way to extract a doc string > from the code? I'm not very familiar with using the C interface for Python, but does it help to know that a docstring for an object is available at that object's ?__doc__? attribute? -- \ ?Time is the great legalizer, even in the field of morals.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:31:48 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:31:48 -0700 (PDT) Subject: Extract doc strings References: <871vbnimbr.fsf@benfinney.id.au> Message-ID: Hi ben, thanks for your answer. Sure, __doc__ is the access point to the docstring, but in this case, I just get the docstring of the code object. So an explanation what a code object, but I need the docstring of real docstring of the script. bye, moerchendiser From jeanmichel at sequans.com Thu Jul 1 05:35:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 11:35:50 +0200 Subject: Extract doc strings In-Reply-To: References: Message-ID: <4C2C6176.6020407@sequans.com> moerchendiser2k3 wrote: > Hi all, > > when I have a PyCodeObject, is there any way to extract a doc string > from the code? > For instance the following script > > <---script----> > """ > Hello World! > """ > def main(): > pass > main() > > > I would like to get "Hello World!". Any chance? Thanks in advance!! > > Bye, moerchendiser2k3 > Hello, """Hello world!!""" import sys def main(): print sys.modules[__name__].__doc__ main() JM From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:52:58 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:52:58 -0700 (PDT) Subject: tp_richcompare vs tp_compare Message-ID: Hi all, just another question. Can anyone explain me whats the real difference between tp_richcompare and tp_compare? I read some stuff, but sometimes I believe the author doesnt know either whats the real difference or they forget it to explain. The Function definition looks very similiar, except the one accepts POD types as return value, the other wants the same for PyObjects. Do I need to implement both? Looks very redundant, isnt it? Or is it just an extension and tp_richcompare is the better choice here? Can anyone please make the light on here? :) Really thanks in advance for your help!! Bye, moerchendiser2k3 From thomas at jollans.com Thu Jul 1 05:55:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 11:55:05 +0200 Subject: Extract doc strings In-Reply-To: References: Message-ID: <4C2C65F9.8030203@jollans.com> On 07/01/2010 11:12 AM, moerchendiser2k3 wrote: > Hi all, > > when I have a PyCodeObject, is there any way to extract a doc string > from the code? > For instance the following script Code objects don't have doc strings, as such. However, for functions at least (this may or may not be true for code originating elsewhere), it appears that the code's first constant is always the docstring, even if it's None: >>> def f(a=()): ... """doc string""" ... return 1,2,3,a ... >>> def g(a=[], b=0): ... return False ... >>> f.__code__.co_consts ('doc string', 1, 2, 3) >>> g.__code__.co_consts (None, False) >>> Why else would g.__code__.co_consts[0] be None if that wasn't a docstring-specific special place. I don't know how you're creating your codeobject, and I don't know if this holds for your case. -- Thomas > > <---script----> > """ > Hello World! > """ > def main(): > pass > main() > This looks like something that should usually be accessed as a module, and in that case, it's trivial, as others have pointed out. From ben+python at benfinney.id.au Thu Jul 1 06:02:59 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 20:02:59 +1000 Subject: Extract doc strings References: <871vbnimbr.fsf@benfinney.id.au> Message-ID: <87wrtfh63w.fsf@benfinney.id.au> moerchendiser2k3 writes: > thanks for your answer. Sure, __doc__ is the access point to the > docstring, but in this case, I just get the docstring of the code > object. So an explanation what a code object, but I need the docstring > of real docstring of the script. I'm probably not understanding what you're asking, then. If you get the docstring of the code object, that seems to be what you asked for, no? The docstring ?of the script? might be the docstring of the module. If that's what you want, you can get the module, then access that module's ?__doc__? attribute. If you don't know how to get the module, then it seems you have a new question to ask: how to get from (whatever it is you currently have) to the module. But, not really knowing what it is you're starting with, I can't say better than that. -- \ ?I took it easy today. I just pretty much layed around in my | `\ underwear all day. ? Got kicked out of quite a few places, | _o__) though.? ?Bug-Eyed Earl, _Red Meat_ | Ben Finney From jeanmichel at sequans.com Thu Jul 1 06:03:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 12:03:24 +0200 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: <4C2C416D.4010507@ixokai.io> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> Message-ID: <4C2C67EC.5070905@sequans.com> Stephen Hansen wrote: > On 6/30/10 11:58 PM, Jorgen Grahn wrote: >> On Wed, 2010-06-30, Steven D'Aprano wrote: >>> On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: >>>> On Tue, 2010-06-29, Stephen Hansen wrote: >>>>> >>>>> There's nothing silly about it. >>>>> >>>>> It is an exaggeration though: but it does represent a good thing to >>>>> keep in mind. >>>> >>>> Not an exaggeration: it's an absolute. It literally says that any time >>>> you try to solve a problem with a regex, (A) it won't solve the >>>> problem >>>> and (B) it will in itself become a problem. And it doesn't tell you >>>> why: you're supposed to accept or reject this without thinking. >>> >>> It's a *two sentence* summary, not a reasoned and nuanced essay on the >>> pros and cons for REs. >> >> Well, perhaps you cannot say anything useful about REs in general in >> two sentences, and should use either more words, or not say anything >> at all. >> >> The way it was used in the quoted text above is one example of what I >> mean. (Unless other details have been trimmed -- I can't check right >> now.) If he meant to say "REs aren't really a good solution for this >> kind of problem, even though they look tempting", then he should have >> said that. > > The way it is used above (Even with more stripping) is exactly where > it is legitimate. > > Regular expressions are a powerful tool. > > The use of a powerful tool when a simple tool is available that > achieves the same end is inappropriate, because power *always* has a > cost. > > The entire point of the quote is that when you look at a problem, you > should *begin* from the position that a complex, powerful tool is not > what you need to solve it. > > You should always begin from a position that a simple tool will > suffice to do what you need. > > The quote does not deny the power of regular expressions; it > challenges widely held assumption and belief that comes from > *somewhere* that they are the best way to approach any problem that is > text related. > > Does it come off as negative towards regular expressions? Certainly. > But not because of any fault of re's on their own, but because there > is this widespread perception that they are the swiss army knife that > can solve any problem by just flicking out the right little blade. > > Its about redefining perception. > > Regular expressions are not the go-to solution for anything to do with > text. Regular expressions are the tool you reach for when nothing else > will work. > > Its not your first step; its your last (or, at least, one that happens > way later then most people come around expecting it to be). > Guys, this dogmatic discussion already took place in this list. Why start again ? Re is part of the python standard library, for some purpose I guess. JM From egbertum at xs4all.nl Thu Jul 1 06:56:01 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 12:56:01 +0200 Subject: List-type attributes and name strings Message-ID: <20100701105601.GA6186@xs4all.nl> Normally you use setattr() if the name of the attribute is in a namestring: >>>> setattr(self, namestring, value) But my attributes are lists or dictionaries, and I don't seem to be able to use setattr anymore. Now I use for a list something like: >>> self.__dict__[namestring].append(value) and for a dictionary: >>> self.__dict__[namestring][keystring]=value But I have the impression that I am cheating, because users should not operate on __dict__ directly. Is that true ? And are there better solutions ? egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From alien8752 at gmail.com Thu Jul 1 07:01:00 2010 From: alien8752 at gmail.com (nuny@bid.nes) Date: Thu, 1 Jul 2010 04:01:00 -0700 (PDT) Subject: CONTROLLED DEMOLITION INC explosive-charge placement technician Tom Sullivan 911 TESTIMONIAL Video References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: On Jun 29, 9:31?am, nanothermite911fbibustards wrote: > On Jun 29, 5:24?am, "n... at bid.nes" wrote: > > > > > On Jun 26, 12:16?pm, nanothermite911fbibustards > > > wrote: > > > ? Let's talk about thermite. > > > ? Do you know anything about thermite? It's a powdered mixture of a > > metal oxide and another pure metal that, when raised to a specific > > minimum temperature, allows the metal to "steal" the oxygen from the > > metal oxide, evolving heat. Example, iron oxide loses its oxygen to > > aluminum, yielding aluminum oxide and metallic iron, plus heat. > > > ? Do you know what temperature it must be brought to in order to > > ignite it? > > > ? How do you propose the alleged "nanothermite" supposedly spread > > around the towers was raised to that temperature *simultaneously*? > > > ? Do you know what amount of heat (not temperature) a given mass of > > thermite can produce? > > > ? What amount of heat could the particles of your alleged > > "nanothermite" produce? Remember, each particle burns only as long as > > the oxide component can provide oxygen to the pure metal component of > > the thermite. > > > ? Mark L. Fergerson > > Spoook, Yeah, right, anyone who dares question you must work for the CIA. > All your QUESTIONS are answered in the papers by 911 truth > videos, by Dr Steven Jones and his VIDEOS !!! I didn't ask them what they think happened, I asked *you* what *you* know about thermite. Do *you* know anything about it, or do you simply believe what people claim on websites? > Go to st911.org and start looking !!! No. I'm not interested in wasting my time on predictable rants. > Go to 911blogger.com and start reading !!! No. I'm not interested in wasting my time on predictable rants. > Go to youtube and google for 911truth. No. I'm not interested in wasting my time on predictable rants. > They had military type wireless coordinated cutter charges that they > accessed from under the elevator shafts. One or all of CIA , MOSSAD , > Blackwater , Kroll etc may have been involved. Those are assertions without evidence, and are beside the point. "Cutter charges" have exactly nothing to do with thermite. > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? No. That's why we know about it. Let me guess, 9-11 was the jyeeews, right? What was that about racism again? Mark L. Fergerson From clp2 at rebertia.com Thu Jul 1 07:02:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 04:02:49 -0700 Subject: List-type attributes and name strings In-Reply-To: <20100701105601.GA6186@xs4all.nl> References: <20100701105601.GA6186@xs4all.nl> Message-ID: On Thu, Jul 1, 2010 at 3:56 AM, egbert wrote: > Normally you use setattr() if the name of the attribute is in a > namestring: >>>>> setattr(self, namestring, value) > But my attributes are lists or dictionaries, and I don't seem to be > able to use setattr anymore. Because you're not setting an attribute anymore, you're mutating an existing dict/list object (that just so happens to be the attribute of another object). > Now I use for a list something like: >>>> self.__dict__[namestring].append(value) getattr(self, namestring).append(value) > and for a dictionary: >>>> self.__dict__[namestring][keystring]=value getattr(self, namestring)[keystring] = value > But I have the impression that I am cheating, because users should not > operate on __dict__ directly. > Is that true ? And are there better solutions ? Yes and yes. See above. When dealing with nested stuff (e.g x.y[z]), switch to getattr() as demonstrated above. Cheers, Chris -- http://blog.rebertia.com From lie.1296 at gmail.com Thu Jul 1 07:20:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 01 Jul 2010 21:20:13 +1000 Subject: List-type attributes and name strings In-Reply-To: References: Message-ID: <4c2c79ee@dnews.tpgi.com.au> On 07/01/10 20:56, egbert wrote: >>>> self.__dict__[namestring][keystring]=value try this: getattr(self, namestring)[keystring] = value From jeanmichel at sequans.com Thu Jul 1 07:21:08 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 13:21:08 +0200 Subject: optphart (alpha2) In-Reply-To: <4C2A016F.8070509@ixokai.io> References: <4C2A016F.8070509@ixokai.io> Message-ID: <4C2C7A24.50507@sequans.com> Stephen Hansen wrote: > On 6/28/10 11:50 PM, rantingrick wrote: >>> You just don't get the point, do you? >> >> And just what *point* an i supposed to be "getting" Stephen? That you >> don't like my contribution? If thats your point then i very much "get" >> it. > > This garbage: > > "optphart is the nemisis of the asinine interfaces and bulky libraries > you may be accustomed to in the stdlib. All of which clog your scripts > with wasted lines and your memory with complex interfaces far worse > than any colon clogging putrifaction of junk food can hold a candle > to. Do yourself a favor and give your scripts an enema by harnessing > the simplistic elegance of the "optphart" module instead!" > > It doesn't advocate your solution; it doesn't describe the benefits of > using it; it doesn't provide a reasonable or technical basis by which > it is in some way superior to others. > > It just hand waves other solutions (which exist and are more fully > featured for *very* good reasons-- but you don't bother addressing why > less is more here, you basically just declare it all shit) all the > while being simply insulting to the authors and users of those solutions. > Come on guys :) relax. "elegance of the optphart module", can't you see it's nothing else but a joke ;) JM From egbertum at xs4all.nl Thu Jul 1 07:32:37 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 13:32:37 +0200 Subject: List-type attributes and name strings In-Reply-To: References: <20100701105601.GA6186@xs4all.nl> Message-ID: <20100701113237.GA7273@xs4all.nl> On Thu, Jul 01, 2010 at 04:02:49AM -0700, Chris Rebert wrote: > switch to getattr() as demonstrated above. > Thanks for opening my eyes, Chris. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:07:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:07:27 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: <4c2c8499$0$20848$426a74cc@news.free.fr> D'Arcy J.M. Cain a ?crit : > On Wed, 30 Jun 2010 14:06:05 -0700 > Stephen Hansen wrote: >> Gmail and Google Groups are not one and the same. There's a number of >> people who subscribe to the list directly, use Gmail, and don't go >> anywhere near Google Groups. > > I know that. My filter doesn't catch them. > >>> If anyone is interested in the procmail recipe I will be using, here it >>> is in all it's glory. >>> >>> :0: Hir >>> * ^List-Id:.*python-list.python.org >>> * ^From:.*@gmail.com >>> * ^Newsgroups: >>> /dev/null > > As you can see, to be caught in the filter you need to have a gmail > address and be sending through the news gateway. which doesn't mean they use Google groups... > People sending from > gmail.com directly to the mailing list don't get picked up. I'm pretty > sure that that defines everyone using Google Groups only. And AFAICT you're wrong. I read and post to c.l.py using my newsreader (so NOT going thru GG), and my personal address is @gmail.com. From roy at panix.com Thu Jul 1 08:11:03 2010 From: roy at panix.com (Roy Smith) Date: Thu, 01 Jul 2010 08:11:03 -0400 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: Stephen Hansen wrote: > The quote does not deny the power of regular expressions; it challenges > widely held assumption and belief that comes from *somewhere* that they > are the best way to approach any problem that is text related. Well, that assumption comes from historical unix usage where traditional tools like awk, sed, ed, and grep, made heavy use of regex, and therefore people learned to become proficient at them and use them all the time. Somewhat later, the next generation of tools such as vi and perl continued that tradition. Given the tools that were available at the time, regex was indeed likely to be the best tool available for most text-related problems. Keep in mind that in the early days, people were working on hard-copy terminals [[http://en.wikipedia.org/wiki/ASR-33]] so economy of expression was a significant selling point for regexes. Not trying to further this somewhat silly debate, just adding a bit of historical viewpoint to answer the implicit question you ask as to where the assumption came from. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 1 08:16:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 12:16:49 GMT Subject: Extract doc strings References: Message-ID: <4c2c8731$0$28647$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 11:55:05 +0200, Thomas Jollans wrote: > On 07/01/2010 11:12 AM, moerchendiser2k3 wrote: >> Hi all, >> >> when I have a PyCodeObject, is there any way to extract a doc string >> from the code? >> For instance the following script > > Code objects don't have doc strings, as such. However, for functions at > least (this may or may not be true for code originating elsewhere), it > appears that the code's first constant is always the docstring, even if > it's None: Nope, you're misinterpreting what you're seeing. Here's a counter-example from Python 3.1: >>> def f(): ... 999 ... return 42 ... >>> f.__code__.co_consts (None, 42) The docstring is None, unless the function definition is immediately followed by a string literal, in which case the string literal is taken as the docstring. Any other object is removed by the keyhole optimizer: >>> import dis >>> dis.dis(f) 3 0 LOAD_CONST 1 (42) 3 RETURN_VALUE In older versions of Python, the keyhole optimizer was less clever. Here's an example from 2.4: >>> def f(): ... 999 ... return 42 ... >>> f.func_code.co_consts (None, 999, 42) >>> import dis >>> dis.dis(f) 2 0 LOAD_CONST 1 (999) 3 POP_TOP 3 4 LOAD_CONST 2 (42) 7 RETURN_VALUE Aside: Python's keyhole optimizer has removed unreachable string constants (other than doc strings) at least since Python 1.5. But doing the same to other object types had to wait until Python 2.5. -- Steven From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:28:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:28:37 +0200 Subject: List-type attributes and name strings In-Reply-To: References: Message-ID: <4c2c898e$0$20698$426a34cc@news.free.fr> egbert a ?crit : > Normally you use setattr() if the name of the attribute is in a > namestring: >>>>> setattr(self, namestring, value) > But my attributes are lists or dictionaries, and I don't seem to be > able to use setattr anymore. Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def __init__(self): ... self.attr1 = {} ... self.attr2 = [] ... >>> attr1 = dict((x, x) for x in 'abc') >>> attr2 = range(5) >>> f = Foo() >>> setattr(f, "attr1", attr1) >>> setattr(f, "attr2", attr2) >>> f.attr1 {'a': 'a', 'c': 'c', 'b': 'b'} >>> f.attr2 [0, 1, 2, 3, 4] >>> Either I failed to understand you or you overlooked some other problem in you code and jumped to the wrong conclusions. > Now I use for a list something like: >>>> self.__dict__[namestring].append(value) > and for a dictionary: >>>> self.__dict__[namestring][keystring]=value Duh. You're confusing *setting* an attribute and *getting it then mutating it*. Can you get the difference between: >>> f.attr2.append(42) and >>> f.attr2 = [7, 87, 98] ? If you don't, then you're in for serious trouble :-/ > But I have the impression that I am cheating, because users should not > operate on __dict__ directly. Client code shouldn't mess with implementation attribute, for sure. This bypasses all the lookup rules, and can break computed attributes (ie properties or other custom descriptors). At least use getattr() and then appropriate call or operator, ie: >>> getattr(f, "attr1")["w"] = "w" >>> getattr(f, "attr2").append(42) FWIW, it's usually better to hide the mere fact that f.attr1 is a list and f.attr2 a dict. Here a "clean" solution would be to make attr1 and attr2 implementation attributes and provide an API over it, but it might be overkill. HTH From wolfram.hinderer at googlemail.com Thu Jul 1 08:29:51 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Thu, 1 Jul 2010 05:29:51 -0700 (PDT) Subject: Composition of functions References: Message-ID: On 1 Jul., 06:04, Stephen Hansen wrote: > The 'reversed' and 'sorted' functions are generators that lazilly > convert an iterable as needed. 'sorted' returns a new list (and is not lazy). From darcy at druid.net Thu Jul 1 08:34:26 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 1 Jul 2010 08:34:26 -0400 Subject: Ignorance and Google Groups (again) In-Reply-To: <4c2c8499$0$20848$426a74cc@news.free.fr> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <4c2c8499$0$20848$426a74cc@news.free.fr> Message-ID: <20100701083426.3731564a.darcy@druid.net> On Thu, 01 Jul 2010 14:07:27 +0200 Bruno Desthuilliers wrote: > And AFAICT you're wrong. I read and post to c.l.py using my newsreader > (so NOT going thru GG), and my personal address is @gmail.com. But... > From: Bruno Desthuilliers -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:41:48 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:41:48 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4c2c8ca6$0$5338$426a74cc@news.free.fr> Stephen Hansen a ?crit : > On 6/30/10 10:37 PM, Aahz wrote: >> In article<4c29ad38$0$26210$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> Aahz a ?crit : >>>> In article<4c285e7c$0$17371$426a74cc at news.free.fr>, >>>> Bruno Desthuilliers wrote: >>>>> Aahz a ?crit : >>>>>> In article<4c2747c1$0$4545$426a74cc at news.free.fr>, >>>>>> Bruno Desthuilliers wrote: >>>>>>> >>>>>>> Python has no pretention at "elegance". >>>>>> That's not true at all. More precisely, I would agree with you if >>>>>> the >>>>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>>>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >>>> >>>> ...and this implies that Python has no focus on elegance because...? >>> >>> Nope, that was an answer about where the emphasis was in my previous >>> statement. I don't mean Python don't care about or is devoid of >>> elegance, just that it's not the primary concern - hence the "has no >>> pretention at" part. >> >> It may not be "the" primary concern, but elegance certainly is *a* >> primary concern. > > I concur. > > Its not explicitly stated, but it is the Zen 0. This is further > supported by its implied presence in many of the Axioms and Truths of > the Bots. > > "Beautiful is better then ugly"; and then the praise of the explicit, of > simplicity, of readability. > > Elegance is a prime concern of Python, as it is the natural result of > the Doctrines of Pythonicity. It may not be stated as a rule, but it a > the reward that we are given for following the path of enlightenment. > "Elegance" (just like "beauty") is in the eyes of the beholder. Explicitness, simplicity and readability are indeed primary concerns in Python's design, but "elegance" is not. Now you'll of course find Python mostly elegant *if* you value expliciteness, simplicity and readability, but that's only because your definition of "elegant" happens to match Guido's. But please gentlemen, let's not fight on this. This no religion, there's no dogma here, and no heretic to burn. From drygalski at googlemail.com Thu Jul 1 08:55:03 2010 From: drygalski at googlemail.com (drygal) Date: Thu, 1 Jul 2010 05:55:03 -0700 (PDT) Subject: stupid question about html page References: <62de7bae-d219-470b-b165-0142d741c1e8@w12g2000yqj.googlegroups.com> Message-ID: <6138f256-8d8f-48a8-8f19-e64bd9cb3711@z10g2000yqb.googlegroups.com> On 1 July, 09:31, luca72 wrote: > On 1 Lug, 10:16, Mithrandir > wrote: > > > > > > > luca72 wrote in news:abfb7720-6132-4b7b-8084- > > 5c1a48164... at y11g2000yqm.googlegroups.com: > > > > hello > > > with webbrowser i open the html or php etc page, how i can save the > > > opened page with python? > > > > Thanks > > > > Luca > > > Not sure of a way to capture info from a browser (like Firefox.) I know > > though that you can save the source of an page with: > > > import urllib > > urllib.urlretrieve("http://www.example.com/", "Fun.html") > > > You still need a web browser to read it formatted. (If you are on a web > > page in Firefox, and want to save it, click File>Save Page As...) > > > If you want to save a picture from the Net see: > > >http://www.daniweb.com/code/snippet216796.html > > > Good luck! > > > -- > > People should read more.https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain > > "All that is gold does not glitter, > > not all those who wander are lost; > > the old that is strong does not wither, > > deep roots are not reached by the frost. > > From the ashes a fire shall be woken, > > a light from the shadows shall spring; > > renenwed shall be blade that was broken, > > the crownless again shall be king." > > Thanks for your reply, the problem is that i don't want to save it > with file-> save. > there is any way to save the page by script. > please note that when i save the page with firefox, it save the html > page and also make a folder with the script used in the page, how i > can make it also with python script? > Thanks > > Luca It is not quite possible. If python is used, it runs behind the scenes and generates html send to the browser. You could only see the .py file if the server was poorly configured so it would show the content of the .py file instead of actually executing it to generate the html code, but in that case you would not see any page either. Regards, From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:56:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:56:08 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <4c2c8499$0$20848$426a74cc@news.free.fr> Message-ID: <4c2c9002$0$17075$426a34cc@news.free.fr> D'Arcy J.M. Cain a ?crit : > On Thu, 01 Jul 2010 14:07:27 +0200 > Bruno Desthuilliers wrote: >> And AFAICT you're wrong. I read and post to c.l.py using my newsreader >> (so NOT going thru GG), and my personal address is @gmail.com. > > But... > >> From: Bruno Desthuilliers > Sorry, there's a missing "sometimes" between "I" and "read" !-) Posting from office now. mmmm... Thinking again : I'm not sure the account I use to access usenet from home is a @gmail.com one neither. I'll check this out. From Bill at SynectixLtd.com Thu Jul 1 09:13:28 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Thu, 1 Jul 2010 14:13:28 +0100 Subject: python source code -> win/dos executable (on linux) References: <4c24c152$0$31381$4fafbaef@reader1.news.tin.it> <4c286d71$0$18654$4fafbaef@reader3.news.tin.it> Message-ID: <893ijnFmv1U1@mid.individual.net> "Stephen Hansen" wrote in message news:mailman.2344.1277821469.32709.python-list at python.org... > On 6/29/10 12:27 AM, Lawrence D'Oliveiro wrote: >> In message<4c286d71$0$18654$4fafbaef at reader3.news.tin.it>, superpollo >> wrote: >> >>> Lawrence D'Oliveiro ha scritto: >>>> >>>> Is it really such a hassle to install things on Windows? >>> >>> no, but it *IS* to explain it to dumb users... :-( >> >> Can't you create an installation package that specifies Python and all >> the >> other necessary dependencies, so the Windows package-management system >> will >> automatically pull the right versions in when the user does the >> installation? > > At first, on reading this, I assumed it was sarcastic (and sort of decided > not to reply, because anti-windows is too easy); but on reading again I'm > not so sure, you're writing it all out so .. dry. Then again, 'hearing' > tone in text is hard. > > If this isn't sarcastic: windows has no package management system. You > include every dependency manually (in varying forms) or things don't run. > > Windows has a way to track what you install, and the ability to uninstall > about three fourths of it later. That's it. > > -- > > ... Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > Not that I am a supporter of Windows nor an expert at MSI BUT later versions of Visual Studio do have a mechanism for building a package. I know it's not in VC6, but is in VS.2008. HTH, Bill From pecora at anvil.nrl.navy.mil Thu Jul 1 09:54:57 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 01 Jul 2010 09:54:57 -0400 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <3f35dcf5-25ff-4aa7-820c-592cbffa4b42@u26g2000yqu.googlegroups.com> Message-ID: In article <3f35dcf5-25ff-4aa7-820c-592cbffa4b42 at u26g2000yqu.googlegroups.com>, rantingrick wrote: > On Jun 30, 4:21?pm, geremy condra wrote: > > > Actually, I agree with this complaint though- it is much easier to type > > spaces than parens. > > Oh Geremy please. If you're going to whine about something at least > find something worth whining about! Yes a few more key strokes are > needed. But print should have been a function from day one. The > benefits of a print function over a print statement are obvious to > those who seek the truth and lost on those who wallow in self pity. If > it's that much trouble for you then pick up an editor that auto > inserts parenthesis for you, or *gasps* write a routine yourself. Look > i know masturbation makes you lazy, but geez! Hey, guys (gals?), Don't any of you have typing utilities that will fill in text after you hit a special key-combination? I get print " typed automatically by holding two modifier keys and hitting 'p' key. Sounds harder than it is and it's really fast. So if I switch to Python 3 I would change that to print(" . E.g. for the Mac there are programs (utilities that run in the background) like Quickeys and TypeItForMe that allow you to do all sorts of automatic inserting of commonly used text. They're cheap and easy to use. There must be something like this for Linux and Windows, no? -- -- Lou Pecora From xiyou.wangcong at gmail.com Thu Jul 1 10:13:29 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:13:29 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 06/30/10 01:25, Ethan Furman wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > Setattr and friends exist to work with dynamic attributes. > Yeah, my point is why setattr() for dynamic attributes while assignments for static attributes? Why not unify them? > "The Perfect Language" does not exist, and never will. I'm not even > sure it could exist for a single person, let alone a group of people > with disparate needs, patterns of thought, etc. > Agreed, but at least, the reason why I am being against so many people here is also trying to make Python be more perfect with my understanding. Thanks! -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 10:15:17 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:15:17 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2CA2F5.2090401@ixokai.io> On 7/1/10 5:29 AM, Wolfram Hinderer wrote: > On 1 Jul., 06:04, Stephen Hansen wrote: >> The 'reversed' and 'sorted' functions are generators that lazilly >> convert an iterable as needed. > > 'sorted' returns a new list (and is not lazy). Oops, you're right. Got the two crossed into one in my head. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From me+list/python at ixokai.io Thu Jul 1 10:18:53 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:18:53 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: <4C2C67EC.5070905@sequans.com> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> Message-ID: <4C2CA3CD.7000401@ixokai.io> On 7/1/10 3:03 AM, Jean-Michel Pichavant wrote: > Re is part of the python standard library, for some purpose I guess. No, *really*? So all those people who have been advocating its useless and shouldn't be are already too late? Damn. Well, there goes *that* whole crusade we were all out on. Since we can't destroy re, maybe we can go club baby seals. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From me+list/python at ixokai.io Thu Jul 1 10:27:23 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:27:23 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2CA5CB.80503@ixokai.io> On 7/1/10 5:11 AM, Roy Smith wrote: > Stephen Hansen wrote: > >> The quote does not deny the power of regular expressions; it challenges >> widely held assumption and belief that comes from *somewhere* that they >> are the best way to approach any problem that is text related. > > Well, that assumption comes from historical unix usage where traditional > tools like awk, sed, ed, and grep, made heavy use of regex, and > therefore people learned to become proficient at them and use them all > the time. Oh, I'm fully aware of the history of re's -- but its not those old hats and even their students and the unix geeks I'm talking about. It's the newbies and people wandering into the language with absolutely no idea about the history of unix, shell scripting and such, who so often arrive with the idea firmly planted in their head, that I wonder at. Sure, there's going to be a certain amount of cross-polination from unix-geeks to students-of-students-of-students-of unix geeks to spread the idea, but it seems more pervasive for that. I just picture a re-vangelist camping out in high schools and colleges selling the party line or something :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ P.S. And no, unix geeks is not a pejorative term. From xiyou.wangcong at gmail.com Thu Jul 1 10:31:29 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:31:29 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 06/30/10 01:20, Stephen Hansen wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > What does perfection have to do with anything? Python does not strive > for perfection. More then that, it rejects the entire idea of > perfection when it gets in the way of simply solving problems in an > easy, clean, readable, and reliable way. "Practicality beats purity". > I don't quite understand the spirit behind. IMHO, being purity should not harm the practicality, they are harmonious. :) > PEP 363 proposes adding new syntax: for new syntax to be accepted into > the language one must meet a *very* high bar. One must show a clear, > compelling reason why this new mental burden is worth increasing the > complexity of the language. > > Syntax won't get added to make the language more "perfect" to some > ideals (especially not ideals to some paradigm like OOP, as opposed to > its own internal ideals of readability, ease and practicality). > > Syntax is a burden. Every change in syntax, every addition in syntax, > requires everyone's to mental investment to increase: it costs more > mental energy to use the language, to fully understand it, then it did > before. > But how could the syntax could be a burden? It is easy to understand. And the reason why needs it is also clear, making class attributes more like a dictionary, isn't this why people insists we should have dynamic attribute creation via assigments? This seems to be unfair. :) > > Is Python perhaps less perfect, pure, with that addition to the > language denied? > > Who cares? Perfection is what the Borg* worship, I like understandable. :) Well, using setattr() rather than trivial assignments is also understandable, in fact, for me the former is even more understandable, it shows more clearly when I am adding a new attribute, I am programming classes, not non-classes. -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 10:39:10 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:39:10 -0700 Subject: Python dynamic attribute creation In-Reply-To: <4c2c8ca6$0$5338$426a74cc@news.free.fr> References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> <4c2c8ca6$0$5338$426a74cc@news.free.fr> Message-ID: <4C2CA88E.7090107@ixokai.io> On 7/1/10 5:41 AM, Bruno Desthuilliers wrote: > Stephen Hansen a ?crit : >> On 6/30/10 10:37 PM, Aahz wrote: >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. >> > > "Elegance" (just like "beauty") is in the eyes of the beholder. > > Explicitness, simplicity and readability are indeed primary concerns in > Python's design, but "elegance" is not. Now you'll of course find Python > mostly elegant *if* you value expliciteness, simplicity and readability, > but that's only because your definition of "elegant" happens to match > Guido's. But see, here I disagree with you, because I do think beauty -- as seen by Guido -- and elegance -- as seen by Guido -- *are* a prime concern of Python's design. Sure, those are subjective things, and not everyone will have the absolute same opinion on them. But there is an overriding sense of style and taste (in terms of code) which went into the design of the language and remained through its evolution, that is a very real and important part of the language we have today. A big difference between those people who like and really enjoy using Python verses those who prefer other solutions does come down to a sense of taste and compatibility with the Guido's taste. Some people never get past the revulsion of 'self' and whitespace. Certainly: there's a lot *more* then just taste at issue (I don't mean to trivialize those who select other solutions for reasons of more substance then style), and some people can be fans even without fully embracing Guido's definition of beauty and elegance. > But please gentlemen, let's not fight on this. This no religion, there's > no dogma here, and no heretic to burn. The religious-speak was a joke :) I'm not sure I remember fighting though, either way. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From xiyou.wangcong at gmail.com Thu Jul 1 10:44:40 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:44:40 +0800 Subject: Python dynamic attribute creation References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: On 07/01/10 13:49, Stephen Hansen wrote: Hi, Stephen, >> >> It may not be "the" primary concern, but elegance certainly is *a* >> primary concern. > > I concur. > > Its not explicitly stated, but it is the Zen 0. This is further > supported by its implied presence in many of the Axioms and Truths of > the Bots. > > "Beautiful is better then ugly"; and then the praise of the explicit, > of simplicity, of readability. > > Elegance is a prime concern of Python, as it is the natural result of > the Doctrines of Pythonicity. It may not be stated as a rule, but it a > the reward that we are given for following the path of enlightenment. Isn't elegance somewhat equalent to perfection? IMHO, if a language is perfect, it is elegant. However, in the other sub-thread, you seem to be against being perfect for Python. :) -- Live like a child, think like the god. From sitalsuneya at gmail.com Thu Jul 1 10:45:05 2010 From: sitalsuneya at gmail.com (Tiresh kumar K.C) Date: Thu, 1 Jul 2010 07:45:05 -0700 (PDT) Subject: TO CHANGE YOUR LIFE BY A SECOND : Message-ID: <6c85ae00-f39e-437e-b511-c665f7ea7b99@u26g2000yqu.googlegroups.com> DEAR ALL , VISIT: Click here http://successpsycho.blogspot.com AND TO CHANGE YOUR LIFE BY A SECOND : TO KNOW -NEW SECRET OF YOUR LIFE -SUCCESS FACTORS -THOUGHT EFFECT From ricaraoz at gmail.com Thu Jul 1 10:50:58 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 01 Jul 2010 11:50:58 -0300 Subject: I strongly dislike Python 3 In-Reply-To: <4c2b702c$1@dnews.tpgi.com.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <0291ae53-144e-497d-8762-3f420de92a58@q12g2000yqj.googlegroups.com> <4c2b702c$1@dnews.tpgi.com.au> Message-ID: <4C2CAB52.6070405@gmail.com> On 30/06/2010 01:23 p.m., Lie Ryan wrote: > On 07/01/10 01:42, Michele Simionato wrote: > >> On Jun 30, 2:52 pm, Lie Ryan wrote: >> >>> On 06/27/10 11:24, Steven D'Aprano wrote: >>> >>> >>>>>> Producing print function takes a little bit more effort than producing a >>>>>> print statement. >>>>>> >>> >>>> (1) The main use-cases for print are quick (and usually dirty) scripts, >>>> interactive use, and as a debugging aid. >>>> >>> That is precisely how the quick-and-dirty syntax of print statement can >>> be justified. While debugging, you'll need to be able to quickly add and >>> delete prints here and there, and the extra parens can quickly become >>> irritating. >>> >> Actually when debugging I use pdb which uses "p" (no parens) for >> printing, so having >> print or print() would not make any difference for me. >> > You mean I have to start a full-blown debugger to figure out the value > of a variable? No thanks, debugger has its use for stepping through > program, but not when printing values is sufficient. > Let's, as an exercise, count how many keystrokes and clicks you have spent on this thread and others complaining on the subject. How many programs do you think you could debug with this count (considering you spend a stroke in each print sentence, and I assume you being smart will not need many prints to figure out problem)? So let's say you'll keep complaining for a couple of years till you are ready to adopt Py3. You see what I mean? If you stop complaining right now the keystrokes you'll save will mean you'll have no extra typing to do at all. HTH From aahz at pythoncraft.com Thu Jul 1 10:51:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:51:11 -0700 Subject: Python dynamic attribute creation References: Message-ID: In article , Michael Torrie wrote: >On 06/28/2010 02:31 PM, Aahz wrote: >> In article , >> Michael Torrie wrote: >>> >>> True. But you can't really criticize a language's implementation of OOP >>> without a good understanding of the "pure" OO language. For example, in >>> Smalltalk If/Then statements are actually methods of Boolean objects. >>> >From a certain point of view that's extremely appealing (consistent, >>> anyway). Almost functional in nature. They are not implemented this >>> way in Python, so that's one thing you could argue is not OO about Python. >> >> Python is in no way a pure OOP language. (I assume you're aware of this, >> but your phrasing leaves that in doubt.) > >My phrasing leaves that in doubt? How does my example of how Smalltalk >implements if/then vs how Pyton's implementation leave that in doubt? >The last sentence alone is very clear. Actually, it's precisely the last sentence that creates doubt: by saying "one thing", it's easy for a careless reader to infer that otherwise you would think that Python is a pure OOP. Not a big deal, just thought it deserved clarification. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From me+list/python at ixokai.io Thu Jul 1 10:53:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:53:15 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <4C2CABDB.3090206@ixokai.io> On 7/1/10 7:31 AM, WANG Cong wrote: > On 06/30/10 01:20, Stephen Hansen wrote: > >>> But if so why setattr() still exists? What is it for if we can do the >>> same thing via assignments? Also, in order to be perfect, Python should >>> accept to add dynamic attributes dynamically, something like PEP >>> 363. That doesn't happen. >> >> What does perfection have to do with anything? Python does not strive >> for perfection. More then that, it rejects the entire idea of >> perfection when it gets in the way of simply solving problems in an >> easy, clean, readable, and reliable way. "Practicality beats purity". >> > > I don't quite understand the spirit behind. IMHO, being purity should > not harm the practicality, they are harmonious. :) The two are diametrically opposed in fact, quite often. Sometimes that's not the case, but that is the exception and not the rule. >> PEP 363 proposes adding new syntax: for new syntax to be accepted into >> the language one must meet a *very* high bar. One must show a clear, >> compelling reason why this new mental burden is worth increasing the >> complexity of the language. >> >> Syntax won't get added to make the language more "perfect" to some >> ideals (especially not ideals to some paradigm like OOP, as opposed to >> its own internal ideals of readability, ease and practicality). >> >> Syntax is a burden. Every change in syntax, every addition in syntax, >> requires everyone's to mental investment to increase: it costs more >> mental energy to use the language, to fully understand it, then it did >> before. >> > But how could the syntax could be a burden? Syntax is always a burden, by definition. Everything added to the language is a burden. Each has a cost. Some, that cost is light, and the benefits great-- but in others > It is easy to understand. For you. It makes it harder for someone to learn the language. _Every_ bit of syntax does. Its one more thing that you have to learn before you read down a piece of code and easily grok exactly what its doing. >> Is Python perhaps less perfect, pure, with that addition to the >> language denied? >> >> Who cares? Perfection is what the Borg* worship, I like understandable. :) > > Well, using setattr() rather than trivial assignments is also > understandable, in fact, for me the former is even more understandable, > it shows more clearly when I am adding a new attribute, I am programming > classes, not non-classes. For you. You find setattr() more understandable. Others do not. You make a distinction between "programming classes" and what you previously called "metaprogramming", others do not. The importance of "programming classes" is something that exists in your mind only -- well, yours and anyone who chooses to think so as well, which is certainly quite a few people. But I'll thank you to not impose your sense of importance of these things on me. There is nothing at all notable about the difference of "programming classes" verses "programming non-classes" to me. :) You're free to make the distinction in your own code; not everyone defines "programming classes" as anything special. As for setattr... sorry, but your assertion is simply untrue: there is nothing about it which says you are adding a new attribute. You can use it to set any attribute you want, even one that already exists and was defined previously. One uses assignment syntax when the name of the attribute they are setting is known at the time when one writes the code. One uses the setattr function when the name of the attribute is not known until runtime. The difference has *nothing at all* to do with "programming classes" or "dynamic" vs "static". The existence of one does *nothing at all* to invalidate the utiltiy of the other. You use one construct in the usual-case of setting the value of an attribute which is known at coding-time (irregardless of if that attribute existed before: /neither/ of these constructs make /any/ distinction between adding a new attribute and replacing an old one that already existed), and one when the name of that attribute is dependent on some runtime state. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From aahz at pythoncraft.com Thu Jul 1 10:55:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:55:15 -0700 Subject: Python dynamic attribute creation References: Message-ID: In article , WANG Cong wrote: >On 07/01/10 13:49, Stephen Hansen wrote: >>Wang Cong deleted the attribution for Aahz: >>> >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. > >Isn't elegance somewhat equalent to perfection? Not in the slightest. However, elegance is often achieved by aiming for perfection. >IMHO, if a language is perfect, it is elegant. Probably, but the converse is completely not true. P->Q does not imply Q->P, and if this isn't obvious to you, you need to study formal logic (which would be of assistance to you in your other programming endeavors). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From alanwilter at gmail.com Thu Jul 1 10:57:40 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 1 Jul 2010 15:57:40 +0100 Subject: drag & drop in a python GUI application Message-ID: Hello there, I know drag & drop is not possible with TK. Which widget could I use for my python application to be able to work with drag & drop? Thanks, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jul 1 10:58:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:58:26 -0700 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> Message-ID: In article , geremy condra wrote: >On Wed, Jun 30, 2010 at 4:34 PM, Steven D'Aprano > wrote: >> On Wed, 30 Jun 2010 22:52:06 +1000, Lie Ryan wrote: >>> >>> That is precisely how the quick-and-dirty syntax of print statement can >>> be justified. While debugging, you'll need to be able to quickly add and >>> delete prints here and there, and the extra parens can quickly become >>> irritating. >> >> *rolls eyes* >> >> Not as irritating as people who complain about having to type parentheses. > >http://www.xkcd.net/297/ http://www.netfunny.com/rhf/jokes/90q2/lispcode.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From me+list/python at ixokai.io Thu Jul 1 11:01:25 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 08:01:25 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4C2CADC5.8040205@ixokai.io> On 7/1/10 7:44 AM, WANG Cong wrote: > On 07/01/10 13:49, Stephen Hansen wrote: >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. > > > Isn't elegance somewhat equalent to perfection? > IMHO, if a language is perfect, it is elegant. No. > However, in the other sub-thread, you seem to be against being perfect > for Python. :) Yes. Perfection, if it exists (it does not), would probably have the property of elegance. Unless by 'perfect' we mean, 'perfectly models this certain paradigm of thought', in which case 'perfect' is really very limited when someone wants to go do something with a different paradigm all together. Technical elegance (as opposed to like, the elegance of silk) is the clear execution of a thought or process in a concise, simple way. It's utterly impossible for any language to be perfect; no language can possibly express all thought and processes of thought in an ideal form. Every language will have things it is better at expressing then others-- thoughts and ways of thinking that flow better from it then others. A language can be elegant though (I don't even think Python is: it just tries to be): but not everything you do with it will then be elegant itself. Elegance happens in the specific: a certain solution, a key design of a system, there you find elegance. It doesn't exist in the general. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From xiyou.wangcong at gmail.com Thu Jul 1 11:02:57 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:02:57 +0800 Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: On 06/27/10 09:06, Steven D'Aprano wrote: >> In that situation, certainly: adding an attribute on the fly to that >> formal definition seems entirely strange and special of an activity. But >> that's only because you *chose* to *see* and *use* the object that way. >> The "special"ness of the activity is entirely in your head, and to >> Python, its an entirely normal event. > > Exactly. Things which other languages make scary and mysterious > "metaprogramming" are, in Python, normal and ordinary programming. It > doesn't seem to do us any harm. > As long as setattr() exists in Python, that will be not so ordinary. :) -- Live like a child, think like the god. From mathar at krypton.strw.leidenuniv.nl Thu Jul 1 11:06:07 2010 From: mathar at krypton.strw.leidenuniv.nl (Richard Mathar) Date: Thu, 1 Jul 2010 15:06:07 +0000 (UTC) Subject: Sphinx-1.0b compilation for python3.1 Message-ID: I am trying to install Sphinx-1.0b under a Python3 environment. Does anyone have experience with that task? cd *1.0b2 python3 setup.py build File "setup.py", line 50 print 'ERROR: Sphinx requires at least Python 2.4 to run.' So ../ 2to3 -w Sphinx-1.0b2 ....... RefactoringTool: Warnings/messages while refactoring: RefactoringTool: ### In file Sphinx-1.0b2/sphinx/writers/text.py ### RefactoringTool: Line 393: cannot convert map(None, ...) with multiple arguments because map() now truncates to the shortest sequence cd *1.0b2 python3 setup.py build --------------------------------------------------------------------------- This script requires setuptools version 0.6c9 to run (even to display help). I will attempt to download it for you (from http://pypi.python.org/packages/3.1/s/setuptools/), but you may need to enable firewall access for this script first. I will start the download in 15 seconds. (Note: if this machine does not have network access, please obtain the file http://pypi.python.org/packages/3.1/s/setuptools/setuptools-0.6c9-py3.1.egg and place it in this directory before rerunning this script.) --------------------------------------------------------------------------- Downloading http://pypi.python.org/packages/3.1/s/setuptools/setuptools-0.6c9-py3.1.egg Traceback (most recent call last): File "setup.py", line 3, in from setuptools import setup, find_packages ImportError: No module named setuptools During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 93, in use_setuptools import pkg_resources ImportError: No module named pkg_resources During handling of the above exception, another exception occurred: Traceback (most recent call last): File "setup.py", line 6, in ez_setup.use_setuptools() File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 95, in use_setuptools return do_download() File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 89, in do_download egg = download_setuptools(version, download_base, to_dir, download_delay) File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 150, in download_setuptools src = urllib.request.urlopen(url) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 121, in urlopen return _opener.open(url, data, timeout) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 355, in open response = meth(req, response) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 467, in http_response 'http', request, response, code, msg, hdrs) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 393, in error return self._call_chain(*args) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 327, in _call_chain result = func(*args) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 475, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found How do I move on from here? From xiyou.wangcong at gmail.com Thu Jul 1 11:15:23 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:15:23 +0800 Subject: Python dynamic attribute creation References: <4c27483c$0$4545$426a74cc@news.free.fr> <72dd3dae-30b3-49b0-bf42-3b63178eb3b4@w31g2000yqb.googlegroups.com> <4c286e66$0$20686$426a74cc@news.free.fr> Message-ID: On 06/28/10 17:43, Bruno Desthuilliers wrote: > Carl Banks a ?crit : >> On Jun 27, 3:49 am, Bruno Desthuilliers >> wrote: >>> WANG Cong a ?crit : >>> >>>> On 06/26/10 00:11, Neil Hodgson wrote: >>>>> WANG Cong: >>>>>> 4) Also, this will _somewhat_ violate the OOP princples, in OOP, >>>>>> this is and should be implemented by inherence. >>>>> Most object oriented programming languages starting with Smalltalk >>>>> have allowed adding attributes (addInstVarName) to classes at runtime. >>>> Thanks, I have to admit that I know nothing about Smalltalk. >>> Then you really don't know much about OO. >> >> I don't really know much about Smalltalk either. >> > > Duh. I cancelled this totally stupid and useless post a couple seconds > after hitting the send button, but still too late :( > > So first let me present my apologies to WANG Cong and everyone else, > this was a crude, arrogant and totally stupid thing to say, and I > should know better. Sorry. > No problem. :) > Now on why I first wrote this (warning : personal opinions ahead): > > "object" started with Simula, but objects in Simula are mostly > glorified ADTs with type-based "polymorphic" dispatch. Smalltalk (and > all it's environment) got _way_ further by turning this into a > coherent whole by introducing messages (which are more than just > type-based polymorphic dispatch - Smalltalk's messages are objects > themselves) and "code blocks" - as the only mean to control "flow". I > believe that Smalltalk is (so far) the only "OO" language that was > innovative enough to really escape from good old procedural > programming, and as such possibly the only "True" OOPL. > > Now for various reasons (including implementation issues and > conservatism), it happened that the Simula approach to OO became the > mainstream with languages like C++ then Java, and that most of "OO" > litterature - "OOP principles", golden rules etc - is about this > somehow very restricted approach, so people being taught "OO" that way > have a very restricted - and incomplete - vision of what OO is really > about. That was how I was taught OO, and I always felt that there was > something wrong, inconsistant or missing. > > Studying Smalltalk (however briefly) was for me a real "AHA", > mind-opening moment - suddenly OO made sense as this coherent, > comprehensive and innovative approach to programming I so far failed > to find in Java or C++. > > Now I don't mean one has to master Smalltalk to be allowed to talk > about OO, nor that OO can't exist outside Smalltak (Python being IMHO > another exemple of an interesting and mostly coherent object system, > even if doesn't go as far as Smalltalk do), but - pardon me if this > seems arrogant (and please correct me if it really is) - I can't help > thinking that one cannot really understand OO whithout at least a > brief study of Smalltalk (and - once again - a full Smalltalk > environment, as Smalltalk the language is only one part of the 'full' > object system). > This sounds really cool, I think I should find some time to learn Smalltalk, even only considering historic reasons. Thanks for sharing your Smalltalk learning experience with us! -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 11:19:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 08:19:50 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4C2CB216.4050006@ixokai.io> On 7/1/10 8:02 AM, WANG Cong wrote: > On 06/27/10 09:06, Steven D'Aprano wrote: > >>> In that situation, certainly: adding an attribute on the fly to that >>> formal definition seems entirely strange and special of an activity. But >>> that's only because you *chose* to *see* and *use* the object that way. >>> The "special"ness of the activity is entirely in your head, and to >>> Python, its an entirely normal event. >> >> Exactly. Things which other languages make scary and mysterious >> "metaprogramming" are, in Python, normal and ordinary programming. It >> doesn't seem to do us any harm. >> > > As long as setattr() exists in Python, that will be not so ordinary. :) setattr is perfectly ordinary. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From python at mrabarnett.plus.com Thu Jul 1 11:29:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jul 2010 16:29:31 +0100 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2CB45B.4050804@mrabarnett.plus.com> Zubin Mithra wrote: > > Er, I don't think you thought that one entirely through (/ tried it > out): > > > My Apologies. > > Here is a working one. > > >>> x="123" > >>> t = list(x) > >>> t.reverse() > >>> print ''.join(t) > 321 > > > But of course, the method which was suggested earlier is far more elegant. > > >>> print ''.join(reversed(list(x))) > If you want even more elegance, try slicing: >>> x = "123" >>> print x[ : : -1] 321 From hema_111150 at yahoo.com Thu Jul 1 11:35:29 2010 From: hema_111150 at yahoo.com (eslam) Date: Thu, 1 Jul 2010 08:35:29 -0700 (PDT) Subject: hi hi hi hi Message-ID: <6bc2d6a1-1ecc-4c46-aa88-89f05ee42bd5@b35g2000yqi.googlegroups.com> How and why do people embrace Islam? ?Part One? People embrace Islam in the West (USA, Canada, UK, France and Germany), in the Middle Eastern countries (Saudi Arabia, the Gulf States, Jordan), in Africa and the Far East (Malaysia, Philippines, Hong Kong) and many other countries all over the world. According to Islam, there is only one revealed religion which has been revealed from the time of Adam until the last of the prophets, Mohammad (PBUH), yet it was revealed on stages. Consequently, the essential message of all the prophets was one and the same, Allah says in the Holy Qur?an: ?Verily, We have sent to every nation a messenger (saying), ?Worship Allah and avoid false gods.? All the Prophets that Allah has sent had one basic messages, for indeed the purpose of creation is only one, which is worshiping Allah. Allah says in the Holy Qur?an ?I did not create the jinn and mankind except for My worship.? This message addressed a basic and essential need in human beings; the need to worship. Such basic need was created in all human beings at the time of Adam?s creation. Man?s Natural Disposition : the Fitrah As Allah made all human beings swear to His Godhood when He first created Adam, this oath is printed on the human soul even before it enters the fetus in the fifth month of pregnancy. So when a child is born, he has a natural belief in Allah. This natural belief is called in Arabic the fitrah. If the child was left alone, he would grow with the same faith and believe in Allah. But what happens is that all children get affected by their surroundings, whether directly or indirectly. Prophet Mohammad (PBUH) said that Allah said: ?I created My servants in the right religion but the devils made them go astray.? Prophet Mohammad (PBUH) also said: ?Each child is born in a state of ?fitrah?, but his parents make him a Jew or a Christian. It is like the way an animal gives birth to a normal offspring. Have you noticed any (young animal) born mutilated before you mutilate them?? And since the child?s body submits to the physical laws which Allah has put in nature, his soul also submits naturally to the belief that Allah is its Lord and Creator. However, his family friends, and his surroundings affect him, and as he grows up, he may find himself following this or that?s way of life. The religion the child follows at early stages of his life (childhood) is one of custom and upbringing, and Allah does not punish him for this religion. However, by reaching maturity one starts differentiating between what?s right and what?s wrong, an adult must now follow the religion of knowledge and reason; Islam. At this point the devil starts doing his best and trying hard to encourage him to stay as he is ( encourage him to stay passive and not do any good deeds), or bring down. Evils are made pleasing to mankind and thus we live in a constant struggle between our fitrah and our desires till we find the right road. If one chooses his fitrah, Allah will help him control his desires, even though it may take most of his life to do so; for example some people embraced Islam in their old age, yet it is never too late. From mwilson at the-wire.com Thu Jul 1 11:36:46 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 1 Jul 2010 15:36:46 +0000 (UTC) Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: Nobody wrote: > On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: >> Given "char buf[512]", buf's type is char * according to the compiler >> and every C textbook I know of. References from Kernighan & Ritchie _The C Programming Language_ second edition: > No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you > use "buf" as an rvalue (rather than an lvalue), it will be implicitly > converted to char*. K&R2 A7.1 > If you take its address, you'll get a "pointer to array of 512 chars", > i.e. a pointer to the array rather than to the first element. Converting > this to a char* will yield a pointer to the first element. K&R2 A7.4.2 ????????Mel. From xiyou.wangcong at gmail.com Thu Jul 1 11:42:20 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:42:20 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 07/01/10 22:53, Stephen Hansen wrote: > > One uses assignment syntax when the name of the attribute they are > setting is known at the time when one writes the code. > > One uses the setattr function when the name of the attribute is not > known until runtime. > > The difference has *nothing at all* to do with "programming classes" > or "dynamic" vs "static". > This is exactly what I am thinking. What we differ is that if using both assignment syntax and setattr() builtin function is a good design. You think the current design which lets them co-exist is more understandable, while I think this is less perfect and then not that more understandable. :) "Understandable" is hard to define, it differs so much from person to person. "Perfect" is a strong sense for which I enjoy programming and learn programming languages. Thanks much for your detailed answers, I like discussing this with you! -- Live like a child, think like the god. From xiyou.wangcong at gmail.com Thu Jul 1 11:46:55 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:46:55 +0800 Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: On 07/01/10 23:19, Stephen Hansen wrote: >> >> As long as setattr() exists in Python, that will be not so ordinary. :) > > setattr is perfectly ordinary. If you think setattr() is as ordinary as a trivial assignment, I will argue with you, this is personal taste. However, I think setattr() is a builtin function, using it exposes the *magic* of metaprogramming (or class-programming, if more correct) at a first glance. -- Live like a child, think like the god. From torriem at gmail.com Thu Jul 1 12:10:16 2010 From: torriem at gmail.com (Michael Torrie) Date: Thu, 01 Jul 2010 10:10:16 -0600 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4C2CBDE8.3010305@gmail.com> On 07/01/2010 01:24 AM, Nobody wrote: > No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you > use "buf" as an rvalue (rather than an lvalue), it will be implicitly > converted to char*. Yes this is true. I misstated. I meant that most text books I've seen say to just use the variable in an *rvalue* as a pointer (can't think of any lvalue use of an array). K&R states that arrays (in C anyway) are always *passed* by pointer, hence when you pass an array to a function it automatically decays into a pointer. Which is what you said. So no need for & and the compiler warning you get with it. That's all. If the OP was striving for pedantic correctness, he would use &buf[0]. From dhilip.jec at gmail.com Thu Jul 1 12:21:40 2010 From: dhilip.jec at gmail.com (Dhilip S) Date: Thu, 1 Jul 2010 21:51:40 +0530 Subject: Python 2.4.2 Installation error Message-ID: Hello Everyone.. I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got error message while doing make command. anybody can tell tell, How to overcome this error.... -- with regards, Dhilip.S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Jul 1 12:35:31 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 01 Jul 2010 09:35:31 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <87aaqbiviw.fsf_-_@benfinney.id.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> Message-ID: <4C2CC3D3.3030100@stoneleaf.us> Ben Finney wrote: > geremy condra writes: > >>> Right. I'm much more concerned about the position of my Ctrl key, to >>> avoid hand injury from all the key chording done as a programmer. >> Not saying its a cure-all, but I broke my hand pretty badly a few years >> ago and had a lot of luck with a homemade foot switch for each of the >> meta keys. Was pretty fun to do (all things considered) and worked >> pretty well. I'm sure if you're willing to do some shopping around you >> could get a prefab one fairly cheaply. > > My current solution is: > > * Never use a notepad on the couch, but only ever at a properly adjusted > table/desk and chair. > > * Remap CapsLock as an additional Ctrl key, on every computer I use > (nobody has ever minded this, because they don't use that key at all > :-) > > * Use my left hand for operating the mouse, since this brings it much > closer to the home position on the keyboard, and a standard keyboard > design forces the right hand to do disproportionately more work. > > * Use a wrist support, consisting of two plastic discs that are > separated and move freely against each other, that allows my whole arm > to move for moving the mouse and hence avoid bending my wrist for that > operation. > > Quite cheap and simple, and I've thereby had no recurrence of injury for > the past 3 years. I'll have to give the left-handed mouse a try... hmmm -- not too bad so far. I also switched over to the Dvorak keyboard layout. Made a world of difference for me. ~Ethan~ From jdoe at usenetlove.invalid Thu Jul 1 12:39:46 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 01 Jul 2010 16:39:46 GMT Subject: OT Komodo Edit, line selection gutter is one pixel wide? Message-ID: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Is there a way to increase the line selection gutter width? It seems to be only one pixel wide. In other words... When I single click on the left side of the line, in order to automatically select the line, the pointer must be in a precise single pixel location immediately to the left of the line. Or am I doing something wrong? Thanks. By the way... I can see that clicking and dragging to select multiple lines can be done somewhere in the space of the first character on the lines, but I am talking about single clicking to select the single line. From me+list/python at ixokai.io Thu Jul 1 12:51:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 09:51:27 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4C2CC78F.8060109@ixokai.io> On 7/1/10 8:46 AM, WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. I'm going to try this one more time -- you place a great deal of importance and special properties on Classes and what they mean to object oriented programming. That is perfectly fine. In some languages, there is indeed a great deal of importance to Classes. They define a sort of formal structure, a contract, and the rules by which the program runs. Object Oriented Programming is ingrained in them as not just a means, but an end -- it's the Right Way to do things, the tenants of the OOP paradigm are ingrained as the rules of interaction between things. In these languages, modifying a class at runtime might indeed be strange, interesting, magical. In Python, none of this holds true. Python's classes are *created* at runtime. The 'class body' is executable code which is run when your program starts, the result of which is your class. Now, let me ask you a (rhetorical) question: exactly when are the attributes 'created' on a class? You say that adding attributes to an object is special, magical. Consider this relatively simple class: class Person(object): def __init__(self, name, age=21): self.name = name self.age = age I can instantiate that easily, of course: me = Person("Stephen", 29) This is all the normal, basic way we deal with classes and attributes right? Right. Here's the important detail. When __init__ is called, the person object has no attributes(*). None at all. Unlike in other more real OOP languages where they have attributes which are just basically uninitialized, here it has none. In the __init__, its adding attributes to that object which already exists on the fly-- at runtime. Now, here I do something "magic": me.hair_color = "brown" I've now added a new attribute to the existing instance, what you're calling something special called "class programming". The problem: that's the *exact same syntax* which was used in __init__. There's no difference between what happened in __init__, where we normally consider that we're defining our attributes, and what may happen later when you decide to add an attribute 'ont he fly'. The second case is special *only* if you *imagine* it is-- and it is special then *only* in your own mind. It is special, "adding an attribute to a previously defined class", if you decide for yourself, classes are things that are set in stone or pre-defined in some way. Classes aren't pre-defined, they're entirely created and defined on the fly. That a certain 'on the fly' may happen early (right after you create an instance) or another may happen at any point later-- Python doesn't and can't even tell the difference (not by itself without any jumping through hoops at least). It's all the same. There's nothing magical about it. Except to you, *personally*. In your head, only. Its fine to believe that and treat classes as special for you: but its your *choice* to do so. If you want magic, go learn about metaclasses, descriptors, and such. Othewrise, I give up. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From usenot at geekmail.INVALID Thu Jul 1 13:00:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 1 Jul 2010 19:00:33 +0200 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> Message-ID: <20100701190033.15ceaeea@geekmail.INVALID> On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman wrote: > I'll have to give the left-handed mouse a try... hmmm -- not too bad > so far. Since we're on the subject: I find the best solution for "lots of typing with a little mousing" to be a keyboard with a pointing stick (or track point or nav stick or whatever people call it). I'm not quite sure why they haven't become standard issue on keyboards. Shame, is what that is. /W -- INVALID? DE! From emile at fenx.com Thu Jul 1 13:09:30 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 10:09:30 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On 7/1/2010 10:00 AM Andreas Waldenburger said... > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > wrote: > >> I'll have to give the left-handed mouse a try... hmmm -- not too bad >> so far. > > Since we're on the subject: I find the best solution for "lots of > typing with a little mousing" to be a keyboard with a pointing stick > (or track point or nav stick or whatever people call it). I'm not quite > sure why they haven't become standard issue on keyboards. Shame, is > what that is. > > /W > When I started having trouble about ten years ago, I switched to a keyboard with integrated mouse pad. No problems since... Emile From marduk at letterboxes.org Thu Jul 1 13:10:26 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 01 Jul 2010 13:10:26 -0400 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <1278004226.9444.9.camel@paska> On Thu, 2010-07-01 at 21:51 +0530, Dhilip S wrote: > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 > got error message while doing make command. anybody can tell tell, How > to overcome this error.... "this" error apparently did not get included in your post. From vijay.nori at gmail.com Thu Jul 1 13:10:31 2010 From: vijay.nori at gmail.com (V N) Date: Thu, 1 Jul 2010 10:10:31 -0700 (PDT) Subject: escape character / csv module Message-ID: string "\x00" has a length of 1. When I use the csv module to write that to a file csv_f = csv.writer(file("test.csv","wb"),delimiter="|") csv_f.writerow(["\x00","zz"]) The output file looks like this: |zz Is it possible to force the writer to write that string? From thomas at jollans.com Thu Jul 1 13:11:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 19:11:07 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <4C2CCC2B.2000108@jollans.com> On 07/01/2010 06:21 PM, Dhilip S wrote: > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Which error? > -- > with regards, > Dhilip.S > > From nagle at animats.com Thu Jul 1 13:17:02 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 10:17:02 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> On 7/1/2010 8:36 AM, Mel wrote: > Nobody wrote: >> On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: >>> Given "char buf[512]", buf's type is char * according to the compiler >>> and every C textbook I know of. > > References from Kernighan& Ritchie _The C Programming Language_ second > edition: > >> No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you >> use "buf" as an rvalue (rather than an lvalue), it will be implicitly >> converted to char*. Yes, unfortunately. The approach to arrays in C is just broken, for historical reasons. To understand C, you have to realize that in the early versions, function declarations weren't visible when function calls were compiled. That came later, in ANSI C. So parameter passing in C is very dumb. Billions of crashes due to buffer overflows later, we're still suffering from that mistake. But this isn't a Python issue. John Nagle From lists at cheimes.de Thu Jul 1 13:18:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 01 Jul 2010 19:18:22 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Perhaps somebody is able to help you if you provide the full error message and describe all steps that lead to the error mesage. http://catb.org/esr/faqs/smart-questions.html#beprecise Christian From usenot at geekmail.INVALID Thu Jul 1 13:19:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 1 Jul 2010 19:19:55 +0200 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: <20100701191955.54cd0aee@geekmail.INVALID> On Thu, 01 Jul 2010 10:09:30 -0700 Emile van Sebille wrote: > On 7/1/2010 10:00 AM Andreas Waldenburger said... > > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > > wrote: > > > >> I'll have to give the left-handed mouse a try... hmmm -- not too > >> bad so far. > > > > Since we're on the subject: I find the best solution for "lots of > > typing with a little mousing" to be a keyboard with a pointing stick > > (or track point or nav stick or whatever people call it). I'm not > > quite sure why they haven't become standard issue on keyboards. > > Shame, is what that is. > > > > /W > > > > When I started having trouble about ten years ago, I switched to a > keyboard with integrated mouse pad. No problems since... > Not bad, but you'll still have to move away your hand from the home row that way. Pointing stick, I tells ya, pointing stick! ;) /W -- INVALID? DE! From thomas at jollans.com Thu Jul 1 13:23:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 19:23:53 +0200 Subject: Python/C++ timer intermittent bug In-Reply-To: References: Message-ID: <4C2CCF29.3030209@jollans.com> On 06/30/2010 09:28 PM, Paul at mail.python.org wrote: > I have a problem with threading using the Python/C API. I have an > extension that implements a timer, and the C++ timer callback function > calls a Python function. The relevant code looks like this: > > [snip] > > static void CALLBACK PeriodicTimer(UINT wTimerID, UINT msg, > DWORD dwUser, DWORD dw1, DWORD dw2) This looks frightfully WIN32. How are you calling a timer? I'm guessing you're using some win32 function. So my tentative tip on where the problem might lie is the interaction of Python's PyThreads and the win32 threading primitives you're probably calling. > { > PyGILState_STATE pgs; > > pgs = PyGILState_Ensure(); > if(attrsetFlag) > { > pres = PyObject_CallFunction(attr,NULL); > if( pres == NULL )printf("CallFunction failed!\n"); > } > PyGILState_Release( pgs ); > > } > > The Python code that sets this up looks like this: > > fetimer.setmodname("Timeslice3") > fetimer.setprocname("Timetester") I'm sure this isn't the problem, but why aren't you just passing in an object? As in fetimer.setcallable(Timeslice3.Timetester)? > [ snip ] > > Fatal Python Error: This thread state must be current when releasing > > Fatal Python Error: PyThreadState_DeleteCurrent: no current tstate > > Fatal Python Error: PyEval_SaveThread: NULL tstate As I said, I'd expect there to be some irregularities between what PyThreads would normally do and what you're doing in the code you didn't post. > > Can anybody help me make this code stable, so that it works all the > time? I can't really help you - I have limited experience with the C API, let alone Python/C threading, and know next to nothing about Windows programming. Maybe you should ask in a more specialized (and quieter) forum, such as the CAPI-SIG mailing list, or python-win32. -- Thomas From googler.1.webmaster at spamgourmet.com Thu Jul 1 13:40:22 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 10:40:22 -0700 (PDT) Subject: Extract doc strings References: <4c2c8731$0$28647$c3e8da3@news.astraweb.com> Message-ID: Great! Thanks a lot! This is what I was looking for. :) Bye, moerchendiser2k3 From homeusenet3 at brianhv.org Thu Jul 1 13:46:39 2010 From: homeusenet3 at brianhv.org (Brian Victor) Date: Thu, 1 Jul 2010 17:46:39 +0000 (UTC) Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: Emile van Sebille wrote: > When I started having trouble about ten years ago, I switched to a > keyboard with integrated mouse pad. No problems since... Where did you find that? I've been looking for one. (Assuming you mean a trackpad, and not a mouse pad.) That said, my own solution was the Kensington Expert Mouse. For some reason, the trackball hurts me much less than a real mouse, and keeps me from being disproportionately annoyed when I have to pick up my pointing device to move the cursor where I want it. ;) -- Brian From mithrandiragainwiki at mailinator.com Thu Jul 1 14:05:05 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 18:05:05 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <4c2c9002$0$17075$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote in news:4c2c9002$0$17075$426a34cc at news.free.fr: > D'Arcy J.M. Cain a ?crit : >> On Thu, 01 Jul 2010 14:07:27 +0200 >> Bruno Desthuilliers >> wrote: >>> And AFAICT you're wrong. I read and post to c.l.py using my >>> newsreader (so NOT going thru GG), and my personal address is >>> @gmail.com. >> >> But... >> >>> From: Bruno Desthuilliers >>> >> > > Sorry, there's a missing "sometimes" between "I" and "read" !-) > Posting from office now. > > mmmm... Thinking again : I'm not sure the account I use to access > usenet from home is a @gmail.com one neither. I'll check this out. Just thought of this last night: If you view the full header you can see this: Complaints-To: groups-abuse at google.com Try blocking posts with that in the header. :) Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From rami.chowdhury at gmail.com Thu Jul 1 14:11:54 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 1 Jul 2010 11:11:54 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <20100701181154.GC2267@tigris> On 2010-07-01 23:42, WANG Cong wrote: > On 07/01/10 22:53, Stephen Hansen wrote: > > > > > One uses assignment syntax when the name of the attribute they are > > setting is known at the time when one writes the code. > > > > One uses the setattr function when the name of the attribute is not > > known until runtime. > > > > The difference has *nothing at all* to do with "programming classes" > > or "dynamic" vs "static". > > > > This is exactly what I am thinking. > > What we differ is that if using both assignment syntax and setattr() > builtin function is a good design. You think the current design which > lets them co-exist is more understandable, while I think this is less > perfect and then not that more understandable. :) Is this not the practicality / purity discussion from another subthread? You think it's "less perfect" (by which I think you actually mean "less pure" - but please correct me if I'm wrong). But you admit that it's more under- standable (i.e. it's more practical). Practicality beats purity, so the "less pure" solution wins. > > "Understandable" is hard to define, it differs so much from person to > person. "Perfect" is a strong sense for which I enjoy programming and > learn programming languages. > > Thanks much for your detailed answers, I like discussing this with you! > > > -- > Live like a child, think like the god. > > -- > http://mail.python.org/mailman/listinfo/python-list ---- Rami Chowdhury "It always takes longer than you expect, even when you take Hofstadter's Law into account." -- Hofstadter's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From emile at fenx.com Thu Jul 1 14:17:22 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 11:17:22 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On 7/1/2010 10:46 AM Brian Victor said... > Emile van Sebille wrote: >> When I started having trouble about ten years ago, I switched to a >> keyboard with integrated mouse pad. No problems since... > > Where did you find that? I've been looking for one. (Assuming you mean > a trackpad, and not a mouse pad.) Actually, I guess it's called a touchpad? And they are hard to find with the ergonomic split keyboard and touchpad placement I prefer. I have three systems I do most of my work on, so when I spot the kind I like I buy four or more so I can update all the keyboards at once and still have a spare. A quick check on cdw.com doesn't show any at the moment. Froogle shows some, but none that match the layout I like. Emile From ian.g.kelly at gmail.com Thu Jul 1 14:20:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 1 Jul 2010 12:20:27 -0600 Subject: OT Komodo Edit, line selection gutter is one pixel wide? In-Reply-To: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 10:39 AM, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? I've been using Komodo for 3.5 years and didn't even realize there was such a gutter until you pointed it out. I don't see any way to make it larger either -- how odd. When I want to select full lines, I use the keyboard. I have Alt+Home mapped to the Beginning of Line command (the one that always takes you to the first column rather than the first character), and then Shift+Up/Down to select. From me+list/python at ixokai.io Thu Jul 1 14:20:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 11:20:50 -0700 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <4c2c9002$0$17075$426a34cc@news.free.fr> Message-ID: <4C2CDC82.4040204@ixokai.io> On 7/1/10 11:05 AM, Mithrandir wrote: > Just thought of this last night: If you view the full header you can see > this: > > Complaints-To: groups-abuse at google.com > > Try blocking posts with that in the header. :) Better idea: auto-forward any messages with that header, to that address. Odds are it's accurate :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From thomas at jollans.com Thu Jul 1 14:30:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 20:30:01 +0200 Subject: OT Komodo Edit, line selection gutter is one pixel wide? In-Reply-To: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <4C2CDEA9.60004@jollans.com> On 07/01/2010 06:39 PM, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. Not sure if this factoid is of any use to you, but many editors support selecting lines by tripple-clicking. From thomas at jollans.com Thu Jul 1 14:33:13 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 20:33:13 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: <4C2CDC82.4040204@ixokai.io> References: <4c2c9002$0$17075$426a34cc@news.free.fr> <4C2CDC82.4040204@ixokai.io> Message-ID: <4C2CDF69.6050407@jollans.com> On 07/01/2010 08:20 PM, Stephen Hansen wrote: > On 7/1/10 11:05 AM, Mithrandir wrote: > >> Just thought of this last night: If you view the full header you can see >> this: >> >> Complaints-To: groups-abuse at google.com >> >> Try blocking posts with that in the header. :) > > Better idea: auto-forward any messages with that header, to that > address. Odds are it's accurate :) > Brilliant! vim .procmailrc! Done! :0: * X-Complaints-To: groups-abuse at google.com !groups-abuse at google.com From dotancohen at gmail.com Thu Jul 1 14:34:15 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 1 Jul 2010 21:34:15 +0300 Subject: Ignorance and Google Groups (again) In-Reply-To: <4C2BB1BD.9000306@ixokai.io> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: On 1 July 2010 00:06, Stephen Hansen wrote: > Gmail and Google Groups are not one and the same. There's a number of people > who subscribe to the list directly, use Gmail, and don't go anywhere near > Google Groups. > I'm one of them. Gmail is great for mailing lists, though I would never use it as a personal email client. But I'm more of a lurker than a poster on this list, so D'Arcy won't miss me anyway. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From aahz at pythoncraft.com Thu Jul 1 14:35:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 11:35:21 -0700 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: In article <20100701190033.15ceaeea at geekmail.INVALID>, Andreas Waldenburger wrote: > >Since we're on the subject: I find the best solution for "lots of >typing with a little mousing" to be a keyboard with a pointing stick >(or track point or nav stick or whatever people call it). I'm not quite >sure why they haven't become standard issue on keyboards. Shame, is >what that is. My solution is to simply use the pointing device as little as possible. Keyboards rule! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From python at bdurham.com Thu Jul 1 14:48:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 01 Jul 2010 14:48:47 -0400 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? Message-ID: <1278010127.6605.1382869273@webmail.messagingengine.com> Curious if any of you are using GPG or PGP encryption and/or signatures in your Python apps? In particular are you: 1. clearsigning specific emails? 2. validating clearsigned emails from others? 3. encrypting/decrypting files? 4. generating signatures for files that you are exchanging/posting for download? 5. what public keyring services are you using? I'm also looking for recommendations on which 3rd party modules you're using for these tasks? In particular is there a particular module you prefer or have concerns about? Here's my short list of modules that *might* support encryption and signing in general: - m2crypto - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) - tlslite - pyme - evpy - python-gnupg (by developer of Python's logging module) Any comments on using the subprocess module to wrap the gpg or openssl command line utilities? This seems to be a common technique for encryption and signing solutions and appears to the technique used by python-gnupg (for example). Thank you, Malcolm From anon at blank.com Thu Jul 1 15:13:02 2010 From: anon at blank.com (anon) Date: Thu, 01 Jul 2010 20:13:02 +0100 Subject: escape character / csv module In-Reply-To: References: Message-ID: <6N5Xn.96826$NW.11876@hurricane> V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? This will do what you want: "\\x00" From cs at zip.com.au Thu Jul 1 15:58:07 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 2 Jul 2010 05:58:07 +1000 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: <20100701195807.GA2508@cskk.homeip.net> On 01Jul2010 19:00, Andreas Waldenburger wrote: | On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman | wrote: | > I'll have to give the left-handed mouse a try... hmmm -- not too bad | > so far. | | Since we're on the subject: I find the best solution for "lots of | typing with a little mousing" to be a keyboard with a pointing stick | (or track point or nav stick or whatever people call it). I'm not quite | sure why they haven't become standard issue on keyboards. Shame, is | what that is. I like the pointing stick too ("trackpoint" in IBM land), yea, even to the point of specially buying an IBM trackpoint keyboard several years ago for our computer room. I used to strongly favour ThinkPads for the same reason (they are/were decent in other ways too, but it was the trackpoint that was their killer feature for me). I've been pushed to a MacBook of late (changed jobs and death/tiredness of the thinkpads) and am getting by with the touchpad, whcih works fairly well; I used to always turn touchpads off in the past, so maybe my stance has changed slightly - I used to brush them all the time, and many systems doubled up a transient brush as a mouse click:-( The Mac's click-to-focus model may also be helping me here - my thinkpad desktop would be UNIX X11 in focus-follows-mouse mode, which is far more sensitive to trouble from accidental mouse movement. But yes, the trackpoint _greatly_ reduced my need to move my arms to reach for a mouse. Loved it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ "I'm a lawyer." "Honest?" "No, the usual kind." From python at mrabarnett.plus.com Thu Jul 1 16:04:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jul 2010 21:04:06 +0100 Subject: escape character / csv module In-Reply-To: References: Message-ID: <4C2CF4B6.7060909@mrabarnett.plus.com> V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? It can write "\x01" but not "\x00", and "\x00ABC" doesn't write anything either. The csv module imports from _csv, which suggests to me that there's code written in C which thinks that the "\x00" is a NUL terminator, so it's a bug, although it's very unusual to want to write characters like "\x00" to a CSV file, and I wouldn't be surprised if this is the first time it's been noticed! :-) From luke.leighton at gmail.com Thu Jul 1 16:22:38 2010 From: luke.leighton at gmail.com (lkcl) Date: Thu, 1 Jul 2010 13:22:38 -0700 (PDT) Subject: python ctypes to int main(int argc, char *argv[]) Message-ID: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> hi, i need to convert an application (fontforge) to a python library. yes, libfontforge is already done as is libgdraw (fontforge-pygtk) but i need to make fontforge the _application_ a python application, using the same ctypes trick that's already done. my question is, therefore, how do i specify a ctypes wrapper around the standard int main(int argc, char *argv[]) which i am (obviously) going to move to a (new) c library? many thanks, l. From stefan_ml at behnel.de Thu Jul 1 17:13:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 01 Jul 2010 23:13:34 +0200 Subject: python ctypes to int main(int argc, char *argv[]) In-Reply-To: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> References: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> Message-ID: lkcl, 01.07.2010 22:22: > i need to convert an application (fontforge) to a python library. > yes, libfontforge is already done as is libgdraw (fontforge-pygtk) but > i need to make fontforge the _application_ a python application, using > the same ctypes trick that's already done. > > my question is, therefore, how do i specify a ctypes wrapper around > the standard int main(int argc, char *argv[]) which i am (obviously) > going to move to a (new) c library? Why don't you just start the program as an external subprocess? Stefan From snorble at hotmail.com Thu Jul 1 17:15:36 2010 From: snorble at hotmail.com (snorble) Date: Thu, 1 Jul 2010 14:15:36 -0700 (PDT) Subject: Packaging question Message-ID: <933a4734-eeff-4d99-89d7-3bbdf7094b1f@e5g2000yqn.googlegroups.com> My question is, why do the modules bar and foo show up in mypack's dir()? I intend for Foo (the class foo.Foo) and Bar (the class bar.Bar) to be there, but was not sure about the modules foo and bar. My big picture intention is to create smaller modules, but more of them (like I am used to doing with C++), and then use a package to organize the namespace so I'm not typing out excessively long names and making the code less readable. Is that a reasonable approach to developing Python programs? $ ls mypack/*.py bar.py foo.py __init__.py $ cat mypack/__init__.py from foo import Foo from bar import Bar $ python Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import mypack >>> dir(mypack) ['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'bar', 'foo'] >>> From egbertum at xs4all.nl Thu Jul 1 17:22:45 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 23:22:45 +0200 Subject: List-type attributes and name strings In-Reply-To: <4c2c898e$0$20698$426a34cc@news.free.fr> References: <4c2c898e$0$20698$426a34cc@news.free.fr> Message-ID: <20100701212245.GA18915@xs4all.nl> On Thu, Jul 01, 2010 at 02:28:37PM +0200, Bruno Desthuilliers wrote: > Either I failed to understand you or you overlooked some other > problem in you code and jumped to the wrong conclusions. > In my problem the the name of the list or dict to mutate arrives in namestring, so I could not use the hard coding of attr1 and attr2 like you did. And because of a blind spot for getattr() I modified __dict__. Thanks to you, Chris and Lie it will not happen again, I promise. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From joshua.r.english at gmail.com Thu Jul 1 17:30:54 2010 From: joshua.r.english at gmail.com (Josh English) Date: Thu, 1 Jul 2010 14:30:54 -0700 (PDT) Subject: Namespace problem? Message-ID: I have a script that generates a report from a bunch of data I've been collecting for the past year. I ran the script, successfully, for several weeks on test runs and creating more detailed reports. Today (back from vacation) and the script doesn't work. It's giving me a name error. I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. Eventually we'll be upgraded top Windows 7.) Here is the reduced code: fws_first_col = 6 for student in range(32): if True: idx = fws_first_col for _month in range(12): idx += 2 fws_last_col = idx print fws_last_col I get: NameError: name 'fws_last_col' is not defined This snippet of code works on it's own, but not in the main script. I know it looks funny, but this should preserve the appropriate nesting of things. Where else could I look to find this problem? From mithrandiragainwiki at mailinator.com Thu Jul 1 17:36:57 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 21:36:57 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <20100630165550.2b57855f.darcy@druid.net> Message-ID: Thomas Jollans wrote in news:mailman.55.1277936519.1673.python-list at python.org: > On 06/30/2010 10:55 PM, D'Arcy J.M. Cain wrote: >> in all it's glory. >> >> :0: Hir >> * ^List-Id:.*python-list.python.org >> * ^From:.*@gmail.com >> * ^Newsgroups: >> /dev/null > > * X-Complaints-To: groups-abuse at google.com > > looks like a nice header to filter on > Oops. Didn't see that you had already posted that idea. I'm sorry. :) But anyway, I had another idea (which hasn't already been mentioned.) ;) Since there are a good deal of "gems" in Google groups, and not all of them are spam artists, how about a whitelist/blacklist in the program? That way some posts from "good" people come through from G-Groups, and others (the "bad" ones) don't. Plus, the ones that you do blacklist would auto-generate a message to groups-abuse at google.com. That'll show 'em. :D Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From mccredie at gmail.com Thu Jul 1 17:50:10 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 1 Jul 2010 21:50:10 +0000 (UTC) Subject: Namespace problem? References: Message-ID: Josh English gmail.com> writes: > > I have a script that generates a report from a bunch of data I've been > collecting for the past year. I ran the script, successfully, for > several weeks on test runs and creating more detailed reports. > > Today (back from vacation) and the script doesn't work. It's giving me > a name error. > > I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. > 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. > Eventually we'll be upgraded top Windows 7.) > > Here is the reduced code: > > fws_first_col = 6 > > for student in range(32): > > if True: > idx = fws_first_col > > for _month in range(12): > idx += 2 > fws_last_col = idx > > print fws_last_col > > I get: > > NameError: name 'fws_last_col' is not defined > > This snippet of code works on it's own, but not in the main script. That doesn't give me enough information to help you with the issue. In general you need to provide enough code to reproduce the failure, not some modified version that doesn't fail. My guess is that the "if True" is actually something else, and it isn't being interpreted as "True". As such, "fws_last_col" never gets assigned, and thus never gets created. You can fix that by assigning fws_last_col to an appropriate default value before the for loop. But what do I know, that is just a guess. Matt From jaykoni at yahoo.com Thu Jul 1 17:52:49 2010 From: jaykoni at yahoo.com (Jay) Date: Thu, 1 Jul 2010 14:52:49 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> Message-ID: <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> pywinauto looks to be almost perfect. All I need now is to read the numbers uncovered when a minesweeper square is clicked on, or that I just hit a mine. On Jun 30, 6:51?pm, Paul McGuire wrote: > On Jun 30, 6:39?pm, Jay wrote: > > > I would like to create a python script that plays the Windows game > > minesweeper. > > > The python code logic and running minesweeper are not problems. > > However, "seeing" the 1-8 in the minesweeper map and clicking on > > squares is. I have no idea how to proceed. > > You can interact with a Windows application using pywinauto (http:// > pywinauto.openqa.org/). > > Sounds like a fun little project - good luck! > > -- Paul From Paul Thu Jul 1 18:00:03 2010 From: Paul (Paul) Date: Thu, 01 Jul 2010 15:00:03 -0700 Subject: Python/C++ timer intermittent bug References: Message-ID: Thanks, Thomas. The answer to most of your questions is that I'm very new at this! I'm asking this on the forums you suggested. - Paul On Thu, 01 Jul 2010 19:23:53 +0200, Thomas Jollans wrote: >On 06/30/2010 09:28 PM, Paul at mail.python.org wrote: >> I have a problem with threading using the Python/C API. I have an >> extension that implements a timer, and the C++ timer callback function >> calls a Python function. The relevant code looks like this: >> >> [snip] >> >> static void CALLBACK PeriodicTimer(UINT wTimerID, UINT msg, >> DWORD dwUser, DWORD dw1, DWORD dw2) > >This looks frightfully WIN32. How are you calling a timer? I'm guessing >you're using some win32 function. So my tentative tip on where the >problem might lie is the interaction of Python's PyThreads and the win32 >threading primitives you're probably calling. > >> { >> PyGILState_STATE pgs; >> >> pgs = PyGILState_Ensure(); >> if(attrsetFlag) >> { >> pres = PyObject_CallFunction(attr,NULL); >> if( pres == NULL )printf("CallFunction failed!\n"); >> } >> PyGILState_Release( pgs ); >> >> } >> >> The Python code that sets this up looks like this: >> >> fetimer.setmodname("Timeslice3") >> fetimer.setprocname("Timetester") > >I'm sure this isn't the problem, but why aren't you just passing in an >object? As in fetimer.setcallable(Timeslice3.Timetester)? > >> [ snip ] >> >> Fatal Python Error: This thread state must be current when releasing >> >> Fatal Python Error: PyThreadState_DeleteCurrent: no current tstate >> >> Fatal Python Error: PyEval_SaveThread: NULL tstate > >As I said, I'd expect there to be some irregularities between what >PyThreads would normally do and what you're doing in the code you didn't >post. > >> >> Can anybody help me make this code stable, so that it works all the >> time? > >I can't really help you - I have limited experience with the C API, let >alone Python/C threading, and know next to nothing about Windows >programming. Maybe you should ask in a more specialized (and quieter) >forum, such as the CAPI-SIG mailing list, or python-win32. > >-- Thomas From aahz at pythoncraft.com Thu Jul 1 18:02:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 15:02:30 -0700 Subject: Python v3.1.2 documentation question References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> Message-ID: In article , Ethan Furman wrote: >Stephen Hansen wrote: >> On 6/29/10 10:01 AM, Ethan Furman wrote: >>> In the glossary section it states: >>> >>> >>> nested scope >>> >>> The ability to refer to a variable in an enclosing definition. For >>> instance, a function defined inside another function can refer to >>> variables in the outer function. Note that nested scopes work only for >>> reference and not for assignment which will always write to the >>> innermost scope. In contrast, local variables both read and write in the >>> innermost scope. Likewise, global variables read and write to the global >>> namespace. >>> >>> >>> Doesn't the nonlocal keyword make variables in outer scopes writable? >> >> Yes. I'd submit a doc bug. > >Bug submitted. For the benefit of people following along at home, it's nice to provide the URL to the ticket. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From lists at cheimes.de Thu Jul 1 18:05:33 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 02 Jul 2010 00:05:33 +0200 Subject: python ctypes to int main(int argc, char *argv[]) In-Reply-To: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> References: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> Message-ID: > my question is, therefore, how do i specify a ctypes wrapper around > the standard int main(int argc, char *argv[]) which i am (obviously) > going to move to a (new) c library? Maybe I missing something here but libraries don't have a main() function. The main() function is the entry point of a program. Libraries have different means for initialization. Christian From joshua.r.english at gmail.com Thu Jul 1 18:07:53 2010 From: joshua.r.english at gmail.com (Josh English) Date: Thu, 1 Jul 2010 15:07:53 -0700 (PDT) Subject: Namespace problem? References: Message-ID: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> On Jul 1, 2:50?pm, Matt McCredie wrote: > > That doesn't give me enough information to help you with the issue. In general > you need to provide enough code to reproduce the failure, not some modified > version that doesn't fail. My guess is that the "if True" is actually something > else, and it isn't being interpreted as "True". As such, "fws_last_col" never > gets assigned, and thus never gets created. You can fix that by assigning > fws_last_col to an appropriate default value before the for loop. But what do I > know, that is just a guess. > > Matt This is the code snippet with more context, but it isn't runnable without creating a bunch of dummy objects: # data is a dictionary. The keys are student names, the values are Tracker object. # The tracker class defines the method hasFWS() which returns a boolean. # _monthnumbers is a list: [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6] I just cut out the code that doesn't have anything to do the variable fws_last_col fws_first_col = 6 for student in sorted(data.keys() ): #~ print student tracker = data[student] if tracker.hasFWS(): idx = fws_first_col for _month in iter(_monthnumbers): idx += 2 fws_last_col = idx fws_month_count_col = idx + 4 fwsrow += 1 print fws_last_col From gabriele.lanaro at gmail.com Thu Jul 1 18:09:59 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Fri, 2 Jul 2010 00:09:59 +0200 Subject: [ANN]: Emacs For Python 0.1, collection of emacs extensions for python development Message-ID: Emacs For Python 0.1 Emacs for python (epy) is a collection of emacs extensions for python development, yet ready and configured for you. It includes also tweaks to commonly used extension to provide extra functionality and fast bug correction. There are also sane configuration that helps you getting started pretty fast. Some of the most important extensions configured and included in the distribution are: - ido prompts - autocompletion + rope (if you have pymacs) - snippets, simplified and standard-compliant - automatic error/warning/info highlighting with flymake (powered by pyflakes) - custom keybindings - much more (really) I remaind you for further information to the home page: http://gabrielelanaro.github.com/emacs-for-python/ You'll find additional information on the github page (readme and wiki): http://github.com/gabrielelanaro/emacs-for-python Thank you for the attention! - Gabriele -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Jul 1 18:25:54 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 01 Jul 2010 23:25:54 +0100 Subject: Namespace problem? In-Reply-To: References: Message-ID: On 01/07/2010 22:30, Josh English wrote: > I have a script that generates a report from a bunch of data I've been > collecting for the past year. I ran the script, successfully, for > several weeks on test runs and creating more detailed reports. > > Today (back from vacation) and the script doesn't work. It's giving me > a name error. > > I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. > 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. > Eventually we'll be upgraded top Windows 7.) > > Here is the reduced code: > > fws_first_col = 6 So fws_first_col is set to 6. > > for student in range(32): student isn't used in the snippet below. > > if True: Isn't this always going to run? > idx = fws_first_col Effectively set idx to 6 each time around the for loop. > > for _month in range(12): > idx += 2 Add 24 to idx each time around the for loop. 24 + 6 == 30. > fws_last_col = idx set fws_last_col to 30 each time around the for loop. > > > print fws_last_col prints 30 only once. > > I get: > > NameError: name 'fws_last_col' is not defined > > This snippet of code works on it's own, but not in the main script. I > know it looks funny, but this should preserve the appropriate nesting > of things. Certainly doesn't look at all correct to me. > > Where else could I look to find this problem? In a mirror? :) Kindest regards. Mark Lawrence. From rhodri at wildebst.demon.co.uk Thu Jul 1 18:30:33 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 01 Jul 2010 23:30:33 +0100 Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: On Thu, 01 Jul 2010 23:07:53 +0100, Josh English wrote: > On Jul 1, 2:50 pm, Matt McCredie wrote: >> >> My guess is that the "if True" is actually something >> else, and it isn't being interpreted as "True". As such, "fws_last_col" >> never >> gets assigned, and thus never gets created. You can fix that by >> assigning >> fws_last_col to an appropriate default value before the for loop. > [snip] > fws_first_col = 6 > > for student in sorted(data.keys() ): > #~ print student > > tracker = data[student] > > if tracker.hasFWS(): > > idx = fws_first_col > > > for _month in iter(_monthnumbers): > idx += 2 > fws_last_col = idx > > fws_month_count_col = idx + 4 > fwsrow += 1 > > print fws_last_col [I snipped the explanations for brevity] If this is a version of your code that actually fails when you run it (rather than being another artistic interpretation of a photograph of your code :-), then I'd go with Matt's analysis. This will give you a NameError for fws_last_col if tracker.hasFWS() happens to return False for all students. -- Rhodri James *-* Wildebeeste Herder to the Masses From emile at fenx.com Thu Jul 1 18:42:49 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 15:42:49 -0700 Subject: automate minesweeper with python In-Reply-To: <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 2:52 PM Jay said... > pywinauto looks to be almost perfect. All I need now is to read the > numbers uncovered when a minesweeper square is clicked on, or that I > just hit a mine. > ... or, you could always win... http://www.daniweb.com/forums/thread186209.html Emile PS -- in about '77 I worked with a guy that had XYZZY as his personalized license plate... From ethan at stoneleaf.us Thu Jul 1 18:42:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 01 Jul 2010 15:42:54 -0700 Subject: Python v3.1.2 documentation question In-Reply-To: References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> Message-ID: <4C2D19EE.6060602@stoneleaf.us> Aahz wrote: > In article , > Ethan Furman wrote: >> Stephen Hansen wrote: >>> On 6/29/10 10:01 AM, Ethan Furman wrote: >>>> In the glossary section it states: >>>> >>>> >>>> nested scope >>>> >>>> The ability to refer to a variable in an enclosing definition. For >>>> instance, a function defined inside another function can refer to >>>> variables in the outer function. Note that nested scopes work only for >>>> reference and not for assignment which will always write to the >>>> innermost scope. In contrast, local variables both read and write in the >>>> innermost scope. Likewise, global variables read and write to the global >>>> namespace. >>>> >>>> >>>> Doesn't the nonlocal keyword make variables in outer scopes writable? >>> Yes. I'd submit a doc bug. >> Bug submitted. > > For the benefit of people following along at home, it's nice to provide > the URL to the ticket. Hmmm.... Well, as this is my first ever bug post (yay! ;) I *think* this is what you want: http://bugs.python.org/issue9121 ~Ethan~ From clp2 at rebertia.com Thu Jul 1 19:07:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 16:07:07 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On Thu, Jul 1, 2010 at 10:00 AM, Andreas Waldenburger wrote: > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > wrote: > >> I'll have to give the left-handed mouse a try... hmmm -- not too bad >> so far. > > Since we're on the subject: I find the best solution for "lots of > typing with a little mousing" to be a keyboard with a pointing stick > (or track point or nav stick or whatever people call it). The appropriate term varies: http://xkcd.com/243/ Cheers, Chris -- http://blog.rebertia.com From ppearson at nowhere.invalid Thu Jul 1 19:12:29 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Jul 2010 23:12:29 GMT Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: <894lmtFeqU1@mid.individual.net> On Thu, 01 Jul 2010 23:30:33 +0100, Rhodri James wrote: > On Thu, 01 Jul 2010 23:07:53 +0100, Josh English > wrote: > >> On Jul 1, 2:50 pm, Matt McCredie wrote: >>> >>> My guess is that the "if True" is actually something >>> else, and it isn't being interpreted as "True". As such, "fws_last_col" >>> never >>> gets assigned, and thus never gets created. You can fix that by >>> assigning >>> fws_last_col to an appropriate default value before the for loop. >> > [snip] >> fws_first_col = 6 >> >> for student in sorted(data.keys() ): >> #~ print student >> >> tracker = data[student] >> >> if tracker.hasFWS(): >> >> idx = fws_first_col >> >> >> for _month in iter(_monthnumbers): >> idx += 2 >> fws_last_col = idx >> >> fws_month_count_col = idx + 4 >> fwsrow += 1 >> >> print fws_last_col > [suggests that hasFWS() is always False] Another possibility is that data.keys() is empty. -- To email me, substitute nowhere->spamcop, invalid->net. From ldo at geek-central.gen.new_zealand Thu Jul 1 19:47:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 02 Jul 2010 11:47 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Michael Torrie wrote: > On 06/29/2010 06:26 PM, Lawrence D'Oliveiro wrote: >>> I'm not sure you understood me correctly, because I advocate >>> *not* doing input sanitization. Hard or not -- I don't want to know, >>> because I don't want to do it. >> >> But no-one has yet managed to come up with an alternative that involves >> less work. > > Your case is still not persuasive. So persuade me. I have given an example of code written the way I do it. Now let?s see you rewrite it using your preferred technique, just to prove that your way is simpler and easier to understand. Enough hand-waving, let?s see some code! From ldo at geek-central.gen.new_zealand Thu Jul 1 19:50:59 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 02 Jul 2010 11:50:59 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: In message <4c2ccd9c$0$1643$742ec2ed at news.sonic.net>, John Nagle wrote: > The approach to arrays in C is just broken, for historical reasons. Nevertheless, it it at least self-consistent. To return to my original macro: #define Descr(v) &v, sizeof v As written, this works whatever the type of v: array, struct, whatever. > So parameter passing in C is very dumb. Nothing to do with the above issue. From aahz at pythoncraft.com Thu Jul 1 20:00:53 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 17:00:53 -0700 Subject: Python v3.1.2 documentation question References: <4C2A26D5.8090507@stoneleaf.us> Message-ID: In article , Ethan Furman wrote: >Aahz wrote: >> In article , >> Ethan Furman wrote: >>> Stephen Hansen wrote: >>>> On 6/29/10 10:01 AM, Ethan Furman wrote: >>>>> In the glossary section it states: >>>>> >>>>> >>>>> nested scope >>>>> >>>>> The ability to refer to a variable in an enclosing definition. For >>>>> instance, a function defined inside another function can refer to >>>>> variables in the outer function. Note that nested scopes work only for >>>>> reference and not for assignment which will always write to the >>>>> innermost scope. In contrast, local variables both read and write in the >>>>> innermost scope. Likewise, global variables read and write to the global >>>>> namespace. >>>>> >>>>> >>>>> Doesn't the nonlocal keyword make variables in outer scopes writable? >>>> Yes. I'd submit a doc bug. >>> Bug submitted. >> >> For the benefit of people following along at home, it's nice to provide >> the URL to the ticket. > >Hmmm.... Well, as this is my first ever bug post (yay! ;) I *think* >this is what you want: > >http://bugs.python.org/issue9121 Congrats! And it's already marked closed! ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From andre.roberge at gmail.com Thu Jul 1 20:20:29 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 1 Jul 2010 17:20:29 -0700 (PDT) Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: On Jul 1, 1:39?pm, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > Assuming it is the same behavior as for Komodo IDE, if you set it up so that linenumbers are shown, then you get a much larger target to click and select the line. Andr? > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 1 21:10:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 01:10:47 GMT Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 23:46:55 +0800, WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. There's nothing magic about metaprogramming. If you're a programmer, you write programs. Some of those programs will be programs about text ("programming"), programs about numbers ("programming"), programs about databases ("programming"), programs about staff performance data ("programming"), and programs about programs ("metaprogramming"). But it's still just programming, and there's nothing magical about it. Languages that try to frighten you away from metaprogramming are doing you a disservice. That's like teaching an electrical engineer how to make all sorts of devices, but not how to make voltmeters or ammeters because they're "meta-electronics". I'm pretty sure that IT is the only discipline that cares about this distinction between "normal work" and "meta work". Engineers are quite happy to make the tools they need to make the tools they need to make the tools they need to make something. Carpenters would think you were crazy if you said that building a scaffold was "meta-carpentry" and therefore "magic" and something to be avoided. There's even a children's song about the sort of loops you can get into when you need a tool X to fix some item Y, but you need Y in order to fix the tool first: http://www.songsforteaching.com/folk/theresaholeinthebucket.htm It's only in IT that "meta work" is considered "special", and that (I think) is because of the influence of academia. Don't get me wrong, I'm a big fan of academia, but I think sometimes they need a good dose of reality. Back before IT was a discipline, people used to write self-modifying code and programs to generate programs and other metaprogramming all the time, and nobody thought twice about it. Now admittedly, *some* metaprogramming techniques (like self-modifying code) make debugging much, much harder, and therefore should be avoided *for that reason*, but that's nothing to do with metaprogramming. If you write code with variables like: a1649264273528924 = a1649269279528924 + a1645976427328924 that's just "programming" but it's damn near impossible to efficiently debug too. -- Steven From tjreedy at udel.edu Thu Jul 1 21:17:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 21:17:27 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 6:42 PM, Emile van Sebille wrote: > On 7/1/2010 2:52 PM Jay said... >> pywinauto looks to be almost perfect. All I need now is to read the >> numbers uncovered when a minesweeper square is clicked on, or that I >> just hit a mine. >> > > ... or, you could always win... > > http://www.daniweb.com/forums/thread186209.html Did you actually try it? Though skeptical, I did, briefly, until I decided that it probably should have been dated April 1. There is no way to enter text into minesweeper, nor to make it full screen, nor, as far as I know, for it to toggle pixels outside its window. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jul 1 21:18:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 21:18:49 -0400 Subject: Composition of functions In-Reply-To: <4C2C49C0.5020900@ixokai.io> References: <4C2C49C0.5020900@ixokai.io> Message-ID: On 7/1/2010 3:54 AM, Stephen Hansen wrote: > On 7/1/10 12:45 AM, Terry Reedy wrote: >> On 7/1/2010 12:32 AM, Mladen Gogala wrote: >>> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: >> >>>> However, you can easily get what you want by using the 'reversed' >>>> function (and similarly, the 'sorted' function), a la: >>>> >>>> >>> y = ''.join(reversed(list(x))) >>>> >>>> The 'reversed' and 'sorted' functions are generators that lazilly >>>> convert an iterable as needed. >>> >>> Ah, that is even better. Thanks. >> >> It is better if you do not mind making an unnecessary copy. If the list >> had 10 million elements, you might prefer your original. > > The original that did not work? :) The revised original that did work with sequential statements. -- Terry Jan Reedy From clp2 at rebertia.com Thu Jul 1 22:02:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 19:02:37 -0700 Subject: Python dynamic attribute creation In-Reply-To: <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 6:10 PM, Steven D'Aprano wrote: > Engineers are quite > happy to make the tools they need to make the tools they need to make the > tools they need to make something. Carpenters would think you were crazy > if you said that building a scaffold was "meta-carpentry" and therefore > "magic" and something to be avoided. +1 QOTW Cheers, Chris From tjreedy at udel.edu Thu Jul 1 22:07:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 22:07:59 -0400 Subject: Python v3.1.2 documentation question In-Reply-To: <4C2D19EE.6060602@stoneleaf.us> References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> <4C2D19EE.6060602@stoneleaf.us> Message-ID: On 7/1/2010 6:42 PM, Ethan Furman wrote: > Hmmm.... Well, as this is my first ever bug post (yay! ;) Great! > I *think* this is what you want: > > http://bugs.python.org/issue9121 I believe Benjamin meant that it was already fixed in http://docs.python.org/dev/py3k/ which is currently the 3.2a0 docs. Good to check there before reporting a doc bug. Terry Jan Reedy From darcy at druid.net Thu Jul 1 22:10:08 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 1 Jul 2010 22:10:08 -0400 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: <20100701221008.d673a9d8.darcy@druid.net> On Thu, 1 Jul 2010 21:34:15 +0300 Dotan Cohen wrote: > I'm one of them. Gmail is great for mailing lists, though I would > never use it as a personal email client. But I'm more of a lurker than > a poster on this list, so D'Arcy won't miss me anyway. As the song says. "How can I miss you if you won't go away." :-) As I explained, I don't block just because you are on gmail.com. I only block if you use Google Groups to post via news. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From emile at fenx.com Thu Jul 1 22:18:08 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 19:18:08 -0700 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 6:17 PM Terry Reedy said... > On 7/1/2010 6:42 PM, Emile van Sebille wrote: >> On 7/1/2010 2:52 PM Jay said... >>> pywinauto looks to be almost perfect. All I need now is to read the >>> numbers uncovered when a minesweeper square is clicked on, or that I >>> just hit a mine. >>> >> >> ... or, you could always win... >> >> http://www.daniweb.com/forums/thread186209.html > > Did you actually try it? Though skeptical, I did, briefly, until I > decided that it probably should have been dated April 1. There is no way > to enter text into minesweeper, nor to make it full screen, nor, as far > as I know, for it to toggle pixels outside its window. > Yes. It works. Emile From rami.chowdhury at gmail.com Thu Jul 1 23:17:55 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 1 Jul 2010 20:17:55 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: <201007012017.56063.rami.chowdhury@gmail.com> On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > Nevertheless, it it at least self-consistent. To return to my original > macro: > > #define Descr(v) &v, sizeof v > > As written, this works whatever the type of v: array, struct, whatever. > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly modified... [rami at tigris ~]$ cat example.c #include #define Descr(v) &v, sizeof v int main(int argc, char ** argv) { char *buf = malloc(512 * sizeof(char)); const int a = 2, b = 3; snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b); fprintf(stdout, buf); free(buf); return 0; } /*main*/ [rami at tigris ~]$ clang example.c example.c:11:18: warning: incompatible pointer types passing 'char **', expected 'char *' [-pedantic] snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b); ^~~~~~~~~~ example.c:4:18: note: instantiated from: #define Descr(v) &v, sizeof v ^~~~~~~~~~~~ <> [rami at tigris ~]$ ./a.out Segmentation fault ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 00:11:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 04:11:49 GMT Subject: Why defaultdict? Message-ID: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> I would like to better understand some of the design choices made in collections.defaultdict. Firstly, to initialise a defaultdict, you do this: from collections import defaultdict d = defaultdict(callable, *args) which sets an attribute of d "default_factory" which is called on key lookups when the key is missing. If callable is None, defaultdicts are *exactly* equivalent to built-in dicts, so I wonder why the API wasn't added on to dict rather than a separate class that needed to be imported. That is: d = dict(*args) d.default_factory = callable If you failed to explicitly set the dict's default_factory, it would behave precisely as dicts do now. So why create a new class that needs to be imported, rather than just add the functionality to dict? Is it just an aesthetic choice to support passing the factory function as the first argument? I would think that the advantage of having it built- in would far outweigh the cost of an explicit attribute assignment. Second, why is the factory function not called with key? There are three obvious kinds of "default values" a dict might want, in order of more-to- less general: (1) The default value depends on the key in some way: return factory(key) (2) The default value doesn't depend on the key: return factory() (3) The default value is a constant: return C defaultdict supports (2) and (3): defaultdict(factory, *args) defaultdict(lambda: C, *args) but it doesn't support (1). If key were passed to the factory function, it would be easy to support all three use-cases, at the cost of a slightly more complex factory function. E.g. the current idiom: defaultdict(factory, *args) would become: defaultdict(lambda key: factory(), *args) (There is a zeroth case as well, where the default value depends on the key and what else is in the dict: factory(d, key). But I suspect that's well and truly YAGNI territory.) Thanks in advance, -- Steven From jdoe at usenetlove.invalid Fri Jul 2 00:34:12 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 02 Jul 2010 04:34:12 GMT Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <4c2d6c43$0$17900$c3e8da3@news.astraweb.com> Andr? wrote: > ... set it up so that linenumbers are shown, then you get a much > larger target to click and select the line. Yes... And it allows clicking and dragging the number area to select multiple lines. Thanks. From clp2 at rebertia.com Fri Jul 2 00:37:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 21:37:31 -0700 Subject: Why defaultdict? In-Reply-To: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 9:11 PM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. Perhaps python-dev should've been CC-ed... > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = defaultdict(callable, *args) > > which sets an attribute of d "default_factory" which is called on key > lookups when the key is missing. If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. > That is: > > d = dict(*args) > d.default_factory = callable > > If you failed to explicitly set the dict's default_factory, it would > behave precisely as dicts do now. So why create a new class that needs to > be imported, rather than just add the functionality to dict? Don't know personally, but here's one thought: If it was done that way, passing around a dict could result in it getting a default_factory set where there wasn't one before, which could lead to strange results if you weren't anticipating that. The defaultdict solution avoids this. > Second, why is the factory function not called with key? Agree, I've never understood this. Ruby's Hash::new does it better (http://ruby-doc.org/core/classes/Hash.html), and even supports your case 0; it calls the equivalent of default_factory(d, key) when generating a default value. > There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C > > defaultdict supports (2) and (3): > > defaultdict(factory, *args) > defaultdict(lambda: C, *args) > > but it doesn't support (1). If key were passed to the factory function, > it would be easy to support all three use-cases, at the cost of a > slightly more complex factory function. > (There is a zeroth case as well, where the default value depends on the > key and what else is in the dict: factory(d, key). But I suspect that's > well and truly YAGNI territory.) Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Fri Jul 2 00:50:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 21:50:49 -0700 Subject: Is there a reference manual for "pyparsing"? Message-ID: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Is there a reference manual for "pyparsing"? Not a tutorial. Not a wiki. Not a set of examples. Not a "getting started guide". Something that actually documents what each primitive does? John Nagle From clp2 at rebertia.com Fri Jul 2 01:02:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 22:02:35 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: <4c2d7037$0$1600$742ec2ed@news.sonic.net> References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 1, 2010 at 9:50 PM, John Nagle wrote: > ?Is there a reference manual for "pyparsing"? ?Not a tutorial. ?Not a wiki. > Not a set of examples. ?Not a "getting started guide". > Something that actually documents what each primitive does? http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 ? Cheers, Chris -- http://blog.rebertia.com From raymond.hettinger at gmail.com Fri Jul 2 01:06:42 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Thu, 1 Jul 2010 22:06:42 -0700 (PDT) Subject: Why defaultdict? References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <2f533b05-aa00-40c3-9be3-8a14434e2f74@m17g2000prl.googlegroups.com> On Jul 1, 9:11?pm, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. . . . > If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. . . . > Second, why is the factory function not called with key? There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C The __missing__() magic method lets you provide a factory with a key. That method is supported by dict subclasses, making it easy to create almost any desired behavior. A defaultdict is an example. It is a dict subclass that calls a zero argument factory function. But with __missing__() can roll your own dict subclass to meet your other needs. A defaultdict was provided to meet one commonly requested set of use cases (mostly ones using int() and list() as factory functions). >From the docs at http://docs.python.org/library/stdtypes.html#mapping-types-dict : '''New in version 2.5: If a subclass of dict defines a method __missing__(), if the key key is not present, the d[key] operation calls that method with the key key as argument. The d[key] operation then returns or raises whatever is returned or raised by the __missing__(key) call if the key is not present. No other operations or methods invoke __missing__(). If __missing__() is not defined, KeyError is raised. __missing__() must be a method; it cannot be an instance variable. For an example, see collections.defaultdict.''' Raymond From nagle at animats.com Fri Jul 2 01:08:18 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 22:08:18 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c2d7450$0$1665$742ec2ed@news.sonic.net> On 7/1/2010 10:02 PM, Chris Rebert wrote: > On Thu, Jul 1, 2010 at 9:50 PM, John Nagle wrote: >> Is there a reference manual for "pyparsing"? Not a tutorial. Not a wiki. >> Not a set of examples. Not a "getting started guide". >> Something that actually documents what each primitive does? > > http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 > ? > That's a big help. Thanks. Perhaps the page "http://pyparsing.wikispaces.com/Documentation" should mention that. Because it's in Subversion, Google can't find that page. (robots.txt: User-agent: * Disallow: /) John Nagle From clp2 at rebertia.com Fri Jul 2 01:17:15 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 22:17:15 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: <4c2d7450$0$1665$742ec2ed@news.sonic.net> References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> <4c2d7450$0$1665$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 1, 2010 at 10:08 PM, John Nagle wrote: > On 7/1/2010 10:02 PM, Chris Rebert wrote: >> On Thu, Jul 1, 2010 at 9:50 PM, John Nagle ?wrote: >>> ?Is there a reference manual for "pyparsing"? ?Not a tutorial. ?Not a >>> wiki. >>> Not a set of examples. ?Not a "getting started guide". >>> Something that actually documents what each primitive does? >> >> http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 >> ? >> > > ? ?That's a big help. ?Thanks. > > ? ?Perhaps the page "http://pyparsing.wikispaces.com/Documentation" > should mention that. Well, it does, indirectly: "Pyparsing ships with class diagrams and html documentation." But yeah, hyperlinks are always good. Cheers, Chris -- http://blog.rebertia.com From stephen.mc at gmail.com Fri Jul 2 01:45:09 2010 From: stephen.mc at gmail.com (Steve) Date: Thu, 1 Jul 2010 22:45:09 -0700 (PDT) Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? References: Message-ID: <2ef9965e-d6cd-4fe8-8155-45488124ff58@l25g2000prn.googlegroups.com> On Jul 2, 4:48?am, pyt... at bdurham.com wrote: > Curious if any of you are using GPG or PGP encryption and/or signatures > in your Python apps? > > In particular are you: > > 1. clearsigning specific emails? > 2. validating clearsigned emails from others? > 3. encrypting/decrypting files? > 4. generating signatures for files that you are exchanging/posting for > download? > 5. what public keyring services are you using? > > I'm also looking for recommendations on which 3rd party modules you're > using for these tasks? In particular is there a particular module you > prefer or have concerns about? > > Here's my short list of modules that *might* support encryption and > signing in general: > > - m2crypto > - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) > - tlslite > - pyme > - evpy > - python-gnupg (by developer of Python's logging module) > > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). > > Thank you, > Malcolm I used python-gnupg successfully to create some Django utilities for sending encrypted email. You can grab the source code at http://github.com/stephenmcd/django-email-extras Cheers, Steve From ian.g.kelly at gmail.com Fri Jul 2 02:09:53 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 2 Jul 2010 00:09:53 -0600 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On Thu, Jul 1, 2010 at 7:17 PM, Terry Reedy wrote: > Did you actually try it? Though skeptical, I did, briefly, until I decided > that it probably should have been dated April 1. There is no way to enter > text into minesweeper, nor to make it full screen, nor, as far as I know, > for it to toggle pixels outside its window. Your objections are invalid. The fact that Minesweeper does not have a text control does not mean that it cannot receive keypresses, and the exterior pixel could hypothetically be implemented as a 1-pixel borderless window belonging to the Minesweeper application. There are enough details from enough different persons on the web, with few if any dissenting opinions, that I'm inclined to believe it probably works. I can't test it myself, though, because it apparently no longer works in Windows Vista or 7, and I no longer have an XP box around. From dave.pawson at gmail.com Fri Jul 2 02:26:44 2010 From: dave.pawson at gmail.com (Dave Pawson) Date: Fri, 2 Jul 2010 07:26:44 +0100 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: Message-ID: I'm the OP btw. On 1 July 2010 18:10, Dennis Lee Bieber wrote: >> I think that Python "could" be a alternative to bash and have some >> advantages, but it's a long way off from being fully implemented. > > ? ? ? ?While a somewhat klutzier language in aspects (the , is both an > parameter separator, AND the continued line indicator, leading to lines > that end in , ,) I'd consider a decent* REXX implementation first... > ? ? ? ?Any program line that is not recognized as starting a REXX statement > is automatically passed to the currently defined command processor. And > one could ensure this by just quoting the first word on the line Useful. However, I know Python, never looked at Rexx, so not much use to me. Tks -- Dave Pawson XSLT XSL-FO FAQ. Docbook FAQ. http://www.dpawson.co.uk From marky1991 at gmail.com Fri Jul 2 03:32:56 2010 From: marky1991 at gmail.com (Mark Young) Date: Fri, 2 Jul 2010 03:32:56 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: Just tested it in XP, it works. -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Fri Jul 2 03:39:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 2 Jul 2010 00:39:12 -0700 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: <1278010127.6605.1382869273@webmail.messagingengine.com> References: <1278010127.6605.1382869273@webmail.messagingengine.com> Message-ID: On Thu, Jul 1, 2010 at 11:48 AM, wrote: > Curious if any of you are using GPG or PGP encryption and/or signatures > in your Python apps? Yes; disclaimer: I'm the author of evpy and am currently working on a openssl wrapper proposed for inclusion in the stdlib. > In particular are you: > > 1. clearsigning specific emails? Yes; I use python-gnupg. > 2. validating clearsigned emails from others? Yes, see above. > 3. encrypting/decrypting files? Yes, I use evpy. > 4. generating signatures for files that you are exchanging/posting for > download? Yes, evpy again. > 5. what public keyring services are you using? Can't comment on this as I don't use them. > I'm also looking for recommendations on which 3rd party modules you're > using for these tasks? In particular is there a particular module you > prefer or have concerns about? Obviously I'm biased towards evpy, but I'm a really, really big fan of people not rolling their own crypto. It sounds like for most of what you want to do gpg or python-gnupg are pretty good options. > Here's my short list of modules that *might* support encryption and > signing in general: > > - m2crypto Supports encryption and signing; a high quality library with much to recommend it, assuming you need the full power of openssl and are able to use SWIG'd software. I think you probably have easier to use alternatives here, though. > - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) pycrypto is a good library as far as it goes, but I see a lot of nonexperts do things very badly with it, and AFAICS it hasn't seen the same level of scrutiny that something like openssl has, especially WRT side channel cryptanalysis. That's very worrying. > - tlslite > - pyme no experience here, can't comment. > - evpy I like it ;). It supports encryption (public and private key) as well as signing and verification routines, and as long as you know your threat model it's reasonably hard to screw up. Having said that, it doesn't do anything with the web of trust or key revocation etc OOTB, so if what you're really looking for is gpg in python, use the right tool for the job. > - python-gnupg (by developer of Python's logging module) I use it and like it for the reasons above. > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). Seems fine, just make sure you know and trust where your keys are going. Geremy Condra From mail at timgolden.me.uk Fri Jul 2 03:46:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 02 Jul 2010 08:46:36 +0100 Subject: Bento 0.0.3 (ex-toydist), a pythonic packaging solution In-Reply-To: <4C2D5135.5010909@silveregg.co.jp> References: <4C2D5135.5010909@silveregg.co.jp> Message-ID: <4C2D995C.40209@timgolden.me.uk> On 02/07/2010 03:38, David wrote: > I am pleased to announce the release 0.0.3 for Bento, the pythonic > packaging solution. > > Bento aims at being an alternative to distutils/setuptools/distribute, > based on a static metadata file format. Existing packages can be > converted from setup.py to bento format automatically. > > http://cournape.github.com/Bento/ Looks very interesting. Just one thing (which might just be me): the front page looks very stylish and is quite a nice summary. But I actually *missed* the (grey on grey) [Take me to Bento documentation] button, which is way below the fold on my screen. Rather, I hit the more evident Github flag at the top and started looking for docs there! Just in case it helps anyone else... TJG From one50123164ef19 at getonemail.com Fri Jul 2 04:06:21 2010 From: one50123164ef19 at getonemail.com (Maciej) Date: Fri, 2 Jul 2010 01:06:21 -0700 (PDT) Subject: GAE + recursion limit Message-ID: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Hi, I'm writing a small translator using pyparsing library v1.5.2 (http://pyparsing.wikispaces.com/) and I'm using it both from command line and on Google App Engine. Recently I checked one of my samples which runs perfect from CLI against GAE and it throws me "RuntimeError 'maximum recursion depth exceeded'". I did some investigation and found out that recursion limit is the same locally and inside GA (1000). I've also tested it locally decreasing this limit to 900 but the error didn't happen. The problem itself rises inside pyparsing lib, line 995. Does anyone have any clue what that might be? Why the problem is on GAE (even when run locally), when command line run works just fine (even with recursion limit decreased)? Thanks in advance for any help. Soltys From __peter__ at web.de Fri Jul 2 04:22:31 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Jul 2010 10:22:31 +0200 Subject: Packaging question References: <933a4734-eeff-4d99-89d7-3bbdf7094b1f@e5g2000yqn.googlegroups.com> Message-ID: snorble wrote: > My question is, why do the modules bar and foo show up in mypack's > dir()? I intend for Foo (the class foo.Foo) and Bar (the class > bar.Bar) to be there, but was not sure about the modules foo and bar. > $ ls mypack/*.py > bar.py > foo.py > __init__.py > > $ cat mypack/__init__.py > from foo import Foo > from bar import Bar > > $ python > Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import mypack >>>> dir(mypack) > ['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__', > '__package__', '__path__', 'bar', 'foo'] How is Python to know that you won't perform an import mypack.foo afterwards? After this statement foo must be an attribute of mypack. But when mypack.foo has been imported before this just performs mypack = sys.modules["mypack"] If the foo attribute weren't added by from foo import Foo the caching mechanism would not work. While import mypack.foo might also have been implemented as mypack = sys.modules["mypack"] if not hasattr(mypack", "foo"): mypack.foo = sys.modules["mypack.foo"] I think that would have been a solution to a non-problem. If you're sure you don't need to access mypack.foo directly you can add del foo to mypack/__init__.py, but don't complain when you get bitten by >>> import mypack.foo >>> mypack.foo Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'foo' > My big picture intention is to create smaller modules, but more of > them (like I am used to doing with C++), and then use a package to > organize the namespace so I'm not typing out excessively long names > and making the code less readable. Is that a reasonable approach to > developing Python programs? I like to put related classes and functions into a single file. As a rule of thumb, when a class needs a file of its own the class is too big... Peter From greg.ewing at canterbury.ac.nz Fri Jul 2 04:41:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 20:41:03 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <895mfgFje6U1@mid.individual.net> WANG Cong wrote: > If you think setattr() is as ordinary as a trivial assignment, I will > argue with you, this is personal taste. To my way of thinking, getattr() and setattr() are the fundamental way of accessing attributes in Python. The dot notation is just syntactic sugar for the overwhelmingly common case of a static attribute name. So the dot-notation is more "ordinary" in the sense of being more commonly used, but not in the sense of being a simpler operation. Both are doing exactly the same thing underneath. -- Greg From syockit at gmail.com Fri Jul 2 04:44:02 2010 From: syockit at gmail.com (syockit) Date: Fri, 2 Jul 2010 01:44:02 -0700 (PDT) Subject: Pool Module: iterator does not yield consistently with different chunksizes Message-ID: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> I've been playing around with custom iterators to map into Pool. When I run the code below: def arif(arr): return arr def permutate(n): k = 0 a = list(range(6)) while k References: Message-ID: <895n87FnsoU1@mid.individual.net> WANG Cong wrote: > Yeah, my point is why setattr() for dynamic attributes while assignments > for static attributes? I think there may be a misunderstanding here. You seem to be thinking of "dynamic attribute" vs. "static attribute" as the distinction between creating a new attribute and modifying an existing one. But that's not what it means in this context -- "dynamic" just means that the attribute name is being computed rather than written into the program. In either case, the attribute may or may not be pre-existing. > Why not unify them? If you mean using exactly the same syntax for both, that would require making the static case more verbose, e.g. instead of foo.blarg you would have to write something like foo.("blarg") just to allow for the possibility of writing foo.(some_arbitrary_expression) If you keep the existing static-attribute syntax, then you haven't really unified anything, you've just added a new syntax for dynamic attributes. And because dynamic attribute access is extremely rare, it's not considered worth having a special syntax for it. It's been suggested before, and rejected on those grounds. -- Greg From cournape at gmail.com Fri Jul 2 05:00:17 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 2 Jul 2010 18:00:17 +0900 Subject: Bento 0.0.3 (ex-toydist), a pythonic packaging solution In-Reply-To: <4C2D995C.40209@timgolden.me.uk> References: <4C2D5135.5010909@silveregg.co.jp> <4C2D995C.40209@timgolden.me.uk> Message-ID: On Fri, Jul 2, 2010 at 4:46 PM, Tim Golden wrote: > > Looks very interesting. Just one thing (which might just be me): > the front page looks very stylish and is quite a nice summary. > But I actually *missed* the (grey on grey) [Take me to Bento documentation] > button, which is way below the fold on my screen. Rather, I hit the > more evident Github flag at the top and started looking for docs there! Good point, I will think about a better way to display this, thanks, David From cournape at gmail.com Fri Jul 2 05:02:12 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 2 Jul 2010 18:02:12 +0900 Subject: GAE + recursion limit In-Reply-To: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Message-ID: On Fri, Jul 2, 2010 at 5:06 PM, Maciej wrote: > Does anyone have any clue what that might be? > Why the problem is on GAE (even when run locally), when command line > run works just fine (even with recursion limit decreased)? > Thanks in advance for any help. Most likely google runs a customized python, with different settings to avoid requests to take too long. I doubt there is much you can do for this problem, but you should ask on GAE group. David From greg.ewing at canterbury.ac.nz Fri Jul 2 05:07:39 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 21:07:39 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> Message-ID: <895o1cFsajU1@mid.individual.net> WANG Cong wrote: > When I talked about OOP, it is general OOP, not related with > any concrete programming languages. There isn't really any such thing, though. There is no universally agreed set of features that a language must have in order to be considered OOP. Arguments of the form "Language L isn't really OOP because it doesn't have feature F" don't wash with anyone who has studied a sufficiently wide variety of languages. Every OOP language has its own take on what it means to be OOP, and none of them is any more correct about it than another. -- Greg From thomas at jollans.com Fri Jul 2 05:20:48 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 11:20:48 +0200 Subject: Why defaultdict? In-Reply-To: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2DAF70.8000808@jollans.com> On 07/02/2010 06:11 AM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. > > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = defaultdict(callable, *args) > > which sets an attribute of d "default_factory" which is called on key > lookups when the key is missing. If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. > That is: > > d = dict(*args) > d.default_factory = callable That's just not what dicts, a very simple and elementary data type, do. I know this isn't really a good reason. In addition to what Chris said, I expect this would complicate the dict code a great deal. > > If you failed to explicitly set the dict's default_factory, it would > behave precisely as dicts do now. So why create a new class that needs to > be imported, rather than just add the functionality to dict? > > Is it just an aesthetic choice to support passing the factory function as > the first argument? I would think that the advantage of having it built- > in would far outweigh the cost of an explicit attribute assignment. > The cost of this feature would be over-complication of the built-in dict type when a subclass would do just as well > > > Second, why is the factory function not called with key? There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) I agree, this is a strange choice. However, nothing's stopping you from being a bit verbose about what you want and just doing it: class mydict(defaultdict): def __missing__(self, key): # ... the __missing__ method is really the more useful bit the defaultdict class adds, by the looks of it. -- Thomas > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C > > defaultdict supports (2) and (3): > > defaultdict(factory, *args) > defaultdict(lambda: C, *args) > > but it doesn't support (1). If key were passed to the factory function, > it would be easy to support all three use-cases, at the cost of a > slightly more complex factory function. E.g. the current idiom: > > defaultdict(factory, *args) > > would become: > > defaultdict(lambda key: factory(), *args) > > > (There is a zeroth case as well, where the default value depends on the > key and what else is in the dict: factory(d, key). But I suspect that's > well and truly YAGNI territory.) From clp2 at rebertia.com Fri Jul 2 05:26:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Jul 2010 02:26:23 -0700 Subject: Why defaultdict? In-Reply-To: <4C2DAF70.8000808@jollans.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> <4C2DAF70.8000808@jollans.com> Message-ID: On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: > On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >> I would like to better understand some of the design choices made in >> collections.defaultdict. >> Second, why is the factory function not called with key? There are three >> obvious kinds of "default values" a dict might want, in order of more-to- >> less general: >> >> (1) The default value depends on the key in some way: return factory(key) > > I agree, this is a strange choice. However, nothing's stopping you from > being a bit verbose about what you want and just doing it: > > class mydict(defaultdict): > ? ?def __missing__(self, key): > ? ? ? ?# ... > > the __missing__ method is really the more useful bit the defaultdict > class adds, by the looks of it. Nitpick: You only need to subclass dict, not defaultdict, to use __missing__(). See the part of the docs Raymond Hettinger quoted. Cheers, Chris From thomas at jollans.com Fri Jul 2 05:32:09 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 11:32:09 +0200 Subject: Why defaultdict? In-Reply-To: References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> <4C2DAF70.8000808@jollans.com> Message-ID: <4C2DB219.6010806@jollans.com> On 07/02/2010 11:26 AM, Chris Rebert wrote: > On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: >> On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >>> I would like to better understand some of the design choices made in >>> collections.defaultdict. > >>> Second, why is the factory function not called with key? There are three >>> obvious kinds of "default values" a dict might want, in order of more-to- >>> less general: >>> >>> (1) The default value depends on the key in some way: return factory(key) >> >> I agree, this is a strange choice. However, nothing's stopping you from >> being a bit verbose about what you want and just doing it: >> >> class mydict(defaultdict): >> def __missing__(self, key): >> # ... >> >> the __missing__ method is really the more useful bit the defaultdict >> class adds, by the looks of it. > > Nitpick: You only need to subclass dict, not defaultdict, to use > __missing__(). See the part of the docs Raymond Hettinger quoted. > Sorry Raymond, I didn't see you. This is where I cancel my "filter out google groups users" experiment. From greg.ewing at canterbury.ac.nz Fri Jul 2 05:42:53 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 21:42:53 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <895q3eF8oaU1@mid.individual.net> WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. But, in Python, creating instance variables is *not* class-programming. It doesn't touch the class at all. In many OO languages, such as Simula, C++ and Java, one of the responsibilities of a class is to define what attributes its instances have. However, that really comes about because those languages are statically typed -- it's not an essential principle of OO at all. In Python, restricting what attributes an object can have is *not* considered to be a responsibility of the class. The class is just a convenient place to put stuff (mostly methods) that some bunch of objects all need to have. Anything beyond that is up to the objects themselves. It so happens that, in most Python programs, all the instances of a given class will usually have a well- defined set of attributes. But Python doesn't go out of its way to enforce that. This is just a part of Python's general philosophy of not requiring declarations. There are very few declarative constructs in Python -- even class and function definitions are executable statements that construct data structures at run time. The only true declarations are the 'global' and 'nonlocal' statements, and they only exist because without them there would be no way to achieve certain things. They are not there to enforce any kind of static check. Why does Python not require declarations? Because it makes code easier and faster to develop. Instead of having to spend time and effort writing declarations, you just get straight on and write the code that does the actual work. And if you change your mind and need to move things around, you don't have to perform extra work to keep the declarations up to date. This can be a big help in the early stages of development, when you're feeling your way and the design is fluid. It also makes the program easier to extend and modify later. The downside is that certain kinds of error, that would be caught at compile time in a more static language, don't show up until you run the program. But if you're testing properly -- which you need to do anyway, whatever language you're using -- they usually show up pretty soon, and aren't much harder to fix when they do. Experience has shown that the overall process -- design, programming, testing and debugging -- tends to be faster using a dynamic, fluid language such as Python, than a static one such as C++ or Java. And, many people would say, more fun as well -- which is a good enough reason on its own for using Python! -- Greg From bruno.42.desthuilliers at websiteburo.invalid Fri Jul 2 05:59:20 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 02 Jul 2010 11:59:20 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4c2db80c$0$30015$426a74cc@news.free.fr> WANG Cong a ?crit : > On 07/01/10 23:19, Stephen Hansen wrote: > >>> As long as setattr() exists in Python, that will be not so ordinary. :) >> setattr is perfectly ordinary. > > If you think setattr() is as ordinary as a trivial assignment, setattr IS a trivial assignment. > > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. No "magic" and no "meta"whatever involved. setattr is as simple as: def setattr(obj, name, value): obj.__setattribute__(name, value) which is *exactly* what gets called when you use the binding statement form ie "obj.someattr = value" which FWIW is just syntactic sugar for the former (just like the 'class' statement is just syntactic sugar for a call to type, etc). I fail to understand why you insist on seeing something as trivial as "magic", "metaprogramming" or whatever. From bruno.42.desthuilliers at websiteburo.invalid Fri Jul 2 06:05:31 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 02 Jul 2010 12:05:31 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <4c2db97f$0$27941$426a34cc@news.free.fr> WANG Cong a ?crit : > On 06/30/10 01:25, Ethan Furman wrote: > >>> But if so why setattr() still exists? What is it for if we can do the >>> same thing via assignments? Also, in order to be perfect, Python should >>> accept to add dynamic attributes dynamically, something like PEP >>> 363. That doesn't happen. >> Setattr and friends exist to work with dynamic attributes. >> > > Yeah, my point is why setattr() for dynamic attributes while assignments > for static attributes? Why not unify them? What is a "dynamic" and what is a "static" attribute ???? > Agreed, but at least, the reason why I am being against so many people > here is also trying to make Python be more perfect with my > understanding. Please start with learning Python's execution model (what exactly happens at runtime, what most statement are syntactic sugar for etc) and Python's object model (how are Python objects, classes, methods etc implemented, attributes lookup rules, metaclasses, descriptors etc). Then PERHAPS you MIGHT have a chance to help making Python "more perfect". From macosx at rocteur.cc Fri Jul 2 06:07:51 2010 From: macosx at rocteur.cc (Jerry Rocteur) Date: Fri, 2 Jul 2010 12:07:51 +0200 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: Message-ID: <20100702100751.GA5284@incc-g5.local> * Dave Pawson [2010-07-02 08:22]: > I'm the OP btw. > > On 1 July 2010 18:10, Dennis Lee Bieber wrote: > > >> I think that Python "could" be a alternative to bash and have some > >> advantages, but it's a long way off from being fully implemented. > > Take a look at Python for Unix and Linux System Administration: http://www.amazon.com/Python-Unix-Linux-System-Administration/dp/0596515820 I quite like the book, I learned about Ipython from this book and I'm quite glad I did! Jerry From stef.mientki at gmail.com Fri Jul 2 06:15:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 02 Jul 2010 12:15:48 +0200 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: References: <1278010127.6605.1382869273@webmail.messagingengine.com> Message-ID: <4C2DBC54.7090004@gmail.com> On 02-07-2010 09:39, geremy condra wrote: > On Thu, Jul 1, 2010 at 11:48 AM, wrote: >> Curious if any of you are using GPG or PGP encryption and/or signatures >> in your Python apps? > Yes; disclaimer: I'm the author of evpy and am currently working on a > openssl wrapper proposed for inclusion in the stdlib. Great Geremy !, but it's difficult to find, and I couldn't find any documentation. Did I not look at the right places ? thanks Stef Mientki From __peter__ at web.de Fri Jul 2 06:22:17 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Jul 2010 12:22:17 +0200 Subject: Pool Module: iterator does not yield consistently with different chunksizes References: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> Message-ID: syockit wrote: > I've been playing around with custom iterators to map into Pool. When > I run the code below: > > def arif(arr): > return arr > > def permutate(n): > k = 0 > a = list(range(6)) > while k for i in range(6): > a.insert(0, a.pop(5)+6) > #yield a[:] <-- produces correct results > yield a > k += 1 > return > > def main(): > from multiprocessing import Pool > pool = Pool() > chksize = 15 > for x in pool.imap_unordered(arif, permutate(100), chksize): > print(x) > > if __name__=="__main__": > main() > > .... will output something like this: > > > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [144, 145, 146, 147, 148, 149] > > ... where results are duplicated number of times equal to chunk size, > and the results between the gap are lost. Using a[:] instead, i get: > > [6, 7, 8, 9, 10, 11] > [12, 13, 14, 15, 16, 17] > [18, 19, 20, 21, 22, 23] > [24, 25, 26, 27, 28, 29] > [30, 31, 32, 33, 34, 35] > [36, 37, 38, 39, 40, 41] > [42, 43, 44, 45, 46, 47] > [48, 49, 50, 51, 52, 53] > > .... it comes out okay. Any explanation for such behavior? > > Ahmad Syukri Python passes references araound, not copies. Consider it = permutate(100) chunksize = 15 from itertools import islice while True: chunk = tuple(islice(it, chunksize)) if not chunk: break # dispatch items in chunk print chunk chunksize items are calculated before they are dispatched. When you yield the same list every time in permutate() previous items in the chunk will see any changes you make on the list with the intention to update it to the next value. Peter From davea at ieee.org Fri Jul 2 07:55:34 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 02 Jul 2010 07:55:34 -0400 Subject: Pool Module: iterator does not yield consistently with different chunksizes In-Reply-To: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> References: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> Message-ID: <4C2DD3B6.5030107@ieee.org> syockit wrote: > I've been playing around with custom iterators to map into Pool. When > I run the code below: > > def arif(arr): > return arr > > def permutate(n): > k = 0 > a = list(range(6)) > while k for i in range(6): > a.insert(0, a.pop(5)+6) > #yield a[:] <-- produces correct results > yield a > k += 1 > return > > def main(): > from multiprocessing import Pool > pool = Pool() > chksize = 15 > for x in pool.imap_unordered(arif, permutate(100), chksize): > print(x) > > if __name__=="__main__": > main() > > .... will output something like this: > > > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [144, 145, 146, 147, 148, 149] > > ... where results are duplicated number of times equal to chunk size, > and the results between the gap are lost. Using a[:] instead, i get: > > [6, 7, 8, 9, 10, 11] > [12, 13, 14, 15, 16, 17] > [18, 19, 20, 21, 22, 23] > [24, 25, 26, 27, 28, 29] > [30, 31, 32, 33, 34, 35] > [36, 37, 38, 39, 40, 41] > [42, 43, 44, 45, 46, 47] > [48, 49, 50, 51, 52, 53] > > .... it comes out okay. Any explanation for such behavior? > > Ahmad Syukri > > While I didn't actually try to follow all your code, I suspect your problem is that when you yield the same object multiple times, they're being all saved, and then when evaluated, they all have the final value. If the values are really independent, somebody has to copy the list, and the [:] does that. DaveA From sjmachin at lexicon.net Fri Jul 2 08:12:04 2010 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jul 2010 05:12:04 -0700 (PDT) Subject: escape character / csv module References: Message-ID: <9309d748-c500-4124-8032-459ce0b47561@b4g2000pra.googlegroups.com> On Jul 2, 6:04?am, MRAB wrote: > The csv module imports from _csv, which suggests to me that there's code > written in C which thinks that the "\x00" is a NUL terminator, so it's a > bug, although it's very unusual to want to write characters like "\x00" > to a CSV file, and I wouldn't be surprised if this is the first time > it's been noticed! :-) Don't be surprised, read the documentation (http://docs.python.org/ library/csv.html#module-csv): """Note This version of the csv module doesn?t support Unicode input. Also, there are currently some issues regarding ASCII NUL characters. Accordingly, all input should be UTF-8 or printable ASCII to be safe; see the examples in section Examples. These restrictions will be removed in the future.""" The NUL/printable part of the note has been there since the module was introduced in Python 2.3.0. From dotancohen at gmail.com Fri Jul 2 08:38:40 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 2 Jul 2010 15:38:40 +0300 Subject: Ignorance and Google Groups (again) In-Reply-To: <20100701221008.d673a9d8.darcy@druid.net> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <20100701221008.d673a9d8.darcy@druid.net> Message-ID: On 2 July 2010 05:10, D'Arcy J.M. Cain wrote: > On Thu, 1 Jul 2010 21:34:15 +0300 > Dotan Cohen wrote: >> I'm one of them. Gmail is great for mailing lists, though I would >> never use it as a personal email client. But I'm more of a lurker than >> a poster on this list, so D'Arcy won't miss me anyway. > > As the song says. "How can I miss you if you won't go away." :-) > I've never heard that, but it sounds line a great line. Googling now! > As I explained, I don't block just because you are on gmail.com. ?I > only block if you use Google Groups to post via news. > Yes, I got to that part after I posted. I should have read to whole thread first. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ethan at stoneleaf.us Fri Jul 2 08:53:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Jul 2010 05:53:42 -0700 Subject: Python v3.1.2 documentation question In-Reply-To: References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> <4C2D19EE.6060602@stoneleaf.us> Message-ID: <4C2DE156.4020404@stoneleaf.us> Terry Reedy wrote: > On 7/1/2010 6:42 PM, Ethan Furman wrote: > >> Hmmm.... Well, as this is my first ever bug post (yay! ;) > > > Great! > > I *think* this is what you want: > >> >> http://bugs.python.org/issue9121 > > > I believe Benjamin meant that it was already fixed in > http://docs.python.org/dev/py3k/ > which is currently the 3.2a0 docs. > Good to check there before reporting a doc bug. > > Terry Jan Reedy Thanks for the pointer, I didn't know about that. Checking it out, though, it seems the entry for nested scopes has been removed in its entirety -- not sure about fixed, but I guess it's definitely not broken anymore! ;) ~Ethan~ From ethan at stoneleaf.us Fri Jul 2 09:05:59 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Jul 2010 06:05:59 -0700 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <4C2DE437.4040205@stoneleaf.us> Terry Reedy wrote: > On 7/1/2010 6:42 PM, Emile van Sebille wrote: > >> On 7/1/2010 2:52 PM Jay said... >> >>> pywinauto looks to be almost perfect. All I need now is to read the >>> numbers uncovered when a minesweeper square is clicked on, or that I >>> just hit a mine. >>> >> >> ... or, you could always win... >> >> http://www.daniweb.com/forums/thread186209.html > > > Did you actually try it? Though skeptical, I did, briefly, until I > decided that it probably should have been dated April 1. There is no way > to enter text into minesweeper, nor to make it full screen, nor, as far > as I know, for it to toggle pixels outside its window. The pixel can be hard to see depending on your background colors and whether your screen is adjusted correctly (I could see the white, but not the black). But on XP Pro is still works. ~Ethan~ From utente at esempio.net Fri Jul 2 09:17:25 2010 From: utente at esempio.net (superpollo) Date: Fri, 02 Jul 2010 15:17:25 +0200 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <4c2de6e6$0$40293$4fafbaef@reader2.news.tin.it> Ethan Furman ha scritto: > Terry Reedy wrote: >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: >> >>> On 7/1/2010 2:52 PM Jay said... >>> >>>> pywinauto looks to be almost perfect. All I need now is to read the >>>> numbers uncovered when a minesweeper square is clicked on, or that I >>>> just hit a mine. >>>> >>> >>> ... or, you could always win... >>> >>> http://www.daniweb.com/forums/thread186209.html >> >> >> Did you actually try it? Though skeptical, I did, briefly, until I >> decided that it probably should have been dated April 1. There is no >> way to enter text into minesweeper, nor to make it full screen, nor, >> as far as I know, for it to toggle pixels outside its window. > > The pixel can be hard to see depending on your background colors and > whether your screen is adjusted correctly (I could see the white, but > not the black). But on XP Pro is still works. works for me too bye From kedra.marbun at gmail.com Fri Jul 2 09:28:59 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 2 Jul 2010 06:28:59 -0700 (PDT) Subject: delegation pattern via descriptor Message-ID: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> hello, friendliest prog lang community on earth ;) i'm feeling that (0) delegation pattern thru descriptor encourages dedicated delegate for each task, if feeling: print(benefits) (1) the delegate is designed to be blind about the class on which the delegate is attached to isn't that the two strengthen the coupling between delegator & delegate obviously __getattribute__ & his 2 friends of 'object' & 'type' have what it takes to make it not like that, it's just that they're not designed to pass it. thus i think it is by design yes i know there's a way around it, the most obvious to me is defining your own hooks (which is not trival, at least to me) , but like i said, it's encouraged wow, it's almost time for brazil to beat the dutch, sorry Guido ;) if fifa['wc']['2010'].winner is not brazil: raise SystemError From torriem at gmail.com Fri Jul 2 11:20:38 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 02 Jul 2010 09:20:38 -0600 Subject: drag & drop in a python GUI application In-Reply-To: References: Message-ID: <4C2E03C6.1070406@gmail.com> On 07/01/2010 08:57 AM, Alan wrote: > I know drag & drop is not possible with TK. Is this a Python Tk limitation or a Tk limitation in general? Google suggests that Tk itself supports some form of dnd. > Which widget could I use for my > python application to be able to work with drag & drop? PyQt will do drag and drop on all platforms. GTK does drag and drop on Unix/X11, and to a lesser degree Win32--not sure about OS X support. I believe wxWidgets also does some level of dnd on all platforms. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 11:35:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 15:35:10 GMT Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> Message-ID: <4c2e072e$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 06:28:59 -0700, kedra marbun wrote: > hello, friendliest prog lang community on earth ;) > > i'm feeling that > (0) delegation pattern thru descriptor encourages dedicated delegate for > each task, if feeling: print(benefits) (1) the delegate is designed to > be blind about the class on which the delegate is attached to > > isn't that the two strengthen the coupling between delegator & delegate > obviously __getattribute__ & his 2 friends of 'object' & 'type' have > what it takes to make it not like that, it's just that they're not > designed to pass it. thus i think it is by design > > yes i know there's a way around it, the most obvious to me is defining > your own hooks (which is not trival, at least to me) , but like i said, > it's encouraged I'm sorry, I don't understand a thing you're saying there. Can you explain what you mean? -- Steven From dhilip.jec at gmail.com Fri Jul 2 11:38:56 2010 From: dhilip.jec at gmail.com (Dhilip S) Date: Fri, 2 Jul 2010 21:08:56 +0530 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: Hello Everyone.. I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got error message while doing make command. anybody can tell tell, How to overcome this error.... Finally i got message like this ... 4036e000-403ad000 r--p 00000000 08:08 156978 /usr/lib/locale/en_IN/LC_CTYPE bff9a000-bffaf000 rw-p 00000000 00:00 0 [stack] Aborted make: ***[sharedmodes] Error 13 -- with regards, Dhilip.S -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 2 12:24:41 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 18:24:41 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <4C2E12C9.7030307@jollans.com> On 07/02/2010 05:38 PM, Dhilip S wrote: > > > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Finally i got message like this ... > > 4036e000-403ad000 r--p 00000000 08:08 156978 > /usr/lib/locale/en_IN/LC_CTYPE > bff9a000-bffaf000 rw-p 00000000 00:00 0 [stack] > Aborted > make: ***[sharedmodes] Error 13 > That looks like the last line of a glibc backtrace, and doesn't tell us much. Please post the exact commands you entered to produce the problem. Best to try again, even if you're sure it will fail. Then post the complete error message, which can span several screenfuls with this kind of problem. Include at least a few lines of output that you can be sure are correct, to give us some context. It's better to post a bit too much than too little. -- Thomas From debatem1 at gmail.com Fri Jul 2 12:58:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 2 Jul 2010 12:58:13 -0400 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: References: <1278010127.6605.1382869273@webmail.messagingengine.com> <4C2DBC54.7090004@gmail.com> Message-ID: On Fri, Jul 2, 2010 at 6:15 AM, Stef Mientki wrote: > ?On 02-07-2010 09:39, geremy condra wrote: >> On Thu, Jul 1, 2010 at 11:48 AM, ? wrote: >>> Curious if any of you are using GPG or PGP encryption and/or signatures >>> in your Python apps? >> Yes; disclaimer: I'm the author of evpy and am currently working on a >> openssl wrapper proposed for inclusion in the stdlib. > Great Geremy !, > but it's difficult to find, > and I couldn't find any documentation. > Did I not look at the right places ? I assume you're talking about the proposed (and unnamed) crypto library, in which case I would be very surprised if you found it unless you looked on my hard drive ;). I don't usually release security-critical code for general use until I've done extensive testing and I simply haven't had time for that over the last week or so. If you're talking about evpy, the documentation for the three user-facing modules is in the docstrings, and I'm almost always here or available by email if you have any questions. Geremy Condra From me+list/python at ixokai.io Fri Jul 2 13:41:01 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 10:41:01 -0700 Subject: Decorators, with optional arguments Message-ID: <4C2E24AD.3040002@ixokai.io> Okay, so! I actually never quite got around to learning to do deep and useful magic with decorators. I've only ever done the most basic things with them. Its all been a little fuzzy in my head: things like what order decorators end up being called in if there's more then one, etc. But in my current situation, what I'm wanting to do is have a decorator that wraps a function but which takes an *optional* argument, and sets that argument as an attribute on said function if its there. Here's what some tweaking and playing around has gotten me, as a recipe: import functools def my_decorator(arg): if callable(arg): # Stuck on 2.5. Leavemealone. :) protocol = None else: protocol = arg def wrap(fn): print "Wrapping." fn.protocol = protocol @functools.wraps(fn) def wrapper(*args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return wrapper if not protocol: # argument-less decorator print "Calling wrap." return wrap(arg) else: print "Returning wrap." return wrap To be used as: class Thing(object): @expose def test1(self, arg1): return arg1 @expose("testing") def test2(self, arg2): return arg2 So, my question: am I doing this right? :) Some play-through testing appears to work. But, the dizzying array of nested def's up there leaves me a bit dazed, so I'm wondering if there's a simpler way to accomplish what I'm trying to do. Thanks. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From no.email at please.post Fri Jul 2 14:00:03 2010 From: no.email at please.post (kj) Date: Fri, 2 Jul 2010 18:00:03 +0000 (UTC) Subject: Numerics question Message-ID: I define ninv = 1.0/n ...where n is some integer, and I want to write some function f such that f(m * ninv) returns the smallest integer that is >= m * ninv, where m is some other integer. And, in particular, if m is p*n for some integer p, then f((p*n) * ninv) should return the integer p. The first solution that comes to mind is something like def f(x): return int(math.ceil(x)) At first this seems to work: >>> f((7*2) * (1.0/2)) 7 >>> f((7*3) * (1.0/3)) 7 ...but there are values of n for which it fails: >>> f((7*75) * (1.0/75)) 8 The problem here is that, due to numerical error, the expression ((7*75) * (1.0/75)) evaluates to a number *just* above 7. The surrounding math.ceil then turns this into 8.0, etc. Is there a way to define f so that it behaves as expected? TIA! ~K From magnus.lycka at gmail.com Fri Jul 2 14:05:19 2010 From: magnus.lycka at gmail.com (magnus.lycka at gmail.com) Date: Fri, 2 Jul 2010 11:05:19 -0700 (PDT) Subject: Importing package with zip-archives Message-ID: <2b5ea92d-d3a3-4aeb-a68c-1d6ddc30010e@k39g2000yqd.googlegroups.com> I'd like to have the following structure of my Python code: I have a directory called 'mysystem'. In this directory, I have files 'comp1.zip' and 'comp2.zip' etc which are zipped archives with python packages and modules. I'd like to be able to use them like this in my code: import mysystem.comp1.module import mysystem.comp2.package.module etc. Can I do that? I guess it requires that the __init__.py in mysystem is written in a clever way, but it's not clear how to do this, and I don't find a lot on this in any Python books or on the net. I tried: mysystem/__init__.py: import sys import os dir = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.path.join(dir, 'comp1.zip')) import comp1 That doesn't do what I want. To access comp1 with this __init__.py I'll have to do import mysystem import comp1.module instead of import mysystem.comp1.module :-( Optionally, I'd like to be able to patch the system by putting a module.py in mysystem/comp2/package/ and get that to override the 'package/module.py' in comp2.zip. It's OK if I need to patch __init__.py in mysystem to do that. From no.email at please.post Fri Jul 2 14:14:10 2010 From: no.email at please.post (kj) Date: Fri, 2 Jul 2010 18:14:10 +0000 (UTC) Subject: Numerics question References: Message-ID: Please disregard my ineptly posed question. ~K In kj writes: >I define >ninv = 1.0/n >...where n is some integer, and I want to write some function f such >that f(m * ninv) returns the smallest integer that is >= m * ninv, >where m is some other integer. And, in particular, if m is p*n >for some integer p, then f((p*n) * ninv) should return the integer >p. >The first solution that comes to mind is something like >def f(x): > return int(math.ceil(x)) >At first this seems to work: >>>> f((7*2) * (1.0/2)) >7 >>>> f((7*3) * (1.0/3)) >7 >...but there are values of n for which it fails: >>>> f((7*75) * (1.0/75)) >8 >The problem here is that, due to numerical error, the expression >((7*75) * (1.0/75)) evaluates to a number *just* above 7. The >surrounding math.ceil then turns this into 8.0, etc. >Is there a way to define f so that it behaves as expected? >TIA! >~K From jdixon at omniti.com Fri Jul 2 14:39:52 2010 From: jdixon at omniti.com (Jason Dixon) Date: Fri, 2 Jul 2010 14:39:52 -0400 Subject: CFP for Surge Scalability Conference 2010 Message-ID: <20100702183952.GW29381@omniti.com> A quick reminder that there's one week left to submit your abstract for this year's Surge Scalability Conference. The event is taking place on Sept 30 and Oct 1, 2010 in Baltimore, MD. Surge focuses on case studies that address production failures and the re-engineering efforts that led to victory in Web Applications or Internet Architectures. Our Keynote speakers include John Allspaw and Theo Schlossnagle. We are currently accepting submissions for the Call For Papers through July 9th. You can find more information, including suggested topics and our current list of speakers, online: http://omniti.com/surge/2010 I'd also like to urge folks who are planning to attend, to get your session passes sooner rather than later. We have limited seating and we are on track to sell out early. For more information, including the CFP, sponsorship of the event, or participating as an exhibitor, please visit the Surge website or contact us at surge at omniti.com. Thanks, -- Jason Dixon OmniTI Computer Consulting, Inc. jdixon at omniti.com 443.325.1357 x.241 From gabriele.lanaro at gmail.com Fri Jul 2 14:48:43 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Fri, 2 Jul 2010 20:48:43 +0200 Subject: [ANN] Emacs For Python 0.1, collection of emacs extensions for python development Message-ID: Emacs For Python 0.1 Emacs for python (epy) is a collection of emacs extensions for python development, yet ready and configured for you. It includes also tweaks to commonly used extension to provide extra functionality and fast bug correction. There are also sane configuration that helps you getting started pretty fast. Some of the most important extensions configured and included in the distribution are: - ido prompts - autocompletion + rope (if you have pymacs) - snippets, simplified and standard-compliant - automatic error/warning/info highlighting with flymake (powered by pyflakes) - custom keybindings - much more (really) I remaind you for further information to the home page: http://gabrielelanaro.github.com/emacs-for-python/ You'll find additional information on the github page (readme and wiki): http://github.com/gabrielelanaro/emacs-for-python Thank you for the attention! - Gabriele -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 2 14:55:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 20:55:26 +0200 Subject: Decorators, with optional arguments In-Reply-To: <4C2E24AD.3040002@ixokai.io> References: <4C2E24AD.3040002@ixokai.io> Message-ID: <4C2E361E.3080602@jollans.com> On 07/02/2010 07:41 PM, Stephen Hansen wrote: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > import functools > > def my_decorator(arg): > if callable(arg): # Stuck on 2.5. Leavemealone. :) > protocol = None > else: > protocol = arg > > def wrap(fn): > print "Wrapping." > fn.protocol = protocol > > @functools.wraps(fn) > def wrapper(*args, **kwargs): > print "Calling." > result = fn(*args, **kwargs) > print "Called." > return result > > return wrapper > > if not protocol: # argument-less decorator > print "Calling wrap." > return wrap(arg) > else: > print "Returning wrap." > return wrap Looks good! You may still want to use functools.update_wrapper or functools.wraps on "wrap". PS: if you weren't stuck on 2.5, but were using 3.x, there's all kinds of fun stuff you could do with function annotations ;-) > > To be used as: > > class Thing(object): > @expose > def test1(self, arg1): > return arg1 > > @expose("testing") > def test2(self, arg2): > return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. > > Thanks. > From alf.p.steinbach+usenet at gmail.com Fri Jul 2 14:58:35 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 02 Jul 2010 20:58:35 +0200 Subject: Decorators, with optional arguments In-Reply-To: References: Message-ID: * Stephen Hansen, on 02.07.2010 19:41: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > import functools > > def my_decorator(arg): > if callable(arg): # Stuck on 2.5. Leavemealone. :) > protocol = None > else: > protocol = arg > > def wrap(fn): > print "Wrapping." > fn.protocol = protocol > > @functools.wraps(fn) > def wrapper(*args, **kwargs): > print "Calling." > result = fn(*args, **kwargs) > print "Called." > return result > > return wrapper > > if not protocol: # argument-less decorator > print "Calling wrap." > return wrap(arg) > else: > print "Returning wrap." > return wrap > > To be used as: > > class Thing(object): > @expose > def test1(self, arg1): > return arg1 > > @expose("testing") > def test2(self, arg2): > return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. If you're willing to have slightly more explicit usage code, consider e.g. #Py3 import functools class expose: def __init__( self, protocol = None ): self._protocol = protocol def __call__( self, f ): print( "Wrapping." ) f.protocol = self._protocol @functools.wraps( f ) def wrapper( *args, **kwargs ): print( "Calling." ) result = f( *args, **kwargs ) print( "Called." ) return result return wrapper class Thing(object): @expose() def test1(self, arg1): return arg1 @expose( "testing" ) def test2(self, arg2): return arg2 o = Thing() print( o.test1( 1.11 ) ) print( o.test2( 2.22 ) ) Cheers & hth., - Alf -- blog at From nathan.alexander.rice at gmail.com Fri Jul 2 14:58:46 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 2 Jul 2010 14:58:46 -0400 Subject: Decorators, with optional arguments In-Reply-To: <4C2E24AD.3040002@ixokai.io> References: <4C2E24AD.3040002@ixokai.io> Message-ID: I like to think of decorators with arguments as decorator factory functions. I try and unroll them as much as possible... I have some decorators that work like so (and please note that the wraps and returns_as_output are separate so that I can mutate the behavior as needed, if you just wanted a single decorator this could be condensed): def wrap(f, wrapping_function, *args): argspec = inspect.getargspec(f) without_defaults = len(argspec.args) - len(argspec.defaults or []) f._args = {} f._varkw = [] f._arg_defaults = (None,) * without_defaults + (argspec.defaults or tuple()) for arg in args: if arg in argspec.args: f._args[arg] = argspec.args.index(arg) else: if argspec.keywords: f._varkw.append(arg) return decorator.decorator(wrapping_function, f) def return_as_output(output_f): def func(f, *args, **kwargs): new_args = list(args) for (dict_name, index) in f._args.items(): if len(args) > index: new_args[index] = output_f(args[index]) else: d = f._arg_defaults[index] kwargs[dict_name] = output_f(kwargs.pop(dict_name, d)) for dict_name in f._varkw: kwargs[dict_name] = output_f(kwargs.pop(dict_name, None)) return f(*new_args, **kwargs) return func def iterables(*args): ''' Decorator that guarantees that the named arguments will be iterable. ''' as_iterables = return_as_output(iter_) return lambda f: wrap(f, as_iterables, *args) Just as an example... I have a family of decorators that check compliance with abstract base classes, then try to mutate variables to provide it if duck typing would fail. I don't know if this helps, it is kind of convoluted, but hopefully it gives you another example to work from. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Jul 2 15:07:33 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 12:07:33 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") Message-ID: <4C2E38F5.10708@animats.com> David Cournapeau wrote: > I think one point which needs to be emphasized more is what does > python 3 bring to people. The" what's new in python 3 page" gives > the impression that python 3 is about removing cruft. That's a very > poor argument to push people to switch. That's the real issue, not parentheses on the "print" statement. Where's the business case for moving to Python 3? It's not faster. It doesn't do anything you can't do in Python 2.6. There's no "killer app" for it. End of life for Python 2.x is many years away; most server Linux distros aren't even shipping with 2.6 yet. How can a business justify spending money on conversion to Python 3? If Python 3 came with Unladen Swallow, and ran several times faster than Python 2.x, there'd be a strong business case for conversion. Especially for large sites with racks of servers grinding through slow CPython code. But it looks like Unladen Swallow will be available for 2.6 before it's available for 3.x. So that's not a selling point for 3.x. Python 3 is a nice cleanup of some legacy syntax issues. But that's just not enough. Perl 6 is a nice cleanup of Perl 5, and look how that went. Ten years on, it's not even mainstream, let alone dominant. This has all been said before. See "Python 3.0: What?s The Point?" from December 2008: http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ Not much has changed since then. What I'm not seeing is a deployment plan along these lines: 1. Identify key modules which must be converted before Python 3 can be used in production environments. 2. Get those modules converted to Python 3. 3. Put together a distribution for the major platforms (at least Linux and Windows) with builds of those modules. This could be done on PyPi, which is at present is mostly a link farm, not a repository. 4. Get some major distros, like Debian and ActiveState, to include Python 3, as "python3", not as the primary Python, so there are no conflicts. (Debian already has a formal policy to keep Python versions separate.) 5. Get at least two major hosting services to put up Python 3. 6. Get at least two popular end-user programs (not modules) to support Python 3. 7. Publicize some success stories. Unless the Python 3 enthusiasts get their act together and work much harder on providing an easy transition experience, it's not going to happen. John Nagle From thomas at jollans.com Fri Jul 2 15:59:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 21:59:45 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: <4C2E4531.1060809@jollans.com> On 07/02/2010 09:07 PM, John Nagle wrote: > > What I'm not seeing is a deployment plan along these lines: > > 1. Identify key modules which must be converted before Python 3 > can be used in production environments. That depends VERY strongly on the environment in question. > > 2. Get those modules converted to Python 3. The stdlib is there. The rocky bits are being fixed all the time. The other important modules all have strong development communities. Upstream numpy works with Python 3 already. (no release yet) That enables SciPy to update, which they will do. PyGObject is also working on Py3 support. > > 3. Put together a distribution for the major platforms (at least > Linux and Windows) with builds of those modules. This > could be done on PyPi, which is at present is mostly a link > farm, not a repository. The use cases for Python being as diverse as they are, this is utter nonsense. Also, I myself see no benefit in making PyPI a mirror of everything, as opposed to a useful index of packages that you may or may not want to use. > > 4. Get some major distros, like Debian and ActiveState, to > include Python 3, as "python3", not as the primary Python, > so there are no conflicts. (Debian already has a formal > policy to keep Python versions separate.) Current Ubuntu releases include Python 3.1 as /usr/bin/python3. So does Debian (not sure about stable at this point). I'm sure the other major Linux distributions are doing the same thing. It's happening! > > 5. Get at least two major hosting services to put up Python 3. Apparently, some hosters already support Python 3. Web development is a bit of a weak spot at the moment though, and this is problematic, due to WSGI not being quite unicode ready. > > 6. Get at least two popular end-user programs (not modules) to > support Python 3. > > 7. Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. It's not happening fast, it probably can't, but it *is* happening. Software distributions are including Python 3, and popular modules/packages are starting to support it. Other software is going to move on in its own time. From pavlovevidence at gmail.com Fri Jul 2 16:17:06 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 13:17:06 -0700 (PDT) Subject: Decorators, with optional arguments References: Message-ID: On Jul 2, 10:41?am, Stephen Hansen wrote: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > ? ? ?import functools > > ? ? ?def my_decorator(arg): > ? ? ? ? ?if callable(arg): # Stuck on 2.5. Leavemealone. :) > ? ? ? ? ? ? ?protocol = None > ? ? ? ? ?else: > ? ? ? ? ? ? ?protocol = arg > > ? ? ? ? ?def wrap(fn): > ? ? ? ? ? ? ?print "Wrapping." > ? ? ? ? ? ? ?fn.protocol = protocol > > ? ? ? ? ? ? ?@functools.wraps(fn) > ? ? ? ? ? ? ?def wrapper(*args, **kwargs): > ? ? ? ? ? ? ? ? ?print "Calling." > ? ? ? ? ? ? ? ? ?result = fn(*args, **kwargs) > ? ? ? ? ? ? ? ? ?print "Called." > ? ? ? ? ? ? ? ? ?return result > > ? ? ? ? ? ? ?return wrapper > > ? ? ? ? ?if not protocol: # argument-less decorator > ? ? ? ? ? ? ?print "Calling wrap." > ? ? ? ? ? ? ?return wrap(arg) > ? ? ? ? ?else: > ? ? ? ? ? ? ?print "Returning wrap." > ? ? ? ? ? ? ?return wrap > > To be used as: > > ? ? ?class Thing(object): > ? ? ? ? ?@expose > ? ? ? ? ?def test1(self, arg1): > ? ? ? ? ? ? ?return arg1 > > ? ? ? ? ?@expose("testing") > ? ? ? ? ?def test2(self, arg2): > ? ? ? ? ? ? ?return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. I usually recommend to factoring out magic parts into their own little function, which then invoke the non-magical part in different ways: def expose_as(protocol): def wrap(fn): print "Wrapping." fn.protocol = protocol @functools.wraps(fn) def wrapper(*args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return wrapper return wrap def expose(arg): """Magic function to allow omitting argument.""" if type(arg) is types.FunctionType: print "Calling with arg as function" return expose_as(None)(arg) print "Calling with arg as protocol" return expose_as(arg) I believe it's a good practice to isolate magic so that it's easy to see, and also to ensure there's a non-magical way to do it if that is needed. However, the world won't come to an end if you do it your way. Carl Banks From solipsis at pitrou.net Fri Jul 2 16:26:03 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 2 Jul 2010 22:26:03 +0200 Subject: Lockless algorithms in python (Nothing to do with GIL) References: Message-ID: <20100702222603.26c5e4af@pitrou.net> On Mon, 28 Jun 2010 16:46:41 -0700 Zac Burns wrote: > In my experience it is far more expensive to allocate a lock in python then > it is the types that use them. Here are some examples: > > >>> timeit.timeit('Lock()', 'from threading import Lock') > 1.4449114807669048 > > >>> timeit.timeit('dict()') > 0.2821554294221187 > > >>> timeit.timeit('list()') > 0.17358153222312467 I'm not sure what Python version on what machine you are using, but here (Python 2.7): >>> timeit.timeit('Lock()', 'from threading import Lock') 0.09944796562194824 >>> timeit.timeit('dict()') 0.17817902565002441 >>> timeit.timeit('list()') 0.19633007049560547 >>> timeit.timeit('{}') 0.03823709487915039 >>> timeit.timeit('[]') 0.05156302452087402 From ptmcg at austin.rr.com Fri Jul 2 16:49:06 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 2 Jul 2010 13:49:06 -0700 (PDT) Subject: GAE + recursion limit References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Message-ID: <70bd0175-f752-4714-a7d9-49a65fc13f75@e5g2000yqn.googlegroups.com> > Does anyone have any clue what that might be? > Why the problem is on GAE (even when run locally), when command line > run works just fine (even with recursion limit decreased)? Can't explain why you see different behavior on GAE vs. local, but it is unusual for a "small" translator to flirt with recursion limit. I don't usually see parsers come close to this with fewer than 40 or 50 sub-expressions. You may have some left-recursion going on. Can you post your translator somewhere, perhaps on pastebin, or on the pyparsing wiki Discussion page (pyparsing.wikispaces.com)? -- Paul From pavlovevidence at gmail.com Fri Jul 2 16:51:31 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 13:51:31 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: <065866d2-bd2c-4591-ae70-a5700c1e89c3@u36g2000prg.googlegroups.com> On Jul 2, 12:07?pm, John Nagle wrote: > ? ? This has all been said before. Yes, we know. And when no one did anything about it the first dozen times it's been said, it wasn't because we didn't hear it, it was because we didn't care. We still don't care now, and won't care no matter how many times you repeat it, because it's simply wrong. So, please do everyone a favor, and stop wasting your own time, and stop repeating this. Carl Banks From tjreedy at udel.edu Fri Jul 2 17:13:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jul 2010 17:13:25 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 10:18 PM, Emile van Sebille wrote: > On 7/1/2010 6:17 PM Terry Reedy said... >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: >>> On 7/1/2010 2:52 PM Jay said... >>>> pywinauto looks to be almost perfect. All I need now is to read the >>>> numbers uncovered when a minesweeper square is clicked on, or that I >>>> just hit a mine. >>>> >>> >>> ... or, you could always win... >>> >>> http://www.daniweb.com/forums/thread186209.html >> >> Did you actually try it? Though skeptical, I did, briefly, until I >> decided that it probably should have been dated April 1. There is no way >> to enter text into minesweeper, nor to make it full screen, nor, as far >> as I know, for it to toggle pixels outside its window. >> > > Yes. It works. Thanks all. I tried again with other windows minimized so that the upper left pixel is medium brown from the wallpaper, and I can make out the white pixel. A maximized unfocued background window has that pixel normally black surrounded by light blue pixels that make one white pixel harder to see for imperfect eyes. Live, post errors, and learn ;-). -- Terry Jan Reedy From pavlovevidence at gmail.com Fri Jul 2 17:28:03 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 14:28:03 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> <4c2de6e6$0$40293$4fafbaef@reader2.news.tin.it> Message-ID: On Jul 2, 6:17?am, superpollo wrote: > Ethan Furman ha scritto: > > > > > Terry Reedy wrote: > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: > > >>> On 7/1/2010 2:52 PM Jay said... > > >>>> pywinauto looks to be almost perfect. All I need now is to read the > >>>> numbers uncovered when a minesweeper square is clicked on, or that I > >>>> just hit a mine. > > >>> ... or, you could always win... > > >>>http://www.daniweb.com/forums/thread186209.html > > >> Did you actually try it? Though skeptical, I did, briefly, until I > >> decided that it probably should have been dated April 1. There is no > >> way to enter text into minesweeper, nor to make it full screen, nor, > >> as far as I know, for it to toggle pixels outside its window. > > > The pixel can be hard to see depending on your background colors and > > whether your screen is adjusted correctly (I could see the white, but > > not the black). ?But on XP Pro is still works. > > works for me too I'm confirming that it even works with Wine emulator in Linux. Carl Banks From jaykoni at yahoo.com Fri Jul 2 17:38:03 2010 From: jaykoni at yahoo.com (Jay) Date: Fri, 2 Jul 2010 14:38:03 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> On Jul 2, 2:13?pm, Terry Reedy wrote: > On 7/1/2010 10:18 PM, Emile van Sebille wrote: > > > > > > > On 7/1/2010 6:17 PM Terry Reedy said... > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: > >>> On 7/1/2010 2:52 PM Jay said... > >>>> pywinauto looks to be almost perfect. All I need now is to read the > >>>> numbers uncovered when a minesweeper square is clicked on, or that I > >>>> just hit a mine. > > >>> ... or, you could always win... > > >>>http://www.daniweb.com/forums/thread186209.html > > >> Did you actually try it? Though skeptical, I did, briefly, until I > >> decided that it probably should have been dated April 1. There is no way > >> to enter text into minesweeper, nor to make it full screen, nor, as far > >> as I know, for it to toggle pixels outside its window. > > > Yes. It works. > > Thanks all. I tried again with other windows minimized so that the upper > left pixel is medium brown from the wallpaper, and I can make out the > white pixel. A maximized unfocued background window has that pixel > normally black surrounded by light blue pixels that make one white pixel > harder to see for imperfect eyes. ?Live, post errors, and learn ;-). > > -- > Terry Jan Reedy- Hide quoted text - > > - Show quoted text - OK, so how does a program read the pixel? From aahz at pythoncraft.com Fri Jul 2 18:00:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 15:00:17 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: In article <4C2E38F5.10708 at animats.com>, John Nagle wrote: > > 5. Get at least two major hosting services to put up Python 3. webfaction.com has python3.1 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From joshua.r.english at gmail.com Fri Jul 2 18:00:50 2010 From: joshua.r.english at gmail.com (Josh English) Date: Fri, 2 Jul 2010 15:00:50 -0700 (PDT) Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: <3bdebf16-cf60-4d91-8070-24d24c114b5f@q40g2000prg.googlegroups.com> On Jul 1, 3:30?pm, "Rhodri James" wrote: > > If this is a version of your code that actually fails when you run it ? > (rather than being another artistic interpretation of a photograph of your ? > code :-), then I'd go with Matt's analysis. ?This will give you a ? > NameError for fws_last_col if tracker.hasFWS() happens to return False for ? > all students. > Actually, tracker.hasFWS() was returning False for an entirely different reason that I didn't expect until I had the script dump all the information it was processing. Thanks for the clue. I added one parameter to one function elsewhere and the thing seems to be working again. Thanks for the help. Josh From pauljefferson at gmail.com Fri Jul 2 18:35:58 2010 From: pauljefferson at gmail.com (Paul) Date: Fri, 2 Jul 2010 15:35:58 -0700 (PDT) Subject: IMAP Problems Message-ID: <1fd46692-b796-409e-ad43-88b1b13ac804@y11g2000yqm.googlegroups.com> Hi, I'm trying to write a simple script which displays the basic details of a person's mailbox. My problem is that it causes all the messages to be marked as read on the server, which is not what I'm after, and I also can't get the imap.sort command to work properly (currently commented out as I replaced it with a imap.search to get the thing working. These are probably very simple things, but I've not tried this library before so am a bit stuck so any help wwould be very gratefully received. Thanks, Paul Code: # -*- coding: cp1252 -*- import imaplib,email # you want to connect to a server; specify which server server= imaplib.IMAP4_SSL('imap.googlemail.com') # after connecting, tell the server who you are server.login('xxxx at gmail.com', 'xxxxxxx') # this will show you a list of available folders # possibly your Inbox is called INBOX, but check the list of mailboxes code, mailboxen= server.list() print mailboxen # if it's called INBOX, then? server.select("INBOX") typ, data = server.search(None, 'ALL') #typ, data = server.sort("Date","UTF-8", 'ALL') print len(data[0].split()) for num in data[0].split(): typ, data = server.fetch(num, '(RFC822)') #print 'Message %s\n%s\n' % (num, data[0][1]) msg = email.message_from_string(data[0][1]) print msg["From"] print msg["Subject"] print msg["Date"] print "_______________________________" server.close() server.logout() From emile at fenx.com Fri Jul 2 18:52:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 02 Jul 2010 15:52:18 -0700 Subject: automate minesweeper with python In-Reply-To: <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> Message-ID: On 7/2/2010 2:38 PM Jay said... > > OK, so how does a program read the pixel? Well, you start with a screen capture utility. I'd check is pywinauto provides that access... Emile From ben+python at benfinney.id.au Fri Jul 2 19:23:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 03 Jul 2010 09:23:31 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> Message-ID: <87630xh3ik.fsf@benfinney.id.au> John Nagle writes: > Where's the business case for moving to Python 3? It's not faster. It's faster to learn, because there's less to learn. How do you know that it's not faster? That's a matter of the speed of individual Python implementations. What data do you have? > It doesn't do anything you can't do in Python 2.6. In the trivial sense that Python doesn't do anything you can't do in pure assembly language, that's true. In the more interesting sense of what can the *programmer* do, there are a number of improvements (dealing with Unicde more sanely; keyword-only arguments; function annotations; etc.) that can't be done in Python 2. That set will only grow over time. > How can a business justify spending money on conversion to Python > 3? You'll have to ask the ones that *have* justified that expense. There are major libraries that work with Python 3 now because people have been funded to work on getting there, and others are happening now. > What I'm not seeing is a deployment plan along these lines: > > 1. Identify key modules which must be converted before Python 3 > can be used in production environments. This needs to be done by those who want to use Python. You can't expect a single ?key modules? for the whole of the Python ecosystem. > 2. Get those modules converted to Python 3. Many of them have been converted, and many more are under active development. But this is entirely dependent on which libraries the specific use case demands. > 3. Put together a distribution for the major platforms (at least > Linux and Windows) with builds of those modules. The better path for the GNU distributions is to get the package distributed by the operating system distributor, instead of expecting every developer to also get the packaging right. Fortunately, for a great many key libraries, that's already the case in Debian which is a huge share of the ?major platforms?. > 4. Get some major distros, like Debian and ActiveState, to > include Python 3, as "python3", not as the primary Python, > so there are no conflicts. (Debian already has a formal > policy to keep Python versions separate.) You know this is already the case; why are you saying you don't see it? > 5. Get at least two major hosting services to put up Python 3. > > 6. Get at least two popular end-user programs (not modules) to > support Python 3. And how is this part of a plan for the PYthon developers? What are you suggesting they do to ?get [someone] to support Python 3?? That's up to the someone, surely? > 7. Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. Since you clearly don't count yourself in the set of ?Python 3 enthusiasts?, why do you keep demanding that they do something you expressly don't care about? -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From astroultraman at gmail.com Fri Jul 2 19:24:43 2010 From: astroultraman at gmail.com (Robert William Hanks) Date: Fri, 2 Jul 2010 20:24:43 -0300 Subject: why python don't support "extended slice direct assignment" for lists? Message-ID: why pure python don't support "extended slice direct assignment" for lists? today we have to write like this, >>> aList=[0,1,2,3,4,5,6,7,8,9] >>> aList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's not always possible >>> aList [None, 1, None, 3, None, 5, None, 7, None, 9] why not accept syntax like this for extended slice aList[::2] = None when let's say, the left side is a list and the right side is bool, int or float. the laborious [nunber]*len(aList[::2]) seens to me less readable when you want to set lost of items of a list to the same number. Also correct me if i am wrong, calling len() and building a list to this kind of operation seems a waste. Just want some feedback. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Jul 2 19:44:06 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 16:44:06 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4c2e79d3$0$1663$742ec2ed@news.sonic.net> On 7/2/2010 3:00 PM, Aahz wrote: > In article<4C2E38F5.10708 at animats.com>, John Nagle wrote: >> >> 5. Get at least two major hosting services to put up Python 3. > > webfaction.com has python3.1 WebFaction's big thing is that they have a really good system for installing anything the user wants. They're doing semi-virtual machine hosting, where each user sees a somewhat different environment, but doesn't have their own copy of the Linux kernel. That's a nice advance in server management. Any user can install Python 3.x, but it's not there by default. See: "http://blog.webfaction.com/python-3-0-is-here" If that approach catches on, Python 3 deployment will be much easier. But for now, only a few smaller players like WebFaction are using it. John Nagle From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 19:57:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 23:57:51 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: > Where's the business case for moving to Python 3? It's not faster. It > doesn't do anything you can't do in Python 2.6. There's no "killer app" > for it. End of life for Python 2.x is many years away; most server Linux > distros aren't even shipping with 2.6 yet. How can a business justify > spending money on conversion to Python 3? If you (generic you, not John specifically) can't, then don't. It's as simple as that. Stick with 2.6, or 2.7, or even 1.5 if that's the version you're using. A client of mine is still using 2.3. That's okay. It's allowed. If your business case is best satisfied by staying with 2.x until the sun burns out, more power to you. Just don't expect security upgrades (let alone functional upgrades) for more than a few years. If they are important to you, then *that's* your business case for upgrading. But if you're starting a new project, there is no cost of conversion. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 19:59:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 23:59:52 GMT Subject: Why defaultdict? References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c2e7d77$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 04:11:49 +0000, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. [...] Thanks to all who replied. -- Steven From anand.shashwat at gmail.com Fri Jul 2 20:02:31 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 3 Jul 2010 05:32:31 +0530 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: On Sat, Jul 3, 2010 at 4:54 AM, Robert William Hanks < astroultraman at gmail.com> wrote: > why pure python don't support "extended slice direct assignment" for lists? > > today we have to write like this, > > >>> aList=[0,1,2,3,4,5,6,7,8,9] > >>> aList > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's not > always possible > Can you show me a case where it really is cumbersome. > >>> aList > [None, 1, None, 3, None, 5, None, 7, None, 9] > > why not accept syntax like this for extended slice > > aList[::2] = None > > when let's say, the left side is a list and the right side is bool, int or > float. > the laborious [nunber]*len(aList[::2]) seens to me less readable when you > want to set lost of items of a list to the same number. > Also correct me if i am wrong, calling len() and building a list to this > kind of operation seems a waste. > >>> aList[::2] [0, 2, 4, 6, 8] Which means you are doing [0, 2, 4, 6, 8] = None, which is plain and simple - wrong. How will you define the legitimacy of this statement. What you are basically doing here is,, >>> [None]*len(aList[::2]) [None, None, None, None, None] >>> aList[::2] [0, 2, 4, 6, 8] Setting [0, 2, 4, 6, 8] to [None, None, None, None, None], thereby operating on two similar data structure (here list) > Just want some feedback. > Just my thoughts. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhijeet.thatte at gmail.com Fri Jul 2 20:17:36 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 2 Jul 2010 17:17:36 -0700 Subject: Sorting dicts inside dicts Message-ID: Hi, I have a huge dict structure like below: * {'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} * Module dict and reg_dicts contain many elements than shown. I want to sort this 'module' dictionary as per 'reg_addr' element in every 'reg_dict'. There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 can contain reg_address = 2000/72 (any number) I do not want output in a list format as the actual dict size is huge which I want to use based on key value pair. So, I want output as : * {'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} * * * Is it possible to sort the things? What I guess is Python stores dicts in a tree like structure but I am forcing it to store the way I want. Is it possible to do something like that. Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Jul 2 20:22:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 3 Jul 2010 05:52:46 +0530 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 3, 2010 at 5:27 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: > > > Where's the business case for moving to Python 3? It's not faster. It > > doesn't do anything you can't do in Python 2.6. There's no "killer app" > > for it. End of life for Python 2.x is many years away; most server Linux > > distros aren't even shipping with 2.6 yet. How can a business justify > > spending money on conversion to Python 3? > The point is python2.7 is the last 2.x version. It will be supported, bugs will be fixed but no new feature will be added. Core devs will concentrate on python 3.x. You can still use 2.x, no one is stopping you. But assume that it is stagnant now. After some time only security related bugs will be fixed. So if you want to wait by then, it's all your wish. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From googler.1.webmaster at spamgourmet.com Fri Jul 2 20:56:35 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 2 Jul 2010 17:56:35 -0700 (PDT) Subject: Crash in PyThread_acquire_lock Message-ID: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Hi all, I have a serious problem I want to solve. My app, where Python is embedded crashs on OSX (10.6 SL). I can reproduce the crash sometimes with a script that makes use of Python threads ( module: threading). 'thelock->locked' is for sure still locked, but I can't identify the problem. Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the crash in PyThread_acquire_lock is the following one: while ( thelock->locked ) { status = pthread_cond_wait(&thelock->lock_released, &thelock- >mut); <<<<<<<<<< >From the view of my code, I can exclude that the GIL was ensured but not properly released by PyStateGIL_Ensure and PyStateGIL_Release. Any ideas how to get rid of this crash somehow? Thanks in advance!! Bye, moerchendiser2k3 #0 0x00007fff86c95316 in __semwait_signal () #1 0x00007fff86c99131 in _pthread_cond_wait () #2 0x000000011c89f8f4 in PyThread_acquire_lock (lock=0x1013803c0, waitflag=1) at thread_pthread.h:452 #3 0x000000011c84a414 in PyEval_RestoreThread (tstate=0x101380200) at Python/ceval.c:334 #4 0x000000011c889725 in PyGILState_Ensure () at Python/pystate.c:592 From python at mrabarnett.plus.com Fri Jul 2 21:25:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jul 2010 02:25:14 +0100 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: <4C2E917A.1090807@mrabarnett.plus.com> Robert William Hanks wrote: > why pure python don't support "extended slice direct assignment" for lists? > > today we have to write like this, > > >>> aList=[0,1,2,3,4,5,6,7,8,9] > >>> aList > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's > not always possible > >>> aList > [None, 1, None, 3, None, 5, None, 7, None, 9] > > why not accept syntax like this for extended slice > > aList[::2] = None > > when let's say, the left side is a list and the right side is bool, int > or float. > the laborious [nunber]*len(aList[::2]) seens to me less readable when > you want to set lost of items of a list to the same number. > Also correct me if i am wrong, calling len() and building a list to this > kind of operation seems a waste. > > Just want some feedback. > When you're assigning to a list slice, why should it duplicate an int but not a list? Or in general, duplicate something that's not iterable but not something that is iterable? A string is iterable, so what should: >>> a[ : : 2] = "abcde" do? It's just simpler and less surprising the way it is. From aahz at pythoncraft.com Fri Jul 2 21:30:33 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 18:30:33 -0700 Subject: tp_richcompare vs tp_compare References: Message-ID: In article , moerchendiser2k3 wrote: > >Do I need to implement both? Looks very redundant, isnt it? Or is it >just an extension and tp_richcompare is the better choice here? Can >anyone please make the light on here? :) Nobody else responded, so please take this non-expert advice: tp_compare is the older and now deprecated slot; you want to use tp_richcompare if you don't need to support older versions of Python. Don't implement both. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From python at mrabarnett.plus.com Fri Jul 2 21:34:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jul 2010 02:34:52 +0100 Subject: Sorting dicts inside dicts In-Reply-To: References: Message-ID: <4C2E93BC.5010309@mrabarnett.plus.com> abhijeet thatte wrote: > Hi, > I have a huge dict structure like below: > /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ > > Module dict and reg_dicts contain many elements than shown. > > I want to sort this 'module' dictionary as per 'reg_addr' element in > every 'reg_dict'. > > There is no relation between 'reg_dict' suffix and address. So, > reg_dict_0 can contain reg_address = 2000/72 (any number) > I do not want output in a list format as the actual dict size is huge > which I want to use based on key value pair. > > So, I want output as : > > /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ > /* > */ > > Is it possible to sort the things? What I guess is Python stores dicts > in a tree like structure but I am forcing it to store the way I want. Is > it possible to do something like that. > Python dicts are implemented as hash tables, not trees, for speed, and they are unordered. If the order matters then you should use an ordered dict instead. You should be able to find an implementation of one. From aahz at pythoncraft.com Fri Jul 2 21:36:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 18:36:49 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c2e79d3$0$1663$742ec2ed@news.sonic.net> Message-ID: In article <4c2e79d3$0$1663$742ec2ed at news.sonic.net>, John Nagle wrote: >On 7/2/2010 3:00 PM, Aahz wrote: >> In article<4C2E38F5.10708 at animats.com>, John Nagle wrote: >>> >>> 5. Get at least two major hosting services to put up Python 3. >> >> webfaction.com has python3.1 > > Any user can install Python 3.x, but it's not there by default. Yes, it is. I logged into my webfaction shell, typed python3.1, and got a standard Python prompt, without doing anything whatsoever to make Python 3.1 available. > "http://blog.webfaction.com/python-3-0-is-here" Is there some reason you're using a broken URL format? > If that approach catches on, Python 3 deployment will be much easier. >But for now, only a few smaller players like WebFaction are using it. In the hosting space that makes Python available, WebFaction is hardly a smaller player. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From mmanns at gmx.net Fri Jul 2 21:53:07 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 3 Jul 2010 03:53:07 +0200 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? References: Message-ID: <20100703035307.7e5ae2d3@Knock> On Thu, 01 Jul 2010 14:48:47 -0400 python at bdurham.com wrote: > Curious if any of you are using GPG or PGP encryption and/or > signatures in your Python apps? ... > 4. generating signatures for files that you are exchanging/posting for > download? I use pyme to create and check save file signatures. > 5. what public keyring services are you using? None > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). pyme works great with Linux. However, I have never installed it on a Windows system. Martin From astroultraman at gmail.com Fri Jul 2 22:19:31 2010 From: astroultraman at gmail.com (Robert William Hanks) Date: Fri, 2 Jul 2010 23:19:31 -0300 Subject: why python don't support "extended slice direct assignment" for lists? Message-ID: to say is "wrong" i think is a bit too much, its just a different type of usage, this type of sintax is extensively used in numpy arrays (extended slice came from numerical python), just asking why not extend the sintax to python list. (not sure if you can use None as in the code i posted in numpy but numbers are ok). I was just rewriting some numpy code in pure python (no numpy for python3 yet), personally i think the pure python way is just ugly and more expensive. On Fri, Jul 2, 2010 at 10:55 PM, wrote: > 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: Why defaultdict? (Steven D'Aprano) > 2. Re: why python don't support "extended slice direct > assignment" for lists? (Shashwat Anand) > 3. Sorting dicts inside dicts (abhijeet thatte) > 4. Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") (Shashwat Anand) > 5. Crash in PyThread_acquire_lock (moerchendiser2k3) > 6. Re: why python don't support "extended slice direct > assignment" for lists? (MRAB) > 7. Re: Sorting dicts inside dicts (MRAB) > 8. Re: tp_richcompare vs tp_compare (Aahz) > 9. Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") (Aahz) > 10. Re: Anyone using GPG or PGP encryption/signatures in your > Python apps? (Martin Manns) > > > ---------- Forwarded message ---------- > From: Steven D'Aprano > To: python-list at python.org > Date: 02 Jul 2010 23:59:52 GMT > Subject: Re: Why defaultdict? > On Fri, 02 Jul 2010 04:11:49 +0000, Steven D'Aprano wrote: > > > I would like to better understand some of the design choices made in > > collections.defaultdict. > [...] > > > Thanks to all who replied. > > > -- > Steven > > > > > > ---------- Forwarded message ---------- > From: Shashwat Anand > To: Robert William Hanks > Date: Sat, 3 Jul 2010 05:32:31 +0530 > Subject: Re: why python don't support "extended slice direct assignment" > for lists? > > > On Sat, Jul 3, 2010 at 4:54 AM, Robert William Hanks < > astroultraman at gmail.com> wrote: > >> why pure python don't support "extended slice direct assignment" for >> lists? >> >> today we have to write like this, >> >> >>> aList=[0,1,2,3,4,5,6,7,8,9] >> >>> aList >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's >> not always possible >> > > Can you show me a case where it really is cumbersome. > > >> >>> aList >> [None, 1, None, 3, None, 5, None, 7, None, 9] >> >> why not accept syntax like this for extended slice >> >> aList[::2] = None >> >> when let's say, the left side is a list and the right side is bool, int or >> float. >> the laborious [nunber]*len(aList[::2]) seens to me less readable when you >> want to set lost of items of a list to the same number. >> Also correct me if i am wrong, calling len() and building a list to this >> kind of operation seems a waste. >> > > >>> aList[::2] > [0, 2, 4, 6, 8] > Which means you are doing [0, 2, 4, 6, 8] = None, which is plain and simple > - wrong. How will you define the legitimacy of this statement. > What you are basically doing here is,, > > >>> [None]*len(aList[::2]) > [None, None, None, None, None] > >>> aList[::2] > [0, 2, 4, 6, 8] > > Setting [0, 2, 4, 6, 8] to [None, None, None, None, None], thereby > operating on two similar data structure (here list) > > >> Just want some feedback. >> > > Just my thoughts. > > ~l0nwlf > > > > ---------- Forwarded message ---------- > From: abhijeet thatte > To: python-list at python.org > Date: Fri, 2 Jul 2010 17:17:36 -0700 > Subject: Sorting dicts inside dicts > Hi, > I have a huge dict structure like below: > * > {'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} > * > > Module dict and reg_dicts contain many elements than shown. > > I want to sort this 'module' dictionary as per 'reg_addr' element in every > 'reg_dict'. > > There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 > can contain reg_address = 2000/72 (any number) > I do not want output in a list format as the actual dict size is huge which > I want to use based on key value pair. > > So, I want output as : > > * > {'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} > * > * > * > > Is it possible to sort the things? What I guess is Python stores dicts in a > tree like structure but I am forcing it to store the way I want. Is it > possible to do something like that. > > Thanks, > > > > > ---------- Forwarded message ---------- > From: Shashwat Anand > To: "Steven D'Aprano" > Date: Sat, 3 Jul 2010 05:52:46 +0530 > Subject: Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") > > > On Sat, Jul 3, 2010 at 5:27 AM, Steven D'Aprano < > steve at remove-this-cybersource.com.au> wrote: > >> On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: >> >> > Where's the business case for moving to Python 3? It's not faster. It >> > doesn't do anything you can't do in Python 2.6. There's no "killer app" >> > for it. End of life for Python 2.x is many years away; most server Linux >> > distros aren't even shipping with 2.6 yet. How can a business justify >> > spending money on conversion to Python 3? >> > > The point is python2.7 is the last 2.x version. It will be supported, bugs > will be fixed but no new feature will be added. Core devs will concentrate > on python 3.x. You can still use 2.x, no one is stopping you. But assume > that it is stagnant now. After some time only security related bugs will be > fixed. So if you want to wait by then, it's all your wish. > > ~l0nwlf > > > ---------- Forwarded message ---------- > From: moerchendiser2k3 > To: python-list at python.org > Date: Fri, 2 Jul 2010 17:56:35 -0700 (PDT) > Subject: Crash in PyThread_acquire_lock > Hi all, > > I have a serious problem I want to solve. My app, where > Python is embedded crashs on OSX (10.6 SL). I can reproduce the crash > sometimes with a script that makes use of Python threads ( module: > threading). > > 'thelock->locked' is for sure still locked, but I can't identify the > problem. > Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the > crash > in PyThread_acquire_lock is the following one: > > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, &thelock- > >mut); <<<<<<<<<< > > >From the view of my code, I can exclude that the GIL was ensured but > not properly released > by PyStateGIL_Ensure and PyStateGIL_Release. > > Any ideas how to get rid of this crash somehow? Thanks in advance!! > > Bye, moerchendiser2k3 > > #0 0x00007fff86c95316 in __semwait_signal () > #1 0x00007fff86c99131 in _pthread_cond_wait () > #2 0x000000011c89f8f4 in PyThread_acquire_lock (lock=0x1013803c0, > waitflag=1) at thread_pthread.h:452 > #3 0x000000011c84a414 in PyEval_RestoreThread (tstate=0x101380200) at > Python/ceval.c:334 > #4 0x000000011c889725 in PyGILState_Ensure () at Python/pystate.c:592 > > > > > ---------- Forwarded message ---------- > From: MRAB > To: python-list at python.org > Date: Sat, 03 Jul 2010 02:25:14 +0100 > Subject: Re: why python don't support "extended slice direct assignment" > for lists? > Robert William Hanks wrote: > >> why pure python don't support "extended slice direct assignment" for >> lists? >> >> today we have to write like this, >> >> >>> aList=[0,1,2,3,4,5,6,7,8,9] >> >>> aList >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's >> not always possible >> >>> aList >> [None, 1, None, 3, None, 5, None, 7, None, 9] >> >> why not accept syntax like this for extended slice >> >> aList[::2] = None >> >> when let's say, the left side is a list and the right side is bool, int or >> float. >> the laborious [nunber]*len(aList[::2]) seens to me less readable when you >> want to set lost of items of a list to the same number. >> Also correct me if i am wrong, calling len() and building a list to this >> kind of operation seems a waste. >> >> Just want some feedback. >> >> When you're assigning to a list slice, why should it duplicate an int > but not a list? Or in general, duplicate something that's not iterable > but not something that is iterable? A string is iterable, so what > should: > > >>> a[ : : 2] = "abcde" > > do? > > It's just simpler and less surprising the way it is. > > > > ---------- Forwarded message ---------- > From: MRAB > To: python-list at python.org > Date: Sat, 03 Jul 2010 02:34:52 +0100 > Subject: Re: Sorting dicts inside dicts > abhijeet thatte wrote: > >> Hi, >> I have a huge dict structure like below: >> >> /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> >> Module dict and reg_dicts contain many elements than shown. >> I want to sort this 'module' dictionary as per 'reg_addr' element in every >> 'reg_dict'. >> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 >> can contain reg_address = 2000/72 (any number) >> I do not want output in a list format as the actual dict size is huge >> which I want to use based on key value pair. >> >> So, I want output as : >> >> >> /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> /* >> */ >> >> Is it possible to sort the things? What I guess is Python stores dicts in >> a tree like structure but I am forcing it to store the way I want. Is it >> possible to do something like that. >> >> Python dicts are implemented as hash tables, not trees, for speed, and > they are unordered. > > If the order matters then you should use an ordered dict instead. You > should be able to find an implementation of one. > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 2 Jul 2010 18:30:33 -0700 > Subject: Re: tp_richcompare vs tp_compare > In article < > d52edb82-4de5-496d-8807-b5d15ee66195 at i31g2000yqm.googlegroups.com>, > moerchendiser2k3 wrote: > > > >Do I need to implement both? Looks very redundant, isnt it? Or is it > >just an extension and tp_richcompare is the better choice here? Can > >anyone please make the light on here? :) > > Nobody else responded, so please take this non-expert advice: > > tp_compare is the older and now deprecated slot; you want to use > tp_richcompare if you don't need to support older versions of Python. > Don't implement both. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you don't know what your program is supposed to do, you'd better not > start writing it." --Dijkstra > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 2 Jul 2010 18:36:49 -0700 > Subject: Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") > In article <4c2e79d3$0$1663$742ec2ed at news.sonic.net>, > John Nagle wrote: > >On 7/2/2010 3:00 PM, Aahz wrote: > >> In article<4C2E38F5.10708 at animats.com>, John Nagle > wrote: > >>> > >>> 5. Get at least two major hosting services to put up Python 3. > >> > >> webfaction.com has python3.1 > > > > Any user can install Python 3.x, but it's not there by default. > > Yes, it is. I logged into my webfaction shell, typed python3.1, and got > a standard Python prompt, without doing anything whatsoever to make > Python 3.1 available. > > > "http://blog.webfaction.com/python-3-0-is-here" > > Is there some reason you're using a broken URL format? > > > If that approach catches on, Python 3 deployment will be much easier. > >But for now, only a few smaller players like WebFaction are using it. > > In the hosting space that makes Python available, WebFaction is hardly a > smaller player. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you don't know what your program is supposed to do, you'd better not > start writing it." --Dijkstra > > > > ---------- Forwarded message ---------- > From: Martin Manns > To: python-list at python.org > Date: Sat, 3 Jul 2010 03:53:07 +0200 > Subject: Re: Anyone using GPG or PGP encryption/signatures in your Python > apps? > On Thu, 01 Jul 2010 14:48:47 -0400 > python at bdurham.com wrote: > > > Curious if any of you are using GPG or PGP encryption and/or > > signatures in your Python apps? > ... > > 4. generating signatures for files that you are exchanging/posting for > > download? > > I use pyme to create and check save file signatures. > > > 5. what public keyring services are you using? > > None > > > Any comments on using the subprocess module to wrap the gpg or openssl > > command line utilities? This seems to be a common technique for > > encryption and signing solutions and appears to the technique used by > > python-gnupg (for example). > > pyme works great with Linux. > However, I have never installed it on a Windows system. > > Martin > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Jul 2 22:20:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 03 Jul 2010 14:20:26 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: In message , Rami Chowdhury wrote: > On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > >> Nevertheless, it it at least self-consistent. To return to my original >> macro: >> >> #define Descr(v) &v, sizeof v >> >> As written, this works whatever the type of v: array, struct, whatever. > > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly > modified... > > char *buf = malloc(512 * sizeof(char)); Again, you misunderstand the difference between a C array and a pointer. Study the following example, which does work, and you might grasp the point: ldo at theon:hack> cat test.c #include int main(int argc, char ** argv) { char buf[512]; const int a = 2, b = 3; snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); fprintf(stdout, buf); return 0; } /*main*/ ldo at theon:hack> ./test 2 + 3 = 5 From clp2 at rebertia.com Fri Jul 2 22:43:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Jul 2010 19:43:01 -0700 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: On Fri, Jul 2, 2010 at 7:19 PM, Robert William Hanks wrote: > to say is "wrong" i think is a bit too much, its just a different type of > usage, this type of sintax is extensively used in numpy arrays (extended > slice came from numerical python), just asking why not extend the sintax to > python list. (not sure if you can use None as in the code i posted in numpy > but numbers are ok). I was just rewriting some numpy code in pure python (no > numpy for python3 yet), personally i think the pure python way is just ugly > and more expensive. > > On Fri, Jul 2, 2010 at 10:55 PM, wrote: >> >> 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: Please avoid replying to the list digest, especially without trimming, as it adds noise to the conversation (and can screw up threading). Cheers, Chris From rami.chowdhury at gmail.com Fri Jul 2 23:07:24 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 2 Jul 2010 20:07:24 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <201007022007.24308.rami.chowdhury@gmail.com> On Friday 02 July 2010 19:20:26 Lawrence D'Oliveiro wrote: > In message , Rami > Chowdhury wrote: > > On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > >> Nevertheless, it it at least self-consistent. To return to my original > >> > >> macro: > >> #define Descr(v) &v, sizeof v > >> > >> As written, this works whatever the type of v: array, struct, whatever. > > > > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly > > modified... > > > > char *buf = malloc(512 * sizeof(char)); > > Again, you misunderstand the difference between a C array and a pointer. > Study the following example, which does work, and you might grasp the > point: > > ldo at theon:hack> cat test.c > #include > > int main(int argc, char ** argv) > { > char buf[512]; > const int a = 2, b = 3; > snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); > fprintf(stdout, buf); > return > 0; > } /*main*/ > ldo at theon:hack> ./test > 2 + 3 = 5 I'm sorry, perhaps you've misunderstood what I was refuting. You posted: > >> macro: > >> #define Descr(v) &v, sizeof v > >> > >> As written, this works whatever the type of v: array, struct, whatever. With my code example I found that, as others have pointed out, unfortunately it doesn't work if v is a pointer to a heap-allocated area. ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From cournape at gmail.com Fri Jul 2 23:09:45 2010 From: cournape at gmail.com (David Cournapeau) Date: Sat, 3 Jul 2010 12:09:45 +0900 Subject: Why Is Escaping Data Considered So Magical? In-Reply-To: <88r8n4Fn3qU1@mid.individual.net> References: <69c2e25c-f4d1-4a60-bda3-1b7a8e99a216@j4g2000yqh.googlegroups.com> <88r8n4Fn3qU1@mid.individual.net> Message-ID: On Mon, Jun 28, 2010 at 6:44 PM, Gregory Ewing wrote: > Carl Banks wrote: > >> Indeed, strncpy does not copy that final NUL if it's at or beyond the >> nth element. ?Probably the most mind-bogglingly stupid thing about the >> standard C library, which has lots of mind-boggling stupidity. > > I don't think it was as stupid as that back when C was > designed Actually, strncpy had a very specific use case when it was introduced (dealing with limited-size entries in very old unix filesystem). It should never be used for C string handling, and I don't think it is fair to say it is stupid: it does exactly what it was designed for. It just happens that most people don't know what it was designed for. David From tjreedy at udel.edu Fri Jul 2 23:50:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jul 2010 23:50:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: On 7/2/2010 3:07 PM, John Nagle wrote: > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? It's not faster. > It doesn't do anything you can't do in Python 2.6. False. One cannot run code in 2.6 that depends on bugfixes in 3.1. Nor can one run code with unicode identifiers. The exclusive new features in 3.1 and 3.2 are less than they might have been because the developers expended extra effort, now ended, to backport new things developed for 3.x. (One result was some neglect of the stdlib, which is now the focus of efforts.) One reason was to make porting to 3.x easier should one wish to do so. The other reason was to make some thing available should one wish not to do so. Using that extra effort as a reason to put down 3.x is not very gracious. > There's no "killer app" for it. For some, unicode identifiers are 'killer reason' to use 3.1. Anyway, can you name me a "killer app" for each and every version of 2.x? > End of life for Python 2.x is many years away; Given that 1.x is still used, so what? > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? How can a business justify spending money on conversion to 2.0, 2,1, 2.2, 2.3, 2.4, 2.5, 2.6, or soon, 2.7? Some cannot for some projects and have not. Enough with strawman arguments against claims no sensible person has made. Python3 was developed for new Python programmers and current programmers who wished to add or switch. It was developed for new code and old code that would benefit from the changes. -- Terry Jan Reedy From darcy at druid.net Sat Jul 3 00:10:22 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 00:10:22 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <20100703001022.c8676aa6.darcy@druid.net> On 2 Jul 2010 15:00:17 -0700 aahz at pythoncraft.com (Aahz) wrote: > > 5. Get at least two major hosting services to put up Python 3. > > webfaction.com has python3.1 So does http://www.Vex.Net/ so there's your two. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From me+list/python at ixokai.io Sat Jul 3 01:31:36 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 22:31:36 -0700 Subject: Decorators, with optional arguments In-Reply-To: <4C2E361E.3080602@jollans.com> References: <4C2E24AD.3040002@ixokai.io> <4C2E361E.3080602@jollans.com> Message-ID: <4C2ECB38.9000504@ixokai.io> On 7/2/10 11:55 AM, Thomas Jollans wrote: > Looks good! You may still want to use functools.update_wrapper or > functools.wraps on "wrap". Are you sure? I've been doing a little bit of experimentation and I only did the 'wraps' on that inner function, because it seemed that it was all that was needed to get the propagation of function data I expected. I've since changed it to: def wrapper(fn, *args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return decorator.decorator(wrapper, fn) Because the decorator library includes argspec propagation which was important for other parts of this code which does introspection. (This toy project is, I fully admit, going into very dark and evil places that I have at length advised people against, 'You don't want to do that!'). > PS: if you weren't stuck on 2.5, but were using 3.x, there's all kinds > of fun stuff you could do with function annotations ;-) Oh, believe me, I desperately wish I could go to 3.x. Between function annotations and the new metaclass power (Hi, __prepare__, I love you, please wait for me and I'll marry you when I migrate). I just can't yet. I can't quite figure out why people are all, '3.x brings you nothing'. Yes, the majority of the focus was cleaning, removing edges, but *lord* there's a LOT I am VERY looking forward to using. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Jul 3 01:37:00 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 22:37:00 -0700 Subject: Decorators, with optional arguments In-Reply-To: References: Message-ID: <4C2ECC7C.5000107@ixokai.io> On 7/2/10 11:58 AM, Alf P. Steinbach /Usenet wrote: > > #Py3 I'm stuck on Python 2.x, as I mentioned (albeit only in a comment). That said this code does not seem to be including any Py3isms that aren't compatible. > class Thing(object): > @expose() > def test1(self, arg1): > return arg1 > > @expose( "testing" ) > def test2(self, arg2): > return arg2 Its the @expose() which bugs me. I have some decorators (made by me and others) which have no args, that look like @hello. Then some which always have args, that look like @hello("whatsup dude"). To then have a decorator which has no args as @hello(), I can't abide. For internal consistancy purposes, I want "no arguments" to always look like @hello, and "arguments" to look like @hello(something). I don't want to have to think, "Hey, does this no-arg version require parens or no?" -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From nagle at animats.com Sat Jul 3 01:40:34 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 22:40:34 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4C2ECD52.5040005@animats.com> On 7/2/2010 9:10 PM, D'Arcy J.M. Cain wrote: > On 2 Jul 2010 15:00:17 -0700 > aahz at pythoncraft.com (Aahz) wrote: >>> 5. Get at least two major hosting services to put up Python 3. >> >> webfaction.com has python3.1 > > So does http://www.Vex.Net/ so there's your two. Not according to Vex's published package list: http://www.vex.net/info/tech/pkglist/ They list packages only for Python 2.6. "vex.net" isn't exactly a major hosting service. John Nagle From nanothermite911fbibustards at gmail.com Sat Jul 3 03:16:30 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Sat, 3 Jul 2010 00:16:30 -0700 (PDT) Subject: Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. A CHRISTIAN VIEW OF THE HOLOCAUST Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. It was made a short time ago before a large group in the Congressional `Room of the Willard Hotel in Washington, D.C. Both the speech and the question and answer period later so electrified the audience that a group of patriots has transferred it to two long-playing records which you may buy to play for friends, clubs, and your church group in your community. The speaker is Mr. Benjamin Freedman, noted authority on Zionism and all of its schemes. Mr. Freedman is a former Jew, and I mean a FORMER Jew. He has fought the Communist world conspiracy tooth and nail, and stands today as a leading American patriot. We now take you to the speaker's platform to present Benjamin Freedman. (applause) [Freedman's speech] What I intend to tell you tonight is something that you have never been able to learn from any other source, and what I tell you now concerns not only you, but your children and the survival of this country and Christianity. I'm not here just to dish up a few facts to send up your blood pressure, but I'm here to tell you things that will help you preserve what you consider the most sacred things in the world: the liberty, and the freedom, and the right to live as Christians, where you have a little dignity, and a little right to pursue the things that your conscience tells you are the right things, as Christians. Now, first of all, I'd like to tell you that on August 25th 1960 -- that was shortly before elections -- Senator Kennedy, who is now the President of the United States, went to New York, and delivered an address to the Zionist Organization of America. In that address, to reduce it to its briefest form, he stated that he would use the armed forces of the United States to preserve the existence of the regime set up in Palestine by the Zionists who are now in occupation of that area. In other words, Christian boys are going to be yanked out of their homes, away from their families, and sent abroad to fight in Palestine against the Christian and Moslem Arabs who merely want to return to their homes. And these Christian boys are going to be asked to shoot to kill these innocent [Arab Palestinians] people who only want to follow out fifteen resolutions passed by the United Nations in the last twelve years calling upon the Zionists to allow these people to return to their homes. Now, when United States troops appear in the Middle East to fight with the Zionists as their allies to prevent the return of these people who were evicted from their homes in the 1948 armed insurrection by the Zionists who were transplanted there from Eastern Europe... when that happens, the United States will trigger World War III. You say, when will that take place? The answer is, as soon as the difficulty between France and Algeria has been settled, that will take place. As soon as France and Algeria have been settled, that will take place. As soon as France and Algeria have settled their difficulty, and the Arab world, or the Moslem world, has no more war on their hands with France, they are going to move these people back into their homes, and when they do that and President kennedy sends your sons to fight over there to help the crooks hold on to what they stole from innocent men, women and children, we will trigger World War III; and when that starts you can be sure we cannot emerge from that war a victor. We are going to lose that war because there is not one nation in the world that will let one of their sons fight with us for such a cause. I know and speak to these ambassadors in Washington and the United Nations -- and of the ninety-nine nations there, I've consulted with maybe seventy of them -- and when we go to war in Palestine to help the thieves retain possession of what they have stolen from these innocent people we're not going to have a man there to fight with us as our ally. And who will these people have supporting them, you ask. Well, four days after President Kennedy -- or he was then Senator Kennedy -- made that statement on August 28, 1960, the Arab nations called a meeting in Lebanon and there they decided to resurrect, or reactivate, the government of Palestine, which has been dormant more or less, since the 1948 armed insurrection by the Zionists. Not only that... they ordered the creation of the Palestine Army, and they are now drilling maybe a half a million soldiers in that area of the world to lead these people back to their homeland. With them, they have as their allies all the nations of what is termed the Bandung Conference Group. That includes the Soviet Union and every Soviet Union satellite. It includes Red China; it includes every independent country in Asia and Africa; or eighty percent of the world's total population. Eighty percent of the world's population. Four out of five human beings on the face of the earth will be our enemies at war with us. And not alone are they four out of five human beings now on the face of this earth, but they are the non-Christian population of the world and they are the non-Caucasians... the non- white nations of the world, and that's what we face. And what is the reason? The reason is that here in the United States, the Zionists and their co-religionists have complete control of our government. For many reasons too many and too complex to go into here at this -- time I'll be glad to answer questions, however, to support that statement -- the Zionists and their co-religionists rule this United States as though they were the absolute monarchs of this country. Now, you say, 'well, that's a very broad statement to make', but let me show what happened while you were -- I don't want to wear that out --- let me show what happened while WE were all asleep. I'm including myself with you. We were all asleep. What happened? World War I broke out in the summer of 1914. Nineteen-hundred and fourteen was the year in which World War One broke out. There are few people here my age who remember that. Now that war was waged on one side by Great Britain, France, and Russia; and on the other side by Germany, Austria-Hungary, and Turkey. What happened? Within two years Germany had won that war: not alone won it nominally, but won it actually. The German submarines, which were a surprise to the world, had swept all the convoys from the Atlantic Ocean, and Great Britain stood there without ammunition for her soldiers, stood there with one week's food supply facing her -- and after that, starvation. At that time, the French army had mutinied. They lost 600,000 of the flower of French youth in the defense of Verdun on the Somme. The Russian army was defecting. They were picking up their toys and going home, they didn't want to play war anymore, they didn't like the Czar. And the Italian army had collapsed. Now Germany -- not a shot had been fired on the German soil. Not an enemy soldier had crossed the border into Germany. And yet, here was Germany offering England peace terms. They offered England a negotiated peace on what the lawyers call a status quo ante basis. That means: ?Let's call the war off, and let everything be as it was before the war started.? Well, England, in the summer of 1916 was considering that. Seriously! They had no choice. It was either accepting this negotiated peace that Germany was magnanimously offering them, or going on with the war and being totally defeated. While that was going on, the Zionists in Germany, who represented the Zionists from Eastern Europe, went to the British War Cabinet and -- I am going to be brief because this is a long story, but I have all the documents to prove any statement that I make if anyone here is curious, or doesn't believe what I'm saying is at all possible -- the Zionists in London went to the British war cabinet and they said: ?Look here. You can yet win this war. You don't have to give up. You don't have to accept the negotiated peace offered to you now by Germany. You can win this war if the United States will come in as your ally.? The United States was not in the war at that time. We were fresh; we were young; we were rich; we were powerful. They [Zionists] told England: ?We will guarantee to bring the United States into the war as your ally, to fight with you on your side, if you will promise us Palestine after you win the war.? In other words, they made this deal: ?We will get the United States into this war as your ally. The price you must pay us is Palestine after you have won the war and defeated Germany, Austria- Hungary, and Turkey.? Now England had as much right to promise Palestine to anybody, as the United States would have to promise Japan to Ireland for any reason whatsoever. It's absolutely absurd that Great Britain -- that never had any connection or any interest or any right in what is known as Palestine -- should offer it as coin of the realm to pay the Zionists for bringing the United States into the war. However, they made that promise, in October of 1916. October, nineteen hundred and sixteen. And shortly after that -- I don't know how many here remember it -- the United States, which was almost totally pro-German -- totally pro-German -- because the newspapers here were controlled by Jews, the bankers were Jews, all the media of mass communications in this country were controlled by Jews, and they were pro-German because their people, in the majority of cases came from Germany, and they wanted to see Germany lick the Czar. The Jews didn't like the Czar, and they didn't want Russia to win this war. So the German bankers -- the German-Jews -- Kuhn Loeb and the other big banking firms in the United States refused to finance France or England to the extent of one dollar. They stood aside and they said: ?As long as France and England are tied up with Russia, not one cent!? But they poured money into Germany, they fought with Germany against Russia, trying to lick the Czarist regime. Now those same Jews, when they saw the possibility of getting Palestine, they went to England and they made this deal. At that time, everything changed, like the traffic light that changes from red to green. Where the newspapers had been all pro-German, where they'd been telling the people of the difficulties that Germany was having fighting Great Britain commercially and in other respects, all of a sudden the Germans were no good. They were villains. They were Huns. They were shooting Red Cross nurses. They were cutting off babies' hands. And they were no good. Well, shortly after that, Mr. Wilson declared war on Germany. The Zionists in London sent these cables to the United States, to Justice Brandeis: ?Go to work on President Wilson. We're getting from England what we want. Now you go to work, and you go to work on President Wilson and get the United States into the war." And that did happen. That's how the United States got into the war. We had no more interest in it; we had no more right to be in it than we have to be on the moon tonight instead of in this room. Now the war -- World War One -- in which the United States participated had absolutely no reason to be our war. We went in there -- we were railroaded into it -- if I can be vulgar, we were suckered into -- that war merely so that the Zionists of the world could obtain Palestine. Now, that is something that the people in the United States have never been told. They never knew why we went into World War One. Now, what happened? After we got into the war, the Zionists went to Great Britain and they said: ?Well, we performed our part of the agreement. Let's have something in writing that shows that you are going to keep your bargain and give us Palestine after you win the war.? Because they didn't know whether the war would last another year or another ten years. So they started to work out a receipt. The receipt took the form of a letter, and it was worded in very cryptic language so that the world at large wouldn't know what it was all about. And that was called the Balfour Declaration. The Balfour Declaration was merely Great Britain's promise to pay the Zionists what they had agreed upon as a consideration for getting the United States into the war. So this great Balfour Declaration, that you hear so much about, is just as phony as a three dollar bill. And I don't think I could make it more emphatic than that. Now, that is where all the trouble started. The United States went in the war. The United States crushed Germany. We went in there, and it's history. You know what happened. Now, when the war was ended, and the Germans went to Paris, to the Paris Peace Conference in 1919, there were 117 Jews there, as a delegation representing the Jews, headed by Bernard Baruch. I was there: I ought to know. Now what happened? The Jews at that peace conference, when they were cutting up Germany and parceling out Europe to all these nations that claimed a right to a certain part of European territory, the Jews said, ?How about Palestine for us?? And they produced, for the first time to the knowledge of the Germans, this Balfour Declaration. So the Germans, for the first time realized, ?Oh, that was the game! That's why the United States came into the war.? And the Germans for the first time realized that they were defeated, they suffered this terrific reparation that was slapped onto them, because the Zionists wanted Palestine and they were determined to get it at any cost. Now, that brings us to another very interesting point. When the Germans realized this, they naturally resented it. Up to that time, the Jews had never been better off in any country in the world than they had been in Germany. You had Mr. Rathenau there, who was maybe 100 times as important in industry and finance as is Bernard Baruch in this country. You had Mr. Balin, who owned the two big steamship lines, the North German Lloyd's and the Hamburg-American Lines. You had Mr. Bleichroder, who was the banker for the Hohenzollern family. You had the Warburgs in Hamburg, who were the big merchant bankers -- the biggest in the world. The Jews were doing very well in Germany. No question about that. Now, the Germans felt: ?Well, that was quite a sellout.? It was a sellout that I can best compare -- suppose the United States was at war today with the Soviet Union. And we were winning. And we told the Soviet Union: ?Well, let's quit. We offer you peace terms. Let's forget the whole thing.? And all of a sudden Red China came into the war as an ally of the Soviet Union. And throwing them into the war brought about our defeat. A crushing defeat, with reparations the likes of which man's imagination cannot encompass. Imagine, then, after that defeat, if we found out that it was the Chinese in this country, our Chinese citizens, who all the time we thought they were loyal citizens working with us, were selling us out to the Soviet Union and that it was through them that Red China was brought into the war against us. How would we feel, in the United States against Chinese? I don't think that one of them would dare show his face on any street. There wouldn't be lampposts enough, convenient, to take care of them. Imagine how we would feel. Well, that's how the Germans felt towards these Jews. "We've been so nice to them"; and from 1905 on, when the first Communist revolution in Russia failed, and the Jews had to scramble out of Russia, they all went to Germany. And Germany gave them refuge. And they were treated very nicely. And here they sold Germany down the river for no reason at all other than they wanted Palestine as a so- called ?Jewish commonwealth.? Now, Nahum Sokolow -- all the great leaders, the big names that you read about in connection with Zionism today -- they, in 1919, 1920, '21, '22, and '23, they wrote in all their papers -- and the press was filled with their statements -- that "the feeling against the Jews in Germany is due to the fact that they realized that this great defeat was brought about by our intercession and bringing the United States into the war against them." The Jews themselves admitted that. It wasn't that the Germans in 1919 discovered that a glass of Jewish blood tasted better than Coca- Cola or Muenschner Beer. There was no religious feeling. There was no sentiment against those people merely on account of their religious belief. It was all political. It was economic. It was anything but religious. Nobody cared in Germany whether a Jew went home and pulled down the shades and said ?Shema' Yisrael? or ?Our Father.? No one cared in Germany any more than they do in the United States. Now this feeling that developed later in Germany was due to one thing: that the Germans held the Jews responsible for their crushing defeat, for no reason at all, because World War One was started against Germany for no reason for which they [Germans] were responsible. They were guilty of nothing. Only of being successful. They built up a big navy. They built up world trade. You must remember, Germany, at the time of Napoleon, at the time of the French Revolution, what was the German Reich consisted of 300 -- three hundred! -- small city-states, principalities, dukedoms, and so forth. Three hundred little separate political entities. And between that time, between the period of. . . between Napoleon and Bismarck, they were consolidated into one state. And within 50 years after that time they became one of the world's great powers. Their navy was rivalling Great Britain's, they were doing business all over the world, they could undersell anybody and make better products. And what happened? What happened as a result of that? There was a conspiracy between England, France, and Russia that: "We must slap down Germany", because there isn't one historian in the world that can find a valid reason why those three countries decided to wipe Germany off the map politically. Now, what happened after that? When Germany realized that the Jews were responsible for her defeat, they naturally resented it. But not a hair on the head of any Jew was harmed. Not a single hair. Professor Tansill, of Georgetown University, who had access to all the secret papers of the State Department, wrote in his book, and quoted from a State Department document written by Hugo Schoenfelt, a Jew who Cordell Hull sent to Europe in 1933 to investigate the so-called camps of political prisoners. And he wrote back that he found them in very fine condition. They were in excellent shape; everybody treated well. And they were filled with Communists. Well, a lot of them were Jews, because the Jews happened to be maybe 98 per cent of the Communists in Europe at that time. And there were some priests there, and ministers, and labor leaders, Masons, and others who had international affiliations. Now, the Jews sort of tried to keep the lid on this fact. They didn't want the world to really understand that they had sold out Germany, and that the Germans resented that. So they did take appropriate action against them [against the Jews]. They. . . shall I say, discriminated against them wherever they could? They shunned them. The same as we would the Chinese, or the Negroes, or the Catholics, or anyone in this country who had sold us out to an enemy and brought about our defeat. Now, after a while, the Jews of the world didn't know what to do, so they called a meeting in Amsterdam. Jews from every country in the world attended in July 1933. And they said to Germany: ?You fire Hitler! And you put every Jew back into his former position, whether he was a Communist, no matter what he was. You can't treat us that way! And we, the Jews of the world, are calling upon you, and serving this ultimatum upon you.? Well, the Germans told them. . . you can imagine. So what did they [the Jews] do? They broke up, and Samuel Untermyer, if the name means anything to people here. . . (You want to ask a question? --- Uh, there were no Communists in Germany at that time. they were called 'Social Democrats.) Well, I don't want to go by what they were called. We're now using English words, and what they were called in Germany is not very material. . . but they were Communists, because in 1917, the Communists took over Germany for a few days. Rosa Luxembourg and Karl Liebknecht, and a group of Jews in Germany took over the government for three days. In fact, when the Kaiser ended the war, he fled to Holland because he thought the Communists were going to take over Germany as they did Russia, and that he was going to meet the same fate that the Czar did in Russia. So he left and went to Holland for safety and for security. Now, at that time, when the Communist threat in Germany was quashed, it was quiet, the Jews were working, still trying to get back into their former -- their status -- and the Germans fought them in every way they could, without hurting a hair on anyone's head. The same as one group, the Prohibitionists, fought the people who were interested in liquor, and they didn't fight one another with pistols, they did it every way they could. Well, that's the way they were fighting the Jews in Germany. And, at that time, mind you, there were 80 to 90 million Germans and there were only 460,000 Jews. . . less than one half of one percent of Germany were Jews. And yet, they controlled all of the press, they controlled most of the economy, because they had come in and with cheap money -- you know the way the Mark was devalued -- they bought up practically everything. Well, in 1933 when Germany refused to surrender, mind you, to the World Conference of Jews in Amsterdam, they broke up and Mr. Untermeyer came back to the United States -- who was the head of the American delegation and the president of the whole conference -- and he went from the steamer to ABC and made a radio broadcast throughout the United States in which he said: "The Jews of the world now declare a Holy War against Germany. We are now engaged in a sacred conflict against the Germans. And we are going to starve them into surrender. We are going to use a world-wide boycott against them, that will destroy them because they are dependent upon their export business." And it is a fact that two thirds of Germany's food supply had to be imported, and it could only be imported with the proceeds of what they exported. Their labor. So if Germany could not export, two thirds of Germany's population would have to starve. There just was not enough food for more than one third of the population. Now in this declaration, which I have here, it was printed on page -- a whole page -- in the New York Times on August 7, 1933, Mr. Samuel Untermyer boldly stated that: ?this economic boycott is our means of self-defense. President Roosevelt has advocated its use in the NRA" . [National Recovery Administration] -- which some of you may remember, where everybody was to be boycotted unless they followed the rules laid down by the New Deal, which of course was declared unconstitutional by the Supreme Court at that time. Nevertheless, the Jews of the world declared a boycott against Germany, and it was so effective that you couldn't find one thing in any store anywhere in the world with the words "made in Germany" on it. In fact, an executive of the Woolworth Company told me that they had to dump millions of dollars worth of crockery and dishes into the river; that their stores were boycotted. If anyone came in and found a dish marked "made in Germany," they were picketed with signs: "Hitler", "murderer", and so forth, and like -- something like these sit-ins that are taking place in the South. R. H. Macy, which is controlled by a family called Strauss who also happen to be Jews. . . a woman found stockings there which came from Chemnitz, marked "made in Germany". Well, they were cotton stockings. They may have been there 20 years, because since I've been observing women's legs in the last twenty years, I haven't seen a pair with cotton stockings on them. So Macy! I saw Macy boycotted, with hundreds of people walking around with signs saying "MURDERS" and "HITLERITES", and so forth. Now up to that time, not one hair on the head of any Jew had been hurt in Germany. There was no suffering, there was no starvation, there was no murder, there was nothing. Now, that. . . naturally, the Germans said, "Why, who are these people to declare a boycott against us and throw all our people out of work, and our industries come to a standstill? Who are they to do that to us?" They naturally resented it. Certainly they painted swastikas on stores owned by Jews. Why should a German go in and give their money to a storekeeper who was part of a boycott who was going to starve Germany into surrender into the Jews of the world, who were going to dictate who their premier or chancellor was to be? Well, it was ridiculous. That continued for some time, and it wasn't until 1938, when a young Jew from Poland walked into the German embassy in Paris and shot one of the officials [a German official] that the Germans really started to get rough with the Jews in Germany. And you found them then breaking windows and having street fights and so forth. Now, for anyone to say that -- I don't like to use the word 'anti-Semitism' because it's meaningless, but it means something to you still, so I'll have to use it -- the only reason that there was any feeling in Germany against Jews was that they were responsible: number one, for World War One; number two, for this world-wide boycott, and number three -- did I say for World War One, they were responsible? For the boycott -- and also for World War II, because after this thing got out of hand, it was absolutely necessary for the Jews and Germany to lock horns in a war to see which one was going to survive. In the meanwhile, I had lived in Germany, and I knew that the Germans had decided [that] Europe is going to be Christian or Communist: there is no in between. It's going to be Christian or it's going to be Communist. And the Germans decided: "We're going to keep it Christian if possible". And they started to re-arm. And there intention was -- by that time the United States had recognized the Soviet Union, which they did in November, 1933 -- the Soviet Union was becoming very powerful, and Germany realized: "Well, our turn is going to come soon, unless we are strong." The same as we in this country are saying today, "Our turn is going to come soon, unless we are strong." And our government is spending 83 or 84 billion dollars of your money for defense, they say. Defense against whom? Defense against 40,000 little Jews in Moscow that took over Russia, and then, in their devious ways, took over control of many other governments of the world. Now, for this country to now be on the verge of a Third World War, from which we cannot emerge a victor, is something that staggers my imagination. I know that nuclear bombs are measured in terms of megatons. A megaton is a term used to describe one million tons of TNT. One million tons of TNT is a megaton. Now, our nuclear bombs have a capacity of 10 megatons, or 10 million tons of TNT. That was when they were first developed five or six years ago. Now, the nuclear bombs that are being developed have a capacity of 200 megatons, and God knows how many megatons the nuclear bombs of the Soviet Union have. So, what do we face now? If we trigger a world war that may develop into a nuclear war, humanity is finished. And why will it take place? It will take place because Act III. . . the curtain goes up on Act III. Act I was World War I. Act II was World War II. Act III is going to be World War III. The Jews of the world, the Zionists and their co-religionists everywhere, are determined that they are going to again use the United States to help them permanently retain Palestine as their foothold for their world government. Now, that is just as true as I am standing here, because not alone have I read it, but many here have read it, and it's known all over the world. Now, what are we going to do? The life you save may be your son's. Your boys may be on their way to that war tonight; and you you don't know it any more than you knew that in 1916 in London the Zionists made a deal with the British War Cabinet to send your sons to war in Europe. Did you know it at that time? Not a person in the United States knew it. You weren't permitted to know it. Who knew it? President Wilson knew it. Colonel House knew it. Other 's knew it. Did I know it? I had a pretty good idea of what was going on: I was liaison to Henry Morgenthau, Sr., in the 1912 campaign when President Wilson was elected, and there was talk around the office there. I was 'confidential man' to Henry Morgenthau, Sr., who was chairman of the Finance Committee, and I was liaison between him and Rollo Wells, the treasurer. So I sat in these meetings with President Wilson at the head of the table, and all the others, and I heard them drum into President Wilson's brain the graduated income tax and what has become the Federal Reserve, and also indoctrinate him with the Zionist movement. Justice Brandeis and President Wilson were just as close as the two fingers on this hand, and President Woodrow Wilson was just as incompetent when it came to determining what was going on as a newborn baby. And that's how they got us into World War I, while we all slept. Now, at this moment... at this moment they may be planning this World War III, in which we don't stand a chance even if they don't use nuclear bombs. How can the United States -- about five percent of the world -- go out and fight eighty to ninety percent of the world on their home ground? How can we do it... send our boys over there to be slaughtered? For what? So the Jews can have Palestine as their 'commonwealth'? They've fooled you so much that you don't know whether you're coming or going. Now any judge, when he charges a jury, says, "Gentlemen, any witness that you find has told a single lie, you can disregard all his testimony." That is correct. I don't know from what state you come, but in New York state that is the way a judge addresses a jury. If that witness said one lie, disregard his testimony. Now, what are the facts about the Jews? > > My Sig was missed > > http://www.youtube.com/watch?v=lX18zUp6WPY > > http://www.youtube.com/watch?v=XQapkVCx1HI > > http://www.youtube.com/watch?v=tXJ-k-iOg0M > > Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? > Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did > you release the 5 dancing Israelis compromising the whole 911 > investigation ? If the Dubai Police can catch Mossad Murderers and put > the videos and Iranian Police can why cant you put the Pentagon > Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and > puting on INTERNATIONAL MEDIA a day after catching him without > TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did > you have to LIE about Dr Afiya Siddiqui and torture that Innocent > little mother of 3 and smashing the skull of her one child ? > > http://www.youtube.com/watch?v=DhMcii8smxkhttp://www.youtube.com/watch?v=0SZ2lxDJmdg > > There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian > courts. > > FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but > only because he was a white. They got away with MURDER of thousands of > Non-whites in all parts of the world. > > Daily 911 news :http://911blogger.com > > http://www.youtube.com/watch?v=tRfhUezbKLw > > http://www.youtube.com/watch?v=x7kGZ3XPEm4 > > http://www.youtube.com/watch?v=lX18zUp6WPY On Jun 29, 9:31?am, nanothermite911fbibustards wrote: > On Jun 29, 5:24?am, "n... at bid.nes" wrote: > > > > > On Jun 26, 12:16?pm, nanothermite911fbibustards > > > wrote: > > > ? Let's talk about thermite. > > > ? Do you know anything about thermite? It's a powdered mixture of a > > metal oxide and another pure metal that, when raised to a specific > > minimum temperature, allows the metal to "steal" the oxygen from the > > metal oxide, evolving heat. Example, iron oxide loses its oxygen to > > aluminum, yielding aluminum oxide and metallic iron, plus heat. > > > ? Do you know what temperature it must be brought to in order to > > ignite it? > > > ? How do you propose the alleged "nanothermite" supposedly spread > > around the towers was raised to that temperature *simultaneously*? > > > ? Do you know what amount of heat (not temperature) a given mass of > > thermite can produce? > > > ? What amount of heat could the particles of your alleged > > "nanothermite" produce? Remember, each particle burns only as long as > > the oxide component can provide oxygen to the pure metal component of > > the thermite. > > > ? Mark L. Fergerson > > Spoook, All your QUESTIONS are answered in the papers by 911 truth > videos, by Dr Steven Jones and his VIDEOS !!! > > Go to st911.org and start looking !!! > > Go to 911blogger.com and start reading !!! > > Go to youtube and google for 911truth. > > They had military type wireless coordinated cutter charges that they > accessed from under the elevator shafts. One or all of CIA , MOSSAD , > Blackwater , Kroll etc may have been involved. > > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? From smallpox911 at gmail.com Sat Jul 3 03:28:55 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 00:28:55 -0700 (PDT) Subject: The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. Message-ID: The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. Now, what are the facts about the Jews? The Jews -- I call them Jews to you, because they are known as Jews. I don't call them Jews. I refer to them as so-called Jews, because I know what they are. If Jesus was a Jew, there isn't a Jew in the world today, and if those people are Jews, certainly our Lord and Savior was not one of them, and I can prove that. Now what happened? The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. They were a warlike tribe that lived deep in the heart of Asia. And they were so warlike that even the Asiatics drove them out of Asia into eastern Europe -- and to reduce this so you don't get too confused about the history of Eastern Europe -- they set up this big Khazar kingdom: 800,000 square miles. Only, there was no Russia, there were no other countries, and the Khazar kingdom was the biggest country in all Europe -- so big and so powerful that when the other monarchs wanted to go to war, the Khazars would lend them 40,000 soldiers. That's how big and powerful they were. Now, they were phallic worshippers, which is filthy. I don't want to go into the details of that now. It was their religion the way it was the religion of many other Pagans or Barbarians elsewhere in the world. Now, the [Khazar] king became so disgusted with the degeneracy of his kingdom that he decided to adopt a so-called monotheistic faith -- either Christianity, Islam -- the Moslem faith -- or what is known today as Judaism -- really Talmudism. So, like spinning a top and calling out "eeny, meeny, miney, moe," he picked out so-called Judaism. And that became the state religion. He sent down to the Talmudic schools of Pumbedita and Sura and brought up thousands of these rabbis with their teachings, and opened up synagogues and schools in his kingdom of 800,000 people -- 800,000 thousand square miles -- and maybe ten to twenty million people; and they became what we call Jews. There wasn't one of them that had an ancestor that ever put a toe in the Holy Land, not only in Old Testament history, but back to the beginning of time. Not one of them! And yet they come to the Christians and they ask us to support their armed insurrection in Palestine by saying: "Well, you want to certainly help repatriate God's chosen people to their Promised Land, their ancestral homeland, It's your Christian duty. We gave you one of our boys as your Lord and Savior. You now go to church on Sunday, and kneel and you worship a Jew, and we're Jews." Well, they were pagan Khazars who were converted just the same as the Irish [were converted]. And it's just as ridiculous to call them "people of the Holy Land," as it would be. . . there are 54 million Chinese Moslems. Fifty four million! And, Mohammed only died in 620 A.D., so in that time, 54 million Chinese have accepted Islam as their religious belief. Now imagine, in China, 2,000 miles away from Arabia, where the city of Mecca is located, where Mohammed was born. . . imagine if the 54 million Chinese called themselves 'Arabs'. Imagine! Why, you'd say they're lunatics. Anyone who believes that those 54 million Chinese are Arabs must be crazy. All they did was adopt as a religious faith; a belief that had its origin in Mecca, in Arabia. The same as the Irish. When the Irish became Christians, nobody dumped them in the ocean and imported from the Holy Land a new crop of inhabitants that were Christians. They weren't different people. They were the same people, but they had accepted Christianity as a religious faith. Now, these Pagans, these Asiatics, these Turko-Finns. . . they were a Mongoloid race who were forced out of Asia into eastern Europe. They likewise, because their king took the faith -- Talmudic faith -- they had no choice. Just the same as in Spain: If the king was Catholic, everybody had to be a Catholic. If not, you had to get out of Spain. So everybody -- they lived on the land just like the trees and the bushes; a human being belonged to the land under their feudal system -- so they [Khazars] all became what we call today, Jews! Now imagine how silly it was for the Christians. . . for the great Christian countries of the world to say, "We're going to use our power, our prestige to repatriate God's chosen people to their ancestral homeland, their Promised Land." Now, could there be a bigger lie than that? Could there be a bigger lie than that? And because they control the newspapers, the magazines, the radio, the television, the book publishing business, they have the ministers in the pulpit, they have the politicians on the soap boxes talking the same language . . . so naturally you'd believe black is white if you heard it often enough. You wouldn't call black black anymore -- you'd start to call black white. And nobody could blame you. Now, that is one of the great lies. . . that is the foundation of all the misery that has befallen the world. Because after two wars fought in Europe -- World War I and World War II -- if it wasn't possible for them to live in peace and harmony with the people in Europe, like their brethren are living in the United States, what were the two wars fought for? Did they have to -- like you flush the toilet -- because they couldn't get along, did they have to say, "Well, we're going back to our homeland and you Christians can help us"? I can't understand yet how the Christians in Europe could have been that dumb because every theologian, every history teacher, knew the things that I'm telling you. But, they naturally bribed them, shut them up with money, stuffed their mouths with money, and now. . . I don't care whether you know all this or not. It doesn't make any difference to me whether you know all these facts or not, but it does make a difference to me. I've got, in my family, boys that will have to be in the next war, and I don't want them to go and fight and die... like they died in Korea. Like they died in Japan. Like they've died all over the world. For what? To help crooks hold on to what they stole from innocent people who had been in peaceful possession of that land, those farms, those homes for hundreds and maybe thousands of years? Is that why the United States must go to war? Because the Democratic Party wants New York State -- the electoral vote? Illinois, the electoral vote? And Pennsylvania, the electoral vote?... which are controlled by the Zionists and their co-religionists?. . . the balance of power? In New York City there are 400,000 members of the liberal party, all Zionists and their co-religionists. And New York State went for Kennedy by 400,000 votes. Now, I don't blame Mr. Kennedy. I'm fond of Mr. Kennedy. I think he's a great man. I think he can really pull us out of this trouble if we get the facts to him. And I believe he knows a great deal more than his appointments indicate he knows. He's playing with the enemy. Like when you go fishing, you've got to play with the fish. Let 'em out and pull 'em in. Let 'em out and pull 'em in. But knowing Mr. Kennedy's father, and how well informed he is on this whole subject, and how close Kennedy is to his father, I don't think Mr. Kennedy is totally in the dark. But I do think that it is the duty of every mother, every loyal Christian , every person that regards the defense of this country as a sacred right, that they communicate -- not with their congressman, not with their senator, but with President Kennedy. And tell him, "I do not think you should send my boy, or our boys, wearing the uniform of the United States of America, and under the flag that you see here, our red, white and blue, to fight there to help keep in the hands of these that which they have stolen". I think everyone should not alone write once, but keep writing and get your friends to write. Now, I could go on endlessly, and tell you these things to support what I have just asked you to do. But I don't think it's necessary to do that. You're above the average group in intelligence and I don't think it's necessary to impress this any more. But. . . I want to tell you one more thing. You talk about... "Oh, the Jews. Why the Jews? Christianity. Why, we got Christianity from the Jews and the Jews gave us Jesus, and the Jews gave us our religion". But do you know that on the day of atonement that you think is so sacred to them, that on that day... and I was one of them! This is not hearsay. I'm not here to be a rabble-rouser. I'm here to give you facts. When, on the Day of Atonement, you walk into a synagogue, the very first prayer that you recite, you stand -- and it's the only prayer for which you stand -- and you repeat three times a short prayer. The Kol Nidre. In that prayer, you enter into an agreement with God Almighty that any oath, vow, or pledge that you may make during the next twelve months -- any oath, vow or pledge that you may take during the next twelve months shall be null and void. The oath shall not be an oath; the vow shall not be a vow; the pledge shall not be a pledge. They shall have no force and effect, and so forth and so on. And further than that, the Talmud teaches: "Don't forget -- whenever you take an oath, vow, and pledge -- remember the Kol Nidre prayer that you recited on the Day of Atonement, and that exempts you from fulfilling that". How much can you depend on their loyalty? You can depend upon their loyalty as much as the Germans depended upon it in 1916. And we're going to suffer the same fate as Germany suffered, and for the same reason. You can't depend upon something as insecure as the leadership that is not obliged to respect an oath, vow or pledge. Now I could go on and recite many other things to you, but I would have a little respect for your time, and you want to really, uh, get through with all of this. Tomorrow's going to be a long day. Now I want to say one thing. You ask me. . . well, you think to yourself: "well how did this fellow get mixed up in this the way he got mixed up in it." Well, I opened my mouth in 1945, and I took big pages in newspapers and tried to tell the American people what I'm telling you. And one newspaper after another refused the advertisement. And when I couldn't find a newspaper to take them -- I paid cash, not credit -- what happened? My lawyer told me, "There's an editor over in Jersey with a paper who will take your announcement". So, I was brought together with Mr. McGinley, and that's how I met him. So somebody told me the lawyer who introduced me, who was the son of the Dean of the Methodist Bishop, he said: "Well, I think he's a little anti-Semitic. I don't know whether I can get him over here. So he brought him over to my apartment and we hit it off wonderfully, and have since then. Now, I say this, and I say it without any qualifications. I say it without any reservations. And I say it without any hesitation. . . if it wasn't for the work that Mr. Conley McGinley did with "Common Sense" -- he's been sending out from 1,800,000 to 2,000,000 every year -- if it wasn't for the work he's been doing sending those out for fifteen years now, we would already be a communist country. Nobody has done what he did to light fires. Many of the other active persons in this fight learned all about if for the first time through "Common Sense". Now, I have been very active in helping him all I could. I'm not as flush as I was. I cannot go on spending the money. . . I'm not going to take up a collection. Don't worry. I see five people getting up to leave. (laughter) I haven't got the money that I used to spend. I used to print a quarter of a million of them out of my own pocket and send them out. Mr. McGinley, when I first met him, had maybe 5,000 printed and circulated them locally. So I said, "With what you know and what I know, we can really do a good job". So I started printing in outside shops of big newspaper companies, a quarter of a million, and paid for them. Well, there's always a bottom to the barrel. I suppose we've all reached that at times. I'm not so poor that I can't live without working and that's what worries the Anti-Defamation League. I can just get by without going and asking for a job or getting on the bread line. But Mr. McGinley is working. He's sick and he's going at this stronger than ever. And all I want to say is that they want to close up "Common Sense" more than any other single thing in the whole world, as a death-blow to the fight Christians are making to survive. So I just want to tell you this. All they do is circulate rumors: "Mr. Benjamin H. Freedman is the wealthy backer of 'Common Sense'." The reason they do that is to discourage the people in the United States: don't send any money to Common Sense. They don't need it. The've got the wealthy Mr. Freedman as a backer. That all has strategy. They don't want to advertise me so that people that have real estate or securities to sell will come and call on me. They just want people to lay off "Common Sense". And all I'm telling you is, I do try to help him, but I haven't been able to. And I will be very honest. One thing I won't do is lie. In the last year I've had so much sickness in my family that I could not give him one dollar. How he's managed to survive, I don't know. God alone knows. And he must be in God's care because how he's pulled through his sickness and with his financial troubles, I don't know. But that press is working. . . and every two weeks about a hundred or a hundred-fifty- thousand of "Common Sense" go out with a new message. And if that information could be multiplied. . . if people that now get it could buy ten or twenty five, or fifty, give them around. Plow that field. Sow those seeds, you don't know which will take root, but for God's sake, this is our last chance. [Freedman then discusses the importance of people forgoing unnecessary purchases to 'buy more stuff', play golf, etc., and use the money to keep "Common Sense" going. He explains that the paper is going in debt; could be closed down and he (Freedman) no longer has the funds, having spent some $2,400,000 in his attempt to bring the information to the American public and elected officials. He then asks for questions from the audience.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {Question inaudible] Freedman: All right, I'll comment on that. This is rather deep, but you all have a very high degree of intelligence, so I'm going to make an attempt. In the time of Bible history, there was a geographic area known as Judea. Judea was a province of the Roman Empire. Now, a person who lived in Judea was known as a Judean, and in Latin it was Judaeus; in Greek it was Judaius. Those are the two words, in Greek and Latin, for a Judean. Now, in Latin and Greek there is no such letter as 'j', and the first syllable of Judaeus and Judaius starts 'ghu'. Now, when the Bible was written, it was first written in Greek, Latin, Panantic, Syriac, Aramaic... all those languages. Never Was the word Jew in any of them because the word didn't exist. Judea was the country, and the people were Judeans, and Jesus was referred to only as a Judean. I've seen those early... the earliest scripts available. In 1345, a man by the name of Wycliffe in England thought that it was time to translate the Bible into English. There was no English edition of the Bible because who the Devil could read? It was only the educated church people who could read Latin and Greek, Syriac, Aramaic and the other languages. Anyhow, Wycliffe translated the Bible into English. But in it, he had to look around for some words for Judaeas and Judaius. There was no English word because Judea had passed out of existence. There was no Judea. People had long ago forgotten that. So in the first translation he used the word, in referring to Jesus, as 'gyu', "jew". At the time, there was no printing press. Then, between 1345 and the 17th century, when the press came into use, that word passed through so many changes... I have them all here. If you want I can read them to you. I will. That word 'gyu' which was in the Wycliffe Bible became. . . first it was ' gyu ', then ' giu ', then ' iu ' (because the ' i ' in Latin is pronounced like the ' j '. Julius Caesar is ' Iul ' because there is no 'j' in Latin) then ' iuw ', then ' ieuu ', then ' ieuy ', then ' iwe ', then ' iow ', then ' iewe ', all in Bibles as time went on. Then ' ieue ', then ' iue ', then ' ive ', and then ' ivw ', and finally in the 18th century... ' jew '. Jew. All the corrupt and contracted forms for Judaius, and Judaeas in Latin. Now, there was no such thing as 'Jew', and any theologian -- I've lectured in maybe 20 of the most prominent theological seminaries in this country, and two in Europe -- there was no such word as Jew. There only was Judea, and Jesus was a Judean and the first English use of a word in an English bible to describe him was 'gyu' -- Jew. A contracted and shortened form of Judaeus, just the same as we call a laboratory a 'lab', and gasoline 'gas'... a tendency to short up. So, in England there were no public schools; people didn't know how to read; it looked like a scrambled alphabet so they made a short word out of it. Now for a theologian to say that you can't harm the Jews, is just ridiculous. I'd like to know where in the scriptures it says that. I'd like to know the text. Look at what happened to Germany for touching Jews. What would you, as a citizen of the United States, do to people who did to you what the so-called Jews -- the Pollacks and Litvaks and Litzianers -- they weren't Jews, as I just explained to you. They were Eastern Europeans who'd been converted to Talmudism. There was no such thing as Judaism. Judaism was a name given in recent years to this religion known in Bible history as Torah [inaudible]. No Jew or no educated person ever heard of Judaism. It didn't exist. They pulled it out of the air. . . a meaningless word. Just like 'anti-Semitic'. The Arab is a Semite. And the Christians talk about people who don't like Jews as anti-Semites, and they call all the Arabs anti-Semites. The only Semites in the world are the Arabs. There isn't one Jew who's a Semite. They're all Turkothean Mongoloids. The Eastern european Jews. So, they brainwashed the public, and if you will invite me to meet this reverend who told you these things, I'll convince him and it'll be one step in the right direction. I'll go wherever I have to go to meet him. ~~~~~~~~~~~~~~~~~~~ Yes, ma'am. Well... I can answer that. First of all, your first premise is wrong. Your first premise that all the Jews are loyal to each other is wrong. Because, the Eastern European Jews outnumber all the rest by so many that they create the impression that they are the Jewish 'race'; that they are the Jewish nation; that they are the Jewish people. . . and the Christians swallow it like a cream puff. But in 1844 the German rabbis called a conference of rabbis from all over the world for the purpose of abolishing the Kol Nidre from the Day of Atonement religious ceremony. In Brunswick, Germany, where that conference was held in 1844, there was almost a terrific riot. A civil war. The Eastern Europeans said, "What the hell. We should give up Kol Nidre? That gives us our grip on our people. We give them a franchise so they can tell the Christians, 'Go to hell. We'll make any deal you want', but they don't have to carry it out. That gives us our grip on our people". So, they're not so united, and if you knew the feeling that exists. . . Now, I'll also show you from an official document by the man responsible for. . . uh, who baptized this race. Here is a paper that we obtained from the archives of the Zionist organization in New York City, and in it is the manuscript by Sir James A. Malcolm, who -- on behalf of the British Cabinet -- negotiated the deal with these Zionists. And in here he says that all the jews in England were against it. The Jews who had been there for years, the [inaudible - probably Sephardim], those who had Portuguese and Spanish ad Dutch ancestry... who were monotheists and believed in that religious belief. That was while the Eastern European Jews were still running around in the heart of Asia and then came into Europe. But they had no more to do with them than. . . can we talk about a Christian 'race'? or a Christian religion?... or are the Christians united? So the same disunity is among the Jews. And I'll show you in this same document that when they went to France to try and get the French government to back that Zionist venture, there was only one Jew in France who was for it. That was Rothschild, and they did it because they were interested in the oil and the Suez Canal ------------------------------------------------ [Question inaudible] Freedman: You know why? Because if they don't, they're decked up. They come around and they tell you how much you must give, and if you don't . . . oh, you're anti-Semitic. Then none of their friends will have anything to do with them, and they start a smear campaign. . . and you have got to give. In New York city, in the garment center, there are twelve manufacturers in the building. And when the drive is on to sell Israel Bonds, the United Jewish Drive, they put a big scoreboard with the names of the firms and opposite them, as you make the amount they put you down for, they put a gold star after the name. Then, the buyers are told, "When you come into that building to call on someone and they haven't got a gold star, tell them that you won't buy from them until they have the gold star". BLACKMAIL. I don't know what else you can call it. Then what do they do? They tell you it's for 'humanitarian purposes' and they send maybe $8 billion dollars to Israel, tax exempt, tax deductible. So if they hadn't sent that eight billion dollars to Israel, seven billion of it would have gone into the U.S. Treasury as income tax. So what happens? That seven billion dollars deficit -- that air pocket -- the gullible Christians have to make up. They put a bigger tax on gas or bread or corporation tax. Somebody has to pay the housekeeping expenses for the government. So why do you let these people send their money over there to buy guns to drive people out of their ancient homeland? And you say, "Oh, well. The poor Jews. They have no place to go and they've been persecuted all their lives". They've never been persecuted for their religion. And I wish I had two rows of Rabbis here to challenge me. Never once, in all of history, have they been persecuted for their religion. Do you know why the Jews were driven out of England? King Edward the First in 1285 drove them out, and they never came back until the Cromwell Revolution which was financed by the Rothschilds. For four- hundred years there wasn't a Jew. But do you know why they were driven out? Because in the Christian faith and the Moslem faith it's a sin to charge 'rent' for the use of money. In other words - what we call interest [usury] is a sin. So the Jews had a monopoly in England and they charged so much interest, and when the Lords and Dukes couldn't pay, they [Jews] foreclosed. And they were creating so much trouble that the king of England finally made himself their partner, because when they they came to foreclose, some of these dukes bumped off the Jews. . . the money-lenders. So the king finally said -- and this is all in history, look up Tianson [Tennyson?] or Rourke, the History of the Jews in England; two books you can find in your library. When the king found out what the trouble was all about, and how much money they were making, he declared himself a fifty-percent partner of the money lenders. Edward the First. And for many years, one-third of the revenues of the British Treasury came from the fifty-percent interest in money-lending by the Jews. But it got worse and worse. So much worse that when the Lords and Dukes kept killing the money-lenders, the King then said, "I declare myself the heir of all the money-lenders. If they're killed you have to pay me, because I'm his sole heir". That made so much trouble, because the King had to go out and collect the money with an army, so he told the Jews to get out. There were 15,000 of them, and they had to get out, and they went across to Ireland, and that's how Ireland got to be part of the United Kingdom. When King Edward found out what they were doing, he decided to take Ireland for himself before someone else did. He sent Robert Southgard with a mercenary army and conquered Ireland. So, show me one time where a Jew was persecuted in any country because of his religion. It has never happened. It's always their impact on the political, social, or economic customs and traditions of the community in which they settle. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Question inaudible] Freedman: Yes, sir. Well, they say most of those things themselves. It was unnecessary for Benjamin Franklin to say it. Most of those things they say themselves. But Benjamin Franklin observed, and by hearsay understood, what was happening in Europe. When Russia, in 920 was formed, and gradually surrounded the Khazar Kingdom, and absorbed them, most of the well-to-do Khazars fled to Western Europe and brought with them the very things to which you object and I object and a lot of other people object. The customs, the habits, the instincts with which they were endowed. When Benjamin Franklin referred to them as Jews because that's the name that they went by, and when the Christians first heard that these people who were fleeing from Russia -- who they were -- that they had practiced this Talmudic faith -- the Christians in Western Europe said, "They must be the remnants of the lost ten tribes!" And Mr. Grutz, the greatest historian amongst the Jews, said that -- and he's probably as good an authority on that subject as there is. So when Ben Franklin came to Europe in the 18th century, he already saw the results of what these people had done after they left their homeland. And every word of it is true... they say it themselves. I can give you half a dozen books they've written in which they say the same thing: When they have money they become tyrants. And when they become defeated, they become ruthless. They're only barbarians. They're the descendants of Asiatic Mongols and they will do anything to accomplish their purpose. What right did they have to take over Russia the way they did? The Czar had abdicated nine or ten months before that. There was no need for them. . . they were going to have a constitutional monarchy. But they didn't want that. When the constitutional monarchy was to assemble in November, they mowed them all down and established the Soviet Union. There was no need for that. But they thought, "Now is the time", and if you you will look in the Encyclopedia Britannica under the word 'Bolshevism', you'll find the five laws there that Lenin put down for a successful revolution. One of them is, "Wait for the right time, and then give them everything you've got". It would pay you to read that. You'd also find that Mr. Harold Blacktree, who wrote the article for the Encyclopedia Britannica states that the Jews conceived and created and cultivated the Communist movement. And that their energy made them the spearhead of the movement. Harold Blacktree wrote it and no one knew more about Communism than he. And the Encyclopedia Britannica for 25 years has been printing it. ~~~~~~~~~~~~~~~~~~~~~~~ [Question inaudible] Freedman: Well, I can't advocate that you do anything that's criminal, but I can tell you this. You can start what I call an endless chain. If you can get your friends to write, objectively, here is the statement: Mr. Kennedy's office gave me this himself. Mr. Smith, who succeeded Mr. Kennedy, took over his office -- was in his office -- and gave me this. He delivered this on the 25th, and it says here: "For release to AM (that means morning papers), August 25th". "Israel is here to stay. It is a national commitment, special obligation of the Democratic Party. The White House must take the lead. American intervention. We will act promptly and decisively against any nation in the Middle East which attacks its neighbor. I propose that we make clear to both Israel and the Arab states our guarantee that we will act with whatever force and speed are necessary to halt any aggression by any nation". Well, do you call the return of people to their homeland [the Arab Palestinians] aggression? Is Mr. Kennedy going to do that? Suppose three million Mexicans came into Texas and drove the six million Texans into the deserts of Arizona and New Mexico. Suppose these Mexicans were slipped in there armed -- the Texans were disarmed -- and one night they drove them all out of Texas and declared themselves the Republic of the Alamo. What would the United States say? Would we say it's aggression for these Texans to try to get their homes back from the Mexican thieves? Suppose the Negroes in Alabama were secretly armed by the Soviets and overnight they rose up and drove all the whites into the swamps of Mississippi and Georgia and Florida. . . drove them out completely, and declared themselves the Republic of Ham, or the Republic of something-or-other. Would we call it aggression if these people, the whites of Alabama, tried to go back to their homes? Would we. . . what would we think if the soviet Union said, "No, those Negroes now occupy them! Leave them there!", or "No, those Mexicans are in Texas. they declared themselves a sovereign state. Leave them there. You have plenty of room in Utah and Nevada. Settle somewhere else". Would we call it aggression if the Alabama whites or the Texans wanted to go back to their homes? So now, you've got to write to President Kennedy and say, "We do not consider it aggression in the sense that you use the word, if these people want to return to their homes as the United Nations -- fifteen times in the last twelve years -- called upon the Zionists in occupation of Palestine to allow the Arab Palestinians to return to their former homes and farms". [End of transcript of Benjamin Freedman speech, given in 1961 at the Willard Hotel in Washington, D.C., on behalf of Conde McGinley's patriotic newspaper of that time, Common Sense.] From smallpox911 at gmail.com Sat Jul 3 03:41:45 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 00:41:45 -0700 (PDT) Subject: SCHOLARLY TESTIMONIAL VIDEO : Joseph Moshe (MOSSAD Microbiologist) Swine flu vaccine 1 References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: Joseph Moshe (MOSSAD Microbiologist) Swine flu vaccine 1 http://www.youtube.com/watch?v=9ranNpzlXIo Part 1 Today, the MSM are not talking about this case any more. Yesterday, they wanted us to believe that Joseph Moshe was a nutcase and a terrorist, arrested for threatening to bomb the White House. Interesting detail about his arrest (the Westwood standoff) was that he seemed to be immune to the 5 cans of tear gas and 5 gallons of law- enforcement grade pepper spray they pumped into his face. He very calmly remained in his car, as the video footage of his arrest shows. Professor Moshe had called into a live radio show by Dr. A. True Ott, (explanation of Joseph Moshes call at 06:00) broadcast on Republic Broadcasting claiming to be a microbiologist who wanted to supply evidence to a States Attorney regarding tainted H1N1 Swine flu vaccines being produced by Baxter BioPharma Solutions. He said that Baxters Ukrainian lab was in fact producing a bioweapon disguised as a vaccine. He claimed that the vaccine contained an adjuvant (additive) designed to weaken the immune system, and replicated RNA from the virus responsible for the 1918 pandemic Spanish flu, causing global sickness and mass death. Joseph Moshe was soon after his arrest sent or let go to Israel. Nothing has been heard from him since. The Secret Service was not the agency involved in the surveillance of Moshe at his home in California. This was done by the FBI, who had orders to detain or arrest him. Mounted on top of a large black vehicle used in his arrest was a microwave weapon that possibly damaged the electronics in Moshes car as well as any communication devices he had which might have been used to contact the media or others who could help him. Baxter Pharmaceutical has been caught, red-handed, in spreading a live, genetically engineered H5N1 Bird flu vaccine as a lethal biological weapon all over the world, destined to be used for human vaccinations. This happened just a few months ago. Baxter International Inc. had mixed live, genetically engineered avian flue viruses in vaccine material shipped to 18 countries. Baxter knew full well that their vaccine was lethal, because the year before they had tested it on a few hundred homeless Polish people dozens died as a result. Qui bono? We think it may be profit-motivated, but for the conspiracy- minded: The latter complaint alludes to intentional culling of the herd. Have you heard of the Georgia Guidestones? An enormous monument loaded with Masonic symbolism costing millions of dollars, it has been erected by unknown, powerful elites (multimillionaires with the clout to erect monuments wherever they please, obviously) around 30 years ago. It gives an alternative ten commandments, of which the first is the extermination of six and a half billion people from the face of the Earth. Half a billion will remain. This is the number of people the planet can sustain indefinitely, so that the descendents of the Rothschilds and Rockefellers can live in peace and affluence indefinitely. Slaves are needed to produce that luxury, but 500 million will do just fine. But how does one go about killing off most of the world? Vaccinating the planet with a bioweapon with near-100% mortality would do the trick. Baxter would provide both the bioweapon as well as the vaccine against it to civilized Western peoples. Result: We can plunder Africa, we have no more competition from SE Asia, the oil is for our taking and only Western and perhaps Chinese sheeple remain. Rockefeller said this in 1994 at a U.N. dinner: We are on the verge of a global transformation. All we need is the right major crisis, and the nations will accept the New World Order. PNAC said something similar right before 9/11. A Spanish Doctor in Internal Medicine largely agrees with the above article: From kedra.marbun at gmail.com Sat Jul 3 04:59:06 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sat, 3 Jul 2010 01:59:06 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: if we limit our discussion to py: why __{get|set|delete}__ don't receive the 'name' & 'class' from __{getattribute|{set|del}attr}__ 'name' is the name that is searched 'class' is the class whose __dict__ has 'name' bound to descriptor delegator & delegator are terms from delegation pattern (oop) which is a specialized area of IoC delegate refers to helper obj, which is descriptor obj in the case of descriptor delegator is the obj that delegates task to helper obj oh crap, brazil lost, but i admit effort of the dutch is awesome if fifa['wc']['2010'].winner is not netherlands: raise SystemError #bugfix From bdesth.quelquechose at free.quelquepart.fr Sat Jul 3 05:06:31 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jul 2010 11:06:31 +0200 Subject: loading configuration files that are themselves python In-Reply-To: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <4c2f1920$0$23926$426a74cc@news.free.fr> Matthew Vernon a ?crit : > Hi, > > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere At least you have a way to do it, so you should be happy !-) Another solution would be to add the path to sys.path, but it wouldn't necessarily be the best thing to do here. From breamoreboy at yahoo.co.uk Sat Jul 3 05:08:04 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 03 Jul 2010 10:08:04 +0100 Subject: delegation pattern via descriptor In-Reply-To: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> Message-ID: On 02/07/2010 14:28, kedra marbun wrote: > hello, friendliest prog lang community on earth ;) Flattery will get you everywhere. > [snip] > > wow, it's almost time for brazil to beat the dutch, sorry Guido ;) > if fifa['wc']['2010'].winner is not brazil: raise SystemError Have you run this and get your SystemError yet? :) Kindest regards. Mark Lawrence From bdesth.quelquechose at free.quelquepart.fr Sat Jul 3 05:15:18 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jul 2010 11:15:18 +0200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c2f1b2f$0$17371$426a74cc@news.free.fr> kedra marbun a ?crit : > if we limit our discussion to py: > why __{get|set|delete}__ don't receive the 'name' & 'class' from > __{getattribute|{set|del}attr}__ > 'name' is the name that is searched While it would have been technically possible, I fail to imagine any use case for this. From matthew at debian.org Sat Jul 3 05:15:28 2010 From: matthew at debian.org (Matthew Vernon) Date: 03 Jul 2010 10:15:28 +0100 Subject: loading configuration files that are themselves python Message-ID: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Hi, Is there a more idiomatic way of loading in a configuration file that's python code than: _temp=__import__(path,fromlist='cachestrs') cachestrs=_temp.cachestrs ? I mean, that's pretty ugly...Plain "import" doesn't work in this case because 'path' is a variable defined elsewhere TIA, Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org From thomas at jollans.com Sat Jul 3 05:16:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 03 Jul 2010 11:16:19 +0200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2EFFE3.7070109@jollans.com> On 07/03/2010 10:59 AM, kedra marbun wrote: > if we limit our discussion to py: > why __{get|set|delete}__ don't receive the 'name' & 'class' from > __{getattribute|{set|del}attr}__ > 'name' is the name that is searched > 'class' is the class whose __dict__ has 'name' bound to descriptor http://users.rcn.com/python/download/Descriptor.htm#descriptor-protocol descr.__get__(self, obj, type=None) --> value descr.__set__(self, obj, value) --> None descr.__delete__(self, obj) --> None These methods are passed the object they're operating on. If the name is in any way important, which is almost certainly is not, it can either be passed in to the constructor of the descriptor or determined by introspection. > > delegator & delegator are terms from delegation pattern (oop) which is > a specialized area of IoC > delegate refers to helper obj, which is descriptor obj in the case of > descriptor > delegator is the obj that delegates task to helper obj you are making no sense. > > oh crap, brazil lost, but i admit effort of the dutch is awesome > if fifa['wc']['2010'].winner is not netherlands: raise SystemError > #bugfix From __peter__ at web.de Sat Jul 3 05:46:03 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 03 Jul 2010 11:46:03 +0200 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: Matthew Vernon wrote: > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere execfile(path) in a module with a fixed name that you can import wherever you need access to your configuration data? Peter From antonyjeevaraj at rediffmail.com Sat Jul 3 05:50:01 2010 From: antonyjeevaraj at rediffmail.com (antonyjeevaraj at rediffmail.com) Date: Sat, 3 Jul 2010 02:50:01 -0700 (PDT) Subject: Make $1500 per month No sign up fee! Message-ID: Make $1500 per month No sign up fee! A new online money making program has been unleashed that is completely rocking the net. But free site sign ups have the best offer that Karen has for you. Setting up is 5minutes and in 15 minutes money is pouring to your account. This is why free site signup is the best money making site in the internet believe me: You get customercare support and they take you step by step in how to fully edit your website You get free wesite where you get products they have choosen for you if you are in the free site The best news is if you order the upgraded package you get 35 money making websites plus comlpete step by step on how to rank in the search engines When you sign up for the affiliate program the deal is so good. For every sale you make a cool $40 your for the keeping but if you upgrade for only $9 before you make your first sale you get to get $50 for each sale. FreeSiteSignUp is a service offering Cash Pulling Affiliate websites which enables you to have your own website business Live WITHOUT having to pay a single penny for the service... http://www.freesitesignup.com/a/coupon.php?id=3448 That is not the end, its made better than anything else out there, by making it possible to have the website up and running within 5 minutes along with necessary guidelines to fetch traffic for free. This conceptual masterpiece has already been PROVEN to be the This is how it works: Enter you personal details like email and names Free site sign up will build you a affiliate website and thats all you are ready to start. That is not the end, its made better than anything else out there, by making it possible to have the website up and running within 5 minutes along with necessary guidelines to fetch traffic for free. This conceptual masterpiece has already been PROVEN to be the best way to make money online, and the users who manage to get their hands on it are going to be at huge monetary benefits with an extra edge to their life. http://www.freesitesignup.com/a/coupon.php?id=3448 Not only you get a free website but also the guidance to get traffic to your website to fetch cash as soon as you have your business live. It's basically a cash machine which never sleeps and keeps w The sad news is the deal is almost gone because they are almost clossing there doors for free sitesA few places are remaining so hurry up http://www.freesitesignup.com/a/coupon.php?id=3448 From eliben at gmail.com Sat Jul 3 06:13:06 2010 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 3 Jul 2010 12:13:06 +0200 Subject: Sorting dicts inside dicts In-Reply-To: <4C2E93BC.5010309@mrabarnett.plus.com> References: <4C2E93BC.5010309@mrabarnett.plus.com> Message-ID: On Sat, Jul 3, 2010 at 03:34, MRAB wrote: > abhijeet thatte wrote: > >> Hi, >> I have a huge dict structure like below: >> >> /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> >> Module dict and reg_dicts contain many elements than shown. >> I want to sort this 'module' dictionary as per 'reg_addr' element in every >> 'reg_dict'. >> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 >> can contain reg_address = 2000/72 (any number) >> I do not want output in a list format as the actual dict size is huge >> which I want to use based on key value pair. >> >> So, I want output as : >> >> >> /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> /* >> */ >> >> Is it possible to sort the things? What I guess is Python stores dicts in >> a tree like structure but I am forcing it to store the way I want. Is it >> possible to do something like that. >> >> Python dicts are implemented as hash tables, not trees, for speed, and > they are unordered. > > If the order matters then you should use an ordered dict instead. You > should be able to find an implementation of one. > > The easiest way to find such an implementation is in the standard library of Python, starting with Python 3.1 (collections.OrderedDict) Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_re at fastmail.us Sat Jul 3 06:44:59 2010 From: john_re at fastmail.us (giovanni_re) Date: Sat, 03 Jul 2010 03:44:59 -0700 Subject: Join July Global Python meetings via VOIP - Free SW HW Culture Mtgs - BerkeleyTIP Message-ID: <1278153900.18707.1383107391@webmail.messagingengine.com> Watch some videos. Mark your calendar. Invite your friends. Join in on IRC or Voice. Join the mailing list, say "Hi. :)" ===== 1) 2010.7 Videos: Building the Python Community, Steve Holden, PyCon 2010 How Python, TurboGears, and MongoDB are Transforming SourceForge.net, Rick Copeland, PyCon Introducing Numpy Arrays, unpingco Motorola Droid Metro PCS Apps, makeitcricket.com How to write VOIP client in less then 2 minutes, rpdammu Open Wonderland virtual worlds platform, Nicole Yankelovich, iED How to Succeed in Mobile, Girl Geek Dinner, Kris Corzine Using KDE Marble to research your next vacation, Justin Kirby Schizophrenic Firewalls - virtualized net stack OpenBSD, Claudio Jeker Meet Google Founder Larry Page, Google Faculty Summit 2009 http://sites.google.com/site/berkeleytip/talk-videos/2010-7-videos == July Meetings - Mark your calendar: 3 Sat 12N-3P PST = 3-6P EST = 19-22 UTC 12 Mon 5 -6P PST = 8-9P EST = 0- 1 UTC Tues 13 18 Sun 12N-3P PST = 3-6P EST = 19-22 UTC 27 Tue 5 -6P PST = 8-9P EST = 0- 1 UTC Wed 28 ===== You're invited to join in with the friendly people at the BerkeleyTIP global meeting - newbie to Ph.D. - everyone is invited. Get a headset & join using VOIP online, or come to Berkeley. 1st step: Join the mailing list: http://groups.google.com/group/BerkTIPGlobal Watch the videos. Discuss them on VOIP. 10 great videos/talks this month. Join with us at the Golden Bear Cafe, Upper Sproul Plaza, UCB at the University of California at Berkeley, or join from your home via VOIP, or send this email locally, create a local meeting, & join via VOIP: Tip: a wifi cafe is a great place to meet. :) PLEASE VIEW THE BTIP WEBSITE & MAILING LIST FOR LATEST DETIALS. http://sites.google.com/site/berkeleytip BerkeleyTIP - Educational, Productive, Social For Learning about, Sharing, & Producing, All Free SW HW & Culture. TIP == Talks, Installfest, Project & Programming Party ===== CONTENTS: 1) 2010 JULY VIDEOS; 2) 2010 JULY MEETING DAYS, TIMES, LOCATIONS; 3) LOCAL MEETING AT U. C. Berkeley; 4) HOT TOPICS; 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) ; 6) INSTALLFEST; 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN; 8) IRC: #berkeleytip on irc.freenode.net; 9) VOIP FOR GLOBAL MEETING; 10) VOLUNTEERING, TO DOs; 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce; 12) ANYTHING I FORGOT TO MENTION?; 13) FOR FORWARDING ======================================================================= ===== 1) - See videos list at top of this email. Thanks to all the speakers, organizations, & videographers. :) [Please alert the speakers that their talks are scheduled for BTIP (if you are with the group that recorded their talk), because I may not have time to do that. Thanks. :) ] Download & watch these talks before the BTIP meetings. Discuss at the meeting. Email the mailing list, tell us what videos you'll watch & want to discuss. Know any other video sources? - please email me. _Your_ group should video record & post online your meeting's talks! ===== 2) 2010 JULY MEETING DAYS, TIMES, LOCATIONS http://sites.google.com/site/berkeleytip/schedule http://sites.google.com/site/berkeleytip/directions In person meetings on 1st Saturday & 3rd Sunday, every month. July 3 & 18, 12N-3P USA-Pacific time, Saturday, Sunday July 3 = Golden Bear Cafe, Upper Sproul Plaza, UCB July 18 = Free Speech Cafe, Moffitt Library, UCB Online only meeting using VOIP - 9 days after weekend meetings: July 12 & 27, 5-6P USA-Pacific time, Monday, Tuesday Mark your calendars. ===== 3) LOCAL MEETING AT U. C. BERKELEY http://sites.google.com/site/berkeleytip/directions RSVP please. See below. It greatly helps my planning. But, _do_ come if you forgot to RSVP. ALWAYS BE SURE TO CHECK THE BTIP WEBSITE _&_ MAILING LIST FOR THE LATEST LAST MINUTE DETAILS & CHANGES, BEFORE COMING TO THE MEETING! :) DO BRING A VOIP HEADSET, available for $10-30 at most electronics retail stores, & a laptop computer, so you are able to communicate with the global BTIP community via VOIP. It is highly recommended that you have a voip headset, & not rely on a laptop's built in microphone & speakers, because the headphones keep the noise level down. Bringing a headset is not required, but is a great part of the being able to communicate with the global community. :) Clothing: Typically 55-80 degrees F. Weather: http://www.wunderground.com/auto/sfgate/CA/Berkeley.html Other location local meeting possibilities: http://sites.google.com/site/berkeleytip/local-meetings Create a local meeting in your town. Invite your friends. :) ===== 4) HOT TOPICS Android phones - Besting iPhone? worthwhile? How knowable is the hw? iPad, iPhone4 & iPod- rooting & running GNU(Linux) Skype for group video conferencing? Open Wonderland virtual worlds platform ===== 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) If you think there is a >70% chance ("likely") you'll come to the in person meeting in Berkeley, please RSVP to me. Thanks. It helps my planning. Please _do_ come even if you haven't RSVP'd, it's not required. Better yet, join the BerkeleyTIP-Global mailing list, send the RSVP there, & tell us what things you're interested in, or what videos you'll try to watch - so we can know what videos are popular, & we might watch them too. :) http://groups.google.com/group/BerkTIPGlobal ===== 6) INSTALLFEST Get help installing & using Free Software, Hardware & Culture. Laptops only, typically. There isn't easy access for physically bringing desktop boxes here. RSVP _HIGHLY RECOMMENDED_ if you want installfest help. Please RSVP to me, Giovanni, at the from address for this announcement, or better, join & send email to the BTIP-Global mailing list telling us what you'd like help with. This way we can be better prepared to help you, & you might get valuable advice from the mailing list members. If you are new to using free software, an excellent system would be the KUbuntu GNU(Linux) software. It is very comprehensive, fairly easy to use (similar to Windows or Mac), & suitable for personal, home, university, or business use. We are also glad to try to help people with software who join via VOIP. Please email the mailing list with requests that you want help with, so we can try to be prepared better to help you. Installfest volunteers/helpers always welcome, in person, or via VOIP. :) ===== 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN If you get to the meeting & don't see a "BerkeleyTIP" sign up yet, please: 1) Make a BTIP sign on an 8x11 paper & put it at your table, 2) Email the mailing list, or join on IRC, & let us know you are there. Ask someone if you could use their computer for a minute to look something up, or send an email. People are usually very friendly & willing to help. We can also email you a temporary guest AirBears account login. We will have wifi guest accounts available for BTIP attendees. Be sure you have wifi capable equipment. Be Prepared: Bring a multi-outlet extension power cord. ===== 8) IRC: #berkeleytip on irc.freenode.net For help with anything, especially how to get VOIP working, & text communication. ===== 9) VOIP FOR GLOBAL MEETING Speak & listen to everyone globally using VOIP. Get a headset! See some VOIP instructions here: http://sites.google.com/site/berkeleytip/voice-voip-conferencing ===== 10) VOLUNTEERING, TO DOs Enjoy doing or learning something(s)? Help out BTIP in that area. Website development, mailing list management, video locating, VOIP server (FreeSwitch, Asterisk) or client (Ekiga, SFLPhone,...), creating a local meeting. Join the mailing list & let us know. Your offers of free help are always welcome here. :) ===== 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce Everyone should join the BerkeleyTIP-Global list: http://groups.google.com/group/BerkTIPGlobal Say "hi", tell us your interests, & what videos you'll like to watch. Info on all lists here: http://sites.google.com/site/berkeleytip/mailing-lists ===== 12) ANYTHING I FORGOT TO MENTION? Please join & email the BerkeleyTIP-Global mailing list. ===== 13) FOR FORWARDING You are invited to forward this message anywhere it would be appreciated. Better yet, use it to create a local meeting. Invite & get together with your friends locally, & join in with us all globally. :) Looking forward to meeting with you in person, or online. :) Giovanni == Join in the Global weekly meetings, via VOIP, about all Free SW HW & Culture http://sites.google.com/site/berkeleytip/ From matthew at debian.org Sat Jul 3 07:10:15 2010 From: matthew at debian.org (Matthew Vernon) Date: 03 Jul 2010 12:10:15 +0100 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <7j39w0zuty.fsf@rapun.sel.cam.ac.uk> Peter Otten <__peter__ at web.de> writes: > Matthew Vernon wrote: > > > Is there a more idiomatic way of loading in a configuration file > > that's python code than: > > > > _temp=__import__(path,fromlist='cachestrs') > > cachestrs=_temp.cachestrs > > > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > > case because 'path' is a variable defined elsewhere > > execfile(path) > > in a module with a fixed name that you can import wherever you need access > to your configuration data? That looks like what I want, thanks :) Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org From nobody at nowhere.com Sat Jul 3 07:31:14 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 03 Jul 2010 12:31:14 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: >> I think one point which needs to be emphasized more is what does >> python 3 bring to people. The" what's new in python 3 page" gives >> the impression that python 3 is about removing cruft. That's a very >> poor argument to push people to switch. > > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? If you're going to be doing a lot of Unicode text processing, I would expect that using Python 3 would make the task somewhat simpler. From darcy at druid.net Sat Jul 3 08:39:44 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 08:39:44 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4C2ECD52.5040005@animats.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <20100703083944.33d28746.darcy@druid.net> On Fri, 02 Jul 2010 22:40:34 -0700 John Nagle wrote: > Not according to Vex's published package list: > > http://www.vex.net/info/tech/pkglist/ As it says on that page it may not be up to date. Look at the generated list link. I guess I should update the static page as well. > "vex.net" isn't exactly a major hosting service. OK, I'll give you that. It is on the backbone of the net at 151 Front Street in Toronto, has almost 100% uptime and uses high speed servers but we don't have 15 layers of bureaucracy between the owner and the user and I certainly know of no "real" hosting provider that invites all their clients out for dinner once a year. And how can we be a real ISP when the president knows most of his clients on a first name basis? I know what being "major" means to the owners and stockholders but what features of being major matter to the client? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Sat Jul 3 08:46:57 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 08:46:57 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4C2ECD52.5040005@animats.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <20100703084657.af4b5700.darcy@druid.net> On Fri, 02 Jul 2010 22:40:34 -0700 John Nagle wrote: > Not according to Vex's published package list: > > http://www.vex.net/info/tech/pkglist/ Hold on. That *is* the generated list and Python 3.1 is on it. We have both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. The page is generated from pkg_info(1) and includes everything we have installed from FreeBSD ports. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at REMOVE-THIS-cybersource.com.au Sat Jul 3 10:24:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jul 2010 14:24:49 GMT Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> On Sat, 03 Jul 2010 08:46:57 -0400, D'Arcy J.M. Cain wrote: > On Fri, 02 Jul 2010 22:40:34 -0700 > John Nagle wrote: >> Not according to Vex's published package list: >> >> http://www.vex.net/info/tech/pkglist/ > > Hold on. That *is* the generated list and Python 3.1 is on it. We have > both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. > The page is generated from pkg_info(1) and includes everything we have > installed from FreeBSD ports. Pfft! Facts! You can prove anything you like with facts! -- Steven From inbox1.sudheer at gmail.com Sat Jul 3 10:33:49 2010 From: inbox1.sudheer at gmail.com (Sudheer) Date: Sat, 3 Jul 2010 10:33:49 -0400 Subject: subprocess query Message-ID: Hi, What's wrong with the following code. The program waits indefenitely at 'output = p2.stdout.read()' from subprocess import * p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) p1.stdin.write("hello") p1.stdin.close() output = p2.stdout.read() print output -- Thanks Sudheer From alf.p.steinbach+usenet at gmail.com Sat Jul 3 10:37:04 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 03 Jul 2010 16:37:04 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f4830$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 03.07.2010 16:24: > On Sat, 03 Jul 2010 08:46:57 -0400, D'Arcy J.M. Cain wrote: > >> On Fri, 02 Jul 2010 22:40:34 -0700 >> John Nagle wrote: >>> Not according to Vex's published package list: >>> >>> http://www.vex.net/info/tech/pkglist/ >> >> Hold on. That *is* the generated list and Python 3.1 is on it. We have >> both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. >> The page is generated from pkg_info(1) and includes everything we have >> installed from FreeBSD ports. > > Pfft! Facts! You can prove anything you like with facts! :-) -- blog at From clp2 at rebertia.com Sat Jul 3 10:39:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Jul 2010 07:39:40 -0700 Subject: subprocess query In-Reply-To: References: Message-ID: On Sat, Jul 3, 2010 at 7:33 AM, Sudheer wrote: > Hi, > ?What's wrong with the following code. The program waits indefenitely > at ?'output = p2.stdout.read()' > > > from subprocess import * > > p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) > p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) > p1.stdin.write("hello") > p1.stdin.close() > > output = p2.stdout.read() > > print output Try using .communicate() instead of reading and writing to .stdin and .stdout. Adding a newline (i.e. "hello\n") may also help. Cheers, Chris -- http://blog.rebertia.com From solipsis at pitrou.net Sat Jul 3 10:43:50 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 3 Jul 2010 16:43:50 +0200 Subject: Crash in PyThread_acquire_lock References: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Message-ID: <20100703164350.123bf02b@pitrou.net> Hello, > 'thelock->locked' is for sure still locked, but I can't identify the > problem. > Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the > crash > in PyThread_acquire_lock is the following one: > > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, &thelock- > >mut); <<<<<<<<<< Are you sure the crash happens in this thread and not another one? From aahz at pythoncraft.com Sat Jul 3 11:09:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Jul 2010 08:09:21 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Fri, 02 Jul 2010 22:40:34 -0700 >John Nagle wrote: >> >> "vex.net" isn't exactly a major hosting service. > >OK, I'll give you that. It is on the backbone of the net at 151 Front >Street in Toronto, has almost 100% uptime and uses high speed servers >but we don't have 15 layers of bureaucracy between the owner and the >user and I certainly know of no "real" hosting provider that invites >all their clients out for dinner once a year. And how can we be a real >ISP when the president knows most of his clients on a first name basis? vex.net is Canada's Panix. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From jjposner at optimum.net Sat Jul 3 11:14:17 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 03 Jul 2010 11:14:17 -0400 Subject: drag & drop in a python GUI application In-Reply-To: References: Message-ID: <4C2F53C9.4070104@optimum.net> On 7/2/2010 11:20 AM, Michael Torrie wrote: > On 07/01/2010 08:57 AM, Alan wrote: >> I know drag& drop is not possible with TK. > > Is this a Python Tk limitation or a Tk limitation in general? Google > suggests that Tk itself supports some form of dnd. > >> Which widget could I use for my >> python application to be able to work with drag& drop? > > PyQt will do drag and drop on all platforms. GTK does drag and drop on > Unix/X11, and to a lesser degree Win32--not sure about OS X support. I > believe wxWidgets also does some level of dnd on all platforms. Drag-and-drop *is* quite doable with Tkinter. But it's certainly easier in PyQt: self.setFlag(G.QGraphicsItem.ItemIsMovable, True) You can contact me off-list if you'd like to see a drag-and-drop application that I first wrote using Tkinter, then reimplemented using PyQt. HTH, John From darcy at druid.net Sat Jul 3 11:55:34 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 11:55:34 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f4830$0$28647$c3e8da3@news.astraweb.com> Message-ID: <20100703115534.ea95ec99.darcy@druid.net> On 03 Jul 2010 14:24:49 GMT Steven D'Aprano wrote: > Pfft! Facts! You can prove anything you like with facts! Argumentum ad Dragnet? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nagle at animats.com Sat Jul 3 12:48:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 03 Jul 2010 09:48:09 -0700 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <4c2f69d6$0$1582$742ec2ed@news.sonic.net> On 7/3/2010 5:46 AM, D'Arcy J.M. Cain wrote: > On Fri, 02 Jul 2010 22:40:34 -0700 > John Nagle wrote: >> Not according to Vex's published package list: >> >> http://www.vex.net/info/tech/pkglist/ > > Hold on. That *is* the generated list and Python 3.1 is on it. We > have both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 > one. The page is generated from pkg_info(1) and includes everything we > have installed from FreeBSD ports. The base Python 3.1 is installed there, but without any modules. Below is the list of Python 2.6 modules installed. Search that page for "py3", and you get nothing. On a hosting service, a raw Python with none of those modules isn't very useful. This is what I mean about Python 3 not being ready for prime time. John Nagle Python packages on Vex: py26-MySQLdb-1.2.2 Access a MySQL database through Python py26-PyGreSQL-4.0,1 A Python interface to PostgreSQL, both classic and DP-API 2.0 py26-gdbm-2.6.4 Python bindings to the GNU dbm library py26-psycopg-1.1.21_1 The high performance Python adapter for PostgreSQL py26-pyPgSQL-2.5.1_3 A Python DB-API 2 compliant library for using PostgreSQL databases py26-rrdtool_lgpl-1.0b1 Python interface to RRDTool, the graphing and logging utility py26-sqlite3-2.6.4_1 Standard Python binding to the SQLite3 library py26-asn1-0.0.9a_1 ASN.1 toolkit for Python py26-cElementTree-1.0.5_1 A fast C implementation of the ElementTree API py26-cheetah-2.2.1 HTML template engine for Python py26-elementtree-1.2.6_1 Container for hierarchical data structures written in Python py26-setuptools-0.6c11 Download, build, install, upgrade, and uninstall Python packages py26-statgrab-0.5 A set of Python bindings for libstatgrab py26-twisted-8.2.0 Metaport of Twisted, an event-driven networking engine py26-twistedCore-8.2.0 An asynchronous networking framework for Python - Core module py26-twistedFlow-8.0.0 Generator based asynchronous result flows py26-twistedRunner-8.2.0 Runner has process management, including an inetd replacement py26-zopeInterface-3.5.2 Zope.interface package from Zope 3 py26-twistedMail-8.2.0 An SMTP, IMAP and POP protocol implementation with clients and servers py26-twistedPair-8.0.0 Twisted Pair can do low level TCP work py26-twistedWords-8.2.0 Twisted Words has more chat than you can handle py26-snmp-3.4.4 SNMP framework for Python py26-twistedSNMP-0.3.13 Twisted Python framework for doing SNMP stuff news py26-twistedNews-8.2.0 An NNTP protocol implementation with client and server py26-fail2ban-0.8.3_2 scans log files and bans IP that makes too many password failures. py26-openssl-0.8_1 Python interface to the OpenSSL library py26-paramiko-1.7.6 A python library for making SSH2 connections py26-posix1e-0.4.0 Python module for manipulating POSIX.1e ACLs py26-pycrack-0.5.1 Python bindings to cracklib py26-pycrypto-2.1.0_1 The Python Cryptography Toolkit py26-twistedConch-8.2.0 An SSH and SFTP protocol implementation with clients and servers py26-docutils-0.5 Python Documentation Utilities py26-dsv-1.4.0 A Python module to parse or write delimeter-separated (e.g. CSV) files py26-twistedLore-8.2.0 Documentation generator with HTML and LaTeX support py26-xml-0.8.4_2 PyXML: Python XML library enhancements py26-cherrypy-3.1.2 A pythonic, object-oriented web development framework py26-django-1.1.1 High-level Python Web framework py26-flup-1.0.2 Random assortment of WSGI servers, middleware py26-twistedWeb-8.2.0 An HTTP protocol implementation together with clients and servers py26-twistedWeb2-8.1.0 The next generation Web Server Framework built with Twisted From rouslank at msn.com Sat Jul 3 13:22:39 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 13:22:39 -0400 Subject: My extension code generator for C++ Message-ID: It's still in the rough, but I wanted to give an update on my C++ extension generator. It's available at http://github.com/Rouslan/PyExpose The documentation is a little slim right now but there is a comprehensive set of examples in test/test_kompile.py (replace the k with a c. For some reason, if I post this message with the correct name, it doesn't show up). The program takes an input file like module doc string class doc string and generates the code for a Python extension. The goal has been to generate code with zero overhead. In other words I wanted to eliminate the tedium of creating an extension without sacrificing anything. In addition to generating a code file, the previous input would result in a header file with the following: extern PyTypeObject obj_DVectorType; inline PyTypeObject *get_obj_DVectorType() { return &obj_DVectorType; } struct obj_DVector { PyObject_HEAD storage_mode mode; std::vector > base; PY_MEM_NEW_DELETE obj_DVector() : base() { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(std::allocator const & _0) : base(_0) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(long unsigned int _0,double const & _1,std::allocator const & _2) : base(_0,_1,_2) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(std::vector > const & _0) : base(_0) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } }; so the object can be allocated in your own code as a single block of memory rather than having a PyObject contain a pointer to the exposed type. storage_type is an enumeration, adding very little to the size of the Python object (or maybe nothing depending on alignment), but if you add new-initializes="true" to the tag and the exposed type never needs to be held by a pointer/reference (as is the case when the exposed type is inside another class/struct), even that variable gets omitted. The code also never uses PyArg_ParseTuple or its variants. It converts every argument using the appropriate PyX_FromY functions. I noticed PyBindGen does the following when a conversion is needed for one argument: py_retval = Py_BuildValue((char *) "(O)", value); if (!PyArg_ParseTuple(py_retval, (char *) "i", &self->obj->y)) { Py_DECREF(py_retval); return -1; } Py_DECREF(py_retval); On the other hand, here's the implementation for __sequence__getitem__: PyObject * obj_DVector___sequence__getitem__(obj_DVector *self,Py_ssize_t index) { try { std::vector > &base = cast_base_DVector(reinterpret_cast(self)); return PyFloat_FromDouble(base.at(py_ssize_t_to_ulong(index))); } EXCEPT_HANDLERS(0) } (cast_base_DVector checks that base is initialized and gets a reference to it with regard to how it's stored in obj_DVector. If the class is new-initialized and only needs one means of storage, it's code will just be "return obj_DVector->base;" and should be inlined by an optimizing compiler.) I'm really interested in what people think of this little project. From urban.yoga.journeys at gmail.com Sat Jul 3 13:48:05 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Sat, 3 Jul 2010 10:48:05 -0700 (PDT) Subject: python app development Message-ID: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> an anyone recommend a resource (book,tutorial,etc.) that focuses on application development in python? something similar to Practical Django Projects, but for stand alone applications instead of web apps (for now). i'm in a bit of a funny place, i have a decent/good grasp of python syntax and my logic isn't bad, but i have no clue on how to assemble an application, i seem to be stuck on writing scripts. i've looked at the source of a few projects but the flow is way over my head, i understand the syntax but not the logic, which is why i'm looking for a project-cenetered learning resource, instead of a reference or language-feature resource. also, it seems that a lot of app programming is 90% gui bindings, with very little actual code, or am i totally way off mark? i recently picked up the django practical projects book, and in a few days i re-wrote a website i did with django. i feel it was the book's project-centric approach that made this possible. From thomas at jollans.com Sat Jul 3 13:54:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 03 Jul 2010 19:54:47 +0200 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: <4C2F7967.20908@jollans.com> On 07/03/2010 07:22 PM, Rouslan Korneychuk wrote: > It's still in the rough, but I wanted to give an update on my C++ > extension generator. It's available at http://github.com/Rouslan/PyExpose Question that pops to mind immediately: How does this differentiate itself from SWIG? ( I can't say I'm familiar with SWIG, but the question had to be posed. ) > > The documentation is a little slim right now but there is a > comprehensive set of examples in test/test_kompile.py (replace the k > with a c. For some reason, if I post this message with the correct name, > it doesn't show up). The program takes an input file like > > > > module doc string > > > class doc string > > > > > return-semantic="copy"/> func="operator[]" would also work, I assume? > > > > > and generates the code for a Python extension. > > [snip] > > I'm really interested in what people think of this little project. How does it deal with pointers? What if something returns a const pointer - is const correctness enforced? All in all, it looks rather neat. Thomas From post at andre-bell.de Sat Jul 3 14:02:25 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Sat, 03 Jul 2010 20:02:25 +0200 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <4C2F7B31.4010903@andre-bell.de> On 07/03/2010 07:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). I think you are referring to GUI applications. There are plenty of GUI Libraries out there. One of my favorites is the Qt library by Nokia (former by Trolltech) for which you can get python bindings PyQt and PySide. http://doc.qt.nokia.com/4.7-snapshot/index.html http://www.riverbankcomputing.co.uk http://www.pyside.org You might want to read through the tutorials given in the documentation at the Nokia site and possibly take a look at the examples provided with, e.g. PyQt. I'm sure other will add in more valuable links and suggestions. Best regards Andre From darcy at druid.net Sat Jul 3 14:22:38 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 14:22:38 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f69d6$0$1582$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f69d6$0$1582$742ec2ed@news.sonic.net> Message-ID: <20100703142238.33d1f51b.darcy@druid.net> On Sat, 03 Jul 2010 09:48:09 -0700 John Nagle wrote: > The base Python 3.1 is installed there, but without any modules. We install modules as clients ask for them. No one has yet requested a Python 3 module. > On a hosting service, a raw Python with none of those modules isn't > very useful. Well, it isn't useless. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nanothermite911fbibustards at gmail.com Sat Jul 3 14:49:21 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Sat, 3 Jul 2010 11:49:21 -0700 (PDT) Subject: The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 d Message-ID: <2612aaa2-607c-40af-8021-943ec27e1d1a@i28g2000yqa.googlegroups.com> The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From tjreedy at udel.edu Sat Jul 3 15:02:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 Jul 2010 15:02:16 -0400 Subject: loading configuration files that are themselves python In-Reply-To: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: On 7/3/2010 5:15 AM, Matthew Vernon wrote: > Hi, > > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere cachestrs=__import__(path,fromlist='cachestrs').cachestrs ? -- Terry Jan Reedy From jyoung79 at kc.rr.com Sat Jul 3 15:29:51 2010 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Sat, 3 Jul 2010 14:29:51 -0500 Subject: drag & drop in a python GUI application Message-ID: <20100703192951.GPWAQ.101331.root@cdptpa-web27-z02> Hi Alan, What OS are you running on? And by 'drag and drop' are you meaning you want to drag and drop on a GUI window, or are you wanting a droplet where you can drop your file/folder on the application icon? Jay -- > Hello there, > I know drag & drop is not possible with TK. Which widget could > I use for my python application to be able to work with drag & > drop? > Thanks, > Alan From tjreedy at udel.edu Sat Jul 3 15:59:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 Jul 2010 15:59:00 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: On 7/3/2010 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. > > i've looked at the source of a few projects but the flow is way over > my head, i understand the syntax but not the logic, which is why i'm > looking for a project-cenetered learning resource, instead of a > reference or language-feature resource. also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? If the app is a gui app and if logic is overly intermixed with gui stuff, I am sure it can seem like that. Many recommend the MVC model-view-controller model for app design. Even that can be confusing; to me it should be model-controller-view, even though that is harder to say. What are the data (values and objects) and how are they stored? What are the rules for manipulating the data and objects? And then, and only then, how to communicate with the user? > > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. Another issue is who controls the flow of interactions, the user or the code. For instance, a gui form used for input tends to direct the user along a linear path. The same form, used for edit, presents existing data and allows the user to pick and choose the fields to edit. This distinction, along with MVC ideas, is important for reading source code. I have mostly seen this issue discussed in game reviews and game design writing. In computer games, there is the same general difference between a linear obstacle course game and a world to be explored in whatever order one wants. (And there are some with both an explorable world *and* a (somewhat optional) linear main quest line.) I am not familiar with any general app design books, but I have seen game design articles and books that are on a par with writing about web design. There are other books on business apps. -- Terry Jan Reedy From nobody at nowhere.com Sat Jul 3 16:11:41 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 03 Jul 2010 21:11:41 +0100 Subject: subprocess query References: Message-ID: On Sat, 03 Jul 2010 10:33:49 -0400, Sudheer wrote: > What's wrong with the following code. The program waits indefenitely > at 'output = p2.stdout.read()' > > > from subprocess import * > > p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) > p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) > p1.stdin.write("hello") > p1.stdin.close() > > output = p2.stdout.read() > > print output The problem is that p2 is inheriting Python's copy of the write end of the pipe corresponding to p1.stdin, which means that it's impossible to generate EOF on the pipe (i.e. p1.stdin.close() is a no-op): PID TTY STAT TIME COMMAND 30437 pts/1 S+ 0:00 /usr/bin/python2.6 ./test.py 30438 pts/1 S+ 0:00 tr a-z A-Z 30439 pts/1 S+ 0:00 tr A-Z a-z /proc/30437/fd: total 0 lrwx------ 1 user users 64 Jul 3 20:51 0 -> /dev/pts/1 lrwx------ 1 user users 64 Jul 3 20:51 1 -> /dev/pts/1 lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 lr-x------ 1 user users 64 Jul 3 20:51 3 -> pipe:[31472684] /proc/30438/fd: total 0 lr-x------ 1 user users 64 Jul 3 20:51 0 -> pipe:[31472681] <= *** l-wx------ 1 user users 64 Jul 3 20:51 1 -> pipe:[31472682] lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 /proc/30439/fd: total 0 lr-x------ 1 user users 64 Jul 3 20:51 0 -> pipe:[31472682] l-wx------ 1 user users 64 Jul 3 20:51 1 -> pipe:[31472684] lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 l-wx------ 1 user users 64 Jul 3 20:51 4 -> pipe:[31472681] <= *** On Unix, you can add close_fds=True when creating p2, but that won't work on Windows (it prevents redirection of stdin/stdout/stderr). OTOH, I don't know whether the problem exists on Windows; if it doesn't just set close_fds to True on Unix and False on Windows. Alternatively, on Unix you should be able to use: fcntl(fd, F_SETFD, FD_CLOEXEC) (from the fcntl module) to prevent the write end of the pipe from being inherited. Worse still, killing the script with Ctrl-C will leave both of the child processes behind. In C, you would typically close the unused ends of the pipes within the child half of the fork(), before the exec(), but you don't have that degree of control with subprocess. On Windows, you can chose whether a handle is inheritable or not, but I don't know whether you can do that from within Python. From rouslank at msn.com Sat Jul 3 16:46:00 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 16:46:00 -0400 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: On 07/03/2010 01:54 PM, Thomas Jollans wrote: > On 07/03/2010 07:22 PM, Rouslan Korneychuk wrote: >> It's still in the rough, but I wanted to give an update on my C++ >> extension generator. It's available at http://github.com/Rouslan/PyExpose > > Question that pops to mind immediately: How does this differentiate > itself from SWIG? ( I can't say I'm familiar with SWIG, but the question > had to be posed. ) > I have never tried swig, but as far as I understand, SWIG uses a layered approach where part of the extension is defined C/C++ and that is wrapped in Python code. Mine implements the extension completely in C++. >> >> The documentation is a little slim right now but there is a >> comprehensive set of examples in test/test_kompile.py (replace the k >> with a c. For some reason, if I post this message with the correct name, >> it doesn't show up). The program takes an input file like >> >> >> >> module doc string >> >> >> class doc string >> >> >> >> >> > return-semantic="copy"/> > > func="operator[]" would also work, I assume? > >> >> >> >> >> and generates the code for a Python extension. >> >> [snip] >> >> I'm really interested in what people think of this little project. > > How does it deal with pointers? What if something returns a const > pointer - is const correctness enforced? > When returning pointers or references, you either have to specify a conversion explicitly or use the "return-semantic" attribute. The current options are "copy", which dereferences the pointer and copies by value, and "managed-ref" which is for exposed classes, where the returned PyObject stores the value as a reference and holds on to a reference-counted pointer to the object the returned the value (there is also "self" which has nothing to do with returning pointers. With "self", the return value of the wrapped method is ignored and a pointer to the class is returned). I can easily add other options for "return-semantic", such as keeping a pointer and deleting it upon destruction. I just implemented the ones I need for the thing I'm working on. As far as returning const pointers and const correctness, I'm not sure exactly what you mean. If you mean is there a mechanism to hold on to const objects and prevent them form being modified, the answer is no. It's not something I need. > All in all, it looks rather neat. > > Thomas Thanks for the comment. From rouslank at msn.com Sat Jul 3 16:52:05 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 16:52:05 -0400 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: I missed one: >> func="operator[]" would also work, I assume? >> Yes, you can also supply a function if the first parameter accepts the type being wrapped (__rop__ methods will even accept the second parameter taking the wrapped type). From pauljefferson at gmail.com Sat Jul 3 18:01:31 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Sat, 3 Jul 2010 23:01:31 +0100 Subject: IMAP Problems Message-ID: Hi, I'm trying to write a simple script which displays the basic details of a person's mailbox. My problem is that it causes all the messages to be marked as read on the server, which is not what I'm after, and I also can't get the imap.sort command to work properly (currently commented out as I replaced it with a imap.search to get the thing working. These are probably very simple things, but I've not tried this library before so am a bit stuck so any help wwould be very gratefully received. Thanks, Paul Code: # -*- coding: cp1252 -*- import imaplib,email # you want to connect to a server; specify which server server= imaplib.IMAP4_SSL('imap.googlemail.com') # after connecting, tell the server who you are server.login('x... @gmail.com', 'xxxxxxx') # this will show you a list of available folders # possibly your Inbox is called INBOX, but check the list of mailboxes code, mailboxen= server.list() print mailboxen # if it's called INBOX, then? server.select("INBOX") typ, data = server.search(None, 'ALL') #typ, data = server.sort("Date","UTF-8", 'ALL') print len(data[0].split()) for num in data[0].split(): typ, data = server.fetch(num, '(RFC822)') #print 'Message %s\n%s\n' % (num, data[0][1]) msg = email.message_from_string(data[0][1]) print msg["From"] print msg["Subject"] print msg["Date"] print "_______________________________" server.close() server.logout() -------------- next part -------------- An HTML attachment was scrubbed... URL: From kylotan at gmail.com Sat Jul 3 18:12:04 2010 From: kylotan at gmail.com (Ben Sizer) Date: Sat, 3 Jul 2010 15:12:04 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator Message-ID: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> It seems that getiterator isn't returning the tags I ask for. >>> tree = parse('gdlibs.html') >>> root = tree.getroot() >>> for el in root.getiterator(): ... print el [much output snipped] >>> it = root.getiterator('script') >>> all_scripts = list(it) >>> print len(all_scripts) 0 I would have expected at least 2 script tags to be found, considering iterating over the whole lot found at least 2 at the end there. What am I doing wrong? >>> import sys >>> print sys.version 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] I will upgrade to 2.6.5 ASAP, but I don't see anything in the changelog that implies a bug that has been fixed here. -- Ben Sizer From kylotan at gmail.com Sat Jul 3 18:32:33 2010 From: kylotan at gmail.com (Ben Sizer) Date: Sat, 3 Jul 2010 15:32:33 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> Message-ID: <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> On Jul 3, 11:12?pm, Ben Sizer wrote: > >>> for el in root.getiterator(): > > ... ? ? ? ?print el > [much output snipped] > > > > Hmm, I think I've worked it out. Apparently the XML namespace forms part of the tag name in this case. Is that what is intended? I didn't see any examples of this in the docs. -- Ben Sizer From nathan.alexander.rice at gmail.com Sat Jul 3 18:36:06 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 3 Jul 2010 18:36:06 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: Expert Python Programming by Tarek Ziade is a fairly good book, covers a lot of core stuff, though it doesn't really cover gui app development at all. On Sat, Jul 3, 2010 at 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. > > i've looked at the source of a few projects but the flow is way over > my head, i understand the syntax but not the logic, which is why i'm > looking for a project-cenetered learning resource, instead of a > reference or language-feature resource. also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? > > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From smallpox911 at gmail.com Sat Jul 3 19:12:09 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 16:12:09 -0700 (PDT) Subject: Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards Message-ID: <16ef11cf-7b5a-470a-bea2-52e298ec2aaf@s9g2000yqd.googlegroups.com> Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html Russia Watched 9/11 In Real Time On Satellite By Jon Carlson Your countrymen have been murdered and the more you delve into it the more it looks as though they were murdered by our government, who used it as an excuse to murder other people thousands of miles away. If you ridicule others who have sincere doubts and who know factual information that directly contradicts the official report and who want explanations from those who hold the keys to our government, and have motive, means, and opportunity to pull off a 9/11, but you are too lazy or fearful, or ... to check into the facts yourself, what does that make you? Full Statement of Lt. Col. Shelton F. Lankford, US Marine Corps (ret) Retired U.S. Marine Corps Fighter Pilot February 20, 2007 http://www.patriotsquestion911.com/Statement%20Lankford.html In April, 2006, Journalist Webster Tarpley interviewed Thierry Meyssan, President of the Voltaire Network, an organization of 20 different news agencies in Europe, Middle East and Africa, with correspondents in many countries. Thierry trumped America's pseudo-journalists with his 2002 book, Pentagate, drawing first blood on the Pentagon 9/11 Hoax. TM:. He (Gen. Ivashov) was the chief of armed forces in Russia on 9/11. He says the Russian forces were watching North America because of the large military exercises being carried out by the US that day, so they saw in real time by satellite what was happening on that day. TM: When they heard about the attacks, Pres. Putin tried to call Bush to tell him that the Russians were not involved. He was not able to reach him. But they understood already that the collapse of the buildings could not have been done by the planes. They already realized it was controlled demolition - an internal problem and not an external attack WGT. How did US government, the State Dept respond to your (Pentagate) critique? TM. First they said I would not be allowed to go your country any more. Then Ms. Clark of State Dept said that if any journalist talks about my book in the US they will not be allowed to attend press conferences at the Pentagon. They published on their website a page trying to refute my book. http://www.waronfreedom.org/tarpley/rbn/RBN-42206-Meyssan.html In April, 2005, writer Chevalier D?sire?, from France but formerly USA, revealed that Russia watched on their satellite as the A3 Skywarrior left a carrier and impacted the Pentagon: It seems that it is common knowledge in these circles that Russian satellites photographed a ship-launched craft (seems to have been a drone type plane rather than a missle) that ended up impacting the Pentagon on Sept 11, 2001, and that, for various reasons this information has been withheld from the public. I was naturally startled to hear this even though I have long held the opinion that it was NOT a commercial jetliner that hit the Pentagon. I think the thing that startled me was the fact that, if Russia (and perhaps other countries with satellites?) had proof that Flight 77 did not hit the Pentagon, why weren't they revealing this? http://web.archive.org/web/20050728121017/http://perfectinfidel.blogspot.com/2005/04/david-beckham-and-flight-77-in-paris.html In 2002 some US spy satellite photos from the sixties were released to the public domain: "It's a welcome move," said Steven Aftergood of the Project on Government Secrecy, an effort of the Federation of American Scientists and based in Washington, D.C. "First and foremost, these images are of historical interest. They feature images of national security significance that served as an important input to the U.S. Government policy process. So they can help historians shed some light on that process," Aftergood told SPACE.com. Considering that the Pentagon STILL hasn't released over 80 videos of the Pentagon Hoax, release of the satellite photos of the 9/11 mass murder is not in the cards. In our last installment the strong case was made that aircraft carrier USS George Washington anchored off Long Island just a short helicopter ride from Manhattan served as base of operations for 9/11: The 9/11 Base Of Operations: Aircraft Carrier USS George Washington http://home.att.net/~south.tower/911AirBase1.htm Of course, a satellite image of the USS George Washington plying the waters off Long Island during the 9/11 mass murder would be the final nail in the coffin. SPOT Satellite Images of World Trade Center Fires on September 11 at 11:55 AM: http://www.globalsecurity.org/eye/html/wtc_nyc-091101-2.htm Image from NASA's Terra Satellite shows the fire plume from Manhattan: http://www.globalsecurity.org/eye/html/wtc_modis-0912_redplumex500.htm NASA's Terra Satellite True-Color Image, taken Sept. 12, 2001: http://www.globalsecurity.org/eye/html/wtc_0913_ny_true.htm International Space Station still image, taken from video sent from the International Space Station September 11, 2001: http://www.globalsecurity.org/eye/html/wtc_074602b1.htm The Space Station website has several more 9/11 photos taken with just a video camera all following the pattern of CROPPING OUT THE AREA THE AIRCRAFT CARRIER USS GEORGE WASHINGTON IS ANCHORED. NASA is a branch of the US Navy, the kingpin of 9/11. http://spaceflight.nasa.gov/gallery/images/station/crew-3/in-flight/ndxpage6.html On 9/16/01, USA Today reported the presence of the USS George Washington: "The Pentagon refuses to say how many aircraft, ships and troops are defending U.S. territory or where they are ? even after TV cameras showed the carrier USS George Washington off New York". http://www.usatoday.com/news/nation/2001/09/16/military-home-front.htm The Jersey Girls want to Raise More Hell on Capitol Hill about 9/11 Truth. Many signers to their petition are leaving short, interesting comments. http://www.petitiononline.com/july10/ Drunken Bush Hurls Vile Insult At Wife (In Public) http://www.rense.com/general75/drunken.htm Edgar J. Steele's lucid and entertaining writing style lays the wood on Bush 9/11 and other crimes: We Hung the Wrong Guy! http://www.conspiracypenpal.com/rants/hung.htm MP Galloway Blasts Organized Attacks On Heroic Chavez http://www.rense.com/general75/cahv.htm As most MSM writers have no practical political party experience and are merely entertainers with no journalistic standards, most of what they say can be taken with a grain of salt. Former GOP insider Karl Schwarz has analyzed the state of American policies that are turning the US into the most hated country in the world even by Americans. Karl's views will be supported by most intelligent Americans: A Platform for America http://www.rense.com/general74/true.htm BBC Photos Corroborate A3 Skywarrior 9/11 Pentagon Hit http://home.att.net/~south.tower/BBCA3photos1.htm Latest analysis of the Pentagon Doubletree Video corroborates that a substitute A3 Skywarrior struck the Pentagon: The Doubletree Hotel 9/11 Pentagon Video http://home.att.net/~south.tower/KCDoubletree1.htm INVESTIGATOR Karl Schwarz was the originator of Intelligence that an A3 SKYWARRIOR, not a Flight AA77 Boeing 757 airliner, HIT THE PENTAGON ON 9/11. Now Karl tells the rest of the story: WHAT HIT THE PENTAGON? By Karl Schwarz http://home.att.net/~carlson.jon/911Pentagon.htm EXCLUSIVE 9/11 Pentagon A3 Skywarrior Wreckage Photos http://home.att.net/~carlson.jon/PentagonA3wreckage1.htm FBI Hides 911 Pentagon Hoax A3 Skywarrior Fuselage, Engine, & 9/11 Truth http://home.att.net/~carlson.jon/FBIHidesA3.htm CNN, Pentagon Videos Expose 9/11 White Jet & Helicopter http://home.att.net/~carlson.jon/Pentagonhelicopter.htm Smoking Gun Photos SHUT 9/11 Pentagon Coffin http://home.att.net/~carlson.jon/coffin.htm 9/11 A3 Skywarrior Wing Impact Caused Pentagon Fire Truck Fire http://home.att.net/~carlson.jon/A3firetruck.htm Rare German Photos Expose 911 Pentagon Hoax http://www.rense.com/general70/3o.htm Of course, DON'T MISS more 9/11 photos and analysis: The 9/11 Base Of Operations: Aircraft Carrier USS George Washington http://home.att.net/~south.tower/911AirBase1.htm Original WTC Design Document Spills NIST 9/11 Demolition Beans http://home.att.net/~south.tower/NISTdemolition1.htm The Flight Of The South Tower Drone Engine http://home.att.net/~south.tower/STengineroute1.htm A Close Look: The North Tower Napalm Bomb http://home.att.net/~south.tower/NTnapalmbombs1.htm CBS Video Shows Military Helicopter Leaving At South Tower Demolition http://home.att.net/~south.tower/STdemolition1.htm CNN Photos Catch South Tower 9/11 Show Director White Jet http://home.att.net/~south.tower/STWhiteJet1.htm Pentagon 9/11 Flight AA77 Left Telltale Engine http://home.att.net/~south.tower/PentagonWrongEngine1.htm Dirty Little 9/11 Secrets Exposed II http://home.att.net/~south.tower/KCDirtyLittle911SecretsII1.htm The 9/11 Keystone Cops Crime The Pavel Hlava Video http://home.att.net/~south.tower/KCPavelHlava1.htm The 9/11 Keystone Cops Crime The Missing Bush I Alibi http://home.att.net/~south.tower/KCBushIalibi1.htm The 9/11 Nutshell Timeline http://home.att.net/~south.tower/911NutshellTimeline1.htm North Tower Napalm Bombs: Two Misses, Two Duds http://home.att.net/~south.tower/NTnapalm1.htm South Tower Flight UA175 Dropped WRONG Engine In NYC Street http://home.att.net/~south.tower/STengine1.htm The NBC News Helicopter Views The South Tower Napalm Bomb http://home.att.net/~south.tower/NBCnapalmbomb10th1.htm The South Tower Crash Videos: COMMON ELEMENTS http://home.att.net/~carlson.jon/STCommonElements1.htm The South Tower Napalm Bomb SEVENTH VIEW http://home.att.net/~carlson.jon/WTCnapalmbomb7th1.htm The South Tower Napalm Bomb SIXTH VIEW http://home.att.net/~carlson.jon/WTCnapalmbomb6th1.htm The South Tower Napalm Bomb FIVE VIEWS http://home.att.net/~carlson.jon/ST5views.htm A CLOSE LOOK: The 9/11 Pentagon TARGET WALL http://home.att.net/~carlson.jon/Pentagondemolition1.htm CNN, Pentagon Videos Expose 9/11 White Jet & Helicopter http://home.att.net/~carlson.jon/Pentagonhelicopter.htm Smoking Gun Photos SHUT 9/11 Pentagon Coffin http://home.att.net/~carlson.jon/coffin.htm 9/11 A3 Skywarrior Wing Impact Caused Pentagon Fire Truck Fire http://home.att.net/~carlson.jon/A3firetruck.htm FBI Hides 911 Pentagon Hoax A3 Skywarrior Fuselage, Engine, & 9/11 Truth http://home.att.net/~carlson.jon/FBIHidesA3.htm Rare German Photos Expose 911 Pentagon Hoax http://www.rense.com/general70/3o.htm Karl Schwarz gives his insight http://www.rense.com/general70/more.htm On 911 An Ill Wind Blew Clinton To Australia: http://www.rense.com/general69/on911.htm Pentagon 9/11 Blue Tarp Photo Uncovered http://www.rense.com/general70/tarp.htm Showtime - Look Inside The 911 Smoke Plume http://www.rense.com/general69/show911.htm 911 Timeline Missing Pieces http://www.rense.com/general69/911ms.htm Hunt The Cherokee - The 9/11 Pentagon Impact http://www.rense.com/general69/hunt911.htm The 911 North Tower Air Show http://www.rense.com/general69/911hh.htm Professor Jones Teaches Tucker About 911 http://www.rense.com/general68/911nul.htm German Intel Agent Von Bulow Solves 9/11 http://www.rense.com/general68/911jh.htm Positive ID: The 9/11 South Tower Airliner 'PODS' http://www.rense.com/general68/poss911.htm FBI Claims 84 Videos Show NO Flight 77 Impact http://www.rense.com/general67/fbicl.htm 9/11 Flight 93 Passengers 'Lost' http://www.rense.com/general67/911pass.htm The 9/11 Pentagon Engine Story http://www.rense.com/general67/911eng.htm The 911 North Tower Demolition Explained http://www.rense.com/general67/9118.htm The Rest Of The 911 Flight 93 Story http://www.rense.com/general67/rest911.htm South Tower Exit Wounds Tell 9/11 Tale http://www.rense.com/general67/911uu.htm Dirty Little 9/11 Secrets Exposed http://www.rense.com/general66/dirt.htm Bush Responds To 911 Fireworks http://www.rense.com/general66/ressp.htm Hollywood-like Fake Smoke Made 9/11 http://www.rense.com/general65/911mir.htm WTC 7 Smoke & Mirrors On 9/11 http://www.rense.com/general65/911m.htm CBC 9/11 Video Secrets Revealed http://www.rense.com/general65/911b.htm 911 CNN Reports Boeing 737s Struck WTC http://www.rense.com/general65/911h.htm Sneak Preview - 911 Pentagon Tapes http://www.rense.com/general64/911et.htm The Rest Of The 9/11 Street Engine Story http://www.rense.com/general64/wth.htm NYC Photos, Flight 93 Witnesses Identify 9/11 White Jet http://www.rense.com/general64/white.htm On 9/11 An Ill Wind Blew to Booker School http://www.rense.com/general63/wte.htm WTC Jet Engine Confirmed NOT From Boeing 767 http://www.rense.com/general63/wtcc.htm Second 911 Remote Control Antenna Verified http://www.rense.com/general63/secnd.htm Avionics Expert-A 911 Remote Control Lesson for PM http://www.rense.com/general63/remo.htm WTC Cutter Charges Clearly Visible http://www.rense.com/general63/cutt.htm Real 911 Science For PM - The ST Airliner Photo http://www.rense.com/general63/st.htm PM Claims Landing Gear Made Pentagon 12 Foot Hole http://www.rense.com/general63/pmm.htm PM Missed NASA 911-type Airliner Crash 20 Years Ago http://www.rense.com/general63/pm.htm Is Popular Mechanics Hiding 911 NYC Engine In Street Photo? http://www.rense.com/general63/hiding.htm Missing Pentagon Jet Engine Identified? http://www.rense.com/general63/ident.htm Missing Pentagon Unobstructed Citgo Videos http://www.rense.com/general63/unob.htm From python at mrabarnett.plus.com Sat Jul 3 19:28:57 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 04 Jul 2010 00:28:57 +0100 Subject: IMAP Problems In-Reply-To: References: Message-ID: <4C2FC7B9.5070706@mrabarnett.plus.com> Paul Jefferson wrote: > Hi, > I'm trying to write a simple script which displays the basic details > of a person's mailbox. My problem is that it causes all the messages > to be marked as read on the server, which is not what I'm after, and > I also can't get the imap.sort command to work properly (currently > commented out as I replaced it with a imap.search to get the thing > working. > These are probably very simple things, but I've not tried this library > before so am a bit stuck so any help wwould be very gratefully > received. > Thanks, > Paul > > Code: > > # -*- coding: cp1252 -*- > import imaplib,email > > # you want to connect to a server; specify which server > server= imaplib.IMAP4_SSL('imap.googlemail.com > ') > # after connecting, tell the server who you are > server.login('x... > @gmail.com > ', 'xxxxxxx') > # this will show you a list of available folders > # possibly your Inbox is called INBOX, but check the list of mailboxes > code, mailboxen= server.list() > print mailboxen > # if it's called INBOX, then? > server.select("INBOX") > > typ, data = server.search(None, 'ALL') > #typ, data = server.sort("Date","UTF-8", 'ALL') > print len(data[0].split()) > for num in data[0].split(): > typ, data = server.fetch(num, '(RFC822)') > #print 'Message %s\n%s\n' % (num, data[0][1]) > msg = email.message_from_string(data[0][1]) > print msg["From"] > print msg["Subject"] > print msg["Date"] > print "_______________________________" > > server.close() > server.logout() > You might want to read what it says here: http://tools.ietf.org/html/rfc2060.html#page-41 If you can use '(BODY[])' instead of '(RFC822)' then you could use '(BODY.PEEK[])'. Alternatively, try: server.store(num, '-FLAGS', r'\Seen') to mark it as unread after fetching. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:23:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:23:21 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Rami Chowdhury wrote: > I'm sorry, perhaps you've misunderstood what I was refuting. You posted: >> >> macro: >> >> #define Descr(v) &v, sizeof v >> >> >> >> As written, this works whatever the type of v: array, struct, >> >> whatever. > > With my code example I found that, as others have pointed out, > unfortunately it doesn't work if v is a pointer to a heap-allocated area. It still correctly passes the address and size of that pointer variable. It that?s not what you intended, you shouldn?t use it. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:25:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:25:46 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Robert Kern wrote: > On 2010-06-25 19:47 , Lawrence D'Oliveiro wrote: > >> In message, Cameron >> Simpson wrote: >> >>> On 25Jun2010 15:38, Lawrence >>> D'Oliveiro wrote: >>> >>> | In message<2010062422432660794-angrybaldguy at gmailcom>, Owen Jacobson >>> | wrote: >>> >>> |> Why would I write this when SQLAlchemy, even without using its ORM >>> |> features, can do it for me? >>> | >>> | SQLAlchemy doesn?t seem very flexible. Looking at the code examples >>> |, they?re very >>> |procedural: build object, then do a string of separate method calls to >>> |add data to it. I prefer the functional approach, as in my table-update >>> |example. >>> >>> He said "without using its ORM". >> >> I noticed that. So were those examples I referenced above ?using its >> ORM?? Can you offer better examples ?without using its ORM?? > > http://www.sqlalchemy.org/docs/sqlexpression.html Still full of very repetitive boilerplate. Doesn?t look like it can create a simpler alternative to my example at all. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:28:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:28:20 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Robert Kern wrote: > On 2010-06-25 19:49 , Lawrence D'Oliveiro wrote: > >> Why do people consider input sanitization so hard? > > It's not hard per se; it's just repetitive, prone to the occasional > mistake, and, frankly, really boring. But as a programmer, I?m not in the habit of doing ?repetitive? and ?boring?. Look at the example I posted, and you?ll see. It?s the ones trying to come up with alternatives to my code who produce things that look ?reptitive? and ?boring?. From maaindia13 at gmail.com Sat Jul 3 21:44:50 2010 From: maaindia13 at gmail.com (quick money) Date: Sat, 3 Jul 2010 18:44:50 -0700 (PDT) Subject: See Hot College Girls Sex images Message-ID: <312c389a-48cb-465b-880f-818c149862f8@i16g2000prn.googlegroups.com> :See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. at http://ukcollegegirls.co.cc Due to high sex content,i have hidden the videos in an image. in that website on left side below search box click on image and watch videos in all angles.please dont tell to anyone. From ldo at geek-central.gen.new_zealand Sat Jul 3 22:33:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 14:33:44 +1200 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> Message-ID: In message , Nobody wrote: > On Tue, 29 Jun 2010 12:30:36 +1200, Lawrence D'Oliveiro wrote: > >>> Seriously, almost every other kind of library uses a binary API. What >>> makes databases so special that they need a string-command based API? >> >> HTML is also effectively a string-based API. > > HTML is a data format. The sane way to construct or manipulate HTML is via > the DOM, not string operations. What is this ?DOM? of which you speak? I looked here , but can find nothing that sounds like that, that is relevant to HTML. >> And what about regular expressions? > > What about them? As the saying goes: > > Some people, when confronted with a problem, think > "I know, I'll use regular expressions." > Now they have two problems. > > They have some uses, e.g. defining tokens[1]. Using them to match more > complex constructs is error-prone ... What if they?re NOT more complex, but they can simply contain user-entered data? >> And all the functionality available through the subprocess >> module and its predecessors? > > The main reason why everyone recommends subprocess over its predecessors > is that it allows you to bypass the shell, which is one of the most > common sources of the type of error being discussed in this thread. How would you deal with this, then: I wrote a script called ExtractMac, to convert various old Macintosh-format documents accumulated over the years (stored in AppleDouble form by uploading to a Netatalk server) to more cross-platform formats. This has a table of conversion commands to use. For example, the entries for PICT and TEXT Macintosh file types look like this: "PICT" : { "type" : "image", "ext" : ".png", "act" : "convert %(src)s %(dst)s", }, "TEXT" : { "type" : "text", "ext" : ".txt", "act" : "LineEndings unix <%(src)s >%(dst)s", }, The conversion code that uses this table looks like Cmd = \ ( Act.get("act", "cp -p %(src)s %(dst)s") % { "src" : ShellEscape(Src), "dst" : ShellEscape(DstFileName), } ) sys.stderr.write("Doing: %s\n" % Cmd) Status = os.system(Cmd) How much simpler would your alternative be? I don?t think it would be simpler at all. From rami.chowdhury at gmail.com Sat Jul 3 22:43:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 3 Jul 2010 19:43:44 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: Message-ID: <201007031943.44611.rami.chowdhury@gmail.com> On Saturday 03 July 2010 19:33:44 Lawrence D'Oliveiro wrote: > In message , Nobody wrote: > > On Tue, 29 Jun 2010 12:30:36 +1200, Lawrence D'Oliveiro wrote: > >>> Seriously, almost every other kind of library uses a binary API. What > >>> makes databases so special that they need a string-command based API? > >> > >> HTML is also effectively a string-based API. > > > > HTML is a data format. The sane way to construct or manipulate HTML is > > via the DOM, not string operations. > > What is this ?DOM? of which you speak? I looked here > , but can find nothing that sounds like > that, that is relevant to HTML. > The Document Object Model - I don't think the standard library has an HTML DOM module but there's certainly one for XML (and XHTML): http://docs.python.org/library/xml.dom.html ---- Rami Chowdhury "Any sufficiently advanced incompetence is indistinguishable from malice." -- Grey's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From greg.ewing at canterbury.ac.nz Sat Jul 3 22:50:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 04 Jul 2010 14:50:38 +1200 Subject: delegation pattern via descriptor In-Reply-To: <4c2f1b2f$0$17371$426a74cc@news.free.fr> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> Message-ID: <89aamgF7vdU1@mid.individual.net> Bruno Desthuilliers wrote: > kedra marbun a ?crit : > >>if we limit our discussion to py: >>why __{get|set|delete}__ don't receive the 'name' & 'class' from >>__{getattribute|{set|del}attr}__ >>'name' is the name that is searched > > > While it would have been technically possible, I fail to imagine any use > case for this. I think he wants to have generic descriptors that are shared between multiple attributes, but have them do different things based on the attribute name. That's not the way property descriptors are designed to be used -- it's assumed that each attribute will have its own descriptor, tailored for that particular attribute. If you want to handle attributes more generically, you need to intervene at the level of __getattribute__, __getattr__ and __setattr__. -- Greg From invalid at invalid.invalid Sat Jul 3 23:12:00 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 4 Jul 2010 03:12:00 +0000 (UTC) Subject: IMAP Problems References: Message-ID: > I'm trying to write a simple script which displays the basic details > of a person's mailbox. My problem is that it causes all the messages > to be marked as read on the server, > > code, mailboxen= server.list() > print mailboxen > # if it's called INBOX, then > server.select("INBOX") You probably want to try examine() instead of select(). That opens the mailbox in a read-only mode which and should avoid changing any flag values. >From RFC3501: The EXAMINE command is identical to SELECT and returns the same output; however, the selected mailbox is identified as read-only. No changes to the permanent state of the mailbox, including per-user state, are permitted; in particular, EXAMINE MUST NOT cause messages to lose the \Recent flag. -- Grant From sturlamolden at yahoo.no Sat Jul 3 23:30:30 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 3 Jul 2010 20:30:30 -0700 (PDT) Subject: Lua is faster than Fortran??? Message-ID: I was just looking at Debian's benchmarks. It seems LuaJIT is now (on median) beating Intel Fortran! C (gcc) is running the benchmarks faster by less than a factor of two. Consider that Lua is a dynamically typed scripting language very similar to Python. LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and SBCL. I know it's "just a benchmark" but this has to count as insanely impressive. Beating Intel Fortran with a dynamic scripting language, how is that even possible? And what about all those arguments that dynamic languages "have to be slow"? If this keeps up we'll need a Python to Lua bytecode compiler very soon. And LuaJIT 2 is rumoured to be much faster than the current... Looking at median runtimes, here is what I got: gcc 1.10 LuaJIT 1.96 Java 6 -server 2.13 Intel Fortran 2.18 OCaml 3.41 SBCL 3.66 JavaScript V8 7.57 PyPy 31.5 CPython 64.6 Perl 67.2 Ruby 1.9 71.1 The only comfort for CPython is that Ruby and Perl did even worse. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 00:15:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jul 2010 04:15:57 GMT Subject: Lua is faster than Fortran??? References: Message-ID: <4c300afc$0$28647$c3e8da3@news.astraweb.com> On Sat, 03 Jul 2010 20:30:30 -0700, sturlamolden wrote: > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, how > is that even possible? By being clever, using Just In Time compilation as much as possible, and almost certainly using masses of memory at runtime. (The usual trade-off between space and time.) See the PyPy project, which aims to do the same thing for Python as Lua have done. Their ultimate aim is to beat the C compiler and be faster than C. So far they've got a bit to go, but they're currently about twice as fast as CPython. > And what about all those arguments that dynamic > languages "have to be slow"? They're bullshit, of course. It depends on the nature of the dynamicism. Some things are inherently slow, but not everything. Fast, tight, dynamic: pick any two. > If this keeps up we'll need a Python to Lua bytecode compiler very soon. "Need" is a bit strong. There are plenty of applications where if your code takes 0.1 millisecond to run instead of 0.001, you won't even notice. Or applications that are limited by the speed of I/O rather than the CPU. But I'm nitpicking... this is a nice result, the Lua people should be proud, and I certainly wouldn't say no to a faster Python :) [...] > The only comfort for CPython is that Ruby and Perl did even worse. It's not like this is a race, and speed is not the only thing which a language is judged by. Otherwise you'd be programming in C, not Python, right? -- Steven From sturlamolden at yahoo.no Sun Jul 4 01:05:56 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 3 Jul 2010 22:05:56 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> Message-ID: <7c61eacb-4a85-4f90-a080-fe073488df2f@g19g2000yqc.googlegroups.com> On 4 Jul, 06:15, Steven D'Aprano wrote: > "Need" is a bit strong. There are plenty of applications where if your > code takes 0.1 millisecond to run instead of 0.001, you won't even > notice. Or applications that are limited by the speed of I/O rather than > the CPU. > But I'm nitpicking... this is a nice result, the Lua people should be > proud, and I certainly wouldn't say no to a faster Python :) Need might be too strong, sorry. I'm not a native speaker of English :) Don't read this as a complaint about Python being too slow. I don't care about milliseconds either. But I do care about libraries like Python's standard library, wxPython, NumPy, and matplotlib. And when I need C, C++ or Fortran I know where to fint it. Nobody in the scientific community would be sad if Python was so fast that no C or Fortran would have to be written. And I am sure Google and many other users of Python would not mind either. And this is kind of a proof that it can be. Considering that Lua is to Python what C is to C++ (more or less), it means that it is possible to make Python run very fast as well. Yes the LuaJIT team should be proud. Making a scripting language run faster than Fortran on CPU-bound work is a superhuman result. From sridharr at activestate.com Sun Jul 4 01:12:48 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sat, 03 Jul 2010 22:12:48 -0700 Subject: How to disable readline when building Python? Message-ID: <4C301850.5000204@activestate.com> For licensing reasons, I need to disable readline, except editline on OSX, when building Python. For the life of me, I cannot figure out how this can be done ("./configure --help" does not show anything relevant); I've tried the following, and readline.so will still be built: - ./configure --without-readline - ./configure --disable-readline - Set `do_readline = False` in setup.py This is for Python 2.6; and I am yet to port the same to 2.7. -srid From stefan_ml at behnel.de Sun Jul 4 02:33:17 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 08:33:17 +0200 Subject: Confusion over etree.ElementTree.Element.getiterator In-Reply-To: <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> Message-ID: Ben Sizer, 04.07.2010 00:32: > On Jul 3, 11:12 pm, Ben Sizer wrote: > >> >>> for el in root.getiterator(): >> >> ... print el >> [much output snipped] >> >> >> >> > > Hmm, I think I've worked it out. Apparently the XML namespace forms > part of the tag name in this case. Is that what is intended? Sure. > I didn't see any examples of this in the docs. Admittedly, it's three clicks away from the library docs on docs.python.org. http://effbot.org/zone/element.htm#xml-namespaces Stefan From stefan_ml at behnel.de Sun Jul 4 02:38:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 08:38:34 +0200 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: Rouslan Korneychuk, 03.07.2010 19:22: > The code also never uses PyArg_ParseTuple or its variants. It converts > every argument using the appropriate PyX_FromY functions. I noticed > PyBindGen does the following when a conversion is needed for one argument: > > py_retval = Py_BuildValue((char *) "(O)", value); > if (!PyArg_ParseTuple(py_retval, (char *) "i", &self->obj->y)) { > Py_DECREF(py_retval); > return -1; > } > Py_DECREF(py_retval); > > On the other hand, here's the implementation for __sequence__getitem__: > > PyObject * obj_DVector___sequence__getitem__(obj_DVector > *self,Py_ssize_t index) { > try { > std::vector > &base = > cast_base_DVector(reinterpret_cast(self)); > return PyFloat_FromDouble(base.at(py_ssize_t_to_ulong(index))); > > } EXCEPT_HANDLERS(0) > } Check the code that Cython uses for these things. It generates specialised type conversion code that has received a lot of careful benchmarking and testing on different platforms. Stefan From rami.chowdhury at gmail.com Sun Jul 4 03:12:30 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 4 Jul 2010 00:12:30 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <201007040012.31112.rami.chowdhury@gmail.com> On Saturday 03 July 2010 20:30:30 sturlamolden wrote: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! That's amazing! Congrats to the Lua team! > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: [snip] > The only comfort for CPython is that Ruby and Perl did even worse. Out of curiosity, does anyone know how the Unladen Swallow version of Python does by comparison? ---- Rami Chowdhury "Given enough eyeballs, all bugs are shallow." -- Linus' Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From cmpython at gmail.com Sun Jul 4 03:26:24 2010 From: cmpython at gmail.com (CM) Date: Sun, 4 Jul 2010 00:26:24 -0700 (PDT) Subject: python app development References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <28b6246b-0c8c-4660-8882-4f1d325c0e1f@x27g2000yqb.googlegroups.com> On Jul 3, 1:48?pm, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. Do you have a particular project in mind? Getting unstuck, I think, is about having a goal and then you'll begin to seek out what you need to make that happen (see below). > also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? I'm sure it varies greatly depending on the application. Depending on the complexity of the GUI and how much care goes into it, that can be a lot of code (it seems to me). > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. I don't know of a book oriented that way (sounds like a good idea), but you might take a look at this video "learning path" from the ShowMeDo website: http://showmedo.com/learningpaths/14/view It is focused on GUI (desktop and web) application development. There is a super basic starter video in there about making a Python image viewer application. Then the video series about building emol seems very thorough (there are 35 videos!), though I haven't watched it yet. What I would suggest is that you first decide what you want to accomplish. Then research and pick a GUI framework first (Tkinter, wxPython, PyQT, PyGTK), then whatever other tools you'll need (database? drawing? math/science?), which will either be in the standard library or in a 3rd party library. Any of the research on what tools to use can be Googled with bountiful results, as those questions are asked a lot. Then just jump in. This will prompt you to learn in a directed way. From stefan_ml at behnel.de Sun Jul 4 04:03:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 10:03:05 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: sturlamolden, 04.07.2010 05:30: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. Sort of. One of the major differences is the "number" type, which is (by default) a floating point type - there is no other type for numbers. The main reason why Python is slow for arithmetic computations is its integer type (int in Py3, int/long in Py2), which has arbitrary size and is an immutable object. So it needs to be reallocated on each computation. If it was easily mappable to a CPU integer, Python implementations could just do that and be fast. But its arbitrary size makes this impossible (or requires a noticeable overhead, at least). The floating point type is less of a problem, e.g. Cython safely maps that to a C double already. But the integer type is. So it's not actually surprising that Lua beats CPython (and the other dynamic languages) in computational benchmarks. It's also not surprising to me that a JIT compiler beats a static compiler. A static compiler can only see static behaviour of the code, potentially with an artificially constructed idea about the target data. A JIT compiler can see the real data that flows through the code and can optimise for that. Stefan From tlikonen at iki.fi Sun Jul 4 04:28:32 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 04 Jul 2010 11:28:32 +0300 Subject: Lua is faster than Fortran??? References: Message-ID: <87d3v3irbj.fsf@mithlond.arda> * 2010-07-04 10:03 (+0200), Stefan Behnel wrote: > The main reason why Python is slow for arithmetic computations is its > integer type (int in Py3, int/long in Py2), which has arbitrary size > and is an immutable object. So it needs to be reallocated on each > computation. If it was easily mappable to a CPU integer, Python > implementations could just do that and be fast. But its arbitrary size > makes this impossible (or requires a noticeable overhead, at least). > The floating point type is less of a problem, e.g. Cython safely maps > that to a C double already. But the integer type is. You may be right. I'll just add that Common Lisp's integers are of arbitrary size too but programmer can declare them as fixnums. Such declarations kind of promise that the numbers really are between most-negative-fixnum and most-positive-fixnum. Compiler can then optimize the code to efficient machine instructions. I guess Python might have use for some sort of (defun foo (variable) (declare (type fixnum variable)) ...) From wxjmfauth at gmail.com Sun Jul 4 04:31:41 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 4 Jul 2010 01:31:41 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? Message-ID: Python all versions. It's not a bug, but I'm suprised the following does not raise a SyntaxError (missing space between '9' and 'for'). >>> [9for c in 'abc'] [9, 9, 9] >>> Side effect: If this behaviour is considered as correct, it makes a correct Python code styling (IDLE, editors, ...) practically impossible to realise. From detlev at die-offenbachs.de Sun Jul 4 04:54:46 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 04 Jul 2010 10:54:46 +0200 Subject: [ANN] eric 5.0.0 released Message-ID: Hi, I just uploaded eric 5.0.0. This is the first official release. It is available via the eric web site. http://eric-ide.python-projects.org/index.html What is it? ----------- eric5 is the Python3 variant of the well know eric4 Python IDE and is the first development environment, that runs natively with Python3. It comes with all batteries included. The features are too much to be listed in this announcement. Please see the eric web site for details. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From dickinsm at gmail.com Sun Jul 4 04:55:16 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jul 2010 01:55:16 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: Message-ID: <169d86ca-70b6-4c3b-915b-99bed39b5373@y4g2000yqy.googlegroups.com> On Jul 4, 9:31?am, jmfauth wrote: > Python all versions. > > It's not a bug, but I'm suprised the following does > not raise a SyntaxError (missing space between > '9' and 'for'). > > > > >>> [9for c in 'abc'] > [9, 9, 9] > > Side effect: If this behaviour is considered as correct, > it makes a correct Python code styling (IDLE, editors, ...) > practically impossible to realise. Why? If Python itself has no problem parsing this code, why should it be so difficult for editors? Python's grammar is fairly simple: it's LL(1) (unlike C's, for example), so can be parsed with only 1 token of lookahead. -- Mark From dickinsm at gmail.com Sun Jul 4 05:02:10 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jul 2010 02:02:10 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <169d86ca-70b6-4c3b-915b-99bed39b5373@y4g2000yqy.googlegroups.com> Message-ID: <609ea5de-f88d-4948-9b7b-7b81ecb2695d@y11g2000yqm.googlegroups.com> On Jul 4, 9:55?am, Mark Dickinson wrote: > Why? ?If Python itself has no problem parsing this code, why should it > be so difficult for editors? ?Python's grammar is fairly simple: ?it's > LL(1) (unlike C's, for example), so can be parsed with only 1 token of > lookahead. Bah. Ignore the bit about C. I was thinking that the dangling else issue made this a problem, but now I'm not sure that's true. -- Mark From pauljefferson at gmail.com Sun Jul 4 05:50:25 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Sun, 4 Jul 2010 10:50:25 +0100 Subject: IMAP Problems In-Reply-To: References: Message-ID: Brilliant! Thanks guys I will have to have a play around later On 4 July 2010 04:12, Grant Edwards wrote: > > > I'm trying to write a simple script which displays the basic details > > of a person's mailbox. My problem is that it causes all the messages > > to be marked as read on the server, > > > > code, mailboxen= server.list() > > print mailboxen > > # if it's called INBOX, then? > > server.select("INBOX") > > You probably want to try examine() instead of select(). That opens > the mailbox in a read-only mode which and should avoid changing any > flag values. > > >From RFC3501: > > The EXAMINE command is identical to SELECT and returns the same > output; however, the selected mailbox is identified as > read-only. No changes to the permanent state of the mailbox, > including per-user state, are permitted; in particular, EXAMINE > MUST NOT cause messages to lose the \Recent flag. > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kedra.marbun at gmail.com Sun Jul 4 06:26:36 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 4 Jul 2010 03:26:36 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> Message-ID: <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> i'm confused which part that doesn't make sense? this is my 2nd attempt to py, the 1st was on april this year, it was just a month, i'm afraid i haven't got the fundamentals right yet. so i'm gonna lay out how i got to this conclusion, CMIIW **explanation of feeling (0) on my 1st post** to me, descriptor is a particular kind of delegation, it takes the job of coding the delegation by having a contract with programmers that the tree meta operations (get, set, del) on attr are delegated to the obj that is bound to the attr are we agree that descriptor is a kind of delegation? the mechanism that makes descriptor works is in __getattribute__, __setattr__, __delattr__ of 'object' & 'type' now, if i want a single descriptor obj to be delegated to multiple tasks, i can't do it since __get__ doesn't get info that can be used to determine which task to do i must have diff descriptor obj for each task class Helper: def __init__(self, name): self.name = name def __get__(self, ins, cls): if self.name == 'task0': ... elif self.name == 'task1': ... else: ... class a: task0 = Helper('task0') task1 = Helper('task1') if __get__ receives the name, then i could do class Helper: def __get__(self, ins, cls, name): ... class a: task0 = task1 = Helper() but after explaining this, i have more doubt on my own stmt in the 1st post "not passing name strengthens the coupling between delegator & delegate". now i think it's more likely the opposite, it weakens the coupling at the expense of more objs. moreover, is it wrong to justify that descriptor is a kind of delegation? my ego speaks: - i think, if the name is passed on, programmers can choose to use it or not (i don't know if it brokes any py principle, i only know KISS) - i realize that using name as the info that descriptors use to determine which task to do, is going to strongly couple the descriptor & the classes that use it, meaning that the descriptor & the user classes must agree on attr names to be used. a simple solution to it is by mapping attr names & names used in the descriptor class Helper: def __init__(self, name_map=None): self.name_map = name_map def __get__(self, ins, cls, name): if self.name_map is None: if name == 'task0': ... ... else: if self.name_map[name] == 'task0': ... ... class a: do_this = do_that = Helper({'do_this':'task0', 'do_that':'task1'}) finally, like all shared things, shared descriptor objs require more effort for synchronization From pavlovevidence at gmail.com Sun Jul 4 06:35:31 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 4 Jul 2010 03:35:31 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: Message-ID: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> On Jul 4, 1:31?am, jmfauth wrote: > Python all versions. > > It's not a bug, but I'm suprised the following does > not raise a SyntaxError (missing space between > '9' and 'for'). > > >>> [9for c in 'abc'] > [9, 9, 9] It does seem strange that Python's lexer wouldn't consider 9for as a single token. Even tough it's not a valid token in Python, your eye kind of sees it as one, so wouldn't it be better to raise a syntax error? Some other places were keyword can follow a number: 9if 0 else 1 (but not "9if 0else 1") 9and 0 9or 0 9in (1,2,3) 9is None > Side effect: If this behaviour is considered as correct, > it makes a correct Python code styling (IDLE, editors, ...) > practically impossible to realise. I'm not sure why an odd corner of the grammar would mess the whole thing up. Most code stylers only approximate the actual grammar anyway. Carl Banks From kedra.marbun at gmail.com Sun Jul 4 06:35:37 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 4 Jul 2010 03:35:37 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: thanks Greg, you get most of what i meant like i said before, i suspect descriptor encourages dedicated / not shared descriptor obj. this encouragement is expressed in the design, and the reasons behind the design were the ones that i was asking about, not how to get around it now, i'm asking another favor, what about the 2nd point in my 1st post? From cournape at gmail.com Sun Jul 4 08:29:59 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 4 Jul 2010 21:29:59 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: On Sun, Jul 4, 2010 at 5:03 PM, Stefan Behnel wrote: > sturlamolden, 04.07.2010 05:30: >> >> I was just looking at Debian's benchmarks. It seems LuaJIT is now (on >> median) beating Intel Fortran! >> >> C (gcc) is running the benchmarks faster by less than a factor of two. >> Consider that Lua is a dynamically typed scripting language very >> similar to Python. > > Sort of. One of the major differences is the "number" type, which is (by > default) a floating point type - there is no other type for numbers. The > main reason why Python is slow for arithmetic computations is its integer > type (int in Py3, int/long in Py2), which has arbitrary size and is an > immutable object. So it needs to be reallocated on each computation. If it > was easily mappable to a CPU integer, Python implementations could just do > that and be fast. But its arbitrary size makes this impossible (or requires > a noticeable overhead, at least). The floating point type is less of a > problem, e.g. Cython safely maps that to a C double already. But the integer > type is. Actually, I think the main reason why Lua is much faster than other dynamic languages is its size. The language is small. You don't list, dict, tuples, etc... Making 50 % of python fast is "easy" (in the sense that it has been done). I would not be surprised if it is exponentially harder the closer you get to 100 %. Having a small language means that the interpreter is small - small enough to be kept in L1, which seems to matter a lot (http://www.reddit.com/r/programming/comments/badl2/luajit_2_beta_3_is_out_support_both_x32_x64/c0lrus0). If you are interested in facts and technical details (rather than mere speculations), this thread is interesting http://lambda-the-ultimate.org/node/3851. It has participation of LuaJIT author, Pypy author and Brendan Eich :) > It's also not surprising to me that a JIT compiler beats a static compiler. > A static compiler can only see static behaviour of the code, potentially > with an artificially constructed idea about the target data. A JIT compiler > can see the real data that flows through the code and can optimise for that. Although I agree that in theory, it is rather obvious that a JIT compiler can do many things that static analysis cannot, this is the first time it has happened in practice AFAIK. Even hotspot was not faster than fortran and C, and it has received tons of work by people who knew what they were doing. The only example of a dynamic language being as fast/faster than C that I am aware of so far is Staline, the aggressive compiler for scheme (used in signal processing in particular). David From m.1ahesh at gmail.com Sun Jul 4 09:44:36 2010 From: m.1ahesh at gmail.com (manoj kumar) Date: Sun, 4 Jul 2010 06:44:36 -0700 (PDT) Subject: High Revenue Keywords Message-ID: <9dbfef3c-8edb-4f78-818a-a537035609dc@18g2000prq.googlegroups.com> Check Out High Revenue Keywords In All Niche's At, http://highrevenuekeywords.blogspot.com/ . Stuff Your Content With These High Revenue Keywords And Maximize Your PPC Pay Per Click Value Doubling Your Revenue For All Clicks.. From wxjmfauth at gmail.com Sun Jul 4 09:49:28 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 4 Jul 2010 06:49:28 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: On 4 juil, 12:35, Carl Banks wrote: > On Jul 4, 1:31?am, jmfauth wrote: > Thanks for having explained in good English my feelings. > > Some other places were keyword can follow a number: > Note, that this does not envolve numbers only. >>> ['z' for c in 'abc'] ['z', 'z', 'z'] >>> 'z'if True else 'a' z >>> > > Side effect: If this behaviour is considered as correct, > > it makes a correct Python code styling (IDLE, editors, ...) > > practically impossible to realise. > > I'm not sure why an odd corner of the grammar would mess the whole > thing up. ?Most code stylers only approximate the actual grammar > anyway. > I guess, most editors (so do I) are mainly using a "re" engine for their styling. --- Not a keyword, but space related, what should I thing about this? >>> print9 Traceback (most recent call last): File "", line 1, in NameError: name 'print9' is not defined >>> print+9 9 >>> print'abc' abc >>> print9.0 File "", line 1 print9.0 ^ SyntaxError: invalid syntax >>> Regards, jmf From darcy at druid.net Sun Jul 4 10:23:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 10:23:48 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: <4c300afc$0$28647$c3e8da3@news.astraweb.com> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> Message-ID: <20100704102348.6e25c22e.darcy@druid.net> On 04 Jul 2010 04:15:57 GMT Steven D'Aprano wrote: > "Need" is a bit strong. There are plenty of applications where if your > code takes 0.1 millisecond to run instead of 0.001, you won't even > notice. Or applications that are limited by the speed of I/O rather than > the CPU. Which is 99% of the real-world applications if you factor out the code already written in C or other compiled languages. That's the point of Python after all. You speed up programming rather than programs but allow for refactoring into C when necessary. And it's not call CPython for nothing. off-the-shelf benchmarks are fun but mostly useless for choosing a language, priogram, OS or machine unless you know that it checks the actual things that you need in the proportion that you need. > But I'm nitpicking... this is a nice result, the Lua people should be > proud, and I certainly wouldn't say no to a faster Python :) Ditto, ditto, ditto and ditto. > It's not like this is a race, and speed is not the only thing which a > language is judged by. Otherwise you'd be programming in C, not Python, > right? Or assembler. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From cournape at gmail.com Sun Jul 4 10:46:10 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 4 Jul 2010 23:46:10 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <20100704102348.6e25c22e.darcy@druid.net> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: > On 04 Jul 2010 04:15:57 GMT > Steven D'Aprano wrote: >> "Need" is a bit strong. There are plenty of applications where if your >> code takes 0.1 millisecond to run instead of 0.001, you won't even >> notice. Or applications that are limited by the speed of I/O rather than >> the CPU. > > Which is 99% of the real-world applications if you factor out the code > already written in C or other compiled languages. This may be true, but there are areas where the percentage is much lower. Not everybody uses python for web development. You can be a python fan, be reasonably competent in the language, and have good reasons to wish for python to be one order of magnitude faster. I find LUA quite interesting: instead of providing a language simple to develop in, it focuses heavily on implementation simplicity. Maybe that's the reason why it could be done at all by a single person. David From bartc at freeuk.com Sun Jul 4 10:47:31 2010 From: bartc at freeuk.com (bart.c) Date: Sun, 4 Jul 2010 15:47:31 +0100 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: "sturlamolden" wrote in message news:daa07acb-d525-4e32-91f0-16490027cc42 at w12g2000yqj.googlegroups.com... > > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: > > gcc 1.10 > > LuaJIT 1.96 > > Java 6 -server 2.13 > Intel Fortran 2.18 > OCaml 3.41 > SBCL 3.66 > > JavaScript V8 7.57 > > PyPy 31.5 > CPython 64.6 > Perl 67.2 > Ruby 1.9 71.1 > > The only comfort for CPython is that Ruby and Perl did even worse. I didn't see the same figures; LuaJIT seem to be 4-5 times as slow as one of the C's, on average. Some benchmarks were slower than that. But I've done my own brief tests and I was quite impressed with LuaJIT which seemed to outperform C on some tests. I'm developing my own language and LuaJIT is a new standard to beat for this type of language. However, Lua is quite a lightweight language with minimalist data types, it doesn't suit everybody. I suspect also the Lua JIT compiler optimises some of the dynamicism out of the language (where it can see, for example, that something is always going to be a number, and Lua only has one numeric type with a fixed range), so that must be a big help. -- Bartc From darcy at druid.net Sun Jul 4 11:00:47 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 11:00:47 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: <20100704110047.d7d77cae.darcy@druid.net> On Sun, 4 Jul 2010 23:46:10 +0900 David Cournapeau wrote: > On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: > > Which is 99% of the real-world applications if you factor out the code > > already written in C or other compiled languages. > > This may be true, but there are areas where the percentage is much > lower. Not everybody uses python for web development. You can be a > python fan, be reasonably competent in the language, and have good > reasons to wish for python to be one order of magnitude faster. I wish it was orders of magnitude faster for web development. I'm just saying that places where we need compiled language speed that Python already has that in C. But, as I said in the previous message, in the end it is up to you to write your own benchmark based on the operations you need and the usage patterns you predict that it will need as well. If your application needs to calculate Pi to 100 places but only needs to do it once there is no need to include that in your benchmark a million times. A language that is optimized for calculating Pi shouln't carry a lot of weight for you. > I find LUA quite interesting: instead of providing a language simple > to develop in, it focuses heavily on implementation simplicity. Maybe > that's the reason why it could be done at all by a single person. Is that really true about LUA? I haven't looked that closely at it but that paragraph probably turned off most people on this list to LUA. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Sun Jul 4 11:05:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 11:05:04 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <20100704110504.dbd8342e.darcy@druid.net> On Sat, 3 Jul 2010 20:30:30 -0700 (PDT) sturlamolden wrote: > CPython 64.6 By the way, I assume that that's Python 2.x. I wonder how Python 3.1 would fare. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From thomas at jollans.com Sun Jul 4 11:08:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 04 Jul 2010 17:08:50 +0200 Subject: SyntaxError not honoured in list comprehension? In-Reply-To: References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: <4C30A402.3030005@jollans.com> On 07/04/2010 03:49 PM, jmfauth wrote: > On 4 juil, 12:35, Carl Banks wrote: >> On Jul 4, 1:31 am, jmfauth wrote: >> > > > Thanks for having explained in good English my feelings. > > >> >> Some other places were keyword can follow a number: >> > > Note, that this does not envolve numbers only. > >>>> ['z' for c in 'abc'] > ['z', 'z', 'z'] >>>> 'z'if True else 'a' > z >>>> > > > >>> Side effect: If this behaviour is considered as correct, >>> it makes a correct Python code styling (IDLE, editors, ...) >>> practically impossible to realise. >> >> I'm not sure why an odd corner of the grammar would mess the whole >> thing up. Most code stylers only approximate the actual grammar >> anyway. >> > > I guess, most editors (so do I) are mainly using > a "re" engine for their styling. > > --- > > Not a keyword, but space related, what should I thing > about this? > >>>> print9 looks like an identifier > Traceback (most recent call last): > File "", line 1, in > NameError: name 'print9' is not defined >>>> print+9 can't be a single identifier. Maybe it's a print statement followed by stuff? (stop being a statement, print!) > 9 >>>> print'abc' can't be an identifier or string literal. Maybe it's a print statement followed by stuff? > abc >>>> print9.0 looks like getattr(print9, '0') - but '0' is not a valid name. Impossible. Error! > File "", line 1 > print9.0 > ^ > SyntaxError: invalid syntax >>>> somewhat strange, yes. From cournape at gmail.com Sun Jul 4 11:25:58 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 00:25:58 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <20100704110047.d7d77cae.darcy@druid.net> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On Mon, Jul 5, 2010 at 12:00 AM, D'Arcy J.M. Cain wrote: > On Sun, 4 Jul 2010 23:46:10 +0900 > David Cournapeau wrote: >> On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: >> > Which is 99% of the real-world applications if you factor out the code >> > already written in C or other compiled languages. >> >> This may be true, but there are areas where the percentage is much >> lower. Not everybody uses python for web development. You can be a >> python fan, be reasonably competent in the language, and have good >> reasons to wish for python to be one order of magnitude faster. > > I wish it was orders of magnitude faster for web development. ?I'm just > saying that places where we need compiled language speed that Python > already has that in C. Well, I wish I did not have to use C, then :) For example, as a contributor to numpy, it bothers me at a fundamental level that so much of numpy is in C. Also, there are some cases where using C for speed is very difficult, because the marshalling cost almost entirely alleviate the speed advantages - that means you have to write in C more than you anticipated. Granted, those may be quite specific to scientific applications, and cython already helps quite a fair bit in those cases. > > But, as I said in the previous message, in the end it is up to you to > write your own benchmark based on the operations you need and the usage > patterns you predict that it will need as well. ?If your application > needs to calculate Pi to 100 places but only needs to do it once there > is no need to include that in your benchmark a million times. I would question the sanity of anyone choosing a language because it can compute Pi to 100 places very quickly :) I am sure google search would beat most languages if you count implementation + running time anyway. > >> I find LUA quite interesting: instead of providing a language simple >> to develop in, it focuses heavily on implementation simplicity. Maybe >> that's the reason why it could be done at all by a single person. > > Is that really true about LUA? ?I haven't looked that closely at it but > that paragraph probably turned off most people on this list to LUA. I hope I did not turn anyone off - but it is definitely not the same set of tradeoff as python. LUA runtime is way below 1 Mb, for example, which is one reason why it is so popular for video games. The following presentation gives a good overview (by LUA creator): http://www.stanford.edu/class/ee380/Abstracts/100310-slides.pdf To go back to the original topic: a good example is numeric types. In python, you have many different numerical types with different semantics. In LUA, it is much simpler. This makes implementation simpler, and some aggressive optimizations very effective. The fact that a LUA interpreter can fit in L1 is quite impressive. David From benjamin at python.org Sun Jul 4 11:34:57 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 4 Jul 2010 10:34:57 -0500 Subject: [RELEASE] Python 2.7 released Message-ID: On behalf of the Python development team, I'm jocund to announce the second release candidate of Python 2.7. Python 2.7 will be the last major version in the 2.x series. However, it will also have an extended period of bugfix maintenance. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7 visit: http://www.python.org/download/releases/2.7/ 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a production release and should be suitable for all libraries and applications. Please report any bugs you find, so they can be fixed in the next maintenance releases. The bug tracker is at: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From jml at mumak.net Sun Jul 4 11:36:19 2010 From: jml at mumak.net (Jonathan Lange) Date: Sun, 4 Jul 2010 16:36:19 +0100 Subject: Twisted 10.1.0 released Message-ID: On behalf of Twisted Matrix Laboratories, I am honored to announce the release of Twisted 10.1.0. Highlights include: * Deferreds now support cancellation * A new "endpoint" interface which can abstractly describe stream transport endpoints such as TCP and SSL * inotify support for Linux, which allows monitoring of file system events. * AMP supports transferring timestamps Note also that this is the *last* supported release of Twisted for Python 2.4 on Windows. For more information, see the NEWS file. It's stable, backwards compatible, well tested and in every way an improvement. Download it now from: http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.tar.bz2 http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.5.msi http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.6.msi Many thanks to Glyph Lefkowitz, who helped do the release preparation, and the PyCon 2010 sprinters, who did so much of the work for this release. jml From sturlamolden at yahoo.no Sun Jul 4 12:00:23 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:00:23 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <303c834a-3737-4f57-8de5-2bb23fa883e5@5g2000yqz.googlegroups.com> On 4 Jul, 16:47, "bart.c" wrote: > I suspect also the Lua JIT compiler optimises some of the dynamicism out of > the language (where it can see, for example, that something is always going > to be a number, and Lua only has one numeric type with a fixed range), so > that must be a big help. Python could do the same, replace int and float with a "long double". It is 80 bit and has a 64 bit mantissa. So it can in theory do the job of all floating point types and integers up to 64 bit (signed and unsigned). A long double can 'duck type' all the floating point and integer types we use. There is really no need for more than one number type. For an interpreted language, it's just a speed killer. Other number types belong in e.g. the ctypes, array, struct and NumPy modules. Speed wise a long double (80 bit) is the native floating point type on x86 FPUs. There is no penalty memory-wise either, wrapping an int as PyObject takes more space. For a dynamic language it can be quite clever to just have one 'native' number type, observing that the mantissa of a floating point number is an unsigned integer. That takes a lot of the dynamicity out of the equation. Maybe you like to have integers and floating point types in the 'language'. But that does not mean it should be two types in the 'implementation' (i.e. internally in the VM). The implementation could duck type both with a suffciently long floating point type, and the user would not notice in the syntax. MATLAB does the same as Lua. Native number types are always double, you have to explicitly create the other. Previously they did not even exist. Scientists have been doing numerical maths with MATLAB for decades. MATLAB never prevented me from working with integers mathematically, even if I only worked with double. If I did not know, I would not have noticed. a = 1; % a is a double a = 1 + 1; % a is a double and exactly 2 a = int32(1); Sturla From benjamin at python.org Sun Jul 4 12:03:47 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 4 Jul 2010 11:03:47 -0500 Subject: [RELEASE] Python 2.7 released In-Reply-To: References: Message-ID: 2010/7/4 Benjamin Peterson : > On behalf of the Python development team, I'm jocund to announce the second > release candidate of Python 2.7. Arg!!! This should, of course, be "final release". -- Regards, Benjamin From sturlamolden at yahoo.no Sun Jul 4 12:12:05 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:12:05 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> On 4 Jul, 10:03, Stefan Behnel wrote: > Sort of. One of the major differences is the "number" type, which is (by > default) a floating point type - there is no other type for numbers. The > main reason why Python is slow for arithmetic computations is its integer > type (int in Py3, int/long in Py2), which has arbitrary size and is an > immutable object. So it needs to be reallocated on each computation. That is why Lua got it right. A floating point type has a mantissa and can duck type an integer. MATLAB does the same. Sturla If it > was easily mappable to a CPU integer, Python implementations could just do > that and be fast. But its arbitrary size makes this impossible (or requires > a noticeable overhead, at least). The floating point type is less of a > problem, e.g. Cython safely maps that to a C double already. But the > integer type is. > > So it's not actually surprising that Lua beats CPython (and the other > dynamic languages) in computational benchmarks. > > It's also not surprising to me that a JIT compiler beats a static compiler. > A static compiler can only see static behaviour of the code, potentially > with an artificially constructed idea about the target data. A JIT compiler > can see the real data that flows through the code and can optimise for that. > > Stefan From sturlamolden at yahoo.no Sun Jul 4 12:21:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:21:24 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> On 4 Jul, 14:29, David Cournapeau wrote: > Actually, I think the main reason why Lua is much faster than other > dynamic languages is its size. The language is small. You don't list, > dict, tuples, etc... They have managed to combine list and dict into one type (table) that does the job of both. And yes there are tuples. There are no classes, but there are closures and other building blocks that can be used to create any object-oriented type system (just like CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I imagine it would be possible to define an equivalent to the Python type system in Lua, and compile Python to Lua. Lua can be compiled to Lua byte code. Factoring Lua, out that means we should be able to compile Python to Lua byte code. From cournape at gmail.com Sun Jul 4 12:34:57 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 01:34:57 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> References: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> Message-ID: On Mon, Jul 5, 2010 at 1:12 AM, sturlamolden wrote: > On 4 Jul, 10:03, Stefan Behnel wrote: > >> Sort of. One of the major differences is the "number" type, which is (by >> default) a floating point type - there is no other type for numbers. The >> main reason why Python is slow for arithmetic computations is its integer >> type (int in Py3, int/long in Py2), which has arbitrary size and is an >> immutable object. So it needs to be reallocated on each computation. > > That is why Lua got it right. A floating point type has a mantissa and > can duck type an integer. MATLAB does the same. I sincerly doubt it - where do take the information that matlab use float to represent int ? It would not be able to represent the full range of 64 bits integer for example. David From sturlamolden at yahoo.no Sun Jul 4 12:37:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:37:17 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> On 4 Jul, 09:12, Rami Chowdhury wrote: > Out of curiosity, does anyone know how the Unladen Swallow version of Python > does by comparison? Judging from their PyCon slides, it's roughly 1.5 times faster than CPython. That might be important to Google, but not to me. From sturlamolden at yahoo.no Sun Jul 4 12:50:00 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:50:00 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> Message-ID: On 4 Jul, 18:34, David Cournapeau wrote: > I sincerly doubt it - where do take the information that matlab use > float to represent int ? I've used Matlab since 1994, so I know it rather well... Only the recent versions can do arithmetics with number types different from double (or complex double). > It would not be able to represent the full > range of 64 bits integer for example. There is a 53 bit mantissa plus a sign bit. Nobody complained on 32 bit systems. That is, when the signed 54 bit integer contained in a double was overflowed, there was a loss of precision but the numerical range would still be that of a double. You get an unsigned integer in MATLAB like this x = uint64(0) but until recently, MATLAB could not do any arithmetics with it. It was there for interaction with Java and C MEX files. A long double has a mantissa of 64 bit however, so it can represent signed 65 bit integers without loss of precision. From stefan_ml at behnel.de Sun Jul 4 13:02:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 19:02:13 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 18:37: > On 4 Jul, 09:12, Rami Chowdhury wrote: > >> Out of curiosity, does anyone know how the Unladen Swallow version of Python >> does by comparison? > > Judging from their PyCon slides, it's roughly 1.5 times faster than > CPython. A number like "1.5 times faster" is meaningless without a specific application and/or code section in mind. I'm pretty sure there are cases where they are much faster than that, and there are cases where the net gain is zero (or -0.x or whatever). Stefan From sturlamolden at yahoo.no Sun Jul 4 13:10:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 10:10:21 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: On 4 Jul, 19:02, Stefan Behnel wrote: > A number like "1.5 times faster" is meaningless without a specific > application and/or code section in mind. I'm pretty sure there are cases > where they are much faster than that, and there are cases where the net > gain is zero (or -0.x or whatever). Here is what they say: Benchmark CPython Unladen Change 2to3 25.13 s 24.87 s 1.01x faster django 1.08 s 0.68 s 1.59x faster html5lib 14.29 s 13.20 s 1.08x faster nbody 0.51 s 0.28 s 1.84x faster rietveld 0.75 s 0.55 s 1.37x faster slowpickle 0.75 s 0.55 s 1.37x faster slowspitfire 0.83 s 0.61 s 1.36x faster slowunpickle 0.33 s 0.26 s 1.26x faster spambayes 0.31 s 0.34 s 1.10x slower From stefan_ml at behnel.de Sun Jul 4 13:51:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 19:51:21 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 19:10: > On 4 Jul, 19:02, Stefan Behnel wrote: > >> A number like "1.5 times faster" is meaningless without a specific >> application and/or code section in mind. I'm pretty sure there are cases >> where they are much faster than that, and there are cases where the net >> gain is zero (or -0.x or whatever). > > Here is what they say: > > Benchmark CPython Unladen Change > 2to3 25.13 s 24.87 s 1.01x faster > django 1.08 s 0.68 s 1.59x faster > html5lib 14.29 s 13.20 s 1.08x faster > nbody 0.51 s 0.28 s 1.84x faster > rietveld 0.75 s 0.55 s 1.37x faster > slowpickle 0.75 s 0.55 s 1.37x faster > slowspitfire 0.83 s 0.61 s 1.36x faster > slowunpickle 0.33 s 0.26 s 1.26x faster > spambayes 0.31 s 0.34 s 1.10x slower Ok, so, which of those do you care about? Stefan From no.email at nospam.invalid Sun Jul 4 14:26:47 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 04 Jul 2010 11:26:47 -0700 Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: <7xhbkfje6w.fsf@ruckus.brouhaha.com> "D'Arcy J.M. Cain" writes: >> I find LUA quite interesting: instead of providing a language simple >> to develop in, it focuses heavily on implementation simplicity. Maybe >> that's the reason why it could be done at all by a single person. > > Is that really true about LUA? I haven't looked that closely at it but > that paragraph probably turned off most people on this list to LUA. I would say Lua focuses on implementation compactness; it's intended as an embedded scripting interpreter. It's easy to sandbox and uses just 50k or so of memory. It's running in a lot of mobile phones, cameras, etc. The language itself is nowhere near as featureful as Python and I wouldn't want to use it for large scale development, but it appears pretty good for what it was intended for. Interestingly, it doesn't have lists or arrays. Its only container structure is comparable to a Python dictionary. Arrays are just the special case of dictionaries indexed by numbers. There is a little bit of syntax sugar to help with that, but it's just the dict structure underneath. I wouldn't say it was all done by one person though, and in particular I think LuaJIT was done by a different group than the main Lua developers. From sturlamolden at yahoo.no Sun Jul 4 15:44:45 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 12:44:45 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: On 4 Jul, 19:51, Stefan Behnel wrote: > Ok, so, which of those do you care about? I have already said I don't care about unladen swallow. From luismgz at gmail.com Sun Jul 4 15:51:42 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 4 Jul 2010 12:51:42 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: On Jul 4, 12:30?am, sturlamolden wrote: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: > > ? ?gcc ? ? ? ? ? ? ? 1.10 > > ? ?LuaJIT ? ? ? ? ? ?1.96 > > ? ?Java 6 -server ? ?2.13 > ? ?Intel Fortran ? ? 2.18 > ? ?OCaml ? ? ? ? ? ? 3.41 > ? ?SBCL ? ? ? ? ? ? ?3.66 > > ? ?JavaScript V8 ? ? 7.57 > > ? ?PyPy ? ? ? ? ? ? 31.5 > ? ?CPython ? ? ? ? ?64.6 > ? ?Perl ? ? ? ? ? ? 67.2 > ? ?Ruby 1.9 ? ? ? ? 71.1 > > The only comfort for CPython is that Ruby and Perl did even worse. You should read this thread: http://lambda-the-ultimate.org/node/3851 There, you'll see this subject discussed and explained at length. Pay special attention to Mike Pall's comments (he is the creator of Luajit) and his opinion about python and pypy. You will read also about other projects, specially new javascript engines such as Mozila's Tracemonkey (the authors participate in this thread) and the pypy folks. It is a very good read for anyone interested in the subject. Very recommended! Good luck! Luis From stefan_ml at behnel.de Sun Jul 4 15:59:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 21:59:35 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 21:44: > On 4 Jul, 19:51, Stefan Behnel wrote: >> Ok, so, which of those do you care about? > > I have already said I don't care about unladen swallow. What I meant, was: which of these benchmarks would have to be better to make you care? Because your decision not to care seems to be based on exactly these benchmarks. Stefan From luismgz at gmail.com Sun Jul 4 16:04:11 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 4 Jul 2010 13:04:11 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <3532d127-1908-496f-a336-ab6f3c9782be@t10g2000yqg.googlegroups.com> On Jul 4, 4:51?pm, Luis M. Gonz?lez wrote: > On Jul 4, 12:30?am, sturlamolden wrote: > > > > > > > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > > median) beating Intel Fortran! > > > C (gcc) is running the benchmarks faster by less than a factor of two. > > Consider that Lua is a dynamically typed scripting language very > > similar to Python. > > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > > SBCL. > > > I know it's "just a benchmark" but this has to count as insanely > > impressive. Beating Intel Fortran with a dynamic scripting language, > > how is that even possible? And what about all those arguments that > > dynamic languages "have to be slow"? > > > If this keeps up we'll need a Python to Lua bytecode compiler very > > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > > Looking at median runtimes, here is what I got: > > > ? ?gcc ? ? ? ? ? ? ? 1.10 > > > ? ?LuaJIT ? ? ? ? ? ?1.96 > > > ? ?Java 6 -server ? ?2.13 > > ? ?Intel Fortran ? ? 2.18 > > ? ?OCaml ? ? ? ? ? ? 3.41 > > ? ?SBCL ? ? ? ? ? ? ?3.66 > > > ? ?JavaScript V8 ? ? 7.57 > > > ? ?PyPy ? ? ? ? ? ? 31.5 > > ? ?CPython ? ? ? ? ?64.6 > > ? ?Perl ? ? ? ? ? ? 67.2 > > ? ?Ruby 1.9 ? ? ? ? 71.1 > > > The only comfort for CPython is that Ruby and Perl did even worse. > > You should read this thread:http://lambda-the-ultimate.org/node/3851 > There, you'll see this subject discussed and explained at length. > Pay special attention to Mike Pall's comments (he is the creator of > Luajit) and his opinion about python and pypy. > You will read also about other projects, specially new javascript > engines such as Mozila's Tracemonkey (the authors participate in this > thread) and the pypy folks. > It is a very good read for anyone interested in the subject. Very > recommended! > Good luck! > > Luis To be more specific, check these comments on the above the above suggested thread: http://lambda-the-ultimate.org/node/3851#comment-57804 http://lambda-the-ultimate.org/node/3851#comment-57700 Luis From sturlamolden at yahoo.no Sun Jul 4 16:20:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 13:20:24 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On 2 Jul, 21:07, John Nagle wrote: > http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ He is right on. The only thing Python 3k will do for me, is break all my code and be incompatible with all extension modules I need. "What's the point?" indeed. From nagle at animats.com Sun Jul 4 16:58:17 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 13:58:17 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <4c30f5e9$0$1586$742ec2ed@news.sonic.net> On 7/4/2010 12:51 PM, Luis M. Gonz?lez wrote: >> Looking at median runtimes, here is what I got: >> >> gcc 1.10 >> >> LuaJIT 1.96 >> >> Java 6 -server 2.13 >> Intel Fortran 2.18 >> OCaml 3.41 >> SBCL 3.66 >> >> JavaScript V8 7.57 >> >> PyPy 31.5 >> CPython 64.6 >> Perl 67.2 >> Ruby 1.9 71.1 >> >> The only comfort for CPython is that Ruby and Perl did even worse. It's embarrassing that Javascript is now 9x faster than Python. Javascript has almost all the dynamic problems that make CPython slow, but they've been overcome in the Javascript JIT compiler. Here's how the Javascript V8 system does it: http://code.google.com/apis/v8/design.html They get rid of unnecessary dictionary lookups for attributes by automatically creating "hidden classes" which, in Python terms, use "slots". If an attribute is added to an object, another hidden class is created with that attribute. Each such class is hard-compiled to machine code while the program is running. So attribute access never requires a dictionary lookup. Adding a new, not-previously-used attribute is a relatively expensive operation, but with most programs, after a while all the new attributes have been added and the program settles down to efficient operation. That's in Google's Chrome browser right now. The Unladen Swallow people should in theory be able to reach that level of performance. (Both groups are employed at Google. So their effectiveness will be compared.) John Nagle From toby at rcsreg.com Sun Jul 4 17:05:56 2010 From: toby at rcsreg.com (Tobiah) Date: Sun, 04 Jul 2010 21:05:56 GMT Subject: Getting the name of the file that imported current module Message-ID: foo.py: import bar bar.show_importer() output: 'foo' or 'foo.py' or 'path/to/foo' etc. Possible? Thanks, Tobiah From me+list/python at ixokai.io Sun Jul 4 17:09:52 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 04 Jul 2010 14:09:52 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: <4C30F8A0.7070109@ixokai.io> On 7/4/10 9:21 AM, sturlamolden wrote: > On 4 Jul, 14:29, David Cournapeau wrote: > >> Actually, I think the main reason why Lua is much faster than other >> dynamic languages is its size. The language is small. You don't list, >> dict, tuples, etc... > > They have managed to combine list and dict into one type (table) that > does the job of both. You say "managed" as if it were some technical accomplishment, or that the result is able to actually do the job of both: neither of these assertions are true. Have you actually *used* Lua? I quite like the language in certain contexts where its appropriate, but if you've actually used it in real code and found tables to be at all a substitute for *either* dictionaries *or* lists, then I think somehow you've managed to actually miss using either data structure in Python to any real extent, somehow. Lua's tables are at very weak "dictionary-like" and "list-like" objects, which indeed have been folded into one. To the detriment of both, at least as far as they are an actual useful data structure. You can't even get the equivalent of len(dict) in it: you have to actually brute-force iterate the table and count manually. Even for a purely array-like table with onlyn umbered indexes, #table can be unreliable: its quite possible through normal list-like operations that you perform on it, it can end up with holes where #table will fail. Since it is *not* an list internally at *all*, but simply an associative array with numbered indexes. I could go on, and on, and on: but the fundamental *weakness* of Lua' data types as data-structures is irrefutable, from its tables to strings to numbers: they are incredibly weak on capabilities. You end up writing all kinds of "library" functions to just do the normal things that should be really easy to do. Now, of course, there's really good reason why Lua is so simple in these ways. Its entirely suitable for Lua as an embedded scripting language to keep things very light, so it can be simple and fast. Good for Lua to fill this niche superbly. But you can't start saying its simple alternatives are at all comparable to Python's extremely rich and capable data types. > And yes there are tuples. No, there isn't. There's ways to create a tuple-like-thing which kind of behaves like a braindead tuple, and functions have a positively bizarre capability of returning more then one value (and accepting variable values), so there's these points in the language where you have this sort of Immutable Sequence, but its opaque until you unwrap it -- and then it ceases to be. That's not the same thing as having an immutable sequence that you can store data in at your discretion, with a rich series of capabilities that you can leverage. > There are no classes, but there are closures and other building blocks > that can be used to create any object-oriented type system Not really. Above, I spoke of tables as data structures, things just storing data. But you're right, they are capable of more then that-- but you're over-selling just how far that capability goes, by a long shot (and underselling just how much work it takes to get it there). Yes, tables have a limited series of 'hooks' that you can tie into to alter their behavior, and through this you can simulate certain higher order type systems as defined in other languages. In fact, lots of people have done this: there's multiple "classy" libraries out there to bring some kind of Class-or-Object-Oriented-Programming to Lua. They work to varying degrees: but the hooks that Lua provides to tables is still significantly lacking to really replace Python's comprehensively dynamic object model, without a LOT of wasted cycles. For example, while you can use __newindex to 'catch' someone setting a new 'key' on a table, and and __index to replace or forward the actual lookup, you can't actually capture someone trying to set a value to a key which already exists. So, you end up having to do a full proxy approach, where your table never actually stores anything directly (except a reference to another hidden table), and so when someone goes to set something you have to set it on the proxied object instead. Because you can't let there ever be any real keys on the proxying / external table. So you're able to work around its lack a bit, to simulate something /like/ what it means to have __setattr__. But then you run into problems. There's no way now to iterate over the table now, because pairs() will only return your internal hidden keys that you're using to point to the proxied table (Although you can get around this with some more complexity by hiding said key into a closure-- but even then, you still can't iterate over the proxied table's keys instead). So what do you do? Well you go replace the global "pairs" function, that's what you do! So it learns your particular style of Classness, and interacts well. Hope you never use any third-party code which has even a vaguely different kind of Classness. Alternately, you can just decide to never use the standard idiom of iteration for your classes, and instead one must always "for x in my_table:iter()" -- so now you have one kind of code operating on 'real' tables, and a totally different kind operating on your 'classy tables'. And on and on. The point is, sure. Lua can sort of simulate different OOP approaches, and Lua-folk are very adept at tweaking, twisting, turning and ripping tables into all kinds of pseudo-data types that match other paradigms, but its all hacks on top of hacks on top of hacks. You end up with some *really* weird and/or messy code if you try. Better to do Lua in Lua, instead of Python in Lua, or Java in Lua. (just like > CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I > imagine it would be possible to define an equivalent to the Python > type system in Lua, and compile Python to Lua. Lua can be compiled to > Lua byte code. Factoring Lua, out that means we should be able to > compile Python to Lua byte code. > > > > -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sun Jul 4 17:17:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 04 Jul 2010 22:17:52 +0100 Subject: Getting the name of the file that imported current module In-Reply-To: References: Message-ID: On 04/07/2010 22:05, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah >>> import re >>> re.__file__ 'C:\\Python26\\lib\\re.pyc' HTH. Mark Lawrence. From sjmachin at lexicon.net Sun Jul 4 18:02:53 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 4 Jul 2010 15:02:53 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: On Jul 5, 1:08?am, Thomas Jollans wrote: > On 07/04/2010 03:49 PM, jmfauth wrote: > > ? File "", line 1 > > ? ? print9.0 > > ? ? ? ? ? ?^ > > SyntaxError: invalid syntax > > somewhat strange, yes. There are two tokens, "print9" (a name) and ".0" (a float constant) -- looks like SyntaxError to me. From tjreedy at udel.edu Sun Jul 4 19:14:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 04 Jul 2010 19:14:52 -0400 Subject: Python 3 put-downs: What's the point? Message-ID: From torriem at gmail.com Sun Jul 4 19:25:58 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 04 Jul 2010 17:25:58 -0600 Subject: Getting the name of the file that imported current module In-Reply-To: References: Message-ID: <4C311886.9050508@gmail.com> On 07/04/2010 03:17 PM, Mark Lawrence wrote: > On 04/07/2010 22:05, Tobiah wrote: >> foo.py: >> >> import bar >> bar.show_importer() >> >> output: >> >> 'foo' or 'foo.py' or 'path/to/foo' etc. >> >> Possible? >> >> Thanks, >> >> Tobiah > > >>> import re > >>> re.__file__ > 'C:\\Python26\\lib\\re.pyc' I think this is exactly opposite of what he was asking for. Given than any number of modules can import other modules but each module really only exists once in the Python object space (normally) would mean that what the OP is asking for isn't possible. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 19:29:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jul 2010 23:29:05 GMT Subject: Getting the name of the file that imported current module References: Message-ID: <4c311941$0$28647$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? I don't think so. Your question isn't even well-defined. Given three modules: # a.py import b import d # b.py import d # c.py import a import d import b print d.show_importer() and you run c.py, what do you expect d.show_importer() to return? And what about "from d import show_importer" -- does that count as "importing d"? Why do you think that a module needs to know what other modules imported it? I can't imagine why this would be necessary, what are you intending to do with it? -- Steven From tim at johnsons-web.com Sun Jul 4 19:46:50 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 04 Jul 2010 18:46:50 -0500 Subject: Shared object access problems Message-ID: Using python 2.6.4 on slackware 13.1 I have MySQLdb 'by hand', that is: by 1)downloading MySQL-python-1.2.3c1.tar.gz 2)unzipping tarfile 3)running python setup.py build 4)running python setup.py install The build and install seemed to proceded without error, but upon invoking the interpreter and running >>> import MySQLdb I get the following ImportError: ############################################################## Traceback (most recent call last): File "", line 1, in File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 19, in File "build/bdist.linux-i686/egg/_mysql.py", line 7, in File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__ ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory ############################################################## There was no libmysqlclient_r.so.15 on my machine, so I made symlinks at both /usr/lib/mysql/ and /usr/lib which are libmysqlclient_r.so.15 pointing to /usr/lib/mysql/libmysqlclient_r.so.16.0.0 Now when I run import MySQLdb, I get the following error: ############################################################## Traceback (most recent call last): File "", line 1, in File "MySQLdb/__init__.py", line 19, in import _mysql File "build/bdist.linux-i686/egg/_mysql.py", line 7, in File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__ ImportError: /usr/lib/libmysqlclient_r.so.15: version `libmysqlclient_15' not found (required by /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg-tmp /_mysql.so) ############################################################## # Note that the parenthesized expression beginning with "(required" # has been broken to accomodate the newsgroup - was one line [sigh!] I've been using python and mysql on linux for 10 years and have done many 'hand installs' and boy has it gotten complicated. Any ideas? thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From python.list at tim.thechases.com Sun Jul 4 19:51:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 04 Jul 2010 18:51:54 -0500 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: <4C311E9A.4090308@tim.thechases.com> I think it's the same venting of frustration that caused veteran VB6 developers to start calling VB.Net "Visual Fred" -- the language was too different and too non-backwards-compatible. The 2to3 tools are better (partly due to the less drastic language changes compared to the Fred'ification of VB) than the VB6->Fred conversion tools. I'd also agree that Py3 comes closer to the language ideals that Py2.x aspired to be, but Py2.x was held back by the fairly strict moratorium on the introduction of backwards incompatible changes. The language changes also introduce frustrations when searching for example code: what was "Python" code examples now may or may not now work in Py3 or Py2 (and more importantly, may not have a caveat regarding which interpreter to use). Finally, the slow transformation of the vast volume of existing Python libraries adds a bit of irritant to the masses. There was some dialog on the Django mailing list a while back about Py3 transitions, but it's still pretty distant on the roadmap. I've often wondered if changing the name of the language (such as "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in the crowd) would have mitigated some of the more vituperative slurs on what became Py3, designating a shared legacy without the expectation of 100% backwards-compatibility. -tkc From nagle at animats.com Sun Jul 4 19:58:04 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 16:58:04 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4c31200c$0$1600$742ec2ed@news.sonic.net> On 7/4/2010 1:20 PM, sturlamolden wrote: > On 2 Jul, 21:07, John Nagle wrote: > >> http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ > > He is right on. The only thing Python 3k will do for me, is break all > my code and be incompatible with all extension modules I need. "What's > the point?" indeed. Exactly. The "incompatible with all extension modules I need" part is the problem right now. A good first step would be to identify the top 5 or 10 modules that are blocking a move to Python 3 by major projects with many users. John Nagle From roy at panix.com Sun Jul 4 20:05:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jul 2010 20:05:03 -0400 Subject: Python 3 put-downs: What's the point? References: Message-ID: In article , Tim Chase wrote: > I've often wondered if changing the name of the language (such as > "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in > the crowd) would have mitigated some of the more vituperative > slurs on what became Py3, designating a shared legacy without the > expectation of 100% backwards-compatibility. Maybe it should have been "Python five, no, THREE!" From clp2 at rebertia.com Sun Jul 4 20:21:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Jul 2010 17:21:37 -0700 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: On Sun, Jul 4, 2010 at 5:05 PM, Roy Smith wrote: > In article , > ?Tim Chase wrote: >> I've often wondered if changing the name of the language (such as >> "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in >> the crowd) would have mitigated some of the more vituperative >> slurs on what became Py3, designating a shared legacy without the >> expectation of 100% backwards-compatibility. > > Maybe it should have been "Python five, no, THREE!" +1 QOTW Cheers, Chris From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 20:29:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 00:29:32 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c31276b$0$28647$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 16:58:04 -0700, John Nagle wrote: > The "incompatible with all extension modules I need" part > is the problem right now. A good first step would be to identify the > top 5 or 10 modules that are blocking a move to Python 3 by major > projects with many users. Are you volunteering to assist, or just belly-aching? Migration to Python 3 is occurring at about the speed that should be expected, modulo the setback that was the seriously flawed 3.0 release. 3.1 should be treated as the "early adopter" version. I would expect 3.3 will probably be the first "mainstream" version, where v3 users start to outnumber v2 users. If people have concrete, *specific* issues that are holding them back from serious plans to migrate to Python 3 then reporting them is a good first step: e.g. telling the author of extension module Foo that you need Python 3 compatibility. Complaining that "extension modules aren't compatible" is just bitching for the sake of bitching and isn't helpful. Please take it elsewhere. Start a blog "why I hate Python 3" or something. Or just stick with Python 2.x forever, without the negativity. There's no law that says you have to upgrade. There are people still using 1.5, and more power to them. -- Steven From sturlamolden at yahoo.no Sun Jul 4 20:34:04 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 17:34:04 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 5 Jul, 01:58, John Nagle wrote: > ? ? ?Exactly. > > ? ? ?The "incompatible with all extension modules I need" part > is the problem right now. ?A good first step would be to > identify the top 5 or 10 modules that are blocking a move to > Python 3 by major projects with many users. The big danger is Python 2.x becoming abandonware (2.7 being the final release) before major projects are ported. Using Python 2.x for new projects is not advisable (at least many will think so), and using 3.x is not possible. What to do? It's not a helpful situation for Python. From ben+python at benfinney.id.au Sun Jul 4 20:38:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 05 Jul 2010 10:38:56 +1000 Subject: Python 3 put-downs: What's the point? References: Message-ID: <87lj9qg3tr.fsf@benfinney.id.au> Roy Smith writes: > Maybe it should have been "Python five, no, THREE!" +1 QOTW -- \ ?Our products just aren't engineered for security.? ?Brian | `\ Valentine, senior vice-president of Microsoft Windows | _o__) development, 2002 | Ben Finney From greg.ewing at canterbury.ac.nz Sun Jul 4 20:49:17 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 05 Jul 2010 12:49:17 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: <89cnv0FjnuU1@mid.individual.net> kedra marbun wrote: > now, i'm asking another favor, what about the 2nd point in my 1st post? Your original post has dropped off my newsscope, so you'll have to remind me what the 2nd point was. -- Greg From smallpox911 at gmail.com Sun Jul 4 20:52:21 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 4 Jul 2010 17:52:21 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies mislead the public on the facts References: <16ef11cf-7b5a-470a-bea2-52e298ec2aaf@s9g2000yqd.googlegroups.com> Message-ID: <7a3b2761-905b-41d0-b506-9ed1c7d5f1b0@t10g2000yqg.googlegroups.com> VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies mislead the public on the facts http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html http://www.gtr5.com/ From smallpox911 at gmail.com Sun Jul 4 20:56:54 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 4 Jul 2010 17:56:54 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts Message-ID: <71420572-82ad-4945-931a-3452eeebcb1d@5g2000yqz.googlegroups.com> VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html http://www.gtr5.com/ From cmpython at gmail.com Sun Jul 4 21:20:38 2010 From: cmpython at gmail.com (CM) Date: Sun, 4 Jul 2010 18:20:38 -0700 (PDT) Subject: Python 3 put-downs: What's the point? References: Message-ID: On Jul 4, 7:14?pm, Terry Reedy wrote: > I think there's a good point to Python 3 put-downs (if I take put-down to mean generally reasonable criticism, which is what I've read here recently, and not trolling). And that is simply to register dissent. Any online group is an opportunity to register dissent in a way that is public, open, immediate, interactive, and will (probably) be preserved for historians to check. The fact is, some people have gripes with Python 3; they are letting it be known. If no one did, there could be no later time at which people could look back and know what the reaction was to its introduction--it would just be a blank. Aren't opinions that dissent from the prevailing ones important to register, whether one thinks they are right or wrong? Che From philip at semanchuk.com Sun Jul 4 21:36:06 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 4 Jul 2010 21:36:06 -0400 Subject: Shared object access problems In-Reply-To: References: Message-ID: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> hi Tim, This seems more likely to be a MySQLdb problem than a Python one. Have you considered asking in the MySQLdb forums? On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > Using python 2.6.4 on slackware 13.1 > I have MySQLdb 'by hand', that is: by > 1)downloading MySQL-python-1.2.3c1.tar.gz > 2)unzipping tarfile > 3)running python setup.py build > 4)running python setup.py install > > The build and install seemed to proceded without error, > but upon invoking the interpreter and running >>>> import MySQLdb > I get the following ImportError: > ############################################################## > Traceback (most recent call last): > File "", line 1, in > File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", > line 19, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 7, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 6, in __bootstrap__ > ImportError: libmysqlclient_r.so.15: > cannot open shared object file: No such file or directory > ############################################################## > There was no libmysqlclient_r.so.15 on my machine, so I made > symlinks at both /usr/lib/mysql/ and /usr/lib which > are libmysqlclient_r.so.15 pointing to > /usr/lib/mysql/libmysqlclient_r.so.16.0.0 > > Now when I run import MySQLdb, I get the following error: > ############################################################## > Traceback (most recent call last): > File "", line 1, in > File "MySQLdb/__init__.py", line 19, in > import _mysql > File "build/bdist.linux-i686/egg/_mysql.py", > line 7, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 6, in __bootstrap__ > ImportError: /usr/lib/libmysqlclient_r.so.15: > version `libmysqlclient_15' not found > (required by > /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg- > tmp > /_mysql.so) > ############################################################## > # Note that the parenthesized expression beginning with "(required" > # has been broken to accomodate the newsgroup - was one line > [sigh!] I've been using python and mysql on linux for 10 years and > have done many 'hand installs' and boy has it gotten complicated. > Any ideas? > thanks > > -- > Tim > tim at johnsons-web.com or akwebsoft.com > http://www.akwebsoft.com > -- > http://mail.python.org/mailman/listinfo/python-list From nagle at animats.com Sun Jul 4 21:59:03 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 18:59:03 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c313c67$0$1646$742ec2ed@news.sonic.net> On 7/4/2010 5:34 PM, sturlamolden wrote: > On 5 Jul, 01:58, John Nagle wrote: > >> Exactly. >> >> The "incompatible with all extension modules I need" part is the >> problem right now. A good first step would be to identify the top >> 5 or 10 modules that are blocking a move to Python 3 by major >> projects with many users. > > The big danger is Python 2.x becoming abandonware (2.7 being the > final release) before major projects are ported. Using Python 2.x > for new projects is not advisable (at least many will think so), and > using 3.x is not possible. What to do? It's not a helpful situation > for Python. Projects have been known to get into a state where version N-1 is abandonware, and version N isn't usable yet. Then they die off. The VRML-Web3D transition is an example. VRML 97 was ahead of its time because few people had enough graphics power in 1997 to run it. During the dot-com boom, the "Web 3D Consortium" (http://www.web3d.org) was formed to put 3D on the web. The approach chosen was to recast VRML in XML notation. Users were starting to get 3D boards in quantity, and VRML was starting to really work. But the forced transition killed work on VRML, while there wasn't enough momentum to get people to use the XML version. The Web3D consortium is still around. They have conferences. They have something of a niche market in DoD training sims. But they're running on empty. Nobody is paying attention. There's no mainstream interest in either VRML or Web3D. It works fine; there are X3D players, and they work great on modern graphics processors. But nobody cares. That's what happens when you mismanage an incompatible transition. That could happen to Python. Python has strong competition. In the last two years, Javascript has become much faster, PHP is getting a JIT compiler, Lua, as recently mentioned, is getting up there with C in speed, and Google is promoting Go. The other scripting languages are becoming rocket-powered. Meanwhile, Python is in year 2 of a 5-year plan to transition to something that goes no faster (and maybe slower) than the previous version. (Yes, there's Unladen Swallow and PyPy, but neither of those projects seems to be anywhere near deployment, and even if they succeed, their claimed speed goals are well below where the competition is now.) That's just not good enough any more. Denying that there's a problem does not help. John Nagle From nagle at animats.com Sun Jul 4 22:24:12 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 19:24:12 -0700 Subject: Shared object access problems In-Reply-To: References: Message-ID: <4c31424c$0$1613$742ec2ed@news.sonic.net> On 7/4/2010 6:36 PM, Philip Semanchuk wrote: > hi Tim, > This seems more likely to be a MySQLdb problem than a Python one. Have > you considered asking in the MySQLdb forums? > > On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > >> Using python 2.6.4 on slackware 13.1 >> I have MySQLdb 'by hand', that is: by >> 1)downloading MySQL-python-1.2.3c1.tar.gz >> 2)unzipping tarfile >> 3)running python setup.py build >> 4)running python setup.py install >> >> The build and install seemed to proceded without error, >> but upon invoking the interpreter and running >>>>> import MySQLdb >> I get the following ImportError: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >> line 19, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: libmysqlclient_r.so.15: >> cannot open shared object file: No such file or directory Did you install the development libraries for MySQL first? Those are needed to build MySQLdb yourself. John Nagle From ggrp2.20.martineau at dfgh.net Sun Jul 4 22:27:14 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Sun, 4 Jul 2010 19:27:14 -0700 (PDT) Subject: Python 2.7 released References: Message-ID: On Jul 4, 8:34?am, Benjamin Peterson wrote: > On behalf of the Python development team, I'm jocund to announce the second > release candidate of Python 2.7. > > Python 2.7 will be the last major version in the 2.x series. However, it will > also have an extended period of bugfix maintenance. > > 2.7 includes many features that were first released in Python 3.1. The faster io > module, the new nested with statement syntax, improved float repr, set literals, > dictionary views, and the memoryview object have been backported from 3.1. Other > features include an ordered dictionary implementation, unittests improvements, a > new sysconfig module, auto-numbering of fields in the str/unicode format method, > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlor Misc/NEWS in the Python > distribution. > > To download Python 2.7 visit: > > ? ? ?http://www.python.org/download/releases/2.7/ > > 2.7 documentation can be found at: > > ? ? ?http://docs.python.org/2.7/ > > This is a production release and should be suitable for all libraries and > applications. ?Please report any bugs you find, so they can be fixed in the next > maintenance releases. ?The bug tracker is at: > > ? ? ?http://bugs.python.org/ > > Enjoy! > > -- > Benjamin Peterson > Release Manager > benjamin at python.org > (on behalf of the entire python-dev team and 2.7's contributors) Benjamin (or anyone else), do you know where I can get the Compiled Windows Help file -- python27.chm -- for this release? In the past I've been able to download it from the Python web site, but have been unable to locate it anywhere for this new release. I can't build it myself because I don't have the Microsoft HTML help file compiler. Thanks in advance. From sjmachin at lexicon.net Sun Jul 4 22:58:18 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 4 Jul 2010 19:58:18 -0700 (PDT) Subject: Python 2.7 released References: Message-ID: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> On Jul 5, 12:27?pm, Martineau wrote: > On Jul 4, 8:34?am, Benjamin Peterson wrote: > > > > > On behalf of the Python development team, I'm jocund to announce the second > > release candidate of Python 2.7. > > > Python 2.7 will be the last major version in the 2.x series. However, it will > > also have an extended period of bugfix maintenance. > > > 2.7 includes many features that were first released in Python 3.1. The faster io > > module, the new nested with statement syntax, improved float repr, set literals, > > dictionary views, and the memoryview object have been backported from 3.1. Other > > features include an ordered dictionary implementation, unittests improvements, a > > new sysconfig module, auto-numbering of fields in the str/unicode format method, > > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWS in the Python > > distribution. > > > To download Python 2.7 visit: > > > ? ? ?http://www.python.org/download/releases/2.7/ > > > 2.7 documentation can be found at: > > > ? ? ?http://docs.python.org/2.7/ > > > This is a production release and should be suitable for all libraries and > > applications. ?Please report any bugs you find, so they can be fixed in the next > > maintenance releases. ?The bug tracker is at: > > > ? ? ?http://bugs.python.org/ > > > Enjoy! > > > -- > > Benjamin Peterson > > Release Manager > > benjamin at python.org > > (on behalf of the entire python-dev team and 2.7's contributors) > > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? In the past > I've been able to download it from the Python web site, but have been > unable to locate it anywhere for this new release. I can't build it > myself because I don't have the Microsoft HTML help file compiler. > > Thanks in advance. If you have a Windows box, download the .msi installer for Python 2.7 and install it. The chm file will be in C:\Python27\Doc (if you choose the default installation directory). Otherwise ask a friendly local Windows user for a copy. From tim at johnsons-web.com Sun Jul 4 23:00:01 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 4 Jul 2010 19:00:01 -0800 Subject: Shared object access problems In-Reply-To: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> References: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> Message-ID: <20100705030001.GA1875@johnsons-web.com> * Philip Semanchuk [100704 18:13]: > hi Tim, > This seems more likely to be a MySQLdb problem than a Python one. You are correct > Have you considered asking in the MySQLdb forums? Didn't know there was one! where is it? I will join thanks tim > On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > >> Using python 2.6.4 on slackware 13.1 >> I have MySQLdb 'by hand', that is: by >> 1)downloading MySQL-python-1.2.3c1.tar.gz >> 2)unzipping tarfile >> 3)running python setup.py build >> 4)running python setup.py install >> >> The build and install seemed to proceded without error, >> but upon invoking the interpreter and running >>>>> import MySQLdb >> I get the following ImportError: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >> line 19, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: libmysqlclient_r.so.15: >> cannot open shared object file: No such file or directory >> ############################################################## >> There was no libmysqlclient_r.so.15 on my machine, so I made >> symlinks at both /usr/lib/mysql/ and /usr/lib which >> are libmysqlclient_r.so.15 pointing to >> /usr/lib/mysql/libmysqlclient_r.so.16.0.0 >> >> Now when I run import MySQLdb, I get the following error: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "MySQLdb/__init__.py", line 19, in >> import _mysql >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: /usr/lib/libmysqlclient_r.so.15: >> version `libmysqlclient_15' not found >> (required by >> /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg- >> tmp >> /_mysql.so) >> ############################################################## >> # Note that the parenthesized expression beginning with "(required" >> # has been broken to accomodate the newsgroup - was one line >> [sigh!] I've been using python and mysql on linux for 10 years and >> have done many 'hand installs' and boy has it gotten complicated. >> Any ideas? >> thanks >> >> -- >> Tim >> tim at johnsons-web.com or akwebsoft.com >> http://www.akwebsoft.com >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From rantingrick at gmail.com Sun Jul 4 23:40:47 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 4 Jul 2010 20:40:47 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c313c67$0$1646$742ec2ed@news.sonic.net> Message-ID: On Jul 4, 8:59?pm, John Nagle wrote: > That's what happens when you > mismanage an incompatible transition. +1 > ? ? Python has strong competition. ?In the last two years, > Javascript has become much faster, PHP is getting a JIT compiler, > Lua, as recently mentioned, is getting up there with C in speed, and > Google is promoting Go. ?The other scripting languages are becoming > rocket-powered. ? Meanwhile, Python is in year 2 of a 5-year plan to > transition to something that goes no faster (and maybe slower) than > the previous version. ?(Yes, there's Unladen Swallow and PyPy, but > neither of those projects seems to be anywhere near deployment, > and even if they succeed, their claimed speed goals are well below where > the competition is now.) ?That's just not good enough any more. > > ? ? Denying that there's a problem does not help. +1 Hmm, i myself railed against the changes in Python3.x about 1 year ago. Then, as i pondered the reasons behind such changes i began to believe that the BDFL is wiser than us all! However, i must agree that many of the points you bring up here are real. People ARE stuck in limbo right now and there is no good direction to go... Stick with 2.x and have all the 3rd party support but soon enough you will need to do a major bug fixing, or move to 3.x -- oh wait i can't move to 3.x because module xxyy is not 3.x compatible! What we have here gentlemen is a situation, a terrible situation made worse by our lack to understand it. From breamoreboy at yahoo.co.uk Mon Jul 5 00:42:35 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 05 Jul 2010 05:42:35 +0100 Subject: Getting the name of the file that imported current module In-Reply-To: <4C311886.9050508@gmail.com> References: <4C311886.9050508@gmail.com> Message-ID: On 05/07/2010 00:25, Michael Torrie wrote: > On 07/04/2010 03:17 PM, Mark Lawrence wrote: >> On 04/07/2010 22:05, Tobiah wrote: >>> foo.py: >>> >>> import bar >>> bar.show_importer() >>> >>> output: >>> >>> 'foo' or 'foo.py' or 'path/to/foo' etc. >>> >>> Possible? >>> >>> Thanks, >>> >>> Tobiah >> >> >>> import re >> >>> re.__file__ >> 'C:\\Python26\\lib\\re.pyc' > > I think this is exactly opposite of what he was asking for. > > Given than any number of modules can import other modules but each > module really only exists once in the Python object space (normally) > would mean that what the OP is asking for isn't possible. You're absolutely correct, thou shalt not post late at night when very tired. :) Cheers. Mark Lawrence From dr.cg at 126.com Mon Jul 5 00:56:25 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 5 Jul 2010 12:56:25 +0800 (CST) Subject: Why Python forbids multiple instances of one module? Message-ID: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Why Python forbids multiple instances of one module? If only Python allows multiple instances of one module, module will be enough to replace class in most cases. After all, it is much easier to write a module than a class, at least we do not have to write self everywhere. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 5 01:42:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 Jul 2010 23:42:02 -0600 Subject: Why Python forbids multiple instances of one module? In-Reply-To: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: 2010/7/4 CHEN Guang : > Why Python forbids multiple instances of one module? > If only Python allows multiple instances of one module, module will > be?enough to replace class in most cases. > After all, it is much easier to?write?a module than a class, at least we do > not have to write self everywhere. If you really want to do that, it should be possible by deleting the entry from sys.modules and re-importing it. You save yourself having to explicitly write self everywhere, but instead you have to declare all your "instance" variables as globals in each "method" that uses them, which isn't much less of a chore. You also lose inheritance, properties (and descriptors in general), magic method support, metaclasses, and pretty much all the other nice features that new-style classes have to offer. From tjreedy at udel.edu Mon Jul 5 01:44:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 01:44:46 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c31200c$0$1600$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 7/4/2010 7:58 PM, John Nagle wrote: > The "incompatible with all extension modules I need" part > is the problem right now. A good first step would be to > identify the top 5 or 10 modules that are blocking a move to > Python 3 by major projects with many users. Let me repeat. Last September, if not before, Guido identified numpy as a top package blocking moves by other packages and projects. I am not sure what he thought, but I consider it number 1. He encouraged the numpy people to produce a 3.x version even though some did not see any personal benefit. We supposedly will see numpy for 3.2. If we actually do, other dominoes will fall into place. I you have any other ideas about other top blockers, please share them. -- Terry Jan Reedy From clp2 at rebertia.com Mon Jul 5 01:49:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Jul 2010 22:49:54 -0700 Subject: Why Python forbids multiple instances of one module? In-Reply-To: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: 2010/7/4 CHEN Guang : > Why Python forbids multiple instances of one module? That's just how its import mechanism works. It allows for modules that need canonical program-wide state to rely on being singleton, and it's also an optimization. You can trick the import machinery and get around the restriction though. > If only Python allows multiple instances of one module, module will > be?enough to replace class in most cases. Why do classes need replacement in the first place? Modules and classes serve distinct purposes. Also: How would you specify a class-module's superclasses? And what if a class depends on other modules/classes/packages? Then the class-module's namespace would be polluted with all the stuff it imported; ick. > After all, it is much easier to?write?a module than a class, at least we do > not have to write self everywhere. That seems a relatively petty reason; see also Ian's excellent point about `global`. Cheers, Chris -- Yay, Fireworks! http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Mon Jul 5 02:31:46 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 06:31:46 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c317c52$0$28665$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 17:34:04 -0700, sturlamolden wrote: > Using Python 2.x for new > projects is not advisable (at least many will think so), and using 3.x > is not possible. What to do? It's not a helpful situation for Python. That's pure FUD. Python 2.7 will be supported longer than the normal support period for versions 2.6, 2.5, 2.4, ... so if you have a new project that requires libraries that aren't available for 3.1, then go right ahead and use 2.7. By the time 2.7 is no longer supported (probably around the time 3.4 comes out?), the library situation will be fixed. Those 3.1 features that can be backported to 2.x have been, specifically to reduce the pain in porting 2.7-based applications to 3.x. Feature- wise, 2.7 is designed to ease the transition from the 2.x series to the 3.x series. Claiming that it's not advisable to use 2.7 is simply nonsense. -- Steven From ldo at geek-central.gen.new_zealand Mon Jul 5 02:50:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:50:10 +1200 Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> <7xpqzbj8st.fsf@ruckus.brouhaha.com> Message-ID: In message <7xpqzbj8st.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > ... and argc/argv were passed to the child process on its stack. I?ve always felt that to be a misfeature. It means you can?t implement a self-contained argument-parsing library, it still needs the mainline to explicitly pass/put its arguments somewhere. From ldo at geek-central.gen.new_zealand Mon Jul 5 02:52:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:52:39 +1200 Subject: Python as a scripting language. Alternative to bash script? References: Message-ID: In message , Mithrandir wrote: > I think that Python "could" be a alternative to bash and have some > advantages, but it's a long way off from being fully implemented. Would you prefer to do the following sort of thing in Python or Bash? AudioParms = "-f s16le -ar 48000 -ac 2" # because I can't seem to pipe compressed audio ImportCmd = \ ( "ffmpeg -v 0 -i <(%(src_video)s)" " %(audio_parms)s -i <(%(src_audio)s)" " -vcodec copy -acodec %(audio_codec)s -y %(dstfile)s" % { "src_video" : "; ".join ( [ "ffmpeg -v 0 -i %(srcfile)s -f image2pipe -vcodec copy" " -y /dev/stdout" % {"srcfile" : ShellEscape(SrcFile)} for SrcFile in SrcFiles ] ), # pipe through compressed video without recompression "src_audio" : "; ".join ( [ "ffmpeg -v 0 -i %(srcfile)s %(audio_parms)s -y /dev/stdout" % { "srcfile" : ShellEscape(SrcFile), "audio_parms" : AudioParms, } for SrcFile in SrcFiles ] ), "dstfile" : ShellEscape(DstFile), "audio_parms" : AudioParms, "audio_codec" : "mp2", # assumption! } ) From ldo at geek-central.gen.new_zealand Mon Jul 5 02:56:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:56:02 +1200 Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: In message , Rhodri James wrote: > Classic Unix programming is a matter of stringing a bunch of tools > together with pipes to get the output you want. This isn't a great > paradigm for GUIs (not without tweaking that hasn't really been done), but > then again it was never meant to be. I?ve never come across any system where you could string together multiple GUI apps, or even multiple GUI operations in the same app, in any sensible or effective way at all. GUIs just aren?t designed to work that way. The command line (or scripting, the difference isn?t that important) remains the only workable way to string together complex combinations of simpler operations. From nagle at animats.com Mon Jul 5 02:56:53 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 23:56:53 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c318235$0$1663$742ec2ed@news.sonic.net> On 7/4/2010 10:44 PM, Terry Reedy wrote: > On 7/4/2010 7:58 PM, John Nagle wrote: > >> The "incompatible with all extension modules I need" part >> is the problem right now. A good first step would be to >> identify the top 5 or 10 modules that are blocking a move to >> Python 3 by major projects with many users. > > Let me repeat. Last September, if not before, Guido identified numpy as > a top package blocking moves by other packages and projects. I am not > sure what he thought, but I consider it number 1. He encouraged the > numpy people to produce a 3.x version even though some did not see any > personal benefit. We supposedly will see numpy for 3.2. If we actually > do, other dominoes will fall into place. > > I you have any other ideas about other top blockers, please share them. The Twisted team has a list of what they need: "http://stackoverflow.com/questions/172306/how-are-you-planning-on-handling-the-migration-to-python-3" * Zope Interface * PyCrypto * PyOpenSSL * PyGTK John Nagle From steve-REMOVE-THIS at cybersource.com.au Mon Jul 5 03:07:22 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 07:07:22 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c313c67$0$1646$742ec2ed@news.sonic.net> Message-ID: <4c3184a9$0$28665$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 18:59:03 -0700, John Nagle wrote: > Denying that there's a problem does not help. Nobody is denying that there is a problem, but there are plenty of people denying that there are any solutions. The folks doing development of CPython are genuinely interested in constructive criticism. Go spend some time on the python-dev mailing list to see that they're serious about resolving problems. But harping on and on with the same old negatives and same old FUD ("Python is too slow, nothing works with Python 3, people will abandon Python, the transition is being mismanaged, blah blah blah blah") conspicuously lacking in *actual* details is not helping anyone. Let's hear specifics. What is your project, what is the project timeline, why did you want to use 3.1 (instead of, say, waiting for 3.2) and what *specific* problem stopped you? I'm not interested in hand-waving and vague generalities. I want to hear names and versions, not bitching. "We are planning on building an app to do Foo, and choose to target 2.6 instead of 3.1 because the 3rd party FooLib only supports 2.5 and 2.6..." "I wrote an app using 3.1, and ran into these really painful problems with this library..." That's the sort of thing that is helpful. By the same token, if you've successfully targeted 3.1, we'd love to hear your success stories too. -- Steven From solipsis at pitrou.net Mon Jul 5 03:28:45 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 5 Jul 2010 09:28:45 +0200 Subject: Python 3 put-downs: What's the point? References: Message-ID: <20100705092845.25702499@pitrou.net> On Sun, 4 Jul 2010 18:20:38 -0700 (PDT) CM wrote: > > Any online group is an opportunity to register dissent in a way that > is public, open, immediate, interactive, and will (probably) be > preserved for historians to check. The fact is, some people have > gripes with Python 3; they are letting it be known. If no one did, > there could be no later time at which people could look back and know > what the reaction was to its introduction--it would just be a blank. > Aren't opinions that dissent from the prevailing ones important to > register, whether one thinks they are right or wrong? Sure. As long as you don't record the same dissent from the same person ten times in a row. Then it becomes trolling. From dickinsm at gmail.com Mon Jul 5 03:44:52 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 5 Jul 2010 00:44:52 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> On Jul 4, 11:02?pm, John Machin wrote: > On Jul 5, 1:08?am, Thomas Jollans wrote: > > > On 07/04/2010 03:49 PM, jmfauth wrote: > > > ? File "", line 1 > > > ? ? print9.0 > > > ? ? ? ? ? ?^ > > > SyntaxError: invalid syntax > > > somewhat strange, yes. > > There are two tokens, "print9" (a name) and ".0" (a float constant) -- > looks like SyntaxError to me. Yep. Looks that way to me, too. Python 2.7.0+ (release27-maint:82569, Jul 5 2010, 08:35:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from cStringIO import StringIO >>> import tokenize, token >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): ... print token.tok_name[tok[0]], tok[1] ... NAME print9 NUMBER .0 ENDMARKER -- Mark From gh at gregor-horvath.com Mon Jul 5 03:50:32 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 5 Jul 2010 09:50:32 +0200 Subject: Python 3 put-downs: What's the point? References: Message-ID: <20100705095032.6f7749fe@brasov> Am Sun, 04 Jul 2010 18:51:54 -0500 schrieb Tim Chase : > I think it's the same venting of frustration that caused veteran > VB6 developers to start calling VB.Net "Visual Fred" -- the > language was too different and too non-backwards-compatible. > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. VB6 and VB.NET are totally different languages and technologies, with some similarity in syntax. This is not true for Python 2->3. This is an healthy organic language growth, not an abandon of a language. -- Greg From benjamin.kaplan at case.edu Mon Jul 5 04:12:34 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 5 Jul 2010 01:12:34 -0700 Subject: Python 2.7 released In-Reply-To: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: On Sun, Jul 4, 2010 at 7:58 PM, John Machin wrote: > On Jul 5, 12:27?pm, Martineau wrote: >> On Jul 4, 8:34?am, Benjamin Peterson wrote: >> >> >> >> > On behalf of the Python development team, I'm jocund to announce the second >> > release candidate of Python 2.7. >> >> > Python 2.7 will be the last major version in the 2.x series. However, it will >> > also have an extended period of bugfix maintenance. >> >> > 2.7 includes many features that were first released in Python 3.1. The faster io >> > module, the new nested with statement syntax, improved float repr, set literals, >> > dictionary views, and the memoryview object have been backported from 3.1. Other >> > features include an ordered dictionary implementation, unittests improvements, a >> > new sysconfig module, auto-numbering of fields in the str/unicode format method, >> > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in >> > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWS in the Python >> > distribution. >> >> > To download Python 2.7 visit: >> >> > ? ? ?http://www.python.org/download/releases/2.7/ >> >> > 2.7 documentation can be found at: >> >> > ? ? ?http://docs.python.org/2.7/ >> >> > This is a production release and should be suitable for all libraries and >> > applications. ?Please report any bugs you find, so they can be fixed in the next >> > maintenance releases. ?The bug tracker is at: >> >> > ? ? ?http://bugs.python.org/ >> >> > Enjoy! >> >> > -- >> > Benjamin Peterson >> > Release Manager >> > benjamin at python.org >> > (on behalf of the entire python-dev team and 2.7's contributors) >> >> Benjamin (or anyone else), do you know where I can get the Compiled >> Windows Help file -- python27.chm -- for this release? In the past >> I've been able to download it from the Python web site, but have been >> unable to locate it anywhere for this new release. I can't build it >> myself because I don't have the Microsoft HTML help file compiler. >> >> Thanks in advance. > > If you have a Windows box, download the .msi installer for Python 2.7 > and install it. The chm file will be in C:\Python27\Doc (if you choose > the default installation directory). Otherwise ask a friendly local > Windows user for a copy. > -- Or you can just use 7-zip or cabextract on the MSi. Saves you from having to uninstall it later, and it works on non-Windows machines. From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 5 04:42:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jul 2010 10:42:13 +0200 Subject: delegation pattern via descriptor In-Reply-To: <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: <4c319ae6$0$14953$426a74cc@news.free.fr> kedra marbun a ?crit : > i'm confused which part that doesn't make sense? > this is my 2nd attempt to py, the 1st was on april this year, it was > just a month, i'm afraid i haven't got the fundamentals right yet. so > i'm gonna lay out how i got to this conclusion, CMIIW > > **explanation of feeling (0) on my 1st post** > to me, descriptor is a particular kind of delegation, it takes the job > of coding the delegation by having a contract with programmers that > the tree meta operations (get, set, del) on attr are delegated to the > obj that is bound to the attr > are we agree that descriptor is a kind of delegation? > > the mechanism that makes descriptor works is in __getattribute__, > __setattr__, __delattr__ of 'object' & 'type' > > now, if i want a single descriptor obj to be delegated to multiple > tasks, i can't do it since __get__ doesn't get info that can be used > to determine which task to do > i must have diff descriptor obj for each task > > class Helper: > def __init__(self, name): > self.name = name > def __get__(self, ins, cls): > if self.name == 'task0': ... > elif self.name == 'task1': ... > else: ... Replacing such "big switch" code with polymorphic dispatch is one of the goals (and feature) of OO. This should be: class Task0(object): def __get__(self, obj, cls): # code here class Task1(object): def __get__(self, obj, cls): # code here class A(object): task0 = Task0() task1 = Task1() If you have common code to share between TaskO and Task1 then factor it out into a base class. > if __get__ receives the name, then i could do > > class Helper: > def __get__(self, ins, cls, name): > ... > > class a: > task0 = task1 = Helper() Yuck. From anthra.norell at bluewin.ch Mon Jul 5 05:07:42 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 11:07:42 +0200 Subject: What is the name of the name space I am in? Message-ID: <4C31A0DE.7010907@bluewin.ch> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue what the "dict" of the current name space is. I can name dicts of imported modules, because their name exists in the current name space. If, for instance, I import a module "service" then that module's name space would be "service.__dict__". But if I import * from service, then I incorporate that name space into the current one and I cannot name it, because the current module's name is not part of the module's own name space. "dir (service)" is equivalent to "service.__dict__.keys ()" if service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" where "?" is the name of the current module, itself not part of the current module's name space. So the question mark stands for an implicit name that can be neither named nor dropped. So my question is: how does one name the dictionary of the name space one is in? Frederic From thomas at jollans.com Mon Jul 5 05:27:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 11:27:37 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A0DE.7010907@bluewin.ch> References: <4C31A0DE.7010907@bluewin.ch> Message-ID: <4C31A589.3070008@jollans.com> On 07/05/2010 11:07 AM, Anthra Norell wrote: > I try to use "new.new.classobj (name, baseclass, dict)" and have no clue > what the "dict" of the current name space is. I can name dicts of > imported modules, because their name exists in the current name space. > If, for instance, I import a module "service" then that module's name > space would be "service.__dict__". But if I import * from service, then > I incorporate that name space into the current one and I cannot name it, > because the current module's name is not part of the module's own name > space. "dir (service)" is equivalent to "service.__dict__.keys ()" if > service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" > where "?" is the name of the current module, itself not part of the > current module's name space. So the question mark stands for an implicit > name that can be neither named nor dropped. So my question is: how does > one name the dictionary of the name space one is in? either globals() or locals(), depending on what you mean. > > Frederic > From soltysh at gmail.com Mon Jul 5 05:31:20 2010 From: soltysh at gmail.com (Soltys) Date: Mon, 5 Jul 2010 02:31:20 -0700 (PDT) Subject: GAE + recursion limit References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> <70bd0175-f752-4714-a7d9-49a65fc13f75@e5g2000yqn.googlegroups.com> Message-ID: <5dd9cd31-9d57-4a99-94cf-7818e305df1e@5g2000yqz.googlegroups.com> On 2 Lip, 22:49, Paul McGuire wrote: > > Does anyone have any clue what that might be? > > Why the problem is onGAE(even when run locally), when command line > > run works just fine (even withrecursionlimitdecreased)? > > Can't explain why you see different behavior onGAEvs. local, but it > is unusual for a "small" translator to flirt withrecursionlimit. ?I > don't usually see parsers come close to this with fewer than 40 or 50 > sub-expressions. ?You may have some left-recursiongoing on. ?Can you > post your translator somewhere, perhaps on pastebin, or on the > pyparsing wiki Discussion page (pyparsing.wikispaces.com)? > > -- Paul @David, thanks for the advice, I did ask on GAE list, id not get answer till now though. @Paul, I think I solved it. I did extensive test during weekend and it appears that my regular translator almost reaches 1000 recursion limit. Probably the last time I've tried to increase the recursion limit for GAE app I did it in the wrong place. (For future, if you'd like to do it, the best and working is to set that right before call to run_wsgi_app(application)). The only think that remains is, I need to review the grammar and how processing happens that I reach that limit with GAE. Thanks guys, Soltys From jeanmichel at sequans.com Mon Jul 5 05:52:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Jul 2010 11:52:58 +0200 Subject: [ANN] eric 5.0.0 released In-Reply-To: References: Message-ID: <4C31AB7A.2000107@sequans.com> Detlev Offenbach wrote: > Hi, > > I just uploaded eric 5.0.0. This is the first official release. It > is available via the eric web site. > > http://eric-ide.python-projects.org/index.html > > What is it? > ----------- > eric5 is the Python3 variant of the well know eric4 Python IDE and is > the first development environment, that runs natively with Python3. It > comes with all batteries included. The features are too much to be > listed in this announcement. Please see the eric web site for details. > > Regards, > Detlev > Nice work, thanks for sharing. JM From clp2 at rebertia.com Mon Jul 5 06:03:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 03:03:13 -0700 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A0DE.7010907@bluewin.ch> References: <4C31A0DE.7010907@bluewin.ch> Message-ID: On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell wrote: > I try to use "new.new.classobj (name, baseclass, dict)" and have no clue Slight tangent: Note that both the `new` module and old-style classes (which are what `classobj` produces) are deprecated. To produce new-style classes dynamically, use `type`. Cheers, Chris -- http://blog.rebertia.com From cournape at gmail.com Mon Jul 5 06:04:35 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 17:04:35 +0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On Mon, Jul 5, 2010 at 12:44 PM, Terry Reedy wrote: > On 7/4/2010 7:58 PM, John Nagle wrote: > >> The "incompatible with all extension modules I need" part >> is the problem right now. A good first step would be to >> identify the top 5 or 10 modules that are blocking a move to >> Python 3 by major projects with many users. > > Let me repeat. Last September, if not before, Guido identified numpy as a > top package blocking moves by other packages and projects. I am not sure > what he thought, but I consider it number 1. He encouraged the numpy people > to produce a 3.x version even though some did not see any personal benefit. > We supposedly will see numpy for 3.2. I think numpy will work for 3.1 as well (I don't know about 3.0, but my understanding is that there is no point into even looking at that release). With the scipy conferences going on, it will certainly be a good occasion to synchronize a bit faster - nothing beats face to face as a communication medium after all :) David From ncauderan at gmail.com Mon Jul 5 06:07:16 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 03:07:16 -0700 (PDT) Subject: SMTPHandler and Unicode Message-ID: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Hello, I want to send error messages with SMTPHandler logging. But SMTPHandler does not seem to be unicode aware. Is there something doable without playing with sys.setdefaultencoding ? import logging,logging.handlers smtpHandler = logging.handlers.SMTPHandler(mailhost=("smtp.example.com",25), fromaddr="toto at example.com", toaddrs="toto at example.com", subject=u"error message") LOG = logging.getLogger() LOG.addHandler(smtpHandler) LOG.error(u"sans accent") LOG.error(u"accentu\u00E9") gives : UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 117: ordinal not in range(128) Thank you ! From googler.1.webmaster at spamgourmet.com Mon Jul 5 06:38:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 5 Jul 2010 03:38:37 -0700 (PDT) Subject: Crash in PyThread_acquire_lock References: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Message-ID: <4c47da20-5203-441a-b6aa-da5f0cdc9f3a@w31g2000yqb.googlegroups.com> Thanks Antoine! :) You were right. It was the wrong thread...uhmm... Bye! :) From kylotan at gmail.com Mon Jul 5 06:40:53 2010 From: kylotan at gmail.com (Ben Sizer) Date: Mon, 5 Jul 2010 03:40:53 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> Message-ID: <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> On Jul 4, 7:33?am, Stefan Behnel wrote: > BenSizer, 04.07.2010 00:32: > > > On Jul 3, 11:12 pm,BenSizer ?wrote: > > >> >>> for el in root.getiterator(): > > >> ... ? ? ? ?print el > >> [much output snipped] > >> > >> > >> > >> > > > Hmm, I think I've worked it out. Apparently the XML namespace forms > > part of the tag name in this case. Is that what is intended? > > Sure. > > > I didn't see any examples of this in the docs. > > Admittedly, it's three clicks away from the library docs on docs.python.org. > > http://effbot.org/zone/element.htm#xml-namespaces Hopefully someone will see fit to roll this important documentation into docs.python.org before the next release... oops, too late. ;) It's one of those things that's easy to fix when you know what the problem is. Unfortunately it makes the examples a bit awkward. The example on http://docs.python.org/library/xml.etree.elementtree.html opens up an xhtml file and reads a "p" tag within a "body" tag, but the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states that 'The root element of the document must contain an xmlns declaration for the XHTML namespace'. Therefore I don't see how the example Python code given could work on a proper xhtml file, given that there should always be a namespace in effect but the code doesn't allow for it. That's my excuse anyway! :) -- Ben Sizer From fetchinson at googlemail.com Mon Jul 5 06:47:15 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 5 Jul 2010 12:47:15 +0200 Subject: Twisted 10.1.0 released In-Reply-To: References: Message-ID: > On behalf of Twisted Matrix Laboratories, I am honored to announce the > release of Twisted 10.1.0. > > Highlights include: > > * Deferreds now support cancellation > > * A new "endpoint" interface which can abstractly describe stream > transport endpoints such as TCP and SSL > > * inotify support for Linux, which allows monitoring of file system events. > > * AMP supports transferring timestamps > > Note also that this is the *last* supported release of Twisted for > Python 2.4 on Windows. > > For more information, see the NEWS file. > > It's stable, backwards compatible, well tested and in every way an > improvement. Download it now from: > > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.tar.bz2 > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.5.msi > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.6.msi > > Many thanks to Glyph Lefkowitz, who helped do the release preparation, > and the PyCon 2010 sprinters, who did so much of the work for this > release. > The twisted website at http://twistedmatrix.com/ seems to be having issues (trac can not connect to its database?). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chris at simplistix.co.uk Mon Jul 5 07:17:02 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 12:17:02 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Message-ID: <4C31BF2E.8060907@simplistix.co.uk> norbert wrote: > I want to send error messages with SMTPHandler logging. But > SMTPHandler does not seem to be unicode aware. Is there something > doable without playing with sys.setdefaultencoding ? try MailingLogger: http://www.simplistix.co.uk/software/python/mailinglogger If you have unicode problems with that, I'd be interested in fixing them! cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From ritchy_gato at hotmail.com Mon Jul 5 07:45:13 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Mon, 5 Jul 2010 04:45:13 -0700 (PDT) Subject: Plot problem.. ?? No sign at all Message-ID: hello guys.. I'm new at python programming and i'm having some problems with a script that i have been developing for my final project of my graduation. I have a script that is supposed to make a plot of a "Residuo" (waveform) witch is an output of a ADC ( Analogic To Digital Converter) for the first stage of the Flash pipiline ADC structure.This script doesn't show any syntax errors but it doesn't show no waveform at all at the plot window. I'm worried about this situation so I came here looking for help since I am new to the Python language. ----------------------------------------------------------------------- from pylab import* Vref = arange(1, 20, 0.02) Vi = arange(1, 10,0.1) for i in Vref: for n in Vi: if n > i/4: V0 = 2*n-i elif (-i/4) <= n and n <= i/4: V0 = 2*n elif Vi < -i/4: V0 = 2*n+i else: print "Try Again" ##print V0 plot (V0)boboz10 -------------------------------------------------------------------------------- From anthra.norell at bluewin.ch Mon Jul 5 08:16:25 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 14:16:25 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A589.3070008@jollans.com> References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> Message-ID: <4C31CD19.9040405@bluewin.ch> Thomas Jollans wrote: > On 07/05/2010 11:07 AM, Anthra Norell wrote: > >> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >> what the "dict" of the current name space is. I can name dicts of >> imported modules, because their name exists in the current name space. >> If, for instance, I import a module "service" then that module's name >> space would be "service.__dict__". But if I import * from service, then >> I incorporate that name space into the current one and I cannot name it, >> because the current module's name is not part of the module's own name >> space. "dir (service)" is equivalent to "service.__dict__.keys ()" if >> service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" >> where "?" is the name of the current module, itself not part of the >> current module's name space. So the question mark stands for an implicit >> name that can be neither named nor dropped. So my question is: how does >> one name the dictionary of the name space one is in? >> > > either globals() or locals(), depending on what you mean. > > >> Frederic >> >> Thomas, Thanks a million. Just the tip I needed. Frederic From ncauderan at gmail.com Mon Jul 5 08:22:17 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 05:22:17 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Message-ID: <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> On 5 juil, 13:17, Chris Withers wrote: > try MailingLogger: > > If you have unicode problems with that, I'd be interested in fixing them! Your package has the same unicode problem : import logging,logging.handlers from mailinglogger.MailingLogger import MailingLogger mailingLogger = MailingLogger(mailhost=('smtp.example.com', 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) LOG = logging.getLogger() LOG.addHandler(mailingLogger) LOG.error(u"sans accent") LOG.error(u"accentu\u00E9") --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128) From chris at simplistix.co.uk Mon Jul 5 08:32:13 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 13:32:13 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> Message-ID: <4C31D0CD.4040607@simplistix.co.uk> norbert wrote: > Your package has the same unicode problem : > import logging,logging.handlers > from mailinglogger.MailingLogger import MailingLogger > mailingLogger = MailingLogger(mailhost=('smtp.example.com', > 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) > LOG = logging.getLogger() > LOG.addHandler(mailingLogger) > LOG.error(u"sans accent") > LOG.error(u"accentu\u00E9") > > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' > in position 7: ordinal not in range(128) Interesting, I don't know what the logging framework's position is on unicode... What happens when you try the same logging with just a FileHandler registered? What encoding does the log file use? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From python at mrabarnett.plus.com Mon Jul 5 08:49:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 05 Jul 2010 13:49:39 +0100 Subject: Plot problem.. ?? No sign at all In-Reply-To: References: Message-ID: <4C31D4E3.5050500@mrabarnett.plus.com> Ritchy lelis wrote: > hello guys.. > > I'm new at python programming and i'm having some problems with a > script that i have been developing for my final project of my > graduation. > > I have a script that is supposed to make a plot of a > "Residuo" (waveform) witch is an output of a ADC ( Analogic To Digital > Converter) for the first stage of the Flash pipiline ADC > structure.This script doesn't show any syntax errors but it doesn't > show no waveform at all at the plot window. > > I'm worried about this situation so I came here looking for help since > I am new to the Python language. > > > ----------------------------------------------------------------------- > > from pylab import* > > Vref = arange(1, 20, 0.02) > Vi = arange(1, 10,0.1) > > for i in Vref: > for n in Vi: > if n > i/4: > V0 = 2*n-i > elif (-i/4) <= n and n <= i/4: > V0 = 2*n > elif Vi < -i/4: > V0 = 2*n+i > else: > print "Try Again" > ##print V0 > plot (V0)boboz10 > > -------------------------------------------------------------------------------- > Only the first 2 'if' conditions are ever true, so nothing is ever plotted. Also, I don't know what you're trying to do here: elif Vi < -i/4: because Vi is an array and i is a float. If Python ever tried to execute it there would be a ValueError exception: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() From ncauderan at gmail.com Mon Jul 5 09:17:38 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 06:17:38 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> Message-ID: <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> On 5 juil, 14:32, Chris Withers wrote: > norbert wrote: > > Your package has the same unicode problem : > > import logging,logging.handlers > > from mailinglogger.MailingLogger import MailingLogger > > mailingLogger = MailingLogger(mailhost=('smtp.example.com', > > 25),fromaddr='t... at example.com',toaddrs=('t... at example.com',)) > > LOG = logging.getLogger() > > LOG.addHandler(mailingLogger) > > LOG.error(u"sans accent") > > LOG.error(u"accentu\u00E9") > > > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' > > in position 7: ordinal not in range(128) > > Interesting, I don't know what the logging framework's position is on > unicode... > > What happens when you try the same logging with just a FileHandler > registered? What encoding does the log file use? > a FileHandler works as expected, the log file being UTF-8 encoded. The SMTPHandler is the only logger I know with this problem, maybe connected to SMTPLib implementation ? From anthra.norell at bluewin.ch Mon Jul 5 09:26:03 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 15:26:03 +0200 Subject: What is the name of the name space I am in? In-Reply-To: References: <4C31A0DE.7010907@bluewin.ch> Message-ID: <4C31DD6B.2060306@bluewin.ch> Chris Rebert wrote: > On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell wrote: > >> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >> > > Slight tangent: > Note that both the `new` module and old-style classes (which are what > `classobj` produces) are deprecated. > To produce new-style classes dynamically, use `type`. > > Cheers, > Chris > -- > http://blog.rebertia.com > > Chris, I noticed the deprecation situation reading the doc, but opted for what I thought might be more backward-compatible. Your suggestion prompted me to take a closer look and it turns out that "types" is compatible as far back as I have to go (2.5). So I use "types" with thanks to you. From solipsis at pitrou.net Mon Jul 5 09:35:32 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 5 Jul 2010 15:35:32 +0200 Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <20100705153532.210103be@pitrou.net> On Mon, 5 Jul 2010 06:17:38 -0700 (PDT) norbert wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. Ouch. Implicit encoding sounds like a bad behaviour. > The > SMTPHandler is the only logger I know with this problem, maybe > connected to SMTPLib implementation ? I suggest you report an issue on http://bugs.python.org From roy at panix.com Mon Jul 5 09:51:53 2010 From: roy at panix.com (Roy Smith) Date: Mon, 05 Jul 2010 09:51:53 -0400 Subject: Python 3 put-downs: What's the point? References: Message-ID: In article , Dennis Lee Bieber wrote: > On Sun, 04 Jul 2010 20:05:03 -0400, Roy Smith declaimed > the following in gmane.comp.python.general: > > > In article , > > Tim Chase wrote: > > > > > I've often wondered if changing the name of the language (such as > > > "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in > > > the crowd) would have mitigated some of the more vituperative > > > slurs on what became Py3, designating a shared legacy without the > > > expectation of 100% backwards-compatibility. > > > > Maybe it should have been "Python five, no, THREE!" > > But Adder works on two levels... The BritCom, and the serpentine... Not to mention that the same main characters show up in each version :-) From 88pigs at gmail.com Mon Jul 5 10:19:36 2010 From: 88pigs at gmail.com (=?GB2312?B?1uzW2LDL?=) Date: Mon, 5 Jul 2010 22:19:36 +0800 Subject: black console window of executing os.chmod() and os.access() Message-ID: Hi all, I want to use os.chmod or os.access to check the permission of a folder on remote Windows computer: os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) or os.access("\\1.1.1.1\sharedfolder", os.W_OK) I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a black console window display one second. Only remote folder has this problem, local folder has no this problem. Anybody know how to remove the black console window? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bill at SynectixLtd.com Mon Jul 5 10:35:59 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Mon, 5 Jul 2010 15:35:59 +0100 Subject: ImportError: DLL load failed: The specified module could not be found, SWIG, life, etc Message-ID: <89e8ueFuc6U1@mid.individual.net> I am struggling :-( I have used SWIG to build a module called SHIP. So I have a directory containing SHIP.py and _SHIP.pyd, as follows: H:\Viper\HostPC\V1\SHIP\Release>dir Volume in drive H has no label. Volume Serial Number is B83B-76F2 Directory of H:\Viper\HostPC\V1\SHIP\Release 05/07/2010 14:43 . 05/07/2010 14:43 .. 03/07/2010 16:28 41,079 SHIP.py 03/07/2010 14:36 495,616 _SHIP.pyd 2 File(s) 536,695 bytes 2 Dir(s) 58,270,535,680 bytes free I have a test Python program which imports sys and os and then attempts to import SHIP; it begins as follows: ## D for John's notebook ## E for Rod's notebook ## H for Bill's notebook DRIVE = 'H:' import sys import os if ( not os.path.exists(DRIVE) ): print "Drive \'%s\' does not exist on this machine; edit top of file" % (DRIVE) sys.exit(0) # Prepend our path sys.path[:0] = [DRIVE + r'\Viper\HostPC\V1\SHIP\Release'] import SHIP SHIP.Initialise(); I then create a Command Prompt window and enter: H:\Viper\HostPC\V1\SHIP>C:\Python26\python -vv Test1.py >tmp.txt 2>&1 In tmp.txt, I see the following: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. # trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyd # trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.py # H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc matches H:\Viper\HostPC\V1\SHIP\Release\SHIP.py import SHIP # precompiled from H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc # trying H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd # clear[2] __name__ # clear[2] __file__ Traceback (most recent call last): File "Test1.py", line 15, in import SHIP File "H:\Viper\HostPC\V1\SHIP\Release\SHIP.py", line 7, in import _SHIP ImportError: DLL load failed: The specified module could not be found. It would seem the "import SHIP" is finding SHIP.py without any trouble. SHIP.py begins by "import _SHIP". Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for some reason, which I cannot fathom, says "DLL load failed". Can anyone offer me any suggestion where I am going wrong or how to tackle this problem? Could it be that the Python 2.6 I am running did not use the same compiler (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this without moving on from VC6? TIA, Bill From alan.isaac at gmail.com Mon Jul 5 10:38:04 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 05 Jul 2010 10:38:04 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: References: Message-ID: On 7/5/2010 7:45 AM, Ritchy lelis wrote: > from pylab import* > > Vref = arange(1, 20, 0.02) > Vi = arange(1, 10,0.1) > > for i in Vref: > for n in Vi: > if n> i/4: > V0 = 2*n-i > elif (-i/4)<= n and n<= i/4: > V0 = 2*n > elif Vi< -i/4: > V0 = 2*n+i > else: > print "Try Again" > ##print V0 > plot (V0) Your data manipulations don't make sense to me, and plotting one point at a time is probably not what you want to do. As a rule, use arange only with integer arguments. Finally, if you want to see your plot, you need to show it (or save it). So create an **array** V0 and then do something like the following: import numpy as np import matplotlib.pyplot as plt Vref = np.linspace(1,20, 1000) Vi = np.linspace(1,10,100) #replace the next line V0 = ... #create an array plt.plot(V0) plt.show() hth, Alan Isaac From thomas at jollans.com Mon Jul 5 10:38:27 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 16:38:27 +0200 Subject: black console window of executing os.chmod() and os.access() In-Reply-To: References: Message-ID: <4C31EE63.3080001@jollans.com> On 07/05/2010 04:19 PM, ??? wrote: > Hi all, > I want to use os.chmod or os.access to check the permission of a > folder on remote Windows computer: > os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) > or > os.access("\\1.1.1.1\sharedfolder", os.W_OK) That won't work: >>> print("\\1.1.1.1\sharedfolder") \1.1.1.1\sharedfolder >>> > > I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a > black console window display one second. > Only remote folder has this problem, local folder has no this problem. > > Anybody know how to remove the black console window? Does the script actually work for remote folders? Does the same problem occur for other file operations on remote systems? Maybe someone else knows an answer, otherwise maybe my thoughts will be of some help. Thomas From 88pigs at gmail.com Mon Jul 5 11:01:02 2010 From: 88pigs at gmail.com (=?GB2312?B?1uzW2LDL?=) Date: Mon, 5 Jul 2010 23:01:02 +0800 Subject: black console window of executing os.chmod() and os.access() In-Reply-To: <4C31EE63.3080001@jollans.com> References: <4C31EE63.3080001@jollans.com> Message-ID: Sorry, I mean "\\\\1.1.1.1\\sharedfolder" Seems os.chmod(), os.access() and os.makedirs() all have this problem when the path is a remote path. 2010/7/5 Thomas Jollans > On 07/05/2010 04:19 PM, ??? wrote: > > Hi all, > > I want to use os.chmod or os.access to check the permission of a > > folder on remote Windows computer: > > os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) > > or > > os.access("\\1.1.1.1\sharedfolder", os.W_OK) > > That won't work: > > >>> print("\\1.1.1.1\sharedfolder") > \1.1.1.1\sharedfolder > >>> > > > > > > I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a > > black console window display one second. > > Only remote folder has this problem, local folder has no this problem. > > > > Anybody know how to remove the black console window? > > Does the script actually work for remote folders? Does the same problem > occur for other file operations on remote systems? > > Maybe someone else knows an answer, otherwise maybe my thoughts will be > of some help. > > Thomas > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 5 11:01:28 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 17:01:28 +0200 Subject: ImportError: DLL load failed: The specified module could not be found, SWIG, life, etc In-Reply-To: <89e8ueFuc6U1@mid.individual.net> References: <89e8ueFuc6U1@mid.individual.net> Message-ID: <4C31F3C8.5010402@jollans.com> On 07/05/2010 04:35 PM, Bill Davy wrote: > I am struggling :-( smile! > > I have used SWIG to build a module called SHIP. So I have a directory > containing SHIP.py and _SHIP.pyd, as follows: > > [ ...] > > Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for > some reason, which I cannot fathom, says "DLL load failed". > Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd depends on some other DLL? Since you used SWIG, I'm guessing that you're wrapping some other library. Maybe that's what it can't find. > > > Can anyone offer me any suggestion where I am going wrong or how to tackle > this problem? > > > > Could it be that the Python 2.6 I am running did not use the same compiler > (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this > without moving on from VC6? > Shouldn't be a problem, as long as the calling convention hasn't change, which it hasn't. If you're on a 64-bit system there might be a problem there with Python and some DLLs being built for different architectures? Cheers, Thomas From nanothermite911fbibustards at gmail.com Mon Jul 5 11:58:19 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Mon, 5 Jul 2010 08:58:19 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts References: <71420572-82ad-4945-931a-3452eeebcb1d@5g2000yqz.googlegroups.com> Message-ID: <83cc2a04-296f-4f84-9633-ccb768095f5c@x27g2000yqb.googlegroups.com> http://www.veteranstoday.com/2010/06/16/jim-w-dean-faked-israeli-flotilla-v= ideos-provide-opening-to-expose-israeli-expionage-here/ JIM W. DEAN: FAKED ISRAELI FLOTILLA VIDEOS PROVIDE OPENING TO EXPOSE ISRAELI EXPIONAGE HERE June 16, 2010 posted by Gordon Duff =B7 20 Comments Share Faked Israeli Flotilla videos provide opening to expose Israeli Espionage here By Jim W. Dean for Veterans Today Dear Friends, The Zionists shot themselves in both feet with this rushed spin job to deflect attention on their slaughter of the Gaza Flotilla activists. We can thank the retired Intel folks for the frame analysis exposing the fraud on the Veterans Today link above. Fortunately more and more retired Intel and security people are getting into the life or death struggle defending the country from our =91domestic enemies=92. These Photo shopped videos were done so poorly as to be almost comical if they were not done to cover up murders. You will have to watch the video several times to really visually catch their mistakes. Don=92t be afraid to use the pause button to study the images. The ending scenes on the fantail immediately struck me as a studio shoot. The lighting was way to bright for a ship in that situation. The actors=85well=85they did a really poor job. In the real videos you see more confusion=85the clothes are not right. If was a completely staged event, even down to the tiny slingshot one guy raises up so it can be noticed. Also, the camera is stationary (on a tripod)=85a huge mistake. YouTube - Veterans Today - That the radical Zionists would lie, cheat or steal to gain some benefit for themselves is not even a news event. Our own American declassified intelligence lays this all out in spades. The best one book read on it is Steven Green=92s Taking Sides, if you can find a used one online. The real news here is how such an obvious fraud was pipelined into American mass media. Any experienced news video editor would have spotted the obvious fraud on these tapes. But they pushed it right out onto unsuspecting Americans who wrongly think that mass media would not pedal something they know to be totally bogus. And how wrong they are. But it gets worse. Our Intel and security agencies always do frame by frame analysis of important video material like this. They also had to have spotted this=85yet they did not warn the American people that this was a fraud. Why not? The answer is that Israel espionage has penetrated American government, media, politics, and even our security institutions to the point that the Zios have no fear of those responsible for our national security protecting us from the Israeli 5th column operating here. They are protected by powerful interests. The military, veteran and intelligence communities are really the only American institutions who can take the lead on tearing the Israeli espionage networks out by the roots. All the other institutions are already compromised. And they will fight like hell as they know that the 5th column could not have been as effective as they have been without more than a few disloyal Americans helping them, many who are well known names. They will do anything to protect themselves from exposure=85anything=85and they have. The USS Liberty is just one example, where dead and wounded servicemen were literally abandoned on the battlefield so as to not reveal to the American public that they were murdered by the Israelis. You might remember that the last whistleblower reform legislation was slapped down a while back. The Congresscritters know what a threat that is. So do the Israelis. We have loyal Intel people who know that the Israelis have been given key Homeland Security contracts that actually have the American taxpayer funding their espionage operations. Oh yes, the Israelis make us pay for it=85smart folks they. Michael Chertoff flew to Israel a few years back to put on a =91fast track=92 seminar for Israeli security companies (staffed by Mussed and military Intel people) to make sure they can the key contracts that they wanted, like airport security and communications plums. This is a huge national scandal, and one that a Congressional investigation would not put a dent into as those folks have sold us out to the Israelis in return for political support. John McCain is one of the worst examples, but he has lots of company. I listened to General Russel Honore give a great Memorial Day speech in Atlanta recently. It was short and sweet in his normal style. =93We were born by accident, based on where our parents were. To live free is a privilege. But to die free is an obligation that we leave to each generation.=94 Folks, If we don=92t join hands and root out this the Israeli 5th column here we will be breaking the chain, and it is getting late in the day. Their numbers are small, so they have put the fix it at the top, political espionage. But we have the numbers to beat them. They have just not been brought to bear due to their divide and conquer, smoke and mirrors tactics. Our political establishment is more afraid of the Israel Lobby than they are of us. We must reverse that situation or we will have betrayed the next generation. So let=92s roll up our sleeves, and get on with the work. First up is going to go see your Congresscritters with a small group of vets/Intel people and go through this video with them step by step, and demand to know why our people did nothing to expose the fraud, including Obama possibly even having been sand bagged on it. Did Rahm Emanuel and David Axelrod know? Did Hillary, Defense and the CIA? Why no official exposure by those sworn to protect us. And ask them what they have done to combat Israeli espionage here? You will enjoy the look on their faces. I promise you that. Jim Dean Heritage TV=85Atlanta Assoc. for Intelligence Officers On Jul 4, 6:05=A0pm, gaze... at shell.xmission.com (Kenny McCormack) wrote: > In article , > small Pox =A0 wrote: > > >VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - > >Bellies ripped open and numerous injured - call for TRUE PATRIOTS . > >The deep undercover spies agents of influence mislead the public on > >the facts > > >http://www.youtube.com/watch?v=3DfRZSzdQuOqM&feature=3Drelated > >http://www.youtube.com/watch?v=3D0q7yEnMjQ6U&feature=3Drelated > >http://www.youtube.com/watch?v=3Da3E2NcC0x20&feature=3Drelated > >http://www.youtube.com/watch?v=3DfRZSzdQuOqM&feature=3Drelated > > >http://www.venusproject.com/911/911RussianSatellite1.html > > >http://www.gtr5.com/ > > Your C question was? JIM W. DEAN: FAKED ISRAELI FLOTILLA VIDEOS PROVIDE OPENING TO EXPOSE ISRAELI EXPIONAGE HERE From timcoote at gmail.com Mon Jul 5 13:01:14 2010 From: timcoote at gmail.com (Tim) Date: Mon, 5 Jul 2010 10:01:14 -0700 (PDT) Subject: throwing exceptions from csv.DictReader or even csv.reader Message-ID: Hullo Csv is a very common format for publishing data as a form of primitive integration. It's an annoyingly brittle approach, so I'd like to ensure that I capture errors as soon as possible, so that I can get the upstream processes fixed, or at worst put in some correction mechanisms and avoid getting polluted data into my analyses. A symptom of several types of errors is that the number of fields being interpreted varies over a file (eg from wrongly embedded quote strings or mishandled embedded newlines). My preferred approach would be to get DictReader to throw an exception when encountering such oddities, but at the moment it seems to try to patch over the error and fill in the blanks for short lines, or ignore long lines. I know that I can use the restval parameter and then check for what's been parsed when I get my results back, but this seems brittle as whatever I use for restval could legitimately be in the data. Is there any way to get csv.DictReader to throw and exception on such simple line errors, or am I going to have to use csv.reader and explicitly check for the number of fields read in on each line? cheers Tim From chris at simplistix.co.uk Mon Jul 5 13:21:39 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 18:21:39 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <20100705153532.210103be@pitrou.net> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: <4C3214A3.3070700@simplistix.co.uk> Antoine Pitrou wrote: > On Mon, 5 Jul 2010 06:17:38 -0700 (PDT) > norbert wrote: >> a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. Yes indeed, hence my question on python-dev... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Mon Jul 5 13:32:50 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Jul 2010 19:32:50 +0200 Subject: throwing exceptions from csv.DictReader or even csv.reader References: Message-ID: Tim wrote: > Csv is a very common format for publishing data as a form of primitive > integration. It's an annoyingly brittle approach, so I'd like to > ensure that I capture errors as soon as possible, so that I can get > the upstream processes fixed, or at worst put in some correction > mechanisms and avoid getting polluted data into my analyses. > > A symptom of several types of errors is that the number of fields > being interpreted varies over a file (eg from wrongly embedded quote > strings or mishandled embedded newlines). My preferred approach would > be to get DictReader to throw an exception when encountering such > oddities, but at the moment it seems to try to patch over the error > and fill in the blanks for short lines, or ignore long lines. I know > that I can use the restval parameter and then check for what's been > parsed when I get my results back, but this seems brittle as whatever > I use for restval could legitimately be in the data. > > Is there any way to get csv.DictReader to throw and exception on such > simple line errors, or am I going to have to use csv.reader and > explicitly check for the number of fields read in on each line? I think you have to use csv.reader. Untested: def DictReader(f, fieldnames=None, *args, **kw): reader = csv.reader(f, *args, **kw) if fieldnames is None: fieldnames = next(reader) for row in reader: if row: if len(fieldnames) != len(row): raise ValueError yield dict(zip(fieldnames, row)) Peter From Bill at SynectixLtd.com Mon Jul 5 13:51:07 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Mon, 5 Jul 2010 18:51:07 +0100 Subject: ImportError: DLL load failed: The specified module could notbe found, SWIG, life, etc References: <89e8ueFuc6U1@mid.individual.net> Message-ID: <89ekcaF5kqU1@mid.individual.net> "Thomas Jollans" wrote in message news:mailman.265.1278342154.1673.python-list at python.org... > On 07/05/2010 04:35 PM, Bill Davy wrote: >> I am struggling :-( > > smile! > >> >> I have used SWIG to build a module called SHIP. So I have a directory >> containing SHIP.py and _SHIP.pyd, as follows: >> >> [ ...] >> >> Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for >> some reason, which I cannot fathom, says "DLL load failed". >> > > Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd > depends on some other DLL? Since you used SWIG, I'm guessing that you're > wrapping some other library. Maybe that's what it can't find. > Well, there's no mention of another librarary, and "import _SHIP" is the first (non-comment) statement in SHIP.py But when I run Dependency Walker against _SHIP.pyd it does say there's a missing DLL (WINUSB.DLL) so I suspect I've got to sort that out. >> >> >> Can anyone offer me any suggestion where I am going wrong or how to >> tackle >> this problem? >> >> >> >> Could it be that the Python 2.6 I am running did not use the same >> compiler >> (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this >> without moving on from VC6? >> > > Shouldn't be a problem, as long as the calling convention hasn't change, > which it hasn't. If you're on a 64-bit system there might be a problem > there with Python and some DLLs being built for different architectures? Yep, all for the same architetcure. I suspect it's a dependency problem. Oh well. > > Cheers, > Thomas From eric.promislow at gmail.com Mon Jul 5 14:01:52 2010 From: eric.promislow at gmail.com (Eric Promislow) Date: Mon, 5 Jul 2010 11:01:52 -0700 (PDT) Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <7b86e51d-32f9-4a4f-8f66-e09be6142f33@w15g2000pro.googlegroups.com> On Jul 1, 9:39?am, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. You can easily do this with a Komodo macro. First you get a reference to the current buffer like so. In JS: var view = ko.views.manager.currentView; var scimoz = view.scimoz; // the editor In Python code: currentView = components.classes["@activestate.com/koViewService;1"].\ getService(Components.interfaces.koIViewService).currentView view = currentView.QueryInterface(Components.interfaces.koIScintillaView) scimoz = view.scimoz To get the current width of the line-selection margin: oldValue = scimoz.getMarginWidth(2) # Margin #2, width given in pixels To set a new value: scimoz.setMarginWidth(2, newValue) # 4 looks like a good value There is no boundary between the breakpoint margin (1) and the line- selection margin. If you want this behaviour in general, you can write a post-file-open macro that will set the margin after a file is opened. You currently can't write a post-file-open trigger in Python, (see bug http://bugs.activestate.com/show_bug.cgi?id=45265) Hope this helps, Eric Promislow Komodo Team Member From usernet at ilthio.net Mon Jul 5 14:02:17 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 5 Jul 2010 18:02:17 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 2010-07-05, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: >> Classic Unix programming is a matter of stringing a bunch of tools >> together with pipes to get the output you want. This isn't a great >> paradigm for GUIs (not without tweaking that hasn't really been done), but >> then again it was never meant to be. > > I???ve never come across any system where you could string together multiple > GUI apps, or even multiple GUI operations in the same app, in any sensible > or effective way at all. GUIs just aren???t designed to work that way. You can if they are designed to be used externally. COM is an execellent example of this as is script-fu and any number of other technologies that allow external access to the subroutines or automation capability of a GUI application. The problem is not that it cannot be done; but, that it must be explicilty designed to be used this way. I have worked with complex business process automation centered around Excel and I have automated some really ugly AJAX style web based applications that would only work inside of IE6 by accessing IE through its COM interface. > The command line (or scripting, the difference isn???t that important) remains > the only workable way to string together complex combinations of simpler > operations. The difference is that it is almost always possible to automate using text based applications, even when the author of the software never designed the software to be scripted. Text based IO streams are easy to capture and manipulate. Automating GUI applications requires interal access to the program through some kind of interface and, ideally, decent documention of the interface, something that is missing from many, if not most, GUIs. Anything else relies on ugly and, generally fragile, mechanisms to intercept the programs output and send event triggers to the application. The recent thread to automate Minesweeper by processing its screenshot is an example of this. From tjreedy at udel.edu Mon Jul 5 14:09:37 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:09:37 -0400 Subject: Confusion over etree.ElementTree.Element.getiterator In-Reply-To: <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> Message-ID: On 7/5/2010 6:40 AM, Ben Sizer wrote: >> Admittedly, it's three clicks away from the library docs on docs.python.org. >> >> http://effbot.org/zone/element.htm#xml-namespaces > > Hopefully someone will see fit to roll this important documentation > into docs.python.org before the next release... oops, too late. ;) Not too late for next release. Open a doc issue with as specific a suggestion as possible. > > It's one of those things that's easy to fix when you know what the > problem is. Unfortunately it makes the examples a bit awkward. The > example on http://docs.python.org/library/xml.etree.elementtree.html > opens up an xhtml file and reads a "p" tag within a "body" tag, but > the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states > that 'The root element of the document must contain an xmlns > declaration for the XHTML namespace'. Therefore I don't see how the > example Python code given could work on a proper xhtml file, given > that there should always be a namespace in effect but the code doesn't > allow for it. > > That's my excuse anyway! :) -- Terry Jan Reedy From wxjmfauth at gmail.com Mon Jul 5 14:12:19 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 5 Jul 2010 11:12:19 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> Message-ID: <06231c4e-a405-42b1-b0ee-f0c104057e3e@i31g2000yqm.googlegroups.com> Thank you all for the discussion and the explanations. > Mark Dickinson I toyed a littled bit this afternoon and I wrote a colouriser (British spelling?) with the tokenize module. It is quite simple and easy. BTW, if I understand correctly the module tokenize import the module token. So your example becomes: >>> from cStringIO import StringIO >>> import tokenize >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): print tokenize.tok_name[tok[0]], tok[1] NAME print9 NUMBER .0 ENDMARKER >>> From tjreedy at udel.edu Mon Jul 5 14:33:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:33:02 -0400 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: On 7/4/2010 9:20 PM, CM wrote: > On Jul 4, 7:14 pm, Terry Reedy wrote: >> > > I think there's a good point to Python 3 put-downs (if I take put-down > to mean generally reasonable criticism, which is what I've read here > recently, and not trolling). And that is simply to register > dissent. But dissent from what? Dissent from something obviously true? (like 'Pythonx.y is useful to some people') Dissent from something obvious false, that no one has said? (like 'Everyone should switch to Pythonx.y') > Any online group is an opportunity to register dissent in a way that > is public, open, immediate, interactive, and will (probably) be > preserved for historians to check. The fact is, some people have > gripes with Python 3; they are letting it be known. I have several 'gripes' with 2.7 and it is currently useless to me. Should I let them be known? How many times? > If no one did, > there could be no later time at which people could look back and know > what the reaction was to its introduction--it would just be a blank. > Aren't opinions that dissent from the prevailing ones important to > register, whether one thinks they are right or wrong? Do you agree with me that the same criteria for gripe legitimacy should be applied equally to all Python versions (even if we should disagree on what those criteria should be)? -- Terry Jan Reedy From tjreedy at udel.edu Mon Jul 5 14:42:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:42:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c318235$0$1663$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 2:56 AM, John Nagle wrote: > On 7/4/2010 10:44 PM, Terry Reedy wrote: >> I you have any other ideas about other top blockers, please share them. > > The Twisted team has a list of what they need: > > "http://stackoverflow.com/questions/172306/how-are-you-planning-on-handling-the-migration-to-python-3" > > > * Zope Interface > * PyCrypto > * PyOpenSSL > * PyGTK Good start. Now what is blocking those four? Lack of developer interest/time/ability? or something else that they need? -- Terry Jan Reedy From emile at fenx.com Mon Jul 5 14:43:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 05 Jul 2010 11:43:55 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 11:02 AM Tim Harig said... > Automating GUI applications requires interal > access to the program through some kind of interface and, ideally, decent > documention of the interface, something that is missing from many, if > not most, GUIs. Anything else relies on ugly and, generally fragile, > mechanisms to intercept the programs output and send event triggers to > the application. I've been doing the 'anything else...' stuff for years now without issue, so ugly, yes, but fragile, not really. Unless you let users on the same machine... Emile From tjreedy at udel.edu Mon Jul 5 14:49:04 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:49:04 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 6:04 AM, David Cournapeau wrote: > On Mon, Jul 5, 2010 at 12:44 PM, Terry Reedy wrote: [snip] > I think numpy will work for 3.1 as well If numpy were released today for 3.1 (or even anytime before 3.2), that would be great. It would let those waiting for it that it is real and that they can go ahead on their ports. Part of the reason for the 3.2 core-change moratorium was to let 3rd-party packages target 3.2 by working with 3.1. If they finish and release sooner (as some have), even better. Unless they depend on something that changes in the stdlib, porting for one should pretty much be porting for both. > (I don't know about 3.0, but > my understanding is that there is no point into even looking at that > release). Agreed. -- Terry Jan Reedy From hema_111150 at yahoo.com Mon Jul 5 15:03:05 2010 From: hema_111150 at yahoo.com (eslam) Date: Mon, 5 Jul 2010 12:03:05 -0700 (PDT) Subject: vidio***** Message-ID: <0bf3eca7-c4c0-4017-b866-2c938dc9d627@i31g2000yqm.googlegroups.com> http://www.kavalec.com/thisisislam.swf From python.list at tim.thechases.com Mon Jul 5 15:32:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Jul 2010 14:32:13 -0500 Subject: Python 3 put-downs: What's the point? In-Reply-To: <20100705095032.6f7749fe@brasov> References: <20100705095032.6f7749fe@brasov> Message-ID: <4C32333D.5020702@tim.thechases.com> On 07/05/2010 02:50 AM, Gregor Horvath wrote: > Am Sun, 04 Jul 2010 18:51:54 -0500 > schrieb Tim Chase: > >> I think it's the same venting of frustration that caused veteran >> VB6 developers to start calling VB.Net "Visual Fred" -- the >> language was too different and too non-backwards-compatible. >> > > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. > > VB6 and VB.NET are totally different languages and technologies, with > some similarity in syntax. This is not true for Python 2->3. > This is an healthy organic language growth, not an abandon of a > language. The quintessential example is Py3's breaking of Hello World. It's a spectrum of language changes -- Visual Fred just happens to be MUCH further down the same spectrum having more dramatic changes. Only a subset of $OLD_VER (whether Py2 or VB6) code will run unmodified under $NEW_VER (whether Py3 or VB.Net). It just happens that the subset for Python is considerably larger than the subset for VB (and Python's conversion tools seem a little more useful than VB's, IMHO). IIRC, neither raw VB6 nor Py2 byte-code will run raw in the new environment (old VB .exe files don't make use of .Net libraries/CLR, nor do Py2 .pyc files run under Py3) so a project-rebuild is a minimum (though in Py3, s/minimum/negligible/) requirement. A little defensive coding in $OLD_VER also helps, and here I'd say Python developers had a MUCH longer lead-time to understand scope & magnitude of the coming changes; VB6 developers (former self included) had VB.Net foisted on them with much less heralding about the areas-of-breakage. I'm very much +0 on Py3...it doesn't impact my life yet and it's not a regular part of my coding, but the changes I've seen are good for the language and the future of Python. But breaking-changes freak some folks out, leading to the put-downs referenced by the OP. As a former VB6 developer, the shift to VB.Net was enough to send me packing. The shift from Py2 to Py3 will be bumpy, but not enough to lose me as a developer. -tkc From kw at codebykevin.com Mon Jul 5 15:35:13 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 05 Jul 2010 15:35:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c318235$0$1663$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <11e61$4c323409$4275d90a$16304@FUSE.NET> On 7/5/10 2:56 AM, John Nagle wrote: > * PyCrypto > * PyOpenSSL These, and Mark Pilgrim's feedparser, need to be 3.x compatible before I can think about Python 3.x. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From dickinsm at gmail.com Mon Jul 5 15:56:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 5 Jul 2010 12:56:23 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> <06231c4e-a405-42b1-b0ee-f0c104057e3e@i31g2000yqm.googlegroups.com> Message-ID: On Jul 5, 7:12?pm, jmfauth wrote: > BTW, if I understand correctly the module tokenize import > the module token. So your example becomes: > > >>> from cStringIO import StringIO > >>> import tokenize > >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): > > ? ? ? ? print tokenize.tok_name[tok[0]], tok[1] Ah yes; you're right. Thanks! Mark From ggrp2.20.martineau at dfgh.net Mon Jul 5 15:59:00 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 12:59:00 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: On Jul 5, 1:12?am, Benjamin Kaplan wrote: > On Sun, Jul 4, 2010 at 7:58 PM, John Machin wrote: > > On Jul 5, 12:27?pm, Martineau wrote: > >> On Jul 4, 8:34?am, Benjamin Peterson wrote: > > >> > On behalf of the Python development team, I'm jocund to announce the second > >> > release candidate of Python 2.7. > > >> > Python 2.7 will be the last major version in the 2.x series. However, it will > >> > also have an extended period of bugfix maintenance. > > >> > 2.7 includes many features that were first released in Python 3.1. The faster io > >> > module, the new nested with statement syntax, improved float repr, set literals, > >> > dictionary views, and the memoryview object have been backported from 3.1. Other > >> > features include an ordered dictionary implementation, unittests improvements, a > >> > new sysconfig module, auto-numbering of fields in the str/unicode format method, > >> > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > >> > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWSin the Python > >> > distribution. > > >> > To download Python 2.7 visit: > > >> > ? ? ?http://www.python.org/download/releases/2.7/ > > >> > 2.7 documentation can be found at: > > >> > ? ? ?http://docs.python.org/2.7/ > > >> > This is a production release and should be suitable for all libraries and > >> > applications. ?Please report any bugs you find, so they can be fixed in the next > >> > maintenance releases. ?The bug tracker is at: > > >> > ? ? ?http://bugs.python.org/ > > >> > Enjoy! > > >> > -- > >> > Benjamin Peterson > >> > Release Manager > >> > benjamin at python.org > >> > (on behalf of the entire python-dev team and 2.7's contributors) > > >> Benjamin (or anyone else), do you know where I can get the Compiled > >> Windows Help file -- python27.chm -- for this release? In the past > >> I've been able to download it from the Python web site, but have been > >> unable to locate it anywhere for this new release. I can't build it > >> myself because I don't have the Microsoft HTML help file compiler. > > >> Thanks in advance. > > > If you have a Windows box, download the .msi installer for Python 2.7 > > and install it. The chm file will be in C:\Python27\Doc (if you choose > > the default installation directory). Otherwise ask a friendly local > > Windows user for a copy. > > -- > > Or you can just use 7-zip or cabextract on the MSi. Saves you from > having to uninstall it later, and it works on non-Windows machines. Perhaps it's hidden somewhere, but I couldn't find the .chm help file in the python-2.7.msi file using 7-zip, nor saw anything that looked like a Doc folder embedded within it -- so I doubt installing it on a Windows machine would work any better. I'd like to view the contents of the help file without actually installing the release which would wipe out any currently installed version (I'm one of those rare people who actually reads manuals *before* using or installing most things.) So my original question stands -- where can one get the Windows Help file for v2.7? From darcy at druid.net Mon Jul 5 16:30:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 5 Jul 2010 16:30:43 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <20100705163043.f4c8d085.darcy@druid.net> On Mon, 05 Jul 2010 14:42:13 -0400 Terry Reedy wrote: > Good start. Now what is blocking those four? > Lack of developer interest/time/ability? > or something else that they need? How about a basic how-to document? I maintain PyGreSQL and would like to move it to 3.x right now but I don't even know what the issues are. I can see on the site the 2.x documents and the 3.x documents for extending with C modules and I can read both from end to end but that hits the time issue above. If there was a relatively simple document that showed what needed to be changed in the C code we could get started on the transition sooner. Or is there no change at the C level? That would make things easy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alex.kapps at web.de Mon Jul 5 16:31:52 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 05 Jul 2010 22:31:52 +0200 Subject: Python 2.7 released In-Reply-To: References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <4C324138.7040202@web.de> Martineau wrote: > Perhaps it's hidden somewhere, but I couldn't find the .chm help file > in the python-2.7.msi file using 7-zip, nor saw anything that looked > like a Doc folder embedded within it -- so I doubt installing it on a > Windows machine would work any better. I don't know much about the .msi format or how 7-Zip handles it, but on my XP box, 7-Zip lists a "python" sub-archive (a 7-Zip "compound"). Within is the python27.chm From cmpython at gmail.com Mon Jul 5 16:41:48 2010 From: cmpython at gmail.com (CM) Date: Mon, 5 Jul 2010 13:41:48 -0700 (PDT) Subject: Python 3 put-downs: What's the point? References: Message-ID: On Jul 5, 2:33?pm, Terry Reedy wrote: > On 7/4/2010 9:20 PM, CM wrote: > > > On Jul 4, 7:14 pm, Terry Reedy ?wrote: > > > I think there's a good point to Python 3 put-downs (if I take put-down > > to mean generally reasonable criticism, which is what I've read here > > recently, and not trolling). ?And that is simply to register > > dissent. > > But dissent from what? > > Dissent from something obviously true? > (like 'Pythonx.y is useful to some people') > > Dissent from something obvious false, that no one has said? > (like 'Everyone should switch to Pythonx.y') I was thinking more like dissent from something that is not obviously true or false, but a matter of debate, like some of the decisions behind Python 3 itself or how the transition is being managed. I got the sense that was about where the complaints lie. Some of the responses to those complaints were educational to me, so I didn't mind reading the exchanges. > > Any online group is an opportunity to register dissent in a way that > > is public, open, immediate, interactive, and will (probably) be > > preserved for historians to check. ?The fact is, some people have > > gripes with Python 3; they are letting it be known. > > I have several 'gripes' with 2.7 and it is currently useless to me. > Should I let them be known? How many times? Maybe you should; maybe it can be constructive criticism to developers or can jog someone to tell you something that you didn't know. How many times? Once, maybe twice. I agree one can overdo it, and maybe you've read more of the gripes than I have and it seems repetitive by now. > > ?If no one did, > > there could be no later time at which people could look back and know > > what the reaction was to its introduction--it would just be a blank. > > Aren't opinions that dissent from the prevailing ones important to > > register, whether one thinks they are right or wrong? > > Do you agree with me that the same criteria for gripe legitimacy should > be applied equally to all Python versions (even if we should disagree on > what those criteria should be)? I think so, sure. From ncauderan at gmail.com Mon Jul 5 16:49:40 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 13:49:40 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: > > Ouch. Implicit encoding sounds like a bad behaviour. Looking at the FileHandler source ( http://svn.python.org/view/python/trunk/Lib/logging/__init__.py?view=markup ) : the utf-8 encoding is a fallback. But *FileHandler family let you specify the encoding you want, so that's OK I think. But SMTPHandler does not have such a thing it sends its email with : msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % ( self.fromaddr, ",".join(self.toaddrs), self.getSubject(record), formatdate(), msg) ... smtp.sendmail(from,to,msg) And there is no encoding in all this. It seems pretty dangerous to me (so my first post) because your application will work without any problem with a FileHandler and the day you'll decide to send email in case of serious problem, it will crash with a UnicodeError. I can't see any workaround, except by subclassing SMTPHandler's emit method to be unicode-aware or at least URF-8 aware. From martin at v.loewis.de Mon Jul 5 17:57:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 05 Jul 2010 23:57:23 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <4C325543.6010408@v.loewis.de> Am 05.07.2010 22:30, schrieb D'Arcy J.M. Cain: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. > I can see on the site the 2.x documents and the 3.x documents for > extending with C modules and I can read both from end to end but that > hits the time issue above. If there was a relatively simple document > that showed what needed to be changed in the C code we could get > started on the transition sooner. > > Or is there no change at the C level? That would make things easy. If somebody would move that into a narrative form, I'd be happy to list the changes I know of, and the approaches I took to make C modules work on both 2.x and 3.x (actually, I did the port of psycopg2, so I expect PyGreSQL might be similar). However, I'm not willing to maintain such a document - I have too many projects already, and English is not my native language. Regards, Martin From mtigges at gmail.com Mon Jul 5 18:01:10 2010 From: mtigges at gmail.com (m) Date: Mon, 5 Jul 2010 15:01:10 -0700 (PDT) Subject: Very odd output from subprocess References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Jul 1, 12:42?am, Nobody wrote: > On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > > If I add the line: > > ? ? ?for l in line: print ord(l),'\t',l > > after the first readline, I get the following: > > > 27 ? ? ? ? ? > > 91 ? ? ? ? [ > > 48 ? ? ? ? 0 > > 48 ? ? ? ? 0 > > 109 ? ? ? ?m > > 27 ? ? ? ? ? > > 91 ? ? ? ? [ > > 51 ? ? ? ? 3 > > 55 ? ? ? ? 7 > > 109 ? ? ? ?m > > > before the codes begin for the string as it appears if I just print > > it. ?So, what is this sequence? ?They seem like some sort of escape > > codes, I've never seen this before at all. > > [00m is the ANSI code to reset attributes to their default state. > [37m is the ANSI code to set the foreground color to white. > > > Can anyone enlighten me as to what is going on? > > > And, can I safely strip sets of 5 characters from the front as long as > > they start with Escape (27)? > > No, escape sequences can be of arbitrary length. > It turned out that make was aliased to colourmake, and the escape codes were being put in there for beautifying the console output. Sorry to bother everyone. From thudfoo at opensuse.us Mon Jul 5 18:15:34 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 5 Jul 2010 15:15:34 -0700 Subject: using the netflix api Message-ID: Has anyone had success using the netflix api with Netflix.py? Especially getting access? From nagle at animats.com Mon Jul 5 18:19:53 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 15:19:53 -0700 Subject: Getting pyparsing to backtrack Message-ID: <4c325a88$0$1672$742ec2ed@news.sonic.net> I'm working on street address parsing again, and I'm trying to deal with some of the harder cases. Here's a subparser, intended to take in things like "N MAIN" and "SOUTH", and break out the "directional" from street name. Directionals = ['southeast', 'northeast', 'north', 'northwest', 'west', 'east', 'south', 'southwest', 'SE', 'NE', 'N', 'NW', 'W', 'E', 'S', 'SW'] direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameParser = Optional(direction.setResultsName("predirectional")) + Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") This parses something like "N WEBB" fine; "N" is the "predirectional", and "WEBB" is the street name. "SOUTH" (which, when not followed by another word, is a streetname, not a predirectional), raises a parsing exception: Street address line parse failed for SOUTH : Expected W:(abcd...) (at char 5), (line:1, col:6) The problem is that "direction" matched SOUTH, and even though "direction" is within an "Optional" and followed by another word, the parser didn't back up when it hit the end of the expression without satisfying the OneOrMore clause. Pyparsing does some backup, but I'm not clear on how much, or how to force it to happen. There's some discussion at "http://www.mail-archive.com/python-list at python.org/msg169559.html". Apparently the "Or" operator will force some backup, but it's not clear how much lookahead and backtracking is supported. John Nagle From nagle at animats.com Mon Jul 5 18:28:47 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 15:28:47 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <11e61$4c323409$4275d90a$16304@FUSE.NET> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <11e61$4c323409$4275d90a$16304@FUSE.NET> Message-ID: <4c325c9e$0$1605$742ec2ed@news.sonic.net> On 7/5/2010 12:35 PM, Kevin Walzer wrote: > On 7/5/10 2:56 AM, John Nagle wrote: > >> * PyCrypto >> * PyOpenSSL > > These, and Mark Pilgrim's feedparser, need to be 3.x compatible before I > can think about Python 3.x. There's been an attempt to port "feedparser" to 3.0, but that needed a port of BeautifulSoup: http://code.google.com/p/feedparser/issues/detail?id=215 They also had some problems with "chardet". John Nagle From philip at semanchuk.com Mon Jul 5 18:38:20 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 5 Jul 2010 18:38:20 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20100705163043.f4c8d085.darcy@druid.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. > I can see on the site the 2.x documents and the 3.x documents for > extending with C modules and I can read both from end to end but that > hits the time issue above. If there was a relatively simple document > that showed what needed to be changed in the C code we could get > started on the transition sooner. > > Or is there no change at the C level? That would make things easy. There are definitely changes at the C level. I ported two pure C extensions from 2 to 3 and was even able to keep a single C codebase. I'd be willing to contribute my experiences to a document somewhere. (Is there a Wiki?) I would have found such a document very helpful before I started porting. Cheers Philip From clp2 at rebertia.com Mon Jul 5 18:41:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 15:41:31 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> Message-ID: On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk wrote: > On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: >> On Mon, 05 Jul 2010 14:42:13 -0400 >> Terry Reedy wrote: >>> Good start. Now what is blocking those four? >>> Lack of developer interest/time/ability? >>> or something else that they need? >> >> How about a basic how-to document? ?I maintain PyGreSQL and would like >> to move it to 3.x right now but I don't even know what the issues are. >> I can see on the site the 2.x documents and the 3.x documents for >> extending with C modules and I can read both from end to end but that >> hits the time issue above. ?If there was a relatively simple document >> that showed what needed to be changed in the C code we could get >> started on the transition sooner. >> >> Or is there no change at the C level? ?That would make things easy. > > There are definitely changes at the C level. > > I ported two pure C extensions from 2 to 3 and was even able to keep a > single C codebase. I'd be willing to contribute my experiences to a document > somewhere. (Is there a Wiki?) Indeed there is: http://wiki.python.org/moin/ Cheers, Chris From googler.1.webmaster at spamgourmet.com Mon Jul 5 19:49:49 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 5 Jul 2010 16:49:49 -0700 (PDT) Subject: Python Embedding Importing relative modules Message-ID: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Hi all, I have a serious problem I haven't solved yet, hope one of you can help me. The first thing is, I embedded Python into my app and I execute several scripts in this environment. The problem is, the scripts don't import modules from their relative path. I guess this is related to the sys.path ['',...] and the current working directory which is set to the directory of my host application. I could set that path manually, but all the scripts might be stored in different locations. So now I try to find a way to handle that. Any suggestions? A solution would be, that each script, appends its own directory to the system path, but this might lead to problems. Imagine all of them have a module called 'foo.py' and its not the same. This might lead to name conflicts, wouldnt it? Btw, I found a source code line in the documentation, where I should really get rid of the ['', ...] path in the system path due to security reasons. import sys; sys.path.pop(0) Hope one of you can help me out here. Really thanks!! Bye, moerchendiser2k3 From greg.ewing at canterbury.ac.nz Mon Jul 5 19:59:54 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 06 Jul 2010 11:59:54 +1200 Subject: What is the name of the name space I am in? In-Reply-To: References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> Message-ID: <89f9edFuavU1@mid.individual.net> >> On 07/05/2010 11:07 AM, Anthra Norell wrote: >> >>> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >>> what the "dict" of the current name space is. Are you sure that's what you really want to know? The 'dict' argument to classobj() defines the attributes that you want the new class to have. It's not meant to be the namespace in which the code creating the class is executing. -- Greg From andrew at acooke.org Mon Jul 5 20:10:46 2010 From: andrew at acooke.org (andrew cooke) Date: Mon, 5 Jul 2010 17:10:46 -0700 (PDT) Subject: Another Regexp Question Message-ID: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> As ever, I guess it's most likely I've misunderstood something, but in Python 2.6 lookback seems to actually be lookahead. All the following tests pass: from re import compile assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc') assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc') assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc') assert compile('(a)b(?=(?(2)x|c))(c)').match('abc') assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc') assert compile('(a)b(?=(?(1)c|x))(c)').match('abc') But it seems to me that the first block should fail, because they check the match *before* the point in question. Note that without group references these work as I would expected: assert compile('(a)b(?<=b)(c)').match('abc') assert not compile('(a)b(?<=c)(c)').match('abc') assert not compile('(a)b(?=b)(c)').match('abc') assert compile('(a)b(?=c)(c)').match('abc') in which lookback does indeed lookback (note the asymmetry, while the first examples were symmetrical). What am I missing this time? :o( Thanks, Andrew From steve at REMOVE-THIS-cybersource.com.au Mon Jul 5 20:15:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 00:15:19 GMT Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <4c327596$0$28647$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > I'd like to view the contents of the help file without actually > installing the release which would wipe out any currently installed > version (I'm one of those rare people who actually reads manuals > *before* using or installing most things.) When you say "wipe out any currently installed version", do you mean an older version of 2.7, or an older version such as 2.6, 2.5, 2.4, ... ? If the first, I don't know of any simple way to keep multiple installations with the same major and minor version number (e.g. 2.7.0a and 2.7.0.b). Sorry. But if you mean the second, that you don't want to over-write 2.6, I'd be shocked if the Python installer does that. Doesn't it install Python to something like C:\Programs\Python ? Performing a source install under Linux, by default existing versions remain in place, but there's a soft link "python" which points to the most recent version. Doing a regular install over-writes the soft link. But there's an "altinstall" option which leaves the link untouched, so (for example) I have python -> python 2.5 while still having other versions installed and accessible directly with python2.6, python2.4 etc. I would be stunned if Windows didn't support an equivalent to altinstall. Are there any Windows users out there who can confirm that the installer does or doesn't leave existing versions in place? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jul 5 20:22:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 00:22:06 GMT Subject: Python 3 put-downs: What's the point? References: <20100705095032.6f7749fe@brasov> Message-ID: <4c32772e$0$28647$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 14:32:13 -0500, Tim Chase wrote: > On 07/05/2010 02:50 AM, Gregor Horvath wrote: >> Am Sun, 04 Jul 2010 18:51:54 -0500 >> schrieb Tim Chase: >> >>> I think it's the same venting of frustration that caused veteran VB6 >>> developers to start calling VB.Net "Visual Fred" -- the language was >>> too different and too non-backwards-compatible. >>> >>> >> VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. >> >> VB6 and VB.NET are totally different languages and technologies, with >> some similarity in syntax. This is not true for Python 2->3. This is an >> healthy organic language growth, not an abandon of a language. > > The quintessential example is Py3's breaking of Hello World. It's a > spectrum of language changes -- Visual Fred just happens to be MUCH > further down the same spectrum having more dramatic changes. Only a > subset of $OLD_VER (whether Py2 or VB6) code will run unmodified under > $NEW_VER (whether Py3 or VB.Net). The same holds for older versions of Python to Python 2.5 or 2.6, it's just that you have to work harder to find the incompatibilities. Try running this under later versions: [steve at sylar ~]$ python2.0 Python 2.0.1 (#1, Jan 14 2010, 15:43:17) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "copyright", "credits" or "license" for more information. >>> None = "Hello world" >>> print None Hello world > It just happens that the subset for > Python is considerably larger than the subset for VB (and Python's > conversion tools seem a little more useful than VB's, IMHO). IIRC, > neither raw VB6 nor Py2 byte-code will run raw in the new environment > (old VB .exe files don't make use of .Net libraries/CLR, nor do Py2 .pyc > files run under Py3) Python byte-code has never been compatible across minor version numbers, let alone major ones. -- Steven From tim at johnsons-web.com Mon Jul 5 20:44:17 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 05 Jul 2010 16:44:17 -0800 Subject: Shared object access problems References: <4c31424c$0$1613$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > On 7/4/2010 6:36 PM, Philip Semanchuk wrote: >> hi Tim, >> This seems more likely to be a MySQLdb problem than a Python one. Have >> you considered asking in the MySQLdb forums? >> >> On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: >> >>> Using python 2.6.4 on slackware 13.1 >>> I have MySQLdb 'by hand', that is: by >>> 1)downloading MySQL-python-1.2.3c1.tar.gz >>> 2)unzipping tarfile >>> 3)running python setup.py build >>> 4)running python setup.py install >>> >>> The build and install seemed to proceded without error, >>> but upon invoking the interpreter and running >>>>>> import MySQLdb >>> I get the following ImportError: >>> ############################################################## >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >>> line 19, in >>> File "build/bdist.linux-i686/egg/_mysql.py", >>> line 7, in >>> File "build/bdist.linux-i686/egg/_mysql.py", >>> line 6, in __bootstrap__ >>> ImportError: libmysqlclient_r.so.15: >>> cannot open shared object file: No such file or directory > > Did you install the development libraries for MySQL first? > Those are needed to build MySQLdb yourself. > > John Nagle By that I think you mean libmysqlclient_r.so* and so forth, if so, yes. The question has become moot, as I recently did an upgrade from slack 13.0 to 13.1, and I've decided to procede with a clean install. So I'm dropping this inquiry and I'll keep my development on ubuntu for the time being. thanks for the help From drobinow at gmail.com Mon Jul 5 20:53:48 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 5 Jul 2010 20:53:48 -0400 Subject: Python 2.7 released In-Reply-To: <4c327596$0$28647$c3e8da3@news.astraweb.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 5, 2010 at 8:15 PM, Steven D'Aprano wrote: > On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > >> I'd like to view the contents of the help file without actually >> installing the release which would wipe out any currently installed >> version (I'm one of those rare people who actually reads manuals >> *before* using or installing most things.) ... > Are there any Windows users out there who can confirm that the installer > does or doesn't leave existing versions in place? The installer does leave existing versions in place. I have no idea what the OP is referring to. From python at mrabarnett.plus.com Mon Jul 5 20:56:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jul 2010 01:56:40 +0100 Subject: Another Regexp Question In-Reply-To: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> Message-ID: <4C327F48.2040100@mrabarnett.plus.com> andrew cooke wrote: > As ever, I guess it's most likely I've misunderstood something, but in > Python 2.6 lookback seems to actually be lookahead. All the following > tests pass: > > from re import compile > > assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc') > assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc') > assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc') > > assert compile('(a)b(?=(?(2)x|c))(c)').match('abc') > assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc') > assert compile('(a)b(?=(?(1)c|x))(c)').match('abc') > > But it seems to me that the first block should fail, because they > check the match *before* the point in question. > Both the first and third should fail, but they pass. > Note that without group references these work as I would expected: > > assert compile('(a)b(?<=b)(c)').match('abc') > assert not compile('(a)b(?<=c)(c)').match('abc') > > assert not compile('(a)b(?=b)(c)').match('abc') > assert compile('(a)b(?=c)(c)').match('abc') > > in which lookback does indeed lookback (note the asymmetry, while the > first examples were symmetrical). > > What am I missing this time? :o( > Nothing. It's a bug. :-( From philip at semanchuk.com Mon Jul 5 21:00:17 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 5 Jul 2010 21:00:17 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> Message-ID: <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk > wrote: >> On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: >>> On Mon, 05 Jul 2010 14:42:13 -0400 >>> Terry Reedy wrote: >>>> Good start. Now what is blocking those four? >>>> Lack of developer interest/time/ability? >>>> or something else that they need? >>> >>> How about a basic how-to document? I maintain PyGreSQL and would >>> like >>> to move it to 3.x right now but I don't even know what the issues >>> are. >>> I can see on the site the 2.x documents and the 3.x documents for >>> extending with C modules and I can read both from end to end but >>> that >>> hits the time issue above. If there was a relatively simple >>> document >>> that showed what needed to be changed in the C code we could get >>> started on the transition sooner. >>> >>> Or is there no change at the C level? That would make things easy. >> >> There are definitely changes at the C level. >> >> I ported two pure C extensions from 2 to 3 and was even able to >> keep a >> single C codebase. I'd be willing to contribute my experiences to a >> document >> somewhere. (Is there a Wiki?) > > Indeed there is: http://wiki.python.org/moin/ Thanks. I don't want to appear ungrateful, but I was hoping for something specific to the 2-to-3 conversion. I guess someone has to start somewhere... From andrew at acooke.org Mon Jul 5 21:25:36 2010 From: andrew at acooke.org (andrew cooke) Date: Mon, 5 Jul 2010 18:25:36 -0700 (PDT) Subject: Another Regexp Question References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> Message-ID: <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> On Jul 5, 8:56?pm, MRAB wrote: > andrew cooke wrote: > > What am I missing this time? :o( > Nothing. It's a bug. :-( Sweet :o) Thanks - do you want me to raise an issue or will you? Cheers, Andrew From python at mrabarnett.plus.com Mon Jul 5 21:38:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jul 2010 02:38:36 +0100 Subject: Another Regexp Question In-Reply-To: <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> Message-ID: <4C32891C.20901@mrabarnett.plus.com> andrew cooke wrote: > On Jul 5, 8:56 pm, MRAB wrote: >> andrew cooke wrote: >>> What am I missing this time? :o( >> Nothing. It's a bug. :-( > > Sweet :o) > > Thanks - do you want me to raise an issue or will you? > You found it. You can have the pleasure. From clp2 at rebertia.com Mon Jul 5 22:46:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 19:46:42 -0700 Subject: markmin 0.1 In-Reply-To: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> References: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> Message-ID: On Mon, Jul 5, 2010 at 4:56 PM, Massimo Di Pierro wrote: > Markmin is a wiki markup language > implemented in less than 100 lines of code (one file, no dependencies) > easy to read > secure > support table, ul, ol, code > support html5 video and audio elements > can align images and resize them > CSS friendly (can specify class for tables and code elements) > can add anchors anywhere > does not use _ for markup (since it creates odd behavior) > automatically links urls > fast > with tests Okay, but where can it be downloaded from? You didn't include a link. Cheers, Chris From ggrp2.20.martineau at dfgh.net Mon Jul 5 22:52:06 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 19:52:06 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <70e08284-c2c3-4e8e-8e44-d0c0285680c8@h40g2000pro.googlegroups.com> On Jul 5, 1:31?pm, Alexander Kapps wrote: > Martineau wrote: > > Perhaps it's hidden somewhere, but I couldn't find the .chm help file > > in the python-2.7.msi file using 7-zip, nor saw anything that looked > > like a Doc folder embedded within it -- so I doubt installing it on a > > Windows machine would work any better. > > I don't know much about the .msi format or how 7-Zip handles it, but > on my XP box, 7-Zip lists a "python" sub-archive (a 7-Zip > "compound"). Within is the python27.chm My mistake -- you're quite right the .chm *is* in the .msi where you indicated. FWIW I actually did look in that sub-section before posting yet somehow missed it. Sorry about that and thanks to all involved for your help. From ggrp2.20.martineau at dfgh.net Mon Jul 5 23:14:49 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 20:14:49 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> Message-ID: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> On Jul 5, 5:53?pm, David Robinow wrote: > On Mon, Jul 5, 2010 at 8:15 PM, Steven D'Aprano wrote: > > On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > > >> I'd like to view the contents of the help file without actually > >> installing the release which would wipe out any currently installed > >> version (I'm one of those rare people who actually reads manuals > >> *before* using or installing most things.) > ... > > Are there any Windows users out there who can confirm that the installer > > does or doesn't leave existing versions in place? > > ?The installer does leave existing versions in place. I have no idea > what the OP is referring to. Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so would have interfered with the currently installed version because I always install Python in the same directory, one named just "Python", to minimize the number of changes I have to make to to other parts of the system. Some trivial examples are desktop shortcuts I've set up which point to the commandline version of the interpreter and another for the help file. I also believe the Windows installer makes registry changes that also involve paths to the currently installed version, which again, is something I wanted to avoid until I'm actually ready to commit to upgrading. If there are better ways on Windows to accomplish this, I'd like to hear about them. I suppose I could use hardlinks or junctions but they're not well supported on most versions of Windows. BTW, my original problem -- getting a copy of the Windows format compiled help file fro v2/7 without installing it has been taken care by suggestions from other, so this discussion is starting to way off- topic... Thanks, Martin From martin at v.loewis.de Mon Jul 5 23:28:00 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 06 Jul 2010 05:28:00 +0200 Subject: Python 2.7 released In-Reply-To: References: Message-ID: <4C32A2C0.1060703@v.loewis.de> > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? I have now put that file separately on the release page. Regards, Martin From kedra.marbun at gmail.com Tue Jul 6 00:10:51 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:10:51 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> Message-ID: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> On Jul 5, 3:42?pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > i'm confused which part that doesn't make sense? > > this is my 2nd attempt to py, the 1st was on april this year, it was > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > i'm gonna lay out how i got to this conclusion, CMIIW > > > **explanation of feeling (0) on my 1st post** > > to me, descriptor is a particular kind of delegation, it takes the job > > of coding the delegation by having a contract with programmers that > > the tree meta operations (get, set, del) on attr are delegated to the > > obj that is bound to the attr > > are we agree that descriptor is a kind of delegation? > > > the mechanism that makes descriptor works is in __getattribute__, > > __setattr__, __delattr__ of 'object' & 'type' > > > now, if i want a single descriptor obj to be delegated to multiple > > tasks, i can't do it since __get__ doesn't get info that can be used > > to determine which task to do > > i must have diff descriptor obj for each task > > > class Helper: > > ? ?def __init__(self, name): > > ? ? ? ? ? ?self.name = name > > ? ?def __get__(self, ins, cls): > > ? ? ? ? ? ?if self.name == 'task0': ... > > ? ? ? ? ? ?elif self.name == 'task1': ... > > ? ? ? ? ? ?else: ... > > Replacing such "big switch" code with polymorphic dispatch is one of the > ? goals (and feature) of OO. This should be: > > class Task0(object): > ? ? ?def __get__(self, obj, cls): > ? ? ? ? ?# code here > > class Task1(object): > ? ? ?def __get__(self, obj, cls): > ? ? ? ? ?# code here > > class A(object): > ? ? ?task0 = Task0() > ? ? ?task1 = Task1() > > If you have common code to share between TaskO and Task1 then factor it > out into a base class. > > > if __get__ receives the name, then i could do > > > class Helper: > > ? ?def __get__(self, ins, cls, name): > > ? ? ? ? ? ?... > > > class a: > > ? ?task0 = task1 = Helper() > > Yuck. what's so 'Yuck' about it? ;) i guess i need a strong stmt: is descriptor a kind of delegation? or is it not? * if it is a kind of delegation, then the code that you labeled as 'Yuck' is just a result of applying delegation what's wrong with delegating multiple tasks to a single obj? that code is similar to this class Helper: def do_this(self, ins): ... def do_that(self, ins): ... class a: delegate = Helper() def task0(self): self.delegate.do_that(self) def task1(self): self.delegate.do_this(self) the diff is that this code manually code the delegation, that's why it can branches to 2 funcs. while descriptor takes all to __get__, because it works on more meta lv * if it's not, then there's nothing to be argued, the name 'descriptor' is perfectly fit: descriptor obj describes attr of class, with 'describe' translates to: . = del, in py vocabularies. then, to think a single descriptor obj describing a single attr is acceptable, it's a common sense From kedra.marbun at gmail.com Tue Jul 6 00:12:47 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:12:47 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: On Jul 5, 7:49?am, Gregory Ewing wrote: > kedra marbun wrote: > > now, i'm asking another favor, what about the 2nd point in my 1st post? > > Your original post has dropped off my newsscope, so > you'll have to remind me what the 2nd point was. > > -- > Greg it's like 'name', it's about info that i think should be passed to descriptor's __{get|set|delete}__. i wonder what are the reasons for not passing the class on which the descriptor is attached to, what pattern is encouraged by this? From kedra.marbun at gmail.com Tue Jul 6 00:15:33 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:15:33 -0700 (PDT) Subject: Getting the name of the file that imported current module References: <4c311941$0$28647$c3e8da3@news.astraweb.com> Message-ID: <52be73ef-363f-47cc-bff7-63f1027f280d@y12g2000prb.googlegroups.com> On Jul 5, 6:29?am, Steven D'Aprano wrote: > On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > > foo.py: > > > import bar > > bar.show_importer() > > > output: > > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > > Possible? > > I don't think so. Your question isn't even well-defined. Given three > modules: > > # a.py > import b > import d > > # b.py > import d > > # c.py > import a > import d > import b > print d.show_importer() > > and you run c.py, what do you expect d.show_importer() to return? > > And what about "from d import show_importer" -- does that count as > "importing d"? > > Why do you think that a module needs to know what other modules imported > it? I can't imagine why this would be necessary, what are you intending > to do with it? > > -- > Steven i guess he just likes to play things around, entertains his imagination, no need for practical reason for that From kedra.marbun at gmail.com Tue Jul 6 00:25:26 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:25:26 -0700 (PDT) Subject: Getting the name of the file that imported current module References: Message-ID: <0abdf4a8-a2bb-4800-a166-866964335eb9@q21g2000prm.googlegroups.com> On Jul 5, 4:05?am, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah if what you mean by 'importer' is the one that really cause py to load the mod, then why not dynamically set it? foo.py ------ import bar, sys if '_importer' not in bar.__dict__: bar._importer = sys.modules[__name__] bar.py ------ def show_importer(): return _importer or you could borrow space from builtins. i don't know if it breaks any rule ;) foo.py ------ def set_importer(mod): bdict = (__builtins__.__dict__ if __name__ == '__main__' else __builtins__) if '_importer' not in bdict: bdict['_importer'] = {mod : sys.modules[__name__]} else: if mod not in bdict: bdict['_importer'][mod] = sys.modules[__name__] import bar set_importer(bar) From nagle at animats.com Tue Jul 6 00:45:07 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 21:45:07 -0700 Subject: Getting pyparsing to backtrack In-Reply-To: <4c325a88$0$1672$742ec2ed@news.sonic.net> References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: <4c32b4d2$0$1677$742ec2ed@news.sonic.net> On 7/5/2010 3:19 PM, John Nagle wrote: > I'm working on street address parsing again, and I'm trying to deal > with some of the harder cases. The approach below works for the cases given. The "Or" operator ("^") supports backtracking, but "Optional()" apparently does not. direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameOnly = Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") streetNameParser = ((direction.setResultsName("predirectional") + streetNameOnly) ^ streetNameOnly) John Nagle From steve-REMOVE-THIS at cybersource.com.au Tue Jul 6 01:11:09 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 05:11:09 GMT Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: <4c32baec$0$28649$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > On Jul 5, 7:49?am, Gregory Ewing wrote: >> kedra marbun wrote: >> > now, i'm asking another favor, what about the 2nd point in my 1st >> > post? >> >> Your original post has dropped off my newsscope, so you'll have to >> remind me what the 2nd point was. >> >> -- >> Greg > > it's like 'name', it's about info that i think should be passed to > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > passing the class on which the descriptor is attached to, what pattern > is encouraged by this? Perhaps I'm missing the context, but since the descriptor is passed the instance, you can easily get the class with type(self) or self.__class__. There's no need to pass the class as a separate argument. -- Steven From tjreedy at udel.edu Tue Jul 6 01:37:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jul 2010 01:37:41 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On 7/5/2010 9:00 PM, Philip Semanchuk wrote: > > On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > >> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk >>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>> single C codebase. I'd be willing to contribute my experiences to a >>> document >>> somewhere. (Is there a Wiki?) >> >> Indeed there is: http://wiki.python.org/moin/ > > Thanks. I don't want to appear ungrateful, but I was hoping for > something specific to the 2-to-3 conversion. I guess someone has to > start somewhere... There is an existing 2to3 and other pages for Python code conversion. I do not know of any for CAPI conversion. The need for such has been acknowledged among the devs but if there is nothing yet, we need someone with specialized experience and a bit of time to make a first draft. If you start one, give it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from the 2to3 page In his post on this thread, Martin Loewis volunteered to list what he knows from psycopg2 if someone else will edit. -- Terry Jan Reedy From rami.chowdhury at gmail.com Tue Jul 6 01:40:03 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 5 Jul 2010 22:40:03 -0700 Subject: delegation pattern via descriptor In-Reply-To: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> Message-ID: <201007052240.03452.rami.chowdhury@gmail.com> On Monday 05 July 2010 21:10:51 kedra marbun wrote: > On Jul 5, 3:42 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > kedra marbun a ?crit : > > > i'm confused which part that doesn't make sense? > > > this is my 2nd attempt to py, the 1st was on april this year, it was > > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > > i'm gonna lay out how i got to this conclusion, CMIIW > > > > > > **explanation of feeling (0) on my 1st post** > > > to me, descriptor is a particular kind of delegation, it takes the job > > > of coding the delegation by having a contract with programmers that > > > the tree meta operations (get, set, del) on attr are delegated to the > > > obj that is bound to the attr > > > are we agree that descriptor is a kind of delegation? > > > > > > the mechanism that makes descriptor works is in __getattribute__, > > > __setattr__, __delattr__ of 'object' & 'type' > > > > > > now, if i want a single descriptor obj to be delegated to multiple > > > tasks, i can't do it since __get__ doesn't get info that can be used > > > to determine which task to do > > > i must have diff descriptor obj for each task > > > > > > class Helper: > > > def __init__(self, name): > > > self.name = name > > > def __get__(self, ins, cls): > > > if self.name == 'task0': ... > > > elif self.name == 'task1': ... > > > else: ... > > > > Replacing such "big switch" code with polymorphic dispatch is one of the > > goals (and feature) of OO. This should be: > > > > class Task0(object): > > def __get__(self, obj, cls): > > # code here > > > > class Task1(object): > > def __get__(self, obj, cls): > > # code here > > > > class A(object): > > task0 = Task0() > > task1 = Task1() > > > > If you have common code to share between TaskO and Task1 then factor it > > out into a base class. > > > > > if __get__ receives the name, then i could do > > > > > > class Helper: > > > def __get__(self, ins, cls, name): > > > ... > > > > > > class a: > > > task0 = task1 = Helper() > > > > Yuck. > > what's so 'Yuck' about it? ;) > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? Thanks for posting the code sample -- it makes your meaning a great deal clearer. No, descriptors are not delegation as in your sample**, although they are very flexible and could be used to implement that if you wanted. > * if it's not, then there's nothing to be argued, the name > 'descriptor' is perfectly fit: descriptor obj describes attr of class, > with 'describe' translates to: . = del, in py vocabularies. then, to > think a single descriptor obj describing a single attr is acceptable, > it's a common sense ** As I understand it, anyway -- someone please correct me if I'm wrong. ---- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity." -- Hanlon's Razor +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From db3l.net at gmail.com Tue Jul 6 02:06:21 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 06 Jul 2010 02:06:21 -0400 Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: Martineau writes: > Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so > would have interfered with the currently installed version because I > always install Python in the same directory, one named just "Python", > to minimize the number of changes I have to make to to other parts of > the system. That's fine, you're just making a conscious choice to only support (yourself) a single version installed at a time. I tend to need multiple versions around when developing, so I keep a bunch of versions all installed in separate directories as \Python\x.y (so I only have a single root directory). With 2.7, my current box has 6 Python interpreters (2.4-3.1) installed at the moment. I use Cygwin (wouldn't try to work on a Windows system without it), so just use bash aliases to execute the right interpreter, but a batch file could be used with the cmd interpreter, and you could link GUI shortcuts to that batch file. Not sure there's a good solution to your help file link, other than the existing Start menu links installed per Python version. Even with local links you'd probably want separate links per version anyway since they're different documents. Of course, since this started by just considering installing it to get at a single file (which I know was since solved), it's probably an acceptable use case for violating your standard policy and picking a different directory name just in this case, and then blowing it away later. :-) > I also believe the Windows installer makes registry > changes that also involve paths to the currently installed version, > which again, is something I wanted to avoid until I'm actually ready > to commit to upgrading. The path information installed in the registry (Software\Python\PythonCore under HLKM or HKCU depending on installation options) is structured according to major.minor release (e.g., 2.6 vs. 2.7 are distinct), but you're right Windows only supports one file extension mapping, so by default the last Python to be installed gets associated with .py/.pyw etc... by default. But you can optionally disable this during installation. On the customize screen showing during installation. de-select the "Register Extensions" option, and the active install won't change any existing mappings and thus have no impact on your current default installation. > If there are better ways on Windows to accomplish this, I'd like to > hear about them. I suppose I could use hardlinks or junctions but > they're not well supported on most versions of Windows. If you're still using the basic Windows command prompt or GUI links then a batch file is the simplest way to go. With something like Cygwin (which I personally would never do without), then you have a variety of techniques available including links, shell aliases, etc... -- David From vinay_sajip at yahoo.co.uk Tue Jul 6 02:22:05 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 5 Jul 2010 23:22:05 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <8d33b35b-26bf-4288-8133-669d318ecafa@a30g2000yqn.googlegroups.com> On Jul 5, 2:35?pm, Antoine Pitrou wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. UTF-8 is only used as a fallback in an exception handler, you can use any supported encoding using the encoding= keyword argument to a FileHandler. > > I suggest you report an issue onhttp://bugs.python.org Yes, please do that and I will investigate. Regards, Vinay Sajip From kedra.marbun at gmail.com Tue Jul 6 02:26:16 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 23:26:16 -0700 (PDT) Subject: Why Python forbids multiple instances of one module? References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: module obj is instance of types.ModuleType, which is instance of 'type', where class obj is instance of 'type'. even only at this point, they're diff in to many ways. there are so many things to do when you truly want module to replace class, as pointed by 2 posts above i'm also a beginner, so i can offer you a tip in learning it: follow the design, py usually has good reasons about it, i've lost in every challenge i put against py design, luckily i find the reasons through my own experiment. yes, it's better to find it through hacking, rather than people talking about it, the reason is the same as coding to learn programming, not only reading book. it will become more understandable when people say py has clean design as for 'self', yes i admit it seems troublesome at first, you'll have reason for it once you know that method is simply a func, you'll embrace the more general design (py requires you to specify a name for the caller) when you learn about metaclass. a nice argument to this is that human beings are visual creatures, it becomes so much easier to have a name that desribes the obj it points to (like 'self', 'cls', 'metacls') than implicit name that trying to be as general as possible (like 'this') From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 6 04:05:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 06 Jul 2010 10:05:47 +0200 Subject: delegation pattern via descriptor In-Reply-To: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> Message-ID: <4c32e3d6$0$661$426a34cc@news.free.fr> kedra marbun a ?crit : > On Jul 5, 3:42 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> kedra marbun a ?crit : >> >> >> >>> i'm confused which part that doesn't make sense? >>> this is my 2nd attempt to py, the 1st was on april this year, it was >>> just a month, i'm afraid i haven't got the fundamentals right yet. so >>> i'm gonna lay out how i got to this conclusion, CMIIW >>> **explanation of feeling (0) on my 1st post** >>> to me, descriptor is a particular kind of delegation, it takes the job >>> of coding the delegation by having a contract with programmers that >>> the tree meta operations (get, set, del) on attr are delegated to the >>> obj that is bound to the attr >>> are we agree that descriptor is a kind of delegation? >>> the mechanism that makes descriptor works is in __getattribute__, >>> __setattr__, __delattr__ of 'object' & 'type' >>> now, if i want a single descriptor obj to be delegated to multiple >>> tasks, i can't do it since __get__ doesn't get info that can be used >>> to determine which task to do >>> i must have diff descriptor obj for each task >>> class Helper: >>> def __init__(self, name): >>> self.name = name >>> def __get__(self, ins, cls): >>> if self.name == 'task0': ... >>> elif self.name == 'task1': ... >>> else: ... >> Replacing such "big switch" code with polymorphic dispatch is one of the >> goals (and feature) of OO. This should be: >> >> class Task0(object): >> def __get__(self, obj, cls): >> # code here >> >> class Task1(object): >> def __get__(self, obj, cls): >> # code here >> >> class A(object): >> task0 = Task0() >> task1 = Task1() >> >> If you have common code to share between TaskO and Task1 then factor it >> out into a base class. >> >>> if __get__ receives the name, then i could do >>> class Helper: >>> def __get__(self, ins, cls, name): >>> ... >>> class a: >>> task0 = task1 = Helper() >> Yuck. > > what's so 'Yuck' about it? ;) It's an implicit, obfuscated and overcomplicated way to do a very simple thing. To be true, I just don't see the point of this pattern - Python has better solutions for delegation (cf the __getattr__ method), and that's not what descriptors are for. > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? The descriptor protocol is the primary support for computed attributes. As such it can be used as a support for delegation, but it's not "a kind of delegation" by itself. > * if it is a kind of delegation, then the code that you labeled as > 'Yuck' is just a result of applying delegation > what's wrong with delegating multiple tasks to a single obj? Nothing wrong with delegating multiple tasks to a single object - but not that way. If you want to use descriptors to specify which tasks should be delegated, you'd be better doing it more explicitely - that is, only use the descriptor as a gateway, and use one descriptor per task. Else just use __getattr__ !-) Sorry, I don't have much time to elaborate on this now. > that code is similar to this > > class Helper: > def do_this(self, ins): ... > def do_that(self, ins): ... > > class a: > delegate = Helper() > def task0(self): self.delegate.do_that(self) > def task1(self): self.delegate.do_this(self) > It's not similar. This second example is explicit, and doesn't couple Helper to a. My 2 cents. From mail at timgolden.me.uk Tue Jul 6 04:07:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 06 Jul 2010 09:07:48 +0100 Subject: Python 2.7 released In-Reply-To: References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: <4C32E454.4000006@timgolden.me.uk> On 06/07/2010 07:06, David Bolen wrote: > I tend to need multiple versions around when developing, so I keep a > bunch of versions all installed in separate directories as \Python\x.y > (so I only have a single root directory). With 2.7, my current box > has 6 Python interpreters (2.4-3.1) installed at the moment. > > I use Cygwin (wouldn't try to work on a Windows system without it), so > just use bash aliases to execute the right interpreter, but a batch > file could be used with the cmd interpreter, and you could link GUI > shortcuts to that batch file. I, too, have multiple versions installed -- newer ones for running code I haven't upgraded; older ones for compatibility testing where needed. I just install to the default c:\pythonxy directories (although I like the idea of a common root) and I put NTFS hardlinks into my general c:\tools directory which is on the path. The out-of-context hardlinks work because of the registry settings which pick up the correct context for each version. (I've never quite clicked with cygwin or MingW despite giving them several goes on the basis of others' enthusiasm...) TJG From cournape at gmail.com Tue Jul 6 04:30:34 2010 From: cournape at gmail.com (David Cournapeau) Date: Tue, 6 Jul 2010 16:30:34 +0800 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20100705163043.f4c8d085.darcy@druid.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? ?I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. One thing that would be very useful is how to maintain something that works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up versions below 2.6 is out of the question for most projects with a significant userbase IMHO. As such, the idea of running the python 3 warnings is not so useful IMHO - unless it could be made to work better for python 2.x < 2.6, but I am not sure the idea even makes sense. > > Or is there no change at the C level? ?That would make things easy. There are quite a few, but outside of the big pain point of strings/byte/unicode which is present at python level as well, a lot of the issues are not so big (and even simpler to deal with). For example, although numpy took time to port (and is still experimental in nature), it took me a couple of hours to get a basic scipy working (numpy uses a lot of C api dark corners, whereas scipy is much more straightforward in its usage of the C API). David From thomas at jollans.com Tue Jul 6 05:02:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 11:02:07 +0200 Subject: Getting pyparsing to backtrack In-Reply-To: References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: <4C32F10F.7020006@jollans.com> On 07/06/2010 04:21 AM, Dennis Lee Bieber wrote: > On Mon, 05 Jul 2010 15:19:53 -0700, John Nagle > declaimed the following in gmane.comp.python.general: > >> I'm working on street address parsing again, and I'm trying to deal >> with some of the harder cases. >> > > Hasn't it been suggested before, that the sanest method to parse > addresses is from the end backwards... > > So that: > > 123 N South St. > > is parsed as > > St. South N 123 You will of course need some trickery for that to work with Hauptstr. 12 From stefan_ml at behnel.de Tue Jul 6 05:02:55 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Jul 2010 11:02:55 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c317c52$0$28665$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c317c52$0$28665$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 05.07.2010 08:31: > On Sun, 04 Jul 2010 17:34:04 -0700, sturlamolden wrote: > >> Using Python 2.x for new >> projects is not advisable (at least many will think so), and using 3.x >> is not possible. What to do? It's not a helpful situation for Python. > > That's pure FUD. > > Python 2.7 will be supported longer than the normal support period for > versions 2.6, 2.5, 2.4, ... so if you have a new project that requires > libraries that aren't available for 3.1, then go right ahead and use 2.7. > By the time 2.7 is no longer supported (probably around the time 3.4 > comes out?), the library situation will be fixed. > > Those 3.1 features that can be backported to 2.x have been, specifically > to reduce the pain in porting 2.7-based applications to 3.x. Feature- > wise, 2.7 is designed to ease the transition from the 2.x series to the > 3.x series. Claiming that it's not advisable to use 2.7 is simply > nonsense. Not to forget about the 2to3 tool. If you write code for 2.6 or 2.7 now, you can actually port it automatically and continuously, and do the final switch when you think it's time. So both choices (2 or 3) are real and available. Stefan From matt.j.warren at gmail.com Tue Jul 6 05:55:25 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 02:55:25 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions Message-ID: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> Hi, I'm using datetime.strptime(string,format) to convert dates parsed from a file into datetime objects. However, the files come from various places around the world, and strptime fails when non-english month names are used. strptime says it converts month names using the current locales version of the name. I've looked into the locale module but can't see how I would setup.change a locales date/time representations, I can only see categories related to decimal number / currency representations. Can anyone show how I could change the locale such that strptime could parse a date string that used say, German month names? Thankyou From certifiedlover at hotmail.com Tue Jul 6 06:03:26 2010 From: certifiedlover at hotmail.com (francisco dorset) Date: Tue, 6 Jul 2010 11:03:26 +0100 Subject: Python-list Digest, Vol 82, Issue 48 In-Reply-To: References: Message-ID: i need resources or books on how to embedding python into c/c++...and also extending it am allergic to cheating, i hate failures, but am in love with achievements <.???`?.F?an???C?`?.???.???`?.?><((((?> From: python-list-request at python.org Subject: Python-list Digest, Vol 82, Issue 48 To: python-list at python.org Date: Tue, 6 Jul 2010 08:25:02 +0200 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..." --Forwarded Message Attachment-- From: martin at v.loewis.de To: python-list at python.org Date: Tue, 6 Jul 2010 05:28:00 +0200 Subject: Re: Python 2.7 released > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? I have now put that file separately on the release page. Regards, Martin --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:10:51 -0700 Subject: Re: delegation pattern via descriptor On Jul 5, 3:42 pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > i'm confused which part that doesn't make sense? > > this is my 2nd attempt to py, the 1st was on april this year, it was > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > i'm gonna lay out how i got to this conclusion, CMIIW > > > **explanation of feeling (0) on my 1st post** > > to me, descriptor is a particular kind of delegation, it takes the job > > of coding the delegation by having a contract with programmers that > > the tree meta operations (get, set, del) on attr are delegated to the > > obj that is bound to the attr > > are we agree that descriptor is a kind of delegation? > > > the mechanism that makes descriptor works is in __getattribute__, > > __setattr__, __delattr__ of 'object' & 'type' > > > now, if i want a single descriptor obj to be delegated to multiple > > tasks, i can't do it since __get__ doesn't get info that can be used > > to determine which task to do > > i must have diff descriptor obj for each task > > > class Helper: > > def __init__(self, name): > > self.name = name > > def __get__(self, ins, cls): > > if self.name == 'task0': ... > > elif self.name == 'task1': ... > > else: ... > > Replacing such "big switch" code with polymorphic dispatch is one of the > goals (and feature) of OO. This should be: > > class Task0(object): > def __get__(self, obj, cls): > # code here > > class Task1(object): > def __get__(self, obj, cls): > # code here > > class A(object): > task0 = Task0() > task1 = Task1() > > If you have common code to share between TaskO and Task1 then factor it > out into a base class. > > > if __get__ receives the name, then i could do > > > class Helper: > > def __get__(self, ins, cls, name): > > ... > > > class a: > > task0 = task1 = Helper() > > Yuck. what's so 'Yuck' about it? ;) i guess i need a strong stmt: is descriptor a kind of delegation? or is it not? * if it is a kind of delegation, then the code that you labeled as 'Yuck' is just a result of applying delegation what's wrong with delegating multiple tasks to a single obj? that code is similar to this class Helper: def do_this(self, ins): ... def do_that(self, ins): ... class a: delegate = Helper() def task0(self): self.delegate.do_that(self) def task1(self): self.delegate.do_this(self) the diff is that this code manually code the delegation, that's why it can branches to 2 funcs. while descriptor takes all to __get__, because it works on more meta lv * if it's not, then there's nothing to be argued, the name 'descriptor' is perfectly fit: descriptor obj describes attr of class, with 'describe' translates to: . = del, in py vocabularies. then, to think a single descriptor obj describing a single attr is acceptable, it's a common sense --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:12:47 -0700 Subject: Re: delegation pattern via descriptor On Jul 5, 7:49 am, Gregory Ewing wrote: > kedra marbun wrote: > > now, i'm asking another favor, what about the 2nd point in my 1st post? > > Your original post has dropped off my newsscope, so > you'll have to remind me what the 2nd point was. > > -- > Greg it's like 'name', it's about info that i think should be passed to descriptor's __{get|set|delete}__. i wonder what are the reasons for not passing the class on which the descriptor is attached to, what pattern is encouraged by this? --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:15:33 -0700 Subject: Re: Getting the name of the file that imported current module On Jul 5, 6:29 am, Steven D'Aprano wrote: > On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > > foo.py: > > > import bar > > bar.show_importer() > > > output: > > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > > Possible? > > I don't think so. Your question isn't even well-defined. Given three > modules: > > # a.py > import b > import d > > # b.py > import d > > # c.py > import a > import d > import b > print d.show_importer() > > and you run c.py, what do you expect d.show_importer() to return? > > And what about "from d import show_importer" -- does that count as > "importing d"? > > Why do you think that a module needs to know what other modules imported > it? I can't imagine why this would be necessary, what are you intending > to do with it? > > -- > Steven i guess he just likes to play things around, entertains his imagination, no need for practical reason for that --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:25:26 -0700 Subject: Re: Getting the name of the file that imported current module On Jul 5, 4:05 am, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah if what you mean by 'importer' is the one that really cause py to load the mod, then why not dynamically set it? foo.py ------ import bar, sys if '_importer' not in bar.__dict__: bar._importer = sys.modules[__name__] bar.py ------ def show_importer(): return _importer or you could borrow space from builtins. i don't know if it breaks any rule ;) foo.py ------ def set_importer(mod): bdict = (__builtins__.__dict__ if __name__ == '__main__' else __builtins__) if '_importer' not in bdict: bdict['_importer'] = {mod : sys.modules[__name__]} else: if mod not in bdict: bdict['_importer'][mod] = sys.modules[__name__] import bar set_importer(bar) --Forwarded Message Attachment-- From: nagle at animats.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:45:07 -0700 Subject: Re: Getting pyparsing to backtrack On 7/5/2010 3:19 PM, John Nagle wrote: > I'm working on street address parsing again, and I'm trying to deal > with some of the harder cases. The approach below works for the cases given. The "Or" operator ("^") supports backtracking, but "Optional()" apparently does not. direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameOnly = Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") streetNameParser = ((direction.setResultsName("predirectional") + streetNameOnly) ^ streetNameOnly) John Nagle --Forwarded Message Attachment-- From: steve-REMOVE-THIS at cybersource.com.au To: python-list at python.org Date: Tue, 6 Jul 2010 05:11:09 +0000 Subject: Re: delegation pattern via descriptor On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > On Jul 5, 7:49 am, Gregory Ewing wrote: >> kedra marbun wrote: >> > now, i'm asking another favor, what about the 2nd point in my 1st >> > post? >> >> Your original post has dropped off my newsscope, so you'll have to >> remind me what the 2nd point was. >> >> -- >> Greg > > it's like 'name', it's about info that i think should be passed to > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > passing the class on which the descriptor is attached to, what pattern > is encouraged by this? Perhaps I'm missing the context, but since the descriptor is passed the instance, you can easily get the class with type(self) or self.__class__. There's no need to pass the class as a separate argument. -- Steven --Forwarded Message Attachment-- From: rami.chowdhury at gmail.com CC: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 22:40:03 -0700 Subject: Re: delegation pattern via descriptor On Monday 05 July 2010 21:10:51 kedra marbun wrote: > On Jul 5, 3:42 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > kedra marbun a ?crit : > > > i'm confused which part that doesn't make sense? > > > this is my 2nd attempt to py, the 1st was on april this year, it was > > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > > i'm gonna lay out how i got to this conclusion, CMIIW > > > > > > **explanation of feeling (0) on my 1st post** > > > to me, descriptor is a particular kind of delegation, it takes the job > > > of coding the delegation by having a contract with programmers that > > > the tree meta operations (get, set, del) on attr are delegated to the > > > obj that is bound to the attr > > > are we agree that descriptor is a kind of delegation? > > > > > > the mechanism that makes descriptor works is in __getattribute__, > > > __setattr__, __delattr__ of 'object' & 'type' > > > > > > now, if i want a single descriptor obj to be delegated to multiple > > > tasks, i can't do it since __get__ doesn't get info that can be used > > > to determine which task to do > > > i must have diff descriptor obj for each task > > > > > > class Helper: > > > def __init__(self, name): > > > self.name = name > > > def __get__(self, ins, cls): > > > if self.name == 'task0': ... > > > elif self.name == 'task1': ... > > > else: ... > > > > Replacing such "big switch" code with polymorphic dispatch is one of the > > goals (and feature) of OO. This should be: > > > > class Task0(object): > > def __get__(self, obj, cls): > > # code here > > > > class Task1(object): > > def __get__(self, obj, cls): > > # code here > > > > class A(object): > > task0 = Task0() > > task1 = Task1() > > > > If you have common code to share between TaskO and Task1 then factor it > > out into a base class. > > > > > if __get__ receives the name, then i could do > > > > > > class Helper: > > > def __get__(self, ins, cls, name): > > > ... > > > > > > class a: > > > task0 = task1 = Helper() > > > > Yuck. > > what's so 'Yuck' about it? ;) > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? Thanks for posting the code sample -- it makes your meaning a great deal clearer. No, descriptors are not delegation as in your sample**, although they are very flexible and could be used to implement that if you wanted. > * if it's not, then there's nothing to be argued, the name > 'descriptor' is perfectly fit: descriptor obj describes attr of class, > with 'describe' translates to: . = del, in py vocabularies. then, to > think a single descriptor obj describing a single attr is acceptable, > it's a common sense ** As I understand it, anyway -- someone please correct me if I'm wrong. ---- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity." -- Hanlon's Razor +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 --Forwarded Message Attachment-- From: tjreedy at udel.edu To: python-list at python.org Date: Tue, 6 Jul 2010 01:37:41 -0400 Subject: Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") On 7/5/2010 9:00 PM, Philip Semanchuk wrote: > > On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > >> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk >>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>> single C codebase. I'd be willing to contribute my experiences to a >>> document >>> somewhere. (Is there a Wiki?) >> >> Indeed there is: http://wiki.python.org/moin/ > > Thanks. I don't want to appear ungrateful, but I was hoping for > something specific to the 2-to-3 conversion. I guess someone has to > start somewhere... There is an existing 2to3 and other pages for Python code conversion. I do not know of any for CAPI conversion. The need for such has been acknowledged among the devs but if there is nothing yet, we need someone with specialized experience and a bit of time to make a first draft. If you start one, give it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from the 2to3 page In his post on this thread, Martin Loewis volunteered to list what he knows from psycopg2 if someone else will edit. -- Terry Jan Reedy --Forwarded Message Attachment-- From: db3l.net at gmail.com To: python-list at python.org Date: Tue, 6 Jul 2010 02:06:21 -0400 Subject: Re: Python 2.7 released Martineau writes: > Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so > would have interfered with the currently installed version because I > always install Python in the same directory, one named just "Python", > to minimize the number of changes I have to make to to other parts of > the system. That's fine, you're just making a conscious choice to only support (yourself) a single version installed at a time. I tend to need multiple versions around when developing, so I keep a bunch of versions all installed in separate directories as \Python\x.y (so I only have a single root directory). With 2.7, my current box has 6 Python interpreters (2.4-3.1) installed at the moment. I use Cygwin (wouldn't try to work on a Windows system without it), so just use bash aliases to execute the right interpreter, but a batch file could be used with the cmd interpreter, and you could link GUI shortcuts to that batch file. Not sure there's a good solution to your help file link, other than the existing Start menu links installed per Python version. Even with local links you'd probably want separate links per version anyway since they're different documents. Of course, since this started by just considering installing it to get at a single file (which I know was since solved), it's probably an acceptable use case for violating your standard policy and picking a different directory name just in this case, and then blowing it away later. :-) > I also believe the Windows installer makes registry > changes that also involve paths to the currently installed version, > which again, is something I wanted to avoid until I'm actually ready > to commit to upgrading. The path information installed in the registry (Software\Python\PythonCore under HLKM or HKCU depending on installation options) is structured according to major.minor release (e.g., 2.6 vs. 2.7 are distinct), but you're right Windows only supports one file extension mapping, so by default the last Python to be installed gets associated with .py/.pyw etc... by default. But you can optionally disable this during installation. On the customize screen showing during installation. de-select the "Register Extensions" option, and the active install won't change any existing mappings and thus have no impact on your current default installation. > If there are better ways on Windows to accomplish this, I'd like to > hear about them. I suppose I could use hardlinks or junctions but > they're not well supported on most versions of Windows. If you're still using the basic Windows command prompt or GUI links then a batch file is the simplest way to go. With something like Cygwin (which I personally would never do without), then you have a variety of techniques available including links, shell aliases, etc... -- David --Forwarded Message Attachment-- From: vinay_sajip at yahoo.co.uk To: python-list at python.org Date: Mon, 5 Jul 2010 23:22:05 -0700 Subject: Re: SMTPHandler and Unicode On Jul 5, 2:35 pm, Antoine Pitrou wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. UTF-8 is only used as a fallback in an exception handler, you can use any supported encoding using the encoding= keyword argument to a FileHandler. > > I suggest you report an issue onhttp://bugs.python.org Yes, please do that and I will investigate. Regards, Vinay Sajip _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.j.warren at gmail.com Tue Jul 6 06:03:34 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 03:03:34 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> Message-ID: <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> On 6 July, 10:55, AlienBaby wrote: > Hi, > > I'm using datetime.strptime(string,format) to convert dates parsed > from a file into datetime objects. > > However, the files come from various places around the world, and > strptime fails when non-english month names are used. > > strptime says it converts month names using the current locales > version of the name. ?I've looked into the locale module but can't see > how I would setup.change a locales date/time representations, I can > only see categories related to decimal number / currency > representations. > > Can anyone show how I could change the locale such that strptime could > parse a date string that used say, German month names? > > Thankyou I just solved this I believe. I didnt spot LC_ALL or LC_TIME previously. From sturlamolden at yahoo.no Tue Jul 6 06:12:08 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 03:12:08 -0700 (PDT) Subject: Python as a scripting language. Alternative to bash script? References: Message-ID: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> On 28 Jun, 19:39, Michael Torrie wrote: > In python I could simply take the output of "ps ax" and use python's > own, superior, cutting routines (using my module): > > (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) > for x in stdout.split('\n'): > ? ? print x.strip().split()[0] Or you just pass the stdout of one command as stdin to another. That is equivalent of piping with bash. From certifiedlover at hotmail.com Tue Jul 6 06:15:45 2010 From: certifiedlover at hotmail.com (francisco dorset) Date: Tue, 6 Jul 2010 11:15:45 +0100 Subject: No subject Message-ID: hey am a programmer i have good knowledge of the c language and i will like to now how i can use to python to provide graphical user-interface for my c programs and or the steps involved in doing this and is it possible???? if yes i will also like some resources or books to learn from..... any info will be useful thankss!!!! _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.j.warren at gmail.com Tue Jul 6 06:21:21 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 03:21:21 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> Message-ID: I'm still having a bit of trouble, for example trying to set the locale to Denmark locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) returns with locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) File "C:\Python26\lib\locale.py", line 494, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting Though, from the docs I understand normalize should return a local formatted for use with setlocale? From gh at gregor-horvath.com Tue Jul 6 06:27:42 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 6 Jul 2010 12:27:42 +0200 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: <20100705095032.6f7749fe@brasov> Message-ID: <20100706122742.6ae5cf3a@brasov> Am Mon, 05 Jul 2010 14:32:13 -0500 schrieb Tim Chase : > On 07/05/2010 02:50 AM, Gregor Horvath wrote: > > Am Sun, 04 Jul 2010 18:51:54 -0500 > > schrieb Tim Chase: > > > >> I think it's the same venting of frustration that caused veteran > >> VB6 developers to start calling VB.Net "Visual Fred" -- the > >> language was too different and too non-backwards-compatible. > >> > > > > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. > > > > VB6 and VB.NET are totally different languages and technologies, > > with some similarity in syntax. This is not true for Python 2->3. > > This is an healthy organic language growth, not an abandon of a > > language. > > The quintessential example is Py3's breaking of Hello World. > It's a spectrum of language changes -- Visual Fred just happens > to be MUCH further down the same spectrum having more dramatic > changes. Only a subset of $OLD_VER (whether Py2 or VB6) code > will run unmodified under $NEW_VER (whether Py3 or VB.Net). It Don't you think that there is a really huge difference in an evolutionary development of a language with some well founded incompatibilities due to some muck outs on one side and and on the other side stopping the development of a language and replacing it with one derived from a completely different one and giving it a related name and syntax? And that such a big difference forbids any comparison, although there are some superficial similarities? -- Greg From andrew at acooke.org Tue Jul 6 06:37:52 2010 From: andrew at acooke.org (andrew cooke) Date: Tue, 6 Jul 2010 03:37:52 -0700 (PDT) Subject: Another Regexp Question References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> Message-ID: http://bugs.python.org/issue9179 On Jul 5, 9:38?pm, MRAB wrote: > andrew cooke wrote: > > On Jul 5, 8:56 pm, MRAB wrote: > >> andrew cooke wrote: > >>> What am I missing this time? :o( > >> Nothing. It's a bug. :-( > > > Sweet :o) > > > Thanks - do you want me to raise an issue or will you? > > You found it. You can have the pleasure. From solipsis at pitrou.net Tue Jul 6 06:38:14 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jul 2010 12:38:14 +0200 Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> Message-ID: <20100706123814.6ac10518@pitrou.net> On Tue, 6 Jul 2010 03:21:21 -0700 (PDT) AlienBaby wrote: > I'm still having a bit of trouble, for example trying to set the > locale to Denmark > > > locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) > > returns with > > locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) > File "C:\Python26\lib\locale.py", line 494, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting > > > Though, from the docs I understand normalize should return a local > formatted for use with setlocale? I think normalize works ok, but setlocale then fails (*). You can only use a locale if it's installed on the computer. That, and other issues (such as the fact that the locale setting is process-wide and can interfere with other parts of your program, or third-party libraries; or the fact that a given locale can have differences depending on the vendor) make the locale mechanism very fragile and annoying. If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ (*): >>> import locale >>> locale.normalize('da_DK') 'da_DK.ISO8859-1' >>> locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/locale.py", line 513, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting From thomas at jollans.com Tue Jul 6 07:31:58 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 13:31:58 +0200 Subject: Python-list Digest, Vol 82, Issue 48 In-Reply-To: References: Message-ID: <4C33142E.8060506@jollans.com> On 07/06/2010 12:03 PM, francisco dorset wrote: > i need resources or books on how to embedding python into c/c++...and > also extending it > > [snip] What is the digest doing at the end of your message then? Anyway: http://docs.python.org/py3k/c-api/index.html http://docs.python.org/py3k/extending/index.html or, if you feel like using the archaic 2.x series of CPython, http://docs.python.org/c-api/index.html http://docs.python.org/extending/index.html Have fun From thomas at jollans.com Tue Jul 6 07:45:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 13:45:15 +0200 Subject: Python GUI for C program [was: ] In-Reply-To: References: Message-ID: <4C33174B.7090902@jollans.com> On 07/06/2010 12:15 PM, francisco dorset wrote: > hey am a programmer i have good knowledge of the c language and i will > like to now how i can use to python to provide graphical user-interface > for my c programs and or the steps involved in doing this and is it > possible???? > > if yes i will also like some resources or books to learn from..... > > any info will be useful thankss!!!! Three ways of doing this: 1. Turn your C program into a library, and write a Python extension module to interface it. 2. Embed Python in your C program. 3. If you're talking command-line programs, you can interface the compiled programs with the subprocess module. For (1) and (2), start with the Extending/Embedding section at http://docs.python.org/py3k/ (or http://docs.python.org/). With (1), using Cython or SWIG might make writing the "glue" between Python and your C code easier. For (3), check the docs of the subprocess module. It might, however, be best to simply write the GUI in C as well, which would avoid the overhead of loading Python and isn't all that difficult either. If you know C++, check out wxWidgets and Qt4. To stick with plain C, have a look at GTK+. Cheers, Thomas From darcy at druid.net Tue Jul 6 08:30:35 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 6 Jul 2010 08:30:35 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <20100706083035.d9ef928b.darcy@druid.net> On Tue, 6 Jul 2010 16:30:34 +0800 David Cournapeau wrote: > One thing that would be very useful is how to maintain something that > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > versions below 2.6 is out of the question for most projects with a Yes, PyGreSQL officially supports 2.3 and up. That means that we can't use "from __future__". We might be able to bump that to 2.4 in the next release but I wouldn't want to jump all the way to 2.6 in one version release. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From icanbob at gmail.com Tue Jul 6 08:56:50 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 6 Jul 2010 05:56:50 -0700 (PDT) Subject: Python GUI for C program [was: ] References: Message-ID: <6a8cbf98-eb2a-4a5d-9588-c3227f8d2728@u26g2000yqu.googlegroups.com> On Jul 6, 7:45 am, Thomas Jollans wrote: > On 07/06/2010 12:15 PM, francisco dorset wrote: > > > hey am a programmer i have good knowledge of the c language and i will > > like to now how i can use to python to provide graphical user-interface > > for my c programs and or the steps involved in doing this and is it > > possible???? > > > if yes i will also like some resources or books to learn from..... > > > any info will be useful thankss!!!! > > Three ways of doing this: > > 1. Turn your C program into a library, and write a Python extension > module to interface it. > > 2. Embed Python in your C program. > > 3. If you're talking command-line programs, you can interface the > compiled programs with the subprocess module. > > For (1) and (2), start with the Extending/Embedding section athttp://docs.python.org/py3k/(orhttp://docs.python.org/). With (1), > using Cython or SWIG might make writing the "glue" between Python and > your C code easier. > > For (3), check the docs of the subprocess module. > > It might, however, be best to simply write the GUI in C as well, which > would avoid the overhead of loading Python and isn't all that difficult > either. If you know C++, check out wxWidgets and Qt4. To stick with > plain C, have a look at GTK+. > > Cheers, > Thomas You might want to also look at the SIMPL toolkit (http:// www.icanprogram.com/06py/lesson1/lesson1.html). You could use Send/ Receive/Reply (QNX style) messaging to add a Python GUI to a C program. There are examples of just this at the link above. bob From Steven.Rumbalski at fiserv.com Tue Jul 6 09:17:02 2010 From: Steven.Rumbalski at fiserv.com (Steven) Date: Tue, 6 Jul 2010 06:17:02 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <4ba793ae-e80e-4de2-afb5-23fdc3a31561@c10g2000yqi.googlegroups.com> On Jul 5, 2:56?am, John Nagle wrote: > ? ? The Twisted team has a list of what they need: > > "http://stackoverflow.com/questions/172306/how-are-you-planning-on-han..." Here's what I got from a quick google review of the below four projects and python 3. > ? ? ?* Zope Interface Here's a blog from a core contributer to Zope, Lennart Regebro claiming Zope Interface now works with Python 3: http://regebro.wordpress.com/2010/04/29/zope-interface-3-6-0-released-with-python-3-support/ I have no idea if this is official Zope, but it does indicate strong progress. > ? ? ?* PyCrypto Couldn't find much. Found this from an email on Pycrypto mailing list: http://lists.dlitz.net/pipermail/pycrypto/2010q2/000244.html """ Hi Tobias > Does Pycrypto work with Python 3.x now? To my knowledge PyCrypto doesn't work yet with Python 3.x. Around 30% of the test cases are still fail. If you want me to check which of the components are pass, please let me know. Cheers, Christoph""" So someone has been looking at Python 3, but doesn't look like much is being done. > ? ? ?* PyOpenSSL Couldn't find anything. > ? ? ?* PyGTK This one shows real progress. There is a bug filed for Python 3 support: https://bugzilla.gnome.org/show_bug.cgi?id=566641 Key comment on that bug: """John Ehresman [developer] 2010-04-17 16:02:43 UTC I just pushed to the py3k branch a couple of fixes to bugs that are independent of the changes for python3 so all tests pass under both python 2.5 and python3.1. It's probably time to think about landing this on the master branch; obviously we want to avoid regressions in python2 support. What needs to be done before this lands on master?""" A couple of comments follow about when to merge Python 3 support. So it looks like they are almost there. Conclusion: 2 of 4 dependencies that Twisted needs to port to Python 3 show strong progress towards completing the port. Steven Rumbalski From torriem at gmail.com Tue Jul 6 09:40:19 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 06 Jul 2010 07:40:19 -0600 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> Message-ID: <4C333243.7040205@gmail.com> On 07/06/2010 04:12 AM, sturlamolden wrote: > On 28 Jun, 19:39, Michael Torrie wrote: > >> In python I could simply take the output of "ps ax" and use python's >> own, superior, cutting routines (using my module): >> >> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >> for x in stdout.split('\n'): >> print x.strip().split()[0] > > Or you just pass the stdout of one command as stdin to another. That > is equivalent of piping with bash. Consider this contrived example: tail -f /var/log/messages | grep openvpn While it's possible to set up pipes and spawn programs in parallel to operate on the pipes, in practice it's simpler to tell subprocess.Popen to use a shell and then just rely on Bash's very nice syntax for setting up the pipeline. Then just read the final output in python. If you set the stdout descriptor to non-blocking, you could read output as it came. From sri_annauni at yahoo.co.in Tue Jul 6 10:00:08 2010 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 6 Jul 2010 19:30:08 +0530 (IST) Subject: Pdf download using mechanize Message-ID: <812496.50589.qm@web7903.mail.in.yahoo.com> HI, I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? Thanks, Srini From aahz at pythoncraft.com Tue Jul 6 10:15:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 07:15:54 -0700 Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> Message-ID: In article , Terry Reedy wrote: >On 7/5/2010 6:40 AM, Ben Sizer wrote: > >>> Admittedly, it's three clicks away from the library docs on docs.python.org. >>> >>> http://effbot.org/zone/element.htm#xml-namespaces >> >> Hopefully someone will see fit to roll this important documentation >> into docs.python.org before the next release... oops, too late. ;) > >Not too late for next release. Open a doc issue with as specific a >suggestion as possible. Actually, it's not too late for this release, either (or at least it used not to be): the docs on the website can be updated even if the downloadable package itself can't be. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From ed at leafe.com Tue Jul 6 10:32:01 2010 From: ed at leafe.com (Ed Leafe) Date: Tue, 6 Jul 2010 10:32:01 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <92216C2C-6EFD-4BA6-873A-F280ADF5990C@leafe.com> On Jul 3, 2010, at 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). You should definitely check out Dabo. Several years ago we were looking for something in Python for developing desktop apps, and while there were several useful tools, there wasn't anything that integrated them together. That was our motivation for creating Dabo. We have a few screencasts to help you get acquainted with Dabo; I'd recommend these two to start: http://cdn.cloudfiles.mosso.com/c129431/dataenvironment1.html http://cdn.cloudfiles.mosso.com/c129432/dataenvironment1.html We also have a pretty comprehensive tutorial document, available at: http://dabodev.com/pycon_tutorial If you have any other questions, join our email discussion list and post them there. There are many helpful people there to answer your questions. http://leafe.com/mailman/listinfo/dabo-users -- Ed Leafe From alan.isaac at gmail.com Tue Jul 6 11:18:00 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 06 Jul 2010 11:18:00 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> Message-ID: <4C334928.4020105@gmail.com> On 7/6/2010 8:05 AM, Ritchy lelis wrote: > 1 - "import numpy as np > import matplotlib.pyplot as plt" > > In what help's me making the call's of the libraries that way? http://bytebaker.com/2008/07/30/python-namespaces/ > 2 - What's the instruction linspace means/does? >>> help(np.linspace) Help on function linspace in module numpy.core.function_base: linspace(start, stop, num=50, endpoint=True, retstep=False) Return evenly spaced numbers over a specified interval. Returns `num` evenly spaced samples, calculated over the interval [`start`, `stop` ]. > 3 - Last but more important: "V0 = ... #create an array" if I > understood, there i'm supposed to introduce the for loop as in my > initial example. correct? It is better to create your arrays without looping, if possible. But create it however you wish. (Note than numpy arrays have a fixed length; create a Python list if you wish to append to it.) Cheers, Alan Isaac From g.rodola at gmail.com Tue Jul 6 11:19:19 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Tue, 6 Jul 2010 17:19:19 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: 2010/7/6 David Cournapeau : >> Or is there no change at the C level? ?That would make things easy. > > There are quite a few, but outside of the big pain point of > strings/byte/unicode which is present at python level as well, a lot > of the issues are not so big (and even simpler to deal with). For > example, although numpy took time to port (and is still experimental > in nature), it took me a couple of hours to get a basic scipy working > (numpy uses a lot of C api dark corners, whereas scipy is much more > straightforward in its usage of the C API). > > David > -- > http://mail.python.org/mailman/listinfo/python-list As for this aspect, I made a port as such (C extension) for psutil, and it hasn't been too difficult, I must admit. For those interested here is a detailed explanation of all the steps I faced, along with revision changes: http://code.google.com/p/psutil/issues/detail?id=75&can=1&q=python%203&colspec=ID%20Summary%20Type%20Opsys%20Status%20Milestone%20Opened%20Owner%20Progress#c9 --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From sturlamolden at yahoo.no Tue Jul 6 11:50:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 08:50:11 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP Message-ID: Just a little reminder: Microsoft has withdrawn VS2008 in favor of VS2010. The express version is also unavailable for download. >:(( We can still get a VC++ 2008 compiler required to build extensions for the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK for .NET 3.5 SP1): http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en Download today, before it goes away! Microsoft has now published a download for Windows 7 SDK for .NET 4. It has the VC++ 2010 compiler. It can be a matter of days before the VC ++ 2008 compiler is totally unavailable. It is possible to build C and Fortran extensions for official Python 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is required for C++ or amd64 though. (Intel's compiler requires VS2008, which has now perished.) Remember Python on Windows will still require VS2008 for a long time. Just take a look at the recent Python 3 loath threads. From python at bdurham.com Tue Jul 6 11:54:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 06 Jul 2010 11:54:46 -0400 Subject: Changing Locale for datetime.strptime conversions In-Reply-To: <20100706123814.6ac10518@pitrou.net> References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com><5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> <20100706123814.6ac10518@pitrou.net> Message-ID: <1278431686.10469.1383542271@webmail.messagingengine.com> Antoine, > If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ Not the OP, but has Babel implemented parsing support? Last time I looked, Babel did a great job with locale specific formatting, but locale specific formatting was still incomplete. Malcolm From aaron.watters at gmail.com Tue Jul 6 11:59:24 2010 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 6 Jul 2010 08:59:24 -0700 (PDT) Subject: Pdf download using mechanize References: Message-ID: <58f1ee32-993c-4e8a-92f5-31a01fe152ed@y11g2000yqm.googlegroups.com> On Jul 6, 10:00?am, srinivasan srinivas wrote: > HI, > I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. > Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? > > Thanks, > Srini Mechanize seems to have a mailing list ;c) https://lists.sourceforge.net/lists/listinfo/wwwsearch-general Also, it would be helpful to know what specific problems you are having. Have you tried following the excellent documentation? http://wwwsearch.sourceforge.net/mechanize/doc.html It looks like downloading any sort of file and saving it should be straightforward to me, but I haven't tried it. Aaron Watters http://whiffdoc.appspot.com === % man less less is more. From alf.p.steinbach+usenet at gmail.com Tue Jul 6 12:00:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 06 Jul 2010 18:00:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: * sturlamolden, on 06.07.2010 17:50: > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download.>:(( > > We can still get a VC++ 2008 compiler required to build extensions for > the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days before the VC > ++ 2008 compiler is totally unavailable. > > It is possible to build C and Fortran extensions for official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > required for C++ or amd64 though. (Intel's compiler requires VS2008, > which has now perished.) > > Remember Python on Windows will still require VS2008 for a long time. > Just take a look at the recent Python 3 loath threads. Perhaps this all for the good. There is no *technical* problem creating a compiler-independent C/C++ language binding. I believe that Java's JNI works fine no matter what compiler you use, although it's many many years since I've done JNI things. Similarly, Python should IMHO just have a well defined compiler independent native code interface, e.g. "PNI", or "pynacoin", the PYthon NAtive COde INterface :-) Cheers, - Alf -- blog at From solipsis at pitrou.net Tue Jul 6 12:03:22 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jul 2010 18:03:22 +0200 Subject: Changing Locale for datetime.strptime conversions In-Reply-To: <1278431686.10469.1383542271@webmail.messagingengine.com> References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> <20100706123814.6ac10518@pitrou.net> <1278431686.10469.1383542271@webmail.messagingengine.com> Message-ID: <20100706180322.6fee23e3@pitrou.net> On Tue, 06 Jul 2010 11:54:46 -0400 python at bdurham.com wrote: > Antoine, > > > If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ > > Not the OP, but has Babel implemented parsing support? Last time I > looked, Babel did a great job with locale specific formatting, but > locale specific formatting was still incomplete. No idea, but if you just want to recognize month names, you can produce all the month names in the desired natural language and then recognize them yourself (using e.g. a regexp). Probably imperfect, but probably sufficient in many cases too. From ceccarelli.aldo at gmail.com Tue Jul 6 12:06:01 2010 From: ceccarelli.aldo at gmail.com (Aldo Ceccarelli) Date: Tue, 6 Jul 2010 09:06:01 -0700 (PDT) Subject: Pdf download using mechanize References: Message-ID: On 6 Lug, 16:00, srinivasan srinivas wrote: > HI, > I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. > Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? > > Thanks, > Srini Hi, Srini: unfortunately I have no direct experience of downloading PDF with mechanize but I'd like to share this IBM article which gives some mechanize snippet and hint (in case of any help to your research) http://www.ibm.com/developerworks/linux/library/l-python-mechanize-beautiful-soup/index.html kind regards, Aldo From ritchy_gato at hotmail.com Tue Jul 6 12:11:32 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 6 Jul 2010 09:11:32 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> Message-ID: <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> On 6 jul, 16:18, Alan G Isaac wrote: > On 7/6/2010 8:05 AM, Ritchy lelis wrote: > > > ?1 - "import numpy as np > > ? ? ? import matplotlib.pyplot as plt" > > > ? ? ? In what help's me making the call's of the libraries that way? > > http://bytebaker.com/2008/07/30/python-namespaces/ > > > ?2 - What's the instruction linspace means/does? > > ?>>> help(np.linspace) > ? ? ? ? ?Help on function linspace in module numpy.core.function_base: > > ? ? ? ? ?linspace(start, stop, num=50, endpoint=True, retstep=False) > ? ? ? ? ? ? ?Return evenly spaced numbers over a specified interval. > > ? ? ? ? ? ? ?Returns `num` evenly spaced samples, calculated over the > ? ? ? ? ? ? ?interval [`start`, `stop` ]. > > > ?3 - Last but more important: "V0 = ... #create an array" if I > > ?understood, there i'm supposed to introduce the for loop as in my > > ?initial example. correct? > > It is better to create your arrays without looping, > if possible. ?But create it however you wish. > (Note than numpy arrays have a fixed length; > create a Python list if you wish to append to it.) > > Cheers, > Alan Isaac ------------------------------------------------- My intention with de for loop was to iterate each point of the arrays Vi and Vref at the math calculations. The V0 it's the result of the math expressions between the Vi and Vref. I can't just create one V0 by a function set by parametters (i don't see how). Could you give a clue? Cheers Ritchy From vlastimil.brom at gmail.com Tue Jul 6 12:16:32 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 6 Jul 2010 18:16:32 +0200 Subject: markmin 0.1 In-Reply-To: References: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> Message-ID: 2010/7/6 Chris Rebert : > On Mon, Jul 5, 2010 at 4:56 PM, Massimo Di Pierro > wrote: >> Markmin is a wiki markup language >> implemented in less than 100 lines of code (one file, no dependencies) >> easy to read >> secure >> ... > > Okay, but where can it be downloaded from? You didn't include a link. > > Cheers, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list > It looks like http://www.web2py.com/examples/static/markmin.html vbr From thomas at jollans.com Tue Jul 6 12:21:32 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 18:21:32 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33580C.9030609@jollans.com> On 07/06/2010 05:50 PM, sturlamolden wrote: > It is possible to build C and Fortran extensions for official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > required for C++ or amd64 though. (Intel's compiler requires VS2008, > which has now perished.) mingw gcc should work for building C++ extensions if it also works for C extensions. There's no difference on the binding side - you simply have to include everything as extern "C", which I am sure the header does for you. As for amd64 - I do not know if there is a mingw64 release for windows already. If there isn't, there should be ;-) But that doesn't really change anything: the express edition of Microsoft's VC++ doesn't include an amd64 compiler anyway, AFAIK. Also, VS2010 should work as well - doesn't it? > > Remember Python on Windows will still require VS2008 for a long time. > Just take a look at the recent Python 3 loath threads. > From alan.isaac at gmail.com Tue Jul 6 12:29:48 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 06 Jul 2010 12:29:48 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> Message-ID: On 7/6/2010 12:11 PM, Ritchy lelis wrote: > My intention with de for loop was to iterate each point of the arrays > Vi and Vref at the math calculations. The V0 it's the result of the > math expressions between the Vi and Vref. I can't just create one V0 > by a function set by parametters (i don't see how). Unfortunately I cannot make sense of the code you posted. Provide a detailed description in words (or psuedocode) of what you are trying to accomplish. Be very careful and detailed is you want a useful response. Alan Isaac From sturlamolden at yahoo.no Tue Jul 6 12:39:52 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 09:39:52 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <84b7f040-b4b6-478c-b8d9-2737fabcaf91@a30g2000yqn.googlegroups.com> On 6 Jul, 18:00, "Alf P. Steinbach /Usenet" wrote: > There is no *technical* problem creating a compiler-independent C/C++ language > binding. I believe that Java's JNI works fine no matter what compiler you use, > although it's many many years since I've done JNI things. Similarly, Python > should IMHO just have a well defined compiler independent native code interface, > e.g. "PNI", or "pynacoin", the PYthon NAtive COde INterface :-) Yes but Python currently does not, due to dependency on VS2003 (2.5) or VS2008 (2.6, 2.7, 3.1) C and C++ runtime DLLs. It's not the binary interface that is the trouble, but CRT versioning. C++ is extra troublesome due to name mangling, standard runtime and exceptions. Here are the issues: C++: VS2010 - does not link with msvcp90.dll but msvcp100.dll. mingw - linkes statically with its own C++ library. Win32, ANSI C: VS2010 - does not link with msvcr90.dll but msvcr100.dll. mingw - ok for C if passed -lmsvcr90 on linking step Win64, ANSI C: VS2010 - does not link with msvcr90.dll but msvcr100.dll. mingw - missing import libraries (libmsvcr90.a and libpython26.a) Visual Studio 2008's C/C++ compiler is the only sane solution. It is still there so go get it if you don't already have a copy (I guess Alf does). From sturlamolden at yahoo.no Tue Jul 6 12:49:15 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 09:49:15 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 18:21, Thomas Jollans wrote: > mingw gcc should work for building C++ extensions if it also works for C > extensions. No, it uses an incompatible statically linked C++ runtime. We need to use msvcp90.dll with Python 2.6/2.7. > As for amd64 - I do not know if there is a mingw64 release for windows > already. If there isn't, there should be ;-) There is. But it does not have an import library for msvcr90.dll. It's omitted from mingw-w64. Also libpython26.a is missing from Python on Windows 64. > Also, VS2010 should work as well - doesn't it? The problem with Microsoft's compilers is that they just let you pick between two CRTs (single- or multi-threaded). We need to specify the version number as well. So no, VS2010 will not work. (At least not without some ugly hacks.) From lists at cheimes.de Tue Jul 6 12:58:31 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 18:58:31 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33580C.9030609@jollans.com> References: <4C33580C.9030609@jollans.com> Message-ID: Am 06.07.2010 18:21, schrieb Thomas Jollans: > mingw gcc should work for building C++ extensions if it also works for C > extensions. There's no difference on the binding side - you simply have > to include everything as extern "C", which I am sure the header does for > you. You need unofficial version of MinGW with gcc 4.x for several C++ extension like PyLucene's JCC. Some project like pywin32 don't work with MinGW, too. > Also, VS2010 should work as well - doesn't it? It may work, it may segfault. The official Python binaries are build with VS 2008. Although you are able to build and use extensions build with other versions of VS it can lead to segfaults. So far every version of VS has introduced its own C runtime library (MSVCRT). If you try to close a FILE* from one MSVCRT with fclose() from another MSVCRT your program SEGFAULT. malloc() and free() suffer from the same problem. From zac256 at gmail.com Tue Jul 6 13:06:18 2010 From: zac256 at gmail.com (Zac Burns) Date: Tue, 6 Jul 2010 10:06:18 -0700 Subject: Lockless algorithms in python (Nothing to do with GIL) In-Reply-To: <20100702222603.26c5e4af@pitrou.net> References: <20100702222603.26c5e4af@pitrou.net> Message-ID: I'm not an expert on this, but wouldn't it be more dependent on the platform than python version? Perhaps it is Windows 7 that is very slow. Perhaps my processor architecture. Not sure... Here are some for 3.1.2x64 >>> import timeit >>> timeit.timeit('Lock()', 'from threading import Lock') 1.4162585386092708 >>> timeit.timeit('dict()', 'from threading import Lock') 0.2730348901369162 >>> timeit.timeit('list()', 'from threading import Lock') 0.1719480219512306 -Zac On Fri, Jul 2, 2010 at 1:26 PM, Antoine Pitrou wrote: > On Mon, 28 Jun 2010 16:46:41 -0700 > Zac Burns wrote: > > In my experience it is far more expensive to allocate a lock in python > then > > it is the types that use them. Here are some examples: > > > > >>> timeit.timeit('Lock()', 'from threading import Lock') > > 1.4449114807669048 > > > > >>> timeit.timeit('dict()') > > 0.2821554294221187 > > > > >>> timeit.timeit('list()') > > 0.17358153222312467 > > I'm not sure what Python version on what machine you are using, but > here (Python 2.7): > > >>> timeit.timeit('Lock()', 'from threading import Lock') > 0.09944796562194824 > >>> timeit.timeit('dict()') > 0.17817902565002441 > >>> timeit.timeit('list()') > 0.19633007049560547 > >>> timeit.timeit('{}') > 0.03823709487915039 > >>> timeit.timeit('[]') > 0.05156302452087402 > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Tue Jul 6 13:09:21 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:09:21 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> Message-ID: <4C336341.4070800@jollans.com> On 07/06/2010 06:58 PM, Christian Heimes wrote: > Am 06.07.2010 18:21, schrieb Thomas Jollans: >> mingw gcc should work for building C++ extensions if it also works for C >> extensions. There's no difference on the binding side - you simply have >> to include everything as extern "C", which I am sure the header does for >> you. > > You need unofficial version of MinGW with gcc 4.x for several C++ > extension like PyLucene's JCC. Some project like pywin32 don't work with > MinGW, too. aha - why is that? But - if you write code that builds with [whatever gcc version you have], the compiler Python is built with shouldn't matter, should it? > >> Also, VS2010 should work as well - doesn't it? > > It may work, it may segfault. > > The official Python binaries are build with VS 2008. Although you are > able to build and use extensions build with other versions of VS it can > lead to segfaults. So far every version of VS has introduced its own C > runtime library (MSVCRT). If you try to close a FILE* from one MSVCRT > with fclose() from another MSVCRT your program SEGFAULT. malloc() and > free() suffer from the same problem. Okay, you need to be careful with FILE*s. But malloc and free? You'd normally only alloc & free something within the same module, using the same functions (ie not mixing PyMem_Malloc and malloc), would you not? You have to code quite defensively, true. But, IF you keep all non-Python data structures local to your module, you should be fine? Coming from a system where I can generally rely on the system gcc to work for everything, I may be a bit na?ve wrt certain questions ;-) Cheers, Thomas PS: Windows CPython programming scares me. From javier.collado at gmail.com Tue Jul 6 13:10:17 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 6 Jul 2010 19:10:17 +0200 Subject: re.sub unexpected behaviour Message-ID: Hello, Let's imagine that we have a simple function that generates a replacement for a regular expression: def process(match): return match.string If we use that simple function with re.sub using a simple pattern and a string we get the expected output: re.sub('123', process, '123') '123' However, if the string passed to re.sub contains a trailing new line character, then we get an extra new line character unexpectedly: re.sub(r'123', process, '123\n') '123\n\n' If we try to get the same result using a replacement string, instead of a function, the strange behaviour cannot be reproduced: re.sub(r'123', '123', '123') '123' re.sub('123', '123', '123\n') '123\n' Is there any explanation for this? If I'm skipping something when using a replacement function with re.sub, please let me know. Best regards, Javier From thomas at jollans.com Tue Jul 6 13:11:06 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:11:06 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C3363AA.5080801@jollans.com> On 07/06/2010 06:49 PM, sturlamolden wrote: > On 6 Jul, 18:21, Thomas Jollans wrote: > >> mingw gcc should work for building C++ extensions if it also works for C >> extensions. > > No, it uses an incompatible statically linked C++ runtime. We need to > use msvcp90.dll with Python 2.6/2.7. Python is written in C. How does the C++ runtime enter into it? > >> As for amd64 - I do not know if there is a mingw64 release for windows >> already. If there isn't, there should be ;-) > > There is. But it does not have an import library for msvcr90.dll. It's > omitted from mingw-w64. Also libpython26.a is missing from Python on > Windows 64. > > >> Also, VS2010 should work as well - doesn't it? > > The problem with Microsoft's compilers is that they just let you pick > between two CRTs (single- or multi-threaded). We need to specify the > version number as well. > > So no, VS2010 will not work. (At least not without some ugly hacks.) From anthra.norell at bluewin.ch Tue Jul 6 13:15:05 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Tue, 06 Jul 2010 19:15:05 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <89f9edFuavU1@mid.individual.net> References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> <89f9edFuavU1@mid.individual.net> Message-ID: <4C336499.8020806@bluewin.ch> Gregory Ewing wrote: >>> On 07/05/2010 11:07 AM, Anthra Norell wrote: >>> >>>> I try to use "new.new.classobj (name, baseclass, dict)" and have no >>>> clue >>>> what the "dict" of the current name space is. > > Are you sure that's what you really want to know? The > 'dict' argument to classobj() defines the attributes > that you want the new class to have. It's not meant > to be the namespace in which the code creating the > class is executing. > No indeed I'm not sure. The doc explains the argument "dict" as "name space", a term I associated with the enclosing module's name space, because it is also visible from inside enclosed blocks. But how right you are! Passing locals () works fine inasmuch as the constructor doesn't complain. Looking subsequently at the class attributes with dir (c) or c.__dict__keys (), however, dumps the entire inventory of the module in addition to the attributes of the base class. Clearly, that can't be right. So, thanks to you! I very much appreciate the guidance along the right path. Frederic From tjreedy at udel.edu Tue Jul 6 13:17:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jul 2010 13:17:02 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On 7/6/2010 11:19 AM, Giampaolo Rodol? wrote: > 2010/7/6 David Cournapeau: >>> Or is there no change at the C level? That would make things easy. >> >> There are quite a few, but outside of the big pain point of >> strings/byte/unicode which is present at python level as well, a lot >> of the issues are not so big (and even simpler to deal with). For >> example, although numpy took time to port (and is still experimental >> in nature), it took me a couple of hours to get a basic scipy working >> (numpy uses a lot of C api dark corners, whereas scipy is much more >> straightforward in its usage of the C API). > > As for this aspect, I made a port as such (C extension) for psutil, > and it hasn't been too difficult, I must admit. > > For those interested here is a detailed explanation of all the steps I > faced, along with revision changes: > http://code.google.com/p/psutil/issues/detail?id=75&can=1&q=python%203&colspec=ID%20Summary%20Type%20Opsys%20Status%20Milestone%20Opened%20Owner%20Progress#c9 That post refers to docs.python.org / dev/3.0/howto/cporting.html [without added space] but that is currently 404 missing. -- Terry Jan Reedy From ritchy_gato at hotmail.com Tue Jul 6 13:18:17 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 6 Jul 2010 10:18:17 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> Message-ID: <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> On 6 jul, 17:29, Alan G Isaac wrote: > On 7/6/2010 12:11 PM, Ritchy lelis wrote: > > > My intention with de for loop was to iterate each point of the arrays > > Vi and Vref at the math calculations. The V0 it's the result of the > > math expressions between the Vi and Vref. I can't just create one V0 > > by a function set by parametters (i don't see how). > > Unfortunately I cannot make sense of the code you posted. > Provide a detailed description in words (or psuedocode) > of what you are trying to accomplish. ?Be very careful > and detailed is you want a useful response. > > Alan Isaac hummm... ok, i will try to make that detailed description. Maybe i have not been so clear because my inglish suck's :D However i have a tutorial and another document that my teacher gave me, i could send you it if you allowed me. It's the 2 best document's i've seen about ADC. Ritchy From vinay_sajip at yahoo.co.uk Tue Jul 6 13:22:04 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jul 2010 17:22:04 +0000 (UTC) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: norbert gmail.com> writes: > > crash with a UnicodeError. I can't see any workaround, except by > subclassing SMTPHandler's emit method to be unicode-aware or at least > URF-8 aware. > Well, you could use an approach like the one suggested here: http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal-with.html From steve at REMOVE-THIS-cybersource.com.au Tue Jul 6 13:32:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 17:32:07 GMT Subject: re.sub unexpected behaviour References: Message-ID: <4c336897$0$28647$c3e8da3@news.astraweb.com> On Tue, 06 Jul 2010 19:10:17 +0200, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern and a > string we get the expected output: > re.sub('123', process, '123') > '123' > > However, if the string passed to re.sub contains a trailing new line > character, then we get an extra new line character unexpectedly: > re.sub(r'123', process, '123\n') > '123\n\n' I don't know why you say it is unexpected. The regex "123" matched the first three characters of "123\n". Those three characters are replaced by a copy of the string you are searching "123\n", which gives "123\n\n" exactly as expected. Perhaps these examples might help: >>> re.sub('W', process, 'Hello World') 'Hello Hello Worldorld' >>> re.sub('o', process, 'Hello World') 'HellHello World WHello Worldrld' Here's a simplified pure-Python equivalent of what you are doing: def replace_with_match_string(target, s): n = s.find(target) if n != -1: s = s[:n] + s + s[n+len(target):] return s > If we try to get the same result using a replacement string, instead of > a function, the strange behaviour cannot be reproduced: re.sub(r'123', > '123', '123') > '123' > > re.sub('123', '123', '123\n') > '123\n' The regex "123" matches the first three characters of "123\n", which is then replaced by "123", giving "123\n", exactly as expected. >>> re.sub("o", "123", "Hello World") 'Hell123 W123rld' -- Steven From thomas at jollans.com Tue Jul 6 13:32:29 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:32:29 +0200 Subject: re.sub unexpected behaviour In-Reply-To: References: Message-ID: <4C3368AD.4060902@jollans.com> On 07/06/2010 07:10 PM, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern and > a string we get the expected output: > re.sub('123', process, '123') > '123' > > However, if the string passed to re.sub contains a trailing new line > character, then we get an extra new line character unexpectedly: > re.sub(r'123', process, '123\n') > '123\n\n' process returns match.string, which is, according to the docs: """The string passed to match() or search()""" You passed "123\n" to sub(), which may not be explicitly listed here, but there's no difference. Process correctly returns "123\n", which is inserted. Let me demonstrate again with a longer string: >>> import re >>> def process(match): ... return match.string ... >>> re.sub(r'\d+', process, "start,123,end") 'start,start,123,end,end' >>> > > If we try to get the same result using a replacement string, instead > of a function, the strange behaviour cannot be reproduced: > re.sub(r'123', '123', '123') > '123' > > re.sub('123', '123', '123\n') > '123\n' Again, the behaviour is correct: you're not asking for "whatever was passed to sub()", but for '123', and that's what you're getting. > > Is there any explanation for this? If I'm skipping something when > using a replacement function with re.sub, please let me know. What you want is grouping: >>> def process(match): ... return "<<" + match.group(1) + ">>" ... >>> re.sub(r'(\d+)', process, "start,123,end") 'start,<<123>>,end' >>> or better, without a function: >>> re.sub(r'(\d+)', r'<<\1>>', "start,123,end") 'start,<<123>>,end' >>> Cheers, Thomas From thomas at jollans.com Tue Jul 6 13:34:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:34:26 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <4C336922.6080300@jollans.com> On 07/06/2010 07:17 PM, Terry Reedy wrote: > docs.python.org / dev/3.0/howto/cporting.html http://docs.python.org/py3k/howto/cporting.html From sturlamolden at yahoo.no Tue Jul 6 13:35:50 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 10:35:50 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> Message-ID: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> On 6 Jul, 19:09, Thomas Jollans wrote: > Okay, you need to be careful with FILE*s. But malloc and free? You'd > normally only alloc & free something within the same module, using the > same functions (ie not mixing PyMem_Malloc and malloc), would you not? You have to be sure PyMem_Malloc is not an preprocessor alias for malloc (I haven't chaecked). In general, CRT objects cannot be shared across CRT boundaries. Also remember the C and C++ standard libraries interact. g++ from links statically with an incompatible C++ standard library (read: it will segfault, it's just a question of when). > Coming from a system where I can generally rely on the system gcc to > work for everything, I may be a bit na?ve wrt certain questions ;-) On sane operating systems you generally have one version of libc installed. Windows did this too (msvcrt.dll) up to the VS2003 release, which came with msvcr71.dll in addition. Since then, M$ (pronounced Megadollar Corp.) have published msvcr80.dll, msvcr90.dll, and msvcr100.dll (and corresponding C++ versions) to annoy C and C++ developers into converting to C# .NET. (And yes, programs using third-party DLL and OCX components become unstable from this. You have to check each DLL/ OCX you use, and each DLL used by each DLL, etc. How fun...) From sturlamolden at yahoo.no Tue Jul 6 13:43:51 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 10:43:51 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <77985134-cd90-4b18-b6d9-ae4dc7e84680@z10g2000yqb.googlegroups.com> On 6 Jul, 19:11, Thomas Jollans wrote: > Python is written in C. How does the C++ runtime enter into it? The C and C++ runtimes interact (e.g. stdlib.h and ), malloc and new, etc. With g++ you have a C++ standard library compiled against msvcrt.dll, whereas Python is using msvcr90.dll. We can use the C++ runtime msvcp90.dll used by VC++ 2008, but this DLL is binary incompatible with g++ (GNU uses a different ABI for C++). From martin.hellwig at dcuktec.org Tue Jul 6 13:46:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 06 Jul 2010 18:46:34 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On 07/06/10 16:50, sturlamolden wrote: > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download.>:(( Public download that is, people like me who have a MSDN subscription can still download old versions like Visual Studio 2005. So I would say that there is no particular hurry. I would think that everyone really serious about MS development with MS tools should get an MSDN subscription anyway, it saves you a lot of money in the long run. -- mph From lists at cheimes.de Tue Jul 6 13:49:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 19:49:32 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C336341.4070800@jollans.com> References: <4C33580C.9030609@jollans.com> <4C336341.4070800@jollans.com> Message-ID: >> You need unofficial version of MinGW with gcc 4.x for several C++ >> extension like PyLucene's JCC. Some project like pywin32 don't work with >> MinGW, too. > > aha - why is that? > > But - if you write code that builds with [whatever gcc version you > have], the compiler Python is built with shouldn't matter, should it? Unless I'm mistaken, official MinGW32 packages still have GCC 3.x. Some projects like JCC need recent C++ compilers. MinGW doesn't provide some features that pywin32 requires. The compiler must create ABI compatible object files and the linker needs to support the latest CRT. Three years ago it took several months until MinGW supported the 9.0 CRT. > Okay, you need to be careful with FILE*s. But malloc and free? You'd > normally only alloc & free something within the same module, using the > same functions (ie not mixing PyMem_Malloc and malloc), would you not? > > You have to code quite defensively, true. But, IF you keep all > non-Python data structures local to your module, you should be fine? You must be carefully with functions like PyFile_FromFile(), too. If you expose the FILE* from the alien CRT to Python somehow you can get into trouble. Lukely PyFile_FromFile() works around most issues but it's still problematic. These kind of SEGFAULTs are hard to debug, too. > Coming from a system where I can generally rely on the system gcc to > work for everything, I may be a bit na?ve wrt certain questions ;-) > > PS: Windows CPython programming scares me. Yeah, it's a pain. From e_d_k at yahoo.com Tue Jul 6 13:52:59 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Tue, 6 Jul 2010 10:52:59 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: Message-ID: <91295.91066.qm@web120510.mail.ne1.yahoo.com> I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! This seems odd to me, has anyone else had this problem? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Tue, 7/6/10, sturlamolden wrote: > From: sturlamolden > Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP > To: python-list at python.org > Date: Tuesday, July 6, 2010, 11:50 AM > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The > express version > is also unavailable for download. >:(( > > We can still get a VC++ 2008 compiler required to build > extensions for > the official Python 2.6 and 2.7 binary installers here > (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK > for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days > before the VC > ++ 2008 compiler is totally unavailable. > > It is possible to build C and Fortran extensions for > official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's > compiler is > required for C++ or amd64 though. (Intel's compiler > requires VS2008, > which has now perished.) > > Remember Python on Windows will still require VS2008 for a > long time. > Just take a look at the recent Python 3 loath threads. > > -- > http://mail.python.org/mailman/listinfo/python-list > From javier.collado at gmail.com Tue Jul 6 13:58:58 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 6 Jul 2010 19:58:58 +0200 Subject: re.sub unexpected behaviour In-Reply-To: <4c336897$0$28647$c3e8da3@news.astraweb.com> References: <4c336897$0$28647$c3e8da3@news.astraweb.com> Message-ID: Thanks for your answers. They helped me to realize that I was mistakenly using match.string (the whole string) when I should be using math.group(0) (the whole match). Best regards, Javier From rantingrick at gmail.com Tue Jul 6 14:10:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 11:10:38 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On Jul 6, 12:37?am, Terry Reedy wrote: > In his post on this thread, Martin Loewis volunteered to list what he > knows from psycopg2 if someone else will edit. Now we are getting somewhere! This is the community spirit i want to see. You don't have to give much people, every little bit counts. But for Google's sake we need to work together to get this thing done. Let's get a list together of 3rd party modules that are "must haves" and start knocking on doors, evangelizing, air dropping leaflets, spreading the word, whatever it takes! The revolution is not going to happen whilst we sleep -- not the Python revolution that is! Get the lead out c.l.p! From aahz at pythoncraft.com Tue Jul 6 14:12:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 11:12:11 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Message-ID: In article <8f5014f6-9aa8-44e2-afe1-a1175bcdd591 at w31g2000yqb.googlegroups.com>, moerchendiser2k3 wrote: > >I have a serious problem I haven't solved yet, hope one of you can >help me. The first thing is, I embedded Python into my app and I >execute several scripts in this environment. > >The problem is, the scripts don't import modules from their relative >path. I guess this is related to the sys.path ['',...] and the current >working directory which is set to the directory of my host >application. > >I could set that path manually, but all the scripts might be stored in >different locations. So now I try to find a way to handle that. Any >suggestions? Set sys.path to include each script's base dir before running it, then restore after each script. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From sturlamolden at yahoo.no Tue Jul 6 14:14:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 11:14:21 -0700 (PDT) Subject: Python GUI for C program [was: ] References: Message-ID: <6255259b-3c26-4222-b03f-f73403ee1c46@z10g2000yqb.googlegroups.com> On 6 Jul, 13:45, Thomas Jollans wrote: > 1. Turn your C program into a library, and write a Python extension Note that using ctypes, Cython or Boost.Python is much less painful than using Python's C API directly. > It might, however, be best to simply write the GUI in C as well, which > would avoid the overhead of loading Python and isn't all that difficult > either. If you know C++, check out wxWidgets and Qt4. To stick with > plain C, have a look at GTK+. You will hardly notice the overhead of loading Python. (It's not Java...) Also a good GUI builder is far more important than language when it comes to making a GUI. Depending on toolkit my preferences are wxFormBuilder, Qt Designer, GLADE or MS Visual Studio. - wxFormBuilder are beginning to be ok for wxPython development without XRC, finally. - PyQt has licensing issues, although Qt is LGPL. PySide is still incomplete. - GLADE/PyGTK has issues on Windows (e.g. need to supply a GTK+ run- time). - Visual Studio can be used for IronPython .NET and native MFC (pywin32 has MFC bindings). - tkinter generally sucks (tedious to use, looks bad). From sturlamolden at yahoo.no Tue Jul 6 14:15:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 11:15:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <481a9a5b-b5ca-4e6d-a07c-919a90b0408a@d37g2000yqm.googlegroups.com> On 6 Jul, 19:52, Ed Keith wrote: > This seems odd to me, has anyone else had this problem? DVD? From me+list/python at ixokai.io Tue Jul 6 14:19:06 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 11:19:06 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <91295.91066.qm@web120510.mail.ne1.yahoo.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C33739A.2080003@ixokai.io> On 7/6/10 10:52 AM, Ed Keith wrote: > I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! The website says its a DVD iso. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Tue Jul 6 14:23:48 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 11:23:48 -0700 (PDT) Subject: Python GUI for C program [was: ] References: <6255259b-3c26-4222-b03f-f73403ee1c46@z10g2000yqb.googlegroups.com> Message-ID: <3aa7c05b-b54c-4b2e-9933-8c84db972ab2@d16g2000yqb.googlegroups.com> On Jul 6, 1:14?pm, sturlamolden wrote: > Also a good GUI builder is far more important than language when it > comes to making a GUI. Depending on toolkit my preferences are > wxFormBuilder, Qt Designer, GLADE or MS Visual Studio. Thats only true when using any language EXCEPT Python. With Python, Python is all you need. Python GUI builders are for pansies. However when using the redundantly asinine C, C++, and Java... well your already getting bent over, might as well bring some lubrication to ease the pain! From robert.kern at gmail.com Tue Jul 6 14:28:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 06 Jul 2010 14:28:32 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <91295.91066.qm@web120510.mail.ne1.yahoo.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 7/6/10 1:52 PM, Ed Keith wrote: > I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! > > This seems odd to me, has anyone else had this problem? These days, ISOs are destined for DVD-Rs. :-) There are also utilities for mounting ISOs directly without burning them to a physical disk. Here is a decent list: http://www.techsupportalert.com/best-free-cd-emulator.htm -- 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 googler.1.webmaster at spamgourmet.com Tue Jul 6 14:50:21 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 6 Jul 2010 11:50:21 -0700 (PDT) Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Message-ID: <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> >Set sys.path to include each script's base dir before running it, then >restore after each script. That works, but doesnt solve the problem. ScriptA.py has a module in its directory called 'bar.py' ScriptB.py has a module in its directory called 'bar.py' Imagine the 'bar.py' modules dont have the same content, so they are not equal. Now when the first bar.py is imported, the second import for a "import bar" imports the first one, because its already stored in sys.modules. From gdamjan at gmail.com Tue Jul 6 14:56:37 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 06 Jul 2010 20:56:37 +0200 Subject: A question about the posibility of raise-yield in Python References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <28847956-9af7-4280-acc9-dd7eca8dd1c3@t10g2000yqg.googlegroups.com> Message-ID: <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> >> > I'm writing this as a complete newbie (on the issue), so don't be >> > surprised if it's the stupidest idea ever. >> >> > I was wondering if there was ever a discusision in the python >> > community on a 'raise-yield' kind-of combined expression. I'd like >> > to know if it was proposed/rejected/discussed/not-decided yet?? >> >> Recently (ok, several hours ago) I've come up to Greenlets [1] and it >> seems they implement exactly what I was asking for, in a C >> extension!! >> >> It's too bad that Python doesn't support this by default and many >> libraries won't make use of it by default. Gevent [2] for example, >> has to monkey-patch Python's socket, time.sleep and other modules so >> that things like urllib work with it. >> >> I'll continue to read now. > > Ah, if I had seen your original post I probably could have pointed you > to some good reading right away. What you've described is called a > continuation, and is natively supported by some languages (like > Scheme). It's usually not done with exceptions, though. In Scheme > it's a special form that looks like an ordinary function call, but you > can "return" from the call any number of times. I thought they were called coroutines? Anyway, here's the Lua implementation of coroutines. It's basically a yield but it will return back several frames. http://lua-users.org/wiki/CoroutinesTutorial -- ?????? ((( http://damjan.softver.org.mk/ ))) Today we create the legacy of tomorrow. From aahz at pythoncraft.com Tue Jul 6 15:11:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 12:11:01 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, moerchendiser2k3 wrote: >Aahz: >> >>Set sys.path to include each script's base dir before running it, then >>restore after each script. > >That works, but doesnt solve the problem. > >ScriptA.py has a module in its directory called 'bar.py' >ScriptB.py has a module in its directory called 'bar.py' > >Imagine the 'bar.py' modules dont have the same content, so they are >not equal. > >Now when the first bar.py is imported, the second import for a "import >bar" imports the first one, because its already stored in sys.modules. Good point, you'll need to save/restore sys.modules, too. That gets you 90-95% of complete namespace separation; if you need more than that, your best bet is to use separate processes. Full-blown namepace isolation is a *hard* problem, just look at all the past attempts to create secure Python (and what you're trying to do is roughly equivalent). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From tim at johnsons-web.com Tue Jul 6 15:16:50 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 06 Jul 2010 11:16:50 -0800 Subject: Recommend a MySQLdb Forum Message-ID: Greetings: I would appreciate it if some could recommend a MySQLdb forum. thanks tim From sturlamolden at yahoo.no Tue Jul 6 15:33:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 12:33:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 19:46, "Martin P. Hellwig" wrote: > Public download that is, people like me who have a MSDN subscription can > still download old versions like Visual Studio 2005. That's nice to know, but I personally don't have an MSDN subscription. Many scientists don't have access to development tools like VS2008. Many hobby developers don't have access expensive MSDN subscriptions. Many don't develop C personally, but just "needs a compiler" to build an extension with distutils. And for all of us not subscribing to MSDN, this is the only remaining source. From drobinow at gmail.com Tue Jul 6 15:40:04 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 6 Jul 2010 15:40:04 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On Tue, Jul 6, 2010 at 1:46 PM, Martin P. Hellwig wrote: > Public download that is, people like me who have a MSDN subscription can > still download old versions like Visual Studio 2005. > > So I would say that there is no particular hurry. > I would think that everyone really serious about MS development with MS > tools should get an MSDN subscription anyway, it saves you a lot of money in > the long run. Amazing! From bdesth.quelquechose at free.quelquepart.fr Tue Jul 6 15:46:41 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 06 Jul 2010 21:46:41 +0200 Subject: delegation pattern via descriptor In-Reply-To: <89aamgF7vdU1@mid.individual.net> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> Message-ID: <4c33a3a6$0$23067$426a74cc@news.free.fr> Gregory Ewing a ?crit : > Bruno Desthuilliers wrote: >> kedra marbun a ?crit : >> >>> if we limit our discussion to py: >>> why __{get|set|delete}__ don't receive the 'name' & 'class' from >>> __{getattribute|{set|del}attr}__ >>> 'name' is the name that is searched >> >> >> While it would have been technically possible, I fail to imagine any use >> case for this. > > I think he wants to have generic descriptors that are > shared between multiple attributes, but have them do > different things based on the attribute name. I already understood this, but thanks !-) What I dont understand is what problem it could solve that couldn't be solved more simply using the either _getattr__ hook or hand-coded delegation, since such a descriptor would be so tightly coupled to the host class that it just doesn't make sense writing a descriptor for this. From lists at cheimes.de Tue Jul 6 15:49:50 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 21:49:50 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: > That's nice to know, but I personally don't have an MSDN subscription. > Many scientists don't have access to development tools like VS2008. > Many hobby developers don't have access expensive MSDN subscriptions. > Many don't develop C personally, but just "needs a compiler" to build > an extension with distutils. And for all of us not subscribing to > MSDN, this is the only remaining source. I agree, the situation isn't ideal. I see if I can get in contact with Microsoft's open source team. Perhaps they can keep the download link to VS 2008 EE working. By the way lot's of universities participate in the MSDN Academy Alliance program. Students, scientists and employees of the university can get most MSDN packages. From casevh at gmail.com Tue Jul 6 15:52:17 2010 From: casevh at gmail.com (casevh) Date: Tue, 6 Jul 2010 12:52:17 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On Jul 6, 9:21?am, Thomas Jollans wrote: > On 07/06/2010 05:50 PM, sturlamolden wrote: > > > It is possible to build C and Fortran extensions for official Python > > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > > required for C++ or amd64 though. (Intel's compiler requires VS2008, > > which has now perished.) > > mingw gcc should work for building C++ extensions if it also works for C > extensions. There's no difference on the binding side - you simply have > to include everything as extern "C", which I am sure the header does for > you. > > As for amd64 - I do not know if there is a mingw64 release for windows > already. If there isn't, there should be ;-) But that doesn't really > change anything: the express edition of Microsoft's VC++ doesn't include > an amd64 compiler anyway, AFAIK. The original version of the Windows 7 SDK includes the command line version of the VS 2008 amd64 compiler. I've used it compile MPIR and GMPY successfully. The GMPY source includes a text file describing the build process using the SDK tools. casevh > > Also, VS2010 should work as well - doesn't it? > > > > > > > Remember Python on Windows will still require VS2008 for a long time. > > Just take a look at the recent Python 3 loath threads.- Hide quoted text - > > - Show quoted text - From googler.1.webmaster at spamgourmet.com Tue Jul 6 16:02:12 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 6 Jul 2010 13:02:12 -0700 (PDT) Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: <33affa14-ded1-4742-a98f-c478df353352@w31g2000yqb.googlegroups.com> Good idea. Just one thing I thought about: Imagine I load them parallel so the GIL might interrupt the save-process of sys.modules, [ENSURE GIL] Load Script Save sys.modules [interrupt] Load Script Save sys.modules ... so this might run into several other problems. But maybe I change that so I load the scripts in a row. Thanks for your shoulder I can cry on ;) Bye, moerchendiser2k3 From sturlamolden at yahoo.no Tue Jul 6 16:19:57 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 13:19:57 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> On 6 Jul, 21:49, Christian Heimes wrote: > I agree, the situation isn't ideal. I see if I can get in contact with > Microsoft's open source team. Perhaps they can keep the download link to > VS 2008 EE working. It seems the MSDN subscription required to get VS 2008 costs one dollar less than $1200. So it does not fit within everyone's budget. From thudfoo at opensuse.us Tue Jul 6 16:35:40 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Tue, 6 Jul 2010 13:35:40 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C333243.7040205@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: > On 07/06/2010 04:12 AM, sturlamolden wrote: >> On 28 Jun, 19:39, Michael Torrie wrote: >> >>> In python I could simply take the output of "ps ax" and use python's >>> own, superior, cutting routines (using my module): >>> >>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>> for x in stdout.split('\n'): >>> ? ? print x.strip().split()[0] >> >> Or you just pass the stdout of one command as stdin to another. That >> is equivalent of piping with bash. > > Consider this contrived example: > > tail -f /var/log/messages | grep openvpn > > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. ?Then just read the final output in python. ?If you set > the stdout descriptor to non-blocking, you could read output as it came. > -- > http://mail.python.org/mailman/listinfo/python-list > Is this a discussion about the pipes module in the std library? From sturlamolden at yahoo.no Tue Jul 6 16:49:40 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 13:49:40 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 21:52, casevh wrote: > On Jul 6, 9:21?am, Thomas Jollans wrote: > > But that doesn't really > > change anything: the express edition of Microsoft's VC++ doesn't include > > an amd64 compiler anyway, AFAIK. See here: http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/ The express edition can be used as is for x86 though (it might not have an optimizing compiler). It can also be used for C++, unlike g++ (at least VC++ is safer). > The original version of the Windows 7 SDK includes the command line > version of the VS 2008 amd64 compiler. C:\Program Files\Microsoft SDKs\Windows\v7.0>cl Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64 Copyright (C) Microsoft Corporation. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] C:\Program Files\Microsoft SDKs\Windows\v7.0> Need any more proof? :D Also note that the Windows 7 SDK can still be used with IDEs, like Qt Creator, KDEvelop (yes there is a Windows version), Eclipse, Visual Studio, and even Visual C++ Express (a little PITA for amd64, but possible too). I'm still fan of a tiny text editor for typing (Kate from KDE tends to be my favorite) and a Python script for building, though. From love_ram2040 at yahoo.com Tue Jul 6 17:06:54 2010 From: love_ram2040 at yahoo.com (porxy) Date: Tue, 6 Jul 2010 14:06:54 -0700 (PDT) Subject: save your money and open all blocked sites now Message-ID: save your money and open all blocked sites now just enter to this proxy http://prog2010.zxq.net/proxy/ and put your site for free From pthibault33 at yahoo.ca Tue Jul 6 17:17:03 2010 From: pthibault33 at yahoo.ca (Pierre Thibault) Date: Tue, 6 Jul 2010 14:17:03 -0700 (PDT) Subject: Python install has difficulties with accented characters in path Message-ID: I am building from the source and installing Python on my machine. I added these tests failed: test_doctest test_httpservers test_logging But I moved the Python installation folder on another directory and the failed tests vanished when I tried again. The difference? The new directory does not have any accented characters in its name while the other one was having one. Should I flag this has a bug? I am installing Python 2.6.5. I am running OpenSuse 11.2 AMD64. From aahz at pythoncraft.com Tue Jul 6 17:29:20 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 14:29:20 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> <33affa14-ded1-4742-a98f-c478df353352@w31g2000yqb.googlegroups.com> Message-ID: In article <33affa14-ded1-4742-a98f-c478df353352 at w31g2000yqb.googlegroups.com>, moerchendiser2k3 wrote: > >Imagine I load them parallel so the GIL might interrupt the >save-process of sys.modules, > >[ENSURE GIL] >Load Script >Save sys.modules >[interrupt] >Load Script >Save sys.modules >... > >so this might run into several other problems. Very yes; if you're trying to maintain script independence, you should either run them sequentially (so you can safely save/restore the environment) or use processes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From thomas at jollans.com Tue Jul 6 17:34:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:34:40 +0200 Subject: Python Embedding Importing relative modules In-Reply-To: References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: <4C33A170.6060802@jollans.com> On 07/06/2010 09:11 PM, Aahz wrote: > In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, > moerchendiser2k3 wrote: >> Aahz: >>> >>> Set sys.path to include each script's base dir before running it, then >>> restore after each script. >> >> That works, but doesnt solve the problem. >> >> ScriptA.py has a module in its directory called 'bar.py' >> ScriptB.py has a module in its directory called 'bar.py' >> >> Imagine the 'bar.py' modules dont have the same content, so they are >> not equal. >> >> Now when the first bar.py is imported, the second import for a "import >> bar" imports the first one, because its already stored in sys.modules. > > Good point, you'll need to save/restore sys.modules, too. That gets you > 90-95% of complete namespace separation; if you need more than that, your > best bet is to use separate processes. Full-blown namepace isolation is > a *hard* problem, just look at all the past attempts to create secure > Python (and what you're trying to do is roughly equivalent). I believe Python (at least in the 3.x series) supports multiple interpreter instances per process. From thomas at jollans.com Tue Jul 6 17:37:24 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:37:24 +0200 Subject: Python install has difficulties with accented characters in path In-Reply-To: References: Message-ID: <4C33A214.2080208@jollans.com> On 07/06/2010 11:17 PM, Pierre Thibault wrote: > I am building from the source and installing Python on my machine. > > I added these tests failed: > > test_doctest > test_httpservers > test_logging > > But I moved the Python installation folder on another directory and > the failed tests vanished when I tried again. The difference? The new > directory does not have any accented characters in its name while the > other one was having one. > > Should I flag this has a bug? > > I am installing Python 2.6.5. I am running OpenSuse 11.2 AMD64. Before filing a bug, best test it with Python 2.7 (just released), 3.1, and, if possible, py3k trunk. I just tried to reproduce this with a current py3k checkout, where it worked. Probably not an issue in Python 3.x due to the changed unicode handling, but it might be a bug that has been fixed since 2.6. From thomas at jollans.com Tue Jul 6 17:45:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:45:05 +0200 Subject: A question about the posibility of raise-yield in Python In-Reply-To: <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <28847956-9af7-4280-acc9-dd7eca8dd1c3@t10g2000yqg.googlegroups.com> <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> Message-ID: <4C33A3E1.1070601@jollans.com> On 07/06/2010 08:56 PM, ?????? ??????????? wrote: >>>> I'm writing this as a complete newbie (on the issue), so don't be >>>> surprised if it's the stupidest idea ever. >>> >>>> I was wondering if there was ever a discusision in the python >>>> community on a 'raise-yield' kind-of combined expression. I'd like >>>> to know if it was proposed/rejected/discussed/not-decided yet?? >>> >>> Recently (ok, several hours ago) I've come up to Greenlets [1] and it >>> seems they implement exactly what I was asking for, in a C >>> extension!! >>> >>> It's too bad that Python doesn't support this by default and many >>> libraries won't make use of it by default. Gevent [2] for example, >>> has to monkey-patch Python's socket, time.sleep and other modules so >>> that things like urllib work with it. >>> >>> I'll continue to read now. >> >> Ah, if I had seen your original post I probably could have pointed you >> to some good reading right away. What you've described is called a >> continuation, and is natively supported by some languages (like >> Scheme). It's usually not done with exceptions, though. In Scheme >> it's a special form that looks like an ordinary function call, but you >> can "return" from the call any number of times. > > I thought they were called coroutines? The scheme call-with-current-continuation facility is a lot more powerful than python generator-coroutines or, I expect, than whatever it is that Lua has. In Python, you can return to a "yield" expression exactly once, then the code continues, and the state is lost. In Scheme, you can pass the state around, save it, and return there as often as you want. Kind of "go-back-to-this-particular-frame-state" as opposed to "go-back-into-that-(co)routine" Everything that you can do with the coroutine facilities in languages like Python, Ruby, and Lua, Scheme's call/cc allows you to do as well. Thomas From aahz at pythoncraft.com Tue Jul 6 17:56:53 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 14:56:53 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On 07/06/2010 09:11 PM, Aahz wrote: >> In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, >> moerchendiser2k3 wrote: >>> Aahz: >>>> >>>> Set sys.path to include each script's base dir before running it, then >>>> restore after each script. >>> >>> That works, but doesnt solve the problem. >>> >>> ScriptA.py has a module in its directory called 'bar.py' >>> ScriptB.py has a module in its directory called 'bar.py' >>> >>> Imagine the 'bar.py' modules dont have the same content, so they are >>> not equal. >>> >>> Now when the first bar.py is imported, the second import for a "import >>> bar" imports the first one, because its already stored in sys.modules. >> >> Good point, you'll need to save/restore sys.modules, too. That gets you >> 90-95% of complete namespace separation; if you need more than that, your >> best bet is to use separate processes. Full-blown namepace isolation is >> a *hard* problem, just look at all the past attempts to create secure >> Python (and what you're trying to do is roughly equivalent). > >I believe Python (at least in the 3.x series) supports multiple >interpreter instances per process. Perhaps things have changed in 3.x, but although 2.x supposedly supported multiple interpreter instances per process, the impression I got was that most people would rather poke their eyes out with a dull stick than try to make multiple interpreters per process actually work. Multiple processes are easy, OTOH. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From cournape at gmail.com Tue Jul 6 18:08:00 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 7 Jul 2010 00:08:00 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet wrote: > * sturlamolden, on 06.07.2010 17:50: >> >> Just a little reminder: >> >> Microsoft has withdrawn VS2008 in favor of VS2010. The express version >> is also unavailable for download.>:(( >> >> We can still get a VC++ 2008 compiler required to build extensions for >> the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK >> for .NET 3.5 SP1): >> >> >> http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en >> >> Download today, before it goes away! >> >> Microsoft has now published a download for Windows 7 SDK for .NET 4. >> It has the VC++ 2010 compiler. It can be a matter of days before the VC >> ++ 2008 compiler is totally unavailable. >> >> It is possible to build C and Fortran extensions for official Python >> 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is >> required for C++ or amd64 though. (Intel's compiler requires VS2008, >> which has now perished.) >> >> Remember Python on Windows will still require VS2008 for a long time. >> Just take a look at the recent Python 3 loath threads. > > Perhaps this all for the good. > > There is no *technical* problem creating a compiler-independent C/C++ > language binding. It is quite hard, though, or would require changes in the API to be entirely safe. When I asked the question a few months ago to see if we could fix those issues once and for all for numpy, the most common answer I got was to pass all the related functions in a structure: http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. The problem is not compiler, but really C runtimes. By itself, the issues are not windows specific (using malloc from one C library and one free from another one is trouble everywhere), but on windows: - multiple C runtimes are *very* common on windows - many things which are runtime independent on unix are not on windows (file descriptor: AFAIK, a file descriptor as returned from open can be dealt with in any C runtime on unix) - the MS standard C library is clearly not a priority: win32 specific objects can be shared across runtimes, but standard C rarely can. - the recent manifest concept (which can improve or worsen the issues) is incredibly convoluted, and poorly documented (they expect you to use MS tool and not to try to understand how it works). David From thomas at jollans.com Tue Jul 6 18:26:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 00:26:53 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33ADAD.9090606@jollans.com> On 07/07/2010 12:08 AM, David Cournapeau wrote: > On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet > wrote: >> There is no *technical* problem creating a compiler-independent C/C++ >> language binding. > > It is quite hard, though, or would require changes in the API to be > entirely safe. When I asked the question a few months ago to see if we > could fix those issues once and for all for numpy, the most common > answer I got was to pass all the related functions in a structure: > http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. > > The problem is not compiler, but really C runtimes. By itself, the > issues are not windows specific (using malloc from one C library and > one free from another one is trouble everywhere), but on windows: > - multiple C runtimes are *very* common on windows I'm also rather sure that it's pretty much impossible to have multiple C libraries in one process on UNIX, but it's obviously quite possible on Windows. > - many things which are runtime independent on unix are not on > windows (file descriptor: AFAIK, a file descriptor as returned from > open can be dealt with in any C runtime on unix) Are you telling me that file descriptors (it's a flippin int!) can't be passed around universally on Windows?? Now Windows programming *really* scares me. > - the MS standard C library is clearly not a priority: win32 specific > objects can be shared across runtimes, but standard C rarely can. And, as has already been said in this thread, this does not concern the .net developer, or any developer that sticks to managed code, be it .net, CPython, or something-else based. > - the recent manifest concept (which can improve or worsen the > issues) is incredibly convoluted, and poorly documented (they expect > you to use MS tool and not to try to understand how it works). Cheers, Thomas From martin at v.loewis.de Tue Jul 6 18:38:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 00:38:06 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33B04E.8040303@v.loewis.de> >> - many things which are runtime independent on unix are not on >> windows (file descriptor: AFAIK, a file descriptor as returned from >> open can be dealt with in any C runtime on unix) > > Are you telling me that file descriptors (it's a flippin int!) can't be > passed around universally on Windows?? There are really three things of concern here: a) operating system file handles, of type HANDLE (which is an unsigned 32-bit value); they are not contiguous, and stdin/stdout/stderr may have arbitrary numbers b) C runtime file handles, of type int. They are contiguous, and stdin/stdout/stderr are 0/1/2. c) C FILE*. OS handles can be passed around freely within a process; across processes, they lose their meaning It's the data of types b) and c) that cause problems: the CRT handle 4 means different things depending on what copy of the CRT is interpreting it. It's worse with FILE*: passing a FILE* of one CRT to the fread() implementation of a different CRT will cause a segfault. > And, as has already been said in this thread, this does not concern the > .net developer, or any developer that sticks to managed code, be it > .net, CPython, or something-else based. Since when is CPython managed code? Regards, Martin From sturlamolden at yahoo.no Tue Jul 6 18:41:04 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 15:41:04 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <2b9aa6a5-757d-4fc8-8f51-49706594a82d@y4g2000yqy.googlegroups.com> On 6 Jul, 21:52, casevh wrote: > The original version of the Windows 7 SDK includes the command line > version of the VS 2008 amd64 compiler. I've used it compile MPIR and > GMPY successfully. The GMPY source includes a text file describing the > build process using the SDK tools. It should also be mentioned that the Windows 7 SDK includes vcbuild.exe, so it can be used to compile Visual Studio 2008 projects (I'm going to try Python). From martin.hellwig at dcuktec.org Tue Jul 6 18:41:10 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 06 Jul 2010 23:41:10 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> References: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> Message-ID: On 07/06/10 21:19, sturlamolden wrote: > On 6 Jul, 21:49, Christian Heimes wrote: > >> I agree, the situation isn't ideal. I see if I can get in contact with >> Microsoft's open source team. Perhaps they can keep the download link to >> VS 2008 EE working. > > It seems the MSDN subscription required to get VS 2008 costs one > dollar less than $1200. So it does not fit within everyone's budget. > > Take in the cost of your operating system, and the ones you want to test against, perhaps you also like to use office. Although I am not a windows developer per se, I do use windows XP, 2000 2003, 2008, Vista and 7 for testing. I also use office for all those clients who think that this is the only format. 1200 USD is actually quite cheap, but then again I didn't pay that because I am either always been in an academic license (about 70 EUR a year) or like now in a program for businesses who just start up (free with my bank as supporting agent). When this 3 year subscription is over I fall anyway in the cheaper renewals and if not I am sure that there is some other brand new scheme like they did for the last decade. Anyway, if you want to provide tools for platforms that are closed source that means that there are costs for the developer and the client. Although the cost for MS platforms are reasonable (as a developer and you know you way around, that means go a couple of times to those free MS events and it is quite likely you get an MSDN subscription for being such a good loyal puppy), there are always costs. If you don't like that better convince your target audience about an open source operating system, whichever that may be. -- mph From ssquma at gmail.com Tue Jul 6 18:50:10 2010 From: ssquma at gmail.com (=?ISO-8859-1?Q?Jose_=C1ngel_Quintanar_Morales?=) Date: Tue, 6 Jul 2010 17:50:10 -0500 Subject: Help with movie module Message-ID: Hi, I'm sorry by my bad english. I have a little problem with pygame.movie module when I try work whit him show this problem [joseangel at qumax reproductor]$ python packbox.py packbox.py:64: RuntimeWarning: use mixer: No module named mixer (ImportError: No module named mixer) pygame.mixer.quit() Traceback (most recent call last): File "packbox.py", line 98, in main() File "packbox.py", line 95, in main publicidad_show(screen) File "packbox.py", line 64, in publicidad_show pygame.mixer.quit() File "/usr/lib/python2.6/site-packages/pygame/__init__.py", line 70, in __getattr__ raise NotImplementedError(MissingPygameModule) NotImplementedError: mixer module not available (ImportError: No module named mixer) anybody help me please, I'm search in the web and I found this email list. thanks Jos? angel -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Tue Jul 6 18:57:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 15:57:21 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <2b9aa6a5-757d-4fc8-8f51-49706594a82d@y4g2000yqy.googlegroups.com> Message-ID: On 7 Jul, 00:41, sturlamolden wrote: > It should also be mentioned that the Windows 7 SDK includes > vcbuild.exe, so it can be used to compile Visual Studio 2008 projects > (I'm going to try Python). Not sure why I forgot to mention, but we can (or even should?) use CMake to generate these project files. We don't need Visual Studio for that. From thomas at jollans.com Tue Jul 6 19:07:22 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 01:07:22 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33B04E.8040303@v.loewis.de> References: <4C33B04E.8040303@v.loewis.de> Message-ID: <4C33B72A.3020109@jollans.com> On 07/07/2010 12:38 AM, Martin v. Loewis wrote: >>> - many things which are runtime independent on unix are not on >>> windows (file descriptor: AFAIK, a file descriptor as returned from >>> open can be dealt with in any C runtime on unix) >> >> Are you telling me that file descriptors (it's a flippin int!) can't be >> passed around universally on Windows?? > > There are really three things of concern here: > a) operating system file handles, of type HANDLE (which is an unsigned > 32-bit value); they are not contiguous, and stdin/stdout/stderr may > have arbitrary numbers > b) C runtime file handles, of type int. They are contiguous, and > stdin/stdout/stderr are 0/1/2. > c) C FILE*. > > OS handles can be passed around freely within a process; across > processes, they lose their meaning > > It's the data of types b) and c) that cause problems: the CRT handle 4 > means different things depending on what copy of the CRT is interpreting it. Ah, okay. On UNIX systems, of course, a) and b) are identical. > > It's worse with FILE*: passing a FILE* of one CRT to the fread() > implementation of a different CRT will cause a segfault. > >> And, as has already been said in this thread, this does not concern the >> .net developer, or any developer that sticks to managed code, be it >> .net, CPython, or something-else based. > > Since when is CPython managed code? It's not managed code in the "runs on .net" sense, but in principle, it is managed, in that garbage collection is managed for you. From sturlamolden at yahoo.no Tue Jul 6 19:14:28 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 16:14:28 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33B04E.8040303@v.loewis.de> Message-ID: <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> On 7 Jul, 01:07, Thomas Jollans wrote: > It's not managed code in the "runs on .net" sense, but in principle, it > is managed, in that garbage collection is managed for you. I think you are confusing Python and C code. From thomas at jollans.com Tue Jul 6 19:26:54 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 01:26:54 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> References: <4C33B04E.8040303@v.loewis.de> <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> Message-ID: <4C33BBBE.7030805@jollans.com> On 07/07/2010 01:14 AM, sturlamolden wrote: > On 7 Jul, 01:07, Thomas Jollans wrote: > >> It's not managed code in the "runs on .net" sense, but in principle, it >> is managed, in that garbage collection is managed for you. > > I think you are confusing Python and C code. Or somebody's confusing something anyway I meant "CPython based", which, in hindsight, might have not have been clear from the grammatically obfuscated sentence I posted. From rodrick.brown at gmail.com Tue Jul 6 20:22:58 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 6 Jul 2010 20:22:58 -0400 Subject: Help with movie module In-Reply-To: References: Message-ID: Did you try emailing the author of this application? 2010/7/6 Jose ?ngel Quintanar Morales > Hi, I'm sorry by my bad english. > > I have a little problem with pygame.movie module when I try work whit him > show this problem > > [joseangel at qumax reproductor]$ python packbox.py > packbox.py:64: RuntimeWarning: use mixer: No module named mixer > (ImportError: No module named mixer) > pygame.mixer.quit() > Traceback (most recent call last): > File "packbox.py", line 98, in > main() > File "packbox.py", line 95, in main > publicidad_show(screen) > File "packbox.py", line 64, in publicidad_show > pygame.mixer.quit() > File "/usr/lib/python2.6/site-packages/pygame/__init__.py", line 70, in > __getattr__ > raise NotImplementedError(MissingPygameModule) > NotImplementedError: mixer module not available > (ImportError: No module named mixer) > > > anybody help me please, I'm search in the web and I found this email list. > > thanks > > Jos? angel > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 6 20:27:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jul 2010 17:27:57 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 1:35 PM, member thudfoo wrote: > On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >> On 07/06/2010 04:12 AM, sturlamolden wrote: >>> On 28 Jun, 19:39, Michael Torrie wrote: >>>> In python I could simply take the output of "ps ax" and use python's >>>> own, superior, cutting routines (using my module): >>>> >>>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>>> for x in stdout.split('\n'): >>>> ? ? print x.strip().split()[0] >>> >>> Or you just pass the stdout of one command as stdin to another. That >>> is equivalent of piping with bash. >> >> Consider this contrived example: >> >> tail -f /var/log/messages | grep openvpn >> >> While it's possible to set up pipes and spawn programs in parallel to >> operate on the pipes, in practice it's simpler to tell subprocess.Popen >> to use a shell and then just rely on Bash's very nice syntax for setting >> up the pipeline. ?Then just read the final output in python. ?If you set >> the stdout descriptor to non-blocking, you could read output as it came. > > Is this a discussion about the pipes module in the std library? No, though that module is not irrelevant to Mr. Torrie's argument. Cheers, Chris -- http://blog.rebertia.com From pthibault33 at yahoo.ca Tue Jul 6 20:39:33 2010 From: pthibault33 at yahoo.ca (Pierre Thibault) Date: Tue, 6 Jul 2010 17:39:33 -0700 (PDT) Subject: Python install has difficulties with accented characters in path References: Message-ID: On 6 juil, 17:37, Thomas Jollans wrote: > Before filing a bug, best test it with Python 2.7 (just released), 3.1, > and, if possible, py3k trunk. > > I just tried to reproduce this with a current py3k checkout, where it > worked. Probably not an issue in Python 3.x due to the changed unicode > handling, but it might be a bug that has been fixed since 2.6. I've tested with the version 2.7 and the issue is gone. From luismgz at gmail.com Tue Jul 6 22:09:14 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 6 Jul 2010 19:09:14 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On Jul 2, 4:07?pm, John Nagle wrote: > David Cournapeau wrote: > > I think one point which needs to be emphasized more is what does > > python 3 bring to people. The" what's new in python 3 page" gives > > the impression that python 3 is about removing cruft. That's a very > > poor argument to push people to switch. > > ? ? That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? ? It's not faster. > It doesn't do anything you can't do in Python 2.6. ?There's no > "killer app" for it. End of life for Python 2.x is many years away; > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? > > ? ? If Python 3 came with Unladen Swallow, and ran several times > faster than Python 2.x, there'd be a strong business case for > conversion. ?Especially for large sites with racks of servers > grinding through slow CPython code. ?But it looks like Unladen > Swallow will be available for 2.6 before it's available for 3.x. > So that's not a selling point for 3.x. > > ? ? Python 3 is a nice cleanup of some legacy syntax issues. ?But > that's just not enough. ?Perl 6 is a nice cleanup of Perl 5, and > look how that went. ?Ten years on, it's not even mainstream, let > alone dominant. > > ? ? This has all been said before. See "Python 3.0: What s The Point?" > from December 2008: > > http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ > > ? ? Not much has changed since then. > > ? ? What I'm not seeing is a deployment plan along these lines: > > ? ? 1. ?Identify key modules which must be converted before Python 3 > ? ? ? ? can be used in production environments. > > ? ? 2. ?Get those modules converted to Python 3. > > ? ? 3. ?Put together a distribution for the major platforms (at least > ? ? ? ? Linux and Windows) with builds of those modules. ?This > ? ? ? ? could be done on PyPi, which is at present is mostly a link > ? ? ? ? farm, not a repository. > > ? ? 4. ?Get some major distros, like Debian and ActiveState, to > ? ? ? ? include Python 3, as "python3", not as the primary Python, > ? ? ? ? so there are no conflicts. ?(Debian already has a formal > ? ? ? ? policy to keep Python versions separate.) > > ? ? 5. ?Get at least two major hosting services to put up Python 3. > > ? ? 6. ?Get at least two popular end-user programs (not modules) to > ? ? ? ? support Python 3. > > ? ? 7. ?Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle What's the problem? Python 2.xx will he around for a long time. It will be supported and you can use it for your existing projects for as long a you want. On the other hand, if you have a new project and you plan to make it successful and usable for many years to come, you should seriously consider using Python 3. From alf.p.steinbach+usenet at gmail.com Tue Jul 6 22:11:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 04:11:10 +0200 Subject: Argh! Name collision! Message-ID: Donald Knuth once remarked (I think it was him) that what matters for a program is the name, and that he'd come up with a really good name, now all he'd had to do was figure out what it should be all about. And so considering Sturla Molden's recent posting about unavailability of MSVC 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and my unimaginative reply proposing names like "pni" and "pynacoin" for a compiler independent Python native code interface, suddenly, as if out of thin air, or perhaps out of fish pudding, the name "pyni" occurred to me. "pyni"! Pronounced like "tiny"! Yay! I sat down and made my first Python extension module, following the tutorial in the docs. It worked! But, wait, perhaps some other extension is already named "piny"? Google. , "PyNI is [a] config file reader/writer". Argh! - Alf -- blog at From chardster at gmail.com Tue Jul 6 22:51:30 2010 From: chardster at gmail.com (Richard Thomas) Date: Tue, 6 Jul 2010 19:51:30 -0700 (PDT) Subject: Argh! Name collision! References: Message-ID: On Jul 7, 3:11?am, "Alf P. Steinbach /Usenet" wrote: > Donald Knuth once remarked (I think it was him) that what matters for a program > is the name, and that he'd come up with a really good name, now all he'd had to > do was figure out what it should be all about. > > And so considering Sturla Molden's recent posting about unavailability of MSVC > 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and my > unimaginative reply proposing names like "pni" and "pynacoin" for a compiler > independent Python native code interface, suddenly, as if out of thin air, or > perhaps out of fish pudding, the name "pyni" occurred to me. > > "pyni"! Pronounced like "tiny"! Yay! > > I sat down and made my first Python extension module, following the tutorial in > the docs. It worked! > > But, wait, perhaps some other extension is already named "piny"? > > Google. > > , "PyNI is [a] config file reader/writer". > > Argh! > > - Alf > > -- > blog at PyNI seems to perform the same function as ConfigParser. I prefer the pronunciation like tiny to Py-N-I. The latter seems clunky. On a possibly related note I was disappointed to discover that Python's QT bindings are called PyQT not QTPy. :-) Chard. From anand.shashwat at gmail.com Tue Jul 6 23:25:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 7 Jul 2010 08:55:12 +0530 Subject: Argh! Name collision! In-Reply-To: References: Message-ID: On Wed, Jul 7, 2010 at 8:21 AM, Richard Thomas wrote: > On Jul 7, 3:11 am, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > > Donald Knuth once remarked (I think it was him) that what matters for a > program > > is the name, and that he'd come up with a really good name, now all he'd > had to > > do was figure out what it should be all about. > > > > And so considering Sturla Molden's recent posting about unavailability of > MSVC > > 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and > my > > unimaginative reply proposing names like "pni" and "pynacoin" for a > compiler > > independent Python native code interface, suddenly, as if out of thin > air, or > > perhaps out of fish pudding, the name "pyni" occurred to me. > > > > "pyni"! Pronounced like "tiny"! Yay! > > > > I sat down and made my first Python extension module, following the > tutorial in > > the docs. It worked! > > > > But, wait, perhaps some other extension is already named "piny"? > > > > Google. > > > > , "PyNI is [a] config file > reader/writer". > > > > Argh! > > > > - Alf > > > > -- > > blog at > > PyNI seems to perform the same function as ConfigParser. I prefer the > pronunciation like tiny to Py-N-I. The latter seems clunky. > > On a possibly related note I was disappointed to discover that > Python's QT bindings are called PyQT not QTPy. :-) > Isn't this the standard. Qt -> PyQt crypto -> pycrypto MT -> PyMT ..... and the list goes on and on .. :) ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 6 23:34:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jul 2010 20:34:06 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C333243.7040205@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: > On 07/06/2010 04:12 AM, sturlamolden wrote: >> On 28 Jun, 19:39, Michael Torrie wrote: >>> In python I could simply take the output of "ps ax" and use python's >>> own, superior, cutting routines (using my module): >>> >>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>> for x in stdout.split('\n'): >>> ? ? print x.strip().split()[0] >> >> Or you just pass the stdout of one command as stdin to another. That >> is equivalent of piping with bash. > > Consider this contrived example: > > tail -f /var/log/messages | grep openvpn > > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. Until there's a Python variable involved that is, unless you want to overlook all the edge cases or do the escaping all by yourself (and then pray you did it right). Cheers, Chris -- http://blog.rebertia.com From me+list/python at ixokai.io Tue Jul 6 23:35:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 20:35:15 -0700 Subject: Argh! Name collision! In-Reply-To: References: Message-ID: <4C33F5F3.4060704@ixokai.io> On 7/6/10 8:25 PM, Shashwat Anand wrote: > On Wed, Jul 7, 2010 at 8:21 AM, Richard Thomas > wrote: > On a possibly related note I was disappointed to discover that > Python's QT bindings are called PyQT not QTPy. :-) > Isn't this the standard. > Qt -> PyQt > crypto -> pycrypto > MT -> PyMT I think the point is QTPy would be pronounced "cutie pie" :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From cournape at gmail.com Tue Jul 6 23:40:43 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 7 Jul 2010 05:40:43 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33ADAD.9090606@jollans.com> References: <4C33ADAD.9090606@jollans.com> Message-ID: On Wed, Jul 7, 2010 at 12:26 AM, Thomas Jollans wrote: > On 07/07/2010 12:08 AM, David Cournapeau wrote: >> On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet >> wrote: >>> There is no *technical* problem creating a compiler-independent C/C++ >>> language binding. >> >> It is quite hard, though, or would require changes in the API to be >> entirely safe. When I asked the question a few months ago to see if we >> could fix those issues once and for all for numpy, the most common >> answer I got was to pass all the related functions in a structure: >> http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. >> >> The problem is not compiler, but really C runtimes. By itself, the >> issues are not windows specific (using malloc from one C library and >> one free from another one is trouble everywhere), but on windows: >> ?- multiple C runtimes are *very* common on windows > > I'm also rather sure that it's pretty much impossible to have multiple C > libraries in one process on UNIX, but it's obviously quite possible on > Windows. I am not sure why you think it is not possible. It is rare, though. > >> ?- many things which are runtime independent on unix are not on >> windows (file descriptor: AFAIK, a file descriptor as returned from >> open can be dealt with in any C runtime on unix) > > Are you telling me that file descriptors (it's a flippin int!) can't be > passed around universally on Windows?? Yes. The reason why it does not work on windows is because file descriptor are not "native": in every unix I have heard of, file descriptor are indexes in a table of the process "structure", hence can be shared freely (no dependency on the C runtime structures). On windows, I have heard they are emulated (the native one is the win32 file handle). David From alf.p.steinbach+usenet at gmail.com Wed Jul 7 00:54:41 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 06:54:41 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 06.07.2010 19:35: > On 6 Jul, 19:09, Thomas Jollans wrote: > >> Okay, you need to be careful with FILE*s. But malloc and free? You'd >> normally only alloc& free something within the same module, using the >> same functions (ie not mixing PyMem_Malloc and malloc), would you not? > > You have to be sure PyMem_Malloc is not an preprocessor alias for > malloc (I haven't chaecked). Python 3.1.1, file [pymem.h]: PyAPI_FUNC(void *) PyMem_Malloc(size_t); #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ : malloc((n) ? (n) : 1)) The problem with the latter that it seems that it's intended for safety but does the opposite... Perhaps (if it isn't intentional) this is a bug of the oversight type, that nobody remembered to update the macro? *** Except for the problems with file descriptors I think a practical interim solution for extensions implemented in C could be to just link the runtime lib statically. For a minimal extension this increased the size from 8 KiB to 49 KiB. And generally with MS tools the size is acceptably small. I think that this would be safe because since the C API has to access things in the interpreter I think it's a given that all the relevant functions delegate to shared library (DLL) implementations, but I have not checked the source code. As a more longterm solution, perhaps python.org could make available the redistributables for various MSVC versions, and then one could introduce some scheme for indicating the runtime lib dependencies of any given extension. Then when installing an extension the installer (distutils package functionality) could just check whether the required runtime is present, and if not give the user the choice of automatically downloading from python.org, or perhaps direct from Microsoft. This scheme would support dependencies on new runtime lib versions not yet conceived when the user's version of Python was installed. Cheers, - Alf -- blog at From rantingrick at gmail.com Wed Jul 7 01:42:25 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 22:42:25 -0700 (PDT) Subject: Argh! Name collision! References: Message-ID: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> On Jul 6, 9:11?pm, "Alf P. Steinbach /Usenet" wrote: > "pyni"! Pronounced like "tiny"! Yay! hmm, how's about an alternate spelling... "pyknee", or "pynee", or "pynie" ... considering those are not taken either? From timr at probo.com Wed Jul 7 02:21:49 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 06 Jul 2010 23:21:49 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: sturlamolden wrote: > >Just a little reminder: > >Microsoft has withdrawn VS2008 in favor of VS2010. Nonsense. They have released VS2010, but they certainly have not "withdrawn" VS2008, and I have heard of no plans to do so. >The express version is also unavailable for download. >:(( Also nonsense. Get it from right here: http://www.microsoft.com/express/downloads/ Note the three tabs: VS2010, SQL Server R2, and VS2008. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From me+list/python at ixokai.io Wed Jul 7 02:46:46 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 23:46:46 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C3422D6.9030702@ixokai.io> On 7/6/10 11:21 PM, Tim Roberts wrote: > sturlamolden wrote: >> >> Just a little reminder: >> >> Microsoft has withdrawn VS2008 in favor of VS2010. > > Nonsense. They have released VS2010, but they certainly have not > "withdrawn" VS2008, and I have heard of no plans to do so. Its not nonsense; Microsoft has historically made unavailable fairly quickly previous versions of the suite after a new release is out. There hasn't been any serious notification of this before it happens. The concern here is not at all without precedent. There has been some very real pain for Python extension authors/maintainers directly related to what compilers and SDK's Microsoft makes available: generally, Python is 'behind' the times of what's the latest version of VS and their SDK that is available. >> The express version is also unavailable for download. >:(( > > Also nonsense. Get it from right here: > http://www.microsoft.com/express/downloads/ > > Note the three tabs: VS2010, SQL Server R2, and VS2008. Again, not nonsense. That's available now. However, very real experience has made certain people *very* reasonably cautious about when "now" becomes "the past" in this situation: what is available now may change as soon as tomorrow or later with very little real notice. Yeah, you can get a MSDN subscription and get access to a lot. Lots of people can't afford that just to compile an extension they support. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From durumdara at gmail.com Wed Jul 7 03:18:18 2010 From: durumdara at gmail.com (durumdara) Date: Wed, 7 Jul 2010 00:18:18 -0700 (PDT) Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? Message-ID: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Hi! I have an environment under Python 2.6 (WinXP). That is based on PIL, wxPython/PyWin32. In the project's pages I see official installer for only PyWin32. I don't know that PIL or wxPython supports Python 3 or not. May with some trick these packages are working. Does anybody know about it? Can I replace my Py2.6 without lost PIL/wxPython? Thanks for your help: dd From stefan_ml at behnel.de Wed Jul 7 03:19:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Jul 2010 09:19:07 +0200 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: John Nagle, 28.06.2010 19:57: > Programs have "argv" and "argc", plus environment variables, > going in. So, going in, there are essentially subroutine parameters. > But all that comes back is an exit code. They should have had > something similar coming back, with arguments to "exit()" returning > the results. Then the "many small intercommunicating programs" > concept would have worked much better. Except that you just broke the simplicity of the pipe mechanism. Stefan From johan.gronqvist at gmail.com Wed Jul 7 03:38:21 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Wed, 07 Jul 2010 09:38:21 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> Message-ID: 2010-07-06 19:18, Ritchy lelis skrev: > On 6 jul, 17:29, Alan G Isaac wrote: >> Unfortunately I cannot make sense of the code you posted. >> Provide a detailed description in words (or psuedocode) >> of what you are trying to accomplish. Be very careful >> and detailed is you want a useful response. >> >> Alan Isaac > > hummm... > > ok, i will try to make that detailed description. I can tell you why I do not understand from your posted code what you are trying to do. Firstly, I do not understand if you are trying to plot a surface, a set of curves, or a curve, or just a set of points? In your posted code, the plot command is part of the else clause, and my guess is that you never intend the else-clause to be executed at all. In your code snippet you loop over two arrays (Vi and Vref), compute a scalar value V0, and all plot-commands you issue are of the form plot(V0). This will probably draw a line of one point (for each value in Vi and Vref), which may not be what you want, and if it draws anything at all, then all points will be drawn at the same x-value, which is also probably not what you want. Secondly, how are the Vi and Vref related to your axes? I assume you want to plot all values you compute for V0, but as a function of what? When I use the plot command, I usually give it (at least) two arguments, where the first is the x-axis, and the second is the y-axis. After I have understood those things, the next question would be about the maths relating the Vi and Vref values to the V0 values, but I do not think I will understand those until after the above points are explained clearer. I definitely think your english is not a problem here. Johan From ptmcg at austin.rr.com Wed Jul 7 04:31:50 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jul 2010 01:31:50 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 6, 3:30 am, David Cournapeau wrote: > On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > > One thing that would be very useful is how to maintain something that > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > versions below 2.6 is out of the question for most projects with a > significant userbase IMHO. As such, the idea of running the python 3 > warnings is not so useful IMHO - unless it could be made to work > better for python 2.x < 2.6, but I am not sure the idea even makes > sense. > This is exactly how I felt about my support for pyparsing, that I was trying continue to provide support for 2.3 users, up through 3.x users, with a single code base. (This would actually have been possible if I had been willing to introduce a performance penalty for Python 2 users, but performance is such a critical issue for parsing I couldn't justify it to myself.) This meant that I had to constrain my implementation, while trying to incorporate forward-looking support features (such as __bool__ and __dir__), which have no effect on older Python versions, but support additions in newer Pythons. I just couldn't get through on the python-dev list that I couldn't just upgrade my code to 2.6 and then use 2to3 to keep in step across the 2-3 chasm, as this would leave behind my faithful pre-2.6 users. Here are some of the methods I used: - No use of sets. Instead I defined a very simple set simulation using dict keys, which could be interchanged with set for later versions. - No generator expressions, only list comprehensions. - No use of decorators. BUT, pyparsing includes a decorator method, traceParseAction, which can be used by users with later Pythons as @traceParseAction in their own code. - No print statements. As pyparsing is intended to be an internal module, it does no I/O as part of its function - it only processes a given string, and returns a data structure. - Python 2-3 compatible exception syntax. This may have been my trickiest step. The change of syntax for except from except ExceptionType, ex: to: except ExceptionType as ex: is completely forward and backward incompatible. The workaround is to rewrite as: except ExceptionType: ex = sys.exc_info()[0] which works just fine in 2.x and 3.x. However, there is a slight performance penalty in doing this, and pyparsing uses exceptions as part of its grammar success/failure signalling and backtracking; I've used this technique everywhere I can get away with it, but there is one critical spot where I can't use it, so I have to keep 2 code bases with slight differences between them. - Implement __bool__, followed by __nonzero__ = __bool__. This will give you boolean support for your classes in 2.3-3.1. - Implement __dir__, which is unused by old Pythons, but supports customization of dir() output for your own classes. - Implement __len__, __contains__, __iter__ and __reversed__ for container classes. - No ternary expressions. Not too difficult really, there are several well-known workarounds for this, either by careful use of and's and or's, or using the bool-as-int to return the value from (falseValue,trueValue)[condition]. - Define a version-sensitive portion of your module, to define synonyms for constants that changed name between versions. Something like: _PY3K = sys.version_info[0] > 2 if _PY3K: _MAX_INT = sys.maxsize basestring = str _str2dict = set alphas = string.ascii_lowercase + string.ascii_uppercase else: _MAX_INT = sys.maxint range = xrange _str2dict = lambda strg : dict( [(c,0) for c in strg] ) alphas = string.lowercase + string.uppercase The main body of my code uses range throughout (for example), and with this definition I get the iterator behavior of xrange regardless of Python version. In the end I still have 2 source files, one for Py2 and one for Py3, but there is only a small and manageable number of differences between them, and I expect at some point I will move forward to supporting Py3 as my primary target version. But personally I think this overall Python 2-3 migration process is moving along at a decent rate, and I should be able to make my switchover in another 12-18 months. But in the meantime, I am still able to support all versions of Python NOW, and I plan to continue doing so (albeit "support" for 2.x versions will eventually mean "continue to offer a frozen feature set, with minimal bug-fixing if any"). I realize that pyparsing is a simple-minded module in comparison to others: it is pure Python, so it has no issues with C extensions; it does no I/O, so print-as-statement vs. print-as-function is not an issue; and it imports few other modules, so the ones it does have not been dropped in Py3; and overall it is only a few thousand lines of code. But I just offer this post as a concrete data point in this discussion. -- Paul From no.email at nospam.invalid Wed Jul 7 04:58:51 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 01:58:51 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <7xiq4racs4.fsf@ruckus.brouhaha.com> Paul McGuire writes: > is completely forward and backward incompatible. The workaround is to > rewrite as: > > except ExceptionType: > ex = sys.exc_info()[0] > > which works just fine in 2.x and 3.x. Are you sure? I wonder if there might be some race condition that could make it fail. I didn't even know about (or forgot) this change. Yucch. From thomas at jollans.com Wed Jul 7 05:06:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 11:06:40 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <7xiq4racs4.fsf@ruckus.brouhaha.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <7xiq4racs4.fsf@ruckus.brouhaha.com> Message-ID: <4C3443A0.4020800@jollans.com> On 07/07/2010 10:58 AM, Paul Rubin wrote: > Paul McGuire writes: >> is completely forward and backward incompatible. The workaround is to >> rewrite as: >> >> except ExceptionType: >> ex = sys.exc_info()[0] >> >> which works just fine in 2.x and 3.x. > > Are you sure? I wonder if there might be some race condition that could > make it fail. Luckily, no: (lib. docs on exc_info()) This function returns a tuple of three values that give information about the exception that is currently being handled. The information returned is specific both to the current thread and to the current stack frame. > > I didn't even know about (or forgot) this change. Yucch. From debatem1 at gmail.com Wed Jul 7 05:29:05 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 05:29:05 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: > On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >> >> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >> >>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk > >>>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>>> single C codebase. I'd be willing to contribute my experiences to a >>>> document >>>> somewhere. (Is there a Wiki?) >>> >>> Indeed there is: http://wiki.python.org/moin/ >> >> Thanks. I don't want to appear ungrateful, but I was hoping for >> something specific to the 2-to-3 conversion. I guess someone has to >> start somewhere... > > There is an existing 2to3 and other pages for Python code conversion. I do > not know of any for CAPI conversion. The need for such has been acknowledged > among the devs but if there is nothing yet, we need someone with specialized > experience and a bit of time to make a first draft. If you start one, give > it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from > the 2to3 page > > In his post on this thread, Martin Loewis volunteered to list what he knows > from psycopg2 if someone else will edit. I'm not sure why I don't have this post, but I'm happy to help edit etc if Martin wants to put together a rough draft. Geremy Condra From tartley at tartley.com Wed Jul 7 05:32:14 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 7 Jul 2010 02:32:14 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> On Jul 6, 4:50?pm, sturlamolden wrote: > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download. >:(( > > We can still get a VC++ 2008 compiler required to build extensions for > the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C59... > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days before the VC > ++ 2008 compiler is totally unavailable. I presume this problem would go away if future versions of Python itself were compiled on Windows with something like MinGW gcc. Also, this would solve the pain of Python developers attempting to redistribute py2exe versions of their programs (i.e. they have to own a Visual Studio license to legally be able to redistribute the required C runtime) I don't understand enough to know why Visual Studio was chosen instead of MinGW. Can anyone shed any light on that decision? Many thanks Jonathan Hartley From hnsri49 at gmail.com Wed Jul 7 05:53:50 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Wed, 7 Jul 2010 15:53:50 +0600 Subject: Problem With the PyRtf Footers Message-ID: Hi all, Am using the pyrtf for the generating the rtf documents from the html.Am able to generate the documents the problem is with the footer.Its coming only for the first page for the rest of the pages it is coming empty.Am using the section.FirstFooter for the first page footer and section.Footer for the subsequent pages.I am not able to figure out what is exactly the problem.If any body knows please help me. Thanks in Advance ! Srinivas HN ph-9986229891 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dm at tu-clausthal.de Wed Jul 7 07:52:12 2010 From: dm at tu-clausthal.de (david mainzer) Date: Wed, 07 Jul 2010 13:52:12 +0200 Subject: Python -- floating point arithmetic Message-ID: <4C346A6C.5090903@tu-clausthal.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA384 Dear Python-User, today i create some slides about floating point arithmetic. I used an example from http://docs.python.org/tutorial/floatingpoint.html so i start the python shell on my linux machine: dm at maxwell $ python Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sum = 0.0 >>> for i in range(10): ... sum += 0.1 ... >>> sum 0.99999999999999989 >>> But thats looks a little bit wrong for me ... i must be a number greater then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 in python ... if i print it. So i create an example program: sum = 0.0 n = 10 d = 1.0 / n print "%.60f" % ( d ) for i in range(n): print "%.60f" % ( sum ) sum += d print sum print "%.60f" % ( sum ) - -------- RESULTs ------ 0.100000000000000005551115123125782702118158340454101562500000 0.000000000000000000000000000000000000000000000000000000000000 0.100000000000000005551115123125782702118158340454101562500000 0.200000000000000011102230246251565404236316680908203125000000 0.300000000000000044408920985006261616945266723632812500000000 0.400000000000000022204460492503130808472633361816406250000000 0.500000000000000000000000000000000000000000000000000000000000 0.599999999999999977795539507496869191527366638183593750000000 0.699999999999999955591079014993738383054733276367187500000000 0.799999999999999933386618522490607574582099914550781250000000 0.899999999999999911182158029987476766109466552734375000000000 1.0 0.999999999999999888977697537484345957636833190917968750000000 and the jump from 0.50000000000000*** to 0.59999999* looks wrong for me ... do i a mistake or is there something wrong in the representation of the floating points in python? my next question, why could i run print "%.66f" % ( sum ) but not print "%.67f" % ( sum ) can anybody tell me how python internal represent a float number?? Best and many thanks in advanced, David -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) iQIcBAEBCQAGBQJMNGpsAAoJEJ82b5xvAlAYYMYP/RTaRcB2NCawBQ25V463+pkO /YtTqsamrFqENrljqpsPrwOOqR02TQrOvZrV72snDPkkcN36tZHKwbmcnOS0tOAc kjX0/oNQOvvEMyJUuHJt9kdNjxMEvUUlENEZHLtpxbypIAo3Waf0FBxKo9F4fJJS PaDIuDgXiLOiaTTUCwa5kKowzjUe8BJOczpUulvGiIvbUac4cxwkPiGvv6L4wzmI /4x1mG5FSibEzcI2zFRsQNHfTqxuKC3a49DuSPtXZo4YWdqVeSXLntQk70uTa78K q4cBVEIDqETQyG0mcRABJpcTMPsnGgbgJD74uhDSTARuyHh405XbjKlic7pe1M12 AhuN71QjpGFl80OOXxCja4OKJCAhPEkfhNsJjrlFnSXAoFWg5YvhDbSVkjW6ftt0 tzyGZEoBpRSjGSIeAojYaqt1Xdxwldz2qFjRLX03io3Fgr8PKRbcLRgg1FXaMFPc gYaY0UEh4dEjt/5afp3ET0LkOhZVMbbi2oSkkFQpRMAzik63zSJRwRxiQXWunlSi HhKqL4sAICf6MODzquuNzJO9wH8Fkpwi+JPEAwnQm/S6Ty00dN22GezG4TWGfepH AhKOIEtRIcMgI7kyBfUdOQe6sifKGGuTEeXK12Td9znZN+wKfqG+Ch1mq4Rwy6P7 p2xwF7ZUWNgRU+5Y/bLG =aS+I -----END PGP SIGNATURE----- From dm at tu-clausthal.de Wed Jul 7 08:05:52 2010 From: dm at tu-clausthal.de (david mainzer) Date: Wed, 07 Jul 2010 14:05:52 +0200 Subject: Python -- floating point arithmetic Message-ID: <4C346DA0.1070708@tu-clausthal.de> Dear Python-User, today i create some slides about floating point arithmetic. I used an example from http://docs.python.org/tutorial/floatingpoint.html so i start the python shell on my linux machine: dm at maxwell $ python Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> sum = 0.0 >>> >>> for i in range(10): ... sum += 0.1 ... >>> >>> sum 0.99999999999999989 >>> >>> But thats looks a little bit wrong for me ... i must be a number greater then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 in python ... if i print it. So i create an example program: sum = 0.0 n = 10 d = 1.0 / n print "%.60f" % ( d ) for i in range(n): print "%.60f" % ( sum ) sum += d print sum print "%.60f" % ( sum ) -------- RESULTs ------ 0.100000000000000005551115123125782702118158340454101562500000 0.000000000000000000000000000000000000000000000000000000000000 0.100000000000000005551115123125782702118158340454101562500000 0.200000000000000011102230246251565404236316680908203125000000 0.300000000000000044408920985006261616945266723632812500000000 0.400000000000000022204460492503130808472633361816406250000000 0.500000000000000000000000000000000000000000000000000000000000 0.599999999999999977795539507496869191527366638183593750000000 0.699999999999999955591079014993738383054733276367187500000000 0.799999999999999933386618522490607574582099914550781250000000 0.899999999999999911182158029987476766109466552734375000000000 1.0 0.999999999999999888977697537484345957636833190917968750000000 and the jump from 0.50000000000000*** to 0.59999999* looks wrong for me ... do i a mistake or is there something wrong in the representation of the floating points in python? my next question, why could i run print "%.66f" % ( sum ) but not print "%.67f" % ( sum ) can anybody tell me how python internal represent a float number?? Best and many thanks in advanced, David From philip at semanchuk.com Wed Jul 7 08:32:27 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jul 2010 08:32:27 -0400 Subject: Recommend a MySQLdb Forum In-Reply-To: References: Message-ID: <838AF739-C880-437A-AF6D-CB3F9E3EC2F5@semanchuk.com> On Jul 6, 2010, at 3:16 PM, Tim Johnson wrote: > Greetings: > I would appreciate it if some could recommend a MySQLdb forum. The one associated the sourceforge project seems like a good bet. 1) go here: http://sourceforge.net/projects/mysql-python/ 2) click support From dickinsm at gmail.com Wed Jul 7 08:55:55 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 7 Jul 2010 05:55:55 -0700 (PDT) Subject: Python -- floating point arithmetic References: Message-ID: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> On Jul 7, 1:05?pm, david mainzer wrote: > Dear Python-User, > > today i create some slides about floating point arithmetic. I used an > example from > > http://docs.python.org/tutorial/floatingpoint.html > > so i start the python shell on my linux machine: > > dm at maxwell $ python > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 > >>> >>> for i in range(10): > > ... ? ? sum += 0.1 > ...>>> >>> sum > 0.99999999999999989 > > But thats looks a little bit wrong for me ... i must be a number greater > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. So you've identified one source of error here, namely that 0.1 isn't exactly representable (and you're correct that the value stored internally is actually a little greater than 0.1). But you're forgetting about the other source of error in your example: when you do 'sum += 0.1', the result typically isn't exactly representable, so there's another rounding step going on. That rounding step might produce a number that's smaller than the actual exact sum, and if enough of your 'sum += 0.1' results are rounded down instead of up, that would easily explain why the total is still less than 1.0. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > ? ? print "%.60f" % ( sum ) > ? ? sum += d > > print sum > print "%.60f" % ( sum ) > > -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? Look at this more closely: you're adding 0.500000000000000000000000.... to 0.1000000000000000055511151231257827021181583404541015625 The *exact* result is, of course 0.6000000000000000055511151231257827021181583404541015625 However, that's not a number that can be exactly represented as a C double (which is how Python stores floats internally). This value falls between the two (consecutive) representable values: 0.59999999999999997779553950749686919152736663818359375 and 0.600000000000000088817841970012523233890533447265625 But of these two, the first is closer to the exact value than the second, so that's the result that you get. You can convince yourself of these results by using the fractions module to do exact arithmetic: >>> from fractions import Fraction >>> tenth = Fraction.from_float(0.1) >>> half = Fraction.from_float(0.5) >>> point_six = Fraction.from_float(0.6) # 0.599999999999 >>> point_six_plus = Fraction.from_float(0.6 + 2**-53) # next float up, 0.6000000 >>> sum = tenth + half # exact value of the sum >>> point_six < sum < point_six_plus # lies between point_six and point_six_plus True >>> sum - point_six < point_six_plus - sum # but it's closer to point_six True > my next question, why could i run > > print "%.66f" % ( sum ) > > but not > > print "%.67f" % ( sum ) That's a historical artefact resulting from use of a fixed-length buffer somewhere deep in Python's internals. This restriction is removed in Python 2.7 and Python 3.x. > can anybody tell me how python internal represent a float number?? In CPython, it's stored as a C double, which typically means in IEEE 754 binary64 format. (Of course, since it's a Python object, it's not just storing the C double itself; it also has fields for the object type and the reference count, so a Python float typically takes 16 bytes of memory on a 32-bit machine, and 24 bytes on a 64-bit machine.) -- Mark From thomas at jollans.com Wed Jul 7 09:08:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 15:08:07 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4C347C37.7060909@jollans.com> On 07/07/2010 02:05 PM, david mainzer wrote: > today i create some slides about floating point arithmetic. I used an > example from > > http://docs.python.org/tutorial/floatingpoint.html > > so i start the python shell on my linux machine: > > dm at maxwell $ python > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>>>>> sum = 0.0 >>>>>>> for i in range(10): > ... sum += 0.1 > ... >>>>>>> sum > 0.99999999999999989 >>>>>>> > But thats looks a little bit wrong for me ... i must be a number greater > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. The simple fact of the matter is: floating point arithmetic isn't accurate. This has nothing to do with Python, it's the fault of your processor's floating point handling. It's good enough in most cases, but you should never rely on a floating-point number to have exactly a certain value. It won't work. To generalize your example a bit: >>> def test_floating_product(a, b): ... sum = 0 ... for _ in range(int(b)): ... sum += a ... return sum, a * int(b), sum == a * b ... >>> test_floating_product(0.1, 1) (0.1, 0.1, True) >>> test_floating_product(0.1, 10) (0.9999999999999999, 1.0, False) >>> test_floating_product(0.2, 4) (0.8, 0.8, True) >>> test_floating_product(0.2, 5) (1.0, 1.0, True) >>> test_floating_product(0.2, 6) (1.2, 1.2000000000000002, False) >>> > -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? the difference is almost exactly 0.1, so that looks okay > > my next question, why could i run > > print "%.66f" % ( sum ) > > but not > > print "%.67f" % ( sum ) I can run either... with Python 3.1. Using 2.6, I get a nice error message: >>> "%.129f" % 0.1 Traceback (most recent call last): File "", line 1, in OverflowError: formatted float is too long (precision too large?) There just isn't anything like 67 decimals of information available. Having that information wouldn't help you a bit. basically, floating point number are stored in the format N * (2 ** E) And use a lot of guesswork. as E gets larger, the precision decreases. Rounding errors occur at the last few decimals, in either direction, depending on the numbers. > > can anybody tell me how python internal represent a float number?? > From lists at cheimes.de Wed Jul 7 09:24:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 15:24:35 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: > can anybody tell me how python internal represent a float number?? It's an IEEE 754 double precision float on all hardware platforms that support IEEE 754 semantics. Python follows the C99 standards for double and complex numbers. Christian From raltbos at xs4all.nl Wed Jul 7 09:50:06 2010 From: raltbos at xs4all.nl (Richard Bos) Date: Wed, 07 Jul 2010 13:50:06 GMT Subject: C interpreter in Lisp/scheme/python References: <28b50375-3331-4717-bb9e-b7f795fe3d76@j4g2000yqh.googlegroups.com> Message-ID: <4c347608.4515218@news.xs4all.nl> Tim Rentsch wrote: > nanothermite911fbibustards > > > How to make Lisp go faster than C > > Didier Verna > > Asking whether Lisp is faster than C is like asking why it's > colder in the mountains than it is in the summer. YM warmer. HTH; HAND. Richard From fetchinson at googlemail.com Wed Jul 7 09:55:45 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 7 Jul 2010 15:55:45 +0200 Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? In-Reply-To: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> References: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Message-ID: > I don't know that PIL or wxPython supports Python 3 or not. May with > some trick these packages are working. > > Does anybody know about it? > Can I replace my Py2.6 without lost PIL/wxPython? PIL currently does not support python 3 but release 1.1.7 will in the future. Don't ask me when, I don't know. I have no idea about the rest. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From philip at semanchuk.com Wed Jul 7 10:05:22 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jul 2010 10:05:22 -0400 Subject: Python -- floating point arithmetic In-Reply-To: <4C347C37.7060909@jollans.com> References: <4C346DA0.1070708@tu-clausthal.de> <4C347C37.7060909@jollans.com> Message-ID: On Jul 7, 2010, at 9:08 AM, Thomas Jollans wrote: > On 07/07/2010 02:05 PM, david mainzer wrote: >> today i create some slides about floating point arithmetic. I used an >> example from >> >> http://docs.python.org/tutorial/floatingpoint.html >> >> so i start the python shell on my linux machine: >> >> dm at maxwell $ python >> Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) >> [GCC 4.3.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information. >>>>>>>> sum = 0.0 >>>>>>>> for i in range(10): >> ... sum += 0.1 >> ... >>>>>>>> sum >> 0.99999999999999989 >>>>>>>> >> But thats looks a little bit wrong for me ... i must be a number >> greater >> then 1.0 because 0.1 = >> 0.100000000000000005551115123125782702118158340454101562500000000000 >> in python ... if i print it. > > The simple fact of the matter is: floating point arithmetic isn't > accurate. This has nothing to do with Python, it's the fault of your > processor's floating point handling. It's good enough in most cases, > but > you should never rely on a floating-point number to have exactly a > certain value. It won't work. Yes, this might be a good time to review the dense but interesting document, "What Every Computer Scientist Should Know About Floating- Point Arithmetic": http://docs.sun.com/source/806-3568/ncg_goldberg.html Cheers Philip From dr.cg at 126.com Wed Jul 7 10:28:56 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 7 Jul 2010 22:28:56 +0800 (CST) Subject: Why Python forbids multiple instances of one module? Message-ID: <1365e96.c236.129ad4f3627.Coremail.dr.cg@126.com> >> Why Python forbids multiple instances of one module? >> If only Python allows multiple instances of one module, module will >> be enough to replace class in most cases. >> After all, it is much easier to write a module than a class, at least we do >> not have to write self everywhere. > If you really want to do that, it should be possible by deleting the > entry from sys.modules and re-importing it. You save yourself having > to explicitly write self everywhere, but instead you have to declare > all your "instance" variables as globals in each "method" that uses > them, which isn't much less of a chore. You also lose inheritance, > properties (and descriptors in general), magic method support, > metaclasses, and pretty much all the other nice features that > new-style classes have to offer. Wow, it works! Thanks a lot for the good idea. It is cool to write, test, debug and maintain POP codes, while realizing the OOP power. I think inheritance might be simulated with: from parentModule import * I really expect for the day when operator overloading and new-style class features find their way into module. Thans again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bartc at freeuk.com Wed Jul 7 11:00:25 2010 From: bartc at freeuk.com (bart.c) Date: Wed, 7 Jul 2010 16:00:25 +0100 Subject: Python -- floating point arithmetic In-Reply-To: References: Message-ID: david mainzer wrote: >>>> sum = 0.0 >>>> for i in range(10): > ... sum += 0.1 > ... >>>> sum > 0.99999999999999989 >>>> > > But thats looks a little bit wrong for me ... i must be a number > greater > then 1.0 because 0.1 = > 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > print "%.60f" % ( sum ) > sum += d > > print sum > print "%.60f" % ( sum ) > > > - -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? I think the main problem is, as sum gets bigger, the less significant bits of the 0.1 representation fall off the end (enough to make it effectively just under 0.1 you're adding instead of just over). > can anybody tell me how python internal represent a float number?? Try "google ieee floating point". The problems aren't specific to Python. -- Bartc From bartc at freeuk.com Wed Jul 7 11:02:38 2010 From: bartc at freeuk.com (bart.c) Date: Wed, 7 Jul 2010 16:02:38 +0100 Subject: Python -- floating point arithmetic In-Reply-To: References: Message-ID: david mainzer wrote: >>>> sum = 0.0 >>>> for i in range(10): > ... sum += 0.1 > ... >>>> sum > 0.99999999999999989 >>>> > > But thats looks a little bit wrong for me ... i must be a number > greater > then 1.0 because 0.1 = > 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > print "%.60f" % ( sum ) > sum += d > > print sum > print "%.60f" % ( sum ) > > > - -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? I think the main problem is, as sum gets bigger, the less significant bits of the 0.1 representation fall off the end (enough to make it effectively just under 0.1 you're adding instead of just over). > can anybody tell me how python internal represent a float number?? Try "google ieee floating point". The problems aren't specific to Python. -- Bartc From michele.simionato at gmail.com Wed Jul 7 11:06:58 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 7 Jul 2010 08:06:58 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <050e5476-662f-4176-9675-8941e109a3fe@k39g2000yqb.googlegroups.com> On Jun 14, 1:07?am, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega This look like a huge project for an evaluation of expressiveness which result is obvious. Lisp (including Scheme) is more expressive than Python, for many definitions of expressiveness (see for instance http://www.ccs.neu.edu/scheme/pubs/scp91-felleisen.ps.gz if you like academic papers). However, who cares? What matters in everyday life are other things, like the availability of libraries, tools, easy of maintenance, etc. In your proposed project the choice of the parsing library would matter a lot. Writing languages is a domain where Lisp is traditionally strong, so you may find good libraries to help you with the task. My guess is that it would take more or less the same amount of effort both in Python and in Lisp. The place where Lisp has an advantage is writing an *embedded* language: then thanks to macros you could write a *compiled* sublanguage. Doing the same in Python is essentially impossible. Michele Simionato From qtvali at gmail.com Wed Jul 7 11:10:27 2010 From: qtvali at gmail.com (Tambet) Date: Wed, 7 Jul 2010 18:10:27 +0300 Subject: Error message repetition Message-ID: Hello! I have such problem that: - My console shows maximally x last lines, then truncates - Error message takes 2 line - In case of very big stack trace, there will be 2*x error lines - In such case I do not see any debug output In this case, it's about recursion: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) and so on... I think it should be instead: File "b2.py", line 124, in seek_solution [*repeated x times*] solution = self.seek_solution(weight + U.gravity, len(test), test) Getting big strack trace is most probable with functions calling themselves - thus, long stack traces usually contain such repetitions. As those functions might not call themselves directly, one cycle of recursion might become four lines long, in such case: Stack item 1: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) Stack item 2: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) Stack item repetitions: [#1, #2] * x This could simply enumerate stack items and then create formulas of repetitions, like: [[#1, #2] * 15, #3 * 15] * 3 If it shows each message written-out at least one and max two or three times, but over that gives it an id and shows patterns of those instead, it will be a lot better. I have, sometimes, gone through some four pages of Java stack traces etc., but I think that having such long array of errors does not make it more readable or simple - if you can see everything in one page, then it's good enough for pondering. And scrolling up and looking at output would be a nice feature ;) Especially now, as I am going to raise recursion limit - this program would be perfectly possible without relying on built-in loop constructions so much, but I did it yesterday in such manner and it simply raised into unmanageable complexity. Thus, now I am trying to encapsulate it's logic into pieces, which maximize the use of Pythons overloads and function-based iterators etc., but this makes error messages that long when I do something wrong - and I can't even check if that was really some mistake in code or just the recursion actually needs to be deeper than I hoped. Tambet -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Wed Jul 7 11:20:27 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 07 Jul 2010 11:20:27 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: <5325a$4c349b5b$4275d90a$27439@FUSE.NET> On 7/2/10 3:07 PM, John Nagle wrote: > > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? It's not faster. > It doesn't do anything you can't do in Python 2.6. There's no > "killer app" for it. End of life for Python 2.x is many years away; > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? That's decision for each business to make. My guess is that many businesses won't upgrade for some time, until the major libraries/modules support Python 3. I don't plan to move to Python 3 for at least a couple of years. > > Python 3 is a nice cleanup of some legacy syntax issues. But > that's just not enough. Perl 6 is a nice cleanup of Perl 5, and > look how that went. Ten years on, it's not even mainstream, let > alone dominant. The Perl analogy isn't really useful here. Perl 6 is somewhere between the HURD and Duke Nukem Forever in terms of being viable. Even the Perl website says, "If you are looking for production ready code please use Perl 5." That's one reason why Perl 5 development has recently undergone a resurgence. Python 3, by contrast, is production-ready in itself; libraries are gradually moving to support it, and Python 2 has a definite end-of-life release in 2.7, with an extended maintenance period for 2.7. The Python developers are providing a much stronger and clearer path forward for Python 3. The transition period may last five years, but the path is clear. As a Mac developer, I'm sympathetic to your frustration. A few years ago Apple deprecated one of its major API's (Carbon), on which my own development depended, and there was a lot of uncertainty about major libraries that use Carbon being updated. This is normal in any transition period. Eventually, the major libraries I depend on were updated by their developers (i.e. ported to the Cocoa API), I was able to migrate my own applications to the updated libraries, and life went on. I think the same thing will happen with Python. It's useful to note the libraries that are not yet ported to support Python 3, and to share best practices for moving forward. Past a certain point, however, I don't see much point in attacking the existence of Python 3 or questioning the need to move toward Python 3. It's here, it's the way forward, and that's not going to change. Might as well accept it. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From python at lonely-star.org Wed Jul 7 11:23:22 2010 From: python at lonely-star.org (Nathan Huesken) Date: Wed, 7 Jul 2010 11:23:22 -0400 Subject: tarfile and progress information Message-ID: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> Hi, I am packing large files with tarfile. Is there any way I can get progress information while packing? Thanks! Nathan From thomas at jollans.com Wed Jul 7 11:28:25 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 17:28:25 +0200 Subject: Error message repetition In-Reply-To: References: Message-ID: <4C349D19.3040203@jollans.com> On 07/07/2010 05:10 PM, Tambet wrote: > Hello! > > I have such problem that: > > * My console shows maximally x last lines, then truncates > * Error message takes 2 line > * In case of very big stack trace, there will be 2*x error lines > * In such case I do not see any debug output > > In this case, it's about recursion: > > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > and so on... Depending on how far this goes up, you might just be able to change the backlog your terminal emulator saves? that would allow you to scroll up. If you can't do that, you should get a proper console. Anyway, if you want to customise the traceback output, you can! simply replace sys.excepthook with your own version. http://docs.python.org/dev/py3k/library/sys.html#sys.excepthook > > I think it should be instead: > File "b2.py", line 124, in seek_solution [*repeated x times*] > solution = self.seek_solution(weight + U.gravity, len(test), test) > > Getting big strack trace is most probable with functions calling > themselves - thus, long stack traces usually contain such repetitions. > > As those functions might not call themselves directly, one cycle of > recursion might become four lines long, in such case: > > Stack item 1: File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > Stack item 2: File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > Stack item repetitions: [#1, #2] * x > > This could simply enumerate stack items and then create formulas of > repetitions, like: > [[#1, #2] * 15, #3 * 15] * 3 > > If it shows each message written-out at least one and max two or three > times, but over that gives it an id and shows patterns of those instead, > it will be a lot better. I have, sometimes, gone through some four pages > of Java stack traces etc., but I think that having such long array of > errors does not make it more readable or simple - if you can see > everything in one page, then it's good enough for pondering. And > scrolling up and looking at output would be a nice feature ;) Especially > now, as I am going to raise recursion limit - this program would be > perfectly possible without relying on built-in loop constructions so > much, but I did it yesterday in such manner and it simply raised into > unmanageable complexity. Thus, now I am trying to encapsulate it's logic > into pieces, which maximize the use of Pythons overloads and > function-based iterators etc., but this makes error messages that long > when I do something wrong - and I can't even check if that was really > some mistake in code or just the recursion actually needs to be deeper > than I hoped. > > Tambet > From torriem at gmail.com Wed Jul 7 11:31:02 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 07 Jul 2010 09:31:02 -0600 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: <4C349DB6.8080001@gmail.com> On 07/06/2010 09:34 PM, Chris Rebert wrote: > On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >> While it's possible to set up pipes and spawn programs in parallel to >> operate on the pipes, in practice it's simpler to tell subprocess.Popen >> to use a shell and then just rely on Bash's very nice syntax for setting >> up the pipeline. > > Until there's a Python variable involved that is, unless you want to > overlook all the edge cases or do the escaping all by yourself (and > then pray you did it right). Very good point. This is a problem that the pipes module suffers from as well. Although we learned in the other thread on escaping SQL statements that escaping is faster, easier and just as safe as other parameterization mechanisms. Uh huh. Back on target, a library similar to pipes that was safe (pipes is not) and had a pythonic syntax would be cool. pipes module works alright, syntax wise, but it's not a clean syntax. From qtvali at gmail.com Wed Jul 7 11:53:53 2010 From: qtvali at gmail.com (Tambet) Date: Wed, 7 Jul 2010 18:53:53 +0300 Subject: Error message repetition In-Reply-To: References: Message-ID: > Depending on how far this goes up, you might just be able to change the > backlog your terminal emulator saves? that would allow you to scroll up. > If you can't do that, you should get a proper console. > I use bash, which allows to do that. This was rather a case example - actually this output gets pretty annoying anyway and should contain only most important information at any given moment. Scrollbar getting too small is another example of the same case ...the case that if something outputs 2000 lines of repetition, it's not very much of use. This could be that someone does not understand the cryptic output, but I think that anyone having that long traceback is probably intelligent enough to google for "Python traceback what those cryptic things mean" ;) I think that this functionality should be triggered only by traceback bigger than, say, 20 lines or so. Also, this is not the point, where processor usage costs anything. Anyway, if you want to customise the traceback output, you can! > simply replace sys.excepthook with your own version. > > http://docs.python.org/dev/py3k/library/sys.html#sys.excepthook > Ok, I should have thought of that - anyway, such thing should be standard functionality. I personally love nonverbose output - if it can't say it in 1 A4, it should just tell me that it could if I asked. I mean, normally I like to have one sight over the traceback and another over program itself. Thanks for that hook ...I will use it in case I get four of five more similar errors today ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Wed Jul 7 12:29:55 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 07 Jul 2010 17:29:55 +0100 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > you should never rely on a floating-point number to have exactly a > certain value. "Never" is an overstatement. There are situations where you can rely upon a floating-point number having exactly a certain value. First, floating-point values are exact. They may be an approximation to some other value, but they are still exact values, not some kind of indeterminate quantum state. Specifically, a floating-point value is a rational number whose denominator is a power of two. Second, if the result of performing a primitive arithmetic operation (addition, subtraction, multiplication, division, remainder) or the square-root function on the equivalent rational values is exactly representable as a floating-point number, then the result will be exactly that value. Third, if the result of performing a primitive arithmetic operation or the square-root function on the equivalent rational values *isn't* exactly representable as a floating-point number, then the floating-point result will be obtained by rounding the exact value according to the FPU's current rounding mode. All of this is entirely deterministic, and follows relatively simple rules. Even if the CPU has a built-in random number generator, it will *not* be used to generate the least-significant bits of a floating-point arithmetic result. The second and third cases above assume that floating-point arithmetic follows IEEE-754 (the second case is likely to be true even for systems which don't strictly adhere to IEEE-754). This is true for most modern architectures, provided that: 1. You aren't using Borland C, which forcibly "optimises" x/y to x*(1/y), so 12/3 isn't exactly equal to 4, as 1/3 isn't exactly representable. Real compilers won't use this sort of approximation unless specifically instructed (e.g. -funsafe-math-optimizations for gcc). 2. You aren't using one of the early Pentium chips. In spite of this, there are some "gotcha"s. E.g. on x86, results are computed to 80-bit (long double) precision internally. These will be truncated to 64 bits if stored in memory. Whether the truncation occurs is largely up to the compiler, although it can be forced with -ffloat-store with gcc. More complex functions (trigonometric, etc) are only accurate to within a given relative error (e.g. +/- the value of the least significant bit), as it isn't always possible to determine the correct value for the least significant bit for a given rounding mode (and even if it is theoretically possible, there is no limit to the number of bits of precision which would be required). From rivkaumiller at gmail.com Wed Jul 7 12:38:40 2010 From: rivkaumiller at gmail.com (Rivka Miller) Date: Wed, 7 Jul 2010 09:38:40 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> On Jun 13, 4:07?pm, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega You should probably narrow down your project to one. For example, write a LISt Processor Meta Circular Evaluator in C. You can take Paul Graham's rendition as a start and forget about garbage collection. Start with getchar()/putchar() for I/O. Although C comes with a regex library, you probably do not need a regex or parser at all for this. This is the beauty of LISP which is why McCarthy was able to bypass the several man years of effort involved in FORmula TRANslator. Even as a young boy like L. Peter Deutsch was able to write it in assembly for one of the PDP's. You will have go implement an associative array or a symbol-value table probably as a stack or linked list. You will have to decide how you implement the trees, as cons cells or some other method. Dynamic scoping is easy to implement and that is what elisp has. I am not aware of any book that provides implementation of LISP in C and explains it at the same time. This is the extent of help I can provide, someone else can probably help you more. Anyone know what the first initial of L. Peter Deutsch stand for ? Rivka From roy at panix.com Wed Jul 7 12:46:53 2010 From: roy at panix.com (Roy Smith) Date: Wed, 07 Jul 2010 12:46:53 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <5325a$4c349b5b$4275d90a$27439@FUSE.NET> Message-ID: In article <5325a$4c349b5b$4275d90a$27439 at FUSE.NET>, Kevin Walzer wrote: > That's decision for each business to make. My guess is that many > businesses won't upgrade for some time, until the major > libraries/modules support Python 3. I don't plan to move to Python 3 for > at least a couple of years. It takes a long time for big businesses to upgrade. It's not like me or you. I just download the latest and greatest, run the installer, and I'm good to go. A big company has to install it in a test lab, certify it, get approval from IT, log a change request, etc. You need to get approval from your manager, your director, your VP, and so on up the management chain until you finally reach somebody who has no clue what's going on and either sits on the request or denies it out of ignorance. Or, more likely, you just hit some middle-management layer where the guy doesn't have the authority to approve it himself, and isn't willing to expend the political capital it would take to get approval from the next layer up. Somebody might decide they don't want to disturb any existing production systems (not a bad idea, really), so you need to order new hardware for it. Even if you can get capital approval for that, it mushrooms into finding rack space, and the UPS is already oversubscribed, and so is the cooling, and there's no available network ports, and so on. Suddenly, downloading some free software has become a 5-figure project. Big businesses have lots of ways to ensure that no progress is ever made. If you think any of the above is made up, you've never worked for a big company. From wolfgang.riedel52 at web.de Wed Jul 7 13:00:04 2010 From: wolfgang.riedel52 at web.de (wolfgang.riedel) Date: Wed, 7 Jul 2010 10:00:04 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <28b50375-3331-4717-bb9e-b7f795fe3d76@j4g2000yqh.googlegroups.com> Message-ID: On 20 June, 03:48, Tim Rentsch wrote: > nanothermite911fbibustards > writes: > > Asking whether Lisp is faster than C is like asking why it's > colder in the mountains than it is in the summer. original Karl Valentin would be but yours is in his sense. Wolfgang From ethan at stoneleaf.us Wed Jul 7 13:32:50 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 07 Jul 2010 10:32:50 -0700 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4C34BA42.5030906@stoneleaf.us> Nobody wrote: > On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > >> you should never rely on a floating-point number to have exactly a >> certain value. > > "Never" is an overstatement. There are situations where you can rely > upon a floating-point number having exactly a certain value. It's not much of an overstatement. How many areas are there where you need the number 0.100000000000000005551115123125782702118158340454101562500000000000? If I'm looking for 0.1, I will *never* (except by accident ;) say if var == 0.1: it'll either be <= or >=. By contrast, if I'm dealing with integers I can say if var == 4 because I *know* that there are values that var can hold that are *exactly* 4. Not 3.999999999817263 or 4.0000000019726. ~Ethan~ From g.rodola at gmail.com Wed Jul 7 13:37:56 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Wed, 7 Jul 2010 19:37:56 +0200 Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? In-Reply-To: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> References: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Message-ID: 2010/7/7 durumdara : > Hi! > > I have an environment under Python 2.6 (WinXP). That is based on PIL, > wxPython/PyWin32. > > In the project's pages I see official installer for only PyWin32. > > I don't know that PIL or wxPython supports Python 3 or not. May with > some trick these packages are working. > > Does anybody know about it? > Can I replace my Py2.6 without lost PIL/wxPython? > > Thanks for your help: > ? dd > > -- > http://mail.python.org/mailman/listinfo/python-list No, as of now you just can't. Now that 2.7 is out and is officially declared as the last 2.x release it's likely that there will be a lot more traction in porting such big names to Python 3. --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ > From python at rcn.com Wed Jul 7 14:08:18 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 7 Jul 2010 11:08:18 -0700 (PDT) Subject: Python -- floating point arithmetic References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: On Jul 7, 5:55?am, Mark Dickinson wrote: > On Jul 7, 1:05?pm, david mainzer wrote: > > > > > Dear Python-User, > > > today i create some slides about floating point arithmetic. I used an > > example from > > >http://docs.python.org/tutorial/floatingpoint.html > > > so i start the python shell on my linux machine: > > > dm at maxwell $ python > > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > > [GCC 4.3.4] on linux2 > > Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 > > >>> >>> for i in range(10): > > > ... ? ? sum += 0.1 > > ...>>> >>> sum > > 0.99999999999999989 > > > But thats looks a little bit wrong for me ... i must be a number greater > > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > > in python ... if i print it. [Mark Dickinson] > So you've identified one source of error here, namely that 0.1 isn't > exactly representable (and you're correct that the value stored > internally is actually a little greater than 0.1). ?But you're > forgetting about the other source of error in your example: when you > do 'sum += 0.1', the result typically isn't exactly representable, so > there's another rounding step going on. ?That rounding step might > produce a number that's smaller than the actual exact sum, and if > enough of your 'sum += 0.1' results are rounded down instead of up, > that would easily explain why the total is still less than 1.0. One key for understanding floating point mysteries is to look at the actual binary sums rather that their approximate representation as a decimal string. The hex() method can make it easier to visualize Mark's explanation: >>> s = 0.0 >>> for i in range(10): ... s += 0.1 ... print s.hex(), repr(s) 0x1.999999999999ap-4 0.10000000000000001 0x1.999999999999ap-3 0.20000000000000001 0x1.3333333333334p-2 0.30000000000000004 0x1.999999999999ap-2 0.40000000000000002 0x1.0000000000000p-1 0.5 0x1.3333333333333p-1 0.59999999999999998 0x1.6666666666666p-1 0.69999999999999996 0x1.9999999999999p-1 0.79999999999999993 0x1.cccccccccccccp-1 0.89999999999999991 0x1.fffffffffffffp-1 0.99999999999999989 Having used hex() to understand representation error (how the binary partial sums are displayed), you can use the Fractions module to gain a better understanding of rounding error introduced by each addition: >>> s = 0.0 >>> for i in range(10): exact = Fraction.from_float(s) + Fraction.from_float(0.1) s += 0.1 actual = Fraction.from_float(s) error = actual - exact print '%-35s%-35s\t%s' % (actual, exact, error) 3602879701896397/36028797018963968 3602879701896397/36028797018963968 0 3602879701896397/18014398509481984 3602879701896397/18014398509481984 0 1351079888211149/4503599627370496 10808639105689191/36028797018963968 1/36028797018963968 3602879701896397/9007199254740992 14411518807585589/36028797018963968 -1/36028797018963968 1/2 18014398509481985/36028797018963968 -1/36028797018963968 5404319552844595/9007199254740992 21617278211378381/36028797018963968 -1/36028797018963968 3152519739159347/4503599627370496 25220157913274777/36028797018963968 -1/36028797018963968 7205759403792793/9007199254740992 28823037615171173/36028797018963968 -1/36028797018963968 2026619832316723/2251799813685248 32425917317067569/36028797018963968 -1/36028797018963968 9007199254740991/9007199254740992 36028797018963965/36028797018963968 -1/36028797018963968 Hope this helps your slides, Raymond From clp2 at rebertia.com Wed Jul 7 14:27:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jul 2010 11:27:07 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C349DB6.8080001@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> <4C349DB6.8080001@gmail.com> Message-ID: On Wed, Jul 7, 2010 at 8:31 AM, Michael Torrie wrote: > On 07/06/2010 09:34 PM, Chris Rebert wrote: >> On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >>> While it's possible to set up pipes and spawn programs in parallel to >>> operate on the pipes, in practice it's simpler to tell subprocess.Popen >>> to use a shell and then just rely on Bash's very nice syntax for setting >>> up the pipeline. >> >> Until there's a Python variable involved that is, unless you want to >> overlook all the edge cases or do the escaping all by yourself (and >> then pray you did it right). > > Very good point. ?This is a problem that the pipes module suffers from > as well. > > Although we learned in the other thread on escaping SQL statements that > escaping is faster, easier and just as safe as other parameterization > mechanisms. ?Uh huh. > > Back on target, a library similar to pipes that was safe (pipes is not) > and had a pythonic syntax would be cool. ?pipes module works alright, > syntax wise, but it's not a clean syntax. Actually, your original post inspired me to take a crack at writing something like that yesterday: http://rebertia.com/code/subproc_pipelines.py Thoughts anyone? (Written on a whim, so no tests or docs at present.) Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Wed Jul 7 14:38:17 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 7 Jul 2010 14:08:17 -0430 Subject: Is This Open To SQL Injection? Message-ID: Hi; I have this code: sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, user, ', %s'.join('%s' * len(col_vals)) cursor.execute(sql, col_vals) Is this open to injection attacks? If so, how correct? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Wed Jul 7 14:52:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 07 Jul 2010 11:52:27 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4C34CCEB.1060901@ixokai.io> On 7/7/10 11:38 AM, Victor Subervi wrote: > Hi; > I have this code: > > sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, > user, ', %s'.join('%s' * len(col_vals)) > cursor.execute(sql, col_vals) First, its always best to be explicit with insert statements. Meaning, don't rely on the underlining structure of a table, as in: INSERT INTO YourRandomTable VALUES ("my", "value", "here"); Instead, do: INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", "value", "here"); > Is this open to injection attacks? If so, how correct? Secondly, I'd say: probably yes. Maybe. You're doing string formatting to construct your SQL, which is where the trouble comes from. Its possible to do safely, but takes exquisite care -- which is why we've been nudging you away from it. But I can't be a whole lot more specific because I can't for the life of me figure out what you're actually doing with it. I can't figure out why you're passing the store and user variables into the SQL statement, instead of just passing them into the .execute as you are supposed to. I.e., cursor.execute(sql, [store, user] + col_vals) or something. It looks like you're sort of trying to get one generic SQL statement which can set some arbitrary number of random columns-- if so, why? I can't picture just what this table layout is or what kind of data it holds to advise better. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From sturlamolden at yahoo.no Wed Jul 7 15:01:09 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:01:09 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On 7 Jul, 11:32, Jonathan Hartley wrote: > Also, > this would solve the pain of Python developers attempting to > redistribute py2exe versions of their programs (i.e. they have to own > a Visual Studio license to legally be able to redistribute the > required C runtime) http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en If this is not sufficient, ask Microsoft for permission or buy a copy of Visual Studio (any will do, you can rebuild Python). I don't understand enough to know why Visual > Studio was chosen instead of MinGW. Can anyone shed any light on that > decision? It the standard C and C++ compiler on Windows. From martin at v.loewis.de Wed Jul 7 15:10:43 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:10:43 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <4C34D133.9060802@v.loewis.de> > Python 3.1.1, file [pymem.h]: > > PyAPI_FUNC(void *) PyMem_Malloc(size_t); > > #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > : malloc((n) ? (n) : 1)) > > The problem with the latter that it seems that it's intended for safety > but does the opposite... Why do you say that? It certainly *does* achieve safety, wrt. to certain errors, specifically: - passing sizes that are out-of-range - supporting malloc(0) on all systems > Perhaps (if it isn't intentional) this is a bug of the oversight type, > that nobody remembered to update the macro? Update in what way? > Except for the problems with file descriptors I think a practical > interim solution for extensions implemented in C could be to just link > the runtime lib statically. For a minimal extension this increased the > size from 8 KiB to 49 KiB. And generally with MS tools the size is > acceptably small. If you think that's fine for your extension module (which may well be the case), go ahead. But then, you could also just link with a different DLL version of the CRT instead. > I think that this would be safe because since the C API has to access > things in the interpreter I think it's a given that all the relevant > functions delegate to shared library (DLL) implementations, but I have > not checked the source code. There are certainly more cases than the ones mentioned so far, in particular the time zone and the locale. The CRT carries global variables for these, so if you set them in the copy of the CRT that Python links with, you won't see the change in your extension module - which may or may not be a problem. > As a more longterm solution, perhaps python.org could make available the > redistributables for various MSVC versions, and then one could introduce > some scheme for indicating the runtime lib dependencies of any given > extension. My preferred long-term solution is to reduce the usage of the C library in CPython as much as reasonable, atleast on Windows. Memory management could directly use the heap functions (or even more directly VirtualAlloc); filenos could be OS handles, and so on. There are probably limitations to what you can achieve, but I think it's worth trying. Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 15:12:14 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:12:14 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: On 7 Jul, 06:54, "Alf P. Steinbach /Usenet" wrote: > PyAPI_FUNC(void *) PyMem_Malloc(size_t); > > #define PyMem_MALLOC(n) ? ? ? ? (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((n) ? (n) : 1)) I was afraid of that :( > Except for the problems with file descriptors I think a practical interim > solution for extensions implemented in C could be to just link the runtime lib > statically. You still have two CRTs linked into the same process. From martin at v.loewis.de Wed Jul 7 15:22:38 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:22:38 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: <4C34D3FE.6000905@v.loewis.de> > I presume this problem would go away if future versions of Python > itself were compiled on Windows with something like MinGW gcc. Also, > this would solve the pain of Python developers attempting to > redistribute py2exe versions of their programs (i.e. they have to own > a Visual Studio license to legally be able to redistribute the > required C runtime) I don't understand enough to know why Visual > Studio was chosen instead of MinGW. Can anyone shed any light on that > decision? sturlamolden has already given the primary reason: Python, traditionally, attempts to use and work with the system vendor's compiler. On Windows, that's MSC. It's typically the one that best knows about platform details that other compilers might be unaware of. In addition, it's also the compiler and IDE that Windows developers (not just Python core people, but also extension developers and embedders) prefer to use, as it has quite good IDE support (in particular debugging and code browsing). Perhaps more importantly, none of the other compilers is really an alternative. GCC in particular cannot build the Win32 extensions, since it doesn't support the COM and ATL C++ features that they rely on (and may not support other MSC extensions, either). So the Win32 extensions must be built with VS, which means Python itself needs to use the same compiler. Likewise important: gcc/mingw is *not* a complete C compiler on Windows. A complete C compiler would have to include a CRT (on Windows); mingw doesn't (cygwin does, but I think you weren't proposing that Python be built for cygwin - you can easily get cygwin Python anyway). Instead, mingw relies on users having a CRT available to them - and this will be a Microsoft one. So even if gcc was used, we would have versioning issues with Microsoft CRTs, plus we would have to rely on target systems including the right CRT, as we couldn't include it in the distribution. HTH, Martin From python at mrabarnett.plus.com Wed Jul 7 15:26:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 20:26:17 +0100 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C34D4D9.4080406@mrabarnett.plus.com> Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) > > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); > >> Is this open to injection attacks? If so, how correct? > > Secondly, I'd say: probably yes. Maybe. You're doing string formatting > to construct your SQL, which is where the trouble comes from. Its > possible to do safely, but takes exquisite care -- which is why we've > been nudging you away from it. > > But I can't be a whole lot more specific because I can't for the life of > me figure out what you're actually doing with it. > > I can't figure out why you're passing the store and user variables into > the SQL statement, instead of just passing them into the .execute as you > are supposed to. I.e., cursor.execute(sql, [store, user] + col_vals) or > something. > > It looks like you're sort of trying to get one generic SQL statement > which can set some arbitrary number of random columns-- if so, why? I > can't picture just what this table layout is or what kind of data it > holds to advise better. > Not only that, there's a missing ")" and the .join is wrong. For example, if 'store' is "STORE", 'user' is "USER" and 'col_vals' has, say, 3 members, then what you get is: insert into personalDataKeys values (STORE, USER, %, %ss, %s%, %ss, %s%, %ss) From sturlamolden at yahoo.no Wed Jul 7 15:32:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:32:11 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> On 7 Jul, 21:12, sturlamolden wrote: > > #define PyMem_MALLOC(n) ? ? ? ? (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((n) ? (n) : 1)) > > I was afraid of that :( Also observe that this macro is very badly written (even illegal) C. Consider what this would do: PyMem_MALLOC(n++) According to Linus Thorvalds using macros like this is not even legal C: http://www.linuxfocus.org/common/src/January2004_linus.html This would be ok, and safe as long as we use the GIL: register Py_ssize_t __pymem_malloc_tmp; #define PyMem_MALLOC(n)\ (__pymem_malloc_tmp = n, (((__pymem_malloc_tmp) < 0 || (__pymem_malloc_tmp) > PY_SSIZE_T_MAX) ? NULL \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((__pymem_malloc_tmp) ? (__pymem_malloc_tmp) : 1))) An inline function is a better solution, but not ANSI C standard: inline void *PyMem_MALLOC(Py_ssize_t n) { return (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL : malloc((n) ? (n) : 1)); } From alf.p.steinbach+usenet at gmail.com Wed Jul 7 15:41:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 21:41:09 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34D133.9060802@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: * Martin v. Loewis, on 07.07.2010 21:10: >> Python 3.1.1, file [pymem.h]: >> >> PyAPI_FUNC(void *) PyMem_Malloc(size_t); >> >> #define PyMem_MALLOC(n) (((n)< 0 || (n)> PY_SSIZE_T_MAX) ? NULL \ >> : malloc((n) ? (n) : 1)) >> >> The problem with the latter that it seems that it's intended for safety >> but does the opposite... > > Why do you say that? It certainly *does* achieve safety, wrt. to certain > errors, specifically: > - passing sizes that are out-of-range > - supporting malloc(0) on all systems It uses malloc instead of PyMem_Malloc. malloc may well be different and use a different heap in an extension DLL than in the Python interpreter and other extensions. That's one thing that the docs (rightly) warn you about. >> Perhaps (if it isn't intentional) this is a bug of the oversight type, >> that nobody remembered to update the macro? > > Update in what way? I was guessing that at one time there was no PyMem_Malloc. And that it was introduced to fix Windows-specific problems, but inadvertently without updating the macro. It's just a guess as to reasons why the macro uses malloc directly. >> Except for the problems with file descriptors I think a practical >> interim solution for extensions implemented in C could be to just link >> the runtime lib statically. For a minimal extension this increased the >> size from 8 KiB to 49 KiB. And generally with MS tools the size is >> acceptably small. > > If you think that's fine for your extension module (which may well be > the case), go ahead. I have no comment on that except pointing it out as a somewhat stupid, somewhat evil social inclusion/exclusion argument, talking to the audience. Argh. You're wasting my time. But anyway, 49 KiB is small by today's standards. For example, you get 20 of those in a single MiB, and about 20.000 in a single GiB. > But then, you could also just link with a different > DLL version of the CRT instead. When I wrote "link the runtime lib statically" that was an alternative to the usual link-as-DLL. It wouldn't make sense to link the runtime lib statically as an alternative to linking it statically. As for linking to a different /version/ of the CRT, if you really mean that, I think that's difficult. It's not necessarily impossible, after all there's STLPort. But I think that it must at the very least be rather difficult to do with Microsoft's tools, for otherwise people would have employed that solution before, and so I wouldn't trust the result, and wouldn't waste the time trying. Cheers, - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Wed Jul 7 15:41:52 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 21:41:52 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 07.07.2010 21:12: > On 7 Jul, 06:54, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> PyAPI_FUNC(void *) PyMem_Malloc(size_t); >> >> #define PyMem_MALLOC(n) (((n)< 0 || (n)> PY_SSIZE_T_MAX) ? NULL \ >> : malloc((n) ? (n) : 1)) > > I was afraid of that :( > > > >> Except for the problems with file descriptors I think a practical interim >> solution for extensions implemented in C could be to just link the runtime lib >> statically. > > You still have two CRTs linked into the same process. So? Cheers, - Alf -- blog at From sturlamolden at yahoo.no Wed Jul 7 15:46:29 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:46:29 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: On 7 Jul, 21:41, "Alf P. Steinbach /Usenet" wrote: > > You still have two CRTs linked into the same process. > > So? CRT resources cannot be shared across CRT borders. That is the problem. Multiple CRTs are not a problem if CRT resources are never shared. From martin at v.loewis.de Wed Jul 7 15:47:59 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:47:59 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> Message-ID: <4C34D9EF.1080603@v.loewis.de> > Also observe that this macro is very badly written (even illegal) C. > Consider what this would do: > > PyMem_MALLOC(n++) > > According to Linus Thorvalds using macros like this is not even legal > C: > > http://www.linuxfocus.org/common/src/January2004_linus.html [Please don't use "legal" wrt. programs - it's not "illegal" to violate the language's rules; you don't go to jail when doing so. Linus said "not allowed"] You are misinterpreting that statement. Linus said that the isdigit macro was non-conforming, *and meant that specifically for isdigit()*. That's because the C standard says that isdigit is a function. Under the as-if rule, you may implement it as a macro as long as nobody can tell the difference. However, in the presented implementation, there is a notable difference. However, the C standard is silent wrt. to PyMem_MALLOC, and it certainly allows the definition of macros which use the macro arguments more than once. > This would be ok, and safe as long as we use the GIL: The macro is ok as it stands (minus the issues with multiple heaps). The Python convention is that you clearly recognize PyMem_MALLOC as a macro, so you should know not to pass parameters with side effects. > register Py_ssize_t __pymem_malloc_tmp; > #define PyMem_MALLOC(n)\ > (__pymem_malloc_tmp = n, (((__pymem_malloc_tmp) < 0 || > (__pymem_malloc_tmp) > PY_SSIZE_T_MAX) ? NULL \ > : malloc((__pymem_malloc_tmp) ? > (__pymem_malloc_tmp) : 1))) That would partially defeat the purpose, namely it would require the compiler to put the size into a variable in memory, and possibly prevent optimizations from taking place that rely on constant propagation (depending on how smart the compiler is). Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 15:51:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:51:24 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: <6f380eb2-8c1f-47b5-b65f-bae91de29c54@x27g2000yqb.googlegroups.com> On 7 Jul, 21:47, "Martin v. Loewis" wrote: > That would partially defeat the purpose, namely it would require the > compiler to put the size into a variable in memory, and possibly prevent > optimizations from taking place that rely on constant propagation > (depending on how smart the compiler is). Also after reading carefully what Linus said, it would still be incorrect if n is a complex expression. So, an inline function is the "correct" one here. From martin at v.loewis.de Wed Jul 7 15:56:36 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:56:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: <4C34DBF4.8020606@v.loewis.de> >>> Perhaps (if it isn't intentional) this is a bug of the oversight type, >>> that nobody remembered to update the macro? >> >> Update in what way? > > I was guessing that at one time there was no PyMem_Malloc. And that it > was introduced to fix Windows-specific problems, but inadvertently > without updating the macro. It's just a guess as to reasons why the > macro uses malloc directly. It might indeed be that the function version was introduced specifically for Windows. However, the macro was left intentionally: both for backwards compatibility, and for use inside Python itself. >>> Except for the problems with file descriptors I think a practical >>> interim solution for extensions implemented in C could be to just link >>> the runtime lib statically. [...] > > When I wrote "link the runtime lib statically" that was an alternative > to the usual link-as-DLL. Ok, I lost the thread. When you said "a practical interim solution" you were talking about what problem? I thought the discussion was about the need to link with the same DLL version as Python. > It wouldn't make sense to link the runtime lib statically as an > alternative to linking it statically. However, it would surely make sense to link with a different DLL than the one that Python links with, assuming that would actually work. > As for linking to a different /version/ of the CRT, if you really mean > that, I think that's difficult. It's not necessarily impossible, after > all there's STLPort. But I think that it must at the very least be > rather difficult to do with Microsoft's tools, for otherwise people > would have employed that solution before, and so I wouldn't trust the > result, and wouldn't waste the time trying. It's actually straight-forward (or used to be, until they came up with the SxS madness). It was actually the case that people did so unexpectingly, and it seemed to work fine, except that it crashed when passing FILE*. Then we started explaining that mixing CRTs is risky. Regards, Martin From alf.p.steinbach+usenet at gmail.com Wed Jul 7 16:04:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 22:04:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 07.07.2010 21:46: > On 7 Jul, 21:41, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >>> You still have two CRTs linked into the same process. >> >> So? > > CRT resources cannot be shared across CRT borders. That is the > problem. Multiple CRTs are not a problem if CRT resources are never > shared. Yeah, but then we're down to file descriptors, C library locales and such as the remaining problems. Cheers, - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Wed Jul 7 16:07:24 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 22:07:24 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34DBF4.8020606@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Martin v. Loewis, on 07.07.2010 21:56: >>>> Perhaps (if it isn't intentional) this is a bug of the oversight type, >>>> that nobody remembered to update the macro? >>> >>> Update in what way? >> >> I was guessing that at one time there was no PyMem_Malloc. And that it >> was introduced to fix Windows-specific problems, but inadvertently >> without updating the macro. It's just a guess as to reasons why the >> macro uses malloc directly. > > It might indeed be that the function version was introduced specifically > for Windows. However, the macro was left intentionally: both for > backwards compatibility, and for use inside Python itself. > >>>> Except for the problems with file descriptors I think a practical >>>> interim solution for extensions implemented in C could be to just link >>>> the runtime lib statically. > [...] >> >> When I wrote "link the runtime lib statically" that was an alternative >> to the usual link-as-DLL. > > Ok, I lost the thread. When you said "a practical interim solution" > you were talking about what problem? I thought the discussion was > about the need to link with the same DLL version as Python. The main problem that the required MSVC redistributables are not necessarily present on the end user's system. >> It wouldn't make sense to link the runtime lib statically as an >> alternative to linking it statically. > > However, it would surely make sense to link with a different DLL than > the one that Python links with, assuming that would actually work. > >> As for linking to a different /version/ of the CRT, if you really mean >> that, I think that's difficult. It's not necessarily impossible, after >> all there's STLPort. But I think that it must at the very least be >> rather difficult to do with Microsoft's tools, for otherwise people >> would have employed that solution before, and so I wouldn't trust the >> result, and wouldn't waste the time trying. > > It's actually straight-forward (or used to be, until they came up with > the SxS madness). It was actually the case that people did so > unexpectingly, and it seemed to work fine, except that it crashed when > passing FILE*. Then we started explaining that mixing CRTs is risky. Oh. Well then. :-) Cheers, - Alf -- blog at From sturlamolden at yahoo.no Wed Jul 7 16:10:00 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 13:10:00 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: On 7 Jul, 21:47, "Martin v. Loewis" wrote: > However, the C standard is silent wrt. to PyMem_MALLOC, and it certainly > allows the definition of macros which use the macro arguments more than > once. Ok, I knew there was something odd here. PyMem_Malloc is indeed a function, whilst PyMem_MALLOC is a deprecated macro. :) From hobson42 at gmaiil.com Wed Jul 7 16:10:36 2010 From: hobson42 at gmaiil.com (Ian) Date: Wed, 07 Jul 2010 21:10:36 +0100 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4C34DF3C.1040009@gmaiil.com> On 07/07/2010 19:38, Victor Subervi wrote: > Hi; > I have this code: > > sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, > user, ', %s'.join('%s' * len(col_vals)) > cursor.execute(sql, col_vals) > > Is this open to injection attacks? If so, how correct? > TIA, > beno Yes, it is trivially open to injection attacks. What would happen if someone enters the next line into one of your col_vals x,y);DROP DATABASE personalDataKeys; ha ha Your sql statement would be closed early by the semicolon, and the DROP TABLE personalDataKeys is then executed and would cause some unexpected data loss. Things could be more serious - DROP DATABASE mysql; for a mysql installation for example. You must always always every time and without any exceptions what-so-ever, put all and every piece of data that comes from outside the program through the appropriate routine to make whatever has been entered into storable data and not part of the sql statement. In php this is mysql_real_escape_string(). In your favourite language there will be an equivalent. If you miss just one occurrence its like leaving the side window unlocked! Someone will get in one day. Regards Ian p.s. Did I mention that there are no exceptions to the "sanitise every piece of data" rule? From invalid at invalid.invalid Wed Jul 7 16:22:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 20:22:32 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: On 2010-07-07, Martin v. Loewis wrote: > >> Also observe that this macro is very badly written (even illegal) C. >> Consider what this would do: >> >> PyMem_MALLOC(n++) >> >> According to Linus Thorvalds using macros like this is not even legal >> C: >> >> http://www.linuxfocus.org/common/src/January2004_linus.html > > [Please don't use "legal" wrt. programs - it's not "illegal" to violate > the language's rules; you don't go to jail when doing so. Linus said > "not allowed"] Nonsense. The world "illegal" doesn't mean "you'll go to jail". "Legal" and "illegal" are used to indicate conformance or nonconformace with respect to some set of rules -- be they a programming language standard, FIFA footbal rules, or Forumula 1 technical regulations. It's perfectly standard usage to refer to an "illegal forward pass" in American football, to "illegal tires" used during a race, or to an "illegal operation" in a program. -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!! From lists at cheimes.de Wed Jul 7 16:26:40 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 22:26:40 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: > Yeah, but then we're down to file descriptors, C library locales and such as the > remaining problems. Don't forget errno! Every CRT might have its own errno thread local. I don't know how its handled on Windows but I suspect it suffers from the same problem. Christia From sturlamolden at yahoo.no Wed Jul 7 16:35:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 13:35:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: mailman.372.1278534414.1673.python-list@python.org Message-ID: On 7 Jul, 22:26, Christian Heimes wrote: > Don't forget errno! Every CRT might have its own errno thread local. I > don't know how its handled on Windows but I suspect it suffers from the > same problem. The Windows API "errno" is GetLastError. But a delinquent CRT might map GetLastError() to other integers. From lists at cheimes.de Wed Jul 7 16:47:24 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 22:47:24 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: > The main problem that the required MSVC redistributables are not necessarily > present on the end user's system. It's not a problem for Python anymore. It took a while to sort all problems out. Martin and other developers have successfully figured out how to install the CRT for system wide and local user installations. A system wide installation installs the CRT in the side by side cache (WinSxS). A local installation keeps the msvcrt90.dll and the Microsoft.VC90.CRT.manifest next to the python.exe. Python extensions no longer embed a manifest so they share the CRT from the python.exe process. In order to ship a standalone exe you have to keep the CRT next to your exe. This should work for py2exe binaries as well. At our company we install our application stack entirely from subversion including Python 2.6.5, Sun JRE and lots of other stuff. This works perfectly fine for us even for servers without the MSVCRT redistributable. Christian From pavlovevidence at gmail.com Wed Jul 7 16:55:38 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jul 2010 13:55:38 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 7, 1:31?am, Paul McGuire wrote: > On Jul 6, 3:30 am, David Cournapeau wrote:> On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > > > One thing that would be very useful is how to maintain something that > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > versions below 2.6 is out of the question for most projects with a > > significant userbase IMHO. As such, the idea of running the python 3 > > warnings is not so useful IMHO - unless it could be made to work > > better for python 2.x < 2.6, but I am not sure the idea even makes > > sense. > > This is exactly how I felt about my support for pyparsing, that I was > trying continue to provide support for 2.3 users, up through 3.x > users, with a single code base. ?(This would actually have been > possible if I had been willing to introduce a performance penalty for > Python 2 users, but performance is such a critical issue for parsing I > couldn't justify it to myself.) ?This meant that I had to constrain my > implementation, while trying to incorporate forward-looking support > features (such as __bool__ and __dir__), which have no effect on older > Python versions, but support additions in newer Pythons. ?I just > couldn't get through on the python-dev list that I couldn't just > upgrade my code to 2.6 and then use 2to3 to keep in step across the > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. > > Here are some of the methods I used: > > - No use of sets. ?Instead I defined a very simple set simulation > using dict keys, which could be interchanged with set for later > versions. > > - No generator expressions, only list comprehensions. > > - No use of decorators. ?BUT, pyparsing includes a decorator method, > traceParseAction, which can be used by users with later Pythons as > @traceParseAction in their own code. > > - No print statements. ?As pyparsing is intended to be an internal > module, it does no I/O as part of its function - it only processes a > given string, and returns a data structure. > > - Python 2-3 compatible exception syntax. ?This may have been my > trickiest step. ?The change of syntax for except from > > ? ? except ExceptionType, ex: > > to: > > ? ? except ExceptionType as ex: > > is completely forward and backward incompatible. ?The workaround is to > rewrite as: > > ? ? except ExceptionType: > ? ? ? ? ex = sys.exc_info()[0] > > which works just fine in 2.x and 3.x. ?However, there is a slight > performance penalty in doing this, and pyparsing uses exceptions as > part of its grammar success/failure signalling and backtracking; I've > used this technique everywhere I can get away with it, but there is > one critical spot where I can't use it, so I have to keep 2 code bases > with slight differences between them. > > - Implement __bool__, followed by __nonzero__ = __bool__. ?This will > give you boolean support for your classes in 2.3-3.1. > > - Implement __dir__, which is unused by old Pythons, but supports > customization of dir() output for your own classes. > > - Implement __len__, __contains__, __iter__ and __reversed__ for > container classes. > > - No ternary expressions. ?Not too difficult really, there are several > well-known workarounds for this, either by careful use of and's and > or's, or using the bool-as-int to return the value from > (falseValue,trueValue)[condition]. > > - Define a version-sensitive portion of your module, to define > synonyms for constants that changed name between versions. ?Something > like: > > ? ? _PY3K = sys.version_info[0] > 2 > ? ? if _PY3K: > ? ? ? ? _MAX_INT = sys.maxsize > ? ? ? ? basestring = str > ? ? ? ? _str2dict = set > ? ? ? ? alphas = string.ascii_lowercase + string.ascii_uppercase > ? ? else: > ? ? ? ? _MAX_INT = sys.maxint > ? ? ? ? range = xrange > ? ? ? ? _str2dict = lambda strg : dict( [(c,0) for c in strg] ) > ? ? ? ? alphas = string.lowercase + string.uppercase > > The main body of my code uses range throughout (for example), and with > this definition I get the iterator behavior of xrange regardless of > Python version. > > In the end I still have 2 source files, one for Py2 and one for Py3, > but there is only a small and manageable number of differences between > them, and I expect at some point I will move forward to supporting Py3 > as my primary target version. ?But personally I think this overall > Python 2-3 migration process is moving along at a decent rate, and I > should be able to make my switchover in another 12-18 months. ?But in > the meantime, I am still able to support all versions of Python NOW, > and I plan to continue doing so (albeit "support" for 2.x versions > will eventually mean "continue to offer a frozen feature set, with > minimal bug-fixing if any"). > > I realize that pyparsing is a simple-minded module in comparison to > others: it is pure Python, so it has no issues with C extensions; it > does no I/O, so print-as-statement vs. print-as-function is not an > issue; and it imports few other modules, so the ones it does have not > been dropped in Py3; and overall it is only a few thousand lines of > code. ?But I just offer this post as a concrete data point in this > discussion. Thanks for the helpful post. However it looks like, other than the except syntax, all of these are things you're already doing to support 2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a little more work than supporting 2.3 and 2.6. We all know that Python is quite successful even with a history of backward-incompatible changes and feature additions and even minor paradigm shifts. What I'm interested in is, what things about the 2 to 3 transition is harder than already exists? >From Paul's post it looks like not as much as you'd think--but as he says it's a pretty simple package. Carl Banks From gnuist006 at gmail.com Wed Jul 7 16:56:39 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 7 Jul 2010 13:56:39 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV Message-ID: "Democracy is sick in the US, government monitors your Internet" http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr Enjoy ..... From gnuist006 at gmail.com Wed Jul 7 16:57:48 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 7 Jul 2010 13:57:48 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV Message-ID: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> "Democracy is sick in the US, government monitors your Internet" http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr Enjoy ..... From 007brendan at gmail.com Wed Jul 7 17:10:57 2010 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 7 Jul 2010 14:10:57 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> > > > One thing that would be very useful is how to maintain something that > > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > > versions below 2.6 is out of the question for most projects with a > > > significant userbase IMHO. As such, the idea of running the python 3 > > > warnings is not so useful IMHO - unless it could be made to work > > > better for python 2.x < 2.6, but I am not sure the idea even makes > > > sense. The entire fact that 3.x was *designed* to be incompatible should tell you that supporting 2.x and 3.x with a single code base is a bad idea, except for the very smallest of projects. This is the point where a project should fork and provide two different versions. From alf.p.steinbach+usenet at gmail.com Wed Jul 7 17:19:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 23:19:13 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Christian Heimes, on 07.07.2010 22:47: >> The main problem that the required MSVC redistributables are not necessarily >> present on the end user's system. > > It's not a problem for Python anymore. It took a while to sort all > problems out. Martin and other developers have successfully figured out > how to install the CRT for system wide and local user installations. A > system wide installation installs the CRT in the side by side cache > (WinSxS). A local installation keeps the msvcrt90.dll and the > Microsoft.VC90.CRT.manifest next to the python.exe. Python extensions no > longer embed a manifest so they share the CRT from the python.exe process. > > In order to ship a standalone exe you have to keep the CRT next to your > exe. This should work for py2exe binaries as well. At our company we > install our application stack entirely from subversion including Python > 2.6.5, Sun JRE and lots of other stuff. This works perfectly fine for us > even for servers without the MSVCRT redistributable. I think you're talking about a different problem. The CRT installed along with CPython works for extensions using the MSVC 9.0 CRT. However developing an extension with MSVC 10 the extension will use the 10.0 CRT, which is not necessarily present on the end user's system. As I see it there are five solutions with different trade-offs: A Already having Visual Studio 2008 (MSVC 9.0), or coughing up the money for an MSDN subscription, or visiting trade shows, so as to obtain that compiler version. -> Not an option for everybody. B Linking the CRT statically. -> Increased size, problems with CRT state such as file descriptors. C Linking the CRT dynamically and bundling the MSVC redistributables with the extension. -> Even more increased size for the download, but smaller total footprint for extensions in sum; same CRT state problems. D Linking the CRT dynamically and providing an optional download and install of the redistributables if they're not present. This would best be done with some support from the Python installation machinery. -> Small nice size for extensions, still same CRT state problems. E As D + a new compiler-independent native code interface that does not carry dependencies on CRT state such as file descriptors, like JNI. -> Really huge effort, and cannot be applied until some new Python version. And I think the clue here is that the CRT state problems can be avoided by careful coding. Hence, for those who cannot do A I think B is a realistic practical option, and D would be nice... Cheers, - Alf -- blog at From tim at bart.johnson.com Wed Jul 7 17:21:56 2010 From: tim at bart.johnson.com (Tim Johnson) Date: Wed, 07 Jul 2010 16:21:56 -0500 Subject: Recommend a MySQLdb Forum References: Message-ID: <8b-dnfRFFKVpcqnRnZ2dnUVZ_vydnZ2d@supernews.com> On 2010-07-07, Philip Semanchuk wrote: > > On Jul 6, 2010, at 3:16 PM, Tim Johnson wrote: > >> Greetings: >> I would appreciate it if some could recommend a MySQLdb forum. > > The one associated the sourceforge project seems like a good bet. > > 1) go here: http://sourceforge.net/projects/mysql-python/ > 2) click support Thanks Philip -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From ncauderan at gmail.com Wed Jul 7 17:30:14 2010 From: ncauderan at gmail.com (norbert) Date: Wed, 7 Jul 2010 14:30:14 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: > Well, you could use an approach like the one suggested here: > > http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-dea... That's nice, thanks. I'll use something like this. Just a thought : I will use "errors=replace" in the call to the encode method to be sure that the logger does not raise any exception. From martin at v.loewis.de Wed Jul 7 17:33:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 23:33:57 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: mailman.372.1278534414.1673.python-list@python.org Message-ID: <4C34F2C5.6040404@v.loewis.de> Am 07.07.2010 22:35, schrieb sturlamolden: > On 7 Jul, 22:26, Christian Heimes wrote: > >> Don't forget errno! Every CRT might have its own errno thread local. I >> don't know how its handled on Windows but I suspect it suffers from the >> same problem. > > The Windows API "errno" is GetLastError. But a delinquent CRT might > map GetLastError() to other integers. Please check the source before posting. msvcrt defines errno as _CRTIMP extern int * __cdecl _errno(void); #define errno (*_errno()) where _errno is (see dosmap.c) int * __cdecl _errno(void) { _ptiddata ptd = _getptd_noexit(); if (!ptd) { return &ErrnoNoMem; } else { return ( &ptd->_terrno ); } } where _getptd_noexit returns the CRT's per-thread data (see tidtable.c). So it *is* a mapping to other integers, and, even though it's called dosmap.c, it is maintained because of the (limited) POSIX support in the CRT. In particular, there is a mapping between GetLastError values and errno values that can't be implemented through simple defines (e.g. both ERROR_FILE_NOT_FOUND and ERROR_PATH_NOT_FOUND map to ENOENT). In addition, a standard C implementation can rely on only certain APIs changing errno, which MS perhaps might not be able to guarantee for GetLastError values in exactly the same manner. So with the way the Windows API is defined, a C implementation has no alternative but to be delinquent. Regards, Martin From alf.p.steinbach+usenet at gmail.com Wed Jul 7 17:40:54 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 23:40:54 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Alf P. Steinbach /Usenet, on 07.07.2010 23:19: > > However developing an extension with MSVC 10 the extension will use the > 10.0 CRT, which is not necessarily present on the end user's system. > > As I see it there are five solutions with different trade-offs: > > A Already having Visual Studio 2008 (MSVC 9.0), or coughing up the > money for an MSDN subscription, or visiting trade shows, so as to > obtain that compiler version. > -> Not an option for everybody. > > B Linking the CRT statically. > -> Increased size, problems with CRT state such as file descriptors. > > C Linking the CRT dynamically and bundling the MSVC redistributables > with the extension. > -> Even more increased size for the download, but smaller total > footprint for extensions in sum; same CRT state problems. > > D Linking the CRT dynamically and providing an optional download and > install of the redistributables if they're not present. This would > best be done with some support from the Python installation machinery. > -> Small nice size for extensions, still same CRT state problems. > > E As D + a new compiler-independent native code interface that > does not carry dependencies on CRT state such as file descriptors, like > JNI. > -> Really huge effort, and cannot be applied until some new Python version. > > And I think the clue here is that the CRT state problems can be avoided > by careful coding. > > Hence, for those who cannot do A I think B is a realistic practical > option, and D would be nice... Wait... F Possibly, as the docs say, "Developer Studio will throw in a lot of import libraries that you do not really need, adding about 100K to your executable. To get rid of them, use the Project Settings dialog, Link tab, to specify ignore default libraries. Add the correct msvcrtxx.lib to the list of libraries." Can anyone confirm whether this works in practice with MSVC 10? Cheers, - Alf -- blog at From python at lonely-star.org Wed Jul 7 17:48:11 2010 From: python at lonely-star.org (Nathan Huesken) Date: Wed, 7 Jul 2010 17:48:11 -0400 Subject: Storing a callback function as a class member Message-ID: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Hi, I have a class, where I want to store a callback function as a member to access later: class CallbackClass: def setCallback(self,cb): self.cb = cb def callCallback(self, para): self.cb(para) Doing so, I get the error: callbackFunc() takes exactly 1 parameter (2 given) self is given as parameter this way, is it not? How can this be done? Thanks! Nathan From sturlamolden at yahoo.no Wed Jul 7 17:49:43 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 14:49:43 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: mailman.372.1278534414.1673.python-list@python.org <4C34F2C5.6040404@v.loewis.de> Message-ID: On 7 Jul, 23:33, "Martin v. Loewis" wrote: > > The Windows API "errno" is GetLastError. But a delinquent CRT might > > map GetLastError() to other integers. > > Please check the source before posting. msvcrt defines errno as I don't have the source to msvcrt, at least not to my knowledge. From martin at v.loewis.de Wed Jul 7 17:56:04 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 23:56:04 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: mailman.372.1278534414.1673.python-list@python.org <4C34F2C5.6040404@v.loewis.de> Message-ID: <4C34F7F4.3010509@v.loewis.de> Am 07.07.2010 23:49, schrieb sturlamolden: > On 7 Jul, 23:33, "Martin v. Loewis" wrote: > >>> The Windows API "errno" is GetLastError. But a delinquent CRT might >>> map GetLastError() to other integers. >> >> Please check the source before posting. msvcrt defines errno as > > I don't have the source to msvcrt, at least not to my knowledge. If you have Visual Studio, and opted to install the CRT sources, you'll find them in VC/crt/src (or VC7/crt/src, depending on VS version). I'm not 100% sure whether they are included in VS Express as well. Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 17:59:48 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 14:59:48 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: On 7 Jul, 23:19, "Alf P. Steinbach /Usenet" wrote: > ? ?D Linking the CRT dynamically and providing an optional download and > ? ? ?install of the redistributables if they're not present. This would > ? ? ?best be done with some support from the Python installation machinery. > ? ? ?-> Small nice size for extensions, still same CRT state problems. This was a problem for py2exe'd apps before Python 2.6 (i.e. no public download for Visual C++ 2003 runtime files.) But for Visual C++ 2008 and 2010, the CRTs can be downloaded from Microsoft and need not be shipped with the application. http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en http://www.microsoft.com/downloads/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BD512D9E-43C8-4655-81BF-9350143D5867&displaylang=en From python at mrabarnett.plus.com Wed Jul 7 18:00:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 23:00:37 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4C34F905.5020301@mrabarnett.plus.com> Brendan Abel wrote: >>>> One thing that would be very useful is how to maintain something that >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>> versions below 2.6 is out of the question for most projects with a >>>> significant userbase IMHO. As such, the idea of running the python 3 >>>> warnings is not so useful IMHO - unless it could be made to work >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>> sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. This is the point where a > project should fork and provide two different versions. I wouldn't say that 3.x was designed to be incompatible. It was designed to tidy the language, and the incompatibilities are an unfortunate result. From invalid at invalid.invalid Wed Jul 7 18:01:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 22:01:28 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? Message-ID: I'm trying to use python bindings for libconfig. There appear to be three very slightly different bindings: http://code.google.com/p/python-libconfig/ http://wiki.github.com/cnangel/python-libconfig/ http://github.com/azeey/python-libconfig/ I'm using the latter with libconfig 1.4.5 http://www.hyperrealm.com/libconfig/ The python bindings appear to come with test cases, but I can't figure out how to run them. From reading the Python docs, it would appear that this should do something useful, but it doesn't: $ python -m unittest pylibconfig ---------------------------------------------------------------------- Ran 0 tests in 0.000s Trying to run the test script directory doesn't work either: $ python tests/test.py Traceback (most recent call last): File "tests/test.py", line 8, in from x64.pylibconfig import Config ImportError: No module named x64.pylibconfig Importing the module seems to be OK, but creating an instance barfs: Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pylibconfig >>> conf = pylibconfig.Config() *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Where to go from here? -- Grant Edwards grant.b.edwards Yow! Do you like "TENDER at VITTLES"? gmail.com From john at castleamber.com Wed Jul 7 18:04:34 2010 From: john at castleamber.com (John Bokma) Date: Wed, 07 Jul 2010 17:04:34 -0500 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> Message-ID: <87wrt7gd8t.fsf@castleamber.com> John Nagle writes: > Python 3 is a nice cleanup of some legacy syntax issues. But > that's just not enough. Perl 6 is a nice cleanup of Perl 5, Eh, I wouldn't call Perl 6 a "nice cleanup". It's much better to consider it a new language with roots in Perl 5 (amongst others). Or to quote from http://dev.perl.org/perl6/: "Perl 5 and Perl 6 are two languages in the Perl family, but of different lineages." > and look how that went. Ten years on, it's not even mainstream, let > alone dominant. I don't think that's the point of Perl 6 (if one can even say such a thing, that is). Right now, (I) think of Perl 6 as a test bed for features that couldn't be put in Perl 5 in an easy manner. Or (I) think of it as a programming language lab. My best guess is that with coming Christmas there will be a Perl 6 comparable to Python 3. But huge disclaimer: I hardly follow Perl 6 development. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From python at mrabarnett.plus.com Wed Jul 7 18:09:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 23:09:28 +0100 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: <4C34FB18.7040904@mrabarnett.plus.com> Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? > Could you provide a short program which we could run to reproduce the problem? From invalid at invalid.invalid Wed Jul 7 18:12:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 22:12:29 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-07, Grant Edwards wrote: > I'm trying to use python bindings for libconfig. There appear to be > three very slightly different bindings: > > http://code.google.com/p/python-libconfig/ > http://wiki.github.com/cnangel/python-libconfig/ > http://github.com/azeey/python-libconfig/ > > I'm using the latter with libconfig 1.4.5 > > http://www.hyperrealm.com/libconfig/ [...] > Importing the module seems to be OK, but creating an instance barfs: > > Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import pylibconfig > > >>> conf = pylibconfig.Config() > *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Oops. Those Python bindings are for version 1.3.2 of libconfig (which does work). They don't work with the current version of libconfig. I guess it's time to figure out how boost works... -- Grant Edwards grant.b.edwards Yow! ... I think I'd at better go back to my DESK gmail.com and toy with a few common MISAPPREHENSIONS ... From rhodri at wildebst.demon.co.uk Wed Jul 7 18:23:24 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 07 Jul 2010 23:23:24 +0100 Subject: Storing a callback function as a class member References: Message-ID: On Wed, 07 Jul 2010 22:48:11 +0100, Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? rhodri at gnudebst:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class CBClass: ... def set_cb(self, cb): ... self.cb = cb ... def call_cb(self, para): ... self.cb(para) ... >>> def trivial(arg): ... print arg ... >>> c = CBClass() >>> c.set_cb(trivial) >>> c.call_cb("Hello, world") Hello, world Works for me. Which version of Python are you using? -- Rhodri James *-* Wildebeeste Herder to the Masses From emile at fenx.com Wed Jul 7 18:31:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 07 Jul 2010 15:31:48 -0700 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: On 7/7/2010 2:48 PM Nathan Huesken said... > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > You'll have to show how you're invoking this -- the following works for me (ie, I don't get an error): class CallbackClass: def setCallback(self,cb): self.cb = cb def callCallback(self, para): self.cb(para) a = CallbackClass() def test(param): return 2*param a.setCallback(test) a.callCallback(3) Emile From tartley at tartley.com Wed Jul 7 18:35:25 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 7 Jul 2010 15:35:25 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> <4C34D3FE.6000905@v.loewis.de> Message-ID: On Jul 7, 8:22?pm, "Martin v. Loewis" wrote: > > I presume this problem would go away if future versions of Python > > itself were compiled on Windows with something like MinGW gcc. Also, > > this would solve the pain of Python developers attempting to > > redistribute py2exe versions of their programs (i.e. they have to own > > a Visual Studio license to legally be able to redistribute the > > required C runtime) I don't understand enough to know why Visual > > Studio was chosen instead of MinGW. Can anyone shed any light on that > > decision? > > sturlamolden has already given the primary reason: Python, > traditionally, attempts to use and work with the system vendor's > compiler. On Windows, that's MSC. It's typically the one that best knows > about platform details that other compilers might be unaware of. > > In addition, it's also the compiler and IDE that Windows developers (not > just Python core people, but also extension developers and embedders) > prefer to use, as it has quite good IDE support (in particular debugging > and code browsing). > > Perhaps more importantly, none of the other compilers is really an > alternative. GCC in particular cannot build the Win32 extensions, since > it doesn't support the COM and ATL C++ features that they rely on (and > may not support other MSC extensions, either). So the Win32 extensions > must be built with VS, which means Python itself needs to use the same > compiler. > > Likewise important: gcc/mingw is *not* a complete C compiler on Windows. > A complete C compiler would have to include a CRT (on Windows); mingw > doesn't (cygwin does, but I think you weren't proposing that Python be > built for cygwin - you can easily get cygwin Python anyway). Instead, > mingw relies on users having a CRT available to > them - and this will be a Microsoft one. So even if gcc was used, we > would have versioning issues with Microsoft CRTs, plus we would have to > rely on target systems including the right CRT, as we couldn't include > it in the distribution. > > HTH, > Martin I see. Thanks very much to both of you for the info, much appreciated. From sturla at molden.no Wed Jul 7 18:55:50 2010 From: sturla at molden.no (sturlamolden) Date: Wed, 7 Jul 2010 15:55:50 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> <4C34D3FE.6000905@v.loewis.de> Message-ID: <7f718cfd-aad3-4e0c-a372-67885a5678ca@i28g2000yqa.googlegroups.com> On 8 Jul, 00:35, Jonathan Hartley wrote: > I see. Thanks very much to both of you for the info, much appreciated. The problem you referred to for py2exe despaired with Python 2.6. For Python 2.5, there was no public download option for msvcr71.dll and msvcp71.dll. There was also the unsolved SxS issue. Thus a license for Visual Studio 2003 was required to distribute py2exe apps for Python 2.5. That is now history. For py2exe apps using Python 2.6, 2.7 or 3.1, you can just ask your clients to install this: http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en There are similar downloads for Visual C++ 2010 run-time files as well. Python 3.2 will probably be built with Visual Studio 2010. From rami.chowdhury at gmail.com Wed Jul 7 19:10:45 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 7 Jul 2010 16:10:45 -0700 Subject: Argh! Name collision! In-Reply-To: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: <201007071610.45700.rami.chowdhury@gmail.com> On Tuesday 06 July 2010 22:42:25 rantingrick wrote: > On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" > +use... at gmail.com> wrote: > > "pyni"! Pronounced like "tiny"! Yay! > > hmm, how's about an alternate spelling... "pyknee", or "pynee", or > "pynie" ... considering those are not taken either? Pynie's taken too -- it's the Python implementation on the Parrot VM. ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From wolfram.hinderer at googlemail.com Wed Jul 7 19:13:25 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Wed, 7 Jul 2010 16:13:25 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> On 7 Jul., 19:32, Ethan Furman wrote: > Nobody wrote: > > On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > > >> you should never rely on a floating-point number to have exactly a > >> certain value. > > > "Never" is an overstatement. There are situations where you can rely > > upon a floating-point number having exactly a certain value. > > It's not much of an overstatement. ?How many areas are there where you > need the number > 0.100000000000000005551115123125782702118158340454101562500000000000? > > If I'm looking for 0.1, I will *never* (except by accident ;) say > > if var == 0.1: > > it'll either be <= or >=. The following is an implementation of a well-known algorithm. Why would you want to replace the floating point comparisons? With what? (This is toy-code.) ##### from random import random def min_cost_path(cost_right, cost_up): """ return minimal cost and its path in a rectangle - going up and right only """ cost = dict() size_x, size_y = max(cost_right) #compute minimal cost cost[0, 0] = 0.0 for x in range(size_x): cost[x + 1, 0] = cost[x, 0] + cost_right[x, 0] for y in range(size_y): cost[0, y + 1] = cost[0, y] + cost_up[0, y] for x in range(size_x): cost[x + 1, y + 1] = min(cost[x, y + 1] + cost_right[x, y + 1], cost[x + 1, y] + cost_up[x + 1, y]) #compute path (reversed) x = size_x y = size_y path = [] while x != 0 and y != 0: if x == 0: y -= 1 path.append("u") elif y == 0: x -= 1 path.append("r") elif cost[x - 1, y] + cost_right[x - 1, y] == cost[x, y]: # fp compare x -= 1 path.append("r") elif cost[x, y - 1] + cost_up[x, y - 1] == cost[x, y]: # fp compare y -= 1 path.append("u") else: raise ValueError return cost[size_x, size_y], "".join(reversed(path)) if __name__ == "__main__": size = 100 cost_right = dict(((x, y), random()) for x in range(size) for y in range(size)) cost_up = dict(((x, y), random()) for x in range(size) for y in range(size)) print min_cost_path(cost_right, cost_up) From python at mrabarnett.plus.com Wed Jul 7 19:36:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jul 2010 00:36:51 +0100 Subject: Argh! Name collision! In-Reply-To: <201007071610.45700.rami.chowdhury@gmail.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> <201007071610.45700.rami.chowdhury@gmail.com> Message-ID: <4C350F93.2040207@mrabarnett.plus.com> Rami Chowdhury wrote: > On Tuesday 06 July 2010 22:42:25 rantingrick wrote: >> On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" > >> +use... at gmail.com> wrote: >>> "pyni"! Pronounced like "tiny"! Yay! >> hmm, how's about an alternate spelling... "pyknee", or "pynee", or >> "pynie" ... considering those are not taken either? > > Pynie's taken too -- it's the Python implementation on the Parrot VM. > "PyNatInt" gets no hits on Google. From kedra.marbun at gmail.com Wed Jul 7 19:42:26 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Wed, 7 Jul 2010 16:42:26 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> Message-ID: <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> On Jul 7, 2:46?am, Bruno Desthuilliers wrote: > Gregory Ewing a ?crit : > > > Bruno Desthuilliers wrote: > >> kedra marbun a ?crit : > > >>> if we limit our discussion to py: > >>> why __{get|set|delete}__ don't receive the 'name' & 'class' from > >>> __{getattribute|{set|del}attr}__ > >>> 'name' is the name that is searched > > >> While it would have been technically possible, I fail to imagine any use > >> case for this. > > > I think he wants to have generic descriptors that are > > shared between multiple attributes, but have them do > > different things based on the attribute name. > > I already understood this, but thanks !-) > > What I dont understand is what problem it could solve that couldn't be > solved more simply using the either _getattr__ hook or hand-coded > delegation, since such a descriptor would be so tightly coupled to the > host class that it just doesn't make sense writing a descriptor for this. yeah, i finally can agree descriptor isn't supposed to be used as delegation in general, it should be the job of __getattr__ however i still think passing name would open up some other possibilities of use (not necessarily on the basis of sharing descriptor), surely some of them (all of it?) are bad. sure as hell, my example is an example of bad use. for now, i conclude that passing name is too risky, it easily allows bad practices particularly against the law of Demeter thanks Bruno btw, is there a common approach to let the interface of a class that uses __getattr__, to include names that are delegated? class A: def do_this(self): ... class B: a = A() def do_that(self): ... def __getattr__(self, name): try: return types.MethodType(getattr(self.a, name), self) except AttributeError: raise AttributeError how to make 'dir(B)' includes 'do_this', do i have to use __dir__? and if i use __dir__, somewhat 'help(B)' doesn't work as usual, i haven't check pydoc.py ;) From cousinstanley at gmail.com Wed Jul 7 19:46:13 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 7 Jul 2010 23:46:13 +0000 (UTC) Subject: Getting pyparsing to backtrack References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: > I'm working on street address parsing again, > and I'm trying to deal with some of the harder cases. > .... For yet another test case my actual address includes .... ... East South Mountain Avenue Sometimes written as .... ... E. South Mtn Ave -- Stanley C. Kitching Human Being Phoenix, Arizona From alf.p.steinbach+usenet at gmail.com Wed Jul 7 19:47:01 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 01:47:01 +0200 Subject: Argh! Name collision! In-Reply-To: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: * rantingrick, on 07.07.2010 07:42: > On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> "pyni"! Pronounced like "tiny"! Yay! > > hmm, how's about an alternate spelling... "pyknee", or "pynee", or > "pynie" ... considering those are not taken either? Hm, for pure shock value I think I'll use the acronym PYthon Native Interface Support. pynis! :-) A set of C++ classes to ease the writing of extensions. Like, // progrock.pynis -- "Python Native Interface Support" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef PYNIS_PTR_H #define PYNIS_PTR_H #include //----------------------------------------- Dependencies: #include #include #include //----------------------------------------- Interface: namespace progrock{ namespace pynis { enum DoAddRef { doAddRef }; class Ptr { private: PyObject* p_; public: Ptr( PyObject* p = 0 ): p_( p ) {} Ptr( PyObject* p, DoAddRef ): p_( p ) { assert( p != 0 ); Py_INCREF( p_ ); } Ptr( Ptr const& other ): p_( other.p_ ) { Py_XINCREF( p_ ); } ~Ptr() { Py_XDECREF( p_ ); } void swapWith( Ptr& other ) { std::swap( p_, other.p_ ); } Ptr& operator=( Ptr other ) { swapWith( other ); return *this; } PyObject* get() const { return p_; } PyObject* release() { PyObject* const result = p_; Py_XDECREF( p_ ); p_ = 0; return result; } }; } } // namespace progrock::pynis #endif Cheers, - Alf (shocked) PS: Darn, forgot to google it. But I think it's unlikely the name's already in use! -- blog at From kedra.marbun at gmail.com Wed Jul 7 19:52:50 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Wed, 7 Jul 2010 16:52:50 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <4c32baec$0$28649$c3e8da3@news.astraweb.com> Message-ID: <4c5d3d09-4cf5-483e-96e2-ce0fade5a471@b4g2000pra.googlegroups.com> On Jul 6, 12:11?pm, Steven D'Aprano wrote: > On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > > On Jul 5, 7:49?am, Gregory Ewing wrote: > >> kedra marbun wrote: > >> > now, i'm asking another favor, what about the 2nd point in my 1st > >> > post? > > >> Your original post has dropped off my newsscope, so you'll have to > >> remind me what the 2nd point was. > > >> -- > >> Greg > > > it's like 'name', it's about info that i think should be passed to > > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > > passing the class on which the descriptor is attached to, what pattern > > is encouraged by this? > > Perhaps I'm missing the context, but since the descriptor is passed the > instance, you can easily get the class with type(self) or self.__class__. > There's no need to pass the class as a separate argument. > > -- > Steven no, the class that i meant is the one that actually has the descriptor in its __dict__, not instance.__class__ the class obj that you said unecessary-as-arg is what __get__ receives as the 3rd arg class Desc: def __get__(*args): print(args) class a: v0 = Desc() class b(a): pass b().v0 #(desc, b(), b) From kee at kagi.com Wed Jul 7 20:14:58 2010 From: kee at kagi.com (Kee Nethery) Date: Wed, 7 Jul 2010 17:14:58 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: Yes, you SQL would be trivial to manipulate via SQL injection. Not only do you need to validate each piece of data submitted by a user, you need to escape all the wildcard characters that your database uses. If the text string supplied by a user has quotes or parens or wildcard characters, the text could be interpreted as SQL and that is what you must avoid. Kee Nethery From 007brendan at gmail.com Wed Jul 7 20:26:20 2010 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 7 Jul 2010 17:26:20 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> On Jul 7, 3:00?pm, MRAB wrote: > Brendan Abel wrote: > >>>> One thing that would be very useful is how to maintain something that > >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > >>>> versions below 2.6 is out of the question for most projects with a > >>>> significant userbase IMHO. As such, the idea of running the python 3 > >>>> warnings is not so useful IMHO - unless it could be made to work > >>>> better for python 2.x < 2.6, but I am not sure the idea even makes > >>>> sense. > > > The entire fact that 3.x was *designed* to be incompatible should tell > > you that supporting 2.x and 3.x with a single code base is a bad idea, > > except for the very smallest of projects. ?This is the point where a > > project should fork and provide two different versions. > > I wouldn't say that 3.x was designed to be incompatible. It was designed > to tidy the language, and the incompatibilities are an unfortunate > result. You're missing the point, and arguing semantics. It's a good thing I didn't misspell anything. Python 3.x will continue to change. The incompatibilities between 3.x and 2.x will only become more numerous. If your goal is to support 2.x, and 3.x, you'd be best supporting them separately. From ian.g.kelly at gmail.com Wed Jul 7 20:35:25 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Jul 2010 18:35:25 -0600 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: On Wed, Jul 7, 2010 at 3:48 PM, Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > ? ?def setCallback(self,cb): > ? ? ? ?self.cb = cb > > ? ?def callCallback(self, para): > ? ? ? ?self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? No, self will not be passed as a parameter. A function is only treated as a method when it is present in the class dict. If it is in the instance dict as you have above, then it's just a normal function. If you want it to receive self in this case, then you should have your callCallback method pass it in explicitly. HTH, Ian From debatem1 at gmail.com Wed Jul 7 20:54:39 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 20:54:39 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: > On Jul 7, 3:00?pm, MRAB wrote: >> Brendan Abel wrote: >> >>>> One thing that would be very useful is how to maintain something that >> >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >> >>>> versions below 2.6 is out of the question for most projects with a >> >>>> significant userbase IMHO. As such, the idea of running the python 3 >> >>>> warnings is not so useful IMHO - unless it could be made to work >> >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >> >>>> sense. >> >> > The entire fact that 3.x was *designed* to be incompatible should tell >> > you that supporting 2.x and 3.x with a single code base is a bad idea, >> > except for the very smallest of projects. ?This is the point where a >> > project should fork and provide two different versions. >> >> I wouldn't say that 3.x was designed to be incompatible. It was designed >> to tidy the language, and the incompatibilities are an unfortunate >> result. > > You're missing the point, and arguing semantics. ?It's a good thing I > didn't misspell anything. > > Python 3.x will continue to change. ?The incompatibilities between 3.x > and 2.x will only become more numerous. ?If your goal is to support > 2.x, and 3.x, you'd be best supporting them separately. I maintain two projects that have to work from 2.5 to 3.1. On one of them (~5kloc) we took the separate support route, and on the other (~30kloc) I decided to keep a single codebase. IME the maintenance burden on the former is substantially higher than the latter. Is the difference in difficulty perhaps domain-related, or a result of a certain style of coding? Could you give us some more details about what you were working on that caused you to conclude this? Geremy Condra From sridharr at activestate.com Wed Jul 7 21:08:07 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Wed, 07 Jul 2010 18:08:07 -0700 Subject: ANN: ActivePython 2.7.0.1 is now available Message-ID: <4C3524F7.7030005@activestate.com> We are pleased to announce the availability of ActivePython 2.7.0.1. http://www.activestate.com/activepython This release corresponds to the recently released Python 2.7, and, like ActivePython 2.6, includes the Python Package Manager (PyPM) with essential packages such as Distribute (a compatible fork of setuptools), virtualenv, pip and SQLAlchemy. See the release notes for full details: http://docs.activestate.com/activepython/2.7/relnotes.html#changes For a high-level overview of this release, please see our blog post: http://www.activestate.com/blog/2010/07/activepython-27-released This is also the first ActivePython release with 64-bit support on MacOSX. What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6 and 2.7 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business, Enterprise or OEM edition only) - Solaris/x86 (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (Enterprise or OEM edition only) - AIX/PowerPC (Business, Enterprise or OEM edition only) - AIX/PowerPC 64-bit (Business, Enterprise or OEM edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From ben+python at benfinney.id.au Wed Jul 7 21:14:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 11:14:15 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <87tyoabwrc.fsf@benfinney.id.au> geremy condra writes: > On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: > > Python 3.x will continue to change. ?The incompatibilities between > > 3.x and 2.x will only become more numerous. ?If your goal is to > > support 2.x, and 3.x, you'd be best supporting them separately. > > I maintain two projects that have to work from 2.5 to 3.1. On one of > them (~5kloc) we took the separate support route, and on the other > (~30kloc) I decided to keep a single codebase. IME the maintenance > burden on the former is substantially higher than the latter. The point, one more time with feeling, is that the incompatibilities between 2.x and 3.x will *increase* over time. If you now have a code base that is relatively easy to maintain for both Python 2.x and 3.x, that is a result of much back-porting efforts and of a new-feature moratorium that is currently in effect. Enjoy that situation as you may, because it is guaranteed not to last. Indeed, the feature moratorium is designed in part to help slow-moving codebases migrate to Python 3.x before Python resumes its normal pace of change again. If you're choosing to use that time to further entrench codebases for Python 2.x, I think that's a short-sighted choice. Python 2.7 is the last 2.x, no further 3.x features will be back-ported. New 3.x features will begin to appear after the moratorium ends. The combination of those two means that *the single-codebase burden will only increase over time* as Python 3.x diverges further from what Python 2.x can support. -- \ ?Programs must be written for people to read, and only | `\ incidentally for machines to execute.? ?Abelson & Sussman, | _o__) _Structure and Interpretation of Computer Programs_ | Ben Finney From python at mrabarnett.plus.com Wed Jul 7 21:22:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jul 2010 02:22:13 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <4C352845.4080709@mrabarnett.plus.com> geremy condra wrote: > On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: >> On Jul 7, 3:00 pm, MRAB wrote: >>> Brendan Abel wrote: >>>>>>> One thing that would be very useful is how to maintain something that >>>>>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>>>>> versions below 2.6 is out of the question for most projects with a >>>>>>> significant userbase IMHO. As such, the idea of running the python 3 >>>>>>> warnings is not so useful IMHO - unless it could be made to work >>>>>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>>>>> sense. >>>> The entire fact that 3.x was *designed* to be incompatible should tell >>>> you that supporting 2.x and 3.x with a single code base is a bad idea, >>>> except for the very smallest of projects. This is the point where a >>>> project should fork and provide two different versions. >>> I wouldn't say that 3.x was designed to be incompatible. It was designed >>> to tidy the language, and the incompatibilities are an unfortunate >>> result. >> You're missing the point, and arguing semantics. It's a good thing I >> didn't misspell anything. >> >> Python 3.x will continue to change. The incompatibilities between 3.x >> and 2.x will only become more numerous. If your goal is to support >> 2.x, and 3.x, you'd be best supporting them separately. > > I maintain two projects that have to work from 2.5 to 3.1. On one of > them (~5kloc) we took the separate support route, and on the other > (~30kloc) I decided to keep a single codebase. IME the maintenance > burden on the former is substantially higher than the latter. Is the > difference in difficulty perhaps domain-related, or a result of a > certain style of coding? Could you give us some more details about > what you were working on that caused you to conclude this? > In my work on the regex module I use a single codebase and generate the sources for Python 2.5-2.7 and for Python 3.1 from it. It works easily enough for me. From fuzzyman at gmail.com Wed Jul 7 21:44:01 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 7 Jul 2010 18:44:01 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On Jul 5, 1:34?am, sturlamolden wrote: > On 5 Jul, 01:58, John Nagle wrote: > > > ? ? ?Exactly. > > > ? ? ?The "incompatible with all extension modules I need" part > > is the problem right now. ?A good first step would be to > > identify the top 5 or 10 modules that are blocking a move to > > Python 3 by major projects with many users. > > The big danger is Python 2.x becoming abandonware (2.7 being the final > release) before major projects are ported. Using Python 2.x for new > projects is not advisable (at least many will think so), and using 3.x > is not possible. What to do? It's not a helpful situation for Python. But Python 2.3, 2.4 & 2.5 are *already* abandonware and see *major* use in many systems and businesses. Python development has always gone ahead of what *some* people use - and they don't seem to mind that they're using essentially abandoned versions of Python. Now that 2.7 is out I *might* be able to persuade my current company to migrate to 2.6 on the servers, and they're far faster at adopting tech than many companies I know. All the best, Michael Foord -- http://www.voidspace.org.uk From pavlovevidence at gmail.com Wed Jul 7 22:01:49 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jul 2010 19:01:49 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: On Jul 7, 2:10?pm, Brendan Abel <007bren... at gmail.com> wrote: > > > > One thing that would be very useful is how to maintain something that > > > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > > > versions below 2.6 is out of the question for most projects with a > > > > significant userbase IMHO. As such, the idea of running the python 3 > > > > warnings is not so useful IMHO - unless it could be made to work > > > > better for python 2.x < 2.6, but I am not sure the idea even makes > > > > sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. ?This is the point where a > project should fork and provide two different versions. Well, I think it could be a reasonable thing to maintain a single codebase in 2.x and use 2to3 (and/or a custom translator) to translate to 3.x version for quite a while. For the humble library I maintain, I plan to release a Python 3 version as soon as a Python 3 version of numpy is released, maintain a single codebase (translating from 2 version to 3) for awhile, then at some point fork them and maintain them separately. Given that I add features about once every 2 years I don't think it'll be too much of a burden, though. Carl Banks From imageguy1206 at gmail.com Wed Jul 7 22:17:02 2010 From: imageguy1206 at gmail.com (imageguy) Date: Wed, 7 Jul 2010 19:17:02 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> > I, too, have multiple versions installed -- newer ones for running code > I haven't upgraded; older ones for compatibility testing where needed. > I just install to the default c:\pythonxy directories (although I like > the idea of a common root) and I put NTFS hardlinks into my general > c:\tools directory which is on the path. The out-of-context hardlinks > work because of the registry settings which pick up the correct context > for each version. Sorry to be daft here, but what do you mean by a "hardlink" ? A windows "Shortcut" ? I have just installed 2.7 and want to start upgrading some code, but alas still want to maintain some 2.5 code too. From no.email at nospam.invalid Wed Jul 7 22:27:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 19:27:45 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <7xoceiaese.fsf@ruckus.brouhaha.com> Ben Finney writes: > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. The issue is less the "incompatibilities" than the -backwards- incompatibilities. Yes, Python 3 may introduce forward incompatibilities by adding features absent from Python 2. But it will be possible to maintain a common codebase simply by not using those features. On the other hand, the door appears closed for Python 3 adding more stuff that breaks Python 2 code. From debatem1 at gmail.com Wed Jul 7 22:32:44 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 22:32:44 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: > geremy condra writes: > >> On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: >> > Python 3.x will continue to change. ?The incompatibilities between >> > 3.x and 2.x will only become more numerous. ?If your goal is to >> > support 2.x, and 3.x, you'd be best supporting them separately. >> >> I maintain two projects that have to work from 2.5 to 3.1. On one of >> them (~5kloc) we took the separate support route, and on the other >> (~30kloc) I decided to keep a single codebase. IME the maintenance >> burden on the former is substantially higher than the latter. > > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. ...and? I don't get to use features from 2.7, why would I expect to use features from 3.3? > If you now have a code base that is relatively easy to maintain for both > Python 2.x and 3.x, that is a result of much back-porting efforts and of > a new-feature moratorium that is currently in effect. Enjoy that > situation as you may, because it is guaranteed not to last. I have to target the oldest version of Python I want to support. New features are irrelevant. I'm not sure why I should need to explain that to you. > Indeed, the feature moratorium is designed in part to help slow-moving > codebases migrate to Python 3.x before Python resumes its normal pace of > change again. If you're choosing to use that time to further entrench > codebases for Python 2.x, I think that's a short-sighted choice. I welcome the day that I can stop supporting 2.x. Until then, I have to support both and your argument is irrelevant. > Python 2.7 is the last 2.x, no further 3.x features will be back-ported. > New 3.x features will begin to appear after the moratorium ends. The > combination of those two means that *the single-codebase burden will > only increase over time* as Python 3.x diverges further from what Python > 2.x can support. See above. Geremy Condra From alf.p.steinbach+usenet at gmail.com Wed Jul 7 22:42:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 04:42:59 +0200 Subject: Argh! Name collision! In-Reply-To: References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: * Alf P. Steinbach /Usenet, on 08.07.2010 01:47: > > enum DoAddRef { doAddRef }; > > class Ptr > { > private: > PyObject* p_; > > public: > Ptr( PyObject* p = 0 ): p_( p ) > {} > > Ptr( PyObject* p, DoAddRef ): p_( p ) > { > assert( p != 0 ); > Py_INCREF( p_ ); > } > > Ptr( Ptr const& other ): p_( other.p_ ) > { > Py_XINCREF( p_ ); > } > > ~Ptr() > { > Py_XDECREF( p_ ); > } > > void swapWith( Ptr& other ) { std::swap( p_, other.p_ ); } > Ptr& operator=( Ptr other ) { swapWith( other ); return *this; } > > PyObject* get() const { return p_; } > > PyObject* release() > { > PyObject* const result = p_; > Py_XDECREF( p_ ); Hark. This Py_XDECREF shouldn't be there, I don't know how it got there. The whole point of 'release', with conventional semantics, is to /not/ decrement the reference count. > p_ = 0; > return result; > } > }; Sorry for posting unfinished code, - Alf PS: "pyni" was a good name. But in use! When I thought about adding the "s" as disambiguation I thought the pure shock value of that was funny in a way, but now it doesn't seem funny. Is "pytes" (Python Extension Support) a good name? -- blog at From ben+python at benfinney.id.au Wed Jul 7 22:49:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 12:49:23 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> Message-ID: <87pqyybscs.fsf@benfinney.id.au> Paul Rubin writes: > Ben Finney writes: > > The point, one more time with feeling, is that the incompatibilities > > between 2.x and 3.x will *increase* over time. > > The issue is less the "incompatibilities" than the -backwards- > incompatibilities. Yes, that's what I meant. Python 3 is deliberately under no obligation to support code that works in Python 2. If something needs fixing, and that fix would involve breaking Python 2 code, then that's not a consideration any more. The predictable result is that Python 3 will continue to gain backward-incompatible changes in future. > On the other hand, the door appears closed for Python 3 adding more > stuff that breaks Python 2 code. What gives you that idea? Can you reference a specific statement from the PYthon developers that says that? -- \ ?Not to be absolutely certain is, I think, one of the essential | `\ things in rationality.? ?Bertrand Russell | _o__) | Ben Finney From cournape at gmail.com Wed Jul 7 22:50:47 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 04:50:47 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Wed, Jul 7, 2010 at 10:55 PM, Carl Banks wrote: > On Jul 7, 1:31?am, Paul McGuire wrote: >> On Jul 6, 3:30 am, David Cournapeau wrote:> On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: >> >> > One thing that would be very useful is how to maintain something that >> > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >> > versions below 2.6 is out of the question for most projects with a >> > significant userbase IMHO. As such, the idea of running the python 3 >> > warnings is not so useful IMHO - unless it could be made to work >> > better for python 2.x < 2.6, but I am not sure the idea even makes >> > sense. >> >> This is exactly how I felt about my support for pyparsing, that I was >> trying continue to provide support for 2.3 users, up through 3.x >> users, with a single code base. ?(This would actually have been >> possible if I had been willing to introduce a performance penalty for >> Python 2 users, but performance is such a critical issue for parsing I >> couldn't justify it to myself.) ?This meant that I had to constrain my >> implementation, while trying to incorporate forward-looking support >> features (such as __bool__ and __dir__), which have no effect on older >> Python versions, but support additions in newer Pythons. ?I just >> couldn't get through on the python-dev list that I couldn't just >> upgrade my code to 2.6 and then use 2to3 to keep in step across the >> 2-3 chasm, as this would leave behind my faithful pre-2.6 users. >> >> Here are some of the methods I used: >> >> - No use of sets. ?Instead I defined a very simple set simulation >> using dict keys, which could be interchanged with set for later >> versions. >> >> - No generator expressions, only list comprehensions. >> >> - No use of decorators. ?BUT, pyparsing includes a decorator method, >> traceParseAction, which can be used by users with later Pythons as >> @traceParseAction in their own code. >> >> - No print statements. ?As pyparsing is intended to be an internal >> module, it does no I/O as part of its function - it only processes a >> given string, and returns a data structure. >> >> - Python 2-3 compatible exception syntax. ?This may have been my >> trickiest step. ?The change of syntax for except from >> >> ? ? except ExceptionType, ex: >> >> to: >> >> ? ? except ExceptionType as ex: >> >> is completely forward and backward incompatible. ?The workaround is to >> rewrite as: >> >> ? ? except ExceptionType: >> ? ? ? ? ex = sys.exc_info()[0] >> >> which works just fine in 2.x and 3.x. ?However, there is a slight >> performance penalty in doing this, and pyparsing uses exceptions as >> part of its grammar success/failure signalling and backtracking; I've >> used this technique everywhere I can get away with it, but there is >> one critical spot where I can't use it, so I have to keep 2 code bases >> with slight differences between them. >> >> - Implement __bool__, followed by __nonzero__ = __bool__. ?This will >> give you boolean support for your classes in 2.3-3.1. >> >> - Implement __dir__, which is unused by old Pythons, but supports >> customization of dir() output for your own classes. >> >> - Implement __len__, __contains__, __iter__ and __reversed__ for >> container classes. >> >> - No ternary expressions. ?Not too difficult really, there are several >> well-known workarounds for this, either by careful use of and's and >> or's, or using the bool-as-int to return the value from >> (falseValue,trueValue)[condition]. >> >> - Define a version-sensitive portion of your module, to define >> synonyms for constants that changed name between versions. ?Something >> like: >> >> ? ? _PY3K = sys.version_info[0] > 2 >> ? ? if _PY3K: >> ? ? ? ? _MAX_INT = sys.maxsize >> ? ? ? ? basestring = str >> ? ? ? ? _str2dict = set >> ? ? ? ? alphas = string.ascii_lowercase + string.ascii_uppercase >> ? ? else: >> ? ? ? ? _MAX_INT = sys.maxint >> ? ? ? ? range = xrange >> ? ? ? ? _str2dict = lambda strg : dict( [(c,0) for c in strg] ) >> ? ? ? ? alphas = string.lowercase + string.uppercase >> >> The main body of my code uses range throughout (for example), and with >> this definition I get the iterator behavior of xrange regardless of >> Python version. >> >> In the end I still have 2 source files, one for Py2 and one for Py3, >> but there is only a small and manageable number of differences between >> them, and I expect at some point I will move forward to supporting Py3 >> as my primary target version. ?But personally I think this overall >> Python 2-3 migration process is moving along at a decent rate, and I >> should be able to make my switchover in another 12-18 months. ?But in >> the meantime, I am still able to support all versions of Python NOW, >> and I plan to continue doing so (albeit "support" for 2.x versions >> will eventually mean "continue to offer a frozen feature set, with >> minimal bug-fixing if any"). >> >> I realize that pyparsing is a simple-minded module in comparison to >> others: it is pure Python, so it has no issues with C extensions; it >> does no I/O, so print-as-statement vs. print-as-function is not an >> issue; and it imports few other modules, so the ones it does have not >> been dropped in Py3; and overall it is only a few thousand lines of >> code. ?But I just offer this post as a concrete data point in this >> discussion. > > Thanks for the helpful post. ?However it looks like, other than the > except syntax, all of these are things you're already doing to support > 2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a > little more work than supporting 2.3 and 2.6. > > We all know that Python is quite successful even with a history of > backward-incompatible changes and feature additions and even minor > paradigm shifts. ?What I'm interested in is, what things about the 2 > to 3 transition is harder than already exists? The 2->3 transition is harder because backward incompatibilities are much more pervasive. In Numpy, adapting the code for python 2.6 was mostly trivial, for example (removing variables named "as" or "with"). For 3.x, it required much more work. The question really is one of cost vs benefit: for any new version of 2.x, supporting it was very useful because new python 2.x would become the default of popular linux distribution, and that's what most casual windows users would get since it was the default download. Python 3.x required much more work, for a much smaller perceived benefit as far as I am concerned (I don't claim to represent anyone but myself here for numpy transition to 3.x). In particular, assuming the main argument of python 3.x is a cleaner language, it evaporates for projects which need to support both 2.x and 3.x projects. Unless you maintain 2 codebases, this means the project code is less clean, not cleaner because of compatibility requirements. As most people I guess, I find discussion about print vs print() completely pointless - certainly, this is the simplest and most trivial change to apply to a codebase. But I think python 3.x needs to bring more tangible advantages to make the cost more bearable. I am hopeful that python 3.4 or 3.5 will have features/improvements which will make this worthwhile, but 3.1, not so much, David From alf.p.steinbach+usenet at gmail.com Wed Jul 7 22:57:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 04:57:13 +0200 Subject: How do I add method dynamically to module using C API? Message-ID: The code below, very much work in progress, just trying things, is C++. Sorry about the formatting, I had to reformat manually for this posting: class Module { private: Ptr p_; public: Module( PyModuleDef const& def ) : p_( ::PyModule_Create( const_cast< PyModuleDef* >( &def ) ) ) { (p_.get() != 0) || cppx::throwX( "Module::: failed" ); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "PyUnicode_FromWideChar failed" ); int const _ = ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ); (_ != -1 ) || cppx::throwX( "PyObject_SetAttrString failed" ); } void setRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef def = { name, f, METH_VARARGS, doc }; Ptr const pyName = ::PyUnicode_FromString( name ); Ptr r = ::PyCFunction_NewEx( &def, p_.get(), pyName.get() ); int const _ = ::PyModule_AddObject( p_.get(), name, r.release() ); (_ != -1 ) || cppx::throwX( "PyModule_AddObject failed" ); } }; Problem: when a routine installed by 'setRoutine' above is called from Python, then it fails with e.g. "SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!" And since things work for a single method when I declare 'def' as 'static', I suspect that means that the function object created by PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? I'm unable to find documentation of PyCFunction_NewEx, and more criticially, I'm unable to find any documented way to turn a C or C++ function into a Python function object? Cheers, - Alf -- blog at From tjreedy at udel.edu Wed Jul 7 23:26:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:26:22 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On 7/7/2010 5:29 AM, geremy condra wrote: > On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: >> On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >>> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >>>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchu >>>>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>>>> single C codebase. I'd be willing to contribute my experiences to a >>>>> document >>>>> somewhere. (Is there a Wiki?) >>>> Indeed there is: http://wiki.python.org/moin/ >>> Thanks. I don't want to appear ungrateful, but I was hoping for >>> something specific to the 2-to-3 conversion. I guess someone has to >>> start somewhere... >> There is an existing 2to3 and other pages for Python code conversion. I do >> not know of any for CAPI conversion. The need for such has been acknowledged >> among the devs but if there is nothing yet, we need someone with specialized >> experience and a bit of time to make a first draft. If you start one, give >> it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from >> the 2to3 pag >> In his post on this thread, Martin Loewis volunteered to list what he knows >> from psycopg2 if someone else will edit. > I'm not sure why I don't have this post, but I'm happy to help edit > etc if Martin > wants to put together a rough draft. Since I wrote that, someone pointed out the the Python How-to collection includes Porting Extension Modules to 3.0 by Benjamim Peterson. So all Pyilip or Martin need to do is read that and suggest additions. Since it is part of the doc set, I presume an issue could be opened on the tracker. -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Jul 7 23:32:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 13:32:03 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <87lj9mbqdo.fsf@benfinney.id.au> geremy condra writes: > On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: > > [backward-]incompatibilities between 2.x and 3.x will *increase* > > over time. > > ...and? I don't get to use features from 2.7, why would I expect to > use features from 3.3? Conversely, why would you support Python 3.1? > > Indeed, the feature moratorium is designed in part to help > > slow-moving codebases migrate to Python 3.x before Python resumes > > its normal pace of change again. If you're choosing to use that time > > to further entrench codebases for Python 2.x, I think that's a > > short-sighted choice. > > I welcome the day that I can stop supporting 2.x. Until then, I have > to support both and your argument is irrelevant. Why do you have to support Python 3 at all? Will you expect to continue maintaining a single code base that supports PYthon 2.x and Python 3.2, then 3.3, and so on? The only point being made here is to answer the question of why people are saying that a single code base for both 2.x and 3.x is a maintenance burden. If, in your case, at the present time, that's not the case, then good for you! But it will get increasingly harder to do, and the reasons why have now been explained. Apply them as you see fit. -- \ ?I'm a born-again atheist.? ?Gore Vidal | `\ | _o__) | Ben Finney From zooko at zooko.com Wed Jul 7 23:41:29 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 21:41:29 -0600 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: I'm starting to think that one should use Decimals by default and reserve floats for special cases. This is somewhat analogous to the way that Python provides arbitrarily-big integers by default and Python programmers only use old-fashioned fixed-size integers for special cases, such as interoperation with external systems or highly optimized pieces (in numpy or in native extension modules, for example). Floats are confusing. I've studied them more than once over the years but I still can't really predict confidently what floats will do in various situations. And most of the time (in my experience) the inputs and outputs to your system and the literals in your code are actually decimal, so converting them to float immediately introduces a lossy data conversion before you've even done any computation. Decimal doesn't have that problem. >From now on I'll probably try to use Decimals exclusively in all my new Python code and switch to floats only if I need to interoperate with an external system that requires floats or I have some tight inner loop that needs to be highly optimized. Regards, Zooko From cournape at gmail.com Wed Jul 7 23:42:19 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 05:42:19 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34D133.9060802@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: On Wed, Jul 7, 2010 at 9:10 PM, Martin v. Loewis wrote: > > My preferred long-term solution is to reduce the usage of the C library > in CPython as much as reasonable, atleast on Windows. Memory management > could directly use the heap functions (or even more directly > VirtualAlloc); filenos could be OS handles, and so on. There are > probably limitations to what you can achieve, but I think it's worth trying. I saw you already mentioned work toward this a few months (years ?) ago. Is there some kind of roadmap, or could you use some help ? I would really like to solve this issue as much as we possibly can, David From tjreedy at udel.edu Wed Jul 7 23:44:58 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:44:58 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On 7/7/2010 4:31 AM, Paul McGuire wrote: [snip interesting report on how Paul suppost pyparsing for 2.3 to 3.1] Thank you for this. Do you think such cross-version support would have been easier or harder if the major changes and deletions in 3.0 has been spread over several versions, such as 2.5 - 2.7. In other words, suppose the Python 3 idea never occurred to anyone and 2.5 dropped the old int division and finished the unification of int and long. 2.6 dropped classic classes and switched range, filter, and map to their iterator versions. 2.7 made unicode the text type This is not purely a hypothetical question since the issue of spreading or bunching changes may arise again in the future. -- Terry Jan Reedy From no.email at nospam.invalid Wed Jul 7 23:49:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 20:49:42 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> <87pqyybscs.fsf@benfinney.id.au> Message-ID: <7x4ogapr8p.fsf@ruckus.brouhaha.com> Ben Finney writes: >> On the other hand, the door appears closed for Python 3 adding more >> stuff that breaks Python 2 code. > > What gives you that idea? Can you reference a specific statement from > the PYthon developers that says that? It's just logic. As I understand it, future versions of Python 3 are supposed to not break programs that work under current versions of Python 3. So any Python 2 program that is a valid Python 3 program today has to stay valid. From debatem1 at gmail.com Wed Jul 7 23:52:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 23:52:13 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87lj9mbqdo.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <87lj9mbqdo.fsf@benfinney.id.au> Message-ID: On Wed, Jul 7, 2010 at 11:32 PM, Ben Finney wrote: > geremy condra writes: > >> On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: >> > [backward-]incompatibilities between 2.x and 3.x will *increase* >> > over time. >> >> ...and? I don't get to use features from 2.7, why would I expect to >> use features from 3.3? > > Conversely, why would you support Python 3.1? Because in 10 years the percentage of people who have Python 2.x installed will be the same as the percentage that have Python 1.x installed today. >> > Indeed, the feature moratorium is designed in part to help >> > slow-moving codebases migrate to Python 3.x before Python resumes >> > its normal pace of change again. If you're choosing to use that time >> > to further entrench codebases for Python 2.x, I think that's a >> > short-sighted choice. >> >> I welcome the day that I can stop supporting 2.x. Until then, I have >> to support both and your argument is irrelevant. > > Why do you have to support Python 3 at all? See above. > Will you expect to continue > maintaining a single code base that supports PYthon 2.x and Python 3.2, > then 3.3, and so on? Yes, with the occasional feature or bugfix. Is there an alternate interpretation I'm missing? > The only point being made here is to answer the question of why people > are saying that a single code base for both 2.x and 3.x is a maintenance > burden. If, in your case, at the present time, that's not the case, then > good for you! But it will get increasingly harder to do, and the reasons > why have now been explained. Apply them as you see fit. I see you stating that it will become harder but I don't see why that should be the case. Geremy Condra From tjreedy at udel.edu Wed Jul 7 23:52:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:52:27 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: On 7/7/2010 9:14 PM, Ben Finney wrote: > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. For the purpose of maintaining least-common-denominator multi-version code, it is only deletions and semantic changes that matter. Feature additions will be more common, at least for awhile. The problem of backporting 3.x code that uses 3.x features definitely will increase. -- Terry Jan Reedy From cournape at gmail.com Thu Jul 8 00:04:33 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 06:04:33 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Thu, Jul 8, 2010 at 5:41 AM, Zooko O'Whielacronx wrote: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. > > This is somewhat analogous to the way that Python provides > arbitrarily-big integers by default and Python programmers only use > old-fashioned fixed-size integers for special cases, such as > interoperation with external systems or highly optimized pieces (in > numpy or in native extension modules, for example). I don't think it is analogous at all. Arbitrary-bit integers have a simple tradeoff: you are willing to lose performance and memory for bigger integer. If you leave performance aside, there is no downside that I know of for using big int instead of "machine int". Since you are using python, you already bought this kind of tradeoff anyway. Decimal vs float is a different matter altogether: decimal has downsides compared to float. First, there is this irreconcilable fact that no matter how small your range is, it is impossible to represent exactly all (even most) numbers exactly with finite memory - float and decimal are two different solutions to this issue, with different tradeoffs. Decimal are more "intuitive" than float for numbers that can be represented as decimal - but most numbers cannot be represented as (finite) decimal. Except for some special usecases, you cannot expect to exactly represent real numbers. Once you accept that fact, you can make a decision on decimal, fraction, float or whatever format you see fit. > And most of the time (in my experience) the inputs and outputs to your > system and the literals in your code are actually decimal, so > converting them to float immediately introduces a lossy data > conversion before you've even done any computation. Decimal doesn't > have that problem. That's not true anymore once you start doing any computation, if by decimal you mean finite decimal. And that will be never true once you start using non trivial computation (i.e. transcendental functions like log, exp, etc...). David From zooko at zooko.com Thu Jul 8 00:07:10 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 22:07:10 -0600 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: Dear Paul McGuire: Thank you very much for these notes! See also a few other notes: Michael Foord: http://www.voidspace.org.uk/python/weblog/arch_d7_2010_03_20.shtml#e1167 Ned Batchelder: http://nedbatchelder.com/blog/200910/running_the_same_code_on_python_2x_and_3x.html I was wondering if it would be useful to have a library that implements these hacks so that people like me who prefer to maintain a single codebase instead of using a tool like 2to3 could easily adopt them. Oh look! Here is one: http://pybites.blogspot.com/2010/06/six-python-23-compatibility-helpers.html :-) Regards, Zooko From tjreedy at udel.edu Thu Jul 8 00:11:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jul 2010 00:11:54 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87pqyybscs.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> <87pqyybscs.fsf@benfinney.id.au> Message-ID: On 7/7/2010 10:49 PM, Ben Finney wrote: > Yes, that's what I meant. Python 3 is deliberately under no obligation > to support code that works in Python 2. If something needs fixing, and > that fix would involve breaking Python 2 code, then that's not a > consideration any more. Code that works in 3.1 *is* 3.1 code. Leaving aside bug fixes and additions that makes code that once raised an exception do something instead, I do not know that 3.1 broke and 3.0 code and I do not know of any deprecations in 3.1 that will become removals in 3.2. > The predictable result is that Python 3 will continue to gain > backward-incompatible changes in future. For the core syntax, not too likely. In any case, the usually 3 version pending-deprecation, deprecation, removal process would apply. Some of the library modules that do not work well for 3.1 will see more changes. >> On the other hand, the door appears closed for Python 3 adding more >> stuff that breaks Python 2 code. > > What gives you that idea? Can you reference a specific statement from > the PYthon developers that says that? 3.0 was stated to be a special case. I will let you look. -- Terry Jan Reedy From martin at v.loewis.de Thu Jul 8 00:46:15 2010 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 08 Jul 2010 06:46:15 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: <4C355817.1010105@v.loewis.de> > I saw you already mentioned work toward this a few months (years ?) > ago. Is there some kind of roadmap, or could you use some help ? I > would really like to solve this issue as much as we possibly can, Well, Python 3 has already dropped stdio for its own io library, and I do want to get rid of the remaining FILE* usage for 3.2. Any other change needs to be discussed on python-dev first; contributions are welcome. Regards, Martin From martin at v.loewis.de Thu Jul 8 00:50:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 06:50:34 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4C35591A.2090503@v.loewis.de> Am 07.07.2010 23:10, schrieb Brendan Abel: >>>> One thing that would be very useful is how to maintain something that >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>> versions below 2.6 is out of the question for most projects with a >>>> significant userbase IMHO. As such, the idea of running the python 3 >>>> warnings is not so useful IMHO - unless it could be made to work >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>> sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. This is the point where a > project should fork and provide two different versions. I completely disagree. My personal experience is that this is well possible even for large code bases, and I would recommend having a single code base for 2.x and 3.x *in particular* for large projects, which probably need to support 2.x users for quite some time, but simultaneously need to support 3.x users. Regards, Martin From michele.simionato at gmail.com Thu Jul 8 00:51:34 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 7 Jul 2010 21:51:34 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 7, 10:55?pm, Carl Banks wrote: > On Jul 7, 1:31?am, Paul McGuire wrote: > > I just > > couldn't get through on the python-dev list that I couldn't just > > upgrade my code to 2.6 and then use 2to3 to keep in step across the > > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. This is a point I do not understand. My recent module plac is meant to work from Python 2.3 to Python 3.1 and to this goal I make use of 2to3 at the *client* side. Users of Python 2.X get the original code with no magic whatsoever; users of Python 3.X get the same code, but at installation time 2to3 is run by the setup.py script. The mechanism requires distribute to be installed, but I would say that having distribute is a must for Python 3.X users; Python 2.X users do not need anything, so the approach is backward compatible. I thought this was the recommended way of using 2to3 and so far is working for me. M. Simionato From martin at v.loewis.de Thu Jul 8 00:52:09 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 06:52:09 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <4C355979.8080407@v.loewis.de> > Python 3.x will continue to change. The incompatibilities between 3.x > and 2.x will only become more numerous. If your goal is to support > 2.x, and 3.x, you'd be best supporting them separately. I don't think that's a particularly good approach. Having a single code base for both likely reduced the maintenance burden significantly compared to a code fork. Regards, Martin From zooko at zooko.com Thu Jul 8 00:53:20 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 22:53:20 -0600 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Wed, Jul 7, 2010 at 10:04 PM, David Cournapeau wrote: > > Decimal vs float is a different matter altogether: decimal has > downsides compared to float. First, there is this irreconcilable fact > that no matter how small your range is, it is impossible to represent > exactly all (even most) numbers exactly with finite memory - float and > decimal are two different solutions to this issue, with different > tradeoffs. Decimal are more "intuitive" than float for numbers that > can be represented as decimal - but most numbers cannot be represented > as (finite) decimal. This is not a downside of decimal as compared to float, since most numbers also cannot be represented as float. >> And most of the time (in my experience) the inputs and outputs to your >> system and the literals in your code are actually decimal, so >> converting them to float immediately introduces a lossy data >> conversion before you've even done any computation. Decimal doesn't >> have that problem. > > That's not true anymore once you start doing any computation, if by > decimal you mean finite decimal. I don't understand. I described two different problems: problem one is that the inputs, outputs and literals of your program might be in a different encoding (in my experience they have most commonly been in decimal). Problem two is that your computations may be lossy. If the inputs, outputs and literals of your program are decimal (as they have been for most of my programs) then using decimal is better than using float because of problem one. Neither has a strict advantage over the other in terms of problem two. (There is also problem zero, which is that floats more confusing, which is how this thread got started. Problem zero is probably the most important problem for many cases.) > And that will be never true once you > start using non trivial computation (i.e. transcendental functions > like log, exp, etc...). I'm sorry, what will never be true? Are you saying that decimals have a disadvantage compared to floats? If so, what is their disadvantage? (And do math libraries like http://code.google.com/p/dmath/ help ?) Regards, Zooko From martin at v.loewis.de Thu Jul 8 01:01:48 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:01:48 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <4C355BBC.7050003@v.loewis.de> > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. I think this is unfounded, and actually false. Instead, the incompatibilities will *decrease* over the next few years. Suppose you support 2.x and 3.x from a single code base. Today, you might support 2.3 up to 3.1. In a year, you might drop 2.3, and start support 3.2. That will lead to a reduction of incompatibilities: you can start using 2.4 features, and drop work-arounds for 2.3 limitations. Likewise when you then, later, drop 2.4. As a specific example, since 2.5, the modules in the email package are in lower case, in compliance with PEP 8. 2.x has backwards compatibility so that you can continue to use the uppercase module names, which you need for 2.3/2.4 compat. In 3.x, you can't use these spelling anymore, so your code might use try/except as a work-around. When you drop 2.4, you can drop the work-around. > If you now have a code base that is relatively easy to maintain for both > Python 2.x and 3.x, that is a result of much back-porting efforts and of > a new-feature moratorium that is currently in effect. Enjoy that > situation as you may, because it is guaranteed not to last. On the contrary: it's getting better. The back-porting efforts only become available in 2.6, and you would have to support at least 2.5 today (at least, that's how many maintainers feel). Only when you can drop 2.5 support, you can actually start *using* these backport features, allowing you to make the 2.x and 3.x code more similar. Eventually, the difference will get larger again. Hopefully, by that time, 2.7 got out of use. Regards, Martin From martin at v.loewis.de Thu Jul 8 01:13:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:13:54 +0200 Subject: Python 2.7 released In-Reply-To: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C355E92.3060403@v.loewis.de> Am 08.07.2010 04:17, schrieb imageguy: > >> I, too, have multiple versions installed -- newer ones for running code >> I haven't upgraded; older ones for compatibility testing where needed. >> I just install to the default c:\pythonxy directories (although I like >> the idea of a common root) and I put NTFS hardlinks into my general >> c:\tools directory which is on the path. The out-of-context hardlinks >> work because of the registry settings which pick up the correct context >> for each version. > > Sorry to be daft here, but what do you mean by a "hardlink" ? > A windows "Shortcut" ? > No, he means a hardlink (file system level directory entries pointing to the same MFT record number), as created by "fsutil hardlink", "mklink /H", or Cygwin "ln". Regards, Martin From martin at v.loewis.de Thu Jul 8 01:23:15 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:23:15 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: Message-ID: <4C3560C3.8090707@v.loewis.de> > And since things work for a single method when I declare 'def' as > 'static', I suspect that means that the function object created by > PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? Correct; it doesn't make a copy of the struct. So when you want the function object to outlive the setRoutine call, you need to allocate the PyMethodDef on the heap. Regards, Martin From me+list/python at ixokai.io Thu Jul 8 01:30:03 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 07 Jul 2010 22:30:03 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C355817.1010105@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C355817.1010105@v.loewis.de> Message-ID: <4C35625B.60606@ixokai.io> On 7/7/10 9:46 PM, "Martin v. L?wis" wrote: >> I saw you already mentioned work toward this a few months (years ?) >> ago. Is there some kind of roadmap, or could you use some help ? I >> would really like to solve this issue as much as we possibly can, > > Well, Python 3 has already dropped stdio for its own io library, and > I do want to get rid of the remaining FILE* usage for 3.2. Any other > change needs to be discussed on python-dev first; contributions are welcome. Really? I wasn't entirely aware of this effect of the "io" module. Somehow, without at all paying attention (because certain third party modules blocking me for awhile, I never looked close enough), I just sort of thought the "io" module was mostly thin wrappers around stdio primitives, into a more Pythonic API. This actually makes me long for Python 3 more. And adjust agendas to push my day-job work to 2.7 as soon as possible, and start a preemptive reconfiguration to support a future Py3k migration. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wuwei23 at gmail.com Thu Jul 8 01:31:43 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 7 Jul 2010 22:31:43 -0700 (PDT) Subject: Is This Open To SQL Injection? References: Message-ID: Stephen Hansen wrote: > You're doing string formatting > to construct your SQL, which is where the trouble comes from. You're wasting your breath, this topic has been discussed ad nauseum with Victor for well over a year now. He appears to be teaching himself relational db based web-development within a paid project and the pressure to produce seems to be greatly overwhelming his need to learn. (Yes, I am aware that I'm a bad evil man because I don't believe that blindly restating the same answer for someone over and over and over is really helping them) From martin at v.loewis.de Thu Jul 8 01:58:18 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:58:18 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <4C3568FA.5030000@v.loewis.de> > I just > couldn't get through on the python-dev list that I couldn't just > upgrade my code to 2.6 and then use 2to3 to keep in step across the > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. Not sure whom you had been talking to. But I would have tried to explain that you don't *have* to port to 2.6 to use 2to3 - it will work just as fine with 2.3 code, and earlier. > - No use of sets. Instead I defined a very simple set simulation > using dict keys, which could be interchanged with set for later > versions. This I don't understand. IIUC, you want to support 2.3 and later. Now, 2.3 already has a set module, even though set is not a builtin. So you could use sets just as well. > - No generator expressions, only list comprehensions. Ok. Not sure how this causes problems, though - just don't use them, then. > - No use of decorators. BUT, pyparsing includes a decorator method, > traceParseAction, which can be used by users with later Pythons as > @traceParseAction in their own code. Of course, users of older Python versions could explicitly wrap the functions with the decorator if they wanted to. > - No print statements. As pyparsing is intended to be an internal > module, it does no I/O as part of its function - it only processes a > given string, and returns a data structure. If you don't need them, fine. If you do, I'd just let 2to3 transform them. > - Python 2-3 compatible exception syntax. This may have been my > trickiest step. The change of syntax for except from > > except ExceptionType, ex: > > to: > > except ExceptionType as ex: > > is completely forward and backward incompatible. The workaround is to > rewrite as: > > except ExceptionType: > ex = sys.exc_info()[0] Likewise, and more importantly so: use 2to3. It can be done this way, but I find the 2to3 solution much cleaner. > But in > the meantime, I am still able to support all versions of Python NOW, > and I plan to continue doing so (albeit "support" for 2.x versions > will eventually mean "continue to offer a frozen feature set, with > minimal bug-fixing if any"). The same would have been possible if you had chosen to use 2to3. Regards, Martin From alf.p.steinbach+usenet at gmail.com Thu Jul 8 02:47:01 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 08:47:01 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: <4C3560C3.8090707@v.loewis.de> References: <4C3560C3.8090707@v.loewis.de> Message-ID: * Martin v. Loewis, on 08.07.2010 07:23: >> And since things work for a single method when I declare 'def' as >> 'static', I suspect that means that the function object created by >> PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? > > Correct; it doesn't make a copy of the struct. So when you want the > function object to outlive the setRoutine call, you need to allocate > the PyMethodDef on the heap. Thanks! That's the direction I tentatively had started to investigate. But second problem now is cleanup: I'd like to deallocate when the module is freed. I tried (1) adding a __del__, but no dice, I guess because it wasn't really an object method but just a free function in a module; and (2) the m_free callback in the module definition structure, but it was not called. Perhaps I don't need to to clean up? Anyway, current looks like this: // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef CPPY_MODULE_H #define CPPY_MODULE_H #include //----------------------------------------- Dependencies: #include "Ptr.h" #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { namespace detail { inline PyModuleDef* moduleDefPtr() { static PyMethodDef methodDefs[] = { //... //{ "system", &pyni_system, METH_VARARGS, "Execute a shell command." }, //{ "__del__", &onModuleDestroy, METH_NOARGS, "Destructor" }, //... { NULL, NULL, 0, NULL } // Sentinel }; static PyModuleDef moduleDef = { PyModuleDef_HEAD_INIT, "cppy", // name of module NULL, // m_doc, // module documentation in UTF-8 sizeof(void*), // size of per-interpreter state of the module, // or -1 if the module keeps state in global variables. methodDefs, NULL, // m_reload NULL, // m_traverse NULL, // m_clear NULL // m_free }; return &moduleDef; } } class Module { private: struct InstanceData { std::list< PyMethodDef > methodDefs; }; void* instanceMemory() const { void* const result = PyModule_GetState( p_.get() ); assert( result != 0 ); return result; } InstanceData*& instanceDataPtr() const { return *reinterpret_cast< InstanceData** >( instanceMemory() ); } Ptr p_; InstanceData* data_; public: Module() : p_( ::PyModule_Create( detail::moduleDefPtr() ) ) { assert( def.m_size == sizeof( void* ) ); (p_.get() != 0) || cppx::throwX( "Module::: failed" ); instanceDataPtr() = data_ = new InstanceData(); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "Module::setDocString: PyUnicode_FromWideChar failed" ); ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::setDocString: PyObject_SetAttrString failed" ); } void addRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef const defData = { name, f, METH_VARARGS, doc }; data_->methodDefs.push_back( defData ); try { PyMethodDef* pDef = &data_->methodDefs.back(); Ptr const pyName = ::PyUnicode_FromString( name ); Ptr r = ::PyCFunction_NewEx( pDef, p_.get(), pyName.get()); ::PyModule_AddObject( p_.get(), name, r.release() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::addRoutine: PyModule_AddObject failed" ); } catch( ... ) { data_->methodDefs.pop_back(); throw; } } }; } } // namespace progrock::cppy #endif I changed the module name from "pyni*" to "cppy"... ;-) Cheers & thanks!, but how to clean up, or must I? - Alf -- blog at From lavanya.msra at gmail.com Thu Jul 8 02:55:46 2010 From: lavanya.msra at gmail.com (lavanya) Date: Wed, 7 Jul 2010 23:55:46 -0700 (PDT) Subject: Appending to a file using Python API Message-ID: <586afe86-cc9b-4c0b-90ea-64c9ed2a7f26@m40g2000prc.googlegroups.com> Hello all, How do you append to a file using Python os::file APIs. So that it appends to the content of the file. Not adding the content to the new line. But just appends next to the exiting content of the file. Example : current content of file A B C if we append D to it, it should be A B C D Not like: A B C D regards, lavanya From nick_keighley_nospam at hotmail.com Thu Jul 8 03:08:23 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 8 Jul 2010 00:08:23 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> Message-ID: On 7 July, 17:38, Rivka Miller wrote: > Although C comes with a regex library, C does not come with a regexp library > Anyone know what the first initial of L. Peter Deutsch stand for ? Laurence according to wikipedia (search time 2s) From nick_keighley_nospam at hotmail.com Thu Jul 8 03:10:31 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 8 Jul 2010 00:10:31 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> Message-ID: <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> On 8 July, 08:08, Nick Keighley wrote: > On 7 July, 17:38, Rivka Miller wrote: > > Anyone know what the first initial of L. Peter Deutsch stand for ? > > Laurence according to wikipedia (search time 2s) oops! He was born Laurence but changed it legally to "L." including the dot From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:10:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:10:58 GMT Subject: Appending to a file using Python API References: <586afe86-cc9b-4c0b-90ea-64c9ed2a7f26@m40g2000prc.googlegroups.com> Message-ID: <4c357a01$0$28634$c3e8da3@news.astraweb.com> On Wed, 07 Jul 2010 23:55:46 -0700, lavanya wrote: > Hello all, > > How do you append to a file using Python os::file APIs. So that it > appends to the content of the file. Not adding the content to the new > line. But just appends next to the exiting content of the file. > > Example : current content of file > A B C > if we append D to it, it should be > A B C D > > Not like: > A B C > D f = open("myfile.txt", "a") f.write("D") will append to the end of myfile.txt, regardless of what is already in myfile.txt. If it ends with a newline: "A B C\n" then you will end up with: "A B C\nD" If there is no newline, you will end up with: "A B CD" If you need anything more complicated than that, the easiest solution is something like this: # read the entire file # modify the last line in memory # write the lines back to the file f = open("myfile.txt", "r") lines = f.readlines() f.close() if not lines: # file exists but is empty lines.append('') last_line = lines[-1] last_line = last_line.rstrip() # remove all trailing whitespace if last_line: last_line += " D\n" else: last_line = "D\n" lines[-1] = last_line f = open("myfile.txt", "w") f.writelines(lines) f.close() -- Steven From martin at v.loewis.de Thu Jul 8 03:13:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 09:13:50 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: <4C3560C3.8090707@v.loewis.de> Message-ID: > I tried (1) adding a __del__, but no dice, I guess > because it wasn't really an object method but just a free function in a > module; and (2) the m_free callback in the module definition structure, > but it was not called. m_free will be called if the module object gets deallocated. So if m_free really isn't called, the module got never deallocated. Regards, Martin From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:32:24 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:32:24 GMT Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4c357f08$0$28634$c3e8da3@news.astraweb.com> On Thu, 08 Jul 2010 06:04:33 +0200, David Cournapeau wrote: > On Thu, Jul 8, 2010 at 5:41 AM, Zooko O'Whielacronx > wrote: >> I'm starting to think that one should use Decimals by default and >> reserve floats for special cases. >> >> This is somewhat analogous to the way that Python provides >> arbitrarily-big integers by default and Python programmers only use >> old-fashioned fixed-size integers for special cases, such as >> interoperation with external systems or highly optimized pieces (in >> numpy or in native extension modules, for example). > > I don't think it is analogous at all. Arbitrary-bit integers have a > simple tradeoff: you are willing to lose performance and memory for > bigger integer. If you leave performance aside, there is no downside > that I know of for using big int instead of "machine int". Well, sure, but that's like saying that if you leave performance aside, there's no downside to Bubblesort instead of Quicksort. However, I believe that in Python at least, the performance cost of arbitrary-sized longs is quite minimal compared to the benefit, at least for "reasonable" sized ints, and so the actual real-world cost of unifying the int and long types is minimal. On the other hand, until Decimal is re-written in C, it will always be *significantly* slower than float. $ python -m timeit "2.0/3.0" 1000000 loops, best of 3: 0.139 usec per loop $ python -m timeit -s "from decimal import Decimal as D" "D(2)/D(3)" 1000 loops, best of 3: 549 usec per loop That's three orders of magnitude difference in speed. That's HUGE, and *alone* is enough to disqualify changing to Decimal as the default floating point data type. Perhaps in the future, if and when Decimal has a fast C implementation, this can be re-thought. > Since you are > using python, you already bought this kind of tradeoff anyway. > > Decimal vs float is a different matter altogether: decimal has downsides > compared to float. First, there is this irreconcilable fact that no > matter how small your range is, it is impossible to represent exactly > all (even most) numbers exactly with finite memory - float and decimal > are two different solutions to this issue, with different tradeoffs. Yes, but how is this a downside *compared* to float? In what way does Decimal have downsides that float doesn't? Neither can represent arbitrary real numbers exactly, but if anything float is *worse* compared to Decimal for two reasons: * Python floats are fixed to a single number of bits, while the size of Decimals can be configured by the user; * floats can represent sums of powers of two exactly, while Decimals can represent sums of powers of ten exactly. Not only does that mean that any number exactly representable as a float can also be exactly represented as a Decimal, but Decimals can *additionally* represent exactly many numbers of human interest that floats cannot. > Decimal are more "intuitive" than float for numbers that can be > represented as decimal - but most numbers cannot be represented as > (finite) decimal. True, but any number that can't be, also can't be exactly represented as a float either, so how does using float help? [...] >> And most of the time (in my experience) the inputs and outputs to your >> system and the literals in your code are actually decimal, so >> converting them to float immediately introduces a lossy data conversion >> before you've even done any computation. Decimal doesn't have that >> problem. > > That's not true anymore once you start doing any computation, if by > decimal you mean finite decimal. And that will be never true once you > start using non trivial computation (i.e. transcendental functions like > log, exp, etc...). But none of those complications are *inputs*, and, again, floats suffer from exactly the same problem. -- Steven From ben+python at benfinney.id.au Thu Jul 8 03:43:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 17:43:11 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <4C355BBC.7050003@v.loewis.de> Message-ID: <87hbkaber4.fsf@benfinney.id.au> "Martin v. Loewis" writes: > > The point, one more time with feeling, is that the incompatibilities > > between 2.x and 3.x will *increase* over time. > > I think this is unfounded, and actually false. Since many other people have responded with similar sentiments, I can only think I must have been expressing myself very poorly today. I agree with everything you say here, but it doesn't go against what I've been saying. If I cared about the issue more, I might have another crack at putting my meaning into words; but those who want to support a broad stride of Python versions are more motivated than I to figure it out, so instead I depart the field. -- \ ?People's Front To Reunite Gondwanaland: Stop the Laurasian | `\ Separatist Movement!? ?wiredog, http://kuro5hin.org/ | _o__) | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:44:47 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:44:47 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4c3581ef$0$28634$c3e8da3@news.astraweb.com> On Wed, 07 Jul 2010 14:10:57 -0700, Brendan Abel wrote: > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. I don't see that follows at all. If the incompatibilities are designed to be mechanically translatable (e.g. "x.keys()" -> "list(x.keys())" then you can start with a single code-base and run the translator. If only there were some sort of Python program that could be used to translate code from 2 to 3... *wink* -- Steven From mail at timgolden.me.uk Thu Jul 8 04:07:04 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 08 Jul 2010 09:07:04 +0100 Subject: Python 2.7 released In-Reply-To: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C358728.60704@timgolden.me.uk> On 08/07/2010 03:17, imageguy wrote: > >> I, too, have multiple versions installed -- newer ones for running code >> I haven't upgraded; older ones for compatibility testing where needed. >> I just install to the default c:\pythonxy directories (although I like >> the idea of a common root) and I put NTFS hardlinks into my general >> c:\tools directory which is on the path. The out-of-context hardlinks >> work because of the registry settings which pick up the correct context >> for each version. > > Sorry to be daft here, but what do you mean by a "hardlink" ? > A windows "Shortcut" ? > > I have just installed 2.7 and want to start upgrading some code, but > alas still want to maintain some 2.5 code too. Hardlinks have always been present on NTFS, just not very widely advertised. They are a way of saying that *this* file and *that* file are actually the *same* file. (They must be on the same volume as they underlying implementation relies on pointing to the volume's master index -- the MFT). They're not copies: if one changes, the other changes. They're not shortcuts, which are a Shell (ie Desktop) mechanism, not a filesystem one I have hardlinks called python26.exe, python31.exe, etc. which point to c:\python26\python.exe, c:\python31\python.exe etc. and also a python3.exe which is another link to c:\python31\python.exe but which will move when python 3.2 is released. However, this is simply a convenience I use. It's perfectly possible to have and to use several versions of Python concurrently without this. How you do it depends on your working practice: whether you use an IDE or double-click on .py files or run from a cmd window, etc. TJG From animator333 at gmail.com Thu Jul 8 04:21:43 2010 From: animator333 at gmail.com (King) Date: Thu, 8 Jul 2010 01:21:43 -0700 (PDT) Subject: simple python deployment tool Message-ID: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Hi, I am writing a python package deployment tool for linux based platforms. I have tried various existing tool sets but none of them is up to the mark and they have their own issues. Initially I'll start with simple approach. 1. Find all the modules/packages and copy to "lib" directory. 2. Find python's *.so dependencies(system libs) and copy them to "syslib" 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" directory. 4. Set up temp environment 5. Run main script using "python
.py" The idea is to produce a cleaner directory structure. Neither I am creating a boot loader nor I am converting main script file into executable. It's plain vanilla stuff. Using above steps I have pulled down a package using wxPython's demo example "pySketch.py". You can download the archive from here: http://rapidshare.com/files/405255400/dist.zip (Note : It's for linux users.) After extracting the contents, run the executable file using "./run". This file sets temporary environment variables and execute "pySketch.py". I apologize for the archive size as all the systems libs are also included. This is eventually not working. I think I am not able to set up temporary environment properly or may be missing some other stuff. I would appreciate if some one can point out mistakes. Here is the practical approach: /lib (all python libs, files and third party modules.) /syslib (all the system libs. libX*.*, cairo, etc.) python (executable) pySketch.py run.sh Contents of "run.sh". ------------------------------ set LD_LIBRARY_PATH="syslib/" set PYTHONPATH="/lib" python pySketch.py Cheers Prashant From g.rodola at gmail.com Thu Jul 8 04:25:36 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 8 Jul 2010 10:25:36 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: 2010/7/8 Michele Simionato : > On Jul 7, 10:55?pm, Carl Banks wrote: >> On Jul 7, 1:31?am, Paul McGuire wrote: >> > I just >> > couldn't get through on the python-dev list that I couldn't just >> > upgrade my code to 2.6 and then use 2to3 to keep in step across the >> > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. > > This is a point I do not understand. My recent module plac is meant to > work from Python 2.3 to Python 3.1 and to this goal I make use of 2to3 > at the *client* side. > Users of Python 2.X get the original code with no magic whatsoever; > users of Python 3.X > get the same code, but at installation time 2to3 is run by the > setup.py script. The mechanism requires distribute to be installed, > but I would say that having distribute is a must for Python 3.X users; > Python 2.X users do not need anything, so the approach is backward > compatible. I thought this was the recommended way of using 2to3 and > so far is working for me. > > ? ? ? ? ? ?M. Simionato > -- > http://mail.python.org/mailman/listinfo/python-list > I used the same approach (2.x default code base which gets translated by 2to3 at installation time) and I managed to do this with distutils alone by doing a little hack in setup.py. Take a look at: http://code.google.com/p/psutil/source/browse/tags/release-0.1.3/setup.py#11 Regards, --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From pjb at informatimago.com Thu Jul 8 04:39:45 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 08 Jul 2010 10:39:45 +0200 Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> Message-ID: <87lj9mfju6.fsf@kuiper.lan.informatimago.com> Nick Keighley writes: > On 8 July, 08:08, Nick Keighley > wrote: >> On 7 July, 17:38, Rivka Miller wrote: > > >> > Anyone know what the first initial of L. Peter Deutsch stand for ? >> >> Laurence according to wikipedia (search time 2s) > > oops! He was born Laurence but changed it legally to "L." including > the dot Too bad, "Laurence" is a nice name. -- __Pascal Bourguignon__ http://www.informatimago.com/ From alf.p.steinbach+usenet at gmail.com Thu Jul 8 04:48:54 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 10:48:54 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: <4C3560C3.8090707@v.loewis.de> Message-ID: * Martin v. Loewis, on 08.07.2010 09:13: >> I tried (1) adding a __del__, but no dice, I guess >> because it wasn't really an object method but just a free function in a >> module; and (2) the m_free callback in the module definition structure, >> but it was not called. > > m_free will be called if the module object gets deallocated. So if > m_free really isn't called, the module got never deallocated. Thanks again. I don't know what I did wrong. Now it's called. :-) But I wasted much time googling to try to find out the /responsibilities/ of the m_free callback, and what its void* argument was. E.g., should it deallocate the module object, and if so, via what deallocation routine? I found some info, but even your PEP, otherwise clear, was silent about this fine point. Finally I looked at the source code that invokes it and found that it has no responsibilities whatsoever, just a use-as-you-wish finalization callback. Nice! But I think that could be more clear in the docs... Code, for those who might be interested: // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef CPPY_MODULE_H #define CPPY_MODULE_H #include //----------------------------------------- Dependencies: #include "Ptr.h" #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { namespace detail { struct InstanceData { std::list< PyMethodDef > methodDefs; }; inline void* instanceMemoryOf( PyObject* pObject ) { void* const result = PyModule_GetState( pObject ); assert( result != 0 ); return result; } inline InstanceData*& instanceDataPtrOf( PyObject* pObject ) { return *reinterpret_cast< InstanceData** >( instanceMemoryOf( pObject ) ); } inline void on_freeModule( void* p ) { PyObject* const pModule = reinterpret_cast< PyObject* >( p ); InstanceData* const pData = instanceDataPtrOf( pModule ); delete pData; printf( "Deallocated!\n" ); // TODO: Remove. } inline PyModuleDef* moduleDefPtr() { static PyMethodDef methodDefs[] = { //... //{ "system", &pyni_system, METH_VARARGS, "Execute a shell command." }, //{ "__del__", &onModuleDestroy, METH_NOARGS, "Destructor" }, //... { NULL, NULL, 0, NULL } // Sentinel }; static PyModuleDef moduleDef = { PyModuleDef_HEAD_INIT, "cppy", // name of module NULL, // m_doc, // module documentation in UTF-8 sizeof(void*), // size of per-interpreter state of the module, // or -1 if the module keeps state in global variables. methodDefs, NULL, // m_reload NULL, // m_traverse NULL, // m_clear &on_freeModule // m_free }; return &moduleDef; } } class Module { private: Ptr p_; detail::InstanceData* data_; detail::InstanceData*& instanceDataPtr() const { return detail::instanceDataPtrOf( p_.get() ); } public: Module() : p_( ::PyModule_Create( detail::moduleDefPtr() ) ) , data_( 0 ) { assert( detail::moduleDefPtr()->m_size == sizeof( void* ) ); (p_.get() != 0) || cppx::throwX( "Module::: failed" ); instanceDataPtr() = data_ = new detail::InstanceData(); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "Module::setDocString: PyUnicode_FromWideChar failed" ); ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::setDocString: PyObject_SetAttrString failed" ); } void addRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef const defData = { name, f, METH_VARARGS, doc }; data_->methodDefs.push_back( defData ); try { PyMethodDef* const pDef = &data_->methodDefs.back(); Ptr const pyName = ::PyUnicode_FromString( name ); (pyName.get() != 0) || cppx::throwX( "Module::addRoutine: PyUnicode_FromString failed" ); Ptr r = ::PyCFunction_NewEx( pDef, p_.get(), pyName.get()); (r.get() != 0) || cppx::throwX( "Module::addRoutine: PyCFunction_NewEx failed" ); ::PyModule_AddObject( p_.get(), name, r.release() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::addRoutine: PyModule_AddObject failed" ); } catch( ... ) { data_->methodDefs.pop_back(); throw; } } }; } } // namespace progrock::cppy #endif Cheers, - Alf -- blog at From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 8 05:02:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 08 Jul 2010 11:02:47 +0200 Subject: delegation pattern via descriptor In-Reply-To: <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> Message-ID: <4c359425$0$2629$426a74cc@news.free.fr> kedra marbun a ?crit : > On Jul 7, 2:46 am, Bruno Desthuilliers > wrote: >> Gregory Ewing a ?crit : >> >>> Bruno Desthuilliers wrote: >>>> kedra marbun a ?crit : >>>>> if we limit our discussion to py: >>>>> why __{get|set|delete}__ don't receive the 'name' & 'class' from >>>>> __{getattribute|{set|del}attr}__ >>>>> 'name' is the name that is searched >>>> While it would have been technically possible, I fail to imagine any use >>>> case for this. >>> I think he wants to have generic descriptors that are >>> shared between multiple attributes, but have them do >>> different things based on the attribute name. >> I already understood this, but thanks !-) >> >> What I dont understand is what problem it could solve that couldn't be >> solved more simply using the either _getattr__ hook or hand-coded >> delegation, since such a descriptor would be so tightly coupled to the >> host class that it just doesn't make sense writing a descriptor for this. > > yeah, i finally can agree descriptor isn't supposed to be used as > delegation in general, it should be the job of __getattr__ > > however i still think passing name would open up some other > possibilities of use Nothing prevents you to pass a "name" to the descriptor instance when instanciating it, ie: class Desc(object): def __init__(self, name): self.name = name def __get__(self, inst, cls): # ... def __set__(self, inst, value): # ... class Foo(object): bar = Desc("bar") baaz = Desc("baaz") Ok, this is not necessarily what you were looking for, but it's IMHO less brittle than relying on which attribute name was looked up (which is something the descriptor shouldn't have to care about). > > btw, is there a common approach to let the interface of a class that > uses __getattr__, to include names that are delegated? In Python 2.x, not that I know (but it may have passed under my radar). If what you want it to automate delegation of a set of methods without too much manual coding, you can use a custom metaclass that will add the relevant methods to the class, based on (ie) a list (or mapping) of methods names. But that might be a bit overkill. > class A: > def do_this(self): ... > > class B: > a = A() I don't see the point of using delegation on a class attribute. That's typically what inheritance is for. > def do_that(self): ... > > def __getattr__(self, name): > try: > return types.MethodType(getattr(self.a, name), self) Err... Did you try the simple way ? return getattr(self.a, name) From newsuser at stacom-software.de Thu Jul 8 05:08:46 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 11:08:46 +0200 Subject: Howto write XML file with comments? Message-ID: Hello, - I've to write a XML document including comments - the document should be formatted that it could be viewed with a text editor What is the fastest (time for realization) approach doing it in python 2.5? Any help or hints are very welcome Thanks Alexander From alex.kapps at web.de Thu Jul 8 05:21:35 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 08 Jul 2010 11:21:35 +0200 Subject: simple python deployment tool In-Reply-To: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Message-ID: <4C35989F.8040904@web.de> King wrote: > Hi, > > I am writing a python package deployment tool for linux based > platforms. I have tried various existing > tool sets but none of them is up to the mark and they have their own > issues. Initially I'll start with simple approach. I'm sorry, but your approach is not going to work. The Right Way(tm) is to not ship any external libraries, but let the user install the dependencies with the distro's package manager. And to not try to build custom packages, but to let the package maintainers of the different distros package your application for you. > 1. Find all the modules/packages and copy to "lib" directory. > 2. Find python's *.so dependencies(system libs) and copy them to > "syslib" That would include all the way down to libc, your archive is going to be huge, but the actual problem is, what if the libc isn't compatible with the kernel, what if the WX, GTK, X11, etc libraries aren't compatible with the running Xserver? End of the story is, you would need to package a minimal (but almost complete) Linux system into your package, which of course is not want you want. > 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" > directory. > 4. Set up temp environment > 5. Run main script using "python
.py" > > The idea is to produce a cleaner directory structure. Neither I am > creating a boot loader nor I am converting main script > file into executable. It's plain vanilla stuff. It's not vanilla stuff, but a very hard problem. In fact you are fighting against the whole system structure. From stefan_ml at behnel.de Thu Jul 8 05:43:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Jul 2010 11:43:29 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Alexander Eisenhuth, 08.07.2010 11:08: > - I've to write a XML document including comments "write" in the sense of typing in a text editor? Or constructing one programmatically in memory? Or ... ? And what kind of data from what kind of source do you want to put into the document? All of that has an impact on the 'right' answer. > - the document should be formatted that it could be viewed with a text > editor > > What is the fastest (time for realization) approach doing it in python 2.5? If you mean to build an XML document programmatically, potentially using data that you get from somewhere, take a look at cElementTree. There's also a short recipe for pretty printing the tree before writing it out. Stefan From animator333 at gmail.com Thu Jul 8 05:44:00 2010 From: animator333 at gmail.com (King) Date: Thu, 8 Jul 2010 02:44:00 -0700 (PDT) Subject: simple python deployment tool References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Message-ID: <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> On Jul 8, 2:21?pm, Alexander Kapps wrote: > King wrote: > > Hi, > > > I am writing a python package deployment tool for linux based > > platforms. I have tried various existing > > tool sets but none of them is up to the mark and they have their own > > issues. Initially I'll start with simple approach. > > I'm sorry, but your approach is not going to work. The Right Way(tm) > is to not ship any external libraries, but let the user install the > dependencies with the distro's package manager. And to not try to > build custom packages, but to let the package maintainers ?of the > different distros package your application for you. Yes, you an do this by creating a .deb package that will take care of installing the required libraries. It may possible that either required version is not available in the distro's repository or the one available is older one then required. So best deal would be to ship at least all the python's libs along with your package. > > 1. Find all the modules/packages and copy to "lib" directory. > > 2. Find python's *.so dependencies(system libs) and copy them to > > "syslib" > > That would include all the way down to libc, your archive is going > to be huge, but the actual problem is, what if the libc isn't > compatible with the kernel, what if the WX, GTK, X11, etc libraries > aren't compatible with the running Xserver? You are right here. It seems there is no standard definition of system libraries on linux. To over come the problem of binary compatibility, I am using ubuntu (hardy) which is on glibc 2.7. Every other external python library including python is compiled on hardy. This is would give you maximum chances that libs would be compatible in case if you run on any other distro which is using glibc >=2.7 > End of the story is, you would need to package a minimal (but almost > complete) Linux system into your package, which of course is not > want you want. > > > 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" > > directory. > > 4. Set up temp environment > > 5. Run main script using "python
.py" > > > The idea is to produce a cleaner directory structure. Neither I am > > creating a boot loader nor I am converting main script > > file into executable. It's plain vanilla stuff. > > It's not vanilla stuff, but a very hard problem. In fact you are > fighting against the whole system structure. Ok, forget about system libs(libX*.* etc.), I don't know why it sounds too complicated. I am hoping it should work and eventually it's easier then tools that create an executable using bootloader. The problem is in setting the correct python environment. Prashant From lists at cheimes.de Thu Jul 8 05:48:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jul 2010 11:48:35 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C35625B.60606@ixokai.io> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C355817.1010105@v.loewis.de> <4C35625B.60606@ixokai.io> Message-ID: > Really? I wasn't entirely aware of this effect of the "io" module. > Somehow, without at all paying attention (because certain third party > modules blocking me for awhile, I never looked close enough), I just > sort of thought the "io" module was mostly thin wrappers around stdio > primitives, into a more Pythonic API. Yes, really. :) The new io modules doesn't use stdio. It operates solely on file descriptors and low level functions like open(2) instead of fopen(3). All high level functions like buffering is implemented in Python (and some C for speed). Christian From newsuser at stacom-software.de Thu Jul 8 06:07:16 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 12:07:16 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Stefan Behnel schrieb: > Alexander Eisenhuth, 08.07.2010 11:08: >> - I've to write a XML document including comments > > "write" in the sense of typing in a text editor? Or constructing one > programmatically in memory? Or ... ? write means write to a file > > And what kind of data from what kind of source do you want to put into > the document? Data is present as tags and attributes > > All of that has an impact on the 'right' answer. > > >> - the document should be formatted that it could be viewed with a text >> editor >> >> What is the fastest (time for realization) approach doing it in python >> 2.5? > > If you mean to build an XML document programmatically, potentially using > data that you get from somewhere, take a look at cElementTree. There's > also a short recipe for pretty printing the tree before writing it out. Is the API of cElementTree different from ElementTree in the python standard library? > > Stefan > From greg.ewing at canterbury.ac.nz Thu Jul 8 06:10:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 08 Jul 2010 22:10:48 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: <89llvrFflvU1@mid.individual.net> kedra marbun wrote: > i wonder what are the reasons for > not passing the class on which the descriptor is attached to, what > pattern is encouraged by this? The same answer applies. It's assumed that you will be writing a custom piece of code for each attribute of each class, and giving each one its own descriptor. By the time you get to the get or set method of a descriptor, you've already dispatched on both the class and attribute name. There is not usually any point in funnelling things back into a single function and then dispatching on the class or name again. Passing the class or name would just add overhead that was unnecessary in the majority of use cases. -- Greg From stefan_ml at behnel.de Thu Jul 8 06:26:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Jul 2010 12:26:23 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Alexander Eisenhuth, 08.07.2010 12:07: > Stefan Behnel schrieb: >> Alexander Eisenhuth, 08.07.2010 11:08: >>> - I've to write a XML document including comments >> >> "write" in the sense of typing in a text editor? Or constructing one >> programmatically in memory? Or ... ? > > write means write to a file You seam to imply that it's obvious what you want to do. From the little information that you give us, it's not. >> And what kind of data from what kind of source do you want to put into >> the document? > > Data is present as tags and attributes Whatever that is supposed to mean in this context. >> All of that has an impact on the 'right' answer. ... and it still does. >>> - the document should be formatted that it could be viewed with a text >>> editor >>> >>> What is the fastest (time for realization) approach doing it in >>> python 2.5? >> >> If you mean to build an XML document programmatically, potentially >> using data that you get from somewhere, take a look at cElementTree. >> There's also a short recipe for pretty printing the tree before >> writing it out. > > Is the API of cElementTree different from ElementTree in the python > standard library? Same thing, different import. Note that both were updated in Py2.7, BTW. Stefan From dr.mtarver at ukonline.co.uk Thu Jul 8 06:27:03 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Thu, 8 Jul 2010 03:27:03 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <61bbe9c0-f9e3-4b44-ba09-81435ce4b924@k39g2000yqb.googlegroups.com> On 14 June, 00:07, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega Probably you want to look at this thread http://groups.google.co.uk/group/comp.lang.lisp/browse_frm/thread/7b1ab36f5d5cce0a/54afe11153025e27?hl=en&lnk=gst&q=minim#54afe11153025e27 where I specified a toy language Minim (much simpler than C) and the goal was to construct an interpreter for it. Similar problem. Many solutions were given in different languages. The thread is very long. One thing you might look at is whether some sort of lexer/parser is supported in any of your targets. Qi supports a compiler-compiler Qi- YACC that allows you to write in BNF which makes this kind of project much easier. See http://www.lambdassociates.org/Book/page404.htm for an overview Mark From steve at holdenweb.com Thu Jul 8 06:49:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jul 2010 06:49:51 -0400 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel In-Reply-To: References: Message-ID: <4C35AD4F.6020305@holdenweb.com> Vicky Twomey-Lee wrote: > Hi All, > > Join us for drinks and a chat (a warm-up session to PyCon Ireland ;-) ). > > When: Wed 14th July, from 7pm > Where: Trinity Capital Hotel > > More details at: > http://www.python.ie/meetup/2010/python_ireland_meetup_-_july_2010/ > Hope you all had a good piss-up! See you a week on Saturday. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 DjangoCon US September 7-9, 2010 http://djangocon.us/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From newsuser at stacom-software.de Thu Jul 8 06:54:34 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 12:54:34 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Sorry for my little riddle, but you solved it quite good with: - http://effbot.org/zone/element-lib.htm#prettyprint and comments are also in ElementTree (xml.etree.ElementTree.Comment) Thanks Stefan Behnel schrieb: > Alexander Eisenhuth, 08.07.2010 12:07: >> Stefan Behnel schrieb: >>> Alexander Eisenhuth, 08.07.2010 11:08: >>>> - I've to write a XML document including comments >>> >>> "write" in the sense of typing in a text editor? Or constructing one >>> programmatically in memory? Or ... ? >> >> write means write to a file > > You seam to imply that it's obvious what you want to do. From the little > information that you give us, it's not. > > >>> And what kind of data from what kind of source do you want to put into >>> the document? >> >> Data is present as tags and attributes > > Whatever that is supposed to mean in this context. > > >>> All of that has an impact on the 'right' answer. > > ... and it still does. > > >>>> - the document should be formatted that it could be viewed with a text >>>> editor >>>> >>>> What is the fastest (time for realization) approach doing it in >>>> python 2.5? >>> >>> If you mean to build an XML document programmatically, potentially >>> using data that you get from somewhere, take a look at cElementTree. >>> There's also a short recipe for pretty printing the tree before >>> writing it out. >> >> Is the API of cElementTree different from ElementTree in the python >> standard library? > > Same thing, different import. > > Note that both were updated in Py2.7, BTW. > > Stefan > From askutt at gmail.com Thu Jul 8 06:58:27 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 03:58:27 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> On Jul 8, 12:53?am, "Zooko O'Whielacronx" wrote: > I don't understand. I described two different problems: problem one is > that the inputs, outputs and literals of your program might be in a > different encoding (in my experience they have most commonly been in > decimal). Problem two is that your computations may be lossy. If the > inputs, outputs and literals of your program are decimal (as they have > been for most of my programs) then using decimal is better than using > float because of problem one. Neither has a strict advantage over the > other in terms of problem two. I can't think of any program I've ever written where the inputs are actually intended to be decimal. Consider a simple video editing program, and the user specifies a frame rate 23.976 fps. Is that what they really wanted? No, they wanted 24000/1001 but didn't feel like typing that. It should be instructive and telling that mplayer now strongly prefers the rational expressions over the decimal ones. Just because you haven't rounded your input in parsing it doesn't change the fact your input may have be rounded before it was presented to the program, which is the reality of the matter more often than not. Even in fields where the numbers are decimal, like finance, the rules are considerably more complicated than what you were taught in the "schoolbook". This is one of the reasons IBM can still make a killing selling mainframes, they got all of those rules right decades ago. > > And that will be never true once you > > start using non trivial computation (i.e. transcendental functions > > like log, exp, etc...). > > I'm sorry, what will never be true? Are you saying that decimals have > a disadvantage compared to floats? If so, what is their disadvantage? He's saying that once you get past elementary operations, you quickly run into irrational numbers, which you will not be representing accurately. Moreover, in general, it's impossible to even round operations involving transcendental functions to an arbitrary fixed- precision, you may need effectively infinite precision in order to the computation. In practice, this means the error induced by a lossy input conversion (assuming you hadn't already lost information) is entirely negligible compared to inherent inability to do the necessary calculations. From dlanorslegov at rocketmail.com Thu Jul 8 07:30:09 2010 From: dlanorslegov at rocketmail.com (Dlanor Slegov) Date: Thu, 8 Jul 2010 04:30:09 -0700 (PDT) Subject: Writing Out from 2 Lists Message-ID: <37807.88947.qm@web120104.mail.ne1.yahoo.com> Hi, I am trying to find a python solution for an informatics problem I have at work.?Generalized equivalent of my problem is: I have an excel sheet with column 1 and column 2 having corresponding information (much like a dictionary, however with repeating "keys"). Its like if you read down column 1: a,b,a,a,b,c and if you read down column 2: 1,2,3,4,5,6. I would like to write "unique" files such as a.txt, b.txt and c.txt with matching information (from column 2) in a.txt in separate rows like: 1,3,4 and in b.txt like: 2,5, etc. What I have been able to do until now is the following: import sys sys.path.append("C:/Downloads/Python/xlrd-0.6.1") import xlrd wb = xlrd.open_workbook("myexcelsheet.xls") sheet = wb.sheet_by_index(0) clmn1 = sheet.col_values(1,1) clmn2 = sheet.col_values(2,1) #NOW WHAT IS HAVE ARE TWO LISTS WITH CORRESPONDING INDICES #My thought is now to write a counter and for each value in clmn1, write a text file with the name of the value and add data from clmn2 in this file. I want to start with index[0], i.e. value 1 of clmn1 and then go to 2nd value and compare (==) it with 1st value and if its equal then append to the same file 2nd value from clmn2...like this with 3rd value in clmn1, i want to compare it to 1st and 2nd value....wrap this whole in to a nice loop. #Don't know if this is the "easy" way, but this is what my mind came up with. Now I am stuck in colored line below, where I am unable to "create a new filename with string coming from a variable": l = len(clmn1) c = 0 while (c < l): filename = clmn1[c] fhdl1 = open('/mypythonfolder/%(filename)s_appendsomename.txt','w') fhdl1.write(clmn2(c)+'\n') print filename ... c = c + 1 ... ... ... I would appreciate comments and suggestions on how can I get through this problem and also would like to know if there are any methods for lists to solve this problem in a different way. Many Thanks, Ronald. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dm at tu-clausthal.de Thu Jul 8 08:16:36 2010 From: dm at tu-clausthal.de (David Mainzer) Date: Thu, 08 Jul 2010 14:16:36 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: On 07/07/2010 08:08 PM, Raymond Hettinger wrote: > On Jul 7, 5:55 am, Mark Dickinson wrote: >> On Jul 7, 1:05 pm, david mainzer wrote: >> >> >> >>> Dear Python-User, >> >>> today i create some slides about floating point arithmetic. I used an >>> example from >> >>> http://docs.python.org/tutorial/floatingpoint.html >> >>> so i start the python shell on my linux machine: >> >>> dm at maxwell $ python >>> Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) >>> [GCC 4.3.4] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 >>>>>>>>> for i in range(10): >> >>> ... sum += 0.1 >>> ...>>> >>> sum >>> 0.99999999999999989 >> >>> But thats looks a little bit wrong for me ... i must be a number greater >>> then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 >>> in python ... if i print it. > > [Mark Dickinson] >> So you've identified one source of error here, namely that 0.1 isn't >> exactly representable (and you're correct that the value stored >> internally is actually a little greater than 0.1). But you're >> forgetting about the other source of error in your example: when you >> do 'sum += 0.1', the result typically isn't exactly representable, so >> there's another rounding step going on. That rounding step might >> produce a number that's smaller than the actual exact sum, and if >> enough of your 'sum += 0.1' results are rounded down instead of up, >> that would easily explain why the total is still less than 1.0. > > One key for understanding floating point mysteries is to look at the > actual binary sums rather that their approximate representation as a > decimal string. The hex() method can make it easier to visualize > Mark's explanation: > >>>> s = 0.0 >>>> for i in range(10): > ... s += 0.1 > ... print s.hex(), repr(s) > > > 0x1.999999999999ap-4 0.10000000000000001 > 0x1.999999999999ap-3 0.20000000000000001 > 0x1.3333333333334p-2 0.30000000000000004 > 0x1.999999999999ap-2 0.40000000000000002 > 0x1.0000000000000p-1 0.5 > 0x1.3333333333333p-1 0.59999999999999998 > 0x1.6666666666666p-1 0.69999999999999996 > 0x1.9999999999999p-1 0.79999999999999993 > 0x1.cccccccccccccp-1 0.89999999999999991 > 0x1.fffffffffffffp-1 0.99999999999999989 > > Having used hex() to understand representation error (how the binary > partial sums are displayed), you can use the Fractions module to gain > a better understanding of rounding error introduced by each addition: > >>>> s = 0.0 >>>> for i in range(10): > exact = Fraction.from_float(s) + Fraction.from_float(0.1) > s += 0.1 > actual = Fraction.from_float(s) > error = actual - exact > print '%-35s%-35s\t%s' % (actual, exact, error) > > > 3602879701896397/36028797018963968 3602879701896397/36028797018963968 > 0 > 3602879701896397/18014398509481984 3602879701896397/18014398509481984 > 0 > 1351079888211149/4503599627370496 10808639105689191/36028797018963968 > 1/36028797018963968 > 3602879701896397/9007199254740992 > 14411518807585589/36028797018963968 -1/36028797018963968 > 1/2 > 18014398509481985/36028797018963968 -1/36028797018963968 > 5404319552844595/9007199254740992 > 21617278211378381/36028797018963968 -1/36028797018963968 > 3152519739159347/4503599627370496 > 25220157913274777/36028797018963968 -1/36028797018963968 > 7205759403792793/9007199254740992 > 28823037615171173/36028797018963968 -1/36028797018963968 > 2026619832316723/2251799813685248 > 32425917317067569/36028797018963968 -1/36028797018963968 > 9007199254740991/9007199254740992 > 36028797018963965/36028797018963968 -1/36028797018963968 > > Hope this helps your slides, > > > Raymond Thanks to all for your help :) All your comments helped me and now i know how it works in python ! Best David From alex.kapps at web.de Thu Jul 8 08:17:36 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 08 Jul 2010 14:17:36 +0200 Subject: simple python deployment tool In-Reply-To: <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> Message-ID: <4C35C1E0.9020609@web.de> King wrote: > On Jul 8, 2:21 pm, Alexander Kapps wrote: >> King wrote: >>> Hi, >>> I am writing a python package deployment tool for linux based >>> platforms. I have tried various existing >>> tool sets but none of them is up to the mark and they have their own >>> issues. Initially I'll start with simple approach. >> I'm sorry, but your approach is not going to work. The Right Way(tm) >> is to not ship any external libraries, but let the user install the >> dependencies with the distro's package manager. And to not try to >> build custom packages, but to let the package maintainers of the >> different distros package your application for you. > > Yes, you an do this by creating a .deb package that will take care of > installing the required libraries. > It may possible that either required version is not available in the > distro's repository or the one available is > older one then required. Yes, that may happen. > So best deal would be to ship at least all > the python's libs along with your package. No, IMHO, the best way to cope with this, is to be a little conservative on what library versions you use. Don't use the most cutting edge versions, but those who are most wildly available. Even if you must use the most recent versions, you should leave the packaging to the distro maintainers. They know their distro a lot better and know how to maintain compatiblity with the rest of the system. >>> 1. Find all the modules/packages and copy to "lib" directory. >>> 2. Find python's *.so dependencies(system libs) and copy them to >>> "syslib" >> That would include all the way down to libc, your archive is going >> to be huge, but the actual problem is, what if the libc isn't >> compatible with the kernel, what if the WX, GTK, X11, etc libraries >> aren't compatible with the running Xserver? > > You are right here. It seems there is no standard definition of system > libraries on linux. To over come the problem of binary > compatibility, I am using ubuntu (hardy) which is on glibc 2.7. Every > other external python library including python is compiled on > hardy. This is would give you maximum chances that libs would be > compatible in case if you run on any other distro which is using glibc >> =2.7 Just because any other disto is based on glibc 2.7 doesn't ensure, that the other parts (like gtk libs vs. X11) are compatible. Actually by doing so, you are limiting your package to Hardy only. Any compatiblity with other Ubuntu versions or other distros would be purely by accident. >> End of the story is, you would need to package a minimal (but almost >> complete) Linux system into your package, which of course is not >> want you want. >> >>> 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" >>> directory. >>> 4. Set up temp environment >>> 5. Run main script using "python
.py" >>> The idea is to produce a cleaner directory structure. Neither I am >>> creating a boot loader nor I am converting main script >>> file into executable. It's plain vanilla stuff. >> It's not vanilla stuff, but a very hard problem. In fact you are >> fighting against the whole system structure. > > Ok, forget about system libs(libX*.* etc.), I don't know why it sounds > too complicated. I am hoping it should work and eventually it's easier > then tools that create an executable using bootloader. The problem is > in setting the correct python environment. It sounds complicated, because it is complicated. :-) Now, imagine, everybody would do this. There would be dozens, maybe hundreds of redundant copies of Python, libXYZ, etc. I don't know what you mean by "create an executable using bootloader", but really, the correct way is to leave the dependency management to the distro and it's package manager. From clp2 at rebertia.com Thu Jul 8 08:36:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jul 2010 05:36:34 -0700 Subject: Writing Out from 2 Lists In-Reply-To: <37807.88947.qm@web120104.mail.ne1.yahoo.com> References: <37807.88947.qm@web120104.mail.ne1.yahoo.com> Message-ID: On Thu, Jul 8, 2010 at 4:30 AM, Dlanor Slegov wrote: > Hi, > > I am trying to find a python solution for an informatics problem I have at > work.?Generalized equivalent of my problem is: > > I have an excel sheet with column 1 and column 2 having corresponding > information (much like a dictionary, however with repeating "keys"). Its > like if you read down column 1: a,b,a,a,b,c and if you read down column 2: > 1,2,3,4,5,6. I would like to write "unique" files such as a.txt, b.txt and > c.txt with matching information (from column 2) in a.txt in separate rows > like: 1,3,4 and in b.txt like: 2,5, etc. > > What I have been able to do until now is the following: > > import sys > sys.path.append("C:/Downloads/Python/xlrd-0.6.1") > import xlrd > > wb = xlrd.open_workbook("myexcelsheet.xls") > sheet = wb.sheet_by_index(0) > > clmn1 = sheet.col_values(1,1) > clmn2 = sheet.col_values(2,1) > > #NOW WHAT IS HAVE ARE TWO LISTS WITH CORRESPONDING INDICES > > #My thought is now to write a counter and for each value in clmn1, write a > text file with the name of the value and add data from clmn2 in this file. I > want to start with index[0], i.e. value 1 of clmn1 and then go to 2nd value > and compare (==) it with 1st value and if its equal then append to the same > file 2nd value from clmn2...like this with 3rd value in clmn1, i want to > compare it to 1st and 2nd value....wrap this whole in to a nice loop. > > #Don't know if this is the "easy" way, but this is what my mind came up > with. Now I am stuck in colored line below, where I am unable to "create a > new filename with string coming from a variable": > > l = len(clmn1) > c = 0 > while (c < l): > filename = clmn1[c] > fhdl1 = open('/mypythonfolder/%(filename)s_appendsomename.txt','w') fhdl1 = open('/mypythonfolder/%s_appendsomename.txt' % filename,'w') > fhdl1.write(clmn2(c)+'\n') > print filename > ... > c = c + 1 Personally, I'd rewrite the loop like this, using zip() and a for-loop: for name, value in zip(clmn1, clmn2): filepath = '/mypythonfolder/' + name + '_appendsomename.txt' with open(filepath, 'a') as f: f.write(str(value)) f.write('\n') Cheers, Chris -- http://blog.rebertia.com From rantingrick at gmail.com Thu Jul 8 08:54:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 8 Jul 2010 05:54:46 -0700 (PDT) Subject: Argh! Name collision! References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: <473a10e4-09df-4c39-b74b-e7cb6e4bb7ea@d16g2000yqb.googlegroups.com> On Jul 7, 6:47?pm, "Alf P. Steinbach /Usenet" wrote: > Hm, for pure shock value I think I'll use the acronym PYthon Native Interface > Support. > > pynis! :-) Well as long as you don't put your "pynis" *pointers* in "pynie" then everything will be Ok! ;-) From askutt at gmail.com Thu Jul 8 09:00:48 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 06:00:48 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> On Jul 8, 7:23?am, Mark Dickinson wrote: > On Jul 8, 11:58?am, Adam Skutt wrote: > > > accurately. ?Moreover, in general, it's impossible to even round > > operations involving transcendental functions to an arbitrary fixed- > > precision, you may need effectively infinite precision in order to the > > computation. > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > decimal module do exactly that, giving correctly-rounded exp() and > log() results to arbitrary precision? You run into the table-maker's dilemma: there's no way to know in advance how many digits you need in order to have n bits of precision in the result. For some computations, the number of bits required to get the desired precision can quickly overwhelm the finite limitations of your machine (e.g., you run out of RAM first or the time to compute the answer is simply unacceptable). Adam From ethan at stoneleaf.us Thu Jul 8 09:10:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Jul 2010 06:10:06 -0700 Subject: Python -- floating point arithmetic In-Reply-To: <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> Message-ID: <4C35CE2E.9020607@stoneleaf.us> Wolfram Hinderer wrote: > On 7 Jul., 19:32, Ethan Furman wrote: > >>Nobody wrote: >> >>>On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: >> >>>>you should never rely on a floating-point number to have exactly a >>>>certain value. >> >>>"Never" is an overstatement. There are situations where you can rely >>>upon a floating-point number having exactly a certain value. >> >>It's not much of an overstatement. How many areas are there where you >>need the number >>0.100000000000000005551115123125782702118158340454101562500000000000? >> >>If I'm looking for 0.1, I will *never* (except by accident ;) say >> >>if var == 0.1: >> >>it'll either be <= or >=. > > > The following is an implementation of a well-known algorithm. > Why would you want to replace the floating point comparisons? With > what? Interesting. I knew when I posted my above comment that I was ignoring such situations. I cannot comment on the code itself as I am unaware of the algorithm, and haven't studied numbers extensively (although I do find them very interesting). So while you've made your point, I believe mine still stands -- comparing floats using == to absolute numbers is almost always a mistake. ~Ethan~ From victorsubervi at gmail.com Thu Jul 8 09:20:00 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 08:50:00 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: On Wed, Jul 7, 2010 at 2:22 PM, Stephen Hansen wrote: > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); > > By following this advice, I realized I didn't need to do that fancy multiplying out the '%s' which was screwing me up anyway, and then I didn't need to create an sql using a '%', and then I didn't need to open the door to injection attack! However, I now have another error. Here is my current command: cursor.execute("insert into personalDataKeys (Store, User, useFirstName, useLastName, usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) I get this error from MySQL which I am having a hard time understanding: LATEST FOREIGN KEY ERROR ------------------------ 100708 6:15:01 Transaction: TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id 1169992000 inserting, thread declared inside InnoDB 500 mysql tables in use 1, locked 1 3 lock struct(s), heap size 368, undo log entries 1 MySQL thread id 1502, query id 23700 localhost beno update insert into personalDataKeys (Store, User, useFirstName, useLastName, usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, 1, 1, 1) Foreign key constraint fails for table `test/personalDataKeys`: , CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES `products` (`Store`) Trying to add in child table, in index `Store` tuple: DATA TUPLE: 2 fields; 0: len 9; hex 7370656369616c7479; asc specialty;; 1: len 6; hex 0000000003b7; asc ;; But in parent table `test/products`, in index `Store`, the closest match we can find is record: PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 696e66696d756d00; asc infimum ;; What is this tuple? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Thu Jul 8 09:22:39 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 06:22:39 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> On Jul 8, 2:00?pm, Adam Skutt wrote: > On Jul 8, 7:23?am, Mark Dickinson wrote:> On Jul 8, 11:58?am, Adam Skutt wrote: > > > > accurately. ?Moreover, in general, it's impossible to even round > > > operations involving transcendental functions to an arbitrary fixed- > > > precision, you may need effectively infinite precision in order to the > > > computation. > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > decimal module do exactly that, giving correctly-rounded exp() and > > log() results to arbitrary precision? > > You run into the table-maker's dilemma: there's no way to know in > advance how many digits you need in order to have n bits of precision > in the result. Sure. But it's a bit of a stretch to go from not knowing what resources you'll need in advance to calling something 'impossible'. :) >?For some computations, the number of bits required to > get the desired precision can quickly overwhelm the finite limitations > of your machine (e.g., you run out of RAM first or the time to compute > the answer is simply unacceptable). Perhaps in theory. In practice, though, it's very rare to need to increase precision more than once or twice beyond an initial first guesstimate, and the amount of extra precision needed is small. That increase is unlikely to cause problems unless you were operating right up against your machine's limits in the first place. -- Mark From DierkErdmann at mail.com Thu Jul 8 09:42:48 2010 From: DierkErdmann at mail.com (DierkErdmann at mail.com) Date: Thu, 8 Jul 2010 06:42:48 -0700 (PDT) Subject: Debugging a segmentation fault Message-ID: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Hi, my python project crashes in a non reproducible way. With gdb I got the backtraces given below. How can I possibly figure out the reason for the segfaults that occur under Linux and Windows, using Python 2.6 in both cases. Thanks Dierk Program received signal SIGSEGV, Segmentation fault. 0x080902bf in dict_dealloc (mp=0xbfbf0b4) at ../Objects/dictobject.c: 911 911 ../Objects/dictobject.c: No such file or directory. in ../Objects/dictobject.c (gdb) bt #0 0x080902bf in dict_dealloc (mp=0xbfbf0b4) at ../Objects/ dictobject.c:911 #1 0x08090304 in dict_dealloc (mp=0xa805d74) at ../Objects/ dictobject.c:911 #2 0x08090304 in dict_dealloc (mp=0xbc2768c) at ../Objects/ dictobject.c:911 #3 0x08090304 in dict_dealloc (mp=0xbc27c64) at ../Objects/ dictobject.c:911 #4 0x080ab611 in subtype_dealloc (self= to continue, or q to quit--- Frame 0x969ddb4, for file analyse.py, line 398, in analyseall (options=, TIMEFMT='%d.%m.%Y', TIMESPAN_DAYS=365, projects=[('ant', 2002, 2008), ('apache', 1995, 2009), ('gcc', 2003, 2009), ('gimp', 2003, 2009), ('gnucash', 2001, 2009), ('gnumeric', 2000, 2009), ('gtk', 2000, 2009), ('kde', 2003, 2009), ('maemo', 2006, 2009), ('python', 1999, 2009), ('samba', 2004, 2009), ('tomcat', 2000, 2009), ('wine', 2003, 2009)], ra=: {'grClusterCoeff': , 'grDensity': , 'grNumberMails': 1593, 'mailsPerDay': , 'grMedianDegree': , 'productivity': , 'grDistKSTest': , 'grEdges': 269, 'grBetweenCentNetw': , 'grNumberNodes': 122, 'grBetweenCentNodeMedian': , 'gr...(truncated), throwflag=0) at ../Python/ ceval.c:1010 #8 0x080e1bb0 in fast_function (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:3836 #9 call_function (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:3771 #10 PyEval_EvalFrameEx (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:2412 Program received signal SIGSEGV, Segmentation fault. visit_decref (op=, data=0x0) at ../Modules/ gcmodule.c:271 271 ../Modules/gcmodule.c: No such file or directory. in ../Modules/gcmodule.c (gdb) bt #0 visit_decref (op=, data=0x0) at ../ Modules/gcmodule.c:271 #1 0x0809223d in dict_traverse (op= {'_sa_adapter': , owner_state=, _strong_obj=None, callables={}, session_id=158970732, modified=False, class_=]), _validators={}, _inheriting_mappers=set([]), _with_polymorphic_selectable=<...>, single=False, allow_partial_pks=True, _dependency_processors=[, direction=, parent=]), _validators={}, _inheriting_mappers=set([]), single=False, allow_partial_pks=True, _dependency_processors=[], tables=[<...>], order_by=False, primary_key=]), index=None, server_onupdate=None, name='id', is_literal=False, nullable=False, default=None, quote=None, autoincrement=True, onupdate=None, foreign_keys=, _...(truncated), visit=0x810c460 , arg=0x0) at ../Objects/dictobject.c:2003 #2 0x0810cebc in subtract_refs (generation=) at ../Modules/gcmodule.c:296 #3 collect (generation=) at ../Modules/ gcmodule.c:817 #4 0x0810d8eb in collect_generations (basicsize=28) at ../Modules/ gcmodule.c:924 #5 _PyObject_GC_Malloc (basicsize=28) at ../Modules/gcmodule.c:1363 #6 0x080ab65b in PyType_GenericAlloc (type=0x8236be0, nitems=0) at ../ Objects/typeobject.c:758 #7 0x080bc9a7 in weakref___new__ (type=0x8236be0, args= (, ), kwargs=0x0) at ../Objects/weakrefobject.c:300 #8 0x080ad0dd in type_call (type=0x8236be0, args= (, ), kwds=0x0) at ../Objects/typeobject.c:726 #9 0x0806245a in PyObject_Call (func=, arg= (, ), kw=0x0) at ../Objects/abstract.c:2492 #10 0x080e0471 in do_call (f= Frame 0x9aabb04, for file /usr/local/lib/python2.6/dist-packages/ SQLAlchemy-0.6.0-py2.6.egg/sqlalchemy/orm/state.py, line 29, in __init__ (self=]), _validators={}, _inheriting_mappers=set([]), _with_polymorphic_selectable=<...>, single=False, allow_partial_pks=True, _dependency_processors=[, direction=, parent=<...>, post_update=False, passive_updates=True, prop=, <...>)], _compile_finished=True, lazy=True, uselist=False, collection_class=None, back_populates=None, table=<...>, innerjoin=False, order_by=False, join_depth=None, strategy=, target=<...>, parent=<...>, use_get=True, uselist=False, _LazyLoader__lazywhere=<_BinaryExpression(negate=, modifiers={}, right=<...>, opera...(truncated), throwflag=0) at ../Python/ceval.c:3968 From philip at semanchuk.com Thu Jul 8 09:44:43 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 8 Jul 2010 09:44:43 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: <162EBD90-A792-49CF-99E0-DB34BD53F728@semanchuk.com> On Jul 7, 2010, at 11:26 PM, Terry Reedy wrote: > On 7/7/2010 5:29 AM, geremy condra wrote: >> On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: >>> On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >>>> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >>>>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchu > >>>>>> I ported two pure C extensions from 2 to 3 and was even able to >>>>>> keep a >>>>>> single C codebase. I'd be willing to contribute my experiences >>>>>> to a >>>>>> document >>>>>> somewhere. (Is there a Wiki?) > >>>>> Indeed there is: http://wiki.python.org/moin/ > >>>> Thanks. I don't want to appear ungrateful, but I was hoping for >>>> something specific to the 2-to-3 conversion. I guess someone has to >>>> start somewhere... > >>> There is an existing 2to3 and other pages for Python code >>> conversion. I do >>> not know of any for CAPI conversion. The need for such has been >>> acknowledged >>> among the devs but if there is nothing yet, we need someone with >>> specialized >>> experience and a bit of time to make a first draft. If you start >>> one, give >>> it an easy to remember name C2to3? 2to3Capi? You choose. And link >>> to it from >>> the 2to3 pag >>> In his post on this thread, Martin Loewis volunteered to list what >>> he knows >>> from psycopg2 if someone else will edit. > >> I'm not sure why I don't have this post, but I'm happy to help edit >> etc if Martin >> wants to put together a rough draft. > > Since I wrote that, someone pointed out the the Python How-to > collection includes Porting Extension Modules to 3.0 > by Benjamim Peterson. So all Pyilip or Martin need to do is read > that and suggest additions. That document is here: http://wiki.python.org/moin/PortingExtensionModulesToPy3k It took me a while to find. It's a shame it's not better known; I looked for such a document before I started porting sysv_ipc and posix_ipc and didn't find this one. Thanks for the pointer. Cheers Philip From python at lonely-star.org Thu Jul 8 09:56:51 2010 From: python at lonely-star.org (Nathan Huesken) Date: Thu, 8 Jul 2010 09:56:51 -0400 Subject: Storing a callback function as a class member In-Reply-To: References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: <20100708095651.7a973168@SamZwo.tch.harvard.edu> Hey, Sorry, I tried to sent only the relevant parts of the example, but the part where the error was, was left out. I defined the function, used as callback like this: class SomeClass: def callback(param): ... So I forgot the "self" parameter, and therefor the callback had a different number of parameters than I expected. Thanks for the effort! Nathan From stefan-usenet at bytereef.org Thu Jul 8 09:59:40 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 15:59:40 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <20100708135940.GA29032@yoda.bytereef.org> Adam Skutt wrote: > On Jul 8, 7:23?am, Mark Dickinson wrote: > > On Jul 8, 11:58?am, Adam Skutt wrote: > > > > > accurately. ?Moreover, in general, it's impossible to even round > > > operations involving transcendental functions to an arbitrary fixed- > > > precision, you may need effectively infinite precision in order to the > > > computation. > > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > decimal module do exactly that, giving correctly-rounded exp() and > > log() results to arbitrary precision? > > You run into the table-maker's dilemma: there's no way to know in > advance how many digits you need in order to have n bits of precision > in the result. For some computations, the number of bits required to > get the desired precision can quickly overwhelm the finite limitations > of your machine (e.g., you run out of RAM first or the time to compute > the answer is simply unacceptable). Yes, this appears to be unsolved yet, see also: http://www.cs.berkeley.edu/~wkahan/LOG10HAF.TXT "Is it time to quit yet? That's the Table-Maker's Dilemma. No general way exists to predict how many extra digits will have to be carried to compute a transcendental expression and round it _correctly_ to some preassigned number of digits. Even the fact (if true) that a finite number of extra digits will ultimately suffice may be a deep theorem." However, in practice, mpfr rounds correctly and seems to be doing fine. In addition to this, I've been running at least 6 months of continuous tests comparing cdecimal and decimal, and neither log() nor exp() poses a problem. pow() is trickier. Exact results have to be weeded out before attempting the correction loop for correct rounding, and this is complicated. For example, in decimal this expression takes a long time (in cdecimal the power function is not correctly rounded): Decimal('100.0') ** Decimal('-557.71e-742888888') Stefan Krah From askutt at gmail.com Thu Jul 8 10:29:41 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 07:29:41 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> Message-ID: <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> On Jul 8, 9:22?am, Mark Dickinson wrote: > On Jul 8, 2:00?pm, Adam Skutt wrote: > > > On Jul 8, 7:23?am, Mark Dickinson wrote:> On Jul 8, 11:58?am, Adam Skutt wrote: > > > > > accurately. ?Moreover, in general, it's impossible to even round > > > > operations involving transcendental functions to an arbitrary fixed- > > > > precision, you may need effectively infinite precision in order to the > > > > computation. > > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > > decimal module do exactly that, giving correctly-rounded exp() and > > > log() results to arbitrary precision? > > > You run into the table-maker's dilemma: there's no way to know in > > advance how many digits you need in order to have n bits of precision > > in the result. > > Sure. ?But it's a bit of a stretch to go from not knowing what > resources you'll need in advance to calling something 'impossible'. :) > > >?For some computations, the number of bits required to > > get the desired precision can quickly overwhelm the finite limitations > > of your machine (e.g., you run out of RAM first or the time to compute > > the answer is simply unacceptable). > > Perhaps in theory. ?In practice, though, it's very rare to need to > increase precision more than once or twice beyond an initial first > guesstimate, and the amount of extra precision needed is small. ?That > increase is unlikely to cause problems unless you were operating right > up against your machine's limits in the first place. I suspect your platitude isn't especially comforting for those who need more computing capability than we can currently construct. However, I wouldn't call the amount of extra needed precision "small" for most transcendental functions, as it's frequently more than double in the worse-case situations and increases non-linearly as the number of desired digits increases. Which almost brings us full circle to where I was originally pointing: the "rounding" problem is inherent in the finite nature of a physical computer, so you cannot make the rounding problem go away. As such, talking about differences in rounding between decimal and binary representations is somewhat of a corner case. Replacing "float" with "decimal" won't get rid of the problems that floating-point brings to the table in the first place. The issues that come up all have to do with lack of human understanding of what the computer is doing. Take even as something as innocent as equality between two floating-point numbers: even exact rounding of all operations doesn't solve this entirely common problem. Accordingly, once we explain why this doesn't work, we frequently don't need the enhanced functionality decimal provides and hopefully can make the determination on our own. If you want to make elementary arithmetic (add, subtract, multiple, divide) behave intuitively then you (arguably) want an arbitrary- precision fractional/rational number class. After that, the right solution is education. Adam From vincent at vincentdavis.net Thu Jul 8 10:34:58 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 8 Jul 2010 08:34:58 -0600 Subject: Python script to install python Message-ID: I would like to have a python script that would download the most recent svn of python, configure, make, install and cleanup after itself. I am not replacing the python version I would be using to run the script. I was struggling to get this to work and I assume someone else has done it better. Any pointers? Thanks Vincent From Bryan.Stopp at argushealth.com Thu Jul 8 10:36:34 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 09:36:34 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> I've seen other threads on this issue, but the resolution still doesn't seem to exist for me. I'm running the configure script with these parameters: ./configure --prefix=/build/tools \ --exec-prefix=/build/tools \ --enable-shared \ --enable-ipv6 \ --with-gcc \ --with-pth I also want to state that I already edited all of the configure & config.guess scripts to comprehend AIX6.1 (they're not updated yet). And as you can see, I'm running this using the "-with-gcc" option. The configure seems to have no problems; so I run a: make clean && make This results in a completed compile. If I go back and look I see a lot of this: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so collect2: library libpython2.6 not found Notice that it can't find the Python lib.. well, it's not installed yet. It's built and in the current directory I'm working out of, but that's not in my LiBPATH. I'll come back to that. If I don't do anything and try to "make install" it pushes the python & libpython libraries to the appropriate locations, and then it appears it tries to re-make the modules: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so However this time it results in a mass of: ld: 0711-224 WARNING: Duplicate symbol: I mean I get like 1000+ of these warnings. But they all culminate in: ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. Fatal Python error: Interpreter not initialized (version mismatch?) make: The signal code from the last command is 6. Now, I said I'd get back to the LIBPATH issue. I thought that if it was looking for that libpython file to compile the modules, it just wasn't finding it. So I executed a: LIBPATH=.:$LIBPATH make This resulted in: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so ld: 0706-006 Cannot find or open library file: -l python2.6 ld:open(): No such file or directory collect2: ld returned 255 exit status Huh? Can't find the library now? In any event, I can't get Python to compile and/or install on my machine. Does anyone have any insight into what is happening to cause this problem? -B PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Jul 8 10:54:10 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Jul 2010 14:54:10 GMT Subject: Is This Open To SQL Injection? References: Message-ID: Ian wrote: > On 07/07/2010 19:38, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % >> (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) >> >> Is this open to injection attacks? If so, how correct? >> TIA, >> beno > Yes, it is trivially open to injection attacks. > > What would happen if someone enters the next line into one of your > col_vals > > x,y);DROP DATABASE personalDataKeys; ha ha > > Your sql statement would be closed early by the semicolon, and the > DROP TABLE personalDataKeys is then executed and would cause some > unexpected data loss. > > Things could be more serious - DROP DATABASE mysql; for a mysql > installation for example. > > You must always always every time and without any exceptions > what-so-ever, put all and every piece of data that comes from outside > the program through the appropriate routine to make whatever has been > entered into storable data and not part of the sql statement. > > In php this is mysql_real_escape_string(). In your favourite language > there will be an equivalent. > > If you miss just one occurrence its like leaving the side window > unlocked! Someone will get in one day. > Try reading the code more carefully. You don't need to escape the strings so long as you use cursor.execute properly. In this case it is being used properly: there is no danger of injection attacks from col_vals. If `store` or `user` come from user input there is a danger as they are being inserted into the generated sql. As has already been pointed out the code to generate the sql is broken, but the principle behind it is sound. In this case the correct thing to do would appear to be: sql = 'insert into personalDataKeys values (%%s, %%s, %s)' % (','.join (['%s'] * len(col_vals))) cursor.execute(sql, (store, user) + col_vals) which safely sanitises all of the data passed to the database. -- Duncan Booth http://kupuguy.blogspot.com From love_ram2040 at yahoo.com Thu Jul 8 10:57:57 2010 From: love_ram2040 at yahoo.com (porxy) Date: Thu, 8 Jul 2010 07:57:57 -0700 (PDT) Subject: open all sites free now Message-ID: <820ac731-5b6a-40f7-8baa-c641c3d2d33f@e5g2000yqn.googlegroups.com> open all sites free now no blocked sites now with this site ,just put your blocked site and it will open free http://openfree.zzl.org/here From invalid at invalid.invalid Thu Jul 8 11:00:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 15:00:29 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-07, Grant Edwards wrote: > Oops. Those Python bindings are for version 1.3.2 of libconfig (which > does work). They don't work with the current version of libconfig. I've stripped the python bindings down to a minimal point, and I've decided there may be a memory corruption problem in the 1.4.5 version of the library. Here's the current boost binding: ---------------------------------pylibconfig.cc------------------------------ #include #include using namespace boost::python; using namespace libconfig; class pyConfig { public: pyConfig() { config = new Config(); } ~pyConfig () { delete config; } private: Config *config; }; BOOST_PYTHON_MODULE(pylibconfig) { class_("Config"); } ---------------------------------pylibconfig.cc------------------------------ That builds without warnings and installs fine, but attempting to actually create an instance of the class in Python causes a glibc memory corruption message: Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pylibconfig >>> conf = pylibconfig.Config() *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Am I correct in concluding it has to be a memory corruption problem in the library itself? -- Grant Edwards grant.b.edwards Yow! I want the presidency at so bad I can already taste gmail.com the hors d'oeuvres. From jwhughes at hughesconcepts.com Thu Jul 8 11:00:49 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Thu, 8 Jul 2010 11:00:49 -0400 Subject: Issue with logging.config Message-ID: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Hi Python Help: I'm doing some work with logging.config and I'm running into an interesting situation. I've run this by python-help, but that didn't help so I thought I would send to the list. Here is the config file [loggers] keys=root,log,syslog [handlers] keys=console,log,syslog [formatters] keys=rootFormat,logFormat,syslogFormat [logger_root] level=DEBUG handlers=console [logger_log] level=DEBUG handlers=log qualname=log [logger_syslog] level=DEBUG handlers=syslog qualname=syslog [handler_console] class=StreamHandler level=DEBUG formatter=rootFormat args=(sys.stdout,) [handler_log] class=handlers.RotatingFileHandler level=DEBUG formatter=logFormat args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) propagate=0 [handler_syslog] class=handlers.SysLogHandler level=DEBUG formatter=syslogFormat host=141.232.41.205 port=handlers.SYSLOG_UDP_PORT facility=LOG_LOCAL0 args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) [formatter_rootFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s [formatter_logFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s [formatter_syslogFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s and the python code ######################################################################## # Imports ######################################################################## import logging import logging.config import os import re from threading import Thread ######################################################################## # Constants ######################################################################## CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' ######################################################################## # Classes ######################################################################## ######## # PingIt ######## class PingIt(Thread): def __init__(self, mcuIP): Thread.__init__(self) self.ip = mcuIP self.status = -1 def run(self): pinging = os.popen("ping -n 2 " + self.ip, 'r') while 1: line = pinging.readline() if not line: break gotResponse = re.findall(PingIt.lifeline, line) if gotResponse: self.status = int(gotResponse[0]) ######################################################################## # Main Routine ######################################################################## # # Get the logger configuration information # logging.config.fileConfig(CONFIG_FILENAME) # # Check if running from command line and create logger # if os.environ.get('PROMPT'): # # create logger for output to stdout # logger = logging.getLogger('root') else: # # create logger for output to logfile # logger = logging.getLogger('log') # # Create logger for syslog output # syslog = logging.getLogger('syslog') # # Declare variables # PingIt.lifeline = re.compile(r"Received = (\d)") mcu_dict = {} ping_list = [] status = ("Not responding", "Responded to only 1 ping of 2", "Alive") # # Open the MCU file # mcu_file = open(MCU_LIST_FILENAME, 'r') # # Loop through the contents of the MCU file and ping the IPs # for mcu in mcu_file: # # mcu file contents example # 192.168.97.227 MCU_HMSTD # # mcu_info[0] = MCU IP Address # mcu_info[1] = MCU Name # mcu_info = mcu.split() mcu_dict[mcu_info[0]] = mcu_info[1] current = PingIt(mcu_info[0]) logger.info("Pinging " + mcu_info[1]) ping_list.append(current) current.start() # # Loop through ping list and print the response # for pinged in ping_list: pinged.join() logger.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) This is the output from the code 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not responding address = ('141.232.41.205', 514) Traceback (most recent call last): File "C:\Python31\lib\logging\handlers.py", line 786, in emit self.socket.sendto(msg, self.address) TypeError: sendto() takes exactly 3 arguments (2 given) 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not responding This is the handlers.py code from the library. I added the print statement to figure out why it is asking for three args but only getting two. Line 777 of handlers.py try: if self.unixsocket: try: self.socket.send(msg) except socket.error: self._connect_unixsocket(self.address) self.socket.send(msg) else: print('msg = ', msg, '\naddress = ', self.address) self.socket.sendto(msg, self.address) except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) line 790 of handlers.py This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea about why this happening I would appreciate knowing what the issue is. Thanks, Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jul 8 11:04:05 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Jul 2010 08:04:05 -0700 Subject: Python 2.7 released References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, imageguy wrote: > >Sorry to be daft here, but what do you mean by a "hardlink" ? >A windows "Shortcut" ? Just to be clear, a hardlink on NTFS functions almost exactly the same as a hardlink on a Unix filesystem -- it's a pointer to the same underlying file. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From invalid at invalid.invalid Thu Jul 8 11:07:31 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 15:07:31 +0000 (UTC) Subject: Python 2.7 released References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: On 2010-07-08, Aahz wrote: > In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, > imageguy wrote: >> >>Sorry to be daft here, but what do you mean by a "hardlink" ? >>A windows "Shortcut" ? > > Just to be clear, a hardlink on NTFS functions almost exactly the same as > a hardlink on a Unix filesystem -- it's a pointer to the same underlying > file. A windows shortcut is more like a Unix symlink (symbolic link), where the real destination path is a string contained in the link/shortcut file. That destination path is then evaluated and "dereferenced" when the link/shortcut is accessed. -- Grant Edwards grant.b.edwards Yow! Of course, you at UNDERSTAND about the PLAIDS gmail.com in the SPIN CYCLE -- From fetchinson at googlemail.com Thu Jul 8 11:11:59 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 8 Jul 2010 17:11:59 +0200 Subject: Python script to install python In-Reply-To: References: Message-ID: > I would like to have a python script that would download the most > recent svn of python, configure, make, install and cleanup after > itself. I am not replacing the python version I would be using to run > the script. > I was struggling to get this to work and I assume someone else has > done it better. Any pointers? Assuming you are on linux I recommend not using a python script for this but rather a shell script. From a python script you would most of the time be calling shell commands anyway. In a shell script you would do something like this: ################################ #!/bin/bash svn checkout ........................ cd whatever ./configure --whatever-options-you-like make # you probably want to run this as root make install # you probably don't want to be root anymore cd .. rm -rf whatever ################################ If you are on windows I assume a similar strategy is best. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From me+list/python at ixokai.io Thu Jul 8 11:15:53 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 08:15:53 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C35EBA9.2040703@ixokai.io> On 7/8/10 6:20 AM, Victor Subervi wrote: > However, I now have another error. Here is my current command: > > cursor.execute("insert into personalDataKeys (Store, User, > useFirstName, useLastName, usePhone, useCell, useFax, useAddress, > useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, > %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) Quick point: why the parens around [store, user] + col_vars? They're redundant. > > I get this error from MySQL which I am having a hard time understanding: > > LATEST FOREIGN KEY ERROR > ------------------------ > 100708 6:15:01 Transaction: > TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id > 1169992000 inserting, thread declared inside InnoDB 500 > mysql tables in use 1, locked 1 > 3 lock struct(s), heap size 368, undo log entries 1 > MySQL thread id 1502, query id 23700 localhost beno update > insert into personalDataKeys (Store, User, useFirstName, useLastName, > usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, > useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, > 1, 1, 1) > Foreign key constraint fails for table `test/personalDataKeys`: > , > CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES > `products` (`Store`) A foreign key is a constraint, a restriction, which says that rows in TableA ("personalDataKeys") depend on certain *matching* rows to already exist and always be valid in TableB ("products"); the exact match is a column they have in common ("Store"). The purpose of foreign keys is to keep data consistent. Here, it appears as if you have established a key such that the 'store' column in your personalDataKeys table must point to a certain row in the products table which has a 'store' column of the exact same value. This error message is indicating that when you do this INSERT, there is no corresponding row in the products table. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From see at sig.for.address Thu Jul 8 11:19:37 2010 From: see at sig.for.address (Victor Eijkhout) Date: Thu, 8 Jul 2010 10:19:37 -0500 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <1jlb3bc.faswymguv56oN%see@sig.for.address> Zooko O'Whielacronx wrote: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. Only if one has Power6 (or 7) which has hardware support for BCD. Otherwise you will have slow applications. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From me+list/python at ixokai.io Thu Jul 8 11:29:35 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 08:29:35 -0700 Subject: Python 2.7 released In-Reply-To: References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C35EEDF.2040607@ixokai.io> On 7/8/10 8:07 AM, Grant Edwards wrote: > On 2010-07-08, Aahz wrote: >> In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, >> imageguy wrote: >>> >>> Sorry to be daft here, but what do you mean by a "hardlink" ? >>> A windows "Shortcut" ? >> >> Just to be clear, a hardlink on NTFS functions almost exactly the same as >> a hardlink on a Unix filesystem -- it's a pointer to the same underlying >> file. > > A windows shortcut is more like a Unix symlink (symbolic link), where > the real destination path is a string contained in the link/shortcut > file. That destination path is then evaluated and "dereferenced" when > the link/shortcut is accessed. This is true, but a windows shortcut is more limited: its a feature of higher level code in the UI (I don't want to say just Explorer, as the standard dialogs deal with it too), and not the filesystem. So it only really works if there's a user specifically clicking through it -- or if you have code made to look for the .lnk files, parse them (they're really simple INI files) and deference it manually. At least, IIUC. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From mail at timgolden.me.uk Thu Jul 8 11:30:59 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 08 Jul 2010 16:30:59 +0100 Subject: Python 2.7 released In-Reply-To: References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C35EF33.9030703@timgolden.me.uk> On 08/07/2010 16:07, Grant Edwards wrote: > On 2010-07-08, Aahz wrote: >> In article<1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, >> imageguy wrote: >>> >>> Sorry to be daft here, but what do you mean by a "hardlink" ? >>> A windows "Shortcut" ? >> >> Just to be clear, a hardlink on NTFS functions almost exactly the same as >> a hardlink on a Unix filesystem -- it's a pointer to the same underlying >> file. > > A windows shortcut is more like a Unix symlink (symbolic link), where > the real destination path is a string contained in the link/shortcut > file. That destination path is then evaluated and "dereferenced" when > the link/shortcut is accessed. Goodness knows I'm probably teaching my grandmother etc. etc. but I would clarify that a Windows shortcut is a *shell* concept: from the NTFS point of view, it's just a something.lnk with some opaque contents. A (>= Vista) NTFS smbolic link is documented as designed "to function just like Unix links". TJG From dickinsm at gmail.com Thu Jul 8 11:36:24 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 08:36:24 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> Message-ID: <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> On Jul 8, 3:29?pm, Adam Skutt wrote: > On Jul 8, 9:22?am, Mark Dickinson wrote: > > On Jul 8, 2:00?pm, Adam Skutt wrote: > > >?For some computations, the number of bits required to > > > get the desired precision can quickly overwhelm the finite limitations > > > of your machine (e.g., you run out of RAM first or the time to compute > > > the answer is simply unacceptable). > > > Perhaps in theory. ?In practice, though, it's very rare to need to > > increase precision more than once or twice beyond an initial first > > guesstimate, and the amount of extra precision needed is small. ?That > > increase is unlikely to cause problems unless you were operating right > > up against your machine's limits in the first place. > > I suspect your platitude isn't especially comforting for those who > need more computing capability than we can currently construct. > However, I wouldn't call the amount of extra needed precision "small" I think that's because we're talking at cross-purposes. To clarify, suppose you want to compute some value (pi; log(2); AGM(1, sqrt(2)); whatever...) to 1000 significant decimal places. Then typically the algorithm (sometimes known as Ziv's onion-peeling method) looks like: (1) Compute an initial approximation to 1002 digits (say), with known absolute error (given by a suitable error analysis); for the sake of argument, let's say that you use enough intermediate precision to guarantee an absolute error of < 0.6 ulps. (2) Check to see whether that approximation unambiguously gives you the correctly-rounded 1000 digits that you need. (3) If not, increase the target precision (say by 3 digits) and try again. It's the precision increase in (3) that I was calling small, and similarly it's step (3) that isn't usually needed more than once or twice. (In general, for most functions and input values; I dare say there are exceptions.) Step (1) will often involve using significantly more than the target precision for intermediate computations, depending very much on what you happen to be trying to compute. IIUC, it's the extra precision in step (1) that you don't want to call 'small', and I agree. IOW, I'm saying that the extra precision required *due to the table- maker's dilemma* generally isn't a concern. I actually agree with much of what you've said. It was just the "impossible" claim that went over the top (IMO). The MPFR library amply demonstrates that computing many transcendental functions to arbitrary precision, with correctly rounded results, is indeed possible. -- Mark From giacomo.boffi at polimi.it Thu Jul 8 11:52:13 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Thu, 08 Jul 2010 17:52:13 +0200 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <86vd8qq8cy.fsf@aiuole.stru.polimi.it> "Zooko O'Whielacronx" writes: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. would you kindly lend me your Decimals ruler? i need to measure the sides of the triangle whose area i have to compute From vincent at vincentdavis.net Thu Jul 8 11:54:10 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 8 Jul 2010 09:54:10 -0600 Subject: Python script to install python In-Reply-To: References: Message-ID: On Thu, Jul 8, 2010 at 9:11 AM, Daniel Fetchinson wrote: >> I would like to have a python script that would download the most >> recent svn of python, configure, make, install and cleanup after >> itself. I am not replacing the python version I would be using to run >> the script. >> I was struggling to get this to work and I assume someone else has >> done it better. ?Any pointers? > > Assuming you are on linux I recommend not using a python script for > this but rather a shell script. From a python script you would most of > the time be calling shell commands anyway. In a shell script you would > do something like this: > > ################################ > #!/bin/bash > > svn checkout ........................ > cd whatever > ./configure --whatever-options-you-like > make > # you probably want to run this as root > make install > # you probably don't want to be root anymore > cd .. > rm -rf whatever > > ################################ Ok I'll take your advice and just use a shell script. I am on osx by the way. Thanks Vincent > > If you are on windows I assume a similar strategy is best. > > Cheers, > Daniel > > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Thu Jul 8 12:03:21 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 11:33:21 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C35EBA9.2040703@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> Message-ID: On Thu, Jul 8, 2010 at 10:45 AM, Stephen Hansen wrote: > On 7/8/10 6:20 AM, Victor Subervi wrote: > > However, I now have another error. Here is my current command: > > > > cursor.execute("insert into personalDataKeys (Store, User, > > useFirstName, useLastName, usePhone, useCell, useFax, useAddress, > > useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, > > %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) > > Quick point: why the parens around [store, user] + col_vars? They're > redundant. > > > > > I get this error from MySQL which I am having a hard time understanding: > > > > LATEST FOREIGN KEY ERROR > > ------------------------ > > 100708 6:15:01 Transaction: > > TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id > > 1169992000 inserting, thread declared inside InnoDB 500 > > mysql tables in use 1, locked 1 > > 3 lock struct(s), heap size 368, undo log entries 1 > > MySQL thread id 1502, query id 23700 localhost beno update > > insert into personalDataKeys (Store, User, useFirstName, useLastName, > > usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, > > useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, > > 1, 1, 1) > > Foreign key constraint fails for table `test/personalDataKeys`: > > , > > CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES > > `products` (`Store`) > > A foreign key is a constraint, a restriction, which says that rows in > TableA ("personalDataKeys") depend on certain *matching* rows to already > exist and always be valid in TableB ("products"); the exact match is a > column they have in common ("Store"). > > The purpose of foreign keys is to keep data consistent. Here, it appears > as if you have established a key such that the 'store' column in your > personalDataKeys table must point to a certain row in the products table > which has a 'store' column of the exact same value. > > This error message is indicating that when you do this INSERT, there is > no corresponding row in the products table. > mysql> describe products Store; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> describe personalDataKeys Store; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec) They both use innodb. They're both indexed. I was thinking after getting your email that maybe I'd set the varchars to different lengths, but no. However... mysql> select * from products; Empty set (0.00 sec) Is it that I can't insert into personalDataKeys until I've first done so in products? After rethinking this, it occurred to me that I probably made a mistake in copying my create table command from personalData to personalDataKeys, both of which had the foreign key of Store referenced to table products. That wasn't necessary, since personalDataKeys only needs to be associated with personalData, so I dropped and recreated the table, updating personalDataKeys foreign key to reference personalData; however, once again: mysql> select * from personalData; Empty set (0.00 sec) Here's the deal: mysql> describe personalData; +-------------------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+------------------+------+-----+------------+----------------+ | ID | int(10) unsigned | NO | PRI | NULL | auto_increment | | Store | varchar(40) | NO | MUL | NULL | | | User | varchar(50) | NO | MUL | NULL | | | FirstName | varchar(100) | NO | | NULL | | | LastName | varchar(100) | NO | | NULL | | | Phone | varchar(13) | YES | | NULL | | | Cell | varchar(13) | YES | | NULL | | | Fax | varchar(13) | YES | | NULL | | | AddressID | int(11) | NO | MUL | NULL | | | ShippingAddressID | int(11) | NO | MUL | NULL | | | DOB | date | YES | | 2000-01-01 | | | Email | varchar(100) | NO | | NULL | | | PW | varchar(12) | NO | | NULL | | +-------------------+------------------+------+-----+------------+----------------+ 13 rows in set (0.00 sec) mysql> describe personalDataKeys; +--------------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | | User | varchar(50) | NO | MUL | NULL | | | useFirstName | tinyint(1) | NO | | NULL | | | useLastName | tinyint(1) | NO | | NULL | | | usePhone | tinyint(1) | NO | | NULL | | | useCell | tinyint(1) | NO | | NULL | | | useFax | tinyint(1) | NO | | NULL | | | useAddress | tinyint(1) | NO | | NULL | | | useShippingAddress | tinyint(1) | NO | | NULL | | | useDOB | tinyint(1) | NO | | NULL | | | useEmail | tinyint(1) | NO | | NULL | | | usePW | tinyint(1) | NO | | NULL | | +--------------------+-------------+------+-----+---------+-------+ 12 rows in set (0.00 sec) In personalDataKeys I store which fields will be required for a given store as it relates to personal data. For example, if there is a pharmacy with users 'doctors' and 'patients', certain fields in personalData will be required for one but not the other, and this needs to be inserted into personalDataKeys. All of this, however, obviously happens before any data is actually entered into either personalData or products. It now seems to me that I have mistakenly put the constraint on the wrong table; that it should be on personalData and not personalDataKeys, but before I do that I would like confirmation that this looks correct. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 8 12:31:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jul 2010 09:31:32 -0700 Subject: Python -- floating point arithmetic In-Reply-To: <86vd8qq8cy.fsf@aiuole.stru.polimi.it> References: <4C346DA0.1070708@tu-clausthal.de> <86vd8qq8cy.fsf@aiuole.stru.polimi.it> Message-ID: On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi wrote: > "Zooko O'Whielacronx" writes: >> I'm starting to think that one should use Decimals by default and >> reserve floats for special cases. > > would you kindly lend me your Decimals ruler? i need to measure the > sides of the triangle whose area i have to compute If your ruler doesn't have a [second] set of marks for centimeters and millimeters, that's really one cheap/cruddy ruler you're using. Cheers, Chris -- Metrication! http://blog.rebertia.com From nagle at animats.com Thu Jul 8 12:35:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 09:35:49 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4c35fe68$0$1666$742ec2ed@news.sonic.net> On 7/7/2010 11:52 AM, Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) Bad approach. Don't put actual data into an SQL statement using string parameter substitution. Try this: values = (store, user) + tuple(col_vals) # all values to be inserted valuesql = ",".join(["%s"]*len(values)) # '%s,%s,%s,%s,%s,%s' sql = "INSERT INTO personaldatakeys VALUES (" + valuesql + ")" cursor.execute(sql, values) # execute INSERT "valuefields" is always some number of repeats of comma-separated "%s" Anything in "values" will be escaped properly. No SQL injection vulnerability. John Nagle From zooko at zooko.com Thu Jul 8 12:38:24 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Thu, 8 Jul 2010 10:38:24 -0600 Subject: Python -- floating point arithmetic In-Reply-To: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Thu, Jul 8, 2010 at 4:58 AM, Adam Skutt wrote: > > I can't think of any program I've ever written where the inputs are > actually intended to be decimal. ?Consider a simple video editing > program, and the user specifies a frame rate 23.976 fps. ?Is that what > they really wanted? ?No, they wanted 24000/1001 but didn't feel like > typing that. Okay, so there was a lossy conversion from the user's intention (24000/1001) to what they typed in (23.976). >>> instr = '23.976' Now as a programmer you have two choices: 1. accept what they typed in and losslessly store it in a decimal: >>> from decimal import Decimal as D >>> x = D(instr) >>> print x 23.976 2. accept what they typed in and lossily convert it to a float: >>> x = float(instr) >>> print "%.60f" % (x,) 23.975999999999999090505298227071762084960937500000000000000000 option 2 introduces further "error" between what you have stored in your program and what the user originally wanted and offers no advantages except for speed, right? >> I'm sorry, what will never be true? Are you saying that decimals have >> a disadvantage compared to floats? If so, what is their disadvantage? > > He's saying that once you get past elementary operations, you quickly > run into irrational numbers, which you will not be representing > accurately. ?Moreover, in general, it's impossible to even round > operations involving transcendental functions to an arbitrary fixed- > precision, you may need effectively infinite precision in order to the > computation. ?In practice, this means the error induced by a lossy > input conversion (assuming you hadn't already lost information) is > entirely negligible compared to inherent inability to do the necessary > calculations. But this is not a disadvantage of decimal compared to float is it? These problems affect both representations. Although perhaps they affect them differently, I'm not sure. I think sometimes people conflate the fact that decimals can easily have higher and more variable precision than floats with the fact that decimals are capable of losslessly storing decimal values but floats aren't. Regards, Zooko From nagle at animats.com Thu Jul 8 12:42:40 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 09:42:40 -0700 Subject: How is Unladen Swallow coming along? Message-ID: <4c360004$0$1607$742ec2ed@news.sonic.net> How is Unladen Swallow coming along? Looking at the site, code is being checked in and issues are being reported, but the last quarterly release was 2009 Q3. They missed their January 2010 release date for "2009 Q4", so they're now about 6 months behind their project plan. ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") John Nagle From me+list/python at ixokai.io Thu Jul 8 12:50:08 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 09:50:08 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> Message-ID: <4C3601C0.6090501@ixokai.io> On 7/8/10 9:03 AM, Victor Subervi wrote: > mysql> describe products Store; > +-------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +-------+-------------+------+-----+---------+-------+ > | Store | varchar(40) | NO | MUL | NULL | | > +-------+-------------+------+-----+---------+-------+ > 1 row in set (0.00 sec) > > mysql> describe personalDataKeys Store; > +-------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +-------+-------------+------+-----+---------+-------+ > | Store | varchar(40) | NO | MUL | NULL | | > +-------+-------------+------+-----+---------+-------+ > 1 row in set (0.00 sec) > > They both use innodb. They're both indexed. I was thinking after getting > your email that maybe I'd set the varchars to different lengths, but no. A foreign key isn't about the schema, per se; its not about the varchar's being different lengths (as they discard trailing padding)-- its about *data*. True, if you had varchar(20) and varchar(40), then if any string longer then 20 wouldn't ever pass -- but that's really secondary. (That's not saying a database may refuse to accept a FK if data types are mismatched) If "personalDataKeys" has a foreign key connecting it to "products", then you can't add something to personalDataKeys with store = "specialty" unless something already exists in "products" with store = "speciality"; > However... > > mysql> select * from products; > Empty set (0.00 sec) > > Is it that I can't insert into personalDataKeys until I've first done so > in products? Yes, that's precisely what foreign keys do. > That wasn't necessary, since personalDataKeys only > needs to be associated with personalData, so I dropped and recreated the > table, updating personalDataKeys foreign key to reference personalData; > however, once again: Are you certain this is what you want? It sounds like you may be using foreign keys without fully understanding what they are. Think of them like a big arrow. If you define a foreign key in personalDataKeys, referencing personalData, you should picture a large arrow pointing from personalDataKeys to personalData. It's pointing because the "constraint" created by the foreign key means, "Every record in this table, personalDataKeys, has a column which *must* exist in its referenced table, personalData, before that record is allowed to be added." A foreign key isn't just a description of a relationship: its a strict rule, declaring that a certain field in one table *actually* refers directly to a *specific* row in *another* table: therefore, this field can't be allowed to be any value which doesn't exist already in that other table. A "primary key" lets you uniquely identify a certain row in one table. A "foreign key" lets you identify a certain row in *another table*, that this table ultimately depends on. > In personalDataKeys I store which fields will be required for a given > store as it relates to personal data. For example, if there is a > pharmacy with users 'doctors' and 'patients', certain fields in > personalData will be required for one but not the other, and this needs > to be inserted into personalDataKeys. My concern here is that you're making *columns* which are "store-dependent", such as sometimes in one store, personalData will have a column/field named "foo", but another store it won't use "foo" but instead use "bar", depending on how the store itself is configured. I'd refer you back to my previous email which described two schemes to record "store-dependant" data: one using a separate table for each store type, another using a generic key/value table. Having one big table with a big mix of columns that various store configurations pick and choose seems like a very inflexible design. Additionally (if you do keep this design), these two tables you described seem to make the columns that are used tied to *users*, not *stores*. The key for personalDataKeys is (Store, User): but isn't it the case that for a certain kind of store (i.e., a pharmacy), /all/ users in that store will have the same fields in personalData be relevant? So shouldn't "personalDataKeys" really be "storeDataKeys"? I.e., a configuration of the store itself of what data keys it considers relevant. > All of this, however, obviously > happens before any data is actually entered into either personalData or > products. Yeah, the constraints and such happen before data is entered. But once they are created, you have to actual enter data in the correct order. The constraints enforce consistency so programmer-error can't introduce data into the tables which is out of whack with the data layout. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Thu Jul 8 12:51:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 08 Jul 2010 18:51:15 +0200 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> Message-ID: <4C360203.8060309@jollans.com> On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I?ve seen other threads on this issue, but the resolution still doesn?t > seem to exist for me. > > > > I?m running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they?re not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas From me+list/python at ixokai.io Thu Jul 8 13:00:43 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 10:00:43 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C36043B.1070303@ixokai.io> On 7/7/10 11:52 AM, Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) > > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); I suddenly feel a need to come back and explain *why* I make the claim to 'best' above: the explicit naming of the fields in the INSERT, specifically, since others have shown how to do the INSERT safely while keeping the essentially variable number of items in the values clause. I still would advise against that approach even if it is safe from a SQL Injection standpoint: but for a different reason entirely, that of long-term maintainability. No design is perfect; no customer specification (no matter how vetted, analyzed, and approved by stakeholders) survives implementation and real-life usage. If you always select specific columns in a specific order (i.e., always SELECT this, that, other; and never SELECT *), and always insert with your columns specified (i.e., always INSERT INTO blah (this, that, other) and never INSERT INTO blah VALUES (..)), then it lets you adapt your application in the future when something comes up. Specifically, it lets you add new columns without breaking everything :) Now, those new columns would need to either allow NULL's or have a default value of course. But some day down the road you can go and do an ALTER TABLE to add say, "my_whatever" to the above, and you don't suddenly have to vet every single piece of code which accesses that table. All the existing code will still work: its getting the pieces of data it knows how to use. As you need to, you can adjust that code to take into account this new piece of data. But by making any new additions "optional" in your SQL, and making all your other accesses explicit, it just eases migration and maintenance in future updates. Some may disagree, I dunno. I just find in my experience that following that practice has saved a lot of time and effort down the road. (Especially during migrations from old versions to new versions, and running versions concurrently during some test-phase, etc, or rolling back a new version if a critical bug is found: the changes made to the database to support the new versions can safely persist without you having to do a much more expensive / time-consuming restoration of the database from a backup). -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From no.email at nospam.invalid Thu Jul 8 13:03:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 08 Jul 2010 10:03:30 -0700 Subject: Debugging a segmentation fault References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: <7x7hl5kisd.fsf@ruckus.brouhaha.com> "DierkErdmann at mail.com" writes: > my python project crashes in a non reproducible way. With gdb I got > the backtraces given below. > How can I possibly figure out the reason for the segfaults that occur > under Linux and Windows, using Python 2.6 in both cases. It's a big C program and you have to debug it as one. Well, first of all try upgrading to the newest versions and see if there is already a fix. Be especially suspicious of any C extension modules you're using. There are also some compile time options that let you rebuild Python with extra consistency checks for reference counts. Turn those on and see what happens. From askutt at gmail.com Thu Jul 8 13:04:38 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 10:04:38 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: On Jul 8, 11:36?am, Mark Dickinson wrote: > I think that's because we're talking at cross-purposes. > > To clarify, suppose you want to compute some value (pi; ?log(2); > AGM(1, sqrt(2)); whatever...) to 1000 significant decimal places. > Then typically the algorithm (sometimes known as Ziv's onion-peeling > method) looks like: > > (1) Compute an initial approximation to 1002 digits (say), with known > absolute error (given by a suitable error analysis); for the sake of > argument, let's say that you use enough intermediate precision to > guarantee an absolute error of < 0.6 ulps. > > (2) Check to see whether that approximation unambiguously gives you > the correctly-rounded 1000 digits that you need. > > (3) If not, increase the target precision (say by 3 digits) and try > again. > > It's the precision increase in (3) that I was calling small, and > similarly it's step (3) that isn't usually needed more than once or > twice. ?(In general, for most functions and input values; ?I dare say > there are exceptions.) > > Step (1) will often involve using significantly more than the target > precision for intermediate computations, depending very much on what > you happen to be trying to compute. ?IIUC, it's the extra precision in > step (1) that you don't want to call 'small', and I agree. > > IOW, I'm saying that the extra precision required *due to the table- > maker's dilemma* generally isn't a concern. Yes, though I think attributing only the precision added in step 3 to the table-maker's dilemma isn't entirely correct. While it'd be certainly less of a dilemma if we could precompute the necessary precision, it doesn't' help us if the precision is generally unbounded. As such, I think it's really two dilemmas for the price of one. > > I actually agree with much of what you've said. ?It was just the > "impossible" claim that went over the top (IMO). ?The MPFR library > amply demonstrates that computing many transcendental functions to > arbitrary precision, with correctly rounded results, is indeed > possible. That's because you're latching onto that word instead of the whole sentence in context and making a much bigger deal out of than is appropriate. The fact that I may not be able to complete a given calculation for an arbitrary precision is not something that can be ignored. It's the same notional problem with arbitrary-precision integers: is it better to run out of memory or overflow the calculation? The answer, of course, is a trick question. Adam From dickinsm at gmail.com Thu Jul 8 13:07:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 10:07:23 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> On Jul 8, 2:59?pm, Stefan Krah wrote: > pow() is trickier. Exact results have to be weeded out before > attempting the correction loop for correct rounding, and this is > complicated. > > For example, in decimal this expression takes a long time (in cdecimal > the power function is not correctly rounded): > > Decimal('100.0') ** Decimal('-557.71e-742888888') Hmm. So it does. Luckily, this particular problem is easy to deal with. Though I dare say that you have more up your sleeve. :)? -- Mark From askutt at gmail.com Thu Jul 8 13:22:29 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 10:22:29 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Jul 8, 12:38?pm, "Zooko O'Whielacronx" wrote: > On Thu, Jul 8, 2010 at 4:58 AM, Adam Skutt wrote: > > > I can't think of any program I've ever written where the inputs are > > actually intended to be decimal. ?Consider a simple video editing > > program, and the user specifies a frame rate 23.976 fps. ?Is that what > > they really wanted? ?No, they wanted 24000/1001 but didn't feel like > > typing that. > > Okay, so there was a lossy conversion from the user's intention > (24000/1001) to what they typed in (23.976). > > >>> instr = '23.976' > > Now as a programmer you have two choices: > > 1. accept what they typed in and losslessly store it in a decimal: > > >>> from decimal import Decimal as D > >>> x = D(instr) > >>> print x > > 23.976 > > 2. accept what they typed in and lossily convert it to a float: > > >>> x = float(instr) > >>> print "%.60f" % (x,) > > 23.975999999999999090505298227071762084960937500000000000000000 > > option 2 introduces further "error" between what you have stored in > your program and what the user originally wanted and offers no > advantages except for speed, right? No, you have a third choice, and it's the only right choice: 3. Convert the input to user's desired behavior and behave accordingly. Anything else, here, will result in A/V sync issues. Which is really my point, just because we write '23.976' on the command-line doesn't necessarily mean that's what we meant. Humans are pretty lazy, and we write rational numbers as incomplete decimals all of the time. > But this is not a disadvantage of decimal compared to float is it? > These problems affect both representations. Although perhaps they > affect them differently, I'm not sure. > > I think sometimes people conflate the fact that decimals can easily > have higher and more variable precision than floats with the fact that > decimals are capable of losslessly storing decimal values but floats > aren't. > No, it's not a specific disadvantage of decimal compared to float. I'm not sure why David C. choose to phrase it in those specific terms, though I'm not sure it matters all that much. What I believe is one must understand that the underlying issues are fundamental, and the only way to solve the issues is to educate programmers so they can write code that behaves correctly in the face of rounding. And I do believe you're correct that programmers frequently see one desirable behavior of decimal FP over binary FP and therefore assume all the badness must have gone away. Adam From invalid at invalid.invalid Thu Jul 8 13:24:19 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 17:24:19 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-08, Grant Edwards wrote: > On 2010-07-07, Grant Edwards wrote: > >> Oops. Those Python bindings are for version 1.3.2 of libconfig (which >> does work). They don't work with the current version of libconfig. > Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pylibconfig > >>> conf = pylibconfig.Config() > *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** > > Am I correct in concluding it has to be a memory corruption problem in > the library itself? Nope. That problem was cause by having two versions of the library installed -- one under /usr and the other under /usr/local. -- Grant Edwards grant.b.edwards Yow! Gee, I feel kind of at LIGHT in the head now, gmail.com knowing I can't make my satellite dish PAYMENTS! From sridharr at activestate.com Thu Jul 8 13:28:43 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 8 Jul 2010 10:28:43 -0700 Subject: ANN: ActivePython 2.6.5.14 is now available Message-ID: <4B67B387-6AFE-4A5E-9F0D-0E9E070D4FC7@activestate.com> We are pleased to announce the availability of ActivePython 2.6.5.14. http://www.activestate.com/activepython This is a minor release with several bug fixes. As usual, it includes an updated Python Package Manager (PyPM) with updates to essential packages such as Distribute (a compatible fork of setuptools), virtualenv, pip and SQLAlchemy. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6 and 2.7 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business, Enterprise or OEM edition only) - Solaris/x86 (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (Enterprise or OEM edition only) - AIX/PowerPC (Business, Enterprise or OEM edition only) - AIX/PowerPC 64-bit (Business, Enterprise or OEM edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From lists at cheimes.de Thu Jul 8 13:32:15 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jul 2010 19:32:15 +0200 Subject: Debugging a segmentation fault In-Reply-To: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: > my python project crashes in a non reproducible way. With gdb I got > the backtraces given below. > How can I possibly figure out the reason for the segfaults that occur > under Linux and Windows, using Python 2.6 in both cases. One of your third party C extension has a reference count bug. It looks like it has an Py_INCREF() to little or a Py_DECREF() too much. The first segfaults occurs in a decref macro: Objects/dictobject.c:911 Py_XDECREF(ep->me_value); , the second is a bit more obscure and hidden in the cyclic GC. The error is either introduced by the same reference counting bug or in error in the type definition and initialization. Which third party products with C extensions do you use? Have you updated your database adapter and NumPy yet? Christian From jnoller at gmail.com Thu Jul 8 13:47:27 2010 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 8 Jul 2010 13:47:27 -0400 Subject: Call for Applications - PSF Sponsored Sprints Message-ID: The PSF is happy to open our first call for applications for sprint funding! Have you ever had a group of people together to hack towards a common goal? You've hosted a sprint! Have you ever wanted to get a group of like minded Pythonistas together to hack for a day? You're going to want to hold a sprint! Whether you call them Sprints, Hackfests, Hack-a-thons, or any other name, they're a great way to hang out with like-minded developers and work on common code. Sprints are an unbeatable way to build friendships and contacts that will last for years to come, and they're a great way to learn about something new if you're just starting out. The Python Software Foundation has set aside funds to be distributed to world-wide sprint efforts. We're anticipating 2-3 events per month focused on covering topics to help the entire community: - Python Core bug triage and patch submission (on-boarding new contributors) - Python Core documentation (including process documentation) improvements - Porting libraries/applications to Python 3 - Python website/wiki content improvements - PyPI packaging hosting site improvements - Contribution to other "core" projects, such as packaging related issues. If you are interested in holding a sprint on any of the topics above and you're looking for some money to help out with sprint costs, we can help (up to a max of $250 USD). Prepare an application including the following information: - Date and Location: Where will the event be? What day and time? - Organizers: Who are the event organizers and sprint coach? Is the sprint being run by a Python user group? - Attendees: How many participants do you expect? - Goal: What is the focus and goal of the sprint? - Budget: How much funding you are requesting, and what will you use it for? - Applications should be sent to: sprints at python.org with the subject "Sprint Funding Application - " We encourage anyone - even those who have never held, or been to a sprint - to consider holding one. We will help you as much as we can with welcome packets, advertising, and hooking you up with required resources - anything to make it possible. As part of being approved, the you will need to agree to deliver a report (hopefully, with pictures!) of the sprint to the Sprint Committee, so we can post it on the sprint blog and site: http://www.pythonsprints.com If you have any questions or need more information, contact us by email at sprints at python.org. More information is up on our blog: http://pythonsprints.com/2010/07/8/call-applications-now-open/ From victorsubervi at gmail.com Thu Jul 8 13:48:13 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 13:18:13 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C3601C0.6090501@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> <4C3601C0.6090501@ixokai.io> Message-ID: I've come to the realization that I don't need FKs at all here. Essentially, what I need to do is consult personalDataKeys simply to determine what data should be loaded into and retrieved from personalData. I was mistaken because the data are not interdependent, it only appeared that way superficially. No, the data aren't loaded into one big table. There are about 10 fields each in these tables. Yes, I should rename it to storeUserDataKeys. Thanks again, Stephen. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From xcr4cx at googlemail.com Thu Jul 8 13:56:29 2010 From: xcr4cx at googlemail.com (christian schulze) Date: Thu, 8 Jul 2010 10:56:29 -0700 (PDT) Subject: pySimpleSessions - PHP sessions implemented in Python Message-ID: Hey, since there is no standalone sessions module for python (at least a properly working one), I created one and thought i'd share it with you. This is the project: http://code.google.com/p/pysimplesessions/ This is the introduction: http://code.google.com/p/pysimplesessions/wiki/Introduction And finally the module source: http://code.google.com/p/pysimplesessions/source/browse/trunk/sessions.py If you need, there are some examples (partly working *g*): http://code.google.com/p/pysimplesessions/source/browse/trunk/#trunk/examples It would be great if I could get some feedback from you. ;) cheers, From stefan-usenet at bytereef.org Thu Jul 8 14:00:14 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 20:00:14 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: <20100708180014.GA32099@yoda.bytereef.org> Adam Skutt wrote: > > > I actually agree with much of what you've said. ?It was just the > > "impossible" claim that went over the top (IMO). ?The MPFR library > > amply demonstrates that computing many transcendental functions to > > arbitrary precision, with correctly rounded results, is indeed > > possible. > That's because you're latching onto that word instead of the whole > sentence in context and making a much bigger deal out of than is > appropriate. The fact that I may not be able to complete a given > calculation for an arbitrary precision is not something that can be > ignored. It's the same notional problem with arbitrary-precision > integers: is it better to run out of memory or overflow the > calculation? The answer, of course, is a trick question. In the paper describing his strategy for correct rounding Ziv gives an estimate for abnormal cases, which is very low. This whole argument is a misunderstanding. Mark and I argue that correct rounding is quite feasible in practice, you argue that you want guaranteed execution times and memory usage. This is clear now, but was not so apparent in the "impossible" paragraph that Mark responded to. I think asking for strictly bounded resource usage is reasonable. In cdecimal there is a switch to turn off correct rounding for exp() and log(). Stefan Krah From Bryan.Stopp at argushealth.com Thu Jul 8 14:01:33 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 13:01:33 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C360203.8060309@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C360203.8060309@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935B2@ARG-EXVS03.corp.argushealth.com> These are good points, but I've fixed the configure & config.guess on about 10 other OSS projects that I needed to compile on this machine. So I know that my changes are correct. The changes boil down to: There are a number of lines in the files that reference AIX versions for configuring details about the system. Specifically, it'll be "if" or "case" statements that look like: *-ibm-aix5*) *aix4*|*aix5*) I just add the aix6 clause: *-ibm-aix5* | *-ibm-aix6*) *aix4*|*aix5*|*aix6*) As Aix6 is binary compatible with 5, but the configure defaults it to an unknown AIX version and completely mis-configures the compiler. As for using the autoconf tool for my system, I'm not really sure if it's even installed or if the latest autoconf supports this version. Oddly enough I'm not the sys admin, but I do play one on TV. I do want to stick with Python 2.6 if I can, but I will give compiling 2.7 a shot to see what, if anything, changes/is fixed. Thanks for the feedback! -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Thursday, July 08, 2010 11:51 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I've seen other threads on this issue, but the resolution still doesn't > seem to exist for me. > > > > I'm running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they're not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From stefan-usenet at bytereef.org Thu Jul 8 14:11:34 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 20:11:34 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> Message-ID: <20100708181134.GA32553@yoda.bytereef.org> Mark Dickinson wrote: > On Jul 8, 2:59?pm, Stefan Krah wrote: > > pow() is trickier. Exact results have to be weeded out before > > attempting the correction loop for correct rounding, and this is > > complicated. > > > > For example, in decimal this expression takes a long time (in cdecimal > > the power function is not correctly rounded): > > > > Decimal('100.0') ** Decimal('-557.71e-742888888') > > Hmm. So it does. Luckily, this particular problem is easy to deal > with. Though I dare say that you have more up your sleeve. :)? Not at the moment, but I'll keep trying. :) Stefan Krah From Bryan.Stopp at argushealth.com Thu Jul 8 14:46:38 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 13:46:38 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C360203.8060309@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C360203.8060309@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935B5@ARG-EXVS03.corp.argushealth.com> I just wanted to follow up my previous email: I tried compiling 2.7 (without editing any config.guess or configure files as they are up to date for AIX6) and it failed with the exact same errors. So I'm still stuck and not sure what I should to do get this to compile. Any other ideas out there? -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Thursday, July 08, 2010 11:51 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I've seen other threads on this issue, but the resolution still doesn't > seem to exist for me. > > > > I'm running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they're not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From luismgz at gmail.com Thu Jul 8 14:52:39 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 11:52:39 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c30f5e9$0$1586$742ec2ed@news.sonic.net> Message-ID: On Jul 4, 5:58?pm, John Nagle wrote: > ? ? TheUnladenSwallowpeople should in theory be able to reach > that level of performance. ?(Both groups are employed at Google. > So their effectiveness will be compared.) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle No. Collin Winter said that they will never be as fast as Chrome's V8 or similar JS engines, since they were created from scratch to be super fast above all else. On the other hand, US is a project to enhance an existing interpreter, carrying a lot of the burden of early design decisions. From zooko at zooko.com Thu Jul 8 15:15:08 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Thu, 8 Jul 2010 13:15:08 -0600 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Thu, Jul 8, 2010 at 11:22 AM, Adam Skutt wrote: > On Jul 8, 12:38?pm, "Zooko O'Whielacronx" wrote: >> Now as a programmer you have two choices: ? >> 1. accept what they typed in and losslessly store it in a decimal: ? >> 2. accept what they typed in and lossily convert it to a float: > No, you have a third choice, and it's the only right choice: > 3. Convert the input to user's desired behavior and behave > accordingly. ?Anything else, here, will result in A/V sync issues. Okay, please tell me about how this is done. I've never dealt with this sort of issue directly. As far as I can imagine, any way to implement option 3 will involve accepting the user's input and storing it in memory somehow and then computing on it. As far as I can tell, doing so with a decimal instead of a float will never be worse for your outcome and will often be better. But, please explain in more detail how this works. Thanks! Regards, Zooko From subterraneus at gmail.com Thu Jul 8 15:17:57 2010 From: subterraneus at gmail.com (Alex Karpinski) Date: Thu, 8 Jul 2010 15:17:57 -0400 Subject: Python Multi-Channel Audio Message-ID: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> I'm looking for some module or system of modules that can help me do a few things with audio 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) 2. Seek within the file 3. Control volume 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. (For the curious: This is part of the audio system for a larger immersive theater project, ) From luismgz at gmail.com Thu Jul 8 15:19:22 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 12:19:22 -0700 (PDT) Subject: How is Unladen Swallow coming along? References: <4c360004$0$1607$742ec2ed@news.sonic.net> Message-ID: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> On Jul 8, 1:42?pm, John Nagle wrote: > ? ? How is Unladen Swallow coming along? ?Looking at the site, code is > being checked in and issues are being reported, but the last quarterly > release was 2009 Q3. ?They missed their January 2010 release date > for "2009 Q4", so they're now about 6 months behind their project > plan. > > ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Don't be shy. Ask this question in Unladen Swallow's google group. They don't bite! Luis From askutt at gmail.com Thu Jul 8 15:33:09 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 12:33:09 -0700 (PDT) Subject: Python -- floating point arithmetic References: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: <6c6f0bc4-040c-4092-9adc-acbac99d45e2@r27g2000yqb.googlegroups.com> On Jul 8, 2:00?pm, Stefan Krah wrote: > > This whole argument is a misunderstanding. Mark and I argue that correct > rounding is quite feasible in practice, you argue that you want guaranteed > execution times and memory usage. This is clear now, but was not so apparent > in the "impossible" paragraph that Mark responded to. No, that's what I'm arguing for, though such a feature is important. I'm pointing out that the feasibility of correct rounding is entirely dependent on what you're doing. For IEEE-754 double, it's feasible for the elementary functions if you can tolerate intermediate calculations that are more than twice as large as your double in the corner cases. Certainly, for a single calculation, this is acceptable, but at how many calculations is it no longer acceptable? Adam From invalid at invalid.invalid Thu Jul 8 15:55:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 19:55:03 +0000 (UTC) Subject: Question about odd code in libconfig bindings Message-ID: I'm playign with Python bindings for libconfig, and one of the methods does something that seems very odd to me. The purpose of the method is to fetch the value found a a particular path within the configuration namespace. If the path exists and has a scalar value the method returns the tuple (,True). Otherwise it returns ('',False). AFAICT, the latter happens in either of two cases: the path doesn't exist at all, or the path exists but doesn't have a scalar value (it's an aggretate object such as a list, group, or array). This seems distinctly un-pythonic. I would think that the right thing to do would be to either return the requested value or raise an exception. The libconfig C++ API defines a "SettingNotFound" exception and "SettingTypeException" that seem appropriate in the two failure cases. Is there something about implementing bindings using Boost that makes this sort of (,) return tuple a desirable way to do things? FWIW, here's the method I find puzzling: tuple value ( const char * path ) { std::string v_string; if ( config->lookupValue ( path, v_string ) ) return make_tuple ( v_string.c_str(), true ); unsigned int v_uint; if ( config->lookupValue ( path, v_uint ) ) return make_tuple ( v_uint, true ); int v_int; if ( config->lookupValue ( path, v_int ) ) return make_tuple ( v_int, true ); bool v_bool; if ( config->lookupValue ( path, v_bool ) ) return make_tuple ( v_bool, true ); unsigned long long v_ulonglong; if ( config->lookupValue ( path, v_ulonglong ) ) return make_tuple ( v_ulonglong, true ); long long v_longlong; if ( config->lookupValue ( path, v_longlong ) ) return make_tuple ( v_longlong, true ); float v_float; if ( config->lookupValue ( path, v_float ) ) return make_tuple ( v_float, true ); double v_double; if ( config->lookupValue ( path, v_double ) ) return make_tuple ( v_double, true ); return make_tuple ( "", false ); } -- Grant Edwards grant.b.edwards Yow! Don't SANFORIZE me!! at gmail.com From sturlamolden at yahoo.no Thu Jul 8 16:10:30 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:10:30 -0700 (PDT) Subject: "is not" operator? Message-ID: What happens here? Does Python (2.6.5) have an "is not" operator? >>> a = 5 >>> print (a is not False) True >>> print (a is (not False)) False >>> print (not (a is False)) True It seems "y is not x" fits well with spoken English, but it is also a bit surprising that "y is not x" does not mean "y is (not x)" but "not (y is x)". Why does Python reorder is and not operators, and what are the formal rules for this behavior? From sturlamolden at yahoo.no Thu Jul 8 16:15:40 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:15:40 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: <04a74fe4-b731-4faf-8621-7c49f8c6a209@z10g2000yqb.googlegroups.com> On 4 Jul, 21:59, Stefan Behnel wrote: > > I have already said I don't care about unladen swallow. > > What I meant, was: which of these benchmarks would have to be better to > make you care? Because your decision not to care seems to be based on > exactly these benchmarks. Those are the only one I've seen. From jkrukoff at ltgc.com Thu Jul 8 16:29:13 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Thu, 08 Jul 2010 14:29:13 -0600 Subject: "is not" operator? In-Reply-To: References: Message-ID: <1278620953.7825.1.camel@localhost.localdomain> On Thu, 2010-07-08 at 13:10 -0700, sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? > > >>> a = 5 > >>> print (a is not False) > True > >>> print (a is (not False)) > False > >>> print (not (a is False)) > True > > It seems "y is not x" fits well with spoken English, but it is also a > bit surprising that "y is not x" does not mean "y is (not x)" but "not > (y is x)". Why does Python reorder is and not operators, and what are > the formal rules for this behavior? Don't forget about the similar "not in", as in: >>> 'a' not in 'abc' False This is probably the section of documentation you want: http://docs.python.org/reference/expressions.html#notin -- John Krukoff Land Title Guarantee Company From robert.kern at gmail.com Thu Jul 8 16:32:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Jul 2010 16:32:10 -0400 Subject: "is not" operator? In-Reply-To: References: Message-ID: On 7/8/10 4:10 PM, sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? Yes. From Grammar/Grammar: comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' '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 sturlamolden at yahoo.no Thu Jul 8 16:41:43 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:41:43 -0700 (PDT) Subject: "is not" operator? References: Message-ID: On 8 Jul, 22:32, Robert Kern wrote: > > What happens here? Does Python (2.6.5) have an "is not" operator? > > Yes. From Grammar/Grammar: > > comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' Thanks :) From nagle at animats.com Thu Jul 8 16:44:29 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 13:44:29 -0700 Subject: How is Unladen Swallow coming along? In-Reply-To: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> Message-ID: <4c3638b0$0$1660$742ec2ed@news.sonic.net> On 7/8/2010 12:19 PM, Luis M. Gonz?lez wrote: > On Jul 8, 1:42 pm, John Nagle wrote: >> How is Unladen Swallow coming along? Looking at the site, code is >> being checked in and issues are being reported, but the last quarterly >> release was 2009 Q3. They missed their January 2010 release date >> for "2009 Q4", so they're now about 6 months behind their project >> plan. >> >> ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") >> >> John Nagle > > Don't be shy. > Ask this question in Unladen Swallow's google group. They don't bite! Found this: "http://www.python.org/dev/peps/pep-3146/#performance-retrospective" It's starting to work, but the performance improvement is tiny, well under 2x faster than CPython. Only 1.08x on "html5lib". That's far less than they expected. They were going for 5x, which is far less than Shed Skin (which restricts Python) already achieves. John Nagle From sturlamolden at yahoo.no Thu Jul 8 16:44:35 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:44:35 -0700 (PDT) Subject: "is not" operator? References: mailman.442.1278621575.1673.python-list@python.org Message-ID: <28c0e59c-baaf-416a-9e24-9f55e4febc60@j4g2000yqh.googlegroups.com> On 8 Jul, 22:29, John Krukoff wrote: > Don't forget about the similar "not in", as in: I noticed that in the grammar Robert posted. It never occurred to me as being a special operator too, but it is. From wolfram.hinderer at googlemail.com Thu Jul 8 16:52:56 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Thu, 8 Jul 2010 13:52:56 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> Message-ID: <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> On 8 Jul., 15:10, Ethan Furman wrote: > Interesting. ?I knew when I posted my above comment that I was ignoring > such situations. ?I cannot comment on the code itself as I am unaware of > the algorithm, and haven't studied numbers extensively (although I do > find them very interesting). > > So while you've made your point, I believe mine still stands -- > comparing floats using == to absolute numbers is almost always a mistake. JFTR, it works because a+b == a+b (while I don't think that a+b == b+a holds for all a and b). In general, I totally agree with you. From tompelka at gmail.com Thu Jul 8 17:07:18 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Thu, 08 Jul 2010 23:07:18 +0200 Subject: object exported through manager from multiprocess module Message-ID: <4C363E06.6000103@gmail.com> Hi all, have troubles with exporting objects through managers from multiprocess module, see example: Worker.py: ################################### from multiprocessing import Process from multiprocessing.managers import BaseManager import pcapy from impacket.ImpactDecoder import EthDecoder __all__ = ['Worker'] class Worker(Process): ''' Class for sniffing packets, runnig as root ''' public = ['go', 'terminate'] def __init__(self): super(Worker, self).__init__() self.iface = '' self.expr = '' self.pcap = '' # define packet decoder self.decoder = EthDecoder() # key for queue daemon, remotely on localhost:5000 self._keyQ = '10b222970537b97919db36ec757370d2' class QueueManager(BaseManager): pass QueueManager.register('get_dataQueue') self._m = QueueManager(address=('127.0.0.1', 5000), authkey=self._keyQ) self._m.connect() self.dataQueue = self._m.get_dataQueue() def go(self, iface, expr): ''' start sniffer ''' print "Starting sniffer" self.iface = iface self.expr = expr super(Worker, self).start() def terminate(self): ''' terminate sniffer ''' super(Worker, self).terminate() def run(self): print "sniffing ..." print self.iface print self.expr self.pcap = pcapy.open_live(self.iface, 1500, 1, 0) self.pcap.setfilter(self.expr) self.pcap.loop(0, self.__packetHandler) print "... done" def __packetHandler(self, hdr, data): ''' handles packets and put them in to the queue ''' print "Handling packets" #print data print "Queue size: %i" % self.dataQueue.qsize() print self.decoder.decode(data) self.dataQueue.put(data) Export object (Worker): ################################### from Worker import Worker class SniffManager(BaseManager): pass SniffManager.register('Worker', callable=Worker) Sm = SniffManager(address=('127.0.0.1', 5001), authkey='f1f16683f3e0208131b46d37a79c8921') Ss = Sm.get_server() Ss.serve_forever() Call object methods remotely: ################################### # get remote object class WorkerManager(BaseManager): pass WorkerManager.register('Worker') w = WorkerManager(address=('127.0.0.1', 5001), authkey='f1f16683f3e0208131b46d37a79c8921') w.connect() worker = w.Worker() worker.go(iface="ethx", expr="whatever") # WORKS FINE but worker.terminate() File "/home/tom/web2py/applications/init/controllers/sniffer.py", line 143, in index worker.terminate() File "", line 2, in terminate File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in _callmethod raise convert_to_error(kind, result) AttributeError: 'NoneType' object has no attribute 'terminate' Which is strange from my point of view, don't you think? Thanks for advices, cheers -- Tomas Pelka -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Thu Jul 8 17:11:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 08 Jul 2010 23:11:50 +0200 Subject: Python Multi-Channel Audio In-Reply-To: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> References: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> Message-ID: <4C363F16.4030301@jollans.com> On 07/08/2010 09:17 PM, Alex Karpinski wrote: > I'm looking for some module or system of modules that can help me do a few things with audio > > 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) > 2. Seek within the file > 3. Control volume > 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 > > I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. First of all, allow me to point to a something I hacked together (mostly) a few weeks ago: http://bitbucket.org/jollybox/pyaudiogen/wiki/Home It's something of a library, VERY minimal/skeletal at the moment, for audio generation (and/or processing) in Python. No idea if this is of any help to you. Python 3 only. Multiple channel support is there, though to be useful it'd still need a bit of glue. Not much to see there yet all in all. > > (For the curious: This is part of the audio system for a larger immersive theater project, ) Though really, what I think you want is jack. It basically allows you to plug things together in any way, and I'm sure you can control the volume of individual "plugs". I expect there is a Python API, but I haven't checked. From gneuner2 at comcast.net Thu Jul 8 17:13:58 2010 From: gneuner2 at comcast.net (George Neuner) Date: Thu, 08 Jul 2010 17:13:58 -0400 Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> <87lj9mfju6.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, 08 Jul 2010 10:39:45 +0200, pjb at informatimago.com (Pascal J. Bourguignon) wrote: >Nick Keighley writes: >> Nick Keighley wrote: >>> Rivka Miller wrote: >> >>>> Anyone know what the first initial of L. Peter Deutsch stand for ? >>> >>> Laurence according to wikipedia (search time 2s) >> >> oops! He was born Laurence but changed it legally to "L." including >> the dot > >Too bad, "Laurence" is a nice name. He probably hates the nickname "Larry". From daniel at stutzbachenterprises.com Thu Jul 8 17:14:01 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 8 Jul 2010 16:14:01 -0500 Subject: ANN: winreg_unicode 0.5.0 Message-ID: I'm pleased to announce the release of winreg_unicode 0.5.0, the first release of winreg_unicode. The winreg_unicode package aims to be a drop-in replacement for Python 2's _winreg module. However, it returns unicode values where possible, similar to Python 3's winreg module. To illustrate the need for the winreg_unicode package, suppose an application must query the registry to discover a filename and the registry contains the string "me?uresorna.txt". Python 2's _winreg module will return "meduresorna.txt" instead, which is not the actual name of the file. The winreg_unicode package does not yet contain all of _winreg's functions. In particular, functions that write to the registry are not yet included. Code contributions are welcome. PyPi: http://pypi.python.org/pypi/winreg_unicode Bug tracker: http://github.com/DanielStutzbach/winreg_unicode/issues Source code: http://github.com/DanielStutzbach/winreg_unicode -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From huhai101 at gmail.com Thu Jul 8 17:29:21 2010 From: huhai101 at gmail.com (wholesale football clothes) Date: Thu, 8 Jul 2010 14:29:21 -0700 (PDT) Subject: cheap sale NBA caps and hats ( www.nike-black.com ) Message-ID: Discount smet caps( www.nike-black.com ) cheapsale NBA caps and hats ( www.nike-black.com ) Supply AFF CAPS and hat ( www.nike-black.com ) cheapsale winter warm caps ( www.nike-black.com ) Discount ed hardy hats and caps ( www.nike-black.com ) Discount juicy caps ( www.nike-black.com ) Discount dc hats and caps ( www.nike-black.com ) Discount ca caps ( www.nike-black.com ) Cheap ny caps ( www.nike-black.com ) Cheap polo caps and hats ( www.nike-black.com ) Cheap bape caps ( www.nike-black.com ) Supply Caddice caps ( www.nike-black.com ) New Fasion Hats & Caps Monster Energy ( www.nike-black.com ) Monster Energy Hats ( www.nike-black.com ) Monster Energy Drink Hats ( www.nike-black.com ) White Monster Energy Hats ( www.nike-black.com ) Monster Energy Fitted Hats ( www.nike-black.com ) Youth Monster Energy Hats Monster Energy New Era Hats ( www.nike-black.com ) Monster Energy Cap ( www.nike-black.com ) Monster Energy Drink Cap ( www.nike-black.com ) White Monster Energy Cap ( www.nike-black.com ) Monster Energy Fitted Cap ( www.nike-black.com ) Youth Monster Energy Cap Red Bull Hats ( www.nike-black.com ) Monster Energy New Era Cap ( www.nike-black.com ) Red Bull New Era ( www.nike-black.com ) Red Bull Caps ( www.nike-black.com ) Red Bull Fitted Hat ( www.nike-black.com ) Red Bull New Era Hats ( www.nike-black.com ) Red Bull Energy Hats ( www.nike-black.com ) White Red Bull Hats ( www.nike-black.com ) Black Red Bull Hats Blue Red Bull Hats ( www.nike-black.com ) Red Bull Hats Ebay ( www.nike-black.com ) Buy Red Bull Hats ( www.nike-black.com ) Team Red Bull Hats ( www.nike-black.com ) Red Bull New Era Hats ( www.nike-black.com ) Red Bull Baseball Hats ( www.nike-black.com ) New Era Caps New Era Hats ( www.nike-black.com ) New Era NY Caps ( www.nike-black.com ) New Era NY Hats ( www.nike-black.com ) Website: http://www.nike-black.com From debatem1 at gmail.com Thu Jul 8 17:41:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 8 Jul 2010 14:41:57 -0700 Subject: Python Multi-Channel Audio In-Reply-To: <4C363F16.4030301@jollans.com> References: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> <4C363F16.4030301@jollans.com> Message-ID: On Thu, Jul 8, 2010 at 2:11 PM, Thomas Jollans wrote: > On 07/08/2010 09:17 PM, Alex Karpinski wrote: >> I'm looking for some module or system of modules that can help me do a few things with audio >> >> 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) >> 2. Seek within the file >> 3. Control volume >> 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 >> >> I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. > > First of all, allow me to point to a something I hacked together > (mostly) a few weeks ago: > http://bitbucket.org/jollybox/pyaudiogen/wiki/Home > > It's something of a library, VERY minimal/skeletal at the moment, for > audio generation (and/or processing) in Python. No idea if this is of > any help to you. Python 3 only. Multiple channel support is there, > though to be useful it'd still need a bit of glue. Not much to see there > yet all in all. > >> >> (For the curious: This is part of the audio system for a larger immersive theater project, ) > > Though really, what I think you want is jack. It basically allows you to > plug things together in any way, and I'm sure you can control the volume > of individual "plugs". > I expect there is a Python API, but I haven't checked. Untried: http://sourceforge.net/projects/py-jack/ Geremy Condra From no.email at nospam.invalid Thu Jul 8 17:44:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 08 Jul 2010 14:44:37 -0700 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> Message-ID: <7xbpahd4xm.fsf@ruckus.brouhaha.com> Wolfram Hinderer writes: > JFTR, it works because a+b == a+b (while I don't think that a+b == b+a > holds for all a and b). I'm pretty sure IEEE 754 addition is always commutative (except maybe in the presence of infinity or NaN and maybe not even then). It differs from rational or real-number arithmetic in that it is not always associative. You can have (a+b)+c != a+(b+c). From luismgz at gmail.com Thu Jul 8 17:51:39 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 14:51:39 -0700 (PDT) Subject: How is Unladen Swallow coming along? References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> <4c3638b0$0$1660$742ec2ed@news.sonic.net> Message-ID: <754462d1-6a2f-4b3e-a206-3dbc55975920@w12g2000yqj.googlegroups.com> On Jul 8, 5:44?pm, John Nagle wrote: > On 7/8/2010 12:19 PM, Luis M. Gonz?lez wrote: > > > On Jul 8, 1:42 pm, John Nagle ?wrote: > >> ? ? ?How is Unladen Swallow coming along? ?Looking at the site, code is > >> being checked in and issues are being reported, but the last quarterly > >> release was 2009 Q3. ?They missed their January 2010 release date > >> for "2009 Q4", so they're now about 6 months behind their project > >> plan. > > >> ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > > > Don't be shy. > > Ask this question in Unladen Swallow's google group. They don't bite! > > ? ? Found this: > > "http://www.python.org/dev/peps/pep-3146/#performance-retrospective" > > ? ? It's starting to work, but the performance improvement is tiny, > well under 2x faster than CPython. ?Only 1.08x on "html5lib". > That's far less than they expected. ?They were going for 5x, > which is far less than Shed Skin (which restricts Python) > already achieves. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Shedskin is an heroic effort by Mark Dufour, but comparing it to Cpython is like comparing oranges to apples. Shedskin is not an interpreter, it's just a way to compile implicitly statically typed python code to c++. So the project is more along the lines of Pyrex/Cython in its goals. I believe it's a great way to compile extension modules written in restricted python, although it could compile entire programs provided they don't rely on non supported libraries or modules. Only a few are supported to different degrees of completeness. At this moment, it seems that Pypy is the project holding more promises. Although I guess Guido has strong reasons to support Unladen Swallow. Lets see what happens... Luis From dickinsm at gmail.com Thu Jul 8 17:54:27 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 14:54:27 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> Message-ID: <1b9dded9-75dc-4cf2-a872-6b26e1ac6ab3@t10g2000yqg.googlegroups.com> On Jul 8, 9:52?pm, Wolfram Hinderer wrote: > JFTR, it works because a+b == a+b (while I don't think that a+b == b+a > holds for all a and b). Actually, that's one of the few identities that's safe. Well, for non- NaN IEEE 754 floating-point, at any rate. And assuming that there's no use of extended precision to compute intermediate results (in which case one side could conceivably be computed with different precision from the other; but that applies to a+b == a+b, too). And assuming that no FPE signals occur and halt the program... (e.g., for overflow, or from doing -inf + inf). Okay, maybe not that safe, then. :) For NaNs, there are two problems: first, if exactly one of a and b is a NaN then a+b and b+a will both be NaNs, so a + b == b + a will be false, even though they're identical. Second, if a and b are *both* NaNs, and you're feeling really fussy and care about signs and payloads, then a + b and b + a won't even necessarily be bitwise identical: a + b will have the sign and payload of a, while b + a has the sign and payload of b. You can see something similar with the Decimal module: >>> Decimal('NaN123') + Decimal('-NaN456') Decimal('NaN123') >>> Decimal('-NaN456') + Decimal('NaN123') Decimal('-NaN456') Or more directly (just for fun), using the struct module to create particular nans: >>> import struct >>> x = struct.unpack('>> y = struct.unpack('>> x nan >>> y nan >>> struct.pack('>> struct.pack(' References: Message-ID: On 19-6-2010 23:45, Shashwat Anand wrote: > Terry: Thanks for bringing this to notice. > Mark: Kudos for your effort in cleaning up bugs.python.org > Like I've said elsewhere, flattery will get you everywhere. :) FYI there are now 480 orphans and I've managed to get 8 issues closed. After one week I even got promoted to the triage team, although I found the pay increase rather disappointing. :) Kindest regards. Mark Lawrence. From ncauderan at gmail.com Thu Jul 8 18:20:44 2010 From: ncauderan at gmail.com (norbert) Date: Thu, 8 Jul 2010 15:20:44 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <7ebf6973-4900-4865-85b1-78231f8396ad@w12g2000yqj.googlegroups.com> On Jul 5, 3:35?pm, Antoine Pitrou wrote: > I suggest you report an issue onhttp://bugs.python.org done : http://bugs.python.org/issue9208 From nyamatongwe+thunder at gmail.com Thu Jul 8 20:02:30 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 09 Jul 2010 10:02:30 +1000 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: sturlamolden: > Windows did this too (msvcrt.dll) up to the VS2003 release, which came > with msvcr71.dll in addition. Since then, M$ (pronounced Megadollar > Corp.) have published msvcr80.dll, msvcr90.dll, and msvcr100.dll (and > corresponding C++ versions) to annoy C and C++ developers into > converting to C# .NET. (And yes, programs using third-party DLL and > OCX components become unstable from this. You have to check each DLL/ > OCX you use, and each DLL used by each DLL, etc. How fun...) One of the benefits to COM is that it acts as a C runtime firewall - it has its own memory allocation interface (IMalloc / CoGetMalloc) and file I/O is performed through interfaces like IStream. It is quite common to use an OCX compiled with one compiler in an application compiled with another. If you break the rules by using malloc rather than IMalloc for memory that is deallocated by a different component to that which allocated it or try to pass around FILE* objects then you will see failures. So, always follow the COM rules. Neil From pavlovevidence at gmail.com Thu Jul 8 21:35:36 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jul 2010 18:35:36 -0700 (PDT) Subject: "is not" operator? References: Message-ID: <267fcbfd-9cfa-4193-9bd8-78a932afe20b@m40g2000prc.googlegroups.com> On Jul 8, 1:32?pm, Robert Kern wrote: > On 7/8/10 4:10 PM, sturlamolden wrote: > > > What happens here? Does Python (2.6.5) have an "is not" operator? > > Yes. From Grammar/Grammar: > > comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' Happy thing, too. I use "is not" a lot more than "is" and am happy to avoid the extra set of parentheses. Carl Banks From anand.shashwat at gmail.com Thu Jul 8 21:37:08 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 9 Jul 2010 07:07:08 +0530 Subject: 500 tracker orphans; we need more reviewers In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 3:28 AM, Mark Lawrence wrote: > On 19-6-2010 23:45, Shashwat Anand wrote: > >> Terry: Thanks for bringing this to notice. >> Mark: Kudos for your effort in cleaning up bugs.python.org >> >> > Like I've said elsewhere, flattery will get you everywhere. :) > I think acknowledgement != flattery, but then you are free to have a different point of view :| > FYI there are now 480 orphans and I've managed to get 8 issues closed. > After one week I even got promoted to the triage team, although I found the > pay increase rather disappointing. :) > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jul 8 22:02:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jul 2010 03:02:36 +0100 Subject: "is not" operator? In-Reply-To: References: Message-ID: <4C36833C.5020509@mrabarnett.plus.com> sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? > >>>> a = 5 >>>> print (a is not False) > True >>>> print (a is (not False)) > False >>>> print (not (a is False)) > True > > It seems "y is not x" fits well with spoken English, but it is also a > bit surprising that "y is not x" does not mean "y is (not x)" but "not > (y is x)". Why does Python reorder is and not operators, and what are > the formal rules for this behavior? > In English the negative comes after the verb (or the auxiliary, if there is one), so: x is not y If you wanted to abbreviate: x is in y the natural result would be: x in y and the opposite: x is not in y: would be abbreviated to: x not in y The resulting inconsistency in Python is somewhat unfortunate, but in practice it's not a problem because: not y returns either False or True, and how often would you write: x is False or: x is True ? From jackdied at gmail.com Thu Jul 8 22:16:27 2010 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 8 Jul 2010 22:16:27 -0400 Subject: "is not" operator? In-Reply-To: <4C36833C.5020509@mrabarnett.plus.com> References: <4C36833C.5020509@mrabarnett.plus.com> Message-ID: On Thu, Jul 8, 2010 at 10:02 PM, MRAB wrote: > sturlamolden wrote: >> It seems "y is not x" fits well with spoken English, but it is also a >> bit surprising that "y is not x" does not mean "y is (not x)" but "not >> (y is x)". Why does Python reorder is and not operators, and what are >> the formal rules for this behavior? >> > In English the negative comes after the verb (or the auxiliary, if there > is one), so: The right way to think about python syntax is not to consider what is obvious to an LL(1) compiler, or what makes sense in English, but rather "what was the obvious way to write an LL(1) syntax if you are a Dutchman who speaks English?" Hope-that-clears-things-up-ly, -Jack From tim.leslie at gmail.com Thu Jul 8 22:21:10 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 9 Jul 2010 12:21:10 +1000 Subject: "is not" operator? In-Reply-To: References: <4C36833C.5020509@mrabarnett.plus.com> Message-ID: On Fri, Jul 9, 2010 at 12:16 PM, Jack Diederich wrote: > > The right way to think about python syntax is not to consider what is > obvious to an LL(1) compiler, or what makes sense in English, but > rather "what was the obvious way to write an LL(1) syntax if you are a > Dutchman who speaks English?" +1 QOTW > > Hope-that-clears-things-up-ly, > > -Jack > -- > http://mail.python.org/mailman/listinfo/python-list > From schlesin at cshl.edu Thu Jul 8 23:39:52 2010 From: schlesin at cshl.edu (Felix) Date: Thu, 8 Jul 2010 20:39:52 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On Jul 4, 11:25?am, David Cournapeau wrote: > On Mon, Jul 5, 2010 at 12:00 AM, D'Arcy J.M. Cain wrote: > > I wish it was orders of magnitude faster for web development. ?I'm just > > saying that places where we need compiled language speed that Python > > already has that in C. > > Well, I wish I did not have to use C, then :) For example, as a > contributor to numpy, it bothers me at a fundamental level that so > much of numpy is in C. This is something that I have been thinking about recently. Python has won quite a following in the scientific computing area, probably especially because of great libraries such as numpy, scipy, pytables etc. But it also seems python itself is falling further and further behind in terms of performance and parallel processing abilities. Of course all that can be fixed by writing C modules (e.g. with the help of cython), but that weakens the case for using python in the first place. For an outsider it does not look like a solution to the GIL mess or a true breakthrough for performance are around the corner (even though there seem to be many different attempts at working around these problems or helping with parts). Am I wrong? If not, what is the perspective? Do we need to move on to the next language and loose all the great libraries that have been built around python? Felix From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 00:37:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 04:37:52 GMT Subject: Opinions please -- how big should a single module grow? Message-ID: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> This is a style question rather than a programming question. How large (how many KB, lines, classes, whatever unit of code you like to measure in) should a module grow before I should break it up into a package? I see that, for example, decimal.py is > 3000 lines of code, so I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. Where do you draw the line? For the purposes of the discussion, you should consider that the code in the module really does belong together, and that splitting it into sub- modules would mean arbitrarily separating code into separate files. -- Steven From timr at probo.com Fri Jul 9 00:39:44 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 08 Jul 2010 21:39:44 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Christian Heimes wrote: >> Yeah, but then we're down to file descriptors, C library locales and such as the >> remaining problems. > >Don't forget errno! Every CRT might have its own errno thread local. I >don't know how its handled on Windows but I suspect it suffers from the >same problem. No. The multi-thread-aware CRT in Visual C++ (which is the only option since VS2008) puts errno in thread-local storage, so it's shared by all CRTs. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan_ml at behnel.de Fri Jul 9 00:44:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 Jul 2010 06:44:07 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: Felix, 09.07.2010 05:39: > On Jul 4, 11:25 am, David Cournapeau wrote: >> Well, I wish I did not have to use C, then :) For example, as a >> contributor to numpy, it bothers me at a fundamental level that so >> much of numpy is in C. > > This is something that I have been thinking about recently. Python has > won quite a following in the scientific computing area, probably > especially because of great libraries such as numpy, scipy, pytables > etc. But it also seems python itself is falling further and further > behind in terms of performance and parallel processing abilities. Well, at least its "parallel processing abilities" are quite good actually. If you have really large computations, they usually run on more than one computer (not just more than one processor). So you can't really get around using something like MPI, in which case an additional threading layer is basically worthless, regardless of the language you use. For computations, threading keeps being highly overrated. WRT a single machine, you should note that GPGPUs are a lot faster these days than even multi-core CPUs. And Python has pretty good support for GPUs, too. > Of course all that can be fixed by writing C modules (e.g. with the help > of cython), but that weakens the case for using python in the first > place. Not at all. Look at Sage, for example. It's attractive because it provides tons of functionality, all nicely glued together through a simple language that even non-programmers can use efficiently and effectively. And its use of Cython makes all of this easily extensible without crossing the gap of a language border. Stefan From stefan_ml at behnel.de Fri Jul 9 00:48:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 Jul 2010 06:48:40 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 09.07.2010 06:37: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. Well, if that's the case, then there's no reason to split it up. However, for any module of substantial growth, I'd expect there to be some point where you start adding section separation comments (Meta-80-#) to make the structure clearer. That might be the time when you should also consider breaking it up into separate source files. Stefan From me+list/python at ixokai.io Fri Jul 9 01:16:08 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 22:16:08 -0700 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36B098.1000409@ixokai.io> On 7/8/10 9:37 PM, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. If that is really true, then it belongs as one module, regardless of size -- I don't believe there's any certain count where you should draw this line. Now, once you get up to say, 5-10 KLOC, I find it hard to believe that everything there really does belong together and there's not a substantial subset of code which really belongs "more" together then it does with the surrounding code. That would then lend itself to be a new file in a package. But that can happen at 1 KLOC too. But then it can still be 5-10 KLOC which, to me, fits perfectly together still. Its just more likely the higher the count that you have subsets that would benefit from logical separation. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From sturlamolden at yahoo.no Fri Jul 9 01:16:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 22:16:11 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On 9 Jul, 05:39, Felix wrote: > This is something that I have been thinking about recently. Python has > won quite a following in the scientific computing area, probably > especially because of great libraries such as numpy, scipy, pytables > etc. Python is much more friendly to memory than Matlab, and a much nicer language to work in. It can also be used to program more than just linear algebra. If you have to read data from a socket, Matlab is not so fun anymore. > But it also seems python itself is falling further and further > behind in terms of performance and parallel processing abilities. First, fine-grained parallelism really belongs in libraries like MKL, GotoBLAS and FFTW. Python can manage the high-level routines just like Matlab. You can call a NumPy routine like np.dot, and the BLAS library (e.g. Intel MKL) will do the multi-threading for you. We almost always use Python to orchestrate C and Fortran. We can use OpenMP in C or Fortran, or we can just release the GIL and use Python threads. Second, the GIL it does not matter for MPI, as it works with processes. Nor does it matter for os.fork or multiprocessing. On clusters, which are as common in high-performance computing as SMP systems, one has to use processes (usually MPI) rather than threads, as there is no shared memory between processors. On SMP systems, MPI can use shared-memory and be just as efficient as threads (OpenMP). (MPI is usually faster due to cache problems with threads.) Consider that Matlab does not even have threads (or did not last time I checked). Yet it takes advantage of multi-core CPUs for numerical computing. It's not the high-level interface that matters, it's the low-level libraries. And Python is just that: a high-level "glue" language. > For an outsider it does not look like a solution to the GIL mess or a > true breakthrough for performance are around the corner (even though > there seem to be many different attempts at working around these > problems or helping with parts). Am I wrong? Yes you are. We don't do CPU intensive work in "pure Python". We use Python to control C and Fortran libraries. That gives us the opportunity to multi-thread in C, release the GIL and multi-thread in Python, or both. From sturlamolden at yahoo.no Fri Jul 9 01:25:39 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 22:25:39 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> On 9 Jul, 06:44, Stefan Behnel wrote: > WRT a single machine, you should note that GPGPUs are a lot faster these > days than even multi-core CPUs. And Python has pretty good support for > GPUs, too. With OpenCL, Python is better than C for heavy computing. The Python or C/C++ program has to supply OpenCL code (structured text) to the OpenCL driver, which does the real work on GPU or CPU. Python is much better than C or C++ at processing text. There will soon be OpenCL drivers for most processors on the market. But OpenCL drivers will not be pre-installed on Windows, as Microsoft has a competing COM-based technology (DirectX Compute, with an atrocious API and syntax). From roy at panix.com Fri Jul 9 01:30:12 2010 From: roy at panix.com (Roy Smith) Date: Fri, 09 Jul 2010 01:30:12 -0400 Subject: Opinions please -- how big should a single module grow? References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: In article <4c36a7a0$0$28647$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. To paraphrase Einstein, A module should be as large as it needs to be, but no larger. There's no hard and fast rule. More important than counting lines of code is that all the things in a module should represent some coherent set of related functionality. Beyond that, I would say the only hard limit on line count is when common editing tools start to balk at opening the file. From nagle at animats.com Fri Jul 9 01:41:50 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 22:41:50 -0700 Subject: Inheriting from "dict" (was: Python dynamic attribute creation) In-Reply-To: <895n87FnsoU1@mid.individual.net> References: <895n87FnsoU1@mid.individual.net> Message-ID: <4c36b6a4$0$1663$742ec2ed@news.sonic.net> On 7/2/2010 1:54 AM, Gregory Ewing wrote: > WANG Cong wrote: > >> Yeah, my point is why setattr() for dynamic attributes while assignments >> for static attributes? > > If you mean using exactly the same syntax for both, that would > require making the static case more verbose, e.g. instead of > > foo.blarg > > you would have to write something like > > foo.("blarg") > > just to allow for the possibility of writing > > foo.(some_arbitrary_expression) Instead of dynamically adding attributes, there's another option: deriving a class from "dict": class HTMLtag(dict) : def __init__(self, tagtype) : self.tagtype = tagtype def __str__(self) : # generate source HTML tag return("<" + self.tagtype + " " + " ".join(map(lambda item: '%s="%s"' % item, self.items())) + ">" tag1 = HTMLtag(a) tag1['href'] = "http://www.example.com" tag1['class'] = "adurl" s = str(tag1) # converts to string This has some advantages. The elements of the dictionary aren't in the same namespace as the attributes of object, so there's no problem with name clashes. Nor is there a problem with reserved words. BeautifulSoup stores HTML tag attributes as object attributes, and they have to special case things like "class". You can iterate over all the elements of the dictionary (as the "__str__" function does above) without interference from attributes which aren't data items. There's no problem with values that aren't valid attribute strings. (Python 2.x won't accept Unicode attributes, for example.) There's no risk of security injection problems because external data overrode a member name or some crucial data attribute. If you find yourself having to write code to avoid any of those problems, like prefixing dynamic attribute names with some symbol to avoid name clashes (or realize, after reading this, that your code has a vulnerability because it's not doing that), it may be better to inherit from "dict" rather than setting attributes explicitly. John Nagle From timr at probo.com Fri Jul 9 03:16:16 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 09 Jul 2010 00:16:16 -0700 Subject: Python -- floating point arithmetic References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: <24jd369ns1ui96vg02h8pe7llo2mi233ab@4ax.com> David Mainzer wrote: > >All your comments helped me and now i know how it works in python ! This has nothing to do with Python. What you're seeing is the way IEEE-754 floating point arithmetic works. You'd see these same results in any programming language, including assembly language (assuming it hasn't changed the rounding mode). -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From davea at ieee.org Fri Jul 9 03:49:10 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 03:49:10 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36D476.7070604@ieee.org> Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > > > I don't have a number for you, but the measure I'd suggest is the size of the documentation. DaveA From davea at ieee.org Fri Jul 9 03:55:45 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 03:55:45 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Message-ID: <4C36D601.9060709@ieee.org> Tim Roberts wrote: > Christian Heimes wrote: > > >>> Yeah, but then we're down to file descriptors, C library locales and such as the >>> remaining problems. >>> >> Don't forget errno! Every CRT might have its own errno thread local. I >> don't know how its handled on Windows but I suspect it suffers from the >> same problem. >> > > No. The multi-thread-aware CRT in Visual C++ (which is the only option > since VS2008) puts errno in thread-local storage, so it's shared by all > CRTs. > I didn't know specifically that errno is in TLS, but I will disagree with the conclusion that a TLS entry is implicitly shared by all CRT's. Unless the CRT for each DLL explicitly does some extra work to allow sharing, each will have its own set of TLS variables. DaveA From nospam at nospam.com Fri Jul 9 04:18:47 2010 From: nospam at nospam.com (Gilles Ganault) Date: Fri, 09 Jul 2010 10:18:47 +0200 Subject: Only one forum app in Python? Message-ID: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Hello I'd like to write a small web app in Python which must include a forum. So I checked the relevant article in Wikipedia, which says that only one forum app is available for Python: http://en.wikipedia.org/wiki/Comparison_of_internet_forum_software_(other) Is Pocoo really the only solution available out there? Thank you. From prologic at shortcircuit.net.au Fri Jul 9 04:29:17 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jul 2010 18:29:17 +1000 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: On Fri, Jul 9, 2010 at 6:18 PM, Gilles Ganault wrote: > Is Pocoo really the only solution available out there? Did you bother to check pypi ? cheers James 1. http://pypi.python.org/ -- -- James Mills -- -- "Problems are solved by method" From stef.mientki at gmail.com Fri Jul 9 05:21:44 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 09 Jul 2010 11:21:44 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36EA28.4020502@gmail.com> On 09-07-2010 06:37, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > > > interesting question. >From the answers already given, I assume it doesn't matter, as long as all the functionality in that module is related. Would it be a good idea to split a module in 2 parts, part 1 : everything that would normally accessible from the outside part 2 : everything that is only used inside the module I think in this way a user of the module (that doesn't know the module yet) has a far more easier entrance. cheers, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Fri Jul 9 05:37:07 2010 From: alt.mcarter at gmail.com (Mark Carter) Date: Fri, 9 Jul 2010 02:37:07 -0700 (PDT) Subject: Python scripts from DOS Message-ID: On my machine, I can go to a DOS shell, and type myscript.py This will cause the script to be run as a python script. So that bit works. On another machine, on which python was set up without admin privileges, if I type myscript.py it will open the "Open With" dialog box. It wont let me execute it with python.exe. It asks me the same question every time, too. If I type python myscript.py then everything works fine. Is there a way of setting up the "other" machine so that it replicates the behaviour of my machine? From thomas at jollans.com Fri Jul 9 05:49:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 11:49:33 +0200 Subject: Python scripts from DOS In-Reply-To: References: Message-ID: <4C36F0AD.3050408@jollans.com> On 07/09/2010 11:37 AM, Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type Which operating systems are we talking about? > myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. What does that mean, exactly? What happens when you try to select python? > It asks me the same question every time, too. If I > type > python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? Depends on which OS we're talking about. I'm guessing you're using Windows, but I don't know which version, and I don't possess the Registry-fu you'll probably need. From asmodai at in-nomine.org Fri Jul 9 05:55:17 2010 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Fri, 9 Jul 2010 11:55:17 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <20100709095517.GL70600@nexus.in-nomine.org> -On [20100709 10:22], Gilles Ganault (nospam at nospam.com) wrote: >Is Pocoo really the only solution available out there? Pocoo as a forum app has been dead for years. Maybe Vithon (http://bitbucket.org/vithon/vithon-forum/src) does what you want/need. http://www.vithon.org/forum should be a live instance of it. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B All for one, one for all... From pdwjfndjbdgfyg at gmail.com Fri Jul 9 06:20:28 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 9 Jul 2010 03:20:28 -0700 (PDT) Subject: HOT N JOBS Message-ID: <4d11cce1-4914-4791-ac46-f1f9192a8747@m17g2000prl.googlegroups.com> hot kiss http://photoseefree.blogspot.com/2009/12/hot-kiss.html hot lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-kiss.html hot navel kiss http://photoseefree.blogspot.com/2009/12/hot-navel-kiss.html hot lip to lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-to-lip-kiss.html super lip kiss http://photoseefree.blogspot.com/2009/12/super-lip-kiss.html lip kiss club http://photoseefree.blogspot.com/2009/12/lip-kiss-club.html kiss club http://photoseefree.blogspot.com/2009/12/kiss-club.html FOR JOBS work from home http://anyjobseehere.blogspot.com/2009/12/work-from-home.html online jobs http://anyjobseehere.blogspot.com/2009/12/online-jobs.html java jobs http://anyjobseehere.blogspot.com/2009/12/java-jobs.html oracle jobs http://anyjobseehere.blogspot.com/2009/12/oracle-jobs.html web designing jobs http://anyjobseehere.blogspot.com/2009/12/web-designing-jobs.html From pdwjfndjbdgfyg at gmail.com Fri Jul 9 06:53:41 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 9 Jul 2010 03:53:41 -0700 (PDT) Subject: HOT N SEX Message-ID: <41ff3db9-402e-42d5-8a95-fc18862ffc7a@w15g2000pro.googlegroups.com> hot kiss http://photoseefree.blogspot.com/2009/12/hot-kiss.html hot lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-kiss.html hot navel kiss http://photoseefree.blogspot.com/2009/12/hot-navel-kiss.html hot lip to lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-to-lip-kiss.html super lip kiss http://photoseefree.blogspot.com/2009/12/super-lip-kiss.html lip kiss club http://photoseefree.blogspot.com/2009/12/lip-kiss-club.html kiss club http://photoseefree.blogspot.com/2009/12/kiss-club.html FOR JOBS work from home http://anyjobseehere.blogspot.com/2009/12/work-from-home.html online jobs http://anyjobseehere.blogspot.com/2009/12/online-jobs.html java jobs http://anyjobseehere.blogspot.com/2009/12/java-jobs.html oracle jobs http://anyjobseehere.blogspot.com/2009/12/oracle-jobs.html web designing jobs http://anyjobseehere.blogspot.com/2009/12/web-designing-jobs.html From puntabluda at gmail.com Fri Jul 9 07:05:49 2010 From: puntabluda at gmail.com (Rebelo) Date: Fri, 9 Jul 2010 04:05:49 -0700 (PDT) Subject: Python scripts from DOS References: Message-ID: On 9 srp, 11:37, Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > ? ?myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type > ? ?myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. It asks me the same question every time, too. If I > type > ? ?python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? http://docs.python.org/release/2.6.5/using/windows.html for python 2.6.5 on windows especially chapter 3.3.4. Executing scripts for python 2.7 : http://docs.python.org/using/windows.html same chapter for python 3.0 : http://docs.python.org/py3k/using/windows.html#executing-scripts From kedra.marbun at gmail.com Fri Jul 9 07:51:30 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 9 Jul 2010 04:51:30 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> <4c359425$0$2629$426a74cc@news.free.fr> Message-ID: <18e1d431-6edf-4034-9eaa-69da66842cba@w37g2000prc.googlegroups.com> On Jul 8, 4:02?pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > On Jul 7, 2:46 am, Bruno Desthuilliers > > wrote: > >> Gregory Ewing a ?crit : > > >>> Bruno Desthuilliers wrote: > >>>> kedra marbun a ?crit : > >>>>> if we limit our discussion to py: > >>>>> why __{get|set|delete}__ don't receive the 'name' & 'class' from > >>>>> __{getattribute|{set|del}attr}__ > >>>>> 'name' is the name that is searched > >>>> While it would have been technically possible, I fail to imagine any use > >>>> case for this. > >>> I think he wants to have generic descriptors that are > >>> shared between multiple attributes, but have them do > >>> different things based on the attribute name. > >> I already understood this, but thanks !-) > > >> What I dont understand is what problem it could solve that couldn't be > >> solved more simply using the either _getattr__ hook or hand-coded > >> delegation, since such a descriptor would be so tightly coupled to the > >> host class that it just doesn't make sense writing a descriptor for this. > > > yeah, i finally can agree descriptor isn't supposed to be used as > > delegation in general, it should be the job of __getattr__ > > > however i still think passing name would open up some other > > possibilities of use > > Nothing prevents you to pass a "name" to the descriptor instance when > instanciating it, ie: > > class Desc(object): > ? ? ?def __init__(self, name): > ? ? ? ? ?self.name = name > ? ? def __get__(self, inst, cls): > ? ? ? ? # ... > ? ? def __set__(self, inst, value): > ? ? ? ? # ... > > class Foo(object): > ? ? ?bar = Desc("bar") > ? ? ?baaz = Desc("baaz") > > Ok, this is not necessarily what you were looking for, but it's IMHO > less brittle than relying on which attribute name was looked up (which > is something the descriptor shouldn't have to care about). > > > > > btw, is there a common approach to let the interface of a class that > > uses __getattr__, to include names that are delegated? > > In Python 2.x, not that I know (but it may have passed under my radar). > If what you want it to automate delegation of a set of methods without > too much manual coding, you can use a custom metaclass that will add the > relevant methods to the class, based on (ie) a list (or mapping) of > methods names. But that might be a bit overkill. > > > class A: > > ? ?def do_this(self): ... > > > class B: > > ? ?a = A() > > I don't see the point of using delegation on a class attribute. That's > typically what inheritance is for. ah, our friend mixin, it's just a sample though > > > ? ?def do_that(self): ... > > > ? ?def __getattr__(self, name): > > ? ? ? ? ? ?try: > > ? ? ? ? ? ? ? ? ? ?return types.MethodType(getattr(self.a, name), self) > > Err... Did you try the simple way ? > ? ? ? ? ? ? ? ? ? ? ? ? ?return getattr(self.a, name) argh, that should be class A: def do_this(self, ins): ... From thomas at jollans.com Fri Jul 9 08:10:25 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 14:10:25 +0200 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> Message-ID: <4C3711B1.1070006@jollans.com> On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > collect2: library libpython2.6 not found What really stumps me (and you too, I expect) about this is the two different error messages. Above, it looks like collect2 simply doesn't find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > ld:open(): No such file or directory > > collect2: ld returned 255 exit status But what on earth is this? It looks like collect2 found the library, and told it's mate ld, which can't open it. collect2 thinks it find a file, ld hits "No such file or directory" on the same file. Maybe it's a dead symlink? Looking for a file with the right name and location would find it, while opening it would hit a dead end, and probably return "No such file " From davea at ieee.org Fri Jul 9 08:22:51 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 08:22:51 -0400 Subject: Python scripts from DOS In-Reply-To: References: Message-ID: <4C37149B.1090308@ieee.org> Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type > myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. It asks me the same question every time, too. If I > type > python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? > > Assuming you're talking Windows XP, Vista or Win7 you can do the following: There are registry settings in two places, hklm and hkcu. If you only have one user on the machine, it probably doesn't matter. in that case, there's a nice commandline way to make these associations. assoc creates associations beteween a file extension and a string ftype creates an association between that string and an executable program. On my machine, assoc .py shows .py=Python.File and ftype Python.File shows python.file="C:\PrgFiles\APYTHO~1\python.exe" "%1" %* Or you can read the following link: http://msdn.microsoft.com/en-us/library/ms724475(VS.85).aspx DaveA From kedra.marbun at gmail.com Fri Jul 9 08:32:14 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 9 Jul 2010 05:32:14 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <89llvrFflvU1@mid.individual.net> Message-ID: On Jul 8, 5:10?pm, Gregory Ewing wrote: > kedra marbun wrote: > > i wonder what are the reasons for > > not passing the class on which the descriptor is attached to, what > > pattern is encouraged by this? > > The same answer applies. It's assumed that you will be > writing a custom piece of code for each attribute of > each class, and giving each one its own descriptor. > > By the time you get to the get or set method of a > descriptor, you've already dispatched on both the > class and attribute name. There is not usually any > point in funnelling things back into a single function > and then dispatching on the class or name again. > Passing the class or name would just add overhead that > was unnecessary in the majority of use cases. > > -- > Greg True, unnecessary overhead. this 'passing class' thing comes from, IIRC, learning python 4ed by Mark Lutz, it's stated there that the 3rd arg to __get__ is the class to which the descriptor instance is attached so if i want the host class, i should do it the way builtin descriptors do (bind it manually)? for example, type.__dict__['__getattribute__'].__class__ is wrapper_descriptor. wrapper_descriptor has member __objclass__ pointing to instance of types.MemberDescriptorType, which disallows set & del, get returns the host class ('type' in this case) *** about the 3rd arg of __get__ i guess py has chosen __get__(self, ins, cls) over __get__(self, ins) to make it easier for decriptor-implementor to find out whether the caller (the left-side operand of dot operator) is instance of obj on which the descriptor obj is found or not this conclusion is based on the fact that: - it is only __get__ that receives the redundant class obj - if the caller is a class obj & descriptor is found on obj that is in its __mro__, the fetch is still routed to __get__: __get__(desc, None, CLASS). this doesn't happen for __{set|delete}__ note that the builtin descriptors even allow their's __get__ to be given only the instance (2nd arg): object.__getattribute__.__get__(obj) is it correct? From youngung.jeong at gmail.com Fri Jul 9 08:33:36 2010 From: youngung.jeong at gmail.com (youngung) Date: Fri, 9 Jul 2010 05:33:36 -0700 (PDT) Subject: ipython problem in opening a file Message-ID: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Hello pythoners! I just dived into ipython since I'd like to make use of matplotlib. Over the trials, I came across a problem. One of the scripts that I have is not working with ipython, while it has been and still is working well with Python GUI. The problem is, even though I have the file in the c:\python26 folder, IPython can't fine it. One of the many things I tried, is as below. ************************************************* f=open('od.txt','w') --------------------------------------------------------------------------- IOError Traceback (most recent call last) C:\Windows\system32\ in () IOError: [Errno 13] Permission denied: 'od.txt' What should I do further to solve this problem? From rtomek at ceti.com.pl Fri Jul 9 08:41:06 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 14:41:06 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Fri, 9 Jul 2010, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with comments) - if something takes a lot of place to comment, then maybe it should go to a separate unit. As of the other side of scale, this 3000 KLOC thing, I believe you would have encountered a performance hit. And probably a big one - I would be afraid of some O(n^2) dragon or something bigger, waiting deeply in CPython code to eat your performance. But, I am just fantasizing - I have no idea of CPython internals and how big is the biggest Python code written so far. Python code tends to be very concise, so 3 MLOC sounds rather extremal to me. On the other hand, it is possible nobody tested CPython for such extreme case. Speaking of performance, there is also target user, and her needs (CGI? desktop? etc). So I would take this under consideration, too - how many times per second (minute, day) this code will be executed? Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From python at bdurham.com Fri Jul 9 08:47:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 09 Jul 2010 08:47:46 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4C36EA28.4020502@gmail.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> <4C36EA28.4020502@gmail.com> Message-ID: <1278679666.9335.1384063345@webmail.messagingengine.com> Steven, Interesting question. I've seen even small modules (in terms of code size) grow quite large with embedded documentation, developer comments, and unit tests. The unit tests can be split to another module. Sometimes classes can be artificially split into separate classes (and thus split across modules) and then combined through inheritance or aggragration. And yes, I recognize I haven't answered your original question :) Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bryan.Stopp at argushealth.com Fri Jul 9 08:54:21 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Fri, 9 Jul 2010 07:54:21 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C3711B1.1070006@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C3711B1.1070006@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> I checked, none of the files are symlinks. The install process never got to the point where it created sym-links for libraries (if it even does, I haven't gotten to that point in the install process.) -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Friday, July 09, 2010 7:10 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > collect2: library libpython2.6 not found What really stumps me (and you too, I expect) about this is the two different error messages. Above, it looks like collect2 simply doesn't find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > ld:open(): No such file or directory > > collect2: ld returned 255 exit status But what on earth is this? It looks like collect2 found the library, and told it's mate ld, which can't open it. collect2 thinks it find a file, ld hits "No such file or directory" on the same file. Maybe it's a dead symlink? Looking for a file with the right name and location would find it, while opening it would hit a dead end, and probably return "No such file " -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From anthra.norell at bluewin.ch Fri Jul 9 09:02:25 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 15:02:25 +0200 Subject: 'reload M' doesn't update 'from M inport *' Message-ID: <1278680545.2376.30.camel@hatchbox-one> I develop in an IDLE window. Module M says 'from service import *'. Next I correct a mistake in function 'service.f'. Now 'service.f' works fine. I do 'reload (service); reload (M)'. The function 'M.f' still misbehaves. 'print inspect.getsource (service.f)' and 'print inspect.getsource (M.f)' shows the same corrected code. 'print service.f' and 'print M.f' show different ids. So I do 'del M; reload (M)'. Nothing changes. I delete M again and run gc.collect () to really clean house. I reload M again and still nothing changes. The id of the reloaded function 'M.f' is still the same as it was before the purge and so M.f still isn't fixed. I know I have more radical options, such as starting a new IDLE window. That would save me time, but I'd like to take the opportunity to understand what is happening. Surely someone out there knows. Frederic From eliben at gmail.com Fri Jul 9 09:02:57 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 9 Jul 2010 16:02:57 +0300 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: > One of the many things I tried, is as below. > > ************************************************* > > > f=open('od.txt','w') > --------------------------------------------------------------------------- > IOError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call > last) > > C:\Windows\system32\ in () > > IOError: [Errno 13] Permission denied: 'od.txt' > > It appears that your ipython runs in C:\Windows\system32 You can find it out for sure by executing "os.getcwd()" after importing the "os" module. You may not have permissions in C:\Windows\system32, which is why the error is printed. Eli From eliben at gmail.com Fri Jul 9 09:17:05 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 9 Jul 2010 16:17:05 +0300 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: On Fri, Jul 9, 2010 at 16:07, Youngung Jeong wrote: > Thank you for your kindness. > I found you're right. It's running in that folder. > What should I do for making this work? > Could you please tell me a bit more... > > Youngung You can change the "current directory" ipython executes in, by either executing it directly (from the command line) in the directory of your choice, or calling the os.chdir function with the path of your choice. Eli From kaklis at gmail.com Fri Jul 9 09:17:29 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Fri, 9 Jul 2010 06:17:29 -0700 (PDT) Subject: Load/Performance Testing of a Web Server Message-ID: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Hi to all, i want to stress test a tomcat web server, so that i could find out its limits. e.g how many users can be connected and request a resource concurrently. I used JMeter which is an excellent tool, but i would like to use a more pythonic approach. Any hints Antonis From rene7705 at gmail.com Fri Jul 9 09:24:32 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Fri, 9 Jul 2010 15:24:32 +0200 Subject: how do you print an object? Message-ID: hi. i'm a recent convert from php because google appengine runs python. i have a whole cms backend to convert (also to bigtable, but thats another story) to python now. the first item on my agenda is the printing of python objects to json objects. i have this nifty xhtml dataviewer (htmlMicroscope, see the downloads page in my signature) that accepts json objects for display in the browser. i also have an xhtml error viewer, logAndHandler, that does sort of the same. i want to use both of these with python, and i will promise to release the python sources for hm() and lah() as well. so my question is simple: how do you go from python object to json representation of that object, preferably keeping everything including function code in the json output? i'll have many more questions, if i decide to convert my cms backend to python. but it seems i'm without option on this ;) side question: anybody know a cloud hosting service that does php? i really have a ton of code already ;) -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From nathan.alexander.rice at gmail.com Fri Jul 9 09:25:57 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 9 Jul 2010 09:25:57 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: I start to look at whether some subset of functions or classes are not referenced by other subsets of functions or classes in a module when it gets to about 1K LoC, and if I don't find any by the time it gets to about 1500 LoC, I start to look at ways I can refactor the code in the module to be less coupled. This might just be anecdotal, but in all the python libraries I've looked at (including the larger 30K+ LoC ones) the quality of code in a module tends to be lower if the module is over around 1500 LoC. -------------- next part -------------- An HTML attachment was scrubbed... URL: From schlesin at cshl.edu Fri Jul 9 09:25:58 2010 From: schlesin at cshl.edu (Felix) Date: Fri, 9 Jul 2010 06:25:58 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <25863592-e417-4157-bbfb-1743e6889fb1@z10g2000yqb.googlegroups.com> On Jul 9, 1:16?am, sturlamolden wrote: > On 9 Jul, 05:39, Felix wrote: > > For an outsider it does not look like a solution to the GIL mess or a > > true breakthrough for performance are around the corner (even though > > there seem to be many different attempts at working around these > > problems or helping with parts). Am I wrong? > > Yes you are. > > We don't do CPU intensive work in "pure Python". We use Python to > control C and Fortran libraries. That gives us the opportunity to > multi-thread in C, release the GIL and multi-thread in Python, or > both. Yes, this setup works very well and is (as I said) probably the reason python is so widely used in scientific computing these days. However I find that I can almost never do everything with vector operations, but have to iterate over data structures at some point. And here the combination of CPython slowness and the GIL means either bad performance or having to write this in C (with which cython helps fortunately). If it were possible to write simple, parallel, reasonably fast loops in (some subset of) python directly that would certainly be a great advantage. Given the performance of other JITs it sounds like it should be possible, but maybe python is too complex to make this realistic. Felix PS: No need to convince me that MATLAB is not the solution. From thomas at jollans.com Fri Jul 9 09:42:44 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 15:42:44 +0200 Subject: how do you print an object? In-Reply-To: References: Message-ID: <4C372754.4090000@jollans.com> On 07/09/2010 03:24 PM, Rene Veerman wrote: > hi. > > i'm a recent convert from php because google appengine runs python. > i have a whole cms backend to convert (also to bigtable, but thats > another story) to python now. > > the first item on my agenda is the printing of python objects to json objects. > i have this nifty xhtml dataviewer (htmlMicroscope, see the downloads > page in my signature) that accepts json objects for display in the > browser. i also have an xhtml error viewer, logAndHandler, that does > sort of the same. > i want to use both of these with python, and i will promise to release > the python sources for hm() and lah() as well. > > so my question is simple: how do you go from python object to json > representation of that object, preferably keeping everything including > function code in the json output? http://docs.python.org/py3k/library/json.html To get function code, have a look at the inspect module docs. > > i'll have many more questions, if i decide to convert my cms backend to python. > but it seems i'm without option on this ;) > > side question: anybody know a cloud hosting service that does php? i > really have a ton of code already ;) > > From schlesin at cshl.edu Fri Jul 9 09:43:03 2010 From: schlesin at cshl.edu (Felix) Date: Fri, 9 Jul 2010 06:43:03 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <43a6038e-1954-438d-90af-da78fecd73ae@d16g2000yqb.googlegroups.com> On Jul 9, 12:44?am, Stefan Behnel wrote: > Felix, 09.07.2010 05:39: > Well, at least its "parallel processing abilities" are quite good actually. > If you have really large computations, they usually run on more than one > computer (not just more than one processor). So you can't really get around > using something like MPI, in which case an additional threading layer is > basically worthless, regardless of the language you use. For computations, > threading keeps being highly overrated. That is certainly true for large computations. But many smaller tasks are run on single machines and it does make a difference if they take 1 minute per run or 10. The average number of cores per computer has been increasing for quite a while now. It seems unfortunate to be restricted to using only one of them at a time (for regular loops, not mathematical vector operations). Python has made so many complicated things easy, but I have not seen an easy way to parallelize a simple loop on a multicore CPU without having to set up infrastructure and/or incurring large overhead from many interpreters and marshalling data. Just the fact that there is such a large number of attempts out there to fix this suggests that something important is missing. From simon at brunningonline.net Fri Jul 9 09:44:23 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 9 Jul 2010 14:44:23 +0100 Subject: Load/Performance Testing of a Web Server In-Reply-To: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> References: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Message-ID: On 9 July 2010 14:17, kaklis at gmail.com wrote: > Hi to all, i want to stress test ? a tomcat web server, so that i > could find out its limits. e.g how many users can be connected and > request a resource concurrently. > I used JMeter which is an excellent tool, but i would like to use a > more pythonic approach. The Grinder? -- Cheers, Simon B. From gfiske at gmail.com Fri Jul 9 10:09:13 2010 From: gfiske at gmail.com (Greg) Date: Fri, 9 Jul 2010 07:09:13 -0700 (PDT) Subject: python instructor Message-ID: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> We're looking for a first-rate python trainer to come to our organization for a day or two. We are a small group of geospatial/ remote sensing scientists whose research spans the gap between environmental accounting/monitoring and policy and human interaction. We have about 5-10 (or so) python users (and potential python users) who could potentially apply new skills to several in-house projects. The difficulty for the teacher would be covering breadth of experience we have currently. Any thoughts or advice would be greatly appreciated. Thanks very much, Greg From christian.sperandio at gmail.com Fri Jul 9 10:26:24 2010 From: christian.sperandio at gmail.com (Chrix) Date: Fri, 9 Jul 2010 07:26:24 -0700 (PDT) Subject: Netbeans plugin and Python 3 Message-ID: <9ed2c37d-bce6-4dd5-9b0b-4f35aa81aa55@c33g2000yqm.googlegroups.com> Hi, Someone knows if Netbeans will support Python 3 language features? Nowadays, I tried Netbeans 6.9 but it only supports Python 2.5 :( And I'd like really to develop with Python 3. Thanks. From youngung.jeong at gmail.com Fri Jul 9 10:27:08 2010 From: youngung.jeong at gmail.com (Youngung Jeong) Date: Fri, 9 Jul 2010 23:27:08 +0900 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: Thanks a lot! Youngung On Fri, Jul 9, 2010 at 10:17 PM, Eli Bendersky wrote: > On Fri, Jul 9, 2010 at 16:07, Youngung Jeong > wrote: > > Thank you for your kindness. > > I found you're right. It's running in that folder. > > What should I do for making this work? > > Could you please tell me a bit more... > > > > Youngung > > You can change the "current directory" ipython executes in, by either > executing it directly (from the command line) in the directory of your > choice, or calling the os.chdir function with the path of your choice. > > Eli > -------------- next part -------------- An HTML attachment was scrubbed... URL: From e_d_k at yahoo.com Fri Jul 9 10:49:05 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Fri, 9 Jul 2010 07:49:05 -0700 (PDT) Subject: python instructor In-Reply-To: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> Message-ID: <199679.68964.qm@web120501.mail.ne1.yahoo.com> Where are you located? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Fri, 7/9/10, Greg wrote: > From: Greg > Subject: python instructor > To: python-list at python.org > Date: Friday, July 9, 2010, 10:09 AM > We're looking for a first-rate python > trainer to come to our > organization for a day or two.? We are a small group > of geospatial/ > remote sensing scientists whose research spans the gap > between > environmental accounting/monitoring and policy and human > interaction. > We have about 5-10 (or so) python users (and potential > python users) > who could potentially apply new skills to several in-house > projects. > The difficulty for the teacher would be covering breadth of > experience > we have currently. > > Any thoughts or advice would be greatly appreciated.? > Thanks very > much, > > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From massi_srb at msn.com Fri Jul 9 11:07:23 2010 From: massi_srb at msn.com (Massi) Date: Fri, 9 Jul 2010 08:07:23 -0700 (PDT) Subject: SqlAlchemy: remote connection on problem on mysql database Message-ID: Hi everyone, in my script I'm trying to connect to a remote database using sqlalchemy. Since I'm pretty new to this library I'm not really sure of what I am doing :-). Up to now what I'm doing to connect to the database is this: engine = create_engine("mysql:// my_username:my_password at phpmyadmin.myhost.com/my_db_name") metadata = MetaData(engine, reflect=True) If I run this script I get the following error: Traceback (most recent call last): File "C:\Documents and Settings\pc2\Desktop\prova.py", line 9, in metadata = MetaData(engine, reflect=True) File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg \sqlalchemy\schema.py", line 1770, in __init__ self.reflect() File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg \sqlalchemy\schema.py", line 1879, in reflect connection=conn)) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\base.py", line 1604, in table_names conn = self.contextual_connect() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\base.py", line 1592, in contextual_connect return self.Connection(self, self.pool.connect(), close_with_result=close_with_result, **kwargs) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 154, in connect return _ConnectionFairy(self).checkout() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 318, in __init__ rec = self._connection_record = pool.get() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 173, in get return self.do_get() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 665, in do_get con = self.create_connection() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 134, in create_connection return _ConnectionRecord(self) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 209, in __init__ self.connection = self.__connect() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 271, in __connect connection = self.__pool._creator() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\strategies.py", line 76, in connect return dialect.connect(*cargs, **cparams) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\default.py", line 227, in connect return self.dbapi.connect(*cargs, **cparams) File "C:\Python25\lib\site-packages\MySQLdb\__init__.py", line 74, in Connect return Connection(*args, **kwargs) File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line 170, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (OperationalError) (2003, "Can't connect to MySQL server on 'phpmyadmin.myhost.com' (10060)") None None Is there something I am missing? thanks in advance for the help! From jdixon at omniti.com Fri Jul 9 11:08:19 2010 From: jdixon at omniti.com (Jason Dixon) Date: Fri, 9 Jul 2010 11:08:19 -0400 Subject: Last day to submit your Surge 2010 CFP! Message-ID: <20100709150818.GE4133@omniti.com> Today is your last chance to submit a CFP abstract for the 2010 Surge Scalability Conference. The event is taking place on Sept 30 and Oct 1, 2010 in Baltimore, MD. Surge focuses on case studies that address production failures and the re-engineering efforts that led to victory in Web Applications or Internet Architectures. You can find more information, including suggested topics and our current list of speakers, online: http://omniti.com/surge/2010 The final lineup should be available on the conference website next week. If you have questions about the CFP, attending Surge, or having your business sponsor/exhibit at Surge 2010, please contact us at surge at omniti.com. Thanks! -- Jason Dixon OmniTI Computer Consulting, Inc. jdixon at omniti.com 443.325.1357 x.241 From rtomek at ceti.com.pl Fri Jul 9 11:21:15 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 17:21:15 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Fri, 9 Jul 2010, Tomasz Rola wrote: > On Fri, 9 Jul 2010, Steven D'Aprano wrote: > > > This is a style question rather than a programming question. > > > > How large (how many KB, lines, classes, whatever unit of code you like to > > measure in) should a module grow before I should break it up into a > > package? I see that, for example, decimal.py is > 3000 lines of code, so > > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > > Where do you draw the line? > > > > For the purposes of the discussion, you should consider that the code in > > the module really does belong together, and that splitting it into sub- > > modules would mean arbitrarily separating code into separate files. > > Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with > comments) - if something takes a lot of place to comment, then maybe it > should go to a separate unit. I meant 2-5 KLOC&C. Oups... Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From robin1 at cnsp.com Fri Jul 9 11:30:31 2010 From: robin1 at cnsp.com (Robin) Date: Fri, 9 Jul 2010 08:30:31 -0700 (PDT) Subject: do Message-ID: please, please post a link to my site, http://offlame.thevoid1.net/ also, post free for all links at www.thevoid1.net/ffa -Robin From aahz at pythoncraft.com Fri Jul 9 11:41:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 08:41:57 -0700 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <86vd8qq8cy.fsf@aiuole.stru.polimi.it> Message-ID: In article , Chris Rebert wrote: >On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi wrote: >> "Zooko O'Whielacronx" writes: >>> >>> I'm starting to think that one should use Decimals by default and >>> reserve floats for special cases. >> >> would you kindly lend me your Decimals ruler? i need to measure the >> sides of the triangle whose area i have to compute > >If your ruler doesn't have a [second] set of marks for centimeters and >millimeters, that's really one cheap/cruddy ruler you're using. Unless I'm badly mistaken, Giacomo was making a funny about Greek geometers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From aahz at pythoncraft.com Fri Jul 9 11:47:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 08:47:51 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: In article , Frederic Rentsch wrote: > >Module M says 'from service import *'. >Next I correct a mistake in function 'service.f'. >Now 'service.f' works fine. > >I do 'reload (service); reload (M)'. >The function 'M.f' still misbehaves. Absolutely! >'print inspect.getsource (service.f)' and >'print inspect.getsource (M.f)' shows the same >corrected code. > >'print service.f' and 'print M.f' show different ids. > >So I do 'del M; reload (M)'. Nothing changes. > >I delete M again and run gc.collect () to really clean house. I reload >M again and still nothing changes. The id of the reloaded function >'M.f' is still the same as it was before the purge and so M.f still >isn't fixed. > >I know I have more radical options, such as starting a new IDLE >window. That would save me time, but I'd like to take the opportunity >to understand what is happening. Surely someone out there knows. Take a look at sys.modules to get a better idea of what's happening. (Maybe someone else will have time to write a longer answer.) But really, relying on reload() is foolish in the general case because it's nearly impossible to track down every single reference. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From alf.p.steinbach+usenet at gmail.com Fri Jul 9 11:52:14 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 17:52:14 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? Message-ID: [Cross-posted comp.lang.python and comp.lang.c++] I lack experience with shared libraries in *nix and so I need to ask... This is about "cppy", some support for writing Python extensions in C++ that I just started on (some days ago almost known as "pynis" (not funny after all)). For an extension module it seems that Python requires each routine to be defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern "C"' and C++ linkage, using a routine declared as 'static' in a class as a C callback, formally they're two different kinds, and I seem to recall that /some/ C++ compiler balks at that kind of mixing unless specially instructed to allow it. Perhaps it was the Sun compiler? Anyway, to be formally correct I cannot generate the required C routines via templating, and I ended up using macros that the user must explicitly invoke, like, here the Py doc's first extension module example recoded using cppy, ------------------------------------------------------------------ #include #include using namespace progrock; class Spam: public cppy::Module { public: Spam(): cppy::Module( "spam" ) { setDocString( L"bl?b?rsyltet?y er bl?tt" ); } PyObject* system( PyObject* args ) { const char *command; int sts; if( !PyArg_ParseTuple( args, "s", &command ) ) { return NULL; } sts = ::system( command ); return Py_BuildValue( "i", sts ); } }; CPPY_MODULE_CROUTINE( Spam, system, "Execute a shell command" ) PyMODINIT_FUNC PyInit_spam() { return cppy::init< Spam >(); } ------------------------------------------------------------------ It works in Windows. But here CPPY_MODULE_CROUTINE does three things: A Defining the 'extern "C"' routine. I cannot think of any problem here. B Defining installation data for that routine. Possible problem: initializing a static with address of routine? C -> Adding that install data record into a linked list! Possible problem: are dynamic initialization actions guaranteed to be performed in *nix shared library? Problem (C) is outside the realm of the C++ standard, since the C++ standard doesn't support shared libraries, and I've never actually used *nix shared libraries so I don't /know/... Is such dynamic initialization guaranteed? For completeness, the macro definition (the 0 in there is a list next-pointer): #define CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ extern "C" \ static PyObject* cppClassName##_##name( PyObject*, PyObject* args ) \ { \ return ::progrock::cppy::module().name( args ); \ } #define CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) \ static ::progrock::cppy::detail::ModuleRoutineDescriptor \ cppClassName##_##name##_descriptor = { \ 0, \ #name, \ docString, \ &cppClassName##_##name \ }; \ \ static bool cppClassName##_##name##_descriptor_installed = \ ::progrock::cppy::detail::addToList< cppClassName >( \ cppClassName##_##name##_descriptor \ ); #define CPPY_MODULE_CROUTINE( cppClassName, name, docString ) \ CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) TIA., - Alf -- blog at From wentlv at gmail.com Fri Jul 9 11:58:35 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 08:58:35 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? Message-ID: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Hi, everyone I'm a new hand at python. I tried to set system default encoding by using "import sys; sys.setdefaultencoding('utf-f')", but I got error message: >>> sys.setdefaultencoding('utf-8') Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'setdefaultencoding' Then I checked dir(sys), seems there was no function named "setdefaultencoding" in "sys" module. But in python's document, it said I should use sys.setdefaultencoding. So, my questions: why there is no setdefaultencoding in sys module? if I want to change system's default encoding, what should I do? Thanks in advance From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 11:58:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 15:58:38 GMT Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: <4c37472e$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 15:02:25 +0200, Frederic Rentsch wrote: > I develop in an IDLE window. > > Module M says 'from service import *'. Next I correct a mistake in > function 'service.f'. Now 'service.f' works fine. from service import * should be considered advanced functionality that is discouraged unless you really know what you are doing, precisely for the problems you are experiencing. You should try to avoid it. But putting that aside, if you have done "from service import *" in module m, where are you getting "service.f" from? The only way that is possible is if you ALSO say "import service". > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. > > 'print inspect.getsource (service.f)' and 'print inspect.getsource > (M.f)' shows the same corrected code. inspect.getsource always looks at the source code on disk, no matter what the byte code in memory actually says. > 'print service.f' and 'print M.f' show different ids. > > So I do 'del M; reload (M)'. Nothing changes. > > I delete M again and run gc.collect () to really clean house. I reload M > again and still nothing changes. The id of the reloaded function 'M.f' > is still the same as it was before the purge and so M.f still isn't > fixed. > > I know I have more radical options, such as starting a new IDLE window. > That would save me time, but I'd like to take the opportunity to > understand what is happening. Surely someone out there knows. Yes. You have to understand importing. Let's start with the simple: import m In *very* simplified pseudo-code, this does: look for module m in the global cache if not there, then: search for m.py compile it to a Module object put the Module object in the cache create a new name "m" in the local namespace set the name "m" to the Module object in the cache Now let's compare it to: from m import f look for module m in the global cache if not there, then: search for m.py compile it to a Module object put the Module object in the cache look for object named "f" in the Module object create a new name "f" in the local namespace set the name "f" to cached object The important thing to notice is the the name "f" is a local variable. It doesn't, and can't, remember that it comes from module m. Reloading m can't do anything to f, because the connection is lost. Now consider that the object "f" that came from m was itself imported from another module, "service". Reloading service doesn't help, because m.f doesn't know it came from service. Reloading m doesn't help, because all that does is run "from service import f" again, and that just fetches f from the global cache. The simplest, easiest way of dealing with this is not to have to deal with it: don't use "from service import f", and ESPECIALLY don't use "from service import *". Always use fully-qualified importing: import service service.f Now "reload(service)" should do what you expect. The other way is not to bother with reload. It's not very powerful, only good for the simplest use in the interactive interpreter. Just exit the interpreter and restart it. -- Steven From martin.hellwig at dcuktec.org Fri Jul 9 12:03:21 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 09 Jul 2010 17:03:21 +0100 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 07/09/10 05:37, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > Personally I like to split up my module quite early and the main criteria is whether this improves (IMO) maintainability. So if I can refactor stuff that with some adaption can be used multiple times I put it in its own module. I rarely exceed 1KLOC per module and on average are on half of that. -- mph From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 12:04:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 16:04:02 GMT Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Message-ID: <4c374872$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > So, my questions: why there is no setdefaultencoding in sys module? if I > want to change system's default encoding, what should I do? I think the answer is: Don't. If you do, you will break built-ins. http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/ Googling will find many discussions about this. -- Steven From wentlv at gmail.com Fri Jul 9 12:06:41 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 09:06:41 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> Message-ID: <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> On Jul 10, 12:04?am, Steven D'Aprano wrote: > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > So, my questions: why there is no setdefaultencoding in sys module? if I > > want to change system's default encoding, what should I do? > > I think the answer is: > > Don't. > > If you do, you will break built-ins. > > http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > Googling will find many discussions about this. > > -- > Steven Interesting, so it has been removed from python? then why it's still in document... It's really misleading. Thanks for your quick answer From wentlv at gmail.com Fri Jul 9 12:16:42 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 09:16:42 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> Message-ID: <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> On Jul 10, 12:06?am, crow wrote: > On Jul 10, 12:04?am, Steven D'Aprano > > > > > cybersource.com.au> wrote: > > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > > So, my questions: why there is no setdefaultencoding in sys module? if I > > > want to change system's default encoding, what should I do? > > > I think the answer is: > > > Don't. > > > If you do, you will break built-ins. > > >http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > > Googling will find many discussions about this. > > > -- > > Steven > > Interesting, so it has been removed from python? then why it's still > in document... It's really misleading. > > Thanks for your quick answer oh, I take back my words, it's still there, just I need to reload(sys). From puntabluda at gmail.com Fri Jul 9 12:20:53 2010 From: puntabluda at gmail.com (Rebelo) Date: Fri, 9 Jul 2010 09:20:53 -0700 (PDT) Subject: SqlAlchemy: remote connection on problem on mysql database References: Message-ID: <8f2b52af-fe20-4219-b54c-7992f3177982@k39g2000yqb.googlegroups.com> from SQLAlchemy docs (http://www.sqlalchemy.org/docs/ dbengine.html#database-engine-options): " create_engine() URL Arguments SQLAlchemy indicates the source of an Engine strictly via RFC-1738 style URLs, combined with optional keyword arguments to specify options for the Engine. The form of the URL is: dialect+driver://username:password at host:port/database Dialect names include the identifying name of the SQLAlchemy dialect which include sqlite, mysql, postgresql, oracle, mssql, and firebird. The drivername is the name of the DBAPI to be used to connect to the database using all lowercase letters. If not specified, a ?default? DBAPI will be imported if available - this default is typically the most widely known driver available for that backend (i.e. cx_oracle, pysqlite/sqlite3, psycopg2, mysqldb). " are you sure that phpmyadmin.myhost.com is your mysql server? or are you missing port? usually its 3306. AFAIK From nitinpawar432 at gmail.com Fri Jul 9 12:27:14 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 9 Jul 2010 21:57:14 +0530 Subject: Netbeans plugin and Python 3 Message-ID: Hi, I never tried python3.0 with netbeans but I use python 2.6.5 with netbean 6.7.1 Here is how I managed to change from python 2.5 (netbeans default) to 2.6.5 1) From the tools-> plugins section install python plugin 2) Once plugin is installed just restart netbeans so that plugin is activated 3) After plugin is activated, you can edit default python version by tools-> python platform 4) It will open a configure window, where you can point python to newly installed 3.0 version. I hope that helps. Thanks, nitin On Fri, Jul 9, 2010 at 9:30 PM, wrote: > 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. python instructor (Greg) > 2. Re: ipython problem in opening a file (Youngung Jeong) > 3. Netbeans plugin and Python 3 (Chrix) > 4. Re: python instructor (Ed Keith) > 5. Last day to submit your Surge 2010 CFP! (Jason Dixon) > 6. SqlAlchemy: remote connection on problem on mysql database (Massi) > 7. do (Robin) > 8. Re: Opinions please -- how big should a single module grow? > (Tomasz Rola) > 9. Re: Python -- floating point arithmetic (Aahz) > 10. Re: 'reload M' doesn't update 'from M inport *' (Aahz) > 11. Cpp + Python: static data dynamic initialization in *nix > shared lib? (Alf P. Steinbach /Usenet) > 12. Why there is no "setdefaultencoding" in sys module? (crow) > > > ---------- Forwarded message ---------- > From: Greg > To: python-list at python.org > Date: Fri, 9 Jul 2010 07:09:13 -0700 (PDT) > Subject: python instructor > We're looking for a first-rate python trainer to come to our > organization for a day or two. We are a small group of geospatial/ > remote sensing scientists whose research spans the gap between > environmental accounting/monitoring and policy and human interaction. > We have about 5-10 (or so) python users (and potential python users) > who could potentially apply new skills to several in-house projects. > The difficulty for the teacher would be covering breadth of experience > we have currently. > > Any thoughts or advice would be greatly appreciated. Thanks very > much, > > Greg > > > > ---------- Forwarded message ---------- > From: Youngung Jeong > To: Eli Bendersky > Date: Fri, 9 Jul 2010 23:27:08 +0900 > Subject: Re: ipython problem in opening a file > Thanks a lot! > > Youngung > > > On Fri, Jul 9, 2010 at 10:17 PM, Eli Bendersky wrote: > >> On Fri, Jul 9, 2010 at 16:07, Youngung Jeong >> wrote: >> > Thank you for your kindness. >> > I found you're right. It's running in that folder. >> > What should I do for making this work? >> > Could you please tell me a bit more... >> > >> > Youngung >> >> You can change the "current directory" ipython executes in, by either >> executing it directly (from the command line) in the directory of your >> choice, or calling the os.chdir function with the path of your choice. >> >> Eli >> > > > > ---------- Forwarded message ---------- > From: Chrix > To: python-list at python.org > Date: Fri, 9 Jul 2010 07:26:24 -0700 (PDT) > Subject: Netbeans plugin and Python 3 > Hi, > > Someone knows if Netbeans will support Python 3 language features? > Nowadays, I tried Netbeans 6.9 but it only supports Python 2.5 :( > And I'd like really to develop with Python 3. > > Thanks. > > > > ---------- Forwarded message ---------- > From: Ed Keith > To: python-list at python.org, Greg > Date: Fri, 9 Jul 2010 07:49:05 -0700 (PDT) > Subject: Re: python instructor > Where are you located? > > -EdK > > Ed Keith > e_d_k at yahoo.com > > Blog: edkeith.blogspot.com > > > --- On Fri, 7/9/10, Greg wrote: > > > From: Greg > > Subject: python instructor > > To: python-list at python.org > > Date: Friday, July 9, 2010, 10:09 AM > > We're looking for a first-rate python > > trainer to come to our > > organization for a day or two. We are a small group > > of geospatial/ > > remote sensing scientists whose research spans the gap > > between > > environmental accounting/monitoring and policy and human > > interaction. > > We have about 5-10 (or so) python users (and potential > > python users) > > who could potentially apply new skills to several in-house > > projects. > > The difficulty for the teacher would be covering breadth of > > experience > > we have currently. > > > > Any thoughts or advice would be greatly appreciated. > > Thanks very > > much, > > > > Greg > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > ---------- Forwarded message ---------- > From: Jason Dixon > To: python-list at python.org > Date: Fri, 9 Jul 2010 11:08:19 -0400 > Subject: Last day to submit your Surge 2010 CFP! > Today is your last chance to submit a CFP abstract for the 2010 Surge > Scalability Conference. The event is taking place on Sept 30 and Oct 1, > 2010 in Baltimore, MD. Surge focuses on case studies that address > production failures and the re-engineering efforts that led to victory > in Web Applications or Internet Architectures. > > You can find more information, including suggested topics and our > current list of speakers, online: > > http://omniti.com/surge/2010 > > The final lineup should be available on the conference website next > week. If you have questions about the CFP, attending Surge, or having > your business sponsor/exhibit at Surge 2010, please contact us at > surge at omniti.com. > > Thanks! > > -- > Jason Dixon > OmniTI Computer Consulting, Inc. > jdixon at omniti.com > 443.325.1357 x.241 > > > > ---------- Forwarded message ---------- > From: Massi > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:07:23 -0700 (PDT) > Subject: SqlAlchemy: remote connection on problem on mysql database > Hi everyone, > > in my script I'm trying to connect to a remote database using > sqlalchemy. Since I'm pretty new to this library I'm not really sure > of what I am doing :-). Up to now what I'm doing to connect to the > database is this: > > engine = create_engine("mysql:// > my_username:my_password at phpmyadmin.myhost.com/my_db_name") > metadata = MetaData(engine, reflect=True) > > If I run this script I get the following error: > > Traceback (most recent call last): > File "C:\Documents and Settings\pc2\Desktop\prova.py", line 9, in > > metadata = MetaData(engine, reflect=True) > File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg > \sqlalchemy\schema.py", line 1770, in __init__ > self.reflect() > File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg > \sqlalchemy\schema.py", line 1879, in reflect > connection=conn)) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\base.py", line 1604, in table_names > conn = self.contextual_connect() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\base.py", line 1592, in contextual_connect > return self.Connection(self, self.pool.connect(), > close_with_result=close_with_result, **kwargs) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 154, in connect > return _ConnectionFairy(self).checkout() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 318, in __init__ > rec = self._connection_record = pool.get() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 173, in get > return self.do_get() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 665, in do_get > con = self.create_connection() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 134, in create_connection > return _ConnectionRecord(self) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 209, in __init__ > self.connection = self.__connect() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 271, in __connect > connection = self.__pool._creator() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\strategies.py", line 76, in connect > return dialect.connect(*cargs, **cparams) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\default.py", line 227, in connect > return self.dbapi.connect(*cargs, **cparams) > File "C:\Python25\lib\site-packages\MySQLdb\__init__.py", line 74, > in Connect > return Connection(*args, **kwargs) > File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line > 170, in __init__ > super(Connection, self).__init__(*args, **kwargs2) > OperationalError: (OperationalError) (2003, "Can't connect to MySQL > server on 'phpmyadmin.myhost.com' (10060)") None None > > Is there something I am missing? thanks in advance for the help! > > > > ---------- Forwarded message ---------- > From: Robin > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:30:31 -0700 (PDT) > Subject: do > please, please post a link to my site, http://offlame.thevoid1.net/ > > also, post free for all links at www.thevoid1.net/ffa > > -Robin > > > > ---------- Forwarded message ---------- > From: Tomasz Rola > To: python-list at python.org > Date: Fri, 9 Jul 2010 17:21:15 +0200 > Subject: Re: Opinions please -- how big should a single module grow? > On Fri, 9 Jul 2010, Tomasz Rola wrote: > > > On Fri, 9 Jul 2010, Steven D'Aprano wrote: > > > > > This is a style question rather than a programming question. > > > > > > How large (how many KB, lines, classes, whatever unit of code you like > to > > > measure in) should a module grow before I should break it up into a > > > package? I see that, for example, decimal.py is > 3000 lines of code, > so > > > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > > > Where do you draw the line? > > > > > > For the purposes of the discussion, you should consider that the code > in > > > the module really does belong together, and that splitting it into sub- > > > modules would mean arbitrarily separating code into separate files. > > > > Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with > > comments) - if something takes a lot of place to comment, then maybe it > > should go to a separate unit. > > I meant 2-5 KLOC&C. Oups... > > Regards, > Tomasz Rola > > -- > ** A C programmer asked whether computer had Buddha's nature. ** > ** As the answer, master did "rm -rif" on the programmer's home ** > ** directory. And then the C programmer became enlightened... ** > ** ** > ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 9 Jul 2010 08:41:57 -0700 > Subject: Re: Python -- floating point arithmetic > In article , > Chris Rebert wrote: > >On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi > wrote: > >> "Zooko O'Whielacronx" writes: > >>> > >>> I'm starting to think that one should use Decimals by default and > >>> reserve floats for special cases. > >> > >> would you kindly lend me your Decimals ruler? i need to measure the > >> sides of the triangle whose area i have to compute > > > >If your ruler doesn't have a [second] set of marks for centimeters and > >millimeters, that's really one cheap/cruddy ruler you're using. > > Unless I'm badly mistaken, Giacomo was making a funny about Greek > geometers. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 9 Jul 2010 08:47:51 -0700 > Subject: Re: 'reload M' doesn't update 'from M inport *' > In article , > Frederic Rentsch wrote: > > > >Module M says 'from service import *'. > >Next I correct a mistake in function 'service.f'. > >Now 'service.f' works fine. > > > >I do 'reload (service); reload (M)'. > >The function 'M.f' still misbehaves. > > Absolutely! > > >'print inspect.getsource (service.f)' and > >'print inspect.getsource (M.f)' shows the same > >corrected code. > > > >'print service.f' and 'print M.f' show different ids. > > > >So I do 'del M; reload (M)'. Nothing changes. > > > >I delete M again and run gc.collect () to really clean house. I reload > >M again and still nothing changes. The id of the reloaded function > >'M.f' is still the same as it was before the purge and so M.f still > >isn't fixed. > > > >I know I have more radical options, such as starting a new IDLE > >window. That would save me time, but I'd like to take the opportunity > >to understand what is happening. Surely someone out there knows. > > Take a look at sys.modules to get a better idea of what's happening. > (Maybe someone else will have time to write a longer answer.) > > But really, relying on reload() is foolish in the general case because > it's nearly impossible to track down every single reference. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > > > > ---------- Forwarded message ---------- > From: "Alf P. Steinbach /Usenet" > > > To: python-list at python.org > Date: Fri, 09 Jul 2010 17:52:14 +0200 > Subject: Cpp + Python: static data dynamic initialization in *nix shared > lib? > [Cross-posted comp.lang.python and comp.lang.c++] > > I lack experience with shared libraries in *nix and so I need to ask... > > This is about "cppy", some support for writing Python extensions in C++ > that I just started on (some days ago almost known as "pynis" (not funny > after all)). > > For an extension module it seems that Python requires each routine to be > defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern "C"' > and C++ linkage, using a routine declared as 'static' in a class as a C > callback, formally they're two different kinds, and I seem to recall that > /some/ C++ compiler balks at that kind of mixing unless specially instructed > to allow it. Perhaps it was the Sun compiler? > > Anyway, to be formally correct I cannot generate the required C routines > via templating, and I ended up using macros that the user must explicitly > invoke, like, here the Py doc's first extension module example recoded using > cppy, > > > ------------------------------------------------------------------ > > #include > #include > using namespace progrock; > > class Spam: public cppy::Module > { > public: > Spam(): cppy::Module( "spam" ) > { > setDocString( L"bl?b?rsyltet?y er bl?tt" ); > } > > PyObject* system( PyObject* args ) > { > const char *command; > int sts; > > if( !PyArg_ParseTuple( args, "s", &command ) ) > { > return NULL; > } > sts = ::system( command ); > return Py_BuildValue( "i", sts ); > } > }; > > CPPY_MODULE_CROUTINE( Spam, system, "Execute a shell command" ) > > PyMODINIT_FUNC PyInit_spam() > { > return cppy::init< Spam >(); > } > > ------------------------------------------------------------------ > > > It works in Windows. > > But here CPPY_MODULE_CROUTINE does three things: > > A Defining the 'extern "C"' routine. > I cannot think of any problem here. > > B Defining installation data for that routine. > Possible problem: initializing a static with address of routine? > > C -> Adding that install data record into a linked list! > Possible problem: are dynamic initialization actions guaranteed > to be performed in *nix shared library? > > Problem (C) is outside the realm of the C++ standard, since the C++ > standard doesn't support shared libraries, and I've never actually used *nix > shared libraries so I don't /know/... > > Is such dynamic initialization guaranteed? > > For completeness, the macro definition (the 0 in there is a list > next-pointer): > > > > #define CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ > extern "C" \ > static PyObject* cppClassName##_##name( PyObject*, PyObject* args ) \ > { \ > return ::progrock::cppy::module().name( args ); \ > } > > #define CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) > \ > static ::progrock::cppy::detail::ModuleRoutineDescriptor > \ > cppClassName##_##name##_descriptor = { > \ > 0, > \ > #name, > \ > docString, > \ > &cppClassName##_##name > \ > }; > \ > > \ > static bool cppClassName##_##name##_descriptor_installed = > \ > ::progrock::cppy::detail::addToList< cppClassName >( > \ > cppClassName##_##name##_descriptor > \ > ); > > #define CPPY_MODULE_CROUTINE( cppClassName, name, docString ) > \ > CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) > \ > CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) > > > > TIA., > > - Alf > > -- > blog at > > > > ---------- Forwarded message ---------- > From: crow > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:58:35 -0700 (PDT) > Subject: Why there is no "setdefaultencoding" in sys module? > Hi, everyone > > I'm a new hand at python. > > I tried to set system default encoding by using > > "import sys; sys.setdefaultencoding('utf-f')", > > but I got error message: > > >>> sys.setdefaultencoding('utf-8') > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'setdefaultencoding' > > Then I checked dir(sys), seems there was no function named > "setdefaultencoding" in "sys" module. But in python's document, it > said I should use sys.setdefaultencoding. > > So, my questions: why there is no setdefaultencoding in sys module? if > I want to change system's default encoding, what should I do? > > Thanks in advance > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dani.valverde at gmail.com Fri Jul 9 12:31:36 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Fri, 09 Jul 2010 18:31:36 +0200 Subject: Hello Message-ID: <4C374EE8.4060404@gmail.com> Hello! I am new to python and pretty new to programming (I have some expertise wit R statistical programming language). I am just starting, so my questions may be a little bit stupid. Can anyone suggest a good editor for python? Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From thomas at jollans.com Fri Jul 9 12:35:34 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 18:35:34 +0200 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> Message-ID: <4C374FD6.8070300@jollans.com> On 07/09/2010 06:06 PM, crow wrote: > On Jul 10, 12:04 am, Steven D'Aprano cybersource.com.au> wrote: >> On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: >>> So, my questions: why there is no setdefaultencoding in sys module? if I >>> want to change system's default encoding, what should I do? >> >> I think the answer is: >> >> Don't. >> >> If you do, you will break built-ins. >> >> http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... >> >> Googling will find many discussions about this. >> >> -- >> Steven > > Interesting, so it has been removed from python? then why it's still > in document... It's really misleading. Actually, it's still there. Lurking in the corners of sys. But site.py knows it's evil: % python Python 2.6.5+ (release26-maint, Jul 6 2010, 12:58:20) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.setdefaultencoding Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'setdefaultencoding' >>> reload(sys) >>> sys.setdefaultencoding >>> From animator333 at gmail.com Fri Jul 9 12:36:11 2010 From: animator333 at gmail.com (King) Date: Fri, 9 Jul 2010 09:36:11 -0700 (PDT) Subject: zipimport (.pyd & .so) files. Message-ID: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Hi, The 'zipimport' modules can only import (.py & .pyc) files from a zip file and doesn't support importing .pyd & .so files. Recently I was examining the code of Py2Exe (python package deployment tool) and I have found that it is using a module 'zipextimporter' that can import dlls(.pyd) modules from a zip file. It is based on the concept of loading library form memory. You can find out more about here: http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ It's strictly for windows platform. I would like to know from expert python users and linux programmers, how we can achieve similar functionality on linux platform? I do have limited c/c++ skill sets but I would love to give a try. Cheers Prashant From alf.p.steinbach+usenet at gmail.com Fri Jul 9 12:37:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 18:37:59 +0200 Subject: Hello In-Reply-To: References: Message-ID: * Dani Valverde, on 09.07.2010 18:31: > Hello! > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? > Cheers! If you're working in Windows the Notepad++ and PSPad and old Crimson Editor (all free) all work nicely and are reasonably light-weight. Cheers & hth., - Alf -- blog at From airscorp at otenet.gr Fri Jul 9 12:41:43 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Fri, 09 Jul 2010 19:41:43 +0300 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C375147.9030708@otenet.gr> > I know I have more radical options, such as starting > a new IDLE window. That would save me time, but > I'd like to take the opportunity to understand what > is happening. Surely someone out there knows. > > Frederic > > Or you can restart the IDLE shell with CTRL+F6. If you can't restart it, you're probably not using an IDLE subprocess: On linux, make sure the menu item doesn't use "-n" in the command On Windows, first open IDLE, then open the file, or change the Open command to not use the "-n" flag. Sorry to not chip in to your question, frankly, Steven nailed it! Just thought to share an IDLE tip :) Nick From invalid at invalid.invalid Fri Jul 9 12:49:20 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Subject: Hello References: Message-ID: On 2010-07-09, Dani Valverde wrote: > I am new to python and pretty new to programming (I have some > expertise wit R statistical programming language). I am just > starting, so my questions may be a little bit stupid. Can anyone > suggest a good editor for python? Emacs, Scite (has nice folding), Vim, Eclipse. -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From rhodri at wildebst.demon.co.uk Fri Jul 9 12:59:59 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 09 Jul 2010 17:59:59 +0100 Subject: Hello References: Message-ID: On Fri, 09 Jul 2010 17:31:36 +0100, Dani Valverde wrote: > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? Whatever you feel most comfortable with. Idle comes packaged with Python, but can be a bit limited. If you can stand the learning curve (and a lot of people can't, it seems), Emacs and Vim are highly configurable and offer a lot of language-specific convenience functions. Basically, try a few different editors out and see what style you like. -- Rhodri James *-* Wildebeeste Herder to the Masses From airscorp at otenet.gr Fri Jul 9 13:02:00 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Fri, 09 Jul 2010 20:02:00 +0300 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: <4C375608.2000905@otenet.gr> Hello Dani! IDLE is very friendly for new users and has got me a long way when I was starting. You also can't beat that it comes bundled with Python. I'd also like to suggest the Python-Tutor list http://mail.python.org/mailman/listinfo/tutor for your "new-user" questions. Lots of helpful folk there, myself included. Nick On 07/09/2010 07:31 PM, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some > expertise wit R statistical programming language). I am just starting, > so my questions may be a little bit stupid. Can anyone suggest a good > editor for python? > Cheers! > > Dani > From sturlamolden at yahoo.no Fri Jul 9 13:03:42 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 9 Jul 2010 10:03:42 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <25863592-e417-4157-bbfb-1743e6889fb1@z10g2000yqb.googlegroups.com> Message-ID: On 9 Jul, 15:25, Felix wrote: > PS: No need to convince me that MATLAB is not the solution. What I mean is that Matlab and Mathematica are inherently "single threaded" interpreters. Yet they are still used for serious parallel computing. While Python has multiple threads but a GIL, only allowing one thread in the interpreter is even more restrictive. From bradley.h at aggiemail.usu.edu Fri Jul 9 13:03:43 2010 From: bradley.h at aggiemail.usu.edu (Bradley Hintze) Date: Fri, 9 Jul 2010 13:03:43 -0400 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: There are lots of great editors out there. It really depends on personal preference. It also depends on your OS. I us Mac OSX and like jEdit (my lab mate likes bbEdit). When I was on windows I liked notepad2. On linux i really like gEdit. Any of these will work great for a beginner! Bradley On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise wit > R statistical programming language). I am just starting, so my questions may > be a little bit stupid. Can anyone suggest a good editor for python? > Cheers! > > Dani > > -- > Daniel Valverde Saub? > c/Joan Maragall 37 4 2 > 17002 Girona > Spain > Tel?fon m?bil: +34651987662 > e-mail: dani.valverde at gmail.com > http://www.acrocephalus.net > http://natupics.blogspot.com > > Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas > utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera > ajudar?s a estalviar aigua, energia i recursos forestals. ?GR?CIES! > > Do not print this message unless it is absolutely necessary. If you must > print it, please use 100% recycled paper whitened without chlorine. By doing > so, you will save water, energy and forest resources. THANK YOU! > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From dani.valverde at gmail.com Fri Jul 9 13:08:19 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Fri, 09 Jul 2010 19:08:19 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> Message-ID: <4C375783.7090700@gmail.com> Sorry, I forgot to mention that I am using Linux. In fact, my first test have been with gedit. Is there any way to directly run the Python code into the console? Cheers! Dani Bradley Hintze wrote: > There are lots of great editors out there. It really depends on > personal preference. It also depends on your OS. I us Mac OSX and like > jEdit (my lab mate likes bbEdit). When I was on windows I liked > notepad2. On linux i really like gEdit. Any of these will work great > for a beginner! > > Bradley > > > On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde wrote: > >> Hello! >> I am new to python and pretty new to programming (I have some expertise wit >> R statistical programming language). I am just starting, so my questions may >> be a little bit stupid. Can anyone suggest a good editor for python? >> Cheers! >> >> Dani >> >> -- >> Daniel Valverde Saub? >> c/Joan Maragall 37 4 2 >> 17002 Girona >> Spain >> Tel?fon m?bil: +34651987662 >> e-mail: dani.valverde at gmail.com >> http://www.acrocephalus.net >> http://natupics.blogspot.com >> >> Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas >> utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera >> ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! >> >> Do not print this message unless it is absolutely necessary. If you must >> print it, please use 100% recycled paper whitened without chlorine. By doing >> so, you will save water, energy and forest resources. THANK YOU! >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > > -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From lists at cheimes.de Fri Jul 9 13:25:31 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 19:25:31 +0200 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> Message-ID: > oh, I take back my words, it's still there, just I need to > reload(sys). Just don't. If you change the default encoding you are going to break important data structures like dicts in a subtle and hard to detect way. If your application needs to change the default encoding, it's broken. The function is removed for a very good reaso. From jeanmichel at sequans.com Fri Jul 9 13:38:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 09 Jul 2010 19:38:18 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C375E8A.6080506@sequans.com> Frederic Rentsch wrote: > I develop in an IDLE window. > > Module M says 'from service import *'. > Next I correct a mistake in function 'service.f'. > Now 'service.f' works fine. > > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. > > 'print inspect.getsource (service.f)' and > 'print inspect.getsource (M.f)' shows the same > corrected code. > > 'print service.f' and 'print M.f' show different ids. > > So I do 'del M; reload (M)'. Nothing changes. > > I delete M again and run gc.collect () to really > clean house. I reload M again and still nothing changes. > The id of the reloaded function 'M.f' is still the > same as it was before the purge and so M.f still isn't > fixed. > > I know I have more radical options, such as starting > a new IDLE window. That would save me time, but > I'd like to take the opportunity to understand what > is happening. Surely someone out there knows. > > Frederic > > > > > > Hi, Don't use reload, this is nothing but a trap, espacially if your using it to update your objects with the code you are writting. JM PS : You're misusing the del statement. It does not remove any object from mmory, however, it removes the reference to it, the object is still in memory. They are very few cases where del is usefull in python, so try to avoid using it as well. From thomas at jollans.com Fri Jul 9 13:48:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 19:48:53 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <4C376105.20008@jollans.com> On 07/09/2010 06:36 PM, King wrote: > Hi, > > The 'zipimport' modules can only import (.py & .pyc) files from a zip > file and doesn't support importing .pyd & .so files. Recently I was > examining the code of Py2Exe (python package deployment tool) and I > have found that it is using a module 'zipextimporter' that can import > dlls(.pyd) modules from a zip file. > It is based on the concept of loading library form memory. You can > find out more about here: > http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ > > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. I don't think it's possible as such: On UNIX systems, dynamic module loading is done with the dl* functions in libdl. From the manual installed on my machine: void *dlopen(const char *filename, int flag); char *dlerror(void); void *dlsym(void *handle, const char *symbol); int dlclose(void *handle); Link with -ldl. dlopen() takes a file name. It is, as far as I know, the only, or at least the only portable way to load a shared object. There might be some way to load so's from memory on certain Unices, but these would only work on one system (and I doubt they exist anyway) So you'd have to extract the file, and make it available through the file system. This would typically mean creating a file under /tmp (or possibly under $HOME/.cache/...) Cheers Thomas > > Cheers > > Prashant > From thomas at jollans.com Fri Jul 9 13:58:10 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 19:58:10 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <4C376332.2040308@jollans.com> On 07/09/2010 06:36 PM, King wrote: > Hi, > > The 'zipimport' modules can only import (.py & .pyc) files from a zip > file and doesn't support importing .pyd & .so files. Recently I was > examining the code of Py2Exe (python package deployment tool) and I > have found that it is using a module 'zipextimporter' that can import > dlls(.pyd) modules from a zip file. > It is based on the concept of loading library form memory. You can > find out more about here: > http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ I just had a quick look at that article (I hadn't before). It's probably possible to do something similar on other systems: In principle, you can know the layout of an .so, and then manually load it. But, basically, don't. While supporting Linux itself might not be too difficult (you can use the libdl (or kernel?) sources as a reference, I expect), but supporting multiple UNIX variants is almost certainly very, very difficult. Maybe there are some actual experts around with a different view, but I'd recommend, to load object code not directly accessible via the file system, put it in the file system! > > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. > > Cheers > > Prashant > From lists at cheimes.de Fri Jul 9 13:58:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 19:58:54 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. I don't know any way to load a shared library from something other than a file on the file system. Unless you find a variant of dlopen() that supports memory segments, you are out of luck. From jeanmichel at sequans.com Fri Jul 9 13:59:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 09 Jul 2010 19:59:00 +0200 Subject: Hello In-Reply-To: <4C375783.7090700@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: <4C376364.9020405@sequans.com> Dani Valverde wrote: > Sorry, I forgot to mention that I am using Linux. In fact, my first > test have been with gedit. Is there any way to directly run the Python > code into the console? > > Cheers! > > Dani > > Bradley Hintze wrote: >> There are lots of great editors out there. It really depends on >> personal preference. It also depends on your OS. I us Mac OSX and like >> jEdit (my lab mate likes bbEdit). When I was on windows I liked >> notepad2. On linux i really like gEdit. Any of these will work great >> for a beginner! >> >> Bradley >> >> >> On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde >> wrote: >> >>> Hello! >>> I am new to python and pretty new to programming (I have some >>> expertise wit >>> R statistical programming language). I am just starting, so my >>> questions may >>> be a little bit stupid. Can anyone suggest a good editor for python? >>> Cheers! >>> >>> Dani > Welcome Dani, Please do not top post. vim & emacs are the most featured text editors, they are suitable for any language. If you want something more oriented towards python, have a try with "eric", that's the IDE name. The name's sucks a lot but I discovered it recently from an annoucement in this list, and I found it pretty impressive. Integrated shell, debugger, linter, refactoring plugin, UI designers etc... JM From rtomek at ceti.com.pl Fri Jul 9 14:03:59 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 20:03:59 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: And just in case... A real life example (my computer, more or less typical Linux setup): find / -type f -name '*.py' -exec wc {} \; | gawk '{ l+=$1; } END {print l / FNR; } BEGIN { l=0; }' (the two lines should be concatenated) This gives a mean: 269.069 So, if I did not screw something, a typical Python code size is far below 1KLOC (wc counts all lines, so my result includes all comments and blanks too). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From no.email at nospam.invalid Fri Jul 9 14:21:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 09 Jul 2010 11:21:32 -0700 Subject: Opinions please -- how big should a single module grow? References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <7x4og8v7mb.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? I'd tend to say 2-4 KLOC, basically the max size in which it's reasonable to scroll through the file and read what it's doing, navigate around it with an editor, etc. Some exceptions are possible. From anthra.norell at bluewin.ch Fri Jul 9 14:38:43 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 20:38:43 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <4c37472e$0$28647$c3e8da3@news.astraweb.com> References: <4c37472e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <1278700723.2362.45.camel@hatchbox-one> On Fri, 2010-07-09 at 15:58 +0000, Steven D'Aprano wrote: > On Fri, 09 Jul 2010 15:02:25 +0200, Frederic Rentsch wrote: > > > I develop in an IDLE window. > > > > Module M says 'from service import *'. Next I correct a mistake in > > function 'service.f'. Now 'service.f' works fine. > > from service import * > > should be considered advanced functionality that is discouraged unless > you really know what you are doing, precisely for the problems you are > experiencing. You should try to avoid it. > > But putting that aside, if you have done "from service import *" in > module m, where are you getting "service.f" from? The only way that is > possible is if you ALSO say "import service". > > > > I do 'reload (service); reload (M)'. > > The function 'M.f' still misbehaves. > > > > 'print inspect.getsource (service.f)' and 'print inspect.getsource > > (M.f)' shows the same corrected code. > > inspect.getsource always looks at the source code on disk, no matter what > the byte code in memory actually says. > > > 'print service.f' and 'print M.f' show different ids. > > > > So I do 'del M; reload (M)'. Nothing changes. > > > > I delete M again and run gc.collect () to really clean house. I reload M > > again and still nothing changes. The id of the reloaded function 'M.f' > > is still the same as it was before the purge and so M.f still isn't > > fixed. > > > > I know I have more radical options, such as starting a new IDLE window. > > That would save me time, but I'd like to take the opportunity to > > understand what is happening. Surely someone out there knows. > > Yes. You have to understand importing. Let's start with the simple: > > import m > > In *very* simplified pseudo-code, this does: > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > create a new name "m" in the local namespace > set the name "m" to the Module object in the cache > > Now let's compare it to: > > from m import f > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > look for object named "f" in the Module object > create a new name "f" in the local namespace > set the name "f" to cached object > > The important thing to notice is the the name "f" is a local variable. It > doesn't, and can't, remember that it comes from module m. Reloading m > can't do anything to f, because the connection is lost. > > Now consider that the object "f" that came from m was itself imported > from another module, "service". Reloading service doesn't help, because > m.f doesn't know it came from service. Reloading m doesn't help, because > all that does is run "from service import f" again, and that just fetches > f from the global cache. > > The simplest, easiest way of dealing with this is not to have to deal > with it: don't use "from service import f", and ESPECIALLY don't use > "from service import *". Always use fully-qualified importing: > > import service > service.f > > Now "reload(service)" should do what you expect. > > The other way is not to bother with reload. It's not very powerful, only > good for the simplest use in the interactive interpreter. Just exit the > interpreter and restart it. > > > -- > Steven Thank you very much for your excellent explanation! I must say that I haven't been using the "from soandso import ..." formula at all. I thought it might expose names to collision, and why should I assume the responsibility if I can avoid the problem altogether using explicit names. If I used the, shall we say, "direct import" this time it was in an effort to develop a more extensive program. I thought if a module grows beyond a size that's comfortable to edit, I could just move select segments to separate files and replace the vacancy with "from the_respective_segment_module import *", analogous to "#include" in C. The remedy seems to have side-effects that can kill the patient. So I'll go back to the explicit imports, then. No problem at all. Thanking you and the other helpers too Frederic From debatem1 at gmail.com Fri Jul 9 14:43:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 14:43:24 -0400 Subject: Hello In-Reply-To: <4C375783.7090700@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > Sorry, I forgot to mention that I am using Linux. In fact, my first test > have been with gedit. Is there any way to directly run the Python code into > the console? Gedit has a plugin that brings up a python intepreter. Edit->Preferences->Plugins->python console I think. Geremy Condra From stefaan.himpe at gmail.com Fri Jul 9 15:10:52 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Fri, 09 Jul 2010 21:10:52 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <1vKZn.103886$We4.70738@hurricane> > Is Pocoo really the only solution available out there? No. See e.g. http://www.pyforum.org/ From schaffer at optonline.net Fri Jul 9 15:13:30 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 09 Jul 2010 15:13:30 -0400 Subject: any issues with long running python apps? Message-ID: <4c3774df$0$31278$607ed4bc@cv.net> i have been asked to guarantee that a proposed Python application will run continuously under MS Windows for two months time. And i am looking to know what i don't know. The app would read instrument data from a serial port, store the data in file, and display in matplotlib. typical sampling times are about once per hour. our design would be to read the serial port once a second (long story, but it worked for ten days straight so far) and just store and display the values once an hour. so basically we'd have a long running for-loop. maybe running in a separate thread. i have thought through the issues on our end: we have to properly handle the serial port and make sure our GUI doesn't hang easily. we'd have to be sure we don't have any memory leaks in numpy or matplotlib and we're not storing data in memory stupidly. i've never looked into Windows serial port driver reliability over the long term. But we think if the serial port hangs, we can detect that and react accordingly. but none of this has anything to do with Python itself. i am sure python servers have been running reliably for long periods of time, but i've never had to deal with a two-month guarantee before. is there something else i am missing here that i should be concerned about on the pure-Python side of things? something under the hood of the python interpreter that could be problematic when run for a long time? or need we only concern ourselves with the nuts behind the wheel:that is, we the developers? thanks Les From tjreedy at udel.edu Fri Jul 9 15:55:58 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 15:55:58 -0400 Subject: 500 tracker orphans; we need more reviewers In-Reply-To: References: Message-ID: On 7/8/2010 5:58 PM, Mark Lawrence wrote: > On 19-6-2010 23:45, Shashwat Anand wrote: >> Terry: Thanks for bringing this to notice. >> Mark: Kudos for your effort in cleaning up bugs.python.org >> > > Like I've said elsewhere, flattery will get you everywhere. :) > > FYI there are now 480 orphans and I've managed to get 8 issues closed. > After one week I even got promoted to the triage team, although I found > the pay increase rather disappointing. :) Great news. Imitation is the sincerest form of flattery. [Charles Caleb Colton,(1780 - 1832): Lacon, volume I, no. 183] -- Terry Jan Reedy From torriem at gmail.com Fri Jul 9 15:56:12 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 09 Jul 2010 13:56:12 -0600 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4C377EDC.2030809@gmail.com> On 07/09/2010 01:13 PM, Les Schaffer wrote: > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? It never hurts to separate the data collection and visualization/analysis parts into separate programs. That way you can keep the critical, long-running data collection program running, and if you get an exception in the GUI because of some divide by zero programming error or some other problem, you can restart that part without impacting the overall system. From lists at cheimes.de Fri Jul 9 15:58:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 21:58:35 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? At our company we have long running Python processes with an uptime of 60, 90 days or more. Python is up to the challenge. ;) But it's a challenge to keep any process written in any programming language running for two months or more. If I were in your case I would split up the work across multiple python process. One guardian process that keeps the other processes alive and checks if they are still reacting on events, another process that reads data from the serial port and writes it to a database or file and a third process to process the data. Small processes reduce the chance of an error. I assume that the "read from serial port" part is the mission critical element of your app. Christian From kosh at aesaeion.com Fri Jul 9 16:03:15 2010 From: kosh at aesaeion.com (William Heymann) Date: Fri, 9 Jul 2010 14:03:15 -0600 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <201007091403.16095.kosh@aesaeion.com> On Friday 09 July 2010, Les Schaffer wrote: > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? > > thanks > > Les I have been running zope apps for about 10 years now and they normally run for many months between being restarted so python has no inherent problems with running that long. Your specific python program might though. You have to make sure you don't have any reference leaks so your program keeps growing in memory but you also have to deal with windows. The program can not be any more reliable then the os it is running on. Personally I would never make a guarantee like that on a windows box. I would have to hand choose every piece of hardware and run some kind of unix on it with a guarantee like that. Last I ran a program for a long time on windows it ran into some kind of address space fragmentation and eventually it would die on windows. There is some kind of problem with the windows VM system. 64bit windows will solve that mostly by having an address space so large you can't fragment it enough to kill the program in any reasonable time frame. If your program is not allocating and destroying large data structures all the time you probably don't have to worry about that but you do have to test it. From davea at ieee.org Fri Jul 9 16:15:27 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 16:15:27 -0400 Subject: [Tutor] the ball needs a kick... In-Reply-To: References: <4C336BB7.8030209@ieee.org> <4C374A4E.60402@ieee.org> Message-ID: <4C37835F.2080505@ieee.org> yes But further messages had better be posted to the forum. And not top-posted. DaveA From tjreedy at udel.edu Fri Jul 9 16:16:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 16:16:52 -0400 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 7/9/2010 3:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. typical sampling times are about once > per hour. our design would be to read the serial port once a second > (long story, but it worked for ten days straight so far) and just store > and display the values once an hour. so basically we'd have a long > running for-loop. maybe running in a separate thread. Is this a dedicated machine, so you do not have anything else going that can delay for more than a second? > > i have thought through the issues on our end: we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to > be sure we don't have any memory leaks in numpy or matplotlib and we're > not storing data in memory stupidly. i've never looked into Windows > serial port driver reliability over the long term. But we think if the > serial port hangs, we can detect that and react accordingly. I read the ibmpc serial port bios code in the early 80s. It was pretty simple then. I would be very surprised if it has been messed up since and not fixed. > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? Python has been used for long-running background processes, at least on *nix, so the Python devs are sensitive to memory leak issues and respond to leak reports. That still leaves memory fragmentation. To try to avoid that, I would allocate all the needed data arrays immediately on startup (with dummy None pointers) and reuse them instead of deleting and regrowing them. Keeping explicit pointers is, of course more tedious and slightly error prone. I hope someone with actual experience also answers. -- Terry Jan Reedy From aahz at pythoncraft.com Fri Jul 9 16:34:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 13:34:54 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: In article , Jean-Michel Pichavant wrote: > >PS : You're misusing the del statement. It does not remove any object >from mmory, however, it removes the reference to it, the object is still >in memory. They are very few cases where del is usefull in python, so >try to avoid using it as well. The first two sentences are true; the last sentence is completely wrong. I've got lots of code using del, and it's a critically useful element of dictionary manipulation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From debatem1 at gmail.com Fri Jul 9 16:42:43 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 16:42:43 -0400 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On Fri, Jul 9, 2010 at 3:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will run > continuously under MS Windows for two months time. And i am looking to know > what i don't know. I normally use Linux for this sort of thing, so YMMV on the following advice. > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. ?typical sampling times are about once per > hour. our design would be to read the serial port once a second (long story, > but it worked for ten days straight so far) and just store and display the > values once an hour. so basically we'd have a long running for-loop. maybe > running in a separate thread. I'd keep the two timers, the process that actually checks and logs the data, and any postprocessing code completely separate. I'd also use something like the logging module to double up on where your data is stored- one on the local machine, another physically separated in case you lose a hard drive. It will also give you more information about where a failure might have occurred if/when it does. I'd also handle output/display on a separate machine. > i have thought through the issues on our end: ?we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to be > sure we don't have any memory leaks in numpy or matplotlib and we're not > storing data in memory stupidly. i've never looked into Windows serial port > driver reliability over the long term. But we think if the serial port > hangs, we can detect that and react accordingly. I would launch this as a subprocess and log so that even if you miss a measurement you still get what you need further on in the process. Just make sure that you can detect it at the time and that you also log an error when it occurs. This also minimizes the amount of memory your application directly handles and the susceptibility of your code to non-fatal problems with the serial port. > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've never > had to deal with a two-month guarantee before. ?is there something else i am > missing here that i should be concerned about on the pure-Python side of > things? something under the hood of the python interpreter that could be > problematic when run for a long time? Just ask all the what-ifs and you'll probably be ok. Geremy Condra From angani at gmail.com Fri Jul 9 16:47:48 2010 From: angani at gmail.com (Raju Angani) Date: Fri, 9 Jul 2010 13:47:48 -0700 (PDT) Subject: Hello References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Jul 9, 11:43?am, geremy condra wrote: > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > > Sorry, I forgot to mention that I am using Linux. In fact, my first test > > have been with gedit. Is there any way to directly run the Python code into > > the console? > > Gedit has a plugin that brings up a python intepreter. > Edit->Preferences->Plugins->python console I think. > > Geremy Condra Hi Dani, I started liking wingware ide, I used free version before my company finally bought a licensed version. Give it a try www.wingware.com Raju Angani From martin.hellwig at dcuktec.org Fri Jul 9 17:03:15 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 09 Jul 2010 22:03:15 +0100 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 07/09/10 20:13, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. Get a good lawyer and put into the contract, the last thing you want is a windows update that restarts the host and you are responsible because you guaranteed that it would run continuously. On the technical side; as Christian Heimes already pointed out, split the programs. Specifically I would have 1 service for data gathering, two separate watchdog services (that checks whether the other watchdog is still running and the 'core' service). The GUI should be an user side app and the services could be too, however consider running the services under the appropriate system account as in the past I have seen some strange things happening with services under user account, especially if there are password policies. I don't see from the interpreter point of view no reason why it couldn't work, it is much more likely your host system will mess things up (even if it wouldn't be windows). -- mph From tjreedy at udel.edu Fri Jul 9 17:10:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:10:05 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> Message-ID: On 7/9/2010 1:25 AM, sturlamolden wrote: > With OpenCL, Python is better than C for heavy computing. The Python > or C/C++ program has to supply OpenCL code (structured text) to the > OpenCL driver, which does the real work on GPU or CPU. Python is much > better than C or C++ at processing text. There will soon be OpenCL > drivers for most processors on the market. For those as ignorant as me, OpenCL = Open Computing Language (for parallel computing). Apple proposed, Khronos Group maintains spec (along with OpenGL), AMD, NVidea, Intel support. Send C-like text to device, as with OpenGL; device compiles and runs; mainly for number crunching with all resources a machine has. OpenCL and OpenGL can work together. There is already a Python binding: http://sourceforge.net/projects/pyopencl/ > But OpenCL drivers will not be pre-installed on Windows, as Microsoft > has a competing COM-based technology (DirectX Compute, with an > atrocious API and syntax). > -- Terry Jan Reedy From anthra.norell at bluewin.ch Fri Jul 9 17:14:23 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 23:14:23 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <4C375E8A.6080506@sequans.com> References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> Message-ID: <1278710063.2362.75.camel@hatchbox-one> On Fri, 2010-07-09 at 19:38 +0200, Jean-Michel Pichavant wrote: > Frederic Rentsch wrote: > > I develop in an IDLE window. > > > > Module M says 'from service import *'. > > Next I correct a mistake in function 'service.f'. > > Now 'service.f' works fine. > > > > I do 'reload (service); reload (M)'. > > The function 'M.f' still misbehaves. > > > > 'print inspect.getsource (service.f)' and > > 'print inspect.getsource (M.f)' shows the same > > corrected code. > > > > 'print service.f' and 'print M.f' show different ids. > > > > So I do 'del M; reload (M)'. Nothing changes. > > > > I delete M again and run gc.collect () to really > > clean house. I reload M again and still nothing changes. > > The id of the reloaded function 'M.f' is still the > > same as it was before the purge and so M.f still isn't > > fixed. > > > > I know I have more radical options, such as starting > > a new IDLE window. That would save me time, but > > I'd like to take the opportunity to understand what > > is happening. Surely someone out there knows. > > > > Frederic > > > > > > > > > > > > > Hi, > > Don't use reload, this is nothing but a trap, espacially if your using > it to update your objects with the code you are writting. > > JM I've found "reload" very usable for development in IDLE. IDLE memorizes my input, and the variables I assign output to. If restart IDLE I lose it all and start over. That is an awfully awkward alternative to "reload", an alternative I wouldn't consider. I found "reload" tricky with several modules, because all dependencies need to be updated and which way they go isn't always obvious. Reloading all modules in the right order works for me. The reload commands come up with Alt-P as long, precisely, as I don't restart IDLE. S : You're misusing the del statement. It does not remove any object > from mmory, however, it removes the reference to it, the object is still > in memory. They are very few cases where del is usefull in python, so > try to avoid using it as well. I understand that things going out of scope delete themselves. I have used del on occasion, for instance, to get rid of invalid members of a list or a dictionary. It has to be done in two passes, though, because neither can be altered during an iteration. The first pass makes a delete list of indices or keys, so that the actual deletion iterates through the delete list, not the object deleted from. Would you call that a misuse? Frederic From nagle at animats.com Fri Jul 9 17:19:44 2010 From: nagle at animats.com (John Nagle) Date: Fri, 09 Jul 2010 14:19:44 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c379276$0$1661$742ec2ed@news.sonic.net> On 7/9/2010 12:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. What if Master Control in Redmond decides to reboot your machine to install an update? They've been known to do that even when you thought you had remote update turned off. If you have to run Windows in a data acquistion application, you should be running Windows Embedded. See http://www.microsoft.com/windowsembedded This is a version of Windows 7 which comes with a tool for building customized boot images. Basically, you take out everything except what your application needs. Do you get Embedded Systems Journal? You should. John Nagle From ian-news at hotmail.com Fri Jul 9 17:22:43 2010 From: ian-news at hotmail.com (Ian Collins) Date: Sat, 10 Jul 2010 09:22:43 +1200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: Message-ID: <89pi93F819U4@mid.individual.net> On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: > [Cross-posted comp.lang.python and comp.lang.c++] > > I lack experience with shared libraries in *nix and so I need to ask... > > This is about "cppy", some support for writing Python extensions in C++ > that I just started on (some days ago almost known as "pynis" (not funny > after all)). > > For an extension module it seems that Python requires each routine to be > defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern > "C"' and C++ linkage, using a routine declared as 'static' in a class as > a C callback, formally they're two different kinds, and I seem to recall > that /some/ C++ compiler balks at that kind of mixing unless specially > instructed to allow it. Perhaps it was the Sun compiler? Yes, it will (correctly) issue a warning. As the is a bit OT, contact me directly and we can work through it. I have had similar fun and games adding PHP modules! -- Ian Collins From tjreedy at udel.edu Fri Jul 9 17:38:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:38:35 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 7/9/2010 12:37 AM, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. 3000 lines is more that I would prefer. I pulled decimal.py into an IDLE edit window; loading was sluggish; the scroll bar is tiny; and any movement moves the text faster and farther than I would like. -- Terry Jan Reedy From debatem1 at gmail.com Fri Jul 9 17:43:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 17:43:51 -0400 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <89pi93F819U4@mid.individual.net> References: <89pi93F819U4@mid.individual.net> Message-ID: On Fri, Jul 9, 2010 at 5:22 PM, Ian Collins wrote: > On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >> >> [Cross-posted comp.lang.python and comp.lang.c++] >> >> I lack experience with shared libraries in *nix and so I need to ask... >> >> This is about "cppy", some support for writing Python extensions in C++ >> that I just started on (some days ago almost known as "pynis" (not funny >> after all)). >> >> For an extension module it seems that Python requires each routine to be >> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >> "C"' and C++ linkage, using a routine declared as 'static' in a class as >> a C callback, formally they're two different kinds, and I seem to recall >> that /some/ C++ compiler balks at that kind of mixing unless specially >> instructed to allow it. Perhaps it was the Sun compiler? > > Yes, it will (correctly) issue a warning. > > As the is a bit OT, contact me directly and we can work through it. ?I have > had similar fun and games adding PHP modules! I'd appreciate it if you'd either leave this on-list or cc me in on this, as I'm working through a similar issue. Geremy Condra From tjreedy at udel.edu Fri Jul 9 17:46:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:46:26 -0400 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: On 7/9/2010 9:02 AM, Frederic Rentsch wrote: > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. Guido removed reload from 3.0 because it gave people false hopes and he gave up on fixing it. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jul 9 17:48:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:48:30 -0400 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Message-ID: On 7/9/2010 11:58 AM, crow wrote: > But in python's document, it > said I should use sys.setdefaultencoding. Where? That may need to be changed. -- Terry Jan Reedy From alf.p.steinbach+usenet at gmail.com Fri Jul 9 17:57:55 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 23:57:55 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <89pi93F819U4@mid.individual.net> References: <89pi93F819U4@mid.individual.net> Message-ID: * Ian Collins, on 09.07.2010 23:22: > On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >> [Cross-posted comp.lang.python and comp.lang.c++] >> >> I lack experience with shared libraries in *nix and so I need to ask... >> >> This is about "cppy", some support for writing Python extensions in C++ >> that I just started on (some days ago almost known as "pynis" (not funny >> after all)). >> >> For an extension module it seems that Python requires each routine to be >> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >> "C"' and C++ linkage, using a routine declared as 'static' in a class as >> a C callback, formally they're two different kinds, and I seem to recall >> that /some/ C++ compiler balks at that kind of mixing unless specially >> instructed to allow it. Perhaps it was the Sun compiler? > > Yes, it will (correctly) issue a warning. > > As the is a bit OT, contact me directly and we can work through it. I > have had similar fun and games adding PHP modules! Thanks. I'm mailing you a zip with the code... The question, of course, whether it works in *nix. Cheers, - Alf -- blog at From debatem1 at gmail.com Fri Jul 9 18:17:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 18:17:24 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> Message-ID: On Fri, Jul 9, 2010 at 5:10 PM, Terry Reedy wrote: > On 7/9/2010 1:25 AM, sturlamolden wrote: > >> With OpenCL, Python is better than C for heavy computing. The Python >> or C/C++ program has to supply OpenCL code (structured text) to the >> OpenCL driver, which does the real work on GPU or CPU. Python is much >> better than C or C++ at processing text. There will soon be OpenCL >> drivers for most processors on the market. > > For those as ignorant as me, OpenCL = Open Computing Language (for parallel > computing). Apple proposed, Khronos Group maintains spec (along with > OpenGL), AMD, NVidea, Intel support. ?Send C-like text to device, as with > OpenGL; device compiles and runs; mainly for number crunching with all > resources a machine has. OpenCL and OpenGL can work together. There is > already a Python binding: > http://sourceforge.net/projects/pyopencl/ Its worth pointing out that right now you're generally better off with CUDA than OpenCL, and that pycuda bindings are usable, if not what I would call easy-to-use. Geremy Condra From ankit at callfire.com Fri Jul 9 18:27:28 2010 From: ankit at callfire.com (Ankit Jhalaria) Date: Fri, 9 Jul 2010 15:27:28 -0700 Subject: PIL Query Message-ID: Hi I was using the PIL. I found it pretty useful. I was wondering if you could please let me know, whether I could change the image size. What I mean is if suppose I have 100 points having the same latitude and longitude, the point on the map appears (for instance as a red circle). My question to you is, can I change the radius of this circle? I was also trying to figure out where in the code I can change the location where the url is served from. So instead of serving the images form http://localhost/classic/4/4,5.png how do I change it to http://localhost/username/classic/4/4,5.png where username is taken from the database. & my last question is, is it possible that I just give the PIL the latitude,longitude and the no. of points having the same latitude and longitude[i.e. intensity], instead of repeating the lat & long coordinates. Your help will be greatly appreciated Thanks Ankit -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Jul 9 18:39:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 10 Jul 2010 08:39:45 +1000 Subject: python instructor References: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> Message-ID: <871vbcb7pq.fsf@benfinney.id.au> Greg writes: > Any thoughts or advice would be greatly appreciated. Rather than here, you should post job advertisements at the Python Job Board . -- \ ?Love is the triumph of imagination over intelligence.? ?Henry | `\ L. Mencken | _o__) | Ben Finney From abhijeet.thatte at gmail.com Fri Jul 9 18:46:14 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 9 Jul 2010 15:46:14 -0700 Subject: Pretty printing with ElementTree Message-ID: Hi, Does any one know how to use pretty printing with ElementTree while generating xml files. We can use that with lxml. But I want to stick with it ElementTree. Thanks, Abhijeet -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkrukoff at ltgc.com Fri Jul 9 19:03:48 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Fri, 09 Jul 2010 17:03:48 -0600 Subject: Pretty printing with ElementTree In-Reply-To: References: Message-ID: <1278716628.7825.15.camel@localhost.localdomain> On Fri, 2010-07-09 at 15:46 -0700, abhijeet thatte wrote: > Hi, > > > Does any one know how to use pretty printing with ElementTree while > generating xml files. > We can use that with lxml. But I want to stick with it ElementTree. > > > Thanks, > Abhijeet It's pretty simple minded, but this recipe from the element tree documentation may do what you want: http://effbot.org/zone/element-lib.htm#prettyprint -- John Krukoff Land Title Guarantee Company From abhijeet.thatte at gmail.com Fri Jul 9 19:14:14 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 9 Jul 2010 16:14:14 -0700 Subject: Pretty printing with ElementTree In-Reply-To: <1278716628.7825.15.camel@localhost.localdomain> References: <1278716628.7825.15.camel@localhost.localdomain> Message-ID: It worked. Thanks, Abhijeet On Fri, Jul 9, 2010 at 4:03 PM, John Krukoff wrote: > On Fri, 2010-07-09 at 15:46 -0700, abhijeet thatte wrote: > > Hi, > > > > > > Does any one know how to use pretty printing with ElementTree while > > generating xml files. > > We can use that with lxml. But I want to stick with it ElementTree. > > > > > > Thanks, > > Abhijeet > > > It's pretty simple minded, but this recipe from the element tree > documentation may do what you want: > http://effbot.org/zone/element-lib.htm#prettyprint > > -- > John Krukoff > Land Title Guarantee Company > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Fri Jul 9 19:30:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 09 Jul 2010 16:30:56 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 7/9/2010 12:13 PM Les Schaffer said... > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. Keep users off the machine, turn off automated updates, and point dns to 127.0.0.1. Oh, put it on a UPS. I've got a handful or two of these automated systems in place and rarely have trouble. Add a watchdog scheduled task process to restart the job and check disk space or memory usage and push out a heartbeat. I found Chris Liechti's serial module years ago and have used it successfully since. The only times that come to mind when I've problems on the python side were related to memory usage and the system started thrashing. Adding memory fixed it. HTH, Emile > And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. typical sampling times are about once > per hour. our design would be to read the serial port once a second > (long story, but it worked for ten days straight so far) and just store > and display the values once an hour. so basically we'd have a long > running for-loop. maybe running in a separate thread. > > i have thought through the issues on our end: we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to > be sure we don't have any memory leaks in numpy or matplotlib and we're > not storing data in memory stupidly. i've never looked into Windows > serial port driver reliability over the long term. But we think if the > serial port hangs, we can detect that and react accordingly. > > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? > > thanks > > Les From roy at panix.com Fri Jul 9 19:32:57 2010 From: roy at panix.com (Roy Smith) Date: Fri, 09 Jul 2010 19:32:57 -0400 Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: In article <4c3774df$0$31278$607ed4bc at cv.net>, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. Heh. The OS won't stay up that long. From aahz at pythoncraft.com Fri Jul 9 19:52:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 16:52:03 -0700 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel References: Message-ID: In article , Steve Holden wrote: >Vicky Twomey-Lee wrote: >> >> When: Wed 14th July, from 7pm >> Where: Trinity Capital Hotel > >Hope you all had a good piss-up! See you a week on Saturday. Did Guido get pissed and give you the keys to the time machine? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From breamoreboy at yahoo.co.uk Fri Jul 9 20:14:30 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 10 Jul 2010 01:14:30 +0100 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel In-Reply-To: References: Message-ID: On 10-7-2010 0:52, Aahz wrote: > In article, > Steve Holden wrote: >> Vicky Twomey-Lee wrote: >>> >>> When: Wed 14th July, from 7pm >>> Where: Trinity Capital Hotel >> >> Hope you all had a good piss-up! See you a week on Saturday. > > Did Guido get pissed and give you the keys to the time machine? No, he simply had a bad day and forgot to run the unit tests. Kindest regards. Mark Lawrence p.s. Best of luck to the Dutch and Spanish Sunday evening in the World Series Soccer!!! From python.list at tim.thechases.com Fri Jul 9 20:23:37 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 09 Jul 2010 19:23:37 -0500 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4C37BD89.1030006@tim.thechases.com> On 07/09/2010 06:32 PM, Roy Smith wrote: >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking >> to know what i don't know. > > Heh. The OS won't stay up that long. While I'm not sure how much of Roy's comment was "hah, hah, just serious", this has been my biggest issue with long-running Python processes on Win32 -- either power outages the UPS can't handle, or (more frequently) the updates (whether Microsoft-initiated or by other vendors' update tools) require a reboot for every ${EXPLETIVE}ing thing. The similar long-running Python processes I have on my Linux boxes have about 0.1% of the reboots/restarts for non-electrical reasons (just kernel and Python updates). As long as you're not storing an ever-increasing quantity of data in memory (write it out to disk storage and you should be fine), I've not had problems with Python-processes running for months. If you want belt+suspenders with that, you can take others' recommendations for monitoring processes and process separation of data-gathering vs. front-end GUI/web interface. -tkc From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 21:09:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 01:09:44 GMT Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4c37c857$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 17:46:26 -0400, Terry Reedy wrote: > On 7/9/2010 9:02 AM, Frederic Rentsch wrote: > >> I do 'reload (service); reload (M)'. >> The function 'M.f' still misbehaves. > > Guido removed reload from 3.0 because it gave people false hopes and he > gave up on fixing it. It's not quite *removed*. It's just no longer a built-in: import imp imp.reload(spam) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 21:13:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 01:13:28 GMT Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> Message-ID: <4c37c938$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 23:14:23 +0200, Frederic Rentsch wrote: > I understand that things going out of scope delete themselves. I have > used del on occasion, for instance, to get rid of invalid members of a > list or a dictionary. It has to be done in two passes, though, because > neither can be altered during an iteration. The first pass makes a > delete list of indices or keys, so that the actual deletion iterates > through the delete list, not the object deleted from. > Would you call that a misuse? No, that is perfectly fine. Pay no attention to anyone who says that del should be avoided. Like all tools, it can be used badly or inefficiently, or by somebody who doesn't understand it, but that's no reason to avoid using del correctly. Another strategy is to make a copy of the dict/list and iterate over that. Copies are fast, since you're only copying the top-level list or dict and not the underlying objects within it. A third is to forget about deleting and create a new list containing only the objects you don't want to delete. All three strategies (two using del, one without) have different use-cases and are perfectly acceptable. -- Steven From no.email at nospam.invalid Fri Jul 9 21:18:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 09 Jul 2010 18:18:42 -0700 Subject: python instructor References: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> <871vbcb7pq.fsf@benfinney.id.au> Message-ID: <7x630ob0ct.fsf@ruckus.brouhaha.com> Ben Finney writes: >> Any thoughts or advice would be greatly appreciated. > Rather than here, you should post job advertisements at the Python Job > Board . Since you are looking for an instructor to come to your site, it would also help if you stated your geographical location. From greg.ewing at canterbury.ac.nz Fri Jul 9 22:02:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 10 Jul 2010 14:02:00 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <89llvrFflvU1@mid.individual.net> Message-ID: <89q23iF1ufU1@mid.individual.net> kedra marbun wrote: > this 'passing class' thing comes from, > IIRC, learning python 4ed by Mark Lutz, it's stated there that the 3rd > arg to __get__ is the class to which the descriptor instance is > attached That's there so that the __get__ method of function objects can return an unbound method when looked up on a class rather than an instance of the class. There is no corresponding use case for a class argument to __set__ or __delete__, so they don't have one. -- Greg From f2h2d2 at gmail.com Fri Jul 9 22:29:01 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Fri, 9 Jul 2010 19:29:01 -0700 (PDT) Subject: Excuse me!! Message-ID: <653c44d7-9b08-48ec-a284-e52a262fa60c@41g2000yqn.googlegroups.com> Would you stop for a moment?! O...man...Haven't you thought-one day- about yourself ? Who has made it? Have you seen a design which hasn't a designer ?! Have you seen a wonderful,delicate work without a worker ?! It's you and the whole universe!.. Who has made them all ?!! You know who ?.. It's "ALLAH",prise be to him. Just think for a moment. How are you going to be after death ?! Can you believe that this exact system of the universe and all of these great creation will end in in nothing...just after death! Have you thought, for a second, How to save your soul from Allah's punishment?! Haven't you thought about what is the right religion?! Read ... and think deeply before you answer.. It is religion of Islam. It is the religion that Mohammad-peace upon him- the last prophet, had been sent by. It is the religion that the right Bible- which is not distorted-has preached. Just have a look at The Bible of (Bernaba). Don't be emstional. Be rational and judge.. Just look..listen...compare..and then judge and say your word. We advise you visiting : http://www.islamreligion.com http://www.islam-guide.com http://www.islamhouse.com/s/9661 ---------------------------------------------------- From falhodeb at gmail.com Fri Jul 9 23:18:59 2010 From: falhodeb at gmail.com (=?windows-1256?B?KCgoKOPM4+baySDH4c/a5skgx+HsIMfh4eUgx+HI0Q==?= =?windows-1256?B?7c/tySkpKSkgLQ==?=) Date: Fri, 9 Jul 2010 20:18:59 -0700 (PDT) Subject: (((((( hi Friend)))))) Message-ID: <610add37-b11e-400c-806f-350e527f778b@a30g2000yqn.googlegroups.com> (((((( hi Friend)))))) I bet that your happiness here Site a priest after being found happiness www.islamalways.com www.shareislam.com Other Sites: For more information about Islam http://islamtomorrow.com/ http://www.55a.net/firas/english/ http://english.islamway.com/ http://www.islamonline.net/english/inde x.shtml http://www.thelastingmiracle.com/eng/ ... http://alislam.6te.net/ http://www.quran.net/ http://www.thelastingmiracle.com/eng/ .. http://www.islamcode.com/ http://islamnewsroom.com/ Book calls to get to know the religion of Islam in English ... Author:. Saviour bin Mahmoud Alsagar Link: http://saaid.net/book/open.php?cat=&book=3850 Message presentations to non-Muslims about Islam http://www.imanway.com/vb/showthread.php?t=14862 Message ready, entitled Islam and the goal of life: ISLAM and the AIM of LIFE http://www.saaid.net/islam/2.htm Islam is a religion ease Islam, the Religion of Ease http://www.saaid.net/islam/3.htm You must know this man In The Name Of Allaah, Most Gracious, Most MercifulYOU MUST KNOW THIS MAN MUHAMMAD http://www.saaid.net/islam/9.htm Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=11984 Prophet Muhammad (peace and a message of thanks and appreciation from a non-Muslim person of the Prophet peace be upon him) http://www.imanway.com/vb/showthread...2092 # post92092 "Even the light laments his brother (piece of literature a simplified world, before and after the Prophet peace be upon him)" http://www.imanway.com/vb/showthread.php?t=15438 Prophet Muhammad (peace be upon him) in the eyes of western fair http://www.imanway.com/vb/showthread.php?t=15225 Certificate of non-Muslims to the Messenger of Allah (peace be upon him) http://www.imanway.com/vb/showthread.php?t=11985 You must know this man http://www.imanway.com/vb/showthread.php?t=11503 Life of the Prophet (peace be upon him) before the mission http://www.imanway.com/vb/showthread.php?t=11186 Signs of Prophethood http://www.imanway.com/vb/showthread.php?t=10815 Guide 12 on the health of the prophethood of the Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=15462 Hadith and Modern Science (genetic map) http://www.imanway.com/vb/showthread...0383 # post80383 A love letter to the whole world about the Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=2996 Success principles http://www.imanway.com/vb/showthread.php?t=2905 Sincerity of the Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=2658 Prophecy of the Prophet Moses peace be upon Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=2657 Gospel of Prophet Jesus Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=2649 Prophet Muhammad, peace be upon him in the Bible http://www.imanway.com/vb/showthread...8364 # post78364 Those who reject Sunnah of the Prophet peace be upon him and only the Qur'an http://www.imanway.com/vb/showthread...4545 # post84545 Jews waiting for the prophets (two, in fact, Jesus and Muhammad peace be upon them) http://www.imanway.com/vb/showthread.php?t=2648 Reply to slander the Gospel "deuteronomy" (God that will kill the prophet who speaks on behalf of the gods Error) http://www.imanway.com/vb/showthread.php?t=2647 Reply to suspicion (Muslims worship Muhammad peace be upon him) http://www.imanway.com/vb/showthread.php?t=16146 Muhammad is the Messenger of God: http://www.imanway.com/vb/showthread.php?t=11984 http://islamic-council.org/lib/FACTS-E-PDF/p5-123.pdf A quick message showing that Islam is a religion does not call for violence http://www.imanway.com/vb/showthread.php?t=15312 Cursing Islam Terrorism http://www.imanway.com/vb/showthread.php?t=15208 Response to a question: Why do most Muslims terrorists? http://www.imanway.com/vb/showthread.php?t=10198 Duties of the Muslim to non-Muslim http://www.imanway.com/vb/showthread.php?t=10828 Stories of Omar bin Khattab show the tolerance of Islam http://www.imanway.com/vb/showthread.php?t=18729 Prophet Muhammad peace be upon him in his last (farewell sermon) http://www.imanway.com/vb/showthread.php?t=18730 LIBRARY BOOKS Islamic library: You can copy the messages from and send Almtbp http://www.musalla.org/Articles/articles.htm Islamic library with more than 106 video clip in English: http://www.hyahya.org/en.m_video_index.php On this link to find Quran with Translation of the meaning in English ((direct link just copy it and then send it)) http://islamtomorrow.com/downloads/Quran_Khan.pdf This Rrabott for an explanation of each province: http://allahsquran.com/read/index.php A link to a collection of books and the Koran in several languages http://islamtomorrow.com/downloads/index.asp From drsalists at gmail.com Fri Jul 9 23:42:46 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 9 Jul 2010 20:42:46 -0700 Subject: any issues with long running python apps? In-Reply-To: <4C37BD89.1030006@tim.thechases.com> References: <4c3774df$0$31278$607ed4bc@cv.net> <4C37BD89.1030006@tim.thechases.com> Message-ID: On Fri, Jul 9, 2010 at 5:23 PM, Tim Chase wrote: > On 07/09/2010 06:32 PM, Roy Smith wrote: > >> i have been asked to guarantee that a proposed Python application will >>> run continuously under MS Windows for two months time. And i am looking >>> to know what i don't know. >>> >> >> Heh. The OS won't stay up that long. >> > > While I'm not sure how much of Roy's comment was "hah, hah, just serious", > this has been my biggest issue with long-running Python processes on Win32 > -- either power outages the UPS can't handle, or (more frequently) the > updates (whether Microsoft-initiated or by other vendors' update tools) > require a reboot for every ${EXPLETIVE}ing thing. The similar long-running > Python processes I have on my Linux boxes have about 0.1% of the > reboots/restarts for non-electrical reasons (just kernel and Python > updates). > > As long as you're not storing an ever-increasing quantity of data in memory > (write it out to disk storage and you should be fine), I've not had problems > with Python-processes running for months. If you want belt+suspenders with > that, you can take others' recommendations for monitoring processes and > process separation of data-gathering vs. front-end GUI/web interface. > > -tkc 1) Separate the crucial parts from the "need it someday" parts, as previously suggested. Perhaps run the crucial parts as a system service or daemon. 2) Use pylint, or at least PyChecker. pylint spills over into stylistic stuff in places, but it's very valuable in writing bullet proof Python, and its various warnings can all be turned off if necessary. I've not tried PyChecker. 3) Test, test, test. Unit test, Component test, System test. Consider hiring a Q/A person, even if only temporarily - if someone other than the main developer performs/writes the tests, they'll probably be more merciless to the code, and hence find more bugs before they become an issue. 4) Seriously: Think about whether you're on the right operating system. 5) Write a list of things that're beyond your control (Power Outages, OS crashes if they won't let you switch, crucial/unintended system patch, earthquake, fire, etc) and get your management to sign off on them as not your fault, with mitigations and contingencies where practical. You might want to include "...including but not limited to..." at the top of your list if you can. 6) Put the machine in a controlled machine room, and only access it over RDP or ssh. Don't put it near the KVM :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene7705 at gmail.com Sat Jul 10 00:56:13 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Sat, 10 Jul 2010 06:56:13 +0200 Subject: how do you do a count of a result set? Message-ID: hi. i'm using this function; def dbCacheGet(self, appParams): results = db.GqlQuery( "SELECT * " "FROM DBcache " "WHERE url='"+appParams['urlCalled']+"'" ).fetch(1) if results.count('*')==0: return None else: return results i dont think this will work correctly. i need a function that returns the complete count in the results variable. i searched the docs, but couldn't find it. hope you can help me out here. -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From clp2 at rebertia.com Sat Jul 10 01:46:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jul 2010 22:46:17 -0700 Subject: how do you do a count of a result set? In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 9:56 PM, Rene Veerman wrote: > hi. > > i'm using this function; > > > ? ? ? ?def dbCacheGet(self, appParams): > ? ? ? ? ? ? ? ?results = db.GqlQuery( > ? ? ? ? ? ? ? ? ? ? ? ?"SELECT * " > ? ? ? ? ? ?"FROM DBcache " > ? ? ? ? ? ?"WHERE url='"+appParams['urlCalled']+"'" > ? ? ? ? ? ? ? ?).fetch(1) > ? ? ? ? ? ? ? ?if results.count('*')==0: > ? ? ? ? ? ? ? ? ? ? ? ?return None > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ? ? ?return results > > > i dont think this will work correctly. > i need a function that returns the complete count in the results variable. But you're returning either None or `results`, neither of which is a number ("count")... Also, .count() appears to take an integer, yet you're passing it the string "*". I thus have little idea what your code is intended to do. > i searched the docs, but couldn't find it. hope you can help me out here. (A) **Include the context** for your question next time, i.e. which library/framework/platform(s) you're using! You're fortunate I just so happened to recognize the mention of GQL and was able to guess that you're using Google App Engine. (B) Define "complete count". Its meaning in this situation is not obviously clear. I will *guess* that "complete count" means the total number of query results, and answer based on that assumption. I'm not that familiar with GAE, but it /appears/ from the docs that your only option is to try .count(), and if you hit the max of 1000+ results, either: * Call .fetch() with higher and higher limits until the results list stops growing, then return its len(); or * Iterate over the query object and count the number of results manually. Here's an attempt at implementing the latter approach: COUNT_MAX = 1000 def dbCacheGet(self, appParams): query_str = "SELECT * FROM DBcache WHERE url='"+appParams['urlCalled']+"'" query = db.GqlQuery(query_str) count = query.count() if count < COUNT_MAX: return count else: return sum(1 for result in query) Overall, I would guess it's probably more advisable and efficient to (if possible) just track these counts manually, ahead of time in your database as you add/remove records; GQL != SQL, so some things must be done differently. Hence probably why the "count the number of query results" approach isn't elegant. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Sat Jul 10 02:21:50 2010 From: nagle at animats.com (John Nagle) Date: Fri, 09 Jul 2010 23:21:50 -0700 Subject: how do you do a count of a result set? In-Reply-To: References: Message-ID: <4c381183$0$1636$742ec2ed@news.sonic.net> On 7/9/2010 11:08 PM, Dennis Lee Bieber wrote: > On Sat, 10 Jul 2010 06:56:13 +0200, Rene Veerman > declaimed the following in gmane.comp.python.general: > >> hi. >> >> i'm using this function; >> >> >> def dbCacheGet(self, appParams): >> results = db.GqlQuery( >> "SELECT * " >> "FROM DBcache " >> "WHERE url='"+appParams['urlCalled']+"'" >> ).fetch(1) >> if results.count('*')==0: >> return None >> else: >> return results >> >> >> i dont think this will work correctly. >> i need a function that returns the complete count in the results variable. This is really a Google AppEngine question. Ask in their support forums. It's worth noting that for many database queries, asking how many hits there are can cost almost as much as actually retrieving them. John Nagle From brian at sweetapp.com Sat Jul 10 02:53:27 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 10 Jul 2010 16:53:27 +1000 Subject: how do you do a count of a result set? In-Reply-To: <4c381183$0$1636$742ec2ed@news.sonic.net> References: <4c381183$0$1636$742ec2ed@news.sonic.net> Message-ID: <4D5A4AD5-C347-42D2-BBB5-5C758F792DB1@sweetapp.com> On 10 Jul 2010, at 16:21, John Nagle wrote: > On 7/9/2010 11:08 PM, Dennis Lee Bieber wrote: >> On Sat, 10 Jul 2010 06:56:13 +0200, Rene Veerman >> declaimed the following in gmane.comp.python.general: >> >>> hi. >>> >>> i'm using this function; >>> >>> >>> def dbCacheGet(self, appParams): >>> results = db.GqlQuery( >>> "SELECT * " >>> "FROM DBcache " >>> "WHERE url='"+appParams['urlCalled']+"'" >>> ).fetch(1) >>> if results.count('*')==0: >>> return None >>> else: >>> return results >>> >>> >>> i dont think this will work correctly. >>> i need a function that returns the complete count in the results >>> variable. > > This is really a Google AppEngine question. Ask in their support > forums. http://groups.google.com/group/google-appengine-python would be a good place to start. > It's worth noting that for many database queries, asking how many > hits there are can cost almost as much as actually retrieving them. That is the case with the App Engine datastore. If your counts contain more than a few hundred results then you would be better so store them somewhere. Cheers, Brian From bnrj.rudra at gmail.com Sat Jul 10 03:29:50 2010 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 10 Jul 2010 00:29:50 -0700 (PDT) Subject: load and plot from multiple file Message-ID: Dear friends, I have several 2 column file which i need to plot in one figure. I generally do it using gnuplot, but when there is several files, its hard to do manually. can you tell me how i can load a file in python and plot several file in one figure(as it is done via replot in gnuplot)? I am novice in python, but tried the matplotlib...with no luck. will u plz help? From usernet at ilthio.net Sat Jul 10 04:13:10 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 10 Jul 2010 08:13:10 +0000 (UTC) Subject: load and plot from multiple file References: Message-ID: On 2010-07-10, rudra wrote: > Dear friends, > I have several 2 column file which i need to plot in one figure. > I generally do it using gnuplot, but when there is several files, its > hard to do manually. > can you tell me how i can load a file in python and plot several file > in one figure(as it is done via replot in gnuplot)? > I am novice in python, but tried the matplotlib...with no luck. > will u plz help? It would really help to see a representative sample of the data that you are working with and what you want the plot to look like. Other then that, you likely just want to load the data from the file into lists (ordered together, lists with sublists, or potentially into a list ofrepresentative objects). You can then simply open a pipe to gnuplot and send it the commands it needs to create your plot. You could also just create a single comined file with all of the information to plot and then use it to create you plots. From animator333 at gmail.com Sat Jul 10 05:42:16 2010 From: animator333 at gmail.com (King) Date: Sat, 10 Jul 2010 02:42:16 -0700 (PDT) Subject: zipimport (.pyd & .so) files. References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <970bd811-f03b-4c20-9505-56c0942e5d06@b4g2000pra.googlegroups.com> I think I am trying to open a can of worms. It's better to leave the idea for now. Prashant From usenot at geekmail.INVALID Sat Jul 10 06:00:48 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 10 Jul 2010 12:00:48 +0200 Subject: Hello References: Message-ID: <20100710120048.39c9a613@geekmail.INVALID> On Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Grant Edwards wrote: > On 2010-07-09, Dani Valverde wrote: > > > I am new to python and pretty new to programming (I have some > > expertise wit R statistical programming language). I am just > > starting, so my questions may be a little bit stupid. Can anyone > > suggest a good editor for python? > > Emacs, Scite (has nice folding), Vim, Eclipse. > Great tips for a newbie. Not. Well, they might be, but chances are, they are overkill for people new to programming and will only alienate them (Scite may be an exception). Text editors are an acquired taste. /W -- INVALID? DE! From xcr4cx at googlemail.com Sat Jul 10 06:11:24 2010 From: xcr4cx at googlemail.com (christian schulze) Date: Sat, 10 Jul 2010 03:11:24 -0700 (PDT) Subject: Hello References: Message-ID: <003f9cf0-93d3-43d4-ac1c-832f9a51b5eb@b35g2000yqi.googlegroups.com> On 9 Jul., 18:31, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? > Cheers! > > Dani > Editors: Scribes, vim, gVim, Emacs, Gedit, Joe, Kate, Leafpad, Mousepad, Nano IDE's: Eric, Geany, ActiveState, Anjuta, Bluefish, Code::Blocks, CodeDragon/ wxStudio, WingIDE I suggest you to try around and find the editor/IDE that fits your needs. I use: Eric, Geany, Scribes, Emacs, Vim, gVim, Bluefish, (Gedit) (You should give Eric a try, its a rather good Python IDE) cheers From bnrj.rudra at gmail.com Sat Jul 10 06:31:07 2010 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 10 Jul 2010 03:31:07 -0700 (PDT) Subject: load and plot from multiple file References: Message-ID: <37a13f23-0743-4305-b720-aacfbeff786e@a4g2000prm.googlegroups.com> On Jul 10, 1:13?pm, Tim Harig wrote: > It would really help to see a representative sample of the data that you > are working with and what you want the plot to look like. The data looks something like that: 0.70711 -2.57266 1.00000 0.16694 1.22474 -0.15287 1.41421 0.28025 1.58114 -0.03806 1.73205 0.05049 1.87083 -0.01686 2.00000 -0.02918 2.12132 0.00246 2.12132 0.13460 2.23607 -0.01552 2.34521 -0.00033 2.44949 0.00550 2.54951 -0.00827 2.54951 -0.01189 2.73861 0.00397 2.82843 0.04685 2.91548 -0.00115 2.91548 -0.00951 3.00000 0.00069 3.00000 0.00214 and there are several such file. I need two types of plotting: 1) multiple plot in same figure 2) grid of plots with different data in different grid From dani.valverde at gmail.com Sat Jul 10 06:49:35 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Sat, 10 Jul 2010 12:49:35 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: <4C38503F.6050309@gmail.com> geremy condra wrote: > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > >> Sorry, I forgot to mention that I am using Linux. In fact, my first test >> have been with gedit. Is there any way to directly run the Python code into >> the console? >> > > Gedit has a plugin that brings up a python intepreter. > Edit->Preferences->Plugins->python console I think. > > Geremy Condra > > I have this plugin enabled, but I don't know how to send the code to the console... Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From debatem1 at gmail.com Sat Jul 10 07:01:30 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 10 Jul 2010 07:01:30 -0400 Subject: Hello In-Reply-To: <4C38503F.6050309@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> Message-ID: On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde wrote: > geremy condra wrote: >> >> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >> wrote: >> >>> >>> Sorry, I forgot to mention that I am using Linux. In fact, my first test >>> have been with gedit. Is there any way to directly run the Python code >>> into >>> the console? >>> >> >> Gedit has a plugin that brings up a python intepreter. >> Edit->Preferences->Plugins->python console I think. >> >> Geremy Condra >> >> > > I have this plugin enabled, but I don't know how to send the code to the > console... type it in? Geremy Condra From dani.valverde at gmail.com Sat Jul 10 07:05:17 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Sat, 10 Jul 2010 13:05:17 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> Message-ID: <4C3853ED.9000806@gmail.com> geremy condra wrote: > On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde wrote: > >> geremy condra wrote: >> >>> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >>> wrote: >>> >>> >>>> Sorry, I forgot to mention that I am using Linux. In fact, my first test >>>> have been with gedit. Is there any way to directly run the Python code >>>> into >>>> the console? >>>> >>>> >>> Gedit has a plugin that brings up a python intepreter. >>> Edit->Preferences->Plugins->python console I think. >>> >>> Geremy Condra >>> >>> >>> >> I have this plugin enabled, but I don't know how to send the code to the >> console... >> > > type it in? > > Geremy Condra > > It could be a solution. But I am used to work with gEdit using the R statistical programming language plugin, and I am able to send the code to console instead of typing it in. Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From donn.ingle at gmail.com Sat Jul 10 07:39:29 2010 From: donn.ingle at gmail.com (donn) Date: Sat, 10 Jul 2010 13:39:29 +0200 Subject: Hello [How to run your code] In-Reply-To: <4C3853ED.9000806@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> <4C3853ED.9000806@gmail.com> Message-ID: <4C385BF1.4010708@gmail.com> On 10/07/2010 13:05, Dani Valverde wrote: > It could be a solution. But I am used to work with gEdit using the R > statistical programming language plugin, and I am able to send the code > to console instead of typing it in. To run your code, save it to a file 'mycode.py' (or whatever), then open a console and cd into that directory, then: python mycode.py That will get you started. Keep the console open and alt-tab to it whenever you want to run your code. \d From flebber.crue at gmail.com Sat Jul 10 07:55:00 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 10 Jul 2010 04:55:00 -0700 (PDT) Subject: Hello References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Jul 10, 8:49?pm, Dani Valverde wrote: > geremy condra wrote: > > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > > >> Sorry, I forgot to mention that I am using Linux. In fact, my first test > >> have been with gedit. Is there any way to directly run the Python code into > >> the console? > > > Gedit has a plugin that brings up a python intepreter. > > Edit->Preferences->Plugins->python console I think. > > > Geremy Condra > > I have this plugin enabled, but I don't know how to send the code to the > console... > > Dani > > -- > Daniel Valverde Saub? > c/Joan Maragall 37 4 2 > 17002 Girona > Spain > Tel?fon m?bil: +34651987662 > e-mail: dani.valve... at gmail.comhttp://www.acrocephalus.nethttp://natupics.blogspot.com > > Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. ?GR?CIES! > > Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! > > ?dani_valverde.vcf > < 1KViewDownload A few good options. Editor: Notepad++ IDE: Pyscripter - Clean clear design easy to use. Eclipse/Pydev Cheers Sayth From debatem1 at gmail.com Sat Jul 10 08:13:18 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 10 Jul 2010 08:13:18 -0400 Subject: Hello In-Reply-To: <4C3853ED.9000806@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> <4C3853ED.9000806@gmail.com> Message-ID: On Sat, Jul 10, 2010 at 7:05 AM, Dani Valverde wrote: > geremy condra wrote: >> >> On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde >> wrote: >> >>> >>> geremy condra wrote: >>> >>>> >>>> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >>>> wrote: >>>> >>>> >>>>> >>>>> Sorry, I forgot to mention that I am using Linux. In fact, my first >>>>> test >>>>> have been with gedit. Is there any way to directly run the Python code >>>>> into >>>>> the console? >>>>> >>>>> >>>> >>>> Gedit has a plugin that brings up a python intepreter. >>>> Edit->Preferences->Plugins->python console I think. >>>> >>>> Geremy Condra >>>> >>>> >>>> >>> >>> I have this plugin enabled, but I don't know how to send the code to the >>> console... >>> >> >> type it in? >> >> Geremy Condra >> >> > > It could be a solution. But I am used to work with gEdit using the R > statistical programming language plugin, and I am able to send the code to > console instead of typing it in. Not sure how that works, but everything in gedit is accessible through python, so it should be a snap to put together a plugin to do what you want. Geremy Condra From prouleau001 at gmail.com Sat Jul 10 09:30:11 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 06:30:11 -0700 (PDT) Subject: Any reason www.python.org is slow? Message-ID: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> All, I have been finding python.org site very slow for the last year and probably before. Is there any known reason why the site is slow? I tried accessing it from several locations and I always get to wait several seconds for a page to load (in any browser/OS). Thanks -- Pierre From solipsis at pitrou.net Sat Jul 10 09:48:43 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 15:48:43 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <20100710154843.1a8919b1@pitrou.net> On Sat, 10 Jul 2010 06:30:11 -0700 (PDT) Pierre Rouleau wrote: > All, > > I have been finding python.org site very slow for the last year and > probably before. Is there any known reason why the site is slow? For the last year?? It's been mostly zippy here. Is IPv6 enabled on your computer? If so, I'd try to disable it. python.org domains resolve to both IPv4 and IPv6 addresses and, if your computer has IPv6 enabled but you don't have any IPv6 connectivity, this can result in slowdowns. Regards Antoine. From prouleau001 at gmail.com Sat Jul 10 09:59:59 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 06:59:59 -0700 (PDT) Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: On Jul 10, 9:48?am, Antoine Pitrou wrote: > On Sat, 10 Jul 2010 06:30:11 -0700 (PDT) > > > I have been finding python.org site very slow for the last year and > > probably before. Is there any known reason why the site is slow? > > For the last year?? > It's been mostly zippy here. > Is IPv6 enabled on your computer? If so, I'd try to disable it. > python.org domains resolve to both IPv4 and IPv6 addresses and, if your > computer has IPv6 enabled but you don't have any IPv6 connectivity, > this can result in slowdowns. > > Regards > > Antoine. Merci Antoine! I did disable IPv6 on my computer at home and it did speed it up. I'll check the other computers where I experienced the same slowness. Thanks again! -- Pierre From martin at v.loewis.de Sat Jul 10 10:03:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:03:24 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <4C387DAC.7020805@v.loewis.de> > For the last year?? > It's been mostly zippy here. > Is IPv6 enabled on your computer? If so, I'd try to disable it. > python.org domains resolve to both IPv4 and IPv6 addresses and, if your > computer has IPv6 enabled but you don't have any IPv6 connectivity, > this can result in slowdowns. That is a common myth. If your computer doesn't have any IPv6 connectivity, all is fine. The web browser will fallback to IPv4 immediately (*), without sending out any IPv6 datagrams first. If your computer does have IPv6 connectivity, but it's broken (i.e. you have a gateway, but eventually packets are discarded), you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in itself then would be fast. If your computer has IPv6 connectivity, but through low-bandwidth tunnels (which may happen with 6to4 tunnels, for example), then you'll get slow responses all the time. Regards, Martin (*) unless it's some older Opera version, in which case you would get no connection to python.org at all. From martin at v.loewis.de Sat Jul 10 10:04:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:04:50 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <4C387E02.2030803@v.loewis.de> > I did disable IPv6 on my computer at home and it did speed it up. I'll > check the other computers where I experienced the same slowness. Of course, it would be interesting to find out what precisely went wrong. If you are curious to find out, let me know, and I'll help investigating. Regards, Martin From luke0104 at gmail.com Sat Jul 10 10:06:47 2010 From: luke0104 at gmail.com (pcchen) Date: Sat, 10 Jul 2010 07:06:47 -0700 (PDT) Subject: About new urllib.request in python 3.1.2 Message-ID: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> Sorry I have searched related topic but none could point out this problem. I am currently using python 3.1.2: >>>Python 3.1.2 (r312:79147, Jun 30 2010, 11:58:11) >>>[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 And for the following three simple lines of code, borrowed from official python-doc 3.1.2: >>>from urllib.request import urlopen >>>response = urlopen('http://python.org/') >>>html = response.read() They could cause this error: File "./http.py", line 3, in from urllib.request import urlopen File "/usr/local/lib/python3.1/urllib/request.py", line 88, in import http.client File "/home/pcchen/Python/http.py", line 3, in from urllib.request import urlopen ImportError: cannot import name urlopen All the related discussions point to urlopen has been moved from urllib to urllib.request, but none can discribe the above error. Any information is appreciated, thank you so much. From solipsis at pitrou.net Sat Jul 10 10:17:57 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 16:17:57 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> Message-ID: <20100710161757.78eaa6f1@pitrou.net> On Sat, 10 Jul 2010 16:03:24 +0200 "Martin v. Loewis" wrote: > > That is a common myth. If your computer doesn't have any IPv6 > connectivity, all is fine. The web browser will fallback to IPv4 > immediately (*), without sending out any IPv6 datagrams first. Ok, I suppose the explanation wasn't factually exact. > If your computer does have IPv6 connectivity, but it's broken > (i.e. you have a gateway, but eventually packets are discarded), > you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in > itself then would be fast. I think it's what most users experience when they are talking about this problem. It manifests itself on many Linux setups. Regards Antoine. From martin at v.loewis.de Sat Jul 10 10:28:19 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:28:19 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> Message-ID: <4C388383.1050904@v.loewis.de> >> If your computer does have IPv6 connectivity, but it's broken >> (i.e. you have a gateway, but eventually packets are discarded), >> you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in >> itself then would be fast. > > I think it's what most users experience when they are talking about > this problem. It manifests itself on many Linux setups. This (*) is something I really cannot believe. What specifically happened on these Linux setups? What specific network use these people, and why do they get bad IPv6 connectivity? Regards, Martin (*) that there are many From solipsis at pitrou.net Sat Jul 10 10:47:09 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 16:47:09 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> <4C388383.1050904@v.loewis.de> Message-ID: <20100710164709.1d217c2a@pitrou.net> On Sat, 10 Jul 2010 16:28:19 +0200 "Martin v. Loewis" wrote: > >> If your computer does have IPv6 connectivity, but it's broken > >> (i.e. you have a gateway, but eventually packets are discarded), > >> you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in > >> itself then would be fast. > > > > I think it's what most users experience when they are talking about > > this problem. It manifests itself on many Linux setups. > > This (*) is something I really cannot believe. > (*) that there are many Well, just take a look at the number of recipes for disabling IPv6 specifically in order to solve slowdown problems: http://www.google.com/search?hl=fr&safe=off&q=linux+ipv6+disable+slowdowns&aq=f&aqi=&aql=&oq=&gs_rfai= It is at least the third time that someone asks why python.org is "slow", and that their problem is "solved" by disabling IPv6. I disabled IPv6 myself, which solved similar slowdown issues. The issues happened on *.python.org, *.google.com and a couple of other domains; hence they weren't python.org-specific. The issues happened with a Web browser but also with ssh; hence they were neither application- nor protocol-specific. The issues happened on two different machines, one hooked to a DSL router, another with wireless connection to various outside networks. Hence the issue is probably not tied to a particular hardware gateway. I was quite surprised myself when I discovered that "solution". But it really suppressed the frequent lag I had in some connection attempts (including ssh connection to a rather close, mostly idle box). It is possible that the way Linux (or some Linux setups: many of the recipes above are for Ubuntu, I use Mandriva myself) handles IPv6 "connectivity" is suboptimal in some cases, and that connection attempts don't fail immediately when they should. I don't have enough knowledge to diagnose further. Regards Antoine. From eliben at gmail.com Sat Jul 10 11:02:45 2010 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 10 Jul 2010 18:02:45 +0300 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: On Fri, Jul 9, 2010 at 19:31, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise wit > R statistical programming language). I am just starting, so my questions may > be a little bit stupid. Can anyone suggest a good editor for python? > Cheers! > Hi Dani, Don't be shy to ask beginner questions. However, you will do well to first read a few FAQs. Start here: http://www.python.org/doc/faq/ Part of it is also available in spanish, for your convenience: http://www.python.org/doc/faq/es/general/ The Python wiki (http://wiki.python.org/moin/FrontPage) is also useful. For example, it has a rather comprehensive page about editors: http://wiki.python.org/moin/PythonEditors Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Jul 10 11:35:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 15:35:06 GMT Subject: About new urllib.request in python 3.1.2 References: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> Message-ID: <4c389329$0$28647$c3e8da3@news.astraweb.com> On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote: > And for the following three simple lines of code, borrowed from official > python-doc 3.1.2: > >>>>from urllib.request import urlopen >>>>response = urlopen('http://python.org/') html = response.read() > > They could cause this error: > > File "./http.py", line 3, in > from urllib.request import urlopen > File "/usr/local/lib/python3.1/urllib/request.py", line 88, in > > import http.client > File "/home/pcchen/Python/http.py", line 3, in > from urllib.request import urlopen > ImportError: cannot import name urlopen Look at the traceback: your code executes "from urllib.request import urlopen". That line in turn executes "import http.client". And *that* fails, which causes the first import to fail. It fails because you have shadowed the built-in package http with your own module http.py. Rename your file to something else ("myhttp.py") and it should just work. -- Steven From pavan_maddali at yahoo.com Sat Jul 10 12:11:14 2010 From: pavan_maddali at yahoo.com (pavan kumar maddali) Date: Sat, 10 Jul 2010 09:11:14 -0700 (PDT) Subject: About new urllib.request in python 3.1.2 In-Reply-To: <4c389329$0$28647$c3e8da3@news.astraweb.com> References: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> <4c389329$0$28647$c3e8da3@news.astraweb.com> Message-ID: <810244.99491.qm@web39701.mail.mud.yahoo.com> Thank You Steve, I am not using the urllib. I am using the xmlrpc and http modules from the python library. Please see the header code for the modules I am including.. from xmlrpc import client import pprint class ClientCertTransport(client.Transport): ?def make_connection(self,host): ??import http ??host, extra_headers,x509 = self.get_host_info(host) ?? ??try: ???HTTPS = http.HTTPS ??except AttributeError: ???raise NotImplementedError("your version of http does not support HTTPS") ??else: ???return HTTPS(host,None,'privkey.pem','resellercert.pem') the rest of the code is just to get the result from the api.... regards Pavan ________________________________ From: Steven D'Aprano To: python-list at python.org Sent: Sat, July 10, 2010 11:35:06 AM Subject: Re: About new urllib.request in python 3.1.2 On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote: > And for the following three simple lines of code, borrowed from official > python-doc 3.1.2: > >>>>from urllib.request import urlopen >>>>response = urlopen('http://python.org/') html = response.read() > > They could cause this error: > >? File "./http.py", line 3, in >? ? from urllib.request import urlopen >? File "/usr/local/lib/python3.1/urllib/request.py", line 88, in > >? ? import http.client >? File "/home/pcchen/Python/http.py", line 3, in >? ? from urllib.request import urlopen > ImportError: cannot import name urlopen Look at the traceback: your code executes "from urllib.request import urlopen". That line in turn executes "import http.client". And *that* fails, which causes the first import to fail. It fails because you have shadowed the built-in package http with your own module http://http.py. Rename your file to something else ("myhttp.py") and it should just work. -- Steven -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdesth.quelquechose at free.quelquepart.fr Sat Jul 10 12:23:22 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 10 Jul 2010 18:23:22 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c38b9fe$0$12484$426a74cc@news.free.fr> Les Schaffer a ?crit : > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. (snip) > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? Zope is (rightly) considered as a memory/resources hog, and I have a Zope instance hosting two apps on a cheap dedicated server that has not been restarted for the past 2 or 3 years. So as long as your code is clean you should not have much problem with the Python runtime itself, at least on a a linux box. Can't tell how it would work on Windows. From gervaz at gmail.com Sat Jul 10 12:24:23 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 16:24:23 GMT Subject: Web page special characters encoding Message-ID: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Hi all, I'm using py3k and the urllib package to download web pages. Can you suggest me a package that can translate reserved characters in html like "è", "ò", "é" in the corresponding correct encoding? Thanks, Mattia From bdesth.quelquechose at free.quelquepart.fr Sat Jul 10 12:37:00 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 10 Jul 2010 18:37:00 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <4c38bd30$0$2776$426a74cc@news.free.fr> Gilles Ganault a ?crit : > Hello > > I'd like to write a small web app in Python which must include a > forum. > > So I checked the relevant article in Wikipedia, which says that only > one forum app is available for Python: > > http://en.wikipedia.org/wiki/Comparison_of_internet_forum_software_(other) > > Is Pocoo really the only solution available out there? There are almost a dozen of Python "forum apps" for Django alone, and Python is known as "the language with more web frameworks than keywords". From asim.ssat at gmail.com Sat Jul 10 12:51:28 2010 From: asim.ssat at gmail.com (asim malik) Date: Sat, 10 Jul 2010 09:51:28 -0700 (PDT) Subject: Indian photographer denies affair with Lindsay Lohan! Message-ID: Speaking on the issue for the first time, Chaudhuri, over the phone from New York, says, "They were completely distorted reports. We are really good friends for more details www.bollywood789.blogspot.com From rami.chowdhury at gmail.com Sat Jul 10 13:07:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 10 Jul 2010 10:07:33 -0700 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <01EF6E9B-AFB9-477C-BF01-871E1FA83280@gmail.com> On Jul 10, 2010, at 09:24 , mattia wrote: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? It won't do the whole job for you but you may find the 'name2codepoint' mapping in the 'html.entities' module useful. HTH, Rami From python at mrabarnett.plus.com Sat Jul 10 13:09:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jul 2010 18:09:12 +0100 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4C38A938.7070207@mrabarnett.plus.com> mattia wrote: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? > import re from html.entities import entitydefs # The downloaded web page will be bytes, so decode it to a string. webpage = downloaded_page.decode("iso-8859-1") # Then decode the HTML entities. webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) From alf.p.steinbach+usenet at gmail.com Sat Jul 10 13:38:03 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 10 Jul 2010 19:38:03 +0200 Subject: Not-quite-the-module-name qualified names in extension modules? What? Message-ID: Hi. I built the [xxmodule.c] from the source distribution, as suggested by the Python 3.1.1 docs. I named this [xx.pyd], as I believed the module name was just "xx". Indeed importing xx works fine, but when I do help(xx) I get ... >>> help( xx ) Help on module xx: NAME xx - This is a template module just for instruction. FILE c:\projects\progrock\lib\progrock\cppy_dev\examples\02_xx_apilevel\xx.pyd CLASSES builtins.Exception(builtins.BaseException) error builtins.object xxmodule.Null builtins.str(builtins.object) xxmodule.Str class Null(builtins.object) | Methods defined here: | ... with the name "xxmodule" somehow in there as qualification. Checking the standard "csv" module I similarly get ... CLASSES builtins.Exception(builtins.BaseException) _csv.Error builtins.object Dialect excel excel_tab DictReader DictWriter Sniffer ... with the name "_csv" in there. And I'm pretty sure that these not-quite-the-module-name names stem from the literal specification of names in the C code in the extension module, assuming that the csv module is indeed a C extension module. Is it really necessary to qualify names in the C code? And can it do harm when such name qualification is not using the final module name but instead something like "xxmodule" or "_csv"? More to the point, what's the point? Cheers, - Alf -- blog at From news1234 at free.fr Sat Jul 10 14:22:21 2010 From: news1234 at free.fr (News123) Date: Sat, 10 Jul 2010 20:22:21 +0200 Subject: MySqlDb any way to see the query string Message-ID: <4c38ba5d$0$10393$426a74cc@news.free.fr> Hi, I'm using MYSQLdb and have following code db = MySQLdb.connect(**cfg) c = db.cursor() qrystr = "insert mytable set id = %s , other_field = %s" c.execute(qrystr, (id_val,other_field_val) ) What I wondered is whether there is any way to print the 'filled in' query string for debuggin. The reason I'm askng is, that I'd like to copy paste the 'filled in' query string and try it from the command line. I know I could create it myself, but I had to do all the esaping myself. Thanks for suggestions N From gelonida at gmail.com Sat Jul 10 14:42:40 2010 From: gelonida at gmail.com (Gelonida) Date: Sat, 10 Jul 2010 20:42:40 +0200 Subject: simples setup for an wsgi https server in python Message-ID: Hi, I'd like to debug a small wsgi module. I run it either on an apache web server or locally via wsgiref.simple_server.make_server and following code snippet: from wsgiref.simple_server import make_server httpd = make_server('localhost',8012,application) while True: httpd.handle_request() print_some_debug_info() It seems, that wsgiref.simple_server.make_server can only create an http server. What I wondered would be how to easiest create an https server, that supports wsgi modules TIA From nagle at animats.com Sat Jul 10 14:54:46 2010 From: nagle at animats.com (John Nagle) Date: Sat, 10 Jul 2010 11:54:46 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c38c1fa$0$1616$742ec2ed@news.sonic.net> On 7/9/2010 12:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, If the device you're listening to is read-only, and you're just listening, make a cable to feed the serial data into two machines, and have them both log it. Put them on separate UPSs and in a place where nobody can knock them over or mess with them. John Nagle From alf.p.steinbach+usenet at gmail.com Sat Jul 10 15:07:12 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 10 Jul 2010 21:07:12 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c38c1fa$0$1616$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c38c1fa$0$1616$742ec2ed@news.sonic.net> Message-ID: * John Nagle, on 10.07.2010 20:54: > On 7/9/2010 12:13 PM, Les Schaffer wrote: >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking >> to know what i don't know. >> >> The app would read instrument data from a serial port, > > If the device you're listening to is read-only, and you're just > listening, make a cable to feed the serial data into two machines, > and have them both log it. Put them on separate UPSs and in > a place where nobody can knock them over or mess with them. "The Ramans do everything in triplicate" - Old jungle proverb Cheers, - Alf -- blog at From exarkun at twistedmatrix.com Sat Jul 10 15:21:43 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Sat, 10 Jul 2010 12:21:43 -0700 (PDT) Subject: simples setup for an wsgi https server in python References: Message-ID: On Jul 10, 2:42?pm, Gelonida wrote: > Hi, > > I'd like to debug a small wsgi module. > > I run it either on an apache web server > > or locally via wsgiref.simple_server.make_server > and following code snippet: > > from wsgiref.simple_server import make_server > httpd = make_server('localhost',8012,application) > while True: > ? ?httpd.handle_request() > ? ?print_some_debug_info() > > It seems, that wsgiref.simple_server.make_server can only create an http > server. > > What I wondered would be how to easiest create an https server, that > supports wsgi modules > > TIA You could do this with Twisted: twistd -n web --https 443 --certificate server.pem --privkey server.key --wsgi your.application Jean-Paul From timr at probo.com Sat Jul 10 15:41:02 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 12:41:02 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Message-ID: <04jh36hf5s66pepkf8a711qd7n5c55j5ob@4ax.com> Dave Angel wrote: >Tim Roberts wrote: >> >> No. The multi-thread-aware CRT in Visual C++ (which is the only option >> since VS2008) puts errno in thread-local storage, so it's shared by all >> CRTs. >> >I didn't know specifically that errno is in TLS, but I will disagree >with the conclusion that a TLS entry is implicitly shared by all CRT's. >Unless the CRT for each DLL explicitly does some extra work to allow >sharing, each will have its own set of TLS variables. Yes, I should have thought about this before posting. I checked the CRT source code, and you are correct. Every DLL that calls the C run-time startup code will do its own TlsAlloc. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sat Jul 10 16:03:15 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jul 2010 21:03:15 +0100 Subject: MySqlDb any way to see the query string In-Reply-To: References: <4c38ba5d$0$10393$426a74cc@news.free.fr> Message-ID: <4C38D203.8030507@mrabarnett.plus.com> Dennis Lee Bieber wrote: > On Sat, 10 Jul 2010 20:22:21 +0200, News123 declaimed > the following in gmane.comp.python.general: > >> Hi, >> >> I'm using MYSQLdb > >> What I wondered is whether there is any way to print the 'filled in' >> query string for debuggin. >> > Just edit the MySQLdb cursors module -- it's plain Python unless > something has changed in the last year... Find the .execute() method, > and stuff in a debug print statement where it does the escaping and > "fill in" (reason MySQLdb uses %s placeholder is that it uses Python to > do the fill in; things may change if the module is ever updated to use > ver 5 prepared queries). > > Come to think of it, one could probably duplicate the .execute() > method, creating a "d_execute" with the print statement, while not > affecting operational code... That way one wouldn't have to edit the > module just for testing. > Why duplicate the method? Why not add a keyword argument to turn on printing or a provide a file-type instance to which it should log the query? From ndbecker2 at gmail.com Sat Jul 10 16:08:26 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 10 Jul 2010 16:08:26 -0400 Subject: Sumatra m/l? Message-ID: Sumatra looks like an interesting project http://pypi.python.org/pypi/Sumatra/0.2 But I have some questions. Is there any mail list or forum? I can't find anything on the website. From aahz at pythoncraft.com Sat Jul 10 16:48:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Jul 2010 13:48:09 -0700 Subject: Sumatra m/l? References: Message-ID: In article , Neal Becker wrote: > >Sumatra looks like an interesting project >http://pypi.python.org/pypi/Sumatra/0.2 And how are we supposed to know that it's interesting? You should provide a summary. Also, it's pretty rude to set followups to gmane.comp.python.general -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From gervaz at gmail.com Sat Jul 10 17:03:41 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 21:03:41 GMT Subject: Web page special characters encoding References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> Il Sat, 10 Jul 2010 18:09:12 +0100, MRAB ha scritto: > mattia wrote: >> Hi all, I'm using py3k and the urllib package to download web pages. >> Can you suggest me a package that can translate reserved characters in >> html like "è", "ò", "é" in the corresponding >> correct encoding? >> > import re > from html.entities import entitydefs > > # The downloaded web page will be bytes, so decode it to a string. > webpage = downloaded_page.decode("iso-8859-1") > > # Then decode the HTML entities. > webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) Thanks, very useful, didn't know about the entitydefs dictionary. From lists at cheimes.de Sat Jul 10 17:15:25 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Jul 2010 23:15:25 +0200 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? I think the html parser of LXML can convert the entities, too. Christian From nagle at animats.com Sat Jul 10 17:48:49 2010 From: nagle at animats.com (John Nagle) Date: Sat, 10 Jul 2010 14:48:49 -0700 Subject: Web page special characters encoding In-Reply-To: <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> Message-ID: <4c38eac5$0$1631$742ec2ed@news.sonic.net> On 7/10/2010 2:03 PM, mattia wrote: > Il Sat, 10 Jul 2010 18:09:12 +0100, MRAB ha scritto: > >> mattia wrote: >>> Hi all, I'm using py3k and the urllib package to download web pages. >>> Can you suggest me a package that can translate reserved characters in >>> html like "è", "ò", "é" in the corresponding >>> correct encoding? >>> >> import re >> from html.entities import entitydefs >> >> # The downloaded web page will be bytes, so decode it to a string. >> webpage = downloaded_page.decode("iso-8859-1") >> >> # Then decode the HTML entities. >> webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) > > Thanks, very useful, didn't know about the entitydefs dictionary. You also need to decode the HTML numerical escapes. Expect that in real-world HTML, out of range values will occasionally appear. John Nagle From solipsis at pitrou.net Sat Jul 10 18:25:35 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 11 Jul 2010 00:25:35 +0200 Subject: Sumatra m/l? References: Message-ID: <20100711002535.223aee77@pitrou.net> On 10 Jul 2010 13:48:09 -0700 aahz at pythoncraft.com (Aahz) wrote: > > Also, it's pretty rude to set followups to gmane.comp.python.general Can you expand? From cs at zip.com.au Sat Jul 10 18:33:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 11 Jul 2010 08:33:43 +1000 Subject: About new urllib.request in python 3.1.2 In-Reply-To: <810244.99491.qm@web39701.mail.mud.yahoo.com> References: <810244.99491.qm@web39701.mail.mud.yahoo.com> Message-ID: <20100710223343.GA1616@cskk.homeip.net> On 10Jul2010 09:11, pavan kumar maddali wrote: | Thank You Steve, | I am not using the urllib. Your example did: from urllib.request import urlopen response = urlopen('http://python.org/') html = response.read() | I am using the xmlrpc and http modules from the | python library. [...] That's not what he meant. Your file is called "http.py". Python searches the current directory first. That means that when any library module (internally) tried to use the "http" module it will find your file, not the library module. So you don't get to use the http library module. Rename your http.py file to "my-http-test.py" and retry. Then its name won't get in the way of the library name. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Success in software development depends on making a carefully planned series of small mistakes in order to avoid making unplanned large mistakes. - Steve McConnell, _Software Project Survival Guide_ From prouleau001 at gmail.com Sat Jul 10 18:39:25 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 15:39:25 -0700 (PDT) Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> <4C388383.1050904@v.loewis.de> Message-ID: <2b7da6c9-2f8f-4576-91e9-ee9232e57a13@y4g2000yqy.googlegroups.com> > > It is possible that the way Linux (or some Linux setups: many of the > recipes above are for Ubuntu, I use Mandriva myself) handles IPv6 > "connectivity" is suboptimal in some cases, and that connection > attempts don't fail immediately when they should. I don't have enough > knowledge to diagnose further. > > Note that I am not using Linux. I had the problem on OS/X 10.4. I did another experiment. I have VMWare Fusion on that computer and have Linux Ubuntu 9.04 in one VMWare appliance. I activated IPv6 on the OS/X Preference for the interface I am using. Access to www.python.org went slow for Firefox and Safari running directly under OS/X. However, access for Firefox running inside VMWare-based Linux Ubuntu 9.04 was fine! I tried pages from Ubuntu first, got them right away, then tried the same page under OS/X and was waiting for over 10 seconds. Regards - Pierre From gervaz at gmail.com Sat Jul 10 19:17:03 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 23:17:03 GMT Subject: Web page special characters encoding References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4c38ff6e$0$18657$4fafbaef@reader3.news.tin.it> Il Sat, 10 Jul 2010 16:24:23 +0000, mattia ha scritto: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? > > Thanks, > Mattia Basically I'm trying to get an html page and stripping out all the tags to obtain just plain text. John Nagle and Christian Heimes somehow figured out what I'm trying to do ;-) So far what I've done, thanks to you suggestions: import lxml.html import lxml.html.clean import urllib.request import urllib.parse from html.entities import entitydefs import re import sys HEADERS = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"} def replace(m): if m.group(1) in entitydefs: return entitydefs[m.group(1)] else: return m.group(1) def test(page): req = urllib.request.Request(page, None, HEADERS) page = urllib.request.urlopen(req) charset = page.info().get_content_charset() if charset is not None: html = page.read().decode(charset) else: html = page.read().decode("iso-8859-1") html = re.sub(r"&(\w+);", replace, html) cleaner = lxml.html.clean.Cleaner(safe_attrs_only = True, style = True) html = cleaner.clean_html(html) # create the element tree tree = lxml.html.document_fromstring(html) txt = tree.text_content() for x in txt.split(): # DOS shell is not able to print characters like u'\u20ac' - why??? try: print(x) except: continue if __name__ == "__main__": if len(sys.argv) < 2: print("Usage:", sys.argv[0], "") print("Example:", sys.argv[0], "http://www.bing.com") sys.exit() test(sys.argv[1]) Every new tips will be appreciated. Ciao, Mattia From timr at probo.com Sat Jul 10 19:24:59 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 16:24:59 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: <570i36ltptk14js0prc79he2342rgt6ffv@4ax.com> Frederic Rentsch wrote: > >I develop in an IDLE window. > >Module M says 'from service import *'. >Next I correct a mistake in function 'service.f'. >Now 'service.f' works fine. > >I do 'reload (service); reload (M)'. >The function 'M.f' still misbehaves. > >'print inspect.getsource (service.f)' and >'print inspect.getsource (M.f)' shows the same >corrected code. > >'print service.f' and 'print M.f' show different ids. Yes. This: from service import xxx is essentially the same as: import service xxx = service.xxx At that point, xxx contains a reference to the "service.xxx" object as it is right now. When you do a reload, that imports a new version of "service.xxx", but your global "xxx" object is still bound to the old one. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Jul 10 19:29:07 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 16:29:07 -0700 Subject: MySqlDb any way to see the query string References: <4c38ba5d$0$10393$426a74cc@news.free.fr> Message-ID: <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> News123 wrote: > >I'm using MYSQLdb > >and have following code > >db = MySQLdb.connect(**cfg) >c = db.cursor() >qrystr = "insert mytable set id = %s , other_field = %s" >c.execute(qrystr, (id_val,other_field_val) ) > >What I wondered is whether there is any way to print the 'filled in' >query string for debuggin. > >The reason I'm askng is, that I'd like to copy paste the 'filled in' >query string and try it from the command line. You have the source code in front of you. After you do the execute, the actual query string that was transmitted is available in "c._executed". If you need to know the result before you submit it, you can scan the source for the "execute" method and see how they do the quoting. It's not that complicated. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From news1234 at free.fr Sat Jul 10 20:07:42 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 02:07:42 +0200 Subject: MySqlDb any way to see the query string In-Reply-To: <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> References: <4c38ba5d$0$10393$426a74cc@news.free.fr> <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> Message-ID: <4C390B4E.80003@free.fr> Hi everybody, im Roberts wrote: > News123 wrote: >> I'm using MYSQLdb >> >> and have following code >> >> db = MySQLdb.connect(**cfg) >> c = db.cursor() >> qrystr = "insert mytable set id = %s , other_field = %s" >> c.execute(qrystr, (id_val,other_field_val) ) >> >> What I wondered is whether there is any way to print the 'filled in' >> query string for debuggin. >> >> The reason I'm askng is, that I'd like to copy paste the 'filled in' >> query string and try it from the command line. > > You have the source code in front of you. After you do the execute, the > actual query string that was transmitted is available in "c._executed". > > If you need to know the result before you submit it, you can scan the > source for the "execute" method and see how they do the quoting. It's not > that complicated. Thanks for all of your answers. In my case c._executed is absolutely sufficient. From ritchy_gato at hotmail.com Sat Jul 10 20:12:23 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Sat, 10 Jul 2010 17:12:23 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> Message-ID: <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> On 7 jul, 08:38, Johan Gr?nqvist wrote: > 2010-07-06 19:18, Ritchy lelis skrev: > > > On 6 jul, 17:29, Alan G Isaac ?wrote: > >> Unfortunately I cannot make sense of the code you posted. > >> Provide a detailed description in words (or psuedocode) > >> of what you are trying to accomplish. ?Be very careful > >> and detailed is you want a useful response. > > >> Alan Isaac > > > hummm... > > > ok, i will try to make that detailed description. > > I can tell you why I do not understand from your posted code what you > are trying to do. > > Firstly, I do not understand if you are trying to plot a surface, a set > of curves, or a curve, or just a set of points? In your posted code, the > plot command is part of the else clause, and my guess is that you never > intend the else-clause to be executed at all. > > In your code snippet you loop over two arrays (Vi and Vref), compute a > scalar value V0, and all plot-commands you issue are of the form > plot(V0). This will probably draw a line of one point (for each value in > Vi and Vref), which may not be what you want, and if it draws anything > at all, then all points will be drawn at the same x-value, which is also > probably not what you want. > > Secondly, how are the Vi and Vref related to your axes? I assume you > want to plot all values you compute for V0, but as a function of what? > When I use the plot command, I usually give it (at least) two arguments, > where the first is the x-axis, and the second is the y-axis. > > After I have understood those things, the next question would be about > the maths relating the Vi and Vref values to the V0 values, but I do not > think I will understand those until after the above points are explained > clearer. > > I definitely think your english is not a problem here. > > Johan hi Johan Thanks for the interest in my problem... really appreciate. About the plot draw it's a curve that it's a set of points wich it's the result of the comput of the Vref and Vi together. I don't know if i had to make a break instruction (like in other's languages) after the "If" instructions if i want the else-condition to be executed? ... (do you have some sujestions?) Anyway i have a picture of a tuturial that i found but in this forum i can't post it. That pic would show what a really want... Relatively to the axis, the Vi takes the x-axis and the Vref takes the y-axis. As i said, i have a good 2 pic of a doc that has the information about this ADC that i'm developing. I would appreciate more of your help, if you permit me i could send you those 2 pic and i guarantee that you would got the certain vision of the problem. I'll be waiting for your answer, i thing that you can help me. Cheers. Ritchy Lelis From sturlamolden at yahoo.no Sat Jul 10 20:48:57 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 10 Jul 2010 17:48:57 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <9da45f74-d042-4405-a8c5-1cbac5baada4@r27g2000yqb.googlegroups.com> On 10 Jul, 02:23, Tim Chase wrote: > While I'm not sure how much of Roy's comment was "hah, hah, just > serious", this has been my biggest issue with long-running Python > processes on Win32 -- either power outages the UPS can't handle, > or (more frequently) the updates Win32 is also the only OS in common use known to fragment memory enough to make long-running processes crash or hang (including system services), and require reboots on regular basis. Algorithms haven't changed, but it takes a bit "longer" for the heap to go fubar with Win64. (That is, "longer" as in "you're dead long before it happens".) For processes that needs to run that long, I would really recommend using Win64 and Python compiled for amd64. From sturlamolden at yahoo.no Sat Jul 10 20:55:53 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 10 Jul 2010 17:55:53 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <65382aab-9d99-4687-a607-5bdb282a06ff@i28g2000yqa.googlegroups.com> On 9 Jul, 02:02, Neil Hodgson wrote: > ? ?If you break the rules by using malloc rather than IMalloc for memory > that is deallocated by a different component to that which allocated it > or try to pass around FILE* objects then you will see failures. Yes, the CRT issue applies to COM as well. COM developers are even less aware of this than Python developers. > So, > always follow the COM rules. Or just avoid COM... From aahz at pythoncraft.com Sat Jul 10 21:54:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Jul 2010 18:54:01 -0700 Subject: Sumatra m/l? References: Message-ID: In article , Antoine Pitrou wrote: >On 10 Jul 2010 13:48:09 -0700 >aahz at pythoncraft.com (Aahz) wrote: >> >> Also, it's pretty rude to set followups to gmane.comp.python.general > >Can you expand? If you look at the original post's headers, you'll see Followup-To: gmane.comp.python.general which does not exist on my news server. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From drsalists at gmail.com Sat Jul 10 22:02:25 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 10 Jul 2010 19:02:25 -0700 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C3711B1.1070006@jollans.com> <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> Message-ID: On Fri, Jul 9, 2010 at 5:54 AM, Stopp, Bryan wrote: > I checked, none of the files are symlinks. The install process never got > to the point where it created sym-links for libraries (if it even does, > I haven't gotten to that point in the install process.) > > -B > > -----Original Message----- > From: python-list-bounces+cbds=argushealth.com at python.org > [mailto:python-list-bounces+cbds = > argushealth.com at python.org] On Behalf > Of Thomas Jollans > Sent: Friday, July 09, 2010 7:10 AM > To: python-list at python.org > Subject: Re: Issues compiling 2.6.5 on AIX 6.1 > > On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > > building '_struct' extension > > > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > > -I/build/tools/src/Python-2.6.5/Include > -I/build/tools/src/Python-2.6.5 > > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > > build/lib.aix-6.1-2.6/_struct.so > > > > collect2: library libpython2.6 not found > > What really stumps me (and you too, I expect) about this is the two > different error messages. Above, it looks like collect2 simply doesn't > find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > > > building '_struct' extension > > > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > > -I/build/tools/src/Python-2.6.5/Include > -I/build/tools/src/Python-2.6.5 > > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > > build/lib.aix-6.1-2.6/_struct.so > > > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > > > ld:open(): No such file or directory > > > > collect2: ld returned 255 exit status > > But what on earth is this? It looks like collect2 found the library, and > told it's mate ld, which can't open it. collect2 thinks it find a file, > ld hits "No such file or directory" on the same file. > > Maybe it's a dead symlink? Looking for a file with the right name and > location would find it, while opening it would hit a dead end, and > probably return "No such file " > > It's been a while since I've used AIX, but is it possible you're mixing 32 bit and 64 bit operations? AIX shared libraries: 1) Are closer to windows dll's than *ix .so's - unsurprising given that Windows shares a heritage with OS/2, and both OS/2 and AIX are from IBM. 2) A .a can hold both 32 bit and 64 bit objects. 3) If you have a .a with 32 objects in it, and try to link against it in 64 bit mode, the file is sort of there and sort of not - ls will see it, but the linker will not. 4) 32 bit libraries suffer from a "loader domain" issue - the first part of $LIBPATH optionally specifies a loader domain, which is a namespace into which shared libraries are loaded 5) 64 bit libraries are supposed to be cleaner than 32 bit 6) Make sure that if you're building for 64 bit (for example) that ld is doing the same when it's called from collect2 or whatever. 7) You can test what kind of shared library you're looking at (and sometimes .a's are _shared_ on AIX - yes, it's weird, yes, it's true) with ar -X - see the man page for more. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dg.gmane at thesamovar.net Sat Jul 10 23:36:26 2010 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sun, 11 Jul 2010 05:36:26 +0200 Subject: Sumatra m/l? In-Reply-To: References: Message-ID: On 10/07/2010 22:08, Neal Becker wrote: > Sumatra looks like an interesting project > http://pypi.python.org/pypi/Sumatra/0.2 > > But I have some questions. Is there any mail list or forum? I can't find > anything on the website. It's part of Neural Ensemble which has a google group (not specifically devoted to Sumatra, but all their projects): http://groups.google.com/group/neuralensemble Dan From luke.leighton at gmail.com Sat Jul 10 23:59:50 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Sun, 11 Jul 2010 03:59:50 +0000 Subject: grailbrowser now running under python 2.5 (probably above too) Message-ID: source at: http://github.com/lkcl/grailbrowser $ python grail.py (note the lack of "python1.5" or "python2.4") conversion of the 80 or so regex's to re has been carried out. entirely successfully or not is a matter yet to be determined. always a hoot to try browsing http://www.bbc.co.uk or http://www.youtube.com with a browser from 11+ years ago, it still cannot be resisted as grail is the only working graphical web browser in the world written in pure python [pybrowser is still in development, stalled]. l. From rantingrick at gmail.com Sun Jul 11 01:38:10 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 22:38:10 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! Message-ID: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Let me tell you folks about a recent case of culo rojo i experianced whilst creating a customized bin packer with Python. First i want to say that i actually like the fact that i can do this.. py> a = [] py> if a: ... do something Instead of this py> if len(a) > 0: ... do something Ok but the buck stops with integers. Why? you ask in amazing befuddlement...Well I happened upon this atrocity when creating variables that hold indexes into a python list. the variables where named "choice1 and choice2 and both where initialized to None. Fine no problem there. So the algorithm will search for the two best choices. The first choice "choice1" will always be array[0]. The second choice "choice2" will need to be found using a completely different algorithm. ...Well i could tell you about it but i would rather just show you with some simple code.. array = [c1,c2,c3,c4,c5,c6,...] while looping: choiceIdx1 = None choiceIdx2 = None if array[0] meets condition this condition: choiceIdx1 = 0 for i in range(len(array)): if array[i] meets this condition: choiceIdx2 = i break if choiceIdx1 and not choiceIdx2: best = array.pop(choiceIdx1) elif choiceIdx2 and not choiceIdx1: best = array.pop(choiceIdx2) elif choiceIdx1 and choiceIdx2: # figure out which choice is better. best = choiceIdx1 if choiceIdx1.better() else choiceIdx2 elif not choiceIdx1 and not choiceIdx2: break else: # assume the worst raise do_somthing_with(best) BUT THAT WONT WORK BECAUSE OF CRAPPY INTEGER BOOLEAN DEFAULTS! So i had to do this crap...! array = [c1,c2,c3,c4,c5,c6,...] while looping: choiceIdx1 = () choiceIdx2 = () if array[0] meets condition this condition: choiceIdx1 = (0,) for i in range(len(array)): if array[i] meets this condition: choiceIdx2 = (i,) break if choiceIdx1 and not choiceIdx2: best = array.pop(choiceIdx1[0]) elif choiceIdx2 and not choiceIdx1: best = array.pop(choiceIdx2[0]) elif choiceIdx1 and choiceIdx2: # figure out which choice is better. best = choiceIdx1[0] if choiceIdx1.better() else choiceIdx2[0] elif not choiceIdx1 and not choiceIdx2: break else: # assume the worst raise do_somthing_with(best) Seems kinda dumb to build a tuple just so a conditional wont blow chunks! This integer bool-ing need to be fixed right away! From rantingrick at gmail.com Sun Jul 11 01:44:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 22:44:33 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 10, 10:59?pm, Luke Kenneth Casson Leighton wrote: > source at:http://github.com/lkcl/grailbrowser > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > conversion of the 80 or so regex's to re has been carried out. > entirely successfully or not is a matter yet to be determined. ?always > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > with a browser from 11+ years ago, it still cannot be resisted as > grail is the only working graphical web browser in the world written > in pure python [pybrowser is still in development, stalled]. > > l. Congratulations on this effort Luke. However you know what project i would really like to see the community get around? ...dramatic pause here... a cross platform Python file browser! Yes i know there are tons of them out there already and Python is a bit slow, but i think it would be useful to many peoples. From me+list/python at ixokai.io Sun Jul 11 01:51:49 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 10 Jul 2010 22:51:49 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4C395BF5.4000305@ixokai.io> On 7/10/10 10:38 PM, rantingrick wrote: > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! Yes, let us penalize the thousands of use cases where 0 being false is useful and good, for the benefit of the one use-case (indexing) where it is not. You don't need to build a tuple. Just change the tests, to "if choiceIdx1 is not None". Its a little more work, sure. But its not enough that its even vaguely worth breaking the otherwise very useful behavior of bool(0) == False. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 02:03:40 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 23:03:40 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Jul 11, 12:51?am, Stephen Hansen wrote: > You don't need to build a tuple. Just change the tests, to "if > choiceIdx1 is not None". Its a little more work, sure. But its not > enough that its even vaguely worth breaking the otherwise very useful > behavior of bool(0) == False. Hmm, i beg to differ. The if choice1 is not None and choice2 is not None is going to run off my screen and into my neighbors backyard swimming pool! If you *can* Stefen, show the class a "very useful" case for integer bool-ing? Please do so, although i doubt you can offer one. Maybe you'll offer this kinda kludgy stuff... function(option=1) #instead of True function(option=0) #instead of False This is another example of the damage integer booling does to your code and your mind. What happened to explicit is better than implicit? What happened to tim toady is a SOB! It is easy to get drawn into this way of coding and very hard to pull out. And it's wrong, wrong, wrong. NEVER substitute 1 for True and/or 0 for False! NEVER! This is anti Pythonic! py> import this From me+list/python at ixokai.io Sun Jul 11 02:22:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 10 Jul 2010 23:22:27 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4C396323.2010908@ixokai.io> On 7/10/10 11:03 PM, rantingrick wrote: > On Jul 11, 12:51 am, Stephen Hansen wrote: > >> You don't need to build a tuple. Just change the tests, to "if >> choiceIdx1 is not None". Its a little more work, sure. But its not >> enough that its even vaguely worth breaking the otherwise very useful >> behavior of bool(0) == False. > > > Hmm, i beg to differ. The if choice1 is not None and choice2 is not > None is going to run off my screen and into my neighbors backyard > swimming pool! "if choiceIdx1 is not None and choiceIdx2 is not None:" is 54 characters. Your straw man argument fails. Even if this is in a method of a class, that's only 64; even with another two levels of indentation it still isn't longer then the 80 which is where some people consider things "long" (I do not: I don't mind code > 100). If you are so desperately concerned with space, then simply do: if (choiceIdx1, choiceIdx2) != (None, None): Its only eleven characters longer. Or, you can do: if None not in (choiceIdx1, choiceIdx2): Its only two characters. You really can't honestly be making an argument about two characters. > If you *can* Stefen, My name is Stephen. This is the second time you've done this: if you can't show even the vaguest respect and actually use my name and not a mockery of it, then I'll just killfile you. > show the class a "very useful" case for integer > bool-ing? Please do so, although i doubt you can offer one. Maybe > you'll offer this kinda kludgy stuff... > > function(option=1) #instead of True > function(option=0) #instead of False Of course I won't offer that. If I wish a boolean flag, something which can have only one of two states (although sometimes a three-state 'maybe' is useful, with None being the 'neither true nor false'), I'd use the boolean. There's numerous cases where "if x" where x is an integer is useful. A counter is the simplest example. Say you're counting how many watermelons are in your inventory there is, and you want to test if there's any or not. "if watermelons" is the concise, readable, understandable way to express this. Readability counts. A boolean test in Python tests "something" verses "nothing", it doesn't test Truth verses False It is entirely consistent in this regard (except in the case of custom classes which may decide to do strange things). Zero is, clearly, nothing. > This is another example of the damage integer booling does to your > code and your mind. Utter nonsense. No one does that unless they are coming from C or some other language without a True/False and don't know about it, or if they are using a codebase which is supporting a very old version of Python before True or False were introduced. But you're just going to argue endlessly, no doubt. Have you ever actually considered the fact that your gut reaction might, I don't know, be wrong or misguided? I've admitted when I'm wrong on more then one occasion. I really don't know why I bother. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 02:50:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 23:50:05 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> On Jul 11, 1:22?am, Stephen Hansen wrote: > If you are so desperately concerned with space, then simply do: > > ? ? if (choiceIdx1, choiceIdx2) != (None, None): > > Its only eleven characters longer. > > Or, you can do: > > ? ? if None not in (choiceIdx1, choiceIdx2): Only the first example was worse than the second. You do realize that Python must build a tuple for ever conditional that uses this semantic? This is more bad, bad, bad than integer bool-ing! My bin packer could potentially compute millions of parts. I do not want to waste valuable processor cycles building numerous tuples just for the sake of a conditional "condition"! This is bad coding style Stephen. > Its only two characters. You really can't honestly be making an argument > about two characters. > > > If you *can* Stefen, > > My name is Stephen. It was a typo not an on purpose misspelling > Of course I won't offer that. If I wish a boolean flag, something which > can have only one of two states (although sometimes a three-state > 'maybe' is useful, with None being the 'neither true nor false'), I'd > use the boolean. I agree... True, False, None. The trinity of bool-inity. > There's numerous cases where "if x" where x is an integer is useful. A > counter is the simplest example. Say you're counting how many > watermelons are in your inventory there is, and you want to test if > there's any or not. "if watermelons" is the concise, readable, > understandable way to express this. Readability counts. I agree but when in a conditional bool(integer) should be forced. Look, don't try to shoove this under the mattress like nobody initializes a variable to None and then maybe or maybe not stores an array index in the variable and then later needs to test for true false in a conditional. It's very common to initialize a counter or index variable to None or 0. And later you don't want 0 and None bool- ing to False and range(1:infinity)+range(-infinity:-1) bool-ing to True! > A boolean test in Python tests "something" verses "nothing", it doesn't > test Truth verses False > > It is entirely consistent in this regard (except in the case of custom > classes which may decide to do strange things). > > Zero is, clearly, nothing. No shit! i am talking about CONDITIONALS HERE. Specifically CONDITIONALS and BOOL-ING! > Utter nonsense. No one does that unless they are coming from C or some > other language without a True/False and don't know about it, or if they > are using a codebase which is supporting a very old version of Python > before True or False were introduced. Ah yes, when nothing else seems to work fall back to you default programming... FUD and ad hominem attacks > But you're just going to argue endlessly, no doubt. Have you ever > actually considered the fact that your gut reaction might, I don't know, > be wrong or misguided? I've admitted when I'm wrong on more then one > occasion. I have no problem admitting when i wrong. In this case however i am completely right. Use True/False for bool-ing, None for emptyness, and integers for inetgers. From ian.g.kelly at gmail.com Sun Jul 11 02:57:55 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Jul 2010 00:57:55 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 12:03 AM, rantingrick wrote: > This is another example of the damage integer booling does to your > code and your mind. What happened to explicit is better than implicit? Explicit is better than implicit. Hence, if you're specifically testing for the property of not being None rather than for the more general truth value, it's better to write "if choiceIdx1 is not None" rather than just "if choiceIdx". This holds true for empty collections as well. On Sun, Jul 11, 2010 at 12:22 AM, Stephen Hansen wrote: > There's numerous cases where "if x" where x is an integer is useful. A > counter is the simplest example. Say you're counting how many > watermelons are in your inventory there is, and you want to test if > there's any or not. "if watermelons" is the concise, readable, > understandable way to express this. Readability counts. I would also point out that the current semantics mean that "bool(container)", "bool(len(container))", and "len(container) > 0" are all equivalent. I view this as a positive thing. It also means that "if integer" in Python and "if (the_same_integer)" in a C module have the same semantics. It would be a nasty surprise for writers of C modules if they didn't. And I think that partly this is simply historical. Before a proper boolean type was added to Python, 1 and 0 were the norm for storing truth values. Changing the truth value of 0 when bools were introduced would have broken tons of existing code. This is also the reason why bool is a subclass of int. From ian.g.kelly at gmail.com Sun Jul 11 03:11:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Jul 2010 01:11:31 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 12:57 AM, Ian Kelly wrote: > And I think that partly this is simply historical. ?Before a proper > boolean type was added to Python, 1 and 0 were the norm for storing > truth values. ?Changing the truth value of 0 when bools were > introduced would have broken tons of existing code. ?This is also the > reason why bool is a subclass of int. Another thought related to that list bit: if bool(0) were True, then bool(int(False)) would also be True. That seems messed up. Then again, bool(str(False)) is already True. Does that bother anybody other than me? From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:13:29 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:13:29 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: * rantingrick, on 11.07.2010 08:50: > On Jul 11, 1:22 am, Stephen Hansen wrote: > >> Utter nonsense. No one does that unless they are coming from C or some >> other language without a True/False and don't know about it, or if they >> are using a codebase which is supporting a very old version of Python >> before True or False were introduced. > > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem > attacks I agree with Stephen, but for a different reason: that given desirability of implicit conversion to bool for some elementary types, then for uniformity there should be such conversion for all of them (and AFAIK there is), and given that, the rule should be the same, namely that default value of each type bool's to False, and other values to True, and so it is. The OP should simply represent "not found" as e.g. integer -1 instead of as a value of a different type. And write e.g. not_found = -1 ... if choiceIdx1 == choiceIdx2 == not_found: bah, none of them elif choice2Idx == not_found: use choice 1 elif choice1Idx == not_found: use choice 2 else: determine bestest choice Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Sun Jul 11 03:19:14 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 00:19:14 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C397072.90409@ixokai.io> On 7/10/10 11:50 PM, rantingrick wrote: > On Jul 11, 1:22 am, Stephen Hansen wrote: > >> If you are so desperately concerned with space, then simply do: >> >> if (choiceIdx1, choiceIdx2) != (None, None): >> >> Its only eleven characters longer. >> >> Or, you can do: >> >> if None not in (choiceIdx1, choiceIdx2): > > > Only the first example was worse than the second. You do realize that > Python must build a tuple for ever conditional that uses this > semantic? This is more bad, bad, bad than integer bool-ing! My bin > packer could potentially compute millions of parts. I do not want to > waste valuable processor cycles building numerous tuples just for the > sake of a conditional "condition"! This is bad coding style Stephen. Nonsense. Prove it. Show actual benchmarks and actual problems to that style. Tests that do, in essence, "if whatever in (constant1, constant2)" are exceedingly common. The burden is on you to prove they are bad. With real data. > >> Its only two characters. You really can't honestly be making an argument >> about two characters. >> >>> If you *can* Stefen, >> >> My name is Stephen. > > It was a typo not an on purpose misspelling If this had been the first time, perhaps. If you had not in *numerous* previous times spelled my name correctly, perhaps. If it were at all possible for "f" to be a typo of "ph", perhaps. As none of those are true, I must assume you are simply trying to be insulting. And yes, I do consider mangling my name to be an insult. >> There's numerous cases where "if x" where x is an integer is useful. A >> counter is the simplest example. Say you're counting how many >> watermelons are in your inventory there is, and you want to test if >> there's any or not. "if watermelons" is the concise, readable, >> understandable way to express this. Readability counts. > > I agree but when in a conditional bool(integer) should be forced. Uh, what? I left off the rest of this paragraph because it is incomprehensible. If bool(anything_at_all) returns True, then "if anything_at_all" must succeed. If bool(anything_at_all) returns False, then "if anything_at_all" must fail. To do otherwise would create two entirely different and strange definitions for what is Truth and what is False. Python defines them very clearly. Something. Verses. Nothing. 1 is something. 0 is nothing. >> A boolean test in Python tests "something" verses "nothing", it doesn't >> test Truth verses False >> >> It is entirely consistent in this regard (except in the case of custom >> classes which may decide to do strange things). >> >> Zero is, clearly, nothing. > > No shit! i am talking about CONDITIONALS HERE. Specifically > CONDITIONALS and BOOL-ING! I, too, am speaking of conditionals here. No shit back at you. The "if" statement works on the test, "Is this something?" If so, it executes its body. If not, it executes the 'else' body if present. >> Utter nonsense. No one does that unless they are coming from C or some >> other language without a True/False and don't know about it, or if they >> are using a codebase which is supporting a very old version of Python >> before True or False were introduced. > > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem > attacks Red herring. Do you know what FUD is? FUD is Fear, Uncertainty, and Doubt. I didn't try to scare you about anything. I didn't try to make you uncertain if something would work. And so on, and so forth. I dismissed your utterly unfounded claim and example which you held up as proof of your central point as nonsense. Do you know what an ad hominem attack is? I didn't say, "Your argument is invalid because you, a jackass, said it" -- that would be an ad hominem attack. My statement is neither FUD, nor even an ad hominem attack. If you dispute my dismissal, show evidence. Any will do. Oh, I do admit that in the end, I did venture into the ad hominem area where I called into question your attitude and general behavior of utter Infallible Rightness and trolling tendencies, but that is not a logical fallacy. You can call into question the motives and character of a person -- provided you are not using this as the sole means of denying their claim. You can't simply sweep my argument aside by claiming its an ad hominem attack because besides my pointing out you're trollish behavior, I'm actually taking the time to refute your actual arguments with arguments of my own. >> But you're just going to argue endlessly, no doubt. Have you ever >> actually considered the fact that your gut reaction might, I don't know, >> be wrong or misguided? I've admitted when I'm wrong on more then one >> occasion. > > I have no problem admitting when i wrong. Please, show an example. > In this case however i am > completely right. Use True/False for bool-ing, None for emptyness, and > integers for inetgers. Nonsense. None is not "for emptiness". None is a discrete entity, which exists for a very specific purpose. It evaluates as false, certainly. But it is neither the definition nor the poster child of emptiness. It is something else entirely. It is None. It is "no value" -- not the absence of a value, nor the absence of any thing, but the discrete state of "I explicitly have no value". That is *very* different, and very powerful, from the simple state of "empty". Many things can be empty. Many things can be nothing. Emptiness is far, far more then None. "" is emptiness, too. {} is emptiness, too. () is emptiness, too. [] is emptiness, too. And, 0 is emptiness, too. As is 0.0, though this is less useful (Since floating point math gets weird). Do you see the pattern? Every fundamental data type has a "nothing" state: and they ALL evaluate as false in conditionals. Why should integers be any different? Because, uh, you say so. Okay. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 03:26:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 00:26:36 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? Message-ID: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Another source of asininity seems to be the naming conventions of the Python language proper! True/False start with an upper case and i applaud this. However str, list, tuple, int, float --need i go on...?-- start with lowercase. Q: Well what the hell is your problem Rick. Who cares right? WRONG, I tell you what my problem is. Now i cannot "wisely" use variables like... str="this is a string" list = [1,2,3] def make_random_objs(range=10) def show_message(str) int = 12 If we would have adopted proper naming conventions from dios numero uno all this nonsense would be rectified! Str, Float, List, Range, etc, etc. You think Python 3000 was a hump to climb over just wait for Python 4000. Just thoughts. From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:30:23 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:30:23 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: * Stephen Hansen, on 11.07.2010 09:19: > On 7/10/10 11:50 PM, rantingrick wrote: >> >> It was a typo not an on purpose misspelling > > If this had been the first time, perhaps. If you had not in *numerous* > previous times spelled my name correctly, perhaps. If it were at all > possible for "f" to be a typo of "ph", perhaps. It is a natural mistake to make in some languages. E.g. in Norwegian the Devil can be spelled Faen or Fanden (modern) or Phanden (old-fashioned, no longer in dictionaries but still used to sort of tone down the expression). It's even there in English, like "file" and "philosophy". So it's an error committed not by the limbic system but by a slightly higher level sound-to-text translator brain circuit. The text is generated from how the word sounds in one's head. Cheers & hth., - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:34:29 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:34:29 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: * rantingrick, on 11.07.2010 09:26: > > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 > > If we would have adopted proper naming conventions from dios numero > uno all this nonsense would be rectified! Str, Float, List, Range, > etc, etc. You think Python 3000 was a hump to climb over just wait for > Python 4000. > > Just thoughts. Just do Str = str List = list Float = float and so on in module "myBasicTypes", and import that. :-) Cheers & hth., - Alf -- blog at From no.email at nospam.invalid Sun Jul 11 03:39:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 11 Jul 2010 00:39:22 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <7xmxtywjpx.fsf@ruckus.brouhaha.com> rantingrick writes: > unspeakably ugly code. I'd write the code differently to not do all those branches. I like to use 1-elemnt lists as an option type, instead of using None, so you can just concatenate them together to get the first non-empty one. Untested code: array = [c1,c2,c3,c4,c5,c6,...] # return first element of iterable that matches condition, wrapped # as a 1-element list. If no match, return empty list. def xfind(condition, iterable): for x in iterable: if condition(x): return [x] return [] while looping: cs = xfind(this_condition, array) + xfind(other_condition, array) # cs is now a list of either zero, one, or two matching elements if len(cs) == 1: r = cs[0] elif len(cs) = 2: r = else: break best = array.pop(r) do_somthing_with(best) Obviously you can golf the above in various ways. From me+list/python at ixokai.io Sun Jul 11 03:53:26 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 00:53:26 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C397876.7040809@ixokai.io> On 7/11/10 12:30 AM, Alf P. Steinbach /Usenet wrote: > * Stephen Hansen, on 11.07.2010 09:19: >> On 7/10/10 11:50 PM, rantingrick wrote: >>> >>> It was a typo not an on purpose misspelling >> >> If this had been the first time, perhaps. If you had not in *numerous* >> previous times spelled my name correctly, perhaps. If it were at all >> possible for "f" to be a typo of "ph", perhaps. > > It is a natural mistake to make in some languages. E.g. in Norwegian the > Devil can be spelled Faen or Fanden (modern) or Phanden (old-fashioned, > no longer in dictionaries but still used to sort of tone down the > expression). It's even there in English, like "file" and "philosophy". > So it's an error committed not by the limbic system but by a slightly > higher level sound-to-text translator brain circuit. The text is > generated from how the word sounds in one's head. I'm aware of the "f" vs "v" vs "ph" thing, and the complexity of it between languages and between the spoken verses written nature of language. And for most instances, I'd just idly note, hey-- "My name is Stephen" and leave it at that -- but this is not the first time with I've run into it with this person, and neither is it the first time I've responded to him and politely corrected him. That, and I have seen absolutely no reason to think this person speaks anything but standard American English. He has, for example, gone so far as to create a rant which declared quite vocally that everyone should adopt English, destroy Unicode and the usage of any other language, and that anyone who didn't follow through with this was ultimately hurting humanity. That any programmer which cow-towed towards this evil empire of Unicodeness was just embracing separatism and decisiveness. When this guy on more then one occasion chooses to articulate my name improperly, I take it as an underhanded act with no purpose but to belittle my point of view. So yes. The first time, its a natural mistake, and I hold no hard feelings. I regularly deal with people who misspell my name and mispronounce my name. A polite correction invariably solves the problem, and we are all happy. But if one then makes the mistake again-- and in an entirely different way (Stefan vs Steven) then they were politely corrected before-- its no longer an issue of linguistic confusion at that point. At that point, I have to assume he's doing it on purpose, and for the sole purpose of being disrespectful and disparaging. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From gd.usenet at spamfence.net Sun Jul 11 04:03:27 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 11 Jul 2010 10:03:27 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: rantingrick wrote: >Another source of asininity seems to be the naming conventions of the >Python language proper! True/False start with an upper case and i >applaud this. However str, list, tuple, int, float --need i go >on...?-- start with lowercase. > >Q: Well what the hell is your problem Rick. Who cares right? > >WRONG, I tell you what my problem is. Now i cannot "wisely" use >variables like... > >str="this is a string" >list = [1,2,3] >def make_random_objs(range=10) >def show_message(str) >int = 12 Someone who wants to write readable and maintainable code would (practically) never want to use variables named in this way. Why? Because these names don't tell anything about the purpose of the variables. So, it is not a disadvantage that the functions you listed above are named in this way. In the contrary, it is an advantage, as it keeps newcomers from using stupid variable names. >If we would have adopted proper naming conventions from dios numero >uno all this nonsense would be rectified! Str, Float, List, Range, >etc, etc. You think Python 3000 was a hump to climb over just wait for >Python 4000. Additionally to what I mention above, there is PEP 0008. Read it, you can learn from it. What you listed above, are functions, and their names comply completely with PEP 0008. Regards, G?nther PS: Even though I suspect that you are simply an agitator rsp. troll (based on what you posted in this group so far), and normally I refuse to feed trolls, I make an exception in this case, so newcomers ar not mislead by your half-baked ideas. From rantingrick at gmail.com Sun Jul 11 04:15:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:15:51 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <26122d68-3c13-430e-ada1-e10cb7126f26@u26g2000yqu.googlegroups.com> On Jul 11, 2:19?am, Stephen Hansen wrote: > Nonsense. > > Prove it. Show actual benchmarks and actual problems to that style. I can't believe i actually have to prove to you that creating a tuple and then testing for bool-inity takes more time than just the bool test, but here goes *another* Sunday school lesson... >>> s1 = "if (a, b) != (None, None):\n pass" >>> t1 = timeit.Timer(s1, 'a=1;b=1') >>> min(t1.repeat()) 0.23950232000015603 >>> s2 = "if a is not None and b is not None:\n pass" >>> t2 = timeit.Timer(s2, 'a=1;b=1') >>> min(t2.repeat()) 0.14334155999995346 > Tests that do, in essence, "if whatever in (constant1, constant2)" are > exceedingly common. The burden is on you to prove they are bad. With > real data. yea, been there done that. > And yes, I do consider mangling my name to be an insult. obviously i sounded out your name in my head. It is getting pretty late here after all so give me break for crying out loud. > 1 is something. Yes, but not necessarily a "True" something! > 0 is nothing. Yes, but not necessarily a "False" nothing! What is a True "something" and what is a False "nothing" Stephen? Put that one up where it belongs with the chicken and the egg where it belongs -- next to the toilet with Hustler and Time. > My statement is neither FUD, nor even an ad hominem attack. If you > dispute my dismissal, show evidence. Any will do. > > Oh, I do admit that in the end, I did venture into the ad hominem area > where I called into question your attitude and general behavior haha, i love how you denied the fact that you used ad hominem attacks and then directly after that tried to makes excuses for the very behavior you denied. Clinton made a career out this very same story telling. Nice work Bill Jr. *wink* > Do you see the pattern? Every fundamental data type has a "nothing" > state: and they ALL evaluate as false in conditionals. > > Why should integers be any different? Because, uh, you say so. No because i provide a very good reason --specifically in the case of a conditional bool-ing-- that integers bool-ing to True/False can be disastrous. And not only did i provide one reason, i provided two. The second being that 1/0 as compared to True/False is misleading in it's intention. Which renders code less readable, and supports bad programming styles. From rantingrick at gmail.com Sun Jul 11 04:26:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:26:38 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <7xmxtywjpx.fsf@ruckus.brouhaha.com> Message-ID: <884ba255-ca02-437c-bc98-2f2d7eb103e0@i31g2000yqm.googlegroups.com> On Jul 11, 2:39?am, Paul Rubin wrote: > rantingrick writes: > > unspeakably ugly code. > > I'd write the code differently to not do all those branches. > I like to use 1-elemnt lists as an option type, instead of using None, > so you can just concatenate them together to get the first non-empty > one. ?Untested code: Hmm, thanks for offering a solution but since functions call's induce so much overhead and you use the len function in each condition i believe the code would run much slower. How much slower, i don't know? Maybe i'll run the test later. I need to come up with some good test cases. Of course i'll want to maximize my side of the argument by producing the most efficient code that really makes your look slow. ;-) From rantingrick at gmail.com Sun Jul 11 04:30:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:30:36 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> On Jul 11, 3:03?am, "G?nther Dietrich" wrote: > So, it is not a disadvantage that the functions you listed above are > named in this way. In the contrary, it is an advantage, as it keeps > newcomers from using stupid variable names. "int" for an Integer is stupid? "list" for a List is stupid? "str" for a String is stupid? What am i missing? From kedra.marbun at gmail.com Sun Jul 11 04:31:07 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 11 Jul 2010 01:31:07 -0700 (PDT) Subject: 'reload M' doesn't update 'from M inport *' References: <4c37472e$0$28647$c3e8da3@news.astraweb.com> Message-ID: > from m import f > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > look for object named "f" in the Module object agree > create a new name "f" in the local namespace > set the name "f" to cached object strongly agree > The important thing to notice is the the name "f" is a local variable. It > doesn't, and can't, remember that it comes from module m. Reloading m > can't do anything to f, because the connection is lost. disagree with 2nd stmt. local 'f' does *remember* (if that's the right word) where it comes from, because it points to the original obj, as you said: 'set the name "f" to cached object' py0.py ====== def f(): ... >>> from py0 import * >>> assert f.__module__ == sys.modules['py0'].__name__ >>> assert f.__globals__ is sys.modules['py0'].__dict__ > Now consider that the object "f" that came from m was itself imported > from another module, "service". Reloading service doesn't help, because > m.f doesn't know it came from service. Reloading m doesn't help, because > all that does is run "from service import f" again, and that just fetches > f from the global cache. disagree with 2nd stmt, partially disagree with 3rd stmt reloading 'service' partially helps, since it updates the mod obj pointed by 'service' in global cache. it needs to be followed by reloading m, then we have m.f points to the new obj. the important part is the order of reloading mods l.py ==== def f(): ... m.py ==== from l import * >>> from m import * at this point, the func obj is referenced by 3 distinct variables with name 'm'(one in each mod) >>> assert sys.getrefcount(f) == 4 >>> referrers = gc.get_referrers(f) >>> mod_dicts = [sys.modules[k].__dict__ for k in sys.modules if k == 'l' or k == 'm' or k == __name__] >>> for d in mod_dicts: ... referrers.remove(d) >>> assert len(referrers) == 0 >>> imp.reload(sys.modules['l']) now the original func obj is ref'ed by 2 vars, the new func obj is ref'ed by 1 var >>> imp.reload(sys.modules['m']) >>> f = sys.modules['m'].f now the original func obj is ready to be recollected, the new func obj is ref'ed by 3 vars > The simplest, easiest way of dealing with this is not to have to deal > with it: don't use "from service import f", and ESPECIALLY don't use > "from service import *". Always use fully-qualified importing: > > import service > service.f strongly agree > The other way is not to bother with reload. It's not very powerful, only > good for the simplest use in the interactive interpreter. Just exit the > interpreter and restart it. set, del, reload are useful when it comes to structure manipulation at runtime, most langs differentiate it, labeling as metaprogramming, py smashes the diff in an elegant way (oh flattery, i love it) ;) as their names say, set & del only bind & unbind obj to var, the obj to bind must be in its bytecode form, in theory one could do it, maybe thru modules that are categorized as "Python Language Services" in the lib manual, but it's not practical (e.g. see the last stmt of types.CodeType.__doc__). this is where 'reload' steps in, and so the story goes ... From post at andre-bell.de Sun Jul 11 04:49:20 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Sun, 11 Jul 2010 10:49:20 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4C398590.9080602@andre-bell.de> On 07/11/2010 10:30 AM, rantingrick wrote: > On Jul 11, 3:03 am, "G?nther Dietrich" > wrote: > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? You are missing (from PEP 8): --- 8< --- 8< --- Class Names Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition. --- 8< --- 8< --- You may want to think of list, int, str, object, ... as classes that don't follow this advice with their class name. But besides that, shouldn't a variable name reflect it's purpose instead of it's type? E.g. name = 'rantingrick' counter = 1 ... as compared to str = 'rantingrick' int = 1? Regards Andre From kaklis at gmail.com Sun Jul 11 05:22:38 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Sun, 11 Jul 2010 02:22:38 -0700 (PDT) Subject: Load/Performance Testing of a Web Server References: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Message-ID: <1668dc8d-ab50-4b58-a1c9-bae19db95202@r27g2000yqb.googlegroups.com> On Jul 9, 4:44?pm, Simon Brunning wrote: > On 9 July 2010 14:17, kak... at gmail.com wrote: > > > Hi to all, i want to stress test ? a tomcat web server, so that i > > could find out its limits. e.g how many users can be connected and > > request a resource concurrently. > > I used JMeter which is an excellent tool, but i would like to use a > > more pythonic approach. > > The Grinder? > > -- > Cheers, > Simon B. Thank you Simon! I'll give it a try. It looks very promising. Antonis K. From bartc at freeuk.com Sun Jul 11 05:57:27 2010 From: bartc at freeuk.com (bart.c) Date: Sun, 11 Jul 2010 10:57:27 +0100 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4Bg_n.204567$k15.45006@hurricane> "rantingrick" wrote in message news:1b285203-33f6-41fb-8321-381c154bc8ed at w12g2000yqj.googlegroups.com... > Let me tell you folks about a recent case of culo rojo i experianced > whilst creating a customized bin packer with Python. First i want to > say that i actually like the fact that i can do this.. > > py> a = [] > py> if a: > ... do something > > Instead of this > > py> if len(a) > 0: > ... do something Or perhaps: if len(a): ... > Ok but the buck stops with integers. Why? you ask in amazing > befuddlement...Well I happened upon this atrocity when creating > variables that hold indexes into a python list. > choiceIdx1 = None > choiceIdx2 = None > if array[0] meets condition this condition: > choiceIdx1 = 0 > for i in range(len(array)): > if array[i] meets this condition: > choiceIdx2 = i > break > if choiceIdx1 and not choiceIdx2: > BUT THAT WONT WORK BECAUSE OF CRAPPY INTEGER BOOLEAN DEFAULTS! So i > had to do this crap...! You can also blame the 0-based indexing in Python. I'm not sure what would be the more fundamental change: changing over to 1-based indexing, or for 0 to be True (probably the opposite meaning to every other language). > array = [c1,c2,c3,c4,c5,c6,...] > while looping: > choiceIdx1 = () > choiceIdx2 = () > if array[0] meets condition this condition: > choiceIdx1 = (0,) > for i in range(len(array)): > if array[i] meets this condition: > choiceIdx2 = (i,) > break > if choiceIdx1 and not choiceIdx2: > > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! So, you're simply trying to signal whether a value is in the range 0 or more, or not? That doesn't sound difficult: start with -1, then test whether it's >=0. But you're trying a boolean test where you expect None=False, and 0,1,2, etc = True. While this would save typing in the condition, you're introducing extraneous stuff elsewhere which makes it harder to read, such as (i,) just to store an index. -- Bartc From marek at xivilization.net Sun Jul 11 07:51:50 2010 From: marek at xivilization.net (Marek Kubica) Date: Sun, 11 Jul 2010 13:51:50 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <20100711135150.5ecf4a61@halmanfloyd.lan.local> On Sun, 11 Jul 2010 00:26:36 -0700 (PDT) rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. Achtually, these are type names with their own constructor. The name of the type of True and False is bool and, bool() returns a bool-object. regards, Marek From johan.gronqvist at gmail.com Sun Jul 11 08:28:54 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Sun, 11 Jul 2010 14:28:54 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: 2010-07-11 02:12, Ritchy lelis skrev: > On 7 jul, 08:38, Johan Gr?nqvist wrote: > > About the plot draw it's a curve that it's a set of points wich it's > the result of the comput of the Vref and Vi together. I don't know if > i had to make a break instruction (like in other's languages) after > the "If" instructions if i want the else-condition to be executed? ... > (do you have some sujestions?) I would have expected a code structure similar to this: (NOTE: This is a very inefficient solution, and not the one suggested earlier, but it is closer to the code snippet you posted originally, and it does produce a plot.) ---------------------- import numpy as np import matplotlib.pyplot as plt Vref = np.linspace(1,20, 100) Vi = np.linspace(1,10,100) for ref in Vref: # Loop over Vref and Vi for i in Vi: if i > ref/4: # Compute V0 V0 = 2*i-ref elif (-ref/4) <= ref and ref <= ref/4: V0 = 2*i elif i < -ref/4: V0 = 2*i+ref plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 plt.show() # Display the plot in a window ---------------------- > Anyway i have a picture of a tuturial that i found but in this forum i > can't post it. That pic would show what a really want... Can you give a link? > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > y-axis. To me this sound like you want to make a 3D-plot, as there is the x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > As i said, i have a good 2 pic of a doc that has the information about > this ADC that i'm developing. > I looked on wikipedia , and saw some figures. Is any of those similar to what you look for? I see that they have (Vi - Vref) on the x-axis, and the computed value on the y-axis. Regards Johan From rene7705 at gmail.com Sun Jul 11 09:23:30 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Sun, 11 Jul 2010 15:23:30 +0200 Subject: getting the variable type Message-ID: hi. i need to know the type of variable i'm dealing with. take this list: files = [ "lib/jquery/jquery-1.4.2.source.js", "lib/jquery-ui-1.8.1/development-bundle/ui/jquery-ui-1.8.1.custom.js", "lib/jquery-ui-1.8.1/development-bundle/ui/jquery.ui.tabs.js", "lib/jquery/jquery.scrollTo-min.js", "lib/jquery/jquery.corner.js", "lib/jquery/jquery.mousewheel.js", "lib/jquery/jquery.em.js", "lib/jquery/jScrollPane.js", "lib_rv/logAndHandler-1.1.0/lah.source.js", "lib_rv/visCanvasLoaderIcon-1.1.0/visCanvasLoaderIcon.source.js", self.getJavascript_getbootJSPHP, "js/mbCore_boot.js", "content/mediaBeez_custom.js" ] # output a list of the files. html = ''; for i in range(len(files)): file = files[i] f = open (file, 'r') html += f.read() page = { 'html' : html } the third-last item in the list is not a string, it's a function. how do i test for that? -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From gelonida at gmail.com Sun Jul 11 09:37:28 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 11 Jul 2010 15:37:28 +0200 Subject: how to determine whether pathname1 is below bathname2 Message-ID: Hi, I wanted to figure out whether a given path name is below another path name. Surprisingly this turned out to be more difficult than initially anticipated: Let's assume I want to find out, whether path1 is below path2 First I thought about checking whether path1 starts with path2 For this I had to - convert path1 / path2 to absolute paths - I had to normalize the path name Further this would still fail for path1='/tmp/dir11' and path2='/tmp/dir1' next option would be to split both absolute and normalized paths by os.sep and check whether the path2's split list starts with path1's split list. That should work but is also not really nice. finally I came up with: ################################################# import os def is_below_dir(fname,topdir): relpath = os.path.relpath(fname,topdir) return not relpath.startswith('..'+os.sep) print is_below_dir(path1,path2) ################################################# The basic idea is, if the path name of path1 relative to path2 does NOT start with '..', then it must be below path2 Does anybody see pitfalls with that solution? Is there by any chance a function, that I overlooked, which does already what I'd like to do? From news1234 at free.fr Sun Jul 11 09:46:40 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 15:46:40 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4c39cb40$0$5856$426a74cc@news.free.fr> Andre Alexander Bell wrote: > On 07/11/2010 10:30 AM, rantingrick wrote: >>> So, it is not a disadvantage that the functions you listed above are >>> named in this way. In the contrary, it is an advantage, as it keeps >>> newcomers from using stupid variable names. >> "int" for an Integer is stupid? >> "list" for a List is stupid? >> "str" for a String is stupid? >> >> What am i missing? > > You are missing (from PEP 8): > > --- 8< --- 8< --- > Class Names > > Almost without exception, class names use the CapWords convention. > Classes for internal use have a leading underscore in addition. > > --- 8< --- 8< --- > > You may want to think of list, int, str, object, ... as classes that > don't follow this advice with their class name. > > But besides that, shouldn't a variable name reflect it's purpose instead > of it's type? E.g. hm, well sometimes I do write generic functions, that do something with a list or a string or an int. However a simple way around this is to use following naming style. to replace def process_list(list): dostuff_with(list) with def process_list(alist): dostuff_with(alist) or with def process_list(a_list): dostuff_with(a_list) I must admit, that I have still problems to not use the variables range or id From breamoreboy at yahoo.co.uk Sun Jul 11 09:46:51 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 11 Jul 2010 14:46:51 +0100 Subject: getting the variable type In-Reply-To: References: Message-ID: On 11-7-2010 14:23, Rene Veerman wrote: > hi. > > i need to know the type of variable i'm dealing with. > > take this list: > > files = [ > "lib/jquery/jquery-1.4.2.source.js", > "lib/jquery-ui-1.8.1/development-bundle/ui/jquery-ui-1.8.1.custom.js", > "lib/jquery-ui-1.8.1/development-bundle/ui/jquery.ui.tabs.js", > "lib/jquery/jquery.scrollTo-min.js", > "lib/jquery/jquery.corner.js", > "lib/jquery/jquery.mousewheel.js", > "lib/jquery/jquery.em.js", > "lib/jquery/jScrollPane.js", > "lib_rv/logAndHandler-1.1.0/lah.source.js", > "lib_rv/visCanvasLoaderIcon-1.1.0/visCanvasLoaderIcon.source.js", > self.getJavascript_getbootJSPHP, > "js/mbCore_boot.js", > "content/mediaBeez_custom.js" > ] > # output a list of the files. > html = ''; > for i in range(len(files)): > file = files[i] You could write for file in files: *BUT* using file will override the builtin name, better (say) for fn in files: > > f = open (file, 'r') hence:- f = open (fn, 'r') > html += f.read() > > page = { > 'html' : html > } > the third-last item in the list is not a string, it's a function. > how do i test for that? > Check out the isinstance function here. http://docs.python.org/library/functions.html HTH. Mark Lawrence From thomas at jollans.com Sun Jul 11 09:52:09 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 15:52:09 +0200 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: References: Message-ID: <4C39CC89.8070500@jollans.com> On 07/11/2010 03:37 PM, Gelonida wrote: > ################################################# > import os > def is_below_dir(fname,topdir): > relpath = os.path.relpath(fname,topdir) > return not relpath.startswith('..'+os.sep) > > print is_below_dir(path1,path2) > ################################################# > The basic idea is, if the path name of path1 > relative to path2 does NOT start with '..', then > it must be below path2 > > > Does anybody see pitfalls with that solution? > Is there by any chance a function, that I overlooked, > which does already what I'd like to do? It probably won't work on Windows because it isolates volumes (drive letters). What does, for example, os.path.relpath do when you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two reasonably correct options: either raise an exception (there is no relative path) or return the absolute path, which doesn't start with .. On UNIX, the only potential problem I see is that it may or may not do what you expect when symlinks are involved somewhere. From aahz at pythoncraft.com Sun Jul 11 10:00:24 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Jul 2010 07:00:24 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: In article , Luke Kenneth Casson Leighton wrote: > >$ python grail.py (note the lack of "python1.5" or "python2.4") Congrats! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From aahz at pythoncraft.com Sun Jul 11 10:01:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Jul 2010 07:01:06 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: In article , rantingrick wrote: > >Congratulations on this effort Luke. However you know what project i >would really like to see the community get around? ...dramatic pause >here... a cross platform Python file browser! Yes i know there are >tons of them out there already and Python is a bit slow, but i think >it would be useful to many peoples. As usual, you would rather tell other people what to do instead of doing any work yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From usenot at geekmail.INVALID Sun Jul 11 10:24:23 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 11 Jul 2010 16:24:23 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c39cb40$0$5856$426a74cc@news.free.fr> Message-ID: <20100711162423.1b8f1d36@geekmail.INVALID> On Sun, 11 Jul 2010 15:46:40 +0200 News123 wrote: > Andre Alexander Bell wrote: > > On 07/11/2010 10:30 AM, rantingrick wrote: > > >>> So, it is not a disadvantage that the functions you listed above > >>> are named in this way. In the contrary, it is an advantage, as it > >>> keeps newcomers from using stupid variable names. > >> "int" for an Integer is stupid? > >> "list" for a List is stupid? > >> "str" for a String is stupid? > >> > >> What am i missing? > > > > [snip] > > hm, well sometimes I do write generic functions, that do something > with a list or a string or an int. > > [snip] > > I must admit, that I have still problems > to not use the variables range or id > There are several approaches: - Use range_, id_, and so on. I think this is the proposed convention. Slightly ugly, though. - Use abbreviations, or misspellings like lst, Set, klass, ... Less ugly, but can get weird. - Prepend 'a' to a type name: alist, aset, astr. Similar weirdness potential as above, but more consistent in terms of style. I sometimes take this to the extreme and prepend 'some_'. So really, this is a non issue, at least for me. Having capitalized boolean values ... that is a bit odd, but as long as children are starving in Africa, this isn't very high on my gripe-list. /W -- INVALID? DE! From gelonida at gmail.com Sun Jul 11 10:34:14 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 11 Jul 2010 16:34:14 +0200 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: <4C39CC89.8070500@jollans.com> References: <4C39CC89.8070500@jollans.com> Message-ID: Hi Thomas, Thomas Jollans wrote: > On 07/11/2010 03:37 PM, Gelonida wrote: >> ################################################# >> import os >> def is_below_dir(fname,topdir): >> relpath = os.path.relpath(fname,topdir) >> return not relpath.startswith('..'+os.sep) >> >> print is_below_dir(path1,path2) >> ################################################# >> The basic idea is, if the path name of path1 >> relative to path2 does NOT start with '..', then >> it must be below path2 >> >> >> Does anybody see pitfalls with that solution? >> Is there by any chance a function, that I overlooked, >> which does already what I'd like to do? > > It probably won't work on Windows because it isolates volumes (drive > letters). What does, for example, os.path.relpath do when > you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two > reasonably correct options: Thanks, Indeed. different drives raise an ecception. I could catch the ValueError and let it just return False > > either raise an exception (there is no relative path) or return the > absolute path, which doesn't start with .. > > On UNIX, the only potential problem I see is that it may or may not do > what you expect when symlinks are involved somewhere. Also true. In my case I'd prefer it would not follow, but it doesn't really matter. So my function in order to be portable had now to look like: ################################################# import os def is_below_dir(fname,topdir): try: relpath = os.path.relpath(fname,topdir) except ValueError: return False return not relpath.startswith('..'+os.sep) print is_below_dir(path1,path2) ################################################# if I wanted to folow symlinks, then had to apply os.path.realpath() on fname AND on topdir From news1234 at free.fr Sun Jul 11 10:36:46 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 16:36:46 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <20100711162423.1b8f1d36@geekmail.INVALID> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c39cb40$0$5856$426a74cc@news.free.fr> <20100711162423.1b8f1d36@geekmail.INVALID> Message-ID: <4c39d6fe$0$2485$426a74cc@news.free.fr> Andreas Waldenburger wrote: > > Having capitalized boolean values ... that is a bit odd, but as long as > children are starving in Africa, this isn't very high on my gripe-list. > +1 From zooko at zooko.com Sun Jul 11 10:45:39 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Sun, 11 Jul 2010 08:45:39 -0600 Subject: I wish for a tool named "2to6". Message-ID: Folks: I have been (I admit it) a Python 3 skeptic. I even speculated that the Python 3 backward-incompatibility would lead to the obsolescence of Python: http://pubgrid.tahoe-lafs.org/uri/URI:DIR2-RO:ixqhc4kdbjxc7o65xjnveoewym:5x6lwoxghrd5rxhwunzavft2qygfkt27oj3fbxlq4c6p45z5uneq/blog.html However, things are really looking up now because it turns out that it is eminently practical to support both Python 2 and Python 3 with a single codebase. There have been some recent discussions about that on this list. A few references: http://mail.python.org/pipermail/python-list/2010-July/1249312.html http://www.voidspace.org.uk/python/weblog/arch_d7_2010_03_20.shtml#e1167 http://nedbatchelder.com/blog/200910/running_the_same_code_on_python_2x_and_3x.html http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html Benjamin Peterson has even written a library intended to help programmers who want to do that: http://packages.python.org/six/ This note to the list is to express my wish for an automated tool named "2to6" which converts my Python 2.6 codebase to being both py2- and py2- compatible using Benjamin Peterson's six library. Regards, Zooko From dhruvbird at gmail.com Sun Jul 11 11:59:06 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Sun, 11 Jul 2010 08:59:06 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? Message-ID: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which suggests that this is done to make sure that the programmer understands that the list is being modified in place, but that rules out constructs like: ([1,2,3,4].reverse()+[[]]).reverse() I want to prepend an empty list to [1,2,3,4]. This is just a toy example, since I can always do that with [[]]+[1,2,3,4]. Regards, -Dhruv. From torriem at gmail.com Sun Jul 11 12:03:12 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jul 2010 10:03:12 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C39EB40.80800@gmail.com> On 07/11/2010 12:50 AM, rantingrick wrote: > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem attacks Please stop calling things what they are not. Stephen's post was not an ad hominem attack, nor was it FUD. Someone who is countering your premise and position (IE disagrees with you) is not automatically attacking your character or some characteristic of your person. http://en.wikipedia.org/wiki/Ad_hominem#Common_misconceptions_about_ad_hominem Kudos to Stephen for replying in such a reasonable and even logical fashion to your post. Would that you would reply to his posts in a similar fashion, rather than leveling silly false accusations of "FUD and ad hominem attacks." From rantingrick at gmail.com Sun Jul 11 12:16:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 09:16:46 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> On Jul 11, 9:01?am, a... at pythoncraft.com (Aahz) wrote: > As usual, you would rather tell other people what to do instead of doing > any work yourself. Dear God! My statement was intended to fetch responses like... "Hey, that sounds like a great idea" or \ "Hey, lets get hacking on this". I am so sick of you people constantly accusing me of being lazy. You don't even know me. Also i think you're really a bit jealous because i have the brass cohones to initiate a coding project without your express written permission. I will not allow myself to be brow beaten by anyone! From thomas at jollans.com Sun Jul 11 12:19:35 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:19:35 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: <4C39EF17.7040206@jollans.com> On 07/11/2010 05:59 PM, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggests that this is done to make sure that > the programmer understands that the list is being modified in place, Yes! > but that rules out constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() No! you can either approach this by imperatively modifying a list in-place: L = [1,2,3,4] L.reverse() L.append([]) L.reverse() Or you can use a more functional style: L2 = reversed(reversed([1,2,3,4]) + [[]]) (or ([1,2,3,4][::-1]+[[]])[::-1], if you like that kind of thing) Imagine list.reverse and list.append *did* return self: L1 = [1,2,3,4] L2 = L1.reverse().append([]).reverse() would you expect, after this code, that (L1 == L2) and (L1 is L2)? I think it would surprise a lot of people. Better clearly separate modifying an object and functionally processing an object. Cheers Thomas From nathan.alexander.rice at gmail.com Sun Jul 11 12:28:05 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sun, 11 Jul 2010 12:28:05 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) Though TBH sometimes get annoyed at this behavior myself. There are a lot of people who are very vocal in support of returning none, and it makes sense in some ways. Since reversed returns an iterator though, it makes this code horrible and unreadable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Sun Jul 11 12:31:39 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:31:39 +0200 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: <4C39F1EB.10006@jollans.com> On 07/11/2010 07:44 AM, rantingrick wrote: > On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton > wrote: >> source at:http://github.com/lkcl/grailbrowser >> >> $ python grail.py (note the lack of "python1.5" or "python2.4") >> >> conversion of the 80 or so regex's to re has been carried out. >> entirely successfully or not is a matter yet to be determined. always >> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >> with a browser from 11+ years ago, it still cannot be resisted as >> grail is the only working graphical web browser in the world written >> in pure python [pybrowser is still in development, stalled]. >> >> l. > > Congratulations on this effort Luke. However you know what project i > would really like to see the community get around? ...dramatic pause > here... a cross platform Python file browser! Yes i know there are > tons of them out there already and Python is a bit slow, but i think > it would be useful to many peoples. Cross platform file manager. Hmm. Does "cross platform" involve UNIX and something that isn't UNIX, say, Windows? Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't be any good. The UNIX and Windows concepts of "file system" are similar enough for most programs not to care too much, but for something like a file manager, that works intimately with the file system, trying to support both UNIX and Windows is NOT a good idea. If you stick to common functionality, the program will be rather useless on both systems. Yes, you could *browse* the file system alright, but that's about it. If you attempt to be full-featured, keeping it in one code base, let alone in one user interface, is destined to be a nightmare and induce suicides. The above might have been very slightly exaggerated. Cheers! Thomas From ritchy_gato at hotmail.com Sun Jul 11 12:39:07 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Sun, 11 Jul 2010 09:39:07 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> On 11 jul, 13:28, Johan Gr?nqvist wrote: > 2010-07-11 02:12, Ritchy lelis skrev: > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > About the plot draw it's a curve that it's a set of points wich it's > > the result of the comput of the Vref and Vi together. I don't know if > > i had to make a break instruction (like in other's languages) after > > the "If" instructions if i want the else-condition to be executed? ... > > (do you have some sujestions?) > > I would have expected a code structure similar to this: > > (NOTE: This is a very inefficient solution, and not the one suggested > earlier, but it is closer to the code snippet you posted originally, and > it does produce a plot.) > > ---------------------- > import numpy as np > import matplotlib.pyplot as plt > Vref = np.linspace(1,20, 100) > Vi = np.linspace(1,10,100) > > for ref in Vref: # Loop over Vref and Vi > ? ? ?for i in Vi: > ? ? ? ? ?if ?i > ref/4: # Compute V0 > ? ? ? ? ? ? ?V0 = 2*i-ref > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > ? ? ? ? ? ? ?V0 = 2*i > ? ? ? ? ?elif i < -ref/4: > ? ? ? ? ? ? ?V0 = 2*i+ref > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > plt.show() # Display the plot in a window > ---------------------- > > > Anyway i have a picture of a tuturial that i found but in this forum i > > can't post it. That pic would show what a really want... > > Can you give a link? > > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > y-axis. > > To me this sound like you want to make a 3D-plot, as there is the > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > > As i said, i have a good 2 pic of a doc that has the information about > > this ADC that i'm developing. > > I looked on wikipedia > , and saw some > figures. Is any of those similar to what you look for? > > I see that they have (Vi - Vref) on the x-axis, and the computed value > on the y-axis. > > Regards > > Johan Hi Yes those fig look's familiar to me but for now the objective its to get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). I found in http://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF there are some fig and explanations on page's 9-13. Can you take a look there please? Also you can take a look in http://www.maxim-ic.com/app-notes/index.mvp/id/1023 (I think there it?s more information than the first link i gave you). I'll be waiting for sujestions. Thank's From thomas at jollans.com Sun Jul 11 12:39:41 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:39:41 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: <4C39F3CD.1020408@jollans.com> On 07/11/2010 06:28 PM, Nathan Rice wrote: > Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) > > Though TBH sometimes get annoyed at this behavior myself. There are a > lot of people who are very vocal in support of returning none, and it > makes sense in some ways. Since reversed returns an iterator though, it > makes this code horrible and unreadable. > ah yes, forgot about that nuance. casting reversed to list. Still, there is slicing. From python at bdurham.com Sun Jul 11 12:51:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 11 Jul 2010 12:51:28 -0400 Subject: Possible to create a read-only complex object? Message-ID: <1278867088.27525.1384321763@webmail.messagingengine.com> I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Another idea I had was to create a wrapper object to proxy all access to the original object. Is there a generic reciepe for this type of wrapper? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Sun Jul 11 12:57:02 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 09:57:02 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <4C39F1EB.10006@jollans.com> References: <4C39F1EB.10006@jollans.com> Message-ID: <4C39F7DE.50409@ixokai.io> On 7/11/10 9:31 AM, Thomas Jollans wrote: > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't > be any good. The UNIX and Windows concepts of "file system" are similar > enough for most programs not to care too much, but for something like a > file manager, that works intimately with the file system, trying to > support both UNIX and Windows is NOT a good idea. Indeed so. And you can't lump the Mac in with "UNIX" here, even though it really is UNIX at the foundation, because there's some very fundamental differences between HFS+ (and some other details that are higher level) and more traditional unix FS's. Not to mention that the Mac FS situation is slightly schitzo since it has two very different ways at looking and treating the files, the posix way and the Foundation way... and users think more in terms of the latter, usually. At least less sophisticated users. You can't do a cross-platform file manager without either doing a huge amount of work exposing each platform separately-- essentially getting separate codebases for each-- or doing a least common denominator situation, at which point I boggle: why the hell did you bother to begin with? Even Finder is better then that, let alone windows' Explorer. Even if you did the former... what the hell is the point, still? What real problem needs solving here that people should drop something and rally behind*? -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ (*): I do not argue that a non-default file manager on an OS might be a great thing. I use Path Finder on the mac and have been very pleased with it for years, and consider its purchase money very well spent. Its hands-down the absolute best file management tool ever done, in my opinion. But really. When I'm using windows (or ubuntu), the only thing I miss is the drop stack(**). I'd *almost* consider a bare-bones LCD file manager which brought only a drop stack to windows and linux to be worth the effort-- except then I'd keep having to switch over to an entirely different program whenever I wanted to do permissions, since Windows and Linux have /completely/ different permission models. (**): The drop stack is a little corner of the window that you can drag files onto. Then drag more files onto. Then drag more files onto. Then you can navigate to another part of the system, and drag files off of said stack, in a LIFO manner, moving them as a result of this action. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From solipsis at pitrou.net Sun Jul 11 13:21:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 11 Jul 2010 19:21:25 +0200 Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <20100711192125.02c4f3b0@pitrou.net> On Sun, 11 Jul 2010 08:59:06 -0700 (PDT) dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggests that this is done to make sure that > the programmer understands that the list is being modified in place, > but that rules out constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() > I want to prepend an empty list to [1,2,3,4]. This is just a toy > example, since I can always do that with [[]]+[1,2,3,4]. >>> x = [1,2,3,4] >>> y = [5,6] >>> x[:0] = y >>> x [5, 6, 1, 2, 3, 4] From python at mrabarnett.plus.com Sun Jul 11 13:23:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 18:23:21 +0100 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <4C39FE09.5030609@mrabarnett.plus.com> rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 > > If we would have adopted proper naming conventions from dios numero > uno all this nonsense would be rectified! Str, Float, List, Range, > etc, etc. You think Python 3000 was a hump to climb over just wait for > Python 4000. > > Just thoughts. If you're so unhappy with Python, why don't you create your own language. I suggest the name "Rantthon". From python at mrabarnett.plus.com Sun Jul 11 13:38:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 18:38:53 +0100 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4C39EF17.7040206@jollans.com> References: <4C39EF17.7040206@jollans.com> Message-ID: <4C3A01AD.4030209@mrabarnett.plus.com> Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: >> Why doesn't python's list append() method return the list itself? For >> that matter, even the reverse() and sort() methods? >> I found this link (http://code.google.com/edu/languages/google-python- >> class/lists.html) which suggests that this is done to make sure that >> the programmer understands that the list is being modified in place, > > Yes! > >> but that rules out constructs like: >> ([1,2,3,4].reverse()+[[]]).reverse() > > No! > > you can either approach this by imperatively modifying a list in-place: > > L = [1,2,3,4] > L.reverse() > L.append([]) > L.reverse() > [snip] If you want to prepend an empty list in-place, use the .insert method: L = [1,2,3,4] L.insert(0, []) From wherespythonmonks at gmail.com Sun Jul 11 13:48:05 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sun, 11 Jul 2010 13:48:05 -0400 Subject: Easy questions from a python beginner Message-ID: I'm an old Perl-hacker, and am trying to Dive in Python. I have some easy issues (Python 2.6) which probably can be answered in two seconds: 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>> True and print "It is true!" I found a nice work-around using eval(compile(.....,"","exec"))... Seems ugly to this Perl Programmer -- certainly Python has something better? 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y = 7; swap(x,y);" given x=7,y=3?? (I want to use Perl's Ref "\" operator, or C's &). (And if I cannot do this [other than creating an Int class], is this behavior limited to strings, ?tuples, and numbers) 3. ?Why might one want to store "strings" as "objects" in numpy arrays? ?(Maybe they wouldn't)? 4. ?Is there a way for me to make some function-definitions explicitly module-local? (Actually related to Q3 below: Is there a way to create an anonymous scope?) 5. Is there a way for me to introduce a indention-scoped variables in python? See for example: http://evanjones.ca/python-pitfall-scope.html 6. ?Is there a Python Checker that enforces?Strunk and White and is bad English grammar anti-python? ?(Only half joking) http://www.python.org/dev/peps/pep-0008/ Thanks, W From dhruvbird at gmail.com Sun Jul 11 14:07:46 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Sun, 11 Jul 2010 11:07:46 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> On Jul 11, 9:19?pm, Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: > > > Why doesn't python's list append() method return the list itself? For > > that matter, even the reverse() and sort() methods? > > I found this link (http://code.google.com/edu/languages/google-python- > > class/lists.html) which suggests that this is done to make sure that > > the programmer understands that the list is being modified in place, > > Yes! > > > but that rules out constructs like: > > ([1,2,3,4].reverse()+[[]]).reverse() > > No! > > you can either approach this by imperatively modifying a list in-place: > > L = [1,2,3,4] > L.reverse() > L.append([]) > L.reverse() > > Or you can use a more functional style: > > L2 = reversed(reversed([1,2,3,4]) + [[]]) Okay, but this assumes that I have reversed/sorted/etc... type of functions for all member functions that mutate the container. Also, as Nathan mentioned, reversed returns an iterator, whereas sorted returns a list. This asymmertic behaviour is a bit unnerving. > > (or ([1,2,3,4][::-1]+[[]])[::-1], if you like that kind of thing) > > Imagine list.reverse and list.append *did* return self: > > L1 = [1,2,3,4] > L2 = L1.reverse().append([]).reverse() > > would you expect, after this code, that (L1 == L2) and (L1 is L2)? I > think it would surprise a lot of people. Better clearly separate > modifying an object and functionally processing an object. I think this is a fair call. Honestly, I wouldn't expect them to be the same. However, there are cases when I want to be able to write down my intent in one line. Much like f(g(h(x))). On a side note, is there any other way to append to a list using slices (apart from the one below): x[len(x):len(x)] = [item to append] And while we are talking about python here, why does this statement: y = x[:0] = [100] behave the way it does? I mean everything except for the last value is assigned to the last value rather than the assignments following the chain and every item getting its succeeding item's reference? Regards, -Dhruv. From thomas at jollans.com Sun Jul 11 14:08:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 20:08:26 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A089A.8040900@jollans.com> On 07/11/2010 07:48 PM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" prior to Python 3.0, print is a statement, not an expression, which means that it's rather unflexible. In Python 3.x, print is a function, and you can use it as one: Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> True and print('It is true!') It is true! >>> > > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? Either use good old if: if True: print 'It is true!' or use a function instead of the print statement: def print_(s): print s True and print_("It is true!") > > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) You can't. A function cannot modify the caller's namespace. "x" and "y" are just names, not pointers you can edit directly. But look at this: >>> x = 1 >>> y = 2 >>> x,y = y,x >>> x 2 >>> y 1 >>> > 4. Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous scope?) Do you mean have the function visible inside the module, but not to the importer? Well, you could "del thefunc" at the end of the module, but then you won't be able to access it from within other functions. You could in principle create a function, pass it as a default argument to every function that uses it, and then delete it. But that's just silly. > > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html No. exception: nested functions. if you really want, you can always del variables after use. > > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ Huh? - Thomas From duncan.booth at invalid.invalid Sun Jul 11 14:17:49 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Jul 2010 18:17:49 GMT Subject: Easy questions from a python beginner References: Message-ID: wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>> True and print "It is true!" > > I found a nice work-around using > eval(compile(.....,"","exec"))... Seems ugly to this Perl > Programmer -- certainly Python has something better? In Python 2.x print is a statement. If you really wanted you could do: True and sys.write("It is true!\n") In Python 3 you can do this: True and print("It is true!") though I can't think of any situations where this would be better that just writing: if somecondition: print "whatever" > > 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >= 7; swap(x,y);" given x=7,y=3?? Why use a function? x, y = y, x > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > ?tuples, and numbers) If you want to use perl's operators I suggest you use perl. > > 3. ?Why might one want to store "strings" as "objects" in numpy > arrays? ?(Maybe they wouldn't)? Why would one want to write incomprehensible questions? > > 4. ?Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous > scope?) Not really. > > 5. Is there a way for me to introduce a indention-scoped variables in > python? See for example: http://evanjones.ca/python-pitfall-scope.html No. The page you reference effectively says 'my brain is used to the way Java works'. *My* brain is used to the way Python works. Who is to say which is better? > > 6. ?Is there a Python Checker that enforces?Strunk and White and is > bad English grammar anti-python? ?(Only half joking) > http://www.python.org/dev/peps/pep-0008/ > pylint will do quite a good job of picking over your code. Most people don't bother. From torriem at gmail.com Sun Jul 11 14:18:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jul 2010 12:18:54 -0600 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A0B0E.3030406@gmail.com> On 07/11/2010 11:48 AM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" This works in Python 3, or 2.6 and later with the print function: >>> True and print("It's true!") That said, this is one particular perl-ism that most python programmers don't really like. I think most python programmers prefer: if True: print "It's true!" Other perlisms like "something or die" are also to be avoided in python generally. Just state what you want: if not something: sys.exit(1) > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? Seems ugly even to Python programmers! And potentially dangerous. Just use an if statement. It's cleaner, more readable, and explicitly declares what you want. > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) I'm not sure you can. Python "variables" are names that are bound to objects. When you pass an object to a function, that object is bound to the names declared in the function. Python passes things by object, not by reference. Names are merely for convenience when accessing an object. If you want a function to be able to modify an object you have to make sure that object is mutable, or if it's not, pass it in a list (which is mutable). You probably could do something like this: (x,y) = (y,x) Seems pretty clean to me, cleaner than using a function to swap things. > 3. Why might one want to store "strings" as "objects" in numpy > arrays? (Maybe they wouldn't)? > > 4. Is there a way for me to make some function-definitions explicitly > module-local? The standard way is to declare them with a name beginning with a leading _ (underscore) to indicate that they are private and should not be accessed by others. Someone could access them if they want, though; python obviously lets programmers shoot themselves in the foot if they want. > (Actually related to Q3 below: Is there a way to create an anonymous scope?) Not that I know of. A nested function usually does enough for me. > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html Perhaps nest a function and call it? > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ From dickinsm at gmail.com Sun Jul 11 14:19:28 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 11 Jul 2010 11:19:28 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> On Jul 11, 6:38?am, rantingrick wrote: > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! Okay. What fix do you propose? Would your fix maintain the identity "0 == False"? For bonus points, explain how you'd deal with any backwards compatibility problems that your fix introduces. Have you considered forking Python? That may be the way forward here. -- Mark From me+list/python at ixokai.io Sun Jul 11 14:37:45 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 11:37:45 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A0F79.8070502@ixokai.io> On 7/11/10 10:48 AM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" Because print is a statement. Statements have to start lines. If you want to do this, use a function-- in Python 2.6 either via "from __future__ import print_function" or writing your own, even if its just a very thing wrapper around the print statement. > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) You can't do that*. Its not limited to any certain type of objects. You can't manipulate calling scopes: if you really want to do that sort of explicit namespace mangling, use dictionaries (or objects, really) as the namespace to mangle and pass them around. > 3. Why might one want to store "strings" as "objects" in numpy > arrays? (Maybe they wouldn't)? I don't use numpy. No idea. > 4. Is there a way for me to make some function-definitions explicitly > module-local? In what sense? If you prepend them with an underscore, the function won't be imported with "from x import *". You can also explicitly control what is imported in that way with a module-level __all__ attribute. Now that won't stop someone from doing "import x" and "x._your_private_function" but Python doesn't believe in enforicng restrictions. > (Actually related to Q3 below: Is there a way to create an anonymous scope?) No. You can create a limited anonymous function with lambda, but note it takes only an expression-- no statements in it. > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html No. Python only has three scopes historically; local, global, and builtin. Then post-2.2(ish, I forget) limited nested scoping -- but only with nested functions, and you can't (until Python 3) re-bind variables in outer scopes (though you can modify them if they are mutable objects). Python's scoping is very basic (we generally think this is a good thing; others are never happy with it) and is not fully lexical scoped. > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ Check out pylint and/or pychecker, which do various style-based checking. If you're asking for something else, I can't pierce your sarcasm to figure out what. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * Yes, I know its actually possible, to manipulate outer/calling scopes with frame hacking. This is dangerous / bad / an implementation detail that one should not rely on or use, generally speaking. If you need to do this you're writing Java or Perl or C in Python, instead of writing Python in Python, so are probably doing all kinds of things that are slow / bad / dangerous / just not taking advantage of Python's strengths. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wherespythonmonks at gmail.com Sun Jul 11 14:45:46 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sun, 11 Jul 2010 14:45:46 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: Thanks for your answers -- it is much appreciated. On #1: I had very often used chained logic with both logging and functional purposes in Perl, and wanted to duplicate this in Python. "It reads like english" Using the print_ print wrapper works for me. Follow-up: Is there a way to define compile-time constants in python and have the bytecode compiler optimize away expressions like: if is_my_extra_debugging_on: print ... when "is_my_extra_debugging" is set to false? I'd like to pay no run-time penalty for such code when extra_debugging is disabled. On #2: My point regarding the impossibility of writing the swap function for ints is to explicitly understand that this isn't possible, so as not to look for solutions along those lines when trying to write python code. On #3: Sorry this is confusing, but I was browsing some struct array code from numpy, in which one of the columns contained strings, but the type information, supplied in numpy.array's dtype argument, specified the type as a an "object" not a string. Just wondering why one would do that. On #4: So there are some hacks, but not something as easy as "import unimportable" or an @noexport decorator. The underscore works, so does "del". On #5: Nesting the function was actually what I was thinking of doing, but alas, I cannot modify outer-scope variables within a function, and of course, I don't want to use globals. On #6: Always trying to improve my writing -- and I thought it was cute that Guido tries to encourage this as well. I am programmer who likes to scope off variables as much as possible (I believe in minimal state). The following is an example of what I am trying to protect against: http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters Will try to avoid namespace mangling until next week. Thanks again, W On Sun, Jul 11, 2010 at 2:17 PM, Duncan Booth wrote: > wheres pythonmonks wrote: > >> I'm an old Perl-hacker, and am trying to Dive in Python. ?I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>>> True and print "It is true!" >> >> I found a nice work-around using >> eval(compile(.....,"","exec"))... Seems ugly to this Perl >> Programmer -- certainly Python has something better? > > In Python 2.x print is a statement. If you really wanted you could do: > > ? True and sys.write("It is true!\n") > > In Python 3 you can do this: > > ? True and print("It is true!") > > though I can't think of any situations where this would be better that just > writing: > > ? if somecondition: print "whatever" > >> >> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >>= 7; swap(x,y);" given x=7,y=3?? > > Why use a function? > > ? x, y = y, x > >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> ?tuples, and numbers) > > If you want to use perl's operators I suggest you use perl. > >> >> 3. ?Why might one want to store "strings" as "objects" in numpy >> arrays? ?(Maybe they wouldn't)? > > Why would one want to write incomprehensible questions? > >> >> 4. ?Is there a way for me to make some function-definitions explicitly >> module-local? >> (Actually related to Q3 below: Is there a way to create an anonymous >> scope?) > > Not really. > >> >> 5. Is there a way for me to introduce a indention-scoped variables in >> python? See for example: http://evanjones.ca/python-pitfall-scope.html > > No. The page you reference effectively says 'my brain is used to the way > Java works'. *My* brain is used to the way Python works. Who is to say > which is better? > >> >> 6. ?Is there a Python Checker that enforces?Strunk and White and is >> bad English grammar anti-python? ?(Only half joking) >> http://www.python.org/dev/peps/pep-0008/ >> > pylint will do quite a good job of picking over your code. Most people > don't bother. > -- > http://mail.python.org/mailman/listinfo/python-list > From me+list/python at ixokai.io Sun Jul 11 15:00:52 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 12:00:52 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A14E4.4040902@ixokai.io> On 7/11/10 11:45 AM, wheres pythonmonks wrote: > Follow-up: > Is there a way to define compile-time constants in python and have the > bytecode compiler optimize away expressions like: > > if is_my_extra_debugging_on: print ... > > when "is_my_extra_debugging" is set to false? I'd like to pay no > run-time penalty for such code when extra_debugging is disabled. Any code wrapped in a __debug__ guard is utterly ommitted if you run Python with the -O option. That, and asserts go away. > On #2: My point regarding the impossibility of writing the swap > function for ints is to explicitly understand that this isn't > possible, so as not to look for solutions along those lines when > trying to write python code. Its impossible because Python's calling and namespace semantics simply don't work like that. There's no references in the traditional sense, because there's no variables-- boxes that you put values in. There's just concrete objects. Objects are passed into the function and given new names; that those objects have names in the enclosing scope is something you don't know, can't access, and can't manipulate.. even the objects don't know what names they happen to be called. Check out http://effbot.org/zone/call-by-object.htm > On #3: Sorry this is confusing, but I was browsing some struct array > code from numpy, in which one of the columns contained strings, but > the type information, supplied in numpy.array's dtype argument, > specified the type as a an "object" not a string. Just wondering why > one would do that. Strings are objects. I don't use numpy, btu I'd assume "object" would basically mean, "anything can go here", as everything is an object. > On #5: Nesting the function was actually what I was thinking of doing, > but alas, I cannot modify outer-scope variables within a function, and > of course, I don't want to use globals. You can modify outer-scope objects: if they are mutable. I.e., a dictionary. What you can't do is modify outer *scopes*, the namespaces. You can't re-bind a new/different object to a certain name in an outer scope. > I am programmer who likes to scope off variables as much as possible > (I believe in minimal state). That's a fine and nice goal. In Python your only real tool for this is to break things up into more logical functions. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Sun Jul 11 15:09:57 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 21:09:57 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A1705.6050603@jollans.com> On 07/11/2010 08:45 PM, wheres pythonmonks wrote: > Thanks for your answers -- it is much appreciated. > > On #1: I had very often used chained logic with both logging and > functional purposes in Perl, and wanted to duplicate this in Python. > "It reads like english" Using the print_ print wrapper works for me. > > Follow-up: > Is there a way to define compile-time constants in python and have the > bytecode compiler optimize away expressions like: > > if is_my_extra_debugging_on: print ... > > when "is_my_extra_debugging" is set to false? I'd like to pay no > run-time penalty for such code when extra_debugging is disabled. no. > On #3: Sorry this is confusing, but I was browsing some struct array > code from numpy, in which one of the columns contained strings, but > the type information, supplied in numpy.array's dtype argument, > specified the type as a an "object" not a string. Just wondering why > one would do that. No expert on numpy, but maybe storing object references is cheaper than storing strings here ? > > On #5: Nesting the function was actually what I was thinking of doing, > but alas, I cannot modify outer-scope variables within a function, and > of course, I don't want to use globals. yes you can. Well, at least since whenever the "nonlocal" keyword was introduced (recent, might be 3.x only) Or you can wrap what you want to change in a dict or list. > I am programmer who likes to scope off variables as much as possible > (I believe in minimal state). > > The following is an example of what I am trying to protect against: > http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters On the other hand, python scoping and namespace rules, while they may be different to those in other languages, are nice and simple. > Will try to avoid namespace mangling until next week. Cheers - Thomas From alf.p.steinbach+usenet at gmail.com Sun Jul 11 15:37:28 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 21:37:28 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * Stephen Hansen, on 11.07.2010 21:00: > On 7/11/10 11:45 AM, wheres pythonmonks wrote: >> Follow-up: >> Is there a way to define compile-time constants in python and have the >> bytecode compiler optimize away expressions like: >> >> if is_my_extra_debugging_on: print ... >> >> when "is_my_extra_debugging" is set to false? I'd like to pay no >> run-time penalty for such code when extra_debugging is disabled. > > Any code wrapped in a __debug__ guard is utterly ommitted if you run > Python with the -O option. That, and asserts go away. > >> On #2: My point regarding the impossibility of writing the swap >> function for ints is to explicitly understand that this isn't >> possible, so as not to look for solutions along those lines when >> trying to write python code. > > Its impossible because Python's calling and namespace semantics simply > don't work like that. There's no references in the traditional sense, > because there's no variables-- boxes that you put values in. There's > just concrete objects. Objects are passed into the function and given > new names; that those objects have names in the enclosing scope is > something you don't know, can't access, and can't manipulate.. even the > objects don't know what names they happen to be called. > > Check out http://effbot.org/zone/call-by-object.htm Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like Java in this respect, that's all; neither Java nor Python support 'swap'. Of course there are variables, that's why the docs call them variables. We've had this discussion before and I know from that that it is a religious issue with a small subset of the Python community, where reason, facts, logic does not apply and is not even recognized as such. So be it. So I'm not out to convince you or other of that sub-community, or trying to reason with you folks on this issue (futile, and generates flames pretty fast), but I do not want newbies brainwashed into that non-reasoning nonsense pure faith religion. For what it's worth, I'm sure that the effbot.org author, whose pages are otherwise quite technically meaningful & useful, in this case, after the flame war with some Java folks, decided that technical accuracy just wasn't worth it. So, I believe, he punted, which is an eminently rational choice when one's goals require acceptance in a society dominated by a religious clique. And just as I'm not out to engage you in any debate on this issue (futile), neither am I calling you irrational. Perhaps your choice is the same as that author's. Cheers, - Alf -- blog at From dkelley21 at gmail.com Sun Jul 11 16:18:39 2010 From: dkelley21 at gmail.com (dk) Date: Sun, 11 Jul 2010 13:18:39 -0700 (PDT) Subject: Getting started with python on macintosh snow leopard with mysql - need help Message-ID: I have been going round and round trying to configure python 2.6 running on osx 10.6.x to work with mySQL 5.1.44. Python seems to work ... i have an installation of mysql 5.1.44 running and have used it in conjunction for other php/apache projects. I want to learn python and think i need a better database then mysql lite that installs with the web2py frame work, so my quest to connect to mysql or postgres began. I seem to be stuck stuck getting mySQLdb drivers installed. I down loaded python 2.6.5 from the python site and MySQL-python-1.2.3 from the my sql site. I have worked past numerous errors by i now get the errors below when i try to compile. -- some background that might help anyone kind enough to have read this far and who might be inclined to take pitty -- I have (tried) to use macports to install setuptools (which MySQL- python-1.2.3 says it needs). MacPorts has put tons of stuff in /opt/local ... so i am not sure i am using this tool the way its intended. this could all be as simple as adding some path declarations in the right place but where? lots of the post i have seen on the subject talk about 32/64 installation ... it makes sense that you might need to be consistent in getting your components to work together, but i am not sure how i tell of the various parts i have install which and how they were compiled. whereis python display /usr/bin/python python -v spits out lots ... but here is a sample: # /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ encodings/utf_8.pyc matches /Library/Frameworks/Python.framework/ Versions/2.6/lib/python2.6/encodings/utf_8.py import encodings.utf_8 # precompiled from /Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.pyc Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin when i try to compile mysql-python-1.2.3 i get the following error returned from python setup.py build ----- building '_mysql' extension gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL In file included from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/unicodeobject.h:4, from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/Python.h:85, from pymemcompat.h:10, from _mysql.c:29: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" redefined In file included from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ pyconfig.h:808:1: warning: this is the location of the previous definition error: command 'gcc-4.0' failed with exit status 1 From john at castleamber.com Sun Jul 11 16:50:50 2010 From: john at castleamber.com (John Bokma) Date: Sun, 11 Jul 2010 15:50:50 -0500 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <87aapxyc7p.fsf@castleamber.com> Thomas Jollans writes: > On 07/11/2010 07:44 AM, rantingrick wrote: >> On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton >> wrote: >>> source at:http://github.com/lkcl/grailbrowser >>> >>> $ python grail.py (note the lack of "python1.5" or "python2.4") >>> >>> conversion of the 80 or so regex's to re has been carried out. >>> entirely successfully or not is a matter yet to be determined. always >>> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >>> with a browser from 11+ years ago, it still cannot be resisted as >>> grail is the only working graphical web browser in the world written >>> in pure python [pybrowser is still in development, stalled]. >>> >>> l. >> >> Congratulations on this effort Luke. However you know what project i >> would really like to see the community get around? ...dramatic pause >> here... a cross platform Python file browser! Yes i know there are >> tons of them out there already and Python is a bit slow, but i think >> it would be useful to many peoples. > > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't > be any good. The UNIX and Windows concepts of "file system" are similar > enough for most programs not to care too much, but for something like a > file manager, that works intimately with the file system, trying to > support both UNIX and Windows is NOT a good idea. Can't think of why not. Of course not all operations are shared by each OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean that on Windows I can't make a file only readable by me. Just give me the Windows security options on Windows, and chmod on *nix and I would be very happy. Especially if all can be done via a context menu a la RISC OS. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From pavlovevidence at gmail.com Sun Jul 11 16:52:34 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jul 2010 13:52:34 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: On Jul 11, 10:48?am, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. Welcome to the light. >?I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. ?Why is it that I cannot use print in booleans?? ?e.g.: > > >>> True and print "It is true!" > > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? I'll repeat other people's sentiments: if you drop nothing else from your perl habits, drop this one. > 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > ?tuples, and numbers) Can't do it, but you can get reference-like behavior if you don't mind a level of indirection. For example: def swap(x,y): t = y[0] y[0] = x[0] x[0] = t a = [1] b = [2] swap(a,b) There's no reason to do this for a swap() function, as you've already seen. But it is sometimes handy for other things. (This includes certain idioms involving regualar expression that are common in Perl. Perl uses some special semantics when performing regexp searches that allow automatic binding of match results. Python doesn't, so in some cases it's helpful to define an object you can mutate to store that information.) In the more general sense, Python functions and methods that mutate the object they operate on are pretty common. > 3. ?Why might one want to store "strings" as "objects" in numpy > arrays? ?(Maybe they wouldn't)? numpy is a library designed mainly to store numerical data, with some advanced slicing operations and other cool stuff like multdimensionality. Some people, however, want to use the cool slicing operations on arrays of Python objects, so numpy has a storage mode for arbitrary Python objects. (If you're wondering why they use object instead of a character type, it's because rows of such an array are fixed-length strings. Main reason to use those is to interface with Fortran string arrays, or maybe to simulate crossword puzzles or something.) > 4. ?Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous scope?) No. The (loose) convention is to define local or private functions with a leading underscore to label them as "intended for internal use only". > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example:http://evanjones.ca/python-pitfall-scope.html Yes, define a nested function. In Python 2 it's limited since you cannot rebind variables in the surrounding scope; that's possible in Python 3, though. > 6. ?Is there a Python Checker that enforces?Strunk and White and is > bad English grammar anti-python? ?(Only half joking)http://www.python.org/dev/peps/pep-0008/ There's a few, PyChecker and PyLint get mentioned a lot. I used to use them until I noticed that it never actually caught anything (except stuff I didn't care about like using "id" as a variable name). Carl Banks From pavlovevidence at gmail.com Sun Jul 11 17:03:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jul 2010 14:03:52 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <98f2d8c8-09f5-4d72-9ecb-94c186f45f7c@z15g2000prn.googlegroups.com> On Jul 11, 11:45?am, wheres pythonmonks wrote: > On #4: ?So there are some hacks, but not something as easy as "import > unimportable" or an @noexport decorator. ?The underscore works, so > does "del". Careful. If you have a module that looks like this: def foo(): bar() def bar(): print "hello" del bar # bar is an internal function It won't work; foo will raise NameError on bar if you try that. However, del is useful to clean up code you run at module import time, for example: squares = [] for i in xrange(101): squares.append(i*i) del i Carl Banks From news1234 at free.fr Sun Jul 11 17:08:31 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 23:08:31 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4c3a32cf$0$14947$426a34cc@news.free.fr> Carl Banks wrote: > On Jul 11, 10:48 am, wheres pythonmonks > wrote: >> I'm an old Perl-hacker, and am trying to Dive in Python. > > Welcome to the light. > > >> I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. Why is it that I cannot use print in booleans?? e.g.: >> >>>>> True and print "It is true!" >> I found a nice work-around using eval(compile(.....,"","exec"))... >> Seems ugly to this Perl Programmer -- certainly Python has something better? > > I'll repeat other people's sentiments: if you drop nothing else from > your perl habits, drop this one. > > >> 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y >> = 7; swap(x,y);" given x=7,y=3?? >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> tuples, and numbers) > > Can't do it, but you can get reference-like behavior if you don't mind > a level of indirection. For example: > > def swap(x,y): > t = y[0] > y[0] = x[0] > x[0] = t > > a = [1] > b = [2] > swap(a,b) or def swap[x,y]: x[0],y[0] = y[0],x[0] From clp2 at rebertia.com Sun Jul 11 17:16:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 14:16:01 -0700 Subject: Easy questions from a python beginner In-Reply-To: <4c3a32cf$0$14947$426a34cc@news.free.fr> References: <4c3a32cf$0$14947$426a34cc@news.free.fr> Message-ID: On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote: > Carl Banks wrote: >> On Jul 11, 10:48 am, wheres pythonmonks >> wrote: >>> I'm an old Perl-hacker, and am trying to Dive in Python. >> >> Welcome to the light. >> >> >>> ?I have some >>> easy issues (Python 2.6) >>> which probably can be answered in two seconds: >>> >>> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>> >>>>>> True and print "It is true!" >>> I found a nice work-around using eval(compile(.....,"","exec"))... >>> Seems ugly to this Perl Programmer -- certainly Python has something better? >> >> I'll repeat other people's sentiments: if you drop nothing else from >> your perl habits, drop this one. >> >> >>> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >>> = 7; swap(x,y);" given x=7,y=3?? >>> (I want to use Perl's Ref "\" operator, or C's &). >>> (And if I cannot do this [other than creating an Int class], is this >>> behavior limited to strings, >>> ?tuples, and numbers) >> >> Can't do it, but you can get reference-like behavior if you don't mind >> a level of indirection. ?For example: >> >> def swap(x,y): >> ? ? t = y[0] >> ? ? y[0] = x[0] >> ? ? x[0] = t >> >> a = [1] >> b = [2] >> swap(a,b) > > or > def swap[x,y]: > ? ?x[0],y[0] = y[0],x[0] >>> def swap[x,y]: File "", line 1 def swap[x,y]: ^ SyntaxError: invalid syntax Cheers, Chris From news1234 at free.fr Sun Jul 11 17:18:16 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 23:18:16 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3a32cf$0$14947$426a34cc@news.free.fr> Message-ID: <4c3a3518$0$9132$426a74cc@news.free.fr> Chris Rebert wrote: > On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote: >> Carl Banks wrote: >>> On Jul 11, 10:48 am, wheres pythonmonks >>> wrote: >>>> I'm an old Perl-hacker, and am trying to Dive in Python. >>> Welcome to the light. >>> >>> >>>> I have some >>>> easy issues (Python 2.6) >>>> which probably can be answered in two seconds: >>>> >>>> 1. Why is it that I cannot use print in booleans?? e.g.: >>>> >>>>>>> True and print "It is true!" >>>> I found a nice work-around using eval(compile(.....,"","exec"))... >>>> Seems ugly to this Perl Programmer -- certainly Python has something better? >>> I'll repeat other people's sentiments: if you drop nothing else from >>> your perl habits, drop this one. >>> >>> >>>> 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y >>>> = 7; swap(x,y);" given x=7,y=3?? >>>> (I want to use Perl's Ref "\" operator, or C's &). >>>> (And if I cannot do this [other than creating an Int class], is this >>>> behavior limited to strings, >>>> tuples, and numbers) >>> Can't do it, but you can get reference-like behavior if you don't mind >>> a level of indirection. For example: >>> >>> def swap(x,y): >>> t = y[0] >>> y[0] = x[0] >>> x[0] = t >>> >>> a = [1] >>> b = [2] >>> swap(a,b) >> or >> def swap[x,y]: >> x[0],y[0] = y[0],x[0] > >>>> def swap[x,y]: > File "", line 1 > def swap[x,y]: apologies: I meant def swap(x,y): x[0],y[0] = y[0],x[0] a = [1] b = [2] swap(a,b) From clp2 at rebertia.com Sun Jul 11 17:22:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 14:22:11 -0700 Subject: Possible to create a read-only complex object? In-Reply-To: <1278867088.27525.1384321763@webmail.messagingengine.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: On Sun, Jul 11, 2010 at 9:51 AM, wrote: > I have a complex object with attributes that contain lists, sets, > dictionaries, and other objects. The lists and dictionaries may themselves > contain complex objects. > > I would like to provide a read-only version of this type of object for other > developers to query for reporting. > > Is there a way to prevent other developers from changing the attributes of > my complex and nested object? Have you considered just making a deep copy of your object instead? That way, others could inspect the copy and mess with it all they want, without affecting the original. http://docs.python.org/library/copy.html#copy.deepcopy Cheers, Chris -- http://blog.rebertia.com From drsalists at gmail.com Sun Jul 11 18:13:54 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 11 Jul 2010 15:13:54 -0700 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: References: <4C39CC89.8070500@jollans.com> Message-ID: You could probably: cd to dir1 getcwd cd to dir2 getcwd repeat cd .. getcwd if getcwd == dir1's cwd, then under until at / cd to dir1 repeat cd .. getcwd if getcwd == dir2's cwd, then under until at / This should deal with symlinks and junctions, as long as you aren't worried about permissions issues on directories. On Sun, Jul 11, 2010 at 7:34 AM, Gelonida wrote: > Hi Thomas, > > Thomas Jollans wrote: > > On 07/11/2010 03:37 PM, Gelonida wrote: > >> ################################################# > >> import os > >> def is_below_dir(fname,topdir): > >> relpath = os.path.relpath(fname,topdir) > >> return not relpath.startswith('..'+os.sep) > >> > >> print is_below_dir(path1,path2) > >> ################################################# > >> The basic idea is, if the path name of path1 > >> relative to path2 does NOT start with '..', then > >> it must be below path2 > >> > >> > >> Does anybody see pitfalls with that solution? > >> Is there by any chance a function, that I overlooked, > >> which does already what I'd like to do? > > > > It probably won't work on Windows because it isolates volumes (drive > > letters). What does, for example, os.path.relpath do when > > you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two > > reasonably correct options: > Thanks, Indeed. different drives raise an ecception. > I could catch the ValueError and let it just return False > > > > > either raise an exception (there is no relative path) or return the > > absolute path, which doesn't start with .. > > > > On UNIX, the only potential problem I see is that it may or may not do > > what you expect when symlinks are involved somewhere. > > Also true. In my case I'd prefer it would not follow, but > it doesn't really matter. > > > So my function in order to be portable > had now to look like: > ################################################# > import os > def is_below_dir(fname,topdir): > try: > relpath = os.path.relpath(fname,topdir) > except ValueError: > return False > return not relpath.startswith('..'+os.sep) > > print is_below_dir(path1,path2) > ################################################# > > if I wanted to folow symlinks, then had to apply > os.path.realpath() on > fname AND on topdir > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at gmail.com Sun Jul 11 18:28:34 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Sun, 11 Jul 2010 15:28:34 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: On Jul 11, 5:16?pm, rantingrick wrote: > On Jul 11, 9:01?am, a... at pythoncraft.com (Aahz) wrote: > > > As usual, you would rather tell other people what to do instead of doing > > any work yourself. > > Dear God! My statement was intended to fetch responses like... > > ? "Hey, that sounds like a great idea" or \ > ? "Hey, lets get hacking on this". > > I am so sick of you people constantly accusing me of being lazy. You > don't even know me. Also i think you're really a bit jealous because i > have the brass cohones to initiate a coding project without your > express written permission. I will not allow myself to be brow beaten > by anyone! But why hijack someone else's announcement to do that? Congratulations alone would have been great. However good your intentions your message came across as "but it would really have been better if you had been doing something else instead...". All the best, Michael Foord -- http://www.voidspace.org.uk/ From rantingrick at gmail.com Sun Jul 11 18:36:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 15:36:52 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <569e34f0-4da0-49a9-a8d2-c23c4424daf0@j8g2000yqd.googlegroups.com> On Jul 11, 12:23?pm, MRAB wrote: > If you're so unhappy with Python, why don't you create your own > language. I suggest the name "Rantthon". Ah yes, then i can finally assume my worthy title of the "Ranting Dictator For Life"! ;-) From python at mrabarnett.plus.com Sun Jul 11 18:37:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 23:37:39 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A47B3.3060502@mrabarnett.plus.com> Alf P. Steinbach /Usenet wrote: > * Stephen Hansen, on 11.07.2010 21:00: >> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>> Follow-up: >>> Is there a way to define compile-time constants in python and have the >>> bytecode compiler optimize away expressions like: >>> >>> if is_my_extra_debugging_on: print ... >>> >>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>> run-time penalty for such code when extra_debugging is disabled. >> >> Any code wrapped in a __debug__ guard is utterly ommitted if you run >> Python with the -O option. That, and asserts go away. >> >>> On #2: My point regarding the impossibility of writing the swap >>> function for ints is to explicitly understand that this isn't >>> possible, so as not to look for solutions along those lines when >>> trying to write python code. >> >> Its impossible because Python's calling and namespace semantics simply >> don't work like that. There's no references in the traditional sense, >> because there's no variables-- boxes that you put values in. There's >> just concrete objects. Objects are passed into the function and given >> new names; that those objects have names in the enclosing scope is >> something you don't know, can't access, and can't manipulate.. even the >> objects don't know what names they happen to be called. >> >> Check out http://effbot.org/zone/call-by-object.htm > > Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python > works like Java in this respect, that's all; neither Java nor Python > support 'swap'. > > Of course there are variables, that's why the docs call them variables. > In Java a variable is declared and exists even before the first assignment to it. In Python a 'variable' isn't declared and won't exist until the first 'assignment' to it. From martin.hellwig at dcuktec.org Sun Jul 11 18:39:32 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 11 Jul 2010 23:39:32 +0100 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: On 07/11/10 04:59, Luke Kenneth Casson Leighton wrote: > source at: > http://github.com/lkcl/grailbrowser > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > conversion of the 80 or so regex's to re has been carried out. > entirely successfully or not is a matter yet to be determined. always > a hoot to try browsing http://www.bbc.co.uk or http://www.youtube.com > with a browser from 11+ years ago, it still cannot be resisted as > grail is the only working graphical web browser in the world written > in pure python [pybrowser is still in development, stalled]. > > l. Congrats! Are you planning to take over the world with grail and pyjs? :-) -- mph From python at mrabarnett.plus.com Sun Jul 11 18:55:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 23:55:04 +0100 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <87aapxyc7p.fsf@castleamber.com> References: <87aapxyc7p.fsf@castleamber.com> Message-ID: <4C3A4BC8.1090106@mrabarnett.plus.com> John Bokma wrote: > Thomas Jollans writes: > >> On 07/11/2010 07:44 AM, rantingrick wrote: >>> On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton >>> wrote: >>>> source at:http://github.com/lkcl/grailbrowser >>>> >>>> $ python grail.py (note the lack of "python1.5" or "python2.4") >>>> >>>> conversion of the 80 or so regex's to re has been carried out. >>>> entirely successfully or not is a matter yet to be determined. always >>>> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >>>> with a browser from 11+ years ago, it still cannot be resisted as >>>> grail is the only working graphical web browser in the world written >>>> in pure python [pybrowser is still in development, stalled]. >>>> >>>> l. >>> Congratulations on this effort Luke. However you know what project i >>> would really like to see the community get around? ...dramatic pause >>> here... a cross platform Python file browser! Yes i know there are >>> tons of them out there already and Python is a bit slow, but i think >>> it would be useful to many peoples. >> Cross platform file manager. Hmm. Does "cross platform" involve UNIX and >> something that isn't UNIX, say, Windows? >> Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't >> be any good. The UNIX and Windows concepts of "file system" are similar >> enough for most programs not to care too much, but for something like a >> file manager, that works intimately with the file system, trying to >> support both UNIX and Windows is NOT a good idea. > > Can't think of why not. Of course not all operations are shared by each > OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean > that on Windows I can't make a file only readable by me. Just give me > the Windows security options on Windows, and chmod on *nix and I would > be very happy. > On Windows the root folders of the different drives could be treated as subfolders of a 'root' folder. > Especially if all can be done via a context menu a la RISC OS. > Ah, RISC OS! I'd heard how user-friendly the Mac was, but when I was first introduced to the Mac (circa MacOS 8) I was very surprised that even it still used old-fashioned Open and Save dialog boxes with their own little file browsers like on a Windows PC instead of drag-and-drop like I'd become used to on RISC OS. And that menu bar not even at the top of the window but at the top of the _screen_! And the way that bringing one Finder window to the front brought _all_ the Finder windows in front of the other windows! I was distinctly underwhelmed... :-( From rantingrick at gmail.com Sun Jul 11 19:22:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 16:22:41 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> Message-ID: <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> On Jul 11, 1:19?pm, Mark Dickinson wrote: > Okay. ?What fix do you propose? ?Would your fix maintain the identity > "0 == False"? No because all integers should bool True. An integer is a value that IS NOT empty and IS NOT None. Therefore the only logical way to handle integer bool-ing is to say they are all True. > For bonus points, explain how you'd deal with any > backwards compatibility problems that your fix introduces. We would't deal with backwards compatibility as this notion of bool(1) == True and bool(0) == False if backwards way of thinking. Sure it saves a few keystrokes but in the end only serves to obfuscate the code and promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF True AND 0 IN PLACE OF False! > Have you considered forking Python? ?That may be the way forward here. I have considered this many times in the past and continue to consider it even today. I believe the Python language to be the best high level language ever created up to this point. I also believe GvR to be a true genius who has forged the path of all 21st century high level languages. However, like all new inventions eventually the bright shiny paint job starts to oxidize and expose the rotten and rusting core that has been slowly disintegrating behind the scenes all along. GvR stood on the shoulders of giants to reach the plateau of elegant bliss that we know today as Python programming. As we all know perfection will never be achieved, only lusted after forever and ever. A perpetual game of cat and mouse. So maybe it is now time for the next genius (Rick?) to stand on Guido's shoulders and reach the next "cookie-jar-of-programming-enlightenment" one shelf higher than Guido's cookies where found. Maybe it was fate that CPython 3000 would disturb so many folks as to create a question in their minds... A splinter lodged deep within the mind constantly tickling new never before thoughts to form... "Is Python all it can be?". A lustful yearning to fix the warts that have been ignored for far too long and were scarified at the alter of the simplistic development cycle. But i think we are now at a crossroads people. We must forge the new path and resist the temptation to circle around the familiar roads endlessly. Heck *maybe* Guido himself is the architect of this change? Maybe he *purposely* sowed discontent in an effort to ignite (or reignite?) a passion for change within this community...? The black monolith is before us. We have reached a crossroads. In the balance hangs the future of high level programming languages. Will we understand what the portal is and take the leap of faith forward, or just bang some bones around like toddlers for another 10,000 years? Only time will tell...? Only time will tell...? From rantingrick at gmail.com Sun Jul 11 19:44:10 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 16:44:10 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 11:31?am, Thomas Jollans wrote: > On 07/11/2010 07:44 AM, rantingrick wrote: > > Congratulations on this effort Luke. However you know what project i > > would really like to see the community get around? ...dramatic pause > > here... a cross platform Python file browser! > > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work....... trying to > support both UNIX and Windows is NOT a good idea. Why is that a bad idea, Python does it all the time? Many software so it all the time. This sounds like more fear than anything. If you attempt to be full-featured, keeping it in one > code base, let alone in one user interface, is destined to be a > nightmare and induce suicides. Thats False! > The above might have been very slightly exaggerated. Thats True! From debatem1 at gmail.com Sun Jul 11 20:00:02 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 11 Jul 2010 20:00:02 -0400 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 7:22 PM, rantingrick wrote: > On Jul 11, 1:19?pm, Mark Dickinson wrote: > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity >> "0 == False"? > > No because all integers should bool True. An integer is a value that > IS NOT empty and IS NOT None. Therefore the only logical way to handle > integer bool-ing is to say they are all True. > >> For bonus points, explain how you'd deal with any >> backwards compatibility problems that your fix introduces. > > We would't deal with backwards compatibility as this notion of bool(1) > == True and bool(0) == False if backwards way of thinking. Sure it > saves a few keystrokes but in the end only serves to obfuscate the > code and promote bad programming styles. WE SHOULD NEVER BE USING 1 IN > PLACE OF True AND 0 IN PLACE OF False! > >> Have you considered forking Python? ?That may be the way forward here. > > ?I have considered this many times in the past and continue to > consider it even today. I believe the Python language to be the best > high level language ever created up to this point. I also believe GvR > to be a true genius who has forged the path of all 21st century high > level languages. However, like all new inventions eventually the > bright shiny paint job starts to oxidize and expose the rotten and > rusting core that has been slowly disintegrating behind the scenes all > along. > > ?GvR stood on the shoulders of giants to reach the plateau of elegant > bliss that we know today as Python programming. As we all know > perfection will never be achieved, only lusted after forever and ever. > A perpetual game of cat and mouse. So maybe it is now time for the > next genius (Rick?) to stand on Guido's shoulders and reach the next > "cookie-jar-of-programming-enlightenment" one shelf higher than > Guido's cookies where found. > > ?Maybe it was fate that CPython 3000 would disturb so many folks as to > create a question in their minds... A splinter lodged deep within the > mind constantly tickling new never before thoughts to form... "Is > Python all it can be?". A lustful yearning to fix the warts that have > been ignored for far too long and were scarified at the alter of the > simplistic development cycle. > > ?But i think we are now at a crossroads people. We must forge the new > path and resist the temptation to circle around the familiar roads > endlessly. Heck *maybe* Guido himself is the architect of this change? > Maybe he *purposely* sowed discontent in an effort to ignite (or > reignite?) a passion for change within this community...? > > The black monolith is before us. We have reached a crossroads. In the > balance hangs the future of high level programming languages. Will we > understand what the portal is and take the leap of faith forward, or > just bang some bones around like toddlers for another 10,000 years? > Only time will tell...? Only time will tell...? I literally laughed out loud as I read this. Go write some code, might help connect you back to reality. Geremy Condra From rantingrick at gmail.com Sun Jul 11 20:01:03 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:01:03 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <4C39F1EB.10006@jollans.com> Message-ID: <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> On Jul 11, 11:57?am, Stephen Hansen wrote: > On 7/11/10 9:31 AM, Thomas Jollans wrote: > > trying to > > support both UNIX and Windows is NOT a good idea. > > And you can't lump the Mac in with "UNIX" here, even though it really is > UNIX at the foundation, because there's some very fundamental > differences between HFS+ (and some other details that are higher level) > and more traditional unix FS's. Not to mention that the Mac FS situation > is slightly schitzo since it has two very different ways at looking and > treating the files, the posix way and the Foundation way... and users > think more in terms of the latter, usually. At least less sophisticated > users. Sure you can! Have you ever heard of a *rare* module by the name of "os"? Yes i know *nobody* uses it but it works nonetheless! > You can't do a cross-platform file manager without either doing a huge > amount of work exposing each platform separately-- essentially getting > separate codebases for each-- or doing a least common denominator > situation, at which point I boggle: why the hell did you bother to begin > with? Even Finder is better then that, let alone windows' Explorer. Nothing is worse than InternetExploder\Exploder, nothing! And whats wrong with seperate code bases, it's three modules and a startup script... if sys.platform == 'win32': import fm32 elif sys.platform == 'darwin': import fmdarwin elif sys.platform == 'nix': import fmnix We just recently had a discussion about CONDITIONALS Stephen have you forgotten already? > (*): I do not argue that a non-default file manager on an OS might be a > great thing. Now you're talking! > (**): The drop stack is a little corner of the window that you can drag > files onto. Then drag more files onto. Then drag more files onto. Then > you can navigate to another part of the system, and drag files off of > said stack, in a LIFO manner, moving them as a result of this action. This drop stack sound interesting. I've always hated the cut paste as you could not add to the cut buffer. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:02:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:02:20 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> On Sat, 10 Jul 2010 23:50:05 -0700, rantingrick wrote: > You do realize that > Python must build a tuple for ever conditional that uses this semantic? > This is more bad, bad, bad than integer bool-ing! My bin packer could > potentially compute millions of parts. I do not want to waste valuable > processor cycles building numerous tuples just for the sake of a > conditional "condition"! This is bad coding style Stephen. No, premature optimization is bad coding. Building a tuple is extremely fast: $ python -m timeit "x = ()" 1000000 loops, best of 3: 0.316 usec per loop $ python -m timeit "x = False" 1000000 loops, best of 3: 0.36 usec per loop Testing is fast too: $ python -m timeit "x = (); 1 if x else 2" 1000000 loops, best of 3: 0.663 usec per loop $ python -m timeit "x = False; 1 if x else 2" 1000000 loops, best of 3: 0.969 usec per loop You've been around here long enough that you should know better. Stop wasting your time, and ours, ranting over the enormous cost of things that aren't costly at all. Come back when you have profiled your code and can prove that the cost of building empty tuples is an actual bottleneck. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:06:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:06:15 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4c3a5c77$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote: > On Jul 11, 3:03?am, "G?nther Dietrich" wrote: > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? If you're going to use generic names, why type three or four letters when one will do? i, j, k, m, n, p, q for ints. L, a, b, x for lists s, t, a, b for strings. If you don't want to use generic names, then int, list, str are useless because they don't mean anything. You need something like: count_of_widgets list_of_widgets description -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:06:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:06:23 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go on...?-- > start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 Yes. So what? You can't wisely use variables like: True = "rantingrick is an obnoxious loudmouth" None = "the problem he is describing" Nor can you wisely use variables like: len = len("something") chr = chr(48) [...] > Just thoughts. But not deep thoughts. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:15:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:15:15 GMT Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <4c3a5e93$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 18:31:39 +0200, Thomas Jollans wrote: > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? Erm, no. No, no, no. It won't > work. Well, it would work, but it wouldn't be any good. The UNIX and > Windows concepts of "file system" are similar enough for most programs > not to care too much, but for something like a file manager, that works > intimately with the file system, trying to support both UNIX and Windows > is NOT a good idea. Try telling that to the KDE people. -- Steven From breamoreboy at yahoo.co.uk Sun Jul 11 20:18:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 Jul 2010 01:18:52 +0100 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 12/07/2010 01:02, Steven D'Aprano wrote: > On Sat, 10 Jul 2010 23:50:05 -0700, rantingrick wrote: > >> You do realize that >> Python must build a tuple for ever conditional that uses this semantic? >> This is more bad, bad, bad than integer bool-ing! My bin packer could >> potentially compute millions of parts. I do not want to waste valuable >> processor cycles building numerous tuples just for the sake of a >> conditional "condition"! This is bad coding style Stephen. > > No, premature optimization is bad coding. > > Building a tuple is extremely fast: > > $ python -m timeit "x = ()" > 1000000 loops, best of 3: 0.316 usec per loop > $ python -m timeit "x = False" > 1000000 loops, best of 3: 0.36 usec per loop > > > Testing is fast too: > > $ python -m timeit "x = (); 1 if x else 2" > 1000000 loops, best of 3: 0.663 usec per loop > $ python -m timeit "x = False; 1 if x else 2" > 1000000 loops, best of 3: 0.969 usec per loop > > > You've been around here long enough that you should know better. Stop > wasting your time, and ours, ranting over the enormous cost of things > that aren't costly at all. Come back when you have profiled your code and > can prove that the cost of building empty tuples is an actual bottleneck. > +1 Kindest regards. Mark Lawrence From rantingrick at gmail.com Sun Jul 11 20:21:08 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:21:08 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: On Jul 11, 5:28?pm, Fuzzyman wrote: > But why hijack someone else's announcement to do that? Congratulations > alone would have been great. However good your intentions your message > came across as "but it would really have been better if you had been > doing something else instead...". Micheal i think you're just simply projecting some inner feelings on to my post resulting in a complete mis-understanding. And i *did not* say the project was useless, on the contrary i am very happy the OP resurrected this lost script. I only suggested a similar project that the OP *may* find to be interesting. Maybe not, but lets leave the decision for the OP, Ok. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:23:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:23:40 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> Message-ID: <4c3a608b$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: > On Jul 11, 1:19?pm, Mark Dickinson wrote: > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity >> "0 == False"? > > No because all integers should bool True. An integer is a value that IS > NOT empty Integers aren't containers, the concept of "empty" or "full" doesn't apply to them. > and IS NOT None. By this definition, the string "rantingrick hasn't thought this through" is an integer. It's not empty, and not None, so therefore an integer by your definition. Possibly the integer two-thirds of the way between 3 and 4. > Therefore the only logical way to handle > integer bool-ing is to say they are all True. For some definition of "logical". >> For bonus points, explain how you'd deal with any backwards >> compatibility problems that your fix introduces. > > We would't deal with backwards compatibility as this notion of bool(1) > == True and bool(0) == False if backwards way of thinking. Sure it saves > a few keystrokes but in the end only serves to obfuscate the code and > promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF > True AND 0 IN PLACE OF False! Nevertheless, what is done is done, and now you have to deal with it. Just wishing that it was never done is not dealing with backwards compatibility, and breaking existing code is not an acceptable option. So if your plan is to refuse to deal with existing code, I am very glad indeed that your plan will go absolutely nowhere. >> Have you considered forking Python? ?That may be the way forward here. > > I have considered this many times in the past and continue to > consider it even today. Please do. I think that this will be the best thing for the Python community. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:24:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:24:09 GMT Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? I found this link > (http://code.google.com/edu/languages/google-python- class/lists.html) > which suggests that this is done to make sure that the programmer > understands that the list is being modified in place, but that rules out > constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() Yes. So what? Where's the problem? List methods work in place. If you're annoyed now, that's *nothing* to the annoyance you'll feel if they returned the list and you did this: alist = [1,2,3] blist = alist.append(4) # Make a new list with 4 appended. assert alist == [1,2,3] > I want to prepend an empty list to [1,2,3,4]. This is just a toy > example, since I can always do that with [[]]+[1,2,3,4]. Or: L = [[]] L.extend([1,2,3,4]) Or: L = [1,2,3,4] L.insert(0, []) Not everything needs to be a one-liner. -- Steven From news1234 at free.fr Sun Jul 11 20:30:39 2010 From: news1234 at free.fr (News123) Date: Mon, 12 Jul 2010 02:30:39 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> Message-ID: <4c3a622f$0$700$426a74cc@news.free.fr> dhruvbird wrote: > > On a side note, is there any other way to append to a list using > slices (apart from the one below): > x[len(x):len(x)] = [item to append] dy you mean x.extend([1,2,3]) ? From me+list/python at ixokai.io Sun Jul 11 20:31:09 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 17:31:09 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> Message-ID: <4C3A624D.2090903@ixokai.io> On 7/11/10 5:01 PM, rantingrick wrote: > On Jul 11, 11:57 am, Stephen Hansen wrote: >> On 7/11/10 9:31 AM, Thomas Jollans wrote: >>> trying to >>> support both UNIX and Windows is NOT a good idea. >> >> And you can't lump the Mac in with "UNIX" here, even though it really is >> UNIX at the foundation, because there's some very fundamental >> differences between HFS+ (and some other details that are higher level) >> and more traditional unix FS's. Not to mention that the Mac FS situation >> is slightly schitzo since it has two very different ways at looking and >> treating the files, the posix way and the Foundation way... and users >> think more in terms of the latter, usually. At least less sophisticated >> users. > > > Sure you can! Have you ever heard of a *rare* module by the name of > "os"? Yes i know *nobody* uses it but it works nonetheless! Uh, "os" is beyond inadequate. Even shutil is severely lacking. For the most basic operations, Python's provided tools basically work only in very simple cases -- but only those simple cases -- and a file manager would be an utter failure if it had those limitations. See the big red box on top of the docs: http://docs.python.org/library/shutil.html Copying a file without the resource fork on a mac, *can* result in essential data being lost (This is less common then it used to be). As simple a task as chown/chmod for posix systems to take ownership of a file and make it only readable by you is actually a *deeply* complex task with the win32api. Check out http://mail.python.org/pipermail/python-win32/2004-July/002111.html for just an example of what it /looks/ like. That's not even getting into the nitty-gritty details, like how Mac's are *usually* case-insensitive, windows is always, linux is almost always not, and yet some power users go out of their way to enable case-sensitivity on mac filesystems (which has a tendency to break all kinds of things). Oh, and a LOT of the filesystem-details and how you could go around handling them on a mac is *very* dependant on just what version of OSX you have. It changes a lot. >> You can't do a cross-platform file manager without either doing a huge >> amount of work exposing each platform separately-- essentially getting >> separate codebases for each-- or doing a least common denominator >> situation, at which point I boggle: why the hell did you bother to begin >> with? Even Finder is better then that, let alone windows' Explorer. > > Nothing is worse than InternetExploder\Exploder, nothing! And whats > wrong with seperate code bases, it's three modules and a startup > script... > > if sys.platform == 'win32': > import fm32 > elif sys.platform == 'darwin': > import fmdarwin > elif sys.platform == 'nix': > import fmnix > > We just recently had a discussion about CONDITIONALS Stephen have you > forgotten already? You underestimate the significance of the differences and how that would impact the resulting user interface; have you actually implemented anything which targeted the big three OS's and did non-trivial file operations? I have: just dealing with permissions and network shares and other details is actually a pain in the ass. And in the end, there's plenty of Explorer/Finder replacements out there which do their job splendidly. And I assume not everyone on linux loves nautilus and uses it :P >> (*): I do not argue that a non-default file manager on an OS might be a >> great thing. > > Now you're talking! Selective quoting to make it sound like I'm agreeing in some way with you = jerkoff move. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sun Jul 11 20:31:14 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 Jul 2010 01:31:14 +0100 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 12/07/2010 01:06, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote: > >> Another source of asininity seems to be the naming conventions of the >> Python language proper! True/False start with an upper case and i >> applaud this. However str, list, tuple, int, float --need i go on...?-- >> start with lowercase. >> >> Q: Well what the hell is your problem Rick. Who cares right? >> >> WRONG, I tell you what my problem is. Now i cannot "wisely" use >> variables like... >> >> str="this is a string" >> list = [1,2,3] >> def make_random_objs(range=10) >> def show_message(str) >> int = 12 > > > Yes. So what? You can't wisely use variables like: > > True = "rantingrick is an obnoxious loudmouth" +1 QOTW > None = "the problem he is describing" > > Nor can you wisely use variables like: > > len = len("something") > chr = chr(48) > > > [...] >> Just thoughts. > > But not deep thoughts. > Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? Kindest regards. Mark Lawrence. From rantingrick at gmail.com Sun Jul 11 20:35:18 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:35:18 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:02?pm, Steven D'Aprano wrote: > Come back when you have profiled your code and > can prove that the cost of building empty tuples is an actual bottleneck. Did you even read this thread, i mean from head to tail. I NEVER said building EMPTY tuples was the cause of my rant. My complaint (an oddly enough the title of this thread!) concerns the fact that Python treats 0 as False and every integer above and below 0 as True. Which is another example of how *some* aspects of Python support bad coding styles. The only reason i used the tuple was so that my conditional logic worked as expected. *Stephen* offered a solution in the form of using tuples within the conditional expression. I countered his solution by showing that creating tuples in a conditional expression is slower that testing for bool-inity. *Steven*, Please read the thread completely before making off hand comments else you could make a complete fool of yourself! From rantingrick at gmail.com Sun Jul 11 20:38:06 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:38:06 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:18?pm, Mark Lawrence wrote: > +1 Oh mark grow a spine already, really. I can't help but thinking of the spineless Robert Ford every time you open your mouth. From johannes.black at gmail.com Sun Jul 11 20:48:40 2010 From: johannes.black at gmail.com (joblack) Date: Sun, 11 Jul 2010 17:48:40 -0700 (PDT) Subject: Errno 9] Bad file descriptor Message-ID: I get sometimes a Errno 9 Bad file descriptor the code is too long to show it here but what are the circumstances this could happen? A web search showed nothing. I have especially the feeling Python 2.6 has some problems with Unicode ... and might not find the file. Is that possible? From rantingrick at gmail.com Sun Jul 11 20:51:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:51:04 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:23?pm, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: > > On Jul 11, 1:19?pm, Mark Dickinson wrote: > > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity > >> "0 == False"? > > > No because all integers should bool True. An integer is a value that IS > > NOT empty > > Integers aren't containers, the concept of "empty" or "full" doesn't > apply to them. And again you failed to follow along with the thread so you have no idea where my statements is projected from. Of course integers are NOT containers in the way a list or dict is a container! My remark was a rebuff of comments made by Stephen earlier. > > and IS NOT None. > > By this definition, the string "rantingrick hasn't thought this through" > is an integer. It's not empty, and not None, so therefore an integer by > your definition. Again you show lack of reading and comprehension skills. The fact that an integer IS NOT None does not mean this is the only definition of an integer. And any blabbing otherwise is just complete nonsensical crap. If you think you're going to fly in here and dis-credit me that easily you'd better pack a lunch next time! I gots my think'in cap on today fella! > > We would't deal with backwards compatibility as this notion of bool(1) > > == True and bool(0) == False if backwards way of thinking. Sure it saves > > a few keystrokes but in the end only serves to obfuscate the code and > > promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF > > True AND 0 IN PLACE OF False! > > Nevertheless, what is done is done, and now you have to deal with it. > Just wishing that it was never done is not dealing with backwards > compatibility, and breaking existing code is not an acceptable option. Yea and if Guido would have taking your defeatist attitude we'd all be using braces for scope! You know D'Aprano, i had once considered you one of the foremost intelligent minds within this group. However, after your display within this thread i am beginning to doubt my original beliefs of you. Hopefully you're just having an "off" day? From ash.connor at gmail.com Sun Jul 11 20:55:45 2010 From: ash.connor at gmail.com (ashconnor) Date: Sun, 11 Jul 2010 17:55:45 -0700 (PDT) Subject: Problems running VirtualEnv under Windows. Message-ID: <7fc04b13-8006-45f6-a099-94bd9353761f@c33g2000yqm.googlegroups.com> Hello, After reading 'Practical Django Projects' I decided that I want to implement the VirtualEnv tip suggested in order to properly segregate code/modules in different projects. I am however having problems with my django installations not using site-packages within the virtualenv but rather attempting to use site-packages in the default python installation directory. Recreating the problem: 1) Install Python 2.7 via the Windows installer. Add C:/Python27;C:/ Python27/Scripts to Windows PATH. 2) Install setuptools-0.6c11-py2.7.egg via the Windows installer. 3) Install VirtualEnv through `pip install virtualenv` 4) Create an VirtualEnv via `virtualenv --no-site-packages MyEnvName` 5) Activate VirtualEnv via `../MyEnvName/Scripts/activate.bat` 6) Install django via `pip install django` 7) Run django-admin.py startproject ProjectName 8) Error results stating django.core module does not exist. NB: This error will not occur if django is installed in your root directory. NB2: Running the Python interpreter in active VirtualEnv to print the sys.path shows the correct paths. Which has just futher added to my confusion. I'd appreciate any insight or troubleshooting assistance. Thanks Ash From python at rcn.com Sun Jul 11 20:55:53 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 11 Jul 2010 17:55:53 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> On Jul 11, 8:59?am, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? Because Guido thinks that having those methods return None is the best way to communicate that the underlying object has been mutated in- place. Some other languages do it differently, but this is Guido's language, so we do it his way. Raymond From rantingrick at gmail.com Sun Jul 11 21:10:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 18:10:19 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> Message-ID: <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> On Jul 11, 7:31?pm, Stephen Hansen wrote: You said about macs... > Copying a file without the resource fork on a mac, *can* result in > essential data being lost (This is less common then it used to be). As > simple a task as chown/chmod for posix systems to take ownership of a > file and make it only readable by you is actually a *deeply* complex > task with the win32api. And again... > That's not even getting into the nitty-gritty details, like how Mac's > are *usually* case-insensitive, windows is always, linux is almost > always not, and yet some power users go out of their way to enable > case-sensitivity on mac filesystems (which has a tendency to break all > kinds of things). And again... > Oh, and a LOT of the filesystem-details and how you could go around > handling them on a mac is *very* dependant on just what version of OSX > you have. It changes a lot. Well i've never used a mac and now i won't even bother for sure! But if you want to maintain the macfman code base feel free. > Selective quoting to make it sound like I'm agreeing in some way with > you = jerkoff move. *fakes throwing stick* *dog runs to get stick but stick not there* Who's smarter ;-) From alf.p.steinbach+usenet at gmail.com Sun Jul 11 21:12:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 03:12:10 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * MRAB, on 12.07.2010 00:37: > Alf P. Steinbach /Usenet wrote: >> * Stephen Hansen, on 11.07.2010 21:00: >>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>> Follow-up: >>>> Is there a way to define compile-time constants in python and have the >>>> bytecode compiler optimize away expressions like: >>>> >>>> if is_my_extra_debugging_on: print ... >>>> >>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>> run-time penalty for such code when extra_debugging is disabled. >>> >>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>> Python with the -O option. That, and asserts go away. >>> >>>> On #2: My point regarding the impossibility of writing the swap >>>> function for ints is to explicitly understand that this isn't >>>> possible, so as not to look for solutions along those lines when >>>> trying to write python code. >>> >>> Its impossible because Python's calling and namespace semantics simply >>> don't work like that. There's no references in the traditional sense, >>> because there's no variables-- boxes that you put values in. There's >>> just concrete objects. Objects are passed into the function and given >>> new names; that those objects have names in the enclosing scope is >>> something you don't know, can't access, and can't manipulate.. even the >>> objects don't know what names they happen to be called. >>> >>> Check out http://effbot.org/zone/call-by-object.htm >> >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >> works like Java in this respect, that's all; neither Java nor Python >> support 'swap'. >> >> Of course there are variables, that's why the docs call them variables. >> > In Java a variable is declared and exists even before the first > assignment to it. In Python a 'variable' isn't declared and won't exist > until the first 'assignment' to it. That is a misconception. In Python a variable is declared by having an assignment to it, which for a local variable may be anywhere within a routine. If such a variable is used before it's been assigned to, then you get an uninitialized variable exception. Clearly the variable must exist in order for the exception to refer to it (not to mention the exception occurring at all). def foo(): print( blah ) blah = "this is both an assignment and a declaration causing it to exist" foo() Clearly when the exception is raised, referring to the variable, the variable exists. Contrary to your statement that is before the assignment. However, as stated up-thread, I do not expect facts, logic or general reasoning to have any effect whatsoever on such hard-core religious beliefs. And I do not care whether I convince you or not. But I *do not* want the religious subset of the community to succeed too much in propagating nonsense idiot beliefs to newbies -- hence the concrete example that any newbie can try. Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Sun Jul 11 21:33:33 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 18:33:33 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C3A70ED.6070106@ixokai.io> On 7/11/10 5:51 PM, rantingrick wrote: > On Jul 11, 7:23 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: >>> On Jul 11, 1:19 pm, Mark Dickinson wrote: >> >>>> Okay. What fix do you propose? Would your fix maintain the identity >>>> "0 == False"? >> >>> No because all integers should bool True. An integer is a value that IS >>> NOT empty >> >> Integers aren't containers, the concept of "empty" or "full" doesn't >> apply to them. > > And again you failed to follow along with the thread so you have no > idea where my statements is projected from. Of course integers are NOT > containers in the way a list or dict is a container! My remark was a > rebuff of comments made by Stephen earlier. I forgot to reply to that; an integer is certainly not empty. But 0 is nothing. Its not empty vs full. Its nothing vs something that determines if something is considered true-ish or not. >> Nevertheless, what is done is done, and now you have to deal with it. >> Just wishing that it was never done is not dealing with backwards >> compatibility, and breaking existing code is not an acceptable option. > > Yea and if Guido would have taking your defeatist attitude we'd all be > using braces for scope! Guido made a new language. You should go do that. Feel free to define it however you want. In Python, the meaning of "truth" goes back a very, very, very long way. It isn't going to change. Every once in awhile people hate it. For awhile after True/False were introduced, some people wanted to go modify things to a boolean strictness. But in the end, its all pointless. This is just how it works. Its not going to change. It would break thousands and thousands of lines of code. There's not going to be another major breakage for, oh, maybe ten years. Or twenty. If ever. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From brendon.wickham at gmail.com Sun Jul 11 21:41:47 2010 From: brendon.wickham at gmail.com (Brendon Wickham) Date: Mon, 12 Jul 2010 11:41:47 +1000 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: "i had once considered you one of the foremost intelligent minds within this group. However, after your display within this thread i am beginning to doubt my original beliefs of you." "Oh ... grow a spine already, really. I can't help but thinking of the spineless Robert Ford every time you open your mouth" @rantingrick : these comments among others fail to meet the standard of engagement expected of, and traditional to, this list. Take a breath, get some sleep and come back with a level head and a civil tongue. If you have any valid point to make at all, your attitude so far has failed to make it credible, and nor will it enable you to enlist supporters. From me+list/python at ixokai.io Sun Jul 11 21:54:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 18:54:15 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> Message-ID: <4C3A75C7.2020405@ixokai.io> On 7/11/10 6:10 PM, rantingrick wrote: > On Jul 11, 7:31 pm, Stephen Hansen wrote: > > You said about macs... >> Copying a file without the resource fork on a mac, *can* result in >> essential data being lost (This is less common then it used to be). As >> simple a task as chown/chmod for posix systems to take ownership of a >> file and make it only readable by you is actually a *deeply* complex >> task with the win32api. > > And again... >> That's not even getting into the nitty-gritty details, like how Mac's >> are *usually* case-insensitive, windows is always, linux is almost >> always not, and yet some power users go out of their way to enable >> case-sensitivity on mac filesystems (which has a tendency to break all >> kinds of things). > > And again... >> Oh, and a LOT of the filesystem-details and how you could go around >> handling them on a mac is *very* dependant on just what version of OSX >> you have. It changes a lot. > > Well i've never used a mac and now i won't even bother for sure! But > if you want to maintain the macfman code base feel free. I like how you tried to cut out my commentary on Windows and its difficulties and peculiarities, but you accidentally included it anyways -- hint: read more then the first line of a paragraph. My point stands. And I take your non actually responding to my actual point as a concession to it. With that, I'm signing off of this conversation. Tah. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sun Jul 11 22:02:28 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 19:02:28 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A77B4.6080701@ixokai.io> On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote: > However, as stated up-thread, I do not expect facts, logic or general > reasoning to have any effect whatsoever on such hard-core religious > beliefs. Grow up, and/or get a grip, and/or get over yourself. Everyone who disagreed with you, disagreed with you with arguments, logic, facts, and reasoning. You disputed those facts, disagreed with the conclusions, but for you to then just dismiss people who don't agree with you as merely "religious", is childish. Exactly why I think you're wrong -- you're free to go re-read, I stand by my statements in this thread, and the others. The same arguments apply. Its not a religion, dear; my conclusions are not a matter of faith. That's all I have to say on this subject; the conversation has been had, at length (repeatedly). I swear, I'm just going to filter you and Rick out to /dev/null today and leave it at that at this rate. I'm getting worn out of these kinds of responses. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:09:02 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:09:02 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3a793e$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 17:35:18 -0700, rantingrick wrote: > On Jul 11, 7:02?pm, Steven D'Aprano cybersource.com.au> wrote: > >> Come back when you have profiled your code and can prove that the cost >> of building empty tuples is an actual bottleneck. > > Did you even read this thread, i mean from head to tail. Yes I did. > I NEVER said > building EMPTY tuples was the cause of my rant. The cause of your rant appears to be that you have nothing better to do with your time. But the *excuse* for your rant was that you had to replace: choiceIdx1 = None with: choiceIdx1 = () and followed with: Seems kinda dumb to build a tuple just so a conditional wont blow chunks! and My bin packer could potentially compute millions of parts. I do not want to waste valuable processor cycles building numerous TUPLES just for the sake of a conditional "condition"! [emphasis added] > My complaint (an oddly > enough the title of this thread!) concerns the fact that Python treats 0 > as False and every integer above and below 0 as True. Which is another > example of how *some* aspects of Python support bad coding styles. Yes, Python does support bad coding styles. The treatment of 0 as a false value is not one of them though. -- Steven From python at mrabarnett.plus.com Sun Jul 11 22:09:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jul 2010 03:09:12 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A7948.20706@mrabarnett.plus.com> Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: >> Alf P. Steinbach /Usenet wrote: >>> * Stephen Hansen, on 11.07.2010 21:00: >>>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>>> Follow-up: >>>>> Is there a way to define compile-time constants in python and have the >>>>> bytecode compiler optimize away expressions like: >>>>> >>>>> if is_my_extra_debugging_on: print ... >>>>> >>>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>>> run-time penalty for such code when extra_debugging is disabled. >>>> >>>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>>> Python with the -O option. That, and asserts go away. >>>> >>>>> On #2: My point regarding the impossibility of writing the swap >>>>> function for ints is to explicitly understand that this isn't >>>>> possible, so as not to look for solutions along those lines when >>>>> trying to write python code. >>>> >>>> Its impossible because Python's calling and namespace semantics simply >>>> don't work like that. There's no references in the traditional sense, >>>> because there's no variables-- boxes that you put values in. There's >>>> just concrete objects. Objects are passed into the function and given >>>> new names; that those objects have names in the enclosing scope is >>>> something you don't know, can't access, and can't manipulate.. even the >>>> objects don't know what names they happen to be called. >>>> >>>> Check out http://effbot.org/zone/call-by-object.htm >>> >>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >>> works like Java in this respect, that's all; neither Java nor Python >>> support 'swap'. >>> >>> Of course there are variables, that's why the docs call them variables. >>> >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. > > If such a variable is used before it's been assigned to, then you get an > uninitialized variable exception. Clearly the variable must exist in > order for the exception to refer to it (not to mention the exception > occurring at all). > > def foo(): > print( blah ) > blah = "this is both an assignment and a declaration causing it to > exist" > > foo() > > Clearly when the exception is raised, referring to the variable, the > variable exists. > > Contrary to your statement that is before the assignment. > > However, as stated up-thread, I do not expect facts, logic or general > reasoning to have any effect whatsoever on such hard-core religious > beliefs. And I do not care whether I convince you or not. But I *do not* > want the religious subset of the community to succeed too much in > propagating nonsense idiot beliefs to newbies -- hence the concrete > example that any newbie can try. > How about this: >>> def foo(): print("Before:", locals()) x = 0 print("After:", locals()) >>> foo() Before: {} After: {'x': 0} From dannybos at gmail.com Sun Jul 11 22:15:39 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 19:15:39 -0700 (PDT) Subject: IOError and Try Again to loop the loop. Message-ID: Heya, I'm running a py script that simply grabs an image, creates a thumbnail and uploads it to s3. I'm simply logging into ssh and running the script through Terminal. It works fine, but gives me an IOError every now and then. I was wondering if I can catch this error and just get the script to start again? I mean, in Terminal it dies anyway, so I have to start it again by hand, which is a pain as it dies so sporadically. Can I automate this error, catch it and just get it to restart the loop? Thanks for your time and energy, Danny From alf.p.steinbach+usenet at gmail.com Sun Jul 11 22:25:14 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 04:25:14 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * Stephen Hansen, on 12.07.2010 04:02: > On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote: >> However, as stated up-thread, I do not expect facts, logic or general >> reasoning to have any effect whatsoever on such hard-core religious >> beliefs. > > Grow up, and/or get a grip, and/or get over yourself. > > Everyone who disagreed with you, disagreed with you with arguments, > logic, facts, and reasoning. You disputed those facts, disagreed with > the conclusions, but for you to then just dismiss people who don't agree > with you as merely "religious", is childish. > > Exactly why I think you're wrong -- you're free to go re-read, I stand > by my statements in this thread, and the others. The same arguments > apply. Its not a religion, dear; my conclusions are not a matter of faith. > > That's all I have to say on this subject; the conversation has been had, > at length (repeatedly). > > I swear, I'm just going to filter you and Rick out to /dev/null today > and leave it at that at this rate. I'm getting worn out of these kinds > of responses. Well, the above is flaming, which I predicted. The alleged facts etc. you're referring are just that, alleged, by you. In contrast, in debates among non-religious folks facts are /presented/, like I've done in this thread, e.g. concrete code, instead of like you alleging that facts have been presented, hinting about things, and so on -- it's pathetic. Cheers & hth., - Alf -- blog at From clp2 at rebertia.com Sun Jul 11 22:31:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 19:31:00 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 7:15 PM, The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? Of course. Use try-except; http://docs.python.org/tutorial/errors.html#handling-exceptions Here's one way to do it: for image in images:#or whatever the actual loop is # whatever while True: try: part_that_may_raise_IOError() except IOError: print("IOError; Retrying...") else: break # whatever other stuff Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sun Jul 11 22:33:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jul 2010 03:33:45 +0100 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: <4C3A7F09.4030508@mrabarnett.plus.com> The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? > > Thanks for your time and energy, > Exceptions can be caught. You could do something like this: while True: try: do_something() break except IOError: pass From mehgcap at gmail.com Sun Jul 11 22:35:07 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 11 Jul 2010 22:35:07 -0400 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: It seems like seeing the code, or at least the bit in question, would be easier, but what about: for img in range(0, len(imagesToUpload:)) try: #do the thumbnail / upload thing on images[i] exceptIOError: i=0 This will duplicate a lot of the images already processed, but you said you are just restarting the script anyway. If you are in a while loop, just move the processing to the for loop and use the while to add all images to be processed to a list. On 7/11/10, The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? > > Thanks for your time and energy, > > Danny > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:39:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:39:39 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: [...] >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. Oh, I'm going to regret being sucked into this... In *CPython*, but not necessarily other implementations, variables which are local to a function are not kept in a dictionary-based namespace, but in slots in the code object (not to be confused with __slots__ used for classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing locals. This is intended as a speed, and possibly memory, optimization. I don't believe this is a requirement though, so implementations may not do this. It is true that the slot is created at compile time, and in *that sense*, local variables exist before they are bound. I'm not entirely convinced that this is the only sense that matters, but never mind. The error message given exposes this to the user: >>> def f(): ... print x ... x = 1 ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced before assignment If you try this with a global, you get this: >>> def f(): ... global x ... print x ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'x' is not defined In this case, there's no doubt that global variable "x" doesn't exist at all -- there is no key "x" in the global namespace. It seems to me that "a slot to hold the variable is created for local variables" is an implementation detail, not a language feature. CPython could easily hide the difference by changing the exception from UnboundLocalError to: NameError: local name 'x' does not exist and nobody would be any wiser. (Well, perhaps people who catch UnboundLocalError, but why would you do that?) I also note that UnboundLocalError is a subclass of NameError, so "variable exists but is not bound" is considered to be a special case of "variable doesn't exist" rather than a completely independent case. In that sense, I think I'm on solid ground to say that in Python variables don't exist until they are bound to a value, and leave it to pedants like you and I to mention that for CPython local variables have space reserved for them by the compiler before they are bound. -- Steven From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:40:07 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:40:07 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3a8087$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: > Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? For some reason, when I answer the phone and say "Hello, Steven speaking?" I often get called Peter. -- Steven From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:43:29 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:43:29 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> <4c3a8087$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: > >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? > > For some reason, when I answer the phone and say "Hello, Steven > speaking?" I often get called Peter. Er, without the question mark. -- Steven From alf.p.steinbach+usenet at gmail.com Sun Jul 11 23:04:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 05:04:13 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * MRAB, on 12.07.2010 04:09: > Alf P. Steinbach /Usenet wrote: >> * MRAB, on 12.07.2010 00:37: >>> Alf P. Steinbach /Usenet wrote: >>>> * Stephen Hansen, on 11.07.2010 21:00: >>>>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>>>> Follow-up: >>>>>> Is there a way to define compile-time constants in python and have >>>>>> the >>>>>> bytecode compiler optimize away expressions like: >>>>>> >>>>>> if is_my_extra_debugging_on: print ... >>>>>> >>>>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>>>> run-time penalty for such code when extra_debugging is disabled. >>>>> >>>>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>>>> Python with the -O option. That, and asserts go away. >>>>> >>>>>> On #2: My point regarding the impossibility of writing the swap >>>>>> function for ints is to explicitly understand that this isn't >>>>>> possible, so as not to look for solutions along those lines when >>>>>> trying to write python code. >>>>> >>>>> Its impossible because Python's calling and namespace semantics simply >>>>> don't work like that. There's no references in the traditional sense, >>>>> because there's no variables-- boxes that you put values in. There's >>>>> just concrete objects. Objects are passed into the function and given >>>>> new names; that those objects have names in the enclosing scope is >>>>> something you don't know, can't access, and can't manipulate.. even >>>>> the >>>>> objects don't know what names they happen to be called. >>>>> >>>>> Check out http://effbot.org/zone/call-by-object.htm >>>> >>>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >>>> works like Java in this respect, that's all; neither Java nor Python >>>> support 'swap'. >>>> >>>> Of course there are variables, that's why the docs call them variables. >>>> >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. >> >> If such a variable is used before it's been assigned to, then you get >> an uninitialized variable exception. Clearly the variable must exist >> in order for the exception to refer to it (not to mention the >> exception occurring at all). >> >> def foo(): >> print( blah ) >> blah = "this is both an assignment and a declaration causing it to exist" >> >> foo() >> >> Clearly when the exception is raised, referring to the variable, the >> variable exists. >> >> Contrary to your statement that is before the assignment. >> >> However, as stated up-thread, I do not expect facts, logic or general >> reasoning to have any effect whatsoever on such hard-core religious >> beliefs. And I do not care whether I convince you or not. But I *do >> not* want the religious subset of the community to succeed too much in >> propagating nonsense idiot beliefs to newbies -- hence the concrete >> example that any newbie can try. >> > How about this: > > >>> def foo(): > print("Before:", locals()) > x = 0 > print("After:", locals()) > > > >>> foo() > Before: {} > After: {'x': 0} How about it? Note that you get the same result if you do x = "blah" def foo(): # print( x ) # Causes uninitialized variable exception here print( "Before:", locals() ) x = 0 print( "After:", locals() ) However, if you remove the local assignment to x, then the out-commented print statement will no longer cause an exception, it will then refer to the global. The reason that it does throw an exception when you do have the local assignment, is that the local x exists at that point. If it didn't exist it could not have any effect. Things that don't exist generally have no effect, except in the minds of the religious, like angels and so on. On the basis of what locals() reports it should be OK to refer to the global x as above. Judging by locals(), there's no local x that could get in the way. But since it is not OK to refer to the global x, the result of locals() has nothing to do with that: it doesn't tell you about the local x -- and no, the Python interpreter does not look forward in time to see that it will appear. In passing, I should perhaps have told you up front, your argument has nothing substantial to do with the article you originally responded to, about the semantics of variables. Your argument is the assertion that different languages can't have similar or identical semantics for some feature. That's nonsense in itself, plus, as you've seen, the difference that you focused on is not there, and, third, what you do maintain is not there, doesn't exist, has a real effect. Cheers & hth., - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 23:11:48 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 03:11:48 GMT Subject: Errno 9] Bad file descriptor References: Message-ID: <4c3a87f4$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 17:48:40 -0700, joblack wrote: > I get sometimes a > > Errno 9 Bad file descriptor > > the code is too long to show it here You can at least show the actual line that fails. Are you trying to open a file, a named socket, a pipe or a device? > but what are the circumstances this > could happen? A web search showed nothing. The first two google hits for "bad file descriptor" seem pretty relevant to me: http://linux.sys-con.com/node/1053821 http://lists.freebsd.org/pipermail/freebsd-questions/2003-June/009583.html > I have especially the feeling Python 2.6 has some problems with Unicode > ... and might not find the file. Is that possible? Possible, but you should get Errno 2 No such file or directory not bad file descriptor. If you're trying to open a file, you have a broken file system and need to run fsck or equivalent. If it's a pipe or socket or something, you need to tell us what it is. -- Steven From dannybos at gmail.com Sun Jul 11 23:13:57 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 20:13:57 -0700 (PDT) Subject: IOError and Try Again to loop the loop. References: Message-ID: Thanks gang, I'm gonna paste what I've put together, doesn't seem right. Am I way off? Here's my code. - It goes through a table Item - Matches that Item ID to an API call - Grabs the data, saves it and creates the thumbnail - It dies due to Timeouts and Other baloney, all silly, nothing code based. items = Item.objects.all().filter(cover='').order_by('-reference_id') for item in items: url = "http://someaddress.org/books/?issue=%s" % item.reference_id url_array = [] url_open = urllib.urlopen(url) url_read = url_open.read().decode('utf-8') try: url_data = simplejson.loads(url_read) url_array.append(url_data) for detail in url_array: if detail['artworkUrl']: cover_url = detail['artworkUrl'].replace(' ','%20') cover_open = urllib.urlretrieve(cover_url) cover_name = os.path.split(cover_url)[1] item.cover.save(cover_name, File(open(cover_open[0])), save=True) ## Create and save Thumbnail print "Cover - %s: %s" % (item.number, url) else: print "Missing - %s: %s" % (item.number, url) except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) pass except IOError: print "IOError; Retrying..." pass print "Done" On Jul 12, 12:33?pm, MRAB wrote: > The Danny Bos wrote: > > Heya, > > > I'm running a py script that simply grabs an image, creates a > > thumbnail and uploads it to s3. I'm simply logging into ssh and > > running the script through Terminal. It works fine, but gives me an > > IOError every now and then. > > > I was wondering if I can catch this error and just get the script to > > start again? > > I mean, in Terminal it dies anyway, so I have to start it again by > > hand, which is a pain as it dies so sporadically. Can I automate this > > error, catch it and just get it to restart the loop? > > > Thanks for your time and energy, > > Exceptions can be caught. You could do something like this: > > ? ? ?while True: > ? ? ? ? ?try: > ? ? ? ? ? ? ?do_something() > ? ? ? ? ? ? ?break > ? ? ? ? ?except IOError: > ? ? ? ? ? ? ?pass From benjamin.kaplan at case.edu Sun Jul 11 23:28:30 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 11 Jul 2010 20:28:30 -0700 Subject: Getting started with python on macintosh snow leopard with mysql - need help In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 1:18 PM, dk wrote: > I have been going round and round trying to configure python 2.6 > running on osx 10.6.x to work with mySQL 5.1.44. > Python seems to work ... i have an installation of mysql 5.1.44 > running and have used it in conjunction for other php/apache projects. > > I want to learn python and think i need a better database then mysql > lite that installs with the web2py frame work, so my quest to connect > to mysql or postgres began. > > I seem to be stuck stuck getting mySQLdb drivers installed. ?I down > loaded python 2.6.5 from the python site and MySQL-python-1.2.3 from > the my sql site. > I have worked past numerous errors by i now get the errors below when > i try to compile. > > -- some background that might help anyone kind enough to have read > this far and who might be inclined to take pitty -- > I have (tried) to use macports to install setuptools (which MySQL- > python-1.2.3 says it needs). > MacPorts has put tons of stuff in /opt/local ... so i am not sure i am > using this tool the way its intended. > this could all be as simple as adding some path declarations in the > right place but where? > That could be part of your problem. Macports basically ignores the rest of the system. Setuptools depends on python, so Macports compiles and installs its own version of Python in /opt/local. So you now have 3 different versions of Python 2.6 on your computer: /usr/bin/python (the System python), /usr/local/bin/python (the Python.org python) and /opt/local/Library/Frameworks/Python.Framework/Versions/2.6/bin/python. You can use Macport's python-select package to choose which one is the default (it symlinks one of them to /opt/local/bin/python which should be first on your path). Anyway, as long as you're using Macports : sudo port install py26-mysql that should solve most of your problems :) > lots of the post i have seen on the subject talk about 32/64 > installation ... it makes sense that you might need to be consistent > in getting your components to work together, but i am not sure how i > tell of the various parts i have install which and how they were > compiled. > > whereis python ?display ?/usr/bin/python > python -v spits out lots ... but here is a sample: > > # /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > encodings/utf_8.pyc matches /Library/Frameworks/Python.framework/ > Versions/2.6/lib/python2.6/encodings/utf_8.py > import encodings.utf_8 # precompiled from /Library/Frameworks/ > Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.pyc > Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > > > > > when i try to compile mysql-python-1.2.3 i get the following error > returned from python setup.py build ----- > > building '_mysql' extension > gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing > -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - > D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ > Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ > temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - > D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - > DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/unicodeobject.h:4, > ? ? ? ? ? ? ? ? from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/Python.h:85, > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > ? ? ? ? ? ? ? ? from _mysql.c:29: > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > stdarg.h: No such file or directory > In file included from _mysql.c:36: > /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" > redefined > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/Python.h:8, > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > ? ? ? ? ? ? ? ? from _mysql.c:29: > /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ > pyconfig.h:808:1: warning: this is the location of the previous > definition > error: command 'gcc-4.0' failed with exit status 1 > -- Strange. Seems that the package is trying to use gcc-4.0 and the MacOSX10.4 SDK. The default version of gcc on Snow Leopard is 4.2, and XCode only comes with the SDKs for the previous two versions of OS X. From debatem1 at gmail.com Mon Jul 12 00:10:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 00:10:09 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Sun, Jul 11, 2010 at 10:39 PM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > >> * MRAB, on 12.07.2010 00:37: > [...] >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. > > Oh, I'm going to regret being sucked into this... > > In *CPython*, but not necessarily other implementations, variables which > are local to a function are not kept in a dictionary-based namespace, but > in slots in the code object (not to be confused with __slots__ used for > classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing > locals. > > This is intended as a speed, and possibly memory, optimization. I don't > believe this is a requirement though, so implementations may not do this. > > It is true that the slot is created at compile time, and in *that sense*, > local variables exist before they are bound. I'm not entirely convinced > that this is the only sense that matters, but never mind. The error > message given exposes this to the user: > >>>> def f(): > ... ? ? print x > ... ? ? x = 1 > ... >>>> f() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 2, in f > UnboundLocalError: local variable 'x' referenced before assignment > > > If you try this with a global, you get this: > >>>> def f(): > ... ? ? global x > ... ? ? print x > ... >>>> f() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in f > NameError: global name 'x' is not defined > > In this case, there's no doubt that global variable "x" doesn't exist at > all -- there is no key "x" in the global namespace. > > > It seems to me that "a slot to hold the variable is created for local > variables" is an implementation detail, not a language feature. CPython > could easily hide the difference by changing the exception from > UnboundLocalError to: > > NameError: local name 'x' does not exist > > and nobody would be any wiser. (Well, perhaps people who catch > UnboundLocalError, but why would you do that?) > > I also note that UnboundLocalError is a subclass of NameError, so > "variable exists but is not bound" is considered to be a special case of > "variable doesn't exist" rather than a completely independent case. In > that sense, I think I'm on solid ground to say that in Python variables > don't exist until they are bound to a value, and leave it to pedants like > you and I to mention that for CPython local variables have space reserved > for them by the compiler before they are bound. Very interesting, and a pleasant change of tone to boot. Thanks. Geremy Condra From clp2 at rebertia.com Mon Jul 12 00:14:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 21:14:44 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: > Thanks gang, > I'm gonna paste what I've put together, doesn't seem right. Am I way > off? > > Here's my code. > ?- It goes through a table Item > ?- Matches that Item ID to an API call > ?- Grabs the data, saves it and creates the thumbnail > ?- It dies due to Timeouts and Other baloney, all silly, nothing code > based. > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > for item in items: > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id > > ? ? ? ?url_array = [] > ? ? ? ?url_open = urllib.urlopen(url) > ? ? ? ?url_read = url_open.read().decode('utf-8') > > ? ? ? ?try: > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) > ? ? ? ? ? ? ? ?url_array.append(url_data) > > ? ? ? ? ? ? ? ?for detail in url_array: Unless I'm missing something, there's no need for url_array to exist at all. It starts out empty, you append url_data to it, then you iterate over it as `detail`; and you don't touch it anywhere else in the loop. Just s/detail/url_data/ and excise url_array altogether. As a bonus, there'll be one less level of indentation. Also, the reason your code doesn't work (currently, it just skips to the next item upon error) is because you're missing a surrounding `while True` loop (and associated embedded `break`) to do the retrying (see my or MRAB's examples). Additionally, stylistically I'd prefer the try-excepts to cover smaller and more targeted areas of the code, rather than having one giant blanket one for the entire loop body; perhaps that's just me though. Cheers, Chris -- How exactly does one acquire a prenominal "The"? http://blog.rebertia.com From debatem1 at gmail.com Mon Jul 12 00:18:36 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 00:18:36 -0400 Subject: [Python-ideas] explicitation lines in python ? In-Reply-To: References: <4C24FEAF.4030304@gmail.com> <4C26F710.4030902@gmail.com> Message-ID: On Sun, Jul 11, 2010 at 11:39 PM, Carl M. Johnson wrote: > On Sun, Jun 27, 2010 at 8:25 PM, Nick Coghlan wrote: > >> The availability of "nonlocal" binding semantics also makes the >> semantics much easier to define than they were in those previous >> discussions (the lack of clear semantics for name binding statements >> with an attached local namespace was the major factor blocking >> creation of a reference implementation for this proposal back then). >> >> For example: >> >> ?c = sqrt(a*a + b*b) where: >> ? ?a = retrieve_a() >> ? ?b = retrieve_b() >> >> could translate to something like: >> >> ?def _anon(): # *(see below) >> ? ?nonlocal c >> ? ?a = retrieve_a() >> ? ?b = retrieve_b() >> ? ?c = sqrt(a*a + b*b) >> ?_anon() >> >> *(unlike Python code, the compiler can make truly anonymous functions >> by storing them solely on the VM stack. It already does this when >> executing class definitions): > > I like this idea, but I would tweak it slightly. Maybe we should say > > EXPRESSION where: > ? ?BLOCK > > is equivalent to > > def _(): > ? ?BLOCK > ? ?return EXPRESSION > _() > > That way, c = a where: a = 7 would be equivalent to > > def _(): > ? a = 7 > ? return a > c = _() > > One advantage of this equivalence is it would make it easier to work > around a longstanding scoping gotcha. A na?ve coder might expect this > code to print out numbers 0 to 4: > > ? ?>>> fs = [] > ? ?>>> for n in range(5): > ? ?... ? ? def f(): > ? ?... ? ? ? ? print(item) > ? ?... ? ? fs.append(f) > ? ?... > ? ?>>> [f() for f in fs] > ? ?4 > ? ?4 > ? ?4 > ? ?4 > ? ?4 > ? ?[None, None, None, None, None] > > I think we all have enough experience to know this isn?t a totally > unrealistic scenario. I personally stumbled into when I was trying to > create a class by looping through a set of method names. > > To get around it, one could use a where clause like so: > > fs = [] > for n in range(5): > ? ?fs.append(f) where: > ? ? ? ?shadow = n > ? ? ? ?def f(): > ? ? ? ? ? ?print(shadow) > > This would print out 0 to 4 as expected and be equivalent to > > ? ?>>> fs = [] > ? ?>>> for n in range(5): > ? ?... ? ? def _(): > ? ?... ? ? ? ? shadow = n > ? ?... ? ? ? ? def f(): > ? ?... ? ? ? ? ? ? print(shadow) > ? ?... ? ? ? ? fs.append(f) > ? ?... ? ? _() > ? ?... > ? ?>>> [f() for f in fs] > ? ?0 > ? ?1 > ? ?2 > ? ?3 > ? ?4 > ? ?[None, None, None, None, None] > > I think a where-clause with def-like namespace semantics would be a > positive addition to Python, once the moratorium is up. > > -- Carl Johnson +1 from me, FWIW Geremy Condra From dannybos at gmail.com Mon Jul 12 00:20:19 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 21:20:19 -0700 (PDT) Subject: IOError and Try Again to loop the loop. References: Message-ID: Thanks Chris, Agreed some of the code is a lot useless, I need to go through that stuff. So something like this (apologies for asking for some details, I'm not good at catching): items = Item.objects.all().filter(cover='').order_by('-reference_id') for item in items: url = "http://someaddress.org/books/?issue=%s" % item.reference_id url_array = [] url_open = urllib.urlopen(url) url_read = url_open.read().decode('utf-8') while True: try: url_data = simplejson.loads(url_read) url_array.append(url_data) for detail in url_array: if detail['artworkUrl']: cover_url = detail['artworkUrl'].replace(' ','%20') cover_open = urllib.urlretrieve(cover_url) cover_name = os.path.split(cover_url) [1] item.cover.save(cover_name, File(open(cover_open[0])), save=True) print "Cover - %s: %s" % (item.number, url) else: print "Missing - %s: %s" % (item.number, url) break except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) pass except IOError: print "IOError; Retrying..." pass print "Done" On Jul 12, 2:14?pm, Chris Rebert wrote: > On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: > > > > > > > Thanks gang, > > I'm gonna paste what I've put together, doesn't seem right. Am I way > > off? > > > Here's my code. > > ?- It goes through a table Item > > ?- Matches that Item ID to an API call > > ?- Grabs the data, saves it and creates the thumbnail > > ?- It dies due to Timeouts and Other baloney, all silly, nothing code > > based. > > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > > for item in items: > > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id > > > ? ? ? ?url_array = [] > > ? ? ? ?url_open = urllib.urlopen(url) > > ? ? ? ?url_read = url_open.read().decode('utf-8') > > > ? ? ? ?try: > > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) > > ? ? ? ? ? ? ? ?url_array.append(url_data) > > > ? ? ? ? ? ? ? ?for detail in url_array: > > Unless I'm missing something, there's no need for url_array to exist > at all. It starts out empty, you append url_data to it, then you > iterate over it as `detail`; and you don't touch it anywhere else in > the loop. Just s/detail/url_data/ and excise url_array altogether. As > a bonus, there'll be one less level of indentation. > > Also, the reason your code doesn't work (currently, it just skips to > the next item upon error) is because you're missing a surrounding > `while True` loop (and associated embedded `break`) to do the retrying > (see my or MRAB's examples). > > Additionally, stylistically I'd prefer the try-excepts to cover > smaller and more targeted areas of the code, rather than having one > giant blanket one for the entire loop body; perhaps that's just me > though. > > Cheers, > Chris > -- > How exactly does one acquire a prenominal "The"?http://blog.rebertia.com From clp2 at rebertia.com Mon Jul 12 00:34:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 21:34:35 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: > On Jul 12, 2:14?pm, Chris Rebert wrote: >> On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: >> > Thanks gang, >> > I'm gonna paste what I've put together, doesn't seem right. Am I way >> > off? >> >> > Here's my code. >> > ?- It goes through a table Item >> > ?- Matches that Item ID to an API call >> > ?- Grabs the data, saves it and creates the thumbnail >> > ?- It dies due to Timeouts and Other baloney, all silly, nothing code >> > based. >> >> > items = Item.objects.all().filter(cover='').order_by('-reference_id') >> > for item in items: >> > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id >> >> > ? ? ? ?url_array = [] >> > ? ? ? ?url_open = urllib.urlopen(url) >> > ? ? ? ?url_read = url_open.read().decode('utf-8') >> >> > ? ? ? ?try: >> > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) >> > ? ? ? ? ? ? ? ?url_array.append(url_data) >> >> > ? ? ? ? ? ? ? ?for detail in url_array: >> >> Unless I'm missing something, there's no need for url_array to exist >> at all. It starts out empty, you append url_data to it, then you >> iterate over it as `detail`; and you don't touch it anywhere else in >> the loop. Just s/detail/url_data/ and excise url_array altogether. As >> a bonus, there'll be one less level of indentation. >> >> Also, the reason your code doesn't work (currently, it just skips to >> the next item upon error) is because you're missing a surrounding >> `while True` loop (and associated embedded `break`) to do the retrying >> (see my or MRAB's examples). >> >> Additionally, stylistically I'd prefer the try-excepts to cover >> smaller and more targeted areas of the code, rather than having one >> giant blanket one for the entire loop body; perhaps that's just me >> though. On Sun, Jul 11, 2010 at 9:20 PM, The Danny Bos wrote: > Thanks Chris, > > Agreed some of the code is a lot useless, I need to go through that > stuff. > So something like this (apologies for asking for some details, I'm not > good at catching): > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > for item in items: > ? ?url = "http://someaddress.org/books/?issue=%s" % > item.reference_id > ? ?url_array = [] > ? ?url_open = urllib.urlopen(url) > ? ?url_read = url_open.read().decode('utf-8') > > ? ?while True: > ? ? ? ?try: > ? ? ? ? ? ? ? ?break > ? ? ? ?except ValueError: > ? ? ? ? ? ? ? ?print "Error Processing record: %s: %s" % > (item.reference_id, url) > ? ? ? ? ? ? ? ?pass > ? ? ? ?except IOError: > ? ? ? ? ? ? ? ?print "IOError; Retrying..." > ? ? ? ? ? ? ? ?pass > > print "Done" Yes, correct, that's essentially it, although the `pass` statements are superfluous, and I would personally put the `break` in a separate+new else-clause of the try-except for clarity; so the try-except part of the code would look like: try: # lots of code here except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) except IOError: print "IOError; Retrying..." else: break Also, please avoid top-posting in the future; http://en.wikipedia.org/wiki/Top-posting#Top-posting Cheers, Chris -- http://blog.rebertia.com From sturlamolden at yahoo.no Mon Jul 12 00:52:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 11 Jul 2010 21:52:17 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" wrote: > Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like > Java in this respect, that's all; neither Java nor Python support 'swap'. x,y = y,x From nathan.alexander.rice at gmail.com Mon Jul 12 01:03:45 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Mon, 12 Jul 2010 01:03:45 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: Yeah, I long ago filed the in place place in the same folder as strings-as-sequences, all() returning True for an empty iterable and any returning True rather than the thing which triggered it. Almost always annoying and worked around, but that's the price you pay for the other nice stuff :) It just takes writing a few hundred lines of Java code for me to shrug and forget about it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Mon Jul 12 01:03:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 11 Jul 2010 22:03:50 -0700 Subject: Learn Python the Hard Way (online tutorial) References: Message-ID: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> I just came across this, a python tutorial purportedly intended for beginning programmers. I only read the first few pages and I'm not crazy about the approach, but I haven't seen it mentioned here, and some folks might like it: http://learnpythonthehardway.org/home From me+list/python at ixokai.io Mon Jul 12 01:10:19 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 22:10:19 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: <4C3AA3BB.4050404@ixokai.io> On 7/11/10 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > strings-as-sequences, all() returning True for an empty iterable and any > returning True rather than the thing which triggered it. You know, the latter two I can see an argument for, and could see the usefulness therein -- though I've never used either like that, but I consider that chance. I could see the use (and could readily write my own all/any in such a case, then keep it in my toolbox). But the first: what?! for ch in data: is exceptionally useful. Strings-as-sequences I've used hundreds, thousands of times. I use it constantly. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From clp2 at rebertia.com Mon Jul 12 01:50:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 22:50:46 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > all() returning True for an empty iterable If you weren't taught about vacuous truth (or even identity elements) in Discrete Mathematics, someone fscked up. Said behavior is the absolute correct behavior from a formal logic standpoint. Cheers, Chris -- http://blog.rebertia.com From alf.p.steinbach+usenet at gmail.com Mon Jul 12 01:51:16 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 07:51:16 +0200 Subject: Easy questions from a python beginner In-Reply-To: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 12.07.2010 06:52: > On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like >> Java in this respect, that's all; neither Java nor Python support 'swap'. > > x,y = y,x > We're talking about defining a 'swap' routine that works on variables. Since Java/Python doesn't support pass by reference of variables it's not possible in these languages, i.e., you missed the point, or made a joke. :-) However, C# is very similar to Java, nearly all the way, except that in C# you can pass by reference. Remove that from C# and you have Java. Add that to Java and you have C#, roughly. No change in other aspects is needed. E.g. (ignore this if you've never heard about it, but it's a subtle point that you might be wondering about now) both Java and C# implement the definite assignment rule. I.e., there's nothing in the core semantics that prevents accessing/passing the variables by reference, although for Python and Java it could be a terminological nightmare, and for Python compounded to the n'th degree by the general confusion of a subset of the Python community about basic concepts. I don't know how C#'ers resolve the terminology... Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Mon Jul 12 01:52:38 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 22:52:38 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3AADA6.1090208@ixokai.io> On 7/11/10 7:25 PM, Alf P. Steinbach /Usenet wrote: > The alleged facts etc. you're referring are just that, alleged, by you. Two people come together and have a debate. Both present arguments. Both present cases. In the end, they are still in disagreement. You declare us, "religious", and therefore our opinions, arguments, facts, and conclusion are based solely on faith and unworthy of consideration on their merits. That, my friend, is an ad hominem attack. Hypocrite. And you are plonked. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From clp2 at rebertia.com Mon Jul 12 01:59:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 22:59:31 -0700 Subject: Learn Python the Hard Way (online tutorial) In-Reply-To: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> References: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> Message-ID: On Sun, Jul 11, 2010 at 10:03 PM, Paul Rubin wrote: > I just came across this, a python tutorial purportedly intended for > beginning programmers. ?I only read the first few pages and I'm not > crazy about the approach, but I haven't seen it mentioned here, and some > folks might like it: > > ?http://learnpythonthehardway.org/home "By Zed A. Shaw" Hm... - Chris From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 02:09:49 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 06:09:49 GMT Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: <4c3ab1ac$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 21:52:17 -0700, sturlamolden wrote: > On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >> works like Java in this respect, that's all; neither Java nor Python >> support 'swap'. > > x,y = y,x Of course that's a good alternative, but that's not what Alf, or the original poster, are talking about. They're specifically talking about writing a function which swaps two variables in the enclosing scope. This is a good test of languages that support call-by-reference, e.g. Pascal: procedure swap(var x:integer, var y: integer): VAR tmp: integer; BEGIN tmp := x; x := y; y := x; END; If you pass two integer variables to swap(), Pascal will exchange their values. You can't do this in Python. You can get close if you assume the enclosing scope is global, or if you pass the name of the variables rather than the variables themselves, but even then you can't make it work reliably. Or at all. Naturally the swap() function itself is not terribly useful in a language like Python that makes exchanging variables so easy, but there are other uses for call-by-reference that aren't quite so trivial. However, I can't think of anything off the top of my head, so here's another trivial example that can't work in Python: s = "hello" call_something_magic(s) assert s == "goodbye" -- Steven From tjreedy at udel.edu Mon Jul 12 02:13:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:13:05 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: On 7/11/2010 1:48 PM, wheres pythonmonks wrote: > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's&). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) Since you are just exploring, addendum to other answers: >>> x,y = 1,2 >>> def swapxy(): global x,y x,y=y,x >>> swapxy() >>> x,y (2, 1) Not too useful >>> s = [1,2] >>> def swap01(lis): lis[:2] = reversed(lis[:2]) # other versions possible >>> swap01(s) >>> s [2, 1] A function can *modify* an input object. When is does, the usual convention is that it should *not* return the object. -- Terry Jan Reedy From me+list/python at ixokai.io Mon Jul 12 02:30:47 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 23:30:47 -0700 Subject: Learn Python the Hard Way (online tutorial) In-Reply-To: References: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> Message-ID: <4C3AB697.9050906@ixokai.io> On 7/11/10 10:59 PM, Chris Rebert wrote: > On Sun, Jul 11, 2010 at 10:03 PM, Paul Rubin wrote: >> I just came across this, a python tutorial purportedly intended for >> beginning programmers. I only read the first few pages and I'm not >> crazy about the approach, but I haven't seen it mentioned here, and some >> folks might like it: >> >> http://learnpythonthehardway.org/home > > "By Zed A. Shaw" > > Hm... Is there some significance to this name that I am unaware? Google points me to a wikipedia article on a guy who appears involved in both Python and Ruby. Is there something about him that colors or holds meaning for his approach? Just curious. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From tjreedy at udel.edu Mon Jul 12 02:51:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:51:59 -0400 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: On 7/11/2010 3:26 AM, rantingrick wrote: > > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. This is an anomaly, known to all long-time Pythoneers, due the the history of Python. Before 2.2 and unification of types and classes as new-style classes, those were all type constructor *functions*, not class names. The idea of breaking most every serious Python program on the planet by upper-casing them has been considered and so far rejected. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jul 12 02:56:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:56:34 -0400 Subject: Possible to create a read-only complex object? In-Reply-To: <1278867088.27525.1384321763@webmail.messagingengine.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: On 7/11/2010 12:51 PM, python at bdurham.com wrote: > I have a complex object with attributes that contain lists, sets, > dictionaries, and other objects. The lists and dictionaries may > themselves contain complex objects. > I would like to provide a read-only version of this type of object for > other developers to query for reporting. > Is there a way to prevent other developers from changing the attributes > of my complex and nested object? > In researching this question, I have identified __setattr__ and > __delattr__ as possible ways to prevent changes to simple attributes, > but I don't believe these magic methods will prevent others from > fiddling with attributes containing lists and dictionaries or the > contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. > Another idea I had was to create a wrapper object to proxy all access to > the original object. Is there a generic reciepe for this type of wrapper? -- Terry Jan Reedy From cs at zip.com.au Mon Jul 12 03:08:50 2010 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Jul 2010 17:08:50 +1000 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> References: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> Message-ID: <20100712070850.GA14063@cskk.homeip.net> On 12Jul2010 02:43, Steven D'Aprano wrote: | On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote: | > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: | >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? | > | > For some reason, when I answer the phone and say "Hello, Steven | > speaking?" I often get called Peter. | | Er, without the question mark. Ah, so you get differing results when you use the question mark? Phonetic punctuation; Victor Borge would be proud. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A lot of people don't know the difference between a violin and a viola, so I'll tell you. A viola burns longer. - Victor Borge From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 03:45:31 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 07:45:31 GMT Subject: Possible to create a read-only complex object? References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: > On 7/11/2010 12:51 PM, python at bdurham.com wrote: >> I have a complex object with attributes that contain lists, sets, >> dictionaries, and other objects. The lists and dictionaries may >> themselves contain complex objects. >> I would like to provide a read-only version of this type of object for >> other developers to query for reporting. Is there a way to prevent >> other developers from changing the attributes of my complex and nested >> object? >> In researching this question, I have identified __setattr__ and >> __delattr__ as possible ways to prevent changes to simple attributes, >> but I don't believe these magic methods will prevent others from >> fiddling with attributes containing lists and dictionaries or the >> contents of these lists and dictionaries. > > Python was not really not developed for multi-developer projects whose > members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 04:05:16 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 08:05:16 GMT Subject: Numpy now supports Python3, Scipy to follow soon Message-ID: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Pardon me if this has already been mentioned, but I didn't see it, and this is big big news. The latest release of numpy now supports Python 2.x and 3.x out of a single code base, and Scipy is predicted to follow soon. http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html If I can take the liberty of quoting Pauli Virtanen: An important point is that supporting Python 3 and Python 2 in the same code base can be done, and it is not very difficult either. It is also much preferable from the maintenance POV to creating separate branches for Python 2 and 3. Well done to all those who contributed to the effort! -- Steven From alf.p.steinbach+usenet at gmail.com Mon Jul 12 04:06:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 10:06:59 +0200 Subject: Design questions for C++ support for Python extensions (cppy) Message-ID: Hi. With the current cppy code the Python 3.1.1 doc's spam example extension module looks like this (actual working code): #include #include using namespace progrock; namespace { class Spam: public cppy::Module { public: Spam(): cppy::Module( L"spam", L"bl?b?rsyltet?y er bl?tt" ) {} PyObject* system( PyObject* args ) { const char *command; if( !PyArg_ParseTuple( args, "s", &command ) ) { return NULL; } int const sts = ::system( command ); return Py_BuildValue( "i", sts ); } }; } // namespace CPPY_MODULE_CROUTINE( Spam, system, L"Execute a shell command" ) PyMODINIT_FUNC PyInit_spam() { return cppy::safeInit< Spam >(); } Issues: 1. Wide string literals OK? The basic Python API often requires UTF-8 encoded byte strings. With C++ source code encoded using e.g. Windows ANSI Western, string literals with national characters such as Norwegian ??? then become gobbledegook or cause outright failure. I balanced the hypothetical need for string literals with national characters, versus perceived unnaturalness of wide string literals for *nix developers, in favor of the former, i.e. L"wide string literals". Related issue here: in Windows MinGW g++ can not compile utf-8 encoded source with BOM, while MSVC requires a BOM in order to detect the encoding. Is L"this" an acceptable decision if you were to use something like cppy? 2. Exception translation OK? The code within the 'system' member routine could conceivably be reduced to a single short line by adding some C++ support, but that would require use of exceptions to report errors. Translating C++ exceptions to Python exceptions does however add some overhead to every Python -> C++ call. Currently I do this only for the module initialization code, but should it be done for every exported method? Or perhaps as user choice? Benefit of translation e.g. reducing 'system' above to sweet single line. Cost is setup of try-block (negligible) and exception translation (inefficient). 3. Some unsafety OK? In 'PyInit_spam' there may be a window of opportunity for client code to Mess Things Up. Within the cppy::safeInit the C++ module object is created and creates a Python module object, and if anything fails then the C++ side frees the Python object. And after PyInit_spam has returned to Python the cleanup responsibility resides with the Python interpreter: freeing the Python module object causes the C++ object to be destroyed. But if say the client code's equivalent of 'PyInit_spam' calls cppy::safeInit and just discards the result and returns 0 (say) to Python, then it seems to not be documented whether Python will free the Python module, i.e. possible leak. 4. Threading? Is it necessary to make singletons/statics thread safe? Or does Python ensure that no other threads execute while PyInit_spam is called? Can it be called simultaneously by two or more threads? 5. Reload of interpreter? My impression from the documentation is that finalization and reinit of the interpreter is something that an application shouldn't really do, and that an extension developer need not worry about that happening. Is it so? Cheers, - Alf -- blog at From clp2 at rebertia.com Mon Jul 12 04:11:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 01:11:53 -0700 Subject: Possible to create a read-only complex object? In-Reply-To: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: >> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>> I have a complex object with attributes that contain lists, sets, >>> dictionaries, and other objects. The lists and dictionaries may >>> themselves contain complex objects. >>> I would like to provide a read-only version of this type of object for >>> other developers to query for reporting. Is there a way to prevent >>> other developers from changing the attributes of my complex and nested >>> object? >>> In researching this question, I have identified __setattr__ and >>> __delattr__ as possible ways to prevent changes to simple attributes, >>> but I don't believe these magic methods will prevent others from >>> fiddling with attributes containing lists and dictionaries or the >>> contents of these lists and dictionaries. >> >> Python was not really not developed for multi-developer projects whose >> members are willing to stomp on each others objects. > > I like the idea of competition-driven development, where the code that > survives best in the face of hostile developers gets used. http://en.wikipedia.org/wiki/Defensive_programming Cheers, Chris From clp2 at rebertia.com Mon Jul 12 04:14:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 01:14:49 -0700 Subject: Netbeans plugin and Python 3 In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 9:27 AM, Nitin Pawar wrote: > Hi, > I never tried python3.0 with netbeans but I use python 2.6.5 with netbean > 6.7.1 > Here is how I managed to change from python 2.5 (netbeans default) to 2.6.5 > 1) From the tools-> plugins section install python plugin > 2) Once plugin is installed just restart netbeans so that plugin is > activated > 3) After plugin is activated, you can edit default python version by tools-> > python platform > 4) It will open a configure window, where you can point python to newly > installed 3.0 version. > I hope that helps. > Thanks, > nitin > > On Fri, Jul 9, 2010 at 9:30 PM, wrote: >> >> 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. python instructor (Greg) >> ? 2. Re: ipython problem in opening a file (Youngung Jeong) >> ? 3. Netbeans plugin and Python 3 (Chrix) >> ? 4. Re: python instructor (Ed Keith) >> ? 5. Last day to submit your Surge 2010 CFP! (Jason Dixon) >> ? 6. SqlAlchemy: remote connection on problem on mysql database (Massi) >> ? 7. do (Robin) >> ? 8. Re: Opinions please -- how big should a single module grow? >> ? ? ?(Tomasz Rola) >> ? 9. Re: Python -- floating point arithmetic (Aahz) >> ?10. Re: 'reload M' doesn't update 'from M inport *' (Aahz) >> ?11. Cpp + Python: static data dynamic initialization in *nix >> ? ? ?shared lib? (Alf P. Steinbach /Usenet) >> ?12. Why there is no "setdefaultencoding" in sys module? (crow) Netiquette note: Please don't include the entire digest in future posts to the mailinglist. Cheers, Chris From almar.klein at gmail.com Mon Jul 12 04:29:50 2010 From: almar.klein at gmail.com (Almar Klein) Date: Mon, 12 Jul 2010 10:29:50 +0200 Subject: Numpy now supports Python3, Scipy to follow soon In-Reply-To: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> References: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Message-ID: On 12 July 2010 10:05, Steven D'Aprano wrote: > Pardon me if this has already been mentioned, but I didn't see it, and > this is big big news. > I haven't heard it yet, this is great news! Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 04:42:05 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 08:42:05 GMT Subject: Possible to create a read-only complex object? References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3ad55d$0$28664$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 01:11:53 -0700, Chris Rebert wrote: > On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano > wrote: >> On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: >>> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>>> I have a complex object with attributes that contain lists, sets, >>>> dictionaries, and other objects. The lists and dictionaries may >>>> themselves contain complex objects. >>>> I would like to provide a read-only version of this type of object >>>> for other developers to query for reporting. Is there a way to >>>> prevent other developers from changing the attributes of my complex >>>> and nested object? >>>> In researching this question, I have identified __setattr__ and >>>> __delattr__ as possible ways to prevent changes to simple attributes, >>>> but I don't believe these magic methods will prevent others from >>>> fiddling with attributes containing lists and dictionaries or the >>>> contents of these lists and dictionaries. >>> >>> Python was not really not developed for multi-developer projects whose >>> members are willing to stomp on each others objects. >> >> I like the idea of competition-driven development, where the code that >> survives best in the face of hostile developers gets used. > > http://en.wikipedia.org/wiki/Defensive_programming Meh, defensive programming is designed to deal with bugs and hostile outsiders. I mean writing your functions and classes to deal with actively hostile coding *partners* who are trying to destroy your class so their class will survive to fight another day... There's probably a Dilbert cartoon about it. I'm not serious of course, if the members of your project are trying to screw your code, you're in trouble. I just like the idea of competition- driven development being the next buzzword, for when agile, test-driven, or pair-programming development is no longer enough. -- Steven From bartc at freeuk.com Mon Jul 12 04:48:04 2010 From: bartc at freeuk.com (bart.c) Date: Mon, 12 Jul 2010 09:48:04 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: "MRAB" wrote in message news:mailman.591.1278900548.1673.python-list at python.org... > Alf P. Steinbach /Usenet wrote: >> def foo(): >> print( blah ) >> blah = "this is both an assignment and a declaration causing it to >> exist" >> >> foo() >> >> Clearly when the exception is raised, referring to the variable, the >> variable exists. > How about this: > > >>> def foo(): > print("Before:", locals()) > x = 0 > print("After:", locals()) > > > >>> foo() > Before: {} > After: {'x': 0} That's interesting. So in Python, you can't tell what local variables a function has just by looking at it's code: def foo(day): if day=="Tuesday": x=0 print ("Locals:",locals()) #foo("Monday") Does foo() have 1 or 2 locals? That might explain some of the difficulties of getting Python implementations up to speed. -- Bartc From debatem1 at gmail.com Mon Jul 12 05:01:30 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 05:01:30 -0400 Subject: Possible to create a read-only complex object? In-Reply-To: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 3:45 AM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: > >> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>> I have a complex object with attributes that contain lists, sets, >>> dictionaries, and other objects. The lists and dictionaries may >>> themselves contain complex objects. >>> I would like to provide a read-only version of this type of object for >>> other developers to query for reporting. Is there a way to prevent >>> other developers from changing the attributes of my complex and nested >>> object? >>> In researching this question, I have identified __setattr__ and >>> __delattr__ as possible ways to prevent changes to simple attributes, >>> but I don't believe these magic methods will prevent others from >>> fiddling with attributes containing lists and dictionaries or the >>> contents of these lists and dictionaries. >> >> Python was not really not developed for multi-developer projects whose >> members are willing to stomp on each others objects. > > I like the idea of competition-driven development, where the code that > survives best in the face of hostile developers gets used. You jest, but I've actually done this. The goal was to test security awareness among developers- we formed two tiger teams, one to develop code and one to exploit it, and had one member of the developer group as a saboteur. His goal was to put in the largest possible vulnerability without getting caught, while the others wanted to produce the most secure code they could that met spec. Geremy Condra From jeanmichel at sequans.com Mon Jul 12 05:42:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 11:42:22 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C3AE37E.2040405@sequans.com> Aahz wrote: > In article , > Jean-Michel Pichavant wrote: > >> PS : You're misusing the del statement. It does not remove any object >> > >from mmory, however, it removes the reference to it, the object is still > >> in memory. They are very few cases where del is usefull in python, so >> try to avoid using it as well. >> > > The first two sentences are true; the last sentence is completely wrong. > I've got lots of code using del, and it's a critically useful element of > dictionary manipulation. > Can you please give a short example ? I'm not challenging though, just curious. JM From jeanmichel at sequans.com Mon Jul 12 05:47:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 11:47:00 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278710063.2362.75.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> <1278710063.2362.75.camel@hatchbox-one> Message-ID: <4C3AE494.3090700@sequans.com> >> Hi, >> >> Don't use reload, this is nothing but a trap, espacially if your using >> it to update your objects with the code you are writting. >> >> JM >> > > I've found "reload" very usable for development in IDLE. IDLE memorizes > my input, and the variables I assign output to. If restart IDLE I lose > it all and start over. That is an awfully awkward alternative to > "reload", an alternative I wouldn't consider. > I found "reload" tricky with several modules, because all > dependencies need to be updated and which way they go isn't always > obvious. Reloading all modules in the right order works for me. The > reload commands come up with Alt-P as long, precisely, as I don't > restart IDLE. > Instead of writing your test code in the IDLE shell, write it into a file, an run this file in IDLE (from the IDLE file edit window hit F5). That way restarting from the begining is costless. If you insist on using reload, then you've already been given helpful answers, understanding the import model is always a good thing anyway :) JM From robin at reportlab.com Mon Jul 12 05:52:00 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 12 Jul 2010 10:52:00 +0100 Subject: round issue Message-ID: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> A client wants to know why his db number -9.85 gets displayed by some simple code as -9.8 I looked at the number and see that >>> -9.85 -9.8499999999999996 ie I expect simple rounding to produce the observed result and indeed >>> '%.1f' % -9.85 '-9.8' however, when I use round I get an unexpected result ie >>> round(-9.85,1) -9.9000000000000004 according to its definition > round(x[, n])? > Return the floating point value x rounded to n digits after the decimal point. > If n is omitted, it defaults to zero. The result is a floating point number. > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 (so. for example, > round(0.5) is 1.0 and round(-0.5) is -1.0). so looking at the absolute differences I see >>> abs(-9.9 - -9.85) 0.050000000000000711 >>> abs(-9.8 - -9.85) 0.049999999999998934 ie the -9.8 value appears closer and at least to a primitive test >>> abs(-9.9 - -9.85) > abs(-9.8 - -9.85) True the distance from the -9.9 result is larger, however, that may be because the model numbers for -9.8 & -9.9 differ in distance from the true 10**-n values eg >>> -9.9 -9.9000000000000004 >>> -9.8 -9.8000000000000007 What value should round(-9.85,1) return? Is the result explainable in python (ie without resort to the internal FP representations etc etc)? -- Robin Becker From mal at egenix.com Mon Jul 12 06:04:16 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 12 Jul 2010 12:04:16 +0200 Subject: Python conference and user group statistics Message-ID: <4C3AE8A0.5070901@egenix.com> Hello, I am currently working on a Python Software Foundation (PSF) project to create marketing material for Python with the aim of providing this to Python conferences and user groups. In order to come up with reasonable figures for the number of brochures and flyers to print, I'd like to get a rough idea about the number of attendees of the various Python conferences and user group meetings. It would be great, if you could report the approx. number of attendees coming to the events and the frequency with which you hold the conferences/meetings. I'm also interested in whether English as language of the marketing material would suffice or whether having the material in other languages would result in better acceptance among your attendees. These are the list of conferences and user groups I'm currently using as basis for the survey: http://www.python.org/community/workshops/ http://wiki.python.org/moin/LocalUserGroups Please reply either in private email or CC to my email address. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 12 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2010-07-19: EuroPython 2010, Birmingham, UK 6 days to go ::: 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 duncan.booth at invalid.invalid Mon Jul 12 06:09:30 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Jul 2010 10:09:30 GMT Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: "Alf P. Steinbach /Usenet" wrote: > * sturlamolden, on 12.07.2010 06:52: >> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet"> +use... at gmail.com> wrote: >> >>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. >>> Python works like Java in this respect, that's all; neither Java nor >>> Python support 'swap'. >> >> x,y = y,x >> > > We're talking about defining a 'swap' routine that works on variables. > > Since Java/Python doesn't support pass by reference of variables it's > not possible in these languages, i.e., you missed the point, or made a > joke. :-) > I think talking about a swap function is confusing the issue somewhat: you don't need to define a swap function in Python because the language supports the functionality directly, but that is just hiding the wider question of what you do in Python instead of using reference or in/out arguments. The simple answer is that Python makes it easy to return more than result from a function, so for every 'out' parameter just return one more result, and for a 'ref' parameter just bind that result back to the same name as you passed in. Note that this gives you more flexibility than languages with 'out' or 'ref' parameters as the caller of the function can decide whether to overwrite the original name or create a new one. A literal implementation of 'swap' in Python is possible but pretty pointless: def swap(a, b): return b, a ... x, y = swap(x, y) but it makes a lot of sense when you move to functions that actually do something useful: scheme, netloc, path, parms, query, fragment = urlparse(url) and there's even a convention for ignoring results we don't care about: head, _, tail = line.partition(':') -- Duncan Booth http://kupuguy.blogspot.com From dhruvbird at gmail.com Mon Jul 12 06:10:34 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 12 Jul 2010 03:10:34 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> Message-ID: On Jul 12, 5:30?am, News123 wrote: > dhruvbird wrote: > > > On a side note, is there any other way to append to a list using > > slices (apart from the one below): > > x[len(x):len(x)] = [item to append] > > dy you mean > x.extend([1,2,3]) No, I meant x.append(4) Except that I want to accomplish it using slices. (I can do it as x[lex(x):] = [item_to_append] but is there any other way?) Regards, -Dhruv. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 06:26:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 10:26:29 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: > That's interesting. So in Python, you can't tell what local variables a > function has just by looking at it's code: In the presence of "exec", you can't really tell *anything*. >>> def f(s): ... exec s ... print locals() ... >>> f("x = 2;y = None") {'y': None, 'x': 2, 's': 'x = 2;y = None'} > def foo(day): > if day=="Tuesday": > x=0 > print ("Locals:",locals()) > > #foo("Monday") > > Does foo() have 1 or 2 locals? That's easy for CPython: it prepares two slots for variables, but only creates one: >>> foo("Monday") ('Locals:', {'day': 'Monday'}) >>> foo.func_code.co_varnames ('day', 'x') >>> foo.func_code.co_nlocals 2 So, the question is, is x a local variable or not? It's not in locals, but the function clearly knows that it could be. > That might explain some of the > difficulties of getting Python implementations up to speed. I'm not quite sure why you say that. -- Steven From jeanmichel at sequans.com Mon Jul 12 06:34:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 12:34:46 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3a793e$0$28662$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4C3AEFC6.3000102@sequans.com> Steven D'Aprano wrote: >> My complaint (an oddly >> enough the title of this thread!) concerns the fact that Python treats 0 >> as False and every integer above and below 0 as True. Which is another >> example of how *some* aspects of Python support bad coding styles. >> > > Yes, Python does support bad coding styles. The treatment of 0 as a false > value is not one of them though. > > Well, actually some people might think otherwise. While I disagree with the OP flaming style, one could argue that muting an integer into a boolean makes no sense (I'm one of them). You can still do it, but there is no "right" way to do it. You can decide that everything else than 0 is True, but you could also pickup the integer 3 as false value, it would work as well since it makes no sense. This is just an arbitrary definition. Where the OP is fooling himself, is that you can't state that bool-ing an integer makes no sense and state the line after that 0 *should* | *has to* return True. I personally can live with 0 == False (with all due respect to our C-coding ancestors :) ), however as one of my personal coding rule I avoid using it. I prefere to explicitly write what I want to test: if myInt <> 0: or if myInt is not None: etc... That way I do not rely on a arbitrary int-to-bool mutation. JM From jeanmichel at sequans.com Mon Jul 12 06:42:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 12:42:51 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4C3AF1AB.1090203@sequans.com> rantingrick wrote: > On Jul 11, 3:03 am, "G?nther Dietrich" > wrote: > > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. >> > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? > def func154(): int32 = 24 list18 = [int32, 14] str14 = "" for int89 in list18: if int89 == int32 or int89 == 88: str14 = "I am missing everything" if str14: print str14 >>> func154() >>> "I am missing everything" JM From dickinsm at gmail.com Mon Jul 12 06:44:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 03:44:23 -0700 (PDT) Subject: round issue References: Message-ID: <2876a1b4-2f1e-4355-866f-d4b271cf3e99@e5g2000yqn.googlegroups.com> On Jul 12, 10:52?am, Robin Becker wrote: > What value should round(-9.85,1) return? Is the result explainable in python (ie > without resort to the internal FP representations etc etc)? As you observe, the closest float to -9.85 is actually just a little smaller (i.e., closer to 0) than -9.85: Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(-9.85) Decimal('-9.8499999999999996447286321199499070644378662109375') So you're right: round(-9.85, 1) *should* return -9.8. The 2.x (for x <= 6) version of round is a bit deficient in that respect. Internally, it's doing the obvious thing: namely, multiplying by 10.0, rounding to the nearest integer, then dividing by 10.0. The problem is that this not-quite-9.85 value, when multiplied by 10, becomes (as a result of rounding error) *exactly* 98.5, which then gets rounded *up* to 99 instead of down to 98. This is fixed in Python 2.7, and in Python 3.x. (The code that was introduced for the new short float repr made it easy to fix.) That said, if your client really *means* -9.85 (rather than some binary approximation to it), and wants it to round in a predictable manner, the right way to fix this would be to use Decimal instead of float to represent the number. That way, you can also specify what rounding mode you want (instead of relying on the default round-half- away-from-zero in 2.x or round-half-to-even in 3.x.) >>> decimal.Decimal('-9.85').quantize(decimal.Decimal('0.1'), rounding=decimal.ROUND_HALF_UP) Decimal('-9.9') >>> decimal.Decimal('-9.85').quantize(decimal.Decimal('0.1'), rounding=decimal.ROUND_HALF_EVEN) Decimal('-9.8') -- Mark From nospam at nospam.com Mon Jul 12 06:49:05 2010 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 12 Jul 2010 12:49:05 +0200 Subject: Only one forum app in Python? References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Sat, 10 Jul 2010 18:37:00 +0200, Bruno Desthuilliers wrote: >There are almost a dozen of Python "forum apps" for Django alone, and >Python is known as "the language with more web frameworks than keywords". Thanks for the tip. I'll head that way. From hniksic at xemacs.org Mon Jul 12 07:20:45 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 12 Jul 2010 13:20:45 +0200 Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> Message-ID: <87630lrlo2.fsf@busola.homelinux.net> dhruvbird writes: > No, I meant x.append(4) > Except that I want to accomplish it using slices. > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > way?) It seems that you've found a way to do so, so why do you need another way? Are you after elegance? Efficiency? Brevity? Here are some other ways to express the same, and all use slices in some way: x[slice(len(x), None)] = [item_to_append] x.__setitem__(slice(len(x), None), [item_to_append]) x.__setslice__(len(x), len(x), [item_to_append]) ...but I have no idea why any of them would make any more sense than x[len(x):] = [item_to_append]. From fuzzyman at gmail.com Mon Jul 12 07:51:24 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Mon, 12 Jul 2010 04:51:24 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: <11e013ef-2ac9-4991-b151-eb7258bd7437@41g2000yqn.googlegroups.com> On Jul 12, 1:21?am, rantingrick wrote: > On Jul 11, 5:28?pm,Fuzzyman wrote: > > > But why hijack someone else's announcement to do that? Congratulations > > alone would have been great. However good your intentions your message > > came across as "but it would really have been better if you had been > > doing something else instead...". > > Micheal i think you're just simply projecting some inner feelings on > to my post resulting in a complete mis-understanding. And i *did not* > say the project was useless, on the contrary i am very happy the OP > resurrected this lost script. I only suggested a similar project that > the OP *may* find to be interesting. Maybe not, but lets leave the > decision for the OP, Ok. Plenty of people have told you in multiple threads how you come across. Eventually you have to realise that they aren't *all* projecting... :-) Michael -- http://www.voidspace.org.uk/ From prologic at shortcircuit.net.au Mon Jul 12 08:01:51 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jul 2010 22:01:51 +1000 Subject: Only one forum app in Python? In-Reply-To: References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Mon, Jul 12, 2010 at 8:49 PM, Gilles Ganault wrote: >>There are almost a dozen of Python "forum apps" for Django alone, and >>Python is known as "the language with more web frameworks than keywords". Speaking of frameworks and python forums, sahriswiki 91) is not a forum, but it's goals are to have a best-of-mix of features from blogging, wiki and cms engines. cheers James 1. http://sahriswiki.org/ -- -- James Mills -- -- "Problems are solved by method" From bartc at freeuk.com Mon Jul 12 08:56:38 2010 From: bartc at freeuk.com (bart.c) Date: Mon, 12 Jul 2010 13:56:38 +0100 Subject: Easy questions from a python beginner In-Reply-To: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... > On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: > >> That's interesting. So in Python, you can't tell what local variables a >> function has just by looking at it's code: >> def foo(day): >> if day=="Tuesday": >> x=0 >> print ("Locals:",locals()) >> >> #foo("Monday") >> >> Does foo() have 1 or 2 locals? > > That's easy for CPython: it prepares two slots for variables, but only > creates one: > >>>> foo("Monday") > ('Locals:', {'day': 'Monday'}) >>>> foo.func_code.co_varnames > ('day', 'x') >>>> foo.func_code.co_nlocals > 2 > > So, the question is, is x a local variable or not? It's not in locals, > but the function clearly knows that it could be. So Alf P.S. could be right; x exists, but Python pretends it doesn't until it's assigned to. >> That might explain some of the >> difficulties of getting Python implementations up to speed. > > I'm not quite sure why you say that. Only that an implementation might be obliged to keep these various tables updated during function execution, instead of just at entry and exit. -- Bartc From nathan.alexander.rice at gmail.com Mon Jul 12 09:20:39 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Mon, 12 Jul 2010 09:20:39 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: Stephen: I'm not adverse to being able to do that, but the number of times that I've wanted to do that is greatly outweighed by the number of times I've had to pass a function "(somestring,)" or call "if isinstance(foo, basestring): ..." to avoid producing a bug. The more abstract and adaptive the code you are writing, the more annoying it gets - you end up with a rats nest of string instance checks and strings wrapped in tuples. Looking at my code, I don't have a lot of use cases for string slicing or iterating character by character. Most of the time I use the string methods, they're faster and (IMO) clearer - lower, index/rindex, find, etc. One use case that I avoid is extracting substrings, by slicing out the results of rfind. There's a good case for this but I feel it's brittle so I usually just jump to regular expressions (and it could be performed equally well with a substring method). That doesn't mean I don't think it's useful, just that as it stands the default language behavior is bug producing, and in my opinion people would be equally well served with an as_list method on strings that makes the behavior explicit. Chris: Let's not run around questioning people's math skills, that's actually my area of expertise, and it's impolite besides :) While having all([]) return True from a formal standpoint "makes sense" it typically reduces people to writing "if all(something) and something:", because feeding an iterable that has been filtered in some way (and thus has a range between 0 and n, where n is the length of the original iterable) is an incredibly common use case. In fact, I'm going to go out on a limb here and say there are a lot of bugs floating around that haven't been caught because the code author used all() under the assumption that it would be passed a non-empty list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcl.office at googlemail.com Mon Jul 12 10:04:08 2010 From: mcl.office at googlemail.com (mcl) Date: Mon, 12 Jul 2010 07:04:08 -0700 (PDT) Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing Message-ID: My Code `import os from PIL import Image from iptcinfo import IPTCInfo info = IPTCInfo('test.jpg') print info.keywords, info.supplementalCategories, info.contacts caption = info.data['caption/abstract'] print caption` running Win XP SP3 I get the message No module: iptcinfo I have downloaded iptcinfo and placed it in python27\Lib\site-packages \iptcinfo I guessed that was the right place, because that is where PIL ended up, but that had a fancy installer with it. As you will appreciate, I am very much an amateur in all this. I can code a bit of python, but where everything goes and links is a complete mystery. All I want is to write a quick script which extracts the Caption field from a directory of JPEGS. I get the filenames and the dimensions with PIL, but I need IPTCinfo to get at the Caption field. If anyone can throw any light on what I need to do or which stupid mistake I have made, I would be most grateful. Richard From invalid at invalid.invalid Mon Jul 12 10:19:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:19:32 +0000 (UTC) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 2010-07-09, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking ^^^^^^^^^^ IMO, that's going to be your main problem. -- Grant Edwards grant.b.edwards Yow! PIZZA!! at gmail.com From invalid at invalid.invalid Mon Jul 12 10:40:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:40:47 +0000 (UTC) Subject: Easy questions from a python beginner References: Message-ID: On 2010-07-11, Thomas Jollans wrote: > On 07/11/2010 08:45 PM, wheres pythonmonks wrote: >> On #3: Sorry this is confusing, but I was browsing some struct array >> code from numpy, in which one of the columns contained strings, but >> the type information, supplied in numpy.array's dtype argument, >> specified the type as a an "object" not a string. A string is an object. >> Just wondering why one would do that. > > No expert on numpy, but maybe storing object references is cheaper than > storing strings here ? Strings are objects. IIRC, numpy has special homogeneous array types to hold certain scalar values: byte, int, float, complex. Those special array types allow for very efficient storage and operations. If you want an array of any other type, or a heterogeneous array, then you use an array of objects and then you can put anything into the array (including strings). -- Grant Edwards grant.b.edwards Yow! The PINK SOCKS were at ORIGINALLY from 1952!! gmail.com But they went to MARS around 1953!! From newsuser at stacom-software.de Mon Jul 12 10:43:21 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Mon, 12 Jul 2010 16:43:21 +0200 Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) Message-ID: Hello together, python: 2.5.1 palttform: winXP I'm using pickle.dump and pickle.load with data that is created in a wrapped (boost.python) piece of C++ code. pickle.dump works fine. pickle.load creates the following exception: [...] data = pickle.load(input) File "C:\Python25\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python25\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python25\lib\pickle.py", line 954, in load_float self.append(float(self.readline()[:-1])) ValueError: invalid literal for float(): -1.#IND - I'm not sure what -1.#IND means. Can somebody assist? - As pickle write the data I'm a bit confused, that is can't be unpickled it. Is that a bug or a feature? BTW: I'm tied to version 2.5 of python Thank and regards Alexander From invalid at invalid.invalid Mon Jul 12 10:51:53 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:51:53 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: On 2010-07-12, Alexander Eisenhuth wrote: > python: 2.5.1 > palttform: winXP > > I'm using pickle.dump and pickle.load with data that is created in a > wrapped (boost.python) piece of C++ code. pickle.dump works fine. > pickle.load creates the following exception: > > [...] > data = pickle.load(input) > File "C:\Python25\lib\pickle.py", line 1370, in load > return Unpickler(file).load() > File "C:\Python25\lib\pickle.py", line 858, in load > dispatch[key](self) > File "C:\Python25\lib\pickle.py", line 954, in load_float > self.append(float(self.readline()[:-1])) > ValueError: invalid literal for float(): -1.#IND > > - I'm not sure what -1.#IND means. That's an infinity. > Can somebody assist? In Python 2.x, pickle doesn't handle infinities and NaNs. > - As pickle write the data I'm a bit confused, that is can't be > unpickled it. Is that a bug or a feature? IMO, it's a bug. It's been fixed in 3.x. > BTW: I'm tied to version 2.5 of python If you want to pickle floating point data that includes infinities and NaNs, you need to write your own handler for floating point values. When pickling you need to check for infinities and NaNs and output some defined strings. When unpickling, you need to check for those strings and generate infinities and NaNs as appropriate. The CPython 2.x version of pickle just uses the underlying C library routines to print and parse floating point values. If those libraries are broken in the way that they represent infinity and NaN, then pickle is broken in the same manner. Windows standard libraries are broken. When formatting floating point values, it produces strings that it can't parse as input. IIRC, Linux works better -- but if you want something that you know is going to work (and work cross-platform), then you need to write your own floating point pickle/unpickle methods, and hook them into the pickle module. -- Grant Edwards grant.b.edwards Yow! Uh-oh!! I'm having at TOO MUCH FUN!! gmail.com From invalid at invalid.invalid Mon Jul 12 10:54:25 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:54:25 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: On 2010-07-12, Grant Edwards wrote: > On 2010-07-12, Alexander Eisenhuth wrote: > >> python: 2.5.1 >> palttform: winXP >> >> I'm using pickle.dump and pickle.load with data that is created in a >> wrapped (boost.python) piece of C++ code. pickle.dump works fine. >> pickle.load creates the following exception: >> >> [...] >> data = pickle.load(input) >> File "C:\Python25\lib\pickle.py", line 1370, in load >> return Unpickler(file).load() >> File "C:\Python25\lib\pickle.py", line 858, in load >> dispatch[key](self) >> File "C:\Python25\lib\pickle.py", line 954, in load_float >> self.append(float(self.readline()[:-1])) >> ValueError: invalid literal for float(): -1.#IND >> >> - I'm not sure what -1.#IND means. > > That's an infinity. Oops, I just noticed that I misread that. 1.#INF is an infinity, 1.#IND is an "indefinite", or what everybody outside of Microsoft calls a NaN (Not-a-Number). -- Grant Edwards grant.b.edwards Yow! ONE LIFE TO LIVE for at ALL MY CHILDREN in ANOTHER gmail.com WORLD all THE DAYS OF OUR LIVES. From sturlamolden at yahoo.no Mon Jul 12 10:59:12 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jul 2010 07:59:12 -0700 (PDT) Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" wrote: > We're talking about defining a 'swap' routine that works on variables. I did not miss the point. One cannot make a swap function that rebinds its arguments in the calling stack frame. But a swap function can swap values, given that the type is not immutable: def swap(a,b): a[0],b[0] = b[0],a[0] >>> a,b = [1],[2] >>> swap(a,b) >>> print a,b [2] [1] From dickinsm at gmail.com Mon Jul 12 11:03:07 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 15:03:07 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: Alexander Eisenhuth stacom-software.de> writes: > File "C:\Python25\lib\pickle.py", line 954, in load_float > self.append(float(self.readline()[:-1])) > ValueError: invalid literal for float(): -1.#IND > > - I'm not sure what -1.#IND means. Can somebody assist? It's the Windows way of representing a NaN (not a number). A NaN is typically what you get when you try to perform an invalid floating-point operation, like taking the square root of a negative number, or dividing 0.0 by 0.0. Some people also use NaNs to represent uninitialized values, or as placeholders for missing data. > - As pickle write the data I'm a bit confused, that is can't > be unpickled it. Is that a bug or a feature? Well, it's certainly not ideal. It shouldn't be a problem in Python 2.6 or 2.7, though; unfortunately, Python 2.5 is no longer receiving bugfixes, so it's not going to change there. > BTW: I'm tied to version 2.5 of python Have you tried using pickle protocol 1 or 2, instead of pickle protocol 0? That may well solve your problem. (Those protocols write out the binary form of a float directly, instead of reading and writing a string representation.) -- Mark From airscorp at otenet.gr Mon Jul 12 11:11:11 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Mon, 12 Jul 2010 18:11:11 +0300 Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing In-Reply-To: References: Message-ID: <4C3B308F.3000300@otenet.gr> Hi Richard! > I have downloaded iptcinfo and placed it in python27\Lib\site-packages > \iptcinfo > > I guessed that was the right place, because that is where PIL ended > up, but that had a fancy installer with it. > > You did place it in the right path, but the "fancy installer" does one more thing, it registers the package into the python-path, so python can get to it. I've long switched from windows unfortunately and can't remember the way it does this though, so you can do it manually. Have some good news though: I looked in the IPTCinfo package and it does indeed include a setup.py, which is a standard way of installing python packages. All you need to do is unpack the package to any folder and run setup.py install from that folder, which should take care of everything for you. Some documentation on installing packages for you to read: http://docs.python.org/install/ Nick From gherron at islandtraining.com Mon Jul 12 12:42:25 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 12 Jul 2010 09:42:25 -0700 Subject: round issue In-Reply-To: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3B45F1.2020109@islandtraining.com> On 07/12/2010 02:52 AM, Robin Becker wrote: > A client wants to know why his db number -9.85 gets displayed by some > simple code as -9.8 > > I looked at the number and see that > > >>> -9.85 > -9.8499999999999996 > > ie I expect simple rounding to produce the observed result and indeed > > >>> '%.1f' % -9.85 > '-9.8' > > however, when I use round I get an unexpected result ie > >>> round(-9.85,1) > -9.9000000000000004 > > according to its definition > >> round(x[, n])? >> Return the floating point value x rounded to n digits after the >> decimal point. >> If n is omitted, it defaults to zero. The result is a floating >> point number. >> Values are rounded to the closest multiple of 10 to the power >> minus n; >> if two multiples are equally close, rounding is done away from 0 >> (so. for example, >> round(0.5) is 1.0 and round(-0.5) is -1.0). > > so looking at the absolute differences I see > > >>> abs(-9.9 - -9.85) > 0.050000000000000711 > >>> abs(-9.8 - -9.85) > 0.049999999999998934 Do you *seriously* need to ask a computer if -9.85 is half-way between -9.9 and -9.8. Just look at the numbers man! Of course it's equally close to both, so rounding to -9.9 is correct according to the definition. Do you actually *believe* that -9.9 - -9.85 = 0.050000000000000711. Of course you know it's really 0.05. All you've done here is demonstrate the fallible nature of (the last several digits of) floating point arithmetic on a computer. Don't let that distract you from using your common sense. Gary Herron > ie the -9.8 value appears closer and at least to a primitive test > > >>> abs(-9.9 - -9.85) > abs(-9.8 - -9.85) > True > > the distance from the -9.9 result is larger, however, that may be > because the model numbers for -9.8 & -9.9 differ in distance from the > true 10**-n values eg > > >>> -9.9 > -9.9000000000000004 > >>> -9.8 > -9.8000000000000007 > > What value should round(-9.85,1) return? Is the result explainable in > python (ie without resort to the internal FP representations etc etc)? From thomas at jollans.com Mon Jul 12 13:16:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 12 Jul 2010 19:16:03 +0200 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: <4C3B4DD3.5080304@jollans.com> On 07/12/2010 01:44 AM, rantingrick wrote: > On Jul 11, 11:31 am, Thomas Jollans wrote: >> On 07/11/2010 07:44 AM, rantingrick wrote: > >>> Congratulations on this effort Luke. However you know what project i >>> would really like to see the community get around? ...dramatic pause >>> here... a cross platform Python file browser! >> >> Cross platform file manager. Hmm. Does "cross platform" involve UNIX and >> something that isn't UNIX, say, Windows? >> Erm, no. No, no, no. It won't work....... trying to >> support both UNIX and Windows is NOT a good idea. > > Why is that a bad idea, Python does it all the time? Many software so > it all the time. This sounds like more fear than anything. Python is not a file manager. > > If you attempt to be full-featured, keeping it in one >> code base, let alone in one user interface, is destined to be a >> nightmare and induce suicides. > > Thats False! > >> The above might have been very slightly exaggerated. > > Thats True! > From nagle at animats.com Mon Jul 12 13:16:07 2010 From: nagle at animats.com (John Nagle) Date: Mon, 12 Jul 2010 10:16:07 -0700 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> On 7/12/2010 7:19 AM, Grant Edwards wrote: > On 2010-07-09, Les Schaffer wrote: > >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking > ^^^^^^^^^^ > > IMO, that's going to be your main problem. If you're doing a real-time job, run a real-time OS. QNX, a real-time variant of Linux, Windows CE, Windows Embedded, LynxOS, etc. There's too much background junk going on in a consumer OS today. Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP. This is a machine that moves around a plasma torch that cuts thick steel plate. A "New Java update is available" window popped up while I was working. Not good. John Nagle From animator333 at gmail.com Mon Jul 12 14:08:50 2010 From: animator333 at gmail.com (King) Date: Mon, 12 Jul 2010 11:08:50 -0700 (PDT) Subject: Node based architecture Message-ID: <5a1a0178-771c-4aa8-9c15-bc1ad2f60fa9@p11g2000prf.googlegroups.com> Hi, I am planning to build a generic node based framework using python. I would start with a simple image editing application. I hope that experienced users understands what am I trying to say here. In simple words: LoaderNode : Load Image from disk OperatorNode : Performs a specific task on data and spit output(data) OutputNode : Get the data from OperatorNode(output) and writes image to disk. Graph : A collection Nodes that are inter connected. The question is how to process graph? Here is a simple representation: class Integer(object): """ A simple integer node. """ def __init__(self, value=0): self.value = value def output(self): return self.value class OperatorAdd(object): """ A simple operator node """ def __init__(self, integerInst1=None, integerInst2=None): self.a = integerInst1.output() self.b = integerInst2.output() def compute(self): return Integer(self.a + self.b) def output(self): return self.compute() "Integer" is data node and "OperatorAdd" is a compute node. Imagine I have created two integer nodes and their output is going to "OperatorNode". One way to solve is to represent every node using a string and then you can write these series of string which actually is a python code that you can execute and get the result. Example: compute = """ i1 = Integer(2) i2 = Integer(3) i3 = OperatorAdd(i1, i2).output() """ Now you can execute "compute" variable using exec(compute) or something like that. This would do the job but I would like to know the opinion of more experienced users. One advantage of above mentioned string method is that it can be saved to disk and later you can load/compute it again. Cheers Prashant From alf.p.steinbach+usenet at gmail.com Mon Jul 12 14:11:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 20:11:36 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 12.07.2010 16:59: > On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> We're talking about defining a 'swap' routine that works on variables. > > I did not miss the point. One cannot make a swap function that rebinds > its arguments in the calling stack frame. But a swap function can swap > values, given that the type is not immutable: > > def swap(a,b): > a[0],b[0] = b[0],a[0] > >>>> a,b = [1],[2] >>>> swap(a,b) >>>> print a,b > [2] [1] OK, that's missing the point. I thought you were joking. Cheers & hth., - Alf -- blog at From ash.connor at gmail.com Mon Jul 12 14:13:50 2010 From: ash.connor at gmail.com (ashconnor) Date: Mon, 12 Jul 2010 11:13:50 -0700 (PDT) Subject: Problems running VirtualEnv under Windows. References: <7fc04b13-8006-45f6-a099-94bd9353761f@c33g2000yqm.googlegroups.com> Message-ID: I've resolved this issue by deleting the *.py file association in Windows. You can do this either by associating *.py with something like textpad, using a utility such as http://defaultprogramseditor.com/ or doing so in the registry. Note that when using the command like you need to issue commands with a preceding `python` keyword. For example in a normal installation enviroment the following is possible `django-admin.py startproject MyProject`, however in a VirtualEnv with *.py associations removed one must do `python django- admin.py startproject MyProject` otherwise Windows will attempt to open the file in the default application even if there isn't one. Thanks, Ash On Jul 12, 1:55?am, ashconnor wrote: > Hello, > > After reading 'Practical Django Projects' I decided that I want to > implement the VirtualEnv tip suggested in order to properly segregate > code/modules in different projects. I am however having problems with > my django installations not using site-packages within the virtualenv > but rather attempting to use site-packages in the default python > installation directory. > > Recreating the problem: > > 1) Install Python 2.7 via the Windows installer. Add C:/Python27;C:/ > Python27/Scripts to Windows PATH. > 2) Install setuptools-0.6c11-py2.7.egg via the Windows installer. > 3) Install VirtualEnv through `pip install virtualenv` > 4) Create an VirtualEnv via `virtualenv --no-site-packages MyEnvName` > 5) Activate VirtualEnv via `../MyEnvName/Scripts/activate.bat` > 6) Install django via `pip install django` > 7) Run django-admin.py startproject ProjectName > 8) Error results stating django.core module does not exist. > > NB: This error will not occur if django is installed in your root > directory. > NB2: Running the Python interpreter in active VirtualEnv to print the > sys.path shows the correct paths. Which has just futher added to my > confusion. > > I'd appreciate any insight or troubleshooting assistance. > > Thanks > > Ash From emile at fenx.com Mon Jul 12 14:15:28 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 12 Jul 2010 11:15:28 -0700 Subject: round issue In-Reply-To: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: On 7/12/2010 2:52 AM Robin Becker said... > What value should round(-9.85,1) return? Per round's definition, -9.9. String interpolation for %n.mf doesn't appear to define it's rounding behavior, so a peek at the source would answer what's being done. It does look inconsistent however, and it seems to me rounding and interpolation should behave similarly. So I'd call it a bug. Emile >>> def display(val): ... print "%.1f" % val ... print round(val,1) ... >>> display(1.45) 1.5 1.5 >>> display(-1.45) -1.5 -1.5 >>> display(-1.85) -1.9 -1.9 >>> display(1.85) 1.9 1.9 >>> display(-7.85) -7.8 -7.9 >>> display(-9.85) -9.8 -9.9 >>> From john at castleamber.com Mon Jul 12 14:26:29 2010 From: john at castleamber.com (John Bokma) Date: Mon, 12 Jul 2010 13:26:29 -0500 Subject: GUIs (was: grailbrowser now running under python 2.5 (probably above too)) References: <87aapxyc7p.fsf@castleamber.com> Message-ID: <8739voeeui.fsf_-_@castleamber.com> MRAB writes: > John Bokma wrote: [..] >> Can't think of why not. Of course not all operations are shared by each >> OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean >> that on Windows I can't make a file only readable by me. Just give me >> the Windows security options on Windows, and chmod on *nix and I would >> be very happy. >> > On Windows the root folders of the different drives could be treated as > subfolders of a 'root' folder. Yup, instead of a single tree there is a forrest. Wouldn't confuse me, and I doubt anyone else. >> Especially if all can be done via a context menu a la RISC OS. >> > Ah, RISC OS! :-D. > > I'd heard how user-friendly the Mac was, but when I was first introduced > to the Mac (circa MacOS 8) I was very surprised that even it still used > old-fashioned Open and Save dialog boxes with their own little file > browsers like on a Windows PC instead of drag-and-drop like I'd become > used to on RISC OS. And that menu bar not even at the top of the window > but at the top of the _screen_! And the way that bringing one Finder > window to the front brought _all_ the Finder windows in front of the > other windows! I was distinctly underwhelmed... :-( > It's on top of the screen because of Fitts's law: it's easier to move accurately to the top of the screen than to the top of the window (unless it's located in the top or bottom of the screen). However, personally I think that a context menu even scores better: it's easier to click a mouse button than to roll up and then move to the correct menu entry. Yes, RISC OS has some very good ideas: 1) context menus instead of menus at the top of the Windows/screen 2) clearly defined operations of each of the three mouse buttons: left = select, middle = context menu, right = adjust 3) the ability to select items in a menu and keep the menu open 4) drag & drop saving/loading (including between applications) 5) direction of scrollbars depends on mouse button: left = expected direction, right = reverse. Based on this I would say that the designers of RISC OS understood Fitts's Law way better. I am aware of ROX but haven't checked it out yet. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alf.p.steinbach+usenet at gmail.com Mon Jul 12 14:28:49 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 20:28:49 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 12.07.2010 04:39: > On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > >> * MRAB, on 12.07.2010 00:37: > [...] >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. > > Oh, I'm going to regret being sucked into this... > > In *CPython*, but not necessarily other implementations, variables which > are local to a function are not kept in a dictionary-based namespace, but > in slots in the code object (not to be confused with __slots__ used for > classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing > locals. > > This is intended as a speed, and possibly memory, optimization. I don't > believe this is a requirement though, so implementations may not do this. > > It is true that the slot is created at compile time, and in *that sense*, > local variables exist before they are bound. I'm not entirely convinced > that this is the only sense that matters, but never mind. The error > message given exposes this to the user: > >>>> def f(): > ... print x > ... x = 1 > ... >>>> f() > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in f > UnboundLocalError: local variable 'x' referenced before assignment > > > If you try this with a global, you get this: > >>>> def f(): > ... global x > ... print x > ... >>>> f() > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in f > NameError: global name 'x' is not defined > > In this case, there's no doubt that global variable "x" doesn't exist at > all -- there is no key "x" in the global namespace. Yes. What I disproved was the statement that every Python variable is created by the execution of an assignment. Some (the global ones) are. :-) > It seems to me that "a slot to hold the variable is created for local > variables" is an implementation detail, not a language feature. Yes. However, any Python implementation has to implement the same user level semantics in some way (note: use level semantics do not include "space reserved" for an unassigned variable, or even for all assigned variables since with single assignment a sufficiently smart compiler can optimize away the space, but user level semantics do include existence and resultant effect). As I see it it doesn't matter whether the implementation is CPython call frame slots or that mechanism called something else or a different mechanism called the same or a different mechanism called something different; what IMO matters is same semantics, that any assignment to a variable within a routine serves as a compile time declaration, creating that local variable in advance, unless, with Python 3.x., that name has been declared as a 'global' or 'nonlocal'. So, this is a possible point of disagreement. I say the semantics of local variable creation are part of the language definition, but I get the /impression/ that maybe you think it's CPython-specific, that e.g. def foo(): x x = 0 might not raise an unassigned variable exception with some conforming Python implementation, i.e. different effect for same code with different implementations, that this is at least /unspecified behavior/ in Python? > CPython > could easily hide the difference by changing the exception from > UnboundLocalError to: > > NameError: local name 'x' does not exist > > and nobody would be any wiser. (Well, perhaps people who catch > UnboundLocalError, but why would you do that?) > > I also note that UnboundLocalError is a subclass of NameError, so > "variable exists but is not bound" is considered to be a special case of > "variable doesn't exist" rather than a completely independent case. In > that sense, I think I'm on solid ground to say that in Python variables > don't exist until they are bound to a value, and leave it to pedants like > you and I to mention that for CPython local variables have space reserved > for them by the compiler before they are bound. He he. I wouldn't say "space reserved". That is an implementation detail. Cheers, - Alf -- blog at From cmpython at gmail.com Mon Jul 12 14:54:15 2010 From: cmpython at gmail.com (CM) Date: Mon, 12 Jul 2010 11:54:15 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: On Jul 12, 1:16?pm, John Nagle wrote: > On 7/12/2010 7:19 AM, Grant Edwards wrote: > > > On 2010-07-09, Les Schaffer ?wrote: > > >> i have been asked to guarantee that a proposed Python application will > >> run continuously under MS Windows for two months time. And i am looking > > ? ? ? ? ? ? ? ? ? ? ? ? ? ^^^^^^^^^^ > > > IMO, that's going to be your main problem. > > ? ? If you're doing a real-time job, run a real-time OS. ?QNX, > a real-time variant of Linux, Windows CE, Windows Embedded, LynxOS, > etc. ?There's too much background junk going on in a consumer OS > today. > > ? ? Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. ?This is a machine that moves around a plasma torch that > cuts thick steel plate. ?A "New Java update is available" window > popped up while I was working. ?Not good. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle I'm not sure I can like that example any better. From dickinsm at gmail.com Mon Jul 12 14:59:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 18:59:35 +0000 (UTC) Subject: round issue References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: Emile van Sebille fenx.com> writes: > > On 7/12/2010 2:52 AM Robin Becker said... > > > What value should round(-9.85,1) return? > > Per round's definition, -9.9. No. The float that's represented by the literal '-9.85' *isn't* exactly -9.85, for all the usual binary floating-point reasons. The value that gets stored is a tiny amount smaller (i.e., closer to zero) than -9.85, so according to the definition it should round *down*, to -9.8. (Or rather, to a float that's very close to, but not exactly equal to, -9.8.) > String interpolation for %n.mf doesn't > appear to define it's rounding behavior, so a peek at the source would > answer what's being done. In Python 2.6, the string interpolation delegates to the system, so it does whatever C string formatting does. Usually that's rounding to nearest, with exact halfway cases rounded to even. In Python 2.7 and 3.x, Python has its own code for string formatting, and again it rounds to nearest, rounding ties to even. > It does look inconsistent however, and it seems to me rounding and > interpolation should behave similarly. Agreed. In this case it's a minor bug that round(-9.85, 1) produces -9.9 instead of -9.8; both string formatting and round should give -9.8. This bug is fixed in Python 2.7 and in Python 3.x. Note that in 2.7 there's still a legitimate difference: round rounds halfway cases away from 0, while string formatting rounds them to even. So the following results are correct: Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> round(1.25, 1) 1.3 >>> '%.1f' % 1.25 '1.2' (1.25 *is* an exact halfway case, since it's exactly representable as a binary float.) In Python 3.x, round always does round-half-to-even, so string formatting and round should agree (and if they don't, it's definitely a bug: please report it!) With all this said, asking for *decimal* rounding of *binary* approximations to *decimal* halfway cases to give the results you expect is ... optimistic, to say the least. Use the decimal module if you care about which way your (almost) halfway cases get rounded. [I already replied to this earlier through Google groups, but I'm not sure whether it went through properly. Apologies for the duplication, if so.] -- Mark From dhruvbird at gmail.com Mon Jul 12 15:24:29 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 12 Jul 2010 12:24:29 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> <87630lrlo2.fsf@busola.homelinux.net> Message-ID: <906a8735-4f2b-45b5-bc14-5ac570098819@z30g2000prg.googlegroups.com> On Jul 12, 4:20?pm, Hrvoje Niksic wrote: > dhruvbird writes: > > No, I meant x.append(4) > > Except that I want to accomplish it using slices. > > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > > way?) > > It seems that you've found a way to do so, so why do you need another > way? ?Are you after elegance? ?Efficiency? ?Brevity? Actually, the reason I ask is because I think a lot of things can be done using slices and its support for negative indexes. Basically putting constants in the slices (as opposed to variables like len(x), etc... which depend upon the variable name). So, was just trying to cogitate on whether append can be implemented that way or not. Regards, -Dhruv. From nagle at animats.com Mon Jul 12 15:46:08 2010 From: nagle at animats.com (John Nagle) Date: Mon, 12 Jul 2010 12:46:08 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3b7102$0$1587$742ec2ed@news.sonic.net> On 7/11/2010 5:24 PM, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > >> Why doesn't python's list append() method return the list itself? For >> that matter, even the reverse() and sort() methods? I found this link >> (http://code.google.com/edu/languages/google-python- class/lists.html) >> which suggests that this is done to make sure that the programmer >> understands that the list is being modified in place, but that rules out >> constructs like: >> ([1,2,3,4].reverse()+[[]]).reverse() > > Yes. So what? Where's the problem? > > List methods work in place. ... > Not everything needs to be a one-liner. It's interesting that all Python functions are considered to return a value. Arguably, if a function just does a "return", it should be an error to try to use its return value. Some languages have a very functional orientation, and everything is considered to return some value, even control structures. LISP is like that. But Python isn't one of those languages. John Nagle From mcl.office at googlemail.com Mon Jul 12 15:56:50 2010 From: mcl.office at googlemail.com (mcl) Date: Mon, 12 Jul 2010 12:56:50 -0700 (PDT) Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing References: Message-ID: <008715c6-4bb3-4d55-a82f-bbecbdfda069@k39g2000yqd.googlegroups.com> On Jul 12, 4:11?pm, Nick Raptis wrote: > Hi Richard!> I have downloaded iptcinfo and placed it in python27\Lib\site-packages > > \iptcinfo > > > I guessed that was the right place, because that is where PIL ended > > up, but that had a fancy installer with it. > > You did place it in the right path, but the "fancy installer" does one > more thing, it registers the package into the python-path, so python can > get to it. > I've long switched from windows unfortunately and can't remember the way > it does this though, so you can do it manually. > > Have some good news though: I looked in the IPTCinfo package and it does > indeed include a setup.py, which is a standard way of installing python > packages. > All you need to do is unpack the package to any folder and run > setup.py install > from that folder, which should take care of everything for you. > > Some documentation on installing packages for you to read:http://docs.python.org/install/ > > Nick What a star. It is all now working. I will try to look at the reference you mentioned, but at the moment I can not even figure out why 'python' on its own does not work. I would have thought the installation would have set the appropriate environment variables, but it does not seem to have. I have to give the full path name to python.exe. Just remembered SET at DOS prompt, but no mention of PYTHON anywhere. Thank you very much again - I now have a list of all my JPEGS and their CAPTIONS. Richard From rhodri at wildebst.demon.co.uk Mon Jul 12 16:19:56 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 12 Jul 2010 21:19:56 +0100 Subject: Easy questions from a python beginner References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote: > "Steven D'Aprano" wrote in > message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... >> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: >> >>> That's interesting. So in Python, you can't tell what local variables a >>> function has just by looking at it's code: > >>> def foo(day): >>> if day=="Tuesday": >>> x=0 >>> print ("Locals:",locals()) >>> >>> #foo("Monday") >>> >>> Does foo() have 1 or 2 locals? >> >> That's easy for CPython: it prepares two slots for variables, but only >> creates one: >> >>>>> foo("Monday") >> ('Locals:', {'day': 'Monday'}) >>>>> foo.func_code.co_varnames >> ('day', 'x') >>>>> foo.func_code.co_nlocals >> 2 >> >> So, the question is, is x a local variable or not? It's not in locals, >> but the function clearly knows that it could be. > > So Alf P.S. could be right; x exists, but Python pretends it doesn't > until it's assigned to. CPython, not Python. And as Steven said, x *doesn't* exist. Allowance is made by that specific implementation of the interpreter because x *might* exist, but in this particular case it doesn't and a more dynamic implementation might choose not to reserve a slot just in case. x is created until it's actually used. -- Rhodri James *-* Wildebeeste Herder to the Masses From john at castleamber.com Mon Jul 12 16:27:07 2010 From: john at castleamber.com (John Bokma) Date: Mon, 12 Jul 2010 15:27:07 -0500 Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <87sk3ofntw.fsf@castleamber.com> John Nagle writes: > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. You can blame that one on Sun (or Oracle nowadays). Good example though. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From hujia06 at gmail.com Mon Jul 12 16:27:19 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 16:27:19 -0400 Subject: how to delete "\n" Message-ID: Hi, I just want to delete "\n" at each line. My operating system is ubuntu 9.1. The code is as follows #!/usr/bin/python import string fileName=open('Direct_Irr.txt', 'r') # read file directIrr = fileName.readlines() fileName.close() for line in directIrr: line.rstrip('\n') print directIrr But I found there is still "\n" . Could someone help me why it is not correct? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Mon Jul 12 16:34:23 2010 From: landimatte at gmail.com (Matteo Landi) Date: Mon, 12 Jul 2010 22:34:23 +0200 Subject: how to delete "\n" In-Reply-To: References: Message-ID: I hope this could help: >>> f = open('powersave.sh') >>> map(lambda s: s.strip(), f.readlines()) ['echo 1 > /sys/module/snd_hda_intel/parameters/power_save', 'echo min_power > /sys/class/scsi_host/host0/link_power_management_policy', 'echo 1 > /sys/module/snd_hda_intel/parameters/power_save'] I know for sure someone else will address you to other better solutions :) On Mon, Jul 12, 2010 at 10:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? > > Thank you > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From alister.ware at ntlworld.com Mon Jul 12 16:36:36 2010 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 12 Jul 2010 20:36:36 GMT Subject: Easy questions from a python beginner References: Message-ID: On Sun, 11 Jul 2010 18:17:49 +0000, Duncan Booth wrote: > wheres pythonmonks wrote: > >> I'm an old Perl-hacker, and am trying to Dive in Python. I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: without going into details on how to do these things in python(many suggestions have already been made) i think you need to take a step back Why do you want to do these particular things in this way? is it because this is what is needed to get the job done or is it because this is what's needed to get the job done in perl? if the later then step back and think what is the real goal & program accordingly. Each language does things differently ( if they didn't we wouldn't have different languages!) what is Best for perl (or c , java, pascal or malbolge) may not necessarily be the best for Python & vice Versa. -- backups: always in season, never out of style. From ian.g.kelly at gmail.com Mon Jul 12 16:38:49 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 14:38:49 -0600 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 2:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? The print statement automatically adds a newline to each line. If you want the lines written verbatim, use sys.stdout.write(line) From tjreedy at udel.edu Mon Jul 12 16:44:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 16:44:40 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: On 7/12/2010 4:48 AM, bart.c wrote: >> >>> def foo(): >> print("Before:", locals()) >> x = 0 >> print("After:", locals()) >> >> >> >>> foo() >> Before: {} >> After: {'x': 0} > > That's interesting. So in Python, you can't tell what local variables a > function has just by looking at it's code: You are being fooled by the multiple meanings of the overloaded term 'variable'. Thing are clearer with the two terms 'name' and 'namespace' (a set of name-object bindings). Before compiling function code, an interpreter must read it and make a classified list of *names*. The interpreter has to know the fixed set of local names in order to know what to do with assignment statements. If the interpreter can tell how many local names there are, so can you. Before a function begins execution, all parameter names must be bound, with no arguments left over. At that point, the local namespace consists of those parameter-object bindings. During the execution of the function, bindings may be added and deleted. The size of the local namespace varies. > def foo(day): > if day=="Tuesday": > x=0 > print ("Locals:",locals()) > > #foo("Monday") > > Does foo() have 1 or 2 locals? foo has 2 local names. Its local namespace starts with 1 binding and may get another, depending of the value of the first. If the size of the local namespace at some point of execution depends on unknown information, then of course the size at that point is also unknown. Here is another example: >>> def f(a): print(locals()) del a print(locals()) a = None print(locals()) >>> f(2) {'a': 2} {} {'a': None} -- Terry Jan Reedy From clp2 at rebertia.com Mon Jul 12 16:45:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 13:45:27 -0700 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? .rstrip() returns a *new* string without trailing whitespace (which you are currently then throwing away); it does *not* modify string objects in-place. Python strings objects are entirely immutable and unmodifiable; all operations on them merely produce /new/ strings. Assuming you still want to use .readlines(), you'd do: directIrr = fileName.readlines() fileName.close() directIrr = [line.rstrip('\n') for line in directIrr] print directIrr For how third line works, google "python list comprehensions". Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Mon Jul 12 16:51:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 16:51:48 -0400 Subject: Numpy now supports Python3, Scipy to follow soon In-Reply-To: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> References: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Message-ID: On 7/12/2010 4:05 AM, Steven D'Aprano wrote: > Pardon me if this has already been mentioned, but I didn't see it, and > this is big big news. > > The latest release of numpy now supports Python 2.x and 3.x out of a > single code base, and Scipy is predicted to follow soon. > > http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html > > If I can take the liberty of quoting Pauli Virtanen: > > An important point is that supporting Python 3 and Python 2 > in the same code base can be done, and it is not very difficult > either. It is also much preferable from the maintenance POV to > creating separate branches for Python 2 and 3. > > > Well done to all those who contributed to the effort! There are extensive notes on the transition at http://projects.scipy.org/numpy/browser/trunk/doc/Py3K.txt I am sure that some of this should be added to the current HowTo on porting CAPI to Py3. -- Terry Jan Reedy From alf.p.steinbach+usenet at gmail.com Mon Jul 12 16:57:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 22:57:10 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Rhodri James, on 12.07.2010 22:19: > On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote: > >> "Steven D'Aprano" wrote in >> message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... >>> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: >>> >>>> That's interesting. So in Python, you can't tell what local variables a >>>> function has just by looking at it's code: >> >>>> def foo(day): >>>> if day=="Tuesday": >>>> x=0 >>>> print ("Locals:",locals()) >>>> >>>> #foo("Monday") >>>> >>>> Does foo() have 1 or 2 locals? >>> >>> That's easy for CPython: it prepares two slots for variables, but only >>> creates one: >>> >>>>>> foo("Monday") >>> ('Locals:', {'day': 'Monday'}) >>>>>> foo.func_code.co_varnames >>> ('day', 'x') >>>>>> foo.func_code.co_nlocals >>> 2 >>> >>> So, the question is, is x a local variable or not? It's not in locals, >>> but the function clearly knows that it could be. >> >> So Alf P.S. could be right; x exists, but Python pretends it doesn't >> until it's assigned to. > > CPython, not Python. And as Steven said, x *doesn't* exist. Allowance is > made by that specific implementation of the interpreter because x > *might* exist, but in this particular case it doesn't and a more dynamic > implementation might choose not to reserve a slot just in case. x is > created until it's actually used. You are conflating existence with space allocation. It's up to the implementation whether to allocate memory for the variable's reference in any particular case where that memory isn't strictly required. This is known as "optimization". Optimization depends on the implementation. Existence of a variable means, among other things, that * You can use the value, with guaranteed effect (either unassigned exception or you get a proper value): in particular, you won't be accessing a global if you're using the name of a local declared by a later assignment. * You can assign to it. How the Python implementation implements that is an implementation detail. In short, how CPython does things is completely irrelevant to the language's semantics, so you're conflating things here. Cheers & hth., - Alf -- blog at From luke.leighton at gmail.com Mon Jul 12 16:59:09 2010 From: luke.leighton at gmail.com (lkcl) Date: Mon, 12 Jul 2010 13:59:09 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) Message-ID: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> for several reasons, i'm doing a cooperative multi-tasking HTTP server: git clone git://pyjs.org/git/multitaskhttpd.git there probably exist perfectly good web frameworks that are capable of doing this sort of thing: i feel certain that twisted is one of them. however, the original author of rtmplite decided to rip twisted out and to use multitask.py and i'm one of those strange people that also likes the idea of using 900 lines of awesome elegant code rather than tens of thousands of constantly-moving-target. one of the things that's slightly unfortunate is that i'm going to have to copy SimpleHTTPServer.py and slightly modify it; CGIHTTPServer.py as well. this is Generally Bad Practice. can anyone think of a way of monkey-patching or otherwise using SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the base class from which those two are derived? i have had to pull bits out of BaseHTTPRequestHandler to make them use the "yield" logic of multitask.py already, which was painful enough. ideas, anyone? l. From alf.p.steinbach+usenet at gmail.com Mon Jul 12 16:59:44 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 22:59:44 +0200 Subject: Standard distutils package problems with MSVC / lacking functionality? Message-ID: I let the setup.py script talk: # 03_1__noddy from distutils.core import setup, Extension import distutils.ccompiler compilerName = distutils.ccompiler.get_default_compiler() options = [] if compilerName == "msvc": # * distutils sets warning level 3: # Overriding with warning level 4 generates command line warning D9025... # There's no good away around that, it needs fix/extension of distutils # or the config file(s) that distutil uses (perhaps that's a makefile?). options.append( "/W4" ) # Must be done in this script. # * distutils forgets to enable exception handling: options.append( "/EHsc" ) # Could be done via CL env. var. # * distutils forgets to enable RTTI: options.append( "/GR" ) # Could be done via CL env. var. # * distutils forgets to enable standard 'for' loop and 'wchar_t' type: options.append( "/Zc:forScope,wchar_t" ) # Could be done via CL env. var. module1 = Extension( name = "noddy", sources = [ "noddy.cpp" ], extra_compile_args = options ) setup( name = "noddy", version = '1.0', description = 'This is a demo package', ext_modules = [module1] ) Cheers, - Alf -- blog at From gdamjan at gmail.com Mon Jul 12 17:15:59 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 12 Jul 2010 23:15:59 +0200 Subject: Lua is faster than Fortran??? References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: On the positive side, Lua supports tail call optimization and coroutines are built in by default. -- ?????? ((( http://damjan.softver.org.mk/ ))) Education is one of the "prices" of freedom that some are unwilling to pay. From python at bdurham.com Mon Jul 12 17:29:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 12 Jul 2010 17:29:11 -0400 Subject: how to delete "\n" In-Reply-To: References: Message-ID: <1278970151.7048.1384527261@webmail.messagingengine.com> Jia, print ''.join( open( 'Direct_Irr.txt' ).read().split() ) Broken out: - open(): open file - read(): read its entire contents as one string - split(): split the contents into a list of lines (splits lines at \n; does not include \n in split values) - ''.join(): join list of lines with an empty char Malcolm From hujia06 at gmail.com Mon Jul 12 17:33:02 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 17:33:02 -0400 Subject: how to delete "\n" In-Reply-To: References: Message-ID: Thank you. It works now. if I use 'print' to print the whole list, 'print' will add newline at the end of the list but not each item in the list. right? For the code: for line in fileName: line = line.rstrip('\n') I think this will affect 'fileName' because it assign the value to 'line' ? But when I print fileName, "\n" still exists at each item in the list. Because each line in my txt file are numeric values. is there any other better way to get each numerical value at each line? for example using numpy or changing string list to numerical list? Thank you for help. On Mon, Jul 12, 2010 at 4:45 PM, Chris Rebert wrote: > On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: > > Hi, I just want to delete "\n" at each line. My operating system is > ubuntu > > 9.1. The code is as follows > > > > #!/usr/bin/python > > import string > > fileName=open('Direct_Irr.txt', 'r') # read file > > directIrr = fileName.readlines() > > fileName.close() > > for line in directIrr: > > line.rstrip('\n') > > print directIrr > > > > But I found there is still "\n" . Could someone help me why it is not > > correct? > > .rstrip() returns a *new* string without trailing whitespace (which > you are currently then throwing away); it does *not* modify string > objects in-place. Python strings objects are entirely immutable and > unmodifiable; all operations on them merely produce /new/ strings. > > Assuming you still want to use .readlines(), you'd do: > directIrr = fileName.readlines() > fileName.close() > directIrr = [line.rstrip('\n') for line in directIrr] > print directIrr > > For how third line works, google "python list comprehensions". > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 12 17:36:11 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 12 Jul 2010 23:36:11 +0200 Subject: how to delete "\n" In-Reply-To: <1278970151.7048.1384527261@webmail.messagingengine.com> References: <1278970151.7048.1384527261@webmail.messagingengine.com> Message-ID: <4C3B8ACB.8030907@jollans.com> On 07/12/2010 11:29 PM, python at bdurham.com wrote: > Jia, > > print ''.join( open( 'Direct_Irr.txt' ).read().split() ) > > Broken out: > > - open(): open file > - read(): read its entire contents as one string > - split(): split the contents into a list of lines > (splits lines at \n; does not include \n in split values) also splits at other whitespace. > - ''.join(): join list of lines with an empty char > > Malcolm From gelonida at gmail.com Mon Jul 12 17:52:15 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 12 Jul 2010 23:52:15 +0200 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: Hi lkcl, Do you have any documentation or overview for your project? Questions I would be interested in: - List of features already working - list of features under development - list of features being in in the near future lkcl wrote: > for several reasons, i'm doing a cooperative multi-tasking HTTP > server: > git clone git://pyjs.org/git/multitaskhttpd.git > > there probably exist perfectly good web frameworks that are capable of > doing this sort of thing: i feel certain that twisted is one of them. > however, the original author of rtmplite decided to rip twisted out > and to use multitask.py and i'm one of those strange people that also > likes the idea of using 900 lines of awesome elegant code rather than > tens of thousands of constantly-moving-target. > > one of the things that's slightly unfortunate is that i'm going to > have to copy SimpleHTTPServer.py and slightly modify it; > CGIHTTPServer.py as well. this is Generally Bad Practice. > > can anyone think of a way of monkey-patching or otherwise using > SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the > base class from which those two are derived? > > i have had to pull bits out of BaseHTTPRequestHandler to make them use > the "yield" logic of multitask.py already, which was painful enough. > > ideas, anyone? > > l. From python at bdurham.com Mon Jul 12 17:53:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 12 Jul 2010 17:53:01 -0400 Subject: how to delete "\n" In-Reply-To: <4C3B8ACB.8030907@jollans.com> References: <1278970151.7048.1384527261@webmail.messagingengine.com> <4C3B8ACB.8030907@jollans.com> Message-ID: <1278971581.13157.1384530935@webmail.messagingengine.com> Thomas, > split() also splits at other whitespace. Doh! Corrected version follows: print ''.join( open( 'Direct_Irr.txt' ).read().splitlines() ) Broken out: - open(): open file - read(): read its entire contents as one string - splitlines(): split the contents into a list of lines (splits lines at \n; does not include \n in split values) - ''.join(): join list of lines with an empty char Malcolm From f2h2d2 at gmail.com Mon Jul 12 17:54:00 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Mon, 12 Jul 2010 14:54:00 -0700 (PDT) Subject: Why did I Embrace Islam? Message-ID: <03506da7-7ea6-46af-b02d-fa4dec101f59@j13g2000yqj.googlegroups.com> Why did I Embrace Islam? This is an extract from Dr. Gronier, a French MP, who embraced Islam. Revealing the reason of embracing Islam he said, I read all of the Ayat (Quranic verses), which have a relation to medical, health, and natural sciences that I studied before and have a wide knowledge of. I found that these verses are totally compatible with and give a picture of our modern sciences. Thus, I embraced Islam as it was obvious that Muhammad revealed the Absolute Truth more than a thousand years ago. Had every specialist, artist or scientist compared those Quranic verses to his own specialization, beyond the shadow of doubt he would embrace Islam, especially if he has a sound mentality and goodwill to search for the truth and not a mentally defective person with the intentions of malevolent aims>> Islam is the last religion to be sent to the world , every religion had proofs that authenticated its Divine source . God foreordained that Islam would be the last message to the world , so it must comprise many miracles that could be categorized under six categories , among them in this age , being the age of science , what is termed as the scientific miracles which science has recently proved them amazingly . let alone the scientific miracle , as we are going to talk about the unseen matters news . Prophet Mohummed had depicted and given prophecies concerning our generation and the many generation to come . In fact , these prophecies which can't be easily enumerated , have come true . As to the miracle of the unseen news , prophet Mohummed gave a large number of them ; some of them happened during his life , others directly after his death . Every age witnessed the fulfilment some of these . The large portion of these prophecies go to our age . Insha Allah , we will tackle these in the coming studies. Some of these prophecies , as prophet Mohummed determined , are portents of the of the doomsday . we ,now , are approaching that day according to the Devine calculation . The miracle of the unseen tackled that the different phases of life , these tackled the social life , economic life , techmological life , political strifes and wars . Though ther are fearful , they prove the true phrophethood of prophet Mohummed . What we are giving here are just two portents that reflect the social and economic life .The Bedouins , in the life of prophet Mohummed , used to lead a very simple life . They used to live in very simple houses out of mud and palm leaves . The discovery of oil made a revolution in every thing in the life of the bedouin . Contraray to the life they used to lead , they ,now , live in very tall structures but even they compete in building very high structures a picture of a tall building in the arabia Here are two Hadith ( traditional sayings of prophet mohummed ) that talk about two prophecies that have come true . It is narrated in Sahih Muslim that Allah's Apostle (peace be upon him) said to his companions ( through a long conversation about the signs of the last hour) ask me but the companions of the prophet embarrassed to ask him. Then there appeared before us a man and sat with the Apostle (peace be upon him) He knelt before him placed his palms on his thighs and said: Muhammad, inform me about al-Islam. The Messenger of Allah (peace be upon him) said: Al-Islam implies that you testify that there is no god but Allah and that Muhammad is the messenger of Allah, and you establish prayer, pay Zakat, observe the fast of Ramadan. He (the inquirer) said: You have told the truth. He (the inquirer) said: Inform me about Iman (faith). He (the Holy Prophet) replied: That you affirm your faith in Allah, in His angels, in His Books, in His Apostles, in the Day of Judgment, and you affirm your faith in the Divine Decree about good and evil. He (the inquirer) said: You have told the truth. He (the inquirer) again said: Inform me about al-Ihsan (performance of good deeds). He (the Holy Prophet) said: That you worship Allah as if you are seeing Him, for though you don't see Him, He, verily, sees you. He (the enquirer) again said: Inform me about the hour (of the Doom). He (the Holy Prophet) remarked: One who is asked knows no more than the one who is inquiring (about it). He (the inquirer) said: Tell me some of its indications. He (the Holy Prophet) said: That the slave-girl will give birth to her mistress and master, that you will find barefooted, destitute goat- herds vying with one another in the construction of magnificent buildings . Man installed hundreds of marine stations to study the characteristics of various seas. Scientists have found out that the differences in these characteristics distinguished one sea from another. But why do these seas not mix and become homogeneous in spite of the effect of tide and ebb that moves sea water twice a day, and causes seas to move forward and backward turbulently, besides other factors that cause sea water to be in continuous movement and turbulence, such as surface and internal waves and sea currents? The answer appeared for the first time in scientific books in 1361 AH/ 1942 AD. Extensive studies of marine characteristics revealed that there are water barriers separating neighboring seas and maintaining the distinctive properties of each sea with respect to density, salinity, marine life, temperature and solubility of oxygen in water. There are large waves, strong currents, and tides in the Mediterranean Sea and the Atlantic Ocean. Mediterranean Sea water enters the Atlantic by Gibraltar. But their temperature, salinity, and densities do not change, because of the barrier that separates them. After 1962 AD there was known the role of sea barriers in modifying the properties of the water masses that pass from one sea to another, to prevent one sea from overwhelming the other. So salty seas retain their own properties and boundaries by virtue of these barriers. A field study comparing the waters of Oman Gulf and those of the Arabian Gulf has shown the difference between them regarding their chemical properties, the prevalent vegetation and the barrier separating them. About a hundred years of research and study has been required to discover the fact of the existence of barriers between sea water masses and their role in making each sea retain its own properties. Hundred of researchers took part and numerous precise scientific instruments and equipment were used to achieve that. Fourteen centuries ago the Holy Qur?an revealed this fact. We can conclude the following from the discussion above: The Holy Qur?an, which was revealed more than 14 centuries ago, includes very precise pieces of information and knowledge about marine phenomena that have been discovered only recently by means of very sophisticated equipment. An instance in this respect is the existence of water barriers between seas. The historical development of Oceanography shows that no precise information had been available on seas before Challenger Expedition (in 1873 AD), let alone at the time when the Holy Qur?an was being revealed 14 centuries ago to an illiterate Prophet that lived in a desert environment and never traveled by sea. Oceanography has witnessed no advances except in the last two centuries, particularly in the latter half of the twentieth century. Prior to that a sea was considered as something fearful and mysterious. Myths and superstitions were fabricated about it. Sea voyagers were only interested in their own safety and how to find the correct routes during their long journeys. Man discovered that salt seas are different only in the thirties of the twentieth century, after thousands of marine stations had been established by researchers to analyze samples of sea water to measure the differences between the degrees of temperature, salinity, density and oxygen dissolubility in the sea water recorded at all those stations, and then realize that salt seas are different. Man did not know anything about the barrier that separates between salt seas till the establishment of the aforesaid stations, and after spending a long time tracing these wavy moving barriers that change their geographical locations with the change of seasons. Man did not know that the water masses of the two seas are separated by a water barrier and are mixed at the same time till he started studying with his ships and equipment the water movement in the meeting region of the seas and analyzing the water masses in those regions. Man did not apply this rule to all seas that meet together except after vast scientific surveying, investigation and verification of this phenomenon, which occurs between each pair of adjacent seas in the world. Now then, did Allah?s Messenger (Peace be upon him) own stations and equipment for analyzing water and the ability to trace the movement of various water masses? Did he carry out a comprehensive surveying process, although he never sailed the sea and lived at a time when superstitions were prevalent, particularly in the field of seas? Were, at the time of Allah?s Messenger (Peace be upon him) such researches, instruments and studies as are available for the oceanographers of today who have discovered all these secrets by means of research and study? This knowledge, which the Qur?an came with, included a precise de******ion of the subtlest secrets at a time when humanity could never have known them, which indicates that its source is Divine **Regarding praying to Makkah at whose middle the Kaaba and the Inviolable Mosque lie, Allah orders us in the Qur?an to do so: ?So turn your face towards the Inviolable Mosque; and wherever you are, then turn your faces towards it.? (The Cow 144[a5]) Various studies, among which one was done by Dr. Hussein Kamal Ad Din, Head of the Department of Survey Engineering at RiyadhUniversity, proved that Makkah is the center of earth. Dr. Robert G. Coleman (3[a6]), StanfordUniversity in USA, did a study on the center of earth gravity and the point in which gravity cosmological radiations meet (the meeting point magnetic gravitational radiations) on earth; he found that this center is Makkah. Makkah, then, is the center of the seven continents as well as the meeting point of magnetic gravitational radiations.. As for going around the Kaaba anticlockwise, it is consistent with the movement of the whole universe: from the atom to the galaxy. Going around is a cosmological phenomenon that includes everything. The electron goes around the nucleus, the moons go around their planets, the planets go around their suns, the suns and the stars go around the centers of their galaxies, and even energy goes around in its paths; all these movements are anticlockwise. It is the same direction of the Hajji going around the Kaaba. salma Bouafair ( Soufi Bouafair )- M.D in teaching French and mathematics The story of this woman is an extraordinary example of the long tiring intellectual journey through which those who converted to Islam always undergo . She embodies the real challenging will and introduces a good courageous intellectual mind which is to be considered the finest kind of courage at all. She proudly narrated her story as follows: ? I was born in 1971 in Montreal, Canada. I was grown up within a religious Catholic family , so I used to go to church until I was 14 years old when I started to have my personal questions about our Creator and the different religions...I have always believed in God and in His power and in His greatness, so I have studied different religions seeking for any convincing answers for my endless questions but again I could not find what I was looking for? I was so confused and distracted until I started my university. There I came to know a Muslim young man , who introduced Islam to me. I was so overwhelmed as it was an easy way to track the answers for my doubts and questions. It took me a whole year just to study such a religion, and the result was that I was obsessed by Islam to the bones. I was further overwhelmed when I saw how the Moslems -in their prayers- adoringly prostrate themselves to God, it is some thing I could not find in any other religion. I was obsessed by such touching movements which the worshipper performs... they convey nothing but peace of mind , politeness and a perfect act of worship, it seems as if he really feels that he is at the hands of God. I started attending the mosque where I could find many other Canadian Muslim sisters, who encouraged me to follow my track to Islam. I wore the veil in an attempt to test my will, and two weeks later came the true moment when I testified that there are no other gods but Allah, the One, and that Muhammad (PBUH) is His prophet and messenger. [Watch videos of world's top scientists commenting on the "Miracle of Science in Quran"] http://islamyesterday.com/videos/science/ Discover the fastest growing religionin the world; http;//www.sultan.org www.55a.net From ninmonkeys at gmail.com Mon Jul 12 18:00:22 2010 From: ninmonkeys at gmail.com (Jake b) Date: Mon, 12 Jul 2010 17:00:22 -0500 Subject: Help choosing license for new projects Message-ID: I'm starting a new python code project. What license do you suggest? I am searching, but I'm not finding a simple comparison of licenses. So I don't know which to use. Maybe MIT or Apache or LGPL or BSD? Are there certain licenses to avoid using because of interaction problems between libraries using GPL2 / GPL3 / MIT / LGPL. / BSD with my own? I want: 1] Pretty much let anyone use it. Users do not have to include source code, as long as I get credit. (which I think normallly is a textfile with project url + name?) 2] (if it matters) I will be using different combinations of pyglet, pygame, wxPython, etc. 3] I want the option to use my own code in something commercial at a later date. Does #3 complicate things, or is fine when including author info? The choices for google code projects are: Apache License 2.0 Eclipse license 1.0 GPLv2 GPLv3 GNU lesser GPL MIT license Mozilla Public license 1.1 New BSD License thanks for advice, -- ninmonkey From python.list at tim.thechases.com Mon Jul 12 18:01:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jul 2010 17:01:33 -0500 Subject: any issues with long running python apps? In-Reply-To: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <4C3B90BD.6000508@tim.thechases.com> On 07/12/2010 12:16 PM, John Nagle wrote: > On 7/12/2010 7:19 AM, Grant Edwards wrote: >> On 2010-07-09, Les Schaffer wrote: >> >>> i have been asked to guarantee that a proposed Python application will >>> run continuously under MS Windows for two months time. And i am looking >> ^^^^^^^^^^ >> >> IMO, that's going to be your main problem. > > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. Hi, it looks like you're attempting to cut something with a plasma torch. Would you like help? (_) inserting a steel plate to cut (_) severing the tip of your finger [ ] Don't show me this tip again. -tkc From alister.ware at ntlworld.com Mon Jul 12 18:05:35 2010 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 12 Jul 2010 22:05:35 GMT Subject: Why did I Embrace Islam? References: <03506da7-7ea6-46af-b02d-fa4dec101f59@j13g2000yqj.googlegroups.com> Message-ID: On Mon, 12 Jul 2010 14:54:00 -0700, nais-saudi wrote: > Why did I Embrace Islam? Very interesting & good fro you but I cannot find any thing related to python here. -- This place just isn't big enough for all of us. We've got to find a way off this planet. From debatem1 at gmail.com Mon Jul 12 18:13:08 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 18:13:08 -0400 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: > for several reasons, i'm doing a cooperative multi-tasking HTTP > server: > ?git clone git://pyjs.org/git/multitaskhttpd.git > > there probably exist perfectly good web frameworks that are capable of > doing this sort of thing: i feel certain that twisted is one of them. > however, the original author of rtmplite decided to rip twisted out > and to use multitask.py and i'm one of those strange people that also > likes the idea of using 900 lines of awesome elegant code rather than > tens of thousands of constantly-moving-target. > > one of the things that's slightly unfortunate is that i'm going to > have to copy SimpleHTTPServer.py and slightly modify it; > CGIHTTPServer.py as well. ?this is Generally Bad Practice. > > can anyone think of a way of monkey-patching or otherwise using > SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the > base class from which those two are derived? > > i have had to pull bits out of BaseHTTPRequestHandler to make them use > the "yield" logic of multitask.py already, which was painful enough. > > ideas, anyone? > > l. I may not be fully understanding what you're doing, but is there a reason that one of the mixins can't be used? Geremy Condra From rami.chowdhury at gmail.com Mon Jul 12 18:14:52 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 12 Jul 2010 15:14:52 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <74B5583A-A65A-49EE-8876-8ADAEA74F138@gmail.com> Perhaps I'm misunderstanding, but ... On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: > > Existence of a variable means, among other things, that > > * You can use the value, with guaranteed effect (either unassigned exception > or you get a proper value) Surely by that definition any variable in any Python program "exists" -- you are guaranteed to get one of NameError, UnboundLocalError, or a value. That seems to argue away the meaning of the word entirely, and renders it not particularly useful. > > How the Python implementation implements that is an implementation detail. > > In short, how CPython does things is completely irrelevant to the language's semantics, so you're conflating things here. > As I'd understood the previous discussion, it is the CPython implementation that reserves local names and produces UnboundLocalErrors. The language semantics don't call for it, and another implementation might choose to handle function locals the same way as globals, through a namespace dictionary -- in which case the variable *wouldn't* exist in any way, shape, or form until it was assigned to. What am I getting wrong here? ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From j at junkwallah.org Mon Jul 12 18:32:27 2010 From: j at junkwallah.org (Junkman) Date: Mon, 12 Jul 2010 15:32:27 -0700 Subject: Python 3 grammar, function parameters Message-ID: <4C3B97FB.5010409@junkwallah.org> Greetings to Python users, I'm trying to parse Python code using the grammar supplied with the documentation set, and have a question on the grammar for function parameters: funcdef: 'def' NAME parameters ['->' test] ':' suite parameters: '(' [typedargslist] ')' typedargslist: ((tfpdef ['=' test] ',')* ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef) | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) tfpdef: NAME [':' test] >From what I understand, a naked asterisk - i.e. it is not a prefix to an identifier - is not a valid parameter, but the grammar explicitly allows it by making the identifier that immediately follows the asterisk optional. Are there cases where naked asterisk is allowed as a function parameter? If not, would it be correct for the grammar to specify the identifier trailing asterisk as mandatory? Thanks for any insight. Jay From alf.p.steinbach+usenet at gmail.com Mon Jul 12 18:55:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 00:55:59 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury, on 13.07.2010 00:14: > Perhaps I'm misunderstanding, but ... > > On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: >> >> Existence of a variable means, among other things, that >> >> * You can use the value, with guaranteed effect (either unassigned exception >> or you get a proper value) > > Surely by that definition any variable in any Python program "exists" -- you > are guaranteed to get one of NameError, UnboundLocalError, or a value. That > seems to argue away the meaning of the word entirely, and renders it not > particularly useful. No, you're conflating non-existence (NameError) with accessing the value of an existing but unassigned variable (UnboundLocalError). It is like arguing that vacuum is the same as cement because sticking your head into it for ten minutes or so yields an effect -- you're dead -- that in many ways is just about the same. However, the tangible existence of cement means that one can pour it over your head, /adding/ the cement, while it's difficult to pour vacuum over your head; rather, for the latter effect one would need to /remove/ the air around your head. OK, the analogy halts a little. But I think you'll get it. Similarly, you can add a variable and thereby cause am UnboundLocalError, and you can remove a variable and thereby cause a NameError. >> How the Python implementation implements that is an implementation detail. >> >> In short, how CPython does things is completely irrelevant to the language's > semantics, so you're conflating things here. >> > > As I'd understood the previous discussion, it is the CPython implementation > that reserves local names and produces UnboundLocalErrors. The language > semantics don't call for it, and another implementation might choose to handle > function locals the same way as globals, through a namespace dictionary -- in > which case the variable *wouldn't* exist in any way, shape, or form until it > was assigned to. > > What am I getting wrong here? The bit about the language semantics not specifying the effect. From the 3.1.1 language reference ?4.1: "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." And it goes on to elaborate on that, a little later: "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." In short, Stephen D'Aprano's remarks were technically on the spot, while Rhodri James's follow up, that it seems influenced your response, was meaningless mumbo-jumbo with strong emphasis added repeatedly to denials of reality. This is the usual reaction of the religious when exposed to reality. Cheers & hth., - Alf -- blog at From debatem1 at gmail.com Mon Jul 12 19:03:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 19:03:09 -0400 Subject: Help choosing license for new projects In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 6:00 PM, Jake b wrote: > I'm starting a new python code project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of licenses. So > I don't know which to use. Maybe MIT or Apache or LGPL or BSD? Fair warning: I like and use the GPL a lot, so I'm biased. Take my advice with a grain of salt and recognize that while everybody has some semi-rational basis for the license they choose, in the end the decision is likely to be made on dogmatic grounds. > Are there certain licenses to avoid using because of interaction > problems between libraries using GPL2 / GPL3 / MIT / LGPL. / BSD with > my own? Generally, GPL'd code likes GPL'd code and BSD/MIT etc are more free-form. Depending on what you leverage this may or may not be a problem for you. > I want: > 1] Pretty much let anyone use it. Users do not have to include source > code, as long as I get credit. (which I think normallly is a textfile > with project url + name?) GPL is pretty much out then. CC-BY-* may be the way to go. > 2] (if it matters) I will be using different combinations of pyglet, > pygame, wxPython, etc. Not going to dig through those to find the licenses for you. Be aware that their choices impact yours. > 3] I want the option to use my own code in something commercial at a later date. Not generally an issue. Even GPL lets you sell your stuff. > Does #3 complicate things, or is fine when including author info? If you have many contributors it can. > The choices for google code projects are: > ?Apache License 2.0 Good choice, not my flavor but it does preserve attribution. > ?Eclipse license 1.0 Small license, doesn't give you the same degree of legal muscle that some others will if it gets violated. > ?GPLv2 > ?GPLv3 Both out on the source-not-required part. Personally, I like them (and the Artistic License) for exactly that reason. > ?GNU lesser GPL Fewer restrictions on linking, etc, but probably not what I would recommend here. > ?MIT license Good choice, well understood and widely used. Note that attribution is not preserved, although copyright is. That may or may not be enough for you. > ?Mozilla Public license 1.1 I'd avoid it, same caveats for the eclipse license and few obvious advantages. > ?New BSD License Also a good choice, same caveat as the X11 license. Geremy Condra From ben+python at benfinney.id.au Mon Jul 12 19:28:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 13 Jul 2010 09:28:24 +1000 Subject: Help choosing license for new projects References: Message-ID: <87pqys9t5z.fsf@benfinney.id.au> Jake b writes: > I want: > 1] Pretty much let anyone use it. Users do not have to include source > code, as long as I get credit. (which I think normallly is a textfile > with project url + name?) The simplest effective license that requires nothing more that attribution is ?under the terms of the Expat license? . The terms are effectively the same as some of the MIT/X11 licenses, but: * It's even shorter and simpler, while still being widely regarded as effective. * The name ?Expat license? is far less ambiguous, because MIT have released X11 under several different licenses, not all of them free. > 2] (if it matters) I will be using different combinations of pyglet, > pygame, wxPython, etc. You'll need to check the license terms on anything that you combine your work with, to see what the effective combination of terms will be. > 3] I want the option to use my own code in something commercial at a > later date. All free software licenses are commercial licenses, by definition. Preventing selling the work, or other commercial use, would make the license terms non-free. So if you choose any free software license this isn't a problem. > Does #3 complicate things, or is fine when including author info? You may be wanting to talk about making the work non-free (proprietary), in which case you're on your own :-) -- \ ?My mind is incapable of conceiving such a thing as a soul. I | `\ may be in error, and man may have a soul; but I simply do not | _o__) believe it.? ?Thomas Edison | Ben Finney From luke.leighton at gmail.com Mon Jul 12 19:28:29 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Mon, 12 Jul 2010 23:28:29 +0000 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: >> for several reasons, i'm doing a cooperative multi-tasking HTTP >> server: >> ?git clone git://pyjs.org/git/multitaskhttpd.git >> >> there probably exist perfectly good web frameworks that are capable of >> doing this sort of thing: i feel certain that twisted is one of them. >> however, the original author of rtmplite decided to rip twisted out >> and to use multitask.py and i'm one of those strange people that also >> likes the idea of using 900 lines of awesome elegant code rather than >> tens of thousands of constantly-moving-target. > I may not be fully understanding what you're doing, but is there a > reason that one of the mixins can't be used? yes: they're threaded. or forking. this is *single-process* cooperative multitasking. but that's not quite an answer, i know. perhaps i should explain the three use-cases: 1) pyjamas-web. pyjamas-web was an experiment i did, last year, to port pyjamas http://pyjs.org to run the *exact* same app which normally is either compiled to javascript (to run in the web browser), or is run as a desktop app.... that *exact* same app i wanted to run it *server-side*. the reason for doing this is so that javascript would not be needed. remember that the apps _really_ look like GTK apps: RootPanel().add(HTML("Hello World") so there's a python application, and i re-implemented all of the widgets to add to an XML document (actually an eltree instance) and i tidied things up with BeautifulSoup, voila, splat, spew forth some HTML, output it from the web framework. i'd picked mod_python. did it work? why yes it did! right up until i had pressed refresh a few times, or pressed a few application "buttons". at that point, it all fell over, because, why? ****ing threads, that's why. HTTP is totally stateless. each mod_python thread is arbitrarily picked to run an incoming request. i had totally forgotten this, and had "associated" the pyjamas application instance with the python thread's local storage memory. oh... shit :) so, one person could be viewing an app, then next minute, someone else connects to the server, and they get the other person's app!! the only sane way round this, especially because if you want to serialise the data structures of the pyjamas app you might have to dump... what... 100k into a database or so (!!) and retrieve it, is to have a SINGLE PROCESS multitasking web server, where all the apps are stored in the SAME PROCESS. then, you can store the apps in a dictionary, and look them up by a session cookie identifier. problem is solved. 2) rtmplite itself rtmplite currently does RTMP only (port 1935). for the exact same reasons as 1) the real-time audio/video streams need to be passed across from client to client, and it needs to be done QUICKLY. passing A/V data across unix domain sockets or shared memory in a _portable_ fashion... does anyone _know_ how to do data sharing portably using python? i don't! i'd love to know! :) so to avoid the problem, easy: just design the app to be single-process, handling multiple RTMP clients simultaneously. now i would like to see rtmplite extended to support HTTP (RTMP can be proxied over HTTP and HTTPS). 3) persistent database connections with per-user credentials this is the _real_ reason why i'm doing this. the GNUmed team are looking to create a web version of GNUmed. however, their current system relies on postgresql "roles" for security. as a python-wxWidgets app, that's of course absolutely fine. but, for a _web_ app, it's not in the slightest bit fine, because _all_ web frameworks assume "global" database credentials. also, they're counting on the database connections being persistent. how in hell's name, when using a stateless protocol like HTTP, do you cross-associate *persistent* and multiple per-user database connections with a user's browser, when all the web frameworks out there only really do "global" single-username, single-password database logins?? and the answer is: by using a cooperative multitasking httpd, which adds a session cookie to each incoming connection, and uses that to create an in-memory "application instance" which will STAY in memory (of the single-process http server). in that in-memory application instance, you can do whatever you like: have a login form which takes user/pass as input, then uses that on the POST to create a database connection, and stores the resultant authenticated psycopg2 "pool" connection into the app instance. the app instance is always always looked up in the dictionary of app instances, using the cookie session id as a key, and thus, each browser will _always_ be directed at the correct app instance. i hate to think how this would be done using any of the standard MixIns. even if you wrote a special MixIn which did single-instance socket handling, you couldn't use it because the BaseHTTPHandler doesn't "cooperate", it has a while True loop on serving connections until they're closed. so, you could serve one HTTP 0.9 request and then another person, orrr you could serve one HTTP 1.0 or 1.1 request that WAS NOT SET TO "Connection: keep-alive" and then do another person... ... but if ever there was a keep-alive set, you would be FORCED to serve that one HTTP connection, blocking absolutely everyone else until they buggered off. ... but with multitaskhttpd, even the persistent HTTP connections are still cooperatively multi-tasking. so, yah, whilst you're reading a big file, or serving a big database query, you're hosed (and i think i have a way to deal with the big database query thing, but it's an optimisation so am leaving it for now [*]), but other than that, you're fine. so - yah. definitely something that i've not been able to find (and don't like twisted, even if it could do this). l. [*] the solution involves creating some threads, accessible using a global lock, which run the database queries. the threads could even be done using a Threaded TCPSocketServer, and in each thread, the handler instance has a persistent database connection. the sockets are there merely to notify the main process (the multitask app) of the fact that a particular database query operation has completed, by sending the unique ID of the thread down the socket. the main process (multitask app) can then hook a global lock, get at the list of threads, grab the one with the right ID, grab the SQL query results and then unhook the global lock. the reason for using sockets is because multitask can do cooperative multitasking on socket filehandles. by having a special task which yields on the Threaded TCPSocketServer connection, the main process can delay answering a particular HTTP request until the database response has been completed. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:34:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:34:18 GMT Subject: Easy questions from a python beginner References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3ba679$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote: > As I see it it doesn't matter whether the implementation is CPython call > frame slots or that mechanism called something else or a different > mechanism called the same or a different mechanism called something > different; what IMO matters is same semantics, that any assignment to a > variable within a routine serves as a compile time declaration, creating > that local variable in advance, unless, with Python 3.x., that name has > been declared as a 'global' or 'nonlocal'. > > So, this is a possible point of disagreement. > > I say the semantics of local variable creation are part of the language > definition, but I get the /impression/ that maybe you think it's > CPython-specific, that e.g. > > def foo(): > x > x = 0 > > might not raise an unassigned variable exception with some conforming > Python implementation, i.e. different effect for same code with > different implementations, that this is at least /unspecified behavior/ > in Python? Almost. I believe that "any assignment to a variable within a routine serves as a compile time declaration" is a promise of the language, but what an implementation does in response to that declaration is unspecified. So long as foo() raises NameError, or a subclass of it, it will be a conforming Python implementation. That's what Python 1.5 does, and I think if some competing implementation targeted 1.5 we'd still be happy to call it Python. (Although we might wonder about the author's sanity...) Implementations are free to subclass NameError, as CPython does with UnboundLocalError, but mustn't raise a completely unrelated error, or no error at all. E.g. I don't think it would be acceptable to implicitly create new names and bind them to some arbitrary default value. E.g. an implementation might do something like this: * when parsing the function, prior to compiling the byte-code, tag every name with a sigil representing whether it is local or non-local; * compile a single byte-code for name lookup; * when executing that instruction, if the name is tagged as a local, search only the local namespace, otherwise search the nonlocal, global and builtin namespaces; * when displaying names to the user (say, in tracebacks) suppress the sigil. Under this implementation, no variable actually exists until it is assigned to. This is equivalent to shifting the decision to use LOAD_FAST or LOAD_GLOBAL to runtime rather than compile time, so it would probably hurt performance rather than increase it, but it would still be a conforming implementation. But of course I'm not Guido, and he has the final word on what counts as acceptable behaviour. -- Steven From luke.leighton at gmail.com Mon Jul 12 19:48:03 2010 From: luke.leighton at gmail.com (lkcl) Date: Mon, 12 Jul 2010 16:48:03 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: <1fea3f6a-f504-4298-b052-d3dcc6a651e1@i31g2000yqm.googlegroups.com> On Jul 12, 9:52?pm, Gelonida wrote: > Hi lkcl, > > Do you have any documentation or overview for your project? git clone git://pyjs.org/git/multitaskhttpd.git i only started it today, but yes, there's a README. the primary reason it's being developed is because GNUmed are looking to create a web service but they want to use the same psycopg2-based middleware that's taken them pretty much forever to develop. see my reply to geremy condra for more details. if this turns out to be something that _really_ hasn't been done before, then i'm happy for other people to pitch in and help out. > Questions ?I would be interested in: > - List of features already working * simple HTTP GET of files and subdirs (because i blatantly copied SimpleHTTPServer.py) * JSONRPC services (i blatantly copied SimpleJSONRPCServer.py, it's something i found, it's based on SimpleXMLRPCService.py) > - list of features under development the time between "under development" and "in future" is so short it's hardly worthwhile stating. i added JSONRPC in about 90 minutes for example. tomorrow i'll add HTTP POST multi-part forms and it will take me about... 50 mins i should imagine, by looking at something like turbogears or django. i'm not going to "waste time reinventing" stuff when i can pretty much cut/paste it. web servers have been _done_ already - it's just that cooperative multitasking seems most definitely _not_ to have been done before. > - list of features being in in the near future * HTTP POST with multi-part forms (just like standard web frameworks) * a better API once i have a clearer idea of what's needed * use of regex matching on apps, just like django urls.py l. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:49:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:49:41 GMT Subject: Help choosing license for new projects References: Message-ID: <4c3baa15$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 17:00:22 -0500, Jake b wrote: > I'm starting a new python code project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of licenses. So I > don't know which to use. Maybe MIT or Apache or LGPL or BSD? http://www.dwheeler.com/essays/gpl-compatible.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:50:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:50:12 GMT Subject: Easy questions from a python beginner References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3baa34$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote: > Existence of a variable means, among other things, that > > * You can use the value, with guaranteed effect (either unassigned > exception > or you get a proper value): in particular, you won't be accessing a > global if you're using the name of a local declared by a later > assignment. That is too strong. Given the global code: x (where x doesn't exist in the global namespace, and therefore does not exist, as you agreed earlier) Python promises to raise NameError. By the above definition, this counts as "variable x exists". But surely that is undesirable -- that implies that *all* variables exist. Even $%@*@( is a variable that exists, as that is guaranteed to raise SyntaxError. -- Steven From alf.p.steinbach+usenet at gmail.com Mon Jul 12 20:06:39 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 02:06:39 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3baa34$0$28644$c3e8da3@news.astraweb.com> References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> <4c3baa34$0$28644$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 13.07.2010 01:50: > On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote: > >> Existence of a variable means, among other things, that >> >> * You can use the value, with guaranteed effect (either unassigned >> exception >> or you get a proper value): in particular, you won't be accessing a >> global if you're using the name of a local declared by a later >> assignment. > > That is too strong. Given the global code: > > x > > (where x doesn't exist in the global namespace, and therefore does not > exist, as you agreed earlier) Python promises to raise NameError. By the > above definition, this counts as "variable x exists". > > But surely that is undesirable -- that implies that *all* variables > exist. Even $%@*@( is a variable that exists, as that is guaranteed to > raise SyntaxError. Hm, I already answered someone else here committing that logic error. In one case an exception is generated by removing a variable. In the other case an exception is generated by adding a variable. Cheers & hth., - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Mon Jul 12 20:18:06 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 02:18:06 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3ba679$0$28644$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> <4c3ba679$0$28644$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 13.07.2010 01:34: > On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote: > >> As I see it it doesn't matter whether the implementation is CPython call >> frame slots or that mechanism called something else or a different >> mechanism called the same or a different mechanism called something >> different; what IMO matters is same semantics, that any assignment to a >> variable within a routine serves as a compile time declaration, creating >> that local variable in advance, unless, with Python 3.x., that name has >> been declared as a 'global' or 'nonlocal'. >> >> So, this is a possible point of disagreement. >> >> I say the semantics of local variable creation are part of the language >> definition, but I get the /impression/ that maybe you think it's >> CPython-specific, that e.g. >> >> def foo(): >> x >> x = 0 >> >> might not raise an unassigned variable exception with some conforming >> Python implementation, i.e. different effect for same code with >> different implementations, that this is at least /unspecified behavior/ >> in Python? > > Almost. > > I believe that "any assignment to a variable within a routine serves as a > compile time declaration" is a promise of the language, but what an > implementation does in response to that declaration is unspecified. So > long as foo() raises NameError, or a subclass of it, it will be a > conforming Python implementation. > > That's what Python 1.5 does, and I think if some competing implementation > targeted 1.5 we'd still be happy to call it Python. (Although we might > wonder about the author's sanity...) Implementations are free to subclass > NameError, as CPython does with UnboundLocalError, but mustn't raise a > completely unrelated error, or no error at all. E.g. I don't think it > would be acceptable to implicitly create new names and bind them to some > arbitrary default value. > > E.g. an implementation might do something like this: > > * when parsing the function, prior to compiling the byte-code, tag > every name with a sigil representing whether it is local or non-local; > * compile a single byte-code for name lookup; > * when executing that instruction, if the name is tagged as a local, > search only the local namespace, otherwise search the nonlocal, > global and builtin namespaces; > * when displaying names to the user (say, in tracebacks) suppress > the sigil. > > Under this implementation, no variable actually exists until it is > assigned to. > > This is equivalent to shifting the decision to use LOAD_FAST or > LOAD_GLOBAL to runtime rather than compile time, so it would probably > hurt performance rather than increase it, but it would still be a > conforming implementation. > > But of course I'm not Guido, and he has the final word on what counts as > acceptable behaviour. The 3.1.1 docs explicitly require UnboundLocalError (I just checked). So, at least for 3.x it is not an implementation detail. Anyway, your phrase "actually exist" presumably refers to storage allocation. That is an implementation detail. As a similar implementation scheme, a compiler can in certain cases detect that a variable is only assigned once, and substitute the value whereever that variable is used, not allocating any storage for it. This is the case in Python, in C++ and in almost any language. We don't start doubting the existence of variables in general (as some in the Python community do) on such grounds. More to the point of this sub-thread, it would be impossible to reason about things if one had to take into account the particular implementation's details at all times. Doing that renders most terms, including "exist", pretty meaningless and useless, since you would have to check whether each particular variable was optimized away or not: for the purpose of discussing existence in Python, what matters is portable effect. Summing up, how CPython implements the required semantics, is irrelevant. :-) Cheers from Norway, - Alf -- blog at From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 20:18:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 00:18:20 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 12:34:46 +0200, Jean-Michel Pichavant wrote: > Well, actually some people might think otherwise. While I disagree with > the OP flaming style, one could argue that muting an integer into a > boolean makes no sense (I'm one of them). You can still do it, but there > is no "right" way to do it. > You can decide that everything else than 0 is True, but you could also > pickup the integer 3 as false value, it would work as well since it > makes no sense. This is just an arbitrary definition. Choosing 3 as a false value would be arbitrary, but the choice of 0 is anything but arbitrary. The distinction that Python makes is between values which are Something (true values) and those which are Nothing (false values). Python has an infinite number of ways of spelling Something: True, 1, 2, 3.1415, "abc", (2, 4), [None, 1, "A"], ... and a smaller number of ways of spelling Nothing: False, None, 0, 0.0, "", (), [], ... The fact that False == 0 (as opposed to, say, [] != 0) is due to the need for backwards compatibility. That bools are implemented as a subclass of int is a historical accident. The fundamental distinction in Python is between objects which are Something and those that are Nothing, and that's not an arbitrary distinction, it's a very deep distinction. This is why virtually all low-level languages treat 0 as a false flag and 1 (or sometimes -1) as a true flag. I say "virtually all", not because I know of any exceptions, but because in the history of computer languages you can probably find every design mistake, arbitrary choice, and perverse decision imaginable made by *somebody*. Consider branch statements. Forth jumps to the "true" branch on any integer flag, and to the "false" branch on 0, but the canonical true value is either 1 (0000 00001 in binary) or -1 (1111 1111). Early versions of BASIC used -1 as true and 0 as false. With Pascal's strong type-checking, you were forced to use the boolean type in branches, but (if I recall correctly) the language guaranteed that false was 0 and true was 1: a packed array of bools would use a 0 bit for false and 1 for true, and an unpacked array would use eight zero bits versus seven zeroes and an one. So there's historical precedent from other languages, backwards compatibility with early Python versions, and a fundamental philosophical distinction all in favour of using 0 for false. Not arbitrary at all. > I prefere to explicitly write what I want to test: > > if myInt <> 0: I would argue against that. Why do you, the coder, care about the specific details of treating ints in a boolean context? The int type itself knows, leave the decision to it. Sure, in the specific case of ints, the distinction is so fundamental, so basic, and so unlikely to change, that there's no real harm in the explicit test. But consider some other type: if myValue.count <= 0 and myValue.next is None and myValue.blob == "": # myValue is considered false versus: if not myValue: Which would you prefer? I think the choice is obvious: the type knows whether it is equivalent to true or false, leave it up to the object to decide. Why bother making an exception for ints, or strings? -- Steven From rami.chowdhury at gmail.com Mon Jul 12 20:29:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 12 Jul 2010 17:29:33 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <2377A6A6-29B3-4395-8995-E17747A23AAE@gmail.com> On Jul 12, 2010, at 15:55 , Alf P. Steinbach /Usenet wrote: > * Rami Chowdhury, on 13.07.2010 00:14: >> Perhaps I'm misunderstanding, but ... >> >> On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: >>> >>> Existence of a variable means, among other things, that >>> >>> * You can use the value, with guaranteed effect (either unassigned exception >>> or you get a proper value) >> >> Surely by that definition any variable in any Python program "exists" -- you >> are guaranteed to get one of NameError, UnboundLocalError, or a value. That >> seems to argue away the meaning of the word entirely, and renders it not >> particularly useful. > > No, you're conflating non-existence (NameError) with accessing the value of an existing but unassigned variable (UnboundLocalError). It is like arguing that vacuum is the same as cement because sticking your head into it for ten minutes or so yields an effect -- you're dead -- that in many ways is just about the same. Right -- but you're playing with the definition of "existence" there, and since you're not using it quite consistently, I wasn't sure what you meant. Your discussion of the language reference below helps clear it up. > >>> How the Python implementation implements that is an implementation detail. >>> >>> In short, how CPython does things is completely irrelevant to the language's >> semantics, so you're conflating things here. >>> >> >> As I'd understood the previous discussion, it is the CPython implementation >> that reserves local names and produces UnboundLocalErrors. The language >> semantics don't call for it, and another implementation might choose to handle >> function locals the same way as globals, through a namespace dictionary -- in >> which case the variable *wouldn't* exist in any way, shape, or form until it >> was assigned to. >> >> What am I getting wrong here? > > The bit about the language semantics not specifying the effect. > > From the 3.1.1 language reference ?4.1: > > "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." > > And it goes on to elaborate on that, a little later: > > "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." Ah, interesting. Thank you for pointing that out -- I didn't know that. I notice the same paragraph is in the 2.7 reference, so it presumably holds for 2.x implementations as well. > This is the usual reaction of the religious when exposed to reality. > > Cheers & hth. It does, thank you. Although the repeated references to the "religious" and their "refusal to accept reality" are less than helpful. > > -- > blog at > -- > http://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Mon Jul 12 20:36:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 17:36:38 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <7xeif8fca1.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > This is why virtually all low-level languages treat 0 as a false ... OK, but is Python a low-level language, and if not, why are low-level languages appropriate examples to follow? >> if myInt <> 0: > > I would argue against that. Why do you, the coder, care about the > specific details of treating ints in a boolean context? The int type > itself knows, leave the decision to it. There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, which is automatically convert strings to numbers, so "12"+3 = 15. Python has the good sense to throw a type error if you attempt such an addition, but it goes and converts various types to bool automatically, which is more Perl-like than I really enjoy. In fact Python 3 added yet another automatic conversion, of int to float on division, so 1/2 = 0.5. Obviously it's a point in the design space where various decisions are possible, but I can get behind the "explicit is better than implicit" idea and say that none of those conversions should be automatic, and if 1/2 = 0 was confusing people in Python 2 enough to justify changing divison semantics in Python 3, the preferable change would be for int division to raise TypeError rather than quietly converting to float. The same thing goes for bool conversion, though we are all used to it by now, and it would be way too disruptive a change. > if myValue.count <= 0 and myValue.next is None and myValue.blob == "": > # myValue is considered false > versus: > if not myValue: > Which would you prefer? I'd personally prefer if not bool(myValue): which would call the myValue's __bool__ method if it chose to implement one. Explicit is better than implicit. From benjamin.kaplan at case.edu Mon Jul 12 20:45:22 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 12 Jul 2010 17:45:22 -0700 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 2:33 PM, Jia Hu wrote: > Thank you. It works now. > > ?if I use?'print' to print?the whole list, 'print'?will add newline > at the end of the list?but not each item in the list.? right? > > For the?code: > for line in fileName: > ??? line = line.rstrip('\n') > I think?this will affect 'fileName' because it assign the value to 'line' ? No it does not. Python assignments never modify anything other than the enclosing namespace. "for line in fileName" reads a line from the file and creates a string. That string resides in memory somewhere, who knows where. It does not reside inside fileName- it is a separate object. That string is then bound to the name "line" in the current namespace (the module's namespace in this case). Variables in Python are just entries in a dictionary. In fact, you can do globals()["line"] and it will return the string associated with that name. line.rstrip("\n") gets the object associated with the name "line" and accesses the object with the name "rstrip" that's associated with the object named "line". It then calls that object (in this case a builtin_function_or_method object) with the string "\n" as a parameter. rstrip then generates a new string. The line = (that new string that was just generated) associates the new string with the name "line". The old string hasn't changed at all (in fact, the object will get deleted almost immediately since it's reference count just dropped to 0). And the file hasn't changed either. > But when I print fileName, "\n" still exists at each item in the list. > > Because each line in?my?txt file are numeric values. is there any other > better way to get each > numerical value at each line? for example using numpy or changing?string > list to numerical list? > > Thank you for?help. > > On Mon, Jul 12, 2010 at 4:45 PM, Chris Rebert wrote: >> >> On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: >> > Hi, I just want to delete "\n" at each line. My?operating system?is >> > ubuntu >> > 9.1. The code is as follows >> > >> > #!/usr/bin/python >> > import string >> > fileName=open('Direct_Irr.txt', 'r') # read file >> > directIrr = fileName.readlines() >> > fileName.close() >> > for line in directIrr: >> > ?????? line.rstrip('\n') >> > print directIrr >> > >> > But I found there is still "\n" . Could someone help me why it is not >> > correct? >> >> .rstrip() returns a *new* string without trailing whitespace (which >> you are currently then throwing away); it does *not* modify string >> objects in-place. Python strings objects are entirely immutable and >> unmodifiable; all operations on them merely produce /new/ strings. >> >> Assuming you still want to use .readlines(), you'd do: >> directIrr = fileName.readlines() >> fileName.close() >> directIrr = [line.rstrip('\n') for line in directIrr] >> print directIrr >> >> For how third line works, google "python list comprehensions". >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From chantikotyada1 at gmail.com Mon Jul 12 20:56:41 2010 From: chantikotyada1 at gmail.com (Chantodu) Date: Mon, 12 Jul 2010 17:56:41 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <0aac4eda-71a7-4de0-8008-a3ef097112cc@n8g2000prh.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account. At http://ukcollegegirls.co.cc Due to high security risks, i have hidden the PayPal Form link in an image. in that website On search box Top Side, click on image and enter your PayPal id And Your name. please don,t tell to any One. From hujia06 at gmail.com Mon Jul 12 21:28:06 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 21:28:06 -0400 Subject: write a .txt file Message-ID: Hello: I have a problem about how to generate a specific.txt file. I use the following code: #!/usr/bin/python # OS: Ubuntu import subprocess fileName = open ('final.txt', 'a') fileName.write ('%s %s %s \n' % (12,25,9)) desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) fileName.seek(0,2) fileName.write ('%s %s %s \n' % (85,25,12)) fileName.close() The above code generates the following result: 12 25 9 85 25 12 hello What I want is: 12 25 9 hello 85 25 12 Could someone provies some suggestions about this problem? Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 12 21:28:28 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 19:28:28 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano wrote: >> I prefere to explicitly write what I want to test: >> >> if myInt <> 0: > > I would argue against that. Why do you, the coder, care about the > specific details of treating ints in a boolean context? The int type > itself knows, leave the decision to it. I think you're missing the point. He's not using ints in a boolean context. If it were a boolean context, he would be using bools in the first place. What he is objecting to is the practice of testing for special cases of ints (i.e. 0) by treating them as bools. The specific details of converting ints to bools are very much relevant here; as long as 0 is false, it works. If -1 is false (a semantic I have actually seen used), then it does not. Cheers, Ian From knny.myer at gmail.com Mon Jul 12 21:29:00 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Mon, 12 Jul 2010 18:29:00 -0700 (PDT) Subject: Check if a command is valid Message-ID: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Hello, I have to figure out if a string is callable on a Linux system. I'm actually doing this: def is_valid_command(command): retcode = 100 # initialize if command: retcode = subprocess.call(command, shell=True) if retcode is 0: print "Valid command." else: print "Looks not so good..." is_valid_command("ls") Never mind the code, because this is not the original. The side effect of subprocess.call() is that it *actually* executes it, but I just need the return code. What are better ways of doing this? From tim.wintle at teamrubber.com Mon Jul 12 21:30:38 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 13 Jul 2010 02:30:38 +0100 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: <1278984638.9880.46.camel@tim-laptop> On Mon, 2010-07-12 at 23:28 +0000, Luke Kenneth Casson Leighton wrote: > On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: > > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: > >> there probably exist perfectly good web frameworks that are capable of > >> doing this sort of thing: i feel certain that twisted is one of them. > >> however, the original author of rtmplite decided to rip twisted out > >> and to use multitask.py and i'm one of those strange people that also > >> likes the idea of using 900 lines of awesome elegant code rather than > >> tens of thousands of constantly-moving-target. have you seen nagare: http://www.nagare.org/ I've not used it - but from my understanding it might be what you're looking for (for the http part at least). > i hate to think how this would be done using any of the standard > MixIns. even if you wrote a special MixIn which did single-instance > socket handling, you couldn't use it because the BaseHTTPHandler > doesn't "cooperate", it has a while True loop on serving connections > until they're closed. I started working on something like this once (but I still had threads) - afraid I can't find the code with it in right now. I think it was similar to what you're doing: at least 2 threads - one accepts requests, the other deals with them. * overload BaseHTTPServer.process_request so it just adds connections to a queue. * worker threads fetch connections from the queue and starts working on them. when they want to give up control they raise an exception to bubble back up, and the connection is re-added to the queue along with any persistent data. I seem to remember the annoying bit being having to override SocketServer.finish_request to use an existing handler. - you can fairly easily limit that to process a single session at a time with a shared dictionary or similar. The reason I was doing it was for work that was cached for a short time, but took a while on cache misses - If I noticed that another thread was currently updating the cached version then I raised an exception. (I had code that unlocked the gil, so multi-threaded made sense) Tim From me+list/python at ixokai.io Mon Jul 12 21:36:32 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 12 Jul 2010 18:36:32 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <4C3BC320.5010200@ixokai.io> On 7/12/10 10:16 AM, John Nagle wrote: > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. That's downright frightening. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Mon Jul 12 21:41:06 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 19:41:06 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Jul 12, 2010 at 6:36 PM, Paul Rubin wrote: > There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, > which is automatically convert strings to numbers, so "12"+3 = 15. > Python has the good sense to throw a type error if you attempt such an > addition, but it goes and converts various types to bool automatically, > which is more Perl-like than I really enjoy. ?In fact Python 3 added yet > another automatic conversion, of int to float on division, so 1/2 = 0.5. > > Obviously it's a point in the design space where various decisions are > possible, but I can get behind the "explicit is better than implicit" > idea and say that none of those conversions should be automatic, and if > 1/2 = 0 was confusing people in Python 2 enough to justify changing > divison semantics in Python 3, the preferable change would be for int > division to raise TypeError rather than quietly converting to float. I don't think it's any more egregious than automatic conversions of mixed-type expressions, such as 3 + 4.5. If you don't want your ints automatically converted to floats on division, then use the integer division operator. 1 // 2 is still 0 in Python 3. Cheers, Ian From python at mrabarnett.plus.com Mon Jul 12 21:58:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jul 2010 02:58:31 +0100 Subject: write a .txt file In-Reply-To: References: Message-ID: <4C3BC847.4040606@mrabarnett.plus.com> Jia Hu wrote: > Hello: > > I have a problem about how to generate a specific.txt file. I use the > following code: > > #!/usr/bin/python > # OS: Ubuntu > import subprocess > fileName = open ('final.txt', 'a') > fileName.write ('%s %s %s \n' % (12,25,9)) > desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) > > fileName.seek(0,2) > fileName.write ('%s %s %s \n' % (85,25,12)) > fileName.close() > > The above code generates the following result: > 12 25 9 > 85 25 12 > hello > > What I want is: > 12 25 9 > hello > 85 25 12 > > Could someone provies some suggestions about this problem? > > Thank you. > When "echo" is called the file is still open, so the might not be able to write to it. Try closing the file before starting the subprocess and then reopen it afterwards. By the way, it slightly confusing that you call the variable "fileName", but it doesn't contain the name of a file! :-) From no.email at nospam.invalid Mon Jul 12 22:14:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 19:14:38 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <7xy6dg1629.fsf@ruckus.brouhaha.com> Ian Kelly writes: > I don't think it's any more egregious than automatic conversions of > mixed-type expressions, such as 3 + 4.5. That could also be explicit: float(3) + 4.5, or 3 + int(4.5). > If you don't want your ints automatically converted to floats on > division, then use the integer division operator. 1 // 2 is still 0 > in Python 3. Sure, I do that, but the issue was that 1/2 was confusing newbies who don't understand the different characteristics of int and floating types. If the idea is to change Python to fix this problem in a newbie-friendly way, the right fix is to create enlightment by raising an exception that points out the problem, not sweep it under the rug with an automatic conversion. From cs at zip.com.au Mon Jul 12 22:30:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 12:30:43 +1000 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <20100713023043.GA16776@cskk.homeip.net> On 12Jul2010 17:36, Paul Rubin wrote: | Steven D'Aprano writes: | > This is why virtually all low-level languages treat 0 as a false ... | | OK, but is Python a low-level language, Not particularly, but true/false and Boolean login are low level ideas. If it works well in a low level language (where all you might have are ints of various flavours and thus some equivalence notion is required), why would you _change_ the conventions in a high level language without a compelling reason? The more commonality in concepts there are, for all that they are just conventions, the easier it is remember how to do things. | and if not, why are low-level | languages appropriate examples to follow? They may not be in any inherent sense, but they are examples and if the usage doesn't cause pain are they inappropriate? Steven: | >> if myInt <> 0: | > | > I would argue against that. Why do you, the coder, care about the | > specific details of treating ints in a boolean context? The int type | > itself knows, leave the decision to it. [...snip...] This I'm only halfway with. I, the coder, _must_ know. The "if" statement has an intent, and I need to know that "if myInt:" matches my intent. Of course, using the right idioms it will match a lot of the time. But I've certainly been bitten by writing: if myDict: intending: if myDict is not None: but also getting: if myDict != {}: Clearly the fault was mine, but I, the coder, _must_ care about the details of using non-Booleans in a Boolean context. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is Texas law that when two trains meet each other at a railroad crossing, each shall come to a full stop, and neither shall proceed until the other has gone. From f2h2d2 at gmail.com Mon Jul 12 23:16:01 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Mon, 12 Jul 2010 20:16:01 -0700 (PDT) Subject: Must We Worship Message-ID: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> Must We Worship Whom Must We Worship The submission of man to His Creator is the essence of Islam. The name ?Islam? is chosen by God (Allah) and not by man. It is the same unifying Message revealed to all the Prophets and Messengers by Allah and which they spread amongst their respective nations. In its Final form it was revealed to Muhammad (Peace & Mercy of Allah be upon him) as a complete Message to whole mankind. The Lord, Allah, is the True and Only Creator that deserves to be worshipped. No worship is worthy of being given to a stone, statue, a cross, a triangle, Khomeini, Farakhan, Eliajahs, Malcom?s X or Y, Ghandi, Krishna, Guru, Buddha, Mahatma, Emperor, Joseph Smith, Sun, Moon (not to that from Korea too!), Light, Fire, rivers, cows, Rama, Temples, Prophets, Messengers (Yes! Muslims do not worship Muhammad-peace be upon him), Saints, Priests, Monks, Movie Stars, Sheiks, etc.!!! All are created beings or things. ALLAH, is the Name of the One True God. His Name is not chosen by man and does not have a number or gender. It is known that Allah is the Name of God in Aramaic, the language of our beloved Prophet Jesus and a sister language of Arabic. The Name ?Allah? has been used by all previous Prophets starting with Adam and by the last and final Prophet, Muhammad (Peace be upon them all). The Innate Nature in man recognizes what is good and bad, what is true and false. It recognizes that the Attributes of Allah must be True, Unique, and All-Perfect. It does not feel comfortable towards any kind of degradation of His Attributes not does it qualities to the Creator. Many who became ?discontent with God? did so because of the practices of the Church in medieval Europe and because of the claims of ?god dwelling in a son? and the concept of the ?original sin?. However, they ?escaped? into worshipping a new theory called ?mother nature? as well as the ?material? World. With the advancement of materialistic technology others from different religions adopted the concept of ?forgetting about God? and ?let us live this life and enjoy it!?, not realizing that they have chosen the worship of the ?original god? of Rome: Desire! .As a result the ?enjoyment? is turning to ?suffering? from AIDS. NOW we can see that all of this materialistic and secular progress produced a spiritual vacuum that led to complex social, economical, political, and psychological problems. Many of those who ?fled? their ?religions? are in search again. Some try to ?escape? the complexity of their daily lives via various means. Those who had the chance to examine the Qur?an and Islam, proceed with a complete way of life that relates man to establish a purpose for his presence on earth. This is well recognized in the Attributes of Allah and what does He require from man. He does not want man to be enslaved to any false deity: nature, drugs, lust, money, other man, desire, or sex. He provides man with the proofs that He is the One who can redeem so that man can free himself from the slavery to any form of creation and to turn to his Creator Alone. THIS Creator Has Perfect Attributes. He is the First, nothing is before Him, the Ever Living. To Him is the Final Return where everyone will be dealt with in the Most Perfect and Just way. He does not begot nor He is begotten. Those who attribute Divinity to Jesus forget or ignore the fact that Jesus was in a mother?s womb. He needed nutrition; he was born and grew up to be a man. He was trusted with the Gospel as a Message to the Children of Israel: ?For there is One God, and one mediator (i.e. a messenger) between God and men (the Children of Israel), the man Christ Jesus) (I Timothy 2:5). A man- messenger calling his nation not to worship him: ?But in vain they do worship me!? (Mathew 15:9). A man who needs to eat, walk, sleed, rest, etc.. cannot have Divine Attributes because he is in need and God (Allah) is Self-Sufficient. AS far as Buddhism, Hinduism, Zoroastrianism, Marxism, and Capitalism, there is the devotion of worshipping created being/things in one form or another. Jews had attributed a ?Nationalistic? belonging to Allah. They labeled Him ?The Tribal God? for the Children of Israel. Men and women following these ?religions? were born with the natural inclination of submission to their Creator, Allah. It is their parents who had driven them into their respective traditions. However, once people are exposed to the Signs of Allah around them, or in the Qur?an or to someone who triggers their Fitra (natural inclination to worship Allah Alone), the reverting process begins and that is why we see a universal spreading of Islam. In the West and despite tha many distortions of Islam in the Media, many admit that Islam may be the fastest growing Faith. No sense of fairness can be achieved without a genuine attempt to know the Word of Allah in the Qur?an and not on the 30-min-Evening News. This is the real challenge for those who seek the Truth. Man is created for a purpose: to live a life in accordance with Allah?s way. Why Not? Do we posses the air we breath? Did we create ourselves or others? Or were we ourselves the Creators? We are limited and weak. So is our right to ignore our Creator where we all need Him? ISLAM is the submission in worship to Allah Alone and it is the essence of all the Messages sent to all nations before us. Allah is All-Just and All-Wise. He does not intend confusion for His Creation. The religion accepted to Him is the one chosen by Him. Its essence must be One, because He is One. It is free from geographical, racist, and status oriented concepts. It is Perfect and it is the complete way of life. All these qualities are chosen by Allah in His Only Religion: Islam. Its details are in in the Qur?an, read it and come with an open heart because none can expose better than the World of Allah. The Qur?an was revealed to Prophet Muhammad. He did not author it. He was unlettered. Its translation is available in many languages in bookstores or in an Islamic Center close to you. Take the time to read it and come/call the Islamic Center, or speak to someone who re-verted and submitted to Allah Alone. The Decision is yours! From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:16:31 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:16:31 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote: > On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano > wrote: >>> I prefere to explicitly write what I want to test: >>> >>> if myInt <> 0: >> >> I would argue against that. Why do you, the coder, care about the >> specific details of treating ints in a boolean context? The int type >> itself knows, leave the decision to it. > > I think you're missing the point. He's not using ints in a boolean > context. If it were a boolean context, he would be using bools in the > first place. Of course he is -- he's branching on an int (a boolean context), and explicitly writing out the test as myInt <> 0. In fact, that test could just as easily be written as bool(myInt), which has the benefit of being even more explicit that you want a bool. It's also silly. Explicitness is not always a virtue. Beginners sometimes write things like: s = "hello " t = "world" print str(s + t) and we rightly shake our heads at the sheer n00b-ness of it. Writing the explicit tests: if bool(myInt): or even: if myInt <> 0: are firmly in the same category. The only difference is that it is more familiar and therefore comfortable to those who are used to languages that don't have Python's truth-testing rules. > What he is objecting to is the practice of testing for > special cases of ints (i.e. 0) by treating them as bools. The specific > details of converting ints to bools are very much relevant here; as long > as 0 is false, it works. If -1 is false (a semantic I have actually > seen used), then it does not. You've seen -1 being used as false? Where? Are you still talking about Python builtins or language semantics? If you're about to say string.find(substring), no, absolutely not. find does not return a true/false flag, it returns an index, with -1 the sentinel for Not Found. This is not a flag! In fact, one of the motivations for adding bools to Python was to avoid people mistakenly thinking that cmp(a, b) returned a flag 0, 1 when it actually returns a three-state -1, 0, 1. This was a common source of errors before Python got bools. -- Steven From ckaynor at zindagigames.com Mon Jul 12 23:16:47 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 12 Jul 2010 20:16:47 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xy6dg1629.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <7xy6dg1629.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Jul 12, 2010 at 7:14 PM, Paul Rubin wrote: > Ian Kelly writes: > > I don't think it's any more egregious than automatic conversions of > > mixed-type expressions, such as 3 + 4.5. > > That could also be explicit: float(3) + 4.5, or 3 + int(4.5). > > > If you don't want your ints automatically converted to floats on > > division, then use the integer division operator. 1 // 2 is still 0 > > in Python 3. > > Sure, I do that, but the issue was that 1/2 was confusing newbies who > don't understand the different characteristics of int and floating > types. If the idea is to change Python to fix this problem in a > newbie-friendly way, the right fix is to create enlightment by raising > an exception that points out the problem, not sweep it under the rug > with an automatic conversion. > Behind this automatic conversion is the concept that there is really one type: Number. The fact that the language has both int and float is merely as there is no good, solid way of storing the Number type, and thus we have float, Decimal, Rational, and probably other less common types. Calculating 1/2 does not give you 0, 1/10 won't give you 0.100000001 (or whatever the number stored in float is). The fact that integers and real numbers are separate in the language is an optimization and intended to improve functionality while providing a simple default (you can choose to use Decimal instead of float if you know you will be dealing with decimal numbers). Chris > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Mon Jul 12 23:22:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 20:22:39 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <7xy6dg83r4.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Writing the explicit tests: > if bool(myInt): > or even: > if myInt <> 0: > > are firmly in the same category. The only difference is that it is more > familiar and therefore comfortable to those who are used to languages > that don't have Python's truth-testing rules. It's like list.append returning None. It helps catch errors. From clp2 at rebertia.com Mon Jul 12 23:50:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 20:50:10 -0700 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 6:29 PM, Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm "callable" seems vague. Is a command string with invalid arguments but a valid executable "callable"? If no, then there's no general way to test "callability" without actually running the command. > actually doing this: > > ? ?def is_valid_command(command): > ? ? ? ?retcode = 100 # initialize > ? ? ? ?if command: > ? ? ? ? ? ?retcode = subprocess.call(command, shell=True) > ? ? ? ?if retcode is 0: That should be `== 0`, not `is 0`. The fact that `is 0` just so happens to work is an implementation detail. > ? ? ? ? ? ?print "Valid command." > ? ? ? ?else: > ? ? ? ? ? ?print "Looks not so good..." > > ? ?is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. Well, you're not gonna be able to get the command's return code without actually running it (unless perhaps you're referring to a return code from the shell itself?). > What are better ways of doing this? One idea: from shlex import split as shell_tokenize from subprocess import check_output def is_valid_command(command): try: executable = shell_tokenize(command)[0] except (ValueError, IndexError):# invalid shell syntax return False return bool(check_output(['which', executable]))# on the PATH? Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:51:06 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:51:06 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 17:36:38 -0700, Paul Rubin wrote: >> I would argue against that. Why do you, the coder, care about the >> specific details of treating ints in a boolean context? The int type >> itself knows, leave the decision to it. > > There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, > which is automatically convert strings to numbers, so "12"+3 = 15. > Python has the good sense to throw a type error if you attempt such an > addition, but it goes and converts various types to bool automatically, No, what Python does is more subtle than that. An example using strings will (I hope!) make it clear. Or possibly muddy the waters even more. Compare converting strings to ints: the string "1" maps to the int 1, "2" to 2, and so forth. There's a one-to-one map of string to int (modulo unicode and whitespace issues), and since this is more or less a universal standard, it's enshrined in the language. Now consider converting strings to bools. Should "true" map to True? Or "yes", "ja", "vrai", "waar", or something else? That's an application- specific question, not a universal standard (not even a de facto standard), and Python rightly avoids it. What about "maybe" or "strawberry jam"? You can't convert "strawberry jam" into True or False any more than you can convert it into an int. What Python does instead is to accept *any* object in a context where other languages (such as Pascal) would insist on a boolean. In practice, that means branches (if) as well as the short-cut operators and, or, not. The semantics of this is well-defined, and I trust I don't need to go over it again. In an expression like: x and y unlike Pascal, there is no requirement that x and y be booleans. This is why I talk about x and y being used "in a boolean context", rather than converting it to a bool. [3,4,5] is not, by any stretch of the imagination, True converted into a list, and likewise [2,3,4] is a list and can't be converted to a flag any more than it can be converted to an int. But what I do say is that, according to Python's semantics, the list [3,4,5] is equivalent to True in a boolean context. Where Python muddies the water is to provide a bool() built-in which *does* convert any object to canonical boolean form. bool([2,3,4]) returns True, which contradicts what I said above about not converting the list into a flag. I accept this -- it's a triumph of practicality over purity. It would be silly to force people to write: # get the canonical form if any_old_object: flag = True else: flag = False when we can say flag = bool(any_old_object). One last thing -- we can see that Python does *not* convert objects to bools "in a boolean context". The Python virtual machine really does accept any object as an argument to and/or/not operators, as well as if: >>> import dis >>> dis.dis(compile('a or b', '', 'single')) 1 0 LOAD_NAME 0 (a) 3 JUMP_IF_TRUE 4 (to 10) 6 POP_TOP 7 LOAD_NAME 1 (b) >> 10 PRINT_EXPR 11 LOAD_CONST 0 (None) 14 RETURN_VALUE The JUMP_IF_TRUE opcode accepts any object, not just True or False. -- Steven From ian.g.kelly at gmail.com Mon Jul 12 23:54:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 21:54:14 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 9:16 PM, Steven D'Aprano wrote: > You've seen -1 being used as false? Where? Are you still talking about > Python builtins or language semantics? Some of our database tables at work use 1 for true, -1 for false, and 0 for neither. Don't look at me, I didn't design it. Why they didn't just make the column nullable is beyond me, but that's the way it is. From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:55:43 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:55:43 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> <7xy6dg83r4.fsf@ruckus.brouhaha.com> Message-ID: <4c3be3bf$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:22:39 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Writing the explicit tests: >> if bool(myInt): >> or even: >> if myInt <> 0: >> >> are firmly in the same category. The only difference is that it is more >> familiar and therefore comfortable to those who are used to languages >> that don't have Python's truth-testing rules. > > It's like list.append returning None. It helps catch errors. How? >>> myInt = 'x' >>> if myInt <> 0: ... print "myInt is not zero, safe to divide" ... print 42/myInt ... myInt is not zero, safe to divide Traceback (most recent call last): File "", line 3, in TypeError: unsupported operand type(s) for /: 'int' and 'str' What error did this catch? -- Steven From no.email at nospam.invalid Mon Jul 12 23:58:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 20:58:39 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> Message-ID: <7x39voc9sg.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > What Python does instead is to accept *any* object in a context where > other languages (such as Pascal) would insist on a boolean. I'm aware of what Python does, just saying I can sympathize with the sentiment that explicit conversions would make more sense. I wouldn't change it in Python since it's what we're all used to, but if I were designing a language from scratch I'd probably make it explicit. From clp2 at rebertia.com Tue Jul 13 00:04:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 21:04:42 -0700 Subject: Python 3 grammar, function parameters In-Reply-To: <4C3B97FB.5010409@junkwallah.org> References: <4C3B97FB.5010409@junkwallah.org> Message-ID: On Mon, Jul 12, 2010 at 3:32 PM, Junkman wrote: > Greetings to Python users, > > I'm trying to parse Python code using the grammar supplied with the > documentation set, and have a question on the grammar for function > parameters: > > funcdef: 'def' NAME parameters ['->' test] ':' suite > parameters: '(' [typedargslist] ')' > typedargslist: ((tfpdef ['=' test] ',')* > ? ? ? ? ? ? ? ?('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] > | '**' tfpdef) > ? ? ? ? ? ? ? ?| tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) > tfpdef: NAME [':' test] > > >From what I understand, a naked asterisk - i.e. it is not a prefix to an > identifier - is not a valid parameter, but the grammar ?explicitly > allows it by making the ?identifier that immediately follows the > asterisk optional. > > Are there cases where naked asterisk is allowed as a function > parameter? Yes, for keyword-only arguments, a new feature in Python 3.x. See PEP 3102 (http://www.python.org/dev/peps/pep-3102/ ). A lone asterisk signals that the function does not take extra positional arguments. All keyword-only arguments must be declared after a lone or normal *-argument. Example: def compare(a, b, *, key=None): compare() does not accept extra positional arguments and has 1 keyword-only argument (namely, `key`). Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Tue Jul 13 00:47:16 2010 From: cmpython at gmail.com (CM) Date: Mon, 12 Jul 2010 21:47:16 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <67f1310d-493a-49b4-9d97-76bf58e223c3@e5g2000yqn.googlegroups.com> > > ? ? ?Yesterday, I was running a CNC plasma cutter that's controlled > > by Windows XP. ?This is a machine that moves around a plasma torch that > > cuts thick steel plate. ?A "New Java update is available" window > > popped up while I was working. ?Not good. > > Hi, it looks like you're attempting to cut something > with a plasma torch. ?Would you like help? > > (_) inserting a steel plate to cut > > (_) severing the tip of your finger > > [ ] Don't show me this tip again. > > -tkc Brilliant. (I almost think you should have gone with far more than severing the tip of the finger, but then you'd lose that killer play on words at the end). From mahyd2011 at gmail.com Tue Jul 13 00:51:34 2010 From: mahyd2011 at gmail.com (mbbabu) Date: Mon, 12 Jul 2010 21:51:34 -0700 (PDT) Subject: See Hot Sexy Star Angelina Jolie Nude Bathing Videos In All Angles. Message-ID: See Hot Sexy Star Angelina Jolie Nude Bathing Videos In All Angles. At http://easypaypalmoney.tk Due to high sex content, i have hidden the videos in an image. I Link in that website On search box Top Side, click on image and watch videos in all angles. please don,t tell to anyone. From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 00:52:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 04:52:58 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> <7x39voc9sg.fsf@ruckus.brouhaha.com> Message-ID: <4c3bf12a$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:58:39 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> What Python does instead is to accept *any* object in a context where >> other languages (such as Pascal) would insist on a boolean. > > I'm aware of what Python does, just saying I can sympathize with the > sentiment that explicit conversions would make more sense. I wouldn't > change it in Python since it's what we're all used to, but if I were > designing a language from scratch I'd probably make it explicit. Fair enough, and that's a reasonable design choice too. Ruby, for example, only has two false values: False and Null. -- Steven From torriem at gmail.com Tue Jul 13 01:28:26 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Jul 2010 23:28:26 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <4C3BF97A.3080207@gmail.com> On 07/12/2010 06:18 PM, Steven D'Aprano wrote: > Early versions of BASIC used -1 as true and 0 as false. They did this for good reason. BASIC had no logical operators. AND, OR, and NOT were all actually bitwise operators. By making the True value -1, the bitwise operations yielded the result one would expect from logical operations. From kkaruppuraja at gmail.com Tue Jul 13 01:29:36 2010 From: kkaruppuraja at gmail.com (sivaji) Date: Mon, 12 Jul 2010 22:29:36 -0700 (PDT) Subject: if you choose this bag you will ged a loptop Message-ID: <5d440858-0bf5-4884-b9d0-65bb83db65a4@s17g2000prh.googlegroups.com> http;//www.123maza.com/elaxa/domain-hosting From torriem at gmail.com Tue Jul 13 01:31:45 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Jul 2010 23:31:45 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <4C3BFA41.5060109@gmail.com> On 07/12/2010 06:36 PM, Paul Rubin wrote: > I'd personally prefer > > if not bool(myValue): > > which would call the myValue's __bool__ method if it chose to implement > one. Explicit is better than implicit. That's just ugly. Probably a more explicit way would be to have an is_true() and is_false() function/method. if is_false(my_value). But that's ugly too, especially when the idea of emptiness or falseness is so consistently defined across python types. I have yet to encounter any situation where I got tripped up on such a small thing as the OP. From DierkErdmann at mail.com Tue Jul 13 01:50:43 2010 From: DierkErdmann at mail.com (DierkErdmann at mail.com) Date: Mon, 12 Jul 2010 22:50:43 -0700 (PDT) Subject: Debugging a segmentation fault References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: <8aeab75c-19c3-4721-a2f1-a5304d85c23f@j4g2000yqh.googlegroups.com> On 8 Jul., 19:32, Christian Heimes wrote: > Which third party products with C extensions do you use? Have you > updated your database adapter and NumPy yet? I'm using sqlalchemy, scipy and numpy. I will try to update these and see if that helps. Dierk From hujia06 at gmail.com Tue Jul 13 01:51:49 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 01:51:49 -0400 Subject: write a .txt file In-Reply-To: References: <4C3BC847.4040606@mrabarnett.plus.com> Message-ID: If I change "'echo "hello">> final.txt" to "ls -a >> final.txt" and add fileName.close() before subprocess. The result is still like: 12 25 9 85 25 12 .... # list of files ..... How can I put the list before the number list 85 25 12? Thank you. On Tue, Jul 13, 2010 at 12:47 AM, Jia Hu wrote: > Thank you. I will try that. > > The code was simplified to show my problem. I do not use fileName as > a variable in my code. Thanks for your reminding. > > On Mon, Jul 12, 2010 at 9:58 PM, MRAB wrote: > >> Jia Hu wrote: >> >>> Hello: >>> I have a problem about how to generate a specific.txt file. I use the >>> following code: >>> #!/usr/bin/python >>> # OS: Ubuntu >>> import subprocess >>> fileName = open ('final.txt', 'a') >>> fileName.write ('%s %s %s \n' % (12,25,9)) >>> desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) >>> >>> fileName.seek(0,2) >>> fileName.write ('%s %s %s \n' % (85,25,12)) >>> fileName.close() >>> The above code generates the following result: >>> 12 25 9 >>> 85 25 12 >>> hello >>> What I want is: >>> 12 25 9 >>> hello >>> 85 25 12 >>> Could someone provies some suggestions about this problem? >>> Thank you. >>> >>> When "echo" is called the file is still open, so the might not be able >> to write to it. Try closing the file before starting the subprocess and >> then reopen it afterwards. >> >> By the way, it slightly confusing that you call the variable "fileName", >> but it doesn't contain the name of a file! :-) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Jul 13 02:15:27 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 12 Jul 2010 23:15:27 -0700 Subject: Errno 9] Bad file descriptor References: Message-ID: <3v0o369u3toutqpt1e3j0klq2jvs3kfna1@4ax.com> joblack wrote: > >I get sometimes a > >Errno 9 Bad file descriptor > >the code is too long to show it here but what are the circumstances >this could happen? A web search showed nothing. > >I have especially the feeling Python 2.6 has some problems with >Unicode ... and might not find the file. Is that possible? You seem to be under the mistaken impression that we all have crystal balls and are able to read your mind. There is SO MUCH you haven't told us here. Which platform? Surely you can post SOME of the code around where the error occurs. For example, there is a bug in the Windows shell that will cause this error if you try to read stdin when a Python script is called implicitly from a command line: C:\tmp>type y.py import sys print sys.stdin.readlines() C:\tmp>y.py < y.py Traceback (most recent call last): File "C:\tmp\y.py", line 3, in print sys.stdin.readlines() IOError: [Errno 9] Bad file descriptor C:\tmp>python y.py < y.py ['import sys\n', '\n', 'print sys.stdin.readlines()\n'] C:\tmp> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cs at zip.com.au Tue Jul 13 02:16:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 16:16:29 +1000 Subject: write a .txt file In-Reply-To: References: Message-ID: <20100713061629.GA14142@cskk.homeip.net> On 12Jul2010 21:28, Jia Hu wrote: | I have a problem about how to generate a specific.txt file. I use the | following code: | | #!/usr/bin/python | # OS: Ubuntu | import subprocess | fileName = open ('final.txt', 'a') | fileName.write ('%s %s %s \n' % (12,25,9)) String still in Python's buffer, not yet in the file. Add: fileName.flush() to ensure data in file before running echo. | desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) Command dispatched, but not yet waited for. So your Python program proceeds and writes to the file _before_ the echo command gets to run. Wait for desLrr to complete before proceeding. | fileName.seek(0,2) | fileName.write ('%s %s %s \n' % (85,25,12)) | fileName.close() And the rest is ok. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ We tend to overestimate the short-term impact of technological change and underestimate its long-term impact. - Amara's Law From timr at probo.com Tue Jul 13 02:18:48 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 12 Jul 2010 23:18:48 -0700 Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: Kenny Meyer wrote: > >I have to figure out if a string is callable on a Linux system. I'm >actually doing this: >... >Never mind the code, because this is not the original. >The side effect of subprocess.call() is that it *actually* executes >it, but I just need the return code. What are better ways of doing >this? You can do what the "which" command does: split the PATH environment variable into individual components, and see if the string maps to a file in any directory in your PATH with the "execute" bit set. That won't catch shell macros, however. You might be able to use "type" to do that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From chenlily84 at hotmail.com Tue Jul 13 02:30:42 2010 From: chenlily84 at hotmail.com (cntrade08) Date: Mon, 12 Jul 2010 23:30:42 -0700 (PDT) Subject: Discount Wholesale Kanji Jeans, ED Hardy Jeans (http://www.cntrade09.com/) Message-ID: <59f06967-a15a-400c-983e-3f52052ef9e4@z34g2000pro.googlegroups.com> Discount Wholesale Affliction Jeans Discount Wholesale AK Jeans (http://www.cntrade09.com/) Discount Wholesale Armani Jeans Discount Wholesale Artful Dodger Jeans Discount Wholesale BAPE Jeans Discount Wholesale BBC Jeans (http://www.cntrade09.com/) Discount Wholesale Black Label Jeans Discount Wholesale Cavalli Jeans Discount Wholesale Christian Audigier Jeans Discount Wholesale Coogi Jeans Discount Wholesale Crown Holder Jeans (http://www.cntrade09.com/) Discount Wholesale D&G Jeans Discount Wholesale Diesel Jeans Discount Wholesale ECKO Jeans (http://www.cntrade09.com/) Discount Wholesale ED Hardy Jeans Discount Wholesale Evisu Jeans Discount Wholesale G-STAR Jeans Discount Wholesale GUCCI Jeans Discount Wholesale Iceberg Jeans Discount Wholesale Kanji Jeans (http://www.cntrade09.com/) Discount Wholesale Laguna Beach Jeans Discount Wholesale Levi s Jeans Discount Wholesale LRG Jeans Discount Wholesale LV Jeans Discount Wholesale Prada Jeans (http://www.cntrade09.com/) Discount Wholesale RMC Jeans Discount Wholesale Roca Wear Jeans Discount Wholesale Rock&Republic Jeans Discount Wholesale True Religion Jeans Discount Wholesale Versace Jeans Discount Wholesale ZEN Jeans (http://www.cntrade09.com/) From stefan_ml at behnel.de Tue Jul 13 02:37:12 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 13 Jul 2010 08:37:12 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: sturlamolden, 04.07.2010 05:30: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... In case anyone's interested, I uploaded a wrapper for LuaJIT2 to PyPI: http://pypi.python.org/pypi/lupa It's written in Cython and heavily borrows from the existing Lua wrapper LunaticPython, with a couple of enhancements and a couple of yet missing features. Stefan From hujia06 at gmail.com Tue Jul 13 02:46:14 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 02:46:14 -0400 Subject: write a .txt file In-Reply-To: References: <20100713061629.GA14142@cskk.homeip.net> Message-ID: Hi: Do you mean the following code? #!/usr/bin/python # OS: Ubuntu import subprocess fileName = open ('final.txt', 'a') fileName.write ('%s %s %s \n' % (12,25,9)) fileName.flush() # add fileName.close() # add desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to "ls -a" fileName=open ('final.txt', 'a') fileName.seek(0,2) fileName.write ('%s %s %s \n' % (85,25,12)) fileName.close() I run that, the result showed the list of file is located after the number list 85 25 12 Is that possible that I put the fileName.flush() in a wrong position ? I am new to Python and do not quite understand the "flush" concept. Thank you. Jia > On Tue, Jul 13, 2010 at 2:16 AM, Cameron Simpson wrote: > >> On 12Jul2010 21:28, Jia Hu wrote: >> | I have a problem about how to generate a specific.txt file. I use the >> | following code: >> | >> | #!/usr/bin/python >> | # OS: Ubuntu >> | import subprocess >> | fileName = open ('final.txt', 'a') >> | fileName.write ('%s %s %s \n' % (12,25,9)) >> >> String still in Python's buffer, not yet in the file. Add: >> >> fileName.flush() >> >> to ensure data in file before running echo. >> >> | desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) >> >> Command dispatched, but not yet waited for. So your Python program >> proceeds >> and writes to the file _before_ the echo command gets to run. >> >> Wait for desLrr to complete before proceeding. >> >> | fileName.seek(0,2) >> | fileName.write ('%s %s %s \n' % (85,25,12)) >> | fileName.close() >> >> And the rest is ok. >> >> Cheers, >> -- >> Cameron Simpson DoD#743 >> http://www.cskk.ezoshosting.com/cs/ >> >> We tend to overestimate the short-term impact of technological change and >> underestimate its long-term impact. - Amara's Law >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Jul 13 02:59:41 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 16:59:41 +1000 Subject: Errno 9] Bad file descriptor In-Reply-To: References: Message-ID: <20100713065941.GA20959@cskk.homeip.net> On 11Jul2010 17:48, joblack wrote: | I get sometimes a | | Errno 9 Bad file descriptor | | the code is too long to show it here but what are the circumstances | this could happen? A web search showed nothing. | | I have especially the feeling Python 2.6 has some problems with | Unicode ... and might not find the file. Is that possible? You get a UNIX "bad file descriptor" error when you try to use an invalid file descriptor number. The typical occasion is when you open a file, use it, close it, and then try to continue to use it. I would suspect you have performed that sequence in some way. But you should really try to produce a small sequence of code that shows the error. That way you can post it here, and for extra value you may reduce it to the point where you realise what you have done wrong, since the failing code is then small enough for you to examine easily. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There is a chasm of carbon and silicon the software can't bridge - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html From cs at zip.com.au Tue Jul 13 03:17:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 17:17:06 +1000 Subject: write a .txt file In-Reply-To: References: Message-ID: <20100713071705.GA22054@cskk.homeip.net> On 13Jul2010 02:46, Jia Hu wrote: | Hi: | | Do you mean the following code? | | #!/usr/bin/python | # OS: Ubuntu | import subprocess | fileName = open ('final.txt', 'a') | fileName.write ('%s %s %s \n' % (12,25,9)) | | fileName.flush() # add | fileName.close() # add You should not need the .close(). | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to "ls | -a" You're still not waiting for the Popen subprocess to finish before continuing. | fileName=open ('final.txt', 'a') You shouldn't need the open() if you skip the .close() | fileName.seek(0,2) If you _do_ do an open(..., "a") then you don't need the seek - append mode will write at the end for you. | fileName.write ('%s %s %s \n' % (85,25,12)) | fileName.close() | | I run that, the result showed the list of file is located after the number | list 85 25 12 | Is that possible that I put the fileName.flush() in a wrong position ? | I am new to Python and do not quite understand the "flush" concept. First: please don't top post. Post below the relevant points as I do above, like a conversation. That way it is clear exactly what each remark is for. Second: "flush" is a general idea used with buffers. When you .write() to a file the data does not normally go directly to disc. This is because a real write to the disc is expensive in time (the CPU is much much faster than a hard drive). Also, a OS-level "write", which transfers the data from your program into the OS's buffers (where it queues, for eventual writing to the disc) is _also_ a comparitively expensive operation. So when you .write() in python (or C using stdio, and in many other languages) the data is normally kept in a memory buffer inside your program. Only when that buffer is filled is an OS-level "write" done. In this way, OS calls are few. This is a performance gain. So, in your program, when you .write() your first line of numbers the data has not been handed to the OS at all, and therefore the "final.txt" file has not seen it. A .flush() call is an explicit request to empty the buffer, making an OS-level "write" immediately. In your program, this is necessary to get the data to "final.txt" before the "echo" or "ls" commands are run. If you .close() a file, that also empties the buffer. But it also closes the file! SO you need to re-open it. For your purposes, a .flush() is enough and leaves the file open for you to continue using it later. Regarding the .seek(): after the "echo" or "ls" command has run the file has grown. Python's "file" object does not know the file has grown because it was not involved. So a .seek(0 is needed to position Python's .write() location to the end of the file instead of where it though things were. Um. Because you have opened the file in 'a' mode you should not need the .seek() - an "append" mode file will always write to the end of the file. So: your first problem only requires a .flush(), to empty the buffer before "echo" or "ls" runs. However, you still have not waited for the "echo" or "ls" to finish - Popen kicks the command off, but it will run at the same time as your program! Call: desLrr.wait() to wait for the "echo" or "ls" to finish before continuing! Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Quick Guide to Resources to break crypto systems of given strength: Difficulty Resources required 2**0 Pencil and paper 2**8 Pencil and paper and a lot of patience 2**16 Warez d00d with a Commodore 64 2**32 Amateur with an average PC 2**40 Smart amateur with a good PC 2**56 Network of workstations, custom-built hardware 2**64 Thousands of PCs working together for several years 2**80 NSA, Microsoft, the Illuminati 2**128 Cubic kilometers of sci-fi nanotech 2**160 Dyson spheres Eddy L O Jansson and Matthew Skala, from: http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html From j.kleese at arcor.de Tue Jul 13 03:28:01 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Tue, 13 Jul 2010 09:28:01 +0200 Subject: Worship We Must In-Reply-To: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> Message-ID: <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> On 13.07.2010 05:16, nais-saudi wrote: > The submission of man to His Creator is the essence of Islam. The submission of topic-related Bla to His Newsgroup is the essence of Posting. Learn it. Know it. Live it. From alf.p.steinbach+usenet at gmail.com Tue Jul 13 03:34:08 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 09:34:08 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: * geremy condra, on 09.07.2010 23:43: > On Fri, Jul 9, 2010 at 5:22 PM, Ian Collins wrote: >> On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >>> >>> [Cross-posted comp.lang.python and comp.lang.c++] >>> >>> I lack experience with shared libraries in *nix and so I need to ask... >>> >>> This is about "cppy", some support for writing Python extensions in C++ >>> that I just started on (some days ago almost known as "pynis" (not funny >>> after all)). >>> >>> For an extension module it seems that Python requires each routine to be >>> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >>> "C"' and C++ linkage, using a routine declared as 'static' in a class as >>> a C callback, formally they're two different kinds, and I seem to recall >>> that /some/ C++ compiler balks at that kind of mixing unless specially >>> instructed to allow it. Perhaps it was the Sun compiler? >> >> Yes, it will (correctly) issue a warning. >> >> As the is a bit OT, contact me directly and we can work through it. I have >> had similar fun and games adding PHP modules! > > I'd appreciate it if you'd either leave this on-list or cc me in on this, as > I'm working through a similar issue. Well, we got no further, but I know of three solutions: A) Punting: just say that the compiler has to support C++/C function type mingling. -> Perhaps the practical solution, but formally unsafe. B) On the script side of things, delegate all calls to single Mother Of All C func downcaller that supplies as extra arg an id of the C++ function. -> Micro-level inefficient but easy to use and formally correct. C) Let the user define the C linkage function wrappers via macros. -> Efficient and formally correct but exposes ugly macro names. I chose (C). I believe Boost's Python binding uses (A), or perhaps (B). Cheers, - Alf PS: You (the reader) may be wondering, why why why Yet Another Python/C++ binding? Well, because I had this great name for it, "pyni", unfortunately already in use. But cppy is very different from Boost: Boost is large, cppy is tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating argument conversion etc., while with cppy your Python design is exposed to C++ with no enforced arg conversions and such; Boost relies on canned magic, difficult to subvert when it doesn't do what you want, while with cppy you are (or, so far, I am) in control; and I suspect that the Boost Python binding, relying on dynamic registries and stuff, is not all that efficient, while cppy is as efficient as using the Python C API to create an extension. And besides, cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) -- blog at From debatem1 at gmail.com Tue Jul 13 04:00:38 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 01:00:38 -0700 Subject: Worship We Must In-Reply-To: <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: > On 13.07.2010 05:16, nais-saudi wrote: >> The submission of man to His Creator is the essence of Islam. > > The submission of topic-related Bla to His Newsgroup is the essence of > Posting. > > Learn it. Know it. Live it. The submission of replies to trolls and spammers is the essence of the internet. Live long. And Prosper. Geremy Condra From pdwjfndjbdgfyg at gmail.com Tue Jul 13 04:08:29 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Tue, 13 Jul 2010 01:08:29 -0700 (PDT) Subject: SEXY VIDEOS Message-ID: HOT SEXY VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-sexy-videos.html HOT KISS VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-kiss-videos.html HOT ROMANTIC VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-romantic-videos.html HOT LIP KISS BEST VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-lip-kiss-best-videos.html jobs java jobs http://allfreshersjobsseehere.blogspot.com/2009/02/java-jobs.html oracle jobs http://allfreshersjobsseehere.blogspot.com/2009/02/oracle-jobs.html work from home http://allfreshersjobsseehere.blogspot.com/2009/02/work-from-home.html make money from online http://allfreshersjobsseehere.blogspot.com/2009/02/make-money-from-online.html online work http://allfreshersjobsseehere.blogspot.com/2009/02/online-work.html From j.kleese at arcor.de Tue Jul 13 04:17:26 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Tue, 13 Jul 2010 10:17:26 +0200 Subject: Worship We Must In-Reply-To: References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> On 13.07.2010 10:00, geremy condra wrote: > On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: >> On 13.07.2010 05:16, nais-saudi wrote: >>> The submission of man to His Creator is the essence of Islam. >> >> The submission of topic-related Bla to His Newsgroup is the essence of >> Posting. >> >> Learn it. Know it. Live it. > > The submission of replies to trolls and spammers is the essence of the internet. > > Live long. And Prosper. The submission of troll feed to the Internet is the essence of Bla. Now do the truffle shuffle! From debatem1 at gmail.com Tue Jul 13 04:32:42 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 01:32:42 -0700 Subject: Worship We Must In-Reply-To: <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, Jul 13, 2010 at 1:17 AM, Johannes Kleese wrote: > On 13.07.2010 10:00, geremy condra wrote: >> On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: >>> On 13.07.2010 05:16, nais-saudi wrote: >>>> The submission of man to His Creator is the essence of Islam. >>> >>> The submission of topic-related Bla to His Newsgroup is the essence of >>> Posting. >>> >>> Learn it. Know it. Live it. >> >> The submission of replies to trolls and spammers is the essence of the internet. >> >> Live long. And Prosper. > > The submission of troll feed to the Internet is the essence of Bla. > > Now do the truffle shuffle! I'm sure you're aware that the shuffle of so-called 'conflict truffles' is highly illegal, not to mention unethical. I'm shocked you would advocate it publicly. Geremy Condra From gdamjan at gmail.com Tue Jul 13 05:21:06 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jul 2010 11:21:06 +0200 Subject: simples setup for an wsgi https server in python References: Message-ID: <2pntg7-ve7.ln1@archaeopteryx.softver.org.mk> > It seems, that wsgiref.simple_server.make_server can only create an > http server. > > What I wondered would be how to easiest create an https server, that > supports wsgi modules PythonPaste has a WSGI server that supports https http://pythonpaste.org/modules/httpserver.html#module-paste.httpserver Werkzeug too http://werkzeug.pocoo.org/documentation/0.6.2/serving.html#ssl I'd strongly suggest you to have both of those libraries installed, they have a lot of WSGI goodies :) -- ?????? ((( http://damjan.softver.org.mk/ ))) Scarlett Johansson: You always see the glass half-empty. Woody Allen: No. I see the glass half-full... but of poison. From greg.ewing at canterbury.ac.nz Tue Jul 13 07:22:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 13 Jul 2010 23:22:42 +1200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4c3b7102$0$1587$742ec2ed@news.sonic.net> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> <4c3b7102$0$1587$742ec2ed@news.sonic.net> Message-ID: <8a302tF2qdU1@mid.individual.net> John Nagle wrote: > Arguably, if a function just does a "return", > it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exception if you try to do anything with it except throw it away. Unfortunately, the existence of such a value would cause headaches for things like debuggers that need to be able to deal with anything at all without blowing up. -- Greg From jeanmichel at sequans.com Tue Jul 13 07:24:11 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Jul 2010 13:24:11 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <4C3C4CDB.40904@sequans.com> Steven D'Aprano wrote: > On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote: > > >> On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano >> wrote: >> >>>> I prefere to explicitly write what I want to test: >>>> >>>> if myInt <> 0: >>>> >>> I would argue against that. Why do you, the coder, care about the >>> specific details of treating ints in a boolean context? The int type >>> itself knows, leave the decision to it. >>> >> I think you're missing the point. He's not using ints in a boolean >> context. If it were a boolean context, he would be using bools in the >> first place. >> > > Of course he is -- he's branching on an int (a boolean context), and > explicitly writing out the test as myInt <> 0. In fact, that test could > just as easily be written as bool(myInt), which has the benefit of being > even more explicit that you want a bool. I never use integers as boolean value. There is no need to in python, since True and False are available. I use integers only as integers (hope you see what i mean, i.e to count a number of...). Knowing that, the only meaning possible would be if myInt: equals to if myInt is not None: in other words, if myInt is a meaningful integer. But this is wrong in python, as "if myInt" means "if myInt <>None and myInt <>0" (I experienced bug because of my wrong understanding). Fine I can live with that. It forces me to write explicitly the condition I require, which is a good thing (explicit >> implicit). JM PS : you made a typo, myInt <> 0 does not equal to bool(myInt) (when myInt is None) From sathish at solitontech.com Tue Jul 13 07:25:33 2010 From: sathish at solitontech.com (Sathish S) Date: Tue, 13 Jul 2010 16:55:33 +0530 Subject: Calling LabVIEW VI from Python Message-ID: Hi ppl, I'm trying to call the LabVIEW VI's from python. I'm trying to use the Call method exposed in the LabVIEW activex. this method expects the input values to be passed as an array of reference. I'm passing a list to it, and I find that the list is unchanged. Here is my code: import win32com.client from win32com.client import gencache gencache.EnsureModule('{8C8AAA4D-51FE-41DE-85CF-8E6929409012}', 0, 5, 5) Application = win32com.client.Dispatch("LabVIEW.Application") InputNames = ("Cluster","Array","Numeric","Output") Cluster=("abcd","1") Array=("1","2.97") Output=() Inputs= (Cluster,Array,"5",Output) Application._FlagAsMethod("GetVIReference") VirtualInstrument = Application.GetVIReference('C:\Test.vi'); VirtualInstrument._FlagAsMethod("OpenFrontPanel") VirtualInstrument.OpenFrontPanel(True,3) VirtualInstrument._FlagAsMethod("Call") VirtualInstrument.Call(InputNames,Inputs) print(Output) print("Output") VirtualInstrument._FlagAsMethod("GetControlValue") print(VirtualInstrument.GetControlValue("Output")) Application._FlagAsMethod("Quit") Application.Quit(); Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 13 07:33:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Jul 2010 13:33:05 +0200 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <4C3C4EF1.3080609@sequans.com> Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? > I'm not sure I get exactly what you're searching for but here's something that may help. If you just whant to know if a command (without parameter) is a Linux command (either a builtin, alias of file exe) you can use the "where" command and inspect its return code, the command is not executed though. >where ls ls is an alias for ls --color=auto -F ls is /bin/ls >where apt-get apt-get is /usr/bin/apt-get >where doesnotexists doesnotexists not found zsh: exit 1 retcode = subprocess.call(command, shell=True) becomes retcode = subprocess.call("where " + command) JM NB : this does not work with parameters appened to the command. From luke.leighton at gmail.com Tue Jul 13 08:00:57 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Tue, 13 Jul 2010 12:00:57 +0000 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <1278984638.9880.46.camel@tim-laptop> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> <1278984638.9880.46.camel@tim-laptop> Message-ID: On Tue, Jul 13, 2010 at 1:30 AM, Tim Wintle wrote: > On Mon, 2010-07-12 at 23:28 +0000, Luke Kenneth Casson Leighton wrote: >> On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: >> > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: >> >> there probably exist perfectly good web frameworks that are capable of >> >> doing this sort of thing: i feel certain that twisted is one of them. >> >> however, the original author of rtmplite decided to rip twisted out >> >> and to use multitask.py and i'm one of those strange people that also >> >> likes the idea of using 900 lines of awesome elegant code rather than >> >> tens of thousands of constantly-moving-target. > > have you seen nagare: > http://www.nagare.org/ i have now! :) it uses stackless python, which is proobbably where the nonblocking aspects come from. going from there... http://stacklessexamples.googlecode.com/svn/trunk/examples/networking/basicWebserver.py ah ha! on the face of it, that does actually look like it achieves the same sort of thing. > I've not used it - but from my understanding it might be what you're > looking for (for the http part at least). yes, for the http part: the rest - mmm no. >> i hate to think how this would be done using any of the standard >> MixIns. ?even if you wrote a special MixIn which did single-instance >> socket handling, you couldn't use it because the BaseHTTPHandler >> doesn't "cooperate", it has a while True loop on serving connections >> until they're closed. > > I started working on something like this once (but I still had threads) > - afraid I can't find the code with it in right now. I think it was > similar to what you're doing: > > at least 2 threads - one accepts requests, the other deals with them. ok, that sounds like the problem has moved: requests could still be received rather than blocked at the TCP level, but they'd still not actually get processed if the 2nd "dealing with it" thread was in "serve_forever()" mode. and because of HTTP Keep-Alives, when close_connection=1 in the HTTPRequestHandler base class, that would still be an issue. looking at that stackless basic web server example, i believe that that's actually it: the concept of "tasklets", and that cooperative scheduling loop: while time.time() < t + delay: stackless.schedule() multitask.py effectively does the same thing, but using "yield", which is just amazing. but... not being funny or anything, but basically i'm done already :) multitaskhttpd works, it doesn't need stackless, i completed a JSONRPC service last night, i'll add POST of multi-part forms today, and i have everything that [GNUmed] will need. i think convincing the gnumed team to get all their users to install and use stackless python would be a bit of a hard sell. l. From __peter__ at web.de Tue Jul 13 08:02:38 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Jul 2010 14:02:38 +0200 Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: Joe Hughes wrote: > I'm doing some work with logging.config and I'm running into an > interesting situation. I've run this by python-help, but that didn't help > so I thought I would send to the list. Here is the config file > > [loggers] > keys=root,log,syslog > > [handlers] > keys=console,log,syslog > > [formatters] > keys=rootFormat,logFormat,syslogFormat > > [logger_root] > level=DEBUG > handlers=console > > [logger_log] > level=DEBUG > handlers=log > qualname=log > > [logger_syslog] > level=DEBUG > handlers=syslog > qualname=syslog > > [handler_console] > class=StreamHandler > level=DEBUG > formatter=rootFormat > args=(sys.stdout,) > > [handler_log] > class=handlers.RotatingFileHandler > level=DEBUG > formatter=logFormat > args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) > propagate=0 > > [handler_syslog] > class=handlers.SysLogHandler > level=DEBUG > formatter=syslogFormat > host=141.232.41.205 > port=handlers.SYSLOG_UDP_PORT > facility=LOG_LOCAL0 > args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) > > [formatter_rootFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > [formatter_logFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > [formatter_syslogFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > and the python code > > ######################################################################## > # Imports > ######################################################################## > import logging > import logging.config > import os > import re > from threading import Thread > > ######################################################################## > # Constants > ######################################################################## > CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' > MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' > > ######################################################################## > # Classes > ######################################################################## > > ######## > # PingIt > ######## > class PingIt(Thread): > def __init__(self, mcuIP): > Thread.__init__(self) > self.ip = mcuIP > self.status = -1 > > def run(self): > pinging = os.popen("ping -n 2 " + self.ip, 'r') > > while 1: > line = pinging.readline() > > if not line: > break > > gotResponse = re.findall(PingIt.lifeline, line) > > if gotResponse: > self.status = int(gotResponse[0]) > > ######################################################################## > # Main Routine > ######################################################################## > # > # Get the logger configuration information > # > logging.config.fileConfig(CONFIG_FILENAME) > > # > # Check if running from command line and create logger > # > if os.environ.get('PROMPT'): > # > # create logger for output to stdout > # > logger = logging.getLogger('root') > else: > # > # create logger for output to logfile > # > logger = logging.getLogger('log') > > # > # Create logger for syslog output > # > syslog = logging.getLogger('syslog') > > # > # Declare variables > # > PingIt.lifeline = re.compile(r"Received = (\d)") > mcu_dict = {} > ping_list = [] > status = ("Not responding", "Responded to only 1 ping of 2", "Alive") > > # > # Open the MCU file > # > mcu_file = open(MCU_LIST_FILENAME, 'r') > > # > # Loop through the contents of the MCU file and ping the IPs > # > for mcu in mcu_file: > # > # mcu file contents example > # 192.168.97.227 MCU_HMSTD > # > # mcu_info[0] = MCU IP Address > # mcu_info[1] = MCU Name > # > mcu_info = mcu.split() > mcu_dict[mcu_info[0]] = mcu_info[1] > current = PingIt(mcu_info[0]) > logger.info("Pinging " + mcu_info[1]) > ping_list.append(current) > current.start() > > # > # Loop through ping list and print the response > # > for pinged in ping_list: > pinged.join() > logger.info("Status - " + mcu_dict[pinged.ip] + " is " + > status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + > " is " + status[pinged.status]) > > This is the output from the code > > 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding > msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is > Not responding > address = ('141.232.41.205', 514) > Traceback (most recent call last): > File "C:\Python31\lib\logging\handlers.py", line 786, in emit > self.socket.sendto(msg, self.address) > TypeError: sendto() takes exactly 3 arguments (2 given) > 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not > responding > > This is the handlers.py code from the library. I added the print > statement to figure out why it is asking for three args but only getting > two. > > Line 777 of handlers.py > > try: > if self.unixsocket: > try: > self.socket.send(msg) > except socket.error: > self._connect_unixsocket(self.address) > self.socket.send(msg) > else: > print('msg = ', msg, '\naddress = ', self.address) > self.socket.sendto(msg, self.address) > except (KeyboardInterrupt, SystemExit): > raise > except: > self.handleError(record) > > line 790 of handlers.py > > This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea > about why this happening I would appreciate knowing what the issue is. The error can be reproduced with Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> from logging.handlers import SysLogHandler >>> handler = SysLogHandler() >>> logger = logging.getLogger() >>> logger.addHandler(handler) >>> logger.critical("yadda") Traceback (most recent call last): File "/usr/lib/python3.1/logging/handlers.py", line 785, in emit self.socket.sendto(msg, self.address) TypeError: sendto() takes exactly 3 arguments (2 given) This is is a known bug, see http://bugs.python.org/issue7077 Peter From e_d_k at yahoo.com Tue Jul 13 08:03:00 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Tue, 13 Jul 2010 05:03:00 -0700 (PDT) Subject: Help choosing license for new projects In-Reply-To: Message-ID: <410241.60269.qm@web120511.mail.ne1.yahoo.com> --- On Mon, 7/12/10, Jake b wrote: > I'm starting a new python code > project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of > licenses. So > I don't know which to use. Maybe MIT or Apache or LGPL or > BSD? > > Are there certain licenses to avoid using because of > interaction > problems between libraries using GPL2 / GPL3 / MIT / LGPL. > / BSD with > my own? I generally avoid GPL, one of the reasons in interaction with other licenses. > > I want: > 1] Pretty much let anyone use it. Users do not have to > include source > code, as long as I get credit. (which I think normallly is > a textfile > with project url + name?) This rules out GPL. > > 2] (if it matters) I will be using different combinations > of pyglet, > pygame, wxPython, etc. You will need to look at the individual licenses to see is they have iterations with other licenses. > > 3] I want the option to use my own code in something > commercial at a later date. > > Does #3 complicate things, or is fine when including author > info? You can always re-license i, as long as you have the copyright to all the code. If other people have made contributions you will need to get their permission before you can re-license. > > The choices for google code projects are: > ? Apache License 2.0 I do not use it, but it is good. > ? Eclipse license 1.0 I have not read this one, so I can not comment. > ? GPLv2 > ? GPLv3 Incomparable with point one. > ? GNU lesser GPL You would need to decide whether this is comparable with your first requirement. LGPL requires that users be able to relink with new versions of the library. This has always bothered me because relinking without recompiling (even when dynamic linking) in C/C++ is a good way to crash a program. But this should not be a problem with Python. > ? MIT license This one is good. > ? Mozilla Public license 1.1 I avoid this one. > ? New BSD License This one is good. I personalty like the Boost License, it has very few restrictions. I hope this helps, -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From johannes.black at gmail.com Tue Jul 13 08:56:51 2010 From: johannes.black at gmail.com (joblack) Date: Tue, 13 Jul 2010 05:56:51 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: Thanks for the answers so far. It's not my code I'm just curious how that could happen: Starting point: ... self.status['text'] = 'Processing ...' try: cli_main(argv) except Exception, e: self.status['text'] = 'Error: ' + str(e) return ... cli_main: keypath, inpath, outpath = argv[1:] ... with open(inpath, 'rb') as inf: serializer = PDFSerializer(inf, keypath) with open(outpath, 'wb') as outf: filenr = outf.fileno() serializer.dump(outf) return 0 PDFSerializer.dump: def dump(self, outf): self.outf = outf ... From clp2 at rebertia.com Tue Jul 13 10:12:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jul 2010 07:12:41 -0700 Subject: Check if a command is valid In-Reply-To: <4C3C4EF1.3080609@sequans.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> Message-ID: On Tue, Jul 13, 2010 at 4:33 AM, Jean-Michel Pichavant wrote: > Kenny Meyer wrote: >> I have to figure out if a string is callable on a Linux system. I'm >> actually doing this: >> >> ? ?def is_valid_command(command): >> ? ? ? ?retcode = 100 # initialize >> ? ? ? ?if command: >> ? ? ? ? ? ?retcode = subprocess.call(command, shell=True) >> ? ? ? ?if retcode is 0: >> ? ? ? ? ? ?print "Valid command." >> ? ? ? ?else: >> ? ? ? ? ? ?print "Looks not so good..." >> >> ? ?is_valid_command("ls") >> >> Never mind the code, because this is not the original. >> The side effect of subprocess.call() is that it *actually* executes >> it, but I just need the return code. What are better ways of doing >> this? >> > > I'm not sure I get exactly what you're searching for but here's something > that may help. > > If you just whant to know if a command (without parameter) is a Linux > command (either a builtin, alias of file exe) you can use the "where" > command and inspect its return code, the command is not executed though. > >>where ls > ls is an alias for ls --color=auto -F > ls is /bin/ls >>where apt-get > apt-get is /usr/bin/apt-get >>where doesnotexists > doesnotexists not found > zsh: exit 1 `where` seems to be a zsh built-in: $ # I'm in UR bash $ nonexistent -bash: nonexistent: command not found $ where bash -bash: where: command not found And not everyone has zsh installed, so... I don't see why one shouldn't use the standard `which` *nix command instead. Also, in retrospect, my suggestion should probably have checked the return code rather than the output; more efficient and simple that way. Cheers, Chris -- http://blog.rebertia.com From jonathan.lee.975 at gmail.com Tue Jul 13 10:41:51 2010 From: jonathan.lee.975 at gmail.com (Jonathan Lee) Date: Tue, 13 Jul 2010 07:41:51 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: Message-ID: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> > Problem (C) is outside the realm of the C++ standard, since the C++ standard > doesn't support shared libraries, and I've never actually used *nix shared > libraries so I don't /know/... > > Is such dynamic initialization guaranteed? > Not guaranteed, though I think there's a combination of dlopen options and gcc command line parameters that invoke this behavior. See the second page of http://www.linuxjournal.com/article/3687 about auto-registration. Personally, though, it never worked for me :/ --Jonathan From astan.chee at al.com.au Tue Jul 13 11:15:04 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 14 Jul 2010 01:15:04 +1000 Subject: executing python scripts within wx frames Message-ID: <4C3C82F8.5060402@al.com.au> Hi, I'm trying to make one of those frames thats similar to the wx python demo where a folder is filled with demo wx python scripts and there is one main script that opens the other ones in as different items in a tree/notebook. I've gotten most of it figured out except the part where the scripts are executed in a wx frame. The difference between what I'm trying to do and the wx python demo one is that mine are generic scripts that output the results to std out/error (or whatever gets displayed in IDLE). Does anyone know how I can do this? Simulate a IDLE or python shell in one of the frames thats basically the output of whatever script has been selected to run? It would be better if the solution was platform independent too. Thanks for any suggestions From robert.kern at gmail.com Tue Jul 13 11:16:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Jul 2010 10:16:07 -0500 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote: > PS: You (the reader) may be wondering, why why why Yet Another Python/C++ > binding? Well, because I had this great name for it, "pyni", unfortunately > already in use. But cppy is very different from Boost: Boost is large, cppy is > tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating > argument conversion etc., while with cppy your Python design is exposed to C++ > with no enforced arg conversions and such; Boost relies on canned magic, > difficult to subvert when it doesn't do what you want, while with cppy you are > (or, so far, I am) in control; and I suspect that the Boost Python binding, > relying on dynamic registries and stuff, is not all that efficient, while cppy > is as efficient as using the Python C API to create an extension. And besides, > cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) Note that Boost is not the only C++ binding out there. You may want to take a look at the old SCXX library, which appears to be similar in intent: http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html matplotlib uses it heavily, and their included copy may include some more recent bugfixes and enhancements: http://matplotlib.sourceforge.net/ -- 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 Tue Jul 13 11:18:13 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Jul 2010 15:18:13 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c3a5c77$0$28647$c3e8da3@news.astraweb.com> Message-ID: <8a3edlFlrjU4@mid.individual.net> On 2010-07-12, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote: > >> On Jul 11, 3:03??am, "G??nther Dietrich" wrote: >> >>> So, it is not a disadvantage that the functions you listed above are >>> named in this way. In the contrary, it is an advantage, as it keeps >>> newcomers from using stupid variable names. >> >> "int" for an Integer is stupid? >> "list" for a List is stupid? >> "str" for a String is stupid? >> >> What am i missing? > > If you're going to use generic names, why type three or four letters when > one will do? > > i, j, k, m, n, p, q for ints. > L, a, b, x for lists > s, t, a, b for strings. > > If you don't want to use generic names, then int, list, str are useless > because they don't mean anything. You need something like: > > count_of_widgets > list_of_widgets > description def map(function, list): # etc. It's a slight annoyance, nothing more. In the data I deal with, I get annoyed at needing to write student_id instead of id, but it's not a huge issue. The big consolation is that Python really doesn't care if I happen to shadow a builtin name that I've never heard of. I forget, and use id as a variable all the time, and nothing bad happens to me, because I don't need the builtin function. To see a really odd example of a similar name clash, create a tab separated values file with a header line starting with ID (I get lots of them in my work), and then open it with Excel (I don't know which version has the most bizarre error message). -- Neil Cerutti From luismgz at gmail.com Tue Jul 13 11:38:59 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 13 Jul 2010 08:38:59 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: On Jul 4, 6:09?pm, Stephen Hansen wrote: > On 7/4/10 9:21 AM, sturlamolden wrote: > > > On 4 Jul, 14:29, David Cournapeau wrote: > > >> Actually, I think the main reason why Lua is much faster than other > >> dynamic languages is its size. The language is small. You don't list, > >> dict, tuples, etc... > > > They have managed to combine list and dict into one type (table) that > > does the job of both. > > You say "managed" as if it were some technical accomplishment, or that > the result is able to actually do the job of both: neither of these > assertions are true. > > Have you actually *used* Lua? I quite like the language in certain > contexts where its appropriate, but if you've actually used it in real > code and found tables to be at all a substitute for *either* > dictionaries *or* lists, then I think somehow you've managed to actually > miss using either data structure in Python to any real extent, somehow. > > Lua's tables are at very weak "dictionary-like" and "list-like" objects, > which indeed have been folded into one. To the detriment of both, at > least as far as they are an actual useful data structure. > > You can't even get the equivalent of len(dict) in it: you have to > actually brute-force iterate the table and count manually. Even for a > purely array-like table with onlyn umbered indexes, #table can be > unreliable: its quite possible through normal list-like operations that > you perform on it, it can end up with holes where #table will fail. > Since it is *not* an list internally at *all*, but simply an associative > array with numbered indexes. > > I could go on, and on, and on: but the fundamental *weakness* of Lua' > data types as data-structures is irrefutable, from its tables to strings > to numbers: they are incredibly weak on capabilities. You end up writing > all kinds of "library" functions to just do the normal things that > should be really easy to do. > > Now, of course, there's really good reason why Lua is so simple in these > ways. Its entirely suitable for Lua as an embedded scripting language to > keep things very light, so it can be simple and fast. Good for Lua to > fill this niche superbly. But you can't start saying its simple > alternatives are at all comparable to Python's extremely rich and > capable data types. > > > And yes there are tuples. > > No, there isn't. There's ways to create a tuple-like-thing which kind of > behaves like a braindead tuple, and functions have a positively bizarre > capability of returning more then one value (and accepting variable > values), so there's these points in the language where you have this > sort of Immutable Sequence, but its opaque until you unwrap it -- and > then it ceases to be. > > That's not the same thing as having an immutable sequence that you can > store data in at your discretion, with a rich series of capabilities > that you can leverage. > > > There are no classes, but there are closures and other building blocks > > that can be used to create any object-oriented type system > > Not really. > > Above, I spoke of tables as data structures, things just storing data. > But you're right, they are capable of more then that-- but you're > over-selling just how far that capability goes, by a long shot (and > underselling just how much work it takes to get it there). > > Yes, tables have a limited series of 'hooks' that you can tie into to > alter their behavior, and through this you can simulate certain higher > order type systems as defined in other languages. In fact, lots of > people have done this: there's multiple "classy" libraries out there to > bring some kind of Class-or-Object-Oriented-Programming to Lua. > > They work to varying degrees: but the hooks that Lua provides to tables > is still significantly lacking to really replace Python's > comprehensively dynamic object model, without a LOT of wasted cycles. > > For example, while you can use __newindex to 'catch' someone setting a > new 'key' on a table, and and __index to replace or forward the actual > lookup, you can't actually capture someone trying to set a value to a > key which already exists. So, you end up having to do a full proxy > approach, where your table never actually stores anything directly > (except a reference to another hidden table), and so when someone goes > to set something you have to set it on the proxied object instead. > Because you can't let there ever be any real keys on the proxying / > external table. > > So you're able to work around its lack a bit, to simulate something > /like/ what it means to have __setattr__. > > But then you run into problems. There's no way now to iterate over the > table now, because pairs() will only return your internal hidden keys > that you're using to point to the proxied table (Although you can get > around this with some more complexity by hiding said key into a > closure-- but even then, you still can't iterate over the proxied > table's keys instead). > > So what do you do? Well you go replace the global "pairs" function, > that's what you do! So it learns your particular style of Classness, and > interacts well. Hope you never use any third-party code which has even a > vaguely different kind of Classness. Alternately, you can just decide to > never use the standard idiom of iteration for your classes, and instead > one must always "for x in my_table:iter()" -- so now you have one kind > of code operating on 'real' tables, and a totally different kind > operating on your 'classy tables'. > > And on and on. The point is, sure. Lua can sort of simulate different > OOP approaches, and Lua-folk are very adept at tweaking, twisting, > turning and ripping tables into all kinds of pseudo-data types that > match other paradigms, but its all hacks on top of hacks on top of > hacks. You end up with some *really* weird and/or messy code if you try. > > Better to do Lua in Lua, instead of Python in Lua, or Java in Lua. > > (just like > > > CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I > > imagine it would be possible to define an equivalent to the Python > > type system in Lua, and compile Python to Lua. Lua can be compiled to > > Lua byte code. Factoring Lua, out that means we should be able to > > compile Python to Lua byte code. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload This is a very good explanation of what Lua is and how it differs from python. It all comes down to what you are looking for in a language. Simplicity of use or simplicity of implementation? Python gives you all the tools to code your algorithm right now with the least delay an with minimal effort, at the expense of some performance penalty. Lua is lean and fast, but if you need to use classes, or list comprehensions or some other cool features easily found in python, you have to code them yourself before using them. Perhaps you don't need them and you prefer a more spartan language in favor of speed and performance, and that's ok. Actually, this is what Lua is for. You may find that coding your own helper functions in Lua are not that difficult, but you have to do it. Basically, both languages are very similar, and their grammar is almost identical in their simplest aspects. But as soon as you start working with Lua, you wish you had all the missing python features. I see Lua as a some sort of minimal Python. It looks like a simplified subset of python. Being simpler, it's also easier to implement efficiently. Note that Lua was created a simple language to be embedded into larger applications written in c or c++. So it doesn't need a standard library, since you would be using libraries built for the main aplication, written in c or c++. However it worth noting that, according to Mike Pall (the creator of Luajit), there's no reason to believe Python could not be as fast a Luajit. It has no show stoppers. It would simply require much more work around its corner cases, being the main difficulties in python's own environment, not in the core language. This is all explained in the above mentioned thread on tracing jits... Luis From python at bdurham.com Tue Jul 13 11:56:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 13 Jul 2010 11:56:46 -0400 Subject: Cross-platform module that creates directory object with all file attributes Message-ID: <1279036606.15881.1384667215@webmail.messagingengine.com> Any recommendations for a cross-platform module that creates a directory object with not only file names, but file attributes as well? Use cases: - Sort files by file size or date last modified - Filter files by read-only status I know I can use various standard library functions [1] to construct such a class, but I'd rather avoid re-inventing the wheel if at all possible. (I fear that this may be one of those seemingly easy tasks that starts off simple and ends up taking a lot more time to implement after real world refactoring). Malcolm [1] os.path.getmtime, os.path.getsize, os.W_OK, etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Tue Jul 13 12:06:36 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 13 Jul 2010 17:06:36 +0100 Subject: round issue In-Reply-To: References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> On 12/07/2010 19:59, Mark Dickinson wrote: ............ >> It does look inconsistent however, and it seems to me rounding and >> interpolation should behave similarly. > > Agreed. In this case it's a minor bug that round(-9.85, 1) > produces -9.9 instead of -9.8; both string formatting > and round should give -9.8. This bug is fixed in Python > 2.7 and in Python 3.x. > > Note that in 2.7 there's still a legitimate difference: round > rounds halfway cases away from 0, while string formatting > rounds them to even. So the following results are correct: > > Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> round(1.25, 1) > 1.3 >>>> '%.1f' % 1.25 > '1.2' > > (1.25 *is* an exact halfway case, since it's exactly > representable as a binary float.) > > In Python 3.x, round always does round-half-to-even, so > string formatting and round should agree (and if they don't, > it's definitely a bug: please report it!) > > With all this said, asking for *decimal* rounding of > *binary* approximations to *decimal* halfway cases to give > the results you expect is ... optimistic, to say the least. > Use the decimal module if you care about which way > your (almost) halfway cases get rounded. > > [I already replied to this earlier through Google groups, but > I'm not sure whether it went through properly. Apologies > for the duplication, if so.] > yes thanks I saw that, but no problem about the dup. I suspect we might end up using some kind of fixed point. Anyhow does anyone have a good algorithm for ensuring rounded percentages do add up to 100%? :) How about grouped percentages ie ensure the group sums and the groups display correctly in rounded form. -- Robin Becker From robin at reportlab.com Tue Jul 13 12:06:36 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 13 Jul 2010 17:06:36 +0100 Subject: round issue In-Reply-To: References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> On 12/07/2010 19:59, Mark Dickinson wrote: ............ >> It does look inconsistent however, and it seems to me rounding and >> interpolation should behave similarly. > > Agreed. In this case it's a minor bug that round(-9.85, 1) > produces -9.9 instead of -9.8; both string formatting > and round should give -9.8. This bug is fixed in Python > 2.7 and in Python 3.x. > > Note that in 2.7 there's still a legitimate difference: round > rounds halfway cases away from 0, while string formatting > rounds them to even. So the following results are correct: > > Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> round(1.25, 1) > 1.3 >>>> '%.1f' % 1.25 > '1.2' > > (1.25 *is* an exact halfway case, since it's exactly > representable as a binary float.) > > In Python 3.x, round always does round-half-to-even, so > string formatting and round should agree (and if they don't, > it's definitely a bug: please report it!) > > With all this said, asking for *decimal* rounding of > *binary* approximations to *decimal* halfway cases to give > the results you expect is ... optimistic, to say the least. > Use the decimal module if you care about which way > your (almost) halfway cases get rounded. > > [I already replied to this earlier through Google groups, but > I'm not sure whether it went through properly. Apologies > for the duplication, if so.] > yes thanks I saw that, but no problem about the dup. I suspect we might end up using some kind of fixed point. Anyhow does anyone have a good algorithm for ensuring rounded percentages do add up to 100%? :) How about grouped percentages ie ensure the group sums and the groups display correctly in rounded form. -- Robin Becker From ritchy_gato at hotmail.com Tue Jul 13 12:13:18 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:13:18 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> Message-ID: <28b460f2-e6ae-4edc-90e2-4f79f880d646@r27g2000yqb.googlegroups.com> On 11 Jul, 17:39, Ritchy lelis wrote: > On 11 jul, 13:28, Johan Gr?nqvist wrote: > > > > > > > 2010-07-11 02:12, Ritchy lelis skrev: > > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > > About the plot draw it's a curve that it's a set of points wich it's > > > the result of the comput of the Vref and Vi together. I don't know if > > > i had to make a break instruction (like in other's languages) after > > > the "If" instructions if i want the else-condition to be executed? ... > > > (do you have some sujestions?) > > > I would have expected a code structure similar to this: > > > (NOTE: This is a very inefficient solution, and not the one suggested > > earlier, but it is closer to the code snippet you posted originally, and > > it does produce a plot.) > > > ---------------------- > > import numpy as np > > import matplotlib.pyplot as plt > > Vref = np.linspace(1,20, 100) > > Vi = np.linspace(1,10,100) > > > for ref in Vref: # Loop over Vref and Vi > > ? ? ?for i in Vi: > > ? ? ? ? ?if ?i > ref/4: # Compute V0 > > ? ? ? ? ? ? ?V0 = 2*i-ref > > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > > ? ? ? ? ? ? ?V0 = 2*i > > ? ? ? ? ?elif i < -ref/4: > > ? ? ? ? ? ? ?V0 = 2*i+ref > > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > > plt.show() # Display the plot in a window > > ---------------------- > > > > Anyway i have a picture of a tuturial that i found but in this forum i > > > can't post it. That pic would show what a really want... > > > Can you give a link? > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > > y-axis. > > > To me this sound like you want to make a 3D-plot, as there is the > > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > As i said, i have a good 2 pic of a doc that has the information about > > > this ADC that i'm developing. > > > I looked on wikipedia > > , and saw some > > figures. Is any of those similar to what you look for? > > > I see that they have (Vi - Vref) on the x-axis, and the computed value > > on the y-axis. > > > Regards > > > Johan > > Hi > > Yes those fig look's familiar to me but for now the objective its to > get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). > > I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF > there are some fig and explanations on page's 9-13. Can you take a > look there please? > > Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023 > (I think there it?s more information than the first link i gave you). > > I'll be waiting for sujestions. > > Thank's- Ocultar texto citado - > > - Mostrar texto citado - hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From rushikesh.busetty at gmail.com Tue Jul 13 12:15:00 2010 From: rushikesh.busetty at gmail.com (RUSHIKESH BUSETTY) Date: Tue, 13 Jul 2010 09:15:00 -0700 (PDT) Subject: HOTTEST ENTERTAINMENT Message-ID: HOT HEROINES PHOTOS http://hotheroinesphoto.blogspot.com/ SEXY SNEHA http://hotheroinesphoto.blogspot.com/2010/06/sneha-hot.html KOUSHA HOT EXPOSING http://hotheroinesphoto.blogspot.com/2010/06/sexy-kousha.html PRIYAMANI IN HOT BIKINI http://hotheroinesphoto.blogspot.com/2010/06/priyamani-hot.html MADHUSHALINI IN HOT DRESS http://hotheroinesphoto.blogspot.com/2010/06/blog-post_2972.html HOTTEST LIPKISS http://hotheroinesphoto.blogspot.com/2010/06/lipkiss-2.html NAMITHA IN BATH http://hotheroinesphoto.blogspot.com/2010/06/nayagarala-namitha.html http://hotheroinesphoto.blogspot.com/2010/06/nayagarala-namitha.html From ritchy_gato at hotmail.com Tue Jul 13 12:17:02 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:17:02 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> Message-ID: <902aea8e-854a-42c5-9801-bca459eeb209@i31g2000yqm.googlegroups.com> On 11 Jul, 17:39, Ritchy lelis wrote: > On 11 jul, 13:28, Johan Gr?nqvist wrote: > > > > > > > 2010-07-11 02:12, Ritchy lelis skrev: > > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > > About the plot draw it's a curve that it's a set of points wich it's > > > the result of the comput of the Vref and Vi together. I don't know if > > > i had to make a break instruction (like in other's languages) after > > > the "If" instructions if i want the else-condition to be executed? ... > > > (do you have some sujestions?) > > > I would have expected a code structure similar to this: > > > (NOTE: This is a very inefficient solution, and not the one suggested > > earlier, but it is closer to the code snippet you posted originally, and > > it does produce a plot.) > > > ---------------------- > > import numpy as np > > import matplotlib.pyplot as plt > > Vref = np.linspace(1,20, 100) > > Vi = np.linspace(1,10,100) > > > for ref in Vref: # Loop over Vref and Vi > > ? ? ?for i in Vi: > > ? ? ? ? ?if ?i > ref/4: # Compute V0 > > ? ? ? ? ? ? ?V0 = 2*i-ref > > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > > ? ? ? ? ? ? ?V0 = 2*i > > ? ? ? ? ?elif i < -ref/4: > > ? ? ? ? ? ? ?V0 = 2*i+ref > > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > > plt.show() # Display the plot in a window > > ---------------------- > > > > Anyway i have a picture of a tuturial that i found but in this forum i > > > can't post it. That pic would show what a really want... > > > Can you give a link? > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > > y-axis. > > > To me this sound like you want to make a 3D-plot, as there is the > > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > As i said, i have a good 2 pic of a doc that has the information about > > > this ADC that i'm developing. > > > I looked on wikipedia > > , and saw some > > figures. Is any of those similar to what you look for? > > > I see that they have (Vi - Vref) on the x-axis, and the computed value > > on the y-axis. > > > Regards > > > Johan > > Hi > > Yes those fig look's familiar to me but for now the objective its to > get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). > > I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF > there are some fig and explanations on page's 9-13. Can you take a > look there please? > > Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023 > (I think there it?s more information than the first link i gave you). > > I'll be waiting for sujestions. > > Thank's- Ocultar texto citado - > > - Mostrar texto citado - hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From ritchy_gato at hotmail.com Tue Jul 13 12:17:20 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:17:20 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> On 11 Jul, 13:28, Johan Gr?nqvist wrote: > 2010-07-11 02:12, Ritchy lelis skrev: > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > About the plot draw it's a curve that it's a set of points wich it's > > the result of the comput of the Vref and Vi together. I don't know if > > i had to make a break instruction (like in other's languages) after > > the "If" instructions if i want the else-condition to be executed? ... > > (do you have some sujestions?) > > I would have expected a code structure similar to this: > > (NOTE: This is a very inefficient solution, and not the one suggested > earlier, but it is closer to the code snippet you posted originally, and > it does produce a plot.) > > ---------------------- > import numpy as np > import matplotlib.pyplot as plt > Vref = np.linspace(1,20, 100) > Vi = np.linspace(1,10,100) > > for ref in Vref: # Loop over Vref and Vi > ? ? ?for i in Vi: > ? ? ? ? ?if ?i > ref/4: # Compute V0 > ? ? ? ? ? ? ?V0 = 2*i-ref > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > ? ? ? ? ? ? ?V0 = 2*i > ? ? ? ? ?elif i < -ref/4: > ? ? ? ? ? ? ?V0 = 2*i+ref > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > plt.show() # Display the plot in a window > ---------------------- > > > Anyway i have a picture of a tuturial that i found but in this forum i > > can't post it. That pic would show what a really want... > > Can you give a link? > > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > y-axis. > > To me this sound like you want to make a 3D-plot, as there is the > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > > As i said, i have a good 2 pic of a doc that has the information about > > this ADC that i'm developing. > > I looked on wikipedia > , and saw some > figures. Is any of those similar to what you look for? > > I see that they have (Vi - Vref) on the x-axis, and the computed value > on the y-axis. > > Regards > > Johan hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From python.list at tim.thechases.com Tue Jul 13 12:29:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 13 Jul 2010 11:29:44 -0500 Subject: Cross-platform module that creates directory object with all file attributes In-Reply-To: <1279036606.15881.1384667215@webmail.messagingengine.com> References: <1279036606.15881.1384667215@webmail.messagingengine.com> Message-ID: <4C3C9478.5070205@tim.thechases.com> On 07/13/2010 10:56 AM, python at bdurham.com wrote: > Any recommendations for a cross-platform module that creates a > directory object with not only file names, but file attributes as > well? > > Use cases: > - Sort files by file size or date last modified > - Filter files by read-only status > > I know I can use various standard library functions [1] to > construct such a class, but I'd rather avoid re-inventing the > wheel if at all possible. (I fear that this may be one of those > seemingly easy tasks that starts off simple and ends up taking a > lot more time to implement after real world refactoring). I think it's sufficiently easy to create a custom solution that there's not much value in trying to map file-metadata into a wrapper object. For your examples: f = os.path.getmtime #f = os.path.getsize sorted_by_mtime = sorted(os.listdir('.'), key=f) or if you need a different location sorted_by_mtime = sorted( os.listdir(loc), key=lambda fname: f(os.path.join(loc, fname)) ) And for your read-only status: files = [fname for fname in os.listdir(loc) if os.access(os.path.join(loc, fname), os.W_OK) ] That doesn't mean somebody hasn't done it before, but given how easy it is without a wrapper object, it's not something I'd go out of my way to find. -tkc From emile at fenx.com Tue Jul 13 12:39:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 13 Jul 2010 09:39:18 -0700 Subject: round issue In-Reply-To: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> <4C3C8F0C.3020606@chamonix.reportlab.co.uk> Message-ID: On 7/13/2010 9:06 AM Robin Becker said... > > Anyhow does anyone have a good algorithm for ensuring rounded > percentages do add up to 100%? :) How about grouped percentages ie > ensure the group sums and the groups display correctly in rounded form. I generally do the calculations in memory then set the largest to 100 - sum(rounded(others)). (Same as for double entry bookkeeping to ensure debits == credits) Emile From rubendario_778 at hotmail.com Tue Jul 13 13:25:52 2010 From: rubendario_778 at hotmail.com (Ruben ruben) Date: Tue, 13 Jul 2010 14:25:52 -0300 Subject: guia de python 2.6.4 en castellano Message-ID: buenos dias mi nombre es ruben queria ver si me podian mandar la guia de python 2.6.4 en castellano yo baje el programa python pero en ingles y mi ingles es muy regular desde ya muchas gracias muy bueno el programa python _________________________________________________________________ En Hotmail estamos reinventando un nuevo correo. Preparate para lo que se viene. Ver m?s http://www.nuevohotmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From downaold at gmail.com Tue Jul 13 13:26:34 2010 From: downaold at gmail.com (Roald de Vries) Date: Tue, 13 Jul 2010 19:26:34 +0200 Subject: floatref Message-ID: Hi all, I have two objects that should both be able to alter a shared float. So i need something like a mutable float object, or a float reference object. Does anybody know if something like that exists? I know it's not hard to build, but I have a feeling that there should be a standard solution to it. Roald From j at junkwallah.org Tue Jul 13 13:48:50 2010 From: j at junkwallah.org (Junkman) Date: Tue, 13 Jul 2010 10:48:50 -0700 Subject: Python 3 grammar, function parameters In-Reply-To: References: <4C3B97FB.5010409@junkwallah.org> Message-ID: <4C3CA702.3070603@junkwallah.org> A-ha! Thank you very much, Chris. Much appreciated. :-) Jay Chris Rebert wrote: > On Mon, Jul 12, 2010 at 3:32 PM, Junkman wrote: >> Greetings to Python users, >> >> I'm trying to parse Python code using the grammar supplied with the >> documentation set, and have a question on the grammar for function >> parameters: >> >> funcdef: 'def' NAME parameters ['->' test] ':' suite >> parameters: '(' [typedargslist] ')' >> typedargslist: ((tfpdef ['=' test] ',')* >> ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] >> | '**' tfpdef) >> | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) >> tfpdef: NAME [':' test] >> >> >From what I understand, a naked asterisk - i.e. it is not a prefix to an >> identifier - is not a valid parameter, but the grammar explicitly >> allows it by making the identifier that immediately follows the >> asterisk optional. >> >> Are there cases where naked asterisk is allowed as a function >> parameter? > > Yes, for keyword-only arguments, a new feature in Python 3.x. See PEP > 3102 (http://www.python.org/dev/peps/pep-3102/ ). > A lone asterisk signals that the function does not take extra > positional arguments. All keyword-only arguments must be declared > after a lone or normal *-argument. > > Example: > def compare(a, b, *, key=None): > > compare() does not accept extra positional arguments and has 1 > keyword-only argument (namely, `key`). > > Cheers, > Chris > -- > http://blog.rebertia.com > From ppearson at nowhere.invalid Tue Jul 13 14:33:57 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 13 Jul 2010 18:33:57 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <8a3pslFebiU1@mid.individual.net> On 13 Jul 2010 03:16:31 GMT, Steven D'Aprano wrote: [snip] > . . . and we rightly shake our heads at the sheer > n00b-ness of it. Writing the explicit tests: > > if bool(myInt): > > or even: > > if myInt <> 0: > > are firmly in the same category. The only difference is that it is more > familiar and therefore comfortable to those who are used to languages > that don't have Python's truth-testing rules. I have been a Python newbie for over 10 years, and would like to mention that what's clear to Python experts is much less clear to me. I think this might matter more than you think, since clarity-to-the-semicompetent is an important component of the "activation barrier" that heavily influences market share. Names are seldom so felicitous as myInt. In practice, when trying to read foreign code, I encounter "if x:", and poor commenting leaves me ignorant of x's type and thus of the exact meaning of "if x:". When I see "if x <> 0:", I get the feeling that x is some kind of number, and the meaning of the test is pretty clear. And then when writing code, I usually can't confidently retrieve the recipe for the boolean interpretation of x from readily accessible memory, so I will write explicitly what I mean, and thereby do a favor for the next guy to look at the code, who is almost always a 10-year Python newbie who needs all the clues he can get. -- To email me, substitute nowhere->spamcop, invalid->net. From xahlee at gmail.com Tue Jul 13 14:43:16 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 13 Jul 2010 11:43:16 -0700 (PDT) Subject: death of newsgroups (Microsoft closing their newsgroups) Message-ID: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> ? Death of Newsgroups http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html plain text version follows. -------------------------------------------------- Death of Newsgroups Xah Lee, 2010-07-13 Microsoft is closing down their newsgroups. See: microsoft.public.windows.powershell. I use comp.lang.lisp, comp.emacs since about 1999. Have been using them pretty much on a weekly basis in the past 10 years. Starting about 2007, the traffic has been increasingly filled with spam, and the posters are always just the 20 or 30 known faces. I think perhaps maybe no more than 100 different posters a year. Since this year or last year, they are some 95% spam. comp.emacs is pretty much just me. gnu.emacs.help is not much better. It's pretty much the same developers and the same few elisp coders, with perhaps 1 new face with once-per-lifetime post every few days. gnu.emacs.help is doing a bit better because it is connected to fsf's mailing list. comp.lang.perl.misc is dead few years ago. It's filled with just snippet of FAQs that's posted by machine. There's perl.beginners since 2002, and it's a moderated group. The one newsgroup that i use that's still healthy is comp.lang.python. Part of the reason it's healthy because it's connected to a mailing list, and python has become a mainstream lang. Though, it is also infected by a lot spam in late years. I did a study of language popularity by graphing newsgroup traffic thru the years. See: Computer Language Popularity Trend. I thought about updating it now and then, but it's useless if the majority of posts are machine generated spam. For vast majority of people who is not a regular user of newsgroups in the 1990s or earlier, i suppose newsgroup has been dead since perhaps 2002. It's somewhat sad. Because newsgroup once was the vibrant hotbed for uncensored information and freespeech, with incidences that spawned main stream public debate on policies, or change of nations. (scientology being one famous example, then there's Cindy's Torment censorship, then i remember also several cases of political dirty secrets being released in newsgroups ) These days, much of this happens in the blogs and there's Wikileaks. Xah ? http://xahlee.org/ ? From gherron at digipen.edu Tue Jul 13 14:54:35 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 13 Jul 2010 11:54:35 -0700 Subject: floatref In-Reply-To: References: Message-ID: <4C3CB66B.9030107@digipen.edu> On 07/13/2010 10:26 AM, Roald de Vries wrote: > Hi all, > > I have two objects that should both be able to alter a shared float. > So i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's > not hard to build, but I have a feeling that there should be a > standard solution to it. > > Roald Huh? I must be missing something here. Isn't this what you use a variable for: sharedFloat = 123 and later sharedFloat = 99 The variable sharedFloat could exit as a global (in some module) or as a instance variable in some shared object or anywhere else you want to store it. As a module attribute: import Shared Shared.sharedFloat = 123 Or as a class attribute: class Shared: sharedFloat = 0 Shared.sharedFloat = 123 or as an instance attribute: class Shared: def __init__(self): self.sharedFloat = 0 sharedObject = Shared() sharedObject.sharedFloat = 123 Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From hujia06 at gmail.com Tue Jul 13 15:16:54 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 15:16:54 -0400 Subject: write a .txt file In-Reply-To: <20100713071705.GA22054@cskk.homeip.net> References: <20100713071705.GA22054@cskk.homeip.net> Message-ID: On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson wrote: > On 13Jul2010 02:46, Jia Hu wrote: > | Hi: > | > | Do you mean the following code? > | > | #!/usr/bin/python > | # OS: Ubuntu > | import subprocess > | fileName = open ('final.txt', 'a') > | fileName.write ('%s %s %s \n' % (12,25,9)) > | > | fileName.flush() # add > | fileName.close() # add > > You should not need the .close(). > > Thank you. > | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to > "ls > | -a" > > You're still not waiting for the Popen subprocess to finish before > continuing. > > | fileName=open ('final.txt', 'a') > > You shouldn't need the open() if you skip the .close() > > | fileName.seek(0,2) > > If you _do_ do an open(..., "a") then you don't need the seek - append > mode will write at the end for you. > > | fileName.write ('%s %s %s \n' % (85,25,12)) > | fileName.close() > | > | I run that, the result showed the list of file is located after the > number > | list 85 25 12 > | Is that possible that I put the fileName.flush() in a wrong position ? > | I am new to Python and do not quite understand the "flush" concept. > > First: please don't top post. Post below the relevant points as I do > above, like a conversation. That way it is clear exactly what each > remark is for. > OK, it is a good suggestion. By the way, do you add the pipe "|" or they are automatically generated ? > > Second: "flush" is a general idea used with buffers. > > When you .write() to a file the data does not normally go directly to > disc. This is because a real write to the disc is expensive in time > (the CPU is much much faster than a hard drive). > > Also, a OS-level "write", which transfers the data from your program into > the OS's buffers (where it queues, for eventual writing to the disc) > is _also_ a comparitively expensive operation. So when you .write() > in python (or C using stdio, and in many other languages) the data is > normally kept in a memory buffer inside your program. Only when that > buffer is filled is an OS-level "write" done. In this way, OS calls are > few. This is a performance gain. > > So, in your program, when you .write() your first line of numbers > the data has not been handed to the OS at all, and therefore the > "final.txt" file has not seen it. A .flush() call is an explicit request > to empty the buffer, making an OS-level "write" immediately. In your > program, this is necessary to get the data to "final.txt" before the > "echo" or "ls" commands are run. > > If you .close() a file, that also empties the buffer. But it also closes > the file! SO you need to re-open it. For your purposes, a .flush() is > enough and leaves the file open for you to continue using it later. > > Regarding the .seek(): after the "echo" or "ls" command has run > the file has grown. Python's "file" object does not know the file has > grown because it was not involved. So a .seek(0 is needed to position > Python's .write() location to the end of the file instead of where it > though things were. > > Um. Because you have opened the file in 'a' mode you should not need the > .seek() - an "append" mode file will always write to the end of the > file. > > So: your first problem only requires a .flush(), to empty the buffer > before "echo" or "ls" runs. However, you still have not waited for the > "echo" or "ls" to finish - Popen kicks the command off, but it will run > at the same time as your program! Call: > > desLrr.wait() I initially thought only desLrr.wait() is needed even if without fileName.flush() , that is because the first line of number will transfer to the memory buffer and then "echo, ls" is also kept in the memory buffer and then wait() to make them finish. But when I actually did this, I find this method is not very correct. The first few words generated by "ls" are missing. When I add "fileName.flush()" again and got a correct output. Should I always write to the file at one time and then run "flush" or "close()" before the next write to the file (e.g. "echo" or the second line of number) ? Thank you. > to wait for the "echo" or "ls" to finish before continuing! > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > Quick Guide to Resources to break crypto systems of given strength: > Difficulty Resources required > 2**0 Pencil and paper > 2**8 Pencil and paper and a lot of patience > 2**16 Warez d00d with a Commodore 64 > 2**32 Amateur with an average PC > 2**40 Smart amateur with a good PC > 2**56 Network of workstations, custom-built hardware > 2**64 Thousands of PCs working together for several years > 2**80 NSA, Microsoft, the Illuminati > 2**128 Cubic kilometers of sci-fi nanotech > 2**160 Dyson spheres > Eddy L O Jansson and Matthew Skala, from: > http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alf.p.steinbach+usenet at gmail.com Tue Jul 13 15:39:50 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 21:39:50 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: * Robert Kern, on 13.07.2010 17:16: > On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote: > >> PS: You (the reader) may be wondering, why why why Yet Another Python/C++ >> binding? Well, because I had this great name for it, "pyni", unfortunately >> already in use. But cppy is very different from Boost: Boost is large, cppy is >> tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating >> argument conversion etc., while with cppy your Python design is exposed to C++ >> with no enforced arg conversions and such; Boost relies on canned magic, >> difficult to subvert when it doesn't do what you want, while with cppy you are >> (or, so far, I am) in control; and I suspect that the Boost Python binding, >> relying on dynamic registries and stuff, is not all that efficient, while cppy >> is as efficient as using the Python C API to create an extension. And besides, >> cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) > > Note that Boost is not the only C++ binding out there. You may want to > take a look at the old SCXX library, which appears to be similar in intent: > > http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html > > matplotlib uses it heavily, and their included copy may include some > more recent bugfixes and enhancements: > > http://matplotlib.sourceforge.net/ Thanks! It seems that SCXX does those things that I've been planning to do but haven't got around to (wrapping standard Python types), while what it doesn't do (abstracting away all those tables etc. and mapping Python calls to C++ calls) is what I've been working on. Which could be a Very Nice combination except that I'm assuming Py3, while SCXX seems to be Py2 only. :-( Cheers, - Alf -- blog at From python at mrabarnett.plus.com Tue Jul 13 15:40:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jul 2010 20:40:16 +0100 Subject: write a .txt file In-Reply-To: References: <20100713071705.GA22054@cskk.homeip.net> Message-ID: <4C3CC120.4060201@mrabarnett.plus.com> Jia Hu wrote: > > > On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson > wrote: > > On 13Jul2010 02:46, Jia Hu > wrote: > | Hi: > | > | Do you mean the following code? > | > | #!/usr/bin/python > | # OS: Ubuntu > | import subprocess > | fileName = open ('final.txt', 'a') > | fileName.write ('%s %s %s \n' % (12,25,9)) > | > | fileName.flush() # add > | fileName.close() # add > > You should not need the .close(). > > > Thank you. > > > | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # > change to "ls > | -a" > > You're still not waiting for the Popen subprocess to finish before > continuing. > > | fileName=open ('final.txt', 'a') > > You shouldn't need the open() if you skip the .close() > > | fileName.seek(0,2) > > If you _do_ do an open(..., "a") then you don't need the seek - append > mode will write at the end for you. > > | fileName.write ('%s %s %s \n' % (85,25,12)) > | fileName.close() > | > | I run that, the result showed the list of file is located after > the number > | list 85 25 12 > | Is that possible that I put the fileName.flush() in a wrong position ? > | I am new to Python and do not quite understand the "flush" concept. > > First: please don't top post. Post below the relevant points as I do > above, like a conversation. That way it is clear exactly what each > remark is for. > > > > OK, it is a good suggestion. By the way, do you add the pipe "|" or > > they are automatically generated ? > > > Second: "flush" is a general idea used with buffers. > > When you .write() to a file the data does not normally go directly to > disc. This is because a real write to the disc is expensive in time > (the CPU is much much faster than a hard drive). > > Also, a OS-level "write", which transfers the data from your program > into > the OS's buffers (where it queues, for eventual writing to the disc) > is _also_ a comparitively expensive operation. So when you .write() > in python (or C using stdio, and in many other languages) the data is > normally kept in a memory buffer inside your program. Only when that > buffer is filled is an OS-level "write" done. In this way, OS calls are > few. This is a performance gain. > > So, in your program, when you .write() your first line of numbers > the data has not been handed to the OS at all, and therefore the > "final.txt" file has not seen it. A .flush() call is an explicit request > to empty the buffer, making an OS-level "write" immediately. In your > program, this is necessary to get the data to "final.txt" before the > "echo" or "ls" commands are run. > > If you .close() a file, that also empties the buffer. But it also closes > the file! SO you need to re-open it. For your purposes, a .flush() is > enough and leaves the file open for you to continue using it later. > > Regarding the .seek(): after the "echo" or "ls" command has run > the file has grown. Python's "file" object does not know the file has > grown because it was not involved. So a .seek(0 is needed to position > Python's .write() location to the end of the file instead of where it > though things were. > > Um. Because you have opened the file in 'a' mode you should not need the > .seek() - an "append" mode file will always write to the end of the > file. > > So: your first problem only requires a .flush(), to empty the buffer > before "echo" or "ls" runs. However, you still have not waited for the > "echo" or "ls" to finish - Popen kicks the command off, but it will run > at the same time as your program! Call: > > desLrr.wait() > > I initially thought only desLrr.wait() is needed even if without > fileName.flush() , that is > because the first line of number will transfer to the memory buffer and > then "echo, ls" is > also kept in the memory buffer and then wait() to make them finish. But > when I actually did this, > I find this method is not very correct. The first few words generated > by "ls" are missing. > When I add "fileName.flush()" again and got a correct output. > > Should I always write to the file at one time and then run "flush" or > "close()" before the next > write to the file (e.g. "echo" or the second line of number) ? > Each process will have its own buffers, so the output from "echo" won't be going into the same buffer as that of your Python script. Whether you need to close the file depends on whether the open file can be shared. When I tried it on Windows XP without closing the file I got an error message saying that it ("echo") couldn't write to the file because it was open in another process (the Python script). If the open file can be shared then you just need to ensure that the script's output is flushed to disk; if the open file can't be shared then you need to close the file (any output that's still in the buffer will be flushed automatically when the file is closed). From alf.p.steinbach+usenet at gmail.com Tue Jul 13 15:53:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 21:53:09 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> References: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> Message-ID: * Jonathan Lee, on 13.07.2010 16:41: >> Problem (C) is outside the realm of the C++ standard, since the C++ standard >> doesn't support shared libraries, and I've never actually used *nix shared >> libraries so I don't /know/... >> >> Is such dynamic initialization guaranteed? >> > > Not guaranteed, though I think there's a combination of dlopen options > and gcc command line parameters that invoke this behavior. See the > second page of > > http://www.linuxjournal.com/article/3687 > > about auto-registration. > > Personally, though, it never worked for me :/ Ah, well. :-( Thanks for the info! OK, I'll just have to replace the auto-registration with some C++ magic. For which I think I'll simply /require/ that the compiler supports mixing of C and C++ linkage, that is, that ... #include extern "C" { typedef int (*Callback)( int ); } void foo( Callback f ) { std::cout << "foo!" << f( 42 ) << std::endl; } int a( int ) { return 1; } extern "C" int b( int ) { return 2; } int main() { foo( a ); // Unholy Mix of C++ and C linkage, formally not OK. foo( b ); // Should be OK with any compiler. } ... compiles, and works. Cheers, & thanks, - Alf -- blog at From micayael at gmail.com Tue Jul 13 15:55:35 2010 From: micayael at gmail.com (micayael) Date: Tue, 13 Jul 2010 12:55:35 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None Message-ID: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Hi. I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 the adodb and psycopg2 module (sudo apt-get install python-adodb python-psycopg2) but when I put this import adodb print adodb.NewADOConnection('postgres') --> None but with print adodb.NewADOConnection('mysql') --> From sturlamolden at yahoo.no Tue Jul 13 16:03:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 13:03:11 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: Message-ID: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> On 9 Jul, 17:52, "Alf P. Steinbach /Usenet" wrote: > For an extension module it seems that Python requires each routine to be defined > as 'extern "C"'. That is strange. PyMethodDef is just a jump table. So why should 'extern "C"' matter? Good luck on re-inventing the wheel (you've probably heared about Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...) From sturlamolden at yahoo.no Tue Jul 13 16:06:32 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 13:06:32 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> Message-ID: <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> On 13 Jul, 21:39, "Alf P. Steinbach /Usenet" wrote: > Thanks! It seems that SCXX does those things that I've been planning to do but > haven't got around to (wrapping standard Python types), while what it doesn't do > (abstracting away all those tables etc. and mapping Python calls to C++ calls) > is what I've been working on. Which could be a Very Nice combination except that > I'm assuming Py3, while SCXX seems to be Py2 only. :-( I'd suggest PyCXX instead. http://cxx.sourceforge.net SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in Python. From hansmu at xs4all.nl Tue Jul 13 16:14:27 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 13 Jul 2010 22:14:27 +0200 Subject: Check if a command is valid In-Reply-To: References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> Message-ID: <4c3cc937$0$22938$e4fe514c@news.xs4all.nl> Chris Rebert wrote: > `where` seems to be a zsh built-in: > $ # I'm in UR bash > $ nonexistent > -bash: nonexistent: command not found > $ where bash > -bash: where: command not found > > And not everyone has zsh installed, so... > I don't see why one shouldn't use the standard `which` *nix command instead. Because `which` ia a C shell script. It reads your .cshrc, to see which aliases would be defined if you were to use the C shell, but it doesn't look at your .bashrc. You're probably better off using `type`: it knows about built-ins and shell functions and that sort of stuff: $ which type /usr/bin/type $ type type type is a shell builtin $ Guess which answer is more relevant to you ..... HTH, -- HansM From alf.p.steinbach+usenet at gmail.com Tue Jul 13 16:35:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 22:35:10 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 13.07.2010 22:03: > On 9 Jul, 17:52, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> For an extension module it seems that Python requires each routine to be defined >> as 'extern "C"'. > > That is strange. PyMethodDef is just a jump table. So why should > 'extern "C"' matter? Formally because they're incompatible function pointer types. C++98 standard ?7.5/1: "Two function types with different language linkages are distinct types even if they are otherwise identical". Add to that ?7.5/4 "A linkage-specification shall occur only in namespace scope". And add to that ?14-4 "A template, a template explicit specialization, or a class-template partial specialization shall not have C linkage." This means that formally correct code that generates callbacks by templating, is ruled out. In practice, 'extern "C"' matters for the jump tables because for those few compilers if any where it really matters (not just the compiler emitting a warning like reportedly Sun CC does), different linkage can imply different machine code level calling convention. For example, who's responsible for cleaning up the stack, the order in which arguments are pushed or which registers they're passed in, and so forth. Ignoring such matters your code gets into la-la land pretty fast, but, it's a different matter when one /understands/ this and places a requirement on the compiler. > Good luck on re-inventing the wheel (you've probably heared about > Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...) Yes, I know Boost.Python in more detail and I've heard of all the rest except SIP, but then regarding SIP I really don't like QT (QT makes eminent sense in the context of Python, they're both essentially dynamically typed, but that means QT is not very nice as C++, plus there is the ugly preprocessor). And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not reinventing the wheel. Cheers & hth., - Alf -- blog at From tim at johnsons-web.com Tue Jul 13 16:47:31 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 13 Jul 2010 15:47:31 -0500 Subject: Hello References: <20100710120048.39c9a613@geekmail.INVALID> Message-ID: On 2010-07-10, Andreas Waldenburger wrote: > On Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Grant Edwards > wrote: > >> On 2010-07-09, Dani Valverde wrote: >> >> > I am new to python and pretty new to programming (I have some >> > expertise wit R statistical programming language). I am just >> > starting, so my questions may be a little bit stupid. Can anyone >> > suggest a good editor for python? >> >> Emacs, Scite (has nice folding), Vim, Eclipse. >> > Great tips for a newbie. > > Not. > > Well, they might be, but chances are, they are overkill for people new > to programming and will only alienate them (Scite may be an exception). > Text editors are an acquired taste. Emacs and Vim are very difficult to learn. Emacs more so than vim (even with vim's modal style of editing IMHO). However, to suggest that either might alienate someone new to programming presupposes some metric on their ability to learn. Since I am not privy to that metric, read on: As linux programmer, I use vim for python, javascript, rebol and adhoc system management and emacs for lispish programmer languages. 1)Most releases of vim (such as those available from ubuntu repositories) are compiled with the python binary embedded. Thus one could customize vim using python itself. 2)Emacs is itself a design environment based on the elisp programming language and both of these. The time spent on learning either of these could pay off in the long run, *but it would be a long run*. Vim and emacs are available for Windows. When I programmed in Windows I used two different editors: Pythowin, obviously coming with the python for windows distribution. Pythonwin is great and very 'helpful'. Boxer - a freeware programmer's editor, that has the best balance of configurability and ease of use of any editor that I have used. But it has been years since I used either. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From rdilipk at lycos.com Tue Jul 13 16:47:48 2010 From: rdilipk at lycos.com (Dilip) Date: Tue, 13 Jul 2010 13:47:48 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> Message-ID: <133f8384-9944-4d61-b159-9af216c178ec@z8g2000yqz.googlegroups.com> On Jul 13, 2:34?am, "Alf P. Steinbach /Usenet" wrote: > Well, we got no further, but I know of three solutions: > > ? ?A) Punting: just say that the compiler has to support C++/C function type > ? ? ? mingling. > ? ? ? -> Perhaps the practical solution, but formally unsafe. > > ? ?B) On the script side of things, delegate all calls to single Mother Of All > ? ? ? C func downcaller that supplies as extra arg an id of the C++ function. > ? ? ? -> Micro-level inefficient but easy to use and formally correct. > > ? ?C) Let the user define the C linkage function wrappers via macros. > ? ? ? -> Efficient and formally correct but exposes ugly macro names. > > I chose (C). Alf This may or may not be what you are looking for but the middleware Ice provides language mapping to enable Python to call into the Ice libraries which are basically written in C++. You can take a look at this: http://www.zeroc.com/icepy.html However that page may not be very descriptive. The codebase, though, is freely downloadable. You can take a look at it if that will help although you need to wade around a little bit to figure out what is where. From sturlamolden at yahoo.no Tue Jul 13 17:17:14 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 14:17:14 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: On 13 Jul, 22:35, "Alf P. Steinbach /Usenet" wrote: > In practice, 'extern "C"' matters for the jump tables because for those few > compilers if any where it really matters (not just the compiler emitting a > warning like reportedly Sun CC does), different linkage can imply different > machine code level calling convention. I see. Just stick to MSVC and GNU and that never happens, just do a C style cast. > Yes, I know Boost.Python in more detail and I've heard of all the rest except > SIP, but then regarding SIP I really don't like QT You don't have to use Qt to use SIP. It's just a tool to automatically wrap C++ for Python (like Swig, except designed for C++). > And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not > reinventing the wheel. It seems you are re-inventing PyCXX (or to a lesser extent Boost.Python). From ramercer at gmail.com Tue Jul 13 17:18:00 2010 From: ramercer at gmail.com (Adam Mercer) Date: Tue, 13 Jul 2010 16:18:00 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem Message-ID: Hi I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a and it is failing with the following: 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c 106 :info:build swig -python -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a pointer/reference variable may leak memory. 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a pointer/reference variable may leak memory. 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a pointer/reference variable may leak memory. 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a pointer/reference variable may leak memory. 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a pointer/reference variable may leak memory. 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a pointer/reference variable may leak memory. 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a pointer/reference variable may leak memory. 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a pointer/reference variable may leak memory. 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a pointer/reference variable may leak memory. 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a pointer/reference variable may leak memory. 117 :info:build SWIG/_util.i:9: Warning 454: Setting a pointer/reference variable may leak memory. 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a pointer/reference variable may leak memory. 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a pointer/reference variable may leak memory. 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -I/opt/local/include -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG -c SWIG/_m2crypto_wrap.c -o build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 138 :info:build SWIG/_m2crypto_wrap.c: At top level: 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in signedness 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in signedness 151 :info:build SWIG/_m2crypto_wrap.c: At top level: 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token 156 :info:build SWIG/_m2crypto_wrap.c:6081: error: expected declaration specifiers or '...' before 'STACK' 157 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': 158 :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared (first use in this function) 159 :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared identifier is reported only once 160 :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function it appears in.) 161 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_entry_create_by_txt': 162 :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in signedness 163 :info:build SWIG/_m2crypto_wrap.c: At top level: 164 :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 165 :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token 166 :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token 167 :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 168 :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token 169 :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token 170 :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token 171 :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token 172 :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token 173 :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 174 :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token 175 :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token 176 :info:build SWIG/_m2crypto_wrap.c:6385: error: expected declaration specifiers or '...' before 'STACK' 177 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': 178 :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared (first use in this function) 179 :info:build SWIG/_m2crypto_wrap.c: At top level: 180 :info:build SWIG/_m2crypto_wrap.c:6390: error: expected declaration specifiers or '...' before 'STACK' 181 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': 182 :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared (first use in this function) 183 :info:build SWIG/_m2crypto_wrap.c: At top level: 184 :info:build SWIG/_m2crypto_wrap.c:6418: error: expected declaration specifiers or '...' before 'STACK' 185 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': 186 :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared (first use in this function) 187 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument 3 of 'pkcs7_verify1' from incompatible pointer type 188 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument 4 of 'pkcs7_verify1' makes integer from pointer without a cast 189 :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments to function 'pkcs7_verify1' 190 :info:build SWIG/_m2crypto_wrap.c: At top level: 191 :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 192 :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': 193 :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 194 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': 195 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared (first use in this function) 196 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' undeclared (first use in this function) 197 :info:build SWIG/_m2crypto_wrap.c:16913: error: expected expression before ')' token 198 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': 199 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared (first use in this function) 200 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared (first use in this function) 201 :info:build SWIG/_m2crypto_wrap.c:16923: error: expected expression before ')' token 202 :info:build SWIG/_m2crypto_wrap.c:16934: error: expected expression before ')' token 203 :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit declaration of function 'sk_ssl_cipher_num' 204 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': 205 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared (first use in this function) 206 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared (first use in this function) 207 :info:build SWIG/_m2crypto_wrap.c:16953: error: expected expression before ')' token 208 :info:build SWIG/_m2crypto_wrap.c:16968: error: expected expression before ')' token 209 :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit declaration of function 'sk_ssl_cipher_value' 210 :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer from integer of different size 211 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_peer_cert_chain': 212 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared (first use in this function) 213 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' undeclared (first use in this function) 214 :info:build SWIG/_m2crypto_wrap.c:17006: error: expected expression before ')' token 215 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': 216 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared (first use in this function) 217 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared (first use in this function) 218 :info:build SWIG/_m2crypto_wrap.c:17016: error: expected expression before ')' token 219 :info:build SWIG/_m2crypto_wrap.c:17027: error: expected expression before ')' token 220 :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit declaration of function 'sk_x509_num' 221 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': 222 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared (first use in this function) 223 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared (first use in this function) 224 :info:build SWIG/_m2crypto_wrap.c:17046: error: expected expression before ')' token 225 :info:build SWIG/_m2crypto_wrap.c:17061: error: expected expression before ')' token 226 :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit declaration of function 'sk_x509_value' 227 :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer from integer of different size 228 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_name_entry_set_data': 229 :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets in assignment differ in signedness 230 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_store_ctx_get1_chain': 231 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared (first use in this function) 232 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' undeclared (first use in this function) 233 :info:build SWIG/_m2crypto_wrap.c:19741: error: expected expression before ')' token 234 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': 235 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared (first use in this function) 236 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' undeclared (first use in this function) 237 :info:build SWIG/_m2crypto_wrap.c:20573: error: expected expression before ')' token 238 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': 239 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared (first use in this function) 240 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared (first use in this function) 241 :info:build SWIG/_m2crypto_wrap.c:20583: error: expected expression before ')' token 242 :info:build SWIG/_m2crypto_wrap.c:20593: error: expected expression before ')' token 243 :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit declaration of function 'sk_x509_free' 244 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': 245 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared (first use in this function) 246 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared (first use in this function) 247 :info:build SWIG/_m2crypto_wrap.c:20609: error: expected expression before ')' token 248 :info:build SWIG/_m2crypto_wrap.c:20624: error: expected expression before ')' token 249 :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit declaration of function 'sk_x509_push' 250 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': 251 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared (first use in this function) 252 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared (first use in this function) 253 :info:build SWIG/_m2crypto_wrap.c:20653: error: expected expression before ')' token 254 :info:build SWIG/_m2crypto_wrap.c:20664: error: expected expression before ')' token 255 :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit declaration of function 'sk_x509_pop' 256 :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer from integer of different size 257 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_req_add_extensions': 258 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared (first use in this function) 259 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared (first use in this function) 260 :info:build SWIG/_m2crypto_wrap.c:20871: error: expected expression before ')' token 261 :info:build SWIG/_m2crypto_wrap.c:20890: error: expected expression before ')' token 262 :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments to function 'x509_req_add_extensions' 263 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': 264 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared (first use in this function) 265 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' undeclared (first use in this function) 266 :info:build SWIG/_m2crypto_wrap.c:20981: error: expected expression before ')' token 267 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_set_conf_lhash': 268 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared (first use in this function) 269 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared (first use in this function) 270 :info:build SWIG/_m2crypto_wrap.c:20991: error: expected expression before ')' token 271 :info:build SWIG/_m2crypto_wrap.c:21002: error: expected expression before ')' token 272 :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit declaration of function 'x509v3_set_conf_lhash' 273 :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer from integer of different size 274 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': 275 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared (first use in this function) 276 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared (first use in this function) 277 :info:build SWIG/_m2crypto_wrap.c:21013: error: expected expression before ')' token 278 :info:build SWIG/_m2crypto_wrap.c:21038: error: expected expression before ')' token 279 :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit declaration of function 'x509v3_ext_conf' 280 :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer from integer of different size 281 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_new_null': 282 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared (first use in this function) 283 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' undeclared (first use in this function) 284 :info:build SWIG/_m2crypto_wrap.c:21116: error: expected expression before ')' token 285 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_free': 286 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared (first use in this function) 287 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared (first use in this function) 288 :info:build SWIG/_m2crypto_wrap.c:21126: error: expected expression before ')' token 289 :info:build SWIG/_m2crypto_wrap.c:21136: error: expected expression before ')' token 290 :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit declaration of function 'sk_x509_extension_free' 291 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_push': 292 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared (first use in this function) 293 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared (first use in this function) 294 :info:build SWIG/_m2crypto_wrap.c:21152: error: expected expression before ')' token 295 :info:build SWIG/_m2crypto_wrap.c:21167: error: expected expression before ')' token 296 :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit declaration of function 'sk_x509_extension_push' 297 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_pop': 298 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared (first use in this function) 299 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared (first use in this function) 300 :info:build SWIG/_m2crypto_wrap.c:21191: error: expected expression before ')' token 301 :info:build SWIG/_m2crypto_wrap.c:21202: error: expected expression before ')' token 302 :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit declaration of function 'sk_x509_extension_pop' 303 :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer from integer of different size 304 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_num': 305 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared (first use in this function) 306 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared (first use in this function) 307 :info:build SWIG/_m2crypto_wrap.c:21218: error: expected expression before ')' token 308 :info:build SWIG/_m2crypto_wrap.c:21229: error: expected expression before ')' token 309 :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit declaration of function 'sk_x509_extension_num' 310 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_value': 311 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared (first use in this function) 312 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared (first use in this function) 313 :info:build SWIG/_m2crypto_wrap.c:21248: error: expected expression before ')' token 314 :info:build SWIG/_m2crypto_wrap.c:21263: error: expected expression before ')' token 315 :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit declaration of function 'sk_x509_extension_value' 316 :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer from integer of different size 317 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_make_stack_from_der_sequence': 318 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared (first use in this function) 319 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' undeclared (first use in this function) 320 :info:build SWIG/_m2crypto_wrap.c:21314: error: expected expression before ')' token 321 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_get_der_encoding_stack': 322 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared (first use in this function) 323 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared (first use in this function) 324 :info:build SWIG/_m2crypto_wrap.c:21324: error: expected expression before ')' token 325 :info:build SWIG/_m2crypto_wrap.c:21335: error: expected expression before ')' token 326 :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit declaration of function 'get_der_encoding_stack' 327 :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer from integer of different size 328 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': 329 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared (first use in this function) 330 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared (first use in this function) 331 :info:build SWIG/_m2crypto_wrap.c:22343: error: expected expression before ')' token 332 :info:build SWIG/_m2crypto_wrap.c:22366: error: expected expression before ')' token 333 :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit declaration of function 'pkcs7_encrypt' 334 :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer from integer of different size 335 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': 336 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared (first use in this function) 337 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared (first use in this function) 338 :info:build SWIG/_m2crypto_wrap.c:22547: error: expected expression before ')' token 339 :info:build SWIG/_m2crypto_wrap.c:22582: error: expected expression before ')' token 340 :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument 4 of 'pkcs7_sign1' makes integer from pointer without a cast 341 :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments to function 'pkcs7_sign1' 342 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': 343 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared (first use in this function) 344 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared (first use in this function) 345 :info:build SWIG/_m2crypto_wrap.c:22628: error: expected expression before ')' token 346 :info:build SWIG/_m2crypto_wrap.c:22659: error: expected expression before ')' token 347 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument 3 of 'pkcs7_verify1' from incompatible pointer type 348 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument 4 of 'pkcs7_verify1' makes integer from pointer without a cast 349 :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments to function 'pkcs7_verify1' 350 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': 351 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared (first use in this function) 352 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared (first use in this function) 353 :info:build SWIG/_m2crypto_wrap.c:22707: error: expected expression before ')' token 354 :info:build SWIG/_m2crypto_wrap.c:22734: error: expected expression before ')' token 355 :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument 3 of 'pkcs7_verify0' makes integer from pointer without a cast 356 :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments to function 'pkcs7_verify0' 357 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': 358 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared (first use in this function) 359 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared (first use in this function) 360 :info:build SWIG/_m2crypto_wrap.c:23188: error: expected expression before ')' token 361 :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' undeclared (first use in this function) 362 :info:build SWIG/_m2crypto_wrap.c:23211: error: expected expression before ')' token 363 :info:build SWIG/_m2crypto_wrap.c:23227: error: expected expression before ')' token 364 :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 Anyone know a way to resolve this? Cheers Adam From alf.p.steinbach+usenet at gmail.com Tue Jul 13 17:22:24 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 23:22:24 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> Message-ID: * sturlamolden, on 13.07.2010 22:06: > On 13 Jul, 21:39, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Thanks! It seems that SCXX does those things that I've been planning to do but >> haven't got around to (wrapping standard Python types), while what it doesn't do >> (abstracting away all those tables etc. and mapping Python calls to C++ calls) >> is what I've been working on. Which could be a Very Nice combination except that >> I'm assuming Py3, while SCXX seems to be Py2 only. :-( > > I'd suggest PyCXX instead. http://cxx.sourceforge.net > > SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in > Python. Thanks. I looked up your URL, and PyCXX design goals seem to be much like what I'm doing, but different in some crucial ways. It's probably great, but it's not to my taste. E.g. the PyCXX String class interface: explicit String( PyObject *pyob, bool owned = false ) String( const Object &ob ) String() String( const char *latin1 ) String( const char *latin1, Py_ssize_t size ) String( const std::string &latin1 ) String( const std::string &v, const char *encoding, const char *error=NULL ) String( const char *s, const char *encoding, const char *error=NULL ) String( const char *s, Py_ssize_t len, const char *encoding, const char *error=NULL ) String & operator=( const Object &o ) String & operator=( PyObject *p ) String & operator=( const unicodestring &v ) size_type size() const size_type capacity() const unicodestring as_unicodestring() const std::string operator std::string() const String encode( const char *encoding, const char *error="strict" ) std::string as_std_string( const char *encoding=NULL, const char *error="strict" ) const In C++ the only way to portably specify a string literal with national characters, is as a wide string literal. Otherwise the result depends on the source code encoding. Yet PyCXX's String does not support wchar_t. Also, things like the 'owned' option is just asking for trouble. I chose this example because a Python string wrapper is the only object wrapper (apart from a general PyPtr) that I've implemented so far. The PyCXX string wrapper fails the design criterions of general usability (including in particular lack of wide char support) and safety (in particular the 'owned' option). And it's underdocumented, like, what encoding does the operator std::string() produce? The details don't matter though. I'm sure that PyCXX is Very Nice for its purpose, as is e.g. Boost.Python (which is Very Very Nice for its purpose). :-) Cheers, & thanks for the link, - Alf -- blog at From sturlamolden at yahoo.no Tue Jul 13 17:28:09 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 14:28:09 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: <67a0404a-6273-4461-912a-9c960e22d8cb@t10g2000yqg.googlegroups.com> On 13 Jul, 22:35, "Alf P. Steinbach /Usenet" wrote: > Yes, I know Boost.Python in more detail and I've heard of all the rest except > SIP, In my opinion, SIP is the easiest way of integrating C++ and Python. Just ignore the PyQt stuff. http://www.riverbankcomputing.co.uk/static/Docs/sip4/using.html#a-simple-c-example http://www.riverbankcomputing.co.uk/software/sip/intro (SIP 4 can also expose C libraries to Python, not just C++.) From thomas at jollans.com Tue Jul 13 17:35:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 13 Jul 2010 23:35:01 +0200 Subject: adodb.NewADOConnection('postgres') returns None In-Reply-To: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: <4C3CDC05.9010809@jollans.com> On 07/13/2010 09:55 PM, micayael wrote: > Hi. > > I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 > the adodb and psycopg2 module (sudo apt-get install python-adodb > python-psycopg2) but when I put this > > import adodb > print adodb.NewADOConnection('postgres') --> None > > but with > > print adodb.NewADOConnection('mysql') --> > http://packages.ubuntu.com/lucid/python-adodb Recommends: python-psycopg (Package not available) If it says it wants psycopg, I wouldn't expect it to work with psycopg2, which is probably quite different in some way - otherwise it would be called the same. - Thomas From philip at semanchuk.com Tue Jul 13 17:54:43 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jul 2010 17:54:43 -0400 Subject: executing python scripts within wx frames In-Reply-To: <4C3C82F8.5060402@al.com.au> References: <4C3C82F8.5060402@al.com.au> Message-ID: <4A875FB1-4257-4517-858C-DC7BC8CBCEA2@semanchuk.com> On Jul 13, 2010, at 11:15 AM, Astan Chee wrote: > Hi, > I'm trying to make one of those frames thats similar to the wx > python demo where a folder is filled with demo wx python scripts and > there is one main script that opens the other ones in as different > items in a tree/notebook. > I've gotten most of it figured out except the part where the scripts > are executed in a wx frame. The difference between what I'm trying > to do and the wx python demo one is that mine are generic scripts > that output the results to std out/error (or whatever gets displayed > in IDLE). Does anyone know how I can do this? Simulate a IDLE or > python shell in one of the frames thats basically the output of > whatever script has been selected to run? > It would be better if the solution was platform independent too. Hi Astan, The subprocess module allows you to capture the stdin/stdout/stderr of a process that you launch. This sounds like what you're looking for. bye Philip From knny.myer at gmail.com Tue Jul 13 18:00:44 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Tue, 13 Jul 2010 18:00:44 -0400 Subject: Check if a command is valid In-Reply-To: References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <20100713220044.GD5162@5732Z> Chris Rebert (clp2 at rebertia.com) wrote: > On Mon, Jul 12, 2010 at 6:29 PM, Kenny Meyer wrote: > > Hello, > > > > I have to figure out if a string is callable on a Linux system. I'm > > "callable" seems vague. Is a command string with invalid arguments but > a valid executable "callable"? If no, then there's no general way to > test "callability" without actually running the command. I'm glad you pointed that out, because you're right. I subconciously meant a file that is in the $PATH. [snip] > > Well, you're not gonna be able to get the command's return code > without actually running it (unless perhaps you're referring to a > return code from the shell itself?). > > > What are better ways of doing this? > > One idea: > > from shlex import split as shell_tokenize > from subprocess import check_output > > def is_valid_command(command): > try: > executable = shell_tokenize(command)[0] > except (ValueError, IndexError):# invalid shell syntax > return False > return bool(check_output(['which', executable]))# on the PATH? > I have tried this and found some unexpected issues with Python 2.6 which I though I should point out: Firstly, the function `check_output` in the `subprocess` module only comes with Python 2.7, but I have found a similar function called `check_call` [1] which seems is similar, but not the same. [1] http://docs.python.org/library/subprocess.html#subprocess.check_call The code now looks like this: from shlex import split as shell_tokenize from subprocess import check_call, CalledProcessError def is_valid_command(command): try: executable = shell_tokenize(command)[0] check_call(['which', executable]) # Raises CalledProcessError if # something went wrong return True except (ValueError, IndexError, CalledProcessError): # Catch exception if there # was an error calling the process return False The idea with `which` is really great one. Thanks a lot, for your time and your input. -- Onward and upwards, Kenny Meyer -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From python at bdurham.com Tue Jul 13 18:19:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 13 Jul 2010 18:19:07 -0400 Subject: Cross-platform module that creates directory object with all file attributes In-Reply-To: <4C3CC796.9010704@timgolden.me.uk> References: <1279036606.15881.1384667215@webmail.messagingengine.com> <4C3CC796.9010704@timgolden.me.uk> Message-ID: <1279059547.25615.1384729753@webmail.messagingengine.com> Hi Tim, > Can't help you with x-platform; but for Windows I can offer my winsys package. > if f.readonly: > print f.created_at, f I like your logical model - that's exactly what I was looking for. Thank you for sharing your code. Cheers, Malcolm From johannes.black at gmail.com Tue Jul 13 19:24:22 2010 From: johannes.black at gmail.com (joblack) Date: Tue, 13 Jul 2010 16:24:22 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: All right I found the web link. It's an improvement to the pdf miner project (adds pdf dump methods). http://pastebin.com/P8SWj5YK From gherron at digipen.edu Tue Jul 13 19:26:53 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 13 Jul 2010 16:26:53 -0700 Subject: floatref In-Reply-To: <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: <4C3CF63D.20008@digipen.edu> On 07/13/2010 03:02 PM, Roald de Vries wrote: > Hi Gary, > > On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>> Hi all, >>> >>> I have two objects that should both be able to alter a shared float. >>> So i need something like a mutable float object, or a float reference >>> object. Does anybody know if something like that exists? I know it's >>> not hard to build, but I have a feeling that there should be a >>> standard solution to it. >>> >>> Roald >> >> Huh? I must be missing something here. Isn't this what you use a >> variable for: > > Maybe I didn't explain well: > > >>> shared_var = 1.0 > >>> x.var = shared_var > >>> y.var = shared_var > >>> x.var = 2.0 > >>> y.var > 1.0 > > I wanted y.var and x.var to point to the same value, so that always > x.var == y.var. So that the last line becomes: > > >>> y.var > 2.0 > > Cheers, Roald Please keep responses and further discussions on list.python-list at python.org instead of using private emails. Python does not have pointers, so if I take your wording"y.var and x.var to point to the same value" literally, then the answer is NO Python does not do that. However, Python does have references all over the place, so you can achieve something similar in many ways. If x and y in your example code are instances of a class, than look into using a property for x.var and y.var. A property is a thing that looks like an attribute, (that would be var in x.var and y.var), but which really executes getter/setter code when accessed. That getter/setter code would then access/set the value in shared_var: shared_var = 123 class Thing(object): def get_var(self): return shared_var def set_var(self, v): global shared_var shared_var = v var = property(get_var, set_var) x = Thing() y = Thing() print x.var, y.var # prints: 123 123 x.var = 99 print x.var, y.var # prints: 99 99 -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From news1234 at free.fr Tue Jul 13 19:49:10 2010 From: news1234 at free.fr (News123) Date: Wed, 14 Jul 2010 01:49:10 +0200 Subject: nicer way to remove prefix of a string if it exists Message-ID: <4c3cfb76$0$20964$426a74cc@news.free.fr> I wondered about a potentially nicer way of removing a prefix of a string if it exists. Here what I tried so far: def rm1(prefix,txt): if txt.startswith(prefix): return txt[len(prefix):] return txt for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: # method 1 inline prefix = "file://" if f.startswith(prefix): rslt = f[len(prefix):] else rsl = f # method 2 as function rslt = rm1('file://',f) Is there any nicer function than above rm1()? Is there any nicer inline statement rhan my method 1' ? From juanknebel at gmail.com Tue Jul 13 19:51:24 2010 From: juanknebel at gmail.com (Juan Andres Knebel) Date: Tue, 13 Jul 2010 20:51:24 -0300 Subject: guia de python 2.6.4 en castellano In-Reply-To: References: Message-ID: Hola, esto tal vez te pueda ayudar, no es para 2.6.4 pero sirve igual. http://www.espaciolinux.com/2009/01/tutorial-%E2%80%9Cpython-para-todos%E2%80%9D-en-espanol/ Igualmente esto es una lista en ingles, por lo que si necesitas ayuda en espanol te recomiendo la lista python en dicho idioma Saludos 2010/7/13 Ruben ruben > buenos dias mi nombre es ruben queria ver si me podian mandar la guia de > python 2.6.4 en castellano yo baje el programa python pero en ingles y mi > ingles es muy regular desde ya muchas gracias muy bueno el programa python > ------------------------------ > Descubr? un nuevo Hotmail: con m?s herramientas para una vida m?s pr?ctica. > Muy pronto. Ver m?s > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Juan Andres Knebel -------------- next part -------------- An HTML attachment was scrubbed... URL: From juanknebel at gmail.com Tue Jul 13 20:08:21 2010 From: juanknebel at gmail.com (Juan Andres Knebel) Date: Tue, 13 Jul 2010 21:08:21 -0300 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4c3cfb76$0$20964$426a74cc@news.free.fr> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: Hi, for rm1 I think something like this could work: def rm1(prefix,txt): regular_expresion = re.compile(r''+prefix+'(.*)') return re.match(regular_expresion,txt).group(1) On Tue, Jul 13, 2010 at 8:49 PM, News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > > > Here what I tried so far: > > > def rm1(prefix,txt): > if txt.startswith(prefix): > return txt[len(prefix):] > return txt > > > for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: > # method 1 inline > prefix = "file://" > if f.startswith(prefix): > rslt = f[len(prefix):] > else > rsl = f > # method 2 as function > rslt = rm1('file://',f) > > > Is there any nicer function than above rm1()? > Is there any nicer inline statement rhan my method 1' ? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Juan Andres Knebel -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Jul 13 20:12:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jul 2010 01:12:27 +0100 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4c3cfb76$0$20964$426a74cc@news.free.fr> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: <4C3D00EB.1010203@mrabarnett.plus.com> News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > > > Here what I tried so far: > > > def rm1(prefix,txt): > if txt.startswith(prefix): > return txt[len(prefix):] > return txt > > > for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: > # method 1 inline > prefix = "file://" > if f.startswith(prefix): > rslt = f[len(prefix):] > else > rsl = f > # method 2 as function > rslt = rm1('file://',f) > > > Is there any nicer function than above rm1()? No. > Is there any nicer inline statement rhan my method 1' ? > You could write: rsl = f[len(prefix):] if f.startswith(prefix) else f in recent versions of Python, but the function is neater. From drsalists at gmail.com Tue Jul 13 20:30:14 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 13 Jul 2010 17:30:14 -0700 Subject: How is Unladen Swallow coming along? In-Reply-To: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> Message-ID: 2010/7/8 Luis M. Gonz?lez > On Jul 8, 1:42 pm, John Nagle wrote: > > How is Unladen Swallow coming along? Looking at the site, code is > > being checked in and issues are being reported, but the last quarterly > > release was 2009 Q3. They missed their January 2010 release date > > for "2009 Q4", so they're now about 6 months behind their project > > plan. > > > > ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > > > John Nagle > > Don't be shy. > Ask this question in Unladen Swallow's google group. They don't bite! I'm not the O.P., but I was curious too, so I asked on an Unladen Swallow mailing list. The response was that progress on Unladen Swallow is still occurring, and is focused on merging things into the py3k-jit branch of the official python repo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Jul 13 20:32:48 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 14 Jul 2010 10:32:48 +1000 Subject: Errno 9] Bad file descriptor In-Reply-To: References: Message-ID: <20100714003248.GA23169@cskk.homeip.net> On 13Jul2010 05:56, joblack wrote: | Thanks for the answers so far. It's not my code I'm just curious how | that could happen: | | Starting point: | ... | self.status['text'] = 'Processing ...' | try: | cli_main(argv) | except Exception, e: | self.status['text'] = 'Error: ' + str(e) | return | ... | cli_main: | | keypath, inpath, outpath = argv[1:] | ... | with open(inpath, 'rb') as inf: | serializer = PDFSerializer(inf, keypath) | with open(outpath, 'wb') as outf: | filenr = outf.fileno() | serializer.dump(outf) | return 0 | | PDFSerializer.dump: | | def dump(self, outf): | self.outf = outf | ... See that you set serializer.outf to the outf you open in cli_main? Any attempt to use serializer _after_ exiting the "with open(outpath, 'wb') as outf" will use serializer.outf, but the outf is now closed. And thus its file descriptor is invalid. BTW, by catching Exception in the starting point code you prevent yourself seeing exactly which line throws the error. It is usualy a bad idea to catch broad things like "Exception". It is normally better to place try/except around very small pieces of code and to catch very specific things. That way you know exactly what's going wrong and don't quietly catch all sorts of unplanned stuff. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ When buying and selling are controlled by legislation, the first things bought and sold are the legislators. - P.J. O'Rourke From aahz at pythoncraft.com Tue Jul 13 20:48:43 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Jul 2010 17:48:43 -0700 Subject: Why doesn't python's list append() method return the list itself? References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: [Original not available on my swerver, responding here] >On 7/11/10 10:03 PM, Nathan Rice wrote: >> >> Yeah, I long ago filed the in place place in the same folder as >> strings-as-sequences, all() returning True for an empty iterable and any >> returning True rather than the thing which triggered it. Because I love to repeat myself: "...string iteration isn't about treating strings as sequences of strings, it's about treating strings as sequences of characters. The fact that characters are also strings is the reason we have problems, but characters are strings for other good reasons." --Aahz http://mail.python.org/pipermail/python-3000/2006-April/000897.html Do you really want to give up Python's lovely string-slicing capabilities? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From tekion at gmail.com Tue Jul 13 21:15:58 2010 From: tekion at gmail.com (tekion) Date: Tue, 13 Jul 2010 18:15:58 -0700 (PDT) Subject: python ldap recursive Message-ID: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Hi, I know perl Net::LDAP could do a recursive search call to LDAP. What I am running into with Python LDAP on the search call is that I would l have to wait for the search to complete to get the result. Where as with Perl recursive search call, I would get the result (not the completed result) back while the search is still running. Does any know if we have something like this in Python LDAP module? Thanks. From alf.p.steinbach+usenet at gmail.com Tue Jul 13 21:19:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 03:19:36 +0200 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: * Gary Herron, on 14.07.2010 01:26: > On 07/13/2010 03:02 PM, Roald de Vries wrote: >> Hi Gary, >> >> On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >>> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>>> Hi all, >>>> >>>> I have two objects that should both be able to alter a shared float. >>>> So i need something like a mutable float object, or a float reference >>>> object. Does anybody know if something like that exists? I know it's >>>> not hard to build, but I have a feeling that there should be a >>>> standard solution to it. >>>> >>>> Roald >>> >>> Huh? I must be missing something here. Isn't this what you use a >>> variable for: >> >> Maybe I didn't explain well: >> >> >>> shared_var = 1.0 >> >>> x.var = shared_var >> >>> y.var = shared_var >> >>> x.var = 2.0 >> >>> y.var >> 1.0 >> >> I wanted y.var and x.var to point to the same value, so that always >> x.var == y.var. So that the last line becomes: >> >> >>> y.var >> 2.0 >> >> Cheers, Roald > > Please keep responses and further discussions on > list.python-list at python.org > instead of using private emails. Seconded. I didn't see that posting. > Python does not have pointers, so if I take your wording"y.var and x.var > to point to the same value" literally, then the answer is NO Python does > not do that. This is just a terminological issue. Saying "Python does not have pointers" is highly misleading in response to the OP's statement. It's easy enough to understand what he means. E.g., in the Java language specification "pointer" has a suitable meaning. And in general, the term "pointer" encompasses far more than the concept of a C or Pascal pointer, e.g., in C++ it includes offset-like things called member pointers. You can't represent or usefully think of a C++ member pointer as a C or Pascal pointer. It isn't useful on its own. So, considering C++ and Java, the general pointer notion is something that refers, however obliquely. You chose a specific meaning of "pointer" where the OP's statement does not make sense, but presumably the OP is explaining his needs in terms of a more general meaning of "pointer"; assuming anything else is silly. > However, Python does have references all over the place, so you can > achieve something similar in many ways. > > If x and y in your example code are instances of a class, than look into > using a property for x.var and y.var. A property is a thing that looks > like an attribute, (that would be var in x.var and y.var), but which > really executes getter/setter code when accessed. That getter/setter > code would then access/set the value in shared_var: > > > shared_var = 123 > > class Thing(object): > def get_var(self): > return shared_var > def set_var(self, v): > global shared_var > shared_var = v > > var = property(get_var, set_var) > > > x = Thing() > y = Thing() > > print x.var, y.var # prints: 123 123 > x.var = 99 > print x.var, y.var # prints: 99 99 This code goes through hoops to /hide/ the fact of the sharing. Rather, I'd make that as explicit as possible. Like, x = {"sharedVar": 123} y = x The one won't be surprised when changing x["sharedVar"] also changes y["sharedVar"]. Cheers & hth., - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 21:53:14 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 01:53:14 GMT Subject: floatref References: Message-ID: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > Hi all, > > I have two objects that should both be able to alter a shared float. So > i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's not > hard to build, but I have a feeling that there should be a standard > solution to it. One standard solution would be to wrap the float in a class as an attribute. Another is to put it in a list: myvalue = [3.1415] pi = myvalue myvalue[0] = 3.0 assert pi[0] == 3.0 A third standard solution is to create a mutable float using delegation. See the MutableStr class in the standard library for hints. An even better solution is to avoid the idiom of shared state in the first place. Whenever people say "I need shared data", the chances are very good that they don't *need* it at all, but merely *want* it because that's the idiom they're used to. But if you really need it, you can make it. -- Steven From anand.shashwat at gmail.com Tue Jul 13 22:22:15 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 07:52:15 +0530 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4C3D00EB.1010203@mrabarnett.plus.com> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> <4C3D00EB.1010203@mrabarnett.plus.com> Message-ID: On Wed, Jul 14, 2010 at 5:42 AM, MRAB wrote: > News123 wrote: > >> I wondered about a potentially nicer way of removing a prefix of a >> string if it exists. >> >> >> Here what I tried so far: >> >> >> def rm1(prefix,txt): >> if txt.startswith(prefix): >> return txt[len(prefix):] >> return txt >> >> >> for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: >> # method 1 inline >> prefix = "file://" >> if f.startswith(prefix): >> rslt = f[len(prefix):] >> else >> rsl = f >> # method 2 as function >> rslt = rm1('file://',f) >> >> >> Is there any nicer function than above rm1()? >> > > No. > > > Is there any nicer inline statement rhan my method 1' ? >> >> You could write: > > rsl = f[len(prefix):] if f.startswith(prefix) else f > Or you can just do split and join, "".join(f.split(prefix, 1)) will do. >>> prefix = 'file://' >>> f = 'file:///home/me/data.txt' >>> "".join(f.split(prefix, 1)) '/home/me/data.txt' >>> f = 'file:///home/me/data.txtfile://' >>> "".join(f.split(prefix, 1)) '/home/me/data.txtfile://' >>> f = '/home/me/data.txt' >>> "".join(f.split(prefix, 1)) '/home/me/data.txt' -------------- next part -------------- An HTML attachment was scrubbed... URL: From barzhomi at gmail.com Tue Jul 13 22:37:08 2010 From: barzhomi at gmail.com (=?KOI8-R?B?4sHWxc4g8tbF1dTTy8nK?=) Date: Wed, 14 Jul 2010 09:37:08 +0700 Subject: Problem with executing python interpretetor on special build of win server 2003 In-Reply-To: References: Message-ID: Hello. Actual problem in the next, when i trying to execute portable python on my build then nothing happens, and the error code is 128. What does mean this code 128? -------------- next part -------------- An HTML attachment was scrubbed... URL: From superjuicylady4 at gmail.com Tue Jul 13 22:40:01 2010 From: superjuicylady4 at gmail.com (superjuicylady) Date: Tue, 13 Jul 2010 19:40:01 -0700 (PDT) Subject: FREE HOT SEX DATES FOR YOU RIGHT NOW Message-ID: <2c93ea89-f0e7-4d39-9f79-6a9cc4205d0b@n8g2000prh.googlegroups.com> if you are feeling bored but hot right now? well just click this safe and secured link for your privacy and enjoy. copy and paste it in your browser if it isnt linked please wait for 1 minute for the site to load free stuff -----> http://u-gfi5eq0m0h.urlcash.net free porn -----> http://u-xfhkxxpjz0.urlcash.net latest movies-----> http://254d9bd5.zxxo.net free games -----> http://5efb70b9.uberpicz.com Enjoy and read instructions very well From cdalten at gmail.com Tue Jul 13 23:03:14 2010 From: cdalten at gmail.com (chad) Date: Tue, 13 Jul 2010 20:03:14 -0700 (PDT) Subject: python namespace question Message-ID: Given the following code... #!/usr/bin/python class cgraph: def printme(self): print "hello\n" x = cgraph() x.printme() Does the function print() exist in the cgraph namespace or the printme() one? From anand.shashwat at gmail.com Tue Jul 13 23:19:20 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 08:49:20 +0530 Subject: python namespace question In-Reply-To: References: Message-ID: On Wed, Jul 14, 2010 at 8:33 AM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > def printme(self): > print "hello\n" > No need to do print "hello\n", python is not C, print "hello" prints hello with a newline. Try it on interpretor. > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the > printme() one? > Where exactly is the print() function here. BTW printme() is in cgraph namespace. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From kentilton at gmail.com Tue Jul 13 23:24:12 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Tue, 13 Jul 2010 23:24:12 -0400 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: <4c3d2dcd$0$31270$607ed4bc@cv.net> Xah Lee wrote: > ? Death of Newsgroups > http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html > > plain text version follows. > > -------------------------------------------------- > Death of Newsgroups > > Xah Lee, 2010-07-13 > > Microsoft is closing down their newsgroups. See: > microsoft.public.windows.powershell. > > I use comp.lang.lisp, comp.emacs since about 1999. Have been using > them pretty much on a weekly basis in the past 10 years. Starting > about 2007, the traffic has been increasingly filled with spam, and > the posters are always just the 20 or 30 known faces. I think perhaps > maybe no more than 100 different posters a year. Since this year or > last year, they are some 95% spam. Forest. Trees. Please note order. Case in point: twelve weeks ago His Timness mentioned this on comp.lang.lisp; http://www.math.union.edu/~dpvc/jsMath/ Now we have this, a port of a desktop app to the web: http://teamalgebra.com/ It happened fast because http://qooxdoo.org/lets me program the Web without bothering with HTML and CSS and browser variation as if I were using a framework like GTk. I learned about qooxdoo... on comp.lang.lisp. The moral? If you look for the spam, you'll find it. kt -- http://www.teamalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:37:03 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:37:03 GMT Subject: python namespace question References: Message-ID: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > def printme(self): > print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the printme() > one? What function print()? You're calling the print STATEMENT. It doesn't exist in any namespace, it's a Python keyword like "if", "for", "return", and similar. Note: this changes in Python 3, where print becomes a function like len(), chr(), max(), and similar. In Python 3, you would write: print("hello\n") and the function lives in the built-in namespace. BTW, print (both versions) automatically prints a newline at the end of the output, so printing "hello\n" will end up with an extra blank line. Is that what you wanted? -- Steven From anand.shashwat at gmail.com Tue Jul 13 23:38:58 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 09:08:58 +0530 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On Tue, Jul 13, 2010 at 6:59 AM, Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? > Check your $PATH. All your system commands lies there. Make a list and save it. Now just check whether your 'command' lies in the list. However better is to run the command, but some commands like 'shutdown' won't be good for this I think. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:40:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:40:50 GMT Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> Message-ID: <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: > The moral? If you look for the spam, you'll find it. And if you *don't* look for spam, you can be sure that some goose will reply to it and get it past your filters. Thanks for that Kenneth, if that is your name and you're not a Xah Lee sock-puppet. Followups set to a black hole. -- Steven From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:43:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:43:41 GMT Subject: python ldap recursive References: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Message-ID: <4c3d326c$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 18:15:58 -0700, tekion wrote: > Hi, > I know perl Net::LDAP could do a recursive search call to LDAP. What I > am running into with Python LDAP on the search call is that I would l > have to wait for the search to complete to get the result. Where as > with Perl recursive search call, I would get the result (not the > completed result) back while the search is still running. Does any know > if we have something like this in Python LDAP module? Thanks. What Python LDAP module are you using? -- Steven From cdalten at gmail.com Tue Jul 13 23:48:29 2010 From: cdalten at gmail.com (chad) Date: Tue, 13 Jul 2010 20:48:29 -0700 (PDT) Subject: python namespace question References: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Jul 13, 8:37?pm, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote: > > Given the following code... > > > #!/usr/bin/python > > > class cgraph: > > ? ? def printme(self): > > ? ? ? ? print "hello\n" > > > x = cgraph() > > x.printme() > > > Does the function print() exist in the cgraph namespace or the printme() > > one? > > What function print()? You're calling the print STATEMENT. It doesn't > exist in any namespace, it's a Python keyword like "if", "for", "return", > and similar. > > Note: this changes in Python 3, where print becomes a function like > len(), chr(), max(), and similar. In Python 3, you would write: > > print("hello\n") > > and the function lives in the built-in namespace. > > BTW, print (both versions) automatically prints a newline at the end of > the output, so printing "hello\n" will end up with an extra blank line. > Is that what you wanted? > I could care less about the extra blank line. I guess I was just more concerned about the namespace question. From clp2 at rebertia.com Tue Jul 13 23:52:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jul 2010 20:52:31 -0700 Subject: python namespace question In-Reply-To: References: Message-ID: On Tue, Jul 13, 2010 at 8:03 PM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > ? ?def printme(self): > ? ? ? ?print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the > printme() one? Neither. It exists in the built-ins namespace along with the rest of the built-in functions like len(), zip(), hex(), etc. The built-ins is the namespace of last resort; it's the last one to be consulted when trying to resolve a name in Python. You can inspect it via __builtins__ Also, in your example, print is being used as a statement (i.e. part of the language syntax), not a function; note the odd lack of parentheses when "calling" it. print was changed to a regular function in Python 3.x. Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 00:29:00 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 04:29:00 GMT Subject: python namespace question References: Message-ID: <4c3d3d0c$0$28657$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 20:52:31 -0700, Chris Rebert wrote: > The built-ins is the > namespace of last resort; it's the last one to be consulted when trying > to resolve a name in Python. You can inspect it via __builtins__ Avoid __builtins__ as it is an implementation detail. The difference between __builtins__ and __builtin__ is one of the more confusing corners of Python, but the correct one to use is __builtin__. http://docs.python.org/library/__builtin__.html -- Steven From kse.listed.co1 at gmail.com Wed Jul 14 00:31:06 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Tue, 13 Jul 2010 21:31:06 -0700 (PDT) Subject: "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ Message-ID: <7cf3c527-90f4-43ec-9ff5-c2e805aa6077@a4g2000prm.googlegroups.com> "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ V From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 00:31:54 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 04:31:54 GMT Subject: floatref References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 03:19:36 +0200, Alf P. Steinbach /Usenet wrote: > Gary Herron wrote: >> Python does not have pointers, so if I take your wording"y.var and >> x.var to point to the same value" literally, then the answer is NO >> Python does not do that. > > This is just a terminological issue. "Just"? If people can't agree on terminology, they can't even understand each other, let alone communicate effectively. If I call you a fine fellow with a detailed grasp of programming and a helpful manner, but what I mean by "fine", "detailed" and "helpful" are different from what you mean by them, how can you tell if I've just complimented you or insulted you? Gary did the right thing by pointing out that the simple-sounding term "points to" is anything but simple, it depends on what you mean by pointing and pointers. > Saying "Python does not have > pointers" is highly misleading in response to the OP's statement. It's > easy enough to understand what he means. E.g., in the Java language > specification "pointer" has a suitable meaning. And in a Java language forum, that would arguably be the right meaning to assume. Possibly even in a Jython forum. But this is neither, it's a Python forum, where "Python" is typically understood to be CPython, not Jython and certainly not Java, and "pointer" is typically understood to mean C or Pascal pointers. In an English language forum, the correct meaning to use for "cafeteria" is a "dining hall", and not "fringe benefit" as it would be in a Hungarian forum. Likewise, the correct meaning to use for the word "gift" in an English forum is a present or object which is given, and not "poison" as a German might assume. [...] > You can't represent or usefully think of a C++ member pointer > as a C or Pascal pointer. It isn't useful on its own. So, considering > C++ and Java, the general pointer notion is something that refers, > however obliquely. So an integer like 3 counts as a pointer, as you can use it as an index into a list, array or other sequence. In that sense, yes, Python has pointers, and makes frequent use of them. You can even do pointer arithmetic! I don't think this position is terribly useful. It's possible to be *too* generic. > You chose a specific meaning of "pointer" where the > OP's statement does not make sense, but presumably the OP is explaining > his needs in terms of a more general meaning of "pointer"; assuming > anything else is silly. The Zen of Python includes: In the face of ambiguity, refuse the temptation to guess. Wise words, not just for programming. -- Steven From alf.p.steinbach+usenet at gmail.com Wed Jul 14 00:50:58 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 06:50:58 +0200 Subject: floatref In-Reply-To: <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 14.07.2010 06:31: > > Gary did the right thing by pointing out that the simple-sounding term > "points to" is anything but simple, it depends on what you mean by > pointing and pointers. Possibly you have a point here. Cheers, - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 01:05:15 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 05:05:15 GMT Subject: floatref References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c3d458b$0$28657$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 06:50:58 +0200, Alf P. Steinbach /Usenet wrote: > Possibly you have a point here. Oh yeah? Don't think you can escape a flame war by agreeing with me! *wink* -- Steven From wuwei23 at gmail.com Wed Jul 14 01:46:32 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 Jul 2010 22:46:32 -0700 (PDT) Subject: python namespace question References: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> Message-ID: <1606d351-6bd4-43bf-8723-159ecc351ebd@z30g2000prg.googlegroups.com> chad wrote: > I could care less about the extra blank line. I guess I was just more > concerned about the namespace question. Which is why Steven spent far more time answering that question than commenting on newline handling. Now say 'thank you'. From gnuist006 at gmail.com Wed Jul 14 02:01:39 2010 From: gnuist006 at gmail.com (bolega) Date: Tue, 13 Jul 2010 23:01:39 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> On Jun 20, 9:31?pm, Richard Fateman wrote: > Define Macro wrote: > > On Jun 13, 7:07 pm, bolega wrote: > >> I am trying to compare LISP/Scheme/Python for their expressiveness. > > >> For this, I propose a vanilla C interpreter. I have seen a book which > >> writes C interpreter in C. > > >> The criteria would be the small size and high readability of the code. > > >> Are there already answers anywhere ? > > Sure. ?Lots of texts on compilers provide exercises which, in one way or > another suggest how to write an interpreter and perhaps a compiler too > for some language. ?Anyone taking a course on compilers is likely to > have followed such exercises in order to pass the course. ?Some > instructors are enlightened enough to allow students to pick the > implementation language. > > Ask any such instructor. Beware, he does not tell the readers the financial details. This is what he wrote to me by email. I would be willing to meet with you here in Berkeley to educate you on these matters at a consulting rate of $850 per hour, with a minimum of 8 hours. RJF > I think you will find that many people use a packaged parser-generator > which eliminates much of the choice-of-language difference. Do you like > Bison, Yacc, Antlr, or one of the many parser generators in Lisp, > python, etc. > > My own experience is that in comparing Lisp to C, students end up with > smaller and better interpreters and compilers, faster. ?I don't know > about python vs C for sure, but I suspect python wins. ?As for > python vs Lisp, I don't know. > > RJF From debatem1 at gmail.com Wed Jul 14 02:18:10 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 23:18:10 -0700 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> Message-ID: On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: > On Jun 20, 9:31?pm, Richard Fateman wrote: >> Define Macro wrote: >> > On Jun 13, 7:07 pm, bolega wrote: >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. >> >> >> For this, I propose a vanilla C interpreter. I have seen a book which >> >> writes C interpreter in C. >> >> >> The criteria would be the small size and high readability of the code. >> >> >> Are there already answers anywhere ? >> >> Sure. ?Lots of texts on compilers provide exercises which, in one way or >> another suggest how to write an interpreter and perhaps a compiler too >> for some language. ?Anyone taking a course on compilers is likely to >> have followed such exercises in order to pass the course. ?Some >> instructors are enlightened enough to allow students to pick the >> implementation language. >> >> Ask any such instructor. > > > > Beware, he does not tell the readers the financial details. This is > what he wrote to me by email. > > > I would be willing to meet with you here in Berkeley to educate you on > these matters at a consulting rate of ?$850 per hour, with a minimum > of 8 hours. > > RJF > He's Berkeley's former CS chair and was implementing lisp before common lisp was a twinkle in anybody's eye. His time is valuable. Geremy Condra From martin at v.loewis.de Wed Jul 14 02:30:46 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 14 Jul 2010 08:30:46 +0200 Subject: Python track at German Zope conference Message-ID: [Das ist im Wesentlichen eine Kopie einer Nachricht, die Dinu an die Python-DE-Liste geschickt hat.] >From September 15 to September 17, 2010, the German Zope conference (organized by DZUG) takes place in Dresden. It has tracks for Python, Zope, and Plone. Dinu Gherman and me are organizing the Python Track, and we are still looking for people interested in presenting Python related projects or topics. If so, please let us know, or submit your talk proposal to the conference site. Also, if you would like to come to the conference if a certain topic was presented, please let us know. You'll find more information on the conference at http://www.zope.de/tagung/Dresden_2010/call-for-papers Notice that there will be tutorials before the regular tracks, and sprints afterwards. Regards, Martin From no.email at nospam.invalid Wed Jul 14 02:35:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 13 Jul 2010 23:35:14 -0700 Subject: C interpreter in Lisp/scheme/python References: Message-ID: <7xoceao9jx.fsf@ruckus.brouhaha.com> bolega writes: > I am trying to compare LISP/Scheme/Python for their expressiveness... > Are there already answers anywhere ? > How would a gury approach such a project ? These two articles http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf http://www.haskell.org/papers/NSWC/jfp.ps about language comparisons (Python is in the first but not the second) might be of interest. If you want to know how to implement C, there is a pretty good book by Hanson and Fraser about LCC, called "A Retargetable C Compiler". Basically a code walkthrough of a small C compiler written in C. From maaindia0 at gmail.com Wed Jul 14 02:41:05 2010 From: maaindia0 at gmail.com (easy money) Date: Tue, 13 Jul 2010 23:41:05 -0700 (PDT) Subject: Simple hack to get $500 to your home. Message-ID: <5b42511e-4382-4567-896a-31228f560d5d@m35g2000prn.googlegroups.com> Simple hack to get $500 to your home at http://cashbygetpaypal.tk Due to high security risks,i have hidden the cheque link in an image. in that website on top side above search box, click on image and enter your name and address where you want to receive your cheque. please don,t tell to anyone. From downaold at gmail.com Wed Jul 14 03:56:08 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 09:56:08 +0200 Subject: floatref In-Reply-To: <4C3CF63D.20008@digipen.edu> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: On Jul 14, 2010, at 1:26 AM, Gary Herron wrote: > On 07/13/2010 03:02 PM, Roald de Vries wrote: >> Hi Gary, >> >> On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >>> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>>> Hi all, >>>> >>>> I have two objects that should both be able to alter a shared >>>> float. >>>> So i need something like a mutable float object, or a float >>>> reference >>>> object. Does anybody know if something like that exists? I know >>>> it's >>>> not hard to build, but I have a feeling that there should be a >>>> standard solution to it. >>>> >>>> Roald >>> >>> Huh? I must be missing something here. Isn't this what you use a >>> variable for: >> >> Maybe I didn't explain well: >> >> >>> shared_var = 1.0 >> >>> x.var = shared_var >> >>> y.var = shared_var >> >>> x.var = 2.0 >> >>> y.var >> 1.0 >> >> I wanted y.var and x.var to point to the same value, so that always >> x.var == y.var. So that the last line becomes: >> >> >>> y.var >> 2.0 >> >> Cheers, Roald > > Please keep responses and further discussions on > list.python-list at python.org > instead of using private emails. Sorry. > Python does not have pointers, so if I take your wording"y.var and > x.var to point to the same value" literally, then the answer is NO > Python does not do that. Maybe I should have put it between quotes, but I used the words 'mutable float' and 'float reference' in the original post, and this was only an attempt to clarify better. > However, Python does have references all over the place, so you can > achieve something similar in many ways. I know, I just wondered if there is a *standard* solution. Cheers, Roald From downaold at gmail.com Wed Jul 14 04:11:54 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 10:11:54 +0200 Subject: floatref In-Reply-To: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> References: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> Message-ID: <7B2036EE-B050-4520-A5A3-6B3B1A53E702@gmail.com> On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > >> Hi all, >> >> I have two objects that should both be able to alter a shared >> float. So >> i need something like a mutable float object, or a float reference >> object. Does anybody know if something like that exists? I know >> it's not >> hard to build, but I have a feeling that there should be a standard >> solution to it. > > > One standard solution would be to wrap the float in a class as an > attribute. E.g.: a class FloatWrapper with a get and set method. Advantages: transparent, easy to implement Disadvantages: for 'f = FloatWrapper' you have to use 'f.set(1.0)' instead of 'f = 1.0', which reads less easily (I think), and a mistake like assigning with 'f = 1.0' is easily made. > Another is to put it in a list: > > myvalue = [3.1415] > pi = myvalue > myvalue[0] = 3.0 > assert pi[0] == 3.0 I thought about something like that, but it's a bit misleading, because the value is actually a list. > An even better solution is to avoid the idiom of shared state in the > first place. Whenever people say "I need shared data", the chances are > very good that they don't *need* it at all, but merely *want* it > because > that's the idiom they're used to. I want to simulate a distributed algorithm, in which components can only communicate through shared state. Cheers, Roald From lars at gustaebel.de Wed Jul 14 04:16:45 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Wed, 14 Jul 2010 10:16:45 +0200 Subject: tarfile and progress information In-Reply-To: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> References: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> Message-ID: <20100714081645.GA28817@axis.g33x.de> On Wed, Jul 07, 2010 at 11:23:22AM -0400, Nathan Huesken wrote: > I am packing large files with tarfile. Is there any way I can get > progress information while packing? There is no builtin way in tarfile, but there are several possible solutions: 1. Replace the tarfile.copyfileobj() function that is used to copy the files' contents to the archive with your own. 2. Subclass the TarFile class, replace the addfile() method, and wrap every file object argument into an object that triggers a callback function for each block of data being read: """ import sys import os import tarfile class FileProxy(object): def __init__(self, fobj, callback): self.fobj = fobj self.callback = callback self.size = os.fstat(self.fobj.fileno()).st_size def read(self, size): self.callback(self.fobj.tell(), self.size) return self.fobj.read(size) def close(self): self.callback(self.size, self.size) self.fobj.close() class MyTarFile(tarfile.TarFile): def __init__(self, *args, **kwargs): self.callback = kwargs.pop("callback") super(MyTarFile, self).__init__(*args, **kwargs) def addfile(self, tarinfo, fileobj=None): if self.callback is not None and fileobj is not None: fileobj = FileProxy(fileobj, self.callback) super(MyTarFile, self).addfile(tarinfo, fileobj) def callback(processed, total): sys.stderr.write("%.1f%% \r" % (processed / float(total) * 100)) tar = MyTarFile.open("test.tar.gz", "w:gz", callback=callback) tar.add("...") tar.close() """ 3. If you have a defined set of files to add you can do something like this: tar = tarfile.open("test.tar.gz", "w:gz") for filename in filenames: tarinfo = tar.gettarinfo(filename) fobj = FileProxy(open(filename, "rb"), callback) tar.addfile(tarinfo, fobj) fobj.close() I hope this helps. Regards, -- Lars Gust?bel lars at gustaebel.de The power of accurate observation is called cynicism by those who have not got it. (George Bernard Shaw) From hniksic at xemacs.org Wed Jul 14 04:17:58 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 14 Jul 2010 10:17:58 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> Message-ID: <8739vma349.fsf@busola.homelinux.net> "Alf P. Steinbach /Usenet" writes: > Also, things like the 'owned' option is just asking for trouble. Isn't owned=true (or equivalent) a necessity when initializing from a PyObject* returned by a function declared to return a "new reference"? How does your API deal with the distinction between new and borrowed references? From downaold at gmail.com Wed Jul 14 04:32:37 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 10:32:37 +0200 Subject: floatref In-Reply-To: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> References: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> Message-ID: <7102D8D5-CC41-4C7E-A480-D7827FBD525D@gmail.com> On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > >> Hi all, >> >> I have two objects that should both be able to alter a shared >> float. So >> i need something like a mutable float object, or a float reference >> object. Does anybody know if something like that exists? I know >> it's not >> hard to build, but I have a feeling that there should be a standard >> solution to it. > > One standard solution would be to wrap the float in a class as an > attribute. I think the nicest solution is to do this with a wrapping descriptor class. Thanks for your input! Cheers, Roald From info at egenix.com Wed Jul 14 05:36:09 2010 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 14 Jul 2010 11:36:09 +0200 Subject: eGenix at EuroPython 2010 Message-ID: <4C3D8509.10907@egenix.com> ________________________________________________________________________ eGenix at EuroPython 2010 ________________________________________________________________________ Meet up with eGenix at this year's EuroPython Conference in Birmingham, UK. The EuroPython Conference is the one of the premier conferences for Python users and developers. This year it is being held from the 19th to 22th July in Birmingham, UK. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/EuroPython-Conference-2010.html ________________________________________________________________________ MEET UP WITH EGENIX AT EUROPYTHON eGenix was one of the founding members of the EuroPython conference team and played a major role in organizing the first EuroPython conference in the year 2002. Since then we have attended every EuroPython conference to meet up face-to-face with the many people we know from the Python & Zope communities and the many people that we don't yet know from these communities -- if you are interested in meeting with us, please drop us a note so that we can arrange a meeting: info at egenix.com. ________________________________________________________________________ EGENIX TALKS AT EUROPYTHON 2010 At this year's EuroPython, eGenix will be giving a talk about an interesting custom project we successfully finished recently: Running Ghana VAT on Python --------------------------- At the EuroPython 2009 conference, we gave a lightning talk showcasing an eGenix Custom Python Project that we have been working on for our client Aya Technologies, Switzerland: EuroPython 2009 - Making 50 Mio. EUR per year using Python http://www.egenix.com/go23/ This year, we will present the fantastic results of that project, go into more depth, analyze the problems we faced and how we solved them. Marc-Andr?, CEO of eGenix, will be giving this presentation on Monday, July 19th in the Library Theatre: http://www.europython.eu/talks/timetable/ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 14 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2010-07-19: EuroPython 2010, Birmingham, UK 4 days to go ::: 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 lists at cheimes.de Wed Jul 14 05:37:29 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jul 2010 11:37:29 +0200 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: > I know, I just wondered if there is a *standard* solution. Yeah, you have to reset your brain and switch to Python mode. *scnr* Seriously, your inquiry sounds like you are trying to code C in Python. I'm using Python for more than seven years and I've never felt the need for a mutable float ref or something similar. Well, except for the first year when my brain was still in C pointer mode. :) From newsuser at stacom-software.de Wed Jul 14 05:48:52 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Wed, 14 Jul 2010 11:48:52 +0200 Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) In-Reply-To: References: Message-ID: Mark Dickinson schrieb: > >> BTW: I'm tied to version 2.5 of python > > Have you tried using pickle protocol 1 or 2, instead of pickle > protocol 0? That may well solve your problem. (Those > protocols write out the binary form of a float directly, instead > of reading and writing a string representation.) > Thanks a lot, it looks like it solves the problem using another version of the protocol Regards From Maria.Reinhammar at accalon.com Wed Jul 14 06:23:24 2010 From: Maria.Reinhammar at accalon.com (Maria R) Date: Wed, 14 Jul 2010 03:23:24 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> I can second the stated opinion that Python per se is stable enough. We deliver production systems running 24/7 with uptimes counted in several months and from what I can see, compared to the OP's app, ours is vastly more complex. The only Python-related issue we have encountered so far, wrt to stability, is how timers are working. Extensive creation of timer threads have locked up after some indeterminable time. We found that the issue was probably related to some update in Windows at the time. We do not know whether this issue is resolved (we encountered it back in Python 1.4) and we rewrote our code to use timers differently. I also second that partitioning the solution in working (server) parts and GUI (client) parts is important. I do not second the generally outspoken distrust in Windows. Indeed, I would prefer *nix/*nux but in our case, stability concerns is not one of the issues behind that. We use threading to a certain extent (in addition to partioning into processes). One approach we have, and have shown very useful to gain stability, is to use Exception handling carefully and extensively. We catch *every* exception, report and counteract but do not allow the process/thread to die. This is not a trival approach, by no means, but when one know the app sufficiently, it can be applied with good results. Just my 2 c //Maria From alf.p.steinbach+usenet at gmail.com Wed Jul 14 06:39:17 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 12:39:17 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <8739vma349.fsf@busola.homelinux.net> References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> <8739vma349.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic, on 14.07.2010 10:17: > "Alf P. Steinbach /Usenet" writes: > >> Also, things like the 'owned' option is just asking for trouble. > > Isn't owned=true (or equivalent) a necessity when initializing from a > PyObject* returned by a function declared to return a "new reference"? No, not quite. Consider this signature (PyCXX): String( PyObject* pyob, bool owned = false ) versus this (cppy): PyString( PyPtr object ) With the first signature, every time you construct a String you have to remember to (explicitly or implicitly) set the bool flag correctly depending on where the actual argument value comes from. With the second signature the /type/ of the actual argument decides, automatically, so there's much less room for messing things up. With the second signature, if the actual argument is a raw PyObject* pointer then it's not owned, and the PyPtr formal argument doesn't increment the reference count but just takes ownership. If the actual argument, on the other hand, is a PyPtr, then the object is owned by the collection of PyPtr instances that refer to the object, and the new formal argument PyPtr instance then increments the reference count. In passing, if it should happen that the Python community uses the word 'owned' in the opposite sense of what's conventional in C++, then I guess & hope you'll figure out what I mean from this description. PyPtr currently looks like this (complete code): // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (c) Alf P. Steinbach, 2010. #ifndef CPPY_PYPTR_H #define CPPY_PYPTR_H #include //----------------------------------------- Dependencies: #include #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { using namespace cppx; enum DoAddRef {}; class PyPtr { private: PyObject* p_; public: typedef cppy::DoAddRef DoAddRef; PyPtr( PyObject* p = 0 ): p_( p ) {} PyPtr( PyObject* p, DoAddRef ): p_( p ) { assert( p != 0 ); Py_INCREF( p_ ); } PyPtr( PyPtr const& other ): p_( other.p_ ) { Py_XINCREF( p_ ); } ~PyPtr() { Py_XDECREF( p_ ); } void swapWith( PyPtr& other ) { std::swap( p_, other.p_ ); } PyPtr& operator=( PyPtr other ) { swapWith( other ); return *this; } PyObject* get() const { return p_; } PyObject* release() { PyObject* const result = p_; p_ = 0; return result; } }; inline PyObject* withAddedRef( PyObject* p ) { Py_INCREF( p ); return p; } inline PyObject* pyNoneRef() { return withAddedRef( Py_None ); } } } // namespace progrock::cppy #endif As you can see at the end there, there is 'withAddedRef' and 'pyNoneRef', and for that matter the 'DoAddRef' and the 'release()' method, for the cases where PyPtr default handling doesn't quite cut it... :-) > How does your API deal with the distinction between new and borrowed > references? See above. There are some cases where it must be dealt with, but the main idea is to encode that into /types/, instead of as context-dependent figure-it-out. That's also the main idea of C++ as compared to C, to encode much more into types, which helps both for compile time error detection and for automating things (like above), which is Very Nice, but which also can make for enormous waste of time trying to make the darned language do what you want it to do! :-) Cheers & hth., - Alf Disclaimer: it's late in the day/night for me, so the above explanation may have big logic holes, mispelings and so on, but I hope it gives the idea. -- blog at From johannes.black at gmail.com Wed Jul 14 07:21:54 2010 From: johannes.black at gmail.com (joblack) Date: Wed, 14 Jul 2010 04:21:54 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> > | > | Starting point: > | ... > | ? ? ? ? self.status['text'] = 'Processing ...' > | ? ? ? ? try: > | ? ? ? ? ? ? cli_main(argv) > | ? ? ? ? except Exception, e: > | ? ? ? ? ? ? self.status['text'] = 'Error: ' + str(e) > | ? ? ? ? ? ? return > | ... > | cli_main: > | > | ? ? keypath, inpath, outpath = argv[1:] > | ... > | ? ? with open(inpath, 'rb') as inf: > | ? ? ? ? serializer = PDFSerializer(inf, keypath) > | ? ? ? ? with open(outpath, 'wb') as outf: > | ? ? ? ? ? ? filenr = outf.fileno() > | ? ? ? ? ? ? serializer.dump(outf) > | ? ? return 0 > | > | PDFSerializer.dump: > | > | ? ? def dump(self, outf): > | ? ? ? ? self.outf = outf > | ... > > See that you set serializer.outf to the outf you open in cli_main? > Any attempt to use serializer _after_ exiting the "with open(outpath, > 'wb') as outf" will use serializer.outf, but the outf is now closed. > And thus itsfiledescriptoris invalid. Okay, I changed it to a try: ... finally: block where I open the file and in finally I close it. Nothing has changed. The error still occures. Doesn't the with open(outpath, 'wb') as outf: clause has to wait until the pdfserialiser.dump method has finished anyway? IMHO it can't just call it and immediately close it. At least the try: finally: construct should work? Or does it the same (call the method and immediately jump to the finally close)? Would it work if I would write: with closing(outpath, 'wb') as outf: ? I'm a little bit confused about Python's strange processing ... From python.list at tim.thechases.com Wed Jul 14 07:27:05 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 14 Jul 2010 06:27:05 -0500 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: References: <4c3cfb76$0$20964$426a74cc@news.free.fr> <4C3D00EB.1010203@mrabarnett.plus.com> Message-ID: <4C3D9F09.1050207@tim.thechases.com> On 07/13/2010 09:22 PM, Shashwat Anand wrote: >> You could write: >> >> rsl = f[len(prefix):] if f.startswith(prefix) else f > > Or you can just do split and join, "".join(f.split(prefix, 1)) will do. This suggestion breaks if the prefix occurs within the string rather than at the beginning: f = "this has file:// inside it" prefix = "file://" So your suggestion really just operates like f.replace(prefix, '', 1) -tkc From antonyjeevaraj at rediffmail.com Wed Jul 14 07:48:48 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Wed, 14 Jul 2010 04:48:48 -0700 (PDT) Subject: MAKE UPTO $5000 MONTHLY! $2000 INYOUR FIRST 30 DAYS! Message-ID: <3b66596d-fbef-4185-b363-3af1a2c0d739@p11g2000prf.googlegroups.com> MAKE UPTO $5000 MONTHLY! $2000 INYOUR FIRST 30 DAYS! Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://www.freesitesignup.com/a/coupon.php?id=3448 Get paid for your real work and earn awesome $$$$ From micayael at gmail.com Wed Jul 14 08:14:08 2010 From: micayael at gmail.com (micayael) Date: Wed, 14 Jul 2010 05:14:08 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Jul 13, 5:35?pm, Thomas Jollans wrote: > On 07/13/2010 09:55 PM, micayael wrote: > > > Hi. > > > I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 > > the adodb and psycopg2 module (sudo apt-get install python-adodb > > python-psycopg2) but when I put this > > > import adodb > > print adodb.NewADOConnection('postgres') --> None > > > but with > > > print adodb.NewADOConnection('mysql') --> > > > > http://packages.ubuntu.com/lucid/python-adodb > > Recommends: python-psycopg (Package not available) > > If it says it wants psycopg, I wouldn't expect it to work with psycopg2, > which is probably quite different in some way - otherwise it would be > called the same. > > ?- Thomas Thanks Thomas. :-( then adodb today dosn't work with postgres (at least on ubuntu) right? From fetchinson at googlemail.com Wed Jul 14 08:27:40 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jul 2010 14:27:40 +0200 Subject: eGenix at EuroPython 2010 In-Reply-To: <4C3D8509.10907@egenix.com> References: <4C3D8509.10907@egenix.com> Message-ID: > EuroPython 2009 - Making 50 Mio. EUR per year using Python > http://www.egenix.com/go23/ This link returns a 404. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mohana2004 at gmail.com Wed Jul 14 08:37:43 2010 From: mohana2004 at gmail.com (Monyl) Date: Wed, 14 Jul 2010 05:37:43 -0700 (PDT) Subject: Identify the Color of an Image Message-ID: Hi, 1. How can I find the color of an image present the webpage? 2. How to identify the font type of the selected text present in the content of the web page It would be much helpfull, if anyone responds to it ASAP Thanks Mohmyda From knny.myer at gmail.com Wed Jul 14 08:58:16 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Wed, 14 Jul 2010 05:58:16 -0700 (PDT) Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> <4c3cc937$0$22938$e4fe514c@news.xs4all.nl> Message-ID: <26baa0df-7ac7-4502-94a8-7faaf9b77316@q22g2000yqm.googlegroups.com> On Jul 13, 4:14?pm, Hans Mulder wrote: > Chris Rebert wrote: > > `where` seems to be a zsh built-in: > > $ # I'm in UR bash > > $ nonexistent > > -bash: nonexistent: command not found > > $ where bash > > -bash: where: command not found > > > And not everyone has zsh installed, so... > > I don't see why one shouldn't use the standard `which` *nix command instead. > > Because `which` ia a C shell script. ?It reads your .cshrc, to see which > aliases would be defined if you were to use the C shell, but it doesn't > look at your .bashrc. > > You're probably better off using `type`: it knows about built-ins and > shell functions and that sort of stuff: > > $ which type > /usr/bin/type > $ type type > type is a shell builtin > $ > > Guess which answer is more relevant to you ..... > > HTH, > > -- HansM Oh thanks, Hans! `type` seems to a good alternative. Surely it can also get the job (better) done. From nathan.alexander.rice at gmail.com Wed Jul 14 09:21:17 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 14 Jul 2010 09:21:17 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: The better question is, do I ever use them? Thinking back over the code I've written in the last couple of years, I would say probably two or three times (mostly in unit tests). I've had to code around string's sequence behavior DOZENS of times. Is it nifty that strings can be sliced like that? Sure. In general my experience has been that the string methods (and some misc functions in other modules) do a better job in simple cases, and regular expressions do a better job in complex cases. I just don't see string slicing having utility that is irreplaceable, and it is bug-inducing in many cases, or at the very least it can propagate programming errors way down stream. Ultimately, I highly doubt it's going anywhere, so it's a moot point. I definitely feel that python is trading real usability for "flash" with string slicing though. On Tue, Jul 13, 2010 at 8:48 PM, Aahz wrote: > [Original not available on my swerver, responding here] > > >On 7/11/10 10:03 PM, Nathan Rice wrote: > >> > >> Yeah, I long ago filed the in place place in the same folder as > >> strings-as-sequences, all() returning True for an empty iterable and any > >> returning True rather than the thing which triggered it. > > Because I love to repeat myself: > > "...string iteration isn't about treating strings as sequences of strings, > it's about treating strings as sequences of characters. The fact that > characters are also strings is the reason we have problems, but characters > are strings for other good reasons." --Aahz > http://mail.python.org/pipermail/python-3000/2006-April/000897.html > > Do you really want to give up Python's lovely string-slicing > capabilities? > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Jul 14 09:24:31 2010 From: no.email at please.post (kj) Date: Wed, 14 Jul 2010 13:24:31 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) Message-ID: I have a C library function hg that returns a long double, so when I import it using C types I specify this return type like this: MYLIB.hg.restype = ctypes.c_longdouble But certain non-zero values returned by hg appear as zero Python-side. If I modify hg so that it prints out its value right before returning it, I get stuff like the following: >>> 0 == MYLIB.hg(100, 200, 100, 6000) from hg: 2.96517e-161 False >>> 0 == MYLIB.hg(200, 200, 200, 6000) from hg: 5.28791e-380 True So, although the value returned by hg in the second invocation above is 5.28791e-380, Python sees it as 0. What am I doing wrong? TIA! ~K From ptmcg at austin.rr.com Wed Jul 14 09:40:58 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 14 Jul 2010 06:40:58 -0700 (PDT) Subject: nicer way to remove prefix of a string if it exists References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: <10092676-6c13-4b78-87d3-de0a19e47a07@g19g2000yqc.googlegroups.com> On Jul 13, 6:49?pm, News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > Here is an iterator solution: from itertools import izip def trim_prefix(prefix, s): i1,i2 = iter(prefix),iter(s) if all(c1==c2 for c1,c2 in izip(i1,i2)): return ''.join(i2) return s print trim_prefix("ABC","ABCDEFGHI") print trim_prefix("ABC","SLFJSLKFSLJFLSDF") Prints: DEFGHI SLFJSLKFSLJFLSDF -- Paul From jwhughes at hughesconcepts.com Wed Jul 14 10:21:32 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 10:21:32 -0400 Subject: Issue with logging.config In-Reply-To: References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: Peter, Thanks for the information. I sent an email to the maintainer and got some information that helped me continue with this. My solution was to change line 785 of handlers.py to self.socket.sendto(bytes(msg, 'ascii'), self.address) After I made the change, I got exactly what I was looking for. Joe On Jul 13, 2010, at 8:02 AM, Peter Otten wrote: > Joe Hughes wrote: > >> I'm doing some work with logging.config and I'm running into an >> interesting situation. I've run this by python-help, but that didn't help >> so I thought I would send to the list. Here is the config file >> >> [loggers] >> keys=root,log,syslog >> >> [handlers] >> keys=console,log,syslog >> >> [formatters] >> keys=rootFormat,logFormat,syslogFormat >> >> [logger_root] >> level=DEBUG >> handlers=console >> >> [logger_log] >> level=DEBUG >> handlers=log >> qualname=log >> >> [logger_syslog] >> level=DEBUG >> handlers=syslog >> qualname=syslog >> >> [handler_console] >> class=StreamHandler >> level=DEBUG >> formatter=rootFormat >> args=(sys.stdout,) >> >> [handler_log] >> class=handlers.RotatingFileHandler >> level=DEBUG >> formatter=logFormat >> args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) >> propagate=0 >> >> [handler_syslog] >> class=handlers.SysLogHandler >> level=DEBUG >> formatter=syslogFormat >> host=141.232.41.205 >> port=handlers.SYSLOG_UDP_PORT >> facility=LOG_LOCAL0 >> > args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) >> >> [formatter_rootFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> [formatter_logFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> [formatter_syslogFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> and the python code >> >> ######################################################################## >> # Imports >> ######################################################################## >> import logging >> import logging.config >> import os >> import re >> from threading import Thread >> >> ######################################################################## >> # Constants >> ######################################################################## >> CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' >> MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' >> >> ######################################################################## >> # Classes >> ######################################################################## >> >> ######## >> # PingIt >> ######## >> class PingIt(Thread): >> def __init__(self, mcuIP): >> Thread.__init__(self) >> self.ip = mcuIP >> self.status = -1 >> >> def run(self): >> pinging = os.popen("ping -n 2 " + self.ip, 'r') >> >> while 1: >> line = pinging.readline() >> >> if not line: >> break >> >> gotResponse = re.findall(PingIt.lifeline, line) >> >> if gotResponse: >> self.status = int(gotResponse[0]) >> >> ######################################################################## >> # Main Routine >> ######################################################################## >> # >> # Get the logger configuration information >> # >> logging.config.fileConfig(CONFIG_FILENAME) >> >> # >> # Check if running from command line and create logger >> # >> if os.environ.get('PROMPT'): >> # >> # create logger for output to stdout >> # >> logger = logging.getLogger('root') >> else: >> # >> # create logger for output to logfile >> # >> logger = logging.getLogger('log') >> >> # >> # Create logger for syslog output >> # >> syslog = logging.getLogger('syslog') >> >> # >> # Declare variables >> # >> PingIt.lifeline = re.compile(r"Received = (\d)") >> mcu_dict = {} >> ping_list = [] >> status = ("Not responding", "Responded to only 1 ping of 2", "Alive") >> >> # >> # Open the MCU file >> # >> mcu_file = open(MCU_LIST_FILENAME, 'r') >> >> # >> # Loop through the contents of the MCU file and ping the IPs >> # >> for mcu in mcu_file: >> # >> # mcu file contents example >> # 192.168.97.227 MCU_HMSTD >> # >> # mcu_info[0] = MCU IP Address >> # mcu_info[1] = MCU Name >> # >> mcu_info = mcu.split() >> mcu_dict[mcu_info[0]] = mcu_info[1] >> current = PingIt(mcu_info[0]) >> logger.info("Pinging " + mcu_info[1]) >> ping_list.append(current) >> current.start() >> >> # >> # Loop through ping list and print the response >> # >> for pinged in ping_list: >> pinged.join() >> logger.info("Status - " + mcu_dict[pinged.ip] + " is " + >> status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + >> " is " + status[pinged.status]) >> >> This is the output from the code >> >> 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding >> msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is >> Not responding >> address = ('141.232.41.205', 514) >> Traceback (most recent call last): >> File "C:\Python31\lib\logging\handlers.py", line 786, in emit >> self.socket.sendto(msg, self.address) >> TypeError: sendto() takes exactly 3 arguments (2 given) >> 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not >> responding >> >> This is the handlers.py code from the library. I added the print >> statement to figure out why it is asking for three args but only getting >> two. >> >> Line 777 of handlers.py >> >> try: >> if self.unixsocket: >> try: >> self.socket.send(msg) >> except socket.error: >> self._connect_unixsocket(self.address) >> self.socket.send(msg) >> else: >> print('msg = ', msg, '\naddress = ', self.address) >> self.socket.sendto(msg, self.address) >> except (KeyboardInterrupt, SystemExit): >> raise >> except: >> self.handleError(record) >> >> line 790 of handlers.py >> >> This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea >> about why this happening I would appreciate knowing what the issue is. > > The error can be reproduced with > > Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import logging >>>> from logging.handlers import SysLogHandler >>>> handler = SysLogHandler() >>>> logger = logging.getLogger() >>>> logger.addHandler(handler) >>>> logger.critical("yadda") > Traceback (most recent call last): > File "/usr/lib/python3.1/logging/handlers.py", line 785, in emit > self.socket.sendto(msg, self.address) > TypeError: sendto() takes exactly 3 arguments (2 given) > > This is is a known bug, see http://bugs.python.org/issue7077 > > Peter > > > -- > http://mail.python.org/mailman/listinfo/python-list From kaklis at gmail.com Wed Jul 14 10:52:30 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 14 Jul 2010 07:52:30 -0700 (PDT) Subject: stdiodemo (twisted-python) and enable command history Message-ID: <2ff970a1-ddf9-465d-a1c3-d9c774f84d08@k39g2000yqb.googlegroups.com> Hello again to all, While playing and extending stdiodemo.py, a came up with a thought of adding command line history. Is this possible? Any hints? Thanks Antonis K. From ericjvandervelden at gmail.com Wed Jul 14 10:54:58 2010 From: ericjvandervelden at gmail.com (Eric J. Van der Velden) Date: Wed, 14 Jul 2010 07:54:58 -0700 (PDT) Subject: list.insert Message-ID: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Hi, I understand this: >>> l=[1,2,3] >>> l[1:2]=[8,9] >>> l [1,8,9,3] But how do you do this with list.insert? Thanks, Eric J. From kentilton at gmail.com Wed Jul 14 11:19:32 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Wed, 14 Jul 2010 11:19:32 -0400 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c3dd58a$0$4989$607ed4bc@cv.net> Steven D'Aprano wrote: > On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: > >> The moral? If you look for the spam, you'll find it. > > And if you *don't* look for spam, you can be sure that some goose will > reply to it and get it past your filters. Thanks for that Kenneth, if > that is your name and you're not a Xah Lee sock-puppet. Let me see if I have this right. Your technique for reducing unwanted traffic is to openly insult one of the participants? That is how you clean things up? Because most people on Usenet respond well to personal insults and hush up? I have so much to learn! Or was it this? > > Followups set to a black hole. > > That works? Amazing. Here, I'll show you what spam looks like: my steadily-improving revolution in learning Algebra: http://teamalgebra.com/ kt -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From cnnshoe006 at gmail.com Wed Jul 14 11:25:12 2010 From: cnnshoe006 at gmail.com (cnnshoe) Date: Wed, 14 Jul 2010 08:25:12 -0700 (PDT) Subject: Wholesale Sports Shoes Clear Air Force One AAA++quality(www.cnnshoe.com) Message-ID: <74294e2e-5b43-4731-8a40-8b33b87d6980@w15g2000pro.googlegroups.com> supply sports shoes. The brand Sports shoes basketball shoes, Boot, walling shoes, Athletic shoes, Jogging shoes, running shoes, leather shoes, football, shoe sports shoe Footwear Sneaker, Shox Max Rift T- shirts, womens t-shirts, Clothing womens clothing, wear hats Caps Jersey jeans Sock Jacks, Watches, wallet, handbags, and Jeans Lady Clothing and so on. Please contact us by email to get more information. please kindly visite our website: http://www.cnnshoe.com msn: cnnshoe2010 at hotmail.com email: cnnshoe at gmail.com From alanwilter at gmail.com Wed Jul 14 11:38:08 2010 From: alanwilter at gmail.com (Alan) Date: Wed, 14 Jul 2010 16:38:08 +0100 Subject: python3: help with subprocess Message-ID: Hi there, Module commands is gone in python3, so I am trying subprocess. So please I would appreciate if someone can tell me how to do this better: before I had: cmd = 'uname -a' out = commands.getoutput(cmd) 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' now: out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE).communicate()[0][:-1] b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with getoutputs I didn't have. But what's giving headache is this "b'..." in the beginning. Can someone explain, point me to where I can now about it and how to make this better? I wanted a plain string in out. Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Jul 14 11:40:20 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 14 Jul 2010 08:40:20 -0700 (PDT) Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> On Jul 14, 3:21?pm, Joe Hughes wrote: > ? ? ? ? Thanks for the information. ?I sent an email to the maintainer and got some information that helped me continue with this. ?My solution was to change line 785 of handlers.py to > > self.socket.sendto(bytes(msg, 'ascii'), self.address) > > After I made the change, I got exactly what I was looking for. > What I suggested was this: http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal-with.html Of course your change may work for you, but it's not a change we can have in the stdlib - since not everyone will be using ASCII for everything. Regards, Vinay Sajip From emile at fenx.com Wed Jul 14 11:41:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 14 Jul 2010 08:41:11 -0700 Subject: list.insert In-Reply-To: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> References: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Message-ID: On 7/14/2010 7:54 AM Eric J. Van der Velden said... > Hi, > > I understand this: > >>>> l=[1,2,3] >>>> l[1:2]=[8,9] >>>> l > [1,8,9,3] > > But how do you do this with list.insert? > >>> l = [1,2,3,4] >>> l[1:2]="" >>> dummy = [l.insert(1,x) for x in reversed([8,9])] Emile From urban.yoga.journeys at gmail.com Wed Jul 14 11:42:03 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Wed, 14 Jul 2010 08:42:03 -0700 (PDT) Subject: python app development References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: On Jul 3, 9:59?pm, Terry Reedy wrote: > On 7/3/2010 1:48 PM,mo reinawrote: > > > an anyone recommend a resource (book,tutorial,etc.) that focuses on > > application development in python? something similar to Practical > > Django Projects, but for stand alone applications instead of web apps > > (for now). > > > i'm in a bit of a funny place, i have a decent/good grasp of python > > syntax and my logic isn't bad, but i have no clue on how to assemble > > an application, i seem to be stuck on writing scripts. > > > i've looked at the source of a few projects but the flow is way over > > my head, i understand the syntax but not the logic, which is why i'm > > looking for a project-cenetered learning resource, instead of a > > reference or language-feature resource. also, it seems that a lot of > > app programming is 90% gui bindings, with very little actual code, or > > am i totally way off mark? > > If the app is a gui app and if logic is overly intermixed with gui > stuff, I am sure it can seem like that. Many recommend the MVC > model-view-controller model for app design. Even that can be confusing; > to me it should be model-controller-view, even though that is harder to > say. What are the data (values and objects) and how are they stored? > What are the rules for manipulating the data and objects? And then, and > only then, how to communicate with the user? > > > > > i recently picked up the django practical projects book, and in a few > > days i re-wrote a website i did with django. i feel it was the book's > > project-centric approach that made this possible. > > Another issue is who controls the flow of interactions, the user or the > code. For instance, a gui form used for input tends to direct the user > along a linear path. The same form, used for edit, presents existing > data and allows the user to pick and choose the fields to edit. This > distinction, along with MVC ideas, is important for reading source code. > > I have mostly seen this issue discussed in game reviews and game design > writing. In computer games, there is the same general difference between > a linear obstacle course game and a world to be explored in whatever > order one wants. (And there are some with both an explorable world *and* > a (somewhat optional) linear main quest line.) > > I am not familiar with any general app design books, but I have seen > game design articles and books that are on a par with writing about web > design. There are other books on business apps. > > -- > Terry Jan Reedy so you're suggesting: -write core algorithm(model) -link algorithm(s) with each other and a central menu, if applicable(controller) -write views for gui or cli(view) this is actually the path that i follow when writing django apps, and is the sequence that is being used in "Practical Django Projects", where first the different classes/data structures are written, then linked together through the url file, and finally html is written for each "view". From gherron at islandtraining.com Wed Jul 14 11:51:23 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 14 Jul 2010 08:51:23 -0700 Subject: Identify the Color of an Image In-Reply-To: References: Message-ID: <4C3DDCFB.4020505@islandtraining.com> On 07/14/2010 05:37 AM, Monyl wrote: > Hi, > > 1. How can I find the color of an image present the webpage? > > 2. How to identify the font type of the selected text present in the > content of the web page > > It would be much helpfull, if anyone responds to it ASAP > > Thanks > Mohmyda > Please be clearer about what you want. 1. An image does not "have" a color, although each pixel in an image does have a color. 2. Text in a web page does not (necessarily) have a font, although the display engine will use a font of its choice to render text. And my browser will probably use a different font than yours. From nagle at animats.com Wed Jul 14 12:01:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 14 Jul 2010 09:01:36 -0700 Subject: Identify the Color of an Image In-Reply-To: References: Message-ID: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> On 7/14/2010 5:37 AM, Monyl wrote: > Hi, > > 1. How can I find the color of an image present the webpage? > > 2. How to identify the font type of the selected text present in the > content of the web page > > It would be much helpfull, if anyone responds to it ASAP > > Thanks > Mohmyda "Selected text"? Selected how? "Selected" implies some form of user interface, like a browser. If you're doing something in a browser, look into Firefox and Greasemonkey. John Nagle From bsk16 at case.edu Wed Jul 14 12:03:51 2010 From: bsk16 at case.edu (Ben Kaplan) Date: Wed, 14 Jul 2010 09:03:51 -0700 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: On Jul 14, 2010, at 8:38 AM, Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So please I would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with getoutputs I didn't have. But what's giving headache is this "b'..." in the beginning. > > Can someone explain, point me to where I can now about it and how to make this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan There are 2 string types in Python: byte strings and unicode strings. In Python 2.x, they were called str and unicode, the default was str, and unicode was signaled by prefixing the string with a u. In python 3.x, they are called bytes and str. str (which is what used to be unicode) is the default, and a byte string (what used to be str) is signaled by putting a b in front of the string. Unicode is an abstract concept. Python can move it around internally, but the only thing you can send to other computers and programs is a sequence of bytes. If you want to convert the byte string to a unicode string, you have to decode it afterwards. out = out.decode("utf-8") From gherron at islandtraining.com Wed Jul 14 12:04:58 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 14 Jul 2010 09:04:58 -0700 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: <4C3DE02A.7060802@islandtraining.com> On 07/14/2010 08:38 AM, Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So > please I would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 > MacBookPro5,2 Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = > sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 > MacBookPro5,2 Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which > with getoutputs I didn't have. But what's giving headache is this > "b'..." in the beginning. > > Can someone explain, point me to where I can now about it and how to > make this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan > -- > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate > Department of Biochemistry, University of Cambridge. > 80 Tennis Court Road, Cambridge CB2 1GA, UK. > >>http://www.bio.cam.ac.uk/~awd28 << The 'b' is not part of the returned value. If you look at the *type* of the returned value, you will find that it is not a string, but rather a byte array. Printing of byte arrays displays the b'...' to indicate the type of thing begin printed. If you want a string, then you must convert the byte array to a string. For instance: str_out = out.decode('ascii') (And remember: in Python3, strings are always unicode.) Also, using out.strip() or str_out.strip() may be a better way to remove the white space. Gary Herron From michele.simionato at gmail.com Wed Jul 14 12:05:05 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jul 2010 09:05:05 -0700 (PDT) Subject: multiline input and readline Message-ID: Googling for ways to use the readline library with multiline input I found out the following stackoverflow answer: http://stackoverflow.com/questions/161495/is-there-a-nice-way-of-handling-multi-line-input-with-gnu-readline The solution is to use the rl_bind_key function, but it does not look like such function is wrapped in Python: what are my options? Notice that compatibility with pyreadline (which work on Windows) would be a plus. TIA, Michele Simionato From ethan at stoneleaf.us Wed Jul 14 12:06:34 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 14 Jul 2010 09:06:34 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3DE08A.1030808@stoneleaf.us> Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: >> Alf P. Steinbach /Usenet wrote: >>> >>> Of course there are variables, that's why the docs call them variables. >>> >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. > > If such a variable is used before it's been assigned to, then you get an > uninitialized variable exception. Clearly the variable must exist in > order for the exception to refer to it (not to mention the exception > occurring at all). Really? So it's impossible for the interpreter, upon seeing the name 'blah', to scan forward to see if 'blah' is somewhere in the function in order to give a more meaningful error message? Of course not. > def foo(): > print( blah ) > blah = "this is both an assignment and a declaration causing it to > exist" > > foo() > > Clearly when the exception is raised, referring to the variable, the > variable exists. You are the only one spouting nonsense. Have you tried this? --> def foo(): ... print locals() ... blah = 'interesting' ... print locals() ... --> foo() {} {'blah': 'interesting'} As can be clearly seen, blah does not exist before the assignment -- the *name* blah has not been *bound* to an object yet, which is also what the error message says when you try to use it before it exists: UnboundLocalError: local variable 'blah' referenced before assignment Nothing religious about it -- just the facts. ~Ethan~ From john at castleamber.com Wed Jul 14 12:20:31 2010 From: john at castleamber.com (John Bokma) Date: Wed, 14 Jul 2010 11:20:31 -0500 Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> <4c3dd58a$0$4989$607ed4bc@cv.net> Message-ID: <87hbk2592o.fsf@castleamber.com> Kenneth Tilton writes: fup2 poster > Let me see if I have this right. Your technique for reducing unwanted > traffic is to openly insult one of the participants? Heh, or just ploinking them (done). Or making them cry like a little baby: http://xahlee.org/Periodic_dosage_dir/t2/harassment.html (it had an effect for a while :-D ) -- The John Bokma guy j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From davea at ieee.org Wed Jul 14 12:24:47 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 14 Jul 2010 12:24:47 -0400 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: <4C3DE4CF.7020100@ieee.org> Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So please I > would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 > Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = > sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 > Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with > getoutputs I didn't have. But what's giving headache is this "b'..." in the > beginning. > > Can someone explain, point me to where I can now about it and how to make > this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan > In Python3, 'plain string' would be unicode. But communicate returns bytes. So convert them to a string, for example, by using str(). By default that'll assume the bytes are ASCII encoded, so if you have any characters above 7f, you'd need something more. DaveA From thomas at jollans.com Wed Jul 14 12:28:42 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 18:28:42 +0200 Subject: ctypes' c_longdouble: underflow error (bug?) In-Reply-To: References: Message-ID: <4C3DE5BA.6070701@jollans.com> On 07/14/2010 03:24 PM, kj wrote: > > > > I have a C library function hg that returns a long double, so when > I import it using C types I specify this return type like this: > > MYLIB.hg.restype = ctypes.c_longdouble > > But certain non-zero values returned by hg appear as zero Python-side. > If I modify hg so that it prints out its value right before returning > it, I get stuff like the following: > >>>> 0 == MYLIB.hg(100, 200, 100, 6000) > from hg: 2.96517e-161 > False >>>> 0 == MYLIB.hg(200, 200, 200, 6000) > from hg: 5.28791e-380 > True > > So, although the value returned by hg in the second invocation > above is 5.28791e-380, Python sees it as 0. > > What am I doing wrong? Nothing. http://docs.python.org/library/ctypes.html#fundamental-data-types c_longdouble maps to float http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex "floating point numbers are implemented using double in C" ergo, the extra precision a long double gives you versus a normal double is lost if you use Python (or, at least, ctypes) If you really want to keep the precision, you need a new/different type. ctypes won't help you. Cython and NumPy may or may not be useful here. - Thomas From __peter__ at web.de Wed Jul 14 12:35:21 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jul 2010 18:35:21 +0200 Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: Vinay Sajip wrote: > On Jul 14, 3:21 pm, Joe Hughes wrote: >> Thanks for the information. I sent an email to the maintainer and got >> some information that helped me continue with this. My solution was to >> change line 785 of handlers.py to >> >> self.socket.sendto(bytes(msg, 'ascii'), self.address) >> >> After I made the change, I got exactly what I was looking for. >> > > What I suggested was this: > > http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal- with.html > > Of course your change may work for you, but it's not a change we can > have in the stdlib - since not everyone will be using ASCII for > everything. It's not obvious to me how you'd adapt that code to work with python3.1 and the SysLogHandler. Can you give some details? Peter From ritchy_gato at hotmail.com Wed Jul 14 12:37:37 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Wed, 14 Jul 2010 09:37:37 -0700 (PDT) Subject: Some success with the "Plot" problem :D Message-ID: <1e0fcfa4-cf05-43ac-8cc6-07d8a5117bdf@5g2000yqz.googlegroups.com> Hello guys On Following the development of my ADC (Analog-to-Digital converter Residue function transference) i already got some progress with the plot problem and (much thanks to colleagues who help me in this forum and not only) i would like to show you all the progress that has already got and take the opportunity to leave some doubt: ------------------------------------------------------------------------------------- import numpy import matplotlib.pylab as plt Vref = numpy.arange(-20, 20, 0.2) Vi = numpy.arange(-10, 10, 0.1) V0 = numpy.arange(Vi.shape[0]) i = 0 while i < Vi.shape[0]: if Vi[i] > Vref[i]/4: V0[i] = 2*Vi[i]-Vref[i] elif (-Vref[i]/4)<= Vi[i] and Vi[i] <= Vref[i]/4: V0[i] = 2*Vi[i] elif Vi[i] < -Vref[i]/4: V0[i] = 2*Vi[i] + Vref[i] i = i + 1 plt.plot(V0) # this plot will make that seems stairs rising plt.show() ----------------------------------------------------------------------------------------- For now i have a draw that seems cool to initialize the second part of my objectives but anyway i would like to request some help because I'm not getting on the waveform to start at origin of the coordinate axes. I'm looking for a better way to create those initial vectors (Vi, Vref, V0), any sujestions? Forword i want them to be implemented as a function that in the start of the program, i ask the user the dimention of the arrays that they want to use. Also if you have any sujestions to improve the script you can drope it here, is always welcome. For who want's to help but don?t have much information about what i'm doing here it's a link that is pretty cool: http://www.eit.lth.se/fileadmin/eit/courses/eti220/files/lectures/2009/lec4.pdf I'll be waiting. Cheers. Ritchy. From steve at REMOVE-THIS-cybersource.com.au Wed Jul 14 12:59:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 16:59:27 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3decee$0$11101$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 09:06:34 -0700, Ethan Furman wrote: > Alf P. Steinbach /Usenet wrote: [...] >> Clearly when the exception is raised, referring to the variable, the >> variable exists. > > You are the only one spouting nonsense. Have you tried this? > > --> def foo(): > ... print locals() > ... blah = 'interesting' > ... print locals() > ... > --> foo() > {} > {'blah': 'interesting'} > > As can be clearly seen, blah does not exist before the assignment -- the > *name* blah has not been *bound* to an object yet, which is also what > the error message says when you try to use it before it exists: While I agree with your basic position that, in a meaningful sense, "blah" does not exist before it is assigned to, your explanation is invalid. In CPython, local variables in functions are optimised into pre-allocated slots. locals() is a *copy* of the actual locals, and any locals which are allocated but not defined are suppressed from the dict. >>> def f(): ... x = 5 ... if y: ... z = 1 ... return x+z ... >>> f.func_code.co_nlocals 2 >>> f.func_code.co_freevars () >>> f.func_code.co_varnames ('x', 'z') More here: http://tech.blog.aknin.name/2010/07/03/pythons-innards-code-objects/ You'll notice that in the sense of having space allocated for them in the code object, the variables already exist before the function has even been executed. But of course that's not the only sense, or even the most important one. I would argue that, in a very real sense, if you call f() with the global y set to False, that *semantically* the local z doesn't exist, even if the error message says different: > UnboundLocalError: local variable 'z' referenced before assignment -- Steven From ricaraoz at gmail.com Wed Jul 14 13:15:51 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Wed, 14 Jul 2010 14:15:51 -0300 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <4c3dd58a$0$4989$607ed4bc@cv.net> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> <4c3dd58a$0$4989$607ed4bc@cv.net> Message-ID: <4C3DF0C7.2050203@gmail.com> On 14/07/2010 12:19 p.m., Kenneth Tilton wrote: > Steven D'Aprano wrote: >> On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: >> >>> The moral? If you look for the spam, you'll find it. >> >> And if you *don't* look for spam, you can be sure that some goose >> will reply to it and get it past your filters. Thanks for that >> Kenneth, if that is your name and you're not a Xah Lee sock-puppet. > > Let me see if I have this right. Your technique for reducing unwanted > traffic is to openly insult one of the participants? That is how you > clean things up? Because most people on Usenet respond well to > personal insults and hush up? I have so much to learn! PLONK!!! From jjposner at optimum.net Wed Jul 14 13:33:52 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 14 Jul 2010 13:33:52 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3DF500.9050707@optimum.net> On 7/14/2010 12:06 PM, Ethan Furman wrote: > ... Have you tried this? > > --> def foo(): > ... print locals() > ... blah = 'interesting' > ... print locals() > ... > --> foo() > {} > {'blah': 'interesting'} > > As can be clearly seen, blah does not exist before the assignment -- the > *name* blah has not been *bound* to an object yet, which is also what > the error message says when you try to use it before it exists: As already cited, according to Section 4.1 "Naming and binding" in the Language Reference, the name "blah" *does* exist before the assignment. That's the implication of this phrase: If the name refers to a local variable that has not been bound, (BTW, "has not been bound" should really be "is not currently bound", to allow for use of *del* earlier in the block.) Try this: #-------------- def foo(): print "1. varnames:", globals()['foo'].__code__.co_varnames print "2. locals:", locals() blah = 'interesting' print "3. locals:", locals() foo() #-------------- The output (Python 2.6.5) is: 1. varnames: ('blah',) 2. locals: {} 3. locals: {'blah': 'interesting'} -John From shishaozhong at gmail.com Wed Jul 14 13:49:08 2010 From: shishaozhong at gmail.com (David) Date: Wed, 14 Jul 2010 10:49:08 -0700 (PDT) Subject: High Performance solutions are needed to do things like urlretrieve Message-ID: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> urlretrieve works fine. However, when file size get very large. It goes on forever, and even fails. For instance, one of download .zip file is of 363,096KB. Particularly, when trying to get, with urlretrieve, a zipped folder of a very large size, it could take up to 20 to 30 minutes. Often it fails, never any problem with smaller folders. Any solution for this? Regards. David From thomas at jollans.com Wed Jul 14 14:04:04 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:04:04 +0200 Subject: High Performance solutions are needed to do things like urlretrieve In-Reply-To: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> References: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> Message-ID: <4C3DFC14.8000501@jollans.com> On 07/14/2010 07:49 PM, David wrote: > > urlretrieve works fine. However, when file size get very large. It > goes on forever, and even fails. > > For instance, one of download .zip file is of 363,096KB. > > Particularly, when trying to get, with urlretrieve, a zipped folder of > a very large size, it could take up to 20 to 30 minutes. Often it > fails, never any problem with smaller folders. Any solution for this? Does this only occur with urllib, or is this the case for other software, like a web browser, or a downloader like wget? The more you try to copy, the longer it takes. The longer it takes, the more probable a problem affecting a file becomes. 20 to 30 minutes might well, depending on the network speed, be a readonable timeframe for 360M. And what does "often" mean here? In other words: Are you sure urlretrieve is to blame for your problems, why are you sure, and have you tried using urllib2 or the other urllib functions? From thomas at jollans.com Wed Jul 14 14:04:59 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:04:59 +0200 Subject: adodb.NewADOConnection('postgres') returns None In-Reply-To: References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: <4C3DFC4B.7010102@jollans.com> On 07/14/2010 02:14 PM, micayael wrote: > On Jul 13, 5:35 pm, Thomas Jollans wrote: >> On 07/13/2010 09:55 PM, micayael wrote: >> >>> Hi. >> >>> I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 >>> the adodb and psycopg2 module (sudo apt-get install python-adodb >>> python-psycopg2) but when I put this >> >>> import adodb >>> print adodb.NewADOConnection('postgres') --> None >> >>> but with >> >>> print adodb.NewADOConnection('mysql') --> >>> >> >> http://packages.ubuntu.com/lucid/python-adodb >> >> Recommends: python-psycopg (Package not available) >> >> If it says it wants psycopg, I wouldn't expect it to work with psycopg2, >> which is probably quite different in some way - otherwise it would be >> called the same. >> >> - Thomas > > Thanks Thomas. > :-( then adodb today dosn't work with postgres (at least on ubuntu) > right? It certainly looks that way. It may be possible to install an old psycopg module by hand - I'd expect that to work as well. From jwhughes at hughesconcepts.com Wed Jul 14 14:08:13 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 14:08:13 -0400 Subject: Issue with logging.config In-Reply-To: References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: <6B0AAE8C-3C20-4F42-BCB4-3607C75C6D25@hughesconcepts.com> This is why I did what I did, because I couldn't figure it out either. I did find issue 5421 at python.org which is where I got the idea for the code change. Joe On Jul 14, 2010, at 12:35 PM, Peter Otten wrote: > Vinay Sajip wrote: > >> On Jul 14, 3:21 pm, Joe Hughes wrote: >>> Thanks for the information. I sent an email to the maintainer and got >>> some information that helped me continue with this. My solution was to >>> change line 785 of handlers.py to >>> >>> self.socket.sendto(bytes(msg, 'ascii'), self.address) >>> >>> After I made the change, I got exactly what I was looking for. >>> >> >> What I suggested was this: >> >> http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal- > with.html >> >> Of course your change may work for you, but it's not a change we can >> have in the stdlib - since not everyone will be using ASCII for >> everything. > > It's not obvious to me how you'd adapt that code to work with python3.1 and > the SysLogHandler. Can you give some details? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Wed Jul 14 14:10:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jul 2010 19:10:04 +0100 Subject: High Performance solutions are needed to do things like urlretrieve In-Reply-To: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> References: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> Message-ID: <4C3DFD7C.50806@mrabarnett.plus.com> David wrote: > urlretrieve works fine. However, when file size get very large. It > goes on forever, and even fails. > > For instance, one of download .zip file is of 363,096KB. > > Particularly, when trying to get, with urlretrieve, a zipped folder of > a very large size, it could take up to 20 to 30 minutes. Often it > fails, never any problem with smaller folders. Any solution for this? > Do you have any control over the other end? If yes, then you could try transferring it in multiple chunks. From clp2 at rebertia.com Wed Jul 14 14:10:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jul 2010 11:10:08 -0700 Subject: list.insert In-Reply-To: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> References: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 7:54 AM, Eric J. Van der Velden wrote: > Hi, > > I understand this: > >>>> l=[1,2,3] >>>> l[1:2]=[8,9] >>>> l > [1,8,9,3] > > But how do you do this with list.insert? You can't clobber existing items in the list using just .insert(), so the closest you could get is something like: del l[1] l.insert(1,9) l.insert(1,8) Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Wed Jul 14 14:24:20 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Jul 2010 18:24:20 +0000 (UTC) Subject: Easy questions from a python beginner References: Message-ID: On 2010-07-11, wheres pythonmonks wrote: > I have some easy issues (Python 2.6) As of a few minutes ago, this thread had 48 postings on my news server. To paraphrase somebody famous: There are no such things as easy questions. There are, however, easy answers. And they're wrong. -- Grant Edwards grant.b.edwards Yow! Did I say I was at a sardine? Or a bus??? gmail.com From thomas at jollans.com Wed Jul 14 14:35:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:35:40 +0200 Subject: Errno 9] Bad file descriptor In-Reply-To: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: <4C3E037C.7090908@jollans.com> On 07/14/2010 01:21 PM, joblack wrote: >> | >> | Starting point: >> | ... >> | self.status['text'] = 'Processing ...' >> | try: >> | cli_main(argv) >> | except Exception, e: >> | self.status['text'] = 'Error: ' + str(e) >> | return >> | ... >> | cli_main: >> | >> | keypath, inpath, outpath = argv[1:] >> | ... >> | with open(inpath, 'rb') as inf: >> | serializer = PDFSerializer(inf, keypath) >> | with open(outpath, 'wb') as outf: >> | filenr = outf.fileno() >> | serializer.dump(outf) >> | return 0 >> | >> | PDFSerializer.dump: >> | >> | def dump(self, outf): >> | self.outf = outf >> | ... >> >> See that you set serializer.outf to the outf you open in cli_main? >> Any attempt to use serializer _after_ exiting the "with open(outpath, >> 'wb') as outf" will use serializer.outf, but the outf is now closed. >> And thus itsfiledescriptoris invalid. > > Okay, I changed it to a try: ... finally: block where I open the file > and in finally I close it. Nothing has changed. The error still > occures. Where does the error occur? If Cameron is right, it occurs somewhere completely different, when serializer.dump() is already long done, when some unsuspecting fool tries to do something with serializer.outf (such as closing it) > > Doesn't the > > with open(outpath, 'wb') as outf: > > clause has to wait until the pdfserialiser.dump method has finished > anyway? IMHO it can't just call it and immediately close it. > > At least the try: finally: construct should work? Or does it the same > (call the method and immediately jump to the finally close)? > > Would it work if I would write: > > with closing(outpath, 'wb') as outf: ? > > I'm a little bit confused about Python's strange processing ... From no at email.here.invalid Wed Jul 14 14:35:49 2010 From: no at email.here.invalid (Mladen Gogala) Date: Wed, 14 Jul 2010 18:35:49 +0000 (UTC) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Wed, 14 Jul 2010 20:04:59 +0200, Thomas Jollans wrote: > It certainly looks that way. It may be possible to install an old > psycopg module by hand - I'd expect that to work as well. Not on Ubuntu 9.10: checking PostgreSQL type catalog... /usr/include/postgresql/catalog/ pg_type.h checking for mxDateTime.h... configure: error: can't build without mx headers mgogala at nycwxp2622:/tmp/psycopg-1.1.21$ ADOdb package for PostgreSQL is broken and needs fixing. -- http://mgogala.byethost5.com From pandyan.senthil at gmail.com Wed Jul 14 14:50:22 2010 From: pandyan.senthil at gmail.com (senthi) Date: Wed, 14 Jul 2010 11:50:22 -0700 (PDT) Subject: CHANCE YOUR LIFE CLICK THEAR Message-ID: <921095ba-038d-4547-9f23-3bfbdb1d6e1d@v6g2000prd.googlegroups.com> http://www.123maza.com/dora/vvvv From no at email.here.invalid Wed Jul 14 14:51:55 2010 From: no at email.here.invalid (Mladen Gogala) Date: Wed, 14 Jul 2010 18:51:55 +0000 (UTC) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Wed, 14 Jul 2010 05:14:08 -0700, micayael wrote: > Thanks Thomas. > :-( then adodb today dosn't work with postgres (at least on ubuntu) > right? No, ADOdb doesn't work with the newer versions of Postgres. ADOdb doesn't work with Psycopg2 and the guy who maintains it did not reply to my email. That is unfortunate because ADOdb is my favorite PHP class library. It seems, though, that the Python version is not nearly as well maintained as the PHP one. -- http://mgogala.byethost5.com From tommybear at hotmail.com Wed Jul 14 15:28:58 2010 From: tommybear at hotmail.com (Thomas Tundor) Date: 14 Jul 2010 19:28:58 GMT Subject: Is Python portable/Can I install it on an USB Stick? Message-ID: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Is Python portable? Can I install it on an USB Stick? Or is Python installing (at least on WinXP) services or register some DLLs or write something into Registry? Thomas From philip at semanchuk.com Wed Jul 14 15:36:23 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jul 2010 15:36:23 -0400 Subject: Is Python portable/Can I install it on an USB Stick? In-Reply-To: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <79F74E57-287B-4723-83E5-113A17007D6C@semanchuk.com> On Jul 14, 2010, at 3:28 PM, Thomas Tundor wrote: > Is Python portable? > > Can I install it on an USB Stick? > > Or is Python installing (at least on WinXP) services or register > some DLLs or > write something into Registry? http://www.portablepython.com/ From lists at cheimes.de Wed Jul 14 15:44:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jul 2010 21:44:07 +0200 Subject: Is Python portable/Can I install it on an USB Stick? In-Reply-To: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: > Is Python portable? > > Can I install it on an USB Stick? > > Or is Python installing (at least on WinXP) services or register some DLLs or > write something into Registry? Yes, a single user installation of Python is portable. An installation for every user is not portable since it installs some DLLs in system32. Some features and extensions are not portable, e.g. COM with pywin32 because they require registered DLLs. Christian From tino at wildenhain.de Wed Jul 14 16:22:59 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 14 Jul 2010 22:22:59 +0200 Subject: floatref In-Reply-To: References: Message-ID: <4C3E1CA3.7020503@wildenhain.de> Am 13.07.2010 19:26, schrieb Roald de Vries: > Hi all, > > I have two objects that should both be able to alter a shared float. > So i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's > not hard to build, but I have a feeling that there should be a > standard solution to it. Nice question to reflect our understanding of the basics of this language. From what I know, we have the terms: - reference - name (pointer is not really used beside from indices into lists or such) I see it this way: you have named and unnamed references to objects. This means you can bind any number of names to an object as well as reference the object in a list, tupe or set: >>> (1,2,3) # unnamed references to int objects 1,2 and 3 >>> a=(1,2,3)[1] # binds a to tuple element #1 (int 2 object) >>> b=a # now a and b are bound to the same int 2 object So back to your question: >>> a=b=1.0 # binds the names a and b to the same float object 1.0 >>> a,b (1.0, 1.0) now, there is no way to alter the float object since it is immutable (as there are str, unicode, int, long, tuple...) >>> a+=0.5 >>> a,b (1.5, 1.0) now you see even the "in place" addition creates a new object and binds the name to it. What you'd need to do would probably wrapping the float value into a class where you can simulate a mutable float by providing a constant name or reference for it within the class. For example: >>> a=b=[1.0] >>> a[0]+=0.5 >>> a,b ([1.5], [1.5]) HTH Tino From steveo at syslang.net Wed Jul 14 16:42:04 2010 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 14 Jul 2010 16:42:04 -0400 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <4C3E211C.4000207@syslang.net> On 07/12/10 21:29, quoth Kenny Meyer: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? Luke! Use the force! #! /usr/bin/python import os def is_valid_command(command): looking_good = False for ii in os.environ['PATH'].split(':'): if os.access(ii + '/' + command, os.X_OK): looking_good = True break print ["Looks not so good...", "Valid command."][looking_good] is_valid_command('python') is_valid_command('pythoon') This way you don't start up any subprocesses and you are actually doing what the shell would do for you. THE ONLY DIFFERENCE is that a persistent bash would hash all of the contents of what lives in PATH and so might have a slight shot of being faster under somewhat obscure conditions. I would strongly encourage you to not execute an arbitrary string to see if it returns a pretty return code. is_valid_command('{cd /; rm -rf /}') Warning: * It only checks if the command exists in PATH and is executable TO YOU: * Do not make fun of is_valid_command. It will get angry. * You might also want to beef it up a la pp = ii + '/' + command if os.access(pp, (os.X_OK) and not os.stat.isdir(p)): so you are checking executable files and not directories etc... * More warnings can be amplified upon over pitchers of beer. -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From luke.leighton at gmail.com Wed Jul 14 16:42:20 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 14 Jul 2010 13:42:20 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 5:44?am, rantingrick wrote: > On Jul 10, 10:59?pm, Luke Kenneth Casson Leighton > > wrote: > > source at:http://github.com/lkcl/grailbrowser > > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > > conversion of the 80 or so regex's to re has been carried out. > > entirely successfully or not is a matter yet to be determined. ?always > > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > > with a browser from 11+ years ago, it still cannot be resisted as > > grail is the only working graphical web browser in the world written > > in pure python [pybrowser is still in development, stalled]. > > > l. > > Congratulations on this effort Luke. However you know what project i > would really like to see the community get around? ...dramatic pause > here... a cross platform Python file browser! weeelll... you _could_ always just use grailbrowser :) it does still support file:// so it lists directories, shows text files and downloads anything it doesn't understand. l. From luke.leighton at gmail.com Wed Jul 14 16:47:49 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 14 Jul 2010 13:47:49 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 10:39?pm, "Martin P. Hellwig" wrote: > On 07/11/10 04:59, Luke Kenneth Casson Leighton wrote:> source at: > >http://github.com/lkcl/grailbrowser > > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > > conversion of the 80 or so regex's to re has been carried out. > > entirely successfully or not is a matter yet to be determined. ?always > > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > > with a browser from 11+ years ago, it still cannot be resisted as > > grail is the only working graphical web browser in the world written > > in pure python [pybrowser is still in development, stalled]. > > > l. > > Congrats! > Are you planning to take over the world with grail and pyjs? :-) mwahaahhah basically, yes. i'm fed up with the mozilla foundation, who have trashed python-xpcom _just_ at the point where i demonstrated its usefulness: the only reason things still work across linux distributions is due to inertia as the distros are still offering xulrunner-1.9.1, and i'm definitely fed up with the webkit developers, one in particular, whose treatment of and attitude to the work that i did to get python bindings to the DOM of webkit was beyond atrocious. so, python-based web browser it is, implement the W3C DOM API with it. hack it about, combine paul bonser's pybrowser back-end (which was where paul did most of the work, and stalled on the front-end), job done, one compliant python browser supporting W3C TR1,2 and 3 and if we're reaaallly lucky i maybe add some HTML5 features too. just don't expect it to be quick! l. From hayathms at gmail.com Wed Jul 14 16:51:01 2010 From: hayathms at gmail.com (Hayathms) Date: Thu, 15 Jul 2010 02:21:01 +0530 Subject: Please Help Message-ID: PLease anyone help me ,, program not running ------------------------------------------------------------------------------------ from tkinter import ttk from tkinter import * class Hami(ttk.Frame): def __init__(self,master=None): ttk.Frame.__init__(self,master,borderwidth=5) self.grid(column=0,row=0,sticky=('W,E,N,S'),padx=5,pady=5) class Honey(ttk.Label): def __init__(self,master=None,te='Honey'): ttk.Label.__init__(master,text=te) self.grid(column=0,row=0) root=Tk() root.title('Employee') root.option_add('*tearOff',FALSE) sam=Hami(root) harmain=Honey(master=sam) root.mainloop() ------------------------------------------------------------------------------------ Error is ----> Traceback (most recent call last): File "C:/Python31/hayathhh.py", line 20, in harmain=Honey(master=sam) File "C:/Python31/hayathhh.py", line 13, in __init__ self.grid(column=0,row=0) File "C:\Python31\lib\tkinter\__init__.py", line 1843, in grid_configure self.tk.call( AttributeError: 'Honey' object has no attribute 'tk' >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Jul 14 16:54:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Jul 2010 20:54:22 +0000 (UTC) Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On 2010-07-14, Steven W. Orr wrote: > On 07/12/10 21:29, quoth Kenny Meyer: > >> I have to figure out if a string is callable on a Linux system. I'm >> actually doing this: >> >> def is_valid_command(command): >> retcode = 100 # initialize >> if command: >> retcode = subprocess.call(command, shell=True) >> if retcode is 0: >> print "Valid command." >> else: >> print "Looks not so good..." >> >> is_valid_command("ls") >> >> Never mind the code, because this is not the original. The side >> effect of subprocess.call() is that it *actually* executes it, but I >> just need the return code. What are better ways of doing this? > > Luke! Use the force! > > #! /usr/bin/python > > import os > def is_valid_command(command): > looking_good = False > for ii in os.environ['PATH'].split(':'): > if os.access(ii + '/' + command, os.X_OK): > looking_good = True > break > print ["Looks not so good...", "Valid command."][looking_good] > > is_valid_command('python') > is_valid_command('pythoon') Just to be clear, that's not the same as the OP's code in two respects: 1) It doesn't handle shell builtins or aliases. 2) It determines not whether a command is valid (returns 0), but whether a command exists as an executable. "Valid" is a rather small subset of "exists". Of course the OP didn't explain what he meant by "callable", so all we have to go on is his posted code. > This way you don't start up any subprocesses and you are actually > doing what the shell would do for you. > > THE ONLY DIFFERENCE is that a persistent bash would hash all of the > contents of what lives in PATH and so might have a slight shot of > being faster under somewhat obscure conditions. No, there are other differences. See above. > I would strongly encourage you to not execute an arbitrary string to > see if it returns a pretty return code. > > is_valid_command('{cd /; rm -rf /}') > > Warning: > * It only checks if the command exists in PATH and is executable TO > YOU: Which is different than determining whether a command (including arguments) is valid (callable and returns 0). However, running a command to determine if it's valid is going to cause problems sooner or later due to side-effects of that command. For example, the first time you the command "rm /path/to/a/file" it may be valid, but the second time it won't be. > * Do not make fun of is_valid_command. It will get angry. And don't taunt happy fun ball! > * You might also want to beef it up a la > pp = ii + '/' + command > if os.access(pp, (os.X_OK) and not os.stat.isdir(p)): > so you are checking executable files and not directories etc... > * More warnings can be amplified upon over pitchers of beer. -- Grant Edwards grant.b.edwards Yow! My mind is making at ashtrays in Dayton ... gmail.com From nad at acm.org Wed Jul 14 16:57:30 2010 From: nad at acm.org (Ned Deily) Date: Wed, 14 Jul 2010 13:57:30 -0700 Subject: Getting started with python on macintosh snow leopard with mysql - need help References: Message-ID: In article , Benjamin Kaplan wrote: > On Sun, Jul 11, 2010 at 1:18 PM, dk wrote: [...] > > when i try to compile mysql-python-1.2.3 i get the following error > > returned from python setup.py build ----- > > > > building '_mysql' extension > > gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing > > -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - > > D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ > > Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ > > temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - > > D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - > > DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL > > In file included from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/unicodeobject.h:4, > > ? ? ? ? ? ? ? ? from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/Python.h:85, > > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > > ? ? ? ? ? ? ? ? from _mysql.c:29: > > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > > stdarg.h: No such file or directory > > In file included from _mysql.c:36: > > /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" > > redefined > > In file included from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/Python.h:8, > > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > > ? ? ? ? ? ? ? ? from _mysql.c:29: > > /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ > > pyconfig.h:808:1: warning: this is the location of the previous > > definition > > error: command 'gcc-4.0' failed with exit status 1 > > -- > > Strange. Seems that the package is trying to use gcc-4.0 and the > MacOSX10.4 SDK. The default version of gcc on Snow Leopard is 4.2, and > XCode only comes with the SDKs for the previous two versions of OS X. Not strange at all. The python.org Python 2.6 (which is installed to /Library/Frameworks/Python.framework) is deliberately built to be compatible with OS X 10.3.9 through 10.6 and, as such, requires gcc-4.0 and the 10.4u SDK. The latter is included in the 10.6 Xcode distribution as a separate package but is not installed by default; to build a Python C extension module for that Python, you need to go back to the Xcode installer for Snow Leopard (or download a new one from Apple) and do a custom installation of that SDK. -- Ned Deily, nad at acm.org From gherron at digipen.edu Wed Jul 14 17:14:37 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 14 Jul 2010 14:14:37 -0700 Subject: Please Help In-Reply-To: References: Message-ID: <4C3E28BD.7040309@digipen.edu> On 07/14/2010 01:51 PM, Hayathms wrote: > PLease anyone help me ,, > > program not running > ------------------------------------------------------------------------------------ > > from tkinter import ttk > from tkinter import * > > class Hami(ttk.Frame): > def __init__(self,master=None): > ttk.Frame.__init__(self,master,borderwidth=5) > self.grid(column=0,row=0,sticky=('W,E,N,S'),padx=5,pady=5) > > > class Honey(ttk.Label): > def __init__(self,master=None,te='Honey'): > ttk.Label.__init__(master,text=te) > self.grid(column=0,row=0) > > > root=Tk() > root.title('Employee') > root.option_add('*tearOff',FALSE) > sam=Hami(root) > harmain=Honey(master=sam) > root.mainloop() > ------------------------------------------------------------------------------------ > > Error is ----> > > > Traceback (most recent call last): > File "C:/Python31/hayathhh.py", line 20, in > harmain=Honey(master=sam) > File "C:/Python31/hayathhh.py", line 13, in __init__ > self.grid(column=0,row=0) > File "C:\Python31\lib\tkinter\__init__.py", line 1843, in grid_configure > self.tk.call( > AttributeError: 'Honey' object has no attribute 'tk' > >>> Here is *one* clear problem. Others may exist. Since Honey is derived from ttk.Label, Honey's constructor must call Label's constructor, (which you do), *however* when called as ttk.Label.__init__, you must provide it with the 'self' parameter. class Honey(ttk.Label): def __init__(self,master=None,te='Honey'): ttk.Label.__init__(*self*,master,text=te) # self parameter added here self.grid(column=0,row=0) -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From vinay_sajip at yahoo.co.uk Wed Jul 14 20:20:48 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 14 Jul 2010 17:20:48 -0700 (PDT) Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> On Jul 14, 7:08?pm, Joe Hughes wrote: > This is why I did what I did, because I couldn't figure it out either. ?I did find issue 5421 at python.org which is where I got the idea for the code change. Perhaps you should read the messages for issue 7077, linked to by Peter above. You'll see that according to RFC 5424, syslog UDP messages should be encoded in UTF-8 with a BOM, not ASCII. Revisions r75586 and later of the Python repository implement the correct fix for the problem. My suggestion (in the blog post I linked to) would apply to socket applications other than syslog. Regards, Vinay Sajip From candide at free.invalid Wed Jul 14 21:30:24 2010 From: candide at free.invalid (candide) Date: Thu, 15 Jul 2010 03:30:24 +0200 Subject: Splitting numeric litterals Message-ID: <4c3e64ba$0$31001$426a74cc@news.free.fr> The escape sequence \ENTER allows to split a string over 2 consecutive lines. On the other hand, it seems impossible to split a numeric litteral across multiple lines, compare : >>> "1000\ ... 000\ ... 000" '1000000000' >>> 1000\ ... 000\ File "", line 2 000\ ^ SyntaxError: invalid syntax >>> Is this the general behaviour ? So, how do you edit code containing a very very long numeric constant ? From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 21:57:25 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 01:57:25 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c3e6b05$0$28672$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 03:30:24 +0200, candide wrote: > The escape sequence \ENTER allows to split a string over 2 consecutive > lines. On the other hand, it seems impossible to split a numeric > litteral across multiple lines [...] > Is this the general behaviour ? Yes. You can't put any whitespace in the middle of a numeric literal: >>> n = 4 2 File "", line 1 n = 4 2 ^ SyntaxError: invalid syntax > So, how do you edit code containing a very very long numeric constant ? s = ( "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" ) assert len(s) == 200 n = int(s) -- Steven From python at mrabarnett.plus.com Wed Jul 14 22:02:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jul 2010 03:02:06 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c3e64ba$0$31001$426a74cc@news.free.fr> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4C3E6C1E.1010402@mrabarnett.plus.com> candide wrote: > The escape sequence \ENTER allows to split a string over 2 consecutive > lines. On the other hand, it seems impossible to split a numeric > litteral across multiple lines, compare : > > >>> "1000\ > ... 000\ > ... 000" > '1000000000' > >>> 1000\ > ... 000\ > File "", line 2 > 000\ > ^ > SyntaxError: invalid syntax > >>> > > > Is this the general behaviour ? So, how do you edit code containing a > very very long numeric constant ? Normally it's only string literals that could be so long that you might want to split them over several lines. It is somewhat unusual to have a _numeric_ literal that's very very long! For an integer literal you could use a string literal and convert it to an integer: >>> int("1000\ 000\ 000") 1000000000 >>> From candide at free.invalid Wed Jul 14 22:37:57 2010 From: candide at free.invalid (candide) Date: Thu, 15 Jul 2010 04:37:57 +0200 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c3e7491$0$10849$426a74cc@news.free.fr> MRAB a ?crit : > want to split them over several lines. It is somewhat unusual to have a > _numeric_ literal that's very very long! > I agree. But consider RSA-155 for instance ... ;) > For an integer literal you could use a string literal and convert it to > an integer: > > >>> int("1000\ > 000\ > 000") > 1000000000 > >>> OK. In C, the following code is allowed : int x=1000\ 000\ 000; but not very usefull for sure ! From rt8396 at gmail.com Wed Jul 14 22:45:01 2010 From: rt8396 at gmail.com (r) Date: Wed, 14 Jul 2010 19:45:01 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <0ab2ecae-f7d2-4025-8308-a12e07200950@t10g2000yqg.googlegroups.com> On Jul 14, 1:24?pm, Grant Edwards wrote: > As of a few minutes ago, this thread had 48 postings on my news > server. > > To paraphrase somebody famous: > > ? ? There are no such things as easy questions. ?There are, however, > ? ? easy answers. ?And they're wrong. ? ? ? ? Ha! This is the very reason i always steer clear of any post with the words "easy", "simple", or "BUSTARDS" in the title. ;-) From jwhughes at hughesconcepts.com Wed Jul 14 22:48:36 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 22:48:36 -0400 Subject: Issue with logging.config In-Reply-To: <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> Message-ID: <1F81AB9F-52FD-4527-9515-F1CF2C628265@hughesconcepts.com> Hi Vinay, I think I figured out what you are talking about after reading RFC 5424. I think this means that this code syslog.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) needs to become something like this BOM = 0xEFBBBF msg = str(BOM) + "Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status] syslog.info(msg) This would add the BOM to the message that RFC 5424 requires. Or did I totally misread it? Thanks, Joe On Jul 14, 2010, at 8:20 PM, Vinay Sajip wrote: > On Jul 14, 7:08 pm, Joe Hughes wrote: >> This is why I did what I did, because I couldn't figure it out either. I did find issue 5421 at python.org which is where I got the idea for the code change. > > Perhaps you should read the messages for issue 7077, linked to by > Peter above. You'll see that according to RFC 5424, syslog UDP > messages should be encoded in UTF-8 with a BOM, not ASCII. Revisions > r75586 and later of the Python repository implement the correct fix > for the problem. > > My suggestion (in the blog post I linked to) would apply to socket > applications other than syslog. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramercer at gmail.com Thu Jul 15 01:05:26 2010 From: ramercer at gmail.com (Adam Mercer) Date: Thu, 15 Jul 2010 00:05:26 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: Anyone have any ideas about this? Cheers Adam On Tue, Jul 13, 2010 at 16:18, Adam Mercer wrote: > Hi > > I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: > > 105 ? ? :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c > 106 ? ? :info:build swig -python > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c > SWIG/_m2crypto.i > 107 ? ? :info:build SWIG/_bio.i:64: Warning 454: Setting a > pointer/reference variable may leak memory. > 108 ? ? :info:build SWIG/_rand.i:19: Warning 454: Setting a > pointer/reference variable may leak memory. > 109 ? ? :info:build SWIG/_evp.i:156: Warning 454: Setting a > pointer/reference variable may leak memory. > 110 ? ? :info:build SWIG/_dh.i:36: Warning 454: Setting a > pointer/reference variable may leak memory. > 111 ? ? :info:build SWIG/_rsa.i:43: Warning 454: Setting a > pointer/reference variable may leak memory. > 112 ? ? :info:build SWIG/_dsa.i:31: Warning 454: Setting a > pointer/reference variable may leak memory. > 113 ? ? :info:build SWIG/_ssl.i:207: Warning 454: Setting a > pointer/reference variable may leak memory. > 114 ? ? :info:build SWIG/_x509.i:313: Warning 454: Setting a > pointer/reference variable may leak memory. > 115 ? ? :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 116 ? ? :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 117 ? ? :info:build SWIG/_util.i:9: Warning 454: Setting a > pointer/reference variable may leak memory. > 118 ? ? :info:build SWIG/_ec.i:111: Warning 454: Setting a > pointer/reference variable may leak memory. > 119 ? ? :info:build SWIG/_engine.i:162: Warning 454: Setting a > pointer/reference variable may leak memory. > 120 ? ? :info:build creating build/temp.macosx-10.6-x86_64-2.5 > 121 ? ? :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG > 122 ? ? :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd > -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include > -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG > -c SWIG/_m2crypto_wrap.c -o > build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING > 123 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': > 124 ? ? :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 125 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': > 126 ? ? :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 127 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': > 128 ? ? :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 129 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': > 130 ? ? :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 131 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': > 132 ? ? :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 133 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': > 134 ? ? :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used > 135 ? ? :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used > 136 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': > 137 ? ? :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 138 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 139 ? ? :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 140 ? ? :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token > 141 ? ? :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token > 142 ? ? :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 143 ? ? :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token > 144 ? ? :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token > 145 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': > 146 ? ? :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 147 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': > 148 ? ? :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in > signedness > 149 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': > 150 ? ? :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in > signedness > 151 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 152 ? ? :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 153 ? ? :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token > 154 ? ? :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token > 155 ? ? :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token > 156 ? ? :info:build SWIG/_m2crypto_wrap.c:6081: error: expected > declaration specifiers or '...' before 'STACK' > 157 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': > 158 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared > (first use in this function) > 159 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared > identifier is reported only once > 160 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function > it appears in.) > 161 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > 'x509_name_entry_create_by_txt': > 162 ? ? :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets > in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in > signedness > 163 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 164 ? ? :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 165 ? ? :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token > 166 ? ? :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token > 167 ? ? :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 168 ? ? :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token > 169 ? ? :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token > 170 ? ? :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token > 171 ? ? :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token > 172 ? ? :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token > 173 ? ? :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 174 ? ? :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token > 175 ? ? :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token > 176 ? ? :info:build SWIG/_m2crypto_wrap.c:6385: error: expected > declaration specifiers or '...' before 'STACK' > 177 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': > 178 ? ? :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared > (first use in this function) > 179 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 180 ? ? :info:build SWIG/_m2crypto_wrap.c:6390: error: expected > declaration specifiers or '...' before 'STACK' > 181 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': > 182 ? ? :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared > (first use in this function) > 183 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 184 ? ? :info:build SWIG/_m2crypto_wrap.c:6418: error: expected > declaration specifiers or '...' before 'STACK' > 185 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': > 186 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared > (first use in this function) > 187 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument > 3 of 'pkcs7_verify1' from incompatible pointer type > 188 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument > 4 of 'pkcs7_verify1' makes integer from pointer without a cast > 189 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments > to function 'pkcs7_verify1' > 190 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 191 ? ? :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 192 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': > 193 ? ? :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 194 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': > 195 ? ? :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared > (first use in this function) > 196 ? ? :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' > undeclared (first use in this function) > 197 ? ? :info:build SWIG/_m2crypto_wrap.c:16913: error: expected > expression before ')' token > 198 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': > 199 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared > (first use in this function) > 200 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared > (first use in this function) > 201 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: expected > expression before ')' token > 202 ? ? :info:build SWIG/_m2crypto_wrap.c:16934: error: expected > expression before ')' token > 203 ? ? :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit > declaration of function 'sk_ssl_cipher_num' > 204 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': > 205 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared > (first use in this function) > 206 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared > (first use in this function) > 207 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: expected > expression before ')' token > 208 ? ? :info:build SWIG/_m2crypto_wrap.c:16968: error: expected > expression before ')' token > 209 ? ? :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit > declaration of function 'sk_ssl_cipher_value' > 210 ? ? :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer > from integer of different size > 211 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_ssl_get_peer_cert_chain': > 212 ? ? :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared > (first use in this function) > 213 ? ? :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' > undeclared (first use in this function) > 214 ? ? :info:build SWIG/_m2crypto_wrap.c:17006: error: expected > expression before ')' token > 215 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': > 216 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared > (first use in this function) > 217 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared > (first use in this function) > 218 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: expected > expression before ')' token > 219 ? ? :info:build SWIG/_m2crypto_wrap.c:17027: error: expected > expression before ')' token > 220 ? ? :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit > declaration of function 'sk_x509_num' > 221 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': > 222 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared > (first use in this function) > 223 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared > (first use in this function) > 224 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: expected > expression before ')' token > 225 ? ? :info:build SWIG/_m2crypto_wrap.c:17061: error: expected > expression before ')' token > 226 ? ? :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit > declaration of function 'sk_x509_value' > 227 ? ? :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer > from integer of different size > 228 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_name_entry_set_data': > 229 ? ? :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets > in assignment differ in signedness > 230 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_store_ctx_get1_chain': > 231 ? ? :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared > (first use in this function) > 232 ? ? :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' > undeclared (first use in this function) > 233 ? ? :info:build SWIG/_m2crypto_wrap.c:19741: error: expected > expression before ')' token > 234 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': > 235 ? ? :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared > (first use in this function) > 236 ? ? :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' > undeclared (first use in this function) > 237 ? ? :info:build SWIG/_m2crypto_wrap.c:20573: error: expected > expression before ')' token > 238 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': > 239 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared > (first use in this function) > 240 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared > (first use in this function) > 241 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: expected > expression before ')' token > 242 ? ? :info:build SWIG/_m2crypto_wrap.c:20593: error: expected > expression before ')' token > 243 ? ? :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit > declaration of function 'sk_x509_free' > 244 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': > 245 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared > (first use in this function) > 246 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared > (first use in this function) > 247 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: expected > expression before ')' token > 248 ? ? :info:build SWIG/_m2crypto_wrap.c:20624: error: expected > expression before ')' token > 249 ? ? :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit > declaration of function 'sk_x509_push' > 250 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': > 251 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared > (first use in this function) > 252 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared > (first use in this function) > 253 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: expected > expression before ')' token > 254 ? ? :info:build SWIG/_m2crypto_wrap.c:20664: error: expected > expression before ')' token > 255 ? ? :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit > declaration of function 'sk_x509_pop' > 256 ? ? :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer > from integer of different size > 257 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_req_add_extensions': > 258 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared > (first use in this function) > 259 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared > (first use in this function) > 260 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: expected > expression before ')' token > 261 ? ? :info:build SWIG/_m2crypto_wrap.c:20890: error: expected > expression before ')' token > 262 ? ? :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments > to function 'x509_req_add_extensions' > 263 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': > 264 ? ? :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared > (first use in this function) > 265 ? ? :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' > undeclared (first use in this function) > 266 ? ? :info:build SWIG/_m2crypto_wrap.c:20981: error: expected > expression before ')' token > 267 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509v3_set_conf_lhash': > 268 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared > (first use in this function) > 269 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared > (first use in this function) > 270 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: expected > expression before ')' token > 271 ? ? :info:build SWIG/_m2crypto_wrap.c:21002: error: expected > expression before ')' token > 272 ? ? :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit > declaration of function 'x509v3_set_conf_lhash' > 273 ? ? :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer > from integer of different size > 274 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': > 275 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared > (first use in this function) > 276 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared > (first use in this function) > 277 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: expected > expression before ')' token > 278 ? ? :info:build SWIG/_m2crypto_wrap.c:21038: error: expected > expression before ')' token > 279 ? ? :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit > declaration of function 'x509v3_ext_conf' > 280 ? ? :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer > from integer of different size > 281 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_new_null': > 282 ? ? :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared > (first use in this function) > 283 ? ? :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' > undeclared (first use in this function) > 284 ? ? :info:build SWIG/_m2crypto_wrap.c:21116: error: expected > expression before ')' token > 285 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_free': > 286 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared > (first use in this function) > 287 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared > (first use in this function) > 288 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: expected > expression before ')' token > 289 ? ? :info:build SWIG/_m2crypto_wrap.c:21136: error: expected > expression before ')' token > 290 ? ? :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit > declaration of function 'sk_x509_extension_free' > 291 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_push': > 292 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared > (first use in this function) > 293 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared > (first use in this function) > 294 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: expected > expression before ')' token > 295 ? ? :info:build SWIG/_m2crypto_wrap.c:21167: error: expected > expression before ')' token > 296 ? ? :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit > declaration of function 'sk_x509_extension_push' > 297 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_pop': > 298 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared > (first use in this function) > 299 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared > (first use in this function) > 300 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: expected > expression before ')' token > 301 ? ? :info:build SWIG/_m2crypto_wrap.c:21202: error: expected > expression before ')' token > 302 ? ? :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit > declaration of function 'sk_x509_extension_pop' > 303 ? ? :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer > from integer of different size > 304 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_num': > 305 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared > (first use in this function) > 306 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared > (first use in this function) > 307 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: expected > expression before ')' token > 308 ? ? :info:build SWIG/_m2crypto_wrap.c:21229: error: expected > expression before ')' token > 309 ? ? :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit > declaration of function 'sk_x509_extension_num' > 310 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_value': > 311 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared > (first use in this function) > 312 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared > (first use in this function) > 313 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: expected > expression before ')' token > 314 ? ? :info:build SWIG/_m2crypto_wrap.c:21263: error: expected > expression before ')' token > 315 ? ? :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit > declaration of function 'sk_x509_extension_value' > 316 ? ? :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer > from integer of different size > 317 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_make_stack_from_der_sequence': > 318 ? ? :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared > (first use in this function) > 319 ? ? :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' > undeclared (first use in this function) > 320 ? ? :info:build SWIG/_m2crypto_wrap.c:21314: error: expected > expression before ')' token > 321 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_get_der_encoding_stack': > 322 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared > (first use in this function) > 323 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared > (first use in this function) > 324 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: expected > expression before ')' token > 325 ? ? :info:build SWIG/_m2crypto_wrap.c:21335: error: expected > expression before ')' token > 326 ? ? :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit > declaration of function 'get_der_encoding_stack' > 327 ? ? :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer > from integer of different size > 328 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': > 329 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared > (first use in this function) > 330 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared > (first use in this function) > 331 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: expected > expression before ')' token > 332 ? ? :info:build SWIG/_m2crypto_wrap.c:22366: error: expected > expression before ')' token > 333 ? ? :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit > declaration of function 'pkcs7_encrypt' > 334 ? ? :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer > from integer of different size > 335 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': > 336 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared > (first use in this function) > 337 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared > (first use in this function) > 338 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: expected > expression before ')' token > 339 ? ? :info:build SWIG/_m2crypto_wrap.c:22582: error: expected > expression before ')' token > 340 ? ? :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument > 4 of 'pkcs7_sign1' makes integer from pointer without a cast > 341 ? ? :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments > to function 'pkcs7_sign1' > 342 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': > 343 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared > (first use in this function) > 344 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared > (first use in this function) > 345 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: expected > expression before ')' token > 346 ? ? :info:build SWIG/_m2crypto_wrap.c:22659: error: expected > expression before ')' token > 347 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument > 3 of 'pkcs7_verify1' from incompatible pointer type > 348 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument > 4 of 'pkcs7_verify1' makes integer from pointer without a cast > 349 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments > to function 'pkcs7_verify1' > 350 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': > 351 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared > (first use in this function) > 352 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared > (first use in this function) > 353 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: expected > expression before ')' token > 354 ? ? :info:build SWIG/_m2crypto_wrap.c:22734: error: expected > expression before ')' token > 355 ? ? :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument > 3 of 'pkcs7_verify0' makes integer from pointer without a cast > 356 ? ? :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments > to function 'pkcs7_verify0' > 357 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': > 358 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared > (first use in this function) > 359 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared > (first use in this function) > 360 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: expected > expression before ')' token > 361 ? ? :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' > undeclared (first use in this function) > 362 ? ? :info:build SWIG/_m2crypto_wrap.c:23211: error: expected > expression before ')' token > 363 ? ? :info:build SWIG/_m2crypto_wrap.c:23227: error: expected > expression before ')' token > 364 ? ? :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 > > Anyone know a way to resolve this? > > Cheers > > Adam > From gnuist006 at gmail.com Thu Jul 15 01:17:05 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 14 Jul 2010 22:17:05 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> Message-ID: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> On Jul 13, 11:18 pm, geremy condra wrote: > On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: > > On Jun 20, 9:31 pm, Richard Fateman wrote: > >> Define Macro wrote: > >> > On Jun 13, 7:07 pm, bolega wrote: > >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. > > >> >> For this, I propose a vanilla C interpreter. I have seen a book which > >> >> writes C interpreter in C. > > >> >> The criteria would be the small size and high readability of the code. > > >> >> Are there already answers anywhere ? > > >> Sure. Lots of texts on compilers provide exercises which, in one way or > >> another suggest how to write an interpreter and perhaps a compiler too > >> for some language. Anyone taking a course on compilers is likely to > >> have followed such exercises in order to pass the course. Some > >> instructors are enlightened enough to allow students to pick the > >> implementation language. > > >> Ask any such instructor. > > > Beware, he does not tell the readers the financial details. This is > > what he wrote to me by email. > > > > > I would be willing to meet with you here in Berkeley to educate you on > > these matters at a consulting rate of $850 per hour, with a minimum > > of 8 hours. > > > RJF > > > > He's Berkeley's former CS chair and was implementing lisp before > common lisp was a twinkle in anybody's eye. His time is valuable. > > Geremy Condra This makes some sense. He replied on the newsgroup in a lengthy post that there are sufficient resources out there giving hint that no one need help me out. Then I was called "lazy" in one email and tersely given JUST the last name of an author who has many books each many 100s pages, when I asked for a relevant book, as if i am a scholar in the field, although he did spend lots of words on irrelevant and unbeneficial things which diminished my enthusiasm. Now, I find out from you that he has/had a business concern or interest in a company that is writing/wrote lisp interpreter in C. Correct me if I am making an error. I dont want to think deprecatingly of any good soul but this is what i experienced. From gnuist006 at gmail.com Thu Jul 15 01:26:26 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 14 Jul 2010 22:26:26 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <7xoceao9jx.fsf@ruckus.brouhaha.com> Message-ID: On Jul 13, 11:35?pm, Paul Rubin wrote: > bolega writes: > > I am trying to compare LISP/Scheme/Python for their expressiveness... > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > These two articles > > ? ?http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf > ? ?http://www.haskell.org/papers/NSWC/jfp.ps > > about language comparisons (Python is in the first but not the second) > might be of interest. > > If you want to know how to implement C, there is a pretty good book by > Hanson and Fraser about LCC, called "A Retargetable C Compiler". > Basically a code walkthrough of a small C compiler written in C. I have decided to limit my goal to tyni LISP interpreter in C because its a smaller and simpler language. From debatem1 at gmail.com Thu Jul 15 01:52:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 14 Jul 2010 22:52:51 -0700 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 10:17 PM, bolega wrote: > On Jul 13, 11:18 pm, geremy condra wrote: >> On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: >> > On Jun 20, 9:31 pm, Richard Fateman wrote: >> >> Define Macro wrote: >> >> > On Jun 13, 7:07 pm, bolega wrote: >> >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. >> >> >> >> For this, I propose a vanilla C interpreter. I have seen a book which >> >> >> writes C interpreter in C. >> >> >> >> The criteria would be the small size and high readability of the code. >> >> >> >> Are there already answers anywhere ? >> >> >> Sure. ?Lots of texts on compilers provide exercises which, in one way or >> >> another suggest how to write an interpreter and perhaps a compiler too >> >> for some language. ?Anyone taking a course on compilers is likely to >> >> have followed such exercises in order to pass the course. ?Some >> >> instructors are enlightened enough to allow students to pick the >> >> implementation language. >> >> >> Ask any such instructor. >> >> > Beware, he does not tell the readers the financial details. This is >> > what he wrote to me by email. >> >> > >> > I would be willing to meet with you here in Berkeley to educate you on >> > these matters at a consulting rate of ?$850 per hour, with a minimum >> > of 8 hours. >> >> > RJF >> > >> >> He's Berkeley's former CS chair and was implementing lisp before >> common lisp was a twinkle in anybody's eye. His time is valuable. >> >> Geremy Condra > > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. No one does. Your problem is yours to solve. > Then I was called "lazy" in one email and tersely > given JUST the last name of an author who has many books each many > 100s pages, when I asked for a relevant book, as if i am a scholar in > the field, although he did spend lots of words on irrelevant and > unbeneficial things which diminished my enthusiasm. Yes, you've failed to take advantage of the resources which have been made available to you, preferring to have other people solve your problem. Sounds like a pretty good working definition of laziness. > Now, I find out > from you that he has/had a business concern or interest in a company > that is writing/wrote lisp interpreter in C. Correct me if I am making > an error. You're making an error. Given that there are probably only a handful of people on earth more qualified to teach you anything you'd want to know about this I'd say he's made you an exceptional offer. Expect no better help elsewhere. Geremy Condra From ian.g.kelly at gmail.com Thu Jul 15 02:30:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Jul 2010 00:30:31 -0600 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 11:17 PM, bolega wrote: > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. I have no record of such a post. From mohana2004 at gmail.com Thu Jul 15 02:56:27 2010 From: mohana2004 at gmail.com (Monyl) Date: Wed, 14 Jul 2010 23:56:27 -0700 (PDT) Subject: Identify the Color of an Image References: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> Message-ID: <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> On Jul 14, 9:01?pm, John Nagle wrote: > On 7/14/2010 5:37 AM, Monyl wrote: > > > Hi, > > > 1. How can I find thecolorof ?animagepresent the webpage? > > > 2. How to identify the font type of the selected text present in the > > content of the web page > > > It would be much helpfull, if anyone responds to it ASAP > > > Thanks > > Mohmyda > > ? ? ?"Selected text"? ?Selected how? ?"Selected" implies some form > of user interface, like a browser. ?If you're doing something in > a browser, look into Firefox and Greasemonkey. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle I will be using a automation tool called Sikuli and select the text or an Image. My Requirement --------------- I will capture the image manually and scriptify using Sikuli. To find the captured image in the web page. Once it finds the image I need to collect the information of the image like, Co-ordinates of the image, height and width, color and pixel rate of the image. If I want to search a particular text in a webpage. I need to find the font name, type, color and size of the text. Note :- We can open the web page in any browser. but I should be able to capture the attributes of the image/Text displayed. From mohana2004 at gmail.com Thu Jul 15 03:13:28 2010 From: mohana2004 at gmail.com (Monyl) Date: Thu, 15 Jul 2010 00:13:28 -0700 (PDT) Subject: Identify the Color of an Image References: Message-ID: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> On Jul 14, 8:51?pm, Gary Herron wrote: > On 07/14/2010 05:37 AM, Monyl wrote: > > > Hi, > > > 1. How can I find thecolorof ?animagepresent the webpage? > > > 2. How to identify the font type of the selected text present in the > > content of the web page > > > It would be much helpfull, if anyone responds to it ASAP > > > Thanks > > Mohmyda > > Please be clearer about what you want. > > 1. Animagedoes not "have" acolor, although each pixel in animage > does have acolor. > > 2. ?Text in a web page does not (necessarily) ?have a font, although the > display engine will use a font of its choice to render text. ?And my > browser will probably use a different font than yours. Hi Gary Herron, 1.If I am going to click on a particular image. I will have click using the co-ordinates of an Image. Can we find the color of the pixel which lies in that particular co-ordinate where I click. 2.I just want to retrive the attributes of the text as it appears on the browser. Can I get the font value depending on the browsers. Hope you understand my problem. From nagle at animats.com Thu Jul 15 03:14:24 2010 From: nagle at animats.com (John Nagle) Date: Thu, 15 Jul 2010 00:14:24 -0700 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: <4c3eb550$0$1665$742ec2ed@news.sonic.net> On 7/14/2010 12:56 AM, Roald de Vries wrote: > I know, I just wondered if there is a *standard* solution. Yes, there is. class floatref(object) : def __init__(self, initialval) : self.__dict__["_val"] = initialval def __getattr__(self, attrname) : if attrname == 'val' : return(self._val) else : raise AttributeError(attrname) def __setattr__(self, attrname, val) : if attrname == 'val' : self.__dict__["_val"] = val else : raise AttributeError(attrname) x = floatref(1.0) y = x print(x.val) x.val = 10.0 print(x.val) print(y.val) Are you happy now? John Nagle From sst.misc at gmail.com Thu Jul 15 03:36:25 2010 From: sst.misc at gmail.com (Simon SSt) Date: Thu, 15 Jul 2010 09:36:25 +0200 Subject: Is python suitable for my needs? Message-ID: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Hi, Never too late to discover a new language :-) I hope anybody could help me answering my questions. I'm a technical consultant for a software editor. Our software is running on the UNIX (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x and 10.x. I'd like to know if Python is suitable for helping me: Monitoring the UNIX box? Get some metrics from Sybase and Oracle? Get JMX metrics from Weblogic Server (Weblogic Server is provided with a scripting tool based on Jython) Thanks for your hints. Simon From epost2 at gmail.com Thu Jul 15 03:45:10 2010 From: epost2 at gmail.com (Bruce) Date: Thu, 15 Jul 2010 00:45:10 -0700 (PDT) Subject: whitespace in a word doc Message-ID: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> I'm trying to create a word doc using win32com. I don't get the same whitespace as when printing the same stuff in the dos window. At the terminal I manage to line up the second column like apples 5 pears 7 I do this by adding whitespace characters to the strings in the first column so that their length is equal to that of the longest string in the first column. I print the excact same string to word. but in the word doc somehting happens that messes things up like this : apples 5 pears 7 Needless to say, this is extremely frustrating. But why does it happen, and how can I align the column in word? From youngung.jeong at gmail.com Thu Jul 15 03:54:19 2010 From: youngung.jeong at gmail.com (youngung) Date: Thu, 15 Jul 2010 00:54:19 -0700 (PDT) Subject: insufficient memory problem in running .exe file in ipython Message-ID: <0b71e44b-10e1-4faf-a473-e8f1ed19875e@q16g2000prf.googlegroups.com> Hello! I came across a problem in running a .exe file through ipython. """ os.system(' ~.exe') """ was used. The error message popped up says Memory error: insufficient physical memory available What should I try further? From mail at timgolden.me.uk Thu Jul 15 03:59:30 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 08:59:30 +0100 Subject: whitespace in a word doc In-Reply-To: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: <4C3EBFE2.1090808@timgolden.me.uk> On 15/07/2010 08:45, Bruce wrote: > I'm trying to create a word doc using win32com. I don't get the same > whitespace as when printing the same stuff in the dos window. At the > terminal I manage to line up the second column like > > apples 5 > pears 7 > > I do this by adding whitespace characters to the strings in the first > column so that their length is equal to that of the longest string in > the first column. > > I print the excact same string to word. but in the word doc somehting > happens that messes things up like this : > > apples 5 > pears 7 > > Needless to say, this is extremely frustrating. But why does it > happen, and how can I align the column in word? Couple of things which will help us to help you: 1) Consider what's going on *without* Python: if you take the exact same text and spaces and type it into a Word document, does the same thing happen? If so, then there is something of a gap in your understanding of how Word arranges spaces, especially with proportional fonts. 2) If the text looks fine when you type it in but dodgy when programmed in from Python, post the code here. If there's an issue with the way your code is doing what its' doing, we need to see the code to work that out. (Usually). If you want things to line up in columns in Word, you probably want to do one of two things (possibly both): use a fixed-width font, eg Courier New; use Word tables. If you go the latter route, it can sometimes be easier to generate the equivalent HTML and then ask Word to open it directly. Depends. TJG From nitinpawar432 at gmail.com Thu Jul 15 04:01:06 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 15 Jul 2010 13:31:06 +0530 Subject: Is python suitable for my needs? In-Reply-To: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Message-ID: Python will absolutely will suit for monitoring. I use it on tomcat, mysql , apache and linux as well as freebsd Thanks, Nitin On Thu, Jul 15, 2010 at 1:06 PM, Simon SSt wrote: > Hi, > > Never too late to discover a new language :-) > > I hope anybody could help me answering my questions. I'm a technical > consultant for a software editor. Our software is running on the UNIX > (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x and > 10.x. > > I'd like to know if Python is suitable for helping me: > Monitoring the UNIX box? > Get some metrics from Sybase and Oracle? > Get JMX metrics from Weblogic Server (Weblogic Server is provided with a > scripting tool based on Jython) > > Thanks for your hints. > > Simon > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From epost2 at gmail.com Thu Jul 15 04:06:17 2010 From: epost2 at gmail.com (Bruce) Date: Thu, 15 Jul 2010 01:06:17 -0700 (PDT) Subject: whitespace in a word doc References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: <57cc4790-aaba-4f36-92b6-9246c3f6c649@y4g2000yqy.googlegroups.com> On Jul 15, 9:59?am, Tim Golden wrote: > On 15/07/2010 08:45, Bruce wrote: > > > > > > > I'm trying to create a word doc using win32com. I don't get the same > > whitespace as when printing the same stuff in the dos window. At the > > terminal I manage to line up the second column like > > > apples ? ? ? ? ?5 > > pears ? ? ? ? ? ?7 > > > I do this by adding whitespace characters to the strings in the first > > column so that their length is equal to that of the longest string in > > the first column. > > > I print the excact same string to word. but in the word doc somehting > > happens that messes things up like this : > > > apples ? ? ? ? ? ? ? ? ? ? ? ?5 > > pears ? ? ? ? ? ? ? 7 > > > Needless to say, this is extremely frustrating. But why does it > > happen, and how can I align the column in word? > > Couple of things which will help us to help you: > > 1) Consider what's going on *without* Python: if you take the exact > same text and spaces and type it into a Word document, does the same > thing happen? Yes. Now using courier new. Thanks. From lee8321 at gmail.com Thu Jul 15 04:25:06 2010 From: lee8321 at gmail.com (swiss luxury watches) Date: Thu, 15 Jul 2010 01:25:06 -0700 (PDT) Subject: Balenciaga Envelop Clutch 084357L_CF Message-ID: Balenciaga Envelop Clutch 084357L_CF http://www.bagstag.com/Balenciaga-Envelop-Clutch-084357L_CF.html Balenciaga Envelop Clutch Information : Brand : Balenciaga ( http://www.bagstag.com/Balenciaga.html ) Code : 084357L_CF Balenciaga Envelop Clutch Pure chevre (goatskin) with matching leather trimmings A central zip pocket on flap Leather coated studs on front and corners. Two compartments Attached mirror Llower buckle accent Black cloth interior Each Balenciaga Envelop Clutch replica comes with a Balenciaga dust bag, Balenciaga authenticity card and a Balenciaga care booklet. Size: 12" x 7" General Attributes Style: Clutches & Pouches Color: Tan Gender: Women From engmohamedeid83 at gmail.com Thu Jul 15 05:16:32 2010 From: engmohamedeid83 at gmail.com (M Eid) Date: Thu, 15 Jul 2010 02:16:32 -0700 (PDT) Subject: VoIP Message-ID: <66e754db-5a55-42a7-b73c-8174ea87cb8b@d37g2000yqm.googlegroups.com> Dears, My blog about Voice over Internet protocol networks......Let's improve our general knowledg http://voib-net.blogspot.com/ Thanks&BR From michael at stroeder.com Thu Jul 15 05:23:12 2010 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 15 Jul 2010 11:23:12 +0200 Subject: python ldap recursive In-Reply-To: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> References: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Message-ID: tekion wrote: > I know perl Net::LDAP could do a recursive search call to LDAP. I don't know perl's Net::LDAP and therefore I'm not sure what you mean with "recursive search call". Personally I'd associate that with recursively processing LDAP tree structure. > What I am running into with Python LDAP on the search call is that I would > l have to wait for the search to complete to get the result. Where as with > Perl recursive search call, I would get the result (not the completed > result) back while the search is still running. In case you're using http://www.python-ldap.org you're probably looking for the asynchronous search methods: http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.search See general note: http://www.python-ldap.org/doc/html/ldap.html#sending-ldap-requests Ciao, Michael. From marek at xivilization.net Thu Jul 15 05:25:18 2010 From: marek at xivilization.net (Marek Kubica) Date: Thu, 15 Jul 2010 11:25:18 +0200 Subject: Is Python portable/Can I install it on an USB Stick? References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <20100715112518.20138a67@halmanfloyd.lan.local> On 14 Jul 2010 19:28:58 GMT tommybear at hotmail.com (Thomas Tundor) wrote: > Is Python portable? Yes. > Can I install it on an USB Stick? Yes. > Or is Python installing (at least on WinXP) services or register some > DLLs or write something into Registry? Well, the installer is writing something into the registry, although it is not neccessary to run Python. regards, Marek From aimeixu at amazon.com Thu Jul 15 05:38:11 2010 From: aimeixu at amazon.com (aimeixu) Date: Thu, 15 Jul 2010 17:38:11 +0800 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python Message-ID: <4C3ED703.2010703@amazon.com> Hi guys, I really need help to figure out a way to get someone's calendar from mail exchange server with python. I have no idea about how to make it .Or could some nice guys give me some hint?Thank a lot . From tino at wildenhain.de Thu Jul 15 05:48:24 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 15 Jul 2010 11:48:24 +0200 Subject: floatref In-Reply-To: <4c3eb550$0$1665$742ec2ed@news.sonic.net> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> <4c3eb550$0$1665$742ec2ed@news.sonic.net> Message-ID: <4C3ED968.4060406@wildenhain.de> Hi John, Am 15.07.2010 09:14, schrieb John Nagle: > On 7/14/2010 12:56 AM, Roald de Vries wrote: >> I know, I just wondered if there is a *standard* solution. > > Yes, there is. > > class floatref(object) : > def __init__(self, initialval) : > self.__dict__["_val"] = initialval > def __getattr__(self, attrname) : > if attrname == 'val' : > return(self._val) > else : > raise AttributeError(attrname) > def __setattr__(self, attrname, val) : > if attrname == 'val' : > self.__dict__["_val"] = val > else : > raise AttributeError(attrname) Uhm. How would that be different to: class floatref(object): def __init__(self,val): self.val=val ? > > x = floatref(1.0) > y = x > > print(x.val) > x.val = 10.0 > print(x.val) > print(y.val) Regards Tino From manoj.nehame.neha at gmail.com Thu Jul 15 06:01:02 2010 From: manoj.nehame.neha at gmail.com (neha manoj) Date: Thu, 15 Jul 2010 03:01:02 -0700 (PDT) Subject: WATCH KATRINA KAIF SEX VIDEOS Message-ID: <64a2a143-ea34-4868-85d0-05044a63c4a1@s17g2000prh.googlegroups.com> WATCH KATRINA KAIF SEX VIDEOS AT http://katrinakaif-sex.weebly.com/ From mail at timgolden.me.uk Thu Jul 15 06:03:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 11:03:55 +0100 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python In-Reply-To: <4C3ED703.2010703@amazon.com> References: <4C3ED703.2010703@amazon.com> Message-ID: <4C3EDD0B.4030008@timgolden.me.uk> On 15/07/2010 10:38, aimeixu wrote: > Hi guys, > I really need help to figure out a way to get someone's calendar from > mail exchange server with python. I have no idea about how to make it > .Or could some nice guys give me some hint?Thank a lot . There's an IMAP-based recipe here: http://sites.google.com/site/mattpoepping/gcalpython and an IronPython one here: http://exchange2ical.codeplex.com/ and an ADO one here: http://www.codeproject.com/KB/dotnet/Dot_Net_2005.aspx and a CDO one here (search for "Open another users calendar folder"): http://www.cdolive.com/cdo5p2.htm The last two aren't directly Python examples but are easily translated via win32com.client. TJG From eckhardt at satorlaser.com Thu Jul 15 06:24:52 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 15 Jul 2010 12:24:52 +0200 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python References: Message-ID: aimeixu wrote: > I really need help to figure out a way to get someone's calendar from > mail exchange server with python. You can implement any network protocol with Python, see e.g. the struct library. However, it would be easier to use an existing protocol implementation. When you say "mail exchange server", what exactly does that mean? I guess you actually mean an Exchange mail which is a product of Microsoft. For that, there is a free implementation of the server-side protocol (openexchange, IIRC). OTOH, you may be able to use the win32 MAPI (message API), but I'm not sure what this can do and if there are Python bindings for it. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From alanwilter at gmail.com Thu Jul 15 06:34:00 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 15 Jul 2010 11:34:00 +0100 Subject: python3: help with pickle Message-ID: Hi there, This is more an exercise to myself to understand python3. I took a code I wrote (acpype) and I am trying to make it compatible with either python 3 or 2. I am trying to make a pickle file compatible with either python 3 and 2 as I believe it should be possible. I've looked at http://docs.python.org/py3k/library/pickle.html but still, when I create a pickle file for an object with python 2.7 and then I try to load it in python3, I got this: Python 3.1.2 (r312:79147, Jul 7 2010, 10:55:24) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from acpype import * # this acpype package contains needed class ACTopol >>> import pickle >>> o = pickle.load(open('AAA.acpype/AAA.pkl','rb')) Traceback (most recent call last): File "", line 1, in File "/sw/lib/python3.1/pickle.py", line 1365, in load encoding=encoding, errors=errors).load() TypeError: ('__init__() takes at least 2 positional arguments (1 given)', , ()) >>> Now trying the contrary, pickle file is created with python3, I got this when trying to load it with python 2.7: Python 2.7 (r27:82500, Jul 7 2010, 10:48:15) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from acpype import * >>> import pickle >>> o = pickle.load(open('AAA.pkl','rb')) Traceback (most recent call last): File "", line 1, in File "/sw/lib/python2.7/pickle.py", line 1378, in load return Unpickler(file).load() File "/sw/lib/python2.7/pickle.py", line 858, in load dispatch[key](self) File "/sw/lib/python2.7/pickle.py", line 1083, in load_newobj obj = cls.__new__(cls, *args) AttributeError: class ACTopol has no attribute '__new__' Apart that, everything else seems to work. Just one note more: when loading the pickle file 2.7 in python 2.7, type(o) is , while pickle 3 in python 3, type(o) is Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwdyson at yahoo.com Thu Jul 15 07:00:53 2010 From: pwdyson at yahoo.com (Paul) Date: Thu, 15 Jul 2010 04:00:53 -0700 (PDT) Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... Message-ID: <299733.71288.qm@web53601.mail.re2.yahoo.com> I'm pleased to announce the release of inflect.py v0.1.8, a module that correctly generates: * the plural of singular nouns and verbs * the singular of plural nouns * ordinals * indefinite articles * present participles * and converts numbers to words Examples: >>> import inflect >>> p = inflect.engine() >>> p.pl('cat') 'cats' >>> p.pl('sheep') 'sheep' >>> p.pl('bacterium') 'bacteria' plural of singular verbs: it walks -> they walk >>> p.pl('walks') 'walk' singular of plural nouns: >>> p.sinoun('bacteria') 'bacterium' >>> p.sinoun('knives') 'knife' ordinals: >>> p.ordinal(31) '31st' >>> p.ordinal('twenty-five') 'twenty-fifth' indefinite articles: >>> p.a('horse') 'a horse' >>> p.a('ant') 'an ant' >>> p.a('hour') 'an hour' present participles: >>> p.prespart('drinks') 'drinking' >>> p.prespart('runs') 'running' >>> p.prespart('flies') 'flying' numbers to words: >>> p.numwords(1234567) 'one million, two hundred and thirty-four thousand, five hundred and sixty-seven' Installation: "pip install inflect" or "easy_install inflect" PyPi: http://pypi.python.org/pypi/inflect Bug Tracker: http://github.com/pwdyson/inflect.py/issues Source Code: http://github.com/pwdyson/inflect.py Cheers, Paul Dyson -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 15 07:12:16 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 04:12:16 -0700 Subject: python3: help with pickle In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 3:34 AM, Alan wrote: > Hi there, > This is more an exercise to myself to understand python3. I took a code I > wrote (acpype) and I am trying to make it compatible with either python 3 or > 2. > I am trying to make a pickle file compatible with either python 3 and 2 as I > believe it should be possible. > I've looked at?http://docs.python.org/py3k/library/pickle.html but still, > when I create a pickle file for an object with python 2.7 and then I try to > load it in python3, I got this: > Python 3.1.2 (r312:79147, Jul ?7 2010, 10:55:24) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from acpype import * # this acpype package contains needed class?ACTopol >>>> import pickle >>>> o = pickle.load(open('AAA.acpype/AAA.pkl','rb')) > Traceback (most recent call last): > ??File "", line 1, in > ??File "/sw/lib/python3.1/pickle.py", line 1365, in load > ?? ?encoding=encoding, errors=errors).load() > TypeError: ('__init__() takes at least 2 positional arguments (1 given)', > , ()) >>>> > Now trying the contrary, pickle file is created with python3, I got this > when trying to load it with python 2.7: > Python 2.7 (r27:82500, Jul ?7 2010, 10:48:15) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from acpype import * >>>> import pickle >>>> o = pickle.load(open('AAA.pkl','rb')) > Traceback (most recent call last): > ??File "", line 1, in > ??File "/sw/lib/python2.7/pickle.py", line 1378, in load > ?? ?return Unpickler(file).load() > ??File "/sw/lib/python2.7/pickle.py", line 858, in load > ?? ?dispatch[key](self) > ??File "/sw/lib/python2.7/pickle.py", line 1083, in load_newobj > ?? ?obj = cls.__new__(cls, *args) > AttributeError: class ACTopol has no attribute '__new__' > Apart that, everything else seems to work. Just one note more: when loading > the pickle file 2.7 in python 2.7, type(o) is?, while > pickle 3 in python 3, type(o) is? Your AbstractTopol class needs to inherit from class `object` so that it (and its descendant ACTopol) become new-style classes. Old-style classes don't exist in Python 3, and I think this is at least partly the cause of your problem. Cheers, Chris -- http://blog.rebertia.com From kwutzke at web.de Thu Jul 15 07:35:06 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 04:35:06 -0700 (PDT) Subject: Extending objects by a method? Message-ID: Hello, I'm new to Python so beware. I have a hierarchical object structure which I iterate over (the elements/classes of interest). I would like to apply the Visitor pattern onto this object structure, so I must add an "accept" method to every object (I'm interesting in) for the Visitor pattern to work. Is there any Python-inbuilt way to dynamically add a method or do I have to wrap each iterated object into a Decorator supplying the accept method? The latter would mean having to rebuild the (part) hierarchy with the Decorator objects before running the Visitor, which I'd like to avoid. Karsten From kwutzke at web.de Thu Jul 15 07:45:08 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 04:45:08 -0700 (PDT) Subject: Extending objects by a method? References: Message-ID: Small correction: I probably have to add a method to a class, so that every object instantiated not by me has the desired functionality. Karsten From maaindia0 at gmail.com Thu Jul 15 08:07:10 2010 From: maaindia0 at gmail.com (easy money) Date: Thu, 15 Jul 2010 05:07:10 -0700 (PDT) Subject: See Hot College Girls Latest Sex Videos. Message-ID: See Hot College Girls Latest Sex Videos. At http://beatifulcollegegirls.tk Due to high sex content, i have hidden the videos in an image. in that website on Top Side search box Above click on image and watch videos in all angles. please don,t tell to anyone. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 15 08:11:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 12:11:51 GMT Subject: insufficient memory problem in running .exe file in ipython References: <0b71e44b-10e1-4faf-a473-e8f1ed19875e@q16g2000prf.googlegroups.com> Message-ID: <4c3efb07$0$11101$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 00:54:19 -0700, youngung wrote: > Hello! > > I came across a problem in running a .exe file through ipython. """ > os.system(' ~.exe') """ was used. The error message popped up says > > Memory error: insufficient physical memory available > > What should I try further? More memory? What's your operating system, how much memory do you have, how much memory does ' ~.exe' (that's a weird name) need? Is your operating system set to limit the amount of memory each process is given? What happens if you don't use ipython but call os.system(' ~.exe') from the normal Python prompt? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jul 15 08:26:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 12:26:08 GMT Subject: Is python suitable for my needs? References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Message-ID: <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 09:36:25 +0200, Simon SSt wrote: > Hi, > > Never too late to discover a new language :-) > > I hope anybody could help me answering my questions. I'm a technical > consultant for a software editor. Our software is running on the UNIX > (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x > and 10.x. > > I'd like to know if Python is suitable for helping me: Monitoring the > UNIX box? You're probably better off using existing tools like Nagios and Munin rather than trying to reinvent the wheel. But yes, Python is a fine language for tasks like that. Server monitoring is an awfully big wheel to reinvent though; you should have a good reason for not using an existing, well-tested and supported product. > Get some metrics from Sybase and Oracle? Google blocked where you are? http://www.oracle.com/technology/pub/articles/prez-python-queries.html http://wiki.oracle.com/page/Python If you've got specific questions that you couldn't answer by googling, you should say so. > Get JMX metrics from Weblogic > Server (Weblogic Server is provided with a scripting tool based on > Jython) That's a pretty good hint. Are you aware that Jython is Python implemented in Java instead of C? In other words, Jython *is* Python. -- Steven From lanyjie at yahoo.com Thu Jul 15 08:30:53 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 15 Jul 2010 05:30:53 -0700 (PDT) Subject: empty set and empty dict for Python 3 Message-ID: <9760.58719.qm@web54201.mail.re2.yahoo.com> Hi there, Maybe somebody already suggested this: How about "{:}" for the empty dict, so that "{}" can denote the empty set? Yingjie From mail at timgolden.me.uk Thu Jul 15 08:44:18 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 13:44:18 +0100 Subject: empty set and empty dict for Python 3 In-Reply-To: <9760.58719.qm@web54201.mail.re2.yahoo.com> References: <9760.58719.qm@web54201.mail.re2.yahoo.com> Message-ID: <4C3F02A2.2000807@timgolden.me.uk> On 15/07/2010 13:30, Yingjie Lan wrote: > Hi there, > > Maybe somebody already suggested this: > > How about "{:}" for the empty dict, > so that "{}" can denote the empty set? Well one thing is that {} has denoted the empty dict for many many releases of Python so a *lot* of code would break if you suddenly switched... TJG From __peter__ at web.de Thu Jul 15 08:49:16 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jul 2010 14:49:16 +0200 Subject: empty set and empty dict for Python 3 References: Message-ID: Yingjie Lan wrote: > Maybe somebody already suggested this: > > How about "{:}" for the empty dict, > so that "{}" can denote the empty set? http://mail.python.org/pipermail/python-3000/2007-April/006620.html From ranjithtenz at gmail.com Thu Jul 15 09:04:32 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Thu, 15 Jul 2010 18:34:32 +0530 Subject: how to install all python plugins Message-ID: Hi! I`m using ubuntu 10.04 I want to install all the python plugins at once or the python plugins list. thank you in advance -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From maaindia19 at gmail.com Thu Jul 15 09:07:43 2010 From: maaindia19 at gmail.com (free money) Date: Thu, 15 Jul 2010 06:07:43 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <741067d6-4608-4f32-85e8-002b61d42378@n19g2000prf.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account At http://easyhappydays.tk Due to high security risks, i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. please don,t tell to any One. From maaindia19 at gmail.com Thu Jul 15 09:08:34 2010 From: maaindia19 at gmail.com (free money) Date: Thu, 15 Jul 2010 06:08:34 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <1ea5528d-885f-40e7-849a-883a3840da97@t13g2000prf.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account At http://easyhappydays.tk Due to high security risks, i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. please don,t tell to any One. From alanwilter at gmail.com Thu Jul 15 09:13:37 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 15 Jul 2010 14:13:37 +0100 Subject: python3: signal.signal/singal.alarm Message-ID: Hi there, I have this, say timeTol = 5 (5 seconds) and 'cmd' takes minutes to execute : import subprocess as sub ... p = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE) pid = p.pid signal.signal(signal.SIGALRM, signal_handler) signal.alarm(timeTol) And it works on python 2.x. However, on python 3.x, the signal_handler is only called when 'p = sub.Popen...' has finished (after minutes) and signal.alarm appears to not be called at 5 sec. Can someone please explain me this behaviour and how to solve this? Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Jul 15 09:58:53 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 15 Jul 2010 08:58:53 -0500 Subject: Extending objects by a method? In-Reply-To: References: Message-ID: <4C3F141D.6030305@tim.thechases.com> On 07/15/2010 06:45 AM, Karsten Wutzke wrote: > Small correction: I probably have to add a method to a class, so that > every object instantiated not by me has the desired functionality. You mean like: >>> class Foo: ... def __init__(self, greeting): ... self.greeting = greeting ... >>> f = Foo("Hello") >>> def greet(self, other): ... print "%s, %s" % (self.greeting, other) ... >>> Foo.greet = greet >>> f.greet("world") Hello, world -tkc From invalid at invalid.invalid Thu Jul 15 10:10:40 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 15 Jul 2010 14:10:40 +0000 (UTC) Subject: whitespace in a word doc References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: On 2010-07-15, Bruce wrote: > I'm trying to create a word doc using win32com. Unfortunately the phrase "word doc" is meaningless. Exactly what format file are you trying to generate? For example: Word97 "doc" or the new "docx" format? > I don't get the same whitespace as when printing the same stuff in > the dos window. At the terminal I manage to line up the second column > like > > apples 5 > pears 7 > > I do this by adding whitespace characters to the strings in the first > column so that their length is equal to that of the longest string in > the first column. Are you just generating an ASCII text file and then opening it in word? > I print the excact same string to word. but in the word doc somehting > happens that messes things up like this : > > apples 5 > pears 7 > > Needless to say, this is extremely frustrating. But why does it > happen, and how can I align the column in word? Why? Because word is using a viable-spaced font and the "dos window" uses a fixed-width font. If you want any control over the appearance of the document, you'll have to either force word to open the file in a fixed-width font, or you'll have to generate a file that contains formatting information. What you appear to want is a table. Generating RTF has worked well for me in the past: http://code.google.com/p/pyrtf-ng/ http://pyrtf.sourceforge.net/ An enahanced version of pyRTF that supports EMF graphics and scaling of graphics is available here: http://www.panix.com/~grante/files/python/PyRTF-0.46.tar.gz If you want to generate graphics, this might be worth a look http://pyemf.sourceforge.net/ You might also be able to generate HTML and then open that file using Word. -- Grant Edwards grant.b.edwards Yow! The Osmonds! You are at all Osmonds!! Throwing up gmail.com on a freeway at dawn!!! From sst.misc at gmail.com Thu Jul 15 10:27:27 2010 From: sst.misc at gmail.com (Simon SSt) Date: Thu, 15 Jul 2010 16:27:27 +0200 Subject: Is python suitable for my needs? In-Reply-To: <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c3f1acf$0$29537$4c5ecfc7@news.xlned.com> Le 15/07/2010 14:26, Steven D'Aprano a ?crit : > On Thu, 15 Jul 2010 09:36:25 +0200, Simon SSt wrote: > >> Hi, >> >> Never too late to discover a new language :-) >> >> I hope anybody could help me answering my questions. I'm a technical >> consultant for a software editor. Our software is running on the UNIX >> (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x >> and 10.x. >> >> I'd like to know if Python is suitable for helping me: Monitoring the >> UNIX box? > > You're probably better off using existing tools like Nagios and Munin > rather than trying to reinvent the wheel. But yes, Python is a fine > language for tasks like that. Server monitoring is an awfully big wheel > to reinvent though; you should have a good reason for not using an > existing, well-tested and supported product. > > >> Get some metrics from Sybase and Oracle? > > Google blocked where you are? > > http://www.oracle.com/technology/pub/articles/prez-python-queries.html > http://wiki.oracle.com/page/Python > > If you've got specific questions that you couldn't answer by googling, > you should say so. > > > >> Get JMX metrics from Weblogic >> Server (Weblogic Server is provided with a scripting tool based on >> Jython) > > That's a pretty good hint. Are you aware that Jython is Python > implemented in Java instead of C? In other words, Jython *is* Python. > > Regarding the System monitoring, I agree there are plenty of excellent solution and I shouldn't reinventing the wheel. I just want a script that will give me some info regarding the system state that I can use at any client site...but this monitoring part isn't my priority. Regarding the DB, thanks for your link I'll look at them thoroughly. And finally for JMX, yes I know about Jython so I'll investigate it. Thanks ----- Simon From andrewcrlucas at sympatico.ca Thu Jul 15 11:23:31 2010 From: andrewcrlucas at sympatico.ca (Andrew Lucas) Date: Thu, 15 Jul 2010 08:23:31 -0700 (PDT) Subject: Python source checkout problem Message-ID: I am trying to check-out the python source using subversion. The documentation says that "svn co http://svn.python.org/projects/python/trunk" should do the trick. When I do this I get the following response: "svn: REPORT of '/projects/!svn/vcc/default': 200 OK (http:// svn.python.org)" There is now a hidden .svn folder in my directory, but I can't find any source anywhere, all subdirectories are empty. When I try to update via "svn update" I get the following response. "svn: Server sent unexpected return value (307 Proxy Redirect) in response to OPTIONS request for 'http://svn.python.org/projects/python/ trunk' " Any ideas what I am doing wrong? Thanks, Andrew From guandalino at gmail.com Thu Jul 15 11:54:23 2010 From: guandalino at gmail.com (guandalino) Date: Thu, 15 Jul 2010 08:54:23 -0700 (PDT) Subject: Question about Python upgrade on linux Message-ID: <4c51f0a6-a8a4-43a0-b76c-181eeea847a5@i28g2000yqa.googlegroups.com> Hi, suppose I have python 2.6.4 installed from source and I want to upgrade to 2.6.5. Python standard library is automatically upgraded at 2.6.5 as well, while 3rd party pure Python and extension modules in site-packages don't. Is it safe to keep the old site-packages or is it suggested to reinstall modules and/or recompile extensions using the new Python? And to upgrade from 2.6 to 2.7? Thanks, best regards. From tjreedy at udel.edu Thu Jul 15 12:04:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jul 2010 12:04:35 -0400 Subject: Python source checkout problem In-Reply-To: References: Message-ID: On 7/15/2010 11:23 AM, Andrew Lucas wrote: > I am trying to check-out the python source using subversion. The > documentation says that Which doc? It probably needs to be changed. > "svn co http://svn.python.org/projects/python/trunk" I believe 'trunk' is frozen as of the 2.7 release. I suspect you want the releasexy-maint branch for some value of x and y or py3k for what is now the main developmemt branch. (3.2a) As to the errors: I am currently browsing the svn view ok. I would try again to make sure it was not a temporary glitch. -- Terry Jan Reedy From mike at nerone.org Thu Jul 15 12:10:02 2010 From: mike at nerone.org (Mike Nerone) Date: Thu, 15 Jul 2010 11:10:02 -0500 Subject: Python source checkout problem In-Reply-To: References: Message-ID: <4C3F32DA.6000608@nerone.org> On 07/15/2010 10:23 AM, Andrew Lucas wrote: > "svn co http://svn.python.org/projects/python/trunk" > > ... > > "svn: Server sent unexpected return value (307 Proxy Redirect) in > response to OPTIONS request for 'http://svn.python.org/projects/python/ > trunk' " > Assuming trunk is what you actually want, I would guess that your environment has a proxy server that's not compatible with subversion getting in your way. Ask your network admins if you're at a business location. Mike Nerone From fetchinson at googlemail.com Thu Jul 15 12:18:49 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 15 Jul 2010 18:18:49 +0200 Subject: how to install all python plugins In-Reply-To: References: Message-ID: > I`m using ubuntu 10.04 I want to install all the python plugins at once > or the python plugins list. > thank you in advance What is a python plugin? If you mean all published packages on the python website, then you probably don't really want to install all of them, only those that you need. If you mean all python packages that are available through the package manager of ubuntu, then you'll need to search the entire list of available packages using ubuntu's package manager, pick out the ones that have 'python' in their names (presumably, this is how it works on fedora) and install them using the above mentioned package manager software. If you don't know how to use it, please see https://help.ubuntu.com/community/SynapticHowto https://help.ubuntu.com/community/InstallingSoftware HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Thu Jul 15 12:24:24 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 15 Jul 2010 18:24:24 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <299733.71288.qm@web53601.mail.re2.yahoo.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> Message-ID: > I'm pleased to announce the release of inflect.py v0.1.8, a module that > correctly generates: > > * the plural of singular nouns and verbs > * the singular of plural nouns > * ordinals > * indefinite articles > * present participles > * and converts numbers to words Wow! Tons of kudos, this must have been hell of a work to put together with all the irregular nouns/verbs/etc, and I really needed something like this for a long time. Thanks a lot, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From thomas at jollans.com Thu Jul 15 12:41:00 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 18:41:00 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <299733.71288.qm@web53601.mail.re2.yahoo.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> Message-ID: <4C3F3A1C.5040208@jollans.com> On 07/15/2010 01:00 PM, Paul wrote: > > > I'm pleased to announce the release of inflect.py v0.1.8, a module that > correctly generates: > > * the plural of singular nouns and verbs > * the singular of plural nouns > * ordinals > * indefinite articles > * present participles > * and converts numbers to words Which languages does it support? If the answer is what I expect it is, did you design the module with multilingualism in mind? From no.email at please.post Thu Jul 15 12:41:07 2010 From: no.email at please.post (kj) Date: Thu, 15 Jul 2010 16:41:07 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: In Thomas Jollans writes: >http://docs.python.org/library/ctypes.html#fundamental-data-types >c_longdouble maps to float Thanks for pointing this out! ~K (Does it make *any difference at all* to use c_longdouble instead of c_double? If not, I wonder what's the point of having c_longdouble at all.) From no.email at please.post Thu Jul 15 12:45:22 2010 From: no.email at please.post (kj) Date: Thu, 15 Jul 2010 16:45:22 +0000 (UTC) Subject: Q for Emacs users: code-folding (hideshow) Message-ID: This is a question _for Emacs users_ (the rest of you, go away :) ). How do you do Python code-folding in Emacs? Thanks! ~K From gscotfleming at yahoo.com Thu Jul 15 12:50:57 2010 From: gscotfleming at yahoo.com (G F) Date: Thu, 15 Jul 2010 09:50:57 -0700 (PDT) Subject: Cannot send email Message-ID: <594998.379.qm@web53205.mail.re2.yahoo.com> A while back I was working for a company and set up a little python script to send out maintenance emails for some equipment we had set up in the field. The script collected information about the equipment composed an email and sent it out to interested persons. Then I left the company and they changed their ISP and got a new IP address. Now the emails are not getting through. The email server is the same as before but it is not working. Below is the error messaage that is reported by the script. Does anyone have any ideas where the trouble is and what can be done about it? The little bit about: "reply: retcode (557); Msg: This mail server does not accept mail addressed to anInterestedPerson at yahoo.com" seems to be telling but I do not know why the server would respond this way. Thank you. >>> s = smtplib.SMTP(emailHost) >>> s.set_debuglevel(1) >>> s.sendmail(emailAddress, sendTo, testTxt) send: 'ehlo [127.0.1.1]\r\n' reply: '250-AUTH LOGIN PLAIN\r\n' reply: '250-AUTH LOGIN\r\n' reply: '250-AUTH=LOGIN\r\n' reply: '250-8BITMIME\r\n' reply: '250-SIZE 40960000\r\n' reply: '250 HELP\r\n' reply: retcode (250); Msg: AUTH LOGIN PLAIN AUTH LOGIN AUTH=LOGIN 8BITMIME SIZE 40960000 HELP send: 'mail FROM: size=10\r\n' reply: '250? Address Okay\r\n' reply: retcode (250); Msg: Address Okay send: 'rcpt TO:\r\n' reply: '557 This mail server does not accept mail addressed to gscotfleming at yahoo.com\r\n' reply: retcode (557); Msg: This mail server does not accept mail addressed to anInterestedPerson at yahoo.com send: 'rset\r\n' Traceback (most recent call last): ? File "", line 1, in ? File "/usr/lib/python2.6/smtplib.py", line 708, in sendmail ??? self.rset() ? File "/usr/lib/python2.6/smtplib.py", line 438, in rset ??? return self.docmd("rset") ? File "/usr/lib/python2.6/smtplib.py", line 363, in docmd ??? return self.getreply() ? File "/usr/lib/python2.6/smtplib.py", line 340, in getreply ??? raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Thu Jul 15 12:58:06 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 18:58:06 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <4C3F3A1C.5040208@jollans.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: Thomas Jollans, 15.07.2010 18:41: > On 07/15/2010 01:00 PM, Paul wrote: >> I'm pleased to announce the release of inflect.py v0.1.8, a module that >> correctly generates: >> >> * the plural of singular nouns and verbs >> * the singular of plural nouns >> * ordinals >> * indefinite articles >> * present participles >> * and converts numbers to words > > Which languages does it support? If the answer is what I expect it is, It is. Most of the time, when people forget to say what they are talking about, assuming that they are either US-Americans or Windows users will hit the nail on the head. Still, a pretty nice tool, I'd say. > did you design the module with multilingualism in mind? Just look at the code, it consists almost exclusively of long lists of words. Multilingualism clearly wasn't a design goal. Stefan From thomas at jollans.com Thu Jul 15 13:04:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 19:04:19 +0200 Subject: ctypes' c_longdouble: underflow error (bug?) In-Reply-To: References: Message-ID: <4C3F3F93.2000803@jollans.com> On 07/15/2010 06:41 PM, kj wrote: > In Thomas Jollans writes: > >> http://docs.python.org/library/ctypes.html#fundamental-data-types > >> c_longdouble maps to float > > Thanks for pointing this out! > ~K > (Does it make *any difference at all* to use c_longdouble instead > of c_double? If not, I wonder what's the point of having c_longdouble > at all.) they're still different types (in C). on my machine, a double is 64 bits wide, while a long double is 128 bits wide. This means that a function that expects a long double argument will expect 16 bytes, but ctypes will only pass 8 bytes if you tell it to pass double. The same applies to return values. From darcy at druid.net Thu Jul 15 13:07:11 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 15 Jul 2010 13:07:11 -0400 Subject: Cannot send email In-Reply-To: <594998.379.qm@web53205.mail.re2.yahoo.com> References: <594998.379.qm@web53205.mail.re2.yahoo.com> Message-ID: <20100715130711.85592265.darcy@druid.net> On Thu, 15 Jul 2010 09:50:57 -0700 (PDT) G F wrote: > Does anyone have any ideas where the trouble is and what can be done > about it? The little bit about: > "reply: retcode (557); Msg: This mail server does not accept mail > addressed to anInterestedPerson at yahoo.com" > seems to be telling but I do not know why the server would respond this way. This is really not a Python question but I think that you will find that the issue is that the server needs to know about the new IP address. The error looks like an anti-relay thing. Contact the mail server admin or ask on a list dedicated to administrating email. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From kwutzke at web.de Thu Jul 15 13:58:34 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 10:58:34 -0700 (PDT) Subject: Code generator and visitor pattern Message-ID: Hello, this is obviously a Python OO question: Since Python isn't stringly typed, single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, which is usually used in OO systems to implement code generators. So, what is the de facto method in Python to handle source code generation? Karsten From jeff at jmcneil.net Thu Jul 15 14:19:31 2010 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 15 Jul 2010 11:19:31 -0700 (PDT) Subject: Question about Python upgrade on linux References: <4c51f0a6-a8a4-43a0-b76c-181eeea847a5@i28g2000yqa.googlegroups.com> Message-ID: On Jul 15, 11:54?am, guandalino wrote: > Hi, suppose I have python 2.6.4 installed from source and I want to > upgrade to 2.6.5. Python standard library is automatically upgraded at > 2.6.5 as well, while 3rd party pure Python and extension modules in > site-packages don't. Is it safe to keep the old site-packages or is it > suggested to reinstall modules and/or recompile extensions using the > new Python? > > And to upgrade from 2.6 to 2.7? > > Thanks, > best regards. Going from 2.6.4 to 2.6.5 ought to be fine (consider the /usr/lib/ python2.x/ naming, and not /usr/lib/python2.x.y naming).When Going from 2.6 to 2.7, you're better off reinstalling your extensions. Thanks, Jeff http://www.jmcneil.net From thomas at jollans.com Thu Jul 15 14:28:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 20:28:47 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F535F.6020002@jollans.com> On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, I expect this is an innocent typo, and you mean strictly. > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, Wait, what? First of all, python is strictly typed in that every object has exactly one type, which is different from other types. So you can't do "1"+2, as you can in some other languages. Anyway, this is interesting: Tell me more about how Python's dynamic nature makes it impossible to do whatever you're trying to do. I'm baffled. What are you trying to do, anyway? > which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from your train of thought, apparently: Now, the thing that code generators probably share is that they write code to files. It depends on what I'm trying to do of course, but I expect there's a good chance that if I wrote a code generator in Python, it wouldn't be particularly object-oriented at all. From kwutzke at web.de Thu Jul 15 14:45:17 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 11:45:17 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: On 15 Jul., 20:28, Thomas Jollans wrote: > On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > > > Hello, > > > this is obviously a Python OO question: > > > Since Python isn't stringly typed, > > I expect this is an innocent typo, and you mean strictly. > > > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, > Yes, typo, I meant strictly. > Wait, what? > First of all, python is strictly typed in that every object has exactly > one type, which is different from other types. So you can't do "1"+2, as > you can in some other languages. > > Anyway, this is interesting: Tell me more about how Python's dynamic > nature makes it impossible to do whatever you're trying to do. I'm > baffled. What are you trying to do, anyway? > > > which is usually used > > in OO systems to implement code generators. So, what is the de facto > > method in Python to handle source code generation? > > WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from > your train of thought, apparently: Now, the thing that code generators > probably share is that they write code to files. It depends on what I'm > trying to do of course, but I expect there's a good chance that if I > wrote a code generator in Python, it wouldn't be particularly > object-oriented at all. Well, I'm most experienced in OO, so writing OO in Python seems like the way to start with Python. The visitor pattern uses single- dispatch, that is, it determines which method to call be the type of object passed in. I did some reading and it turned out that Python can't do it without some tricks (function decorators and 3rd party code). For what I'm doing, I can't, or rather don't want to rely on 3rd party code (that has reasons). Thus, the visitor OO pattern must be replaced by some other way. As I expected, you already hinted a non-OO solution. Which is now that *I* am wondering what that would look like... Note, that I have an hierarchical object structure which I want to iterate over, so using OO looked natural to me. If there's a better approach, I'm all ears. Karsten From lists at cheimes.de Thu Jul 15 14:46:13 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 15 Jul 2010 20:46:13 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? Do you mean strongly typed langauge? You are wrong, Python is a strongly typed language. Perhaps you are confusing strong/weak with dynamic/static? These attributes are orthogonal to each other. Python is a strongly and dynamicly typed language. The visitor pattern is required for double dispatching in *some* OO language like C++, to work around issues with inheritance and function overloading. Python's OO works differently. Christian From johan.gronqvist at gmail.com Thu Jul 15 14:57:35 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Thu, 15 Jul 2010 20:57:35 +0200 Subject: how to install all python plugins In-Reply-To: References: Message-ID: 2010-07-15 18:18, Daniel Fetchinson skrev: > > If you mean all python packages that are available through the package > manager of ubuntu, then you'll need to search the entire list of > available packages using ubuntu's package manager, pick out the ones > that have 'python' in their names (presumably, this is how it works on > fedora) and install them using the above mentioned package manager > software. To install all packages whose names start with "python-" in ubuntu: "apt-get install python-*" (as root, or prepended with sudo) / johan From kwutzke at web.de Thu Jul 15 15:00:00 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 12:00:00 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> > > Yes, typo, I meant strictly. > Damn, I mean strongly. At least not for identifying which methods to call depending on the type/s. Karsten From thomas at jollans.com Thu Jul 15 15:07:10 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 21:07:10 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F5C5E.4010908@jollans.com> On 07/15/2010 08:45 PM, Karsten Wutzke wrote: > On 15 Jul., 20:28, Thomas Jollans wrote: >> On 07/15/2010 07:58 PM, Karsten Wutzke wrote: >> >>> Hello, >> >>> this is obviously a Python OO question: >> >>> Since Python isn't stringly typed, >> >> I expect this is an innocent typo, and you mean strictly. >> >>> single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, >> > > Yes, typo, I meant strictly. > >> Wait, what? >> First of all, python is strictly typed in that every object has exactly >> one type, which is different from other types. So you can't do "1"+2, as >> you can in some other languages. >> >> Anyway, this is interesting: Tell me more about how Python's dynamic >> nature makes it impossible to do whatever you're trying to do. I'm >> baffled. What are you trying to do, anyway? >> >>> which is usually used >>> in OO systems to implement code generators. So, what is the de facto >>> method in Python to handle source code generation? >> >> WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from >> your train of thought, apparently: Now, the thing that code generators >> probably share is that they write code to files. It depends on what I'm >> trying to do of course, but I expect there's a good chance that if I >> wrote a code generator in Python, it wouldn't be particularly >> object-oriented at all. > > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. I did some reading and it turned out that Python > can't do it without some tricks (function decorators and 3rd party > code). Well, yes: the name of a function or method refers to a single callable object and piece of code. if you care about the type of the argument, you must say so explicitly: class A: def dothing(self, obj): if isinstance(obj, str): self.dostringthing(obj) elif isinstance(obj, (int,float)): self.donumberthing(obj) else: self.dogenericthing(obj) # ... while python doesn't have C++-style function overloading, its alternative also doesn't have the limitations that come with it. From nagle at animats.com Thu Jul 15 15:10:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 15 Jul 2010 12:10:49 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> I had a similar problem back in 2007. See http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems Also see http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs There have been problems with SWIG. There have been problems with how OpenSSL was built (with or without elliptic curve crypto support). And there were some issues with building on 64-bit hardware running 32-bit operating systems, because the build script was checking the wrong system configuration parameter. Not sure what problem you're having with Mac OS X. From the errors, though, I suspect that not all the components involved are consistent with 32/64 bit width. John Nagle On 7/14/2010 10:05 PM, Adam Mercer wrote: > Anyone have any ideas about this? > > Cheers > > Adam > > On Tue, Jul 13, 2010 at 16:18, Adam Mercer wrote: >> Hi >> >> I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 >> (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a >> and it is failing with the following: >> >> 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c >> 106 :info:build swig -python >> -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 >> -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c >> SWIG/_m2crypto.i >> 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 117 :info:build SWIG/_util.i:9: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 >> 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG >> 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd >> -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes >> -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 >> -I/opt/local/include >> -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG >> -c SWIG/_m2crypto_wrap.c -o >> build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING >> 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': >> 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': >> 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': >> 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': >> 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': >> 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': >> 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used >> 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used >> 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': >> 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 138 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token >> 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token >> 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token >> 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token >> 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': >> 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': >> 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets >> in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in >> signedness >> 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': >> 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets >> in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in >> signedness >> 151 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token >> 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token >> 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token >> 156 :info:build SWIG/_m2crypto_wrap.c:6081: error: expected >> declaration specifiers or '...' before 'STACK' >> 157 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': >> 158 :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared >> (first use in this function) >> 159 :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared >> identifier is reported only once >> 160 :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function >> it appears in.) >> 161 :info:build SWIG/_m2crypto_wrap.c: In function >> 'x509_name_entry_create_by_txt': >> 162 :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets >> in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in >> signedness >> 163 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 164 :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 165 :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token >> 166 :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token >> 167 :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 168 :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token >> 169 :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token >> 170 :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token >> 171 :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token >> 172 :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token >> 173 :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 174 :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token >> 175 :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token >> 176 :info:build SWIG/_m2crypto_wrap.c:6385: error: expected >> declaration specifiers or '...' before 'STACK' >> 177 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': >> 178 :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared >> (first use in this function) >> 179 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 180 :info:build SWIG/_m2crypto_wrap.c:6390: error: expected >> declaration specifiers or '...' before 'STACK' >> 181 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': >> 182 :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared >> (first use in this function) >> 183 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 184 :info:build SWIG/_m2crypto_wrap.c:6418: error: expected >> declaration specifiers or '...' before 'STACK' >> 185 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': >> 186 :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared >> (first use in this function) >> 187 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument >> 3 of 'pkcs7_verify1' from incompatible pointer type >> 188 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument >> 4 of 'pkcs7_verify1' makes integer from pointer without a cast >> 189 :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments >> to function 'pkcs7_verify1' >> 190 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 191 :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 192 :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': >> 193 :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 194 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': >> 195 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared >> (first use in this function) >> 196 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' >> undeclared (first use in this function) >> 197 :info:build SWIG/_m2crypto_wrap.c:16913: error: expected >> expression before ')' token >> 198 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': >> 199 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared >> (first use in this function) >> 200 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared >> (first use in this function) >> 201 :info:build SWIG/_m2crypto_wrap.c:16923: error: expected >> expression before ')' token >> 202 :info:build SWIG/_m2crypto_wrap.c:16934: error: expected >> expression before ')' token >> 203 :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit >> declaration of function 'sk_ssl_cipher_num' >> 204 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': >> 205 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared >> (first use in this function) >> 206 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared >> (first use in this function) >> 207 :info:build SWIG/_m2crypto_wrap.c:16953: error: expected >> expression before ')' token >> 208 :info:build SWIG/_m2crypto_wrap.c:16968: error: expected >> expression before ')' token >> 209 :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit >> declaration of function 'sk_ssl_cipher_value' >> 210 :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer >> from integer of different size >> 211 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_ssl_get_peer_cert_chain': >> 212 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared >> (first use in this function) >> 213 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' >> undeclared (first use in this function) >> 214 :info:build SWIG/_m2crypto_wrap.c:17006: error: expected >> expression before ')' token >> 215 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': >> 216 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared >> (first use in this function) >> 217 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared >> (first use in this function) >> 218 :info:build SWIG/_m2crypto_wrap.c:17016: error: expected >> expression before ')' token >> 219 :info:build SWIG/_m2crypto_wrap.c:17027: error: expected >> expression before ')' token >> 220 :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit >> declaration of function 'sk_x509_num' >> 221 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': >> 222 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared >> (first use in this function) >> 223 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared >> (first use in this function) >> 224 :info:build SWIG/_m2crypto_wrap.c:17046: error: expected >> expression before ')' token >> 225 :info:build SWIG/_m2crypto_wrap.c:17061: error: expected >> expression before ')' token >> 226 :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit >> declaration of function 'sk_x509_value' >> 227 :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer >> from integer of different size >> 228 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_name_entry_set_data': >> 229 :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets >> in assignment differ in signedness >> 230 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_store_ctx_get1_chain': >> 231 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared >> (first use in this function) >> 232 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' >> undeclared (first use in this function) >> 233 :info:build SWIG/_m2crypto_wrap.c:19741: error: expected >> expression before ')' token >> 234 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': >> 235 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared >> (first use in this function) >> 236 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' >> undeclared (first use in this function) >> 237 :info:build SWIG/_m2crypto_wrap.c:20573: error: expected >> expression before ')' token >> 238 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': >> 239 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared >> (first use in this function) >> 240 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared >> (first use in this function) >> 241 :info:build SWIG/_m2crypto_wrap.c:20583: error: expected >> expression before ')' token >> 242 :info:build SWIG/_m2crypto_wrap.c:20593: error: expected >> expression before ')' token >> 243 :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit >> declaration of function 'sk_x509_free' >> 244 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': >> 245 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared >> (first use in this function) >> 246 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared >> (first use in this function) >> 247 :info:build SWIG/_m2crypto_wrap.c:20609: error: expected >> expression before ')' token >> 248 :info:build SWIG/_m2crypto_wrap.c:20624: error: expected >> expression before ')' token >> 249 :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit >> declaration of function 'sk_x509_push' >> 250 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': >> 251 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared >> (first use in this function) >> 252 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared >> (first use in this function) >> 253 :info:build SWIG/_m2crypto_wrap.c:20653: error: expected >> expression before ')' token >> 254 :info:build SWIG/_m2crypto_wrap.c:20664: error: expected >> expression before ')' token >> 255 :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit >> declaration of function 'sk_x509_pop' >> 256 :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer >> from integer of different size >> 257 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_req_add_extensions': >> 258 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared >> (first use in this function) >> 259 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared >> (first use in this function) >> 260 :info:build SWIG/_m2crypto_wrap.c:20871: error: expected >> expression before ')' token >> 261 :info:build SWIG/_m2crypto_wrap.c:20890: error: expected >> expression before ')' token >> 262 :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments >> to function 'x509_req_add_extensions' >> 263 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': >> 264 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared >> (first use in this function) >> 265 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' >> undeclared (first use in this function) >> 266 :info:build SWIG/_m2crypto_wrap.c:20981: error: expected >> expression before ')' token >> 267 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509v3_set_conf_lhash': >> 268 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared >> (first use in this function) >> 269 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared >> (first use in this function) >> 270 :info:build SWIG/_m2crypto_wrap.c:20991: error: expected >> expression before ')' token >> 271 :info:build SWIG/_m2crypto_wrap.c:21002: error: expected >> expression before ')' token >> 272 :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit >> declaration of function 'x509v3_set_conf_lhash' >> 273 :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer >> from integer of different size >> 274 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': >> 275 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared >> (first use in this function) >> 276 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared >> (first use in this function) >> 277 :info:build SWIG/_m2crypto_wrap.c:21013: error: expected >> expression before ')' token >> 278 :info:build SWIG/_m2crypto_wrap.c:21038: error: expected >> expression before ')' token >> 279 :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit >> declaration of function 'x509v3_ext_conf' >> 280 :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer >> from integer of different size >> 281 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_new_null': >> 282 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared >> (first use in this function) >> 283 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' >> undeclared (first use in this function) >> 284 :info:build SWIG/_m2crypto_wrap.c:21116: error: expected >> expression before ')' token >> 285 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_free': >> 286 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared >> (first use in this function) >> 287 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared >> (first use in this function) >> 288 :info:build SWIG/_m2crypto_wrap.c:21126: error: expected >> expression before ')' token >> 289 :info:build SWIG/_m2crypto_wrap.c:21136: error: expected >> expression before ')' token >> 290 :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit >> declaration of function 'sk_x509_extension_free' >> 291 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_push': >> 292 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared >> (first use in this function) >> 293 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared >> (first use in this function) >> 294 :info:build SWIG/_m2crypto_wrap.c:21152: error: expected >> expression before ')' token >> 295 :info:build SWIG/_m2crypto_wrap.c:21167: error: expected >> expression before ')' token >> 296 :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit >> declaration of function 'sk_x509_extension_push' >> 297 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_pop': >> 298 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared >> (first use in this function) >> 299 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared >> (first use in this function) >> 300 :info:build SWIG/_m2crypto_wrap.c:21191: error: expected >> expression before ')' token >> 301 :info:build SWIG/_m2crypto_wrap.c:21202: error: expected >> expression before ')' token >> 302 :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit >> declaration of function 'sk_x509_extension_pop' >> 303 :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer >> from integer of different size >> 304 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_num': >> 305 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared >> (first use in this function) >> 306 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared >> (first use in this function) >> 307 :info:build SWIG/_m2crypto_wrap.c:21218: error: expected >> expression before ')' token >> 308 :info:build SWIG/_m2crypto_wrap.c:21229: error: expected >> expression before ')' token >> 309 :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit >> declaration of function 'sk_x509_extension_num' >> 310 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_value': >> 311 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared >> (first use in this function) >> 312 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared >> (first use in this function) >> 313 :info:build SWIG/_m2crypto_wrap.c:21248: error: expected >> expression before ')' token >> 314 :info:build SWIG/_m2crypto_wrap.c:21263: error: expected >> expression before ')' token >> 315 :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit >> declaration of function 'sk_x509_extension_value' >> 316 :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer >> from integer of different size >> 317 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_make_stack_from_der_sequence': >> 318 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared >> (first use in this function) >> 319 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' >> undeclared (first use in this function) >> 320 :info:build SWIG/_m2crypto_wrap.c:21314: error: expected >> expression before ')' token >> 321 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_get_der_encoding_stack': >> 322 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared >> (first use in this function) >> 323 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared >> (first use in this function) >> 324 :info:build SWIG/_m2crypto_wrap.c:21324: error: expected >> expression before ')' token >> 325 :info:build SWIG/_m2crypto_wrap.c:21335: error: expected >> expression before ')' token >> 326 :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit >> declaration of function 'get_der_encoding_stack' >> 327 :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer >> from integer of different size >> 328 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': >> 329 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared >> (first use in this function) >> 330 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared >> (first use in this function) >> 331 :info:build SWIG/_m2crypto_wrap.c:22343: error: expected >> expression before ')' token >> 332 :info:build SWIG/_m2crypto_wrap.c:22366: error: expected >> expression before ')' token >> 333 :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit >> declaration of function 'pkcs7_encrypt' >> 334 :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer >> from integer of different size >> 335 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': >> 336 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared >> (first use in this function) >> 337 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared >> (first use in this function) >> 338 :info:build SWIG/_m2crypto_wrap.c:22547: error: expected >> expression before ')' token >> 339 :info:build SWIG/_m2crypto_wrap.c:22582: error: expected >> expression before ')' token >> 340 :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument >> 4 of 'pkcs7_sign1' makes integer from pointer without a cast >> 341 :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments >> to function 'pkcs7_sign1' >> 342 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': >> 343 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared >> (first use in this function) >> 344 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared >> (first use in this function) >> 345 :info:build SWIG/_m2crypto_wrap.c:22628: error: expected >> expression before ')' token >> 346 :info:build SWIG/_m2crypto_wrap.c:22659: error: expected >> expression before ')' token >> 347 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument >> 3 of 'pkcs7_verify1' from incompatible pointer type >> 348 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument >> 4 of 'pkcs7_verify1' makes integer from pointer without a cast >> 349 :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments >> to function 'pkcs7_verify1' >> 350 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': >> 351 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared >> (first use in this function) >> 352 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared >> (first use in this function) >> 353 :info:build SWIG/_m2crypto_wrap.c:22707: error: expected >> expression before ')' token >> 354 :info:build SWIG/_m2crypto_wrap.c:22734: error: expected >> expression before ')' token >> 355 :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument >> 3 of 'pkcs7_verify0' makes integer from pointer without a cast >> 356 :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments >> to function 'pkcs7_verify0' >> 357 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': >> 358 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared >> (first use in this function) >> 359 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared >> (first use in this function) >> 360 :info:build SWIG/_m2crypto_wrap.c:23188: error: expected >> expression before ')' token >> 361 :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' >> undeclared (first use in this function) >> 362 :info:build SWIG/_m2crypto_wrap.c:23211: error: expected >> expression before ')' token >> 363 :info:build SWIG/_m2crypto_wrap.c:23227: error: expected >> expression before ')' token >> 364 :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 >> >> Anyone know a way to resolve this? >> >> Cheers >> >> Adam >> From stefan_ml at behnel.de Thu Jul 15 15:10:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:10:58 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Karsten Wutzke, 15.07.2010 20:45: > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. Well, then do that. Put the types into a dict and map them to the functions to call, then call the function through the dict. That's a pretty common way to do dispatching. > Note, that I have an hierarchical object structure which I want to > iterate over, so using OO looked natural to me. If there's a better > approach, I'm all ears. You speak in riddles, but my guess is that your problem is that you don't want to dispatch mechanism to match only exact types but also subtypes. No problem, just build your dict incrementally and add new types as they come in. See this file for an example: http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py Stefan From stefan_ml at behnel.de Thu Jul 15 15:14:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:14:56 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> Message-ID: Karsten Wutzke, 15.07.2010 21:00: >> Yes, typo, I meant strictly. > > Damn, I mean strongly. At least not for identifying which methods to > call depending on the type/s. I think you meant "statically typed". http://c2.com/cgi-bin/wiki?StronglyTyped http://www.c2.com/cgi/wiki?StaticTyping Stefan From python at mrabarnett.plus.com Thu Jul 15 15:33:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jul 2010 20:33:47 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F629B.9000208@mrabarnett.plus.com> Stefan Behnel wrote: > Karsten Wutzke, 15.07.2010 20:45: >> Well, I'm most experienced in OO, so writing OO in Python seems like >> the way to start with Python. The visitor pattern uses single- >> dispatch, that is, it determines which method to call be the type of >> object passed in. > > Well, then do that. Put the types into a dict and map them to the > functions to call, then call the function through the dict. That's a > pretty common way to do dispatching. > > >> Note, that I have an hierarchical object structure which I want to >> iterate over, so using OO looked natural to me. If there's a better >> approach, I'm all ears. > > You speak in riddles, but my guess is that your problem is that you > don't want to dispatch mechanism to match only exact types but also > subtypes. No problem, just build your dict incrementally and add new > types as they come in. See this file for an example: > > http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py > Another variation: the dispatch table starts with entries for certain types then it adds subtypes on demand: def visit(self, obj): try: handler = self.dispatch_table[type(obj)] except KeyError: for disp_type, disp_func in self.dispatch_table.items(): if isinstance(obj, disp_type): self.dispatch_table[type(obj)] = disp_func handler = disp_func else: raise RuntimeError("Visitor does not accept object: %s" % obj) return handler(obj) From samnsparky at gmail.com Thu Jul 15 15:37:26 2010 From: samnsparky at gmail.com (Sparky) Date: Thu, 15 Jul 2010 12:37:26 -0700 (PDT) Subject: Best Pythonic Approach to Annotation/Metadata? Message-ID: Hello Python community! I am building a JSON-RPC web application that uses quite a few models. I would like to return JSON encoded object information and I need a system to indicate which properties should be returned when the object is translated to a JSON encoded string. Unfortunately, this application runs on top of Google's App Engine and, thus, private attributes are not an option. Also, a preliminary search leads me to believe that there are no real established ways to annotate variables. Ideally I want to do something like: def to_JSON(self): returnDict = {} for member in filter(someMethod, inspect.getmembers(self)): returnDict[member[0]] = member[1] return json.dumps(returnDict) I recognize that two solutions would be to 1) include a prefix like "public_" before variable names or 2) have a list/tuple of attributes that should be transmitted, simply using the "in" operator. However, both these options seem like a pretty ungraceful way to do it. Does anyone else have an idea? Are there any established methods to apply metadata / annotations to variables in Python or do you believe one of the above is a good "pythonic" way to solve this problem? I am using 2.6. Thanks, Sam From mccredie at gmail.com Thu Jul 15 15:43:06 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 15 Jul 2010 19:43:06 +0000 (UTC) Subject: Code generator and visitor pattern References: Message-ID: Karsten Wutzke web.de> writes: > So, what is the de facto method in Python to handle source code generation? Take a look at the NodeVisitor class in the ast module in python 2.6+. The visitor pattern is implemented in the python standard library. Matt From stefan_ml at behnel.de Thu Jul 15 15:48:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:48:54 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4C3F629B.9000208@mrabarnett.plus.com> References: <4C3F629B.9000208@mrabarnett.plus.com> Message-ID: MRAB, 15.07.2010 21:33: > Stefan Behnel wrote: >> Karsten Wutzke, 15.07.2010 20:45: >>> Well, I'm most experienced in OO, so writing OO in Python seems like >>> the way to start with Python. The visitor pattern uses single- >>> dispatch, that is, it determines which method to call be the type of >>> object passed in. >> >> Well, then do that. Put the types into a dict and map them to the >> functions to call, then call the function through the dict. That's a >> pretty common way to do dispatching. >> >> >>> Note, that I have an hierarchical object structure which I want to >>> iterate over, so using OO looked natural to me. If there's a better >>> approach, I'm all ears. >> >> You speak in riddles, but my guess is that your problem is that you >> don't want to dispatch mechanism to match only exact types but also >> subtypes. No problem, just build your dict incrementally and add new >> types as they come in. See this file for an example: >> >> http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py >> > Another variation: the dispatch table starts with entries for certain > types then it adds subtypes on demand: > > def visit(self, obj): > try: > handler = self.dispatch_table[type(obj)] > except KeyError: > for disp_type, disp_func in self.dispatch_table.items(): > if isinstance(obj, disp_type): > self.dispatch_table[type(obj)] = disp_func > handler = disp_func > else: > raise RuntimeError("Visitor does not accept object: %s" % obj) > return handler(obj) Well, yes, that's basically what the code behind the above link does, except that it follows the type hierarchy correctly to find the closest match. Stefan From ranjithtenz at gmail.com Thu Jul 15 16:02:50 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Fri, 16 Jul 2010 01:32:50 +0530 Subject: Python script to start, restart and stop the apache server Message-ID: Hi, I planned to write a python script to starts the apache server and when the HTTPD goes down/drop it should auto restart and when user chooses stop it should stop the apache server. Here the start and stop should be user set but the restart when the server goes down. Similar to this program, This is shell script, #!/bin/bash # Apache Process Monitor # Restart Apache Web Server When It Goes Down # ------------------------------------------------------------------------- # Copyright (c) 2003 nixCraft project # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- # RHEL / CentOS / Fedora Linux restart command RESTART="/sbin/service httpd restart" # uncomment if you are using Debian / Ubuntu Linux #RESTART="/etc/init.d/apache2 restart" #path to pgrep command PGREP="/usr/bin/pgrep" # Httpd daemon name, # Under RHEL/CentOS/Fedora it is httpd # Under Debian 4.x it is apache2 HTTPD="httpd" # find httpd pid $PGREP ${HTTPD} if [ $? -ne 0 ] # if apache not running then # restart apache $RESTART fi Johan Gr?nqvist and Daniel Fetchinson thanks for your reply. -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkrukoff at ltgc.com Thu Jul 15 16:26:05 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Thu, 15 Jul 2010 14:26:05 -0600 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: <1279225565.4395.9.camel@localhost.localdomain> On Thu, 2010-07-15 at 12:37 -0700, Sparky wrote: > the above is a good "pythonic" way to solve this problem? I am using > 2.6. Hopefully a helpful correction, but if you're running on google app engine, you're using python 2.5 on the google side irrespective of what you're running for development. -- John Krukoff Land Title Guarantee Company From peter.milliken at gmail.com Thu Jul 15 16:34:22 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 15 Jul 2010 13:34:22 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: On Jul 16, 2:45?am, kj wrote: > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > How do you do Python code-folding in Emacs? > > Thanks! > > ~K I don't - when I first looked at folding-mode (I assume this is what you are referring too?) I couldn't be bothered putting the {{{ }}} strings into the code comments - maybe somebody else has had better success with it? But I just couldn't be bothered. Although if you use a template generating system such as ELSE, you could probably work it into the code templates and have them generated automatically. I must admit that I started to modify my code templates once upon a time to provide this but lost interest part way through and just put up with splitting the window and "hiding" the intervening code that way. Personally I think something like "folding" would be better worked into the major mode and performed on a syntactic scan basis i.e. the elisp must understand where the code blocks begin and end and make folding decisions based on where point is located in relation to surround code blocks. Actually, it might be possible now that pymacs is available (well, I say "now" - even though pymacs has been available for quite some time, I looked at folding mode even earlier!) i.e. call a Python helper program that would provide the syntactic scanning of the buffer contents and return appropriate markers into the buffer for the folding mode code to work with. One day when I have run out of other (programming) things to do I might investigate this :-) Anybody else now of any better ideas or whatever? Now that I think about it, I wouldn't mind using folding mode if I could make it "easier" to use myself! :-) Peter From hwpi31 at gmail.com Thu Jul 15 16:40:49 2010 From: hwpi31 at gmail.com (Nonpython) Date: Thu, 15 Jul 2010 13:40:49 -0700 (PDT) Subject: [OFF TOPIC] How to Learn Lambda Calculus: A Guide Message-ID: 1: Try to learn lambda calculus 2: Fail to learn lambda calculus 3: Sit in corner rocking 4: Consider suicide. From peter.milliken at gmail.com Thu Jul 15 16:53:51 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 15 Jul 2010 13:53:51 -0700 (PDT) Subject: How to Learn Lambda Calculus: A Guide References: Message-ID: <33833e4a-e2c0-445a-81f3-d70ffc021900@p22g2000pre.googlegroups.com> On Jul 16, 6:40?am, Nonpython wrote: > 1: Try to learn lambda calculus > 2: Fail to learn lambda calculus > 3: Sit in corner rocking > 4: Consider suicide. You forgot: 5: (quietly) drooling But then that might be part of the advanced course? I really can't remember, my PHD in 'lambda calculus' was done so long ago now... From ian.hobson at ntlworld.com Thu Jul 15 16:54:30 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:54:30 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F7586.2070202@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From ian.hobson at ntlworld.com Thu Jul 15 16:55:35 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:55:35 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F75C7.2020707@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From ian.hobson at ntlworld.com Thu Jul 15 16:55:35 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:55:35 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F75C7.2020707@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From python at bdurham.com Thu Jul 15 17:14:22 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 15 Jul 2010 17:14:22 -0400 Subject: Possible to include \n chars in doctest code samples or output? Message-ID: <1279228462.13146.1385097561@webmail.messagingengine.com> I'm working with some Python 2.6 code that is using the doctest module for unittests. I tried adding tests whose code and results required newlines (\n). Apparently newlines in string constants breaks the doctest code. Any workarounds other than using another char for newlines and wrapping all my strings with .replace( someChar, chr(10) )? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Thu Jul 15 17:26:59 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 23:26:59 +0200 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279228462.13146.1385097561@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> Message-ID: <4C3F7D23.2060204@jollans.com> On 07/15/2010 11:14 PM, python at bdurham.com wrote: > I'm working with some Python 2.6 code that is using the doctest module > for unittests. > > I tried adding tests whose code and results required newlines (\n). > Apparently newlines in string constants breaks the doctest code. > > Any workarounds other than using another char for newlines and wrapping > all my strings with .replace( someChar, chr(10) )? Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. Remember that the two following strings are identical: """a b""" """a\nb""" As are these two: r"\n" "\\n" Anyway, you need to escape the backslash if you want backslash-n to be in your docstring. Otherwise you'll get a newline like any other newline, not a character sequence doctest can eval() to a newline while processing. From ramercer at gmail.com Thu Jul 15 18:03:13 2010 From: ramercer at gmail.com (Adam Mercer) Date: Thu, 15 Jul 2010 17:03:13 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> References: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 15, 2010 at 14:10, John Nagle wrote: > ? I had a similar problem back in 2007. ?See > > http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems > > Also see > > http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs > > ? There have been problems with SWIG. There have been problems with > how OpenSSL was built (with or without elliptic curve crypto support). > And there were some issues with building on 64-bit hardware running > 32-bit operating systems, because the build script was checking > the wrong system configuration parameter. > > ? Not sure what problem you're having with Mac OS X. ?From the > errors, though, I suspect that not all the components involved > are consistent with 32/64 bit width. Thanks, I'm sure everything is consistent with the architecture, i.e. everything is 64 bit. The last time I build M2Crypto on this box was against SWIG-1.3.x and OpenSSL-0.9.8? So one of these (or both) has broken something... Looks like I'll have to revert each one at a time... Cheers Adam From a.j.romanista at gmail.com Thu Jul 15 18:04:37 2010 From: a.j.romanista at gmail.com (ata.jaf) Date: Thu, 15 Jul 2010 15:04:37 -0700 (PDT) Subject: About problems that I have with learning wxPython in Macintosh Message-ID: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Hi, I'm newbie to wxPython and need it to develop my little app. But from start I have problems with tutorials. Because all of them are compatible with Windows but not so much with Mac. For example in this code: import wx class MainWindow(wx.Frame) : def __init__(self, parent, title) : wx.Frame.__init__(self, parent, title=title, size=(200, 100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.CreateStatusBar() filemenu = wx.Menu() filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this program.') filemenu.AppendSeparator() filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') menuBar = wx.MenuBar() menuBar.Append(filemenu, '&File') self.SetMenuBar(menuBar) self.Show(True) app = wx.App(False) frame = MainWindow(None, 'Sample editor') app.MainLoop() The menus doesn't appear in the product. Can anyone help me to find a tutorial that is for using wxPython on a Mac? Thanks Ata From debatem1 at gmail.com Thu Jul 15 18:14:53 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 15 Jul 2010 15:14:53 -0700 Subject: How to Learn Lambda Calculus: A Guide In-Reply-To: References: <33833e4a-e2c0-445a-81f3-d70ffc021900@p22g2000pre.googlegroups.com> Message-ID: On Thu, Jul 15, 2010 at 1:53 PM, Peter wrote: > On Jul 16, 6:40?am, Nonpython wrote: >> 1: Try to learn lambda calculus >> 2: Fail to learn lambda calculus >> 3: Sit in corner rocking >> 4: Consider suicide. > > You forgot: > > 5: (quietly) drooling > > But then that might be part of the advanced course? I really can't > remember, my PHD in 'lambda calculus' was done so long ago now... No PhD required (if one ever is, besides for jobification purposes). Simple (somewhat shallow) introduction: http://eflorenzano.com/blog/post/lambda-calculus/ A construction of the Church numerals: http://www.stephendiehl.com/?p=66 Not so hard, really. Geremy Condra From debatem1 at gmail.com Thu Jul 15 18:17:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 15 Jul 2010 15:17:48 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 15, 2010 at 3:03 PM, Adam Mercer wrote: > On Thu, Jul 15, 2010 at 14:10, John Nagle wrote: >> ? I had a similar problem back in 2007. ?See >> >> http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems >> >> Also see >> >> http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs >> >> ? There have been problems with SWIG. There have been problems with >> how OpenSSL was built (with or without elliptic curve crypto support). >> And there were some issues with building on 64-bit hardware running >> 32-bit operating systems, because the build script was checking >> the wrong system configuration parameter. >> >> ? Not sure what problem you're having with Mac OS X. ?From the >> errors, though, I suspect that not all the components involved >> are consistent with 32/64 bit width. > > Thanks, I'm sure everything is consistent with the architecture, i.e. > everything is 64 bit. The last time I build M2Crypto on this box was > against SWIG-1.3.x and OpenSSL-0.9.8? So one of these (or both) has > broken something... Looks like I'll have to revert each one at a > time... > > Cheers > > Adam The move to 1.0 was a PITA for me, although I appreciate the improved EVP_PKEY support it will probably break a chunk of code. Geremy Condra From mukeshtiwari.iiitm at gmail.com Thu Jul 15 18:22:39 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Thu, 15 Jul 2010 15:22:39 -0700 (PDT) Subject: File transfer on network Message-ID: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Hello all Currently i am trying to develop a client and server in python. Client takes screenshot in every 20 seconds and send it to server. Server store the received file in folder. Here is code for Client import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/tmp_1/screenshot.png',"png") f=open('/home//tmp_1/screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() Server Code import sys import socket import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) host,port="",50007 s.bind((host,port)) s.listen(1) conn,add=s.accept() i=0 while 1: f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') while 1: data=conn.recv(2048) if not data:break f.write(data) f.close() print 'file received' time.sleep(20) i+=1; #print ' file received ' conn.close() My problem is that server is copying only first image copyscreenshot_0.png while my client continuously taking screen shot. Kindly tell me what is wrong with my server code. Thank you Mukesh Tiwari import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False, 8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(), 0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/user/Programs/Mukesh_Tiwari/ python/tmp_1/screenshot.png',"png") f=open('/home/user/Programs/Mukesh_Tiwari/python/tmp_1/ screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "client.py" 25L, 715C 7,2-9 All From samnsparky at gmail.com Thu Jul 15 18:30:11 2010 From: samnsparky at gmail.com (Sparky) Date: Thu, 15 Jul 2010 15:30:11 -0700 (PDT) Subject: Best Pythonic Approach to Annotation/Metadata? References: Message-ID: <4944e4eb-7a04-43f6-a21b-ba122286cc1a@d37g2000yqm.googlegroups.com> On Jul 15, 2:26?pm, John Krukoff wrote: > On Thu, 2010-07-15 at 12:37 -0700, Sparky wrote: > > > > > the above is a good "pythonic" way to solve this problem? I am using > > 2.6. > > Hopefully a helpful correction, but if you're running on google app > engine, you're using python 2.5 on the google side irrespective of what > you're running for development. > > -- > John Krukoff > Land Title Guarantee Company Sorry about that and thanks for pointing out my mistake there. Sam From mukeshtiwari.iiitm at gmail.com Thu Jul 15 18:35:51 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Thu, 15 Jul 2010 15:35:51 -0700 (PDT) Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <3728a08c-f994-4d2e-9d23-cccc91a59990@i18g2000pro.googlegroups.com> Kindly see this post as above post contains some garbage code in end. Sorry for that. Hello all Currently i am trying to develop a client and server in python. Client takes screenshot in every 20 seconds and send it to server. Server store the received file in folder. Here is code for Client import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False, 8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(), 0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/tmp_1/screenshot.png',"png") f=open('/home//tmp_1/screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() Server Code import sys import socket import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) host,port="",50007 s.bind((host,port)) s.listen(1) conn,add=s.accept() i=0 while 1: f=open('/home/tmp_2/copyscreenshot_'+str(i) +'.png','wb') while 1: data=conn.recv(2048) if not data:break f.write(data) f.close() print 'file received' time.sleep(20) i+=1; #print ' file received ' conn.close() My problem is that server is copying only first image copyscreenshot_0.png while my client continuously taking screen shot. Kindly tell me what is wrong with my server code. Thank you Mukesh Tiwari From luke.leighton at gmail.com Thu Jul 15 18:39:29 2010 From: luke.leighton at gmail.com (lkcl) Date: Thu, 15 Jul 2010 15:39:29 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> <1278984638.9880.46.camel@tim-laptop> Message-ID: On Jul 13, 12:00?pm, Luke Kenneth Casson Leighton wrote: > but... not being funny or anything, but basically i'm done already :)multitaskhttpdworks, it doesn't need stackless, i completed a JSONRPC > service last night, i'll add POST of multi-part forms today, and i > have everything that [GNUmed] will need. ok instead of adding this to httpd.py i created an HTTP proxy out of multitaskhttpd. i also cobbled together an example JSONRPC Server which is highly likely to be used in gnumed, now. this modified version of SimpleJSONRPCServer.py i had to rip bits of BaseHTTPServer.py and add in Connection Keep-Alives on every response. so, send_error needed modding/replacing, as did send_head, list_directory and so on, all with a view to making sure that the HTTP proxy is "happy". the reason why the proxy works is because the incoming HTTP connection results in an HTTP/1.1 proxy connection with Connection: Keep-Alive set. so, even if the user's browser drops the connection, the proxy permanently keeps open the connection to the upstream HTTP server. in the case of the standard SimpleHTTPServer.py and so on that results in the handle_request() loop basically serving that same user _forever_. well... it would, if it wasn't for the fact that the standard version of send_error() in BaseHTTPServer.py does "Connection: Close", hence the reason why i had to replace it. so, yeah - now you can do truly dreadful things like... create a massive in-memory data structure and never have to serialise it because the back-end process will _still_ be around pretty much forever... and you can keep doing that until the server runs out of memory. hurrah! l. From python at mrabarnett.plus.com Thu Jul 15 19:08:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 00:08:09 +0100 Subject: File transfer on network In-Reply-To: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <4C3F94D9.8020501@mrabarnett.plus.com> mukesh tiwari wrote: > Hello all > Currently i am trying to develop a client and server in python. Client > takes screenshot in every 20 seconds and send it to server. Server > store the received file in folder. Here is code for Client > > import sys > import socket > import gtk.gdk > import time > if __name__ == "__main__": > s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); > host,port="localhost",50007 > s.connect((host,port)) > while 1: > w = gtk.gdk.get_default_root_window() > sz = w.get_size() > pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) > pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) > if (pb != None): > pb.save('/home/tmp_1/screenshot.png',"png") > f=open('/home//tmp_1/screenshot.png','rb') > while 1: > blk=f.read(2048) > if not blk:break > s.send(blk) > f.close() > print 'file transfer done'; > time.sleep(20) > > s.close() > > > Server Code > import sys > import socket > import time > if __name__ == "__main__": > > s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) > host,port="",50007 > s.bind((host,port)) > s.listen(1) > conn,add=s.accept() > i=0 > while 1: > f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') > while 1: > data=conn.recv(2048) > if not data:break > f.write(data) > > f.close() > print 'file received' > time.sleep(20) > i+=1; > #print ' file received ' > > conn.close() > > > My problem is that server is copying only first image > copyscreenshot_0.png while my client continuously taking screen shot. > Kindly tell me what is wrong with my server code. > The .recv will return an empty string only when the connection is closed by the client, but the client keeps the connection open. You could either open and close a connection for each image, or have the client tell the server how many bytes it's going to send, followed by the bytes (my preference would be to send the size as a string ending with, say, a newline). Another point: the .send method doesn't guarantee that it'll send all the bytes (it'll return the number of bytes that it has actually sent); use the .sendall method instead. From pavlovevidence at gmail.com Thu Jul 15 19:14:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jul 2010 16:14:01 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> On Jul 15, 11:45?am, Karsten Wutzke wrote: > On 15 Jul., 20:28, Thomas Jollans wrote: > > > On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > > > > Hello, > > > > this is obviously a Python OO question: > > > > Since Python isn't stringly typed, > > > I expect this is an innocent typo, and you mean strictly. > > > > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, > > Yes, typo, I meant strictly. > > > > > > > Wait, what? > > First of all, python is strictly typed in that every object has exactly > > one type, which is different from other types. So you can't do "1"+2, as > > you can in some other languages. > > > Anyway, this is interesting: Tell me more about how Python's dynamic > > nature makes it impossible to do whatever you're trying to do. I'm > > baffled. What are you trying to do, anyway? > > > > which is usually used > > > in OO systems to implement code generators. So, what is the de facto > > > method in Python to handle source code generation? > > > WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from > > your train of thought, apparently: Now, the thing that code generators > > probably share is that they write code to files. It depends on what I'm > > trying to do of course, but I expect there's a good chance that if I > > wrote a code generator in Python, it wouldn't be particularly > > object-oriented at all. > > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. I did some reading and it turned out that Python > can't do it without some tricks (function decorators and 3rd party > code). For what I'm doing, I can't, or rather don't want to rely on > 3rd party code (that has reasons). Thus, the visitor OO pattern must > be replaced by some other way. Oh brother. Around these parts, we consider the main use of most Design Patterns to be to work around limitations of other languages. Visitor Pattern is probably the worst example of it. In Python it's completely unnecessary (at least in its boilerplate- heavy incarnation as used in C++), and the fact that Python isn't strongly typed, as you put it, is exactly the reason why. Say you have a bunch of unrelated types that define a calculate method, you have a variable x that could be any of these types. Here's how you would do that in Python: x.calculate() Bam, that's it. Visitor Pattern in Python. You don't have to create a bunch of homemade dispatching boilerplate like you do in C++. Carl Banks From missive at hotmail.com Thu Jul 15 19:20:42 2010 From: missive at hotmail.com (Lee Harr) Date: Fri, 16 Jul 2010 03:50:42 +0430 Subject: [ANNC] pynguin-0.9 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release has focused on improvements to usabilty and ??? user-friendliness, with much input and many reports ??? from actual users. Thanks Alec! There is a huge list ??? of bug fixes and new features. Pynguin is tested with Python 2.6.5 and PyQt 4.7.2 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.9: ??? Pynguin API ??????? - added pythonic accessors for .x .y and .heading ??????? - added methods for getting heading: xyh() and h() ??????? - added promote() method to change which pynguin is primary ??????? - added remove() to get rid of unneeded pynguins ??????????? - also enables removing pynguin, but keeping its drawing ??????????? - added reap() method to remove all other pynguins and ??????????????? take charge of all their drawings at once ??????? - made turnto() instant, like goto() ??????? - plain reset() now only affects single pynguin ??????????? - restores as much as possible to initial state ??????????? - use reset(True) or reset(full=True) for complete reset ??????? - square() is now built in ??????? - added avatar() to access setImageid() more reliably ??????? - changed onclick() API slightly ??????????? - updated onclick examples and added new examples ??? Canvas ??????? - added ability to zoom and pan the canvas ??????? - added ability to track pynguin if it draws off the screen ??????? - pynguins can now be dragged in to position ??????? - now passes mouse clicks to all pynguins ??? Integrated Editor ??????? - fixed problem with editor undo entries being lost ??????? - better recognition of when document has actually been modified ??????? - automatically strips prompts when pasting to code editor ??????? - allow changing font size and word wrapping in editor ??????? - fixed tabifying/untabifying selection in editor ??? Integrated Console ??????? - fixed copying from console area (shortcut and context menu) ??????? - KeyboardInterrupt is now quiet by default ??????? - fixed tab/backtab in console area ??????? - added keyboard shortcuts for scrolling in console ??????? - added ctrl-d shortcut for exiting when typing in console ??? General ??????? - added periodic automatic saving ??????? - better control-c handling ??????????? - code that never uses Pynguin methods can now be stopped ??????????? - limits print rate to keep console responsive ??????????? - fixed prompt alignment after ctrl-c on non-function code ??????? - made .png default export and improved error message on failure ??????? - now allows unicode in code area and console ??????? - added command line switch to enable debugging ??????? - added Save As, New, and Open shortcuts _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 From benjamin.kaplan at case.edu Thu Jul 15 19:28:31 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 15 Jul 2010 16:28:31 -0700 Subject: About problems that I have with learning wxPython in Macintosh In-Reply-To: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> References: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Message-ID: On Thu, Jul 15, 2010 at 3:04 PM, ata.jaf wrote: > Hi, > I'm newbie to wxPython and need it to develop my little app. > But from start I have problems with tutorials. Because all of them are > compatible with Windows but not so much with Mac. > For example in this code: > > > import wx > > class MainWindow(wx.Frame) : > def __init__(self, parent, title) : > wx.Frame.__init__(self, parent, title=title, size=(200, 100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.CreateStatusBar() > > filemenu = wx.Menu() > > filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this > program.') > filemenu.AppendSeparator() > filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') > > menuBar = wx.MenuBar() > menuBar.Append(filemenu, '&File') > self.SetMenuBar(menuBar) > self.Show(True) > > app = wx.App(False) > frame = MainWindow(None, 'Sample editor') > app.MainLoop() > > > > The menus doesn't appear in the product. > Can anyone help me to find a tutorial that is for using wxPython on a > Mac? > Thanks > Ata > -- > Did you look on the menubar? wxPython uses native components (Cocoa in the case of OS X) so the menu should appear in the menu bar and not in the application window. wx will automatically move some of the items in the menu to the appropriate location (About, Preferences, and Quit are all in the Application menu for instance and not the file menu) The wxPython Wiki has a page about Mac-specific issues : http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X Also, you'll get better answer for questions like this (which are wx-specific and not Python-specific) on the wxPython list: http://groups.google.com/group/wxpython-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes.black at gmail.com Thu Jul 15 19:46:35 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 15 Jul 2010 16:46:35 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: > Where does the error occur? If Cameron is right, it occurs somewhere > completely different, when serializer.dump() is already long done, when > some unsuspecting fool tries to do something with serializer.outf (such > as closing it) I have found it but still I don't get it. Dump looks like this: ... File "C: ... ineptpdf8.4.20.pyw", line 1266, in initialize return self.initialize_fopn(docid, param) File "C: ... ineptpdf8.4.20.pyw", line 1411, in initialize_fopn print buildurl IOError: [Errno 9] Bad file descriptor Two strange things: 1st: in the buildurl is only the url (as a string) to open (something like http://www.serverblaba.com/asdfasdf?wdfasdf=4&awfwf=34 ...) 2nd: it works if I start in in IDLE, it doesn't work if I double klick on the .pyw file. How can printing out a string throw a IOError exception? I'm quite puzzled. From f2h2d2 at gmail.com Thu Jul 15 19:46:40 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Thu, 15 Jul 2010 16:46:40 -0700 (PDT) Subject: Fairy scenes Message-ID: <9837d665-a093-41f0-aba4-4261b40271ea@j4g2000yqh.googlegroups.com> Fairy scenes The sections that cried and asked YouTube viewers translation: http://www.youtube.com/v/IFq9cjtrWlQ&rel=0 http://www.youtube.com/v/y2BN73Q-AJw&rel=0 http://www.youtube.com/v/nNFMvznJ-4c&rel=0 http://www.youtube.com/v/qVB9HNQ-w2I&rel=0 http://www.youtube.com/v/RWfR9z91j8I&rel=0 http://www.todayislam.com/yusuf.htm http://islamtomorrow.com From python at mrabarnett.plus.com Thu Jul 15 20:07:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 01:07:33 +0100 Subject: Errno 9] Bad file descriptor In-Reply-To: References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: <4C3FA2C5.5050404@mrabarnett.plus.com> joblack wrote: >> Where does the error occur? If Cameron is right, it occurs somewhere >> completely different, when serializer.dump() is already long done, when >> some unsuspecting fool tries to do something with serializer.outf (such >> as closing it) > I have found it but still I don't get it. > > Dump looks like this: > > ... > > File "C: ... ineptpdf8.4.20.pyw", line 1266, in initialize return > self.initialize_fopn(docid, param) > File "C: ... ineptpdf8.4.20.pyw", line 1411, in initialize_fopn print > buildurl > > IOError: [Errno 9] Bad file descriptor > > Two strange things: > > 1st: in the buildurl is only the url (as a string) to open (something > like http://www.serverblaba.com/asdfasdf?wdfasdf=4&awfwf=34 ...) > 2nd: it works if I start in in IDLE, it doesn't work if I double klick > on the .pyw file. > > How can printing out a string throw a IOError exception? I'm quite > puzzled. The extension .pyw says to run the script without opening a console window. If there's no console, the script can't print to it. Result? IOError exception. From nfdisco at gmail.com Thu Jul 15 20:42:01 2010 From: nfdisco at gmail.com (ernest) Date: Thu, 15 Jul 2010 17:42:01 -0700 (PDT) Subject: __getattribute__ hook and len() problem Message-ID: Hi! I have this class that overrides the __getattribute__ method, so that it returns the attributes of str(self) instead of the attributes of self. class Part(object): def __init__(self): self.content = [] def __str__(self): return str.join('\n', self.content) def __getattribute__(self, name): if name in ['content', 'write', '__str__']: return object.__getattribute__(self, name) else: return str(self).__getattribute__(name) def write(self, data): self.content.append(data) Then I do: In [50]: p = Part() In [51]: p.write('foo') In [52]: p.upper() Out[56]: 'FOO' This is okay, works as expected. However, len(p) fails: TypeError: object of type 'Part' has no len() And yet, p.__len__() returns 3. I though len(object) simply called object.__len__. Can somebody shed some light on this?? Many thanks in advance. Ernest From cbc at unc.edu Thu Jul 15 20:50:17 2010 From: cbc at unc.edu (Chris Calloway) Date: Thu, 15 Jul 2010 20:50:17 -0400 Subject: Toronto PyCamp 2010 Message-ID: <4C3FACC9.6030208@unc.edu> The University of Toronto Department of Physics brings PyCamp to Toronto on Monday, August 30 through Friday, September 3, 2010. Register today at http://trizpug.org/boot-camp/torpy10/ For beginners, this ultra-low-cost Python Boot Camp makes you productive so you can get your work done quickly. PyCamp emphasizes the features which make Python a simpler and more efficient language. Following along with example Python PushUps? speeds your learning process in a modern high-tech classroom. Become a self-sufficient Python developer in just five days at PyCamp! Conducted on the campus of the University of Toronto, PyCamp comes with your own single OS/single developer copy of Wing Professional Python IDE. -- Sincerely, Chris Calloway office: 332 Chapman Hall phone: (919) 599-3530 mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599 From clp2 at rebertia.com Thu Jul 15 20:51:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 17:51:56 -0700 Subject: __getattribute__ hook and len() problem In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 5:42 PM, ernest wrote: > Hi! > > I have this class that overrides the __getattribute__ method, > so that it returns the attributes of str(self) instead of the > attributes of self. > > class Part(object): > ? ?def __init__(self): > ? ? ? ?self.content = [] > ? ?def __str__(self): > ? ? ? ?return str.join('\n', self.content) > ? ?def __getattribute__(self, name): > ? ? ? ?if name in ['content', 'write', '__str__']: > ? ? ? ? ? ?return object.__getattribute__(self, name) > ? ? ? ?else: > ? ? ? ? ? ?return str(self).__getattribute__(name) > ? ?def write(self, data): > ? ? ? ?self.content.append(data) > > Then I do: > > In [50]: p = Part() > > In [51]: p.write('foo') > > However, len(p) fails: > > TypeError: object of type 'Part' has no len() > > And yet, p.__len__() returns 3. I though len(object) simply > called object.__len__. > > Can somebody shed some light on this?? Quoth http://docs.python.org/reference/datamodel.html#more-attribute-access-for-new-style-classes : """ 3.4.2.1. More attribute access for new-style classes object.__getattribute__(self, name) ***Note: This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions. See Special method lookup for new-style classes (http://docs.python.org/reference/datamodel.html#new-style-special-lookup ).*** """ (emphasis mine) Cheers, Chris -- http://blog.rebertia.com From lists at cheimes.de Thu Jul 15 20:56:12 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jul 2010 02:56:12 +0200 Subject: __getattribute__ hook and len() problem In-Reply-To: References: Message-ID: > And yet, p.__len__() returns 3. I though len(object) simply > called object.__len__. Not exactly, all __magic__ methods of new style classes are called like getattr(type(obj), "__len__")(obj). As a result magic methods are never looked up on the object, including hooks like __getattr_() and __getattribute__(). Christian From aahz at pythoncraft.com Thu Jul 15 20:59:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Jul 2010 17:59:31 -0700 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> <4c3a8087$0$28662$c3e8da3@news.astraweb.com> Message-ID: In article <4c3a8087$0$28662$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >For some reason, when I answer the phone and say "Hello, Steven >speaking?" I often get called Peter. That's the Peter Principle in action. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From nfdisco at gmail.com Thu Jul 15 21:21:13 2010 From: nfdisco at gmail.com (ernest) Date: Thu, 15 Jul 2010 18:21:13 -0700 (PDT) Subject: __getattribute__ hook and len() problem References: Message-ID: <2acf330e-5156-499f-8675-dc493c128a07@w30g2000yqw.googlegroups.com> Thanks Chris & Christian. Mistery solved :) Ernest From usenet-nospam at seebs.net Thu Jul 15 22:43:02 2010 From: usenet-nospam at seebs.net (Seebs) Date: 16 Jul 2010 02:43:02 GMT Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On 2010-07-15, bolega wrote: > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. Then I was called "lazy" in one email and tersely > given JUST the last name of an author who has many books each many > 100s pages, when I asked for a relevant book, as if i am a scholar in > the field, although he did spend lots of words on irrelevant and > unbeneficial things which diminished my enthusiasm. If you found those "irrelevant and unbeneficial", then while I agree that he may have been wasting his time, he would have been wasting it even worse trying to walk you through the technical material when you're clearly not currently at a stage where you are ready to learn anyway. > Now, I find out > from you that he has/had a business concern or interest in a company > that is writing/wrote lisp interpreter in C. Correct me if I am making > an error. I dont want to think deprecatingly of any good soul but this > is what i experienced. If you are trying to imply that he was acting in some unethical way, you have further cemented the notion that trying to talk to you is a waste of anyone's time. *plonk* -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! From fuglyducky at gmail.com Thu Jul 15 22:53:23 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Thu, 15 Jul 2010 19:53:23 -0700 (PDT) Subject: Newbie: Python 3 and MySQL??? Message-ID: I am brand new Python and need to connect to a MySQL DB. The books I have been using are all Python 3 so I'd like to stick with what I know. Does anyone know if there is a library out there for connecting to MySQL with Python 3? If not, does anyone have any info on when MySQLdb may be ported? Thanks!!! From gavcomedy at gmail.com Thu Jul 15 23:11:12 2010 From: gavcomedy at gmail.com (gavino) Date: Thu, 15 Jul 2010 20:11:12 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: Message-ID: <1a63a61c-a9f2-4e02-9c7e-00637c06b3a7@k8g2000prh.googlegroups.com> On Jul 7, 1:56?pm, bolega wrote: > "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > Enjoy ..... AWESOME From ldo at geek-central.gen.new_zealand Thu Jul 15 23:22:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 16 Jul 2010 15:22:47 +1200 Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: In message , MRAB wrote: > Normally it's only string literals that could be so long that you might > want to split them over several lines. It is somewhat unusual to have a > _numeric_ literal that's very very long! Seems a peculiar assumption to make in a language that allows integers of arbitrary length, does it not? From stefan_ml at behnel.de Thu Jul 15 23:33:17 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 05:33:17 +0200 Subject: Code generator and visitor pattern In-Reply-To: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: Carl Banks, 16.07.2010 01:14: > Around these parts, we consider the main use of most Design Patterns > to be to work around limitations of other languages. Visitor Pattern > is probably the worst example of it. > > In Python it's completely unnecessary (at least in its boilerplate- > heavy incarnation as used in C++), and the fact that Python isn't > strongly typed, as you put it, is exactly the reason why. > > Say you have a bunch of unrelated types that define a calculate > method, you have a variable x that could be any of these types. > Here's how you would do that in Python: > > x.calculate() > > Bam, that's it. Visitor Pattern in Python. You don't have to create > a bunch of homemade dispatching boilerplate like you do in C++. Well, you can do that in every OO language. It's not what the visitor pattern is there for, though. The code I referenced is from the Cython compiler, and we use it to "do stuff" with the AST. The visitor pattern is actually a pretty common way to bind code in a single place that does a certain thing to different parts of a data structure. Without it, if you kept that code *inside* of the data structure, you'd have to spill the type specific parts all over your code. Stefan From no.email at nospam.invalid Thu Jul 15 23:51:05 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 15 Jul 2010 20:51:05 -0700 Subject: Code generator and visitor pattern References: Message-ID: <7x1vb4dqza.fsf@ruckus.brouhaha.com> Karsten Wutzke writes: > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? A minute of web surfing found this: http://chris-lamb.co.uk/2006/12/08/visitor-pattern-in-python/ From rami.chowdhury at gmail.com Fri Jul 16 00:48:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 15 Jul 2010 21:48:44 -0700 Subject: Newbie: Python 3 and MySQL??? In-Reply-To: References: Message-ID: <210D964F-D736-441F-9E4D-2F6F49E90D6E@gmail.com> On Jul 15, 2010, at 19:53 , fuglyducky wrote: > I am brand new Python and need to connect to a MySQL DB. The books I > have been using are all Python 3 so I'd like to stick with what I > know. Does anyone know if there is a library out there for connecting > to MySQL with Python 3? I believe OurSQL supports Python 3.x -- http://packages.python.org/oursql/ HTH, Rami ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From crazy808s at yahoo.com Fri Jul 16 00:49:27 2010 From: crazy808s at yahoo.com (Dylan Gleason) Date: Thu, 15 Jul 2010 21:49:27 -0700 (PDT) Subject: IDLE won't start on Mac OSX Message-ID: <550552.57286.qm@web56208.mail.re3.yahoo.com> Hello, My name is Dylan. I am new to this list and am just getting started with Python and programming in general (although I have some experience with general UNIX wankery). I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX 10.6.3), but it will not start, citing the following error message: >>> IDLE's subprocess didn't make connection. Either IDLE can't start subprocess or >>>personal firewall software is blocking the connection. I tried disabling my firewall and restarting but unfortunately I still get the same message. I executed Python via the command line and it seemed to work just fine. Can someone help me?? Thanks, Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jul 16 01:00:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 22:00:02 -0700 Subject: IDLE won't start on Mac OSX In-Reply-To: <550552.57286.qm@web56208.mail.re3.yahoo.com> References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: On Thu, Jul 15, 2010 at 9:49 PM, Dylan Gleason wrote: > Hello, > My name is Dylan. I am new to this list and am just getting started with > Python and programming in general (although I have some experience with > general UNIX wankery). > I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX > 10.6.3), but it will not start, citing the following error message: >>>> IDLE's subprocess didn't make connection. Either IDLE can't start >>>> subprocess or personal firewall software is blocking the connection. > I tried disabling my firewall and restarting but unfortunately I still get > the same message. > I executed Python via the command line and it seemed to work just fine. Can > someone help me?? How are you starting IDLE (i.e. what icon are you clicking or what command are you running)? How did you install Python (e.g. Fink, MacPorts, Python.org installer, etc.)? Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Fri Jul 16 01:19:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 22:19:47 -0700 Subject: IDLE won't start on Mac OSX In-Reply-To: References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: On Thu, Jul 15, 2010 at 10:00 PM, Chris Rebert wrote: > On Thu, Jul 15, 2010 at 9:49 PM, Dylan Gleason wrote: >> Hello, >> My name is Dylan. I am new to this list and am just getting started with >> Python and programming in general (although I have some experience with >> general UNIX wankery). >> I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX >> 10.6.3), but it will not start, citing the following error message: >>>>> IDLE's subprocess didn't make connection. Either IDLE can't start >>>>> subprocess or personal firewall software is blocking the connection. >> I tried disabling my firewall and restarting but unfortunately I still get >> the same message. >> I executed Python via the command line and it seemed to work just fine. Can >> someone help me?? > > How are you starting IDLE (i.e. what icon are you clicking or what > command are you running)? > How did you install Python (e.g. Fink, MacPorts, Python.org installer, etc.)? ---------- Forwarded message ---------- From: Dylan Gleason Date: Thu, Jul 15, 2010 at 10:07 PM Subject: Re: IDLE won't start on Mac OSX To: Chris Rebert I am clicking the IDLE.app icon located in the Applications folder. I installed Python with the Python.mpkg file from the disk image file for version 2.7 (universal binary), which I in turn downloaded from the Python website. Thanks, Dylan ---------- In the future, please use Reply-All (so everyone can see your reply) and don't top-post (it makes conversations harder to follow; http://en.wikipedia.org/wiki/Top-post ). Hopefully your answers will help others in solving your problem; I personally don't have an answer for ya (my setup is different). Cheers, Chris -- http://blog.rebertia.com From nad at acm.org Fri Jul 16 01:24:20 2010 From: nad at acm.org (Ned Deily) Date: Thu, 15 Jul 2010 22:24:20 -0700 Subject: IDLE won't start on Mac OSX References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: In article <550552.57286.qm at web56208.mail.re3.yahoo.com>, Dylan Gleason wrote: > I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX 10.6.3), > but it will not start, citing the following error message: > > >>> IDLE's subprocess didn't make connection. Either IDLE can't start > >>> subprocess or > >>>personal firewall software is blocking the connection. > > I tried disabling my firewall and restarting but unfortunately I still get > the > same message. > > I executed Python via the command line and it seemed to work just fine. Can > someone help me?? If you downloaded the python.org 2.7 installer for OS X 10.5 or later, you are probably running into the problems documented here: http://bugs.python.org/issue9227 As a workaround, try downloading and installing the 32-bit Mac Installer for 2.7. The IDLE that it installs *should* work OK on 10.6. http://python.org/download/releases/2.7/ -- Ned Deily, nad at acm.org From python at bdurham.com Fri Jul 16 01:26:40 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 01:26:40 -0400 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <4C3F7D23.2060204@jollans.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> Message-ID: <1279258000.23856.1385149339@webmail.messagingengine.com> Thomas, > Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. I understand what you're saying, but I'm struggling with how to represent the following strings in doctest code and doctest results. No matter what combination of backslashes or raw strings I use, I am unable to find a way to code the following. >>> encode( '", \, \t, \n' ) '\", \\, \\t, \\n' Thank you, Malcolm From johan.gronqvist at gmail.com Fri Jul 16 01:41:58 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Fri, 16 Jul 2010 07:41:58 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> Message-ID: Hi Ritchy, This is the first time I am doing this, but it's a standard response given on lists like this. 2010-07-13 18:17, Ritchy lelis skrev: > This is how looks like the flash residue transference function that i > was talking about... > > http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif > > I'm suposed to obtain a figure like that in my plot. > From the hints you have been given, and your answers to those hints, my conclusion is that the issue is not with the programming, but with your understanding of the problem. I get the feeling you do not understand what you are trying to do, and therefore our programming hints do not help you. Based on the "we will not do your homework"-principle, I will therefore not read up on your theory, and therefore not produce your plot for you. That will not change until you show better understanding for the plot you are trying to generate. Regards Johan From pavlovevidence at gmail.com Fri Jul 16 01:50:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jul 2010 22:50:20 -0700 (PDT) Subject: Code generator and visitor pattern References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: On Jul 15, 8:33?pm, Stefan Behnel wrote: > Carl Banks, 16.07.2010 01:14: > > > > > > > Around these parts, we consider the main use of most Design Patterns > > to be to work around limitations of other languages. ?Visitor Pattern > > is probably the worst example of it. > > > In Python it's completely unnecessary (at least in its boilerplate- > > heavy incarnation as used in C++), and the fact that Python isn't > > strongly typed, as you put it, is exactly the reason why. > > > Say you have a bunch of unrelated types that define a calculate > > method, you have a variable x that could be any of these types. > > Here's how you would do that in Python: > > > ? ? ?x.calculate() > > > Bam, that's it. ?Visitor Pattern in Python. ?You don't have to create > > a bunch of homemade dispatching boilerplate like you do in C++. > > Well, you can do that in every OO language. It's not what the visitor > pattern is there for, though. > > The code I referenced is from the Cython compiler, and we use it to "do > stuff" with the AST. The visitor pattern is actually a pretty common way to > bind code in a single place that does a certain thing to different parts of > a data structure. Without it, if you kept that code *inside* of the data > structure, you'd have to spill the type specific parts all over your code. Ahh, so this aspect oriented programming is it. I see your point, Visitor Pattern isn't necessary to work around the "can't easily polymorph unrelated types" limitation, but could still be necessary to work around "can't easily dispatch on methods not part of the class" limitation. So, ok, Visitor Pattern maybe isn't the worst one. My bad Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 02:06:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 06:06:47 GMT Subject: Possible to include \n chars in doctest code samples or output? References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> Message-ID: <4c3ff6f7$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 01:26:40 -0400, python wrote: > Thomas, > >> Recall that doctest doesn't parse the code, it extracts the docstrings. >> And docstrings are just strings, and are parsed like strings. > > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. No > matter what combination of backslashes or raw strings I use, I am unable > to find a way to code the following. > >>>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' I don't believe that this is a valid example. The interactive interpreter prints the repr() of objects unless you explicitly call print, which you have not done. I don't believe that there is any string whose repr() is what you have given. Consequently, there's no way to get that output in the interpreter (without using print), and the doctest MUST fail. But even if I'm wrong... when you run up against the limitations of doctests, don't use doctests. Is there any reason why you need to show that specific example out of the infinite number of possible examples? Remember that doctests aren't intended for a comprehensive test suite. Use unit tests for that. Or put the tests in a plain text file, not a docstring, and point doctest at that. That will reduce the amount of awkward escaping needed. If you insist on using that example, including it in the docstring should be simple. Call up the interactive interpreter, and run this: >>> from mymodule import encode # whatever your module happens to be >>> encode( '", \, \t, \n' ) something prints here Now copy the last two lines (the encode line, and the output). Paste it into your docstring, adjusting the indentation if needed. Then edit the two lines, doubling EVERY backslash. That should do it. If it doesn't, please show us the code of the encode function, the doctest failure, and the two lines copied from the interactive interpreter. -- Steven From mithrandiragainwiki at mailinator.com Fri Jul 16 02:23:39 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Fri, 16 Jul 2010 06:23:39 +0000 (UTC) Subject: Worship We Must References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, 13 Jul 2010 01:32:42 -0700, geremy condra wrote: > > I'm sure you're aware that the shuffle of so-called 'conflict truffles' > is highly illegal, not to mention unethical. I'm shocked you would > advocate it publicly. > > Geremy Condra Ignore them. It's just Google Groups spam. :( -- /home/mithrandir/Documents/sig.txt From nanothermite911fbibustards at gmail.com Fri Jul 16 02:50:01 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Thu, 15 Jul 2010 23:50:01 -0700 (PDT) Subject: >>> Assembler Book - Read or Download Individual Chapters - Volume 5 Chapter One: Thunks <<< Message-ID: <405e0ca4-5873-427f-af6d-ff8ab8ebcfab@i31g2000yqm.googlegroups.com> Assembler Book - Read or Download Individual Chapters Table of Contents and Index Short Table of Contents (44KB) PDF File Full Table of Contents (408KB) PDF File Index (724KB) PDF File Volume One - Data Representation (40K) Chapter One: Foreward (60K) PDF File Chapter Two: Hello, World of Assembly (316 K) PDF File Chapter Three: Data Representation (304K) PDF File Chapter Four: More Data Representation (284) PDF File Chapter Five: Questions, Projects, and Lab Exercises (136K) PDF File Volume Two - Introduction to Machine Architecture (28K) Chapter One: System Organization (164K) PDF File Chapter Two: Memory Access and Organization (340K) PDF File Chapter Three: Introduction to Digital Design (336K) PDF File Chapter Four: CPU Architecture (244K) PDF File Chapter Five: Instruction Set Architecture (212K) PDF File Chapter Six: Memory Architecture (164K) PDF File Chapter Seven: The I/O Subsystem (188K) PDF File Chapter Eight: Questions, Projects, and Lab Exercises (264K) PDF File Volume Three - Basic Assembly Language Programming (28K) Chapter One: Constants, Variables, and Data Types (216K) PDF File Chapter Two: Character Strings (176K) PDF File Chapter Three: Characters and Character Sets (204K) PDF File Chapter Four: Arrays (172K) PDF File Chapter Five: Records, Unions, and Namespaces (156K) PDF File Chapter Six: Dates and Times (144K) PDF File Chapter Seven: File I/O (188K) PDF File Chapter Eight: Introduction to Procedures (224K) PDF File Chapter Nine: Managing Large Programs (144K) PDF File Chapter Ten: Integer Arithmetic (216K) PDF File Chapter Eleven: Real Arithmetic (412K) PDF File Chapter Twelve: Calculation Via Table Lookup (152K) PDF File Chapter Thirteen: Questions, Projects, and Lab Exercises (480 K) PDF File Volume Four - Intermediate Assembly Language Programming (28K) Chapter One: Advanced High Level Control Structures (180 KB) PDF File Chapter Two: Low Level Control Structures (428 KB) PDF File Chapter Three: Intermediate Procedures (348 KB) PDF File Chapter Four: Advanced Arithmetic (436K) PDF File Chapter Five: Bit Manipulation (220 KB) PDF File Chapter Six: String Instructions (120 KB) PDF File Chapter Seven: The HLA Compile-Time Language (164 KB) PDF File Chapter Eight: Macros(272 KB) PDF File Chapter Nine: Domain Specific Languages (436 KB) PDF File Chapter Ten: Classes and Objects (408 KB) PDF File Chapter Eleven: The MMX Instruction Set (280 KB) PDF File Chapter Twelve: Mixed Language Programming (328 KB) PDF File Chapter Thirteen: Questions, Projects, and Lab Exercises (612 KB) PDF File Volume Five - Advanced Procedures (28K) Chapter One: Thunks (208 KB) PDF File Chapter Two: Iterators (200 KB) PDF File Chapter Three: Coroutines (100 KB) PDF File Chapter Four: Low Level Parameter Implementation (240 KB) PDF File Chapter Five: Lexical Nesting (184 KB) PDF File Chapter Six: Questions, Projects, and Lab Exercises (56KB) PDF File Appendices Appendix A: Solutions to Selected Exercises (20KB) N/A Appendix B: Console Graphic Characters (24KB) PDF File Appendix C: HLA Programming Style Guidelines (264KB) PDF File Appendix D: The 80x86 Instruction Set (224KB) PDF File Appendix E: HLA Language Reference (16KB) N/A Appendix F: HLA Standard Library Reference (16KB) N/A Appendix G: HLA Exceptions (52KB) PDF File Appendix H: HLA Compile-Time Functions (224KB) PDF File Appendix I: Installing HLA on Your System (192KB) PDF File Appendix J: Debugging HLA Programs (60KB) PDF File Appendix K: Comparison of HLA and MASM (16KB) N/A Appendix L: Code Generation for HLA High Level Statements 104KB) PDF File line Last updated: January 19, 2005 2:02 PM , Please send comments to Dr. Bradley K. Jensen jensenb at unt.edu ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From hjtoi-better-remove-before-reply at comcast.net Fri Jul 16 03:09:31 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Fri, 16 Jul 2010 00:09:31 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem References: Message-ID: On 07/13/2010 02:18 PM, Adam Mercer wrote: > I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at this time, you should check out M2Crypto from the Subversion repository. See http://chandlerproject.org/Projects/MeTooCrypto for details on how to get the sources. -- Heikki Toivonen - http://heikkitoivonen.net From nanothermite911fbibustards at gmail.com Fri Jul 16 03:15:17 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:15:17 -0700 (PDT) Subject: Rapidly navigating buffers using search References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> Message-ID: On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST From nanothermite911fbibustards at gmail.com Fri Jul 16 03:26:37 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:26:37 -0700 (PDT) Subject: Microsoft Hatred, Richard Matthew Stallman, Bill Gates, Larry Ellison, ORACLE References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> Message-ID: <19c60c5f-4d0f-4984-bb97-acf85cf071ee@i28g2000yqa.googlegroups.com> On Jul 16, 12:15?am, nanothermite911fbibustards wrote: > On Jul 11, 10:27 am, Xah Lee wrote: > > > > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > > M Stallman, and much of the unix people (although we should remember > > that Richard Stallman hated unix, if not more thanMicrosoft, and > > thehatredof unix was a major reason he started GNU's Not Unix, by > > ORACLE by Larry Ellison is a more dangerous monopoly with boundless > GREED > > Bill Gates is a decent family man and a genuine PHILANTHROPIST > They are all from Bronx http://www.nndb.com/people/439/000022373/ Larry Ellison Larry EllisonAKA Lawrence Joseph Ellison Born: 17-Aug-1944 Birthplace: Bronx, NY Gender: Male Religion: Jewish Race or Ethnicity: White Sexual orientation: Straight Occupation: Business Nationality: United States Executive summary: CEO of Oracle Larry Ellison was born out of wedlock to a 19-year-old mother, and raised by her aunt. As a boy he showed an aptitude for math and science, and as a young man he was a computer programmer for Ampex Corporation. His primary project for Ampex was crafting a large-scale database for the Central Intelligence Agency (CIA). The database was code-named "Oracle". Ellison put up $2,000 of his own money to start Software Development Laboratories in 1977, in partnership with Robert Miner, his boss from Ampex. The new company was renamed Relational Software Inc. in 1979, as it prepared to release Oracle Version 2, a commercial database system -- but the company had never released a "Version 1" of Oracle. Calling it "Version 2" was a marketing tactic, intended to convey the notion that any initial bugs had been worked out. Oracle sold briskly, and in 1983 the company renamed itself after its principal product. Oracle Corporation went public in 1986, and was on the verge of bankruptcy by 1990, when it was revealed that its revenues had been overstated for several years. The company has since rebounded, and been extremely profitable. In 1996, Ellison took a month-long sabbatical, and spent most of his waking time on-line. When he returned he'd decided that the 'net was the next big thing, bigger than personal computers. Oracle started reconfiguring its software for on-line data sharing, and for adaptability to not-quite-computer products like TVs with internet access and pocket internet devices. This strategy has made Oracle still more profitable. Oracle's main competitors are Microsoft and IBM, and one of Ellison's passions is needling Microsoft. He's been a prominent proponent of efforts to break Microsoft up for antitrust violations. "I think when somebody breaks the law, they should be punished", says Ellison. He's admitted hiring private detectives to gather information on Microsoft's tactics, and charged that Microsoft funded pro-Microsoft "grassroots" political action groups that were pressuring the Justice Department to drop its antitrust prosecution. Microsoft responded that Oracle might be funding anti-Microsoft political groups. Neener- neener. David Theroux, president of the Independent Institute -- alleged by Ellison to be a Microsoft front -- said of Ellison, "anybody who stoops to whatever was done here, cannot be trusted. Oracle has apparently felt the need to employ back-alley tactics, subterfuge, and disinformation in order to achieve its aims". Ellison's net worth dropped about $3.5 billion after September 11, as stocks plummeted and Oracle stock lost almost 50% of its value. It was at this time that Ellison became a loud supporter of a U.S. identity card, which -- he insisted -- would help prevent terrorism. Ellison has offered to provide data-tracking software for the national ID card free of charge (but with fees for maintenance and upgrades, of course). As envisioned by Ellison, the national ID card would be "optional" for native-born Americans, but mandatory for immigrants. Ellison had a dispute with the city of San Jose, CA, and its airport, when his personal jet violated the city's jet curfew law at least six times. Noise control legislation makes it illegal for planes weighing 75,000 pounds or more to take off or land at San Jose International Airport during overnight hours, but after Ellison sued, the city granted him a special exemption to the law in 2001. In 2000, Forbes listed Ellison as the world's second richest man, worth $47 billion to Bill Gates's $60 billion. By 2007, Forbes had Ellison slipping to fourth place, worth only $26 billion. Close friend of Steve Jobs. Mother: Florence Spellman (unwed mother, at age 19) Father: Louis Ellison (adoptive father) Mother: Lillian Ellison (adoptive mother) Wife: Adda Quinn (m. 1967, div. 1974) Wife: Nancy Wheeler (m. 1977, div. 1978) Wife: Barbara Boothe (m. 1983, div. 1986) Daughter: Megan Ellison Son: David Ellison Girlfriend: Adelyn Lee (later fired by an Oracle VP, she sued Ellison, settled for $100k) Wife: Melanie Craft (romance novelist, m. 18-Dec-2003) High School: South Shore High School, Chicago, IL University: University of Illinois Urbana-Champaign (two years, dropped out) University: University of Chicago (one quarter, dropped out) Oracle CEO (1977-) Oracle President (1978-96) nCUBE CEO (1996-2002) nCUBE Majority Shareholder (1988-) Ampex Amdahl (1973-) Member of the Board of Apple (-2002) Member of the Board of Oracle (1977-, as Chairman, 1990-92 and 1995-2004) Academy of Achievement (1997) Dreier for Congress Committee John McCain 2008 Monday Morning PAC Obama for Illinois US Big Brother Award Greatest Corporate Invader Rhinoplasty FILMOGRAPHY AS ACTOR Iron Man 2 (26-Apr-2010) Himself The Triumph of the Nerds: The Rise of Accidental Empires (12- Jun-1996) Himself Appears in articles: Time, 23-Jun-2003, DETAILS: Eat... or Be Eaten -- Software mogul Larry Ellison makes a hostile bid for a rival firm -- and predicts that other tech giants will follow his lead (p.47, three pages), BYLINE: Chris Taylor New! NNDB MAPPER Create a map starting with Larry Ellison Requires Flash 7+ and Javascript. Do you know something we don't? Submit a correction or make a comment about this profile Copyright ?2010 Soylent Communications From nanothermite911fbibustards at gmail.com Fri Jul 16 03:45:22 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:45:22 -0700 (PDT) Subject: CONVICTED RAPIST of 13y old girl Semantha Geimer, ROMAN POLANSKY is RELEASED by a KANGAROO court in Switzerland, Re: Microsoft Hatred, Richard Matthew Stallman, Bill Gates, Larry Ellison, ORACLE References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> <19c60c5f-4d0f-4984-bb97-acf85cf071ee@i28g2000yqa.googlegroups.com> Message-ID: <62a07fd7-fb45-4368-af79-0615b36df10a@r27g2000yqb.googlegroups.com> CONVICTED RAPIST, ROMAN POLANSKY is RELEASED by a KANGAROO court in Switzerland We all know that Germans are paying a big tribute to the polanskys and the swiss paid for the gold in the teeth. Israeli Professor: 'We Could Destroy All European Capitals' By Nadim Ladki 2-6-3 (IAP News) -- An Israeli professor and military historian hinted that Israel could avenge the holocaust by annihilating millions of Germans and other Europeans. Speaking during an interview which was published in Jerusalem Friday, Professor Martin Van Crevel said Israel had the capability of hitting most European capitals with nuclear weapons. "We possess several hundred atomic warheads and rockets and can launch them at targets in all directions, perhaps even at Rome. Most European capitals are targets of our air force." Creveld, a professor of military history at the Hebrew University in Jerusalem, pointed out that "collective deportation" was Israel's only meaningful strategy towards the Palestinian people. "The Palestinians should all be deported. The people who strive for this (the Israeli government) are waiting only for the right man and the right time. Two years ago, only 7 or 8 per cent of Israelis were of the opinion that this would be the best solution, two months ago it was 33 per cent, and now, according to a Gallup poll, the figure is 44 percent." Creveld said he was sure that Israeli Prime Minister Ariel Sharon wanted to deport the Palestinians. "I think it's quite possible that he wants to do that. He wants to escalate the conflict. He knows that nothing else we do will succeed." Asked if he was worried about Israel becoming a rogue state if it carried out a genocidal deportation against Palestinians, Creveld quoted former Israeli Defense Minister Moshe Dayan who said "Israel must be like a mad dog, too dangerous to bother." Creveld argued that Israel wouldn't care much about becoming a rogue state. "Our armed forces are not the thirtieth strongest in the world, but rather the second or third. We have the capability to take the world down with us. And I can assure you that this will happen before Israel goes under." Islamic Association for Palestine (IAP) http://www.iap.org A CHRISTIAN VIEW OF THE HOLOCAUST Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. It was made a short time ago before a large group in the Congressional `Room of the Willard Hotel in Washington, D.C. Both the speech and the question and answer period later so electrified the audience that a group of patriots has transferred it to two long-playing records which you may buy to play for friends, clubs, and your church group in your community. The speaker is Mr. Benjamin Freedman, noted authority on Zionism and all of its schemes. Mr. Freedman is a former Jew, and I mean a FORMER Jew. He has fought the Communist world conspiracy tooth and nail, and stands today as a leading American patriot. We now take you to the speaker's platform to present Benjamin Freedman. (applause) [Freedman's speech] What I intend to tell you tonight is something that you have never been able to learn from any other source, and what I tell you now concerns not only you, but your children and the survival of this country and Christianity. I'm not here just to dish up a few facts to send up your blood pressure, but I'm here to tell you things that will help you preserve what you consider the most sacred things in the world: the liberty, and the freedom, and the right to live as Christians, where you have a little dignity, and a little right to pursue the things that your conscience tells you are the right things, as Christians. I'm not so poor that I can't live without working and that's what worries the Anti-Defamation League. I can just get by without going and asking for a job or getting on the bread line. But Mr. McGinley is working. He's sick and he's going at this stronger than ever. And all I want to say is that they want to close up "Common Sense" more than any other single thing in the whole world, as a death-blow to the fight Christians are making to survive. So I just want to tell you this. All they do is circulate rumors: "Mr. Benjamin H. Freedman is the wealthy backer of 'Common Sense'." The reason they do that is to discourage the people in the United States: don't send any money to Common Sense. They don't need it. The've got the wealthy Mr. Freedman as a backer. That all has strategy. They don't want to advertise me so that people that have real estate or securities to sell will come and call on me. They just want people to lay off "Common Sense". And all I'm telling you is, I do try to help him, but I haven't been able to. And I will be very honest. One thing I won't do is lie. In the last year I've had so much sickness in my family that I could not give him one dollar. How he's managed to survive, I don't know. God alone knows. And he must be in God's care because how he's pulled through his sickness and with his financial troubles, I don't know. But that press is working. . . and every two weeks about a hundred or a hundred-fifty- thousand of "Common Sense" go out with a new message. And if that information could be multiplied. . . if people that now get it could buy ten or twenty five, or fifty, give them around. Plow that field. Sow those seeds, you don't know which will take root, but for God's sake, this is our last chance. From mukeshtiwari.iiitm at gmail.com Fri Jul 16 03:52:23 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 16 Jul 2010 00:52:23 -0700 (PDT) Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: On Jul 16, 4:08?am, MRAB wrote: > mukesh tiwari wrote: > > Hello all > > Currently i am trying to develop a client and server in python. Client > > takes screenshot in every 20 seconds and send it to server. Server > > store the received file in folder. Here is code for Client > > > import sys > > import socket > > import gtk.gdk > > import time > > if __name__ == "__main__": > > ? ?s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); > > ? ?host,port="localhost",50007 > > ? ?s.connect((host,port)) > > ? ?while 1: > > ? ? ? ? ? ?w = gtk.gdk.get_default_root_window() > > ? ? ? ? ? ?sz = w.get_size() > > ? ? ? ? ? ?pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) > > ? ? ? ? ? ?pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) > > ? ? ? ? ? ?if (pb != None): > > ? ? ? ? ? ? ? ? ? ? ? ?pb.save('/home/tmp_1/screenshot.png',"png") > > ? ? ? ? ? ?f=open('/home//tmp_1/screenshot.png','rb') > > ? ? ? ? ? ?while 1: > > ? ? ? ? ? ? ? ? ? ?blk=f.read(2048) > > ? ? ? ? ? ? ? ? ? ?if not blk:break > > ? ? ? ? ? ? ? ? ? ?s.send(blk) > > ? ? ? ? ? ?f.close() > > ? ? ? ? ? ?print 'file transfer done'; > > ? ? ? ? ? ?time.sleep(20) > > > ? ?s.close() > > > Server Code > > import sys > > import socket > > import time > > if __name__ == "__main__": > > > ? ?s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) > > ? ?host,port="",50007 > > ? ?s.bind((host,port)) > > ? ?s.listen(1) > > ? ? ? conn,add=s.accept() > > ? ?i=0 > > ? ?while 1: > > ? ? ? ? ? ?f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') > > ? ? ? ? ? ?while 1: > > ? ? ? ? ? ? ? ? ? ?data=conn.recv(2048) > > ? ? ? ? ? ? ? ? ? ?if not data:break > > ? ? ? ? ? ? ? ? ? ?f.write(data) > > > ? ? ? ? ? ?f.close() > > ? ? ? ? ? ?print 'file received' > > ? ? ? ? ? ?time.sleep(20) > > ? ? ? ? ? ?i+=1; > > ? ?#print ' file received ' > > > ? ?conn.close() > > > My problem is that server is copying only first image > > copyscreenshot_0.png while my client continuously taking screen shot. > > Kindly tell me what is wrong with my server code. > > The .recv will return an empty string only when the connection is closed > by the client, but the client keeps the connection open. > > You could either open and close a connection for each image, or have the > client tell the server how many bytes it's going to send, followed by > the bytes (my preference would be to send the size as a string ending > with, say, a newline). > > Another point: the .send method doesn't guarantee that it'll send all > the bytes (it'll return the number of bytes that it has actually sent); > use the .sendall method instead. Thank you MARB. I used your first idea and opening and closing connection for each image. Just wanted to know if i have to take pictures at small intervals , this method is efficient or not? It would be great if you can provide a bit code for second method. Keeping the connection open but how to know that this is end a particular image and save it. From michele.simionato at gmail.com Fri Jul 16 03:52:25 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 16 Jul 2010 00:52:25 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> On Jul 15, 7:58?pm, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten You ask about code generation and you already had answers in that area, but let me talk a bit about a simpler topic, traversing a hierarchical file system. I think this is relevant (even if not answering your question) if you want to get familiar with the Python way. In the old days, the way to traverse a file system was through the os.path.walk function. Here is what the docs say (from http://docs.python.org/library/os.path.html): """ os.path.walk(path, visit, arg) Calls the function visit with arguments (arg, dirname, names) for each directory in the directory tree rooted at path (including path itself, if it is a directory). The argument dirname specifies the visited directory, the argument names lists the files in the directory (gotten from os.listdir(dirname)). The visit function may modify names to influence the set of directories visited below dirname, e.g. to avoid visiting certain parts of the tree. (The object referred to by names must be modified in place, using del or slice assignment.) """ As you see the documentation make explicit reference to the visitor pattern. However a note below says: """ This function is deprecated and has been removed in 3.0 in favor of os.walk(). """ In other word, the visitor pattern is *not* the Pythonic way to solve this problem. The Pythonic way is to use os.walk, which converts the nested structure in a flat structure. From the docs (http://docs.python.org/library/os.html): """ This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn?t look under any CVS subdirectory: import os from os.path import join, getsize for root, dirs, files in os.walk('python/Lib/email'): print root, "consumes", print sum(getsize(join(root, name)) for name in files), print "bytes in", len(files), "non-directory files" if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories """ There is a big conceptual difference between os.path.walk and os.walk. The first works like a framework: you pass a function to it and os.path.walk is in charging of calling it when needed. The second works like a library: os.walk flattens the hierarchical structure and then you are in charge of doing everything you wish with it. os.walk is the Pythonic way, and you suggested to follow that approach; for instance elementTree and lxml (libraries for parsing XML data) work exactly that way. Actually one of the motivating examples for the introduction of generators in Python was their use in flattening data structure, i.e. exactly the pattern used by os.walk. The message is stop thinking like in Java and start using idiomatic Python. We are here to help. Michele Simionato From smallpox911 at gmail.com Fri Jul 16 04:07:39 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:07:39 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** Message-ID: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Self-Study Course : The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS First, we will present the TRANSFORMATION, using HIGHLY AUTHENTIC source . Lying and Deception is the second nature of zionists , so we cant contaminate ourselves with an iota of it. We present evidence from the mouth of TORAH true jews which you will also see with your own eyes in a unique style. Rabbi Israel Domb - The Author of THE TRANSFORMATION http://www.youtube.com/watch?v=1QfgvDXsDds Rabbi Israel Domb ushers me into the dining room of his terraced house in Stamford Hill. With a lace-covered table that fills the room and glass-panelled sideboard, we could almost be in Eastern Europe in the 50s. Now 86, Domb shuffles slightly in the slippers that, with his long, black satin coat, make up his housewear. But he exudes the twin qualities of self-containedness and benevolence that mark those who believe they've arrived at a place of existential and spiritual certainty. Bizarrely, the entire proceedings are filmed by a young man neither of us was expecting. Wanting to capture the discourse of one of their elders, and aware of the increasing need for publicity material, Neturei Karta in New York have commissioned videos of most of my interviews. Domb's long life testifies to the experience of 20th-century Jewry. He came to England from Poland in 1939, and lost his mother and sisters in the Holocaust. But it has also been a life lived countercurrent: he visited the newly founded state of Israel in the 50s and started speaking and writing against Zionism, which made him unpopular with the Orthodox community. The publication of The Transformation , the definitive exposition of the Neturei Karta worldview, confirmed his status as one of the movement's main spiritual leaders. Bound in dark red leather, and the length of a short novel, its register is hard to place, with its blend of theological assertion and historical- political commentary written in a style dating from decades ago. He insists that the politicised turn of his life grew out of his upbringing in a deeply religious family. He tells me how, when the Nazis came, a Polish teacher offered to hide his two blonde sisters. 'My mother said, "I appreciate your kindness. But I would rather they should die as Jews than be brought up as non-Jews." I come from a family of very strong convictions. Neturei Karta is nothing new.' Domb claims that while most modern Jews have departed from true Judaism, the Neturei Karta - which means 'guardians of the holy city' in Aramaic - are the minority charged with keeping the faith. The movement was established in Jerusalem in the 30s. Its supporters, living in the Holy Land since the 18th century, had always opposed a Jewish state and were concerned about the growing pressure to establish a Jewish homeland. Domb insists that its tenets go back to the origins of Jewish identity. 'Neturei Karta is not an idea, it's not a new trend, it's not a party with a programme,' he tells me. 'It is the authentic Jewishness of the Jewish people.' At its theological heart lies the belief that the Jews have been exiled for their sins and are destined to suffer, a fate which will be redeemed only when divine intervention, with the coming of the Messiah, changes the world order. In the meantime, Jews must remain stateless, living under the rule of whichever country hosts them. Zionism, as the desire for a sovereign state, represents a blasphemous rejection of God's will. 'An earthly solution for the Jewish people is not possible, because we are not destined for any earthly happiness. The Jewish people should come to their senses and see that the Zionist state is one big misfortune,' says Domb. In conversation, Domb frequently distinguishes the religious level - the messianism that forbids the Jews political intervention - from what he calls the 'mundane' or worldly perspective. When he talks on this second level, his observations are sharpened with a campaigning edge. 'When the Zionists speak about peace, they want peace, but what it means is a peaceful occupation,' he says. But he also has a Middle- European, black sense of humour, chuckling grimly to himself as he invokes the worst excesses of human behaviour: 'Were they invited to the West Bank? Were they invited to Ramallah and Jenin? Were they invited to throw out from their homes around 600,000 Arabs?' The political solution Domb advocates is, ironically, more radical than the PLO's, which recognised Israel's right to exist in 1988. He has no hope that this will happen, but he thinks the Israelis should renounce their claims to land within the 1948 borders and make reparations to the Palestinians. With the state of Israel dismantled, Jews could remain in the Holy Land, but live under Palestinian rule. But ultimately, he stresses, Neturei Karta's objection to Israel rests on theological rather than political grounds. 'The very existence of the Jewish state is diametrically opposed to Judaism,' he says. 'But as it happens, the Arabs have suffered, and it is our duty to say to them: "It is morally wrong, it is illegal from the worldly point of view, and we are not part of it. So don't blame all the Jewish people for the sufferings which you have had."' The acknowledgement of this injustice, he says, imposes an obligation on the Neturei Karta to actively seek out Palestinians to make clear their position. Speaking slowly and with emphasis, he declares: 'It's an encouraging matter that young people come out, speak against Zionism. But they also have to guard against speaking nonsense and overdoing it.' Unsurprisingly, Neturei Karta's brand of overt protest finds them little favour with the leaders of Britain's Jewry. The Chief Rabbi Jonathan Sacks, speaking at the Zionist Federation's Israel Independence Day rally at Wembley, where one of the Neturei Karta set alight an Israeli flag, condemned their stance as 'unforgivable'. Neville Nagler, director general of the Board of the Deputies of British Jews, dismisses them as 'a fringe organisation, off the wall'. He claims that their 'vicious hostility to Israel, their willingness to desecrate the Sabbath to show up at demonstrations' isolates them even from the Orthodox community among whom they live. Rabbi Tony Bayfield, head of Britain's Reform Synagogues, says that Neturei's religiously grounded anti-Zionism is untenable nowadays: 'The intellectual and theological battle was lost the best part of a century ago. It's no longer relevant or meaningful. For the vast majority of Jews, the existence of the state of Israel is not negotiable.' It's a paradoxical attitude - dismissing the group as irrelevant while evincing palpable hostility - which is perhaps a measure of how far the Neturei Karta touches on the central, raw nerve of the Middle East conflict: Israel's right to exist. The Neturei Karta in New York have long experience in handling public protest and controversy. Based in the city's Monsey area, the bigger, more established group has been organising anti-Zionist protests since 1948, some of which, they say, have attracted up to 30,000 Orthodox Jews. Their leader, Rabbi Moshe Beck, visiting his sons in London and speaking through a Yiddish interpreter, tells me that the heightened tension of the past year has caused some supporters to fall off and provoked threats against him and other activists. But many remain steadfast. 'Those that do it are prepared for whatever consequences,' he insists, adding: 'All our actions are no more or less than proclaiming the truth - it's not a political idea.' Beck, a frail-looking man of 68 who does not once make eye contact during our hour-long meeting, seems an unlikely character to be at the frontline of so much conflict. Born in Hungary, he emigrated to Israel soon after its establishment. What he saw there - the emergence of a modern, secular society, combined with the government's harsh treatment of the Palestinians - horrified him, clashing as it did with the inner religious life he was pur suing through study and reflection. Then he met Neturei Karta's most respected leader, Amram Blau, and became active in the Jerusalem-based movement. But in 1973, feeling it was no longer right to live in Israel, he and his family moved to New York. In Israel, Neturei Karta's position is very different. Part of the ultra-Orthodox community in the Mea Shearim quarter of Jerusalem, the group denies the legitimacy of the government, refusing to pay taxes and avoiding military conscription into the Israeli Defence Forces. In the 60s and 70s they fought an often violent campaign for observing the Sabbath, finally persuading the authorities to close some of Jerusalem's streets on the holy day. Its leader and self-styled foreign minister, Rabbi Moshe Hirsh, who considers himself a Palestinian Jew, ran a high-profile campaign in the 80s to be appointed as Neturei Karta's representative in the PLO. In 1994, Arafat endorsed his position as the Palestinian National Authority's Minister for Jewish Affairs but, as a non-Arabic speaker and unable to deal directly with Israeli representatives because of Neturei Karta's refusal to recognise the Israeli government, Hirsh has had a more advisory than ministerial role in the Palestinian adminis tration. He has used his position as a platform for campaigning, in 2000 urging Arafat to unilaterally declare an independent Palestinian state. But for the most part, Neturei Karta's activities are fairly low key. Hirsh, who claims 10,000 supporters in Jerusalem, says that the group is so well established that taking to the streets is felt to be unnecessary. 'We don't recognise the government; everyone knows that. We don't see the need,' he says. From smallpox911 at gmail.com Fri Jul 16 04:19:54 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:19:54 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** References: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Message-ID: <8c1e7781-fab5-4635-998b-d503b3f929d9@d37g2000yqm.googlegroups.com> The Kitab al Khazari, an Arabic phrase meaning Book of the Khazars, is one of most famous works of the medieval Spanish Jewish philosopher and poet Rabbi Yehuda Halevi, completed around 1140.[1] Divided into five essays ("ma'amarim," Articles), it takes the form of a dialogue between the pagan king of the Khazars and a Jew who was invited to instruct him in the tenets of the Jewish religion. Originally written in Arabic, the book was translated by numerous scholars (including Judah ibn Tibbon) into Hebrew and other languages. Though the book is not considered a historical account of the Khazar conversion to Judaism, scholars such as D.M. Dunlop have postulated that Yehuda had access to Khazar documents upon which he loosely based his work. His contemporary, Avraham ibn Daud, reported meeting Khazar rabbinical students in Toledo, Spain in the mid-12th century. Introduction After a short account of the incidents preceding the conversion of the king, and of the conversations of the latter with a philosopher, a Christian, and a Muslim concerning their respective beliefs, a Jew appears on the stage, and by his first statement startles the king; for, instead of giving him proofs of the existence of God, he asserts and explains the miracles performed by Him in favor of the Israelites. The king expresses his astonishment at this exordium, which seems to him incoherent; but the Jew replies that the existence of God, the creation of the world, etc., being taught by religion, do not need any speculative demonstrations. Further, he propounds the principle upon which his religious system is founded; namely, that revealed religion is far superior to natural religion. For the aim of ethical training, which is the object of religion, is not to create in man good intentions, but to cause him to perform good deeds. This aim can not be attained by philosophy, which is undecided as to the nature of good, but can be secured by religious training, which teaches what is good. As science is the sum of all truth found by successive generations, so religious training is based upon a set of traditions; in other words, history is an important factor in the development of human culture and science. [edit] "Creatio ex Nihilo" Halevi writes that as the Jews are the only depositaries of a written history of the development of the human race from the beginning of the world, the superiority of their traditions can not be denied. Halevi asserts that no comparison is possible between Jewish culture, which in his view is based upon religious truth, and Greek culture, which is based upon science only. He holds that the wisdom of Greek philosophers lacked that divine support with which the Israelite prophets were endowed. Had a trustworthy tradition that the world was created out of nothing been known to Aristotle, he would have supported it by at least as strong arguments as those advanced by him to prove the eternity of matter. Belief in the eternity of matter, however, is not absolutely contrary to Jewish religious ideas; for the Biblical narrative of the Creation refers only to the beginning of the human race, and does not preclude the possibility of preexistent matter. Still, relying upon tradition, the Jews believe in "creatio ex nihilo," which theory can be sustained by as powerful arguments as those advanced in favor of the belief in the eternity of matter. The objection that the Absolutely Infinite and Perfect could not have produced imperfect and finite beings, made by the Neoplatonists to the theory of "creatio ex nihilo," is not removed by attributing the existence of all mundane things to the action of nature; for the latter is only a link in the chain of causes having its origin in the First Cause, which is God. [edit] Superiority of his faith Halevi now attempts to demonstrate the superiority of his religion, Judaism. From smallpox911 at gmail.com Fri Jul 16 04:20:03 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:20:03 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** References: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Message-ID: <58d8b6b7-e7eb-45af-9b97-d896a9b8fe7d@d16g2000yqb.googlegroups.com> The Kitab al Khazari, an Arabic phrase meaning Book of the Khazars, is one of most famous works of the medieval Spanish Jewish philosopher and poet Rabbi Yehuda Halevi, completed around 1140.[1] Divided into five essays ("ma'amarim," Articles), it takes the form of a dialogue between the pagan king of the Khazars and a Jew who was invited to instruct him in the tenets of the Jewish religion. Originally written in Arabic, the book was translated by numerous scholars (including Judah ibn Tibbon) into Hebrew and other languages. Though the book is not considered a historical account of the Khazar conversion to Judaism, scholars such as D.M. Dunlop have postulated that Yehuda had access to Khazar documents upon which he loosely based his work. His contemporary, Avraham ibn Daud, reported meeting Khazar rabbinical students in Toledo, Spain in the mid-12th century. Introduction After a short account of the incidents preceding the conversion of the king, and of the conversations of the latter with a philosopher, a Christian, and a Muslim concerning their respective beliefs, a Jew appears on the stage, and by his first statement startles the king; for, instead of giving him proofs of the existence of God, he asserts and explains the miracles performed by Him in favor of the Israelites. The king expresses his astonishment at this exordium, which seems to him incoherent; but the Jew replies that the existence of God, the creation of the world, etc., being taught by religion, do not need any speculative demonstrations. Further, he propounds the principle upon which his religious system is founded; namely, that revealed religion is far superior to natural religion. For the aim of ethical training, which is the object of religion, is not to create in man good intentions, but to cause him to perform good deeds. This aim can not be attained by philosophy, which is undecided as to the nature of good, but can be secured by religious training, which teaches what is good. As science is the sum of all truth found by successive generations, so religious training is based upon a set of traditions; in other words, history is an important factor in the development of human culture and science. [edit] "Creatio ex Nihilo" Halevi writes that as the Jews are the only depositaries of a written history of the development of the human race from the beginning of the world, the superiority of their traditions can not be denied. Halevi asserts that no comparison is possible between Jewish culture, which in his view is based upon religious truth, and Greek culture, which is based upon science only. He holds that the wisdom of Greek philosophers lacked that divine support with which the Israelite prophets were endowed. Had a trustworthy tradition that the world was created out of nothing been known to Aristotle, he would have supported it by at least as strong arguments as those advanced by him to prove the eternity of matter. Belief in the eternity of matter, however, is not absolutely contrary to Jewish religious ideas; for the Biblical narrative of the Creation refers only to the beginning of the human race, and does not preclude the possibility of preexistent matter. Still, relying upon tradition, the Jews believe in "creatio ex nihilo," which theory can be sustained by as powerful arguments as those advanced in favor of the belief in the eternity of matter. The objection that the Absolutely Infinite and Perfect could not have produced imperfect and finite beings, made by the Neoplatonists to the theory of "creatio ex nihilo," is not removed by attributing the existence of all mundane things to the action of nature; for the latter is only a link in the chain of causes having its origin in the First Cause, which is God. [edit] Superiority of his faith Halevi now attempts to demonstrate the superiority of his religion, Judaism. From uDOTsDOTreddy at cs.bham.ac.uk Fri Jul 16 04:22:48 2010 From: uDOTsDOTreddy at cs.bham.ac.uk (Uday S Reddy) Date: Fri, 16 Jul 2010 09:22:48 +0100 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: On 7/13/2010 7:43 PM, Xah Lee wrote: > > I use comp.lang.lisp, comp.emacs since about 1999. Have been using > them pretty much on a weekly basis in the past 10 years. Starting > about 2007, the traffic has been increasingly filled with spam, and > the posters are always just the 20 or 30 known faces. I think perhaps > maybe no more than 100 different posters a year. Since this year or > last year, they are some 95% spam. > > comp.emacs is pretty much just me. > > gnu.emacs.help is not much better. It's pretty much the same > developers and the same few elisp coders, with perhaps 1 new face with > once-per-lifetime post every few days. gnu.emacs.help is doing a bit > better because it is connected to fsf's mailing list. Doing "better" means having more posts? I don't believe that having a lot of posts is necessarily a measure of goodness. In my opinion, discussion forums do well when they encourage people to think carefully and communicate clearly. In this respect, I think mailing lists do worse, newsgroups better, and web-based forums the best. Mailing lists seem to turn into talking shops where people get to know each other over time and their "public" nature gets lost. Those who write a lot end up dominating them, independent of whether they write any sense or not. The other people get tired and stop reading. So, you can generate a lot of traffic, but its value is dubious. Newsgroups are much better because they are public and, visibly so. If somebody says something stupid, a lot of people will jump on them. And, so, over time, they develop some quality. (There is no guarantee, of course. I have also seen a lot of newsgroups, especially in politics, really degenerate with opposing factions fighting and dominating everything else.) Web-based forums, especially those where people have to register, work the best in my experience. They are very visibly public, discouraging people to write nonsense. The difficulty of writing on the web instead of your favorite editor hopefully provides some resistance to write. So, people tend to think more than they write. I used a forum called silentpcforum last year to help me build myself a new computer. There was a lot of high quality information dating back to years, which was easy to find and easy to use. So, if newsgroups die and get replaced by web forums, that would be a move for the better. If they get replaced by mailing lists, that would be a move for the worse. Cheers, Uday From dr.mtarver at ukonline.co.uk Fri Jul 16 04:24:51 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Fri, 16 Jul 2010 01:24:51 -0700 (PDT) Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> Message-ID: <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> On 15 July, 23:21, bolega wrote: > http://www.gnu.org/philosophy/stallman-kth.html > > RMS lecture at KTH (Sweden), 30 October 1986 > > (Kungliga Tekniska H?gskolan (Royal Institute of Technology)) > Stockholm, Sweden > > Arranged by the student society > ?Datorf?reningen Stacken? > 30 October 1986 > > [Note: This is a slightly edited transcript of the talk. As such it > contains false starts, as well as locutions that are natural in spoken > English but look strange in print. It is not clear how to correct them > to written English style without ?doing violence to the original > speech?.] > > It seems that there are three things that people would like me to talk > about. On the one hand I thought that the best thing to talk about > here for a club of hackers, was what it was like at the MIT in the old > days. What made the Artificial Intelligence Lab such a special place. > But people tell me also that since these are totally different people > from the ones who were at the conference Monday and Tuesday that I > ought to talk about what's going on in the GNU project and that I > should talk about why software and information can not be owned, which > means three talks in all, and since two of those subjects each took an > hour it means we're in for a rather long time. So I had the idea that > perhaps I could split it in to three parts, and people could go > outside for the parts they are not interested in, and that then when I > come to the end of a part I can say it's the end and people can go out > and I can send Jan Rynning out to bring in the other people. (Someone > else says: ?Janne, han trenger ingen mike? (translation: ?Janne, he > doesn't need a mike?)). Jan, are you prepared to go running out to > fetch the other people? Jmr: I am looking for a microphone, and > someone tells me it is inside this locked box. Rms: Now in the old > days at the AI lab we would have taken a sledgehammer and cracked it > open, and the broken door would be a lesson to whoever had dared to > lock up something that people needed to use. Luckily however I used to > study Bulgarian singing, so I have no trouble managing without a > microphone. > > Anyway, should I set up this system to notify you about the parts of > the talk, or do you just like to sit through all of it? (Answer: > Yeaaah) > > When I started programming, it was 1969, and I did it in an IBM > laboratory in New York. After that I went to a school with a computer > science department that was probably like most of them. There were > some professors that were in charge of what was supposed to be done, > and there were people who decided who could use what. There was a > shortage of terminals for most people, but a lot of the professors had > terminals of their own in their offices, which was wasteful, but > typical of their attitude. When I visited the Artificial Intelligence > lab at MIT I found a spirit that was refreshingly different from that. > For example: there, the terminals was thought of as belonging to > everyone, and professors locked them up in their offices on pain of > finding their doors broken down. I was actually shown a cart with a > big block of iron on it, that had been used to break down the door of > one professors office, when he had the gall to lock up a terminal. > There were very few terminals in those days, there was probably > something like five display terminals for the system, so if one of > them was locked up, it was a considerable disaster. > > In the years that followed I was inspired by that ideas, and many > times I would climb over ceilings or underneath floors to unlock rooms > that had machines in them that people needed to use, and I would > usually leave behind a note explaining to the people that they > shouldn't be so selfish as to lock the door. The people who locked the > door were basically considering only themselves. They had a reason of > course, there was something they thought might get stolen and they > wanted to lock it up, but they didn't care about the other people they > were affecting by locking up other things in the same room. Almost > every time this happened, once I brought it to their attention, that > it was not up to them alone whether that room should be locked, they > were able to find a compromise solution: some other place to put the > things they were worried about, a desk they could lock, another little > room. But the point is that people usually don't bother to think about > that. They have the idea: ?This room is Mine, I can lock it, to hell > with everyone else?, and that is exactly the spirit that we must teach > them not to have. > > But this spirit of unlocking doors wasn't an isolated thing, it was > part of an entire way of life. The hackers at the AI lab were really > enthusiastic about writing good programs, and interesting programs. > And it was because they were so eager to get more work done, that they > wouldn't put up with having the terminals locked up, or lots of other > things that people could do to obstruct useful work. The differences > between people with high morale who really care about what they're > trying to do, and people who think of it as just a job. If it's just a > job, who cares if the people who hired you are so stupid they make you > sit and wait, it's their time, their money but not much gets done in a > place like that, and it's no fun to be in a place like that. > > Another thing that we didn't have at the AI lab was file protection. > There was no security at all on the computer. And we very consciously > wanted it that way. The hackers who wrote the Incompatible Timesharing > System decided that file protection was usually used by a self-styled > system manager to get power over everyone else. They didn't want > anyone to be able to get power over them that way, so they didn't > implement that kind of a feature. The result was, that whenever > something in the system was broken, you could always fix it. You never > had to sit there in frustration because there was NO WAY, because you > knew exactly what's wrong, and somebody had decided they didn't trust > you to do it. You don't have to give up and go home, waiting for > someone to come in in the morning and fix the system when you know ten > times as well as he does what needs to be done. > > And we didn't let any professors or bosses decide what work was going > to be done either, because our job was to improve the system! We > talked to the users of course; if you don't do that you can't tell > what's needed. But after doing that, we were the ones best able to see > what kind of improvements were feasible, and we were always talking to > each other about how we'd like to see the system changed, and what > sort of neat ideas we'd seen in other systems and might be able to > use. So the result is that we had a smoothly functioning anarchy, and > after my experience there, I'm convinced that that is the best way for > people to live. > > Unfortunately the AI lab in that form was destroyed. For many years we > were afraid the AI lab would be destroyed by another lab at MIT, the > Lab for Computer Science, whose director was a sort of empire builder > type, doing everything he could to get himself promoted within MIT, > and make his organization bigger, and he kept trying to cause the AI > lab to be made a part of his lab, and nobody wanted to do things his > way because he believed that people should obey orders and things like > that. > > But that danger we managed to defend against, only to be destroyed by > something we had never anticipated, and that was commercialism. Around > the early 80's the hackers suddenly found that there was now > commercial interest in what they were doing. It was possible to get > rich by working at a private company. All that was necessary was to > stop sharing their work with the rest of the world and destroy the MIT- > AI lab, and this is what they did despite all the efforts I could make > to prevent them. > > Essentially all the competent programmers except for me, at the AI lab > were hired away, and this caused more than a momentary change, it > caused a permanent transformation because it broke the continuity of > the culture of hackers. New hackers were always attracted by the old > hackers; there were the most fun computers and the people doing the > most interesting things, and also a spirit which was a great deal of > fun to be part of. Once these things were gone, there is nothing to > recommend the place to anyone new, so new people stopped arriving. > There was no-one they could be inspired by, no-one that they could > learn those traditions from. In addition no-one to learn how to do > good programming from. With just a bunch of professors and graduate > students, who really don't know how to make a program work, you can't > learn to make good programs work. So the MIT AI lab that I loved is > gone and after a couple of years of fighting against the people who > did it to try to punish them for it I decided that I should dedicate > my self to try to create a new community with that spirit. > > But one of the problems I had to face was the problem of proprietary > software. For example one thing that happened at the lab, after the > hackers left, was that the machines and the software that we had > developed could no longer be maintained. The software of course > worked, and it continued to work if nobody changed it, but the > machines did not. The machines would break and there would be no-one > who could fix them and eventually they would be thrown out. In the old > days, yes we had service contracts for the machines, but it was > essentially a joke. That was a way of getting parts after the expert > hackers from the AI lab fixed the problem. Because if you let the > field-service person fix it it would take them days, and you didn't > want to do that, you wanted it to work. So, the people who knew how to > do those things would just go and fix it quickly, and since they were > ten times as competent as any field service person, they could do a > much better job. And then they would have the ruined boards, they > would just leave them there and tell the field service person ?take > these back and bring us some new ones?. > > In the real old days our hackers used to modify the > > read more ?... Perhaps as an antidote http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi Mark From stefan_ml at behnel.de Fri Jul 16 04:25:19 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 10:25:19 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: Carl Banks, 16.07.2010 07:50: > On Jul 15, 8:33 pm, Stefan Behnel wrote: >> The code I referenced is from the Cython compiler, and we use it to "do >> stuff" with the AST. The visitor pattern is actually a pretty common way to >> bind code in a single place that does a certain thing to different parts of >> a data structure. Without it, if you kept that code *inside* of the data >> structure, you'd have to spill the type specific parts all over your code. > > Ahh, so this aspect oriented programming is it. Never thought about it that way, but you have a point there. It's pretty much the same idea as AOP, but without any of those huge and feature drooling code injection frameworks. Stefan From jeanmichel at sequans.com Fri Jul 16 05:00:55 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 16 Jul 2010 11:00:55 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> Message-ID: <4C401FC7.3010203@sequans.com> Karsten Wutzke wrote: >> Yes, typo, I meant strictly. >> >> > > Damn, I mean strongly. At least not for identifying which methods to > call depending on the type/s. > > Karsten > Stringly is the perfect combination of strictly and strongly. Nice one :) JM From clp2 at rebertia.com Fri Jul 16 05:22:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jul 2010 02:22:56 -0700 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 12:37 PM, Sparky wrote: > Hello Python community! > > I am building a JSON-RPC web application that uses quite a few models. > I would like to return JSON encoded object information and I need a > system to indicate which properties should be returned when the object > is translated to a JSON encoded string. Unfortunately, this > application runs on top of Google's App Engine and, thus, private > attributes are not an option. Also, a preliminary search leads me to > believe that there are no real established ways to annotate variables. > Ideally I want to do something like: > > def to_JSON(self): > ? ? ? ?returnDict = {} > ? ? ? ?for member in filter(someMethod, inspect.getmembers(self)): > ? ? ? ? ? ? ? ?returnDict[member[0]] = member[1] > ? ? ? ?return json.dumps(returnDict) > > I recognize that two solutions would be to 1) include a prefix like > "public_" before variable names or 2) have a list/tuple of attributes > that should be transmitted, simply using the "in" operator. However, > both these options seem like a pretty ungraceful way to do it. Does > anyone else have an idea? Are there any established methods to apply > metadata / annotations to variables in Python or do you believe one of > the above is a good "pythonic" way to solve this problem? Those are about as Pythonic as you're going to get; I for one find the prefix (or similar) solution rather neat (Good luck pulling it off in a less dynamic language!), but option (2) is probably better in your particular case. Remember that at class-definition-time, Python has no idea what instance variables an object will have, so nothing exists for you to annotate; hence we're left with solutions of the forms you've given. You /could/ do something involving decorators and property()s, but that would be more verbose, more unnecessarily complicated, and less Pythonic. Cheers, Chris -- http://blog.rebertia.com From lists at cheimes.de Fri Jul 16 05:57:53 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jul 2010 11:57:53 +0200 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: > def to_JSON(self): > returnDict = {} > for member in filter(someMethod, inspect.getmembers(self)): > returnDict[member[0]] = member[1] > return json.dumps(returnDict) By the way you don't need filter here. The getmembers() function has a filter functions. It's called 'predicate'. Try inspect.getmembers(self, someMethod). http://docs.python.org/library/inspect.html#inspect.getmembers From marduk at letterboxes.org Fri Jul 16 06:48:21 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 16 Jul 2010 06:48:21 -0400 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279258000.23856.1385149339@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <1279258000.23856.1385149339@webmail.messagingengine.com> Message-ID: <1279277301.487364.5.camel@paska> On Fri, 2010-07-16 at 01:26 -0400, python at bdurham.com wrote: > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. > No > matter what combination of backslashes or raw strings I use, I am > unable > to find a way to code the following. > > >>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' >>> encode(', '.join([chr(i) for i in (34, 92, 9, 10)])) But, as another poster already said, if the limitations of doctests are causing you to struggle, then don't use doctests and instead use "real" tests. From micayael at gmail.com Fri Jul 16 07:09:16 2010 From: micayael at gmail.com (micayael) Date: Fri, 16 Jul 2010 04:09:16 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On 14 jul, 14:51, Mladen Gogala wrote: > On Wed, 14 Jul 2010 05:14:08 -0700, micayael wrote: > > Thanks Thomas. > > :-( then adodb today dosn't work with postgres (at least on ubuntu) > > right? > > No, ADOdb doesn't work with the newer versions of Postgres. ADOdb doesn't > work with Psycopg2 and the guy who maintains it did not reply to my > email. That is unfortunate because ADOdb is my favorite PHP class > library. It seems, though, that the Python version is not nearly as well > maintained as the PHP one. > > --http://mgogala.byethost5.com Thanks all of you for reply. Well bad news then, we have to use Psycopg2 directly. From bjornsteinarfjeldpettersen at gmail.com Fri Jul 16 08:02:11 2010 From: bjornsteinarfjeldpettersen at gmail.com (thebjorn) Date: Fri, 16 Jul 2010 05:02:11 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: On Jul 15, 10:34?pm, Peter wrote: > On Jul 16, 2:45?am, kj wrote: > > > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > > How do you do Python code-folding in Emacs? > > > Thanks! > > > ~K > [...] > Anybody else now of any better ideas or whatever? Now that I think > about it, I wouldn't mind using folding mode if I could make it > "easier" to use myself! :-) > > Peter I gave up too :-( Komodo from ActiveState has Emacs bindings and folding, and is generally a good editor and environment for when you want such a thing. It also has an out-of-process debugger that has helped me solve some nasty bugs. Still, I keep going back to Emacs, it's just snappier(*) and easier(**) to work with... Instead of folding I either split the window or create a new Frame (Ctrl 5 2) for the content I wish to refer to. -- bjorn (*) ha! (**) ...I know... From bjornsteinarfjeldpettersen at gmail.com Fri Jul 16 08:05:55 2010 From: bjornsteinarfjeldpettersen at gmail.com (thebjorn) Date: Fri, 16 Jul 2010 05:05:55 -0700 (PDT) Subject: Cannot send email References: <594998.379.qm@web53205.mail.re2.yahoo.com> Message-ID: On Jul 15, 7:07?pm, "D'Arcy J.M. Cain" wrote: > On Thu, 15 Jul 2010 09:50:57 -0700 (PDT) > > G F wrote: > > Does anyone have any ideas where the trouble is and what can be done > > about it? The little bit about: > > "reply: retcode (557); Msg: This mail server does not accept mail > > addressed to anInterestedPer... at yahoo.com" > > seems to be telling but I do not know why the server would respond this way. > > This is really not a Python question but I think that you will find > that the issue is that the server needs to know about the new IP > address. ?The error looks like an anti-relay thing. > > Contact the mail server admin or ask on a list dedicated to > administrating email. > Jeff Atwood had a column about it recently http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html well worth a read. -- bjorn From inquisitive.scientist at gmail.com Fri Jul 16 08:45:50 2010 From: inquisitive.scientist at gmail.com (Inquisitive Scientist) Date: Fri, 16 Jul 2010 05:45:50 -0700 (PDT) Subject: improvement for copy.deepcopy : no memo for immutable types Message-ID: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> I am having problems with running copy.deepcopy on very large data structures containing lots of numeric data: 1. copy.deepcopy can be very slow 2. copy.deepcopy can cause memory errors even when I have plenty of memory I think the problem is that the current implementation keeps a memo for everything it copies even immutable types. In addition to being slow, this makes the memo dict grow very large when there is lots of simple numeric data to be copied. For long running programs, large memo dicts seem to cause memory fragmentation and result in memory errors. It seems like this could be easily fixed by adding the following lines at the very start of the deepcopy function: if isinstance(x, (type(None), int, long, float, bool, str)): return x This seems perfectly safe, should speed things up, keep the memo dict smaller, and be easy to add. Can someone add this to copy.py or point me to the proper procedure for requesting this change in copy.py? Thanks, -I.S. From nick_keighley_nospam at hotmail.com Fri Jul 16 09:00:57 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Fri, 16 Jul 2010 06:00:57 -0700 (PDT) Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: On 16 July, 09:24, Mark Tarver wrote: > On 15 July, 23:21, bolega wrote: > > >http://www.gnu.org/philosophy/stallman-kth.html > > > RMS lecture at KTH (Sweden), 30 October 1986 did you really have to post all of this... > > read more ?... ...oh sorry only about a third of it... > Perhaps as an antidote > > http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-form... ...to add two lines? From stefan_ml at behnel.de Fri Jul 16 09:02:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 15:02:50 +0200 Subject: improvement for copy.deepcopy : no memo for immutable types In-Reply-To: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> Message-ID: Inquisitive Scientist, 16.07.2010 14:45: > I am having problems with running copy.deepcopy on very large data > structures containing lots of numeric data: > > 1. copy.deepcopy can be very slow > 2. copy.deepcopy can cause memory errors even when I have plenty of > memory > > I think the problem is that the current implementation keeps a memo > for everything it copies even immutable types. In addition to being > slow, this makes the memo dict grow very large when there is lots of > simple numeric data to be copied. For long running programs, large > memo dicts seem to cause memory fragmentation and result in memory > errors. > > It seems like this could be easily fixed by adding the following lines > at the very start of the deepcopy function: > > if isinstance(x, (type(None), int, long, float, bool, str)): > return x > > This seems perfectly safe, should speed things up, keep the memo dict > smaller, and be easy to add. and - have you tried it? Stefan From schaffer at optonline.net Fri Jul 16 09:07:42 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 16 Jul 2010 09:07:42 -0400 Subject: any issues with long running python apps? In-Reply-To: <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> Message-ID: <4c40599f$0$21783$607ed4bc@cv.net> thanks to all for the replies. the Windows memory fragmentation was one of the "i didn't know that" items. we will use 64-bit Windows OS if the job happens. agree with all the other suggestions: multiple threads for data and GUI, etc. Also, might push for Linux even though the company is Windows-only presently. but thinking about the issue some more as well as everyone's comments, have decided to proceed cautiously and let the client decide first that they really need this app regardless of guaranteed Windows-based uptime. Les From victorsubervi at gmail.com Fri Jul 16 09:22:31 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 16 Jul 2010 08:52:31 -0430 Subject: MySQL One More Again Message-ID: Hi; I have the following code: cursor.execute('select MyTable from optionsDetails where Store=%s', (store,)) options_tables = [item[0] for item in cursor] for table in options_tables: cursor.execute('select * from %' % table) You can already see what my question is. One of y'all said it's possible under certain conditions to use the % without risking attack. Now is when I need to know how to do that. Please advise. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Jul 16 09:29:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 15:29:35 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c40599f$0$21783$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> <4c40599f$0$21783$607ed4bc@cv.net> Message-ID: Les Schaffer, 16.07.2010 15:07: > agree with all the other suggestions: multiple threads for data and GUI, The way I read it, the suggestion was to use separate processes, not multiple threads. That's a pretty important difference. Stefan From nfdisco at gmail.com Fri Jul 16 09:29:46 2010 From: nfdisco at gmail.com (ernest) Date: Fri, 16 Jul 2010 06:29:46 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> On 15 Jul, 18:45, kj wrote: > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > How do you do Python code-folding in Emacs? > > Thanks! > > ~K I tried the outline-mode and it seemed to work. It can collapse different blocks of code, such as functions, classes, etc. However, I never got used to it because of the bizarre key bindings. Bye. Ernest From usenot at geekmail.INVALID Fri Jul 16 09:38:31 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 16 Jul 2010 15:38:31 +0200 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: <20100716153831.5d399451@geekmail.INVALID> On Fri, 16 Jul 2010 06:29:46 -0700 (PDT) ernest wrote: > On 15 Jul, 18:45, kj wrote: > > This is a question _for Emacs users_ (the rest of you, go away :) > > ?). > > > > How do you do Python code-folding in Emacs? > > > > Thanks! > > > > ~K > > I tried the outline-mode and it seemed to work. It can > collapse different blocks of code, such as functions, > classes, etc. > > However, I never got used to it because of the bizarre > key bindings. > Yeah, that's Emacs for ya ... Like, BURRRN! ... OK, I'll move along. /W -- INVALID? DE! From python at mrabarnett.plus.com Fri Jul 16 09:49:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 14:49:21 +0100 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4C406361.8050607@mrabarnett.plus.com> Lawrence D'Oliveiro wrote: > In message , MRAB wrote: > >> Normally it's only string literals that could be so long that you might >> want to split them over several lines. It is somewhat unusual to have a >> _numeric_ literal that's very very long! > > Seems a peculiar assumption to make in a language that allows integers of > arbitrary length, does it not? What's the recommended maximum line length in Python? 80 characters? If you take into account indentation, etc, that's still a long integer. And it's still only the _recommended_ maximum. From no.email at please.post Fri Jul 16 09:53:02 2010 From: no.email at please.post (kj) Date: Fri, 16 Jul 2010 13:53:02 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: In Thomas Jollans writes: >On 07/15/2010 06:41 PM, kj wrote: >> In Thomas Jollans writes: >> >>> http://docs.python.org/library/ctypes.html#fundamental-data-types >> >>> c_longdouble maps to float >> >> Thanks for pointing this out! >> ~K >> (Does it make *any difference at all* to use c_longdouble instead >> of c_double? If not, I wonder what's the point of having c_longdouble >> at all.) >they're still different types (in C). i understand that doubles and long doubles are different in C. >on my machine, a double is 64 bits wide, while a long double is 129 bits >wide. This means that a function that expects a long double argument >will expect 16 bytes, but ctypes will only pass 8 bytes if you tell it >to pass double. The same applies to return values. This is extremely confusing. From my naive reading of the documentation, I would have expected that the following two blocks would produce identical results (expl is one of the standard C math library exponential functions, with signature "long double expl(long double)"): MATH.expl.argtypes = [c_longdouble] MATH.expl.restype = c_longdouble print MATH.expl(0) MATH.expl.argtypes = [c_double] MATH.expl.restype = c_double print MATH.expl(0) ...but no, they don't: the first one prints out the correct result, 1.0, while the second one prints out 0.0, of all things. (In fact, with the second (mis)configuration, the value returned by MATH.expl is always equal to its argument, go figure.) I find these results perplexing because, based on the docs, I expected that they *both* would be analogous to doing the following in C: printf("%f\n", (double) expl((double) 0.0)); /* prints out 1.000000 */ i.e., in *both* cases, expl would get passed a double (which gets automatically cast into a long double), and in both cases its returned value would be cast into a double. Clearly, this is not what's happening, but I can't figure out the correct interpreation of what's going on based on the documentation... From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 09:59:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 13:59:31 GMT Subject: improvement for copy.deepcopy : no memo for immutable types References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> Message-ID: <4c4065c2$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 05:45:50 -0700, Inquisitive Scientist wrote: > I am having problems with running copy.deepcopy on very large data > structures containing lots of numeric data: [...] > This seems perfectly safe, should speed things up, keep the memo dict > smaller, and be easy to add. Can someone add this to copy.py or point me > to the proper procedure for requesting this change in copy.py? These are the minimum steps you can take: (1) Go to the Python bug tracker: http://bugs.python.org/ (2) If you don't already have one, create an account. (3) Create a new bug report, explaining why you think deepcopy is buggy, the nature of the bug, and your suggested fix. If you do so, it might be a good idea to post a link to the bug here, for interested people to follow up. However doing the minimum isn't likely to be very useful. Python is maintained by volunteers, and there are more bugs than person-hours available to fix them. Consequently, unless a bug is serious, high- profile, or affects a developer personally, it is likely to be ignored. Sometimes for years. Sad but true. You can improve the odds of having the bug (assuming you are right that it is a bug) fixed by doing more than the minimum. The more of these you can do, the better the chances: (4) Create a test that fails with the current code, following the examples in the standard library tests. Confirm that it fails with the existing module. (5) Patch the copy module to fix the bug. Confirm that the new test passes with your patch, and that you don't cause any regressions (failed tests). (6) Create a patch file that adds the new test and the patch. Upload it to the bug tracker. There's no point in writing the patch for Python 2.5 or 3.0, don't waste your time. Version 2.6 *might* be accepted. 2.7 and/or 3.1 should be, provided people agree that it is a bug. If you do all these things -- demonstrate successfully that this is a genuine bug, create a test for it, and fix the bug without breaking anything else, then you have a good chance of having the fix accepted. Good luck! Your first patch is always the hardest. -- Steven From schaffer at optonline.net Fri Jul 16 10:13:17 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 16 Jul 2010 10:13:17 -0400 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> <4c40599f$0$21783$607ed4bc@cv.net> Message-ID: <4c4068f5$0$31269$607ed4bc@cv.net> Stefan Behnel wrote: > Les Schaffer, 16.07.2010 15:07: >> agree with all the other suggestions: multiple threads for data and GUI, > > The way I read it, the suggestion was to use separate processes, not > multiple threads. That's a pretty important difference. check. processes, not threads. Les From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 10:17:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 14:17:02 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c4069de$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > Lawrence D'Oliveiro wrote: >> In message , MRAB >> wrote: >> >>> Normally it's only string literals that could be so long that you >>> might want to split them over several lines. It is somewhat unusual to >>> have a _numeric_ literal that's very very long! >> >> Seems a peculiar assumption to make in a language that allows integers >> of arbitrary length, does it not? > > What's the recommended maximum line length in Python? 80 characters? If > you take into account indentation, etc, that's still a long integer. And > it's still only the _recommended_ maximum. Not only that, but it only takes 73 digits to write out the total number of particles in the entire universe: 1000000000000000000000000000000000000000000000000000000000000000000000000 or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all the way up to 1e87.) So for anything related to counting or labelling actual, physical objects, you will be dealing with smaller numbers than that. E.g. the number of grains of sand on the earth has been estimated (very roughly) as a mere 1000000000000000000000000, or 25 digits. It always makes me laugh when I receive an invoice from some company, and the account number or invoice number is (e.g.) 1000000023456789. Who do they think they're fooling? -- Steven From python at mrabarnett.plus.com Fri Jul 16 10:32:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:32:40 +0100 Subject: File transfer on network In-Reply-To: References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <4C406D88.40707@mrabarnett.plus.com> mukesh tiwari wrote: > On Jul 16, 4:08 am, MRAB wrote: >> mukesh tiwari wrote: >>> Hello all >>> Currently i am trying to develop a client and server in python. Client >>> takes screenshot in every 20 seconds and send it to server. Server >>> store the received file in folder. Here is code for Client >>> import sys >>> import socket >>> import gtk.gdk >>> import time >>> if __name__ == "__main__": >>> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); >>> host,port="localhost",50007 >>> s.connect((host,port)) >>> while 1: >>> w = gtk.gdk.get_default_root_window() >>> sz = w.get_size() >>> pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) >>> pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) >>> if (pb != None): >>> pb.save('/home/tmp_1/screenshot.png',"png") >>> f=open('/home//tmp_1/screenshot.png','rb') >>> while 1: >>> blk=f.read(2048) >>> if not blk:break >>> s.send(blk) >>> f.close() >>> print 'file transfer done'; >>> time.sleep(20) >>> s.close() >>> Server Code >>> import sys >>> import socket >>> import time >>> if __name__ == "__main__": >>> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) >>> host,port="",50007 >>> s.bind((host,port)) >>> s.listen(1) >>> conn,add=s.accept() >>> i=0 >>> while 1: >>> f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') >>> while 1: >>> data=conn.recv(2048) >>> if not data:break >>> f.write(data) >>> f.close() >>> print 'file received' >>> time.sleep(20) >>> i+=1; >>> #print ' file received ' >>> conn.close() >>> My problem is that server is copying only first image >>> copyscreenshot_0.png while my client continuously taking screen shot. >>> Kindly tell me what is wrong with my server code. >> The .recv will return an empty string only when the connection is closed >> by the client, but the client keeps the connection open. >> >> You could either open and close a connection for each image, or have the >> client tell the server how many bytes it's going to send, followed by >> the bytes (my preference would be to send the size as a string ending >> with, say, a newline). >> >> Another point: the .send method doesn't guarantee that it'll send all >> the bytes (it'll return the number of bytes that it has actually sent); >> use the .sendall method instead. > > Thank you MARB. I used your first idea and opening and closing > connection for each image. Just wanted to know if i have to take > pictures at small intervals , this method is efficient or not? Creating a new connection every 20 seconds should be OK. For much smaller intervals you would need to test it yourself. The minimum interval depends on how often you're sending data and you're sending each time, and keeping the connection open would let you avoid the extra overhead and get a little bit more capacity. > It would be great if you can provide a bit code for second method. > Keeping the connection open but how to know that this is end a > particular image and save it. The client is told how many bytes of image data it should expect, so it can count how many it has written to the image file and close the file when all of them. You'll learn more if you try it yourself first! :-) From johann.spies at gmail.com Fri Jul 16 10:34:19 2010 From: johann.spies at gmail.com (Johann Spies) Date: Fri, 16 Jul 2010 16:34:19 +0200 Subject: Nested loop not working Message-ID: I am overlooking something stupid. I have two files: one with keywords and another with data (one record per line). I want to determine for each keyword which lines in the second file contains that keyword. The following code is not working. It loops through the second file but only uses the first keyword in the first file. #!/usr/bin/env python # -*- coding: utf-8 -*- import re keywords = open("sleutelwoorde",'r') data = open("sarua_marine_sleutelwoorde.csv",'r') remove_quotes = re.compile('"') for sw in keywords: for r in data: swc = remove_quotes('',sw)[:-1] if swc in r.lower(): print swc + ' ---> ' + r print swc What am I missing? Regards Johann -- "Finally, brethren, whatsoever things are true, whatsoever things are honest, whatsoever things are just, whatsoever things are pure, whatsoever things are lovely, whatsoever things are of good report; if there be any virtue, and if there be any praise, think on these things." Philippians 4:8 From python at mrabarnett.plus.com Fri Jul 16 10:39:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:39:21 +0100 Subject: MySQL One More Again In-Reply-To: References: Message-ID: <4C406F19.5080909@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have the following code: > > cursor.execute('select MyTable from optionsDetails where Store=%s', > (store,)) > options_tables = [item[0] for item in cursor] > for table in options_tables: > cursor.execute('select * from %' % table) > Should be: 'select * from %s' % table Details! :-) > You can already see what my question is. One of y'all said it's possible > under certain conditions to use the % without risking attack. Now is > when I need to know how to do that. Please advise. > It's safe when there's no way that the value you're putting in can come from the user. Here you're taking it from the 'optionsDetails' table. Can the user add, alter or delete that entry in any way? From python at mrabarnett.plus.com Fri Jul 16 10:41:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:41:45 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c4069de$0$11101$c3e8da3@news.astraweb.com> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C406FA9.9030504@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > >> Lawrence D'Oliveiro wrote: >>> In message , MRAB >>> wrote: >>> >>>> Normally it's only string literals that could be so long that you >>>> might want to split them over several lines. It is somewhat unusual to >>>> have a _numeric_ literal that's very very long! >>> Seems a peculiar assumption to make in a language that allows integers >>> of arbitrary length, does it not? >> What's the recommended maximum line length in Python? 80 characters? If >> you take into account indentation, etc, that's still a long integer. And >> it's still only the _recommended_ maximum. > > Not only that, but it only takes 73 digits to write out the total number > of particles in the entire universe: > > 1000000000000000000000000000000000000000000000000000000000000000000000000 > > or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all > the way up to 1e87.) So for anything related to counting or labelling > actual, physical objects, you will be dealing with smaller numbers than > that. E.g. the number of grains of sand on the earth has been estimated > (very roughly) as a mere 1000000000000000000000000, or 25 digits. > > It always makes me laugh when I receive an invoice from some company, and > the account number or invoice number is (e.g.) 1000000023456789. Who do > they think they're fooling? > It's possible that they're splitting it into fields. From victorsubervi at gmail.com Fri Jul 16 10:55:10 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 16 Jul 2010 10:25:10 -0430 Subject: MySQL One More Again In-Reply-To: <4C406F19.5080909@mrabarnett.plus.com> References: <4C406F19.5080909@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 10:09 AM, MRAB wrote: > Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> cursor.execute('select MyTable from optionsDetails where Store=%s', >> (store,)) >> options_tables = [item[0] for item in cursor] >> for table in options_tables: >> cursor.execute('select * from %' % table) >> >> Should be: > > 'select * from %s' % table > > Details! :-) LOL. Whoops. Thanks. > > > You can already see what my question is. One of y'all said it's possible >> under certain conditions to use the % without risking attack. Now is when I >> need to know how to do that. Please advise. >> >> It's safe when there's no way that the value you're putting in can come > from the user. > > Here you're taking it from the 'optionsDetails' table. Can the user add, > alter or delete that entry in any way? > No, and that's kind of what I figured. Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Fri Jul 16 10:56:25 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 16 Jul 2010 07:56:25 -0700 (PDT) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: <8a635803-56c4-4593-954a-510561567e17@d8g2000yqf.googlegroups.com> On Jul 16, 2:53?pm, kj wrote: > This is extremely confusing. ?From my naive reading of the > documentation, I would have expected that the following two blocks > would produce identical results (expl is one of the standard C math > library exponential functions, with signature "long double expl(long > double)"): > > MATH.expl.argtypes = [c_longdouble] > MATH.expl.restype = c_longdouble > print MATH.expl(0) > > MATH.expl.argtypes = [c_double] > MATH.expl.restype = c_double > print MATH.expl(0) > > ...but no, they don't: the first one prints out the correct result, > 1.0, while the second one prints out 0.0, of all things. ?(In fact, > with the second (mis)configuration, the value returned by MATH.expl > is always equal to its argument, go figure.) This is just a case of garbage in, garbage out. In the second case you're telling ctypes that the signature of expl is double expl(double) which just isn't true. ctypes has no way of telling that in fact expl takes a long double rather than a double. > I find these results perplexing because, based on the docs, I > expected that they *both* would be analogous to doing the following > in C: > > printf("%f\n", (double) expl((double) 0.0)); /* prints out 1.000000 */ No, not really. Assuming that expl has been declared somewhere (e.g. you've included math.h), the C compiler knows that expl takes a long double, so it'll convert the "(double) 0.0" argument to a long double before passing it to expl. Your second Python+ctypes example would be equivalent to doing something like this in C: #include double expl(double x); /* deliberate misdeclaration of expl */ int main(void) { printf("%f\n", expl(0.0)); return 0; } which indeed produces 0.0 on my machine (gcc 4.2 / OS X 10.6). And the compiler helpfully issues a warning: test.c:1: warning: conflicting types for built-in function ?expl? Actually, the warning is a bit surprising, because there's only one (wrong) declaration for expl, so what is there for it to conflict with? The answer is that there are some commonly used library functions that gcc has builtin versions for, so already knows the signature of; expl is one of these. This is backed up by the fact that when compiling with -fno-builtin-expl, no warning is issued. > i.e., in *both* cases, expl would get passed a double (which gets > automatically cast into a long double), But how on earth would ctypes *know* it's supposed to convert (nitpick: not cast) to a long double? The function signature isn't available to ctypes; it's only through you setting .argtypes and .restype that ctypes knows anything about it. -- Mark From ian.g.kelly at gmail.com Fri Jul 16 10:56:46 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Jul 2010 08:56:46 -0600 Subject: Nested loop not working In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 8:34 AM, Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. ?It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > ? ?for r in data: > ? ? ? ?swc = remove_quotes('',sw)[:-1] > ? ? ? ?if swc in r.lower(): > ? ? ? ? ? ? ? ?print swc + ' ---> ' + r > ? ? ? ? ? ? ? ?print swc > > What am I missing? Not sure about the loop, but this line looks incorrect: swc = remove_quotes('',sw)[:-1] I don't think a compiled regular expression object is callable; you have to call one of its methods. HTH, Ian From python at mrabarnett.plus.com Fri Jul 16 10:59:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:59:28 +0100 Subject: Nested loop not working In-Reply-To: References: Message-ID: <4C4073D0.7050601@mrabarnett.plus.com> Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? > The line: for r in data reads through the file until it the end. The next time around the outer loop it's already at the end of the file. You need to reset it to the start of the file with: data.seek(0) Incidentally, it would be faster if you read the keywords into a list first (assuming that there isn't a huge number of keywords) and then scanned through the file once. From pwdyson at yahoo.com Fri Jul 16 11:15:54 2010 From: pwdyson at yahoo.com (Paul) Date: Fri, 16 Jul 2010 08:15:54 -0700 (PDT) Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... Message-ID: <717828.19237.qm@web53602.mail.re2.yahoo.com> > Thomas Jollans, 15.07.2010 18:41: > > On 07/15/2010 01:00 PM, Paul wrote: > >> I'm pleased to announce the release of inflect.py v0.1.8, a module that > >> correctly generates: > >> * the plural of singular nouns and verbs > >> * the singular of plural nouns > >> * ordinals > >> * indefinite articles > >> * present participles > >> * and converts numbers to words > > Which languages does it support? If the answer is what I expect it is, > It is. Most of the time, when people forget to say what they are talking > about, assuming that they are either US-Americans or Windows users will hit > the nail on the head. > Still, a pretty nice tool, I'd say. > > did you design the module with multilingualism in mind? > Just look at the code, it consists almost exclusively of long lists of > words. Multilingualism clearly wasn't a design goal. > Stefan The module is based upon a Perl module that has been around for about ten years. I did a line by line translation of the Perl code into Python, got that working and am now slowly redesigning the code. I am currently removing many of the regular expressions, which makes the code many times faster (and clearer, I think). The code alternates between applying rules and using lists of words. The author of the original Perl code, Damian Conway, wrote an academic paper on the approach taken. http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html A future goal is to have this work in a way that is far more pluggable and so be applicable to other languages. But at the moment I'm happy to have got it working. I'm pretty sure that if Damian was writing this from scratch today he would design it differently. However, I had existing Perl code that worked, so I would rather start with that, get it working in Python and covered by tests. Then I can improve the design with the safety of test coverage. The Perl version is called Lingua::EN::Inflect, so was more explicit about being for English in its naming and there are other Perl Lingua::XX::Inflects for other languages. But my lack of mentioning English in the announcement was an oversight. Both the Perl author and I are Australian, and so the modules support British English over American English where necessary, with the Oxford English Dictionary as our guide. Cheers, Paul From ramercer at gmail.com Fri Jul 16 11:18:41 2010 From: ramercer at gmail.com (Adam Mercer) Date: Fri, 16 Jul 2010 10:18:41 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 02:09, Heikki Toivonen wrote: > That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL > changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at > this time, you should check out M2Crypto from the Subversion repository. See > http://chandlerproject.org/Projects/MeTooCrypto for details on how to get > the sources. Thanks any ETA on a new release supporting OpenSSL 1.0.x? Cheers Adam From fetchinson at googlemail.com Fri Jul 16 11:26:05 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 16 Jul 2010 17:26:05 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: >>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>> correctly generates: >>> >>> * the plural of singular nouns and verbs >>> * the singular of plural nouns >>> * ordinals >>> * indefinite articles >>> * present participles >>> * and converts numbers to words >> >> Which languages does it support? If the answer is what I expect it is, > > It is. Most of the time, when people forget to say what they are talking > about, assuming that they are either US-Americans or Windows users will hit > the nail on the head. And most of the time, when people are bitching about US-Americans, assuming that they are Europeans will hit the nail on the head :) Duck-and-run-ly yours, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Fri Jul 16 11:29:23 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 16 Jul 2010 11:29:23 -0400 Subject: Nested loop not working In-Reply-To: References: Message-ID: <4C407AD3.204@ieee.org> Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? > > Regards > Johann > > Once you've read all the data from 'data' in the first inner loop, there's no more for the second keyword. Easiest answer is to do something like: data.seek(0) just before the inner loop. That will (re)position to begin of hte 'data' file. DaveA From fetchinson at googlemail.com Fri Jul 16 11:29:44 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 16 Jul 2010 17:29:44 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>>> correctly generates: >>>> >>>> * the plural of singular nouns and verbs >>>> * the singular of plural nouns >>>> * ordinals >>>> * indefinite articles >>>> * present participles >>>> * and converts numbers to words >>> >>> Which languages does it support? If the answer is what I expect it is, >> >> It is. Most of the time, when people forget to say what they are talking >> about, assuming that they are either US-Americans or Windows users will >> hit >> the nail on the head. > > And most of the time, when people are bitching about US-Americans, > assuming that they are Europeans will hit the nail on the head :) In this case, I actually should modify the above to: when people are bitching about an English speaker they don't like for some reason and they automatically think that said person must be US-American when in fact he/she is Australian (or British or South African or something else), assuming that they are Europeans will hit the nail on the head :) Duck-and-run-even-faster-ly yours, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From drobinow at gmail.com Fri Jul 16 11:42:46 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 16 Jul 2010 11:42:46 -0400 Subject: Q for Emacs users: code-folding (hideshow) In-Reply-To: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: On Fri, Jul 16, 2010 at 9:29 AM, ernest wrote: > On 15 Jul, 18:45, kj wrote: >> This is a question _for Emacs users_ (the rest of you, go away :) ?). >> >> How do you do Python code-folding in Emacs? >> >> Thanks! >> >> ~K > > I tried the outline-mode and it seemed to work. It can > collapse different blocks of code, such as functions, > classes, etc. > > However, I never got used to it because of the bizarre > key bindings. Really, if you can't be bothered to set your key bindings to something you prefer, then I don't think Emacs is the right tool for you. From rui.vapps at gmail.com Fri Jul 16 12:01:01 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 16 Jul 2010 09:01:01 -0700 (PDT) Subject: create dynamic instance Message-ID: class Test: def __init__(self): self.value=0 def change(self, val): self.value=val if __name__=='__main__': for x in range(10): x=Test() """ the question is how do i call x.value outside of that for loop? something like print x.value ? """ thanks for any help. From fuglyducky at gmail.com Fri Jul 16 12:10:09 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Fri, 16 Jul 2010 09:10:09 -0700 (PDT) Subject: Python 3 and setuptools Message-ID: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> I am trying to install a library that requires setuptools. Unfortunately, setuptools isn't available for Python 3 yet. Is this correct? Any idea when it may be available OR if there is a different tool/method of getting setuptools installed for Python 3? Thanks!!! From nagle at animats.com Fri Jul 16 12:10:57 2010 From: nagle at animats.com (John Nagle) Date: Fri, 16 Jul 2010 09:10:57 -0700 Subject: MySQL One More Again In-Reply-To: References: Message-ID: <4c40849f$0$1583$742ec2ed@news.sonic.net> On 7/16/2010 7:39 AM, MRAB wrote: > Victor Subervi wrote: >> Hi; >> I have the following code: >> >> cursor.execute('select MyTable from optionsDetails where Store=%s', >> (store,)) >> options_tables = [item[0] for item in cursor] >> for table in options_tables: >> cursor.execute('select * from %' % table) As has been explained to you repeatedly, you're doing it wrong. You don't use a relational database to get a field which leads to another table. Put the options in one table keyed by Store. Go buy a copy of "Databases for Dummies": http://www.amazon.com/Intranet-Databases-Dummies-Paul-Litwin/dp/0764502212 John Nagle From python at mrabarnett.plus.com Fri Jul 16 12:15:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 17:15:19 +0100 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <717828.19237.qm@web53602.mail.re2.yahoo.com> References: <717828.19237.qm@web53602.mail.re2.yahoo.com> Message-ID: <4C408597.9000705@mrabarnett.plus.com> Paul wrote: >> Thomas Jollans, 15.07.2010 18:41: > >>> On 07/15/2010 01:00 PM, Paul wrote: >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module >>>> that correctly generates: > >>>> * the plural of singular nouns and verbs >>>> * the singular of plural nouns >>>> * ordinals >>>> * indefinite articles >>>> * present participles >>>> * and converts numbers to words > >>> Which languages does it support? If the answer is what I expect it >>> is, > >> It is. Most of the time, when people forget to say what they are >> talking about, assuming that they are either US-Americans or Windows >> users will hit the nail on the head. > >> Still, a pretty nice tool, I'd say. > >>> did you design the module with multilingualism in mind? > >> Just look at the code, it consists almost exclusively of long lists >> of words. Multilingualism clearly wasn't a design goal. > >> Stefan > > The module is based upon a Perl module that has been around for about > ten years. I did a line by line translation of the Perl code into > Python, got that working and am now slowly redesigning the code. I am > currently removing many of the regular expressions, which makes the > code many times faster (and clearer, I think). > > The code alternates between applying rules and using lists of words. > The author of the original Perl code, Damian Conway, wrote an academic > paper on the approach taken. > http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html > > A future goal is to have this work in a way that is far more pluggable > and so be applicable to other languages. But at the moment I'm happy > to have got it working. > > I'm pretty sure that if Damian was writing this from scratch today he > would design it differently. However, I had existing Perl code that > worked, so I would rather start with that, get it working in Python > and covered by tests. Then I can improve the design with the safety of > test coverage. > > The Perl version is called Lingua::EN::Inflect, so was more explicit > about being for English in its naming and there are other Perl > Lingua::XX::Inflects for other languages. But my lack of mentioning > English in the announcement was an oversight. Both the Perl author and > I are Australian, and so the modules support British English over > American English where necessary, with the Oxford English Dictionary > as our guide. > Could I suggest that you also change the method names to something clearer? From python at mrabarnett.plus.com Fri Jul 16 12:17:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 17:17:54 +0100 Subject: create dynamic instance In-Reply-To: References: Message-ID: <4C408632.5060205@mrabarnett.plus.com> Ray wrote: > class Test: > def __init__(self): > self.value=0 > def change(self, val): > self.value=val > > if __name__=='__main__': > for x in range(10): > x=Test() > """ > the question is how do i call x.value outside of that for loop? > something like > print x.value ? > """ > > thanks for any help. Have you tried it? Why are you using the same name for the loop variable and the instance you're creating? From stefan_ml at behnel.de Fri Jul 16 12:20:37 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 18:20:37 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: Daniel Fetchinson, 16.07.2010 17:29: >>>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>>>> correctly generates: >>>>> >>>>> * the plural of singular nouns and verbs >>>>> * the singular of plural nouns >>>>> * ordinals >>>>> * indefinite articles >>>>> * present participles >>>>> * and converts numbers to words >>>> >>>> Which languages does it support? If the answer is what I expect it is, >>> >>> It is. Most of the time, when people forget to say what they are talking >>> about, assuming that they are either US-Americans or Windows users will >>> hit the nail on the head. >> >> And most of the time, when people are bitching about US-Americans, >> assuming that they are Europeans will hit the nail on the head :) > > In this case, I actually should modify the above to: when people are > bitching about an English speaker they don't like for some reason and > they automatically think that said person must be US-American when in > fact he/she is Australian (or British or South African or something > else), assuming that they are Europeans will hit the nail on the head > :) :) I'm happy to see that the good old clich?s still work in all directions. Makes the world so easy. Stefan From rui.vapps at gmail.com Fri Jul 16 12:22:16 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 16 Jul 2010 09:22:16 -0700 (PDT) Subject: create dynamic instance References: Message-ID: <5fe7c1ea-4a1b-46d8-a2f0-5267ac4847cc@n19g2000prf.googlegroups.com> On Jul 16, 12:17?pm, MRAB wrote: > Ray wrote: > > class Test: > > ? def __init__(self): > > ? ? self.value=0 > > ? def change(self, val): > > ? ? self.value=val > > > if __name__=='__main__': > > ? for x in range(10): > > ? ? x=Test() > > ? """ > > ? the question is how do i call x.value outside of that for loop? > > ? something like > > ? print x.value ? > > ? """ > > > thanks for any help. > > Have you tried it? > > Why are you using the same name for the loop variable and the instance > you're creating? yes. I need to create instance. the code above is just a example. on real code, it read a dict, and create the instance from dict.keys() name. that dict is build dynamic from database. From breamoreboy at yahoo.co.uk Fri Jul 16 12:23:34 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 16 Jul 2010 17:23:34 +0100 Subject: improvement for copy.deepcopy : no memo for immutable types In-Reply-To: <4c4065c2$0$11101$c3e8da3@news.astraweb.com> References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> <4c4065c2$0$11101$c3e8da3@news.astraweb.com> Message-ID: On 16/07/2010 14:59, Steven D'Aprano wrote: [snip] > However doing the minimum isn't likely to be very useful. Python is > maintained by volunteers, and there are more bugs than person-hours > available to fix them. Consequently, unless a bug is serious, high- > profile, or affects a developer personally, it is likely to be ignored. > Sometimes for years. Sad but true. > To give people an idea, here's the weekly Summary of Python tracker Issues on python-dev and timed at 17:07 today. " 2807 open (+44) / 18285 closed (+18) / 21092 total (+62) Open issues with patches: 1144 Average duration of open issues: 703 days. Median duration of open issues: 497 days. Open Issues Breakdown open 2765 (+42) languishing 14 ( +0) pending 27 ( +2) Issues Created Or Reopened (64) " I've spent a lot of time helping out in the last few weeks on the issue tracker. The oldest open issue I've come across was dated 2001, and there could be older. Unless more volunteers come forward, particularly to do patch reviews or similar, the situation as I see it can only get worse. Kindest regards. Mark Lawrence. From post at andre-bell.de Fri Jul 16 12:37:00 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Fri, 16 Jul 2010 18:37:00 +0200 Subject: create dynamic instance In-Reply-To: References: Message-ID: <4C408AAC.7090009@andre-bell.de> On 07/16/2010 06:01 PM, Ray wrote: > if __name__=='__main__': > for x in range(10): > x=Test() > """ > the question is how do i call x.value outside of that for loop? > something like > print x.value ? > """ You would have to keep references to your Test objects (untested code): if __name__ == '__main__': test_objects = [] for x in range(10): test_objects[x] = Test() print test_objects[0].value ... You may want to rewrite this as a list comprehension if __name__ == '__main__': test_objects = [Test() for i in range(10)] print test_objects[0].value Andre From solipsis at pitrou.net Fri Jul 16 12:40:28 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 16 Jul 2010 18:40:28 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: <20100716184028.79874a61@pitrou.net> On Fri, 16 Jul 2010 17:29:44 +0200 Daniel Fetchinson wrote: > >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that > >>>> correctly generates: > >>>> > >>>> * the plural of singular nouns and verbs > >>>> * the singular of plural nouns > >>>> * ordinals > >>>> * indefinite articles > >>>> * present participles > >>>> * and converts numbers to words > >>> > >>> Which languages does it support? If the answer is what I expect it is, > >> > >> It is. Most of the time, when people forget to say what they are talking > >> about, assuming that they are either US-Americans or Windows users will > >> hit > >> the nail on the head. > > > > And most of the time, when people are bitching about US-Americans, > > assuming that they are Europeans will hit the nail on the head :) > > In this case, I actually should modify the above to: when people are > bitching about an English speaker they don't like for some reason and > they automatically think that said person must be US-American when in > fact he/she is Australian (or British or South African or something > else), assuming that they are Europeans will hit the nail on the head > :) That's why we'd rather bitch about Anglo-Saxons instead. Regards Antoine. From thomas at jollans.com Fri Jul 16 12:45:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 18:45:03 +0200 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279258000.23856.1385149339@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <1279258000.23856.1385149339@webmail.messagingengine.com> Message-ID: <4C408C8F.5010505@jollans.com> On 07/16/2010 07:26 AM, python at bdurham.com wrote: > Thomas, > >> Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. > > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. No > matter what combination of backslashes or raw strings I use, I am unable > to find a way to code the following. > >>>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' Does either of these docstrings work: def encode(s): """description >>> encode( '", \\, \\t, \\n' ) '\\", \\\\, \\\\t, \\\\n' """ ... def encode(s): r"""description >>> encode( '", \, \t, \n' ) '\", \\, \\t, \\n' """ ... From thomas at jollans.com Fri Jul 16 12:51:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 18:51:05 +0200 Subject: Python 3 and setuptools In-Reply-To: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> References: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> Message-ID: <4C408DF9.9060900@jollans.com> On 07/16/2010 06:10 PM, fuglyducky wrote: > I am trying to install a library that requires setuptools. > Unfortunately, setuptools isn't available for Python 3 yet. Is this > correct? Any idea when it may be available OR if there is a different > tool/method of getting setuptools installed for Python 3? It is available. It is, in fact, in the Debian archives, which is where I got it from, thought this probably doesn't help you directly. http://packages.debian.org/sid/python3-setuptools Closer inspection reveals that it's actually a fork. There you go: http://pypi.python.org/pypi/distribute Cheers - Thomas From jason at powerpull.net Fri Jul 16 12:58:08 2010 From: jason at powerpull.net (Jason Friedman) Date: Fri, 16 Jul 2010 16:58:08 +0000 Subject: rstrip() Message-ID: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "x.vsd-dir".rstrip("-dir") 'x.vs' I expected 'x.vsd' as a return value. From usenot at geekmail.INVALID Fri Jul 16 12:59:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 16 Jul 2010 18:59:40 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: <20100716185940.23994a28@geekmail.INVALID> On Fri, 16 Jul 2010 17:26:05 +0200 Daniel Fetchinson wrote: > >>> I'm pleased to announce the release of inflect.py v0.1.8, a > >>> module that correctly generates: > >>> > >>> * the plural of singular nouns and verbs > >>> * the singular of plural nouns > >>> * ordinals > >>> * indefinite articles > >>> * present participles > >>> * and converts numbers to words > >> > >> Which languages does it support? If the answer is what I expect it > >> is, > > > > It is. Most of the time, when people forget to say what they are > > talking about, assuming that they are either US-Americans or > > Windows users will hit the nail on the head. > > And most of the time, when people are bitching about US-Americans, > assuming that they are Europeans will hit the nail on the head :) > I think Arabs may have shaken up that guess a bit, huh? OK, less snark, more Python. Sorry. ;) /W -- INVALID? DE! From pengyu.ut at gmail.com Fri Jul 16 13:01:11 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 12:01:11 -0500 Subject: Is '[' a function or an operator or an language feature? Message-ID: I mean to get the man page for '[' like in the following code. x=[1,2,3] But help('[') doesn't seem to give the above usage. ########### Mutable Sequence Types ********************** List objects support additional operations that allow in-place modification of the object. Other mutable sequence types (when added to the language) should also support these operations. Strings and tuples are immutable sequence types: such objects cannot be modified once created. The following operations are defined on mutable sequence types (where *x* is an arbitrary object): ... ########## I then checked help('LISTLITERALS'), which gives some description that is available from the language reference. So '[' in "x=[1,2,3]" is considered as a language feature rather than a function or an operator? ############ List displays ************* A list display is a possibly empty series of expressions enclosed in square brackets: list_display ::= "[" [expression_list | list_comprehension] "]" list_comprehension ::= expression list_for list_for ::= "for" target_list "in" old_expression_list [list_iter] old_expression_list ::= old_expression [("," old_expression)+ [","]] list_iter ::= list_for | list_if list_if ::= "if" old_expression [list_iter] ..... ########### -- Regards, Peng From john.hammink at gmail.com Fri Jul 16 13:06:23 2010 From: john.hammink at gmail.com (John Hammink) Date: Fri, 16 Jul 2010 10:06:23 -0700 (PDT) Subject: Python Imaging Library available for Python 3.1 ? Fractals References: Message-ID: <29ac0e3e-6a06-4f41-bdf7-15cb01d34444@r27g2000yqb.googlegroups.com> On Jun 6, 12:40?am, pdlemper@earthlink.net wrote: > On the site > ? ?http://code.activestate.com/recipes/langs/python/ > there are several scripts for fractals. ?See page five. > These begin > ? ? ? ? ? ? ? ? ? ? ? ? from PIL import Image > > This fails in my python 3.1.2 > > Google reveals PIL is Python Imaging Library from > pythonware.com > According to their website PIL is not available beyond 2.6 ?: ( > > Do I need a full GUI like tkinter to image a fractal ( on my > python 3.1.2 ) ?? ? ?Is there any simpler option ? > Thanks, ? ? ? ? ? ? ? Dave WB3DWE I'm a beginner pretty much, but I've just got Shai Vaingast's Newton- Raphson fractal working. I'm using python 2.6.5. from PIL import Image from cmath import * ... I don't need any windowing kit or anything. Maybe you can downgrade your python? or set up an older environment for it. From anand.shashwat at gmail.com Fri Jul 16 13:12:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 16 Jul 2010 22:42:46 +0530 Subject: rstrip() In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 10:28 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. > rstrip([chars]) The chars are stripped from right. Here it's ['-', 'd','i','r'] , hence these 4 characters will be stripped from right, so you are left with 'x.vs' -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 16 13:14:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 19:14:19 +0200 Subject: rstrip() In-Reply-To: References: Message-ID: <4C40936B.4000701@jollans.com> On 07/16/2010 06:58 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. >>> "x-vsd-dir".rstrip("-dir") 'x-vs' >>> "x-vsd-dir".rstrip("123id-r456") 'x-vs' >>> "x-vsd-dir".rstrip("-di") 'x-vsd-dir' >>> "fooabc".rstrip("bca") 'foo' >>> http://docs.python.org/py3k/library/stdtypes.html#str.rstrip :: """ The chars argument is not a suffix; rather, all combinations of its values are stripped: """ From soren.skou.nielsen at gmail.com Fri Jul 16 13:17:01 2010 From: soren.skou.nielsen at gmail.com (Soren) Date: Fri, 16 Jul 2010 10:17:01 -0700 (PDT) Subject: py2app with weave fails Message-ID: <4f6430e5-31ea-450d-a2b9-56442a7141fa@k19g2000yqc.googlegroups.com> Hi, I'm trying to create a standalone app using py2app, but it seems no matter what I do I get this error: Traceback (most recent call last): File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/__boot__.py", line 158, in _run('RAW.py') File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/__boot__.py", line 134, in _run execfile(path, globals(), globals()) File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/RAW.py", line 42, in from masking import CircleMask, RectangleMask, PolygonMask File "masking.pyc", line 34, in File "fileIO.pyc", line 29, in File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/__init__.py", line 13, in from inline_tools import inline File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/inline_tools.py", line 5, in import ext_tools File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/ext_tools.py", line 6, in import build_tools File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/build_tools.py", line 28, in import platform_info File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/platform_info.py", line 15, in from numpy.distutils.core import setup File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/numpy/distutils/core.py", line 25, in from numpy.distutils.command import config, config_compiler, \ File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/numpy/distutils/command/ build_ext.py", line 9, in from distutils.command.build_ext import build_ext as old_build_ext File "distutils/command/build_ext.pyc", line 13, in ImportError: cannot import name USER_BASE 2010-07-16 13:10:07.542 RAW[24832] RAW Error 2010-07-16 13:10:07.544 RAW[24832] RAW Error An unexpected error has occurred during execution of the main script Does anyone have an idea on how to fix this?? Thanks, Soren From kwatford+python at gmail.com Fri Jul 16 13:20:01 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Fri, 16 Jul 2010 13:20:01 -0400 Subject: rstrip() In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 12:58 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. > -- > http://mail.python.org/mailman/listinfo/python-list > rstrip strips a given set of characters, not a specific string. '-dir' contains d, so the trailing d is also stripped. From thomas at jollans.com Fri Jul 16 13:20:13 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 19:20:13 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4C401FC7.3010203@sequans.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> <4C401FC7.3010203@sequans.com> Message-ID: <4C4094CD.6040905@jollans.com> On 07/16/2010 11:00 AM, Jean-Michel Pichavant wrote: > Karsten Wutzke wrote: >>> Yes, typo, I meant strictly. >>> >>> >> >> Damn, I mean strongly. At least not for identifying which methods to >> call depending on the type/s. >> >> Karsten >> > Stringly is the perfect combination of strictly and strongly. Nice one :) stringly typed sounds like "everything is a string" - doesn't Tcl do that ? ^^ From python at mrabarnett.plus.com Fri Jul 16 13:27:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 18:27:28 +0100 Subject: rstrip() In-Reply-To: References: Message-ID: <4C409680.8000503@mrabarnett.plus.com> Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. .strip, .lstrip and .rstrip treat their argument like a set of characters and remove any of those characters from the end(s) of the string. In your example it's removing any "-", "d", "i" or "r" from the right-hand end of "x.vsd-dir", leaving "x.vs", like this: result = "x.vsd-dir" characters = "-dir" while result and result[-1] in characters: result = result[ : -1] From bartc at freeuk.com Fri Jul 16 13:30:38 2010 From: bartc at freeuk.com (bart.c) Date: Fri, 16 Jul 2010 18:30:38 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c4069de$0$11101$c3e8da3@news.astraweb.com> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c4069de$0$11101$c3e8da3 at news.astraweb.com... > On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > Not only that, but it only takes 73 digits to write out the total number > of particles in the entire universe: > > 1000000000000000000000000000000000000000000000000000000000000000000000000 > > or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all > the way up to 1e87.) > So for anything related to counting or labelling > actual, physical objects, you will be dealing with smaller numbers than > that. E.g. the number of grains of sand on the earth has been estimated > (very roughly) as a mere 1000000000000000000000000, or 25 digits. Big integers tend to be used for playing around with mathematical ideas, and they have to be exact. So if you wanted to hardcode 1000! for some reason, you'd need some 2568 digits which is a little awkward on one line. > It always makes me laugh when I receive an invoice from some company, and > the account number or invoice number is (e.g.) 1000000023456789. Who do > they think they're fooling? I used to do that. Giving someone an invoice number, or product serial number, 000001 doesn't exactly give the impression of a thriving business. -- Bartc From nagle at animats.com Fri Jul 16 13:40:27 2010 From: nagle at animats.com (John Nagle) Date: Fri, 16 Jul 2010 10:40:27 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <8a302tF2qdU1@mid.individual.net> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> <4c3b7102$0$1587$742ec2ed@news.sonic.net> <8a302tF2qdU1@mid.individual.net> Message-ID: <4c409999$0$1633$742ec2ed@news.sonic.net> On 7/13/2010 4:22 AM, Gregory Ewing wrote: > John Nagle wrote: >> Arguably, if a function just does a "return", >> it should be an error to try to use its return value. > > It's been suggested at least once before that the > default return value for a function should be some > special value that raises an exception if you try > to do anything with it except throw it away. Treating that case as an error would be consistent with the way attribute access works in Python. In Python, attempting to access a nonexistent attribute raises an exception. In Javascript, that returns a null. Javascript makes no distinction between "null" and "nonexistent", but Python does. It's un-Pythonic and inconsistent that functions which return nothing are considered to return a None object. John Nagle From robert.kern at gmail.com Fri Jul 16 13:41:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Jul 2010 12:41:48 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/10 12:01 PM, Peng Yu wrote: > I then checked help('LISTLITERALS'), which gives some description that > is available from the language reference. So '[' in "x=[1,2,3]" is > considered as a language feature rather than a function or an > operator? Yes. It is part of the list literal syntax of the Python language. -- 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 gregory.j.baker at gmail.com Fri Jul 16 13:55:14 2010 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Fri, 16 Jul 2010 10:55:14 -0700 (PDT) Subject: rstrip() References: Message-ID: <50ce9040-aecd-4030-b69e-5aab682c02af@x20g2000pro.googlegroups.com> On Jul 16, 10:58?am, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>> "x.vsd-dir".rstrip("-dir") > > 'x.vs' > > I expected 'x.vsd' as a return value. One way to achieve the desired result: 'x.vsd-dir'.split('-')[0] From robert.kern at gmail.com Fri Jul 16 14:28:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Jul 2010 13:28:49 -0500 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: On 7/16/10 12:30 PM, bart.c wrote: > > "Steven D'Aprano" wrote in message > news:4c4069de$0$11101$c3e8da3 at news.astraweb.com... >> On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > >> Not only that, but it only takes 73 digits to write out the total number >> of particles in the entire universe: >> >> 1000000000000000000000000000000000000000000000000000000000000000000000000 >> >> or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all >> the way up to 1e87.) >> So for anything related to counting or labelling >> actual, physical objects, you will be dealing with smaller numbers than >> that. E.g. the number of grains of sand on the earth has been estimated >> (very roughly) as a mere 1000000000000000000000000, or 25 digits. > > Big integers tend to be used for playing around with mathematical ideas, and > they have to be exact. So if you wanted to hardcode 1000! for some reason, you'd > need some 2568 digits which is a little awkward on one line. This happens too rarely to justify adding line-spanning integer literals to the language's syntax. -- 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 msandeep167 at gmail.com Fri Jul 16 14:59:56 2010 From: msandeep167 at gmail.com (ssssssssssssss) Date: Fri, 16 Jul 2010 11:59:56 -0700 (PDT) Subject: ( . ) ( . ) ( . ) ( . ) ( . ) Nude desi videos and pictures ( . ) ( . ) ( . ) ( . ) ( . ) ( . ) Message-ID: <883048a2-51d1-4965-b5b3-d9088f6a13fa@y12g2000prb.googlegroups.com> Click here for nude desi videos >>>>>>>>>>>>>>>>>>>>>>> http://ukpinkgirls.co.cc/ http://uk-worldwebhosting.co.cc/ From pengyu.ut at gmail.com Fri Jul 16 15:13:21 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 14:13:21 -0500 Subject: How to list all the python help topics that are capitalized? Message-ID: Hi, I see that there are help topics that are capitalized, which I think in general are related with languages syntax. I want to see the complete list of such help topics. Would you please let me know if there is a command to do so? >>> help('SUBSCRIPTS') Related help topics: SEQUENCEMETHODS1 >>> help('[') Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> help('LISTLITERALS') Related help topics: LISTS, LITERALS -- Regards, Peng From spheba at gmail.com Fri Jul 16 15:17:42 2010 From: spheba at gmail.com (hena) Date: Fri, 16 Jul 2010 12:17:42 -0700 (PDT) Subject: +++++++++ 18 + teen girls sex clips and pics +++++++++++ Message-ID: Click here to watch nude desi actress videos, Wallpapers, and more >>>>>>>>>>>>> http://ukpinkgirls.co.cc/ http://uk-worldwebhosting.co.cc/ From sunckell at gmail.com Fri Jul 16 15:20:16 2010 From: sunckell at gmail.com (Chad Kellerman) Date: Fri, 16 Jul 2010 15:20:16 -0400 Subject: pattern matching with multiple lists Message-ID: Greetings, ???? I have some code that I wrote and know there is a better way to write it.? I wonder if anyone could point me in the right direction on making this 'cleaner'. ???? I have two lists:?? liveHostList = [ app11, app12, web11, web12, host11 ] ??????????????????????????????????? stageHostList????? = [? web21, web22, host21, app21, app22 ] ???? I need to pair the elements in the list such that: ??? app11? pairs with app21 ??? app12 pairs with app22 ??? web11 pairs with web21 ??? web12 pairs with web22 ??? host11pairs with host21 ??? each time I get the list I don't know the order, and the lists will grow over time.? (hosts will be added in pairs.? app13 to liveHostList and app23 to stageHostList, etc) Anyways this is what I have.? I think it can be written better with map, but not sure.? Any help would be appreciated. import re for liveHost in liveHostlist: ??? nameList = list(liveHost) ??? clone??? = nameList[-1] ??? di?????? = nameList[-2] ??? generic? = liveHost[:-2] ??? for stageHost in stageHostList: ??? ??? if re.match( generic + '.' + clone, stageHost ): ??? ??? ??? print "Got a pair: " + stageHost + liveHost Thanks again for any suggestions, Chad -- A grasshopper walks into a bar and the bartender says "Hey, we have a drink named after you." And the grasshopper says "Really, You have a drink named Murray?" From thomas at jollans.com Fri Jul 16 15:44:04 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 21:44:04 +0200 Subject: Identify the Color of an Image In-Reply-To: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> References: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> Message-ID: <4C40B684.9020600@jollans.com> On 07/15/2010 09:13 AM, Monyl wrote: >> Please be clearer about what you want. >> >> 1. Animagedoes not "have" acolor, although each pixel in animage >> does have acolor. >> >> 2. Text in a web page does not (necessarily) have a font, although the >> display engine will use a font of its choice to render text. And my >> browser will probably use a different font than yours. > > Hi Gary Herron, > > 1.If I am going to click on a particular image. I will have click > using the co-ordinates of an Image. Can we find the color of the pixel > which lies in that particular co-ordinate where I click. You haven't even told us which platform you're talking about. This is a highly platform specific problem. > > 2.I just want to retrive the attributes of the text as it appears on > the browser. Can I get the font value depending on the browsers. If you want to know which font a browser is using to render something, you'll have to, essentially, ask the browser! I doubt this is something any browser would support, as it's hard to imagine *any* practical use case. Should be possible by extending firefox. (or any open source browser) > > Hope you understand my problem. Not really. From python at mrabarnett.plus.com Fri Jul 16 16:10:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:10:03 +0100 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: Message-ID: <4C40BC9B.2010500@mrabarnett.plus.com> Peng Yu wrote: > Hi, > > I see that there are help topics that are capitalized, which I think > in general are related with languages syntax. I want to see the > complete list of such help topics. Would you please let me know if > there is a command to do so? > >>>> help('SUBSCRIPTS') > > Related help topics: SEQUENCEMETHODS1 > >>>> help('[') > > Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS > >>>> help('LISTLITERALS') > > Related help topics: LISTS, LITERALS > Try: >>> help("topics") From pengyu.ut at gmail.com Fri Jul 16 16:21:53 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 15:21:53 -0500 Subject: How to list all the python help topics that are capitalized? In-Reply-To: <4C40BC9B.2010500@mrabarnett.plus.com> References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: > Peng Yu wrote: >> >> Hi, >> >> I see that there are help topics that are capitalized, which I think >> in general are related with languages syntax. I want to see the >> complete list of such help topics. Would you please let me know if >> there is a command to do so? >> >>>>> help('SUBSCRIPTS') >> >> Related help topics: SEQUENCEMETHODS1 >> >>>>> help('[') >> >> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >> >>>>> help('LISTLITERALS') >> >> Related help topics: LISTS, LITERALS >> > Try: > >>>> help("topics") Would you please let me know where this is documented? -- Regards, Peng From thomas at jollans.com Fri Jul 16 16:25:14 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 22:25:14 +0200 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: <4C40C02A.1080203@jollans.com> On 07/16/2010 10:21 PM, Peng Yu wrote: > On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: >> Peng Yu wrote: >>> >>> Hi, >>> >>> I see that there are help topics that are capitalized, which I think >>> in general are related with languages syntax. I want to see the >>> complete list of such help topics. Would you please let me know if >>> there is a command to do so? >>> >>>>>> help('SUBSCRIPTS') >>> >>> Related help topics: SEQUENCEMETHODS1 >>> >>>>>> help('[') >>> >>> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> >>>>>> help('LISTLITERALS') >>> >>> Related help topics: LISTS, LITERALS >>> >> Try: >> >>>>> help("topics") > > Would you please let me know where this is documented? > help('help') From rami.chowdhury at gmail.com Fri Jul 16 16:25:21 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 16 Jul 2010 13:25:21 -0700 Subject: Identify the Color of an Image In-Reply-To: <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> References: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> Message-ID: <201007161325.21534.rami.chowdhury@gmail.com> On Wednesday 14 July 2010 23:56:27 Monyl wrote: > > I will be using a automation tool called Sikuli and select the text or > an Image. It sounds to me like this is a question not about Python, but about Sikuli. I suggest you ask the question at https://answers.launchpad.net/sikuli or on their mailing list at https://lists.csail.mit.edu/mailman/listinfo/sikuli-users . > > My Requirement > --------------- > > I will capture the image manually and scriptify using Sikuli. To find > the captured image in the web page. Once it finds the image I need to > collect the information of the image like, > > Co-ordinates of the image, height and width, color and pixel rate of > the image. > > If I want to search a particular text in a webpage. I need to find the > font name, type, color and size of the text. > > Note :- We can open the web page in any browser. but I should be able > to capture the attributes of the image/Text displayed. ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From python at mrabarnett.plus.com Fri Jul 16 16:29:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:29:16 +0100 Subject: pattern matching with multiple lists In-Reply-To: References: Message-ID: <4C40C11C.4080802@mrabarnett.plus.com> Chad Kellerman wrote: > Greetings, > I have some code that I wrote and know there is a better way to > write it. I wonder if anyone could point me in the right direction > on making this 'cleaner'. > > I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ] > stageHostList = [ web21, > web22, host21, app21, app22 ] > > I need to pair the elements in the list such that: > app11 pairs with app21 > app12 pairs with app22 > web11 pairs with web21 > web12 pairs with web22 > host11pairs with host21 > > each time I get the list I don't know the order, and the lists > will grow over time. (hosts will be added in pairs. app13 to > liveHostList and app23 to stageHostList, etc) > > > Anyways this is what I have. I think it can be written better with > map, but not sure. Any help would be appreciated. > > import re > for liveHost in liveHostlist: > > nameList = list(liveHost) > clone = nameList[-1] > di = nameList[-2] > generic = liveHost[:-2] > > for stageHost in stageHostList: > if re.match( generic + '.' + clone, stageHost ): > print "Got a pair: " + stageHost + liveHost > > Thanks again for any suggestions, > Chad > So you recognise a pair by them having the same 'key', which is: name[ : -2] + name[-1 : ] Therefore you can put one of the lists into a dict and look up the name by its key: liveHostDict = dict((liveHost[ : -2] + liveHost[-1 : ], liveHost) for liveHost in liveHostList) for stageHost in stageHostList: key = stageHost[ : -2] + stageHost[-1 : ] liveHost = liveHostDict[key] print "Got a pair: %s %s" % (stageHost, liveHost) From python at mrabarnett.plus.com Fri Jul 16 16:33:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:33:30 +0100 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: <4C40C21A.30507@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: >> Peng Yu wrote: >>> Hi, >>> >>> I see that there are help topics that are capitalized, which I think >>> in general are related with languages syntax. I want to see the >>> complete list of such help topics. Would you please let me know if >>> there is a command to do so? >>> >>>>>> help('SUBSCRIPTS') >>> Related help topics: SEQUENCEMETHODS1 >>> >>>>>> help('[') >>> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> >>>>>> help('LISTLITERALS') >>> Related help topics: LISTS, LITERALS >>> >> Try: >> >>>>> help("topics") > > Would you please let me know where this is documented? > >>> help() From alf.p.steinbach+usenet at gmail.com Fri Jul 16 17:14:41 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 16 Jul 2010 23:14:41 +0200 Subject: Nested loop not working In-Reply-To: References: Message-ID: * Johann Spies, on 16.07.2010 16:34: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? For the inner loop, 'data' is an object that represents a file and keeps track of a current read position of the file. The first execution of the loop moves that read position all the way to the End Of the File, EOF. The second time this loop is attempted, which would be for the second keyword, the 'data' object's read position is already at end of file, and thus nothing's done. One way to just make it work is to open and close the data file within the outer loop. Actually with CPython it's automatically closed, as far as I can recall, so you only need to reopen it, but this (if true) is less than completely documented. This way is inefficient for small data set, but works. In order to get a better handle on the general problem -- not the Python technicalitities -- google up "KWIC", KeyWord In Context. It's a common exercise problem given to first or second-year students. So I think there should be an abundance of answers and discussion, although I haven't googled. Cheers & hth., - Alf -- blog at From python.list at tim.thechases.com Fri Jul 16 17:58:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 16 Jul 2010 16:58:18 -0500 Subject: pattern matching with multiple lists In-Reply-To: References: Message-ID: <4C40D5FA.1010403@tim.thechases.com> On 07/16/2010 02:20 PM, Chad Kellerman wrote: > Greetings, > I have some code that I wrote and know there is a better way to > write it. I wonder if anyone could point me in the right direction > on making this 'cleaner'. > > I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ] > stageHostList = [ web21, > web22, host21, app21, app22 ] > > I need to pair the elements in the list such that: > app11 pairs with app21 > app12 pairs with app22 > web11 pairs with web21 > web12 pairs with web22 > host11pairs with host21 While I like MRAB's solution even better than mine[1], you can also use: liveHostList = ["app11", "app12", "web11", "web12", "host11"] stageHostList = ["web21", "web22", "host21", "app21", "app22"] def bits(s): return (s[:-2],s[-1]) for live, stage in zip( sorted(liveHostList, key=bits), sorted(stageHostList, key=bits), ): print "Match: ", live, stage -tkc [1] His solution is O(N), making one pass through each list, with O(1) lookups into the created dict during the 2nd loop, while mine is likely overwhelmed by the cost of the sorts...usually O(N log N) for most reasonable sorts. However, this doesn't likely matter much until your list-sizes are fairly large. From tjreedy at udel.edu Fri Jul 16 18:42:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 18:42:31 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/2010 1:01 PM, Peng Yu wrote: > I mean to get the man page for '[' like in the following code. > > x=[1,2,3] You might find my Python symbol glossary useful. https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html From db3l.net at gmail.com Fri Jul 16 18:47:11 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 16 Jul 2010 18:47:11 -0400 Subject: About problems that I have with learning wxPython in Macintosh References: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Message-ID: "ata.jaf" writes: > import wx > > class MainWindow(wx.Frame) : > def __init__(self, parent, title) : > wx.Frame.__init__(self, parent, title=title, size=(200, 100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.CreateStatusBar() > > filemenu = wx.Menu() > > filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this > program.') > filemenu.AppendSeparator() > filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') > > menuBar = wx.MenuBar() > menuBar.Append(filemenu, '&File') > self.SetMenuBar(menuBar) > self.Show(True) > > app = wx.App(False) > frame = MainWindow(None, 'Sample editor') > app.MainLoop() > > The menus doesn't appear in the product. > Can anyone help me to find a tutorial that is for using wxPython on a > Mac? I think the menus are actually working as designed, and they are present, but just not perhaps what or where you expected. That's because some of the standard IDs (e.g., wx.ID_ABOUT) and some names (e.g., "E&xit") are adjusted under OSX to conform to that platform's menu standard. This is actually to your benefit, as you can use the same wxPython code to get menus on each platform to which users on that platform will be familiar. So for example, ID_ABOUT and ID_EXIT are always under the Application menu (and E&xit becomes &Quit) which is where Mac users expect them to be. Mac users would be quite confused if your application exited with Command-x rather than Command-Q. See http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X for a little more information. There are also a series of methods on wxApp if you want finer control over this (such as SetMacAboutMenuItemId, SetMacExitMenuItemId, SetMacPreferencesMenuItemId) but using the standard ID_* names does it automatically. If you're looking for your own specific menus, I'd just switch away from the standard ids and names. For example, if you switched the wx.ID_* in the above to -1, you'd see them show up under the File menu rather than relocated to the Application menu. Although "E&xit" would still get replaced with "&Quit". But if you are in fact setting up a menu for an application exit, I'd let wxPython do what it's doing, as your application will appear "normal" to users on the Mac. I'd also suggest moving over to the wxPython mailing list for followup questions as there are more folks there familiar with wxPython. -- David From python at bdurham.com Fri Jul 16 18:47:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 18:47:48 -0400 Subject: os.times values under Windows Message-ID: <1279320468.5600.1385279675@webmail.messagingengine.com> Python 2.6 under Windows: are the two non-zero values returned by this function of any practical use? The documentation [1] is vague and points to the Windows Platform API which I'm not sure maps 1:1 to the help description. In looking at the values returned on my system (Windows 7, 64-bit), I wonder if the documentation is correct because it looks like the values for user and system time might be reversed? >>> import os >>> os.times() (2465.0030011999997, 132.4292489, 0.0, 0.0, 0.0) >>> help(os.times) Help on built-in function times in module nt: times(...) times() -> (utime, stime, cutime, cstime, elapsed_time) Return a tuple of floating point numbers indicating process times. Thanks, Malcolm [1] http://docs.python.org/library/os.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jul 16 18:51:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 18:51:54 -0400 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: > On 7/16/10 12:30 PM, bart.c wrote: >> they have to be exact. So if you wanted to hardcode 1000! for some >> reason, you'd >> need some 2568 digits which is a little awkward on one line. No, only 20 digits >>> math.factorial(1000) 402387260077093773543702433923003985719374 ... Most big ints people want to work with can be encoded similarly. -- Terry Jan Reedy From candide at free.invalid Fri Jul 16 19:34:48 2010 From: candide at free.invalid (candide) Date: Sat, 17 Jul 2010 01:34:48 +0200 Subject: Subsets of Python implemented in Python Message-ID: <4c40ec99$0$8103$426a34cc@news.free.fr> I don't understand why some parts of the Python language (or the Python standard library too) are implemented in C while some other parts are implemented in the Python language itself. For instance, lists and dictionnaries are implemented in C but sets are not. Wouldn't be better to implement all in C (for efficiency reasons for example) ? From chardster at gmail.com Fri Jul 16 19:54:05 2010 From: chardster at gmail.com (Richard Thomas) Date: Fri, 16 Jul 2010 16:54:05 -0700 (PDT) Subject: Subsets of Python implemented in Python References: <4c40ec99$0$8103$426a34cc@news.free.fr> Message-ID: On Jul 17, 12:34?am, candide wrote: > I don't understand why some parts of the Python language (or the Python > standard library too) are implemented in C while some other parts are > implemented in the Python language itself. For instance, lists and > dictionnaries are implemented in C but sets are not. > > Wouldn't be better to implement all in C (for efficiency reasons for > example) ? CPython's sets are implemented in C. Old versions of Python implemented sets in the 'set' module which was written in Python but that has been deprecated and removed. A lot of the standard library is implemented in Python because it makes it more easily portable to non- CPython implementations. Chard. From hujia06 at gmail.com Fri Jul 16 20:52:23 2010 From: hujia06 at gmail.com (Jia Hu) Date: Fri, 16 Jul 2010 20:52:23 -0400 Subject: timing Message-ID: Hello: If I want to calculate the runtime of a section of a program. How can I do it? Thank you, Jia -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 20:57:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 00:57:54 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c410011$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 18:30:38 +0100, bart.c wrote: >> It always makes me laugh when I receive an invoice from some company, >> and the account number or invoice number is (e.g.) 1000000023456789. >> Who do they think they're fooling? > > I used to do that. Giving someone an invoice number, or product serial > number, 000001 doesn't exactly give the impression of a thriving > business. Sure, and there's nothing wrong with (say) 1000234 as your starting figure. I know people who put the year as the starting four digits: 201012345, say. But when you're a one-man company, is anyone going to think that you've genuinely put out 1000000000023456789 invoices to date? Even if you're a giant multinational corporation, such a number is just ridiculous, and it is user-hostile, especially when dealing with the robot interface to their help-desk or paying bills by phone. "Enter your invoice number followed by the hash-key." 1 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 2 *beep* 3 *beep* 4 *beep* 5 *beep* 6 *beep* ... 7 *beep* 8 * beep* 9 *beep* # *beep* "Sorry, that invoice number is incorrect. Please try again." -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 21:02:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 01:02:51 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c41013b$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 15:41:45 +0100, MRAB wrote: >> It always makes me laugh when I receive an invoice from some company, >> and the account number or invoice number is (e.g.) 1000000023456789. >> Who do they think they're fooling? >> > It's possible that they're splitting it into fields. Anything is possible. It's possible that they're encoding secret instructions to their army of sleeper agents in the invoice numbers too, but how likely is it? Good accounting practice is to treat invoice numbers as a simple unique numeric key. Every accounting software I've used has started the invoices at some value N, and returned N+1, N+2, N+3, ... with the starting value N user-configurable. But even if some software flies in the face of all accounting principles, good database design, and common sense, by overloading invoice numbers to include "fields" (of what?), what is the likelihood that my fields just happen to be virtually all zero? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 21:06:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 01:06:27 GMT Subject: Subsets of Python implemented in Python References: <4c40ec99$0$8103$426a34cc@news.free.fr> Message-ID: <4c410212$0$11101$c3e8da3@news.astraweb.com> On Sat, 17 Jul 2010 01:34:48 +0200, candide wrote: > I don't understand why some parts of the Python language (or the Python > standard library too) are implemented in C while some other parts are > implemented in the Python language itself. For instance, lists and > dictionnaries are implemented in C but sets are not. > > Wouldn't be better to implement all in C (for efficiency reasons for > example) ? Efficiency for who? The person writing the code? The CPU? There's currently a thread about the difficulty of finding volunteers willing *and able* to fix bugs in Python. If all of the Python code base was written in C, this would be a thousand times worse. There are many Python developers who can patch Python code, but not even read C code, let alone write it effectively. Most of the Python standard library is written in Python because (1) it's easier (2) it's fast enough (3) it allows experimentation and rapid prototyping E.g. the sets module was written in Python to start with, then replaced with a C built-in once it had proven itself. In other words, the Python standard library is written in Python for the exact same reasons that *any* software project might be written in Python. -- Steven From pengyu.ut at gmail.com Fri Jul 16 21:42:48 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 20:42:48 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: > On 7/16/2010 1:01 PM, Peng Yu wrote: >> >> I mean to get the man page for '[' like in the following code. >> >> x=[1,2,3] > > You might find my Python symbol glossary useful. > https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html This is for Python 3. Is there one for Python 2.x? -- Regards, Peng From clp2 at rebertia.com Fri Jul 16 21:58:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jul 2010 18:58:13 -0700 Subject: timing In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 5:52 PM, Jia Hu wrote: > Hello: > > If I want to calculate the runtime of a section of a program. How can I do > it? Taking you extremely literally: from time import time start = time() run_section_here() end = time() runtime = end-start Assuming you're doing this in order to optimize: http://docs.python.org/library/profile.html Or in particularly simple cases: http://docs.python.org/library/timeit.html Cheers, Chris -- http://blog.rebertia.com From hujia06 at gmail.com Fri Jul 16 22:05:14 2010 From: hujia06 at gmail.com (Jia Hu) Date: Fri, 16 Jul 2010 22:05:14 -0400 Subject: timing In-Reply-To: References: Message-ID: Thank you, it is so straightforward. On Fri, Jul 16, 2010 at 9:58 PM, Chris Rebert wrote: > On Fri, Jul 16, 2010 at 5:52 PM, Jia Hu wrote: > > Hello: > > > > If I want to calculate the runtime of a section of a program. How can I > do > > it? > > Taking you extremely literally: > from time import time > start = time() > run_section_here() > end = time() > runtime = end-start > > Assuming you're doing this in order to optimize: > http://docs.python.org/library/profile.html > Or in particularly simple cases: > http://docs.python.org/library/timeit.html > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Jul 16 22:08:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jul 2010 03:08:40 +0100 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: <4C4110A8.8040406@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >> On 7/16/2010 1:01 PM, Peng Yu wrote: >>> I mean to get the man page for '[' like in the following code. >>> >>> x=[1,2,3] >> You might find my Python symbol glossary useful. >> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html > > This is for Python 3. Is there one for Python 2.x? > Is anyone /still/ using Python 2.x? ;-) From python.list at tim.thechases.com Fri Jul 16 22:23:09 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 16 Jul 2010 21:23:09 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C4110A8.8040406@mrabarnett.plus.com> References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: <4C41140D.4010001@tim.thechases.com> On 07/16/2010 09:08 PM, MRAB wrote: > Peng Yu wrote: >>> You might find my Python symbol glossary useful. >>> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html >> >> This is for Python 3. Is there one for Python 2.x? >> > Is anyone /still/ using Python 2.x? ;-) 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, week-in week-out, for sixpence a week, and when we got home our Dad would thrash us to sleep wi' his belt... -tkc From pengyu.ut at gmail.com Fri Jul 16 22:36:25 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 21:36:25 -0500 Subject: Where is a module usually installed? Message-ID: My Python is installed in the following location. ~/utility/linux/opt/Python-2.6.5/ I then installed SCons (http://www.scons.org/) using the command "python setup.py install", which install it at ~/utility/linux/opt/Python-2.6.5/lib/scons-2.0.0.final.0 sys.path doesn't have the above directory. I have to add it to my PYTHONPATH. Would a python module usually be installed at the following location? ~/utility/linux/opt/Python-2.6.5/lib/python2.6 -- Regards, Peng From python at bdurham.com Fri Jul 16 22:59:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 22:59:11 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41140D.4010001@tim.thechases.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> Message-ID: <1279335551.5281.1385300137@webmail.messagingengine.com> Tim, > 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, week-in week-out, for sixpence a week, and when we got home our Dad would thrash us to sleep wi' his belt... Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter our code, in the dark, using loose binary toggle switches with poor connections. We used to have to get out of the lake at three o'clock in the morning, clean the lake, eat a handful of hot gravel, go to work at the mill every day for tuppence a month, come home, and Dad would beat us around the head and neck with a broken bottle, if we were LUCKY! Cheers, Malcolm [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm From tjreedy at udel.edu Fri Jul 16 23:12:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 23:12:20 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/2010 9:42 PM, Peng Yu wrote: > On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >> On 7/16/2010 1:01 PM, Peng Yu wrote: >>> >>> I mean to get the man page for '[' like in the following code. >>> >>> x=[1,2,3] >> >> You might find my Python symbol glossary useful. >> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html > > This is for Python 3. Is there one for Python 2.x? They are close to 100% the same. I intentionally worded the entries so one could look in the manuals for details. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Sat Jul 17 01:29:35 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 17 Jul 2010 01:29:35 -0400 Subject: [ANN] Struqtural: High level database interface library Message-ID: Struqtural makes it easy to get data into a database, and easy to work with it once it's there. Some of the big features include: * Automatically generate all tables and relations needed to represent XML in a database, including one to one, one to many, many to one and many to many relationships (JSON and YAML support is planned for a future release), returning mapped objects. * Automatically generate python objects for a specified table in a database, with support for discovery of all types of relationships (sort of like SQL Soup on 4 different kinds of steroids). * Automatically create persisted representations of python objects in a database, along with a persistent version of the object class. * Automatically infer SQL data types and create table representations for delimited text files (i.e. CSV/TSV), returning mapped objects. * Easily generate and query EAV/vertical attribute tables. * Easily generate and query graphs/trees/directed acyclic graphs. * Easily manage session configuration and creation for multiple databases. * Easily override almost all behavior with custom code or configuration variables * And much more... Once you're up and running, it's SQL Alchemy under the hood, with a few tune-ups that you are free to bypass if you don't like them. Home page:?http://www.turnkey-analytics.com/struqtural/ PyPI:?http://pypi.python.org/pypi/Struqtural Source:?https://code.launchpad.net/pydatastep Bugs:?https://bugs.launchpad.net/pydatastep To see Struqtural in action, take a look at the tutorial... ================================================= Struqtural has been designed to be as smart as possible. Because of that, most common use cases are retardedly simple. Let?s take a look, shall we? First, let?s just examine the most basic use case: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> data = [{"A":True, "B":1, "C":1.5, "D":"a"}, ... {"A":False, "B":2, "C":2.5, "D":"b"}, ... {"A":True, "B":3, "C":3.5, "D":"c"}, ... {"A":False, "B":4, "C":4.5, "D":"d"}] >>> example_structure = Structure(loader.CollectionLoader, data, "B", "SimpleInstance") >>> print "primary keys:", example_structure.primary_keys primary keys: ['B'] # Note that you could have also specified the primary key using an iterable >>> print "table name:", example_structure.table table name: SimpleInstances >>> print "table columns:", example_structure.columns table columns: ['SimpleInstances.A', 'SimpleInstances.C', 'SimpleInstances.B', 'SimpleInstances.D'] >>> for true_instance in example_structure.filter("B>2"): ... print true_instance SimpleInstance(A=True, C=3.5, B=3, D="c") SimpleInstance(A=False, C=4.5, B=4, D="d") >>> for small_true_instance in example_structure.query().filter("A", "C<3"): ... print small_true_instance SimpleInstance(A=True, C=1.5, B=1, D="a") Another nice feature is that Struqtural is pretty flexible about how you pass it data: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> more_data = [["T", "1", "1.0"], ... ["FALSE", "2", "2.0"], ... ["true", "3", "3.0"], ... ["False", "4", "4.0"]] # Note that more_data is strings, which isn't uncommon in the real world >>> data_headers = ["A", "B", "E"] >>> categories = Structure(loader.CollectionLoader, (data_headers, more_data), ["B", "E"], "Category") # Just a quick aside to demonstrate that Struqtural gets your table names right >>> print "table name:", categories.table table name: Categories >>> for category in categories: ... print category ... Category(A=True, B=1, E=1.0) Category(A=False, B=2, E=2.0) Category(A=True, B=3, E=3.0) Category(A=False, B=4, E=4.0) As you can see the strings have been handled elegantly. Type conversion is completely controllable and extensible. A small collection of useful type inference and conversion functions have been included. How about if we want to create a new structure out of multiple previously existing ones: >>> example_structure = Structure(loader.CollectionLoader, data, "B", "SimpleInstance") >>> connector = example_structure.connector >>> categories = Structure(loader.CollectionLoader, (data_headers, more_data), ["B", "E"], "Category", connector) >>> joint_structure = Structure(loader.JoinLoader, categories, example_structure) >>> for instance in joint_structure: ... print instance Category(A=True, B=1, E=1.0, C=1.5, D="a") Category(A=False, B=2, E=2.0, C=2.5, D="b") Category(A=True, B=3, E=3.0, C=3.5, D="c") Category(A=False, B=4, E=4.0, C=4.5, D="d") Note that we took advantage of some intelligence on the join we did there, since we have identically named, identically typed columns in the two tables. If you needed to be explicit about it you could just as easily have called structure like so (where the dictionary key is the column on the left table, in this case categories, and the value is the column on the joined table): >>> joined_with = (example_structure, {'A':'A', 'B':'B'}) >>> joint_structure = Structure(loader.JoinLoader, categories, joined_with) Next, let?s create persisted versions of pre-existing objects: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> class Mock(object): ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c >>> mocks = [Mock(1, 2, 3), Mock(4, 5, 6), Mock(7, 8, 9)] >>> another_example_structure = Structure(loader.ObjectLoader, mocks, "a") >>> for mock in another_example_structure.query(): ... print mock Mock(a=1, c=3, b=2) Mock(a=4, c=6, b=5) Mock(a=7, c=9, b=8) Pretty easy, right? Notice that you got a nice __repr__ for free there, too. Any type which can be converted to a known SQL primitive will be mapped automatically by default, though this is easily configurable. If a variable cannot be directly mapped, or more than one type occurs on for a given variable name, by default it will be pickled so that what comes off the database is identical to what went in, though this can also be easily disabled. Note This does not directly instrument pre-existing objects. It populates the database with the data of the objects. Any changes made to the original Mock objects in the above example will not be persisted. I suggest replacing the original objects with the new objects from the session immediately. Also, rather than modify the original class, a modified subclass is created, so it is advisable to save the modified class as well. This was a design decision, however it would be trivial to switch, so the behavior may change depending on user feedback. Now on to something a little bit more complicated... Struqtural can automatically generate a schema from XML. As a basic example, let?s use the following document: 123 10/29/00 007 Bond, Inc. 1 3 ABC 12.95 What happens when you give this document to Struqtural? Let?s take a look: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_1) >>> order_structure = multi.properties["Order"] >>> for order in order_structure.query(): ... print "Order number:", order.number ... print "Order date:", order.date ... print "Order customer count:", len(order.customers) ... for customer in order.customers: ... print "Order customer:", customer ... print "Order line count:", len(order.lines) ... for line in order.lines: ... print "Order line:", line ... print "Order line part count:", len(line.parts) ... for part in line.parts: ... print "Order line part:", part ... Order number: 123 Order date: 2000-10-29 Order customer count: 1 Order customer: Customer(order_id=1, custnum=7, name="Bond, Inc.", id=1) Order line count: 1 Order line: Line(order_id=1, linenum=1, id=1, quantity=3) Order line part count: 1 Order line part: Part(line_id=1, price=12.95, id=1, partnum="ABC") Ok, Struqtural automatically figured out all the relations and properties from the XML file, that?s pretty neat. Because we didn?t set any tag primary keys or provide a SchemaFormatter object with a primary key identification engine, an id key is automatically added. Since this behavior is typically not desirable, it is very easy to override. Note You will probably notice that our customer has an order_id... In this case, that customer appears only on the one Order, so that is not too odd. Had the customer appeared on multiple orders, the order would have had a customer_id. Even better, if multiple customers appeared on any order, a secondary table would be automatically created to handle the relationship, as we?ll demonstrate in a minute. So Struqtural can get data into a database easily, you say. What if my data is already in the database? What can you do for me? No problem, check it out: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_1) >>> order_structure = multi.properties["Order"] >>> connector = order_structure.connector # This isn't strictly needed, but gives us nice, informative names. # The key in names is the table name, the value is the name you would like to give # the instance you are creating to represent that table. >>> names = {"Customers":"Customer", "Lines":"Line", "Parts":"Part"} >>> multi = MultiStructure(loader.DatabaseMultiLoader, "Orders", connector, names) >>> order_structure = multi.properties["Orders"] >>> for order in order_structure.query(): ... print "Order number:", order.number ... print "Order date:", order.date ... print "Order customer count:", len(order.customers) ... for customer in order.customers: ... print "Order customer:", customer ... print "Order line count:", len(order.lines) ... for line in order.lines: ... print "Order line:", line ... print "Order line part count:", len(line.parts) ... for part in line.parts: ... print "Order line part:", part Order number: 123 Order date: 2000-10-29 Order customer count: 1 Order customer: Customer(order_id=1, custnum=7, name="Bond, Inc.", id=1) Order line count: 1 Order line: Line(order_id=1, linenum=1, id=1, quantity=3) Order line part count: 1 Order line part: Part(line_id=1, price=12.95, partnum="ABC", id=1) You just got the ?Orders? table and everything connected with it (including stuff that points to it as well as stuff it points to) loaded and mapped, and it took almost no work! You?re free to do interesting stuff! Pretty awesome, huh? Let?s push things to the edge now with a quick demo of many to many relationship support. For this example we?re going to be using the following XML: 123 Sales 143 Raul Lopez 687 John Smith 947 Ming Chu 456 Marketing 157 Jim Jones 687 John Smith 947 Ming Chu Note that we?re also going to be passing tag primary keys here, so that things work properly: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> primary_keys = {"Department":"DeptNum", "Employee":"Number"} >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_2, ... primary_keys=primary_keys) >>> department_structure = multi.properties["Department"] >>> for department in department_structure.query(): ... print "Department number:", department.deptnum ... print "Employee count:", len(department.employees) ... for employee in department.employees: ... print "Employee name:", employee.name ... print "Employee number:", employee.number ... Department number: 123 Employee count: 3 Employee name: Raul Lopez Employee number: 143 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 Department number: 456 Employee count: 3 Employee name: Jim Jones Employee number: 157 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 If you already have a database with many to many relationships, that is no problem. As long as the secondary tables for the relationship don?t contain any non-foreign key columns or foreign keys for more than two tables, you?re in good shape. For example: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> primary_keys = {"Department":"DeptNum", "Employee":"Number"} >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_2, ... primary_keys=primary_keys) >>> department_structure = multi.properties["Department"] >>> connector = department_structure.connector >>> names = {"Departments":"Department", "Employees":"Employee"} >>> multi = MultiStructure(loader.DatabaseMultiLoader, "Departments", connector, ... names, backref_by_default=True) >>> departments = multi.properties["Departments"] >>> for department in department_structure.query(): ... print "Department number:", department.deptnum ... print "Employee count:", len(department.employees) ... for employee in department.employees: ... print "Employee name:", employee.name ... print "Employee number:", employee.number ... Department number: 123 Employee count: 3 Employee name: Raul Lopez Employee number: 143 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 Department number: 456 Employee count: 3 Employee name: Jim Jones Employee number: 157 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 You will note that in all these examples we used a memory resident SQLite database. If you want to use a real database, you will need to pass a connector to your structure. You create one like so: >>> from struqtural.database import DatabaseConnector >>> connector = DatabaseConnector("my_database_config.cfg") That?s it! In fact, Struqtural will even automatically look in a few logical places for your configuration information, so you can set it up once and you?ll never have to pass it the location of a configuration file again. Just to give you an example of the format for the configuration file (this is included in the resources subdirectory): [current engine] engine= [parameter values] user= pass= host= db= [parameter lists] mysql=mysql://{user}:{pass}@{host}/{db} postgresql=postgresql://{user}:{pass}@{host}/{db} Note The configuration file shown here does not include driver, port or other information that you would probably want to be able to specify in a real case. Those parameters are supported, so if you modify the configuration to include them, the struqtural.database.connector.Databaseconnector will work as expected. From breamoreboy at yahoo.co.uk Sat Jul 17 04:01:40 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 Jul 2010 09:01:40 +0100 Subject: Where is a module usually installed? In-Reply-To: References: Message-ID: On 17/07/2010 03:36, Peng Yu wrote: > My Python is installed in the following location. > ~/utility/linux/opt/Python-2.6.5/ > > I then installed SCons (http://www.scons.org/) using the command > "python setup.py install", which install it at > ~/utility/linux/opt/Python-2.6.5/lib/scons-2.0.0.final.0 > > sys.path doesn't have the above directory. I have to add it to my PYTHONPATH. > > Would a python module usually be installed at the following location? > ~/utility/linux/opt/Python-2.6.5/lib/python2.6 > See the following for an explanation. http://docs.python.org/release/2.6.5/library/site.html#module-site HTH. Mark Lawrence From steve at REMOVE-THIS-cybersource.com.au Sat Jul 17 04:03:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 08:03:27 GMT Subject: Is '[' a function or an operator or an language feature? References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: >> Is anyone /still/ using Python 2.x? ;-) > > 2.x?! You were lucky. We lived for three months with Python 1.x in a > septic tank. We used to have to get up at six in the morning, write our > 1.x code using ed, You got to use ed? Oh, we *dreamed* of using an editor! We had to edit the sectors on disk directly with a magnetised needle. A rusty, blunt needle. -- Steven From debatem1 at gmail.com Sat Jul 17 04:17:58 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 01:17:58 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 17, 2010 at 1:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > >>> Is anyone /still/ using Python 2.x? ;-) >> >> 2.x?! ?You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, > > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. Real programmers use butterflies. http://xkcd.com/378/ Geremy Condra From breamoreboy at yahoo.co.uk Sat Jul 17 04:57:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 Jul 2010 09:57:15 +0100 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <1279335551.5281.1385300137@webmail.messagingengine.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> <1279335551.5281.1385300137@webmail.messagingengine.com> Message-ID: On 17/07/2010 03:59, python at bdurham.com wrote: > Tim, > >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > Cheers, > Malcolm > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm I'm just envisaging a "Paper Tape Repairman" sketch. Kindest regards. Mark Lawrence. From alf.p.steinbach+usenet at gmail.com Sat Jul 17 05:50:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 17 Jul 2010 11:50:48 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) Message-ID: [Cross-posted comp.lang.c++ and comp.lang.python] Consider the following code, from an example usage of some C++ support for Python I'm working on, "cppy": struct Noddy { PyPtr first; PyPtr last; int number; Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) : number( 0 ) { // ... some initialization here } PyPtr name() { return (PyString( first ) + L" " + PyString( last )).pyPtr(); } }; struct NoddyPyClass: PyClass< Noddy > { typedef PyClass< Noddy > Base; NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) : Base( m, name, doc, Exposition() .method( L"name", CPPY_METHOD_FORWARDER( name ), L"Return the name, combining the first and last name" ) .attribute( L"first", CPPY_GETSET_FORWARDERS( first ), L"first name" ) .attribute( L"last", CPPY_GETSET_FORWARDERS( last ), L"last name" ) .attribute( L"number", CPPY_GETSET_FORWARDERS( number ), L"noddy number" ) ) {} }; Originally e.g. CPPY_GETSET_FORWARDERS( number ), had to be written as CPPY_GETSET_FORWARDERS( int, number ), because in order to use a compile time member pointer as template actual argument, one needs to supply the member type as a separate template argument. E.g. the template might look like template< class Class, class MemberType, MemberType Class::*pMember > struct ForwardersForGetAndSet { // Some definitions here, hardwiring that compile time member pointer! }; Apparently there was no way around the user repeating explicitly the member type that the compiler already knew about... It seemed akin to deducing the return type of a function. Difficult in C++98 (although Boost does a fair job). But then it seemed that I'm not totally senile yet, for this occurred to me: #define CPPY_GETSET_FORWARDERS( name ) \ ::progrock::cppy::forwardersGetSet( \ &CppClass::name \ ).themForwarders< &CppClass::name >() Here forwardersGetSet is a templated function that via argument type deduction produces an instance of a templated struct, thereby "knowing" the member type, which struct in turn has a member function templated on the member pointer, which the macro supplies *twice*, once as run-time arg and once as compile-time. He he. Perhaps this trick is well-known already, but it was new to me, so! :-) Cheers, - Alf -- blog at From nospam at nospam.com Sat Jul 17 05:56:18 2010 From: nospam at nospam.com (Gilles Ganault) Date: Sat, 17 Jul 2010 11:56:18 +0200 Subject: Only one forum app in Python? References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Sat, 10 Jul 2010 18:37:00 +0200, Bruno Desthuilliers wrote: >There are almost a dozen of Python "forum apps" for Django alone, and >Python is known as "the language with more web frameworks than keywords". So this list at Wikipedia is out-of-date/wrong, and there are more options through web frameworks. Thanks guys. From thomas at jollans.com Sat Jul 17 06:39:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 12:39:05 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C418849.7060409@jollans.com> On 07/17/2010 10:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > >>> Is anyone /still/ using Python 2.x? ;-) >> >> 2.x?! You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, > > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. > You try and tell the young people of today that, and they won't believe you. From as at sci.fi Sat Jul 17 08:27:40 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 17 Jul 2010 15:27:40 +0300 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: David Robinow writes: > Really, if you can't be bothered to set your key bindings to something > you prefer, then I don't think Emacs is the right tool for you. Uh, I absolutely think Emacs is the right tool for me, but I don't think I've never changed any key bindings in the 20 years I've used it. Considering the number of functions and existing key bindings, the whole idea makes me think it would be like a game of musical chairs, always some function would be left without a key binding? From tlikonen at iki.fi Sat Jul 17 08:57:01 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Sat, 17 Jul 2010 15:57:01 +0300 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: <87oce66zc2.fsf@mithlond.arda> * 2010-07-16 06:29 (-0700), ernest wrote: > I tried the outline-mode and it seemed to work. It can collapse > different blocks of code, such as functions, classes, etc. > > However, I never got used to it because of the bizarre key bindings. I use outline-minor-mode and the code below to make key bindings fast and easy. Alt + up/down arrow will go to previous/next heading or code block. Alt + left/right will close or open one sublevel. And that's about it. My code is slightly modified version of the code from http://www.emacswiki.org/emacs/OutlineMinorMode Note that on that page there is also a tip to use Vim-like manual fold markers (like the Vim's default "{{{"). ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; outline-mode-easy-bindings.el ;; ;; Installation: Store this file as outline-mode-easy-bindings.el ;; somewhere in your load-path and create hooks for outline modes to ;; load this automatically, for example: ;; (add-hook 'outline-mode-hook 'my-outline-easy-bindings) ;; (add-hook 'outline-minor-mode-hook 'my-outline-easy-bindings) ;; ;; (defun my-outline-easy-bindings () ;; (require 'outline-mode-easy-bindings nil t)) (defun outline-body-p () (save-excursion (outline-back-to-heading) (outline-end-of-heading) (and (not (eobp)) (progn (forward-char 1) (not (outline-on-heading-p)))))) (defun outline-body-visible-p () (save-excursion (outline-back-to-heading) (outline-end-of-heading) (not (outline-invisible-p)))) (defun outline-subheadings-p () (save-excursion (outline-back-to-heading) (let ((level (funcall outline-level))) (outline-next-heading) (and (not (eobp)) (< level (funcall outline-level)))))) (defun outline-subheadings-visible-p () (interactive) (save-excursion (outline-next-heading) (not (outline-invisible-p)))) (defun outline-hide-more () (interactive) (when (outline-on-heading-p) (cond ((and (outline-body-p) (outline-body-visible-p)) (hide-entry) (hide-leaves)) (t (hide-subtree))))) (defun outline-show-more () (interactive) (when (outline-on-heading-p) (cond ((and (outline-subheadings-p) (not (outline-subheadings-visible-p))) (show-children)) ((and (not (outline-subheadings-p)) (not (outline-body-visible-p))) (show-subtree)) ((and (outline-body-p) (not (outline-body-visible-p))) (show-entry)) (t (show-subtree))))) (let ((major outline-mode-map) (minor outline-minor-mode-map)) (define-key major (kbd "M-") 'outline-hide-more) (define-key major (kbd "M-") 'outline-show-more) (define-key major (kbd "M-") 'outline-previous-visible-heading) (define-key major (kbd "M-") 'outline-next-visible-heading) (define-key major (kbd "C-c J") 'outline-hide-more) (define-key major (kbd "C-c L") 'outline-show-more) (define-key major (kbd "C-c I") 'outline-previous-visible-heading) (define-key major (kbd "C-c K") 'outline-next-visible-heading) (define-key minor (kbd "M-") 'outline-hide-more) (define-key minor (kbd "M-") 'outline-show-more) (define-key minor (kbd "M-") 'outline-previous-visible-heading) (define-key minor (kbd "M-") 'outline-next-visible-heading) (define-key minor (kbd "C-c J") 'outline-hide-more) (define-key minor (kbd "C-c L") 'outline-show-more) (define-key minor (kbd "C-c I") 'outline-previous-visible-heading) (define-key minor (kbd "C-c K") 'outline-next-visible-heading)) (provide 'outline-mode-easy-bindings) From alf.p.steinbach+usenet at gmail.com Sat Jul 17 09:02:58 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 17 Jul 2010 15:02:58 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: * Alf P. Steinbach /Usenet, on 17.07.2010 11:50: > [Cross-posted comp.lang.c++ and comp.lang.python] > > [snip] > this occurred to me: > > #define CPPY_GETSET_FORWARDERS( name ) \ > ::progrock::cppy::forwardersGetSet( \ > &CppClass::name \ > ).themForwarders< &CppClass::name >() > > Here forwardersGetSet is a templated function that via argument type > deduction produces an instance of a templated struct, thereby "knowing" > the member type, which struct in turn has a member function templated on > the member pointer, which the macro supplies *twice*, once as run-time > arg and once as compile-time. That trick allowed uniform treatment of data and function member pointers. :-) So, with cppy the complete noddy2 example from the docs (I'm sort of working my way through the Python doc examples) now looks as shown below. The "typelessness" of the 'first' and 'last' members is in order to recreate as close as possible the noddy2 functionality, or, lack of it. Also, I haven't got around to sort of backporting the 'Exposition' scheme to modules. So, exposure of module functionality looks a little different from same for types, for now. // The Python 3.1.1 docs' Noddy 2 example rewritten using cppy. // Docs: "Extending and Embedding the Python Interpreter" ?2.1.1 #include // PyWeakPtr, PyPtr, PyModule, PyClass using namespace progrock; namespace { using namespace cppy; struct Noddy { PyPtr first; PyPtr last; int number; Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) : number( 0 ) { devsupport::suppressUnusedWarning( pySelf ); PyWeakPtr pFirstName = 0; PyWeakPtr pLastName = 0; static char* kwlist[] = { "first", "last", "number", 0 }; ::PyArg_ParseTupleAndKeywords( args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, pointerTo( pFirstName ), pointerTo( pLastName ), &number ) >> Accept< IsNonZero >() || throwX( "Invalid args" ); if( pFirstName != 0 ) { first = pFirstName; } if( pLastName != 0 ) { last = pLastName; } } PyPtr name() { (first != 0) || throwX( ::PyExc_AttributeError, "first" ); (last != 0) || throwX( ::PyExc_AttributeError, "last" ); return (PyString( first ) + L" " + PyString( last )).pyPtr(); } }; struct NoddyPyClass: PyClass< Noddy > { NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) : PyClass< Noddy >( m, name, doc, Exposition() .method( L"name", CPPY_GLUE( name ), L"Return the name, combining the first and last name" ) .attribute( L"first", CPPY_GLUE( first ), L"first name" ) .attribute( L"last", CPPY_GLUE( last ), L"last name" ) .attribute( L"number", CPPY_GLUE( number ), L"noddy number" ) ) {} }; class NoddyModule: public PyModule { private: NoddyPyClass noddyPyClass_; public: NoddyModule() : PyModule( L"noddy2", L"Example module that creates an extension type." ) , noddyPyClass_( *this, L"Noddy", L"A Noddy object has a name and a noddy number" ) {} }; } // namespace PyMODINIT_FUNC PyInit_noddy2() { return cppy::safeInit< NoddyModule >(); } I wonder if this is readable / self-documenting, or not? Cheers, - Alf -- blog at From sturlamolden at yahoo.no Sat Jul 17 09:25:12 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 17 Jul 2010 06:25:12 -0700 (PDT) Subject: Struqtural: High level database interface library References: Message-ID: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> On 17 Jul, 07:29, Nathan Rice wrote: > Let?s push things to the edge now with a quick demo of many to many > relationship support. For this example we?re going to be using the > following XML: > > > ? ? > ? ? ? ? 123 > ? ? ? ? Sales > ? ? ? ? > ? ? ? ? ? ? 143 > ? ? ? ? ? ? Raul Lopez > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 687 > ? ? ? ? ? ? John Smith > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 947 > ? ? ? ? ? ? Ming Chu > ? ? ? ? > ? ? > ? ? > ? ? ? ? 456 > ? ? ? ? Marketing > ? ? ? ? > ? ? ? ? ? ? 157 > ? ? ? ? ? ? Jim Jones > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 687 > ? ? ? ? ? ? John Smith > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 947 > ? ? ? ? ? ? Ming Chu > ? ? ? ? > ? ? > Oh yes, I'd rather write pages of that rather than some SQL in a Python string. From ptmcg at austin.rr.com Sat Jul 17 09:57:06 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 17 Jul 2010 06:57:06 -0700 (PDT) Subject: Is '[' a function or an operator or an language feature? References: Message-ID: <42f45ff6-db51-474d-aa0b-0860a3333907@y4g2000yqy.googlegroups.com> On Jul 16, 12:01?pm, Peng Yu wrote: > I mean to get the man page for '[' like in the following code. > > x=[1,2,3] > > But help('[') doesn't seem to give the above usage. > > ########### > Mutable Sequence Types > ********************** > > List objects support additional operations that allow in-place > modification of the object. Other mutable sequence types (when added > to the language) should also support these operations. Strings and > tuples are immutable sequence types: such objects cannot be modified > once created. The following operations are defined on mutable sequence > types (where *x* is an arbitrary object): > ... > ########## > > I then checked help('LISTLITERALS'), which gives some description that > is available from the language reference. So '[' in "x=[1,2,3]" is > considered as a language feature rather than a function or an > operator? > > ############ > List displays > ************* > > A list display is a possibly empty series of expressions enclosed in > square brackets: > > ? ?list_display ? ? ? ?::= "[" [expression_list | list_comprehension] "]" > ? ?list_comprehension ?::= expression list_for > ? ?list_for ? ? ? ? ? ?::= "for" target_list "in" old_expression_list > [list_iter] > ? ?old_expression_list ::= old_expression [("," old_expression)+ [","]] > ? ?list_iter ? ? ? ? ? ::= list_for | list_if > ? ?list_if ? ? ? ? ? ? ::= "if" old_expression [list_iter] > ..... > ########### > -- > Regards, > Peng Also look for __getitem__ and __setitem__, these methods defined on your own container classes will allow you to write "myobject['x']" and have your own custom lookup code get run. -- Paul From sturlamolden at yahoo.no Sat Jul 17 10:19:46 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 17 Jul 2010 07:19:46 -0700 (PDT) Subject: Sharing: member type deduction for member pointers (Alf's device?) References: Message-ID: On 17 Jul, 15:02, "Alf P. Steinbach /Usenet" wrote: > #include ? ? ?// PyWeakPtr, PyPtr, PyModule, PyClass > using namespace progrock; > > namespace { > ? ? ?using namespace cppy; > > ? ? ?struct Noddy > ? ? ?{ > ? ? ? ? ?PyPtr ? ? ? first; > ? ? ? ? ?PyPtr ? ? ? last; > ? ? ? ? ?int ? ? ? ? number; > > ? ? ? ? ?Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) > ? ? ? ? ? ? ?: number( 0 ) > ? ? ? ? ?{ > ? ? ? ? ? ? ?devsupport::suppressUnusedWarning( pySelf ); > > ? ? ? ? ? ? ?PyWeakPtr ? pFirstName ?= 0; > ? ? ? ? ? ? ?PyWeakPtr ? pLastName ? = 0; > > ? ? ? ? ? ? ?static char* ? ?kwlist[] = { "first", "last", "number", 0 }; > > ? ? ? ? ? ? ?::PyArg_ParseTupleAndKeywords( > ? ? ? ? ? ? ? ? ?args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, > ? ? ? ? ? ? ? ? ?pointerTo( pFirstName ), pointerTo( pLastName ), &number > ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?>> Accept< IsNonZero >() > ? ? ? ? ? ? ? ? ?|| throwX( "Invalid args" ); > > ? ? ? ? ? ? ?if( pFirstName != 0 ) ? { first = pFirstName; } > ? ? ? ? ? ? ?if( pLastName != 0 ) ? ?{ last = pLastName; } > ? ? ? ? ?} > > ? ? ? ? ?PyPtr name() > ? ? ? ? ?{ > ? ? ? ? ? ? ?(first != 0) > ? ? ? ? ? ? ? ? ?|| throwX( ::PyExc_AttributeError, "first" ); > ? ? ? ? ? ? ?(last != 0) > ? ? ? ? ? ? ? ? ?|| throwX( ::PyExc_AttributeError, "last" ); > ? ? ? ? ? ? ?return (PyString( first ) + L" " + PyString( last )).pyPtr(); > ? ? ? ? ?} > ? ? ?}; > > ? ? ?struct NoddyPyClass: PyClass< Noddy > > ? ? ?{ > ? ? ? ? ?NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) > ? ? ? ? ? ? ?: PyClass< Noddy >( m, name, doc, Exposition() > ? ? ? ? ? ? ? ? ?.method( > ? ? ? ? ? ? ? ? ? ? ?L"name", ? ?CPPY_GLUE( name ), > ? ? ? ? ? ? ? ? ? ? ?L"Return the name, combining the first and last name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"first", ? CPPY_GLUE( first ), ? ? L"first name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"last", ? ?CPPY_GLUE( last ), ? ? ?L"last name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"number", ?CPPY_GLUE( number ), ? ?L"noddy number" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?) > ? ? ? ? ?{} > ? ? ?}; > > ? ? ?class NoddyModule: public PyModule > ? ? ?{ > ? ? ?private: > ? ? ? ? ?NoddyPyClass ? ?noddyPyClass_; > > ? ? ?public: > ? ? ? ? ?NoddyModule() > ? ? ? ? ? ? ?: PyModule( > ? ? ? ? ? ? ? ? ?L"noddy2", L"Example module that creates an extension type." ) > ? ? ? ? ? ? ?, noddyPyClass_( *this, > ? ? ? ? ? ? ? ? ?L"Noddy", L"A Noddy object has a name and a noddy number" ) > ? ? ? ? ?{} > ? ? ?}; > > } ? ?// namespace > > PyMODINIT_FUNC > PyInit_noddy2() > { > ? ? ?return cppy::safeInit< NoddyModule >();} > I wonder if this is readable / self-documenting, or not? Are you serious? It's C++, Heaven forbid, and you wonder if it's readable or not? From rajgopal.srinivasan at gmail.com Sat Jul 17 12:21:00 2010 From: rajgopal.srinivasan at gmail.com (raj) Date: Sat, 17 Jul 2010 09:21:00 -0700 (PDT) Subject: Python 3.1.2 and marshal Message-ID: Hi, I am using 64 bit Python on an x86_64 platform (Fedora 13). I have some code that uses the python marshal module to serialize some objects to files. However, in moving the code to python 3 I have come across a situation where, if more than one object has been serialized to a file, then while trying to de-serialize only the first object is de-serialized. Trying to de-serialize the second object raises an EOFError. De-serialization of multiple objects works fine in Python 2.x. I tried going through the Python 3 documentation to see if marshal functionality has been changed, but haven't found anything to that effect. Does anyone else see this problem? Here is some example code: bash-4.1$ cat marshaltest.py import marshal numlines = 1 numwords = 25 stream = open('fails.mar','wb') marshal.dump(numlines, stream) marshal.dump(numwords, stream) stream.close() tmpstream = open('fails.mar', 'rb') value1 = marshal.load(tmpstream) value2 = marshal.load(tmpstream) print(value1 == numlines) print(value2 == numwords) Here are the results of running this code bash-4.1$ python2.7 marshaltest.py True True bash-4.1$ python3.1 marshaltest.py Traceback (most recent call last): File "marshaltest.py", line 13, in value2 = marshal.load(tmpstream) EOFError: EOF read where object expected Interestingly the file created by using Python 3.1 is readable by both Python 2.7 as well as Python 2.6 and both objects are successfully read. Cheers, raj From news1234 at free.fr Sat Jul 17 12:27:15 2010 From: news1234 at free.fr (News123) Date: Sat, 17 Jul 2010 18:27:15 +0200 Subject: rstrip() In-Reply-To: References: Message-ID: <4c41d9e3$0$25709$426a74cc@news.free.fr> Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. This is kind of similiar to the question, that I posted recently. "nicer way to remove prefix of a string if it exists" if you want to remove '-dir' at the end of the string if it exists and leave the string as it is if it is not followed by '-dir', then you could do: def rmv_suffix(suffix,txt): if txt.endswith(suffix): return txt[:-len(suffix)] return txt >>> rmv_suffix('-dir','abcd') 'abcd' >>> rmv_suffix('-dir','abcd-dir') 'abcd' >>> rmv_suffix('-dir','abcd-dir-and then more') 'abcd-dir-and then more' >>> the other solution would involve regular expressions: import re >>> re.sub('-dir$','','abcd') 'abcd' >>> re.sub('-dir$','','abcd-dir') 'abcd' >>> re.sub('-dir$','','abcd-dirand more') 'abcd-dirand more' >>> From gherron at islandtraining.com Sat Jul 17 12:38:49 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 17 Jul 2010 09:38:49 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C41DC99.90406@islandtraining.com> On 07/17/2010 01:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > > >>> Is anyone /still/ using Python 2.x? ;-) >>> >> 2.x?! You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, >> > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. > Along those lines, there's this -- one of my favorite comics: http://xkcd.com/378/ and unrelated to the thread but still about python: http://xkcd.com/353/ Gary Herron From thomas at jollans.com Sat Jul 17 13:11:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 19:11:33 +0200 Subject: Python 3.1.2 and marshal In-Reply-To: References: Message-ID: <4C41E445.5070002@jollans.com> On 07/17/2010 06:21 PM, raj wrote: > Hi, > > I am using 64 bit Python on an x86_64 platform (Fedora 13). I have > some code that uses the python marshal module to serialize some > objects to files. However, in moving the code to python 3 I have come > across a situation where, if more than one object has been serialized > to a file, then while trying to de-serialize only the first object is > de-serialized. Trying to de-serialize the second object raises an > EOFError. De-serialization of multiple objects works fine in Python > 2.x. I tried going through the Python 3 documentation to see if > marshal functionality has been changed, but haven't found anything to > that effect. Does anyone else see this problem? Here is some > example code: Interesting. I modified your script a bit: 0:pts/2:/tmp% cat marshtest.py from __future__ import print_function import marshal import sys if sys.version_info[0] == 3: bytehex = lambda i: '%02X ' % i else: bytehex = lambda c: '%02X ' % ord(c) numlines = 1 numwords = 25 stream = open('fails.mar','wb') marshal.dump(numlines, stream) marshal.dump(numwords, stream) stream.close() tmpstream = open('fails.mar', 'rb') for byte in tmpstream.read(): sys.stdout.write(bytehex(byte)) sys.stdout.write('\n') tmpstream.seek(0) print('pos:', tmpstream.tell()) value1 = marshal.load(tmpstream) print('val:', value1) print('pos:', tmpstream.tell()) value2 = marshal.load(tmpstream) print('val:', value2) print('pos:', tmpstream.tell()) print(value1 == numlines) print(value2 == numwords) 0:pts/2:/tmp% python2.6 marshtest.py 69 01 00 00 00 69 19 00 00 00 pos: 0 val: 1 pos: 5 val: 25 pos: 10 True True 0:pts/2:/tmp% python3.1 marshtest.py 69 01 00 00 00 69 19 00 00 00 pos: 0 val: 1 pos: 10 Traceback (most recent call last): File "marshtest.py", line 29, in value2 = marshal.load(tmpstream) EOFError: EOF read where object expected 1:pts/2:/tmp% So, the contents of the file is identical, but Python 3 reads the whole file, Python 2 reads only the data it uses. This looks like a simple optimisation: read the whole file at once, instead of byte-by-byte, to improve performance when reading large objects. (such as Python modules...) The question is: was storing multiple objects in sequence an intended use of the marshal module? I doubt it. You can always wrap your data in tuples or use pickle. > > bash-4.1$ cat marshaltest.py > import marshal > > numlines = 1 > numwords = 25 > > stream = open('fails.mar','wb') > marshal.dump(numlines, stream) > marshal.dump(numwords, stream) > stream.close() > > tmpstream = open('fails.mar', 'rb') > value1 = marshal.load(tmpstream) > value2 = marshal.load(tmpstream) > > print(value1 == numlines) > print(value2 == numwords) > > > Here are the results of running this code > > bash-4.1$ python2.7 marshaltest.py > True > True > > bash-4.1$ python3.1 marshaltest.py > Traceback (most recent call last): > File "marshaltest.py", line 13, in > value2 = marshal.load(tmpstream) > EOFError: EOF read where object expected > > Interestingly the file created by using Python 3.1 is readable by both > Python 2.7 as well as Python 2.6 and both objects are successfully > read. > > Cheers, > raj From thomas at jollans.com Sat Jul 17 13:16:12 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 19:16:12 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41DC99.90406@islandtraining.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: <4C41E55C.4060201@jollans.com> On 07/17/2010 06:38 PM, Gary Herron wrote: > On 07/17/2010 01:03 AM, Steven D'Aprano wrote: >> On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: >> >> >>>> Is anyone /still/ using Python 2.x? ;-) > http://xkcd.com/353/ There we have the most important difference between Python 2 and 3: in the latter, "import antigravity" actually works. From emile at fenx.com Sat Jul 17 13:27:09 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:27:09 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41DC99.90406@islandtraining.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On 7/17/2010 9:38 AM Gary Herron said... > and unrelated to the thread but still about python: > > http://xkcd.com/353/ ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import antigravity Nothing happens. >>> Emile From emile at fenx.com Sat Jul 17 13:28:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:28:01 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C4110A8.8040406@mrabarnett.plus.com> References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: On 7/16/2010 7:08 PM MRAB said... > Peng Yu wrote: >> On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >>> On 7/16/2010 1:01 PM, Peng Yu wrote: >>>> I mean to get the man page for '[' like in the following code. >>>> >>>> x=[1,2,3] >>> You might find my Python symbol glossary useful. >>> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html >> >> This is for Python 3. Is there one for Python 2.x? >> > Is anyone /still/ using Python 2.x? ;-) Is anyone /actually/ using Python 3.x ;-) Emile From emmynoether3 at gmail.com Sat Jul 17 13:31:47 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 10:31:47 -0700 (PDT) Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: <1e9dc79f-f483-4b46-827e-20ef278c3a94@d16g2000yqb.googlegroups.com> > So, if newsgroups die and get replaced by web forums, that would be a move for > the better. If they get replaced by mailing lists, that would be a move for > the worse. Uday has gotten the valuation of the three communications media - a little wrong. 1/ Newsgroups are international, free and without censorship in the true spirit of democracy. 2/ The forums are privately owned, serve private interests and the most autocratic medium, you can be denied reading permissions if you go against official line which is never described. 3/ The mailing lists are archived, so read permission is often available and write permission can be denied. They are the second best. Moderated lists are no good. The quality of discussion in any of these media only depends on the generosity of the members in sharing information. Take a look at past archives of the newsgroups, and marvel at the quality of information. They stand as a counterexample to anyone bickering about newsgroups. Today, after monetary interests have attached to the software and the internet, the whole game is about controlling discourse, about marketing and creating hype towards sales and prominence without giving anything of substance. The forums are an excellent tool for this corporate control. The newsgroups are the ONLY NEUTRAL medium. Its obvious about the spam going on here today that the OCCASIONAL political messages are disliked by some groups and they start MASSIVELY spamming with sex-viagra-xanax etc. to drown OCCASIONAL political messages and hide them in a burst of spam. Alternatively, some companies dont like discussion and they produce the spam. The best method is to put some of these VIAGRA-XANAX words in the kill file or spam filter or search filters. On Jul 16, 1:22?am, Uday S Reddy wrote: > > Doing "better" means having more posts? ?I don't believe that having a lot of > posts is necessarily a measure of goodness. > > In my opinion, discussion forums do well when they encourage people to think > carefully and communicate clearly. ?In this respect, I think mailing lists do > worse, newsgroups better, and web-based forums the best. Uday presents a FACTOID on the order of "goodness". Forums are generally against freedom. They appeared around 2001 to control discourse and kill newsgroups, democracy and freedom of speech. Its the same forces who wanted to institute the Patriot Law and who mailed the ANTHRAX for that are the ones destroying the newsgroups by spamming. They operate on the principle of "provocation/reaction" cycle as explained Lucidly by Alex Jones which you can learn in first 2 minutes of this video http://video.google.com/videoplay?docid=5792753647750188322 > Mailing lists seem to turn into talking shops where people get to know each > other over time and their "public" nature gets lost. ?Those who write a lot end > up dominating them, independent of whether they write any sense or not. ?The > other people get tired and stop reading. ?So, you can generate a lot of > traffic, but its value is dubious. > > Newsgroups are much better because they are public and, visibly so. ?If > somebody says something stupid, a lot of people will jump on them. ?And, so, > over time, they develop some quality. ?(There is no guarantee, of course. ?I > have also seen a lot of newsgroups, especially in politics, really degenerate > with opposing factions fighting and dominating everything else.) > > Web-based forums, especially those where people have to register, work the best > in my experience. ?They are very visibly public, discouraging people to write > nonsense. ?The difficulty of writing on the web instead of your favorite editor > hopefully provides some resistance to write. ?So, people tend to think more > than they write. > > I used a forum called silentpcforum last year to help me build myself a new > computer. ?There was a lot of high quality information dating back to years, > which was easy to find and easy to use. > From emile at fenx.com Sat Jul 17 13:36:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:36:43 -0700 Subject: Struqtural: High level database interface library In-Reply-To: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> References: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> Message-ID: On 7/17/2010 6:25 AM sturlamolden said... > On 17 Jul, 07:29, Nathan Rice wrote: > >> Let?s push things to the edge now with a quick demo of many to many >> relationship support. For this example we?re going to be using the >> following XML: >> >> >> >> 123 >> Sales >> >> 143 >> Raul Lopez >> >> >> 687 >> John Smith >> >> >> 947 >> Ming Chu >> >> >> >> 456 >> Marketing >> >> 157 >> Jim Jones >> >> >> 687 >> John Smith >> >> >> 947 >> Ming Chu >> >> >> > > > Oh yes, I'd rather write pages of that rather than some SQL in a > Python string. > That's not the point. I've got examples of XML content that I don't create that could be tamed quite easily (if I understand from a quick once over). This looks really interesting. I've got to go read more now... Emile From benjamin.kaplan at case.edu Sat Jul 17 13:57:01 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 17 Jul 2010 10:57:01 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On Sat, Jul 17, 2010 at 10:27 AM, Emile van Sebille wrote: > On 7/17/2010 9:38 AM Gary Herron said... > > and unrelated to the thread but still about python: >> >> http://xkcd.com/353/ >> > > ActivePython 2.6.1.1 (ActiveState Software Inc.) based on > Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import antigravity > Nothing happens. > >>> > > Emile > > Try it in Python 3. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emmynoether3 at gmail.com Sat Jul 17 14:11:10 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:11:10 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: Message-ID: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> On Jul 16, 1:41?am, Uday S Reddy wrote: > On 7/16/2010 12:23 AM, Xah Lee wrote: > > > > > It got closed right away i suppose partly has to do with my > > unforgiving nature of criticizing and run-in with some GNU emacs > > developers in gnu.emacs.help and comp.emacs in the past 5 or so years. > > I think "criticizing" is an understatement for what you do. ?Insulting and > abusing might be closer to the truth. ?You do write a lot of sense, but you > also go off on rants occasionally writing stuff that has no place in civil > conversation. ?I am sure that the emacs developers try to be as professional as > they can, but they would only be human if they undervalue your input because of > your writing style. Well, there is a lot of resistance from the emacs community in sharing information. Richard Stallman is a true STALLER of progress. He has held the whole process hostage by not sharing information. He has RENEGED on his promise to make it truly open by suppressing documentation of his softwares. > > Re-writing the whole doc in a modern perspective might take me one > > month full time. (e.g. 160 hours) But if it were to be done in a > > public way, or submit to him, the time it takes to communicate, email, > > write justifications, create diffs, etc, can easily take half a year > > full time (960 hours). In the end, i'm not even sure half of the text > > in the new doc would be accepted. > > If you can rewrite it in a month's time, then what are you waiting for? ?You > can write it and publish it on your own, calling it a "Modernized Emacs > Manual". ?If people find it valuable and it is accurate, then I am sure Gnu > will distribute it. The one who has the key can open the lock in a jiffy. The one who does not have the key will take lots of labor to do it esp if he has never opened the lock before. All Richard Stallman has to do is to hand draw the data-structures and architecture of the various programs. Give references to the places where he got the ideas. He does not even have to type. He can write with pencil and scan and thats all. This way he can make marvelously elaborate diagrams. He can even make audios or videos. He has plenty of time to make POLITICAL videos. He has plenty of time to to write that elaborate manual on LISP MACHINE PROPOSAL on the internet. Its less about bugs and more about releasing the details and tricks of the softwares he has written. Yes, he can do in one month because he has the key. Will he do it only after he is anointed as a king in the temple of Solomon ? > > The GNU Emacs's bug database sucks majorly. I have problem finding all > > bugs posted by me. (it's using Debbugs.) Hard to find any bug by its > > search feature. They did not have a bug database, only in around 2008. > > Most commercial software have a bug database system in 1990s, and most > > large open source projects have one by early 2000s. (I wrote a bug > > tracker in 1998, 4k lines of Perl (with CGI, MySQL), in about 2 weeks, > > for a startup brainpower.com.) > > I go to gmane.emacs.bugs and view it in Thunderbird. ?I have no problem finding > my bug reports or any one else's. The FSF people have intentionally erected lots of barriers for others. FSF plays a crooked game and this will be discussed in detail. In this video, Stall man makes 4 promises to public but stalls on 2nd of them. http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr 1/ Freedom to Run to the Program 2/ Freedom to study the source code, you control it <------ Software is a puzzle and it must be explained to be able to do that, its like a lock 3/ Freedom to help your neightbors, share with them 4/ Freedom to contribute to your community Software is a puzzle and it must be explained to be able to do that, its like a lock "to MAKE SURE you get the four freedoms" He is WRONG !!! He has not made sure. He has not taken the first steps. Software architecture must be documented. A model minimal release must be given. If it takes too long to document the program by writing in Latex, then he can write by hand or make an video with camera on the paper and he can talk. From nathan.alexander.rice at gmail.com Sat Jul 17 14:20:41 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 17 Jul 2010 14:20:41 -0400 Subject: Struqtural: High level database interface library In-Reply-To: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> References: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> Message-ID: > Oh yes, I'd rather write lines of that rather than pages of SQL in a Python string. (not to mention, avoid some easy to fall into security flaws, not have to worry about porting dialect specific SQL code, etc, etc). Fixed that for you. I can't take the credit for that part though, that magic comes from SQL Alchemy. All Struqtural does is let you move data into a database easily, move data from a database to Python easily, and simplify the creation of some common complex schemas. From emmynoether3 at gmail.com Sat Jul 17 14:34:59 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:34:59 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: <030bc145-6931-49ac-a953-b33e62d3fb90@w35g2000prd.googlegroups.com> Message-ID: On Jul 16, 2:59?pm, Xah Lee wrote: > In comp.emacs Xah Lee wrote: > > > GNU Emacs Developement Inefficiency > > It [a bug report] got closed right away i suppose partly has to do with > > my unforgiving nature of criticizing and run-in with some GNU emacs > > developers in gnu.emacs.help and comp.emacs in the past 5 or so years. > > On Jul 16, 9:25?am, Alan Mackenzie wrote: > > > It has to be said that that criticism has sometimes involved the use of > > curse words. > > i admit that's true. Didnt you say that you wrote several polite emails and it did not work ??? Have some spine and say the truth !!! > > So if your bug reports are getting things moved, what's so frustrating? > > couldn've been better. You meant "could've" > > > Re-writing the whole doc in a modern perspective might take me one > > > month full time. (e.g. 160 hours) > > > I think it would take you a great deal longer than that. ?But it would be > > easy enough to experiment on. ?Chose some chapter from the Emacs or Elisp > > manual, fire away and see how long it takes you. > > btw, i don't think elisp manual needs to be re-worked, or at least not > critical... but i think it's much critical that the emacs manual be. What he needs is to give a clear and concise explanation of the data- structures and algorithms of the software. If he used ideas from others, he need to give reference to them so others can find it and get into depth. There is no need to make professional diagrams using xfig etc if it takes too much time. He only needs a scanner, pencil , eraser and a ruler. Others who worked for him and learnt the hard way can also do it , but I suspect he extracted such a price that they wont be able to give freely. The XEMACs people deserve some commendation . > > I think your changes would not be accepted as such. ?Quite bluntly, your > > English isn't good enough, so somebody would have to go through your > > version eliminating solecisms. ?There's a vast gap between being able to > > use English adequately to transmit your meaning and being able to write > > stylish and correct English. ?Your English belongs to the former > > category. ?As a matter of interest, what is your native language? > > Haha, that's a good one. This is why they brought indians to checkmate the chinese. They can put this accusation of english as they used to do on the asians and japanese throughout the 90s by Japanese Bashing. I remember very well that George Bush senior vomited on the face of Toshiki Kaifu to insult him intentionally in Japan. This is just a false excuse to give proper space to you. I think you write excellently. > i disconcur. See: > > ? The Writing Style on XahLee.org > ?http://xahlee.org/Periodic_dosage_dir/bangu/xah_style.html > > > > (the GNU emacs dev's revision control system was CVS up to ~2008. CVS > > > has been phased out by 2000 in vast majority of software orgs or > > > projects. I think GNU emacs now using SVN, while most bleeding edge > > > orgs have switched to git, mercurial, distributed systems. (e.g. > > > FireFox, Google)) > > > What's your source for "the vast majority" of projects no longer using > > CVS, again as a matter of interest? > > sloppy exaggeration. Though, i would say ?majority?, from experience. > e.g. look at google and other large orgs commercial or open source, > and look at the revision system supported by large project hosters > such as google code, SourceForge, github... Mackenzie, bring a properly written documentation by FSF for example on emacs of gcc. I want to see where RMS got his ideas ? Did he invent all of them himself ? Is he giving proper references to the sources of the ideas ? Is that plagiarism ? I am sick of such jews/zionists like RMS, Roman Polansky, Bernard Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism by their flagrant unethical behaviour. If you use someone else's ideas, give reference. Dont try to portray yourself falsely as a genius by hiding sources and weaving rosy false pictures of being a victim or born out of wedlock. you went to school and got good education. you got insights from your community and good mentorship from other jews in aggressive networking in the jews like other communities dont have. These are facts. Thats why these people dont stand to scrutiny and questioning. > > Emacs uses BZR, not SVN, and has > > done since the beginning of 2010. > > Thanks for your correction. Updated my site. Write a good documentation using pencil and scan that helps newbies enter the field. If it is not there, you will be subject of perpetual criticism and no thanks. > (also thanks to Uday S Reddy & David Kastrup for comment.) > > ? Xah > ?http://xahlee.org/ > > ? From emile at fenx.com Sat Jul 17 14:37:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 11:37:55 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On 7/17/2010 10:57 AM Benjamin Kaplan said... > Try it in Python 3. > Cool. :) Although I wouldn't have been surprised had my monitor levitated. :) Emile From emmynoether3 at gmail.com Sat Jul 17 14:43:09 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:43:09 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: Message-ID: <0d3e8a52-a7a3-4f9b-9fb5-b4b1e3fddf7c@c10g2000yqi.googlegroups.com> On Jul 15, 4:23?pm, Xah Lee wrote: > ? GNU Emacs Developement Inefficiency > ?http://xahlee.org/emacs/GNU_Emacs_dev_inefficiency.html > > essay; commentary. Plain text version follows. > > -------------------------------------------------- > GNU Emacs Developement Inefficiency > > Xah Lee, 2010-07-15 > > I've also written to Richard Stallman a few times in private in about > 2008 or 2009, about documentation improvements. With extreme > politeness and respect on my part. You took good precaution to deny him any excuse to fend you off ... so that we can all know the true reality of the situation. Its long said by others that this idea of freedom is a bait. Still, I want to give him / FSF a chance to prove their sincerity in enabling others in reading the code and learning from it ... > Without going into detail, i'm just > disenchanted by his reaction. In short, it appears to me he did not > pay much attention, and basically in the end asked me to submit > changes to him. Yeah right. The whole shebang seems to be very well > described by Ben Wing. (See: GNU Emacs and Xemacs Schism, by Ben > Wing.) (Richard Stallman's emails are pretty short, just a couple > terse sentences; but he does, however, whenever he got a chance, tell > his correspondents to use the term GNU/Linux, and ask them to > contribute.) > > Re-writing the whole doc in a modern perspective might take me one > month full time. (e.g. 160 hours) But if it were to be done in a > public way, or submit to him, the time it takes to communicate, email, > write justifications, create diffs, etc, can easily take half a year > full time (960 hours). In the end, i'm not even sure half of the text > in the new doc would be accepted. > > The GNU Emacs's bug database sucks majorly. I have problem finding all > bugs posted by me. (it's using Debbugs.) Hard to find any bug by its > search feature. They did not have a bug database, only in around 2008. > Most commercial software have a bug database system in 1990s, and most > large open source projects have one by early 2000s. (I wrote a bug > tracker in 1998, 4k lines of Perl (with CGI, MySQL), in about 2 weeks, > for a startup brainpower.com.) > > Am pretty sure there are several good ?FSF Free? bug databases. (see: > Comparison of issue-tracking systems) Few years ago, some may have > problem to be politically qualified to be ?Free? for FSF to adopt. > However, these days there are many that FSF officially sactions as > ?Free?. However, when you look at FSF, you see that even when a > software became free, they usually are still picky with lots qualms, > and typically always ends up using their OWN ones (i.e. from GNU > project), even though it is clear that it is inferior. (the GNU emacs > dev's revision control system was CVS up to ~2008. CVS has been phased > out by 2000 in vast majority of software orgs or projects. I think GNU > emacs now using SVN, while most bleeding edge orgs have switched to > git, mercurial, distributed systems. (e.g. FireFox, Google)) > > These are consequence of old and large orgs, with its old policies and > beaucracies. See: ?Free? Software Morality, Richard Stallman, and > Paperwork Bureaucracy. > > Who are the main developers of FSF software these days? Mostly, they > are either paid as FSF employee, or students still trying to break out > their craft in programing, or 40/50 years old semi-retired programers > who otherwise isn't doing anything. Those willing and able, spend time > and get decent salary in commercial corps, or went to start their own > projects or business that'd be far more rewarding financially or not > than being another name in FSF's list of contributors. > > These days, FSF and Richard Stallman more serves as a figure-head and > political leader in open source movement. FSF's software, largely are > old and outdated (e.g. unix command line utils), with the exception of > perhaps GCC and GPG. If we go by actual impact of open source software > in society, i think Google's role, and other commercial orgs (such as > Apache, Perl, Python, PHP, various langs on JVM, and other project > hosters hosting any odd-end single-man projects), exceeded FSF by > ~2000. > > ? Xah > ?http://xahlee.org/ > > ? From emmynoether3 at gmail.com Sat Jul 17 15:09:05 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 12:09:05 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> Message-ID: <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> On Jul 7, 1:57?pm, bolega wrote: > "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > Enjoy ..... In this video, Stall man makes 4 promises to public but stalls on 2nd of them. http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr 1/ Freedom to Run to the Program 2/ Freedom to study the source code, you control it <------ Software is a puzzle and it must be explained to be able to do that, its like a lock 3/ Freedom to help your neightbors, share with them 4/ Freedom to contribute to your community Software is a puzzle and it must be explained to be able to do that, its like a lock "to MAKE SURE you get the four freedoms" He is WRONG !!! He has not made sure. He has not taken the first steps. Software architecture must be documented. A model minimal release must be given. If it takes too long to document the program by writing in Latex, then he can write by hand or make an video with camera on the paper and he can talk. Mackenzie, bring a properly written documentation by FSF for example on emacs of gcc. I want to see where RMS got his ideas ? Did he invent all of them himself ? Is he giving proper references to the sources of the ideas ? Is that plagiarism ? I am sick of such jews/zionists like RMS, Roman Polansky, Bernard Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism by their flagrant unethical behaviour. If you use someone else's ideas, give reference. Dont try to portray yourself falsely as a genius by hiding sources and weaving rosy false pictures of being a victim or born out of wedlock. you went to school and got good education. you got insights from your community and good mentorship from other jews in aggressive networking in the jews like other communities dont have. These are facts. Thats why these people dont stand to scrutiny and questioning. > > Emacs uses BZR, not SVN, and has > > done since the beginning of 2010. > Thanks for your correction. Updated my site. Write a good documentation using pencil and scan that helps newbies enter the field. If it is not there, you will be subject of perpetual criticism and no thanks. From hjtoi-better-remove-before-reply at comcast.net Sat Jul 17 15:20:23 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Sat, 17 Jul 2010 12:20:23 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem References: Message-ID: On 07/16/2010 08:18 AM, Adam Mercer wrote: >> That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL >> changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at >> this time, you should check out M2Crypto from the Subversion repository. See >> http://chandlerproject.org/Projects/MeTooCrypto for details on how to get >> the sources. > > Thanks any ETA on a new release supporting OpenSSL 1.0.x? I was actually planning on doing a release by the end of June, but life happened. Maybe by the end of August... -- Heikki Toivonen - http://heikkitoivonen.net From mad.mick at gmx.de Sat Jul 17 15:38:01 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sat, 17 Jul 2010 21:38:01 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Karsten Wutzke wrote: > The visitor pattern uses single-dispatch, that is, it determines > which method to call be the type of object passed in. Say, in Python, I have an object o and want to call one of it's methods, say m. Then which of possibly many methods m to call is determined by the type of o, and nothing else (at least without further magic) - hence, it is single dispatch. The VP uses two single dispatch calls (one being a callback) to accomplish double dispatching. Java has a form of multiple dispatch through function overloading. In fact, it's still single dispatch, because which of the targets overloaded methods gets called is determined at compile time by the staticly known types of the methods parameters, AKA the formal parameter types. Anyway. Although VP *uses* double dispatch, it does not necessarily rely on function overloading. In Java the VP is most often implemented like this: interface IASTNode { void accept(IASTVisitor); } class IfNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visit(this); } } class ElseNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visit(this); } } interface IASTVisitor { void visit(IfNode node); void visit(ElseNode node); ... } class PrettyPrinter implements IASTVisitor { public void visit(IfNode n) { ... } public void visit(ElseNode n) { ... } } but it could as well be implemented like this: interface IASTNode { void accept(IASTVisitor); } class IfNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visitIfNode(this); } } class ElseNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visitElseNode(this); } } interface IASTVisitor { void visitIfNode(IfNode node); void visitElseNode(ElseNode node); ... } class PrettyPrinter implements IASTVisitor { public void visitIfNode(IfNode n) { ... } public void visitElseNode(ElseNode n) { ... } } If Java were *really* a multiple dispatch language, it wouldn't be necessary to repeat the accept-code for every subclass. Instead a single accept method in the base class would suffice. In fact, with true multiple dispatch VP wouldn't even be needed. Regards, Mick. From mad.mick at gmx.de Sat Jul 17 15:55:09 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sat, 17 Jul 2010 21:55:09 +0200 Subject: Code generator and visitor pattern In-Reply-To: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> References: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> Message-ID: Hello, Am 16.07.2010 09:52, Michele Simionato wrote: > [os.path.walk vs os.walk] > There is a big conceptual difference between os.path.walk and os.walk. > The first works like a framework: you pass a function to it and > os.path.walk is in charging of calling it when needed. The second works > like a library: os.walk flattens the hierarchical structure and then > you are in charge of doing everything you wish with it. > > os.walk is the Pythonic way, and you suggested to follow that > approach; for instance elementTree and lxml (libraries for parsing XML > data) work exactly that way. Actually one of the motivating examples for > the introduction of generators in Python was their use in flattening > data structure, i.e. exactly the pattern used by os.walk. The Visitor Pattern isn't about traversing, so they could as well have had an os.walk() that took a visitor object. Instead, it's about the untangling of unrelated stuff. Not the traversing vs. everything else - that's what iterators are for, like you said. But if you want to be able to add new types of operations without ever touching the code of the objects on which to apply those operations, then the VP is an easy way to accomplish things: class IfNode: def apply(self, operation): operation.handleIfNode(self) ... class ElseNode: def apply(self, operation): operation.handleElseNode(self) ... class PrettyPrinter: def handleIfNode(self, if_node): # print if_node pretty def handleElseNode(self, else_node): # print else_node pretty ... class Interpreter: def handleIfNode(self, if_node): # interpret if_node def handleElseNode(self, else_node): # interpret else_node ... class AST: def apply(self, operation): # apply operation to all nodes ... some_ast = ... some_ast.apply(PrettyPrinter()) some_ast.apply(Interpreter()) The traversing in AST.apply() is not really part of the pattern, it could also be done in the client code. The VP lives in the relation between the ...Node and the operation classes. It Encapsulates What Varies and helps to uphold the Open/Closed Principle, because to add new operations one does not need to touch the ...Node classes. It implements double dispatching in a single dispatch language. Regards, Mick. From dak at gnu.org Sat Jul 17 15:56:51 2010 From: dak at gnu.org (David Kastrup) Date: Sat, 17 Jul 2010 21:56:51 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <87d3ulj30c.fsf@lola.goethe.zz> Emmy Noether writes: > On Jul 7, 1:57?pm, bolega wrote: >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> Enjoy ..... > > In this video, Stall man makes 4 promises to public but stalls on 2nd > of them. > > > http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > > 1/ Freedom to Run to the Program > 2/ Freedom to study the source code, you control it <------ Software > is a puzzle and it must be explained to be able to do that, its like > a > lock > 3/ Freedom to help your neightbors, share with them > 4/ Freedom to contribute to your community > > > Software is a puzzle and it must be explained to be able to do that, > its like a lock There is no unfreedom involved here. Freedom does not hand you a free ride. Only a free road. -- David Kastrup From kst-u at mib.org Sat Jul 17 16:56:04 2010 From: kst-u at mib.org (Keith Thompson) Date: Sat, 17 Jul 2010 13:56:04 -0700 Subject: GNU Emacs Developement Inefficiency (commentary) References: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> Message-ID: Emmy Noether writes: [98 lines deleted] The parent article was posted to comp.emacs and comp.lang.lisp. Why did you cross-post your followup to comp.lang.c, comp.lang.python, and comp.lang.scheme? -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From clp2 at rebertia.com Sat Jul 17 18:11:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jul 2010 15:11:18 -0700 Subject: rstrip() In-Reply-To: <4C409680.8000503@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 10:27 AM, MRAB wrote: > Jason Friedman wrote: >> >> $ python >> Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> "x.vsd-dir".rstrip("-dir") >> >> 'x.vs' >> >> I expected 'x.vsd' as a return value. > > .strip, .lstrip and .rstrip treat their argument like a set of > characters and remove any of those characters from the end(s) of the > string. It's a pity that str.strip() doesn't actually take a set() of length-1 strings, which would make its behavior more obvious and cut down on this perennial question. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sat Jul 17 18:17:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jul 2010 23:17:08 +0100 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> Message-ID: <4C422BE4.8070304@mrabarnett.plus.com> Chris Rebert wrote: > On Fri, Jul 16, 2010 at 10:27 AM, MRAB wrote: >> Jason Friedman wrote: >>> $ python >>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) >>> [GCC 4.4.1] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> "x.vsd-dir".rstrip("-dir") >>> 'x.vs' >>> >>> I expected 'x.vsd' as a return value. >> .strip, .lstrip and .rstrip treat their argument like a set of >> characters and remove any of those characters from the end(s) of the >> string. > > It's a pity that str.strip() doesn't actually take a set() of length-1 > strings, which would make its behavior more obvious and cut down on > this perennial question. > Even better, a set (or tuple) of strings. It's the kind of thing that could've been done in Python 3, with Python 2's .strip(string) becoming .strip(set(string)), but it didn't occur to me until too late. :-( From breamoreboy at yahoo.co.uk Sat Jul 17 19:08:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 18 Jul 2010 00:08:22 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: On 17/07/2010 20:38, Mick Krippendorf wrote: > Karsten Wutzke wrote: >> The visitor pattern uses single-dispatch, that is, it determines >> which method to call be the type of object passed in. > > Say, in Python, I have an object o and want to call one of it's methods, > say m. Then which of possibly many methods m to call is determined by > the type of o, and nothing else (at least without further magic) - > hence, it is single dispatch. The VP uses two single dispatch calls (one > being a callback) to accomplish double dispatching. > > Java has a form of multiple dispatch through function overloading. In > fact, it's still single dispatch, because which of the targets > overloaded methods gets called is determined at compile time by the > staticly known types of the methods parameters, AKA the formal parameter > types. > > Anyway. Although VP *uses* double dispatch, it does not necessarily rely > on function overloading. In Java the VP is most often implemented like this: > > > > interface IASTNode { > void accept(IASTVisitor); > } > > class IfNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visit(this); > } > } > > class ElseNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visit(this); > } > } > > interface IASTVisitor { > void visit(IfNode node); > void visit(ElseNode node); > ... > } > class PrettyPrinter implements IASTVisitor { > public void visit(IfNode n) { > ... > } > public void visit(ElseNode n) { > ... > } > } > > > > but it could as well be implemented like this: > > > > interface IASTNode { > void accept(IASTVisitor); > } > > class IfNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visitIfNode(this); > } > } > > class ElseNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visitElseNode(this); > } > } > > interface IASTVisitor { > void visitIfNode(IfNode node); > void visitElseNode(ElseNode node); > ... > } > class PrettyPrinter implements IASTVisitor { > public void visitIfNode(IfNode n) { > ... > } > public void visitElseNode(ElseNode n) { > ... > } > } > > > > If Java were *really* a multiple dispatch language, it wouldn't be > necessary to repeat the accept-code for every subclass. Instead a single > accept method in the base class would suffice. In fact, with true > multiple dispatch VP wouldn't even be needed. > > > Regards, > Mick. Boilerplate, boilerplate everywhere, but not a beer to drink. Hope everyone at EuroPython is having a good time. Kindest regards. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Jul 17 19:13:41 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 18 Jul 2010 00:13:41 +0100 Subject: rstrip() In-Reply-To: <4C422BE4.8070304@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> Message-ID: On 17/07/2010 23:17, MRAB wrote: > Chris Rebert wrote: >> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >> wrote: >>> Jason Friedman wrote: >>>> $ python >>>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) >>>> [GCC 4.4.1] on linux2 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>>>>> "x.vsd-dir".rstrip("-dir") >>>> 'x.vs' >>>> >>>> I expected 'x.vsd' as a return value. >>> .strip, .lstrip and .rstrip treat their argument like a set of >>> characters and remove any of those characters from the end(s) of the >>> string. >> >> It's a pity that str.strip() doesn't actually take a set() of length-1 >> strings, which would make its behavior more obvious and cut down on >> this perennial question. >> > Even better, a set (or tuple) of strings. It's the kind of thing that > could've been done in Python 3, with Python 2's .strip(string) becoming > .strip(set(string)), but it didn't occur to me until too late. :-( Maybe 3.2 which is still in alpha, if not 3.3? Kindest regards. Mark Lawrence. From ldo at geek-central.gen.new_zealand Sat Jul 17 19:29:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 18 Jul 2010 11:29:55 +1200 Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: In message , MRAB wrote: > You could either open and close a connection for each image, or have the > client tell the server how many bytes it's going to send, followed by > the bytes (my preference would be to send the size as a string ending > with, say, a newline). I have used variations on this in several projects. From emmynoether3 at gmail.com Sat Jul 17 19:44:20 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 16:44:20 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> Message-ID: <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> On Jul 17, 2:49?pm, Cor Gest wrote: > Some entity, AKA David Kastrup , > wrote this mindboggling stuff: > (selectively-snipped-or-not-p) >>> Software is a puzzle and it must be explained to be able to do that, >>> its like a lock >> There is no unfreedom involved here. ?Freedom does not hand you a free >> ride. ?Only a free road. No one asks for a free ride. A free road is good enough. If RMS used other people's free roads (gnu is not the first free thing. the first free thing is what he got at AI labs at TAX Payer money. I read his interview where he said that the hackers would break into professor's offices. Perhaps we do the same to him and break into his FSF office and leave a "friend" note we came to get the docs he has not released.) which has proper signs, proper references, and he could ask profs proper questions, and get straight answers, he must do the same in return. The concise answer: We want a free road but not a free puzzle. Perhaps, next time when he is sick he take his DNA code and parse it using bison. Now, dont run away from this argument and bring each and every of the boys from his mailing list to tackle this question. He is a manager and he can put the volunteers to the task of documenting, illuminating and revealing the operation of his softwares and its evolution. He owes it to others [just like he got for free , I bet ya he could never afford any of his machines on his own money at that time when they were so rare so it must be public money. Even a company like IBM gets public funding. Its all issue of ethics, not of free software. Its issue of two way road. Or else our society would die. People all away in Africa are beginning to agitate from the theft of their resources and evolutionary time by europeans led by jews and so you gotta give them back by fully disclosing technologies. I know you can bribe say a big player like india. We dont want anti-semitism to spread and want the same ethical requirements for everyone.] to describe the algorithms used, references, or else, describe them if he dont want to give references. He need to give priorty to the past undocumented tools. Automatically, more volunteers will come. Right now, the mistrust of Richard Stall man and FSF is growing everywhere. Strength of my arguments stand on their validity. I repeat, no one wants a free ride. We want a free road that you seemed to offer. But we dont want a free puzzle. Or else, ask him to decode his own DNA alone in reasonable time. Its nothing but a code. > You know, nowdadys many 'people' are used to get everything on a platter > any mental incovieniences are circumvented as much as possible, so is > any try for independent thinking about anything strongly dissuaded. > > The last 25 years, since click-tah-icon-software emerged > "the dumbing down of programming" [1] has been on a rampage. > > [1]http://www.salon.com/21st/feature/1998/05/cov_12feature.html From aahz at pythoncraft.com Sat Jul 17 20:09:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 17 Jul 2010 17:09:42 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: In article , Jean-Michel Pichavant wrote: >Aahz wrote: >> In article , >> Jean-Michel Pichavant wrote: >>> >>> PS : You're misusing the del statement. It does not remove any object >>> from mmory, however, it removes the reference to it, the object is still >>> in memory. They are very few cases where del is usefull in python, so >>> try to avoid using it as well. >> >> The first two sentences are true; the last sentence is completely wrong. >> I've got lots of code using del, and it's a critically useful element of >> dictionary manipulation. > >Can you please give a short example ? I'm not challenging though, just >curious. Let's suppose you want to remove duplicate keys from a second dict: for k in d1: if k in d2: del d2[k] You could do d2.pop() instead, but I'll bet you'll find that it's slightly slower, which makes a difference in a tight loop. (Mainly, though, I learned this idiom long before pop() was available.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From ramercer at gmail.com Sat Jul 17 20:15:56 2010 From: ramercer at gmail.com (Adam Mercer) Date: Sat, 17 Jul 2010 20:15:56 -0400 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: On Sat, Jul 17, 2010 at 15:20, Heikki Toivonen wrote: > I was actually planning on doing a release by the end of June, but life > happened. Maybe by the end of August... Know what whats like :-) I've backported the OpenSSL patches for the MacPorts port so for the time being this particular fire has been put out. Cheers Adam From emmynoether3 at gmail.com Sat Jul 17 20:16:35 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 17:16:35 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> Message-ID: <252adaf3-df99-4d27-8fcf-a3e339e7a0ac@w12g2000yqj.googlegroups.com> The XEMACS programmers have documented in writing that Richard Matthews Stallman asked them to explain every single line of code. They got exasperated and would explain him blocks. I suspect that they were playing the same game as him - perhaps giving him the same medicine. If he was NEEDY of an explanation of every single line, isn't it UTTERLY SHAMELESS of him to deny others similar information and give them such a puzzle ? We have the right to tell the people what it really is all about. By writing the GNU license, he eliminated the competition only from those one-in-a-million who were persistent enough to read his code and figure it out. This is because by not documenting and describing his softwares, he ensured that there is little chance that the multitude would be able to take the code and do anything with it. But by writing the GNU license, he made sure that those few who can understand it cant take it away and build on it. An new type of license is needed that requires concurrent documentation with each release, even if hand-written. Scans can be put together in a pdf and diagrams drawn with hand. From rui.maciel at gmail.com Sat Jul 17 20:34:36 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Sun, 18 Jul 2010 01:34:36 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <4c424c1b$0$1334$a729d347@news.telepac.pt> Emmy Noether wrote: > Mackenzie, bring a properly written documentation by FSF for example > on emacs of gcc. I want to see where RMS got his ideas ? Did he > invent > all of them himself ? Is he giving proper references to the sources > of > the ideas ? Is that plagiarism ? > > I am sick of such jews/zionists like RMS, Roman Polansky, Bernard > Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl > he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism > by their flagrant unethical behaviour. You are a lousy troll. Rui Maciel From debatem1 at gmail.com Sat Jul 17 21:10:01 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 18:10:01 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <4c424c1b$0$1334$a729d347@news.telepac.pt> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <4c424c1b$0$1334$a729d347@news.telepac.pt> Message-ID: On Sat, Jul 17, 2010 at 5:34 PM, Rui Maciel wrote: > Emmy Noether wrote: > > >> Mackenzie, bring a properly written documentation by FSF for example >> on emacs of gcc. I want to see where RMS got his ideas ? Did he >> invent >> all of them himself ? Is he giving proper references to the sources >> of >> the ideas ? Is that plagiarism ? >> >> I am sick of such jews/zionists like RMS, Roman Polansky, Bernard >> Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl >> he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism >> by their flagrant unethical behaviour. > > > You are a lousy troll. I'm seriously considering blocking everyone who uses the word 'zionist' in an email. The amount of anti-semitic crap that comes through on this list is staggering. Geremy Condra From me+list/python at ixokai.io Sat Jul 17 23:01:13 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 17 Jul 2010 20:01:13 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <4C426E79.5030607@ixokai.io> On 7/17/10 12:09 PM, Emmy Noether wrote: > I am sick of such jews/zionists [...] This racist rant may be on-topic for some of the other newsgroups/lists you are cross-posting to, but it is most assuredly not on topic for Python. Also, its just daft. But that's another thing entirely. Reported. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rajgopal.srinivasan at gmail.com Sun Jul 18 00:46:10 2010 From: rajgopal.srinivasan at gmail.com (raj) Date: Sat, 17 Jul 2010 21:46:10 -0700 (PDT) Subject: Python 3.1.2 and marshal References: Message-ID: <43f8638f-adb7-4c3c-a12a-932e469eb144@w37g2000prc.googlegroups.com> On Jul 17, 10:11?pm, Thomas Jollans wrote: [Snip] > So, the contents of the file is identical, but Python 3 reads the whole > file, Python 2 reads only the data it uses. > > This looks like a simple optimisation: read the whole file at once, > instead of byte-by-byte, to improve performance when reading large > objects. (such as Python modules...) > Good analysis and a nice catch. Thanks. It is likely that the intent is to optimize performance. > The question is: was storing multiple objects in sequence an intended > use of the marshal module? The documentation (http://docs.python.org/py3k/library/marshal.html) for marshal itself states (emphasis added by me), marshal.load(file)? Read *one value* from the open file and return it. If no valid value is read (e.g. because the data has a different Python version?s incompatible marshal format), raise EOFError, ValueError or TypeError. The file must be an open file object opened in binary mode ('rb' or 'r +b'). This suggests that support for reading multiple values is intended. > I doubt it. You can always wrap your data in > tuples or use pickle. > The code that I am moving to 3.x dates back to the python 1.5 days, when marshal was significantly faster than pickle and Zope was evolutionarily at the Bobo stage :-). I have switched the current code to pickle - makes more sense. The pickle files are a bit larger and loading it is a tad bit slower, but nothing that makes even a noticeable difference for my use case. Thanks. raj From be.krul at gmail.com Sun Jul 18 01:01:26 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 17 Jul 2010 22:01:26 -0700 (PDT) Subject: why is this group being spammed? Message-ID: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> why is this group being spammed? From clp2 at rebertia.com Sun Jul 18 01:09:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jul 2010 22:09:19 -0700 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > why is this group being spammed? Because that's what happens in unmoderated USENET newsgroups. Cheers, Chris From ben+python at benfinney.id.au Sun Jul 18 01:24:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 18 Jul 2010 15:24:18 +1000 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <874ofx9xbx.fsf@benfinney.id.au> "be.krul" writes: > why is this group being spammed? What kind of answer are you looking for? Are you asking about the motives of spammers, or the technical explanation for how the spam arrives, or something else? -- \ ?The best ad-libs are rehearsed.? ?Graham Kennedy | `\ | _o__) | Ben Finney From me+list/python at ixokai.io Sun Jul 18 01:40:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 17 Jul 2010 22:40:15 -0700 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <4C4293BF.5070701@ixokai.io> On 7/17/10 10:01 PM, be.krul wrote: > why is this group being spammed? Because while God created the Internet, the Devil twisted it by creating spammers. What do you expect? Adam just didn't pay enough attention when Eve made him a waldorf salad; we descendants of Seth have gone and tried to devour not only the knowledge of good and evil but all knowledge of all things, most notably breasts. Of course there'd be a dire consequence for our hubris. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From alf.p.steinbach+usenet at gmail.com Sun Jul 18 01:57:42 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 18 Jul 2010 07:57:42 +0200 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: * be.krul, on 18.07.2010 07:01: > why is this group being spammed? It depends a little on what you're asking, e.g. technical versus motivation. But I'll answer about something you probably didn't mean to ask, namely what human trait enables and almost forces that kind of behavior. And I believe it is the same trait that let hypnotists do funny TV-shows with quite normal folks behaving in ridiculous ways, the same trait that causes wars, the same trait that causes religion, the same trait that holds back science so that "paradigm shifts" only occur when new generations take over, a trait that /makes/ your feet start moving to the rhythm when you hear the right kind of music, and so on. Namely the instinctual drive to fit in in a social group by sharing that group's behavior and values. This instinct is possibly stronger than the sex drive, e.g., wars are seldom fought over sex ("surrender, and give us sex!", no, that's not it, it's "surrender, and become part of us!"). Consider, there would be almost no spam if spamming didn't pay. And the only way that spam can pay is if there are at least some suckers with good money. And the only way that there can be a reasonable number of suckers of such monumental stupidity, who also have good money, is, as I see it, if intelligence and good sense is not a requirement for succeeding in society. But what is required, then, for succeeding in society? Some of it is no doubt blind chance, but I believe that the main requirement is simply one of fitting in, conformance. Thus, if my hypothesis is right, almost any idiot can rise to any level of responsibility and social standing simply by fitting in, conforming. This idiot then has good money and might be one of the suckers responding to spam. Cheers, - Alf -- blog at From debatem1 at gmail.com Sun Jul 18 02:09:54 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 23:09:54 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet wrote: > * be.krul, on 18.07.2010 07:01: >> >> why is this group being spammed? > > It depends a little on what you're asking, e.g. technical versus motivation. > > But I'll answer about something you probably didn't mean to ask, namely what > human trait enables and almost forces that kind of behavior. > > And I believe it is the same trait that let hypnotists do funny TV-shows > with quite normal folks behaving in ridiculous ways, the same trait that > causes wars, the same trait that causes religion, the same trait that holds > back science so that "paradigm shifts" only occur when new generations take > over, a trait that /makes/ your feet start moving to the rhythm when you > hear the right kind of music, and so on. Namely the instinctual drive to fit > in in a social group by sharing that group's behavior and values. This > instinct is possibly stronger than the sex drive, e.g., wars are seldom > fought over sex ("surrender, and give us sex!", no, that's not it, it's > "surrender, and become part of us!"). Helen of Troy begs to differ. Geremy Condra From ldo at geek-central.gen.new_zealand Sun Jul 18 02:49:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 18 Jul 2010 18:49:33 +1200 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: In message , Nick Keighley wrote: > On 16 July, 09:24, Mark Tarver wrote: >> On 15 July, 23:21, bolega wrote: >> >> >http://www.gnu.org/philosophy/stallman-kth.html >> >> > RMS lecture at KTH (Sweden), 30 October 1986 > > did you really have to post all of this... > > > >> > read more ?... > > ...oh sorry only about a third of it... Still totally unnecessary, though. >> Perhaps as an antidote >> >> http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi In other words, software that was developed at Symbolics was not given way for free to LMI. Is that so surprising? Which is conceding Stallman?s point. Anyway, that wasn?t Symbolics?s ?plan?; it was part of the MIT licensing agreement, the very same one that LMI signed. LMI?s changes were all proprietary to LMI, too. I don?t understand this bit. The only ?MIT licensing agreement? I?m aware off _allows_ you to redistribute your copies without the source, but doesn?t _require_ it. From dak at gnu.org Sun Jul 18 03:27:40 2010 From: dak at gnu.org (David Kastrup) Date: Sun, 18 Jul 2010 09:27:40 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> Message-ID: <87wrstgsgj.fsf@lola.goethe.zz> Emmy Noether writes: >> Some entity, AKA David Kastrup , >> wrote this mindboggling stuff: >> (selectively-snipped-or-not-p) > >>>> Software is a puzzle and it must be explained to be able to do that, >>>> its like a lock > >>> There is no unfreedom involved here. ?Freedom does not hand you a free >>> ride. ?Only a free road. > > No one asks for a free ride. A free road is good enough. Obviously you don't understand what you are talking about. > Perhaps we do the same to him and break into his FSF office and leave > a "friend" note we came to get the docs he has not released. You can't "get" anything that has not been written. > The concise answer: We want a free road but not a free puzzle. You have the freedom to walk the forest you perceive. You have the freedom to build the road that you want, in that forest. If it is a puzzle to you, that is your own problem. It is not a puzzle because somebody would have cut a whole into pieces and scattered them around. It is a puzzle because nobody put it together yet. Feel free to do so, doing others the service you want done. > Now, dont run away from this argument and bring each and every of the > boys from his mailing list to tackle this question. He is a manager > and he can put the volunteers to the task of documenting, illuminating > and revealing the operation of his softwares and its evolution. You want a free ride, very obviously. > He owes it to others And you think your whining entitles you to it. What did you ever do to _deserve_ others working for you? -- David Kastrup From j.kleese at arcor.de Sun Jul 18 03:49:24 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Sun, 18 Jul 2010 09:49:24 +0200 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> On 18.07.2010 08:09, geremy condra wrote: > On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet > wrote: >> in in a social group by sharing that group's behavior and values. This >> instinct is possibly stronger than the sex drive, e.g., wars are seldom >> fought over sex ("surrender, and give us sex!", no, that's not it, it's >> "surrender, and become part of us!"). > > Helen of Troy begs to differ. Britney Spears, too. From mad.mick at gmx.de Sun Jul 18 04:09:17 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 18 Jul 2010 10:09:17 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Mark Lawrence wrote: > On 17/07/2010 20:38, Mick Krippendorf wrote: >> >> If Java were *really* a multiple dispatch language, it wouldn't be >> necessary to repeat the accept-code for every subclass. Instead a single >> accept method in the base class would suffice. In fact, with true >> multiple dispatch VP wouldn't even be needed. > > Boilerplate, boilerplate everywhere, but not a beer to drink. That's Java for ya. class ASTNode: def accept(self, visitor): getattr(visitor, self.__class__.__name__)(self) class IfNode(ASTNode): ... # inherits generic accept method class ElseNode(ASTNode): ... # inherits generic accept method class PrettyPrinter: def IfNode(self, node): ... def ElseNode(self, node): ... Regards, Mick. From 3-nospam at temporary-address.org.uk Sun Jul 18 04:09:34 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Sun, 18 Jul 2010 09:09:34 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <87iq4dmcsh.fsf@temporary-address.org.uk> Emmy Noether writes: > On Jul 7, 1:57?pm, bolega wrote: >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> Enjoy ..... > > In this video, Stall man makes 4 promises to public but stalls on 2nd > of them. I have no idea of the rights or wrongs of this case. But I've found through experience that when someone uses a "witty" misspelling of someone's name, they are almost always the one in the wrong. 5 lines in and here we are - so if your case has merit, think about whether you want to do this. BTW - Did you see what I did there? I snipped all the rest of the post as it wasn't relevant. I know several people have asked you to do it, but you seem to be having difficulty with the concept, so I thought I'd give you a practical example. -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From emmynoether3 at gmail.com Sun Jul 18 04:23:47 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sun, 18 Jul 2010 01:23:47 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> Message-ID: <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> On Jul 18, 12:27?am, David Kastrup wrote: > Emmy Noether writes: > >> Some entity, AKA David Kastrup , > >> wrote this mindboggling stuff: > >> (selectively-snipped-or-not-p) > > >>>> Software is a puzzle and it must be explained to be able to do that, > >>>> its like a lock > > >>> There is no unfreedom involved here. ?Freedom does not hand you a free > >>> ride. ?Only a free road. > > > No one asks for a free ride. A free road is good enough. > > Obviously you don't understand what you are talking about. > > > Perhaps we do the same to him and break into his FSF office and leave > > a "friend" note we came to get the docs he has not released. > > You can't "get" anything that has not been written. > > > The concise answer: We want a free road but not a free puzzle. > > You have the freedom to walk the forest you perceive. ?You have the > freedom to build the road that you want, in that forest. > > If it is a puzzle to you, that is your own problem. ?It is not a puzzle > because somebody would have cut a whole into pieces and scattered them > around. ?It is a puzzle because nobody put it together yet. > > Feel free to do so, doing others the service you want done. > > > Now, dont run away from this argument and bring each and every of the > > boys from his mailing list to tackle this question. He is a manager > > and he can put the volunteers to the task of documenting, illuminating > > and revealing the operation of his softwares and its evolution. > > You want a free ride, very obviously. > > > He owes it to others > > And you think your whining entitles you to it. By his own admission he broke into professor's offices to help others, ie unlock the monitors. He has tried to project an image of a saint for freedom. Its a DECEPTION. A scoundrel has a right to be scoundrel. But if he projects himself as a saint, then people have a right to clear the facts. > What did you ever do to _deserve_ others working for you? What did we do to deserve him to write that elisp manual of 800+ pages ? NOTHING. He gave it to us in the hope that his software will spread like a VIRUS. He had hopes for money from big companies probably, which he must be making to pay the astronomical rent in tbe boston/cambridge area. I can assure you that he can document all the essentials of his program in a thin book of a few hundred pages with a trivial amount of man-hours compared to being spent on things which brings fewer volunteers. It is said : A picture is worth a thousand words. Make some transition diagrams, structures, and UML type diagrams of the operation of the software. > What did you ever do to _deserve_ others working for you? Draw a diagram, A state transition diagram to understand how illogical you are. A person arrives in the state of a newbie and wants to exit in a state of having made a contribution to FSF. How can one do it without adequate documentation ? Xah Lee has been complaining for a year. First you deprive people of ESSENTIAL documentation to contribute. Stall man has written user manuals to effect viral spread. But he has not written operational details to get the same viral contribution by others. He must not want it. Yet you want to use it as a taunt as in pot calling the kettle black ???!!! OK, why dont you explain a few basic things, if it not a puzzle ????!!!! DEFUN ("or", For, Sor, 0, UNEVALLED, 0, "Eval args until one of them yields non-NIL, then return that value. \n\ The remaining args are not evalled at all.\n\ If all args return NIL, return NIL.") (args) Lisp_Object args; { register Lisp_Object val; Lisp_Object args_left; struct gcpro gcpro1; if (NULL(args)) return Qnil; args_left = args; GCPRO1 (args_left); do { val = Feval (Fcar (args_left)); if (!NULL (val)) break; args_left = Fcdr (args_left); } while (!NULL(args_left)); UNGCPRO; return val; } I saw that on comp.lang.c and found no one capable of explaining it. And where does the manual explain the C struct or ADT of the basic cons cell ? which file has the definition ? where is his eval_quote function definition ? Basically, Richard Mathew Stall man is a STALLER of PROGRESS. He expected the XEMACS people to EXPLAIN HIM EVERY SINGLE line of code. What did he do to expect all this ? He was even paid money , as claimed by the XEMACS people. What did he do to deserve and EXPECT a line by line explanation from them ?????!!!!!! ANSWER this question and dont run away !!!!!! He is prone to forgetting like all mortals and if he is prolific to write that 900 page manual, I am sure he has hidden notes that he has not released. Where was he recording the line by line explanation he was receiving from the XEMACS people ? If not in his own very personal version ??? Answer these very strong arguments ??? What did he deserve to get the XEMACS people's explanations ? AND why is he INCAPABLE of building upon the XEMACS work ??? This is all about documentation, professional jealousies of these mean spirited people with double standards. Send him a CC of this thread. I expect him to explain some of these issues of documentation. > -- > David Kastrup From emmynoether3 at gmail.com Sun Jul 18 04:38:15 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sun, 18 Jul 2010 01:38:15 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: > Emmy Noether writes: > > On Jul 7, 1:57?pm, bolega wrote: > >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > >> Enjoy ..... > > > In this video, Stall man makes 4 promises to public but stalls on 2nd > > of them. > > I have no idea of the rights or wrongs of this case. ?But I've found > through experience that when someone uses a "witty" misspelling of > someone's name, they are almost always the one in the wrong. ? Huh, you forgot that the whole of GNU = Gnu Not Unix You have double standard and you know very well whats right and whats wrong. > 5 lines in > and here we are - so if your case has merit, think about whether you > want to do this. > > BTW - Did you see what I did there? ?I snipped all the rest of the post > as it wasn't relevant. ?I know several people have asked you to do it, > but you seem to be having difficulty with the concept, so I thought I'd > give you a practical example. > -- > Online waterways route planner ? ? ? ? ? ?|http://canalplan.eu > Plan trips, see photos, check facilities ?|http://canalplan.org.uk From jcb at inf.ed.ac.uk Sun Jul 18 04:50:32 2010 From: jcb at inf.ed.ac.uk (Julian Bradfield) Date: Sun, 18 Jul 2010 08:50:32 +0000 (UTC) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> Message-ID: On 2010-07-18, Emmy Noether wrote: > DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > "Eval args until one of them yields non-NIL, then return that value. > \n\ > The remaining args are not evalled at all.\n\ > If all args return NIL, return NIL.") > (args) > Lisp_Object args; > { > register Lisp_Object val; > Lisp_Object args_left; > struct gcpro gcpro1; > > if (NULL(args)) > return Qnil; > > args_left = args; > GCPRO1 (args_left); > > do > { > val = Feval (Fcar (args_left)); > if (!NULL (val)) > break; > args_left = Fcdr (args_left); > } > while (!NULL(args_left)); > > UNGCPRO; > return val; > } > > I saw that on comp.lang.c and found no one capable of explaining it. What do you need explained? Other than what's already in the manual (Gnu Emacs Internals section of the Elisp manual.) > And where does the manual explain the C struct or ADT of the basic > cons cell ? which file has the definition ? where is his eval_quote > function definition ? Try lisp.h RMS doesn't really believe in ADTs - that's one of the main complaints from XEmacs. As for finding functions, I believe Emacs has commands to help with that, but personally I just go grep eval_quote *.c From 3-nospam at temporary-address.org.uk Sun Jul 18 05:30:29 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Sun, 18 Jul 2010 10:30:29 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <87aappm91m.fsf@temporary-address.org.uk> Emmy Noether writes: > On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: >> Emmy Noether writes: >> > On Jul 7, 1:57?pm, bolega wrote: >> >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> >> Enjoy ..... >> >> > In this video, Stall man makes 4 promises to public but stalls on 2nd >> > of them. >> >> I have no idea of the rights or wrongs of this case. ?But I've found >> through experience that when someone uses a "witty" misspelling of >> someone's name, they are almost always the one in the wrong. ? > > Huh, you forgot that the whole of GNU = Gnu Not Unix > > You have double standard and you know very well whats right and whats > wrong. Ah. I see. You know my thoughts better than I do. That means you're another nutter. What I wrote was entirely true - I haven't read these great long posts in any detail. I've just deleted your email unread and plonked you. -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From thomas at jollans.com Sun Jul 18 06:55:17 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 12:55:17 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <1279335551.5281.1385300137@webmail.messagingengine.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> <1279335551.5281.1385300137@webmail.messagingengine.com> Message-ID: <4C42DD95.8050802@jollans.com> On 07/17/2010 04:59 AM, python at bdurham.com wrote: > Tim, > >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm In slightly related news, I just stumbled upon this: http://catb.org/esr/jargon/html/story-of-mel.html Now of course, he had it tough. From news1234 at free.fr Sun Jul 18 07:18:10 2010 From: news1234 at free.fr (News123) Date: Sun, 18 Jul 2010 13:18:10 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> Message-ID: <4c42e2f2$0$20937$426a74cc@news.free.fr> Mark Lawrence wrote: > On 17/07/2010 23:17, MRAB wrote: >> Chris Rebert wrote: >>> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >>> wrote: >>>> Jason Friedman wrote: >>> >>> It's a pity that str.strip() doesn't actually take a set() of length-1 >>> strings, which would make its behavior more obvious and cut down on >>> this perennial question. >>> >> Even better, a set (or tuple) of strings. It's the kind of thing that >> could've been done in Python 3, with Python 2's .strip(string) becoming >> .strip(set(string)), but it didn't occur to me until too late. :-( > > Maybe 3.2 which is still in alpha, if not 3.3? > > Kindest regards. > > Mark Lawrence. > It could even be introduced without breaking compatibility. if being defined as str.rstrip([iterable]) so you could either call string.rstrip( [ '-dir' ] ) or as string.rstrip( '-dir' ) However I wouldn't be sure, that it really reduces the amount of questions being asked. In order to reduce the ambiguities one had to have two distinct functions. If one wouldn't want to break backwards-compatibility, then the new names would be for stripping off prefixes / suffixes and could be str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) I'd love to have this functionality, though I can live with importing my self written function. From rui.vapps at gmail.com Sun Jul 18 07:36:24 2010 From: rui.vapps at gmail.com (Ray) Date: Sun, 18 Jul 2010 04:36:24 -0700 (PDT) Subject: create dynamic instance References: Message-ID: <3ce37b9c-4e0c-42da-9b82-e07986658bcf@c36g2000prf.googlegroups.com> thanks a lot. I was really stupid. of course I should keep a references to use it later. From thomas at jollans.com Sun Jul 18 07:42:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 13:42:15 +0200 Subject: rstrip() In-Reply-To: <4c42e2f2$0$20937$426a74cc@news.free.fr> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> Message-ID: <4C42E897.5090103@jollans.com> On 07/18/2010 01:18 PM, News123 wrote: > Mark Lawrence wrote: >> On 17/07/2010 23:17, MRAB wrote: >>> Chris Rebert wrote: >>>> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >>>> wrote: >>>>> Jason Friedman wrote: >>>> >>>> It's a pity that str.strip() doesn't actually take a set() of length-1 >>>> strings, which would make its behavior more obvious and cut down on >>>> this perennial question. >>>> >>> Even better, a set (or tuple) of strings. It's the kind of thing that >>> could've been done in Python 3, with Python 2's .strip(string) becoming >>> .strip(set(string)), but it didn't occur to me until too late. :-( >> >> Maybe 3.2 which is still in alpha, if not 3.3? >> >> Kindest regards. >> >> Mark Lawrence. >> > > It could even be introduced without breaking compatibility. > > if being defined as > str.rstrip([iterable]) > so you could either call > string.rstrip( [ '-dir' ] ) > or as > string.rstrip( '-dir' ) The former should certainly raise an exception. '-dir' is not a single character ! Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but that's just silly. > > > However I wouldn't be sure, that it really reduces the amount of > questions being asked. > > In order to reduce the ambiguities one had to have two distinct functions. > If one wouldn't want to break backwards-compatibility, then the new > names would be for stripping off prefixes / suffixes and could be > str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) > > > I'd love to have this functionality, though I can live with importing my > self written function. From rjh at see.sig.invalid Sun Jul 18 07:48:30 2010 From: rjh at see.sig.invalid (Richard Heathfield) Date: Sun, 18 Jul 2010 12:48:30 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <6MOdnZERJ9-Zd9_RnZ2dnUVZ7rSdnZ2d@bt.com> Emmy Noether wrote: > On Jul 18, 1:09 am, Nick <3-nos... at temporary-address.org.uk> wrote: >> Emmy Noether writes: >>> On Jul 7, 1:57 pm, bolega wrote: >>> In this video, Stall man makes 4 promises to public but stalls on 2nd >>> of them. >> I have no idea of the rights or wrongs of this case. But I've found >> through experience that when someone uses a "witty" misspelling of >> someone's name, they are almost always the one in the wrong. > > Huh, you forgot that the whole of GNU = Gnu Not Unix > > You have double standard and you know very well whats right and whats > wrong. If you must be an idiot, that's entirely up to you, but I would take it as a personal favour if you could be an idiot *somewhere else*. If you don't like GNU software, fine - don't use it. End of problem. -- Richard Heathfield Email: -http://www. +rjh@ "Usenet is a strange place" - dmr 29 July 1999 Sig line vacant - apply within From news1234 at free.fr Sun Jul 18 10:17:45 2010 From: news1234 at free.fr (News123) Date: Sun, 18 Jul 2010 16:17:45 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> Message-ID: <4c430d0a$0$20945$426a74cc@news.free.fr> Thomas Jollans wrote: > > >> string.rstrip( [ '-dir' ] ) >> or as >> string.rstrip( '-dir' ) > > The former should certainly raise an exception. '-dir' is not a single > character ! > Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but > that's just silly. > It's silly with the example of '-dir' it's much less silly with a string like ' \t'. The doc is rather clear about it: str.rstrip([chars]) It is marked 'chars' and not 'suffix' The textual description is even clearer: "The chars argument is not a suffix; rather, all combinations of its values are stripped:" When I asked in this grpup about a way of how to strip off a prefix I never even considered strip as a solution having read the doc before. I also think, that the functionality of strip / rstrip is useful as is. It would just be great to have functions to strip prefixes/suffixes. If these new commands were alphabetically next to the classic commands, ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for string functions would probably use the function, which is appropriate for his purpose. Breaking backwardscompatibility within python 3 might not be the best choice. >> However I wouldn't be sure, that it really reduces the amount of >> questions being asked. >> >> In order to reduce the ambiguities one had to have two distinct functions. >> If one wouldn't want to break backwards-compatibility, then the new >> names would be for stripping off prefixes / suffixes and could be >> str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) >> >> >> I'd love to have this functionality, though I can live with importing my >> self written function. > From dak at gnu.org Sun Jul 18 10:53:53 2010 From: dak at gnu.org (David Kastrup) Date: Sun, 18 Jul 2010 16:53:53 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> Message-ID: <87oce4hmda.fsf@lola.goethe.zz> Emmy Noether writes: > On Jul 18, 12:27?am, David Kastrup wrote: > >> What did you ever do to _deserve_ others working for you? > > What did we do to deserve him to write that elisp manual of 800+ > pages ? NOTHING. So once one gives you something, you demand everything? > He gave it to us in the hope that his software will spread like a > VIRUS. Yup. It is called "culture". It is _supposed_ to spread exponentially. That's what the peculiar brain structure of humans is good for. Communicating knowledge instead of inheriting it. That's the fundamental advantage we have over other animals. Not something lightly given up. > A person arrives in the state of a newbie and wants to exit in a state > of having made a contribution to FSF. That's the problem of the person. It has not been a goal of the GNU project to turn every person into somebody useful. They have the freedom to try, getting everything for their start that anybody else has available. > How can one do it without adequate documentation ? Emacs development is active, so there are people considering the documentation adequate for starting to work on Emacs. > Xah Lee has been complaining for a year. First you deprive people of > ESSENTIAL documentation to contribute. You can't "deprive" anybody of anything that is not there to start with. > DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > "Eval args until one of them yields non-NIL, then return that value. > \n\ > The remaining args are not evalled at all.\n\ > If all args return NIL, return NIL.") > (args) > Lisp_Object args; > { > register Lisp_Object val; > Lisp_Object args_left; > struct gcpro gcpro1; > > if (NULL(args)) > return Qnil; > > args_left = args; > GCPRO1 (args_left); > > do > { > val = Feval (Fcar (args_left)); > if (!NULL (val)) > break; > args_left = Fcdr (args_left); > } > while (!NULL(args_left)); > > UNGCPRO; > return val; > } > > I saw that on comp.lang.c and found no one capable of explaining it. If you see other context-free stuff on comp.lang.c, the situation will not be different. The above code is rather trivial. But you'll find the respective parts explained in the Emacs Lisp manual. In fact, the above is likely extracted from exactly there, from (info "(elisp) Writing Emacs Primitives") I append the whole at the bottom to not interrupt the flow of non-thought. > And where does the manual explain the C struct or ADT of the basic > cons cell ? which file has the definition ? where is his eval_quote > function definition ? eval_quote? What's that? > Basically, Richard Mathew Stall man is a STALLER of PROGRESS. He > expected the XEMACS people to EXPLAIN HIM EVERY SINGLE line of code. > What did he do to expect all this ? He was the maintainer of upstream Emacs, and it was his decision what code was going there. And he had to keep maintainability in mind. Something which was less of a priority with XEmacs developers, and likely part of the reason that they are running out of fresh blood much worse than Emacs these days. > He was even paid money , as claimed by the XEMACS people. > > What did he do to deserve and EXPECT a line by line explanation from > them ?????!!!!!! ANSWER this question and dont run away !!!!!! There was nothing to "deserve". It was his job to keep Emacs going forward, and his opinion and decision that throwing the Lucid Emacs code in would not have been good in the long run. It has not been good for XEmacs in the long run. Whether it would have been better or worse for a grand unified Emacs, noone will ever know. He decided to play it safe given the information he had at that time, and Emacs is still there and going forward. In spite of trolls like you spouting abuse by the hundreds. More than can be said for many other projects. File: elisp, Node: Writing Emacs Primitives, Next: Object Internals, Prev: Memory Usage, Up: GNU Emacs Internals E.5 Writing Emacs Primitives ============================ Lisp primitives are Lisp functions implemented in C. The details of interfacing the C function so that Lisp can call it are handled by a few C macros. The only way to really understand how to write new C code is to read the source, but we can explain some things here. An example of a special form is the definition of `or', from `eval.c'. (An ordinary function would have the same general appearance.) DEFUN ("or", For, Sor, 0, UNEVALLED, 0, doc: /* Eval args until one of them yields non-nil, then return that value. The remaining args are not evalled at all. If all args return nil, return nil. usage: (or CONDITIONS ...) */) (Lisp_Object args) { register Lisp_Object val = Qnil; struct gcpro gcpro1; GCPRO1 (args); while (CONSP (args)) { val = Feval (XCAR (args)); if (!NILP (val)) break; args = XCDR (args); } UNGCPRO; return val; } Let's start with a precise explanation of the arguments to the `DEFUN' macro. Here is a template for them: DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC) LNAME This is the name of the Lisp symbol to define as the function name; in the example above, it is `or'. FNAME This is the C function name for this function. This is the name that is used in C code for calling the function. The name is, by convention, `F' prepended to the Lisp name, with all dashes (`-') in the Lisp name changed to underscores. Thus, to call this function from C code, call `For'. Remember that the arguments must be of type `Lisp_Object'; various macros and functions for creating values of type `Lisp_Object' are declared in the file `lisp.h'. SNAME This is a C variable name to use for a structure that holds the data for the subr object that represents the function in Lisp. This structure conveys the Lisp symbol name to the initialization routine that will create the symbol and store the subr object as its definition. By convention, this name is always FNAME with `F' replaced with `S'. MIN This is the minimum number of arguments that the function requires. The function `or' allows a minimum of zero arguments. MAX This is the maximum number of arguments that the function accepts, if there is a fixed maximum. Alternatively, it can be `UNEVALLED', indicating a special form that receives unevaluated arguments, or `MANY', indicating an unlimited number of evaluated arguments (the equivalent of `&rest'). Both `UNEVALLED' and `MANY' are macros. If MAX is a number, it may not be less than MIN and it may not be greater than eight. INTERACTIVE This is an interactive specification, a string such as might be used as the argument of `interactive' in a Lisp function. In the case of `or', it is 0 (a null pointer), indicating that `or' cannot be called interactively. A value of `""' indicates a function that should receive no arguments when called interactively. If the value begins with a `(', the string is evaluated as a Lisp form. DOC This is the documentation string. It uses C comment syntax rather than C string syntax because comment syntax requires nothing special to include multiple lines. The `doc:' identifies the comment that follows as the documentation string. The `/*' and `*/' delimiters that begin and end the comment are not part of the documentation string. If the last line of the documentation string begins with the keyword `usage:', the rest of the line is treated as the argument list for documentation purposes. This way, you can use different argument names in the documentation string from the ones used in the C code. `usage:' is required if the function has an unlimited number of arguments. All the usual rules for documentation strings in Lisp code (*note Documentation Tips::) apply to C code documentation strings too. After the call to the `DEFUN' macro, you must write the argument list that every C function must have, including the types for the arguments. For a function with a fixed maximum number of arguments, declare a C argument for each Lisp argument, and give them all type `Lisp_Object'. When a Lisp function has no upper limit on the number of arguments, its implementation in C actually receives exactly two arguments: the first is the number of Lisp arguments, and the second is the address of a block containing their values. They have types `int' and `Lisp_Object *'. Within the function `For' itself, note the use of the macros `GCPRO1' and `UNGCPRO'. `GCPRO1' is used to "protect" a variable from garbage collection--to inform the garbage collector that it must look in that variable and regard its contents as an accessible object. GC protection is necessary whenever you call `Feval' or anything that can directly or indirectly call `Feval'. At such a time, any Lisp object that this function may refer to again must be protected somehow. It suffices to ensure that at least one pointer to each object is GC-protected; that way, the object cannot be recycled, so all pointers to it remain valid. Thus, a particular local variable can do without protection if it is certain that the object it points to will be preserved by some other pointer (such as another local variable which has a `GCPRO')(1). Otherwise, the local variable needs a `GCPRO'. The macro `GCPRO1' protects just one local variable. If you want to protect two variables, use `GCPRO2' instead; repeating `GCPRO1' will not work. Macros `GCPRO3', `GCPRO4', `GCPRO5', and `GCPRO6' also exist. All these macros implicitly use local variables such as `gcpro1'; you must declare these explicitly, with type `struct gcpro'. Thus, if you use `GCPRO2', you must declare `gcpro1' and `gcpro2'. Alas, we can't explain all the tricky details here. `UNGCPRO' cancels the protection of the variables that are protected in the current function. It is necessary to do this explicitly. Built-in functions that take a variable number of arguments actually accept two arguments at the C level: the number of Lisp arguments, and a `Lisp_Object *' pointer to a C vector containing those Lisp arguments. This C vector may be part of a Lisp vector, but it need not be. The responsibility for using `GCPRO' to protect the Lisp arguments from GC if necessary rests with the caller in this case, since the caller allocated or found the storage for them. You must not use C initializers for static or global variables unless the variables are never written once Emacs is dumped. These variables with initializers are allocated in an area of memory that becomes read-only (on certain operating systems) as a result of dumping Emacs. *Note Pure Storage::. Do not use static variables within functions--place all static variables at top level in the file. This is necessary because Emacs on some operating systems defines the keyword `static' as a null macro. (This definition is used because those systems put all variables declared static in a place that becomes read-only after dumping, whether they have initializers or not.) Defining the C function is not enough to make a Lisp primitive available; you must also create the Lisp symbol for the primitive and store a suitable subr object in its function cell. The code looks like this: defsubr (&SUBR-STRUCTURE-NAME); Here SUBR-STRUCTURE-NAME is the name you used as the third argument to `DEFUN'. If you add a new primitive to a file that already has Lisp primitives defined in it, find the function (near the end of the file) named `syms_of_SOMETHING', and add the call to `defsubr' there. If the file doesn't have this function, or if you create a new file, add to it a `syms_of_FILENAME' (e.g., `syms_of_myfile'). Then find the spot in `emacs.c' where all of these functions are called, and add a call to `syms_of_FILENAME' there. The function `syms_of_FILENAME' is also the place to define any C variables that are to be visible as Lisp variables. `DEFVAR_LISP' makes a C variable of type `Lisp_Object' visible in Lisp. `DEFVAR_INT' makes a C variable of type `int' visible in Lisp with a value that is always an integer. `DEFVAR_BOOL' makes a C variable of type `int' visible in Lisp with a value that is either `t' or `nil'. Note that variables defined with `DEFVAR_BOOL' are automatically added to the list `byte-boolean-vars' used by the byte compiler. If you define a file-scope C variable of type `Lisp_Object', you must protect it from garbage-collection by calling `staticpro' in `syms_of_FILENAME', like this: staticpro (&VARIABLE); Here is another example function, with more complicated arguments. This comes from the code in `window.c', and it demonstrates the use of macros and functions to manipulate Lisp objects. DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, Scoordinates_in_window_p, 2, 2, "xSpecify coordinate pair: \nXExpression which evals to window: ", "Return non-nil if COORDINATES is in WINDOW.\n\ COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ ... If they are on the border between WINDOW and its right sibling,\n\ `vertical-line' is returned.") (coordinates, window) register Lisp_Object coordinates, window; { int x, y; CHECK_LIVE_WINDOW (window, 0); CHECK_CONS (coordinates, 1); x = XINT (Fcar (coordinates)); y = XINT (Fcdr (coordinates)); switch (coordinates_in_window (XWINDOW (window), &x, &y)) { case 0: /* NOT in window at all. */ return Qnil; case 1: /* In text part of window. */ return Fcons (make_number (x), make_number (y)); case 2: /* In mode line of window. */ return Qmode_line; case 3: /* On right border of window. */ return Qvertical_line; default: abort (); } } Note that C code cannot call functions by name unless they are defined in C. The way to call a function written in Lisp is to use `Ffuncall', which embodies the Lisp function `funcall'. Since the Lisp function `funcall' accepts an unlimited number of arguments, in C it takes two: the number of Lisp-level arguments, and a one-dimensional array containing their values. The first Lisp-level argument is the Lisp function to call, and the rest are the arguments to pass to it. Since `Ffuncall' can call the evaluator, you must protect pointers from garbage collection around the call to `Ffuncall'. The C functions `call0', `call1', `call2', and so on, provide handy ways to call a Lisp function conveniently with a fixed number of arguments. They work by calling `Ffuncall'. `eval.c' is a very good file to look through for examples; `lisp.h' contains the definitions for some important macros and functions. If you define a function which is side-effect free, update the code in `byte-opt.el' which binds `side-effect-free-fns' and `side-effect-and-error-free-fns' so that the compiler optimizer knows about it. ---------- Footnotes ---------- (1) Formerly, strings were a special exception; in older Emacs versions, every local variable that might point to a string needed a `GCPRO'. > He is prone to forgetting like all mortals and if he is prolific to > write that 900 page manual, I am sure he has hidden notes that he has > not released. Where was he recording the line by line explanation he > was receiving from the XEMACS people ? If not in his own very personal > version ??? What makes you think he received any such explanation? Why would not the XEmacs people, after writing such explanations, put them in their own code and manuals? Your conspiracy theories just stink. > Answer these very strong arguments ??? Ok, so they stink strongly. > What did he deserve to get the XEMACS people's explanations ? AND why > is he INCAPABLE of building upon the XEMACS work ??? This is all about > documentation, professional jealousies of these mean spirited people > with double standards. Send him a CC of this thread. I expect him to > explain some of these issues of documentation. I quoted the above part from the documentation. I do not consider this sort of shit worth his attention and certainly won't forward it, lending it credibility. It is not like he has a secret Email address or something. I should hope he would have the prudence to just throw crap like the above away should he receive it from some anonymous idiot not willing to sign his name under his brain farts. -- David Kastrup From clp2 at rebertia.com Sun Jul 18 11:35:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jul 2010 08:35:41 -0700 Subject: why is this group being spammed? In-Reply-To: <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Sun, Jul 18, 2010 at 12:49 AM, Johannes Kleese wrote: > On 18.07.2010 08:09, geremy condra wrote: >> On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet >> wrote: > >>> in in a social group by sharing that group's behavior and values. This >>> instinct is possibly stronger than the sex drive, e.g., wars are seldom >>> fought over sex ("surrender, and give us sex!", no, that's not it, it's >>> "surrender, and become part of us!"). >> >> Helen of Troy begs to differ. > > Britney Spears, too. Sorry, which war was that again? Cheers, Chris From python at bdurham.com Sun Jul 18 12:45:00 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 12:45:00 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C42DD95.8050802@jollans.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com><1279335551.5281.1385300137@webmail.messagingengine.com> <4C42DD95.8050802@jollans.com> Message-ID: <1279471500.17203.1385458203@webmail.messagingengine.com> Thomas, > In slightly related news, I just stumbled upon this: > http://catb.org/esr/jargon/html/story-of-mel.html > > Now of course, he had it tough. Tough??? Well we had it tough. Our computers[1][2] had 0 bytes of RAM and 0 bytes of ROM. We had to hand wire our logic and physically push data through logic gates without the benefit of transistors. We used to have to get up out of the shoebox at twelve o'clock at night, and LICK the road clean with our tongues. We had half a handful of freezing cold gravel, worked twenty-four hours a day at the mill for fourpence every six years, and when we got home, our Dad would slice us in two with a bread knife. Malcolm [1] http://totallytrygve.com/computer.php?item=188&picture=0 [2] I learned about computers through one of these kits. When I first stumbled across assembly language (6502), my first thought was, "wow, this is so much easier than what I've been doing"! >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm In slightly related news, I just stumbled upon this: http://catb.org/esr/jargon/html/story-of-mel.html Now of course, he had it tough. From python at mrabarnett.plus.com Sun Jul 18 12:49:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 18 Jul 2010 17:49:11 +0100 Subject: rstrip() In-Reply-To: <4c430d0a$0$20945$426a74cc@news.free.fr> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> Message-ID: <4C433087.8090403@mrabarnett.plus.com> News123 wrote: > Thomas Jollans wrote: > >> >>> string.rstrip( [ '-dir' ] ) >>> or as >>> string.rstrip( '-dir' ) >> The former should certainly raise an exception. '-dir' is not a single >> character ! >> Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but >> that's just silly. >> > It's silly with the example of '-dir' it's much less silly with > a string like ' \t'. > > The doc is rather clear about it: > str.rstrip([chars]) > > It is marked 'chars' and not 'suffix' > > The textual description is even clearer: > "The chars argument is not a suffix; rather, all combinations of its > values are stripped:" > > > When I asked in this grpup about a way of how to strip off a prefix I > never even considered strip as a solution having read the doc before. > > I also think, that the functionality of strip / rstrip is useful as is. > > > It would just be great to have functions to strip prefixes/suffixes. > If these new commands were alphabetically next to the classic commands, > ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for > string functions would probably use the function, which is appropriate > for his purpose. > > Breaking backwardscompatibility within python 3 might not be the best > choice. > [snip] How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something similar? From lord at emf.net Sun Jul 18 13:26:50 2010 From: lord at emf.net (Tom Lord) Date: Sun, 18 Jul 2010 10:26:50 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> Message-ID: <26b77eee-6a92-468d-989f-14d443ef45c9@t5g2000prd.googlegroups.com> On Jul 17, 11:11?am, Emmy Noether wrote: > Well, there is a lot of resistance from the emacs community in sharing > information. Richard Stallman is a true STALLER of progress. He has > held the whole process hostage by not sharing information. He has > RENEGED on his promise to make it truly open by suppressing > documentation of his softwares. I used to think similarly but differently. In my case I thought of him as a "STALLER" for not more aggressively changing Emacs to keep up with GUIs, with better languages than elisp, with better ways to implement text buffers, and so forth. One day I woke up and realized: hey, I've been using this same damn program for 15 years (and now, today, more than 20). I use it every day. I'm annoyed on systems that lack it. It satisfies me, as a user, in ways that almost no other program I've used for a long time does. Aha - I realized. He must be doing something right. And it became way more interesting to try to understand what he's doing right than to focus exclusively on what he's doing wrong. On the documentation thing ... well: Stallman's code (and code descended from Stallman's code) tends to annoy me with its sparcity of good commenting, its long, convoluted functions, its sometimes wacky choices of how to structure module dependencies, its horrific approach to portability..... Problem is, though, than when I've had to actually work on any of that code? Yeah, it takes some hours or days of study to puzzle it out - weeks even - but then once you've "got it" you've got it. It's actually fairly lucid in spite of the style. One of the things he does right is not overly documenting the code. First, it's a lot of work. Second, the folks that wind up contributing the most to it learn a lot and learn it well by puzzling it out a bit first on their own. Yes, really. I'm not suggesting weak internals documentation and all the other aspects as a general style that everyone should adapt. I do think it slows some things down. Yet in some cases, like Emacs, .... well, it's hard to argue with success, ain't it? > All Richard Stallman has to do is to hand draw the data-structures and > architecture of the various programs. Give references to the places > where he got the ideas. Isn't that (the drawing) something you could do? As for where he got the ideas: a lot of Emacs architecture is based on common knowledge ideas, some on the order of 40 years old. There's not a lot that isn't original in the core architecture that one would normally want cites about. From thomas at jollans.com Sun Jul 18 13:43:44 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 19:43:44 +0200 Subject: [Python-Dev] Function Operators In-Reply-To: References: Message-ID: <4C433D50.70004@jollans.com> On 07/18/2010 05:52 PM, Reid Kleckner wrote: > Usual disclaimer: python-dev is for the development *of* python, not > *with*. See python-list, etc. Moving to python-list. Please keep discussion there. > > That said, def declares new functions or methods, so you can't put > arbitrary expressions in there like type(f).__mul__ . > > You can usually assign to things like that though, but in this case > you run into trouble, as shown below: > >>>> def func(): pass > ... >>>> type(func) > >>>> def compose(f, g): > ... return lambda x: f(g(x)) > ... >>>> type(func).__mul__ = compose > Traceback (most recent call last): > File "", line 1, in > TypeError: can't set attributes of built-in/extension type 'function' > > As the interpreter says, it doesn't like people mucking with operator > slots on built in types. > > Finally, if you like coding in that very functional style, I'd > recommend Haskell or other ML derived languages. Python doesn't > support that programming style very well by choice. > > Reid > > On Sun, Jul 18, 2010 at 8:34 AM, Christopher Olah > wrote: >> Dear python-dev, >> >> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >> times). I often run into situations in python where such operators >> could result in cleaner code. Eventually, I decided to implement it >> myself and see how it worked in practice. >> >> However, my intuitive implementation [1] doesn't seem to work. In >> particular, despite what it says in function's documentation, function >> does not seem to be in __builtin__. Furthermore, when I try to >> implement this through type(f) (where f is a function) I get invalid >> syntax errors. >> >> I hope I haven't made some trivial error; I'm rather inexperienced as >> a pythonist. >> >> Christopher Olah >> >> >> [1] Sketch: >> >> def __builtin__.function.__mul__(self, f): >> return lambda x: self(f(x)) >> >> def __builtin__.function.__pow__(self, n): >> return lambda x: reduce(lambda a,b: [f for i in range(n)]+[x]) As Reid explained, you can't just muck around with built-in types like that. However, you can "use a different type". If you're not familiar with Python decorators, look them up, and then have a look at this simple implementation of what you were looking for: >>> class mfunc: ... def __init__(self, func): ... self.func = func ... self.__doc__ = func.__doc__ ... self.__name__ = func.__name__ ... def __call__(self, *args, **kwargs): ... return self.func(*args, **kwargs) ... def __mul__(self, f2): ... @mfunc ... def composite(*a, **kwa): ... return self.func(f2(*a, **kwa)) ... return composite ... def __pow__(self, n): ... if n < 1: ... raise ValueError(n) ... elif n == 1: ... return self.func ... else: ... return self * (self ** (n-1)) ... >>> @mfunc ... def square(x): return x*x ... >>> @mfunc ... def twice(x): return 2*x ... >>> (square*twice)(1.5) 9.0 >>> addthree = mfunc(lambda x: x+3) >>> addfifteen = (addthree ** 5) >>> addfifteen(0) 15 >>> From python at bdurham.com Sun Jul 18 13:46:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 13:46:48 -0400 Subject: Print file via file association using os.system or subprocess? (Windows) Message-ID: <1279475208.25344.1385464451@webmail.messagingengine.com> Under Windows: Is there a way to print a file using the file's file extension association using either the os.system or subprocess modules (vs. win32 extensions)? Use case: print PDF or Office documents to default printer without having to distribute win32 extensions. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From christopherolah.co at gmail.com Sun Jul 18 14:48:04 2010 From: christopherolah.co at gmail.com (Christopher Olah) Date: Sun, 18 Jul 2010 14:48:04 -0400 Subject: [Python-Dev] Function Operators In-Reply-To: <4C433D50.70004@jollans.com> References: <4C433D50.70004@jollans.com> Message-ID: Firstly, apologies for posting to the wrong list. Since I was fiddling around with a modification to the language, if the implementation details of something I'd never expect to get accepted, I'd thought python-dev might be appropriate... In retrospect, it is fairly clear that it was the wrong choice. Secondly, the problem with using decorators is that it doesn't make it so that all functions do this by default. If one is going to decorate every function they use/declare, lambdas look preferable. In any case, thank you for your help. Christopher On Sun, Jul 18, 2010 at 1:43 PM, Thomas Jollans wrote: > On 07/18/2010 05:52 PM, Reid Kleckner wrote: >> Usual disclaimer: python-dev is for the development *of* python, not >> *with*. ?See python-list, etc. > > Moving to python-list. Please keep discussion there. > >> >> That said, def declares new functions or methods, so you can't put >> arbitrary expressions in there like type(f).__mul__ . >> >> You can usually assign to things like that though, but in this case >> you run into trouble, as shown below: >> >>>>> def func(): pass >> ... >>>>> type(func) >> >>>>> def compose(f, g): >> ... ? ? return lambda x: f(g(x)) >> ... >>>>> type(func).__mul__ = compose >> Traceback (most recent call last): >> ? File "", line 1, in >> TypeError: can't set attributes of built-in/extension type 'function' >> >> As the interpreter says, it doesn't like people mucking with operator >> slots on built in types. >> >> Finally, if you like coding in that very functional style, I'd >> recommend Haskell or other ML derived languages. ?Python doesn't >> support that programming style very well by choice. >> >> Reid >> >> On Sun, Jul 18, 2010 at 8:34 AM, Christopher Olah >> wrote: >>> Dear python-dev, >>> >>> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >>> times). I often run into situations in python where such operators >>> could result in cleaner code. Eventually, I decided to implement it >>> myself and see how it worked in practice. >>> >>> However, my intuitive implementation [1] doesn't seem to work. In >>> particular, despite what it says in function's documentation, function >>> does not seem to be in __builtin__. Furthermore, when I try to >>> implement this through type(f) (where f is a function) I get invalid >>> syntax errors. >>> >>> I hope I haven't made some trivial error; I'm rather inexperienced as >>> a pythonist. >>> >>> Christopher Olah >>> >>> >>> [1] Sketch: >>> >>> def __builtin__.function.__mul__(self, f): >>> ? ?return lambda x: self(f(x)) >>> >>> def __builtin__.function.__pow__(self, n): >>> ? ?return lambda x: reduce(lambda a,b: [f for i in range(n)]+[x]) > > > As Reid explained, you can't just muck around with built-in types like > that. However, you can "use a different type". > > If you're not familiar with Python decorators, look them up, and then > have a look at this simple implementation of what you were looking for: > >>>> class mfunc: > ... ? ? def __init__(self, func): > ... ? ? ? ? self.func = func > ... ? ? ? ? self.__doc__ = func.__doc__ > ... ? ? ? ? self.__name__ = func.__name__ > ... ? ? def __call__(self, *args, **kwargs): > ... ? ? ? ? return self.func(*args, **kwargs) > ... ? ? def __mul__(self, f2): > ... ? ? ? ? @mfunc > ... ? ? ? ? def composite(*a, **kwa): > ... ? ? ? ? ? ? return self.func(f2(*a, **kwa)) > ... ? ? ? ? return composite > ... ? ? def __pow__(self, n): > ... ? ? ? ? if n < 1: > ... ? ? ? ? ? ? raise ValueError(n) > ... ? ? ? ? elif n == 1: > ... ? ? ? ? ? ? return self.func > ... ? ? ? ? else: > ... ? ? ? ? ? ? return self * (self ** (n-1)) > ... >>>> @mfunc > ... def square(x): return x*x > ... >>>> @mfunc > ... def twice(x): return 2*x > ... >>>> (square*twice)(1.5) > 9.0 >>>> addthree = mfunc(lambda x: x+3) >>>> addfifteen = (addthree ** 5) >>>> addfifteen(0) > 15 >>>> > > > From tjreedy at udel.edu Sun Jul 18 15:10:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Jul 2010 15:10:34 -0400 Subject: [Python-Dev] Function Operators In-Reply-To: <4C433D50.70004@jollans.com> References: <4C433D50.70004@jollans.com> Message-ID: >> Christopher Olah >>> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >>> times). I often run into situations in python where such operators >>> could result in cleaner code. Python has a general mechanism for composing functions to make new functions: the def statement. "z = f*g" is a special case operation combining two compatible one-parameter parameter functions. In Python, it is spelled def z(x): return f(g(x)) The advantage of the latter is that it gives the resulting function object a definition name attached to the function as an attribute, which is important for error tracebacks. This gets to a difference between math and computing. In math, 'z=f*f', if it is not an equality claim ('z==f*g' in Python terms), defines 'z' to mean the *pre-existing*, abstract, attribute-less function that can also be denoted by 'f*g'. In Python (in particular), it would mean "create a *new*, anonymous function object and associate it non-exclusively with 'z'". If f and g are not primitive functions but are compositions themselves, then substituting the composition for g in the composition for f may allow for simplification and greater efficiency. This consideration is irrelevant in math, where computation happens instantaneously, or where f*g is simply a set of ordered pairs, just like f and g (all with instataneous lookup). As for f^n, it is very rare in practice for n to be a fixed value more than 2 or 3. For n==2, f^2 is simply f*f, see above. For n==3, def f3(x): return f(f(f(x))) has the advantage of creating one new function instead of two. I believe larger values of n mostly arise in iteration to a fixed point or until some other stopping point in reached. Terry Jan Reedy From news1234 at free.fr Sun Jul 18 18:10:45 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 00:10:45 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> Message-ID: <4c437be5$0$5702$426a74cc@news.free.fr> MRAB wrote: > News123 wrote: >> Thomas Jollans wrote: >> >>> >>>> string.rstrip( [ '-dir' ] ) >>>> or as >>>> string.rstrip( '-dir' ) >>> The former should certainly raise an exception. '-dir' is not a single >>> character ! >>> Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but >>> that's just silly. >>> >> It's silly with the example of '-dir' it's much less silly with >> a string like ' \t'. >> >> The doc is rather clear about it: >> str.rstrip([chars]) >> >> It is marked 'chars' and not 'suffix' >> >> The textual description is even clearer: >> "The chars argument is not a suffix; rather, all combinations of its >> values are stripped:" >> >> >> When I asked in this grpup about a way of how to strip off a prefix I >> never even considered strip as a solution having read the doc before. >> >> I also think, that the functionality of strip / rstrip is useful as is. >> >> >> It would just be great to have functions to strip prefixes/suffixes. >> If these new commands were alphabetically next to the classic commands, >> ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for >> string functions would probably use the function, which is appropriate >> for his purpose. >> >> Breaking backwardscompatibility within python 3 might not be the best >> choice. >> > [snip] > How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > similar? sounds reasonable to me From sturlamolden at yahoo.no Sun Jul 18 18:18:59 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 18 Jul 2010 15:18:59 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> On 18 Jul, 07:01, "be.krul" wrote: > why is this group being spammed? There used to be bots that issued cancel messages against spam, but I don't think they are actively maintained anymore. From kentilton at gmail.com Sun Jul 18 18:27:26 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Sun, 18 Jul 2010 18:27:26 -0400 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals In-Reply-To: References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: <4c437fcb$0$31260$607ed4bc@cv.net> Lawrence D'Oliveiro wrote: > In message > , Nick Keighley wrote: > >> On 16 July, 09:24, Mark Tarver wrote: >>> On 15 July, 23:21, bolega wrote: >>> >>>> http://www.gnu.org/philosophy/stallman-kth.html >>>> RMS lecture at KTH (Sweden), 30 October 1986 >> did you really have to post all of this... >> >> >> >>>> read more ?... >> ...oh sorry only about a third of it... > > Still totally unnecessary, though. > >>> Perhaps as an antidote >>> >>> http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi > > In other words, software that was developed at Symbolics was not given > way for free to LMI. Is that so surprising? > > Which is conceding Stallman?s point. > > Anyway, that wasn?t Symbolics?s ?plan?; it was part of the MIT licensing > agreement, the very same one that LMI signed. LMI?s changes were all > proprietary to LMI, too. > > I don?t understand this bit. The only ?MIT licensing agreement? I?m aware > off _allows_ you to redistribute your copies without the source, but doesn?t > _require_ it. > > Right, and this "fascinating" and "amazing" and "awesome" post needs only one rejoinder: twenty-four years later all we have is "free as in beer" software being milked by proprietary enterprises. Sadly, they would be more effective and more profitable if RMS had never existed, because then they would be paying fair market price for significantly better proprietary tools driven by the demands of a price/value competitive market. What we do not have is any interesting amount of "free as in speech" software, because no one uses the GPL. The LGPL is Stallman's way of saying, OK, I was wrong. kt -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From falk at green.rahul.net Sun Jul 18 18:58:45 2010 From: falk at green.rahul.net (Edward A. Falk) Date: Sun, 18 Jul 2010 22:58:45 +0000 (UTC) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: In article <334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, be.krul wrote: >why is this group being spammed? They're *all* being spammed. Why? Because they can, and because Google doesn't care. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From falk at green.rahul.net Sun Jul 18 18:59:54 2010 From: falk at green.rahul.net (Edward A. Falk) Date: Sun, 18 Jul 2010 22:59:54 +0000 (UTC) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: In article , Alf P. Steinbach /Usenet wrote: > >Consider, there would be almost no spam if spamming didn't pay. Or if ISPs refused to tolerate it from their customers. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From breamoreboy at yahoo.co.uk Sun Jul 18 19:08:54 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 19 Jul 2010 00:08:54 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On 18/07/2010 23:58, Edward A. Falk wrote: > In article<334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, > be.krul wrote: >> why is this group being spammed? > > They're *all* being spammed. Why? Because they can, and because Google > doesn't care. > I see little or nothing because I read through gmane.comp.python.general. Kindest regards. Mark Lawrence. From skippy.hammond at gmail.com Sun Jul 18 20:09:42 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 19 Jul 2010 10:09:42 +1000 Subject: Print file via file association using os.system or subprocess? (Windows) In-Reply-To: <1279475208.25344.1385464451@webmail.messagingengine.com> References: <1279475208.25344.1385464451@webmail.messagingengine.com> Message-ID: <4C4397C6.30605@gmail.com> On 19/07/2010 3:46 AM, python at bdurham.com wrote: > Under Windows: Is there a way to print a file using the file's file > extension association using either the os.system or subprocess modules > (vs. win32 extensions)? > Use case: print PDF or Office documents to default printer without > having to distribute win32 extensions. > Thanks, > Malcolm You probably want to use the windows ShellExec function with a 'print' verb. Mark From ethan at stoneleaf.us Sun Jul 18 20:31:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 18 Jul 2010 17:31:58 -0700 Subject: rstrip() In-Reply-To: <4C433087.8090403@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> <4C433087.8090403@mrabarnett.plus.com> Message-ID: <4C439CFE.6050406@stoneleaf.us> MRAB wrote: > [snip] > How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > similar? +1 on the names ~Ethan~ From python at bdurham.com Sun Jul 18 21:49:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 21:49:27 -0400 Subject: Print file via file association using os.system or subprocess? (Windows) In-Reply-To: <4C4397C6.30605@gmail.com> References: <1279475208.25344.1385464451@webmail.messagingengine.com> <4C4397C6.30605@gmail.com> Message-ID: <1279504167.26700.1385507775@webmail.messagingengine.com> Hi Mark, > You probably want to use the windows ShellExec function with a 'print' verb. Thanks Mark! And cheers for the great win32api library!! I've included a link[1] on how to do this for anyone searching the archives. Malcolm [1] Print via ShellExecute (prints to the user's default printer) http://timgolden.me.uk/python/win32_how_do_i/print.html#shellexecute Example: win32api.ShellExecute( 0, 'print', fileName, None, '.', 0 ) Under Windows: Is there a way to print a file using the file's file extension association using either the os.system or subprocess modules (vs. win32 extensions)? Use case: print PDF or Office documents to default printer without having to distribute win32 extensions. From python at bdurham.com Sun Jul 18 21:51:17 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 21:51:17 -0400 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr><4C433087.8090403@mrabarnett.plus.com> Message-ID: <1279504277.27617.1385508209@webmail.messagingengine.com> And don't forget the oft requested strip_tease(). Malcolm From f2h2d2 at gmail.com Sun Jul 18 23:12:37 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Sun, 18 Jul 2010 20:12:37 -0700 (PDT) Subject: Human Rights In An Islamic State Message-ID: <0b3b2bb8-ad0b-438c-9a78-c8e8339035bd@y11g2000yqm.googlegroups.com> Human Rights In An Islamic State Human Rights In An Islamic State 1. The Security Of Life And Property: In the address which the Prophet delivered on the occasion of the Farewell Hajj, he said: "Your lives and properties are forbidden to one another till you meet your Lord on the Day of Resurrection." The Prophet has also said about the dhimmis (the non-Muslim citizens of the Muslim state): "One who kills a man under covenant (i.e., dhimmi) will not even smell the fragrance of Paradise." 2. The Protection Of Honor: The Holy Quran lays down: "You who believe, do not let one (set of) people make fun of another set." "Do not defame one another." "Do not insult by using nicknames." "Do not backbite or speak ill of one another." (49:11-12) 3. Sanctity And Security Of Private Life: The Quran has laid down the injunction: "Do not spy on one another." (49:12) "Do not enter any houses unless you are sure of their occupant's consent." (24:27) 4. The Security Of Personal Freedom: Islam has laid down the principle that no citizen can be imprisoned unless his guilt has been proven in an open court. To arrest a man only on the basis of suspicion and to throw him into a prison without proper court proceedings and without providing him a reasonable opportunity to produce his defense is not permissible in Islam. 5. The Right To Protest Against Tyranny: Among the rights that Islam has conferred on human beings is the right to protest against government's tyranny. Referring to it the Quran says: "God does not love evil talk in public unless it is by someone who has been injured thereby." (4:148) In Islam, as has been argued earlier, all power and authority belong to God, and with man there is only delegated power which becomes a trust; everyone who becomes a recipient of such a power has to stand in awful reverence before his people toward whom and for whose sake he will be called upon to use these powers. This was acknowledged by Hazrat Abu Bakr who said in his very first address: "Cooperate with me when I am right but correct me when I commit error; obey me so long as I follow the commandments of Allah and His Prophet; but turn away from me when I deviate." 6. Freedom Of Expression: Islam gives the right of freedom of thought and expression to all citizens of the Islamic state on the condition that it should be used for the propagation of virtue and truth and not for spreading evil and wickedness. The Islamic concept of freedom of expression is much superior to the concept prevalent in the West. Under no circumstances would Islam allow evil and wickedness to be propagated. It also does not give anybody the right to use abusive or offensive language in the name of criticism. It was the practice of the Muslims to enquire from the Holy Prophet whether on a certain matter a divine injunction had been revealed to him. If he said that he had received no divine injunction, the Muslims freely expressed their opinion on the matter. 7. Freedom Of Association: Islam has also given people the right to freedom of association and formation of parties or organizations. This right is also subject to certain general rules. 8. Freedom Of Conscience And Conviction: Islam has laid down the injunction: "There should be no coercion in the matter of faith." (2:256) On the contrary, totalitarian societies totally deprive the individuals of their freedom. Indeed, this undue exaltation of the state authority curiously enough postulates a sort of servitude, of slavishness on the part of man. At one time slavery meant total control of man over man - now that type of slavery has been legally abolished but in its place totalitarian societies impose a similar sort of control over individuals. 9. Protection Of Religious Sentiments: Along with the freedom of conviction and freedom of conscience, Islam has given the right to the individual that his religious sentiments will be given due respect and nothing will be said or done which may encroach upon his right. 10. Protection From Arbitrary Imprisonment: Islam also recognizes the right of the individual not to be arrested or imprisoned for the offenses of others. The Holy Quran has laid down this principle clearly: "No bearer of burdens shall be made to bear the burden of another." (35:18) 11. The Right To Basic Necessities of Life: Islam has recognized the right of the needy people for help and assistance to be provided to them: "And in their wealth there is acknowledged right for the needy and the destitute." (51:19) 12. Equality Before Law: Islam gives its citizens the right to absolute and complete equality in the eyes of the law. 13. Rulers Not Above The Law: A woman belonging to a high and noble family was arrested in connection with theft. The case was brought to the Prophet, and it was recommended that she might be spared the punishment of theft. The Prophet replied: "The nations that lived before you were destroyed by God because they punished the common man for their offenses and let their dignitaries go unpunished for their crimes; I swear by Him Who holds my life in His hand that even if Fatima, the daughter of Muhammad, had committed this crime, I would have amputated her hand." 14. The Right To Participate In The Affairs Of State: "And their business is (conducted) through consultation among themselves." (42:38) The "Shura" or the legislative assembly has no other meaning except that the executive head of the government and the members of the assembly should be elected by free and independent choice of the people. Lastly, it is to be made clear that Islam tries to achieve the above mentioned human rights and many others not only by providing certain legal safeguards but mainly by inviting mankind to transcend the lower level of animal life to be able to go beyond the mere ties fostered by the kinship of blood, racial superiority, linguistic arrogance, and economic privileges. It invites mankind to move on to a plane of existence where, by reason of his inner excellence, man can realize the ideal of the Brotherhood of man. From eldiener at tropicsoft.invalid Mon Jul 19 00:53:56 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 00:53:56 -0400 Subject: Difference between import in script and from interpreter Message-ID: In a python script a: from xxx.yyy.zzz import aaa fails with the message: "ImportError: No module named xxx.yyy.zzz" but from within the python interpreter the same line succeeds. What would be the causes of that ? From within the python interpreter I have looked at sys.path and xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am not sure why this is failing within the python script. From steve-REMOVE-THIS at cybersource.com.au Mon Jul 19 01:15:25 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 19 Jul 2010 05:15:25 GMT Subject: Difference between import in script and from interpreter References: Message-ID: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote: > In a python script a: > > from xxx.yyy.zzz import aaa > > fails with the message: > > "ImportError: No module named xxx.yyy.zzz" > > but from within the python interpreter the same line succeeds. What > would be the causes of that ? > > From within the python interpreter I have looked at sys.path and > xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am > not sure why this is failing within the python script. And how is sys.path different when you run it as a script? -- Steven From news1234 at free.fr Mon Jul 19 03:06:09 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 09:06:09 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> <4C433087.8090403@mrabarnett.plus.com> Message-ID: <4c43f962$0$3717$426a74cc@news.free.fr> Dennis Lee Bieber wrote: > On Sun, 18 Jul 2010 17:49:11 +0100, MRAB > declaimed the following in gmane.comp.python.general: > >> How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > > Not sure what the first would do... unless one is envisioning > > "abracadabra".strip_str("abra")... > > For the others... trim_suffix, trim_prefix are more explicit in > meaning -- after all, someone might ask if there is an *strip_unicode > too! (or _bytes). That still leaves the question of what the desired > behavior of > > "Shanana".trim_suffix("na") > > is to produce? "Sha" or "Shana"? > > What I'd imagine would be stripping of a suffix or the first match in a list of suffixes exactly once. TO me this seems the most common use case, though one is surprised how functions can be used. Example: def strip_suffix(str,*suffixes): for suffix in suffixes: if str.endswith(suffix): return str[-len(suffix):] return str From news1234 at free.fr Mon Jul 19 03:10:24 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 09:10:24 +0200 Subject: Difference between import in script and from interpreter In-Reply-To: References: Message-ID: <4c43fa60$0$3717$426a74cc@news.free.fr> Edward Diener wrote: > In a python script a: > > from xxx.yyy.zzz import aaa > > fails with the message: > > "ImportError: No module named xxx.yyy.zzz" > > but from within the python interpreter the same line succeeds. What > would be the causes of that ? > > From within the python interpreter I have looked at sys.path and > xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am > not sure why this is failing within the python script. Probably your problem is, that you call a python script, which is NOT located in the current working directlory. if you type python then imports will be relative to your current working directory if you execute a script imports will be relative to the scripts location. no idea in which directory you are when starting python from a windows menu. you can set PYTHONPATH to point to the base directory of your project if you want to be sure to always find your modules From gnuist006 at gmail.com Mon Jul 19 03:11:37 2010 From: gnuist006 at gmail.com (bolega) Date: Mon, 19 Jul 2010 00:11:37 -0700 (PDT) Subject: Emacs Time Line, Graphical Chart by Jamie Zawinski - Valuable Resource for Newbies - written: 8-Mar-1999, updated: 29-Oct-2007 Message-ID: <411df585-3bf4-4640-ab8f-50282c3b47a8@k39g2000yqb.googlegroups.com> Many newbies would find this one by Jamie Zawinski, of immense help http://www.jwz.org/doc/emacs-timeline.html written: 8-Mar-1999, updated: 29-Oct-2007 For more detail about the early days, please see Bernie Greenberg's paper, Multics Emacs: The History, Design and Implementation. I've drawn lines only where code is shared, not merely ideas. 1976 TECMAC and TMACS a pair of "TECO-macro realtime editors." by Guy Steele, Dave Moon, Richard Greenblatt, Charles Frankston, et al. | | 1976 EMACS by Richard Stallman, Guy Steele, EINE (EINE Is Not EMACS) and Dave Moon. by Dan Weinreb. Merger of TECMAC and TMACS, plus for MIT Lisp Machine. a dynamic loader and Meta-key cmds. First Emacs written in Lisp. Ran on ITS and TWENEX (Tops-20) | written in TECO and PDP 10 assembly. | | | 1978 Multics Emacs ZWEI (ZWEI Was EINE Initially) by Bernie Greenberg. by Dan Weinreb and Mike McMahon. written in MacLisp; | also used Lisp as its | extension language. | 1980 ZMACS (direct descendant of ZWEI) on Symbolics LM-2, LMI LispM, and later, TI Explorer (1983-1989) 1981 Gosling Emacs : by James Gosling : written in C; with "Mocklisp" as its extension language. / | 1983 / | / Unipress Emacs (6-may-83) / $395 commercial product. 1984 / Hemlock / by Bill Chiles, / Rob MacLachlan, et al. 1985 GNU Emacs 13.0? (20-mar-85) written in Spice Lisp by Richard Stallman. (CMU Common Lisp) initial public release? : | : GNU Emacs 15.10 (11-apr-85) : | GNU Emacs 15.34 (07-may-85) | GNU Emacs 16.56 (15-jul-85) (Gosling code expunged for copyright reasons) | | GNU Emacs 16.60 (19-sep-85) (contained first patches from the net, including preliminary SYSV support) | | GNU Emacs 17.36 (20-dec-85) (included TeX manual; first version that worked on SYSV out of the box) | | 1986 GNU Emacs 18.24 beta (02-oct-86) | 1987 GNU Emacs 18.41 (22-mar-87) | GNU Emacs 18.45 (02-jun-87) | GNU Emacs 18.49 (18-sep-87) | \ | \________________________________________________ | \ | \ | Early work on Epoch begins (1987) | by Alan M. Carroll 1988 GNU Emacs 18.50 (13-feb-88) | | | GNU Emacs 18.51 (07-may-88) | | | GNU Emacs 18.52 (01-sep-88) | | Epoch 1.0 (14-dec-88) | by Alan M. Carroll with Simon Kaplan 1989 GNU Emacs 18.53 (24-feb-89) | | \ | | \________________________________________________ | _____ | | \ GNU Emacs 18.54 (26-apr-89) | \ | | \ GNU Emacs 18.55 (23-aug-89) | \ | | | \ | | | NEmacs 3.2.1 (15-dec-89) | | | "Nihongo Emacs": a fork | | | with multi-byte Japanese | | | language support. | | | | | | Epoch 2.0 (23-dec-89) | | | | | | | | | 1990 | | Epoch 3.1 (06-feb-90) | | | | | | \ | NEmacs 3.3.1 (3-mar-90) | \ | | | \ Epoch 3.2 (11-dec-90) | | \ last Carroll release. | | \____ (sporadic work on | | | GNU Emacs 19 begins) | | | | | | | | | | | | Epoch 4.0 (27-aug-90) | | | Now maintained by NCSA. | | | | | 1991 GNU Emacs 18.57 (??-jan-91) | | | | | | | GNU Emacs 18.58 (??-???-91) | | | | | | | 1992 | |___ | MULE 0.9.0b (4-mar-92) | | \ | "Multilingual | | \ | Enhancements to Emacs": | | \ | support for input methods | | \ | and various languages | | Lucid Emacs 19.0 (??-apr-92) | including Japanese, | | by Jamie Zawinski et al. | Chinese, Korean, Greek, | | | | Hebrew, and Cyrillic. | | Lucid Emacs 19.1 (04-jun-92) | | | | | | | | | Lucid Emacs 19.2 (19-jun-92) | | | | | | | | | Lucid Emacs 19.3 (09-sep-92) | | GNU Emacs 18.59 (31-oct-92) | | | | | | | | | 1993 | / Lucid Emacs 19.4 (21-jan-93) | | | / | | | | / Lucid Emacs 19.5 (05-feb-93) | | | / (trade-show giveaway CD only) | | | / | | | | ____________/ Lucid Emacs 19.6 (09-apr-93) | | | / | | | | / | | | GNU Emacs 19.7 beta (22-may-93) | /| | first public v19 beta | / | | | | / | ...___ | GNU Emacs 19.8 beta (27-may-93) | / | \ | | \ | / | \ | | \________________ | ___________________/ | MULE 1.0 (1-aug-93) | \ | / | (based on GNU Emacs 18.59) | Lucid Emacs 19.8 (06-sep-93) | | | (Epoch merger, preliminary | | | I18N support) | | | | | | GNU Emacs 19.22 beta (28-nov-93) | | | | | | | 1994 | Lucid Emacs 19.9 (12- may-94) / | | (scrollbars, Athena) / | | | / | GNU Emacs 19.23 beta (17-may-94) | / | | \ | / | | \____________ | ___________________/ | | \ | / | | Lucid Emacs 19.10 (27- may-94) | | last JWZ release. | | | | GNU Emacs 19.24 beta (16-may-94) | | | | ...___ | | | \ | | | \ | | | MULE 2.0 (6-aug-94) | | (based on GNU Emacs 19.25) | | | | XEmacs 19.11 (13- sep-94) | | Lucid Emacs -> XEmacs renaming. | | now maintained by Chuck Thompson | | and Ben Wing. | | | | GNU Emacs 19.27 beta (14-sep-94) | | | | | GNU Emacs 19.28 (01-nov-94) | | first official v19 release. | ...___ | | | \ | | | \ | | | MULE 2.2 (28-dec-94) | | (based on GNU Emacs 19.28) | | | | | | 1995 | | MULE 2.3 (24-jul-95) | | . | XEmacs 19.12 (23- jun-95) . | (tty support) \ . GNU Emacs 19.29 (21-jun-95) | \ . | | (work on 20.x begins) . GNU Emacs 19.30 (24-nov-95) | : . | \ | : . | \_____________ | . | \ | . | XEmacs 19.13 (01- sep-95) . 1996 GNU Emacs 19.31 (25-may-96) | . | XEmacs 19.14 (23- jun-96) . GNU Emacs 19.34 (21-aug-96) | \ . 1997 | XEmacs 20.0 (09-feb-97) \ . | now maintained by \ . | Steve Baur. | . | | XEmacs 19.15 (26- mar-97) . | | | . | XEmacs 20.1 (15-apr-97) | . | | | . | XEmacs 20.2 (16-may-97) | . GNU Emacs 20.1 (17-sep-97) | | . | | | . GNU Emacs 20.2 (20-sep-97) | | . | | XEmacs 19.16 (31- oct-97) . | | . | XEmacs 20.3 (21- nov-97) . | | / | | ________________________________/ | | / | | / 1998 | XEmacs 20.4 (28-feb-98) | first reasonably stable | release with MULE support. | XEmacs "core" and "packages" | now packaged separately. | | | | | XEmacs 21.0-pre5 (18-jul-98) | Numbering scheme goes wonky due to | switch to stable + unstable branches. GNU Emacs 20.3 (19-aug-98) | | | | XEmacs 21.0.60 (10-dec-98) | / \___________________ | / \ 1999 | / XEmacs 21.2.9 (03- feb-99) | / (trunk / unstable branch) | / | | XEmacs 21.1.3 (26-jun-99) | | (stable / maintenance branch) | | maintained by Vin Shelton. | | | | GNU Emacs 20.4 (12-jul-99) | | | | | 2000 | | XEmacs 21.2.27 (18-jan-00) | | | | XEmacs 21.1.9 (13-feb-00) | | | | GNU Emacs 21.1 (20-oct-01) | XEmacs 21.2.36 (04-oct-00) | | | 2001 | XEmacs 21.1.14 (27-jan-01) | | (branch retired) | | XEmacs 21.2.40 (08-jan-01) | ____________________/ | | / | | / XEmacs 21.5.0 (18-apr-01) | / (trunk / unstable branch) | / | | XEmacs 21.4.0 (16-apr-01) | | (stable / maintenance branch) | | Maintained by Stephen Turnbull. | | Shipped by Red Hat, Debian, | | Mandrake, etc. | | | | 2002 GNU Emacs 21.2 (16-mar-02) | XEmacs 21.5.6 (05-apr-02) | | | | XEmacs 21.4.7 (04-may-02) | | | | 2003 | XEmacs 21.4.12 (15-jan-03) | | first "stable" 21.4 | | | | GNU Emacs 21.3 (19-mar-03) | | | | | | XEmacs 21.4.13 (25-may-03) | | maintained by Vin Shelton. | | | | | | XEmacs 21.5.14 (01-jun-03) | | | | XEmacs 21.4.14 (05-sep-03) | | | | | | XEmacs 21.5.16 (26-sep-03) 2004 | | | | XEmacs 21.4.15 (03-feb-04) | | | | | | XEmacs 21.5.18 (22-oct-04) | | | | XEmacs 21.4.17 (06-feb-05) | 2005 | | | GNU Emacs 21.4a (17-feb-05) | XEmacs 21.5.19 (18-feb-05) | | | | | XEmacs 21.5.23 (26-oct-05) | | | | XEmacs 21.4.18 (03-dec-05) | | | | | | XEmacs 21.5.24 (19-dec-05) | | | 2006 | XEmacs 21.4.19 (28-jan-06) | | | | | | XEmacs 21.5.28 (21-may-06) | | | XEmacs 21.4.20 (09-dec-06) | | GNU Emacs 22.1 (02-jun-07) | | 2007 XEmacs 21.4.21 (14-oct-07) From nick_keighley_nospam at hotmail.com Mon Jul 19 03:27:33 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Mon, 19 Jul 2010 00:27:33 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <12697207-f70c-4f6d-8be3-e326e4dbaddf@k19g2000yqc.googlegroups.com> On 18 July, 09:38, Emmy Noether wrote: > On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: > > Emmy Noether writes: > > > In this video, Stall man makes 4 promises to public but stalls on 2nd > > > of them. > > > I have no idea of the rights or wrongs of this case. ?But I've found > > through experience that when someone uses a "witty" misspelling of > > someone's name, they are almost always the one in the wrong. ? > > Huh, you forgot that the whole of GNU = Gnu Not Unix you know someone named GNU? They must have had strange parents... From vladaspams at gmail.com Mon Jul 19 03:41:17 2010 From: vladaspams at gmail.com (Vladimir Jovic) Date: Mon, 19 Jul 2010 09:41:17 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: Alf P. Steinbach /Usenet wrote: > #include // PyWeakPtr, PyPtr, PyModule, > PyClass > using namespace progrock; > > namespace { > using namespace cppy; > > struct Noddy > { > PyPtr first; > PyPtr last; > int number; > > Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) > : number( 0 ) > { > devsupport::suppressUnusedWarning( pySelf ); > > PyWeakPtr pFirstName = 0; > PyWeakPtr pLastName = 0; > > static char* kwlist[] = { "first", "last", "number", 0 }; > > ::PyArg_ParseTupleAndKeywords( > args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, > pointerTo( pFirstName ), pointerTo( pLastName ), &number > ) > >> Accept< IsNonZero >() > || throwX( "Invalid args" ); > > if( pFirstName != 0 ) { first = pFirstName; } > if( pLastName != 0 ) { last = pLastName; } Why not initiallize all member variables in the initializer list? > } > > PyPtr name() > { > (first != 0) > || throwX( ::PyExc_AttributeError, "first" ); > (last != 0) > || throwX( ::PyExc_AttributeError, "last" ); Nice trick. I would still find this more readable : if ( first != 0 ) { throwX( ::PyExc_AttributeError, "first" ); } > return (PyString( first ) + L" " + PyString( last )).pyPtr(); > } > }; > > struct NoddyPyClass: PyClass< Noddy > > { > NoddyPyClass( PyModule& m, PyString const& name, PyString const& > doc ) > : PyClass< Noddy >( m, name, doc, Exposition() > .method( > L"name", CPPY_GLUE( name ), > L"Return the name, combining the first and last name" > ) > .attribute( > L"first", CPPY_GLUE( first ), L"first name" > ) > .attribute( > L"last", CPPY_GLUE( last ), L"last name" > ) > .attribute( > L"number", CPPY_GLUE( number ), L"noddy number" > ) > ) > {} > }; > > class NoddyModule: public PyModule > { > private: > NoddyPyClass noddyPyClass_; > > public: > NoddyModule() > : PyModule( > L"noddy2", L"Example module that creates an extension > type." ) > , noddyPyClass_( *this, > L"Noddy", L"A Noddy object has a name and a noddy number" ) hmmm what is L ? From alf.p.steinbach+usenet at gmail.com Mon Jul 19 04:21:52 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 10:21:52 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: * Vladimir Jovic, on 19.07.2010 09:41: > Alf P. Steinbach /Usenet wrote: > >> #include // PyWeakPtr, PyPtr, PyModule, >> PyClass >> using namespace progrock; >> >> namespace { >> using namespace cppy; >> >> struct Noddy >> { >> PyPtr first; >> PyPtr last; >> int number; >> >> Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) >> : number( 0 ) >> { >> devsupport::suppressUnusedWarning( pySelf ); >> >> PyWeakPtr pFirstName = 0; >> PyWeakPtr pLastName = 0; >> >> static char* kwlist[] = { "first", "last", "number", 0 }; >> >> ::PyArg_ParseTupleAndKeywords( >> args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, >> pointerTo( pFirstName ), pointerTo( pLastName ), &number >> ) >> >> Accept< IsNonZero >() >> || throwX( "Invalid args" ); >> >> if( pFirstName != 0 ) { first = pFirstName; } >> if( pLastName != 0 ) { last = pLastName; } > > Why not initiallize all member variables in the initializer list? 'PyPtr' is a smart pointer with default constructor, so 'first' and 'last' are initialized to zero implicitly. My goal was to emulate the Python 3.1.1 docs' Noddy2 example as closely as possible. And that code's assignment of zero to 'first' and 'last' here corresponds to default initialization to zero. :-) Anyway, parsing the Python arguments in the constructor initializer list is possible, but would be inefficient to do directly since it would then involve parsing the Python arguments three times (once for each data member). There is at least one way around that problem, namely outfitting a derived class with knowledge of the Noddy class' Python-side __init__ arguments. But I haven't implemented such support, and I don't know if it would do any good. As it is Noddy above is self-contained, except for exporting names to the Python side. With a derived class doing the argument parsing it would be less self-contained, and the machinery for that would add complexity, I think. So, I strive to make things simple and explicit (KISS: Keep It Simple, Stupid!). And I strive to not go into orgies of smart templates doing things implicitly... >> } >> >> PyPtr name() >> { >> (first != 0) >> || throwX( ::PyExc_AttributeError, "first" ); >> (last != 0) >> || throwX( ::PyExc_AttributeError, "last" ); > > Nice trick. I would still find this more readable : > > if ( first != 0 ) > { > throwX( ::PyExc_AttributeError, "first" ); > } Ah, well. :-) You can read about the rationale here: -- posted yesterday. Of course the only reason that those member variables /can/ be 0 is because I'm following the doc's progression of examples. The next version in the docs avoid the 0 possibility, as I recall. And the simple way of achieving that in cppy would be to declare 'first' and 'last' as PyString instead of generic PyPtr... >> return (PyString( first ) + L" " + PyString( last )).pyPtr(); >> } >> }; >> >> struct NoddyPyClass: PyClass< Noddy > >> { >> NoddyPyClass( PyModule& m, PyString const& name, PyString >> const& doc ) >> : PyClass< Noddy >( m, name, doc, Exposition() >> .method( >> L"name", CPPY_GLUE( name ), >> L"Return the name, combining the first and last name" >> ) >> .attribute( >> L"first", CPPY_GLUE( first ), L"first name" >> ) >> .attribute( >> L"last", CPPY_GLUE( last ), L"last name" >> ) >> .attribute( >> L"number", CPPY_GLUE( number ), L"noddy number" >> ) >> ) >> {} >> }; >> >> class NoddyModule: public PyModule >> { >> private: >> NoddyPyClass noddyPyClass_; >> >> public: >> NoddyModule() >> : PyModule( >> L"noddy2", L"Example module that creates an extension >> type." ) >> , noddyPyClass_( *this, >> L"Noddy", L"A Noddy object has a name and a noddy >> number" ) > > > hmmm what is L ? It's standard C and C++ notation for a wide character literal, where each character is of type 'wchar_t' instead of plain 'char'. Essentially the intent is to hold Unicode UTF16 or UTF32 code points, which is how it is in practice, although for political correctness the C and C++ standards allow for other wide character encodings (not necessarily Unicode). It is the only way to /portably/ use national character literals in C++, because otherwise the result depends on the source code encoding. E.g. sizeof( "?" ) yields 2 (the character '?' plus a zero byte at the end) with source code in Windows ANSI Western, and 3 with source code in UTF8, while sizeof( L"?" )/sizeof( wchar_t ) should in practice -- with Unicode wide chars -- always yield 2, namely the wide character encoding of '?' plus a zero wchar_t. The Python C API generally assumes that all 'char' strings are encoded in UTF8, while in Windows they're generally in Windows ANSI Western, so, I avoid that. Cheers, & thanks, - Alf -- blog at From debatem1 at gmail.com Mon Jul 19 04:22:19 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 19 Jul 2010 01:22:19 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <87oce4hmda.fsf@lola.goethe.zz> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> <87oce4hmda.fsf@lola.goethe.zz> Message-ID: On Sun, Jul 18, 2010 at 7:53 AM, David Kastrup wrote: > ? ?File: elisp, ?Node: Writing Emacs Primitives, ?Next: Object Internals, ?Prev: Memory Usage, ?Up: GNU Emacs Internals > > ? ?E.5 Writing Emacs Primitives > ? ?============================ > > ? ?Lisp primitives are Lisp functions implemented in C. ?The details of > ? ?interfacing the C function so that Lisp can call it are handled by a few > ? ?C macros. ?The only way to really understand how to write new C code is > ? ?to read the source, but we can explain some things here. > > ? ? ? An example of a special form is the definition of `or', from > ? ?`eval.c'. ?(An ordinary function would have the same general > ? ?appearance.) > > ? ? ? ? DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > ? ? ? ? ? doc: /* Eval args until one of them yields non-nil, then return that > ? ? ? ? value. The remaining args are not evalled at all. > ? ? ? ? If all args return nil, return nil. > ? ? ? ? usage: (or CONDITIONS ...) ?*/) > ? ? ? ? ? (Lisp_Object args) > ? ? ? ? { > ? ? ? ? ? register Lisp_Object val = Qnil; > ? ? ? ? ? struct gcpro gcpro1; > > ? ? ? ? ? GCPRO1 (args); > > ? ? ? ? ? while (CONSP (args)) > ? ? ? ? ? ? { > ? ? ? ? ? ? ? val = Feval (XCAR (args)); > ? ? ? ? ? ? ? if (!NILP (val)) > ? ? ? ? ? ? ? ? break; > ? ? ? ? ? ? ? args = XCDR (args); > ? ? ? ? ? ? } > > ? ? ? ? ? UNGCPRO; > ? ? ? ? ? return val; > ? ? ? ? } > > ? ? ? Let's start with a precise explanation of the arguments to the > ? ?`DEFUN' macro. ?Here is a template for them: > > ? ? ? ? DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC) > > ? ?LNAME > ? ? ? ? This is the name of the Lisp symbol to define as the function > ? ? ? ? name; in the example above, it is `or'. > > ? ?FNAME > ? ? ? ? This is the C function name for this function. ?This is the name > ? ? ? ? that is used in C code for calling the function. ?The name is, by > ? ? ? ? convention, `F' prepended to the Lisp name, with all dashes (`-') > ? ? ? ? in the Lisp name changed to underscores. ?Thus, to call this > ? ? ? ? function from C code, call `For'. ?Remember that the arguments must > ? ? ? ? be of type `Lisp_Object'; various macros and functions for creating > ? ? ? ? values of type `Lisp_Object' are declared in the file `lisp.h'. > > ? ?SNAME > ? ? ? ? This is a C variable name to use for a structure that holds the > ? ? ? ? data for the subr object that represents the function in Lisp. > ? ? ? ? This structure conveys the Lisp symbol name to the initialization > ? ? ? ? routine that will create the symbol and store the subr object as > ? ? ? ? its definition. ?By convention, this name is always FNAME with `F' > ? ? ? ? replaced with `S'. > > ? ?MIN > ? ? ? ? This is the minimum number of arguments that the function > ? ? ? ? requires. ?The function `or' allows a minimum of zero arguments. > > ? ?MAX > ? ? ? ? This is the maximum number of arguments that the function accepts, > ? ? ? ? if there is a fixed maximum. ?Alternatively, it can be `UNEVALLED', > ? ? ? ? indicating a special form that receives unevaluated arguments, or > ? ? ? ? `MANY', indicating an unlimited number of evaluated arguments (the > ? ? ? ? equivalent of `&rest'). ?Both `UNEVALLED' and `MANY' are macros. > ? ? ? ? If MAX is a number, it may not be less than MIN and it may not be > ? ? ? ? greater than eight. > > ? ?INTERACTIVE > ? ? ? ? This is an interactive specification, a string such as might be > ? ? ? ? used as the argument of `interactive' in a Lisp function. ?In the > ? ? ? ? case of `or', it is 0 (a null pointer), indicating that `or' > ? ? ? ? cannot be called interactively. ?A value of `""' indicates a > ? ? ? ? function that should receive no arguments when called > ? ? ? ? interactively. ?If the value begins with a `(', the string is > ? ? ? ? evaluated as a Lisp form. > > ? ?DOC > ? ? ? ? This is the documentation string. ?It uses C comment syntax rather > ? ? ? ? than C string syntax because comment syntax requires nothing > ? ? ? ? special to include multiple lines. ?The `doc:' identifies the > ? ? ? ? comment that follows as the documentation string. ?The `/*' and > ? ? ? ? `*/' delimiters that begin and end the comment are not part of the > ? ? ? ? documentation string. > > ? ? ? ? If the last line of the documentation string begins with the > ? ? ? ? keyword `usage:', the rest of the line is treated as the argument > ? ? ? ? list for documentation purposes. ?This way, you can use different > ? ? ? ? argument names in the documentation string from the ones used in > ? ? ? ? the C code. ?`usage:' is required if the function has an unlimited > ? ? ? ? number of arguments. > > ? ? ? ? All the usual rules for documentation strings in Lisp code (*note > ? ? ? ? Documentation Tips::) apply to C code documentation strings too. > > ? ? ? After the call to the `DEFUN' macro, you must write the argument > ? ?list that every C function must have, including the types for the > ? ?arguments. ?For a function with a fixed maximum number of arguments, > ? ?declare a C argument for each Lisp argument, and give them all type > ? ?`Lisp_Object'. ?When a Lisp function has no upper limit on the number > ? ?of arguments, its implementation in C actually receives exactly two > ? ?arguments: the first is the number of Lisp arguments, and the second is > ? ?the address of a block containing their values. ?They have types `int' > ? ?and `Lisp_Object *'. > > ? ? ? Within the function `For' itself, note the use of the macros > ? ?`GCPRO1' and `UNGCPRO'. ?`GCPRO1' is used to "protect" a variable from > ? ?garbage collection--to inform the garbage collector that it must look > ? ?in that variable and regard its contents as an accessible object. ?GC > ? ?protection is necessary whenever you call `Feval' or anything that can > ? ?directly or indirectly call `Feval'. ?At such a time, any Lisp object > ? ?that this function may refer to again must be protected somehow. > > ? ? ? It suffices to ensure that at least one pointer to each object is > ? ?GC-protected; that way, the object cannot be recycled, so all pointers > ? ?to it remain valid. ?Thus, a particular local variable can do without > ? ?protection if it is certain that the object it points to will be > ? ?preserved by some other pointer (such as another local variable which > ? ?has a `GCPRO')(1). ?Otherwise, the local variable needs a `GCPRO'. > > ? ? ? The macro `GCPRO1' protects just one local variable. ?If you want to > ? ?protect two variables, use `GCPRO2' instead; repeating `GCPRO1' will > ? ?not work. ?Macros `GCPRO3', `GCPRO4', `GCPRO5', and `GCPRO6' also > ? ?exist. ?All these macros implicitly use local variables such as > ? ?`gcpro1'; you must declare these explicitly, with type `struct gcpro'. > ? ?Thus, if you use `GCPRO2', you must declare `gcpro1' and `gcpro2'. > ? ?Alas, we can't explain all the tricky details here. > > ? ? ? `UNGCPRO' cancels the protection of the variables that are protected > ? ?in the current function. ?It is necessary to do this explicitly. > > ? ? ? Built-in functions that take a variable number of arguments actually > ? ?accept two arguments at the C level: the number of Lisp arguments, and > ? ?a `Lisp_Object *' pointer to a C vector containing those Lisp > ? ?arguments. ?This C vector may be part of a Lisp vector, but it need not > ? ?be. ?The responsibility for using `GCPRO' to protect the Lisp arguments > ? ?from GC if necessary rests with the caller in this case, since the > ? ?caller allocated or found the storage for them. > > ? ? ? You must not use C initializers for static or global variables unless > ? ?the variables are never written once Emacs is dumped. ?These variables > ? ?with initializers are allocated in an area of memory that becomes > ? ?read-only (on certain operating systems) as a result of dumping Emacs. > ? ?*Note Pure Storage::. > > ? ? ? Do not use static variables within functions--place all static > ? ?variables at top level in the file. ?This is necessary because Emacs on > ? ?some operating systems defines the keyword `static' as a null macro. > ? ?(This definition is used because those systems put all variables > ? ?declared static in a place that becomes read-only after dumping, whether > ? ?they have initializers or not.) > > ? ? ? Defining the C function is not enough to make a Lisp primitive > ? ?available; you must also create the Lisp symbol for the primitive and > ? ?store a suitable subr object in its function cell. ?The code looks like > ? ?this: > > ? ? ? ? defsubr (&SUBR-STRUCTURE-NAME); > > ? ?Here SUBR-STRUCTURE-NAME is the name you used as the third argument to > ? ?`DEFUN'. > > ? ? ? If you add a new primitive to a file that already has Lisp primitives > ? ?defined in it, find the function (near the end of the file) named > ? ?`syms_of_SOMETHING', and add the call to `defsubr' there. ?If the file > ? ?doesn't have this function, or if you create a new file, add to it a > ? ?`syms_of_FILENAME' (e.g., `syms_of_myfile'). ?Then find the spot in > ? ?`emacs.c' where all of these functions are called, and add a call to > ? ?`syms_of_FILENAME' there. > > ? ? ? The function `syms_of_FILENAME' is also the place to define any C > ? ?variables that are to be visible as Lisp variables. ?`DEFVAR_LISP' > ? ?makes a C variable of type `Lisp_Object' visible in Lisp. ?`DEFVAR_INT' > ? ?makes a C variable of type `int' visible in Lisp with a value that is > ? ?always an integer. ?`DEFVAR_BOOL' makes a C variable of type `int' > ? ?visible in Lisp with a value that is either `t' or `nil'. ?Note that > ? ?variables defined with `DEFVAR_BOOL' are automatically added to the list > ? ?`byte-boolean-vars' used by the byte compiler. > > ? ? ? If you define a file-scope C variable of type `Lisp_Object', you > ? ?must protect it from garbage-collection by calling `staticpro' in > ? ?`syms_of_FILENAME', like this: > > ? ? ? ? staticpro (&VARIABLE); > > ? ? ? Here is another example function, with more complicated arguments. > ? ?This comes from the code in `window.c', and it demonstrates the use of > ? ?macros and functions to manipulate Lisp objects. > > ? ? ? ? DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, > ? ? ? ? ? Scoordinates_in_window_p, 2, 2, > ? ? ? ? ? "xSpecify coordinate pair: \nXExpression which evals to window: ", > ? ? ? ? ? "Return non-nil if COORDINATES is in WINDOW.\n\ > ? ? ? ? COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ > ? ? ? ? ... > ? ? ? ? If they are on the border between WINDOW and its right sibling,\n\ > ? ? ? ? ? ?`vertical-line' is returned.") > ? ? ? ? ? (coordinates, window) > ? ? ? ? ? ? ?register Lisp_Object coordinates, window; > ? ? ? ? { > ? ? ? ? ? int x, y; > > ? ? ? ? ? CHECK_LIVE_WINDOW (window, 0); > ? ? ? ? ? CHECK_CONS (coordinates, 1); > ? ? ? ? ? x = XINT (Fcar (coordinates)); > ? ? ? ? ? y = XINT (Fcdr (coordinates)); > > ? ? ? ? ? switch (coordinates_in_window (XWINDOW (window), &x, &y)) > ? ? ? ? ? ? { > ? ? ? ? ? ? case 0: ? ? ? ? ? ? ? ? ? ? /* NOT in window at all. */ > ? ? ? ? ? ? ? return Qnil; > > ? ? ? ? ? ? case 1: ? ? ? ? ? ? ? ? ? ? /* In text part of window. */ > ? ? ? ? ? ? ? return Fcons (make_number (x), make_number (y)); > > ? ? ? ? ? ? case 2: ? ? ? ? ? ? ? ? ? ? /* In mode line of window. */ > ? ? ? ? ? ? ? return Qmode_line; > > ? ? ? ? ? ? case 3: ? ? ? ? ? ? ? ? ? ? /* On right border of window. ?*/ > ? ? ? ? ? ? ? return Qvertical_line; > > ? ? ? ? ? ? default: > ? ? ? ? ? ? ? abort (); > ? ? ? ? ? ? } > ? ? ? ? } > > ? ? ? Note that C code cannot call functions by name unless they are > ? ?defined in C. ?The way to call a function written in Lisp is to use > ? ?`Ffuncall', which embodies the Lisp function `funcall'. ?Since the Lisp > ? ?function `funcall' accepts an unlimited number of arguments, in C it > ? ?takes two: the number of Lisp-level arguments, and a one-dimensional > ? ?array containing their values. ?The first Lisp-level argument is the > ? ?Lisp function to call, and the rest are the arguments to pass to it. > ? ?Since `Ffuncall' can call the evaluator, you must protect pointers from > ? ?garbage collection around the call to `Ffuncall'. > > ? ? ? The C functions `call0', `call1', `call2', and so on, provide handy > ? ?ways to call a Lisp function conveniently with a fixed number of > ? ?arguments. ?They work by calling `Ffuncall'. > > ? ? ? `eval.c' is a very good file to look through for examples; `lisp.h' > ? ?contains the definitions for some important macros and functions. > > ? ? ? If you define a function which is side-effect free, update the code > ? ?in `byte-opt.el' which binds `side-effect-free-fns' and > ? ?`side-effect-and-error-free-fns' so that the compiler optimizer knows > ? ?about it. > > ? ? ? ---------- Footnotes ---------- > > ? ? ? (1) Formerly, strings were a special exception; in older Emacs > ? ?versions, every local variable that might point to a string needed a > ? ?`GCPRO'. > To me, this is amazing documentation. I would love it if there were something this explicit for the C API. Geremy Condra From jeanmichel at sequans.com Mon Jul 19 05:57:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 19 Jul 2010 11:57:32 +0200 Subject: Difference between import in script and from interpreter In-Reply-To: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> References: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> Message-ID: <4C44218C.6070802@sequans.com> Steven D'Aprano wrote: > On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote: > > >> In a python script a: >> >> from xxx.yyy.zzz import aaa >> >> fails with the message: >> >> "ImportError: No module named xxx.yyy.zzz" >> >> but from within the python interpreter the same line succeeds. What >> would be the causes of that ? >> >> From within the python interpreter I have looked at sys.path and >> xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am >> not sure why this is failing within the python script. >> > > And how is sys.path different when you run it as a script? > > > '' is not in sys.path when running a script. '' is in sys.path by default within a interpreter. JM From lepto.python at gmail.com Mon Jul 19 06:54:39 2010 From: lepto.python at gmail.com (oyster) Date: Mon, 19 Jul 2010 18:54:39 +0800 Subject: how to copy and move file with its attribute? Message-ID: I mean writeonly, hidden, system and so on attributes I use windows, but if possible, is there any method to do so in a crossplatfrom way? thanks From __peter__ at web.de Mon Jul 19 07:17:40 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jul 2010 13:17:40 +0200 Subject: how to copy and move file with its attribute? References: Message-ID: oyster wrote: > I mean writeonly, hidden, system and so on attributes > > I use windows, but if possible, is there any method to do so in a > crossplatfrom way? I can't check, but shutil.copy2() may do what you want. Peter From dhruvbird at gmail.com Mon Jul 19 07:18:48 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 04:18:48 -0700 (PDT) Subject: Accumulate function in python Message-ID: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Hello, I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] And would like to compute the cumulative sum of all the integers from index zero into another array. So for the array above, I should get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] What is the best way (or pythonic way) to get this. Regards, -Dhruv. From vlastimil.brom at gmail.com Mon Jul 19 07:21:08 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 19 Jul 2010 13:21:08 +0200 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: 2010/7/19 oyster : > I mean writeonly, hidden, system and so on attributes > > I use windows, but if possible, is there any method to do so in a > crossplatfrom way? > > thanks > -- > http://mail.python.org/mailman/listinfo/python-list > You may check to see several possibilities http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html Probably the shutil module might be appropriate for simple usecases. hth, vbr From nitinpawar432 at gmail.com Mon Jul 19 07:25:47 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Mon, 19 Jul 2010 16:55:47 +0530 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: Hi, you may want to do like this array=[0,1,2] sumArray = [] for element in range(0,len(array)): if element == 0 : sumArray.append(array[element]) else: sumArray.append((array[element] + sumArray[element-1])) and then you can recheck it Thanks, nitin On Mon, Jul 19, 2010 at 4:48 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Jul 19 07:28:35 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jul 2010 13:28:35 +0200 Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: dhruvbird wrote: > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. Homework? >>> def cumulative_sum(values, start=0): ... for v in values: ... start += v ... yield start ... >>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) [0, 1, 3, 4, 5, 5, 5, 7, 10] Peter From vlastimil.brom at gmail.com Mon Jul 19 07:40:29 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 19 Jul 2010 13:40:29 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: 2010/7/19 dhruvbird : > Hello, > ?I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > ?And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > ?What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. > -- Hi, just a straightworward, naive approach...: lst_int = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] acc_int = 0 output_lst = [] for i in lst_int: acc_int += i output_lst.append(acc_int) print output_lst vbr From mad.mick at gmx.de Mon Jul 19 08:14:15 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Mon, 19 Jul 2010 14:14:15 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: Am 19.07.2010 13:18, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. import copy import itertools def acc(items, copy=copy.deepcopy): items = iter(items) result = next(items) yield copy(result) for item in items: result += item yield copy(result) print list(acc([0, 1, 2, 1, 1, 0, 0, 2, 3])) print list(itertools.islice(acc(itertools.count()), 10)) print list(acc(['a', 'b', 'c'])) print list(acc([[a], [b], [c]])) Output: [0, 1, 3, 4, 5, 5, 5, 7, 10] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] ['a', 'ab', 'abc'] [[a], [a, b], [a, b, c]] Without copy.deepcopy() the last line would be: [[a, b, c], [a, b, c], [a, b, c]] The copy=copy.deepcopy parameter allows for things like this: >>> print list(acc([[a], [b], [c]], tuple)) [(a,), (a, b), (a, b, c)] or: >>> print list(acc([['a'], ['b'], ['f'], ['s'], ['c'], ['g']], max)) ['a', 'b', 'f', 's', 's', 's'] or: >>> data = [[0], [1], [2], [1], [1], [2], [3]] >>> print list(acc(data, lambda x: float(sum(x)) / float(len(x)))) [0.0, 0.5, 1.0, 1.0, 1.0, 1.1666666666666667, 1.4285714285714286] Endless possibilities in an endless universe. Regards, Mick. From python at lists.fastmail.net Mon Jul 19 08:32:06 2010 From: python at lists.fastmail.net (python at lists.fastmail.net) Date: Mon, 19 Jul 2010 14:32:06 +0200 Subject: decimal.Decimal formatting Message-ID: <1279542726.26482.1385575193@webmail.messagingengine.com> I have various decimals which eventually are written to an XML file. Requirements indicate a precision of 11. I am currently having some 'issues' with Decimal("0"). When using quantize(decimal.Decimal("1e-11")) the result is not 0.00000000000, but 1e-11. Personally I agree 1e-11 is a better notation than 0.00000000000, but I currently need the long one. Is there a way to overwrite the switch to the scientific notation? Apparently there is a switch in notation 'between' 1e-6 and 1e-7. Thijs From alf.p.steinbach+usenet at gmail.com Mon Jul 19 08:41:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 14:41:13 +0200 Subject: CPython 3.1.1 docs error in noddy3 example? Message-ID: "Extending and Embedding the Python Interpreter" ?2.1.2, the noddy3 extension module example, uses "S" as format character for string arguments in its call to PyArg_ParseTupleAndKeywords. This causes Noddy to only accept bytes as arguments, instead of strings (format "U"). I suspect this is a leftover from Python 2.x, where strings were bytes, and that this is a bug? Cheers, - Alf -- blog at From xr.lists at gmail.com Mon Jul 19 08:48:16 2010 From: xr.lists at gmail.com (Alex A.) Date: Mon, 19 Jul 2010 15:48:16 +0300 Subject: timing In-Reply-To: References: Message-ID: You could use pycallgraph module Regards, Alex Abushkevich -------------- next part -------------- An HTML attachment was scrubbed... URL: From eldiener at tropicsoft.invalid Mon Jul 19 08:53:53 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 08:53:53 -0400 Subject: Different python versions confusion under Windows Vista x64 Message-ID: In Windows Vista x64 I have installed python 2.6 64-bit version and python 3.1 64-bit version to separate folders. Within the command interpreter I add python 2.6 to the PATH. In the command interpreter, When I type python somescript.py with an import sys print (sys.version) in the script, it shows: 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] In the command interpreter if I type 'python' I see: Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32 Does anybody have any ideas why this is happening ? From alf.p.steinbach+usenet at gmail.com Mon Jul 19 09:15:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 15:15:10 +0200 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: * Edward Diener, on 19.07.2010 14:53: > In Windows Vista x64 I have installed python 2.6 64-bit version and > python 3.1 64-bit version to separate folders. Within the command > interpreter I add python 2.6 to the PATH. > > In the command interpreter, When I type python somescript.py with an > > import sys > print (sys.version) > > in the script, it shows: > > 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] > > In the command interpreter if I type 'python' I see: > > Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit > (AMD64)] on win32 > > Does anybody have any ideas why this is happening ? At a guess your description of what's happening is not entirely accurate. Although it could be, since Windows moves in mysterious ways. Please try the following commands in sequence, with no other commands: python -V echo %path% ftype python.file python somescript.py Then right-click the command interpreter's title bar to get edit menu. /Mark/ the text of your commands and results. Then /copy/ it to the clipboard (note: you can't use [Ctrl C] here, use the edit menu or just press Enter). Then post the commands and results here, /paste/ them into your message (e.g. [Ctrl V]). And then, if you haven't already figured it out, somebody probably will. :-) Cheers & hth., - Alf -- blog at From mistobaan at gmail.com Mon Jul 19 09:41:10 2010 From: mistobaan at gmail.com (Fabrizio Milo aka misto) Date: Mon, 19 Jul 2010 15:41:10 +0200 Subject: [ANN] Lupa 0.6 - Lua in Python In-Reply-To: <4C433F2B.8050706@behnel.de> References: <4C433F2B.8050706@behnel.de> Message-ID: This is very very interesting. Do you have any direct application of it ? I know games like World of Warcraft uses Lua as scripting language. Thanks. Fabrizio -------------------------- Luck favors the prepared mind. (Pasteur) From post at andre-bell.de Mon Jul 19 10:24:41 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Mon, 19 Jul 2010 16:24:41 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4C446029.2000501@andre-bell.de> On 07/19/2010 01:18 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. Maybe not pythonic, but straight-forward: >>> import numpy >>> numpy.cumsum(x) array([ 0, 1, 3, 4, 5, 5, 5, 7, 10]) An example with a class class CumulativeSum(object): def __init__(self, start=0): self._current = start def __call__(self, value): self._current += value return self._current >>> cummulative_sum = CumulativeSum(0) >>> map(cummulative_sum, x) [0, 1, 3, 4, 5, 5, 5, 7, 10] Dirty: current = 0 def cummulative_sum(value): global current current += value return current >>> map(cummulative_sum, x) [0, 1, 3, 4, 5, 5, 5, 7, 10] Weird: def cummulative_sum_reducer(x, y): x.append(x[-1] + y) return x >>> reduce(cummulative_sum_reducer, x, [0]) [0, 0, 1, 3, 4, 5, 5, 5, 7, 10] Cheers Andre From kwa at kuwata-lab.com Mon Jul 19 10:48:55 2010 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 19 Jul 2010 23:48:55 +0900 Subject: ANN: pyTenjin 0.9.0 - very fast and full-featured template engine Message-ID: I released pyTenjin 0.9.0 http://www.kuwata-lab.com/tenjin/ http://pypi.python.org/pypi/Tenjin/ This release contains a lot of enhancements and changes. Also you should read planned changes in the next release (1.0.0). See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes for details. Overview -------- pyTenjin is very fast and full-featured template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (nestable layout template, partial template, preprocessing, ...) * Google App Engine supported Documents --------- * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * Examples http://www.kuwata-lab.com/tenjin/pytenjin-examples.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Enhancements from 0.8.1 ----------------------- * Performance improved (about 5%). * (IMPORTANT!!) Fragment cache supported. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#fragment-cache for details. * (IMPORTANT!!) include() now takes keyword arguments as local variables. ex. * Add new module 'tenjin.gae'. * Add 'input' argument to tenjin.Template() to create template object without file. ex. input = "

Hello ${name}

" t = tenjin.Template(None, input=input) html = t.render({'name': 'World'}) * Add tenjin.Engine.add_template() to add template object explicitly. * User's guide (doc/users-guide.html) is rewrited entirely. * Add benchmark for Jinja2. Changes from 0.8.1 ------------------ * (IMPORTANT!!) It is strongly recommended to close 'if', 'for', 'while', ... by corresponding '#endif', '#endfor', '#endwhile', and so on. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes for details. * (IMPORTANT!!) Google App Engine support is changed. All you have to do is to call tenjin.gae.init() at first. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#google-appengine for details. * (IMPORTANT!!) tenjin.Engine is changed to share a cache storage between engines by default. This improves performance of Tenjin but your test scripts may get errors. If you get errors in your test scripts, clear cache storage for each test. def setUp(self): tenjin.Engine.cache.clear() If you prefer previous behaviour, set tenjin.Engine.cache to None. ## create new MarshalCacheStorage object for each engine tenjin.Engine.cache = None * Now you can set default template class to tenjin.Engine.templateclass. ex. tenjin.Engine.templateclass = MyTemplate * 'cache' argument of tenjin.Engine() is changed. [old behaviour] if 'cache' is None, cache template object into memory. [new behaviour] if 'cache' is None, use default cache storage. * Default preamble is changed from "print ''.join(_buf)" to "print(''.join(_buf))". * 'doc/faq.html' is integrated into 'doc/users-guide.html'. * All test scripts are changed to import oktest instead of unittest. Bug fixes --------- * Fixed to set correct file path of template object which is loaded from cache. * Fixed a bug that 'pytenjin -sbN' didn't trim line number on the last line Have fun! -- regards, makoto kuwata From steve at REMOVE-THIS-cybersource.com.au Mon Jul 19 10:49:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jul 2010 14:49:31 GMT Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4c4465fb$0$11101$c3e8da3@news.astraweb.com> On Mon, 19 Jul 2010 04:18:48 -0700, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] And would > like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] [pedant] The above are *lists*, not arrays. Python has arrays, but you have to call "import array" to get them. [/pedant] > What is the best way (or pythonic way) to get this. Others have given you a plethora of advanced, complicated and obscure ways to solve this question, but I haven't seen anyone give the simplest method (simple as in no tricks or advanced features): data = [0, 1, 2, 1, 1, 0, 0, 2, 3] csums = [] for x in data: if csums: y = x + csums[-1] else: y = x csums.append(y) We can save some code with the ternary operator: data = [0, 1, 2, 1, 1, 0, 0, 2, 3] csums = [] for x in data: csums.append((x + csums[-1]) if csums else x) Here's a version that writes the cumulative sum in place: data = [0, 1, 2, 1, 1, 0, 0, 2, 3] for i in range(1, len(data)): data[i] += data[i-1] -- Steven From stefan-usenet at bytereef.org Mon Jul 19 11:23:39 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Mon, 19 Jul 2010 17:23:39 +0200 Subject: decimal.Decimal formatting In-Reply-To: <1279542726.26482.1385575193@webmail.messagingengine.com> References: <1279542726.26482.1385575193@webmail.messagingengine.com> Message-ID: <20100719152339.GA4422@yoda.bytereef.org> python at lists.fastmail.net wrote: > I have various decimals which eventually are written to an XML file. > Requirements indicate a precision of 11. I am currently having some > 'issues' with Decimal("0"). When using > quantize(decimal.Decimal("1e-11")) the result is not 0.00000000000, but > 1e-11. > > Personally I agree 1e-11 is a better notation than 0.00000000000, but I > currently need the long one. Is there a way to overwrite the switch to > the scientific notation? Apparently there is a switch in notation > 'between' 1e-6 and 1e-7. Try: >>> format(Decimal("0"), ".11f") '0.00000000000' Stefan Krah From pjb at informatimago.com Mon Jul 19 11:42:33 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 19 Jul 2010 17:42:33 +0200 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> <4c437fcb$0$31260$607ed4bc@cv.net> Message-ID: <87mxtnjx5i.fsf@kuiper.lan.informatimago.com> Kenneth Tilton writes: > What we do not have is any interesting amount of "free as in speech" > software, because no one uses the GPL. I do. So far, I resist to calls to put my software in a less freedom-promoting license. Hey everybody! Switch from MIT or BSD to GPL! Now! -- __Pascal Bourguignon__ http://www.informatimago.com/ From WolfgangMeiners01 at web.de Mon Jul 19 11:52:56 2010 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Mon, 19 Jul 2010 17:52:56 +0200 Subject: Email =?ISO-8859-15?Q?f=FCr_Dich?= Message-ID: <4c4474d8$0$6777$9b4e6d93@newsspool3.arcor-online.net> Liebe Kirsten, ich liebe dich und freue mich, dass du bald auch Ferien hast. Wolfgang From dirk at plfn.invalid Mon Jul 19 12:10:23 2010 From: dirk at plfn.invalid (Deadly Dirk) Date: Mon, 19 Jul 2010 16:10:23 +0000 (UTC) Subject: Email =?iso-8859-1?b?Zvxy?= Dich References: <4c4474d8$0$6777$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Mon, 19 Jul 2010 17:52:56 +0200, Wolfgang Meiners wrote: > Liebe Kirsten, > > ich liebe dich und freue mich, dass du bald auch Ferien hast. > > Wolfgang Und die ganze Python gruppe liebt dich auch. -- The missionaries go forth to Christianize the savages - as if the savages weren't dangerous enough already. From homeusenet4 at brianhv.org Mon Jul 19 12:12:04 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Mon, 19 Jul 2010 16:12:04 +0000 (UTC) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. Now that Steven's given you the simple, pythonic way, I'll just mention the advanced, complicated and obscure way that might be vaguely familiar if you're coming from a functional programming background: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] def running_sum(result, current_value): return result + [result[-1]+current_value if result else current_value] reduce(running_sum, x, []) Having offered this, I don't recall ever seeing reduce used in real python code, and explicit iteration is almost always preferred. -- Brian From bayesianroom at googlemail.com Mon Jul 19 12:12:20 2010 From: bayesianroom at googlemail.com (li wang) Date: Mon, 19 Jul 2010 09:12:20 -0700 (PDT) Subject: mod_python load cx_Oracle error Message-ID: <73e34de4-a508-4d78-9d79-937c31c3d3ba@x2g2000prk.googlegroups.com> It's quite weird when I import cx_Oracle in python interactive shell, it works perfectly. but when I import cx_Oracle in a *,py script, handled by mod_python.publisher, it keep reportint : ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory Can I anyone have a clue what's the matter, any help would be appreciated! From zooko at zooko.com Mon Jul 19 12:31:24 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 19 Jul 2010 10:31:24 -0600 Subject: ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1 Message-ID: Folks: This innovative distributed filesystem is written entirely in Python. Well, actually we rely on some C/C++ extension code in Python packages like "zfec" and "pycryptopp" for some mathematical heavy lifting, but all of the code in the tahoe-lafs package is actually pure Python. Regards, Zooko ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1 The Tahoe-LAFS team is pleased to announce the immediate availability of version 1.7.1 of Tahoe-LAFS, an extremely reliable distributed storage system. Tahoe-LAFS is the first distributed storage system which offers "provider-independent security"?meaning that not even the operators of your storage servers can read or alter your data without your consent. Here is the one-page explanation of its unique security and fault-tolerance properties: http://tahoe-lafs.org/source/tahoe/trunk/docs/about.html Tahoe-LAFS v1.7.1 is the successor to v1.7.0, which was released June 18, 2010 [1]. v1.7.1 is a stable minor release which adds several bugfixes and improvements in security, forward-compatibility, packaging, usability, and portability. See the NEWS file [2] for details. WHAT IS IT GOOD FOR? With Tahoe-LAFS, you distribute your filesystem across multiple servers, and even if some of the servers are compromised by by an attacker, the entire filesystem continues to work correctly, and continues to preserve your privacy and security. You can easily share specific files and directories with other people. In addition to the core storage system itself, volunteers have built other projects on top of Tahoe-LAFS and have integrated Tahoe-LAFS with existing systems. These include frontends for Windows, Macintosh, JavaScript, iPhone, and Android, and plugins for Hadoop, bzr, mercurial, duplicity, TiddlyWiki, and more. See the Related Projects page on the wiki [3]. We believe that strong cryptography, Free and Open Source Software, erasure coding, and principled engineering practices make Tahoe-LAFS safer than RAID, removable drive, tape, on-line backup or "cloud storage" systems. This software is developed under test-driven development, and there are no known bugs or security flaws which would compromise confidentiality or data integrity under recommended use. (For all currently known issues please see the known_issues.txt file [4].) COMPATIBILITY This release is fully compatible with the version 1 series of Tahoe-LAFS. Clients from this release can write files and directories in the format used by clients of all versions back to v1.0 (which was released March 25, 2008). Clients from this release can read files and directories produced by clients of all versions since v1.0. Servers from this release can serve clients of all versions back to v1.0 and clients from this release can use servers of all versions back to v1.0. This is the tenth release in the version 1 series. This series of Tahoe-LAFS will be actively supported and maintained for the forseeable future, and future versions of Tahoe-LAFS will retain the ability to read and write files compatible with this series. LICENCE You may use this package under the GNU General Public License, version 2 or, at your option, any later version. See the file "COPYING.GPL" [5] for the terms of the GNU General Public License, version 2. You may use this package under the Transitive Grace Period Public Licence, version 1 or, at your option, any later version. (The Transitive Grace Period Public Licence has requirements similar to the GPL except that it allows you to delay for up to twelve months after you redistribute a derived work before releasing the source code of your derived work.) See the file "COPYING.TGPPL.html" [6] for the terms of the Transitive Grace Period Public Licence, version 1. (You may choose to use this package under the terms of either licence, at your option.) INSTALLATION Tahoe-LAFS works on Linux, Mac OS X, Windows, Cygwin, Solaris, *BSD, and probably most other systems. Start with "docs/quickstart.html" [7]. HACKING AND COMMUNITY Please join us on the mailing list [8]. Patches are gratefully accepted -- the RoadMap page [9] shows the next improvements that we plan to make and CREDITS [10] lists the names of people who've contributed to the project. The Dev page [11] contains resources for hackers. SPONSORSHIP Tahoe-LAFS was originally developed by Allmydata, Inc., a provider of commercial backup services. After discontinuing funding of Tahoe-LAFS R&D in early 2009, they have continued to provide servers, bandwidth, small personal gifts as tokens of appreciation, and bug reports. Thank you to Allmydata, Inc. for their generous and public-spirited support. Google, Inc. is sponsoring Tahoe-LAFS development as part of the Google Summer of Code 2010. Google suggested that we should apply for the Summer of Code program, and when we did they generously awarded four sponsorships to students from around the world to hack on Tahoe-LAFS this summer. Thank you to Google, Inc. for their generous and public-spirited support. HACK TAHOE-LAFS! If you can find a security flaw in Tahoe-LAFS which is serious enough that feel compelled to warn our users and issue a fix, then we will award you with a customized t-shirts with your exploit printed on it and add you to the "Hack Tahoe-LAFS Hall Of Fame" [12]. ACKNOWLEDGEMENTS This is the fifth release of Tahoe-LAFS to be created solely as a labor of love by volunteers. Thank you very much to the team of "hackers in the public interest" who make Tahoe-LAFS possible. David-Sarah Hopwood and Zooko Wilcox-O'Hearn on behalf of the Tahoe-LAFS team July 18, 2010 Rainhill, Merseyside, UK and Boulder, Colorado, USA [1] http://tahoe-lafs.org/trac/tahoe/browser/relnotes.txt?rev=4514 [2] http://tahoe-lafs.org/trac/tahoe/browser/NEWS?rev=4577 [3] http://tahoe-lafs.org/trac/tahoe/wiki/RelatedProjects [4] http://tahoe-lafs.org/trac/tahoe/browser/docs/known_issues.txt [5] http://tahoe-lafs.org/trac/tahoe/browser/COPYING.GPL [6] http://tahoe-lafs.org/source/tahoe/trunk/COPYING.TGPPL.html [7] http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html [8] http://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev [9] http://tahoe-lafs.org/trac/tahoe/roadmap [10] http://tahoe-lafs.org/trac/tahoe/browser/CREDITS?rev=4567 [11] http://tahoe-lafs.org/trac/tahoe/wiki/Dev [12] http://tahoe-lafs.org/hacktahoelafs/ From python.koda at gmail.com Mon Jul 19 12:38:47 2010 From: python.koda at gmail.com (Alban Nona) Date: Mon, 19 Jul 2010 12:38:47 -0400 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: Hello, About this one. I tried the os.system copy. But it seems I cant find the right syntax. *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* This one seems to not working. Is there anyway I can do this way: localpath= c:\ networkpath=g:\ os.system("copy localpath networkpath) I tried many variations, but still not working. Any help will apreciated :/ Thanks ! 2010/7/19 Vlastimil Brom > 2010/7/19 oyster : > > I mean writeonly, hidden, system and so on attributes > > > > I use windows, but if possible, is there any method to do so in a > > crossplatfrom way? > > > > thanks > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > You may check to see several possibilities > http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html > Probably the shutil module might be appropriate for simple usecases. > > hth, > vbr > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dhruvbird at gmail.com Mon Jul 19 12:56:03 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 09:56:03 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> On Jul 19, 9:12?pm, Brian Victor wrote: > dhruvbird wrote: > > Hello, > > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > > ? And would like to compute the cumulative sum of all the integers > > from index zero into another array. So for the array above, I should > > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > > ? What is the best way (or pythonic way) to get this. > > Now that Steven's given you the simple, pythonic way, I'll just mention > the advanced, complicated and obscure way that might be vaguely familiar > if you're coming from a functional programming background: > > x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > def running_sum(result, current_value): > ? ? return result + [result[-1]+current_value if result else current_value] > > reduce(running_sum, x, []) > > Having offered this, I don't recall ever seeing reduce used in real > python code, and explicit iteration is almost always preferred. Yes, even I have noticed that reduce is a tad under-used function. So, I guess no function like "accumulate" below exists in the standard lib. def accumulate(proc, seed, seq): ret = [] for i in seq: ret.append(proc(seed, i)) return ret x = [0, 1, 3, 4, 5, 5, 5, 7, 10] print accumulate(lambda x,y: x+y, 0, x) My guess is that accumulate can be used in many more scenarios. Regards, -Dhruv. From python at mrabarnett.plus.com Mon Jul 19 12:57:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jul 2010 17:57:31 +0100 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: <4C4483FB.2030009@mrabarnett.plus.com> Alban Nona wrote: > Hello, > > About this one. I tried the os.system copy. But it seems I cant find the > right syntax. > > *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* > > This one seems to not working. > In what way doesn't it work? If the names contain spaces then you need to quote them: os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) (It's easier to always quote them.) If the destination doesn't exist then you need to add the "/i" flag: os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2)) > Is there anyway I can do this way: > > localpath= c:\ > networkpath=g:\ > > os.system("copy localpath networkpath) > > I tried many variations, but still not working. Any help will apreciated :/ > From dhruvbird at gmail.com Mon Jul 19 13:01:59 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 10:01:59 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <1994a39d-eb84-42f1-a434-6123a100ef81@a4g2000prm.googlegroups.com> On Jul 19, 4:28?pm, Peter Otten <__pete... at web.de> wrote: > dhruvbird wrote: > > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > > ? And would like to compute the cumulative sum of all the integers > > from index zero into another array. So for the array above, I should > > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > > ? What is the best way (or pythonic way) to get this. > > Homework? not really :) It's just that I was wondering if a built-in function for doing such things (which I find myself doing increasingly with an explicit loop) exists. Regards, -Dhruv. > > >>> def cumulative_sum(values, start=0): > > ... ? ? for v in values: > ... ? ? ? ? ? ? start += v > ... ? ? ? ? ? ? yield start > ...>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) > > [0, 1, 3, 4, 5, 5, 5, 7, 10] > > Peter From john at castleamber.com Mon Jul 19 13:20:48 2010 From: john at castleamber.com (John Bokma) Date: Mon, 19 Jul 2010 12:20:48 -0500 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <87fwzf2xsf.fsf@castleamber.com> "be.krul" writes: > why is this group being spammed? Do you report those spammers? While Google is extremely lazy with dealing with spammers, if sufficient people report them action might be taken. Also make sure to report those spammers with their ISP; posts via GG contain the posting IP address. Even trolls can be hurt, if enough people report them: http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From scott.mccarty at gmail.com Mon Jul 19 13:28:47 2010 From: scott.mccarty at gmail.com (Scott McCarty) Date: Mon, 19 Jul 2010 13:28:47 -0400 Subject: CPython Signal Handler Check for SIGKILL Message-ID: All, I just want to understand the C/Python piece better because I am writing a tutorial on signals and I am using python to demonstrate. I thought it would be fun to show that the SIGKILL is never processed, but instead python errors out. There is something in Python checking the SIGKILL signal handler, while not checking SIGTERM and I can't find the Python C code that handles it. When I am writing something like this, I like to point out the C code, not just cite the documentation (I did find this change in behaviour noted in the Python change log). I have searched everywhere (mostly the code and a little google) and I cannot understand where the SIGKILL signal gets checked when it is set as a handler. I have scoured the Modules/signalmodule.c only to find two instances of the RuntimeError exception, but I cannot understand how python knows when a handler is set for SIGKILL. I understand that this changed in 2.4 and I am not trying to change it, I just really want to understand where this happens. I used grep to find SIGKILL and SIGTERM to see if I could determine where the critical difference is, but I cannot figure it out. I have about 2 hours of searching around and I can't figure it out, I assume it has to rely on some default behaviour in Unix, but I have no idea. I don't see a difference between SIGKILL and SIGTERM in the python code, but obviously there is some difference. I understand what the difference is in Unix/Linux, I just want to see it in the python code. Since python is checking at run time to see what signals handlers are added, I know there must be a difference. I am not asking about the signals, I understand them, I am asking about the registration of the SIGNAL handler and how it knows that you are trying to register SIGKILL, you get an error like this. ./signal-catcher.py Traceback (most recent call last): File "./signal-catcher.py", line 22, in signal.signal(signal.SIGKILL, signal_handler_kill) RuntimeError: (22, 'Invalid argument') And the code is very simple, this attempts to register a handler for SIGKILL, but python knows and won't let you. signal.signal(signal.SIGKILL, signal_handler_kill) Please can someone just point me in the right direction. Thank You Scott M -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Mon Jul 19 13:51:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Jul 2010 17:51:34 GMT Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <1994a39d-eb84-42f1-a434-6123a100ef81@a4g2000prm.googlegroups.com> Message-ID: dhruvbird wrote: > On Jul 19, 4:28?pm, Peter Otten <__pete... at web.de> wrote: >> dhruvbird wrote: >> > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] >> > ? And would like to compute the cumulative sum of all the integers >> > from index zero into another array. So for the array above, I should >> > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] >> > ? What is the best way (or pythonic way) to get this. >> >> Homework? > > not really :) > > It's just that I was wondering if a built-in function for doing such > things (which I find myself doing increasingly with an explicit loop) > exists. > Why would you find yourself doing it more than once? Write it once in a function and then just re-use the code. From python.koda at gmail.com Mon Jul 19 13:55:16 2010 From: python.koda at gmail.com (Alban Nona) Date: Mon, 19 Jul 2010 13:55:16 -0400 Subject: how to copy and move file with its attribute? In-Reply-To: <4C4483FB.2030009@mrabarnett.plus.com> References: <4C4483FB.2030009@mrabarnett.plus.com> Message-ID: Hello Mrab, Thank you very much for this informations. Homever, Im still stuck with a problem: import os import sys import threading import shutil source= "C://Production//" dest= "D://Production//" os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) It seems that it wont copy the files File not found - //Production// 0 File(s) copied any idea of why its doing this please ? 2010/7/19 MRAB > Alban Nona wrote: > >> Hello, >> >> About this one. I tried the os.system copy. But it seems I cant find the >> right syntax. >> >> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* >> >> This one seems to not working. >> >> In what way doesn't it work? > > If the names contain spaces then you need to quote them: > > > os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) > > (It's easier to always quote them.) > > If the destination doesn't exist then you need to add the "/i" flag: > > os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2)) > > > Is there anyway I can do this way: >> >> localpath= c:\ >> networkpath=g:\ >> >> os.system("copy localpath networkpath) >> >> I tried many variations, but still not working. Any help will apreciated >> :/ >> >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 19 13:56:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 19 Jul 2010 19:56:07 +0200 Subject: CPython Signal Handler Check for SIGKILL In-Reply-To: References: Message-ID: <4C4491B7.5030404@jollans.com> On 07/19/2010 07:28 PM, Scott McCarty wrote: > All, I just want to understand the C/Python piece better because I am > writing a tutorial on signals and I am using python to demonstrate. I > thought it would be fun to show that the SIGKILL is never processed, but > instead python errors out. There is something in Python checking the > SIGKILL signal handler, while not checking SIGTERM and I can't find the > Python C code that handles it. When I am writing something like this, I > like to point out the C code, not just cite the documentation (I did > find this change in behaviour noted in the Python change log). You cannot handle SIGKILL. Nothing to do with Python. Let me demonstrate: 0:pts/8:/tmp% cat sig.c #include #include void handle_sig(int sig) { printf("SIGNAL: %d\n", sig); } int main(int argc, char **argv) { if (signal(SIGUSR1, handle_sig) == SIG_ERR) printf("failed to set for USR1\n"); if (signal(SIGTERM, handle_sig) == SIG_ERR) printf("failed to set for TERM\n"); if (signal(SIGKILL, handle_sig) == SIG_ERR) printf("failed to set for KILL\n"); for(;;); } 0:pts/8:/tmp% cc -osig sig.c 0:pts/8:/tmp% ./sig failed to set for KILL ^C 130:pts/8:/tmp% > > I have searched everywhere (mostly the code and a little google) and I > cannot understand where the SIGKILL signal gets checked when it is set > as a handler. I have scoured the Modules/signalmodule.c only to find two > instances of the RuntimeError exception, but I cannot understand how > python knows when a handler is set for SIGKILL. I understand that this > changed in 2.4 and I am not trying to change it, I just really want to > understand where this happens. I used grep to find SIGKILL and SIGTERM > to see if I could determine where the critical difference is, but I > cannot figure it out. > > I have about 2 hours of searching around and I can't figure it out, I > assume it has to rely on some default behaviour in Unix, but I have no > idea. I don't see a difference between SIGKILL and SIGTERM in the python > code, but obviously there is some difference. I understand what the > difference is in Unix/Linux, I just want to see it in the python code. > Since python is checking at run time to see what signals handlers are > added, I know there must be a difference. I am not asking about the > signals, I understand them, I am asking about the registration of the > SIGNAL handler and how it knows that you are trying to register SIGKILL, > you get an error like this. > > ./signal-catcher.py > Traceback (most recent call last): > File "./signal-catcher.py", line 22, in > signal.signal(signal.SIGKILL, signal_handler_kill) > RuntimeError: (22, 'Invalid argument') > > And the code is very simple, this attempts to register a handler for > SIGKILL, but python knows and won't let you. > > signal.signal(signal.SIGKILL, signal_handler_kill) > > Please can someone just point me in the right direction. > > Thank You > Scott M > From rui.maciel at gmail.com Mon Jul 19 13:56:33 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 19 Jul 2010 18:56:33 +0100 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> <4c437fcb$0$31260$607ed4bc@cv.net> Message-ID: <4c4491d4$0$17017$a729d347@news.telepac.pt> Kenneth Tilton wrote: > What we do not have is any interesting amount of "free as in speech" > software, because no one uses the GPL. You appear to be either confused or out of touch with reality. If that wasn't enough, your comment becomes a bit more amusing once we check your post's user agent. Rui Maciel From solipsis at pitrou.net Mon Jul 19 14:06:16 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 19 Jul 2010 20:06:16 +0200 Subject: CPython Signal Handler Check for SIGKILL References: Message-ID: <20100719200616.19a344e0@pitrou.net> Hello, > I am not asking about the signals, I understand them, > I am asking about the registration of the SIGNAL handler and how it knows > that you are trying to register SIGKILL, you get an error like this. > > ./signal-catcher.py > Traceback (most recent call last): > File "./signal-catcher.py", line 22, in > signal.signal(signal.SIGKILL, signal_handler_kill) > RuntimeError: (22, 'Invalid argument') >>> import errno >>> errno.errorcode[22] 'EINVAL' EINVAL is the error returned by the standard POSIX signal() function when trying to register a handler for SIGKILL. As the signal() man page says: [...] The signals SIGKILL and SIGSTOP cannot be caught or ignored. [...] ERRORS EINVAL signum is invalid. So, in short, Python doesn't check SIGKILL by itself. It's just forbidden by the underlying C standard library, and Python propagates the error as a RuntimeError. Regards Antoine. From no at email.here.invalid Mon Jul 19 14:08:00 2010 From: no at email.here.invalid (Mladen Gogala) Date: Mon, 19 Jul 2010 18:08:00 +0000 (UTC) Subject: mod_python load cx_Oracle error References: <73e34de4-a508-4d78-9d79-937c31c3d3ba@x2g2000prk.googlegroups.com> Message-ID: On Mon, 19 Jul 2010 09:12:20 -0700, li wang wrote: > It's quite weird when I import cx_Oracle in python interactive shell, it > works perfectly. > but when I import cx_Oracle in a *,py script, handled by > mod_python.publisher, it keep reportint : > > ImportError: libclntsh.so.10.1: cannot open shared object file: No such > file or directory > > Can I anyone have a clue what's the matter, any help would be > appreciated! That's an Oracle error, it means that you didn't set and export LD_LIBRARY_PATH like this: export LD_LIBRARY_PATH=$ORACLE_HOME/lib This is how it normally works: mgogala at nycwxp2622:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>> And this is what happens when I unset the shell variable: mgogala at nycwxp2622:~$ unset LD_LIBRARY_PATH mgogala at nycwxp2622:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory >>> My cx_Oracle is linked against Oracle instant client 11.2 on Ubuntu. -- http://mgogala.byethost5.com From python at mrabarnett.plus.com Mon Jul 19 14:09:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jul 2010 19:09:55 +0100 Subject: how to copy and move file with its attribute? In-Reply-To: References: <4C4483FB.2030009@mrabarnett.plus.com> Message-ID: <4C4494F3.5080408@mrabarnett.plus.com> Alban Nona wrote: > Hello Mrab, > > Thank you very much for this informations. > Homever, Im still stuck with a problem: > > import os > import sys > import threading > import shutil > > source= "C://Production//" > dest= "D://Production//" > > os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) > > > It seems that it wont copy the files > > File not found - //Production// > 0 File(s) copied > > any idea of why its doing this please ? > [snip] If you're using slashes then there's no need to double them. Also, you don't need to end the folder names with slashes or backslashes (except for root folders). That's what it doesn't like, apparently. source = "C:/Production" dest = "D:/Production" os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) From hujia06 at gmail.com Mon Jul 19 14:19:00 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 19 Jul 2010 14:19:00 -0400 Subject: why is this group being spammed? In-Reply-To: <87fwzf2xsf.fsf@castleamber.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <87fwzf2xsf.fsf@castleamber.com> Message-ID: I use Gmail. When I receive spams, I will click "Report Spam". In addition, I will not empty the spam box of my email immediately. When I receive about 25 spams, I will click "Filter messages like these" to filter all the spams and let gmail automatically delete them. On Mon, Jul 19, 2010 at 1:20 PM, John Bokma wrote: > "be.krul" writes: > > > why is this group being spammed? > > Do you report those spammers? > > While Google is extremely lazy with dealing with spammers, if sufficient > people report them action might be taken. Also make sure to report those > spammers with their ISP; posts via GG contain the posting IP address. > > Even trolls can be hurt, if enough people report them: > http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html > > -- > John Bokma > j3b > > Hacking & Hiking in Mexico - http://johnbokma.com/ > http://castleamber.com/ - Perl & Python Development > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.mccarty at gmail.com Mon Jul 19 14:34:33 2010 From: scott.mccarty at gmail.com (Scott McCarty) Date: Mon, 19 Jul 2010 14:34:33 -0400 Subject: CPython Signal Handler Check for SIGKILL In-Reply-To: <20100719200616.19a344e0@pitrou.net> References: <20100719200616.19a344e0@pitrou.net> Message-ID: Yes, yes, thank you both. That is exactly what I didn't understand, I knew it was some how linked to the C library and wasn't exactly being handled or decided at the Python layer, I just didn't understand the C part good enough. I have found the CPython source code that checks. I see what you are saying, it is basically checking for SIG_ERR like the C code and just setting the RuntimeError which forces an exit, thereby making the python module respond in a way very similar to the C library. Here is the CPython code in Modules/signalmodule.c if (PyOS_setsig(sig_num, func) == SIG_ERR) { PyErr_SetFromErrno(PyExc_RuntimeError); return NULL; } Second, I would like to apologize, this list is amazing, and I made a stupid comment on the core developers mailing list this morning because I didn't understand that this was the right place to post this question. Thank You Scott M On Mon, Jul 19, 2010 at 2:06 PM, Antoine Pitrou wrote: > > Hello, > > > I am not asking about the signals, I understand them, > > I am asking about the registration of the SIGNAL handler and how it knows > > that you are trying to register SIGKILL, you get an error like this. > > > > ./signal-catcher.py > > Traceback (most recent call last): > > File "./signal-catcher.py", line 22, in > > signal.signal(signal.SIGKILL, signal_handler_kill) > > RuntimeError: (22, 'Invalid argument') > > >>> import errno > >>> errno.errorcode[22] > 'EINVAL' > > EINVAL is the error returned by the standard POSIX signal() function > when trying to register a handler for SIGKILL. As the signal() man page > says: > > [...] > The signals SIGKILL and SIGSTOP cannot be caught or ignored. > [...] > ERRORS > EINVAL signum is invalid. > > > So, in short, Python doesn't check SIGKILL by itself. It's just > forbidden by the underlying C standard library, and Python propagates > the error as a RuntimeError. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Jul 19 14:42:46 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:42:46 +0100 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> Message-ID: On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote: >> why is this group being spammed? > > There used to be bots that issued cancel messages against spam, but I > don't think they are actively maintained anymore. Mostly because cancel messages are invariably ignored nowadays. From no.email at nospam.invalid Mon Jul 19 14:45:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 19 Jul 2010 11:45:33 -0700 Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <7xpqyjgvjm.fsf@ruckus.brouhaha.com> Brian Victor writes: > def running_sum(result, current_value): > return result + [result[-1]+current_value if result else current_value] > > reduce(running_sum, x, []) That is not really any good because Python lists are actually vectors, so result+[...] actually copies the whole old list, making your function take quadratic time. It would be ok in a FP language where lists were chains of cons nodes and result+[...] just allocated a single cons. I think Peter Otten's solution involving a generator is the one most in the current Python spirit. It's cleaner (for my tastes) than the ones that use things like list.append. From nobody at nowhere.com Mon Jul 19 14:46:55 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:46:55 +0100 Subject: how to copy and move file with its attribute? References: Message-ID: On Mon, 19 Jul 2010 17:57:31 +0100, MRAB wrote: >> About this one. I tried the os.system copy. But it seems I cant find the >> right syntax. >> >> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* >> >> This one seems to not working. >> > In what way doesn't it work? > > If the names contain spaces then you need to quote them: > > os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) No, you need to use subprocess.call() instead of os.system(). If you absolutely must use os.system() for some reason, at least quote the arguments correctly. If you want to know how to do this, look at the subprocess.py source code (hint: it's not as simple as the above suggests). From nobody at nowhere.com Mon Jul 19 14:49:15 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:49:15 +0100 Subject: CPython Signal Handler Check for SIGKILL References: Message-ID: On Mon, 19 Jul 2010 20:06:16 +0200, Antoine Pitrou wrote: > So, in short, Python doesn't check SIGKILL by itself. It's just > forbidden by the underlying C standard library, Actually, it's forbidden by the kernel. The C library just passes along the error to Python, which just passes it to the application. From joshua.landau.ws at gmail.com Mon Jul 19 14:49:55 2010 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 19 Jul 2010 19:49:55 +0100 Subject: Pyglet being extremely slow Message-ID: I've just tried Pyglet on my computer, a lower-end laptop at that, and going though the Pyglet tutorials I've tried this: import pyglet > window = pyglet.window.Window() > @window.event def on_key_press(symbol, modifiers): print 'A key was pressed' > @window.event def on_draw(): window.clear() > pyglet.app.run() And from a button-press to the print-statement activating takes ~3 seconds. I mean, yeah so I'm on a slow-ish-medium laptop but... three bloody seconds? On another one that shows the FPS of the program I'm getting 0 (fps). I would give you more detail but this has me stumped. Pygame was a decent performer -- and I'm not even drawing anything. Yeah, any help? *sigh* PS: Note that I'm on Ubuntu with a tiling window manager (Awesome). -------------- next part -------------- An HTML attachment was scrubbed... URL: From hujia06 at gmail.com Mon Jul 19 15:06:41 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 19 Jul 2010 15:06:41 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> Message-ID: Hi noboby: How can you make the current email and name hidden? On Mon, Jul 19, 2010 at 2:42 PM, Nobody wrote: > On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote: > > >> why is this group being spammed? > > > > There used to be bots that issued cancel messages against spam, but I > > don't think they are actively maintained anymore. > > Mostly because cancel messages are invariably ignored nowadays. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at picloud.com Mon Jul 19 15:49:40 2010 From: ken at picloud.com (Ken Elkabany) Date: Mon, 19 Jul 2010 12:49:40 -0700 Subject: ANN: PiCloud's Python Platform is now open to the Public! Message-ID: After 5 months in private beta, PiCloud, a cloud computing platform for the Python Programming Language, is now open to the general public. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as two lines of code! No server management necessary. All new users receive 5 free compute hours of computation. You can find out more here: http://www.picloud.com Full service description: PiCloud is a cloud computing platform that integrates into the Python Programming Language. It enables you to leverage the compute power of Amazon Web Services without having to manage, maintain, or configure virtual servers. PiCloud integrates seamlessly into your existing code base through a custom Python library, cloud. To offload the execution of a function to the cloud, all you must do is pass your desired function into the cloud library. PiCloud will then run the function on its high-performance and automatically-scaling cluster. We quickly scale our server capacity to meet your computational needs, and only charge you for the resources you actually consume. Getting on the cloud has never been this easy! PiCloud improves the full cycle of software development and deployment. Functions that are run on PiCloud have their resource usage monitored, performance analyzed, and errors traced; we further aggregate all your functions to give you a bird's eye view of your service. Through these introspective capabilities, PiCloud enables you to develop faster, easier, and smarter. Common use cases for our platform: * Scientific computing * Simulations * Video and image encoding * Statistical analysis of data sets * Real-time data processing * Charts and graphs generation Cheers, Ken Elkabany PiCloud, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.trojan at noaa.gov Mon Jul 19 16:06:59 2010 From: george.trojan at noaa.gov (George Trojan) Date: Mon, 19 Jul 2010 20:06:59 +0000 Subject: parmiko problem Message-ID: I have a problem with connecting to a host without specifying password (but with ssh keys configured correctly. That is [tina src]$ sftp alice Connecting to alice... sftp> works, but the code import paramiko paramiko.util.log_to_file('/tmp/paramiko') t = paramiko.Transport(('alice', 22)) t.connect(username='gtrojan') # , password='a-passwd']) sftp = paramiko.SFTPClient.from_transport(t) sftp.close() t.close() results in the following output in /tmp/paramiko: DEB [20100719-19:58:22.497] thr=1 paramiko.transport: starting thread (client mode): 0xb81e1150L INF [20100719-19:58:22.501] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_4.3) DEB [20100719-19:58:22.502] thr=1 paramiko.transport: kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib at openssh.com'] server compress:['none', 'zlib at openssh.com'] client lang:[''] server lang:[''] kex follows?False DEB [20100719-19:58:22.502] thr=1 paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr DEB [20100719-19:58:22.502] thr=1 paramiko.transport: using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none DEB [20100719-19:58:22.571] thr=1 paramiko.transport: Switch to new keys ... DEB [20100719-19:58:22.578] thr=2 paramiko.transport: [chan 1] Max packet in: 34816 bytes WAR [20100719-19:58:22.611] thr=1 paramiko.transport: Oops, unhandled type 3 DEB [20100719-20:00:22.502] thr=1 paramiko.transport: EOF in transport thread and a traceback in the terminal: Traceback (most recent call last): File "./try.py", line 18, in sftp = paramiko.SFTPClient.from_transport(t) File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 102, in from_transport File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, in open_session File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, in open_channel EOFError When the remove the comment on the connect() line and specify password the code works fine. Is this a bug, or I am missing something? I am running Python 2.6.3 on Centos 5.4. George From george.trojan at noaa.gov Mon Jul 19 17:02:53 2010 From: george.trojan at noaa.gov (George Trojan) Date: Mon, 19 Jul 2010 21:02:53 +0000 Subject: parmiko problem In-Reply-To: References: Message-ID: George Trojan wrote: > I have a problem with connecting to a host without specifying password > (but with ssh keys configured correctly. That is > > [tina src]$ sftp alice > Connecting to alice... > sftp> > > works, but the code > > import paramiko > paramiko.util.log_to_file('/tmp/paramiko') > t = paramiko.Transport(('alice', 22)) > t.connect(username='gtrojan') # , password='a-passwd']) > sftp = paramiko.SFTPClient.from_transport(t) > sftp.close() > t.close() > > results in the following output in /tmp/paramiko: > > DEB [20100719-19:58:22.497] thr=1 paramiko.transport: starting thread > (client mode): 0xb81e1150L > INF [20100719-19:58:22.501] thr=1 paramiko.transport: Connected > (version 2.0, client OpenSSH_4.3) > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: kex > algos:['diffie-hellman-group-exchange-sha1', > 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server > key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', > 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', > 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', > 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', > 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', > 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', > 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', > 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', > 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', > 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client > compress:['none', 'zlib at openssh.com'] server compress:['none', > 'zlib at openssh.com'] client lang:[''] server lang:[''] kex follows?False > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: Ciphers agreed: > local=aes128-ctr, remote=aes128-ctr > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: using kex > diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local > aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; > compression: local none, remote none > DEB [20100719-19:58:22.571] thr=1 paramiko.transport: Switch to new > keys ... > DEB [20100719-19:58:22.578] thr=2 paramiko.transport: [chan 1] Max > packet in: 34816 bytes > WAR [20100719-19:58:22.611] thr=1 paramiko.transport: Oops, unhandled > type 3 > DEB [20100719-20:00:22.502] thr=1 paramiko.transport: EOF in transport > thread > > and a traceback in the terminal: > > Traceback (most recent call last): > File "./try.py", line 18, in > sftp = paramiko.SFTPClient.from_transport(t) > File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 102, > in from_transport > File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, > in open_session > File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, > in open_channel > EOFError > > When the remove the comment on the connect() line and specify password > the code works fine. Is this a bug, or I am missing something? I am > running Python 2.6.3 on Centos 5.4. > > George Thanks for listening;-) Found my problem - has to pass private key to connect(): paramiko.util.log_to_file('/tmp/paramiko') t = paramiko.Transport(('alice', 22)) path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa') key = paramiko.DSSKey.from_private_key_file(path) t.connect(username='gtrojan', pkey=key) sftp = paramiko.SFTPClient.from_transport(t) print sftp.listdir() sftp.close() t.close() From eldiener at tropicsoft.invalid Mon Jul 19 17:45:23 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 17:45:23 -0400 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote: > * Edward Diener, on 19.07.2010 14:53: >> In Windows Vista x64 I have installed python 2.6 64-bit version and >> python 3.1 64-bit version to separate folders. Within the command >> interpreter I add python 2.6 to the PATH. >> >> In the command interpreter, When I type python somescript.py with an >> >> import sys >> print (sys.version) >> >> in the script, it shows: >> >> 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] >> >> In the command interpreter if I type 'python' I see: >> >> Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit >> (AMD64)] on win32 >> >> Does anybody have any ideas why this is happening ? > > At a guess your description of what's happening is not entirely accurate. > > Although it could be, since Windows moves in mysterious ways. > > Please try the following commands in sequence, with no other commands: > > python -V > echo %path% > ftype python.file > python somescript.py > > Then right-click the command interpreter's title bar to get edit menu. > /Mark/ the text of your commands and results. Then /copy/ it to the > clipboard (note: you can't use [Ctrl C] here, use the edit menu or just > press Enter). Then post the commands and results here, /paste/ them into > your message (e.g. [Ctrl V]). > > And then, if you haven't already figured it out, somebody probably will. > :-) I figured out the cause. One of the Python scripts started with: #!Path/to/Python31Executable which evidently caused python 3.1 to be called to run that script. I am not sure that script was run via an 'import' statement, as opposed to a 'python someScript.py' within another script, but I suspect the latter. From joel.goldstick at columbuswebmakers.com Mon Jul 19 18:08:25 2010 From: joel.goldstick at columbuswebmakers.com (Joel Goldstick) Date: Mon, 19 Jul 2010 18:08:25 -0400 Subject: Accumulate function in python In-Reply-To: References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4C44CCD9.3000508@columbuswebmakers.com> Peter Otten wrote: > dhruvbird wrote: > >> I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] >> And would like to compute the cumulative sum of all the integers >> from index zero into another array. So for the array above, I should >> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] >> What is the best way (or pythonic way) to get this. > > Homework? > >>>> def cumulative_sum(values, start=0): > ... for v in values: > ... start += v > ... yield start > ... >>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) > [0, 1, 3, 4, 5, 5, 5, 7, 10] > > Peter nice! Peter From ranavishal at gmail.com Mon Jul 19 21:30:20 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Mon, 19 Jul 2010 18:30:20 -0700 Subject: How is memory managed in python? Message-ID: Hi, In my web application (Django) I call a function for some request which loads like 500 MB data from the database uses it to do some calculation and stores the output in disk. I just wonder even after this request is served the apache / python process is still shows using that 500 MB, why is it so? Can't I release that memory? Thanks Vishal Rana -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranjithtenz at gmail.com Mon Jul 19 21:41:56 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Tue, 20 Jul 2010 07:11:56 +0530 Subject: How to pass the shell in Python Message-ID: Hi Folks, Can anyone tell me how to run shell commands using python script. -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Jul 19 21:48:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jul 2010 02:48:43 +0100 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: <4C45007B.8000602@mrabarnett.plus.com> Ranjith Kumar wrote: > Hi Folks, > Can anyone tell me how to run shell commands using python script. > Use the 'subprocess' module. From eldiener at tropicsoft.invalid Mon Jul 19 21:50:28 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 21:50:28 -0400 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: On 7/19/2010 5:45 PM, Edward Diener wrote: > On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote: >> * Edward Diener, on 19.07.2010 14:53: >>> In Windows Vista x64 I have installed python 2.6 64-bit version and >>> python 3.1 64-bit version to separate folders. Within the command >>> interpreter I add python 2.6 to the PATH. >>> >>> In the command interpreter, When I type python somescript.py with an >>> >>> import sys >>> print (sys.version) >>> >>> in the script, it shows: >>> >>> 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] >>> >>> In the command interpreter if I type 'python' I see: >>> >>> Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit >>> (AMD64)] on win32 >>> >>> Does anybody have any ideas why this is happening ? >> >> At a guess your description of what's happening is not entirely accurate. >> >> Although it could be, since Windows moves in mysterious ways. >> >> Please try the following commands in sequence, with no other commands: >> >> python -V >> echo %path% >> ftype python.file >> python somescript.py >> >> Then right-click the command interpreter's title bar to get edit menu. >> /Mark/ the text of your commands and results. Then /copy/ it to the >> clipboard (note: you can't use [Ctrl C] here, use the edit menu or just >> press Enter). Then post the commands and results here, /paste/ them into >> your message (e.g. [Ctrl V]). >> >> And then, if you haven't already figured it out, somebody probably will. >> :-) > > I figured out the cause. One of the Python scripts started with: > > #!Path/to/Python31Executable > > which evidently caused python 3.1 to be called to run that script. I am > not sure that script was run via an 'import' statement, as opposed to a > 'python someScript.py' within another script, but I suspect the latter. No, this is incorrect. The cause had nothing to do with the above. It was because .py files were associated with the 3.1 version of Python, no Python folder was in the PATH, and a Pyhton script invoked python passing it a .py file. So even though the initial command specified the 2.6 version of Python on a script, subsequent scripts were run using Python 3.1. I since changed the association of .py files to the 2.6 version of Python and everything works correctly. From clp2 at rebertia.com Tue Jul 20 02:43:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jul 2010 23:43:38 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana wrote: > Hi, > In my web application (Django) I call a function for some request which > loads like 500 MB data from the database uses it to do some calculation and > stores the output in disk. I just wonder even after this request is served > the apache / python process is still shows using that 500 MB, why is it so? > Can't I release that memory? http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm There are multiple layers of memory allocation involved. To avoid thrashing+fragmentation and to improve efficiency, free memory is not always immediately returned to the operating system. Example: If your problem involved calling your 500MB function twice, free-ing after the first call and then immediately re-allocating another 500MB of memory for the second call would waste time. Cheers, Chris -- http://blog.rebertia.com From stefan_ml at behnel.de Tue Jul 20 04:15:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Jul 2010 10:15:34 +0200 Subject: [ANN] Lupa 0.6 - Lua in Python In-Reply-To: References: <4C433F2B.8050706@behnel.de> Message-ID: Fabrizio Milo aka misto, 19.07.2010 15:41: > This is very very interesting. > > Do you have any direct application of it ? > I know games like World of Warcraft uses Lua as scripting language. Lua is widely used in the gaming industry, mainly for its size but also for its speed. Personally, I don't have any direct use for it, so this is mainly a fun project to see how well I can get it integrated and how fast I can get it. Stefan From dmitrey.kroshko at scipy.org Tue Jul 20 06:10:25 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 03:10:25 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug Message-ID: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. So, when I invoke in other code part "hasattr(myObject, 'size')", instead o returning True/False it goes to __getattr__ and starts constructor for another one oofun, that wasn't intended behaviour. Thus "hasattr(myObject, 'size')" always returns True. It prevents me of some bonuses and new features to be done in FuncDesigner. >>> 'size' in dir(b) False >>> hasattr(b,'size') True >>> 'size' in dir(b) True Could you fix it? From clp2 at rebertia.com Tue Jul 20 06:37:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 03:37:46 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > >>>> 'size' in dir(b) > False >>>> hasattr(b,'size') > True >>>> 'size' in dir(b) > True > > Could you fix it? There's probably some hackery you could do to check whether hasattr() is in the call stack, and then not dynamically create the attribute in __getattr__ if that's the case, but that's obviously quite kludgey. /Slightly/ less hackish: Replace hasattr() in the __builtin__ module with your own implementation that treats instances of FuncDesigner specially. Least ugly suggestion: Just don't use hasattr(); use your `x in dir(y)` trick instead. > Subject: [...] I think this is Python bug Nope, that's just how hasattr() works. See http://docs.python.org/library/functions.html#hasattr (emphasis mine): """ hasattr(object, name) The arguments are an object and a string. The result is True if the string is the name of one of the object?s attributes, False if not. (***This is implemented by calling getattr(object, name)*** and seeing whether it raises an exception or not.) """ I suppose you could argue for the addition of a __hasattr__ special method, but this seems like a really rare use case to justify adding such a method (not to mention the language change moratorium is still currently in effect). Cheers, Chris -- http://blog.rebertia.com From dmitrey.kroshko at scipy.org Tue Jul 20 06:59:30 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 03:59:30 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> On Jul 20, 1:37?pm, Chris Rebert wrote: > On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and connected to > > myObject as attribute. > > > So, when I invoke in other code part "hasattr(myObject, 'size')", > > instead o returning True/False it goes to __getattr__ and starts > > constructor for another one oofun, that wasn't intended behaviour. > > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) > > False > >>>> hasattr(b,'size') > > True > >>>> 'size' in dir(b) > > True > > > Could you fix it? > > There's probably some hackery you could do to check whether hasattr() > is in the call stack, and then not dynamically create the attribute in > __getattr__ if that's the case, but that's obviously quite kludgey. It's too unreliable solution, hasattr may or may not appear in stack wrt different cases > /Slightly/ less hackish: Replace hasattr() in the __builtin__ module > with your own implementation that treats instances of FuncDesigner > specially. It's too unreliable as well > Least ugly suggestion: Just don't use hasattr(); use your `x in > dir(y)` trick instead. something in dir() consumes O(n) operations for lookup, while hasattr or getattr() require O(log(n)). It matters for me, because it's inside deeply nested mathematical computations FuncDesigner is made for. > > > Subject: [...] I think this is Python bug > > Nope, that's just how hasattr() works. Seehttp://docs.python.org/library/functions.html#hasattr(emphasis mine): > """ > hasattr(object, name) > ? ? The arguments are an object and a string. The result is True if > the string is the name of one of the object?s attributes, False if > not. (***This is implemented by calling getattr(object, name)*** and > seeing whether it raises an exception or not.) > """ Thus I believe this is very ugly implementation. Some code implemented via "__getattr__" can start to execute arbitrary Python code, that is certainly not desired behaviour "hasattr" was designed for (to perform a check only), and it's too hard to reveal the situations, that makes a potential holes for viruses etc. Moreover, the implementation via "try getattr(object, name)" slowers code evaluation, I wonder why it is implemented so. > > I suppose you could argue for the addition of a __hasattr__ special > method, but this seems like a really rare use case to justify adding > such a method (not to mention the language change moratorium is still > currently in effect). I think much more easier solution would be to implement an additional argument to hasattr, e.g. hasattr(obj, field, onlyLookupInExistingFields = {True/False}). I think by default it's better set to True, now it behaves like False. D. From duncan.booth at invalid.invalid Tue Jul 20 07:14:55 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jul 2010 11:14:55 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > >>>> 'size' in dir(b) > False >>>> hasattr(b,'size') > True >>>> 'size' in dir(b) > True > > Could you fix it? This isn't a bug, it is by design: try reading the documentation for 'hasattr' as that explains that it is implemented by calling getattr and seeing whether or not it throws an exception. If you want different behaviour you just need to define your own helper function that has the behaviour you desire. e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. -- Duncan Booth http://kupuguy.blogspot.com From guandalino at gmail.com Tue Jul 20 07:42:58 2010 From: guandalino at gmail.com (guandalino) Date: Tue, 20 Jul 2010 04:42:58 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) Message-ID: Hi, running Python 2.7 test suite for urllib2 there is a test that doesn't pass. Do you have an idea about where the problem could be and how to solve it? Thanks, best regards. $ # ubuntu 8.04 $ pwd ~/sandbox/2.7/lib/python2.7/test $ python test_urllib2.py ====================================================================== ERROR: test_file (__main__.HandlerTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_urllib2.py", line 711, in test_file h.file_open, Request(url)) File "/home/redt/sandbox/2.7/lib/python2.7/unittest/case.py", line 456, in assertRaises callableObj(*args, **kwargs) File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, in file_open return self.open_local_file(req) File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, in open_local_file (not port and socket.gethostbyname(host) in self.get_names()): gaierror: [Errno -5] No address associated with hostname Notes: $ hostname speedy $ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain speedy ::1 localhost speedy ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts Finally, I don't know if this matters but the tests have been executed offline (without an internet connection). From s.selvamsiva at gmail.com Tue Jul 20 07:57:45 2010 From: s.selvamsiva at gmail.com (S.Selvam) Date: Tue, 20 Jul 2010 17:27:45 +0530 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 7:11 AM, Ranjith Kumar wrote: > Hi Folks, > Can anyone tell me how to run shell commands using python script. > > For simple work, i generally use os.system call. -- Regards, S.Selvam " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 20 08:00:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 20 Jul 2010 14:00:39 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4C458FE7.3020004@sequans.com> dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) >>>> > False > >>>> hasattr(b,'size') >>>> > True > >>>> 'size' in dir(b) >>>> > True > > Could you fix it? > Quite simple, when calling b.size, return the computed value but do not set it as attribute, the value will be computed on each b.size call, and hasattr w. If you don't want to compute it each time, cause there no reason for it to change, use a private dummy attribute to record the value instead of size (__size for instance) and return the value of __size when getting the value of size. class Foo(object): def __init__(self): self.__size = None def __getattr__(self, name): if name == "size": if self.__size is None: self.__size = 5 # compute the value return self.__size raise AttributeError(name) b = Foo() print 'size' in dir(b) print hasattr(b, 'size') print 'size' in dir(b) False True False JM From lists at cheimes.de Tue Jul 20 08:31:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 14:31:38 +0200 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: > In my web application (Django) I call a function for some request which > loads like 500 MB data from the database uses it to do some calculation and > stores the output in disk. I just wonder even after this request is served > the apache / python process is still shows using that 500 MB, why is it so? > Can't I release that memory? Are you talking about resident or virtual memory here? From lists at cheimes.de Tue Jul 20 08:40:18 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 14:40:18 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: Am 20.07.2010 12:10, schrieb dmitrey: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. From nikos.the.gr33k at gmail.com Tue Jul 20 10:43:20 2010 From: nikos.the.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/I=?=) Date: Tue, 20 Jul 2010 07:43:20 -0700 (PDT) Subject: Trying to redirect every urel request to test.py script with the visitors page request as url parameter. Message-ID: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> Hello guys! This is my first post in this group! I'am trying to create a python script to take a visitors page request as url parameter, and the insert or update the counters database table and the render the template(my tempalets are actually html files) that has int hem special strign identifies format charactes so to replace them with actual data form within my python script. While the mod_rewwrite redirects okey when i try to http://webville.gr apache by default tries to open idnex.html file right? but due to Code: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+) /cgi-bin/test.py?page=$1 [L,PT] redirectes the url to test.py script and i expect it to give to my pythoin script the initial url before the mod_rewrite as a URL parameter. while i tested and my script works ok(its a simple test cghi script afgter all) when i enable out mod_rewriute code within the htaccess file i get an Internal Server Error You can see if you try to http://webville.gr/index.html whiel if i disbale mod_rewrite code my test.py script work proiducing results. That leads me to beleive that the intiial requests never passes as url parameter. my python script is this simple script: Code: #!/usr/bin/python # -*- coding: utf-8 -*- import cgitb import os, sys, socket, datetime cgitb.enable() print ( "Content-type: text/html\n" ) # get some enviromental values if os.environ.has_key('HTTP_REFERER'): page = os.environ['HTTP_REFERER'] else: page = "tipota" host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) print page, host, date Can you help please? Also i want the code to redirect to test.py only if the initial request is a .html page not with every page. Thanks again! From dmitrey.kroshko at scipy.org Tue Jul 20 11:32:39 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:32:39 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: On 20 ???, 15:00, Jean-Michel Pichavant wrote: > dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and connected to > > myObject as attribute. > > > So, when I invoke in other code part "hasattr(myObject, 'size')", > > instead o returning True/False it goes to __getattr__ and starts > > constructor for another one oofun, that wasn't intended behaviour. > > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) > > > False > > >>>> hasattr(b,'size') > > > True > > >>>> 'size' in dir(b) > > > True > > > Could you fix it? > > Quite simple, when calling b.size, return the computed value but do not > set it as attribute, the value will be computed on each b.size call, and > hasattr w. If you don't want to compute it each time, cause there no > reason for it to change, use a private dummy attribute to record the > value instead of size (__size for instance) and return the value of > __size when getting the value of size. > > class Foo(object): > ? ? def __init__(self): > ? ? ? ? self.__size = None > > ? ? def __getattr__(self, name): > ? ? ? ? if name == "size": > ? ? ? ? ? ? if self.__size is None: > ? ? ? ? ? ? ? ? self.__size = 5 # compute the value > ? ? ? ? ? ? return self.__size > ? ? ? ? raise AttributeError(name) > > b = Foo() > print 'size' in dir(b) > print hasattr(b, 'size') > print 'size' in dir(b) > > False > True > False > > JM This doesn't stack with the following issue: sometimes user can write in code "myObject.size = (some integer value)" and then it will be involved in future calculations as ordinary fixed value; if user doesn't supply it, but myObject.size is involved in calculations, then the oofun is created to behave like similar numpy.array attribute. From jldunn2000 at gmail.com Tue Jul 20 11:33:57 2010 From: jldunn2000 at gmail.com (loial) Date: Tue, 20 Jul 2010 08:33:57 -0700 (PDT) Subject: Kick off a delete command from python and not wait Message-ID: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> I have a requirement to kick off a shell script from a python script without waiting for it to complete. I am not bothered about any return code from the script. What is the easiest way to do this. I have looked at popen but cannot see how to do it. From dmitrey.kroshko at scipy.org Tue Jul 20 11:39:41 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:39:41 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> > e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. So can anyone explain me how to look into object's dict? As I have wrote, "something in dir(...)" requires O(numOfFields) while I would like to use o(log(n)) >How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. Could anyone provide an example of it to be implemented, taking into account that a user can manually set "myObject.size" to an integer value? From neilc at norwich.edu Tue Jul 20 11:39:42 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 20 Jul 2010 15:39:42 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <8alu9uFosjU2@mid.individual.net> On 2010-07-20, dmitrey wrote: > This doesn't stack with the following issue: sometimes user can > write in code "myObject.size = (some integer value)" and then > it will be involved in future calculations as ordinary fixed > value; if user doesn't supply it, but myObject.size is involved > in calculations, then the oofun is created to behave like > similar numpy.array attribute. Telling them, "Don't do that," is a good solution in Python. -- Neil Cerutti From dmitrey.kroshko at scipy.org Tue Jul 20 11:47:00 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:47:00 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <8alu9uFosjU2@mid.individual.net> Message-ID: <6ed6b050-ca1d-48db-81bf-d894d0ffb0c1@f6g2000yqa.googlegroups.com> On 20 ???, 18:39, Neil Cerutti wrote: > On 2010-07-20, dmitrey wrote: > > > This doesn't stack with the following issue: sometimes user can > > write in code "myObject.size = (some integer value)" and then > > it will be involved in future calculations as ordinary fixed > > value; if user doesn't supply it, but myObject.size is involved > > in calculations, then the oofun is created to behave like > > similar numpy.array attribute. > > Telling them, "Don't do that," is a good solution in Python. > > -- > Neil Cerutti But this is already documented feature, and it works as intended, so moving it into something like "myObject._size" will bring backward incompatibility and break all FuncDesigner user API and style, where no underlines are present, it will seem like a hack that it really is. Sometimes apriory knowing size value as fixed integer brings some code speedup, also, if a user supplies the value, a check for computed value wrt the provided size is performed each time. From ranavishal at gmail.com Tue Jul 20 11:49:44 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:49:44 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Chris, Thanks for the link. On Mon, Jul 19, 2010 at 11:43 PM, Chris Rebert wrote: > On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana wrote: > > Hi, > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > > http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm > > There are multiple layers of memory allocation involved. To avoid > thrashing+fragmentation and to improve efficiency, free memory is not > always immediately returned to the operating system. Example: If your > problem involved calling your 500MB function twice, free-ing after the > first call and then immediately re-allocating another 500MB of memory > for the second call would waste time. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranavishal at gmail.com Tue Jul 20 11:50:57 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:50:57 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Hi Christian, I am not sure which one is used in this case, I use htop to see the memory used by apache / python. Thanks Vishal Rana On Tue, Jul 20, 2010 at 5:31 AM, Christian Heimes wrote: > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > Are you talking about resident or virtual memory here? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranavishal at gmail.com Tue Jul 20 11:51:51 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:51:51 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Thanks for your input. On Mon, Jul 19, 2010 at 7:23 PM, Scott McCarty wrote: > I had this exactly same problem with Peel and as far as I could find there > is no way reclaiming this memory unless you set max requests, which will > kill the Apache children processes after that number of requests. It's > normally something used for debugging, but can be used to reclaim ram. > > On the flip side, you could find your machine servers down and your child > processes will reuse that memory when they receive another request that uses > a huge amount of ram. It really depends on how often you are doing that > kind of processing, how you want to tune apache. > > Scott M > > On Jul 19, 2010 9:31 PM, "Vishal Rana" wrote: > > Hi, > > > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > > > Thanks > > Vishal Rana > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 20 11:52:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 20 Jul 2010 17:52:25 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4C45C639.6050207@sequans.com> dmitrey wrote: > On 20 ???, 15:00, Jean-Michel Pichavant > wrote: > >> dmitrey wrote: >> >>> hi all, >>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>> it is overloaded in __getattr__, so if someone invokes >>> "myObject.size", it is generated (as another oofun) and connected to >>> myObject as attribute. >>> >>> So, when I invoke in other code part "hasattr(myObject, 'size')", >>> instead o returning True/False it goes to __getattr__ and starts >>> constructor for another one oofun, that wasn't intended behaviour. >>> Thus "hasattr(myObject, 'size')" always returns True. It prevents me >>> of some bonuses and new features to be done in FuncDesigner. >>> >>>>>> 'size' in dir(b) >>>>>> >>> False >>> >>>>>> hasattr(b,'size') >>>>>> >>> True >>> >>>>>> 'size' in dir(b) >>>>>> >>> True >>> >>> Could you fix it? >>> >> Quite simple, when calling b.size, return the computed value but do not >> set it as attribute, the value will be computed on each b.size call, and >> hasattr w. If you don't want to compute it each time, cause there no >> reason for it to change, use a private dummy attribute to record the >> value instead of size (__size for instance) and return the value of >> __size when getting the value of size. >> >> class Foo(object): >> def __init__(self): >> self.__size = None >> >> def __getattr__(self, name): >> if name == "size": >> if self.__size is None: >> self.__size = 5 # compute the value >> return self.__size >> raise AttributeError(name) >> >> b = Foo() >> print 'size' in dir(b) >> print hasattr(b, 'size') >> print 'size' in dir(b) >> >> False >> True >> False >> >> JM >> > > This doesn't stack with the following issue: sometimes user can write > in code "myObject.size = (some integer value)" and then it will be > involved in future calculations as ordinary fixed value; if user > doesn't supply it, but myObject.size is involved in calculations, then > the oofun is created to behave like similar numpy.array attribute. > Here are some solutions in my humble order of preference: 1/ ask the user to always fill the size field 2/ ask the user to never fill the size filed (you can override __setattr__ to make sure...) 3/ override __setattr__ to set __size instead of size JM From duncan.booth at invalid.invalid Tue Jul 20 11:52:52 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jul 2010 15:52:52 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: dmitrey wrote: >> e.g. one that just looks in the object's dictionary so as to avoid >> returning true for properties or other such fancy attributes. > > So can anyone explain me how to look into object's dict? As I have > wrote, "something in dir(...)" requires O(numOfFields) while I would > like to use o(log(n)) O(1) might be even better. Try this: def dmitry_hasattr(obj, name): """Checks for existence of an attribute directly in an object's dictionary. Doesn't see all attributes but doesn't have side effects.""" d = getattr(obj, '__dict__') if d is not None: return name in d return False -- Duncan Booth http://kupuguy.blogspot.com From lists at cheimes.de Tue Jul 20 11:53:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 17:53:54 +0200 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: <4C45C692.8030804@cheimes.de> Am 20.07.2010 17:50, schrieb Vishal Rana: > Hi Christian, > > I am not sure which one is used in this case, I use htop to see the memory > used by apache / python. In its default configuration htop reports three different types of memory usage: virt, res and shr (virtual, resident and shared memory). Which of them stays at 500 MB? Christian From robert.kern at gmail.com Tue Jul 20 12:05:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 12:05:19 -0400 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> Message-ID: On 7/20/10 6:59 AM, dmitrey wrote: > On Jul 20, 1:37 pm, Chris Rebert wrote: >> Least ugly suggestion: Just don't use hasattr(); use your `x in >> dir(y)` trick instead. > > something in dir() consumes O(n) operations for lookup, while hasattr > or getattr() require O(log(n)). It matters for me, because it's inside > deeply nested mathematical computations FuncDesigner is made for. I'm not sure where you are getting log(n) from, but regardless, if you have so many attributes that the O() matters more than the constant, you have more problems than this. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Tue Jul 20 12:06:58 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 12:06:58 -0400 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: On 7/20/10 11:39 AM, dmitrey wrote: >> e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. > > So can anyone explain me how to look into object's dict? As I have > wrote, "something in dir(...)" requires O(numOfFields) while I would > like to use o(log(n)) ('size' in obj.__dict__) is O(1) with a pretty low constant. -- 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 ian.g.kelly at gmail.com Tue Jul 20 12:19:17 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Jul 2010 10:19:17 -0600 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 9:39 AM, dmitrey wrote: >>How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. > > Could anyone provide an example of it to be implemented, taking into > account that a user can manually set "myObject.size" to an integer > value? The following will work in Python 2.6+: class MyClass(object): @property def size(self): if not hasattr(self, '_size'): self._size = self._compute_size() return self._size @size.setter def size(self, value): self._size = value To support earlier versions of Python, you would write it like so: class MyClass(object): def _get_size(self): if not hasattr(self, '_size'): self._size = self._compute_size() return self._size def _set_size(self, value): self._size = value size = property(_get_size, _set_size) From animator333 at gmail.com Tue Jul 20 12:45:25 2010 From: animator333 at gmail.com (King) Date: Tue, 20 Jul 2010 09:45:25 -0700 (PDT) Subject: Compile python executable only for package deployment on Linux Message-ID: Hi, I have created a simple tool(python script) that creates a self sufficient package ready for deployment. Current implementation is based on shell scripting to set environment for the app and finally execute "python main.py". I am planning to convert "main.py" into an executable. The plan is to rip the unnecessary code from source code that produce python executable such as command line arguments etc, use "main.py" as python string (hardcoded inside executable source) and execute it using "exec" or similar methods and finally creates executable. Am I right here? Is this is the correct approach? For example a simple script: import os import math print math.sin(23.0) print os.getenv("PATH") Once I'll convert above script as i have mentioned above in an executable say: "myapp", executing "myapp" will print messages on console. Cheers Prashant From ranavishal at gmail.com Tue Jul 20 13:04:02 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 10:04:02 -0700 Subject: How is memory managed in python? In-Reply-To: <4C45C692.8030804@cheimes.de> References: <4C45C692.8030804@cheimes.de> Message-ID: Christian, It stays in RES and VIRT as well. Thanks Vishal Rana On Tue, Jul 20, 2010 at 8:53 AM, Christian Heimes wrote: > Am 20.07.2010 17:50, schrieb Vishal Rana: > > Hi Christian, > > > > I am not sure which one is used in this case, I use htop to see the > memory > > used by apache / python. > > In its default configuration htop reports three different types of > memory usage: virt, res and shr (virtual, resident and shared memory). > Which of them stays at 500 MB? > > Christian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Tue Jul 20 13:25:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Jul 2010 19:25:23 +0200 Subject: Compile python executable only for package deployment on Linux In-Reply-To: References: Message-ID: King, 20.07.2010 18:45: > I have created a simple tool(python script) that creates a self > sufficient package ready for deployment. Current implementation is > based on shell scripting to set environment for the app and finally > execute "python main.py". > > I am planning to convert "main.py" into an executable. The plan is to > rip the unnecessary code from source code that produce python > executable such as command line arguments etc, use "main.py" as python > string (hardcoded inside executable source) and execute it using > "exec" or similar methods and finally creates executable. > > Am I right here? Is this is the correct approach? From what you write here, I'm not exactly sure what you want to achieve, but... > For example a simple script: > > import os > import math > print math.sin(23.0) > print os.getenv("PATH") > > Once I'll convert above script as i have mentioned above in an > executable say: "myapp", executing "myapp" will print messages on > console. Assuming that Python is installed on the machine and readily runnable from the PATH, this will make the script executable: #!/usr/bin/env python import os import math ... Note that the file must have the executable bit set. Search for "shebang", which is the spelled-out name for the "#!" special file prefix. Stefan From hujia06 at gmail.com Tue Jul 20 13:28:41 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 20 Jul 2010 13:28:41 -0400 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: sub = subprocess.Popen("shell command", shell=True) If you have to wait the shell finishes its commands and then continue the next Python code. You can add another line: sub.wait() On Tue, Jul 20, 2010 at 7:57 AM, S.Selvam wrote: > > > On Tue, Jul 20, 2010 at 7:11 AM, Ranjith Kumar wrote: > >> Hi Folks, >> Can anyone tell me how to run shell commands using python script. >> > >> > > For simple work, i generally use os.system call. > > -- > Regards, > S.Selvam > > " I am because we are " > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 20 13:32:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 10:32:12 -0700 Subject: Kick off a delete command from python and not wait In-Reply-To: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> References: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 8:33 AM, loial wrote: > I have a requirement to kick off a shell script from a python script > without waiting for it to complete. I am not bothered about any return > code from the script. > > What is the easiest way to do this. I have looked at popen but cannot > see how to do it. Use the `subprocess` module. import subprocess proc = subprocess.Popen(["shell_script.sh", "arg1", "arg2"], stdout=subprocess.PIPE, stderr=subprcoess.PIPE) # lots of code here doing other stuff proc.wait() I believe you need to /eventually/ call .wait() as shown to avoid the child becoming a zombie process. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Jul 20 13:42:16 2010 From: animator333 at gmail.com (King) Date: Tue, 20 Jul 2010 10:42:16 -0700 (PDT) Subject: Compile python executable only for package deployment on Linux References: Message-ID: <39ac3ceb-d396-4464-8107-4f5d798e9a4a@y32g2000prc.googlegroups.com> Hi Stefan, Well, the idea is similar to package tools like pyinstaller or cx_freeze. There approach is slightly different then what I intend to do here. You have to pass the name of the script to python executable("python main.py") in order to execute it. What I mean here is to create python executable using python executable source code only(not compilation of entire python using source code) and insert "main.py" contents in source code(hardcoded) and produce a new executable. When you run that executable, it should run the "main.py", which was hard coded while building using fixed string or any other method. The executable is actually a modified version of python executable. It won't take any argument because we'll rip that piece of code out. Hope this will clear out. Cheers prashant From tjreedy at udel.edu Tue Jul 20 15:24:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jul 2010 15:24:42 -0400 Subject: urllib2 test fails (2.7, linux) In-Reply-To: References: Message-ID: On 7/20/2010 7:42 AM, guandalino wrote: > Hi, running Python 2.7 test suite for urllib2 there is a test that > doesn't pass. > Do you have an idea about where the problem could be and how to solve > it? > > Thanks, > best regards. > > $ # ubuntu 8.04 > $ pwd > ~/sandbox/2.7/lib/python2.7/test > $ python test_urllib2.py > ====================================================================== > ERROR: test_file (__main__.HandlerTests) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "test_urllib2.py", line 711, in test_file > h.file_open, Request(url)) Look there to find the complete statement. For 3.1, it would be self.assertRaises(urllib.error.URLError, h.file_open, Request(url)) (urllib2 is now urllib.request) You could insert a print to find what url caused a problem. > File "/home/redt/sandbox/2.7/lib/python2.7/unittest/case.py", line This puzzles me. In 3.1, unittest is a module, unittest.py, not a package containing modules like 'case.py'. I though it was the same for 2.7 > 456, in assertRaises > callableObj(*args, **kwargs) This is in unittest.py. It says that this test case *should* fail, but with a different error (urllib.error.URLError) than the one you got (gaierror). > File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, > in file_open > return self.open_local_file(req) > File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, > in open_local_file > (not port and socket.gethostbyname(host) in self.get_names()): > gaierror: [Errno -5] No address associated with hostname gaierror comes from socket.gethostbyname > Finally, I don't know if this matters but the tests have been executed > offline (without an internet connection). Since error is in open_local_file, I would think not. -- Terry Jan Reedy From b3nder at yandex.ru Tue Jul 20 15:26:52 2010 From: b3nder at yandex.ru (Alexander) Date: Tue, 20 Jul 2010 23:26:52 +0400 Subject: convert time to UTC seconds since epoch Message-ID: <4C45F87C.1040607@yandex.ru> Hi, list How with python standard library to convert string like 'YYYY-MM-DD mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time zone or given in explicit way like +0100. From rami.chowdhury at gmail.com Tue Jul 20 16:46:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 20 Jul 2010 13:46:44 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: <4C45F87C.1040607@yandex.ru> References: <4C45F87C.1040607@yandex.ru> Message-ID: <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> On Jul 20, 2010, at 12:26 , Alexander wrote: > Hi, list > > How with python standard library to convert string like 'YYYY-MM-DD > mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time > zone or given in explicit way like +0100. If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? HTH, Rami ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From kaklis at gmail.com Tue Jul 20 17:38:35 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 20 Jul 2010 14:38:35 -0700 (PDT) Subject: linux console command line history Message-ID: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Hi to all, I 'm writing a linux console app with sockets. It's basically a client app that fires commands in a server. For example: $log user 55 $sessions list $server list etc. What i want is, after entering some commands, to press the up arrow key and see the previous commands that i have executed. Any hints? Any examples? Antonis From nobody at nowhere.com Tue Jul 20 17:44:11 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 20 Jul 2010 22:44:11 +0100 Subject: Kick off a delete command from python and not wait References: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> Message-ID: On Tue, 20 Jul 2010 10:32:12 -0700, Chris Rebert wrote: > I believe you need to /eventually/ call .wait() as shown to avoid the > child becoming a zombie process. Alternatively, you can call .poll() periodically. This is similar to .wait() insofar as it will "reap" the process if it has terminated, but unlike .wait(), .poll() won't block if the process is still running. On Unix, you can use os.fork(), have the child execute the command in the background, and have the parent wait for the child with os.wait(). The child will terminate as soon as it has spawned the grandchild, and the grandchild will be reaped automatically upon termination (so you can forget about it). From benjamin.kaplan at case.edu Tue Jul 20 17:47:00 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 20 Jul 2010 14:47:00 -0700 Subject: linux console command line history In-Reply-To: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 2:38 PM, kaklis at gmail.com wrote: > Hi to all, > I 'm writing a linux console app with sockets. It's basically a client > app that fires commands in a server. > For example: > $log user 55 > $sessions list > $server list etc. > What i want is, after entering some commands, to press the up arrow > key and see the previous commands that i have executed. > Any hints? Any examples? > > Antonis > -- Look at the readline module. http://docs.python.org/library/readline.html From tjreedy at udel.edu Tue Jul 20 17:58:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jul 2010 17:58:33 -0400 Subject: How to treat the first or last item differently Message-ID: A Python newcomer asked this question on python-ideas list. I am answering here for the benefit of others. Example: building a string res with commas separating substrings s from some sequence. Either the first item added must be s versus ', '+s or the last must be s versus s+', '. For building strings, of course, the join method solves the problem, adding n-1 separators between n items. items = ['first', 'second', 'last'] print(', '.join(items)) #first, second, last DISCLAIMER: All of the following code chunks produce the same result, for the purpose of illustration, but they are NOT the way to build a string result with dependable efficiency. To treat the first item differently, either peel it off first ... it = iter(items) try: # protect against empty it, simplify if know not res = next(it) for s in it: res += ', ' + s except StopIteration: res = '' print(res) # first, second, last or use a flag. res = '' First = True for s in items: if First: res=s First=False else: res += ', ' + s print(res) # first, second, last There is no way, in general, to know whether next(it) will yield another item after the current one. That suggests that the way to know whether an item is the last or not is try to get another first, before processing the current item. One approach is to look ahead ... it = iter(items) res = '' try: cur = next(it) for nxt in it: # cur is not last res += cur + ', ' cur = nxt else: # cur is last item res += cur except StopIteration: pass print(res) # first, second, last Another is to add a unique sentinel to the sequence. Last = object() items.append(Last) # so not empty, so no protection against that needed it = iter(items) res = '' cur = next(it) for nxt in it: if nxt is not Last: res += cur + ', ' cur = nxt else: res += cur print(res) # first, second, last It makes sense to separate last detection from item processing so last detection can be put in a library module and reused. def o_last(iterable): " Yield item,islast pairs" it = iter(iterable) cur = next(it) for nxt in it: yield cur,False cur = nxt else: yield cur,True def comma_join(strings): res = '' for s,last in o_last(strings): res += s if not last: res += ', ' return res print(comma_join(['first', 'second', 'last'])) print(comma_join(['first', 'last'])) print(comma_join(['last'])) print(comma_join([])) # first, second, last # first, last # last # -- Terry Jan Reedy From peter.milliken at gmail.com Tue Jul 20 18:01:03 2010 From: peter.milliken at gmail.com (Peter) Date: Tue, 20 Jul 2010 15:01:03 -0700 (PDT) Subject: Pickle MemoryError - any ideas? Message-ID: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> I have created a class that contains a list of files (contents, binary) - so it uses a LOT of memory. When I first pickle.dump the list it creates a 1.9GByte file on the disk. I can load the contents back again, but when I attempt to dump it again (with or without additions), I get the following: Traceback (most recent call last): File "", line 1, in File "c:\Python26\Lib\pickle.py", line 1362, in dump Pickler(file, protocol).dump(obj) File "c:\Python26\Lib\pickle.py", line 224, in dump self.save(obj) File "c:\Python26\Lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\Python26\Lib\pickle.py", line 600, in save_list self._batch_appends(iter(obj)) File "c:\Python26\Lib\pickle.py", line 615, in _batch_appends save(x) File "c:\Python26\Lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\Python26\Lib\pickle.py", line 488, in save_string self.write(STRING + repr(obj) + '\n') MemoryError I get this error either attempting to dump the entire list or dumping it in "segments" i.e. the list is 2229 elements long, so from the command line I attempted using pickle to dump individual parts of the list into into files i.e. every 500 elements were saved to their own file - but I still get the same error. I used the following sequence when attempting to dump the list in segments - X and Y were 500 element indexes apart, the sequence fails on [1000:1500]: f = open('archive-1', 'wb', 2) pickle.dump(mylist[X:Y], f) f.close() I am assuming that available memory has been exhausted, so I tried "waiting" between dumps in the hopes that garbage collection might free some memory - but that doesn't help at all. In summary: 1. The list gets originally created from various sources 2. the list can be dumped successfully 3. the program restarts and successfully loads the list 4. the list can not be (re) dumped without getting a MemoryError This seems like a bug in pickle? Any ideas (other than the obvious - don't save all of these files contents into a list! Although that is the only "answer" I can see at the moment :-)). Thanks Peter From kwatford+python at gmail.com Tue Jul 20 18:09:22 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 18:09:22 -0400 Subject: Exposing buffer interface for non-extension types? Message-ID: Is there any way to expose the PEP 3118 buffer interface for objects that aren't extension types? Currently, I can expose the NumPy array interface (using either __array_interface__ or __array_struct__) for any class, extension or otherwise. But I can't find any reference to python-side interfacing for PEP 3118. SWIG makes an extension module for your wrapped code, but not extension *types*, so the classes it produces are pure-python with methods added in from the extension module. The NumPy array interface works fine for now (especially since NumPy is the only thing I need to consume these objects), but the documentation claims that it's being deprecated in favor of PEP 3118, so I thought it might be relevant to bring this up. From b3nder at yandex.ru Tue Jul 20 18:51:24 2010 From: b3nder at yandex.ru (Alexander) Date: Wed, 21 Jul 2010 02:51:24 +0400 Subject: convert time to UTC seconds since epoch In-Reply-To: <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> References: <4C45F87C.1040607@yandex.ru> <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> Message-ID: <4C46286C.6010708@yandex.ru> On 21.07.2010 00:46, Rami Chowdhury wrote: > On Jul 20, 2010, at 12:26 , Alexander wrote: > >> Hi, list >> >> How with python standard library to convert string like 'YYYY-MM-DD >> mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time >> zone or given in explicit way like +0100. > If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? > Yes. May be I don't undertand something. but it seems strptime doesn't work with timezones at all. Only understands localzone and dates w/o zones. From stefan_ml at behnel.de Tue Jul 20 18:58:15 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 00:58:15 +0200 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: Ken Watford, 21.07.2010 00:09: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? Given that it's a pure C-level interface, I don't think there would be much use for that. > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. SWIG makes an extension module for your wrapped code, > but not extension *types*, so the classes it produces are pure-python > with methods added in from the extension module. Try using Cython instead, it has native support for the buffer protocol. Stefan From emile at fenx.com Tue Jul 20 19:10:07 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 20 Jul 2010 16:10:07 -0700 Subject: Pickle MemoryError - any ideas? In-Reply-To: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: On 7/20/2010 3:01 PM Peter said... > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > Any ideas? Switch to 64 bit Windows & Python? Emile From kaklis at gmail.com Tue Jul 20 19:12:32 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 20 Jul 2010 16:12:32 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: <7f51c705-e53c-44e4-891f-0f731598f102@d37g2000yqm.googlegroups.com> On Jul 21, 12:47?am, Benjamin Kaplan wrote: > On Tue, Jul 20, 2010 at 2:38 PM, kak... at gmail.com wrote: > > Hi to all, > > I 'm writing a linux console app with sockets. It's basically a client > > app that fires commands in a server. > > For example: > > $log user 55 > > $sessions list > > $server list etc. > > What i want is, after entering some commands, to press the up arrow > > key and see the previous commands that i have executed. > > Any hints? Any examples? > > > Antonis > > -- > > Look at the readline module.http://docs.python.org/library/readline.html ok that's fine, thanks. I have also find a very helpful example in PyMoTW http://www.doughellmann.com/PyMOTW/readline/index.html(Thanks Doug!!!). But if i want to run this in it's own separate thread, how could i do that? there is an # Prompt the user for text input_loop() which is blocking? Antonis K. From pavlovevidence at gmail.com Tue Jul 20 20:06:50 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 17:06:50 -0700 (PDT) Subject: Pickle MemoryError - any ideas? References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: On Jul 20, 3:01?pm, Peter wrote: > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > > When I first pickle.dump the list it creates a 1.9GByte file on the > disk. I can load the contents back again, but when I attempt to dump > it again (with or without additions), I get the following: > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\Python26\Lib\pickle.py", line 1362, in dump > ? ? Pickler(file, protocol).dump(obj) > ? File "c:\Python26\Lib\pickle.py", line 224, in dump > ? ? self.save(obj) > ? File "c:\Python26\Lib\pickle.py", line 286, in save > ? ? f(self, obj) # Call unbound method with explicit self > ? File "c:\Python26\Lib\pickle.py", line 600, in save_list > ? ? self._batch_appends(iter(obj)) > ? File "c:\Python26\Lib\pickle.py", line 615, in _batch_appends > ? ? save(x) > ? File "c:\Python26\Lib\pickle.py", line 286, in save > ? ? f(self, obj) # Call unbound method with explicit self > ? File "c:\Python26\Lib\pickle.py", line 488, in save_string > ? ? self.write(STRING + repr(obj) + '\n') > MemoryError (Aside) Wow, pickle concatenates strings like this? > I get this error either attempting to dump the entire list or dumping > it in "segments" i.e. the list is 2229 elements long, so from the > command line I attempted using pickle to dump individual parts of the > list into into files i.e. every 500 elements were saved to their own > file - but I still get the same error. > > I used the following sequence when attempting to dump the list in > segments - X and Y were 500 element indexes apart, the sequence fails > on [1000:1500]: > > f = open('archive-1', 'wb', 2) > pickle.dump(mylist[X:Y], f) > f.close() First thing to do is try cPickle module instead of pickle. > I am assuming that available memory has been exhausted, so I tried > "waiting" between dumps in the hopes that garbage collection might > free some memory - but that doesn't help at all. Waiting won't trigger a garbage collection. Well first of all, it's not garbage collection but cycle collection (objects not part of refernce cycles are collected immediately after they're destroyed, at least they are in CPyhton), and given that your items are all binary data, I doubt there are many reference cycles in your data. Anyway, cycle collection is triggered when object creation/deletion counts meet certain criteria (which won't happen if you are waiting), but you could call gc.collect() to force a cycle collection. > In summary: > > 1. The list gets originally created from various sources > 2. the list can be dumped successfully > 3. the program restarts and successfully loads the list > 4. the list can not be (re) dumped without getting a MemoryError > > This seems like a bug in pickle? No > Any ideas (other than the obvious - don't save all of these files > contents into a list! Although that is the only "answer" I can see at > the moment :-)). You should at least consider if one of the dbm-style databases (dbm, gdbm, or dbhash) meets your needs. Carl Banks From neoethical at gmail.com Tue Jul 20 20:27:26 2010 From: neoethical at gmail.com (neoethical) Date: Tue, 20 Jul 2010 20:27:26 -0400 Subject: Set Python Path for Idle Mac 10.5 Message-ID: Hi, New to programming and after doing some research I've chosed to work with Python. One thing that's bothering me is that I would like to set up a specific folder in my Documents folder to hold my modules. How do I go about doing this? I've found the way to change it for each IDLE session but I'd like to make it check the folder automatically. I've done a bunch of searches and have come up with nothing helpful. Thanks. -Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Jul 20 20:28:12 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 17:28:12 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: Message-ID: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> On Jul 20, 3:09?pm, Ken Watford wrote: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? > > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. SWIG makes an extension module for your wrapped code, > but not extension *types*, so the classes it produces are pure-python > with methods added in from the extension module. > > The NumPy array interface works fine for now (especially since NumPy > is the only thing I need to consume these objects), but the > documentation claims that it's being deprecated in favor of PEP 3118, > so I thought it might be relevant to bring this up. Can you tell let us know what you want to use it for? We could offer better help. Numpy is generally how I get at buffers in Python 2.x. For instance if I have an object m that supports buffer protocol (m could a string, mmap object, Python array, etc.), then the following will create an array view of the same buffer: numpy.ndarray((10,10),type=numpy.float32,buffer=m) As far as I know this procedure won't be too different under PEP 3118; if anything it's simplified in Python 3 since it can discover type and shape information itself. (You'll have to check with the numpy people on that.) Carl Banks From kwatford+python at gmail.com Tue Jul 20 20:38:27 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 20:38:27 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel wrote: > Ken Watford, 21.07.2010 00:09: >> >> Is there any way to expose the PEP 3118 buffer interface for objects >> that aren't extension types? > > Given that it's a pure C-level interface, I don't think there would be much > use for that. Perhaps, but *why* is it only a pure C-level interface? It's based on/inspired by the array interface, which was not a pure C-level interface. Did they simply neglect to provide the functionality due to lack of obvious use cases, or did they consciously decide to drop that functionality? >> Currently, I can expose the NumPy array interface (using either >> __array_interface__ or __array_struct__) for any class, extension or >> otherwise. But I can't find any reference to python-side interfacing >> for PEP 3118. SWIG makes an extension module for your wrapped code, >> but not extension *types*, so the classes it produces are pure-python >> with methods added in from the extension module. > > Try using Cython instead, it has native support for the buffer protocol. I've used Cython before, and I generally like it. But its purpose is slightly different than SWIG's, and does not particularly meet my current project's needs. From nagle at animats.com Tue Jul 20 20:58:03 2010 From: nagle at animats.com (John Nagle) Date: Tue, 20 Jul 2010 17:58:03 -0700 Subject: Pickle MemoryError - any ideas? In-Reply-To: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: <4c46462f$0$1608$742ec2ed@news.sonic.net> On 7/20/2010 3:01 PM, Peter wrote: > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > > When I first pickle.dump the list it creates a 1.9GByte file on the > disk. I can load the contents back again, but when I attempt to dump > it again (with or without additions), I get the following: Be sure to destroy the pickle object when you're done with it. Don't reuse it. Pickle has a cache - it saves every object pickled, and if the same object shows up more than once, the later instances are represented as a cache ID. This can fill memory unnecessarily. See "http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f8b999c25af263a" John Nagle From ian.g.kelly at gmail.com Tue Jul 20 21:01:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Jul 2010 19:01:48 -0600 Subject: convert time to UTC seconds since epoch In-Reply-To: <4C46286C.6010708@yandex.ru> References: <4C45F87C.1040607@yandex.ru> <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> <4C46286C.6010708@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 4:51 PM, Alexander wrote: > ?On 21.07.2010 00:46, Rami Chowdhury wrote: >> On Jul 20, 2010, at 12:26 , Alexander wrote: >> >>> Hi, list >>> >>> How with python standard library to convert string like 'YYYY-MM-DD >>> mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time >>> zone or given in explicit way like +0100. >> If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? >> > Yes. May be I don't undertand something. but it seems strptime doesn't > work with timezones at all. Only understands localzone and dates w/o zones. Have you looked at the dateutil.parser module? It's not part of the standard library but probably does what you need. http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2 Cheers, Ian From kwatford+python at gmail.com Tue Jul 20 21:04:01 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 21:04:01 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote: > On Jul 20, 3:09?pm, Ken Watford wrote: >> Is there any way to expose the PEP 3118 buffer interface for objects >> that aren't extension types? >> >> Currently, I can expose the NumPy array interface (using either >> __array_interface__ or __array_struct__) for any class, extension or >> otherwise. But I can't find any reference to python-side interfacing >> for PEP 3118. SWIG makes an extension module for your wrapped code, >> but not extension *types*, so the classes it produces are pure-python >> with methods added in from the extension module. >> >> The NumPy array interface works fine for now (especially since NumPy >> is the only thing I need to consume these objects), but the >> documentation claims that it's being deprecated in favor of PEP 3118, >> so I thought it might be relevant to bring this up. > > Can you tell let us know what you want to use it for? ?We could offer > better help. > > Numpy is generally how I get at buffers in Python 2.x. ?For instance > if I have an object m that supports buffer protocol (m could a string, > mmap object, Python array, etc.), then the following will create an > array view of the same buffer: > > numpy.ndarray((10,10),type=numpy.float32,buffer=m) > > As far as I know this procedure won't be too different under PEP 3118; > if anything it's simplified in Python 3 since it can discover type and > shape information itself. ?(You'll have to check with the numpy people > on that.) I'm not having trouble using buffers, I'm having trouble providing them. As a part of SWIG-wrapping a larger C++ project, I'm producing some wrappings for Blitz++ arrays. I can extract the shape and stride information from the array object to fill either NumPy's or PEP 3118's appropriate structure. In the case of NumPy, I can easily arrange for the necessary interface on the proxy object to be fulfilled, because NumPy doesn't care what kind of object it's attached to. But the PEP 3118 interface can only be provided by C extension types. One possibility I've considered is injecting a small extension type into the wrapper that provides PEP 3118 by reading the NumPy array interface info off of the object, and then inject it into all appropriate SWIG-generated proxy classes as an additional base class. This isn't a big deal for me - the array interface works just fine, and probably will for longer than I'll be working on this project - but it just struck me as strange that some of my existing array-interface-enabled classes can't be trivially ported to PEP 3118 because they're defined in pure Python modules rather than extension modules. From fabiofz at gmail.com Tue Jul 20 21:09:51 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 20 Jul 2010 22:09:51 -0300 Subject: Pydev 1.6.0 Released Message-ID: Hi All, Pydev 1.6.0 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Debugger o Code-completion added to the debug console o Entries in the debug console are evaluated on a line-by-line basis (previously an empty line was needed) o Threads started with thread.start_new_thread are now properly traced in the debugger o Added method -- pydevd.set_pm_excepthook() -- which clients may use to debug uncaught exceptions o Printing exception when unable to connect in the debugger * General o Interactive console may be created using the eclipse vm (which may be used for experimenting with Eclipse) o Apply patch working (Fixed NPE when opening compare editor in a dialog) o Added compatibility to Aptana Studio 3 (Beta) -- release from July 12th What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From sturlamolden at yahoo.no Tue Jul 20 21:17:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 20 Jul 2010 18:17:17 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: Message-ID: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> On 21 Jul, 02:38, Ken Watford wrote: > Perhaps, but *why* is it only a pure C-level interface? It is exposed to Python as memoryview. If memoryview is not sufficient, we can use ctypes.pythonapi to read the C struct. From robert.kern at gmail.com Tue Jul 20 21:26:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 21:26:03 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On 7/20/10 8:38 PM, Ken Watford wrote: > On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel wrote: >> Ken Watford, 21.07.2010 00:09: >>> >>> Is there any way to expose the PEP 3118 buffer interface for objects >>> that aren't extension types? >> >> Given that it's a pure C-level interface, I don't think there would be much >> use for that. > > Perhaps, but *why* is it only a pure C-level interface? It's based > on/inspired by the array interface, which was not a pure C-level > interface. Did they simply neglect to provide the functionality due to > lack of obvious use cases, or did they consciously decide to drop that > functionality? Lack of obvious use cases. The primary use case is for C extensions to communicate with each other. SWIG is the odd man out in that it does not create true extension types. While the functionality of the PEP derives from numpy's interface, it's inclusion in Python was largely seen as the extension of the older buffer interface which is also a pure C interface. The Python-level __array_interface__ numpy API is not and will not be deprecated despite some outdated language in the documentation. Please continue to use 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 greg.hennessy at cox.net Tue Jul 20 21:31:28 2010 From: greg.hennessy at cox.net (Greg Hennessy) Date: Wed, 21 Jul 2010 01:31:28 +0000 (UTC) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: On 2010-07-20, Rami Chowdhury wrote: > If you have a sufficiently recent version of Python, have you >considered time.strptime: >http://docs.python.org/library/time.html#time.strptime ? Given the documentation talks about "double leap seconds" which don't exist, why should this code be trusted? From kwatford+python at gmail.com Tue Jul 20 21:39:23 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 21:39:23 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 9:26 PM, Robert Kern wrote: > On 7/20/10 8:38 PM, Ken Watford wrote: >> >> On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel >> ?wrote: >>> >>> Ken Watford, 21.07.2010 00:09: >>>> >>>> Is there any way to expose the PEP 3118 buffer interface for objects >>>> that aren't extension types? >>> >>> Given that it's a pure C-level interface, I don't think there would be >>> much >>> use for that. >> >> Perhaps, but *why* is it only a pure C-level interface? It's based >> on/inspired by the array interface, which was not a pure C-level >> interface. Did they simply neglect to provide the functionality due to >> lack of obvious use cases, or did they consciously decide to drop thaThat >> functionality? > > Lack of obvious use cases. The primary use case is for C extensions to > communicate with each other. SWIG is the odd man out in that it does not > create true extension types. While the functionality of the PEP derives from > numpy's interface, it's inclusion in Python was largely seen as the > extension of the older buffer interface which is also a pure C interface. > > The Python-level __array_interface__ numpy API is not and will not be > deprecated despite some outdated language in the documentation. Please > continue to use it. Thanks, that's good to know. (Someone should probably do something about the big red box that says the opposite in the current docs). I assume the same is true about __array_struct__? Since it *is* an extension despite the non-extension types, filling in a structure is a little more convenient than building the dictionary. From clp2 at rebertia.com Tue Jul 20 21:44:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 18:44:40 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: References: <4C45F87C.1040607@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: > On 2010-07-20, Rami Chowdhury wrote: >> If you have a sufficiently recent version of Python, have you >>considered time.strptime: >>http://docs.python.org/library/time.html#time.strptime ? > > Given the documentation talks about "double leap seconds" which don't > exist, why should this code be trusted? Because they exist(ed) in POSIX. See http://www.ucolick.org/~sla/leapsecs/onlinebib.html : """ The standards committees decided that POSIX time should be UTC, but the early POSIX standards inexplicably incorporated a concept which never existed in UTC -- the ``double leap second''. This mistake reportedly existed in the POSIX standard from 1989, and it persisted in POSIX until at least 1997. """ Cheers, Chris -- http://blog.rebertia.com From greg.hennessy at cox.net Tue Jul 20 21:48:58 2010 From: greg.hennessy at cox.net (Greg Hennessy) Date: Wed, 21 Jul 2010 01:48:58 +0000 (UTC) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: On 2010-07-21, Chris Rebert wrote: > On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: >> Given the documentation talks about "double leap seconds" which don't >> exist, why should this code be trusted? > > Because they exist(ed) in POSIX. Why should POSIX time calculations involving leap seconds be trusted? This is a pet peeve of mine, when will someone actually implement leap seconds correctly? And as a professional astronomer myself, I'm well aware of Steve Allen's website. :) From clp2 at rebertia.com Tue Jul 20 21:57:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 18:57:44 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: References: <4C45F87C.1040607@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 6:48 PM, Greg Hennessy wrote: > On 2010-07-21, Chris Rebert wrote: >> On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: >>> Given the documentation talks about "double leap seconds" which don't >>> exist, why should this code be trusted? >> >> Because they exist(ed) in POSIX. > > Why should POSIX time calculations involving leap seconds be trusted? I'm not saying they necessarily should, but they're standardized and the `time` module is based on POSIX/Unix-ish assumptions; not following POSIX would be inconsistent and problematic. Breaking standards is bad, M'Kay? > This is a pet peeve of mine, when will someone actually implement leap > seconds correctly? Well, at least there's the possibility they will be eliminated in the future anyway, which would make their implementation a non-issue. :-) Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Tue Jul 20 21:58:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 21:58:15 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On 7/20/10 9:39 PM, Ken Watford wrote: > On Tue, Jul 20, 2010 at 9:26 PM, Robert Kern wrote: >> On 7/20/10 8:38 PM, Ken Watford wrote: >>> >>> On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel >>> wrote: >>>> >>>> Ken Watford, 21.07.2010 00:09: >>>>> >>>>> Is there any way to expose the PEP 3118 buffer interface for objects >>>>> that aren't extension types? >>>> >>>> Given that it's a pure C-level interface, I don't think there would be >>>> much >>>> use for that. >>> >>> Perhaps, but *why* is it only a pure C-level interface? It's based >>> on/inspired by the array interface, which was not a pure C-level >>> interface. Did they simply neglect to provide the functionality due to >>> lack of obvious use cases, or did they consciously decide to drop thaThat >>> functionality? >> >> Lack of obvious use cases. The primary use case is for C extensions to >> communicate with each other. SWIG is the odd man out in that it does not >> create true extension types. While the functionality of the PEP derives from >> numpy's interface, it's inclusion in Python was largely seen as the >> extension of the older buffer interface which is also a pure C interface. >> >> The Python-level __array_interface__ numpy API is not and will not be >> deprecated despite some outdated language in the documentation. Please >> continue to use it. > > Thanks, that's good to know. (Someone should probably do something > about the big red box that says the opposite in the current docs). I just did. I'm sorry; we had a discussion about that some time ago, and I thought we had removed it then. > I assume the same is true about __array_struct__? Since it *is* an > extension despite the non-extension types, filling in a structure is a > little more convenient than building the dictionary. Yes, __array_struct__ is also not deprecated. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Tue Jul 20 22:02:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 22:02:17 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> References: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> Message-ID: On 7/20/10 9:17 PM, sturlamolden wrote: > On 21 Jul, 02:38, Ken Watford wrote: > >> Perhaps, but *why* is it only a pure C-level interface? > > It is exposed to Python as memoryview. That's not really his question. His question is why there is no way for a pure Python class (like SWIG wrappers) have no way to expose the buffer interface. memoryview allows pure Python code to *consume* the buffer interface but not for pure Python classes to *provide* 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 j.m.girven at warwick.ac.uk Tue Jul 20 22:13:29 2010 From: j.m.girven at warwick.ac.uk (D2Hitman) Date: Tue, 20 Jul 2010 19:13:29 -0700 (PDT) Subject: Multidimensional Fitting Message-ID: <29221343.post@talk.nabble.com> I want to fit an n-dimensional distribution with an n-dimensional gaussian. So far i have managed to do this in 2d (see below). I am not sure how to convert this to work in n-dimensions. Using "ravel" on the arrays is not ideal, but optimize does not appear to work on multidimensional arrays. It seems "meshgrid" also does not translate to nd. import numpy as np from scipy import optimize #2D #random points N = 1000 nd = 2 a = np.random.normal(loc=[1.,2.], scale=[1.,2.], size=[N,nd]) #histogram points bins = [10, 20] H, e = np.histogramdd(a, bins=bins) #find center rather than left edge edges = [] for i in range(len(e)): edges.append( e[i][:-1] + np.diff(e[i])/2. ) #not n-dimensional x, y = np.meshgrid(edges[0], edges[1]) x, y = np.ravel(x), np.ravel(y) H = np.ravel(H) #2D gaussian gauss2d = lambda p, x, y: p[0] * np.exp( (-0.5*(x-p[1])**2/p[2]**2) - (0.5*(y-p[3])**2/p[4]**2) ) + p[5] residuals = lambda p, x, y, H: H - gauss2d(p, x, y) #Fitting p0 = [1., 0., 1., 0., 1., 0] plsq, cov_x, infodict, mesg, ier = optimize.leastsq(residuals, p0, args=(x, y, H), full_output=True) #Reading off _x, _y = 0.091, 1.293 print '%.3f %.3f %.4f' % (_x, _y, gauss2d(plsq, _x,_y) / plsq[0]) -- View this message in context: http://old.nabble.com/Multidimensional-Fitting-tp29221343p29221343.html Sent from the Python - python-list mailing list archive at Nabble.com. From pavlovevidence at gmail.com Tue Jul 20 22:14:22 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 19:14:22 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: On Jul 20, 6:04?pm, Ken Watford wrote: > On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote: > > On Jul 20, 3:09?pm, Ken Watford wrote: > >> Is there any way to expose the PEP 3118 buffer interface for objects > >> that aren't extension types? > > >> Currently, I can expose the NumPy array interface (using either > >> __array_interface__ or __array_struct__) for any class, extension or > >> otherwise. But I can't find any reference to python-side interfacing > >> for PEP 3118. SWIG makes an extension module for your wrapped code, > >> but not extension *types*, so the classes it produces are pure-python > >> with methods added in from the extension module. > > >> The NumPy array interface works fine for now (especially since NumPy > >> is the only thing I need to consume these objects), but the > >> documentation claims that it's being deprecated in favor of PEP 3118, > >> so I thought it might be relevant to bring this up. > > > Can you tell let us know what you want to use it for? ?We could offer > > better help. > > > Numpy is generally how I get at buffers in Python 2.x. ?For instance > > if I have an object m that supports buffer protocol (m could a string, > > mmap object, Python array, etc.), then the following will create an > > array view of the same buffer: > > > numpy.ndarray((10,10),type=numpy.float32,buffer=m) > > > As far as I know this procedure won't be too different under PEP 3118; > > if anything it's simplified in Python 3 since it can discover type and > > shape information itself. ?(You'll have to check with the numpy people > > on that.) > > I'm not having trouble using buffers, I'm having trouble providing them. I see. > As a part of SWIG-wrapping a larger C++ project, I'm producing some > wrappings for Blitz++ arrays. I can extract the shape and stride > information from the array object to fill either NumPy's or PEP 3118's > appropriate structure. In the case of NumPy, I can easily arrange for > the necessary interface on the proxy object to be fulfilled, because > NumPy doesn't care what kind of object it's attached to. But the PEP > 3118 interface can only be provided by C extension types. Well, let's get the facts straight before proceeding. The buffer protocol has always been for C only. PEP 3118 is an extension to this buffer protocol, so it's also C only. Numpy's array interface is not the buffer protocol, and is specific to numpy (though I guess other types are free to use it among themselves, if they wish). So what you've been doing was *not* to provide buffers; it was to provide some numpy-specific methods that allowed numpy to discover your buffers. That said, your complaint is reasonable. And since the numpy docs say "use PEP 3118 instead of array interface" your misunderstanding is understandable. I assume it's not practical to address your real problem (i.e., SWIG), so we'll instead take it for granted that you have a block of memory in some custom C code that you can't expose as a real buffer. In the past, you've used numpy's special Python methods to let numpy know where your memory block was, but what do you do now? Your suggestion to write a small base class is probably the best you can do as things stand now. Another thing you can do is write a small extension to create a surrogate buffer object (that implements buffer protocol), so if you want to create an ndarray from a buffer you can do it like this: b = create_surrogate_buffer(pointer=_proxy.get_buffer_pointer()) numpy.ndarray(shape=_proxy.get_shape(),type=_proxy.get_type(),buffer=b) Not as convenient to use, but might be simpler to code up than the base-class solution. The numpy developers might be sympathetic to your concerns since you have a reasonable use case (they might also tell you you need to get a real wrapper generator). Just be sure to keep the distinction clear between "buffer protocol" (which is what PEP 3118 is, is C only, and the buffer must be owned by a Python object) and "array interface" (which is what you were using for 2.x, is C or Python, and the buffer can be anywhere). HTH Carl Banks From robert.kern at gmail.com Tue Jul 20 22:22:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 22:22:27 -0400 Subject: Multidimensional Fitting In-Reply-To: <29221343.post@talk.nabble.com> References: <29221343.post@talk.nabble.com> Message-ID: On 7/20/10 10:13 PM, D2Hitman wrote: > > I want to fit an n-dimensional distribution with an n-dimensional gaussian. > So far i have managed to do this in 2d (see below). I am not sure how to > convert this to work in n-dimensions. Using "ravel" on the arrays is not > ideal, but optimize does not appear to work on multidimensional arrays. It > seems "meshgrid" also does not translate to nd. You will want to ask scipy questions on the scipy mailing list: http://www.scipy.org/Mailing_Lists Don't try to fit a Gaussian to a histogram using least-squares. It's an awful way to estimate the parameters. Just use np.mean() and np.cov() to estimate the mean and covariance matrix directly. -- 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 nad at acm.org Tue Jul 20 22:48:19 2010 From: nad at acm.org (Ned Deily) Date: Tue, 20 Jul 2010 19:48:19 -0700 Subject: Set Python Path for Idle Mac 10.5 References: Message-ID: In article , neoethical wrote: > New to programming and after doing some research I've chosed to work with > Python. One thing that's bothering me is that I would like to set up a > specific folder in my Documents folder to hold my modules. How do I go about > doing this? I've found the way to change it for each IDLE session but I'd > like to make it check the folder automatically. I've done a bunch of > searches and have come up with nothing helpful. On OS X, depending on which version of Python you are using, there are usually two ways to start IDLE: either by launching IDLE.app (often found in /Applications/Python x.y or /Applications/MacPython x.y) or by invoking IDLE from the command line (generally something like /usr/local/bin/idlex.y). When started from a terminal command line, IDLE uses the current working directory ("folder") as the default for opening and saving files from the shell window. When you "launch" IDLE.app (by double-clicking on its icon, for example), it always uses Documents as the default working directory. Unfortunately, AFAIK, there is no built-in way to specify a different default for the shell window, which is a bit annoying. The simplest way to work around it, I think, would be to always start IDLE from the command line after changing to the desired default directory. So, from a terminal session (in Terminal.app or equivalent), something like this for, say, python3.1 installed from python.org: cd /path/to/default/directory /usr/local/bin/idle3.1 The equivalent could be turned into a shell function or alias or an AppleScript app or Automator action. >From the command line, you can also give IDLE a list of one or more files to open, each in its own file window. When the focus is on a file window, file command such as open and save default to the directory of the opened file (this is also true in IDLE.app). So you could have something like this: cd /path/to/project/directory /usr/local/bin/idle3.1 my_mod_1.py my_mod_2.py ... or, if you want to edit all of the python modules in a directory: cd /path/to/project/directory /usr/local/bin/idle3.1 *.py You can achieve a similar effect (except for the shell window) in the Finder by dragging the files to the IDLE.app icon (in a Finder window or on the dock). Double-clicking on the .py files themselves can be made to work but it's a bit of a crap shoot which version of IDLE or other app might actually be launched; it's best to avoid depending on that mechanism. -- Ned Deily, nad at acm.org From jason at powerpull.net Tue Jul 20 23:04:37 2010 From: jason at powerpull.net (Jason Friedman) Date: Wed, 21 Jul 2010 03:04:37 +0000 Subject: Trying to redirect every urel request to test.py script with the visitors page request as url parameter. In-Reply-To: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> References: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> Message-ID: 2010/7/20 ????? : > Hello guys! This is my first post in this group! I do not have an answer to your question, other than to suggest you look at (and/or post) relevant lines from Apache's access.log and error.log. I write mostly to say that, in my experience, folks on this list are very helpful, but your post has many, many spelling errors, making it difficult to read. It looks like you are using Gmail, which has a "Check Spelling" drop-down on the compose window. If you re-post with better spelling you might get more responses. From j.m.girven at warwick.ac.uk Tue Jul 20 23:56:40 2010 From: j.m.girven at warwick.ac.uk (D2Hitman) Date: Tue, 20 Jul 2010 20:56:40 -0700 (PDT) Subject: Multidimensional Fitting In-Reply-To: References: <29221343.post@talk.nabble.com> Message-ID: <29221776.post@talk.nabble.com> Robert Kern-2 wrote: > > Don't try to fit a Gaussian to a histogram using least-squares. It's an > awful > way to estimate the parameters. Just use np.mean() and np.cov() to > estimate the > mean and covariance matrix directly. > Ok, what about distributions other than gaussian? Would you use leastsq in that case? If yes, i will post that to the scipy mailing list. -- View this message in context: http://old.nabble.com/Multidimensional-Fitting-tp29221343p29221776.html Sent from the Python - python-list mailing list archive at Nabble.com. From robert.kern at gmail.com Wed Jul 21 00:31:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 Jul 2010 00:31:29 -0400 Subject: Multidimensional Fitting In-Reply-To: <29221776.post@talk.nabble.com> References: <29221343.post@talk.nabble.com> <29221776.post@talk.nabble.com> Message-ID: On 7/20/10 11:56 PM, D2Hitman wrote: > > > Robert Kern-2 wrote: >> >> Don't try to fit a Gaussian to a histogram using least-squares. It's an >> awful >> way to estimate the parameters. Just use np.mean() and np.cov() to >> estimate the >> mean and covariance matrix directly. >> > > Ok, what about distributions other than gaussian? Would you use leastsq in > that case? If yes, i will post that to the scipy mailing list. No, you would use a maximum likelihood method. -- 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 michele.simionato at gmail.com Wed Jul 21 02:03:41 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 20 Jul 2010 23:03:41 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: On Jul 20, 11:38?pm, "kak... at gmail.com" wrote: > Hi to all, > I 'm writing a linux console app with sockets. It's basically a client > app that fires commands in a server. > For example: > $log user 55 > $sessions list > $server list etc. > What i want is, after entering some commands, to press the up arrow > key and see the previous commands that i have executed. > Any hints? Any examples? > > Antonis You may find interesting to look at the source code for plac (http:// micheles.googlecode.com/hg/plac/doc/plac_adv.html). The readline support (including command history and autocompletion) is implemented in the ReadlineInput class (see http://code.google.com/p/micheles/source/browse/plac/plac_ext.py). If you just want command history you can use rlwrap (http:// freshmeat.net/projects/rlwrap). From kaklis at gmail.com Wed Jul 21 04:03:27 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 01:03:27 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: <63733ddf-9068-4e60-a031-141e20c571aa@f6g2000yqa.googlegroups.com> On Jul 21, 9:03?am, Michele Simionato wrote: > On Jul 20, 11:38?pm, "kak... at gmail.com" wrote: > > > Hi to all, > > I 'm writing a linux console app with sockets. It's basically a client > > app that fires commands in a server. > > For example: > > $log user 55 > > $sessions list > > $server list etc. > > What i want is, after entering some commands, to press the up arrow > > key and see the previous commands that i have executed. > > Any hints? Any examples? > > > Antonis > > You may find interesting to look at the source code for plac (http:// > micheles.googlecode.com/hg/plac/doc/plac_adv.html). The readline > support (including command history and autocompletion) is implemented > in the ReadlineInput class (seehttp://code.google.com/p/micheles/source/browse/plac/plac_ext.py). > If you just want command history you can use rlwrap (http:// > freshmeat.net/projects/rlwrap). That's great! thank you so much Michele! Antonis From __peter__ at web.de Wed Jul 21 04:16:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Jul 2010 10:16:42 +0200 Subject: How to treat the first or last item differently References: Message-ID: Terry Reedy wrote: > It makes sense to separate last detection from item processing so last > detection can be put in a library module and reused. Here's an extension of your idea that puts the detection of both the first and the last item into a generator: def mark_first(items): items = iter(items) yield True, next(items) for item in items: yield False, item def mark_last(items): items = iter(items) prev = next(items) for cur in items: yield False, prev prev = cur yield True, prev def mark_ends(items): return ((head, tail, item) for head, (tail, item) in mark_first(mark_last(items))) for items in "", "a", "ab", "abc": print list(items), "-->", list(mark_ends(items)) for first, last, item in mark_ends("abc"): if first: print "first", if last: print "last", print item It may not be the most efficient approach, but it looks clean. From stefan_ml at behnel.de Wed Jul 21 04:26:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 10:26:03 +0200 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: Ken Watford, 21.07.2010 03:04: >>> Currently, I can expose the NumPy array interface (using either >>> __array_interface__ or __array_struct__) for any class, extension or >>> otherwise. But I can't find any reference to python-side interfacing >>> for PEP 3118. SWIG makes an extension module for your wrapped code, >>> but not extension *types*, so the classes it produces are pure-python >>> with methods added in from the extension module. >> >> Try using Cython instead, it has native support for the buffer protocol. > > I've used Cython before, and I generally like it. But its purpose is > slightly different than SWIG's, and does not particularly meet my > current project's needs. >[...] > As a part of SWIG-wrapping a larger C++ project, I'm producing some > wrappings for Blitz++ arrays. Right, support for C++ templates in Cython isn't as good yet as it could be, although there has been some work in that direction. Contributions are welcome. However, note that you can write the tiny bit of plain C++ glue code necessary to access the Blitz++ arrays, and then use Cython to wrap that and to implement the buffer interface and all the other wrapper code. C++ support by itself is pretty good in Cython 0.13. (to be released soon, get it from here: http://hg.cython.org/cython-closures ) Stefan From massi_srb at msn.com Wed Jul 21 04:55:18 2010 From: massi_srb at msn.com (Massi) Date: Wed, 21 Jul 2010 01:55:18 -0700 (PDT) Subject: SQLalchemy+py2exe+pymssql error Message-ID: <433760cb-e55f-4778-a357-0649aa8b9f71@x21g2000yqa.googlegroups.com> Hi everyone, I'm trying to build an executable with py2exe. My script uses SQLalchemy and pymssql with python 2.6. Here is my setup file: from distutils.core import setup import py2exe manifest = """ myProgram """ setup(name="MyProg", windows=[{"script": "MyProg.py", "other_resources": [(24,1,manifest)]}], options={"py2exe": {"includes":[ "sqlalchemy.dialects.mssql", "pymssql", "_mssql"]}} ) The executable is successfully built up, but when I run the program I get the following error message: Exception in thread Thread-3: Traceback (most recent call last): File "threading.pyc", line 532, in __bootstrap_inner File "threading.pyc", line 484, in run File "MyProg.py", line 166, in DatabaseSetup File "sqlalchemy\engine\__init__.pyc", line 241, in create_engine File "sqlalchemy\engine\strategies.pyc", line 60, in create File "sqlalchemy\dialects\mssql\pymssql.pyc", line 61, in dbapi File "pymssql.pyc", line 12, in File "pymssql.pyc", line 10, in __load File "_mssql.pxd", line 10, in init pymssql (pymssql.c:7364) File "_mssql.pyc", line 12, in File "_mssql.pyc", line 10, in __load File "_mssql.pyx", line 36, in init _mssql (_mssql.c:14941) ImportError: No module named uuid Can anyone point me out what I am doing wrong? Thanks you in advance! From bluefisher80 at gmail.com Wed Jul 21 04:56:44 2010 From: bluefisher80 at gmail.com (Jim Qiu) Date: Wed, 21 Jul 2010 16:56:44 +0800 Subject: source install of python2.7 and rpm install of cx_Oracle collision Message-ID: Hi all, I make installed python 2.7 from source, and also installed the RPM version of cx_Oracle for python 2.7. But ldd tells me : #ldd cx_Oracle.so libpython2.7.so.1.0 => not found I find out that only libpython2.7.a generated when I install python2.7, who can tell me what I need to do ? I want a libpython2.7.so.1.0 generated when I install python. I am not familiar with GCC and .so .a stuff. Best regards, Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Jul 21 05:58:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 21 Jul 2010 11:58:41 +0200 Subject: Exposing buffer interface for non-extension types? References: Message-ID: <20100721115841.49d25acc@pitrou.net> On Tue, 20 Jul 2010 18:09:22 -0400 Ken Watford wrote: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? > > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. There is none, but feel free to make a proposal on python-ideas if you think there's an use case for it. Regards Antoine. From fetchinson at googlemail.com Wed Jul 21 06:02:09 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 21 Jul 2010 12:02:09 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: > I make installed python 2.7 from source, and also installed the RPM version > of cx_Oracle for python 2.7. > > But ldd tells me : > #ldd cx_Oracle.so > libpython2.7.so.1.0 => not found > > I find out that only libpython2.7.a generated when I install python2.7, who > can tell me what I need to do ? I want a libpython2.7.so.1.0 generated when > > > I install python. > > I am not familiar with GCC and .so .a stuff. In this case I'd recommend removing the source install of python 2.7, install it from rpm, followed by installing cx_Oracle from rpm. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kaklis at gmail.com Wed Jul 21 08:36:21 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 05:36:21 -0700 (PDT) Subject: Sorting a list created from a parsed xml message Message-ID: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Hi pythonistas, >From the subject of my message it's clear that i get an xml message from a socket, i parse it and the result is a list like the one that follows: ID_Col 4 Server ak ip OFFLINE 29 Server and2 ip OFFLINE 5 Proxy l34e ip OFFLINE 6 Proxy barc ip ONLINE 41 Proxy proxy-2 ip ONLINE 53 Server server-4 ip ONLINE 52 Server server-3 ip ONLINE What i want is to print this list sorted by ID_Col? Any Suggestions? Antonis K. From holger.brunck at keymile.com Wed Jul 21 08:57:28 2010 From: holger.brunck at keymile.com (Holger brunck) Date: Wed, 21 Jul 2010 14:57:28 +0200 Subject: detect endianness of a binary with python Message-ID: <4C46EEB8.6070702@keymile.com> Hi all, I use python 2.5 and I am looking for a possibility to determine a file type. Especially the endianness of a file is needed for me. Is there a way to detect this easily in python? Something like the "file" utility for linux would be very helpfull. Any help is appreciated. Best regards Holger Brunck From stefan_ml at behnel.de Wed Jul 21 08:58:53 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 14:58:53 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Message-ID: kaklis at gmail.com, 21.07.2010 14:36: > From the subject of my message it's clear that i get an xml message > from a socket, Not at all, but now that you say it... > i parse it and the result is a list like the one that > follows: > ID_Col > 4 Server ak ip OFFLINE > > 29 Server and2 ip OFFLINE > > 5 Proxy l34e ip OFFLINE > > 6 Proxy barc ip ONLINE > > 41 Proxy proxy-2 ip ONLINE > > 53 Server server-4 ip ONLINE > > 52 Server server-3 ip ONLINE Doesn't look like a Python list to me... > What i want is to print this list sorted by ID_Col? > Any Suggestions? Assuming that the above is supposed to represent a list of tuples, you can use the .sort() method on the list and pass operator.itemgetter(0) as 'key' argument (see the sort() method and the operator module). Stefan From kaklis at gmail.com Wed Jul 21 09:04:16 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 06:04:16 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Message-ID: <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> On Jul 21, 8:58?am, Stefan Behnel wrote: > kak... at gmail.com, 21.07.2010 14:36: > > > From the subject of my message it's clear that i get an xml message > > from a socket, > > Not at all, but now that you say it... > > > > > i parse it and the result is a list like the one that > > follows: > > ID_Col > > 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > > 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > > 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > > 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > > 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > > 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > > 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > Doesn't look like a Python list to me... > > > What i want is to print this list sorted by ID_Col? > > Any Suggestions? > > Assuming that the above is supposed to represent a list of tuples, you can > use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > argument (see the sort() method and the operator module). > > Stefan No it is not a Python list at all. This the way i print the parsed items 'like a list'. But i want them to be sorted. From neilc at norwich.edu Wed Jul 21 09:15:25 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 21 Jul 2010 13:15:25 GMT Subject: An ODBC interface for Python 3? Message-ID: <8aoa7dFuu2U1@mid.individual.net> A quick web search yielded no current support for the ODBC interface for Python 3. I'd like to get a simple "tracer bullet" up and running ASAP. I need to connect to an MSSQL database from Windows XP/2000, using an ODBC interface. Is this a case where I'll need to go back to Python 2.6? -- Neil Cerutti From kaklis at gmail.com Wed Jul 21 09:38:26 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 06:38:26 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> Message-ID: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> On Jul 21, 9:04?am, "kak... at gmail.com" wrote: > On Jul 21, 8:58?am, Stefan Behnel wrote: > > > > > kak... at gmail.com, 21.07.2010 14:36: > > > > From the subject of my message it's clear that i get an xml message > > > from a socket, > > > Not at all, but now that you say it... > > > > i parse it and the result is a list like the one that > > > follows: > > > ID_Col > > > 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > > > 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > > > 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > > > 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > > > 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > > > 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > > > 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > > Doesn't look like a Python list to me... > > > > What i want is to print this list sorted by ID_Col? > > > Any Suggestions? > > > Assuming that the above is supposed to represent a list of tuples, you can > > use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > > argument (see the sort() method and the operator module). > > > Stefan > > No it is not a Python list at all. This the way i print the parsed > items 'like a list'. > But i want them to be sorted. Well i did this: SortedServers = [] for session in sessions: for IP in session.getElementsByTagName("ipAddress"): for iphn in session.getElementsByTagName("hostName"): tempTuple = session.getAttribute("id"), session.getAttribute("type"), iphn.childNodes[0].data, IP.childNodes[0].data, session.getAttribute("status") SortedServers.append(tempTuple) Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) for item in Sorted: print item but the list is still unsorted and with u' in front of each item (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') How do i remove the u' Antonis From stefan_ml at behnel.de Wed Jul 21 09:49:57 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 15:49:57 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: kaklis at gmail.com, 21.07.2010 15:38: > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: >> On Jul 21, 8:58 am, Stefan Behnel wrote: >> >> >> >>> kak... at gmail.com, 21.07.2010 14:36: >> >>>> From the subject of my message it's clear that i get an xml message >>>> from a socket, >> >>> Not at all, but now that you say it... >> >>>> i parse it and the result is a list like the one that >>>> follows: >>>> ID_Col >>>> 4 Server ak ip OFFLINE >> >>>> 29 Server and2 ip OFFLINE >> >>>> 5 Proxy l34e ip OFFLINE >> >>>> 6 Proxy barc ip ONLINE >> >>>> 41 Proxy proxy-2 ip ONLINE >> >>>> 53 Server server-4 ip ONLINE >> >>>> 52 Server server-3 ip ONLINE >> >>> Doesn't look like a Python list to me... >> >>>> What i want is to print this list sorted by ID_Col? >>>> Any Suggestions? >> >>> Assuming that the above is supposed to represent a list of tuples, you can >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' >>> argument (see the sort() method and the operator module). >> >>> Stefan >> >> No it is not a Python list at all. This the way i print the parsed >> items 'like a list'. >> But i want them to be sorted. > > Well i did this: > > SortedServers = [] > > for session in sessions: > for IP in session.getElementsByTagName("ipAddress"): > for iphn in session.getElementsByTagName("hostName"): > tempTuple = session.getAttribute("id"), > session.getAttribute("type"), iphn.childNodes[0].data, > IP.childNodes[0].data, session.getAttribute("status") > > SortedServers.append(tempTuple) > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) > for item in Sorted: > print item > > but the list is still unsorted and with u' in front of each item > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') It seems you want to sort the list numerically. In that case, use int(SortedServers[0]) as the key. Sorting by string values will sort the list lexicographically. > How do i remove the u' You should read the Python tutorial, specifically the sections about strings. Then, read the sections on lists and sequences. In short: Don't care about the "u'" prefix, that's just fine. Stefan From mail at timgolden.me.uk Wed Jul 21 09:51:56 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 21 Jul 2010 14:51:56 +0100 Subject: An ODBC interface for Python 3? In-Reply-To: <8aoa7dFuu2U1@mid.individual.net> References: <8aoa7dFuu2U1@mid.individual.net> Message-ID: <4C46FB7C.7080508@timgolden.me.uk> On 21/07/2010 2:15 PM, Neil Cerutti wrote: > A quick web search yielded no current support for the ODBC > interface for Python 3. > > I'd like to get a simple "tracer bullet" up and running ASAP. I > need to connect to an MSSQL database from Windows XP/2000, using > an ODBC interface. > > Is this a case where I'll need to go back to Python 2.6? > pyodbc has a branch which supports Py3k. I've installed it and it worked ok. Can't get hold of the web at the moment, but I'm sure you'll be able to find it. TJG From neilc at norwich.edu Wed Jul 21 09:58:58 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 21 Jul 2010 13:58:58 GMT Subject: An ODBC interface for Python 3? References: <8aoa7dFuu2U1@mid.individual.net> Message-ID: <8aocp1Fm37U1@mid.individual.net> On 2010-07-21, Tim Golden wrote: > On 21/07/2010 2:15 PM, Neil Cerutti wrote: >> A quick web search yielded no current support for the ODBC >> interface for Python 3. >> >> I'd like to get a simple "tracer bullet" up and running ASAP. I >> need to connect to an MSSQL database from Windows XP/2000, using >> an ODBC interface. >> >> Is this a case where I'll need to go back to Python 2.6? > > pyodbc has a branch which supports Py3k. I've installed it and > it worked ok. Can't get hold of the web at the moment, but I'm > sure you'll be able to find it. Thanks, Tim. I did see that support for pyodbc for Python 3 was really close to being released. There's odbc support using pywin32's odbc module as well, which should be more than sufficient. My web search skillz apparently were not up to snuff this morning. -- Neil Cerutti From invalid at invalid.invalid Wed Jul 21 10:02:16 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 21 Jul 2010 14:02:16 +0000 (UTC) Subject: detect endianness of a binary with python References: Message-ID: On 2010-07-21, Holger brunck wrote: > I use python 2.5 and I am looking for a possibility to determine a > file type. Especially the endianness of a file is needed for me. Is > there a way to detect this easily in python? Only if you already know what's going to be in the file. > Something like the "file" utility for linux would be very helpfull. > > Any help is appreciated. You're going to have to describe in detail what's in the file before anybody can help. -- Grant Edwards grant.b.edwards Yow! A shapely CATHOLIC at SCHOOLGIRL is FIDGETING gmail.com inside my costume.. From brandon.harris at reelfx.com Wed Jul 21 10:42:23 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 09:42:23 -0500 Subject: Multiline regex In-Reply-To: References: Message-ID: <4C47074F.4090507@reelfx.com> I'm trying to read in and parse an ascii type file that contains information that can span several lines. Example: createNode animCurveTU -n "test:master_globalSmooth"; setAttr ".tan" 9; setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; setAttr -s 4 ".kit[3]" 10; setAttr -s 4 ".kot[3]" 10; createNode animCurveTU -n "test:master_res"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; I'm wanting to grab the information out in chunks, so createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; would be what my regex would grab. I'm currently only able to grab out the first line and part of the second line, but no more. regex is as follows my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") I've run several variations of this, but none return me all of the expected information. Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? Brandon L. Harris From torriem at gmail.com Wed Jul 21 10:44:57 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 21 Jul 2010 08:44:57 -0600 Subject: detect endianness of a binary with python In-Reply-To: References: Message-ID: <4C4707E9.9030201@gmail.com> On 07/21/2010 08:02 AM, Grant Edwards wrote: > On 2010-07-21, Holger brunck wrote: > >> I use python 2.5 and I am looking for a possibility to determine a >> file type. Especially the endianness of a file is needed for me. Is >> there a way to detect this easily in python? > > Only if you already know what's going to be in the file. > >> Something like the "file" utility for linux would be very helpfull. >> >> Any help is appreciated. > > You're going to have to describe in detail what's in the file before > anybody can help. There is a python module called "magic" that uses the same engine as file to determine a file type. It's part of the "find" source code: http://www.darwinsys.com/file/ On Fedora I can just yum install python-magic to get it. From daniel at stutzbachenterprises.com Wed Jul 21 10:47:08 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 09:47:08 -0500 Subject: ANN: blist 1.2.0 Message-ID: The blist package contains several container types to supplement those built-in to Python. These types closely mirror the built-in types' methods, so the learning curve is close to zero. The package includes: - blist: a list type with O(log n) insertions, deletes, and slices and other performance enhancements - btuple: a tuple type with O(log) slices - sorteddict: a dict type that efficiently keeps keys in sorted order - sortedlist: a list type that efficiently keeps the items sorted order - sortedset: an indexable set type that efficiently keeps the items sorted order - weaksortedlist, weaksortedset: weak reference versions of sortedlist and sortedset What's new? ----------- - blist.sort() is now *substantially* faster than list.sort() when using int or float keys (O(n) vs. O(n log n)) - The sortedset, sortedlist, and sorteddict types have been revamped for better compatibility with the standard library's types. - Comprehensive reference documentation is now available at http://stutzbachenterprises.com/blist/ - Numerous other speed improvements Links ----- - blist vs. list performance comparison: http://stutzbachenterprises.com/performance-blist - Documentation: http://stutzbachenterprises.com/blist/ - Download: http://pypi.python.org/pypi/blist/ - Source repository: http://github.com/DanielStutzbach/blist - Issue tracker: http://github.com/DanielStutzbach/blist/issues -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Wed Jul 21 11:04:04 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 21 Jul 2010 11:04:04 -0400 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: Slurp the entire file into a string and pick out the fields you need. Sent from my iPhone 4. On Jul 21, 2010, at 10:42 AM, Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the expected information. > > Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? > > Brandon L. Harris > > > -- > http://mail.python.org/mailman/listinfo/python-list From brandon.harris at reelfx.com Wed Jul 21 11:06:14 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:06:14 -0500 Subject: Multiline regex In-Reply-To: References: <4C47074F.4090507@reelfx.com> Message-ID: <4C470CE6.2030306@reelfx.com> what do you mean by slurp the entire file? I'm trying to use regular expressions because line by line parsing will be too slow. And example file would have somewhere in the realm of 6 million lines of code. Brandon L. Harris Rodrick Brown wrote: > Slurp the entire file into a string and pick out the fields you need. > > Sent from my iPhone 4. > > On Jul 21, 2010, at 10:42 AM, Brandon Harris wrote: > > >> I'm trying to read in and parse an ascii type file that contains information that can span several lines. >> Example: >> >> createNode animCurveTU -n "test:master_globalSmooth"; >> setAttr ".tan" 9; >> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; >> setAttr -s 4 ".kit[3]" 10; >> setAttr -s 4 ".kot[3]" 10; >> createNode animCurveTU -n "test:master_res"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> I'm wanting to grab the information out in chunks, so >> >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> would be what my regex would grab. >> I'm currently only able to grab out the first line and part of the second line, but no more. >> regex is as follows >> >> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") >> >> I've run several variations of this, but none return me all of the expected information. >> >> Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? >> >> Brandon L. Harris >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From eknath.iyer at gmail.com Wed Jul 21 11:13:43 2010 From: eknath.iyer at gmail.com (Eknath Venkataramani) Date: Wed, 21 Jul 2010 20:43:43 +0530 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Do you have to use only regex? If not, I'd certainly suggest 'pyparsing'. It's a pleasure to use and very easy on the eye too, if you know what I mean. > I'm wanting to grab the information out in chunks, so > -- Eknath Venkataramani -------------- next part -------------- An HTML attachment was scrubbed... URL: From brandon.harris at reelfx.com Wed Jul 21 11:14:43 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:14:43 -0500 Subject: Multiline regex In-Reply-To: References: <4C47074F.4090507@reelfx.com> Message-ID: <4C470EE3.4060708@reelfx.com> At the moment I'm trying to stick with built in python modules to create tools for a much larger pipeline on multiple OSes. Brandon L. Harris Eknath Venkataramani wrote: > > > On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris > > wrote: > > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > > Do you have to use only regex? If not, I'd certainly suggest > 'pyparsing'. It's a pleasure to use and very easy on the eye too, if > you know what I mean. > > I'm wanting to grab the information out in chunks, so > > > -- > Eknath Venkataramani From andreas.tawn at ubisoft.com Wed Jul 21 11:15:42 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 17:15:42 +0200 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the > second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the > expected information. > > Is there something special that needs to be done to have the regexp > grab > any number of the setAttr lines without specification? > > Brandon L. Harris Aren't you making life too complicated for yourself? blocks = [] for line in yourFile: if line.startswith("createNode"): if currentBlock: blocks.append(currentBlock) currentBlock = [line] else: currentBlock.append(line) blocks.append(currentBlock) Cheers, Drea From __peter__ at web.de Wed Jul 21 11:16:04 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Jul 2010 17:16:04 +0200 Subject: Multiline regex References: Message-ID: Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the > second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the > expected information. > > Is there something special that needs to be done to have the regexp grab > any number of the setAttr lines without specification? Groups are marked with parens (...) not brackets [...]. >>> text = """\ ... createNode animCurveTU -n "test:master_globalSmooth"; ... setAttr ".tan" 9; ... setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; ... setAttr -s 4 ".kit[3]" 10; ... setAttr -s 4 ".kot[3]" 10; ... createNode animCurveTU -n "test:master_res"; ... setAttr ".tan" 9; ... setAttr ".ktv[0]" 103 0; ... setAttr ".kot[0]" 5; ... createNode animCurveTU -n "test:master_faceRig"; ... setAttr ".tan" 9; ... setAttr ".ktv[0]" 103 0; ... setAttr ".kot[0]" 5; ... """ >>> for m in re.compile("(createNode animCurve.*\n(\s*setAttr.*\n)*)").finditer(text): ... print m.group(1) ... print "-" * 40 ... createNode animCurveTU -n "test:master_globalSmooth"; setAttr ".tan" 9; setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; setAttr -s 4 ".kit[3]" 10; setAttr -s 4 ".kot[3]" 10; ---------------------------------------- createNode animCurveTU -n "test:master_res"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; ---------------------------------------- createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; ---------------------------------------- Peter From nagle at animats.com Wed Jul 21 11:17:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 21 Jul 2010 08:17:36 -0700 Subject: Accumulate function in python In-Reply-To: <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> Message-ID: <4c470fa3$0$1583$742ec2ed@news.sonic.net> On 7/19/2010 9:56 AM, dhruvbird wrote: > On Jul 19, 9:12 pm, Brian Victor wrote: >> dhruvbird wrote: >> Having offered this, I don't recall ever seeing reduce used in real >> python code, and explicit iteration is almost always preferred. > > Yes, even I have noticed that reduce is a tad under-used function. Yes, I had a use case for it once, but it wasn't worth the trouble. "map" is often useful, but "reduce", not so much. Python isn't really a functional language. There's no bias toward functional solutions, lambdas aren't very general, and the performance isn't any better. Nor is any concurrency provided by "map" or "reduce". So there's no win in trying to develop cute one-liners. John Nagle From holger.brunck at keymile.com Wed Jul 21 11:29:14 2010 From: holger.brunck at keymile.com (Holger brunck) Date: Wed, 21 Jul 2010 17:29:14 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C46EEB8.6070702@keymile.com> References: <4C46EEB8.6070702@keymile.com> Message-ID: <4C47124A.10405@keymile.com> >> Something like the "file" utility for linux would be very helpfull. >> >> Any help is appreciated. >You're going to have to describe in detail what's in the file before >anybody can help. We are creating inside our buildsystem for an embedded system a cram filesystem image. Later on inside our build process we have to check the endianness, because it could be Little Endian or big endian (arm or ppc). The output of the "file" tool is for a little endian cramfs image: : Linux Compressed ROM File System data, little endian size 1875968 version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files It would be possible to execute ret = os.system("file | grep "little endian") and evaluate the return code. But I don't like to evaluate a piped system command. If there is an way without using the os.system command this would be great. Best regards Holger From solipsis at pitrou.net Wed Jul 21 11:32:50 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 21 Jul 2010 17:32:50 +0200 Subject: ANN: blist 1.2.0 References: Message-ID: <20100721173250.2d666f99@pitrou.net> On Wed, 21 Jul 2010 09:47:08 -0500 Daniel Stutzbach wrote: > > What's new? > ----------- > > - blist.sort() is now *substantially* faster than list.sort() when using int > or float keys (O(n) vs. O(n log n)) Are you using some kind of radix sort? Could it be contributed back into the standard list type? Regards Antoine. From brandon.harris at reelfx.com Wed Jul 21 11:42:11 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:42:11 -0500 Subject: Multiline regex In-Reply-To: <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4C471553.9060500@reelfx.com> I could make it that simple, but that is also incredibly slow and on a file with several million lines, it takes somewhere in the league of half an hour to grab all the data. I need this to grab data from many many file and return the data quickly. Brandon L. Harris Andreas Tawn wrote: >> I'm trying to read in and parse an ascii type file that contains >> information that can span several lines. >> Example: >> >> createNode animCurveTU -n "test:master_globalSmooth"; >> setAttr ".tan" 9; >> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; >> setAttr -s 4 ".kit[3]" 10; >> setAttr -s 4 ".kot[3]" 10; >> createNode animCurveTU -n "test:master_res"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> I'm wanting to grab the information out in chunks, so >> >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> would be what my regex would grab. >> I'm currently only able to grab out the first line and part of the >> second line, but no more. >> regex is as follows >> >> my_regexp =e.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") >> >> I've run several variations of this, but none return me all of the >> expected information. >> >> Is there something special that needs to be done to have the regexp >> grab >> any number of the setAttr lines without specification? >> >> Brandon L. Harris >> > > Aren't you making life too complicated for yourself? > > blocks =] > for line in yourFile: > if line.startswith("createNode"): > if currentBlock: > blocks.append(currentBlock) > currentBlock =line] > else: > currentBlock.append(line) > blocks.append(currentBlock) > > Cheers, > > Drea > > From andreas.tawn at ubisoft.com Wed Jul 21 11:55:48 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 17:55:48 +0200 Subject: Multiline regex In-Reply-To: <4C471553.9060500@reelfx.com> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> > I could make it that simple, but that is also incredibly slow and on a > file with several million lines, it takes somewhere in the league of > half an hour to grab all the data. I need this to grab data from many > many file and return the data quickly. > > Brandon L. Harris That's surprising. I just made a file with 13 million lines of your data (447Mb) and read it with my code. It took a little over 36 seconds. There must be something different in your set up or the real data you've got. Cheers, Drea From brandon.harris at reelfx.com Wed Jul 21 11:57:35 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:57:35 -0500 Subject: Multiline regex In-Reply-To: <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4C4718EF.7050202@reelfx.com> Could it be that there isn't just that type of data in the file? there are many different types, that is just one that I'm trying to grab. Brandon L. Harris Andreas Tawn wrote: >> I could make it that simple, but that is also incredibly slow and on a >> file with several million lines, it takes somewhere in the league of >> half an hour to grab all the data. I need this to grab data from many >> many file and return the data quickly. >> >> Brandon L. Harris >> > > That's surprising. > > I just made a file with 13 million lines of your data (447Mb) and read it with my code. It took a little over 36 seconds. There must be something different in your set up or the real data you've got. > > Cheers, > > Drea > From nanothermite911fbibustards at gmail.com Wed Jul 21 12:10:14 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 09:10:14 -0700 (PDT) Subject: Please, stop spamming References: Message-ID: <8a4273c7-5f55-440a-880b-7fd25969567b@w30g2000yqw.googlegroups.com> On Jul 14, 7:38?pm, Daniel Valio wrote: > Indeed, you will make Usenet an old history that your father talked > about on the early days of the Internet. Really, you are destroying > the Internet with useless spams about naked famous woman, or Viagra, > Cialis et alia. > You are making the internet look like a big stupid useless spammed > thing. Stop it! > That should be a Lisp group, not a Hey-you-may-spam-here-as-you-want- > to group! [snip] > Thanks in advance for the comprehension. > From Brazil, Daniel Valio. Daniel, This spam is by CIA, MOSSAD, AIPAC, ZIONISTS to HIDE a slight mention of their crimes. Ignore it, and continue, if you want to success. I agree with someone that they carried out 911 to destroy FREEDOMS. One paradigm of these ODIOUS CRIMINALS is to blame what they do on others and with a VIGOR to lie so it appears a truth. These BUSTARDS have the knowhow, time and resources which ordinary people dont have. These CRIMINALS are SNAKES feeding on our tax payer money. The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From daniel at stutzbachenterprises.com Wed Jul 21 12:15:53 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 11:15:53 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: <20100721173250.2d666f99@pitrou.net> References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Wed, Jul 21, 2010 at 10:32 AM, Antoine Pitrou wrote: > Are you using some kind of radix sort? > Could it be contributed back into the standard list type? Yes and yes. I have a few mostly-complete patches on the tracker that I need to polish off, as well as several easy-to-fix bugs that I need to take care of. After that I plan to work on porting my sort optimizations back to the standard list type. Here's a performance comparison of sorting with blist versus 3.1's list: http://stutzbachenterprises.com/performance-blist/sort-random-list -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Wed Jul 21 12:27:14 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 18:27:14 +0200 Subject: Multiline regex In-Reply-To: <4C4718EF.7050202@reelfx.com> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> <4C4718EF.7050202@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C769E8@PDC-MAIL-CMS01.ubisoft.org> >>> I could make it that simple, but that is also incredibly slow and on >>> a file with several million lines, it takes somewhere in the league of >>> half an hour to grab all the data. I need this to grab data from >>> many many file and return the data quickly. >>> >>> Brandon L. Harris >>> >> That's surprising. >> >> I just made a file with 13 million lines of your data (447Mb) and >> read it with my code. It took a little over 36 seconds. There must be >> something different in your set up or the real data you've got. >> >> Cheers, >> >> Drea >> > Could it be that there isn't just that type of data in the file? there > are many different types, that is just one that I'm trying to grab. > > Brandon L. Harris I don't see why it would make such a difference. If your data looks like... \t \t \t Just change this line... if line.startswith("createNode"): to... if not line.startswith("\t"): and it won't care what sort of data the file contains. Processing that data after you've collected it will still take a while, but that's the same whichever method you use to read it. Cheers, Drea p.s. Just noticed I hadn't pre-declared the currentBlock list. From jeremy at jeremysanders.net Wed Jul 21 12:56:16 2010 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Wed, 21 Jul 2010 17:56:16 +0100 Subject: Multiline regex References: <4C47074F.4090507@reelfx.com> Message-ID: Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: What about something like this (you need re.MULTILINE): In [16]: re.findall('^([^ ].*\n([ ].*\n)+)', a, re.MULTILINE) Out[16]: [('createNode animCurveTU -n "test:master_globalSmooth";\n setAttr ".tan" 9;\n setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;\n setAttr -s 4 ".kit[3]" 10;\n setAttr -s 4 ".kot[3]" 10;\n', ' setAttr -s 4 ".kot[3]" 10;\n'), ('createNode animCurveTU -n "test:master_res";\n setAttr ".tan" 9;\n setAttr ".ktv[0]" 103 0;\n setAttr ".kot[0]" 5;\n', ' setAttr ".kot[0]" 5;\n'), ('createNode animCurveTU -n "test:master_faceRig";\n setAttr ".tan" 9;\n setAttr ".ktv[0]" 103 0;\n', ' setAttr ".ktv[0]" 103 0;\n')] If you blocks start without a space and subsequent lines with a space. Jeremy From sla29970 at gmail.com Wed Jul 21 13:27:28 2010 From: sla29970 at gmail.com (Steve Allen) Date: Wed, 21 Jul 2010 10:27:28 -0700 (PDT) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: <7be79f8d-edaa-42ca-9a5a-fa938972fd77@m17g2000prl.googlegroups.com> On Jul 20, 6:57?pm, Chris Rebert wrote: [regarding trust of POSIX vis a vis leap seconds] > I'm not saying they necessarily should, but they're standardized and > the `time` module is based on POSIX/Unix-ish assumptions; not > following POSIX would be inconsistent and problematic. > Breaking standards is bad, M'Kay? Standards are good. When it comes to leap seconds there can be no current implementation which satisfies everyone because of this http://www.ucolick.org/~sla/leapsecs/epochtime.html Until the delegates to ITU-R SG7 produce a better recommendation there is going to be chaotic disregard of the standard where folks with different needs choose different practical implementations. From wxjmfauth at gmail.com Wed Jul 21 14:13:31 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 21 Jul 2010 11:13:31 -0700 (PDT) Subject: Inconsistency in the format docstring (2.7). Message-ID: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> Small inconsistency in the format.__doc__ >>> sys.version 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] >>> ''.format.__doc__ S.format(*args, **kwargs) -> unicode >>> type('{}'.format(999)) >>> type('{}'.format('abc?')) From thomas at jollans.com Wed Jul 21 15:06:38 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 21 Jul 2010 21:06:38 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C47124A.10405@keymile.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: <4C47453E.7030203@jollans.com> On 07/21/2010 05:29 PM, Holger brunck wrote: > >>> Something like the "file" utility for linux would be very helpfull. >>> >>> Any help is appreciated. > >> You're going to have to describe in detail what's in the file before >> anybody can help. > > We are creating inside our buildsystem for an embedded system a cram filesystem > image. Later on inside our build process we have to check the endianness, > because it could be Little Endian or big endian (arm or ppc). > > The output of the "file" tool is for a little endian cramfs image: > : Linux Compressed ROM File System data, little endian size 1875968 > version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > > It would be possible to execute > ret = os.system("file | grep "little endian") > and evaluate the return code. > But I don't like to evaluate a piped system command. If there is an way without > using the os.system command this would be great. Files don't, as such, have a detectable endianess. 0x23 0x41 could mean either 0x4123 or 0x2341 - there's no way of knowing. The "file" utility also doensn't really know about endianess (well, maybe it does swap bytes here and there, but that's an implementation detail) - it just knows about file types. It knows what a little-endian cramfs image looks like, and what a big-endian cramfs image looks like. And as they're different, it can tell them apart. If you're only interested in a couple of file types, it shouldn't be too difficult to read the first few bytes/words with the struct module and apply your own heuristics. Open the files in question in a hex editor and try to figure out how to tell them apart! From python at mrabarnett.plus.com Wed Jul 21 15:54:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jul 2010 20:54:34 +0100 Subject: detect endianness of a binary with python In-Reply-To: <4C47453E.7030203@jollans.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> <4C47453E.7030203@jollans.com> Message-ID: <4C47507A.5080205@mrabarnett.plus.com> Thomas Jollans wrote: > On 07/21/2010 05:29 PM, Holger brunck wrote: >>>> Something like the "file" utility for linux would be very helpfull. >>>> >>>> Any help is appreciated. >>> You're going to have to describe in detail what's in the file before >>> anybody can help. >> We are creating inside our buildsystem for an embedded system a cram filesystem >> image. Later on inside our build process we have to check the endianness, >> because it could be Little Endian or big endian (arm or ppc). >> >> The output of the "file" tool is for a little endian cramfs image: >> : Linux Compressed ROM File System data, little endian size 1875968 >> version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files >> >> It would be possible to execute >> ret = os.system("file | grep "little endian") >> and evaluate the return code. >> But I don't like to evaluate a piped system command. If there is an way without >> using the os.system command this would be great. > > Files don't, as such, have a detectable endianess. 0x23 0x41 could mean > either 0x4123 or 0x2341 - there's no way of knowing. > > The "file" utility also doensn't really know about endianess (well, > maybe it does swap bytes here and there, but that's an implementation > detail) - it just knows about file types. It knows what a little-endian > cramfs image looks like, and what a big-endian cramfs image looks like. > And as they're different, it can tell them apart. > > If you're only interested in a couple of file types, it shouldn't be too > difficult to read the first few bytes/words with the struct module and > apply your own heuristics. Open the files in question in a hex editor > and try to figure out how to tell them apart! If you have control over the file format then you could ensure that there's a double-byte value such as 0xFF00 at a certain offset. That will tell you the endianness of the file. From gdamjan at gmail.com Wed Jul 21 15:56:37 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 21 Jul 2010 21:56:37 +0200 Subject: Pydev 1.6.0 Released References: Message-ID: > Pydev 1.6.0 has been released > > Details on Pydev: http://pydev.org > Details on its development: http://pydev.blogspot.com The supposed feature to start a console in which the contents of the current editor window are automatically "exec"ed /available still doesn't work for me. I'm talking about this: http://www.pydev.org/manual_adv_interactive_console.html Pressing Ctrl-Alt-Enter, a interactive console opens but my class defined in the editor window is not available. -- ?????? ((( http://damjan.softver.org.mk/ ))) Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. - Antoine de Saint-Exup?ry From nanothermite911fbibustards at gmail.com Wed Jul 21 16:21:53 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 13:21:53 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? Message-ID: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From guandalino at gmail.com Wed Jul 21 17:06:55 2010 From: guandalino at gmail.com (guandalino) Date: Wed, 21 Jul 2010 14:06:55 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) References: Message-ID: On 20 Lug, 21:24, Terry Reedy wrote: Hi Terry, thanks for your reply. > > ====================================================================== > > ERROR: test_file (__main__.HandlerTests) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > ? ?File "test_urllib2.py", line 711, in test_file > > ? ? ?h.file_open, Request(url)) [cut] > You could insert a print to find what url caused a problem. Output: file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp file:///file_does_not_exist.txt file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp Offending line is the the 4th. > This is in unittest.py. It says that this test case *should* fail, but > with a different error (urllib.error.URLError) than the one you got > (gaierror). > > > ? ?File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, > > in file_open > > ? ? ?return self.open_local_file(req) > > ? ?File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, > > in open_local_file > > ? ? ?(not port and socket.gethostbyname(host) in self.get_names()): > > gaierror: [Errno -5] No address associated with hostname > > gaierror comes from socket.gethostbyname When I print the value of the variable 'host' in urllib2.py line 1301 I get this: somerandomhost.ontheinternet.com. This is why socket.gethostbyname(host) raises gaierror -5, there is no address associated to somerandomhost.ontheinternet.com. Instead the values that 'host' takes for the other urls are localhost or 127.0.0.1, both valid for gethostbyname(). Any hint? Thanks. From tjreedy at udel.edu Wed Jul 21 18:27:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 18:27:36 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/21/2010 12:15 PM, Daniel Stutzbach wrote: > Here's a performance comparison of sorting with blist versus 3.1's list: > http://stutzbachenterprises.com/performance-blist/sort-random-list Question related to possible addition of radix sort to lists: These tests use random numbers with a constant, relatively high density of 25%, which is favorable to radix sort. What if you do the same test with a constant range of, say, 1000000000 (1 billion) or even a trillion or quadrillion. Or how about sorting a thousand 128bit ip6 addresses? Which wins for that? list.sort is (near) linear for lists that are mostly ordered. I think Tim's writeup about this in in the source. For instance, if one extends a sorted with 1% random additions and resorts, list.sort will skip the sorted part, sort the additions, and merge them back in. Radix sort ignores pre-existing order. So either a lot of comparitive profiling would be needed for auto-selection of sort method, or it should be user selectable. Does your radix sort meet the stability guarantee of list.sort? If not, a separate .rsort method would be needed anyway. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jul 21 18:50:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 18:50:16 -0400 Subject: Inconsistency in the format docstring (2.7). In-Reply-To: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> References: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> Message-ID: On 7/21/2010 2:13 PM, jmfauth wrote: > Small inconsistency in the format.__doc__ > >>>> sys.version > 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] >>>> ''.format.__doc__ > S.format(*args, **kwargs) -> unicode > > >>>> type('{}'.format(999)) > >>>> type('{}'.format('abc?')) > Thank you for reporting this. Forwarded to the tracker as http://bugs.python.org/issue9328 -- Terry Jan Reedy From daniel at stutzbachenterprises.com Wed Jul 21 18:56:55 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 17:56:55 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy wrote: > These tests use random numbers with a constant, relatively high density of > 25%, which is favorable to radix sort. What if you do the same test with a > constant range of, say, 1000000000 (1 billion) or even a trillion or > quadrillion. Or how about sorting a thousand 128bit ip6 addresses? Which > wins for that? > blist switches to radix sort only if the keys contain only floats or only integers that fit into a C long. If the integers get too big, it reverts to timsort. When using a sort key, the decorate-sort-undecorate pattern requires touching every object once before the sort. The check for a consistent type is done inexpensively during the decorate phase. Here's an example result with a density of only 1%, where the radix sort is around 4 times as fast: otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' 'y.sort(key=float)' 100 loops, best of 3: 12.4 msec per loop otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s 'import random' -s 'x = [random.randrange(10000*100) for i in range(10000)]' 'y = blist(x)' 'y.sort(key=float)' 100 loops, best of 3: 3.4 msec per loop And a density of 0.01%: otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' 'y.sort(key=float)' 100 loops, best of 3: 12 msec per loop otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s 'import random' -s 'x = [random.randrange(10000*10000) for i in range(10000)]' 'y = blist(x)' 'y.sort(key=float)' 100 loops, best of 3: 3.52 msec per loop > list.sort is (near) linear for lists that are mostly ordered. I think Tim's > writeup about this in in the source. For instance, if one extends a sorted > with 1% random additions and resorts, list.sort will skip the sorted part, > sort the additions, and merge them back in. Radix sort ignores pre-existing > order. So either a lot of comparitive profiling would be needed for > auto-selection of sort method, or it should be user selectable. > I've tested exactly that scenario. For already-ordered lists, radix sort and timsort tie. > Does your radix sort meet the stability guarantee of list.sort? > Yes. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 21 19:13:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 19:13:21 -0400 Subject: urllib2 test fails (2.7, linux) In-Reply-To: References: Message-ID: On 7/21/2010 5:06 PM, guandalino wrote: > On 20 Lug, 21:24, Terry Reedy wrote: > > Hi Terry, thanks for your reply. > >>> ====================================================================== >>> ERROR: test_file (__main__.HandlerTests) >>> ---------------------------------------------------------------------- >>> Traceback (most recent call last): >>> File "test_urllib2.py", line 711, in test_file >>> h.file_open, Request(url)) > [cut] >> You could insert a print to find what url caused a problem. > > Output: > file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp > file:///file_does_not_exist.txt > file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp > file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp > Offending line is the the 4th. Ah. I did not see anything like that in 3.1 test_urllib2. Either I just simply missed it, or it is obscured, or it was removed because it causes failures;-). >> This is in unittest.py. It says that this test case *should* fail, but >> with a different error (urllib.error.URLError) than the one you got >> (gaierror). >> >>> File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, >>> in file_open >>> return self.open_local_file(req) >>> File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, >>> in open_local_file >>> (not port and socket.gethostbyname(host) in self.get_names()): >>> gaierror: [Errno -5] No address associated with hostname >> >> gaierror comes from socket.gethostbyname > > When I print the value of the variable 'host' in urllib2.py line 1301 > I get this: somerandomhost.ontheinternet.com. This is why > socket.gethostbyname(host) raises gaierror -5, there is no address > associated to somerandomhost.ontheinternet.com. Instead the values > that 'host' takes for the other urls are localhost or 127.0.0.1, both > valid for gethostbyname(). > > Any hint? Remove the offending fake url. If you want to investigate the history of the file, go to http://svn.python.org/view/python/branches/release27-maint/Lib/test/test_urllib2.py?view=log If you do not get an answer here, file a bug report. If you can, put orsenthil,benjamin.peterson,ezio.melotti on the nosy list, as they are recent committers to this file. Say I said to do so if you want. Add tjreedy also so I can see responses and learn too. -- Terry Jan Reedy From prologic at shortcircuit.net.au Wed Jul 21 19:16:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jul 2010 09:16:04 +1000 Subject: [ann] Hatta 1.4.0 wiki engine released In-Reply-To: References: Message-ID: On Wed, Jul 21, 2010 at 6:01 PM, Radomir Dopieralski wrote: > I'm proud to announce release 1.4.0 of Hatta wiki engine. Congrats. cheers James -- -- James Mills -- -- "Problems are solved by method" From Space998 at hotmail.com Wed Jul 21 19:31:02 2010 From: Space998 at hotmail.com (spudnik) Date: Wed, 21 Jul 2010 16:31:02 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: thermite is not what you think, it is; it's primary use is for dismantling steel frameworks, piece by piece, just as they were welded -- see the report by MIT's Head Welder. thus: there, you've hit upon the self-same absurdity of Newton's "theory" of corpuscles, vis-a-vu waves of light in the non-vacuum of space (unconsciously .-) thus quoth: Does every dust speck have gravitons? ?And if not, how do the specks know... "which way the mass is"? --BP's cap&trade "free-er trade nostrum" is before Senate! http://tarpley.net/online-books/george-bush-the-unauthorized-biography/chapter-8-the-permian-basin-gang/ From steve-REMOVE-THIS at cybersource.com.au Wed Jul 21 20:25:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 00:25:58 GMT Subject: Multiline regex References: <4C47074F.4090507@reelfx.com> Message-ID: <4c479016$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 10:06:14 -0500, Brandon Harris wrote: > what do you mean by slurp the entire file? I'm trying to use regular > expressions because line by line parsing will be too slow. And example > file would have somewhere in the realm of 6 million lines of code. And you think trying to run a regex over all 6 million lines at once will be faster? I think you're going to be horribly, horribly disappointed. And then on Wed, 21 Jul 2010 10:42:11 -0500, Brandon Harris wrote: > I could make it that simple, but that is also incredibly slow and on a > file with several million lines, it takes somewhere in the league of > half an hour to grab all the data. I need this to grab data from many > many file and return the data quickly. What do you mean "grab" all the data? If all you mean is read the file, then 30 minutes to read ~ 100MB of data is incredibly slow and you're probably doing something wrong, or you're reading it over a broken link with very high packet loss, or something. If you mean read the data AND parse it, then whether that is "incredibly slow" or "amazingly fast" depends entirely on how complicated your parser needs to be. If *all* you mean is "read the file and group the lines, for later processing", then I would expect it to take well under a minute to group millions of lines. Here's a simulation I ran, using 2001000 lines of text based on the examples you gave. It grabs the blocks, as required, but does no further parsing of them. def merge(lines): """Join multiple lines into a single block.""" accumulator = [] for line in lines: if line.lower().startswith('createnode'): if accumulator: yield ''.join(accumulator) accumulator = [] accumulator.append(line) if accumulator: yield ''.join(accumulator) def test(): import time t = time.time() count = 0 f = open('/steve/test.junk') for block in merge(f): # do some make-work n = sum([1 for c in block if c in '1234567890']) count += 1 print "Processed %d blocks from 2M+ lines." % count print "Time taken:", time.time() - t, "seconds" And the result on a low-end PC: >>> test() Processed 1000 blocks from 2M+ lines. Time taken: 17.4497909546 seconds -- Steven From invalid at invalid.invalid Wed Jul 21 22:31:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 22 Jul 2010 02:31:54 +0000 (UTC) Subject: detect endianness of a binary with python References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: On 2010-07-21, Thomas Jollans wrote: >> It would be possible to execute ret = os.system("file | >> grep "little endian") and evaluate the return code. But I don't like >> to evaluate a piped system command. If there is an way without using >> the os.system command this would be great. > > Files don't, as such, have a detectable endianess. 0x23 0x41 could mean > either 0x4123 or 0x2341 - there's no way of knowing. > > The "file" utility also doensn't really know about endianess (well, > maybe it does swap bytes here and there, but that's an implementation > detail) - it just knows about file types. It knows what a little-endian > cramfs image looks like, and what a big-endian cramfs image looks like. > And as they're different, it can tell them apart. > > If you're only interested in a couple of file types, it shouldn't be too > difficult to read the first few bytes/words with the struct module and > apply your own heuristics. Open the files in question in a hex editor > and try to figure out how to tell them apart! And by looking at the rules that "file" uses for the two file types that matter, one should be able to figure out how to implement something in Python. Or one can use the Python "magic" module as previously suggested: http://pypi.python.org/pypi/python-magic/ -- Grant From nagle at animats.com Wed Jul 21 22:45:24 2010 From: nagle at animats.com (John Nagle) Date: Wed, 21 Jul 2010 19:45:24 -0700 Subject: Did class inheritance from "dict" work in early Python? Message-ID: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Did class inheritance from "dict" work in early Python? Or did that only start working when "new objects" came in? John Nagle From me+list/python at ixokai.io Wed Jul 21 23:11:37 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 21 Jul 2010 20:11:37 -0700 Subject: Did class inheritance from "dict" work in early Python? In-Reply-To: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> References: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Message-ID: <4C47B6E9.8010409@ixokai.io> On 7/21/10 7:45 PM, John Nagle wrote: > Did class inheritance from "dict" work in early Python? Or did > that only start working when "new objects" came in? The latter, that's why UserDict (and UserList) was added. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From steve-REMOVE-THIS at cybersource.com.au Wed Jul 21 23:34:01 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 03:34:01 GMT Subject: Did class inheritance from "dict" work in early Python? References: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Message-ID: <4c47bc29$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 19:45:24 -0700, John Nagle wrote: > Did class inheritance from "dict" work in early Python? Or did that > only start working when "new objects" came in? Only with the introduction of new-style classes and "object" in version 2.2. http://www.python.org/download/releases/2.2.3/descrintro/#subclassing Before that the technique of choice was to use automatic delegation, e.g. see the UserDict module. -- Steven From nanothermite911fbibustards at gmail.com Thu Jul 22 00:16:26 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:16:26 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: You shall see CIA / Mossad / AIPAC / CRIMINAL PRIVATE KROLL/BLACKWATER/ gstatic.com bustards start spamming to drown 911 truth. their spam is about VIAGRA/DIAZEPAM/VALIUM/SEX etc. They hate our freedoms. They sent anthrax. They did 911. They put the blame on arabs but they are the ones as FORENSIC proves WITHOUT ANY DOUBT !!! White crime rate is 5 times Asian per capita in the USA. On Jul 21, 1:21?pm, nanothermite911fbibustards wrote: > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > israelis and what is the status of FORENSIC evidence and trace of NANO > THERMITE in WTC dust ? > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From nanothermite911fbibustards at gmail.com Thu Jul 22 00:24:50 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:24:50 -0700 (PDT) Subject: please come and help to defend against ISLAM , bring physicists to refute their calculation on speed of light and wormholes References: <49ecfb9d-fc4b-4b1d-b8fb-2bbcb15d07a6@m35g2000prn.googlegroups.com> Message-ID: <4905e445-215c-4dd2-8000-15b40700a827@s17g2000prh.googlegroups.com> On Jul 21, 9:23?pm, nanothermite911fbibustards wrote: > http://www.speed-light.info/angels_speed_of_light.htm From nanothermite911fbibustards at gmail.com Thu Jul 22 00:35:41 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:35:41 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: <9b6a9f32-333c-4e2a-a621-47f7770bb88e@x20g2000pro.googlegroups.com> On Jul 21, 9:16?pm, nanothermite911fbibustards wrote: > You shall see CIA / Mossad / AIPAC / CRIMINAL PRIVATE KROLL/BLACKWATER/ > gstatic.com bustards start spamming to drown 911 truth. their spam is > about VIAGRA/DIAZEPAM/VALIUM/SEX etc. > > They hate our freedoms. They sent anthrax. They did 911. They put the > blame on arabs but they are the ones as FORENSIC proves WITHOUT ?ANY > DOUBT !!! > > White crime rate is 5 times Asian per capita in the USA. > > On Jul 21, 1:21?pm, nanothermite911fbibustards wrote: > > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > > israelis and what is the status of FORENSIC evidence and trace of NANO > > THERMITE in WTC dust ? > > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > israelis and what is the status of FORENSIC evidence and trace of NANO > THERMITE in WTC dust ? > > The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE > is UNACCEPTABLE. > > ===== > > http://www.youtube.com/watch?v=lX18zUp6WPY > > http://www.youtube.com/watch?v=XQapkVCx1HI > > http://www.youtube.com/watch?v=tXJ-k-iOg0M > > Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? > Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did > you release the 5 dancing Israelis compromising the whole 911 > investigation ? If the Dubai Police can catch Mossad Murderers and put > the videos and Iranian Police can why cant you put the Pentagon > Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and > puting on INTERNATIONAL MEDIA a day after catching him without > TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did > you have to LIE about Dr Afiya Siddiqui and torture that Innocent > little mother of 3 and smashing the skull of her one child ? > > http://www.youtube.com/watch?v=DhMcii8smxkhttp://www.youtube.com/watch?v=0SZ2lxDJmdg > > There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian > courts. > > FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but > only because he was a white. They got away with MURDER of thousands of > Non-whites in all parts of the world. > > Daily 911 news :http://911blogger.com > > http://www.youtube.com/watch?v=tRfhUezbKLw > > http://www.youtube.com/watch?v=x7kGZ3XPEm4 > > http://www.youtube.com/watch?v=lX18zUp6WPY > > Conclusion : FBI bustards are RACIST and INcompetent. They could > neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they > cover them up - whichever was their actual goal or task. > > SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across > tbe board, esp the whites/jew on the top. > > FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and > UNPATRIOTIC Act > FBI bustards failed to prevent ROMAN POLANSKY from absconding to > europe and rapes. > FBI bustards failed to prevent OKLAHOMA Now Germany -- not a shot had been fired on the German soil. Not an enemy soldier had crossed the border into Germany. And yet, here was Germany offering England peace terms. They offered England a negotiated peace on what the lawyers call a status quo ante basis. That means: ?Let's call the war off, and let everything be as it was before the war started.? Well, England, in the summer of 1916 was considering that. Seriously! They had no choice. It was either accepting this negotiated peace that Germany was magnanimously offering them, or going on with the war and being totally defeated. While that was going on, the Zionists in Germany, who represented the Zionists from Eastern Europe, went to the British War Cabinet and -- I am going to be brief because this is a long story, but I have all the documents to prove any statement that I make if anyone here is curious, or doesn't believe what I'm saying is at all possible -- the Zionists in London went to the British war cabinet and they said: ?Look here. You can yet win this war. You don't have to give up. You don't have to accept the negotiated peace offered to you now by Germany. You can win this war if the United States will come in as your ally.? The United States was not in the war at that time. We were fresh; we were young; we were rich; we were powerful. They [Zionists] told England: ?We will guarantee to bring the United States into the war as your ally, to fight with you on your side, if you will promise us Palestine after you win the war.? In other words, they made this deal: ?We will get the United States into this war as your ally. The price you must pay us is Palestine after you have won the war and defeated Germany, Austria- Hungary, and Turkey.? Now England had as much right to promise Palestine to anybody, as the United States would have to promise Japan to Ireland for any reason whatsoever. It's absolutely absurd that Great Britain -- that never had any connection or any interest or any right in what is known as Palestine -- should offer it as coin of the realm to pay the Zionists for bringing the United States into the war. However, they made that promise, in October of 1916. October, nineteen hundred and sixteen. And shortly after that -- I don't know how many here remember it -- the United States, which was almost totally pro-German -- totally pro-German -- because the newspapers here were controlled by Jews, the bankers were Jews, all the media of mass communications in this country were controlled by Jews, and they were pro-German because their people, in the majority of cases came from Germany, and they wanted to see Germany lick the Czar. The Jews didn't like the Czar, and they didn't want Russia to win this war. So the German bankers -- the German-Jews -- Kuhn Loeb and the other big banking firms in the United States refused to finance France or England to the extent of one dollar. They stood aside and they said: ?As long as France and England are tied up with Russia, not one cent!? But they poured money into Germany, they fought with Germany against Russia, trying to lick the Czarist regime. Now those same Jews, when they saw the possibility of getting Palestine, they went to England and they made this deal. At that time, everything changed, like the traffic light that changes from red to green. Where the newspapers had been all pro-German, where they'd been telling the people of the difficulties that Germany was having fighting Great Britain commercially and in other respects, all of a sudden the Germans were no good. They were villains. They were Huns. They were shooting Red Cross nurses. They were cutting off babies' hands. And they were no good. Well, shortly after that, Mr. Wilson declared war on Germany. The Zionists in London sent these cables to the United States, to Justice Brandeis: ?Go to work on President Wilson. We're getting from England what we want. Now you go to work, and you go to work on President Wilson and get the United States into the war." And that did happen. That's how the United States got into the war. We had no more interest in it; we had no more right to be in it than we have to be on the moon tonight instead of in this room. Now the war -- World War One -- in which the United States participated had absolutely no reason to be our war. We went in there -- we were railroaded into it -- if I can be vulgar, we were suckered into -- that war merely so that the Zionists of the world could obtain Palestine. Now, that is something that the people in the United States have never been told. They never knew why we went into World War One. Now, what happened? After we got into the war, the Zionists went to Great Britain and they said: ?Well, we performed our part of the agreement. Let's have something in writing that shows that you are going to keep your bargain and give us Palestine after you win the war.? Because they didn't know whether the war would last another year or another ten years. So they started to work out a receipt. The receipt took the form of a letter, and it was worded in very cryptic language so that the world at large wouldn't know what it was all about. And that was called the Balfour Declaration. The Balfour Declaration was merely Great Britain's promise to pay the Zionists what they had agreed upon as a consideration for getting the United States into the war. So this great Balfour Declaration, that you hear so much about, is just as phony as a three dollar bill. And I don't think I could make it more emphatic than that. Now, that is where all the trouble started. The United States went in the war. The United States crushed Germany. We went in there, and it's history. You know what happened. Now, when the war was ended, and the Germans went to Paris, to the Paris Peace Conference in 1919, there were 117 Jews there, as a delegation representing the Jews, headed by Bernard Baruch. I was there: I ought to know. Now what happened? The Jews at that peace conference, when they were cutting up Germany and parceling out Europe to all these nations that claimed a right to a certain part of European territory, the Jews said, ?How about Palestine for us?? And they produced, for the first time to the knowledge of the Germans, this Balfour Declaration. So the Germans, for the first time realized, ?Oh, that was the game! That's why the United States came into the war.? And the Germans for the first time realized that they were defeated, they suffered this terrific reparation that was slapped onto them, because the Zionists wanted Palestine and they were determined to get it at any cost. Now, that brings us to another very interesting point. When the Germans realized this, they naturally resented it. Up to that time, the Jews had never been better off in any country in the world than they had been in Germany. You had Mr. Rathenau there, who was maybe 100 times as important in industry and finance as is Bernard Baruch in this country. You had Mr. Balin, who owned the two big steamship lines, the North German Lloyd's and the Hamburg-American Lines. You had Mr. Bleichroder, who was the banker for the Hohenzollern family. You had the Warburgs in Hamburg, who were the big merchant bankers -- the biggest in the world. The Jews were doing very well in Germany. No question about that. Now, the Germans felt: ?Well, that was quite a sellout.? It was a sellout that I can best compare -- suppose the United States was at war today with the Soviet Union. And we were winning. And we told the Soviet Union: ?Well, let's quit. We offer you peace terms. Let's forget the whole thing.? And all of a sudden Red China came into the war as an ally of the Soviet Union. And throwing them into the war brought about our defeat. A crushing defeat, with reparations the likes of which man's imagination cannot encompass. Imagine, then, after that defeat, if we found out that it was the Chinese in this country, our Chinese citizens, who all the time we thought they were loyal citizens working with us, were selling us out to the Soviet Union and that it was through them that Red China was brought into the war against us. How would we feel, in the United States against Chinese? I don't think that one of them would dare show his face on any street. There wouldn't be lampposts enough, convenient, to take care of them. Imagine how we would feel. Well, that's how the Germans felt towards these Jews. "We've been so nice to them"; and from 1905 on, when the first Communist revolution in Russia failed, and the Jews had to scramble out of Russia, they all went to Germany. And Germany gave them refuge. And they were treated very nicely. And here they sold Germany down the river for no reason at all other than they wanted Palestine as a so- called ?Jewish commonwealth.? Now, Nahum Sokolow -- all the great leaders, the big names that you read about in connection with Zionism today -- they, in 1919, 1920, '21, '22, and '23, they wrote in all their papers -- and the press was filled with their statements -- that "the feeling against the Jews in Germany is due to the fact that they realized that this great defeat was brought about by our intercession and bringing the United States into the war against them." From e.datateam at gmail.com Thu Jul 22 01:43:00 2010 From: e.datateam at gmail.com (E-DataTeam) Date: Wed, 21 Jul 2010 22:43:00 -0700 (PDT) Subject: solution manual & test bank Message-ID: <92fffa19-09dd-4efa-82f0-266792453997@d17g2000yqb.googlegroups.com> Hi! we are GetSolution team Our mission supplying solution manuals , test banks , to students all over the world if you need any solutions manual or test bank just email us This is partial list of our solutions, if the solution you want isn't on the list, do not give up, just contact us. WwW.GetSolutionTeam.CoM Note: all solutions manual in soft copy that mean in Adobe Acrobat Reader (PDF ) format. to get the solution manual you want please send message to getsolution at hotmail.com getsolution(at)hotmail.com replace (at) to @ please don't post your request here to get the solutions please send like that: hi my name is Jone i want to get this solutions manual/ test bank: "A First Course In Probability Solution Manual,Ross 6th " How much is it to know how u can get the solutions please visit our website www.GetSolutionTeam.com " We Have Live Support On The WebSite" This is partial list of our solutions, if the solution you want isn't on the list, do not give up, just contact us. From nanothermite911fbibustards at gmail.com Thu Jul 22 02:15:34 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 23:15:34 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: <444e75c2-9b8d-4d56-9e4a-96b4b33c82c0@q35g2000yqn.googlegroups.com> On Jul 21, 4:31?pm, spudnik wrote: > thermite is not what you think, it is; > it's primary use is for dismantling steel frameworks, > piece by piece, just as they were welded -- > see the report by MIT's Head Welder. > > thus: > there, you've hit upon the self-same absurdity > of Newton's "theory" of corpuscles, vis-a-vu waves of light > in the non-vacuum of space (unconsciously .-) > > thus quoth: > Does every dust speck have gravitons? ?And if not, how do the specks > know... "which way the mass is"? > > --BP's cap&trade "free-er trade nostrum" is before Senate!http://tarpley.net/online-books/george-bush-the-unauthorized-biograph... Whats the qualification of you a faceless, spooooky bustard ? unlike HONORABLE Professor Dr Steven Jones, who sacrificed his job and career at BYU - Brigham Young University . Whats your sacrifice to show your conviction from your ODIOUS and PUTRID mouth ? From fulviocasali at gmail.com Thu Jul 22 02:26:35 2010 From: fulviocasali at gmail.com (fulv) Date: Wed, 21 Jul 2010 23:26:35 -0700 (PDT) Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters Message-ID: I get the following error: File "", line 1, in ? File "/Users/fulvio/plone/seiu_new/buildout/eggs/z3c.saconfig-0.11- py2.4.egg/z3c/saconfig/utility.py", line 164, in __call__ _ENGINES[self._key] = engine = sqlalchemy.create_engine( File "/Users/fulvio/plone/seiu_new/buildout/eggs/SQLAlchemy-0.6.3- py2.4.egg/sqlalchemy/engine/__init__.py", line 244, in create_engine return strategy.create(*args, **kwargs) TypeError: create() takes exactly 2 non-keyword arguments (150 given) Basically, args and kwargs come as the return values from my overridden function configuration(): args, kw = self.configuration() _ENGINES[self._key] = engine = sqlalchemy.create_engine( *args, **kw) This is what I'm returning from configuration(): args = (connection_string) kwargs = {'echo' : True, 'encoding' : 'cp1252'} return args, kwargs In other words, args is a list containing just one string. It seems to me that create_engine is interpreting that as a list of 150 characters. Any suggestions, on what I'm doing wrong? Thanks! Fulvio From girish.cfc at gmail.com Thu Jul 22 02:35:32 2010 From: girish.cfc at gmail.com (Girish) Date: Wed, 21 Jul 2010 23:35:32 -0700 (PDT) Subject: Unzip File un Python 5.5 Message-ID: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Hello All, I am using Python 2.5. How do I extract all the files and directories in a zip file? Thanks in advance.. -Girish From nopsidy at gmail.com Thu Jul 22 02:49:27 2010 From: nopsidy at gmail.com (nopsidy) Date: Thu, 22 Jul 2010 01:49:27 -0500 Subject: Unzip File un Python 5.5 In-Reply-To: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> References: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Message-ID: hi, hope this helps. http://www.google.com/search?hl=en&q=unzip+file+in+python -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu Jul 22 02:53:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jul 2010 16:53:05 +1000 Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters In-Reply-To: References: Message-ID: On Thu, Jul 22, 2010 at 4:26 PM, fulv wrote: > ?args = (connection_string) Replace this with: args = (connection_string,) NOTE: The trailing , (comma) indicating that this _is_ a tuple. cheers James -- -- James Mills -- -- "Problems are solved by method" From ben+python at benfinney.id.au Thu Jul 22 02:56:05 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 22 Jul 2010 16:56:05 +1000 Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters References: Message-ID: <87zkxk57ju.fsf@benfinney.id.au> fulv writes: > return strategy.create(*args, **kwargs) > TypeError: create() takes exactly 2 non-keyword arguments (150 given) > > Basically, args and kwargs come as the return values from my > overridden function configuration(): > > args, kw = self.configuration() > _ENGINES[self._key] = engine = > sqlalchemy.create_engine( > *args, **kw) (As a side note: Please use a mail client that won't wrap your lines incorrectly like the above. That might mean not using Google Mail.) > This is what I'm returning from configuration(): > > args = (connection_string) > kwargs = {'echo' : True, 'encoding' : 'cp1252'} > return args, kwargs > > In other words, args is a list containing just one string. No, it isn't. The syntax you've used merely puts parentheses around the object ?connection_string?; parentheses don't make a list. So, when you use the argument unpacking syntax, the string gets unpacked into its component characters, as you noticed. You might have meant ?a tuple containing just one string?. But parentheses don't make a tuple either. To make a tuple, use commas. You may put parentheses around the tuple to distinguish it from surrounding syntax, and because commas are used in various other places, sometimes you need to. But never forget that it's the commas that make the tuple, not the parentheses. args = (connection_string,) kwargs = {'echo': True, 'encoding': 'cp1252'} return args, kwargs I hope that helps. -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Thu Jul 22 03:21:53 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 07:21:53 GMT Subject: Unzip File un Python 5.5 References: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Message-ID: <4c47f191$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 23:35:32 -0700, Girish wrote: > Hello All, > > I am using Python 2.5. How do I extract all the files and directories in > a zip file? import zipfile z = zipfile.ZipFile("test.zip", mode="r") for internal_filename in z.namelist(): contents = z.read(internal_filename) open(internal_filename, 'w').write(contents) z.close() Or upgrade to Python 2.6 and use the extractall method: http://docs.python.org/library/zipfile.html#zipfile.ZipFile.extractall -- Steven From aimeixu at amazon.com Thu Jul 22 04:14:14 2010 From: aimeixu at amazon.com (aimeixu) Date: Thu, 22 Jul 2010 16:14:14 +0800 Subject: an error about DJANGO_SETTINGS_MODULE Message-ID: <4C47FDD6.1080800@amazon.com> Hi, I use python Django framework to make a bookmark website, when I clicked login button on the user login page .and I import "from django.contrib.auth.models import User" in the console,It will occur the following error: >>> from django.contrib.auth.models import User Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/django/contrib/auth/models.py", line 6, in ? from django.db import models File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, in ? if not settings.DATABASES: File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 276, in __getattr__ self._setup() File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 38, in _setup raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE) ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined. 'cause I am a newbie to python .Please help me find out where the error is and how to solve this problem. Thanks a lot. Best Wishes, From clp2 at rebertia.com Thu Jul 22 05:21:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jul 2010 02:21:29 -0700 Subject: an error about DJANGO_SETTINGS_MODULE In-Reply-To: <4C47FDD6.1080800@amazon.com> References: <4C47FDD6.1080800@amazon.com> Message-ID: On Thu, Jul 22, 2010 at 1:14 AM, aimeixu wrote: > Hi, > I use python Django framework to make a bookmark website, when I clicked > ?login button on ?the user login page .and I ?import "from > django.contrib.auth.models import User" in the console,It will occur the > following error: >>>> from django.contrib.auth.models import User > Traceback (most recent call last): > ?File "", line 1, in ? > ?File "/usr/lib/python2.4/site-packages/django/contrib/auth/models.py", line > 6, in ? > ? from django.db import models > ?File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, in > ? > ? if not settings.DATABASES: > ?File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line > 276, in __getattr__ > ? self._setup() > ?File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 38, > in _setup > ? raise ImportError("Settings cannot be imported, because environment > variable %s is undefined." % ENVIRONMENT_VARIABLE) > ImportError: Settings cannot be imported, because environment variable > DJANGO_SETTINGS_MODULE is undefined. > 'cause I am a newbie to python .Please help me find out where the error is > and how to solve this problem. Thanks a lot. The Django-specific mailinglist may be found at: http://groups.google.com/group/django-users You are more likely to get a [better] answer if you ask there. Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Thu Jul 22 05:38:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 22 Jul 2010 11:38:23 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C47124A.10405@keymile.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: >>> Something like the "file" utility for linux would be very helpfull. >>> >>> Any help is appreciated. > >>You're going to have to describe in detail what's in the file before >>anybody can help. > > We are creating inside our buildsystem for an embedded system a cram > filesystem > image. Later on inside our build process we have to check the endianness, > because it could be Little Endian or big endian (arm or ppc). > > The output of the "file" tool is for a little endian cramfs image: > : Linux Compressed ROM File System data, little endian size > 1875968 > version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > > It would be possible to execute > ret = os.system("file | grep "little endian") > and evaluate the return code. > But I don't like to evaluate a piped system command. If there is an way > without > using the os.system command this would be great. > Please see http://pypi.python.org/pypi/python-magic HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From pdwjfndjbdgfyg at gmail.com Thu Jul 22 05:41:09 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Thu, 22 Jul 2010 02:41:09 -0700 (PDT) Subject: REAL HOT VIDEOS Message-ID: <2686d7b5-cc89-4db6-bb6e-97be373d55bd@l25g2000prn.googlegroups.com> hot kisses http://hotvidos.blogspot.com/2010/07/hot-kisses.html hot lip kiss http://hotvidos.blogspot.com/2010/07/hot-lip-kiss.html katrina kaif hot videos http://hotvidos.blogspot.com/2010/07/katrina-kaif-hot-videos.html bollywood hot vieos http://hotvidos.blogspot.com/2010/07/bollywood-hot-vieos.html tollywood hot vieos http://hotvidos.blogspot.com/2010/07/tollywood-hot-vieos.html tamil hot videos http://hotvidos.blogspot.com/2010/07/tamil-hot-videos.html mallu hot videos http://hotvidos.blogspot.com/2010/07/mallu-hot-videos.html real hot videos http://hotvidos.blogspot.com/2010/07/real-hot-videos.html hollywood hot videos http://hotvidos.blogspot.com/2010/07/hollywood-hot-videos.html From kwutzke at web.de Thu Jul 22 07:03:05 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 22 Jul 2010 04:03:05 -0700 (PDT) Subject: Visitor pattern and separating iteration Message-ID: Hello, I'm referring to http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9ba9816fe4fd55# I'm currently implementing what looks like a promising solution. I have one problem though. My code generator isn't awfully complex, but still I have problems trying to figure out where to put the iteration code. Ideally, this should be in the classes the generator operates on. Take the following Python code from my generator class: def handleMethod(self, method): # generate indent depending on object depth in tree indent = self.generateIndent(method) # "public final" modifierString = "" i = 0 for modifier in method.getModifiers(): if i > 0: modifierString += " " modifierString += modifier i += 1 # "String firstName, String lastName" parameterString = "" i = 0 for parameter in method.getParameters(): if i > 0: parameterString += ", " parameterString += parameter.getType() + " " + parameter.getName() i += 1 code = indentString + modifierString + " " + (method.getReturnType() is None and "" or method.getReturnType() + " ") + method.getName() + "(" + parameterString + ")" code += "\n{" # here the statements should go code += "\n}" return code The place where the statements should go would require an iteration over the statements. When looking at other code samples, you often see def accept(self, visitor): for child in self.getChildren(): child.accept(visitor) visitor.visitMyClass(self) Now, I am wondering how separation of iteration and actual code generation can be done in my situation. def accept(self, generator): for child in self.getChildren(): child.accept(generator) generator.handleMethod(self) I could of course add a parameter to handleMethod which would be the generated code for the statements, but is that design of any good use then? I'm rather tempted to ditch the idea of separating iteration and code generation, but then the use of the visitor pattern becomes more and more questionable. What is it I'm missing? Karsten From kwutzke at web.de Thu Jul 22 07:11:57 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 22 Jul 2010 04:11:57 -0700 (PDT) Subject: Visitor pattern and separating iteration References: Message-ID: <45c17022-1a95-4081-9107-6caad1531e01@f33g2000yqe.googlegroups.com> > ? ? ? ? # "public final" > ? ? ? ? modifierString = "" > > ? ? ? ? i = 0 > > ? ? ? ? for modifier in method.getModifiers(): > ? ? ? ? ? ? if i > 0: > ? ? ? ? ? ? ? ? modifierString += " " > ? ? ? ? ? ? modifierString += modifier > > ? ? ? ? ? ? i += 1 > And please don't comment on the code itself, as I'm just starting to learn the Python API. The above should be modifierString = " ".join(method.getModifiers()) Thanks Karsten From kaklis at gmail.com Thu Jul 22 08:54:58 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Thu, 22 Jul 2010 05:54:58 -0700 (PDT) Subject: Convert Unix timestamp to Readable Date/time Message-ID: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> Well i have the following number 1279796174846 i did the following: mdate = 1279796174846 tempStr = str(mdate) tempStr2 = tempStr[:-3] tempInt = int(tempStr2) print "Last Login :", datetime.datetime.fromtimestamp(tempInt) that prints out: 2010-07-22 06:56:14 But when i check my answer at http://www.onlineconversion.com/unix_time.htm i got: Thu, 22 Jul 2010 10:56:14 GMT which is what i want. What am i doing wrong? Thanks Antonis From clp2 at rebertia.com Thu Jul 22 09:01:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jul 2010 06:01:47 -0700 Subject: Convert Unix timestamp to Readable Date/time In-Reply-To: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> References: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> Message-ID: On Thu, Jul 22, 2010 at 5:54 AM, kaklis at gmail.com wrote: > Well i have the following number 1279796174846 > ?i did the following: > > mdate = 1279796174846 > tempStr = str(mdate) > tempStr2 = tempStr[:-3] > tempInt = int(tempStr2) > print "Last Login :", datetime.datetime.fromtimestamp(tempInt) > > that prints out: 2010-07-22 06:56:14 > But when i check my answer at http://www.onlineconversion.com/unix_time.htm > > i got: ? ?Thu, 22 Jul 2010 10:56:14 GMT which is what i want. > What am i doing wrong? >From http://docs.python.org/library/datetime.html (emphases added): """ classmethod datetime.fromtimestamp(timestamp[, tz]) Return the ***local*** date and time corresponding to the POSIX timestamp [...] """ vs. """ classmethod datetime.utcfromtimestamp(timestamp)? Return the ***UTC*** datetime corresponding to the POSIX timestamp [...] """ IOW, read the fine docs. Cheers, Chris -- http://blog.rebertia.com From jbbrown at sunflower.kuicr.kyoto-u.ac.jp Thu Jul 22 10:51:54 2010 From: jbbrown at sunflower.kuicr.kyoto-u.ac.jp (J.B. Brown) Date: Thu, 22 Jul 2010 23:51:54 +0900 Subject: Sun Grid Engine / NFS and Python shell execution question Message-ID: Hello everyone, and thanks for your time to read this. For quite some time, I have had a problem using Python's shell execution facilities in combination with a cluster computer environment (such as Sun Grid Engine (SGE)). In particular, I wish to repeatedly execute a number of commands in sub-shells or pipes within a single function, and the repeated execution is depending on the previous execution, so just writing a brute force script file and executing commands is not an option for me. To isolate and exemplify my problem, I have created three files: (1) one which exemplifies the spirit of the code I wish to execute in Python (2) one which serves as the SGE execution script file, and actually calls python to execute the code in (1) (3) a simple shell script which executes (2) a sufficient number of times that it fills all processors on my computing cluster and leaves an additional number of jobs in the queue. Here is the spirit of the experiment/problem: generateTest.py: ---------------------------------------------- # Constants numParallelJobs = 100 testCommand = "continue" #"os.popen( \"clear\" )" loopSize = "1000" # First, write file with test script. pythonScript = file( "testScript.py", "w" ) pythonScript.write( """ import os for i in range( 0, """ + loopSize + """ ): for j in range( 0, """ + loopSize + """ ): for k in range( 0, """ + loopSize + """ ): for l in range( 0, """ + loopSize + """ ): """ + testCommand + """ """ ) pythonScript.close() # Second, write SGE script file to execute the Python script. sgeScript = file( "testScript.sge", "w" ) sgeScript.write ( """ #$ -cwd #$ -N pythonTest #$ -e /export/home/jbbrown/errorLog #$ -o /export/home/jbbrown/outputLog python testScript.py """ ) sgeScript.close() # Finally, write script to run SGE script a specified number of times. import os launchScript = file( "testScript.sh", "w" ) for i in range( 0, numParallelJobs ): launchScript.write( "qsub testScript.sge" + os.linesep ) launchScript.close() ---------------------------------------------- Now, let's assume that I have about 50 processors available across 8 compute nodes, with one NFS-mounted disk. If I run the code as above, simply executing Python "continue" statements and do nothing, the cluster head node reports no serious NFS daemon load. However - if I change the code to use the os.popen() call shown as a comment above, or use os.system(), the NFS daemon load on my system skyrockets within seconds of distributing the jobs to the compute nodes -- even though I'm doing nothing but executing the clear screen command, which technically doesn't pipe any output to the location for logging stdout. Even if I change the SGE script file to redirect standard output and error to explicitly go to /dev/null, I still have the same problem. I believe the source of this problem is that os.popen() or os.system() calls spawn subshells which then reference my shell resource files (.zshrc, .cshrc, .bashrc, etc.). But I don't see an alternative to os.popen{234} or os.system(). os.exec*() cannot solve my problem, because it transfers execution to that program and stops executing the script which called os.exec*(). Without having to rewrite a considerable amount of code (which performs cross validation by repeatedly executing in a subshell) in terms of a shell script language filled with a large number of conditional statements, does anyone know of a way to execute external programs in the middle of a script without referencing the shell resource file located on an NFS mounted directory? I have read through the >help(os) documentation repeatedly, but just can't find a solution. Even a small lead or thought would be greatly appreciated. With thanks from humid Kyoto, J.B. Brown From python at mrabarnett.plus.com Thu Jul 22 11:31:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jul 2010 16:31:55 +0100 Subject: Sun Grid Engine / NFS and Python shell execution question In-Reply-To: References: Message-ID: <4C48646B.40101@mrabarnett.plus.com> J.B. Brown wrote: > Hello everyone, and thanks for your time to read this. > > For quite some time, I have had a problem using Python's shell > execution facilities in combination with a cluster computer > environment (such as Sun Grid Engine (SGE)). > In particular, I wish to repeatedly execute a number of commands in > sub-shells or pipes within a single function, and the repeated > execution is depending on the previous execution, so just writing a > brute force script file and executing commands is not an option for > me. > > To isolate and exemplify my problem, I have created three files: > (1) one which exemplifies the spirit of the code I wish to execute in Python > (2) one which serves as the SGE execution script file, and actually > calls python to execute the code in (1) > (3) a simple shell script which executes (2) a sufficient number of > times that it fills all processors on my computing cluster and leaves > an additional number of jobs in the queue. > > Here is the spirit of the experiment/problem: > generateTest.py: > ---------------------------------------------- > # Constants > numParallelJobs = 100 > testCommand = "continue" #"os.popen( \"clear\" )" > loopSize = "1000" > > # First, write file with test script. > pythonScript = file( "testScript.py", "w" ) > pythonScript.write( > """ > import os > for i in range( 0, """ + loopSize + """ ): > for j in range( 0, """ + loopSize + """ ): > for k in range( 0, """ + loopSize + """ ): > for l in range( 0, """ + loopSize + """ ): > """ + testCommand + """ > """ ) > pythonScript.close() > > # Second, write SGE script file to execute the Python script. > sgeScript = file( "testScript.sge", "w" ) > sgeScript.write ( > """ > #$ -cwd > #$ -N pythonTest > #$ -e /export/home/jbbrown/errorLog > #$ -o /export/home/jbbrown/outputLog > python testScript.py > """ ) > sgeScript.close() > > # Finally, write script to run SGE script a specified number of times. > import os > launchScript = file( "testScript.sh", "w" ) > for i in range( 0, numParallelJobs ): > launchScript.write( "qsub testScript.sge" + os.linesep ) > launchScript.close() > > ---------------------------------------------- > > Now, let's assume that I have about 50 processors available across 8 > compute nodes, with one NFS-mounted disk. > If I run the code as above, simply executing Python "continue" > statements and do nothing, the cluster head node reports no serious > NFS daemon load. > > However - if I change the code to use the os.popen() call shown as a > comment above, or use os.system(), > the NFS daemon load on my system skyrockets within seconds of > distributing the jobs to the compute nodes -- even though I'm doing > nothing but executing the clear screen command, which technically > doesn't pipe any output to the location for logging stdout. > Even if I change the SGE script file to redirect standard output and > error to explicitly go to /dev/null, I still have the same problem. > > I believe the source of this problem is that os.popen() or os.system() > calls spawn subshells which then reference my shell resource files > (.zshrc, .cshrc, .bashrc, etc.). > But I don't see an alternative to os.popen{234} or os.system(). > os.exec*() cannot solve my problem, because it transfers execution to > that program and stops executing the script which called os.exec*(). > > Without having to rewrite a considerable amount of code (which > performs cross validation by repeatedly executing in a subshell) in > terms of a shell script language filled with a large number of > conditional statements, does anyone know of a way to execute external > programs in the middle of a script without referencing the shell > resource file located on an NFS mounted directory? > I have read through the >help(os) documentation repeatedly, but just > can't find a solution. > > Even a small lead or thought would be greatly appreciated. > Have you looked at the 'subprocess' module? From fulviocasali at gmail.com Thu Jul 22 12:01:58 2010 From: fulviocasali at gmail.com (fulv) Date: Thu, 22 Jul 2010 09:01:58 -0700 (PDT) Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters References: Message-ID: <42e580ef-f9b3-4305-b531-860ecc46e999@y32g2000prc.googlegroups.com> Thank you all! Really appreciate the quick help! From burton at userful.com Thu Jul 22 12:12:51 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 22 Jul 2010 10:12:51 -0600 Subject: Improper Backtraces in Exec'd Code Message-ID: Hello, I have written an importing extension along the lines of PEP 302 (http://www.python.org/dev/peps/pep-0302/) and have run into a bit of a problem with stack backtraces after exceptions. When I run code with the using my importing extension, backtraces come up looking like this: Traceback (most recent call last): File "", line 134, in File "", line 9, in File "", line 7, in a File "", line 4, in b TypeError What I'm having a problem with is that the file names are no longer being printed during the backtrace. The following code is from my importer function load_module: try: mod = sys.modules[module_name] already_in_sys_modules = True except KeyError: mod = sys.modules.setdefault(module_name, imp.new_module(module_name)) already_in_sys_modules = False mod.__file__ = "%s" % module_path mod.__loader__ = self if is_package: mod.__path__ = [ module_path ] mod.__dict__['__file__'] = module_path try: exec code in mod.__dict__ except: import traceback print traceback.format_exc(5) print "ERROR: could not load module: %s" % module_path if not already_in_sys_modules: del sys.modules[module_name] mod = None As shown in PEP 302, I am setting the mod.__file__ variable and as my own idea I set __file__ in mod.__dict__. Niether of these steps seem to set the file properly in the backtrace. So the question here is, where does the backtrace printing module get it's __file__ parameters from, or what am I missing to set it properly? Thanks in advance. -- Burton Samograd From nils at ccsg.de Thu Jul 22 12:19:25 2010 From: nils at ccsg.de (Nils Ruettershoff) Date: Thu, 22 Jul 2010 18:19:25 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: <4C486F8D.6020902@ccsg.de> Hi Jim, Jim Qiu wrote: > > I make installed python 2.7 from source, and also installed the RPM > version of cx_Oracle for python 2.7. > > But ldd tells me : > #ldd cx_Oracle.so > libpython2.7.so.1.0 => not found > > I find out that only libpython2.7.a generated when I install > python2.7, who can tell me what I need to do ? I want a > libpython2.7.so.1.0 generated when > [...] Due to the fact that you have compiled python from source, the python library is not in the defaul library path. Due to that the lib can't be found. As a quick workourd you can extend the LD_LIBRARY_PATH variable with the path and check if cx_Orcacle get now the lib. Lets assume you "installed" python at /opt/Python2.7a, then you need to extend the variable in this way: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/Python2.7a/lib" afterwards do the ldd again and check if the lib could be found now. If not, you've got the wrong path. Now you need to perist the changed library path. For this, you need to be root: 1. echo "/opt/Python2.7a/lib" > /etc/ld.so.conf.d/Pathon2.7a.conf 2. refresh your shared library cache with "ldconfig" Now you OS knows the new library location. But this is not clean. As Daniel mention, you should try to get a rpm. Otherwise you may get in trouble, if you install a newer Python2.7 version and forget to maintain you library paths. Cheers, Nils From nils at ccsg.de Thu Jul 22 12:39:46 2010 From: nils at ccsg.de (Nils Ruettershoff) Date: Thu, 22 Jul 2010 18:39:46 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: <4C487452.7040303@ccsg.de> Hi Jim, Jim Qiu wrote: [...] > I find out that only libpython2.7.a generated when I install > python2.7, who can tell me what I need to do ? I want a > libpython2.7.so.1.0 generated when > I've didn't read your complete mail... In addition to the steps I've described in my other mail, you need to the "configure" script, that you like to have shared libraries. So you need to add --enable-shared to your configure call: ./configure --prefix=/opt/Python2.7a --enable-shared Now you got the shared libraries in the lib folder. Cheers, Nils From thomas at jollans.com Thu Jul 22 12:56:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 22 Jul 2010 18:56:03 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: <4C487823.4080003@jollans.com> On 07/21/2010 03:38 PM, kaklis at gmail.com wrote: > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: >> On Jul 21, 8:58 am, Stefan Behnel wrote: >> >> >> >>> kak... at gmail.com, 21.07.2010 14:36: >> >>>> From the subject of my message it's clear that i get an xml message >>>> from a socket, >> >>> Not at all, but now that you say it... >> >>>> i parse it and the result is a list like the one that >>>> follows: >>>> ID_Col >>>> 4 Server ak ip OFFLINE >> >>>> 29 Server and2 ip OFFLINE >> >>>> 5 Proxy l34e ip OFFLINE >> >>>> 6 Proxy barc ip ONLINE >> >>>> 41 Proxy proxy-2 ip ONLINE >> >>>> 53 Server server-4 ip ONLINE >> >>>> 52 Server server-3 ip ONLINE >> >>> Doesn't look like a Python list to me... >> >>>> What i want is to print this list sorted by ID_Col? >>>> Any Suggestions? >> >>> Assuming that the above is supposed to represent a list of tuples, you can >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' >>> argument (see the sort() method and the operator module). >> >>> Stefan >> >> No it is not a Python list at all. This the way i print the parsed >> items 'like a list'. >> But i want them to be sorted. > > Well i did this: > > SortedServers = [] > > for session in sessions: > for IP in session.getElementsByTagName("ipAddress"): > for iphn in session.getElementsByTagName("hostName"): > tempTuple = session.getAttribute("id"), > session.getAttribute("type"), iphn.childNodes[0].data, > IP.childNodes[0].data, session.getAttribute("status") Please try to persuade your mail client to not mess up python code, if you could. It would make this *so* much easier to read > > SortedServers.append(tempTuple) > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) Anyway, let's look at that key function of yours: key=lambda id: SortedServers[0] translated to traditional function syntax: def key(id): return SortedServers[0] No matter which item sorted() examines, the key it sorts by is always the same (the first item of the WHOLE LIST). You want something more like this: def key(row): return row[0] ergo, what you want, all in all, is either of these: Sorted = sorted(SortedServers, key=(lambda row: row[0])) # option 1 SortedServers.sort(key=(lambda row: row[0])) # option 2 option 2, the in-place sort, might be faster. (and, as Stefan noted, as you probably want a numeric sort, you'll want your key to be an int) > for item in Sorted: > print item > > but the list is still unsorted and with u' in front of each item > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') > > How do i remove the u' > > Antonis From __peter__ at web.de Thu Jul 22 13:00:43 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Jul 2010 19:00:43 +0200 Subject: Improper Backtraces in Exec'd Code References: Message-ID: Burton Samograd wrote: > Hello, > > I have written an importing extension along the lines of PEP 302 > (http://www.python.org/dev/peps/pep-0302/) and have run into a bit of a > problem with stack backtraces after exceptions. > > When I run code with the using my importing extension, backtraces come > up looking like this: > > Traceback (most recent call last): > File "", line 134, in > File "", line 9, in > File "", line 7, in a > File "", line 4, in b > TypeError > > What I'm having a problem with is that the file names are no longer > being printed during the backtrace. The following code is from my > importer function load_module: > > try: > mod = sys.modules[module_name] > already_in_sys_modules = True > except KeyError: > mod = sys.modules.setdefault(module_name, > imp.new_module(module_name)) > already_in_sys_modules = False > mod.__file__ = "%s" % module_path > mod.__loader__ = self > if is_package: > mod.__path__ = [ module_path ] > mod.__dict__['__file__'] = module_path > try: > exec code in mod.__dict__ > except: > import traceback > print traceback.format_exc(5) > print "ERROR: could not load module: %s" % module_path > if not already_in_sys_modules: > del sys.modules[module_name] > mod = None > > As shown in PEP 302, I am setting the mod.__file__ variable and as my > own idea I set __file__ in mod.__dict__. Niether of these steps seem to > set the file properly in the backtrace. > > So the question here is, where does the backtrace printing module get > it's __file__ parameters from, or what am I missing to set it properly? > > Thanks in advance. > > -- > Burton Samograd exec code implicitly compiles code with "" as the filename. The filename is stored in f.func_code.co_filename and it is read-only. >> exec "def f(x): return f(x-1) if x else 1/0" >>> f(3) Traceback (most recent call last): File "", line 1, in File "", line 1, in f File "", line 1, in f File "", line 1, in f File "", line 1, in f ZeroDivisionError: integer division or modulo by zero If you make the compilation step explicit you can pass a filename: >>> exec compile("def f(x): return f(x-1) if x else 1/0", "yadda.py", "exec") >>> f(3) Traceback (most recent call last): File "", line 1, in File "yadda.py", line 1, in f File "yadda.py", line 1, in f File "yadda.py", line 1, in f File "yadda.py", line 1, in f ZeroDivisionError: integer division or modulo by zero Of course the offending line isn't quoted because there is no file "yadda.py" on my harddisk. But I can change that: >>> with open("yadda.py", "w") as out: print >> out, "I was fooled!" ... >>> f(3) Traceback (most recent call last): File "", line 1, in File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! ZeroDivisionError: integer division or modulo by zero Peter From johannes.black at gmail.com Thu Jul 22 13:47:26 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 22 Jul 2010 10:47:26 -0700 (PDT) Subject: pycrypto rsa string decryption Message-ID: I have an encrypted string and a key string (512 bits long). After studying the pycrypto documentation I still don't get how to read the private key and decrypt the string. - read the 512 bit string as private key - decrypt the encrypted string with rsa Any short code example how to do that? Greetings and thanks From burton at userful.com Thu Jul 22 13:48:38 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 22 Jul 2010 11:48:38 -0600 Subject: Improper Backtraces in Exec'd Code References: Message-ID: Peter Otten <__peter__ at web.de> writes: > If you make the compilation step explicit you can pass a filename: > >>>> exec compile("def f(x): return f(x-1) if x else 1/0", "yadda.py", > "exec") The works great. Problem solved. Thanks. -- Burton Samograd From Space998 at hotmail.com Thu Jul 22 15:25:29 2010 From: Space998 at hotmail.com (spudnik) Date: Thu, 22 Jul 2010 12:25:29 -0700 (PDT) Subject: trace of NANO THERMITE in WTC dust -- and almost no asbestos, because the scare stopped it from being used (and the buildings might not have collapsed, if it was) References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> <444e75c2-9b8d-4d56-9e4a-96b4b33c82c0@q35g2000yqn.googlegroups.com> Message-ID: <54a8c42f-1632-40cf-8eb0-fee14f32ea9b@k1g2000prl.googlegroups.com> I know what Thermite (TM) is, and I didn't even googol it. > Whats the qualification of you a faceless, spooooky bustard ? unlike > HONORABLE Professor Dr Steven Jones, who sacrificed his job and career > at BYU ?- Brigham Young University . Whats your sacrifice to show your > conviction from your ODIOUS and PUTRID mouth ? thus: if the entagnlement of two Newtonian rocks o'light, could traansmit information, then it would be some thing, but they are actually nor photons per se. thus: more folks should know about this quantumization! > I no longer accept redshift as a Doppler motion and > that would have huge consequence to a Tifft quantization. --BP's next bailout of Wall St. and "the City" (of London, gated community & financial district), or the last, if nothing is left of the USA. http://tarpley.net/online-books/george-bush-the-unauthorized-biography/chapter-8-the-permian-basin From hobson42 at gmaiil.com Thu Jul 22 16:25:56 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 22 Jul 2010 21:25:56 +0100 Subject: Visitor pattern and separating iteration In-Reply-To: References: Message-ID: <4C48A954.8060803@gmaiil.com> Hi Karsten, On 22/07/2010 12:03, Karsten Wutzke wrote: > What is it I'm missing? > I think you are making it more complicated than it really is. The visitor pattern is about bringing all the little bits that would otherwise be scattered all over many node classes into one visitor class. For code generation this means that all the code generation is done in your visitor class. For pretty-printing you have another visitor class. For code optimization a third visitor class. If there is only one sequence in which the nodes should be visited, then you can build it in to the nodes of the tree. If you need to visit your nodes in different orders you might be better off building a separated tree-walker class for each order. Thus you might have a post-order-walker for use with the code generating visitor, and a in-order-walker for a pretty-printing visitor. The optimizing walker may need to take different routes through the tree depending upon what it finds. For example, it may compute the value of the RHS of an assignment before computing the address of the LHS, so it can make better use of registers. Here the visitor class itself needs to do the walking. Regards Ian From breamoreboy at yahoo.co.uk Thu Jul 22 16:35:59 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 22 Jul 2010 21:35:59 +0100 Subject: Visitor pattern and separating iteration In-Reply-To: References: Message-ID: On 22/07/2010 12:03, Karsten Wutzke wrote: > Hello, > > I'm referring to > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9ba9816fe4fd55# > > I'm currently implementing what looks like a promising solution. I > have one problem though. My code generator isn't awfully complex, but > still I have problems trying to figure out where to put the iteration > code. Ideally, this should be in the classes the generator operates > on. Take the following Python code from my generator class: > > def handleMethod(self, method): > > # generate indent depending on object depth in tree > indent = self.generateIndent(method) > > # "public final" > modifierString = "" > > i = 0 > > for modifier in method.getModifiers(): > if i> 0: > modifierString += " " > modifierString += modifier > > i += 1 > > # "String firstName, String lastName" > parameterString = "" > > i = 0 > > for parameter in method.getParameters(): > if i> 0: > parameterString += ", " > parameterString += parameter.getType() + " " + > parameter.getName() > > i += 1 > > code = indentString + modifierString + " " + > (method.getReturnType() is None and "" or method.getReturnType() + " > ") + method.getName() + "(" + parameterString + ")" > > code += "\n{" > > # here the statements should go > > code += "\n}" > > return code > > The place where the statements should go would require an iteration > over the statements. When looking at other code samples, you often see > > def accept(self, visitor): > for child in self.getChildren(): > child.accept(visitor) > > visitor.visitMyClass(self) > > Now, I am wondering how separation of iteration and actual code > generation can be done in my situation. > > def accept(self, generator): > for child in self.getChildren(): > child.accept(generator) > > generator.handleMethod(self) > > I could of course add a parameter to handleMethod which would be the > generated code for the statements, but is that design of any good use > then? I'm rather tempted to ditch the idea of separating iteration and > code generation, but then the use of the visitor pattern becomes more > and more questionable. > > What is it I'm missing? > > Karsten I suggest you google for "python patterns alex martelli". From what I've read, he's forgotten more about Python and/or patterns than most of us will ever know. HTH. Mark Lawrence. From smallpox911 at gmail.com Thu Jul 22 17:40:50 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 22 Jul 2010 14:40:50 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Message-ID: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Stallman took over his EMACS Oracle's Larry Ellison, took over his SUN-JAVA Steve Jobs has Apple A free competitor to Oracle must be there to limit this fiend from taking over the world. There was VICIOUS propaganda against Microsoft's, Bill Gates. 1981 Gosling Emacs by James Gosling written in C; with "Mocklisp" as its extension language. / | 1983 / | / Unipress Emacs (6-may-83) / $395 commercial product. http://nighthacks.com/roller/jag/ \begin{quotation} When Sun folks get together and bullshit about their theories of why Sun died, the one that comes up most often is another one of these supplier disasters. Towards the end of the DotCom bubble, we introduced the UltraSPARC-II. Total killer product for large datacenters. We sold lots. But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Not very often, but often enough to be problems for customers. Sun customers were used to uptimes of years. The US-II was giving uptimes of weeks. We couldn't even figure out if it was a hardware problem or a software problem - Solaris had to be updated for the new machine, so it could have been a kernel problem. But nothing was reproducible. We'd get core dumps and spend hours pouring over them. Some were just crazy, showing values in registers that were simply impossible given the preceeding instructions. We tried everything. Replacing processor boards. Replacing backplanes. It was deeply random. It's very randomness suggested that maybe it was a physics problem: maybe it was alpha particles or cosmic rays. Maybe it was machines close to nuclear power plants. One site experiencing problems was near Fermilab. We actually mapped out failures geographically to see if they correlated to such particle sources. Nope. In desperation, a bright hardware engineer decided to measure the radioactivity of the systems themselves. Bingo! Particles! But from where? Much detailed scanning and it turned out that the packaging of the cache ram chips we were using was noticeably radioactive. We switched suppliers and the problem totally went away. After two years of tearing out hair out, we had a solution. \end{quotation} [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - for them ??? ] \begin{quotation} Despite being "blissfully unemployed", I've been remarkably busy. Some of my time has been taken up by job hunting, some by a fun geek project (more on that in a later post), but an awful lot has been taken up talking to people about life at Oracle. They need a place to vent, and I try to be a good listener. The exodus has been a thundering stampede. Pretty soon, all Larry will have left is an IP portfolio. Perhaps that's all he wanted: there's precious little evidence that he was interested in any of the people. Early on after quitting, I kept waking up in the middle of the night having nightmares about composing screeching blog entries. They would have been fun, but pointless. I decided that it was finally time to do some real relaxing and spend some quality time with a beach and an ocean - I figured I needed to do it before the poison that BP's been dumping kills much more. I had a great time. Got back last night. Feeling hugely better. \end{quotation} From smallpox911 at gmail.com Thu Jul 22 17:47:28 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 22 Jul 2010 14:47:28 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. References: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> Message-ID: <4ca2a6ca-4be2-4d74-ad16-79b701f034ac@q12g2000yqj.googlegroups.com> On Jul 22, 2:40?pm, small Pox wrote: > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > Stallman took over his EMACS > Oracle's Larry Ellison, took over his SUN-JAVA > Steve Jobs has Apple > > A free competitor to Oracle must be there to limit this fiend from > taking over the world. > > There was VICIOUS propaganda against Microsoft's, Bill Gates. > > 1981 ? ? ? ? ? ? ? Gosling Emacs > ? ? ? ? ? ? ? ? ? ?by James Gosling > ? ? ? ? ? ? ? ? ? ?written in C; with "Mocklisp" > ? ? ? ? ? ? ? ? ? ?as its extension language. > ? ? ? ? ? ? ? ? ? ? ? ?/ ? ? ?| > 1983 ? ? ? ? ? ? ? / ? ? ? | > ? ? ? ? ? ? ? ? ? ? ?/ ? Unipress Emacs (6-may-83) > ? ? ? ? ? ? ? ? ? ? / ? ?$395 commercial product. > > http://nighthacks.com/roller/jag/ > > \begin{quotation} > When Sun folks get together and bullshit about their theories of why > Sun died, the one that comes up most often is another one of these > supplier disasters. Towards the end of the DotCom bubble, we > introduced the UltraSPARC-II. Total killer product for large > datacenters. We sold lots. But then reports started coming in of odd > failures. Systems would crash strangely. We'd get crashes in > applications. All applications. Crashes in the kernel. Not very often, > but often enough to be problems for customers. Sun customers were used > to uptimes of years. The US-II was giving uptimes of weeks. We > couldn't even figure out if it was a hardware problem or a software > problem - Solaris had to be updated for the new machine, so it could > have been a kernel problem. But nothing was reproducible. We'd get > core dumps and spend hours pouring over them. Some were just crazy, > showing values in registers that were simply impossible given the > preceeding instructions. We tried everything. Replacing processor > boards. Replacing backplanes. It was deeply random. It's very > randomness suggested that maybe it was a physics problem: maybe it was > alpha particles or cosmic rays. Maybe it was machines close to nuclear > power plants. One site experiencing problems was near Fermilab. We > actually mapped out failures geographically to see if they correlated > to such particle sources. Nope. In desperation, a bright hardware > engineer decided to measure the radioactivity of the systems > themselves. Bingo! Particles! But from where? Much detailed scanning > and it turned out that the packaging of the cache ram chips we were > using was noticeably radioactive. We switched suppliers and the > problem totally went away. After two years of tearing out hair out, we > had a solution. > \end{quotation} > > [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - > for them ??? ] > > \begin{quotation} > Despite being "blissfully unemployed", I've been remarkably busy. Some > of my time has been taken up by job hunting, some by a fun geek > project (more on that in a later post), but an awful lot has been > taken up talking to people about life at Oracle. They need a place to > vent, and I try to be a good listener. The exodus has been a > thundering stampede. Pretty soon, all Larry will have left is an IP > portfolio. Perhaps that's all he wanted: there's precious little > evidence that he was interested in any of the people. Early on after > quitting, I kept waking up in the middle of the night having > nightmares about composing screeching blog entries. They would have > been fun, but pointless. I decided that it was finally time to do some > real relaxing and spend some quality time with a beach and an ocean - > I figured I needed to do it before the poison that BP's been dumping > kills much more. I had a great time. Got back last night. Feeling > hugely better. > \end{quotation} Watch the VIDEO Thou Shall WIN by DECEPTION - VICTOR OSTROVSKY Press TV-News Analysis-Israel Lebanon Spies-07-16-2010(Part1) http://vodpod.com/watch/4042625-press-tv-news-analysis-israel-lebanon-spies-07-16-2010part1 From nanothermite911fbibustards at gmail.com Thu Jul 22 18:07:55 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Thu, 22 Jul 2010 15:07:55 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. References: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> Message-ID: <2e05c1c5-cf8e-480e-9ed8-828739fe3f0e@r27g2000yqb.googlegroups.com> On Jul 22, 2:40?pm, small Pox wrote: > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > Stallman took over his EMACS > Oracle's Larry Ellison, took over his SUN-JAVA > Steve Jobs has Apple > > A free competitor to Oracle must be there to limit this fiend from > taking over the world. > > There was VICIOUS propaganda against Microsoft's, Bill Gates. > > 1981 ? ? ? ? ? ? ? Gosling Emacs > ? ? ? ? ? ? ? ? ? ?by James Gosling > ? ? ? ? ? ? ? ? ? ?written in C; with "Mocklisp" > ? ? ? ? ? ? ? ? ? ?as its extension language. > ? ? ? ? ? ? ? ? ? ? ? ?/ ? ? ?| > 1983 ? ? ? ? ? ? ? / ? ? ? | > ? ? ? ? ? ? ? ? ? ? ?/ ? Unipress Emacs (6-may-83) > ? ? ? ? ? ? ? ? ? ? / ? ?$395 commercial product. > > http://nighthacks.com/roller/jag/ > > \begin{quotation} > When Sun folks get together and bullshit about their theories of why > Sun died, the one that comes up most often is another one of these > supplier disasters. Towards the end of the DotCom bubble, we > introduced the UltraSPARC-II. Total killer product for large > datacenters. We sold lots. But then reports started coming in of odd > failures. Systems would crash strangely. We'd get crashes in > applications. All applications. Crashes in the kernel. Not very often, > but often enough to be problems for customers. Sun customers were used > to uptimes of years. The US-II was giving uptimes of weeks. We > couldn't even figure out if it was a hardware problem or a software > problem - Solaris had to be updated for the new machine, so it could > have been a kernel problem. But nothing was reproducible. We'd get > core dumps and spend hours pouring over them. Some were just crazy, > showing values in registers that were simply impossible given the > preceeding instructions. We tried everything. Replacing processor > boards. Replacing backplanes. It was deeply random. It's very > randomness suggested that maybe it was a physics problem: maybe it was > alpha particles or cosmic rays. Maybe it was machines close to nuclear > power plants. One site experiencing problems was near Fermilab. We > actually mapped out failures geographically to see if they correlated > to such particle sources. Nope. In desperation, a bright hardware > engineer decided to measure the radioactivity of the systems > themselves. Bingo! Particles! But from where? Much detailed scanning > and it turned out that the packaging of the cache ram chips we were > using was noticeably radioactive. We switched suppliers and the > problem totally went away. After two years of tearing out hair out, we > had a solution. > \end{quotation} > > [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - > for them ??? ] > > \begin{quotation} > Despite being "blissfully unemployed", I've been remarkably busy. Some > of my time has been taken up by job hunting, some by a fun geek > project (more on that in a later post), but an awful lot has been > taken up talking to people about life at Oracle. They need a place to > vent, and I try to be a good listener. The exodus has been a > thundering stampede. Pretty soon, all Larry will have left is an IP > portfolio. Perhaps that's all he wanted: there's precious little > evidence that he was interested in any of the people. Early on after > quitting, I kept waking up in the middle of the night having > nightmares about composing screeching blog entries. They would have > been fun, but pointless. I decided that it was finally time to do some > real relaxing and spend some quality time with a beach and an ocean - > I figured I needed to do it before the poison that BP's been dumping > kills much more. I had a great time. Got back last night. Feeling > hugely better. > \end{quotation} Watch the VIDEO Thou Shall WIN by DECEPTION - VICTOR OSTROVSKY Press TV-News Analysis-Israel Lebanon Spies-07-16-2010(Part1) http://vodpod.com/watch/4042625-press-tv-news-analysis-israel-lebanon-spies-07-16-2010part1 http://vodpod.com/watch/3996570-press-tv-news-analysis-us-nukes-for-israel-07-08-2010part2 ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY From tjreedy at udel.edu Thu Jul 22 18:25:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jul 2010 18:25:07 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/21/2010 6:56 PM, Daniel Stutzbach wrote: > On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy > wrote: > > These tests use random numbers with a constant, relatively high > density of 25%, which is favorable to radix sort. What if you do the > same test with a constant range of, say, 1000000000 (1 billion) or > even a trillion or quadrillion. Or how about sorting a thousand > 128bit ip6 addresses? Which wins for that? > blist switches to radix sort only if the keys contain only floats or > only integers that fit into a C long. If the integers get too big, it > reverts to timsort. > > When using a sort key, the decorate-sort-undecorate pattern requires > touching every object once before the sort. The check for a consistent > type is done inexpensively during the decorate phase. And it is pretty cheap even when there is no decorate phase. > Here's an example result with a density of only 1%, where the radix sort > is around 4 times as fast: > > otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = > [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' > 'y.sort(key=float)' > 100 loops, best of 3: 12.4 msec per loop > > otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s > 'import random' -s 'x = [random.randrange(10000*100) for i in > range(10000)]' 'y = blist(x)' 'y.sort(key=float)' > 100 loops, best of 3: 3.4 msec per loop > And a density of 0.01%: > > otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = > [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' > 'y.sort(key=float)' > 100 loops, best of 3: 12 msec per loop > > otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s > 'import random' -s 'x = [random.randrange(10000*10000) for i in > range(10000)]' 'y = blist(x)' 'y.sort(key=float)' > 100 loops, best of 3: 3.52 msec per loop Looks good so far. I would like to see that repeated all the way down to range(10) to make sure people doing millions of small sorts were not getting screwed. > list.sort is (near) linear for lists that are mostly ordered. I > think Tim's writeup about this in in the source. For instance, if > one extends a sorted with 1% random additions and resorts, list.sort > will skip the sorted part, sort the additions, and merge them back > in. Radix sort ignores pre-existing order. So either a lot of > comparitive profiling would be needed for auto-selection of sort > method, or it should be user selectable. > I've tested exactly that scenario. For already-ordered lists, radix > sort and timsort tie. Tim tested about 7 list structure scenarios with a range of lengths. If you post a patch, I would request that you do the same. Have you run a patched version against test_sort.py? I believe it mostly tests lists of small ints, so radix methods would mostly be switched in. If it were added and the switching were internal, new test cases would be needed to test test timsort. >> Does your radix sort meet the stability guarantee of list.sort? > Yes. Great. There is, of course, a test for that in the suite. -- Terry Jan Reedy From wherespythonmonks at gmail.com Thu Jul 22 18:34:11 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 22 Jul 2010 18:34:11 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4C3A0F79.8070502@ixokai.io> References: <4C3A0F79.8070502@ixokai.io> Message-ID: Okay -- so I promised that I would try the namespace mangling approach, and here's what I have come up with: Approach #1: Pass in the variables to be swapped as strings. (boring) >>> import sys >>> def swap(n1,n2): ... try: ... raise RuntimeException() ... except: ... e,b,t = sys.exc_info() ... ldict = t.tb_frame.f_back.f_locals ... t = ldict[n1]; ... ldict[n1] = ldict[n2] ... ldict[n2] = t ... >>> x = 'A' >>> y = 'B' >>> id(x) 47946650437696 >>> id(y) 47946649710192 >>> swap('x','y') >>> print id(x) 47946649710192 >>> print id(y) 47946650437696 >>> print x,y B A Approach #2: Allow the user to pass in arbitrary objects, takes the id, infer what the variable in by hashing all possible objects, and then apply the swap operation above. >>> def swap2(o1,o2): ... try: ... raise RuntimeException() ... except: ... e,b,t = sys.exc_info() ... ldict = t.tb_frame.f_back.f_locals ... iddict = dict( (id(v), k ) for k,v in ldict.items() ) ... # print id(o1), id(o2) ... n1 = iddict[id(o1)] ... n2 = iddict[id(o2)] ... t = ldict[n1]; ... ldict[n1] = ldict[n2] ... ldict[n2] = t ... >>> print x,y B A >>> swap2(x,y) >>> print x,y A B >>> Now, I want to make the above codes more "Pythonic" -- is there a way to: 1. Get the function's arguments from the perspective of the caller? def f(x): print "caller's view of x = %s" % callersview(x) Then, f(1+2+3) would yield: caller's view of x = 1 + 2 + 3 2. Is there a better way to loopup by id? I'm not very familiar with sys.exc_info, but creating the id->name hash each time seems like overkill. 3. Is there a reference on all the special variables, like __foo__? 4. Is there any work on deparsing (like Perl's deparse) lambda functions to inline algebra and get a performance gain? Thanks again for your input, W ( from Perl-hacker to Python Programmer ) On Sun, Jul 11, 2010 at 2:37 PM, Stephen Hansen wrote: > On 7/11/10 10:48 AM, wheres pythonmonks wrote: >> I'm an old Perl-hacker, and am trying to Dive in Python. ?I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>>> True and print "It is true!" > > Because print is a statement. Statements have to start lines. If you > want to do this, use a function-- in Python 2.6 either via "from > __future__ import print_function" or writing your own, even if its just > a very thing wrapper around the print statement. > >> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >> = 7; swap(x,y);" given x=7,y=3?? >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> ?tuples, and numbers) > > You can't do that*. Its not limited to any certain type of objects. You > can't manipulate calling scopes: if you really want to do that sort of > explicit namespace mangling, use dictionaries (or objects, really) as > the namespace to mangle and pass them around. > >> 3. ?Why might one want to store "strings" as "objects" in numpy >> arrays? ?(Maybe they wouldn't)? > > I don't use numpy. No idea. > >> 4. ?Is there a way for me to make some function-definitions explicitly >> module-local? > > In what sense? If you prepend them with an underscore, the function > won't be imported with "from x import *". You can also explicitly > control what is imported in that way with a module-level __all__ attribute. > > Now that won't stop someone from doing "import x" and > "x._your_private_function" but Python doesn't believe in enforicng > restrictions. > >> (Actually related to Q3 below: Is there a way to create an anonymous scope?) > > No. You can create a limited anonymous function with lambda, but note it > takes only an expression-- no statements in it. > >> 5. Is there a way for me to introduce a indention-scoped variables in python? >> See for example: http://evanjones.ca/python-pitfall-scope.html > > No. Python only has three scopes historically; local, global, and > builtin. Then post-2.2(ish, I forget) limited nested scoping -- but only > with nested functions, and you can't (until Python 3) re-bind variables > in outer scopes (though you can modify them if they are mutable objects). > > Python's scoping is very basic (we generally think this is a good thing; > others are never happy with it) and is not fully lexical scoped. > >> 6. ?Is there a Python Checker that enforces Strunk and White and is >> bad English grammar anti-python? ?(Only half joking) >> http://www.python.org/dev/peps/pep-0008/ > > Check out pylint and/or pychecker, which do various style-based > checking. If you're asking for something else, I can't pierce your > sarcasm to figure out what. > > -- > > ? Stephen Hansen > ? ... Also: Ixokai > ? ... Mail: me+list/python (AT) ixokai (DOT) io > ? ... Blog: http://meh.ixokai.io/ > > * Yes, I know its actually possible, to manipulate outer/calling scopes > with frame hacking. This is dangerous / bad / an implementation detail > that one should not rely on or use, generally speaking. If you need to > do this you're writing Java or Perl or C in Python, instead of writing > Python in Python, so are probably doing all kinds of things that are > slow / bad / dangerous / just not taking advantage of Python's strengths. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From breamoreboy at yahoo.co.uk Thu Jul 22 19:02:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 23 Jul 2010 00:02:52 +0100 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 22/07/2010 23:25, Terry Reedy wrote: > On 7/21/2010 6:56 PM, Daniel Stutzbach wrote: >> On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy > > wrote: >> >> These tests use random numbers with a constant, relatively high >> density of 25%, which is favorable to radix sort. What if you do the >> same test with a constant range of, say, 1000000000 (1 billion) or >> even a trillion or quadrillion. Or how about sorting a thousand >> 128bit ip6 addresses? Which wins for that? > >> blist switches to radix sort only if the keys contain only floats or >> only integers that fit into a C long. If the integers get too big, it >> reverts to timsort. >> >> When using a sort key, the decorate-sort-undecorate pattern requires >> touching every object once before the sort. The check for a consistent >> type is done inexpensively during the decorate phase. > > And it is pretty cheap even when there is no decorate phase. > >> Here's an example result with a density of only 1%, where the radix sort >> is around 4 times as fast: >> >> otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = >> [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' >> 'y.sort(key=float)' >> 100 loops, best of 3: 12.4 msec per loop >> >> otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s >> 'import random' -s 'x = [random.randrange(10000*100) for i in >> range(10000)]' 'y = blist(x)' 'y.sort(key=float)' >> 100 loops, best of 3: 3.4 msec per loop > >> And a density of 0.01%: >> >> otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = >> [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' >> 'y.sort(key=float)' >> 100 loops, best of 3: 12 msec per loop >> >> otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s >> 'import random' -s 'x = [random.randrange(10000*10000) for i in >> range(10000)]' 'y = blist(x)' 'y.sort(key=float)' >> 100 loops, best of 3: 3.52 msec per loop > > Looks good so far. I would like to see that repeated all the way down to > range(10) to make sure people doing millions of small sorts were not > getting screwed. > >> list.sort is (near) linear for lists that are mostly ordered. I >> think Tim's writeup about this in in the source. For instance, if >> one extends a sorted with 1% random additions and resorts, list.sort >> will skip the sorted part, sort the additions, and merge them back >> in. Radix sort ignores pre-existing order. So either a lot of >> comparitive profiling would be needed for auto-selection of sort >> method, or it should be user selectable. >> I've tested exactly that scenario. For already-ordered lists, radix >> sort and timsort tie. > > Tim tested about 7 list structure scenarios with a range of lengths. If > you post a patch, I would request that you do the same. > > Have you run a patched version against test_sort.py? I believe it mostly > tests lists of small ints, so radix methods would mostly be switched in. > > If it were added and the switching were internal, new test cases would > be needed to test test timsort. > >>> Does your radix sort meet the stability guarantee of list.sort? >> Yes. > > Great. There is, of course, a test for that in the suite. > Can I please book front row tickets for the shoot out between the reigning heavyweight champ Timbot and the challenger, the up and coming Danbot? :) Kindest regards. Mark Lawrence. From nyamatongwe+thunder at gmail.com Thu Jul 22 19:19:37 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 23 Jul 2010 09:19:37 +1000 Subject: Sun Grid Engine / NFS and Python shell execution question In-Reply-To: References: Message-ID: <7m42o.1390$FH2.1317@viwinnwfe02.internal.bigpond.com> J.B. Brown: > I believe the source of this problem is that os.popen() or os.system() > calls spawn subshells which then reference my shell resource files > (.zshrc, .cshrc, .bashrc, etc.). > But I don't see an alternative to os.popen{234} or os.system(). > os.exec*() cannot solve my problem, because it transfers execution to > that program and stops executing the script which called os.exec*(). Call fork then call exec from the new process. Search the web for "fork exec" to find examples in C. Neil From daniel at stutzbachenterprises.com Thu Jul 22 19:22:14 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 22 Jul 2010 18:22:14 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Thu, Jul 22, 2010 at 5:25 PM, Terry Reedy wrote: > Looks good so far. I would like to see that repeated all the way down to > range(10) to make sure people doing millions of small sorts were not getting > screwed. > I only use the radix sort for n > 40. :-) > Have you run a patched version against test_sort.py? I believe it mostly > tests lists of small ints, so radix methods would mostly be switched in. > For testing purposes, I maintain a private fork of Python where I've replaced the built-in list with blist. I then run Python's test suite as a way of testing blist. So, yes, all of the tests have been run. :-) However, since I only use radix for n > 40, many of the tests have not actually tested the radix sort. > If it were added and the switching were internal, new test cases would be > needed to test test timsort. That's a good point. It's tempting to add an undocumented parameter to blist.sort that selects the sorting algorithm to use, to make it make it easier to test multiple algorithms. There are probably several different ways to achieve a similar effect. Do you mind if we table that discussion until I actually have a patch? -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From guandalino at gmail.com Thu Jul 22 19:22:48 2010 From: guandalino at gmail.com (guandalino) Date: Thu, 22 Jul 2010 16:22:48 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) References: Message-ID: On 22 Lug, 01:13, Terry Reedy wrote: [cut] > > Any hint? > > Remove the offending fake url. This makes tests to pass, but I have concrete reasons to think that urllib2 is really broken on my system. Btw, a(nother) weird thing is that I wrote a standalone test file based on test_urllib2.py and the test that there failed now passes. import unittest, urllib2 class Test(unittest.TestCase): def runTest(self): h = urllib2.FileHandler() urls = ( "file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/ test/%40test_29416_tmp", "file:///file_does_not_exist.txt", "file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/ python2.7/test/@test_29416_tmp", "file://somerandomhost.ontheinternet.com/home/home/redt/ sandbox/2.7/lib/python2.7/test/@test_29416_tmp",) for url in urls: self.assertRaises(urllib2.URLError, h.file_open, urllib2.Request(url)) print "PASSED" PASSED PASSED PASSED PASSED <-- this doesn't pass in test_urllib2 because gaierror is raised instead of URLError. I'm going to file an issue on python's bug tracker. Just the last thing to be sure it's not my fault... My system already had Python installed system wide (2.5.2) and I did the new installation in my home directory. To "activate" the new interpreter I added /home/redt/ sandbox/2.7/bin as first element in PATH. PYTHONPATH is empty. python - V gives 2.7. Is it OK or new and old pythons step on each other's foot? Thanks again, best regards. From tjreedy at udel.edu Thu Jul 22 19:52:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jul 2010 19:52:10 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/22/2010 7:22 PM, Daniel Stutzbach wrote: > On Thu, Jul 22, 2010 at 5:25 PM, Terry Reedy That's a good point. It's tempting to add an undocumented parameter to > blist.sort that selects the sorting algorithm to use, to make it make it > easier to test multiple algorithms. There are probably several > different ways to achieve a similar effect. Do you mind if we table > that discussion until I actually have a patch? Definitely. That will not be my decision. Since you seem serious about this, I decided to give you a preview of the questions to expect, and suggest some to answer in your initial filing. Another sort of issue will be code maintainability. Two algorithms is potentially more problems than one. To me, that partly depends on how well factored the current code is. It would be best is rsort were a switch replacement for timsort after all preparations (such as decorate) were done. I will leave that for you to address when you file. And that is about all I can think of. -- Terry Jan Reedy From me+list/python at ixokai.io Thu Jul 22 19:59:02 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 22 Jul 2010 16:59:02 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4C48DB46.2070000@ixokai.io> On 7/22/10 3:34 PM, wheres pythonmonks wrote: > Now, I want to make the above codes more "Pythonic" -- is there a way to: > > 1. Get the function's arguments from the perspective of the caller? > > def f(x): > print "caller's view of x = %s" % callersview(x) > > Then, f(1+2+3) would yield: > caller's view of x = 1 + 2 + 3 No. You can use frame hacking to dig up the locals of the calling frame as you did (such a horrible abuse of the poor language :)), there's no way to determine with any accuracy what exactly they decided to pass into you to get 'x'. I.e., I'm pretty sure its impossible to tell the difference between: x = 3 f(x) And: x = 3 f(3) From within f()'s perspective. This kind of thing gets asked a lot when people don't understand Python's name binding and object passing characteristics and come from other languages. It especially surprises people sometimes to learn that: x = 30000 f(x) f(30000) That in this case, 'f' will receive two completely different objects-- different id's and all. And yet: x = 3 f(x) f(3) In this case, each call will receive the exact same object. > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. Do you mean given a certain 'id', look up what object it is? No there's no way to do that. An id in Python is just informational, and an implementation detail. The language doesn't provide any meaningful tools you can use with them. I mean there's gc.get_objects(), but that doesn't return everything. > 3. Is there a reference on all the special variables, like __foo__? http://docs.python.org/reference/datamodel.html > 4. Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? There's nothing like that which I'm aware of. You can use projects like numpy or cython to get performance gain in important areas. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From pavlovevidence at gmail.com Thu Jul 22 20:12:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jul 2010 17:12:59 -0700 (PDT) Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> Message-ID: <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> On Jul 22, 3:34?pm, wheres pythonmonks wrote: > Okay -- so I promised that I would try the namespace mangling > approach, and here's what I have come up with: > > Approach #1: ?Pass in the variables to be swapped as strings. ?(boring) > > >>> import sys > >>> def swap(n1,n2): > > ... ?try: > ... ? raise RuntimeException() > ... ?except: > ... ? e,b,t = sys.exc_info() > ... ?ldict = t.tb_frame.f_back.f_locals > ... ?t = ldict[n1]; > ... ?ldict[n1] = ldict[n2] > ... ?ldict[n2] = t > ...>>> x = 'A' > >>> y = 'B' > >>> id(x) > 47946650437696 > >>> id(y) > 47946649710192 > >>> swap('x','y') > >>> print id(x) > 47946649710192 > >>> print id(y) > 47946650437696 > >>> print x,y > > B A Have you tried calling this swap inside a function? I bet you haven't. def test(): x = "A" y = "B" swap("x","y") print x,y > Approach #2: ?Allow the user to pass in arbitrary objects, takes the > id, infer what the variable in by hashing all possible objects, and > then apply the swap operation above. > > >>> def swap2(o1,o2): > > ... ?try: > ... ? raise RuntimeException() > ... ?except: > ... ? e,b,t = sys.exc_info() > ... ?ldict = t.tb_frame.f_back.f_locals > ... ?iddict = dict( (id(v), k ) for k,v in ldict.items() ) > ... ?# print id(o1), id(o2) > ... ?n1 = iddict[id(o1)] > ... ?n2 = iddict[id(o2)] > ... ?t = ldict[n1]; > ... ?ldict[n1] = ldict[n2] > ... ?ldict[n2] = t > ... > > >>> print x,y > B A > >>> swap2(x,y) > >>> print x,y > A B Same question. > Now, I want to make the above codes more "Pythonic" It's simply not possible (let alone Pythonic), in general, to rebind variables in the namespace of the caller. You were able to do it for a very limited circumstance, when the calling namespace was module-level. It doesn't work when the calling namespace is a function. This is true in Python 2 and 3. IMO, even if it could work, the very act of rebinding variables in another namespace is unPythonic. About the only time I've resorted to it is some metaprogramming tasks, and even then I give the functions that do it very explicit names, and I still feel dirty. > -- is there a way to: > > 1. ?Get the function's arguments from the perspective of the caller? > > def f(x): > ? print "caller's view of x = %s" % callersview(x) > > Then, f(1+2+3) would yield: > caller's view of x = 1 + 2 + 3 Nope, other than inspecting the caller's frame. > 2. ?Is there a better way to loopup by id? ?I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. Looking up by id is a bad idea in general. Objects associated with an id can be destroyed, and id be reused. So if you're storing an id, by the time you get to it it could be a different object, or an object that no longer exists. > 3. ?Is there a reference on all the special variables, like __foo__? Python Language Reference > 4. ?Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? psyco (q.g.) might help, not sure if it'll help much for lambdas, though. > Thanks again for your input, > > W > > ( from Perl-hacker to Python Programmer ) No offense, but you seem like you're still tying to be a hacker. If that's what you want, fine, but generally speaking (and particularly for Python), you are going to have a better experience if you do it the language's way. And just to throw this out there, based on your questions I think it's possible that Ruby would fit your style better. (It lets you play fast and loose with namespaces and code blocks and such.) Carl Banks From fabiofz at gmail.com Thu Jul 22 20:47:51 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 22 Jul 2010 21:47:51 -0300 Subject: Pydev 1.6.0 Released In-Reply-To: References: Message-ID: > > The supposed feature to start a console in which the contents of the > current editor window are automatically "exec"ed /available still > doesn't work for me. > > I'm talking about this: > http://www.pydev.org/manual_adv_interactive_console.html > > Pressing Ctrl-Alt-Enter, a interactive console opens but my class > defined in the editor window is not available. The first time Ctrl-Alt-Enter is used, it should open the console, if you want to make the execfile, you have to do Ctrl-Alt-Enter with a console already open. Cheers, Fabio From domingo.aguilera at gmail.com Thu Jul 22 20:57:32 2010 From: domingo.aguilera at gmail.com (batok) Date: Thu, 22 Jul 2010 17:57:32 -0700 (PDT) Subject: Brief guide to using virtualenv and wxpython Message-ID: This Brief guide to using virtualenv with wxpython , written with sphinx may be helpful for you. If your dev platform is mac os x. The documented process is about python 2.7 , wxpython 2.8.11 and virtualenv. http://bit.ly/bwdWCR From navkirats at gmail.com Thu Jul 22 21:30:11 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Fri, 23 Jul 2010 07:00:11 +0530 Subject: Sending HTTP headers via plain sockets Message-ID: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> Hi Guys, I am very new to python and I am trying to send HTTP headers for redirection using sockets in python 3, but in vain. If I use the meta tag REFRESH method the redirection works. Please advise what I am missing, below is the snippet of my code: hostsock is the socket object print('Redirecting client') hostsock.send("""HTTP/1.1 301 Moved Permanently Location: http://www.example.com"") I have been up all night trying to figure this one out : ( I would be grateful if someone could point me in the right direction Regards, Nav From navkirats at gmail.com Thu Jul 22 22:26:49 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Fri, 23 Jul 2010 07:56:49 +0530 Subject: Sending HTTP headers via plain sockets In-Reply-To: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> References: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> Message-ID: <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> Aaah figured it out...!! It was elementary, I was lacking the carriage return and line feed characters at the end of the status and header line. Here is how I solved it: hostsock.send(b'HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.example.com\r\n' ) Regards, Nav On 23-Jul-2010, at 7:00 AM, Navkirat Singh wrote: > Hi Guys, > > I am very new to python and I am trying to send HTTP headers for > redirection using sockets in python 3, but in vain. If I use the > meta tag REFRESH method the redirection works. Please advise what I > am missing, below is the snippet of my code: > > hostsock is the socket object > > > print('Redirecting client') > hostsock.send("""HTTP/1.1 301 Moved Permanently > Location: http://www.example.com"") > > > I have been up all night trying to figure this one out : ( I would > be grateful if someone could point me in the right direction > > Regards, > Nav From python at mrabarnett.plus.com Thu Jul 22 22:33:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Jul 2010 03:33:34 +0100 Subject: Sending HTTP headers via plain sockets In-Reply-To: <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> References: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> Message-ID: <4C48FF7E.3080307@mrabarnett.plus.com> Navkirat Singh wrote: > Aaah figured it out...!! > > It was elementary, I was lacking the carriage return and line feed > characters at the end of the status and header line. Here is how I > solved it: > > hostsock.send(b'HTTP/1.1 301 Moved Permanently\r\nLocation: > http://www.example.com\r\n') > > Regards, > Nav > You might want to note that the .send method doesn't guarantee to send all the bytes, so you might want to use .sendall instead (it's in the documentation). > On 23-Jul-2010, at 7:00 AM, Navkirat Singh wrote: > >> Hi Guys, >> >> I am very new to python and I am trying to send HTTP headers for >> redirection using sockets in python 3, but in vain. If I use the meta >> tag REFRESH method the redirection works. Please advise what I am >> missing, below is the snippet of my code: >> >> hostsock is the socket object >> >> >> print('Redirecting client') >> hostsock.send("""HTTP/1.1 301 Moved Permanently >> Location: http://www.example.com"") >> >> >> I have been up all night trying to figure this one out : ( I would be >> grateful if someone could point me in the right direction >> >> Regards, >> Nav > From wherespythonmonks at gmail.com Thu Jul 22 22:47:11 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 22 Jul 2010 22:47:11 -0400 Subject: Easy questions from a python beginner In-Reply-To: <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: Thanks for pointing out that swap (and my swap2) don't work everywhere -- is there a way to get it to work inside functions? "No offense, but you seem like you're still tying to be a hacker. If that's what you want, fine, but generally speaking (and particularly for Python), you are going to have a better experience if you do it the language's way." None taken, but I always think that it is the language's job to express my thoughts... I don't like to think that my thoughts are somehow constrained by the language. The truth is that I don't intend to use these approaches in anything serious. However, I've been known to do some metaprogramming from time to time. In a recent application, I pass in a list of callables (lambdas) to be evaluated repeatedly. Clearly, a superior solution is to pass a single lambda that returns a list. [Less function call dispatches] However, it might be more efficient to avoid the function call overhead completely and pass-in a string which is substituted into a string code block, compiled, and executed. W On Thu, Jul 22, 2010 at 8:12 PM, Carl Banks wrote: > On Jul 22, 3:34?pm, wheres pythonmonks > wrote: >> Okay -- so I promised that I would try the namespace mangling >> approach, and here's what I have come up with: >> >> Approach #1: ?Pass in the variables to be swapped as strings. ?(boring) >> >> >>> import sys >> >>> def swap(n1,n2): >> >> ... ?try: >> ... ? raise RuntimeException() >> ... ?except: >> ... ? e,b,t = sys.exc_info() >> ... ?ldict = t.tb_frame.f_back.f_locals >> ... ?t = ldict[n1]; >> ... ?ldict[n1] = ldict[n2] >> ... ?ldict[n2] = t >> ...>>> x = 'A' >> >>> y = 'B' >> >>> id(x) >> 47946650437696 >> >>> id(y) >> 47946649710192 >> >>> swap('x','y') >> >>> print id(x) >> 47946649710192 >> >>> print id(y) >> 47946650437696 >> >>> print x,y >> >> B A > > Have you tried calling this swap inside a function? ?I bet you > haven't. > > def test(): > ? ?x = "A" > ? ?y = "B" > ? ?swap("x","y") > ? ?print x,y > > >> Approach #2: ?Allow the user to pass in arbitrary objects, takes the >> id, infer what the variable in by hashing all possible objects, and >> then apply the swap operation above. >> >> >>> def swap2(o1,o2): >> >> ... ?try: >> ... ? raise RuntimeException() >> ... ?except: >> ... ? e,b,t = sys.exc_info() >> ... ?ldict = t.tb_frame.f_back.f_locals >> ... ?iddict = dict( (id(v), k ) for k,v in ldict.items() ) >> ... ?# print id(o1), id(o2) >> ... ?n1 = iddict[id(o1)] >> ... ?n2 = iddict[id(o2)] >> ... ?t = ldict[n1]; >> ... ?ldict[n1] = ldict[n2] >> ... ?ldict[n2] = t >> ... >> >> >>> print x,y >> B A >> >>> swap2(x,y) >> >>> print x,y >> A B > > Same question. > > >> Now, I want to make the above codes more "Pythonic" > > It's simply not possible (let alone Pythonic), in general, to rebind > variables in the namespace of the caller. > > You were able to do it for a very limited circumstance, when the > calling namespace was module-level. ?It doesn't work when the calling > namespace is a function. ?This is true in Python 2 and 3. > > IMO, even if it could work, the very act of rebinding variables in > another namespace is unPythonic. ?About the only time I've resorted to > it is some metaprogramming tasks, and even then I give the functions > that do it very explicit names, and I still feel dirty. > > >> -- is there a way to: >> >> 1. ?Get the function's arguments from the perspective of the caller? >> >> def f(x): >> ? print "caller's view of x = %s" % callersview(x) >> >> Then, f(1+2+3) would yield: >> caller's view of x = 1 + 2 + 3 > > Nope, other than inspecting the caller's frame. > >> 2. ?Is there a better way to loopup by id? ?I'm not very familiar with >> sys.exc_info, but creating the id->name hash each time seems like >> overkill. > > Looking up by id is a bad idea in general. ?Objects associated with an > id can be destroyed, and id be reused. ?So if you're storing an id, by > the time you get to it it could be a different object, or an object > that no longer exists. > > >> 3. ?Is there a reference on all the special variables, like __foo__? > > Python Language Reference > > >> 4. ?Is there any work on deparsing (like Perl's deparse) lambda >> functions to inline algebra and get a performance gain? > > psyco (q.g.) might help, not sure if it'll help much for lambdas, > though. > >> Thanks again for your input, >> >> W >> >> ( from Perl-hacker to Python Programmer ) > > No offense, but you seem like you're still tying to be a hacker. ?If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way. > > And just to throw this out there, based on your questions I think it's > possible that Ruby would fit your style better. ?(It lets you play > fast and loose with namespaces and code blocks and such.) > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > From hellomarch at gmail.com Thu Jul 22 23:18:43 2010 From: hellomarch at gmail.com (march) Date: Thu, 22 Jul 2010 20:18:43 -0700 (PDT) Subject: Where is the man page of python library Message-ID: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> Hi, guys. As a regular user of python, I am often annoyed by the fact that the official python docementation is too short and too simple to satisfy my requirement. While working with socket, I want to know every detail about every API. I can easilly achieve that by reading man page if the language is C. But It seems that the Python story is different. For the interface recv(), all I got is only three sentences. " Receive data from the socket. The return value is a string representing the data received. The maximum amount of data to be received at once is specified by bufsize. " http://docs.python.org/library/socket.html#socket.socket.recv What if the call fail? What if the peer close the socket? What is the difference between blocking and non-blocking socket? How could I get the errno or exception? All the answers are "No comment". I hate this documentation! guys, where could I turn to for help? Thanks in advance. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 22 23:45:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 03:45:22 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4c491052$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 18:34:11 -0400, wheres pythonmonks wrote: > Okay -- so I promised that I would try the namespace mangling approach, > and here's what I have come up with: > > Approach #1: Pass in the variables to be swapped as strings. (boring) Boring and slow and stupid. It makes an interesting trick to prove it can (almost) be done, but for production use? No way. There is nothing that *needs* call-by-reference that can't be done just as effectively using a slightly different approach. This approach also has the fatal flaw that not all objects have names, or have only one name. In Python, objects are often anonymous, and the standard Python idiom for swapping works fine for them: a = [1, 2, 3, "d", 5] b = ["a", "b", "c", 4, "e"] a[3], b[3] = b[3], a[3] I expect your hack to choke and die if you try swapping anonymous objects. [snip successful test of swapping using named globals] As Carl already pointed out, this doesn't work outside of the global scope. This demonstrates an interesting lesson re testing. It's not enough to test these hacks with names in the global scope. You also need to test them with names in a local and nested scope, and in classes. [...] > Now, I want to make the above codes more "Pythonic" The way to make them more Pythonic is to avoid them like the plague. One of the differences in philosophy between Perl and Python is that Python doesn't approve of doing things just because you can. There is very little interest in or respect given to hacking Python. We're programmers, not hackers, and we look for the most simple way to do things, not the gnarliest or trickiest or least obvious way. (Any yet, as a general rule, neither does Python particular get in your way. We have a saying: we're all adults here, if you want to shoot yourself in the foot, go right ahead.) Occasionally, *very* occasionally, that makes it hard to do something that would be simple in another language. But much rarer than you might think, and a lot of popular programming idioms are work-arounds that are simply not needed in Python. E.g. call-by-reference itself was a work- around to prevent unnecessary copying of large data structures like arrays in languages like Algol and Pascal (or so I understand). When Java guys come here and start asking how to implement design patterns in Python, 9 times out of 10 the answer is "you don't need it" rather than "you can't do it". It's not quite true that we consider "hack" to be a pejorative, we're certainly true of the positive uses of the word. But as a general rule the Python community looks rather askance at anything that might be described as a hack. We're far more likely to describe something as a dirty hack than a cool, nifty or amazing hack. It's not true, as some folks say, that there is "only one way to do it" in Python. But the Python ideal is for there to be "one obvious way to do it". If there's an obvious way, why would you look for an obscure, tricky hack? You better have a good reason for not using the obvious way, because writing the code is the *smallest* part of the job. You need to test it, and debug it, and maintain it, and they're all much, much harder. > is there a way to: > > 1. Get the function's arguments from the perspective of the caller? I don't understand the question. If the caller passes arg = [1,2,3], then both the caller and the called function agree that the argument is the list [1,2,3]. Both caller and callee see the same list. It would be a pretty strange programming language where the called function saw something different from what the caller passed... > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. No. > 3. Is there a reference on all the special variables, like __foo__? If you're talking about "magic methods" and special attributes, like obj.__len__, then you should read this: http://docs.python.org/reference/datamodel.html This may also be helpful: http://www.ironpythoninaction.com/magic-methods.html If you're talking about special globals like __name__, I don't think there are any others. __name__ is (confusingly) documented here: http://docs.python.org/library/__main__.html > 4. Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? No. How would you do that? If I have something like this: def my_func(arg): return some_class(1, 2, 3, callback=lambda x: arg.method(x)) how would you inline that? *Where* would you inline that? Perhaps you're thinking that lambdas are commonly used like this: def my_func(args): f = lambda a, b, c: 3*a + 4*b -2*c results = [] for x in args: results.append(f(2, x, 3)) results.append(f(x, x**2, x**3) return results then, yes, that lambda could be inlined. But that's a rare and uncommon use for lambdas, and some would say unpythonic. Even if you could inline it, CPython isn't big on micro-optimizations. It's generally considered that the extra complexity and risk of bugs isn't worth the tiny performance gain. Simplicity itself is a virtue, and many optimizations tend to be anything but simple, if not dirty hacks. -- Steven From f2h2d2 at gmail.com Thu Jul 22 23:51:43 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Thu, 22 Jul 2010 20:51:43 -0700 (PDT) Subject: TOLERANCE IN ISLAM Message-ID: <2839481a-d0f3-4433-b95e-070840d6275a@t2g2000yqe.googlegroups.com> TOLERANCE IN ISLAM http://www.islamhouse.com/s/9661 Tolerance In Islam TOLERANCE IN ISLAM In Spain under the Umayyads and in Baghdad under the Abbasid Khalifas, Christians and Jews, equally with Muslims, were admitted to the Schools and universities - not only that, but were boarded and lodged in hostels at the cost of the state. When the Moors were driven out of Spain, the Christian conquerors held a terrific persecution of the Jews. Those who were fortunate enough to escape fled, some of them to Morocco and many hundreds to the Turkish empire, where their descendants still live in separate communities, and still speak among themselves an antiquated form of Spanish. The Muslim empire was a refuge for all those who fled from persecution by the Inquisition. The Western Christians, till the arrival of the Encyclopaedists in the eighteenth century, did not know and did not care to know, what the Muslim believed, nor did the Western Christian seek to know the views of Eastern Christians with regard to them. The Christian Church was already split in two, and in the end, it came to such a pass that the Eastern Christians, as Gibbon shows, preferred Muslim rule, which allowed them to practice their own form of religion and adhere to their peculiar dogmas, to the rule of fellow Christians who would have made them Roman Catholics or wiped them out. For the Muslims, Judaism, Christianity and Islam are but three forms of one religion, which, in its original purity, was the religion of Abraham: Al-Islam, that perfect Self-Surrender to the Will of God, which is the basis of Theocracy. The Jews, in their religion, after Moses, limited God's mercy to their chosen nation and thought of His kingdom as the dominion of their race. Even Christ himself, as several of his sayings show, declared that he was sent only to the lost sheep of the House of Israel and seemed to regard his mission as to the Hebrews only; and it was only after a special vision vouchsafed to St. Peter that his followers in after days considered themselves authorized to preach the Gospel to the Gentiles. The Christians limited God?s mercy to those who believed certain dogmas. Every one who failed to hold the dogmas was an outcast or a miscreant, to be persecuted for his or her soul?s good. In Islam only is manifest the real nature of the Kingdom of God. The two verses (2:255-256) of the Qur?an are supplementary. Where there is that realization of the majesty and dominion of Allah (SWT), there is no compulsion in religion. Men choose their path - allegiance or opposition - and it is sufficient punishment for those who oppose that they draw further and further away from the light of truth. In Egypt the Copts were on terms of closest friendship with the Muslims in the first centuries of the Muslim conquest, and they are on terms at closest friendship with the Muslims at the present day. In Syria the various Christian communities lived on terms of closest friendship with the Muslims in the first centuries of the Muslim conquest, and they are on terms of closest friendship with the Muslims at the present day, openly preferring Muslim domination to a foreign yoke.... >From the expulsion of the Moriscos dates the degradation and decline of Spain. San Fernando was really wiser and more patriotic in his tolerance to conquered Seville, Murcia and Toledo than was the later king who, under the guise of Holy warfare, captured Grenada and let the Inquisition work its will upon the Muslims and the Jews. And the modern Balkan States and Greece are born under a curse. It may even prove that the degradation and decline of European civilization will be dated from the day when so-called civilized statesmen agreed to the inhuman policy of Czarist Russia and gave their sanction to the crude fanaticism of the Russian Church. There is no doubt but that, in the eyes of history, religious toleration is the highest evidence of culture in a people. Let no Muslim, when looking on the ruin of the Muslim realm which was compassed through the agency of those very peoples whom the Muslims had tolerated and protected through the centuries when Western Europe thought it a religious duty to exterminate or forcibly convert all peoples of another faith than theirs - let no Muslim, seeing this, imagine that toleration is a weakness in Islam. It is the greatest strength of Islam because it is the attitude of truth. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 00:07:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 04:07:20 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> Message-ID: <4c491577$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > Hi, guys. > > As a regular user of python, I am often annoyed by the fact that the > official python docementation is too short and too simple to satisfy my > requirement. Python is a volunteer effort. If the docs don't suit your requirements, we're grateful for patches. > While working with socket, I want to know every detail about every API. > I can easilly achieve that by reading man page if the language is C. But > It seems that the Python story is different. Python is open source. Where the documentation is silent, the ultimate authority is the source code. Particularly if the code is a thin wrapper around the C library, which I expect (but don't know for sure) the socket code will be. > For the interface recv(), all I got is only three sentences. " > Receive data from the socket. The return value is a string representing > the data received. The maximum amount of data to be received at once is > specified by bufsize. " > http://docs.python.org/library/socket.html#socket.socket.recv > > What if the call fail? You will get an exception, just like the page says: All errors raise exceptions. The normal exceptions for invalid argument types and out-of-memory conditions can be raised; errors related to socket or address semantics raise the error socket.error. > What if the peer close the socket? You will get an exception, just like the Fine Manual says. > What is the > difference between blocking and non-blocking socket? Python isn't a tutor for basic programming concepts like sockets. That's what Google is for :) But having said that, the documentation does explain the difference: In non-blocking mode, if a recv() call doesn?t find any data, or if a send() call can?t immediately dispose of the data, a error exception is raised; in blocking mode, the calls block until they can proceed. http://docs.python.org/library/socket.html#socket.socket.setblocking > How could I get the errno or exception? You get the exception the same way you get *every* exception: by catching it with a try...except block. If you don't know that, you need to learn the basics and not blame the documentation. Untested, but this probably will work: try: something_involving_sockets() except socket.error, e: if len(e.args) == 1: print "Error message is:", e.args[0] else: print "errno =", e.args[0] print "Error message is:", e.args[1] > All the answers are "No comment". > > I hate this documentation! Don't blame the documentation for your failure to read it. It's true that it could be improved, but most of your questions were answered by the page you linked to. -- Steven From me+list/python at ixokai.io Fri Jul 23 00:23:05 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 22 Jul 2010 21:23:05 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4C491929.3020108@ixokai.io> On 7/22/10 7:47 PM, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? > > "No offense, but you seem like you're still tying to be a hacker. If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way." > > None taken, but I always think that it is the language's job to > express my thoughts... I don't like to think that my thoughts are > somehow constrained by the language. The thing is, every language is adept at expressing different kinds of abstractions. They have different goals and ways of encouraging certain types of solutions while discouraging (and many times simply not even trying to offer support for) others: you're going up against those 'discouraged' very, very hard-- and you're going to hit a wall :) The Python language does constrain your expressiveness in these sorts of areas, and there's no way around it. If that doesn't suit you-- you're free to use another language which works better to how your brain works. Ruby actually might be a very good suggestion. I don't mean this as a 'Deal with it or f- off, loser' statement. :) I mean that Python uses a very simple model in how it handles namespaces, calling and similar -- a lot of what seems completely natural to express in other languages is either slow, convoluted, complicated or flatly impossible here. On purpose. But, for those things that aren't expressed easily in Python, there's almost always a *different way* to express the actual need and intention-- in a way that is elegant and direct, in Python. You can't do it the other way "Pythonic", because "Pythonic" is to *not* do it that way. To not do things like try to treat variables as if they had box-like-behavior. > The truth is that I don't intend to use these approaches in anything > serious. However, I've been known to do some metaprogramming from > time to time. Depending on how you define "metaprogramming", Python is pretty notoriously ill-suited towards the task (more, its basically considered a feature it doesn't let you go there) -- or, it allows you to do vast amounts of stuff with its few dark magic hooks. I've never had a satisfying definition of metaprogramming that more then 50% of any group agree with, so I'm not sure which you're looking for. :) Python allows you to easily override nearly all operations and interactions between objects, construct classes, instances and such at runtime and modify them at any time. If metaprogramming is this to you, basically runtime tweaking and modification of classes types objects and the like, Python's good to go. But! What it doesn't let you do is get clever with syntax and write a sort of "simplified" or domain specific language to achieve certain sorts of repetitive tasks quickly. You always end up writing normal Python that looks like all other Python. You just might have a few more __methods__ and learn some dark magic like metaclasses and descriptors and decorators. (Not that -all- uses of such are dark magic, but when you start combining those your code can start to resemble a magic spell doing unholy things-- like my library with classes that have argument-based method overloading, so x.test("hi") and x.test("hi", 2) call two totally different functions. Not that I'll ever admit to having written the beast, nor that I actually did more then use it for pure proof of concept, and neither shall I willingly ever show anyone the monstrosity). > In a recent application, I pass in a list of callables (lambdas) to be > evaluated repeatedly. > Clearly, a superior solution is to pass a single lambda that returns a > list. [Less function call dispatches] > However, it might be more efficient to avoid the function call > overhead completely and pass-in a string which is substituted into a > string code block, compiled, and executed. This is the kind of "metaprogramming" where Python says nyet, that first kind I mentioned about being Notoriously Ill Suited. You can do things like compile code dynamically, generate up bytecode even, but it'll never be more efficient. Use a generator instead. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From hellomarch at gmail.com Fri Jul 23 01:24:39 2010 From: hellomarch at gmail.com (march) Date: Thu, 22 Jul 2010 22:24:39 -0700 (PDT) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Steven, thank you for your reply. It is true that I didn't read the document with enough carefulness. some of my questions are answered in the page I post the link of. Some are not. But the documentation is poor. You need to read throughout the entire page, hoping to find what you need about one single API, and you might fail. I don't think "Python is a volunteer effort" can justify the poor documentation. Linux, glibc are based on volunteer effort too, and they has good documentations. I am not blaming those volunteers who devote their precious time to this language. It will be good if the python communities get more people who like to write documentation. Anyway, thank you again. On Jul 23, 12:07?pm, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > > Hi, guys. > > > As a regular user of python, I am often annoyed by the fact that the > > official python docementation is too short and too simple to satisfy my > > requirement. > > Python is a volunteer effort. If the docs don't suit your requirements, > we're grateful for patches. > > > While working with socket, I want to know every detail about every API. > > I can easilly achieve that by reading man page if the language is C. But > > It seems that the Python story is different. > > Python is open source. Where the documentation is silent, the ultimate > authority is the source code. Particularly if the code is a thin wrapper > around the C library, which I expect (but don't know for sure) the socket > code will be. > > > For the interface recv(), all I got is only three sentences. " > > Receive data from the socket. The return value is a string representing > > the data received. The maximum amount of data to be received at once is > > specified by bufsize. " > >http://docs.python.org/library/socket.html#socket.socket.recv > > > What if the call fail? > > You will get an exception, just like the page says: > > ? ? All errors raise exceptions. The normal exceptions for > ? ? invalid argument types and out-of-memory conditions can be > ? ? raised; errors related to socket or address semantics raise > ? ? the error socket.error. > > > What if the peer close the socket? > > You will get an exception, just like the Fine Manual says. > > > What is the > > difference between blocking and non-blocking socket? > > Python isn't a tutor for basic programming concepts like sockets. That's > what Google is for :) > > But having said that, the documentation does explain the difference: > > ? ? In non-blocking mode, if a recv() call doesn?t find any data, > ? ? or if a send() call can?t immediately dispose of the data, > ? ? a error exception is raised; in blocking mode, the calls block > ? ? until they can proceed. > > http://docs.python.org/library/socket.html#socket.socket.setblocking > > > How could I get the errno or exception? > > You get the exception the same way you get *every* exception: by catching > it with a try...except block. If you don't know that, you need to learn > the basics and not blame the documentation. > > Untested, but this probably will work: > > try: > ? ? something_involving_sockets() > except socket.error, e: > ? ? if len(e.args) == 1: > ? ? ? ? print "Error message is:", e.args[0] > ? ? else: > ? ? ? ? print "errno =", e.args[0] > ? ? ? ? print "Error message is:", e.args[1] > > > All the answers are "No comment". > > > I hate this documentation! > > Don't blame the documentation for your failure to read it. It's true that > it could be improved, but most of your questions were answered by the > page you linked to. > > -- > Steven From timr at probo.com Fri Jul 23 01:44:55 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 22 Jul 2010 22:44:55 -0700 Subject: detect endianness of a binary with python References: <4C46EEB8.6070702@keymile.com> Message-ID: Holger brunck wrote: > >We are creating inside our buildsystem for an embedded system a cram filesystem >image. Later on inside our build process we have to check the endianness, >because it could be Little Endian or big endian (arm or ppc). > >The output of the "file" tool is for a little endian cramfs image: >: Linux Compressed ROM File System data, little endian size 1875968 >version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > >It would be possible to execute >ret = os.system("file | grep "little endian") >and evaluate the return code. I wouldn't use os.system with grep and evaluate the return code. Instead I'd use subprocess.Popen("file ") and read the text output of the commdn directly. By parsing that string, I can extract all kinds of interesting information. That is an entirely Unix-like way of doing things. Don't reinvent the wheel when there's a tool that already does what you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From daniel at stutzbachenterprises.com Fri Jul 23 01:52:28 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 23 Jul 2010 00:52:28 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Thu, Jul 22, 2010 at 6:52 PM, Terry Reedy wrote: > Another sort of issue will be code maintainability. Two algorithms is > potentially more problems than one. To me, that partly depends on how well > factored the current code is. > Two algorithms is more code than one algorithm. No way around that. :-) Radix sort is a relatively simple sorting algorithm, so the extra complexity is not too bad. Once I have a patch ready, others can decide if the additional complexity is worth the performance boost. > It would be best is rsort were a switch replacement for timsort after all > preparations (such as decorate) were done. > Yes, that's pretty much what I have in mind. In pseudo-code: sort: decorate() if all_correct_type and n > 40: radix_sort() else timsort() undecorate() > And that is about all I can think of. Thank you for the thoughts. I appreciate them! -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Jul 23 02:26:57 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jul 2010 23:26:57 -0700 (PDT) Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: On Jul 22, 7:47?pm, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? Impossible without hacking the interpreter. > "No offense, but you seem like you're still tying to be a hacker. ?If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way." > > None taken, but I always think that it is the language's job to > express my thoughts... I don't. In fact whenever I investigate new languages I make an effort to accommodate its thinking, I find I learn a lot more than I would by it into my preconceived thinking. YMMV. >?I don't like to think that my thoughts are > somehow constrained by the language. And yet your previous thoughts seem oddly constrained by Perl.... If you really want a language that can accommodate any thought you could possibly have, you should check out Lisp. (defmacro swap (a b) '(let ((t1 ,a) (t2 ,b)) (setq ,b t1) (setq ,a t2))) hygiene-left-as-an-exercise-ly yr's, Carl Banks From girish.cfc at gmail.com Fri Jul 23 02:54:23 2010 From: girish.cfc at gmail.com (Girish) Date: Thu, 22 Jul 2010 23:54:23 -0700 (PDT) Subject: Change Encoding in Py 2.5 Message-ID: Hello, Is ter a way to change default encoding in py 2.5 ? Thanks, Girish.. From stefan_ml at behnel.de Fri Jul 23 03:18:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jul 2010 09:18:47 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: References: Message-ID: Girish, 23.07.2010 08:54: > Is ter a way to change default encoding in py 2.5 ? Yes, but it's highly discouraged. If you tell us why you want to do it, we may be able to point to a better way to get what you want. Stefan From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 03:19:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 07:19:38 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: <4c494289$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 22:24:39 -0700, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. some > of my questions are answered in the page I post the link of. Some are > not. > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. Of course the documentation can be improved. Nobody thinks it is perfect. But the Python documentation is actually pretty good compared to a lot of things out there. Perhaps you're spoilt from reading first class documentation and haven't had to struggle with fifteenth class documentation. > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on volunteer effort too, and they > has good documentations. You missed my point. Python is a volunteer effort. If you think the documentation is poor, what are YOU doing to fix that, apart from complaining? We welcome patches to the documentation. If you don't know how to write a patch file, that's okay too. What suggestions do you have for fixing the docs? If people agree that your suggestions are good, *and* they care enough to make the effort, then somebody *might* generate a bug report for it, which eventually *might* lead to somebody producing a patch. But if you want to increase the chances, you need to be active and not just an armchair critic. Write the patch. If you can't write the patch, at least raise a bug report with a suggestion for fixing it. > I am not blaming those volunteers who devote their precious time to this > language. It will be good if the python communities get more people who > like to write documentation. Volunteers are welcome. The first step is to suggest an improvement to the docs, not just complain that they're not good enough. How would you fix the docs for socket.recv? -- Steven From breamoreboy at yahoo.co.uk Fri Jul 23 03:20:03 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 23 Jul 2010 08:20:03 +0100 Subject: Where is the man page of python library In-Reply-To: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: [Fix top posting] > > On Jul 23, 12:07 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: >>> Hi, guys. >> >>> As a regular user of python, I am often annoyed by the fact that the >>> official python docementation is too short and too simple to satisfy my >>> requirement. >> >> Python is a volunteer effort. If the docs don't suit your requirements, >> we're grateful for patches. >> >>> While working with socket, I want to know every detail about every API. >>> I can easilly achieve that by reading man page if the language is C. But >>> It seems that the Python story is different. >> >> Python is open source. Where the documentation is silent, the ultimate >> authority is the source code. Particularly if the code is a thin wrapper >> around the C library, which I expect (but don't know for sure) the socket >> code will be. >> >>> For the interface recv(), all I got is only three sentences. " >>> Receive data from the socket. The return value is a string representing >>> the data received. The maximum amount of data to be received at once is >>> specified by bufsize. " >>> http://docs.python.org/library/socket.html#socket.socket.recv >> >>> What if the call fail? >> >> You will get an exception, just like the page says: >> >> All errors raise exceptions. The normal exceptions for >> invalid argument types and out-of-memory conditions can be >> raised; errors related to socket or address semantics raise >> the error socket.error. >> >>> What if the peer close the socket? >> >> You will get an exception, just like the Fine Manual says. >> >>> What is the >>> difference between blocking and non-blocking socket? >> >> Python isn't a tutor for basic programming concepts like sockets. That's >> what Google is for :) >> >> But having said that, the documentation does explain the difference: >> >> In non-blocking mode, if a recv() call doesn?t find any data, >> or if a send() call can?t immediately dispose of the data, >> a error exception is raised; in blocking mode, the calls block >> until they can proceed. >> >> http://docs.python.org/library/socket.html#socket.socket.setblocking >> >>> How could I get the errno or exception? >> >> You get the exception the same way you get *every* exception: by catching >> it with a try...except block. If you don't know that, you need to learn >> the basics and not blame the documentation. >> >> Untested, but this probably will work: >> >> try: >> something_involving_sockets() >> except socket.error, e: >> if len(e.args) == 1: >> print "Error message is:", e.args[0] >> else: >> print "errno =", e.args[0] >> print "Error message is:", e.args[1] >> >>> All the answers are "No comment". >> >>> I hate this documentation! >> >> Don't blame the documentation for your failure to read it. It's true that >> it could be improved, but most of your questions were answered by the >> page you linked to. >> >> -- >> Steven > On 23/07/2010 06:24, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. > some of my questions are answered in the page I post the link of. Some > are not. > > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. > > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on volunteer effort too, and > they has good documentations. > > I am not blaming those volunteers who devote their precious time to > this language. It will be good if the python communities get more > people who like to write documentation. > > Anyway, thank you again. > I'll be on the Python issue tracker later today. I look forward to seeing your first of many contributions to the "poor" Python documentation. Pigs might fly? :) Kindest regards. Mark Lawrence. From debatem1 at gmail.com Fri Jul 23 04:03:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 23 Jul 2010 01:03:34 -0700 Subject: Where is the man page of python library In-Reply-To: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: On Thu, Jul 22, 2010 at 10:24 PM, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. > some of my questions are answered in the page I post the link of. Some > are not. > > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. > > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on ?volunteer effort too, and > they has good documentations. > > I am not blaming those volunteers who devote their precious time to > this language. It will be good if the python communities get more > people who like to write documentation. > > Anyway, thank you again. Two things: 1) don't top post, it's bad form. 2) I'd be happy to help you through the process of getting your doc changes written and onto the tracker. Others more capable than myself have offered their help once things reach that stage. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:10:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:10:11 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4c494e62$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? Not in CPython. In IronPython or Jython, maybe, I don't know enough about them. But even if you got it to work, it would be an implementation- dependent trick. [...] > I always think that it is the language's job to express > my thoughts... Ha, no, it's the language's job to execute algorithms. If it did so in a way that is similar to the way people think, that would be scary. Have you *seen* the way most people think??? *wink* > I don't like to think that my thoughts are somehow > constrained by the language. Whether you "like" to think that way, or not, thoughts are influenced and constrained by language. While I don't accept the strong form of the Sapir-Whorf hypothesis (that some thoughts are *impossible* due to lack of language to express them, a position which has been discredited), a weaker form is almost certainly correct. Language influences thought. Turing Award winner and APL creator Kenneth E. Iverson gave a lecture about this theme, "Notation as a tool of thought", and argued that more powerful notations aided thinking about computer algorithms. Paul Graham also discusses similar ideas, such as the "blub paradox". Graham argues that the typical programmer is "satisfied with whatever language they happen to use, because it dictates the way they think about programs". We see this all the time, with people trying to write Java in Python, Perl in Python, and Ruby in Python. And Yukihiro Matsumoto has said that one of his inspirations for creating Ruby was the science fiction novel Babel-17, which in turn is based on the Sapir-Whorf Hypothesis. > The truth is that I don't intend to use these approaches in anything > serious. However, I've been known to do some metaprogramming from time > to time. > > In a recent application, I pass in a list of callables (lambdas) to be > evaluated repeatedly. Are you aware that lambdas are just functions? The only differences between a "lambda" and a function created with def is that lambda is syntactically limited to a single expression, and that functions created with lambda are anonymous (they don't have a name, or at least, not a meaningful name). > Clearly, a superior solution is to pass a single lambda that returns a > list. I don't see why you say this is a superior solution, mostly because you haven't explained what the problem is. > [Less function call dispatches] How? You have to generate the list at some point. Whether you do it like this: functions = (sin, cos, tan) data = (2.3, 4.5, 1.2) result = [f(x) for f, x in zip(functions, data)] or like this: result = (lambda x, y, z: return (sin(x), cos(y), tan(z)) )(2.3, 4.5, 1.2) you still end up with the same number of function calls (four). Any execution time will almost certainly be dominated by the work done inside the lambda (sin, cos and tan) rather than the infrastructure. And unless you have profiled your code, you would be surprised as to where the bottlenecks are. Your intuitions from Perl will not guide you well in Python -- it's a different language, and the bottlenecks are different. > However, it might be more > efficient to avoid the function call overhead completely and pass-in a > string which is substituted into a string code block, compiled, and > executed. See, that's *exactly* what I mean about intuitions. No no no no!!! Using exec or eval in Python code is almost certainly a *pessimation*, not an optimization! I expect this will be an order of magnitude slower to parse, compile and execute a string than it is to execute a function. Using exec or friends to avoid the overhead of function calls is like pushing your car to work to avoid the overhead of having to get in and out of the car. But of course, don't take my word for it. Write your code and profile it, see where the bottlenecks are. I might be wrong. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:24:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:24:34 GMT Subject: Change Encoding in Py 2.5 References: Message-ID: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 09:18:47 +0200, Stefan Behnel wrote: > Girish, 23.07.2010 08:54: >> Is ter a way to change default encoding in py 2.5 ? > > Yes, but it's highly discouraged. If you tell us why you want to do it, > we may be able to point to a better way to get what you want. I think it is discouraged because it *will* break things in the standard library and builtins. It's discouraged in the same way that pouring sugar into the petrol tank of your car is discouraged. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:26:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:26:31 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: <4c495237$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 08:20:03 +0100, Mark Lawrence wrote: > [Fix top posting] While you were fixing the top posting, did you bother to trim any unnecessary quoting? Let me scroll down and see... ... why no, no you didn't. I'm not a religious man, but the verse about the mote in your brother's eye might be appropriate about now. It's one thing to make a point about another's social faux pas, and other to make an equally big one yourself while doing so. -- Steven From hv at tbz-pariv.de Fri Jul 23 04:45:32 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 23 Jul 2010 10:45:32 +0200 Subject: non-blocking IO EAGAIN on write Message-ID: <8at354F51tU1@mid.individual.net> Hi, I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) on write(). My working code looks like this. But I am unsure how many bytes have been written to the pipe if I get an EAGAIN IOError. Up to now I retry with the same chunk. If I get EAGAIN can I just sleep, and then retry with the same data chunk? pipe=subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=-1) fcntl.fcntl(pipe.stdin, fcntl.F_SETFL, os.O_NONBLOCK) .... chunk_size=1024 while select.select([], [pipe.stdin], [], 5): check_timeout() chunk=fd.read(chunk_size) for i_eagain in range(10): try: pipe.stdin.write(chunk) except IOError, exc: if exc.errno==errno.EAGAIN: logging.info('write to pipe %s EAGAIN. I will try again i=%s. %s' % (cmd, i_eagain, exc)) time.sleep(.3) continue logging.error('write to pipe %s failed: %s' % (cmd, exc), exc_info=True) raise break # write was successful (default) else: raise Exception('Too many EAGAIN on write %s %s' % (cmd, exc), exc_info=True) Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 05:05:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 09:05:21 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4c495b50$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: > On 7/22/10 7:47 PM, wheres pythonmonks wrote: [...] >> The truth is that I don't intend to use these approaches in anything >> serious. However, I've been known to do some metaprogramming from time >> to time. > > Depending on how you define "metaprogramming", Python is pretty > notoriously ill-suited towards the task (more, its basically considered > a feature it doesn't let you go there) -- or, it allows you to do vast > amounts of stuff with its few dark magic hooks. I've never had a > satisfying definition of metaprogramming that more then 50% of any group > agree with, so I'm not sure which you're looking for. :) I disagree strongly at your characterisation that Python is notorious for being ill-suited towards metaprogramming. I'd say the complete opposite -- what is considered dark and scary metaprogramming tasks in other languages is considered too ordinary to even mention in Python. If you have a class that defines a single member (or attribute in Python terminology) "spam", and you want to add a second "ham" to a specific instance, such a thing is either deep, dark metaprogramming in some languages, if not outright impossible. In Python it is not even noteworthy: instance.ham = "something" # *yawns* Recently there was a thread started by some Java or C++ refugee who was distressed about attribute access in Python, because it made metaprogramming frighteningly easy: http://mail.python.org/pipermail/python-list/2010-June/1248029.html My response at the time was: Python makes metaprogramming *easy*: http://mail.python.org/pipermail/python-list/2010-June/1248053.html I can't imagine how he would have reacted if we had showed him how easy it is to monkey-patch built-in functions... [...] > But! What it doesn't let you do is get clever with syntax and write a > sort of "simplified" or domain specific language to achieve certain > sorts of repetitive tasks quickly. You always end up writing normal > Python that looks like all other Python. Exactly... 90% of the time that you think you want a DSL, Python beat you to it. It is true that other languages (like Lisp, or Forth) allow you to write your own syntax. That's incredibly powerful, but it also has serious costs. If you can define your own syntax, that means every piece of code you look at is potentially a different language. -- Steven From qq263020776 at gmail.com Fri Jul 23 05:18:41 2010 From: qq263020776 at gmail.com (nu) Date: Fri, 23 Jul 2010 02:18:41 -0700 (PDT) Subject: make a folder to .nsi file(which finally will convert to .exe) use python Message-ID: <54269fe3-085c-4360-93eb-866223a0bcca@v35g2000prn.googlegroups.com> Has any python liberary can make a folder to .nsi file? Thanks From duncan.booth at invalid.invalid Fri Jul 23 05:26:02 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Jul 2010 09:26:02 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > >> Thanks for pointing out that swap (and my swap2) don't work everywhere >> -- is there a way to get it to work inside functions? Consider languages where you can easily write a swap function (or any other function that updates its arguments). e.g. consider C or C#. For C your function must take pointers to the variables, so when you call swap you have to make this explicit by taking the address of each variable: foo(&x, &y); For C# the function takes references to the variables. Again you have to also make this explicit at the point of call by prefixing the argument with 'ref': foo(ref x, ref y); Python is really no different: if you want a function to rebind its arguments you have to make that explicit at the point of call. The only difference is that in Python you make the rebinding explicit by assigning to the names: x, y = foo(x, y) -- Duncan Booth http://kupuguy.blogspot.com From wherespythonmonks at gmail.com Fri Jul 23 05:28:05 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 23 Jul 2010 05:28:05 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c494e62$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: Funny... just spent some time with timeit: I wonder why I am passing in strings if the callback overhead is so light... More funny: it looks like inline (not passed in) lambdas can cause python to be more efficient! >>> import random >>> d = [ (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in xrange(0,1000000) ] >>> def A1(): j = [ lambda t: (t[2]*t[1],t[2]**2+5) for t in d ] >>> def A2(): j = [ (t[2]*t[1],t[2]**2+5) for t in d ] >>> def A3(l): j = [ l(t) for t in d] >>> import timeit >>> timeit.timeit('A1()','from __main__ import A1,d',number=10); 2.2185971572472454 >>> timeit.timeit('A2()','from __main__ import A2,d',number=10); 7.2615454749912942 >>> timeit.timeit('A3(lambda t: (t[2]*t[1],t[2]**2+5))','from __main__ import A3,d',number=10); 9.4334241349350947 So: in-line lambda possible speed improvement. in-line tuple is slow, passed-in callback, slowest yet? Is this possibly right? Hopefully someone can spot the bug? W On Fri, Jul 23, 2010 at 4:10 AM, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > >> Thanks for pointing out that swap (and my swap2) don't work everywhere >> -- is there a way to get it to work inside functions? > > Not in CPython. In IronPython or Jython, maybe, I don't know enough about > them. But even if you got it to work, it would be an implementation- > dependent trick. > > [...] >> I always think that it is the language's job to express >> my thoughts... > > Ha, no, it's the language's job to execute algorithms. If it did so in a > way that is similar to the way people think, that would be scary. Have > you *seen* the way most people think??? > > *wink* > > >> I don't like to think that my thoughts are somehow >> constrained by the language. > > > Whether you "like" to think that way, or not, thoughts are influenced and > constrained by language. While I don't accept the strong form of the > Sapir-Whorf hypothesis (that some thoughts are *impossible* due to lack > of language to express them, a position which has been discredited), a > weaker form is almost certainly correct. Language influences thought. > > Turing Award winner and APL creator Kenneth E. Iverson gave a lecture > about this theme, "Notation as a tool of thought", and argued that more > powerful notations aided thinking about computer algorithms. > > Paul Graham also discusses similar ideas, such as the "blub paradox". > Graham argues that the typical programmer is "satisfied with whatever > language they happen to use, because it dictates the way they think about > programs". We see this all the time, with people trying to write Java in > Python, Perl in Python, and Ruby in Python. > > And Yukihiro Matsumoto has said that one of his inspirations for creating > Ruby was the science fiction novel Babel-17, which in turn is based on > the Sapir-Whorf Hypothesis. > > > >> The truth is that I don't intend to use these approaches in anything >> serious. ?However, I've been known to do some metaprogramming from time >> to time. >> >> In a recent application, I pass in a list of callables (lambdas) to be >> evaluated repeatedly. > > Are you aware that lambdas are just functions? The only differences > between a "lambda" and a function created with def is that lambda is > syntactically limited to a single expression, and that functions created > with lambda are anonymous (they don't have a name, or at least, not a > meaningful name). > > >> Clearly, a superior solution is to pass a single lambda that returns a >> list. > > I don't see why you say this is a superior solution, mostly because you > haven't explained what the problem is. > > >> [Less function call dispatches] > > How? You have to generate the list at some point. Whether you do it like > this: > > functions = (sin, cos, tan) > data = (2.3, 4.5, 1.2) > result = [f(x) for f, x in zip(functions, data)] > > or like this: > > result = (lambda x, y, z: return (sin(x), cos(y), tan(z)) > ? ?)(2.3, 4.5, 1.2) > > you still end up with the same number of function calls (four). Any > execution time will almost certainly be dominated by the work done inside > the lambda (sin, cos and tan) rather than the infrastructure. And unless > you have profiled your code, you would be surprised as to where the > bottlenecks are. Your intuitions from Perl will not guide you well in > Python -- it's a different language, and the bottlenecks are different. > > >> However, it might be more >> efficient to avoid the function call overhead completely and pass-in a >> string which is substituted into a string code block, compiled, and >> executed. > > See, that's *exactly* what I mean about intuitions. No no no no!!! Using > exec or eval in Python code is almost certainly a *pessimation*, not an > optimization! I expect this will be an order of magnitude slower to > parse, compile and execute a string than it is to execute a function. > Using exec or friends to avoid the overhead of function calls is like > pushing your car to work to avoid the overhead of having to get in and > out of the car. > > But of course, don't take my word for it. Write your code and profile it, > see where the bottlenecks are. I might be wrong. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From dirknbr at gmail.com Fri Jul 23 06:14:11 2010 From: dirknbr at gmail.com (dirknbr) Date: Fri, 23 Jul 2010 03:14:11 -0700 (PDT) Subject: Unicode error Message-ID: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> I am having some problems with unicode from json. This is the error I get UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in position 61: ordinal not in range(128) I have kind of developped this but obviously it's not nice, any better ideas? try: text=texts[i] text=text.encode('latin-1') text=text.encode('utf-8') except: text=' ' Dirk From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 06:42:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 10:42:26 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: <4c497212$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 03:14:11 -0700, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) > > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' Don't write bare excepts, always catch the error you want and nothing else. As you've written it, the result of encoding with latin-1 is thrown away, even if it succeeds. text = texts[i] # Don't hide errors here. try: text = text.encode('latin-1') except UnicodeEncodeError: try: text = text.encode('utf-8') except UnicodeEncodeError: text = ' ' do_something_with(text) Another thing you might consider is setting the error handler: text = text.encode('utf-8', errors='ignore') Other error handlers are 'strict' (the default), 'replace' and 'xmlcharrefreplace'. -- Steven From clp2 at rebertia.com Fri Jul 23 06:45:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jul 2010 03:45:19 -0700 Subject: Unicode error In-Reply-To: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: On Fri, Jul 23, 2010 at 3:14 AM, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) Please include the full Traceback and the actual code that's causing the error! We aren't mind readers. This error basically indicates that you're incorrectly mixing byte strings and Unicode strings somewhere. Cheers, Chris -- http://blog.rebertia.com From dirknbr at gmail.com Fri Jul 23 06:56:15 2010 From: dirknbr at gmail.com (dirknbr) Date: Fri, 23 Jul 2010 03:56:15 -0700 (PDT) Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: To give a bit of context. I am using twython which is a wrapper for the JSON API search=twitter.searchTwitter(s,rpp=100,page=str(it),result_type='recent',lang='en') for u in search[u'results']: ids.append(u[u'id']) texts.append(u[u'text']) This is where texts comes from. When I then want to write texts to a file I get the unicode error. Dirk From __peter__ at web.de Fri Jul 23 07:20:19 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jul 2010 13:20:19 +0200 Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: wheres pythonmonks wrote: > Funny... just spent some time with timeit: > > I wonder why I am passing in strings if the callback overhead is so > light... > > More funny: it looks like inline (not passed in) lambdas can cause > python to be more efficient! >>>> import random >>>> d = [ (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in >>>> xrange(0,1000000) ] def A1(): j = [ lambda t: (t[2]*t[1],t[2]**2+5) for >>>> t in d ] > >>>> def A2(): j = [ (t[2]*t[1],t[2]**2+5) for t in d ] > >>>> def A3(l): j = [ l(t) for t in d] > >>>> import timeit >>>> timeit.timeit('A1()','from __main__ import A1,d',number=10); > 2.2185971572472454 >>>> timeit.timeit('A2()','from __main__ import A2,d',number=10); > 7.2615454749912942 >>>> timeit.timeit('A3(lambda t: (t[2]*t[1],t[2]**2+5))','from __main__ >>>> import A3,d',number=10); > 9.4334241349350947 > > So: in-line lambda possible speed improvement. in-line tuple is slow, > passed-in callback, slowest yet? > > Is this possibly right? > > Hopefully someone can spot the bug? A1() makes a lot of lambdas but doesn't invoke them. Once that is fixed A1() is indeed slower than A2(): >>> from timeit import timeit >>> import random >>> d = [(random.choice("AB"), x, random.gauss(0, 1)) for x in xrange(10**6)] >>> def A1(d=d): return [(lambda t: (t[2]*t[1],t[2]**2+5))(t) for t in d] ... >>> def A2(d=d): return [(t[2]*t[1], t[2]**2+5) for t in d] ... >>> assert A1() == A2() >>> timeit("A1()", "from __main__ import A1", number=10) 14.275790929794312 >>> timeit("A2()", "from __main__ import A2", number=10) 10.31659197807312 Peter From davea at ieee.org Fri Jul 23 07:35:57 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 07:35:57 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C497E9D.4070105@ieee.org> Duncan Booth wrote: > > Consider languages where you can easily write a swap function (or any other > function that updates its arguments). e.g. consider C or C#. > > For C your function must take pointers to the variables, so when you call > swap you have to make this explicit by taking the address of each variable: > > foo(&x, &y); > > For C# the function takes references to the variables. Again you have to > also make this explicit at the point of call by prefixing the argument with > 'ref': > > foo(ref x, ref y); > > Python is really no different: if you want a function to rebind its > arguments you have to make that explicit at the point of call. The only > difference is that in Python you make the rebinding explicit by assigning > to the names: > > x, y = foo(x, y) > > > I don't disagree with the overall point, but C has references (or at least C++ does, I don't think I've written any pure C code since 1992). If the function is declared to take references, the caller doesn't do a thing differently. void foo(int &a, int &b); is called by foo(x, y), and the function may indeed swap the arguments. If I recall correctly, pascal is the same way. The called function declares byref, and the caller doesn't do anything differently. DaveA From davea at ieee.org Fri Jul 23 07:44:03 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 07:44:03 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C498083.6080908@ieee.org> wheres pythonmonks wrote: > Funny... just spent some time with timeit: > > I wonder why I am passing in strings if the callback overhead is so light... > > More funny: it looks like inline (not passed in) lambdas can cause > python to be more efficient! > >>>> import random >>>> d = (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in xrange(0,1000000) ] >>>> def A1(): j = lambda t: (t[2]*t[1],t[2]**2+5) for t in d ] >>>> > > >>>> def A2(): j = (t[2]*t[1],t[2]**2+5) for t in d ] >>>> > > But A1() gives a different result. It builds a list of function objects. It doesn't actually do any of those multiplies. In fact, I don't even think it would get the same answers if you then looped through it, calling the functions it stored. DaveA From kwutzke at web.de Fri Jul 23 08:07:53 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Fri, 23 Jul 2010 05:07:53 -0700 (PDT) Subject: Visitor pattern and separating iteration References: Message-ID: On 22 Jul., 22:25, Ian wrote: > Hi Karsten, > > On 22/07/2010 12:03, Karsten Wutzke wrote:> What is it I'm missing? > > I think you are making it more complicated than it really is. > > The visitor pattern is about bringing all the little bits that would > otherwise be scattered all over > many node classes into one visitor class. For code generation this means > that all the code generation is done > in your visitor class. For pretty-printing you have another visitor > class. For code optimization a third > visitor class. > > If there is only one sequence in which the nodes should be visited, then > you can build it > in to the nodes of the tree. > > If you need to visit your nodes in different orders you might be better > off building a separated > tree-walker class for each order. Thus you might have a > post-order-walker for use with the code > generating visitor, and a in-order-walker for a pretty-printing visitor. > > The optimizing walker may need to take different routes through the tree > depending > upon what it finds. For example, it may compute the value of the RHS of > an assignment > before computing the address of the LHS, so it can make better use of > registers. Here the > visitor class itself needs to do the walking. > > Regards > > Ian My objects to iterate over are plain object-structures, composites. I have only one code generation pass, so generating code and then pretty printing is not intended/possible. I have many user options to configure the code generation. The visitor pattern is ideal for that matter, because I can keep the options in the generator rather than scatter all the options into the object classes' accessor methods. (making me think the visitor is just right and not more complicated than needed) I was just curious about separating the iteration code into the object classes, because GoF said "The main reason to put the traversal strategy in the visitor is to implement a *particular complex* traversal, one that depends on the results of the operations on the object structure." My code generator isn't really THAT complex (I thought), but reviewing the latter part of the quote makes me believe I was wrong. Code generation always depends on the previous results, that is the children of a composite in the object structure. Now that I realized it, I feel great about traversing in the visitor. Python just has a few consequences that makes creating common interfaces/abstract classes a little unusual. I'm just starting to really love Python (or its API), though I don't feel I've already discovered the core what it is really about. Best regards Karsten From franco at grex.org Fri Jul 23 09:10:16 2010 From: franco at grex.org (francogrex) Date: Fri, 23 Jul 2010 15:10:16 +0200 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: In article <16a7e301-2e85-47eb-971e-79acc4e076a6 at b35g2000yqi. googlegroups.com>, gnuist006 at gmail.com says... >This makes some sense. He replied on the newsgroup in a lengthy post >that there are sufficient resources out there giving hint that no one >need help me out. Then I was called "lazy" in one email and tersely >given JUST the last name of an author who has many books each many >100s pages, when I asked for a relevant book, as if i am a scholar in >the field, although he did spend lots of words on irrelevant and >unbeneficial things which diminished my enthusiasm. Now, I find out >from you that he has/had a business concern or interest in a company >that is writing/wrote lisp interpreter in C. Correct me if I am making >an error. I dont want to think deprecatingly of any good soul but this >is what i experienced. No, you're not making a bad judgement. He's not the only one who treats newcomers with disrespect and scorn. Unfortunately many so-called experts in the field look down on newbies and mistreat them (in any programming language forum), forgetting in the process that they were also at a certain time newbies until someone gentle and nice enough teachers took the trouble to educate them. On the other hand there are less neurotic experts out there who are glad to help out someone learning. It's like in some universities, you have the bad "professors" who are freaks (probably they have a lot of problems at home, their wives screwing all the males on the block, daughters drug addicts etc) and want to take their hatred out on you, and you have the good and mentally stable professors who actually deserve their title. From lists at cheimes.de Fri Jul 23 09:26:26 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jul 2010 15:26:26 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> References: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> Message-ID: > I think it is discouraged because it *will* break things in the standard > library and builtins. It's discouraged in the same way that pouring sugar > into the petrol tank of your car is discouraged. Mythbusters have tested this urban legend. In their test the engine run better with sugar. [1] Christian [1] http://mythbustersresults.com/episode15 From stefan_ml at behnel.de Fri Jul 23 09:59:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jul 2010 15:59:58 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: References: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> Message-ID: Christian Heimes, 23.07.2010 15:26: >> I think it is discouraged because it *will* break things in the standard >> library and builtins. It's discouraged in the same way that pouring sugar >> into the petrol tank of your car is discouraged. > > Mythbusters have tested this urban legend. In their test the engine run > better with sugar. [1] "Did you blow up your car testing that out?" - "No, I just read comp.lang.python." Stefan From invalid at invalid.invalid Fri Jul 23 10:26:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 23 Jul 2010 14:26:27 +0000 (UTC) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 2010-07-23, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > >> Hi, guys. >> >> As a regular user of python, I am often annoyed by the fact that the >> official python docementation is too short and too simple to satisfy my >> requirement. > > Python is a volunteer effort. If the docs don't suit your requirements, > we're grateful for patches. > >> While working with socket, I want to know every detail about every API. >> I can easilly achieve that by reading man page if the language is C. But >> It seems that the Python story is different. > > Python is open source. Where the documentation is silent, the ultimate > authority is the source code. Particularly if the code is a thin wrapper > around the C library, which I expect (but don't know for sure) the socket > code will be. > > >> For the interface recv(), all I got is only three sentences. " >> Receive data from the socket. The return value is a string representing >> the data received. The maximum amount of data to be received at once is >> specified by bufsize. " >> http://docs.python.org/library/socket.html#socket.socket.recv >> >> What if the call fail? > > You will get an exception, just like the page says: > > All errors raise exceptions. The normal exceptions for > invalid argument types and out-of-memory conditions can be > raised; errors related to socket or address semantics raise > the error socket.error. > > >> What if the peer close the socket? > > You will get an exception, Nope. You read a value of "". > just like the Fine Manual says. If it does say that, it needs to be fixed. >> I hate this documentation! Then quit bitching and submit a patch. > Don't blame the documentation for your failure to read it. It's true > that it could be improved, but most of your questions were answered > by the page you linked to. -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 10:49:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 14:49:10 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c49abe6$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 14:26:27 +0000, Grant Edwards wrote: >>> What if the peer close the socket? >> >> You will get an exception, > > Nope. You read a value of "". Thank you for the correction. >> just like the Fine Manual says. > > If it does say that, it needs to be fixed. No, I apparently just made it up. -- Steven From rantingrick at gmail.com Fri Jul 23 11:42:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 23 Jul 2010 08:42:52 -0700 (PDT) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> Message-ID: <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> On Jul 23, 9:49?am, Steven D'Aprano wrote: > On Fri, 23 Jul 2010 14:26:27 +0000, Grant Edwards wrote: > > If it does say that, it needs to be fixed. > > No, I apparently just made it up. Yes and i'll bet you've *never* just "made up" anything to scaffold your arguments? . Since this trait is one of the major personality flaws of the deeply religious... are you *sure* your *not* a religious man Steven? We've also seen our fair share of haughty arrogance and sanctimoniousness from time to time. Just observations really. Sorry, i guess I just wanted to put a big neon sign around your mistake. Of course now we both have our eyes poked out! In the land of the blind, the one eyed man is king! ;-) From robert.kern at gmail.com Fri Jul 23 11:44:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jul 2010 10:44:51 -0500 Subject: detect endianness of a binary with python In-Reply-To: References: <4C46EEB8.6070702@keymile.com> Message-ID: On 7/23/10 12:44 AM, Tim Roberts wrote: > I wouldn't use os.system with grep and evaluate the return code. Instead > I'd use subprocess.Popen("file") and read the text output of the > commdn directly. By parsing that string, I can extract all kinds of > interesting information. Small correction: subprocess.Popen(["file", our_image_filename]) -- 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 prologic at shortcircuit.net.au Fri Jul 23 12:09:09 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 24 Jul 2010 02:09:09 +1000 Subject: Where is the man page of python library In-Reply-To: <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> Message-ID: On Sat, Jul 24, 2010 at 1:42 AM, rantingrick wrote: > In the land of the blind, the one eyed man is king! ;-) RIck, your comments don't really help the situation. Really. -- -- James Mills -- -- "Problems are solved by method" From me+list/python at ixokai.io Fri Jul 23 12:22:16 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 23 Jul 2010 09:22:16 -0700 Subject: Easy questions from a python beginner In-Reply-To: <4c495b50$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c495b50$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C49C1B8.5060500@ixokai.io> On 7/23/10 2:05 AM, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: > >> On 7/22/10 7:47 PM, wheres pythonmonks wrote: > [...] >>> The truth is that I don't intend to use these approaches in anything >>> serious. However, I've been known to do some metaprogramming from time >>> to time. >> >> Depending on how you define "metaprogramming", Python is pretty >> notoriously ill-suited towards the task (more, its basically considered >> a feature it doesn't let you go there) -- or, it allows you to do vast >> amounts of stuff with its few dark magic hooks. I've never had a >> satisfying definition of metaprogramming that more then 50% of any group >> agree with, so I'm not sure which you're looking for. :) > > I disagree strongly at your characterisation that Python is notorious for > being ill-suited towards metaprogramming. I'd say the complete opposite > -- what is considered dark and scary metaprogramming tasks in other > languages is considered too ordinary to even mention in Python. I rather think you missed my point entirely. 'Depending on how you define "metaprogramming"' The 'Depending' was the most important part of that sentence. You go on to talk about runtime modification of classes and the like. That, Python lets you do quite readily, and then go on to do crazy amounts of without any significant effort. That's one definition of metaprogramming. That one Python does well. The other involves things like macros, or things where you basically write a new sub-language in the language itself to achieve some commonly desired task more efficiently (or just more succinctly). That's another definition of metaprogramming: where its not so much structures (classes, etc) which are modified at runtime (which Python lets you do readily), but the syntax or semantics of the language itself. That Python isn't game for. > [...] >> But! What it doesn't let you do is get clever with syntax and write a >> sort of "simplified" or domain specific language to achieve certain >> sorts of repetitive tasks quickly. You always end up writing normal >> Python that looks like all other Python. > > Exactly... 90% of the time that you think you want a DSL, Python beat you > to it. Yet, that is a branch of what is considered metaprogramming that the OP seems to be asking for, that we do not offer any sort of real support for. I was making this distinction. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Fri Jul 23 12:27:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 18:27:47 +0200 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: <4C49C303.4010106@jollans.com> On 07/23/2010 12:56 PM, dirknbr wrote: > To give a bit of context. I am using twython which is a wrapper for > the JSON API > > > search=twitter.searchTwitter(s,rpp=100,page=str(it),result_type='recent',lang='en') > for u in search[u'results']: > ids.append(u[u'id']) > texts.append(u[u'text']) > > This is where texts comes from. > > When I then want to write texts to a file I get the unicode error. So your data is unicode? Good. Well, files are just streams of bytes, so to write unicode data to one you have to encode it. Since Python can't know which encoding you want to use (utf-8, by the way, if you ask me), you have to do it manually. something like: outfile.write(text.encode('utf-8')) From jim.hefferon at gmail.com Fri Jul 23 13:01:00 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 10:01:00 -0700 (PDT) Subject: time between now and the next 2:30 am? Message-ID: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> How can I calculate how much time is between now and the next 2:30 am? Naturally I want the system to worry about leap years, etc. Thanks, Jim From neilc at norwich.edu Fri Jul 23 13:06:11 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Jul 2010 17:06:11 GMT Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> Message-ID: <8au0g3FmmoU1@mid.individual.net> On 2010-07-23, Jim wrote: > How can I calculate how much time is between now and the next > 2:30 am? Naturally I want the system to worry about leap > years, etc. You need the datetime module. Specifically, a datetime and timedelta object. -- Neil Cerutti From thomas at jollans.com Fri Jul 23 13:13:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 19:13:45 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4C49CDC9.1000108@jollans.com> On 07/23/2010 12:34 AM, wheres pythonmonks wrote: > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. I just had the most horrendous idea. Really, looking up objects by ID, or even swapping two objects, isn't that difficult if you do some C black magic. Don't try this in front of the kids. I wrote a little module, called "hell": Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> from hell import swap, getptr >>> dir >>> len >>> swap(dir, len) >>> dir >>> len >>> a = "this was a" >>> b = "this was b, hell yeah" >>> (a, b, id(a), id(b)) ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>> tpl = (a, b, id(a), id(b)) >>> tpl ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>> swap(a, b) >>> tpl ('this was b, hell yeah', 'this was a', 32417752, 32418144) >>> getptr(32417752) 'this was b, hell yeah' >>> The code is below. Use it under the terms of the WTFPL version 2. (http://sam.zoy.org/wtfpl/) -- Thomas PS: all of this is a very BAD IDEA. But interesting, in a way. ################# setup.py ############ from distutils.core import setup, Extension hellmodule = Extension('hell', sources = ['hellmodule.c']) setup (name = 'hellmodule', version = '0.1-apocalypse', description = 'Functions from hell. Never ever use.', ext_modules = [hellmodule]) ################# hellmodule.c ############## #define PY_SSIZE_T_CLEAN #include static PyObject *swap(PyObject *self, PyObject *args); static PyObject *getptr(PyObject *self, PyObject *args); static PyMethodDef hell_methods[] = { {"swap", &swap, METH_VARARGS, ""}, {"getptr", &getptr, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef hell_module = { PyModuleDef_HEAD_INIT, "hell", /* module name */ "functions from hell. never use.", /* doc */ -1, hell_methods }; PyMODINIT_FUNC PyInit_hell(void) { return PyModule_Create(&hell_module); } static PyObject * swap(PyObject *self, PyObject *args) { PyObject *obj1, *obj2; Py_ssize_t len; PyObject *temp; if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) { return NULL; } len = obj1->ob_type->tp_basicsize; if (obj2->ob_type->tp_basicsize != len) { PyErr_SetString(PyExc_TypeError, "types have different sizes (incompatible)"); return NULL; } temp = PyMem_Malloc(len); memcpy(temp, obj1, len); memcpy(obj1, obj2, len); memcpy(obj2, temp, len); obj2->ob_refcnt = obj1->ob_refcnt; obj1->ob_refcnt = temp->ob_refcnt; Py_INCREF(Py_None); return Py_None; } static PyObject * getptr(PyObject *self, PyObject *args) { unsigned long lId; PyObject *retv; if (!PyArg_ParseTuple(args, "k", &lId)) { return NULL; } retv = (PyObject*) lId; Py_INCREF(retv); return retv; } From thomas at jollans.com Fri Jul 23 14:07:34 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 20:07:34 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4C49CDC9.1000108@jollans.com> References: <4C3A0F79.8070502@ixokai.io> <4C49CDC9.1000108@jollans.com> Message-ID: <4C49DA66.7020707@jollans.com> On 07/23/2010 07:13 PM, Thomas Jollans wrote: > On 07/23/2010 12:34 AM, wheres pythonmonks wrote: >> 2. Is there a better way to loopup by id? I'm not very familiar with >> sys.exc_info, but creating the id->name hash each time seems like >> overkill. > > I just had the most horrendous idea. Really, looking up objects by ID, > or even swapping two objects, isn't that difficult if you do some C > black magic. Don't try this in front of the kids. > > I wrote a little module, called "hell": > > Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> from hell import swap, getptr >>>> dir > >>>> len > >>>> swap(dir, len) >>>> dir > >>>> len > >>>> a = "this was a" >>>> b = "this was b, hell yeah" >>>> (a, b, id(a), id(b)) > ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>>> tpl = (a, b, id(a), id(b)) >>>> tpl > ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>>> swap(a, b) >>>> tpl > ('this was b, hell yeah', 'this was a', 32417752, 32418144) >>>> getptr(32417752) > 'this was b, hell yeah' >>>> The great thing about this is that it can illustrate, in a very perverse manner, some lovely facets of Python. For example: combined hash and equality checks when accessing sets and dicts: Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from hell import swap >>> s1 = 'string1' >>> s2 = 'string2' >>> s = {s1, s2} >>> swap(s1, s2) >>> s {'string1', 'string2'} >>> s1 in s False >>> s2 in s False >>> s1 in list(s) True >>> s2 in list(s) True >>> From smono927 at gmail.com Fri Jul 23 14:30:08 2010 From: smono927 at gmail.com (SeanMon) Date: Fri, 23 Jul 2010 11:30:08 -0700 (PDT) Subject: Function closure inconsistency Message-ID: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): x += 1 return x return g1 def f2(): x = [] def g(): x.append(0) return x return g a = f1() b = f2() a() #UnboundLocalError: local variable 'x' referenced before assignment b() #No error, [0] returned b() #No error, [0, 0] returned From benjamin.kaplan at case.edu Fri Jul 23 14:49:52 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 11:49:52 -0700 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: On Fri, Jul 23, 2010 at 11:30 AM, SeanMon wrote: > > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > ? ?x = 0 > ? ?def g(): > ? ? ? ?x += 1 > ? ? ? ?return x > ? ?return g1 > > def f2(): > ? ?x = [] > ? ?def g(): > ? ? ? ?x.append(0) > ? ? ? ?return x > ? ?return g > > a = f1() > b = f2() > > a() #UnboundLocalError: local variable 'x' referenced before > assignment > b() #No error, [0] returned > b() #No error, [0, 0] returned > -- It's not closure related at all. Same thing happens at the module level. x = 0 def f1() : ?? x += 1 #gives UnboundLocalError x = [] def f2() : ?? x.append(1) #succeeds. The reason for it is that if you have any assignments to the variable in the function, Python creates a new local variable for it. x += 1 is an assignment, not a modification. Python 2.x allows you to assign to the global scope (using the global keyword) but support for assigning to the outer function's scope wasn't added until Python 3 (with the nonlocal keyword) def f1(): ?? x = 0 ?? def g(): ???????nonlocal x ?????? x += 1 ?????? return x ?? return g1 > > http://mail.python.org/mailman/listinfo/python-list From emmynoether3 at gmail.com Fri Jul 23 15:06:34 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Fri, 23 Jul 2010 12:06:34 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. Message-ID: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> Title Portable LISP interpreter Creator/Author Cox, L.A. Jr. ; Taylor, W.P. Publication Date 1978 May 31 OSTI Identifier OSTI ID: 7017786 Report Number(s) UCRL-52417 DOE Contract Number W-7405-ENG-48 Resource Type Technical Report Research Org California Univ., Livermore (USA). Lawrence Livermore Lab. Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; PROGRAMMING LANGUAGES Description/Abstract A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. Country of Publication United States Language English Format Medium: X; Size: Pages: 21 Availability Dep. NTIS, PC A02/MF A01. System Entry Date 2008 Feb 12 From jim.hefferon at gmail.com Fri Jul 23 15:44:12 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 12:44:12 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: <576fe427-b7a4-47d2-adf5-45f04d6dc905@w30g2000yqw.googlegroups.com> Thanks; I'll have a look, and a think. Jim From davea at ieee.org Fri Jul 23 15:51:45 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 15:51:45 -0400 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: <4C49F2D1.7070106@ieee.org> SeanMon wrote: > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > x = 0 > def g(): > x += 1 > return x > return g1 > > def f2(): > x = [] > def g(): > x.append(0) > return x > return g > > a = f1() > b = f2() > > a() #UnboundLocalError: local variable 'x' referenced before > assignment > b() #No error, [0] returned > b() #No error, [0, 0] returned > > Your example is more complex than needed. The symptom doesn't need a function closure. >>> def g(): ... x += 1 ... return x ... >>> g() Traceback (most recent call last): File "", line 1, in File "", line 2, in g UnboundLocalError: local variable 'x' referenced before assignment >>> def f(): ... x.append(0) ... return x ... >>> x = [3,5] >>> f() [3, 5, 0] >>> The difference between the functions is that in the first case, x is reassigned; therefore it's a local. But it's not defined before that line, so you get the ref before assign error. In the second case, append() is an in-place operation, and doesn't create a local variable. DaveA From python at bdurham.com Fri Jul 23 16:35:56 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 23 Jul 2010 16:35:56 -0400 Subject: Light-weight/very-simple version control under Windows using Python? Message-ID: <1279917356.23092.1386443203@webmail.messagingengine.com> I have some very simple use cases[1] for adding some version control capabilities to a product I'm working on. My product uses simple, text (UTF-8) based scripts that are independent of one another. I would like to "version control" these scripts on behalf of my users. By version control, I mean *very-simple* version control with no branching or merging - just the ability to store, list and restore a specific version of a file. The data store should be a local file with the ability to upsize to a multi-user database in the future. I'm looking for recommendations on possible solutions: 1. Use an existing version control utility. There are lots of options here(!), any recommendations on a light weight, open source one that xcopy installs under Windows with lots of command line options? 2. Interface to a hosted version control system (SaaS) that provides a RESTful API. Any recommendations here? 3. Build this capability myself using Python and Python's DBI layer to store files in a local SQLite database at first (but with the ability to upsize to a real client server database in the future). Seems like a fun project to work on, but also smells like I'd be re-inventing the wheel with very little value added other than simpler deployment? Any suggestions appreciated. Malcolm [1] Here's my use cases: 1. Check a file in with optional comment and username; ideally get a version number that can be used to reference this specific check-in in the future. 2. Get a history listing of all checkins for a specific file (version number, timestamp, file size, user, comment) 3. Check out a specific version of a file by version number. 4. Delete checked-in versions by version number, date range, and/or username. 5. (Optional) Diff 2 versions of a file by version number and return diff in richly formatted format that visually shows changes via color and font effects (strikethru) (I'm thinking of using BeyondCompare for this if not present in a simple version control tool) From thomas at jollans.com Fri Jul 23 16:49:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 22:49:40 +0200 Subject: Light-weight/very-simple version control under Windows using Python? In-Reply-To: <1279917356.23092.1386443203@webmail.messagingengine.com> References: <1279917356.23092.1386443203@webmail.messagingengine.com> Message-ID: <4C4A0064.6050709@jollans.com> On 07/23/2010 10:35 PM, python at bdurham.com wrote: > 1. Use an existing version control utility. There are lots of options > here(!), any recommendations on a light weight, open source one that > xcopy installs under Windows with lots of command line options? You could just go with Mercurial, you know. Very popular, powerful, portable, distributed (so you need no server infrastructure...), free software of course, and written in Python, so interfacing it from Python isn't that hard. It also scales up and down very well, so you can easily change your mind about what you want it to do later if you want to. > 1. Check a file in with optional comment and username; ideally > get a version number that can be used to reference this specific > check-in in the future. trivial. > 2. Get a history listing of all checkins for a specific file > (version number, timestamp, file size, user, comment) trivial as in that's the whole point. > 3. Check out a specific version of a file by version number. Mercurial, and the other distributed VCS, don't technically track changes to files, they track changes to the whole repository (think "directory" if you're not acquainted with DVCS) -- as with any other existing solution you might use, you'll have to think a bit more on its (whatever tool you end up using) terms. > 4. Delete checked-in versions by version number, date range, > and/or username. Do you really want to do this? It's possible, even with Mercurial, but do you really want to create history just to delete it later? Think about it. > 5. (Optional) Diff 2 versions of a file by version number and > return diff in richly formatted format that visually shows > changes via color and font effects (strikethru) (I'm thinking > of using BeyondCompare for this if not present in a simple > version control tool) Yeah, just look for a nice graphical diff tool. KDiff3 springs to mind, I think that's what comes bundled with TortoiseHg on Windows. From gneuner2 at comcast.net Fri Jul 23 17:10:02 2010 From: gneuner2 at comcast.net (George Neuner) Date: Fri, 23 Jul 2010 17:10:02 -0400 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Fri, 23 Jul 2010 15:10:16 +0200, francogrex wrote: >Unfortunately many so-called experts in the field look down >on newbies and mistreat them (in any programming language forum), >forgetting in the process that they were also at a certain time >newbies until some gentle and nice enough teachers took the >trouble to educate them. I don't think it's accurate to say that [some] experts really "scorn" newbies, but I do agree that newbies are occasionally mistreated. One thing newbies have to realize is that on Usenet you are quite likely to be talking to people who were there at the beginning and, of necessity, are largely self educated in whatever the subject matter might be. Many - I'd even say most - are happy to clarify understanding and help with complicated problems, but there is a general expectation that newbies have some basic research skills and that they have tried to solve their problem before asking for help. Unfortunately, there is a small percentage of people who think Usenet and other online forums are for answering homework questions or for digging out of a jam at work. Getting help depends a lot on how the question is asked: strident pleas for quick help or demands for an answer are immediate red flags, but so are questions that begin with "X is crap, why can't I do ..." and even seemingly polite questions that are vague or unfocused (possibly indicating little or no thought behind them) or posts which are directed to a large number of groups (such as this thread we're in now). And, of course, in the language forums, drawing comparisons to non-subject languages is generally considered rude except when done to illustrate a relevant discussion point. Introducing irrelevant comparisons, deliberately proselytizing X in a Y group or doing a lot of complaining about the subject language is bound to attract disdain. As the Internet has grown, the absolute number of people in that "small percentage" has grown as well. A newbie can simply be unlucky enough to ask a question at the wrong time. If there has been a recent rash of problem posts then experts may accidentally respond negatively to a legitimate question. Of course, there are cross-cultural issues too. Many of the technical groups are English-language. English, even when polite, can seem harsh and/or abrupt to non-native speakers. On the whole, moderated groups are more conducive to helping newbies because the moderator(s) filter obvious red flag posts. And, finally, newbies themselves should realize that experts are donating time to answer questions and do get frustrated answering the same questions over and over. They should not be offended by "cold" responses that direct them to FAQs or that just give links to study material. Newbies who need hand-holding or warm welcoming responses filled with detail should go find a tutor. > ... you have the bad "professors" who are freaks >(probably they have a lot of problems at home, their wives >screwing all the males on the block, daughters drug addicts etc) >and want to take their hatred out on you, Unquestionably, there are experts who need their dosages adjusted. But the same can be said for some percentage of other users too. OTOH, newbies often aren't in the position to know who is an expert ... obviously, anyone able to correctly answer their question knows more about that specific issue. That doesn't necessarily qualify the responder as an "expert". Some people get defensive at the edges of their comfort zones. Just some thoughts. YMMV. George From daniel at stutzbachenterprises.com Fri Jul 23 17:26:59 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 23 Jul 2010 16:26:59 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: Message-ID: On Wed, Jul 21, 2010 at 9:47 AM, Daniel Stutzbach < daniel at stutzbachenterprises.com> wrote: > What's new? > ----------- > > - blist.sort() is now *substantially* faster than list.sort() when using > int or float keys (O(n) vs. O(n log n)) > - The sortedset, sortedlist, and sorteddict types have been revamped for > better compatibility with the standard library's types. > - Comprehensive reference documentation is now available at > http://stutzbachenterprises.com/blist/ > - Numerous other speed improvements > Quick addendum: I just uploaded blist 1.2.1 which fixes a compilation error on BSD-derived systems (notably MacOS X). -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Jul 23 17:27:56 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 23 Jul 2010 22:27:56 +0100 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: On Fri, 23 Jul 2010 10:45:32 +0200, Thomas Guettler wrote: > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN > (Resource temporarily unavailable) on write(). My working code looks > like this. But I am unsure how many bytes have been written to the pipe > if I get an EAGAIN IOError. It should be zero; that's how the underlying system calls behave. If any bytes are read/written, the number of bytes are returned. The call only blocks (or fails with EAGAIN if non-blocking I/O is enabled) if it isn't possible to read/write any data. From nobody at nowhere.com Fri Jul 23 17:46:46 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 23 Jul 2010 22:46:46 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > Don't write bare excepts, always catch the error you want and nothing > else. That advice would make more sense if it was possible to know which exceptions could be raised. In practice, that isn't possible, as the documentation seldom provides this information. Even for the built-in classes, the documentation is weak in this regard; for less important modules and third-party libraries, it's entirely absent. From thomas at jollans.com Fri Jul 23 18:04:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 00:04:40 +0200 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C4A11F8.3020905@jollans.com> On 07/23/2010 11:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. > In practice, at least in Python, it tends to be better to work the "other way around": first, write code without exception handlers. Test. If you get an exception, there are really two possible reactions: 1. "WHAT??" => This shouldn't be happening. Rather than catching everything, fix your code, or think it through until you reach conclusion #2 below. 2. "Ah, yes. Of course. I should check for that." => No problem! You're staring at a traceback right now, so you know the exception raised. If you know there should be an exception, but you don't know which one, it should be trivial to create condition in which the exception arises, should it not? Then, you can handle it properly, without resorting to guesswork or over-generalisations. From benjamin.kaplan at case.edu Fri Jul 23 18:04:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 15:04:46 -0700 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, Jul 23, 2010 at 2:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. > You still don't want to use bare excepts.People tend to get rather annoyed when you handle KeyboardInterrupts and SystemExits like you would a UnicodeError. Use Exception if you don't know what exceptions can be raised. From tjreedy at udel.edu Fri Jul 23 18:08:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:08:52 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c494e62$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 7/23/2010 4:10 AM, Steven D'Aprano wrote: > Using exec or friends to avoid the overhead of function calls is like > pushing your car to work to avoid the overhead of having to get in and > out of the car. And, of course, exec *is* a function call (explicitly in 3.x, but somewhere also in the innards of 2.x). Thanks for the laugh of the day. -- Terry Jan Reedy From f2h2d2 at gmail.com Fri Jul 23 18:14:08 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Fri, 23 Jul 2010 15:14:08 -0700 (PDT) Subject: Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ Message-ID: <233c48c4-2eb5-43a6-bedc-7a396d31228a@w12g2000yqj.googlegroups.com> Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ The Qur?an tells us a lot of wonderful things about Jesus. As a result, believers in the Qur?an love Jesus, honour him, and believe in him. In fact, no Muslim can be a Muslim unless he or she believes in Jesus, on whom be peace. The Qur?an says that Jesus was born of a virgin, that he spoke while he was still only a baby, that he healed the blind and the leper by God?s leave, and that he raised the dead by God?s leave. What then is the significance of these miracles? First, the virgin birth. God demonstrates his power to create in every way. God created everyone we know from a man and a woman. But how about Adam, on whom be peace? God created him from neither a man nor a woman. And Eve from only a man, but not a woman. And, finally, to complete the picture, God created Jesus from a woman, but not a man. What about the other miracles? These were to show that Jesus was not acting on his own behalf, but that he was backed by God. The Qur?an specifies that these miracles were performed by God?s leave. This may be compared to the Book of Acts in the Bible, chapter 2, verse 22, where it says that the miracles were done by God to show that he approved of Jesus. Also, note that Jesus himself is recorded in the Gospel of John to have said, ?I can do nothing of my own authority? (5:30). The miracles, therefore, were done not by his own authority, but by God?s authority. What did Jesus teach? The Qur?an tells us that Jesus came to teach the same basic message which was taught by previous prophets from God?that we must shun every false god and worship only the one true God. Jesus taught that he is the servant and messenger of that one true God, the God of Abraham. These Quranic teachings can be compared with the Bible ( Mark 10:18; Matthew 26:39; John 14:28, 17:3, and 20:17) where Jesus teaches that the one he worshipped is the only true God. See also Matthew 12:18; Acts 3:13, and 4:27 where we find that his disciples knew him as Servant of God. The Qur?an tells us that some of the Israelites rejected Jesus, and conspired to kill him, but Allah (God) rescued Jesus and raised him to Himself. Allah will cause Jesus to descend again, at which time Jesus will confirm his true teachings and everyone will believe in him as he is and as the Qur?an teaches about him. Jesus is the Messiah. He is a word from Allah, and a spirit from Him. He is honoured in this world and in the hereafter, and he is one of those brought nearest to Allah. Jesus was a man who spoke the truth which he heard from God. This can be compared with the Gospel According to John where Jesus says to the Israelites: ?You are determined to kill me, a man who has told you the truth that I heard from God? (John 8:40). The Virgin Birth of Jesus Muslims believe in the virgin birth of Jesus. When the angels announced to Mary (peace be upon her) about Allah?s promise that she will have a son, she was surprised, since she was a virgin. ?How can this be?? she thought. She was reminded that it is easy for Allah to create whatever he wills. She said: My Lord! How can I have a child when no mortal hath touched me? He said: So (it will be). Allah createth what He will. If He decreeth a thing, He saith unto it only: Be! and it is (Qur?an 3:47). It is not difficult for Allah to do anything he wants. He can create a child with both human parents or only one. No miracle is beyond His power. After all, He had created Adam (peace be upon him) from neither a man nor a woman. He created the rest of us from both man and woman. What is so hard if Allah decides to create a human being from a woman only? He only commands ?Be!? and it occurs. Some people think that since Jesus, peace be upon him, had no human father then God must be his father. The Qur?an rejects this view. The position of Jesus with Allah is comparable to the position of Adam with Allah. Just because Adam had no human parent does not mean we should call him the Son of God. Lo! the likeness of Jesus with Allah is as the likeness of Adam. He created him from dust, then He said unto him: Be! and he is. (Qur?an 3:59). According to the Qur?an, everyone except Allah are His servants. And they say: the Beneficent hath taken unto Himself a Son. Assuredly ye utter a disastrous thing, whereby almost the heavens are torn, and the earth is split asunder and the mountains fall to ruins, that ye ascribe to the Beneficent a son, when it is not meet for (the Majesty of) the Beneficent that He should chose a son. There is none in the heavens and the earth but cometh unto the Beneficent as a slave. (Qur?an 19:88-93) The Miracles of Jesus According to the Qur?an, Jesus, on whom be peace, performed the following miracles by Allah?s leave: 1. Spoke while he was only a baby. 2. Healed those born blind. 3. Healed the lepers. 4. Revived the dead. 5. Breathed life into a bird made of clay. In the Qur?an Allah quotes Jesus, peace be upon him, as saying: Lo! I come unto you with a sign from your Lord. Lo! I fashion for you out of clay the likeness of a bird, and I breathe into it and it is a bird by Allah?s leave. I heal him who was born blind, and the leper, and I raise the dead, by Allah?s leave. And I announce to you what you eat and what you store up in your houses. Lo! herein verily is a portent for you if you are to be believers. And (I come) confirming that which was before me of the Torah, and to make lawful some of that which was forbidden unto you. I come unto you with a sign from your Lord, so keep your duty to Allah and obey me. Lo! Allah is my Lord and your Lord, so worship Him. That is a straight path. (Qur?an 3: 49-51). Again, in the Qur?an Allah tells us about the situation on the Day of Judgement: In the day when Allah gathers together the messengers and says: What was your response (from mankind)? they say: We have no knowledge. Lo! Thou, only Thou art the Knower of Things Hidden. When Allah says: O Jesus, son of Mary! Remember My favour unto you and unto your mother; how I strengthened you with the holy Spirit, so that you spoke unto mankind in the cradle as in maturity; and how I taught you the ******ure and Wisdom and the Torah and the Gospel; and how you did shape of clay as it were the likeness of a bird by My permission, and did blow upon it and it was a bird by My permission, and you did heal him who was born blind and the leper by My permission . . . (Qur?an 5:109-110) Not all of these miracles are recorded in the canonical gospels, the four gospels contained in the Christian Bible. The fact that Jesus spoke while he was yet a baby is not written anywhere in the Bible. This should not be surprising, because none of the Gospels can claim to recover every single event in the life of Jesus. Instead, the gospel According to John seeks to emphasize that the events were too many to record. Similarly, the miracle of breathing life into a bird made of clay is not attested by the Christian Bible. This too should not make us wonder. It is obvious that the writers of the gospels could write down only the tradition that was available to them. Furthermore, they could not write down everything they knew about Jesus for they were writing on papyrus material that were very limited in length. What is worthy to notice here is that the Prophet Muhammad, may peace and the blessings of Allah be upon him, was honest enough to promulgate this information about Jesus. The religion taught by God through Muhammad would deny the divinity of Jesus. Any human being, therefore, who wished to deny the divinity of Jesus would have tried to belittle Jesus. Since Christians looked upon the miracles of Jesus as a proof of his divinity, we might expect that any human being who tries to deny the divinity of Jesus would not have informed people of miracles not previously known to them. He might have even tried to deny some of the miracles recorded in the canonical gospels. On the other hand, the prophet Muhammad honestly conveyed the message delivered to him from Allah. (May the peace and blessings of Allah be upon him.) Allah tells us the truth without fear. Human beings trying to win followers tell us only what is conducive to winning us over. They usually withhold information that could lead to opposite conclusions. On the other hand, Allah informs us about the miracles of Jesus even if people use this information to support their prior commitment to the doctrine of the divinity of Jesus. Allah does not need to win worshippers. Those who worship Allah does so for their own good. And those who worship false gods do so to their own detriment. What Allah emphasizes, though, is that the miracles of Jesus do not prove he was divine. The miracles he performed were a sign, a proof, that he was God?s messenger. He performed them with God?s help and permission. Those who use his miracles as proof of his divinity would choose to forget the following sayings of Jesus: I can of my own authority do nothing. (John 5:30) They also forget the declaration of Peter: Jesus of Nazareth, a man approved of God among you by miracles and wonders and signs, which God did by him in the midst of you, as ye yourselves know. (Acts 2:22 KJV). These passages suggest that Jesus did not do miracles on his own. These, rather were accomplished by God?s leave. Allah reminds us of this. Jesus also constantly repeated to his audience that the miracles he performed were by God?s leave. ------------------------------------------------------------------------------------------------------------------------------------------------------------ The True Message of Jesus Christ ????? ???? ?????? ?????? ?????? ????? ????? ???? ??????? The True Message of Jesus Christ Auther: Dr. Bilal Philips *******: Introduction Chapter One: The ******ures Authentic Manu******s Contradictions Chapter Two: The Person A Man "Evidence"For Jesus Divinity Chapter Three: The Message Chapter Four: The Way Conclusion Bibliography CHAPTER TWO: JESUS, THE PERSON As has been shown in the previous chapter, the Biblical ******ures, both New and Old Testaments, are unreliable sources and cannot, therefore, be used as an authentic means of knowing the truth about the man called Jesus Christ or about his mission and message. However, a close examination of these ******ures in the light of Qur?aanic verses will reveal some of the truths about Jesus that have survived in the Bible. A Messenger Throughout the Qur?aan, Jesus is identified fundamentally as a Messenger of God. In Chapter as-Saff (61):6, God quotes Jesus as follows: { ?????? ????? ?????? ????? ???????? ???????? ??????????? ?????? ??????? ????? ?????????? ?????????? ?????? ?????? ??????? ???? ??????????? } ?And [remember] when Jesus, son of Mary, said: ?O Children of Israel, I am the messenger of Allaah sent to you, confirming the Torah [which came] before me.? There are many verses in the New Testament supporting the messengership / prophethood of Jesus. The following are only a few: In Matthew 21:11, the people of his time are recorded as referring to Jesus as a prophet: ?And the crowds said, ?This is the prophet Jesus of Nazareth of Galilee.? ? In Mark, 6:4, it is stated that Jesus referred to himself as a prophet: ?And Jesus said to them, ?A prophet is not without honour, except in his own country, and among his own kin, and in his own house.? ? In the following verses, Jesus is referred to as having been sent as a messenger is sent. In Matthew 10:40, Jesus was purported to have said: ?He that receiveth you receiveth me, and he that receiveth me receiveth him that sent me.? In John 17:3, Jesus is also quoted as saying: ?And this is life eternal, that they might know thee the only true God, and Jesus Christ, whom thou hast sent.? [1] ==================== A Man The Qur?aanic revelation not only affirms Jesus? prophethood, but it also clearly denies Jesus? divinity. In Chapter al-Maa?idah, (5): 75, God points out that Jesus ate food, which is a human act, obviously not befitting to God. { ??? ?????????? ????? ???????? ?????? ??????? ???? ?????? ???? ???????? ????????? ????????? ?????????? ?????? ??????????? ?????????? ??????? ?????? ????????? ?????? ????????? ????? ??????? ?????? ???????????} ?The Messiah, Son of Mary, was no more than a messenger and many messengers passed away before him. His mother was exceedingly truthful, and they both ate food. See how I have made the signs clear for them, yet see how they are deluded.? There are numerous accounts in the New Testament which also deny Jesus? divinity. For example, in Matthew 19:17, Jesus responded to one who addressed him as ?O good master?, saying: ?Why callest thou me good? There is none good but one, that is God.? If he rejected being called ?good?, [2] and stated that only God is truly good, he clearly implies that he is not God. In John 14:28, Jesus was saying: ?The Father is greater than I.? By stating that the ?Father? is greater than himself, Jesus distinguishes himself from God. Also in John 20:17, Jesus told Mary Magdalene to tell his followers: ?I ascend unto my Father and your Father; and to my God and your God.? Jesus? reference to God as ?my Father and your Father? further emphasizes the distinction between himself and God. Furthermore, by referring to God as ?his God?, he left no room for anyone to intelligently claim that he was God. Even in some of the writings of Paul, which the Church has taken to be sacred, Jesus is referred to as a ?man?, distinct and different from God. In 1st Timothy, 2:5, Paul writes: ?For there is one God, and one mediator between God and men, the man Christ Jesus.? There are also verses in the Qur?aan which confirm Prophet Muhammad?s humanity, in order to prevent his followers from elevating him to a divine or semi-divine status, as was done to Prophet Jesus. For example, in Chapter al-Kahf (18):110, Allaah instructs the Prophet Muhammad (e) to inform all who hear his message: { ???? ???????? ?????? ?????? ?????????? ?????? ??????? ???????? ?????????? ????? ??????? } ?Say: ?Indeed, I am only a man like you to whom it has been revealed that your God is only one God.? ? In Chapter al-A?raaf (7):187, Allaah also directed Prophet Muhammad (e) to acknowledge that the time of the Judgement is known only to God. {????????????? ???? ?????????? ???????? ?????????? ???? ???????? ????????? ?????? ?????? ??? ??????????? ??????????? ?????? ???? } ?They ask you about the Final Hour: 'When will its apointed time be?? Say: ?Knowledge of it is with my Lord. None can reveal its time besides Him.? ? In the Gospel according to Mark 13:31-32, Jesus is also reported to have denied having knowledge of when the final hour of this world would be, saying: ?Heaven and the earth shall pass away but my word shall not pass away, but of that day or hour no man knoweth, neither the angels in the heaven nor the Son but the Father.? One of the attributes of God is omniscience, knowledge of all things. Therefore, his denial of knowledge of the Day of Judgement is also a denial of divinity, for one who does not know the time of the final hour cannot possibly be God .[3] An Immaculate Conception The Qur?aan confirms the Biblical story of Jesus? virgin birth. However, in the Qur?aanic account of Jesus? birth, Mary was an unmarried maiden whose life was dedicated to the worship of God by her mother. While she was worshipping in a place of religious seclusion, angels came and informed her of her impending pregnancy. { ???? ??????? ???????????? ??? ???????? ????? ????? ??????????? ?????????? ?????? ??????? ??????????? ?????? ????? ???????? ???????? ??? ????????? ?? ?????????? ?????? ??????????????} ?When the angels said: ?O Mary, indeed Allaah gives you glad tidings of a Word from Him, whose name will be the Messiah, Jesus the son of Mary. He will be honored in this world and the next and will be of those close to Allaah.? ? Qur?aan, (3):45 { ??????? ????? ?????? ??????? ??? ?????? ?????? ??????????? ?????? ????? ???????? ????? ???????? ??? ??????? ????? ????? ??????? ?????????? ??????? ???? ???? ????????? } ?She said: ?O my Lord, how can I have a son when no man has touched me?? He said: ?Even so?Allaah creates what He wishes. When He decrees something, He only has to say to it: ?Be!? and it is.? ? Qur?aan, (3): 47 However, the Qur?aan clarifies that Jesus? virgin birth did not change the state of his humanity. His creation was like the creation of Aadam, who had neither father nor mother. { ????? ?????? ?????? ?????? ????? ???????? ????? ???????? ???? ??????? ????? ????? ???? ???? ????????? } ?Surely, the example of Jesus, in Allaah?s sight, is like that of Aadam. He created him from dust and said: ?Be!? and he was.? Qur?aan, (3):59 The Miracles The Qur?aanic account of Jesus? ministry confirms most[4] of his miracles mentioned in the Bible and identifies some not mentioned in the Bible. For example, the Qur?aan informs that Jesus was a messenger of God from his birth, and his first miracle was speaking as a child in the cradle. After Mary had given birth to Jesus, people accused her of fornication. Instead of responding to their accusations, she pointed to her newly born child: { ??????????? ???????? ??????? ?????? ????????? ???? ????? ??? ????????? ???????? ????? ?????? ?????? ????? ???????? ?????????? ??????????? ????????} ?[When] she pointed to him, they asked, ?How can we talk to a child in the cradle?? He [Jesus] said: ?Indeed, I am a servant of Allaah. He gave me the ******ure and made me a prophet.? ? Qur?aan, (19):29-30 Among his other miracles of bringing the dead back to life, healing lepers, and making the blind see, the Qur?aan records another miracle not mentioned in the Bible. Prophet Jesus fashioned birds out of clay, blew on them and they flew away, living birds. But the point which is emphasized throughout the Qur?aan is that whenever Jesus performed a miracle, he informed the people that it was by God?s permission. He made it clear to his followers that he was not doing the miracles by himself, in the same way that the earlier Prophets made it clear to those around them. Unfortunately, those who claim divinity for Jesus, usually hold up his miracles as evidence. However, other prophets were recorded to have done the same or similar miracles in the Old Testament. Jesus fed 5,000 people with five loaves of bread and two fishes. Elisha fed 100 people with twenty barley loaves and a few ears of corn (II Kings 4:44) Jesus healed lepers. Elisha cured Naaman the leper (II Kings 5:14). Jesus caused the blind to see. Elisha caused the blind to see (II Kings 6:17&20). Jesus raised the dead. Elijah did the same (I Kings 17:22). So did Elisha (II Kings 4:34). Even Elisha?s bones could restore the dead (II Kings 13:21). Jesus walked on water. Moses and his people crossed the dead sea (Exodus 14:22). There are also ****s in the New Testament which confirm that Jesus did not act on his own. Jesus is quoted in John 5:30, as saying: ?I can of mine own self do nothing...? and in Luke 11:20, as saying, ?But if I with the finger of God cast out devils, no doubt the Kingdom of God is come upon you.? In Acts 2:22, Paul writes: ?Men of Israel, hear these words: Jesus of Nazareth, a man attested to you by God with mighty works and wonders and signs which God did through him in your midst, as you yourselves know...? Is the message of Prophet Jesus to the worlds or the children of Israel only? http://www.imanway.com/vb/showthread...5500 # post85500 Jesus said, "I am the way and no one up to the father except through me" http://www.imanway.com/vb/showthread...2091 # post92091 The Bible itself shows a lack of Christ's crucifixion and that no one else has the heart http://www.imanway.com/vb/showthread...2282 # post82282 Gospel of Judas (to prove that the heart of Jesus Christ peace be upon him) http://www.imanway.com/vb/showthread.php?t=14478 Do you send Christ to be crucified? http://www.imanway.com/vb/showthread.php?t=2588 Proof of the prophethood of the Prophet Jesus in the Bible http://www.imanway.com/vb/showthread.php?t=2610 Meaning of the word "Christ" http://www.imanway.com/vb/showthread.php?t=2607 Jesus between Islam and Christianity http://www.imanway.com/vb/showthread.php?t=13716 Prophet Jesus peace be upon him (Abdullah) in the Qur'an and the Bible http://www.imanway.com/vb/showthread.php?t=10772 Paul is the invention of modern Christianity and destroyed the original message of Christ http://www.imanway.com/vb/showthread...0361 # post80361 Confessions of the Christians themselves not credible Gospels http://www.imanway.com/vb/showthread.php?t=2626 Christian scholars recognize contradictory texts in the Bible http://www.imanway.com/vb/showthread.php?t=2625 Description of God (exalted above what they attribute) in the Bible http://www.imanway.com/vb/showthread.php?t=2640 Muslims pray as the Prophet Jesus prayed http://www.imanway.com/vb/showthread.php?t=2656 Muslim Peace Xlam prophet Jesus peace be upon him http://www.imanway.com/vb/showthread.php?t=2655 Who is the "Emmanuel" (Emmanuel: God with us means) Christians believe that Jesus Christ but it is only the name of another person, the name of a person shows God's help us and not the fact (that God is with us and us in the form of human being) http://www.imanway.com/vb/showthread.php?t=2653 Who is the "Melchizedek" or the king of peace (not the prophet Jesus given that he mentioned (the guide was born)) http://www.imanway.com/vb/showthread.php?t=2652 Is the Bible the Word of God? (Sheikh Ahmed Deedat God's mercy) http://jamaat.net/bible/BibleIntro.html Recognition of the founder of Christianity distorted (Paul) twisting the Bible http://www.imanway.com/vb/showthread.php?t=2623 Destruction of the principles and instructions of the prophet Jesus peace be upon him Graphically http://www.imanway.com/vb/showthread.php?t=2622 History of the foundation, "Trinity or Triangulation" http://www.imanway.com/vb/showthread.php?t=2621 Random evidence of modern Christian thought http://www.imanway.com/vb/showthread.php?t=2620 Prophet Jesus did not say never "was the right", he was calling to worship God alone (according to the Bible) http://www.imanway.com/vb/showthread.php?t=2619 Erroneous translation of the Bible word for "worship of Christ" http://www.imanway.com/vb/showthread.php?t=2618 What the Bible says the sin of Adam? http://www.imanway.com/vb/showthread...3994 # post83994 Who forgives sins? http://www.imanway.com/vb/showthread.php?t=2617 Lifting of the prophet Jesus does not indicate his divinity http://www.imanway.com/vb/showthread.php?t=2616 What about the previous nations that have not contemporary with Jesus Christ? Has not been invited to the faith and the Trinity Steel http://www.imanway.com/vb/showthread.php?t=2615 Evidence to refute the divinity of Christ, peace be upon him http://www.imanway.com/vb/showthread.php?t=2614 God calls Christ "Abdi (according to the Gospel)" so it is not unreasonable to have his son and call him so http://www.imanway.com/vb/showthread.php?t=2613 May God, "Isa (as they claim)," he prayed for himself? http://www.imanway.com/vb/showthread.php?t=2612 Code is "Da Vinci" http://www.imanway.com/vb/showthread.php?t=15166 Discuss the idea of "text from the Bible" Itallon the divinity of Christ http://www.imanway.com/vb/showthread.php?t=2608 The word "father" in the Bible did not mean the real father of Christ and the directory as stated more than one person http://www.imanway.com/vb/showthread.php?t=2605 Miracles of the Prophet Jesus does not indicate his divinity and the evidence that more than a prophet had miracles http://www.imanway.com/vb/showthread.php?t=2604 Some churches believe in the Prophethood of Jesus Christ peace be upon him http://www.imanway.com/vb/showthread.php?t=2603 Refute the idea of the Trinity scientifically (analogy with water, ice and steam) http://www.imanway.com/vb/showthread.php?t=2602 Logical analysis http://www.imanway.com/vb/showthread.php?t=2599 Discuss the idea of triangulation and the greatest sin http://www.imanway.com/vb/showthread.php?t=2598 How the son of God? (I ask forgiveness from God) http://www.imanway.com/vb/showthread.php?t=2589 How mixed with polytheistic religion Christianity ideas? http://www.imanway.com/vb/showthread.php?t=2586 Questions from a Christian to Sheikh Mohammed Locket http://www.imanway.com/vb/showthread...0169 # post80169 Answer Question: Why do Muslims hate Jesus http://www.imanway.com/vb/showthread.php?t=16150 What Jesus said about the celebration of Christmas? http://www.imanway.com/vb/showthread...2283 # post92283 From tjreedy at udel.edu Fri Jul 23 18:21:06 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:21:06 -0400 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: On 7/23/2010 2:30 PM, SeanMon wrote: > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > x = 0 > def g(): In 3.x, add nonlocal x > x += 1 > return x > return g1 You meant g def f1(): x = 0 def g(): nonlocal x x += 1 return x return g f=f1() print(f()) print(f()) print(f()) print(f()) 1 2 3 4 -- Terry Jan Reedy From tjreedy at udel.edu Fri Jul 23 18:27:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:27:50 -0400 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 7/23/2010 5:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. I intend to bring that issue up on pydev list sometime. But in the meanwhile, once you get an error, you know what it is. You can intentionally feed code bad data and see what you get. And then maybe add a test to make sure your code traps such errors. -- Terry Jan Reedy From db3l.net at gmail.com Fri Jul 23 18:43:31 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 23 Jul 2010 18:43:31 -0400 Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: Neil Cerutti writes: > On 2010-07-23, Jim wrote: >> How can I calculate how much time is between now and the next >> 2:30 am? Naturally I want the system to worry about leap >> years, etc. > > You need the datetime module. Specifically, a datetime and > timedelta object. Although it sounds like the question is to derive the timedelta value, so it's not known up front. That's a little trickier since you'd need to construct the datetime object for "next 2:30 am" to subtract "now" from to get the delta. But that requires knowing when the next day is, thus dealing with month endings. Could probably use the built-in calendar module to help with that though. For the OP, you might also take a peek at the dateutil third party module, and its relativedelta support, which can simplify the creation of the "next 2:30 am" datetime object. Your case could be handled by something like: from datetime import datetime from dateutil.relativedelta import relativedelta target = datetime.now() + relativedelta(days=+1, hour=2, minute=30, second=0, microsecond=0) remaining = target - datetime.now() This ends up with target being a datetime instance for the next day at 2:30am, and remaining being a timedelta object representing the time remaining, at least as of the moment of its calculation. Note that relativedelta leaves fields alone that aren't specified, so since datetime.now() includes down to microseconds, I clear those explicitly). Since you really only need the date, you could also use datetime.date.today() instead as the basis of the calculation and then not need second/microsecond parameters to relativedelta. -- David From lists at cheimes.de Fri Jul 23 19:24:33 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 24 Jul 2010 01:24:33 +0200 Subject: time between now and the next 2:30 am? In-Reply-To: References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: > Your case could be handled by something like: > > from datetime import datetime > from dateutil.relativedelta import relativedelta > > target = datetime.now() + relativedelta(days=+1, hour=2, minute=30, > second=0, microsecond=0) > remaining = target - datetime.now() You don't need the dateutil package for the trick: >>> dt = datetime(2010, 1, 1, 1, 0) >>> str(dt) '2010-01-01 01:00:00' >>> next = dt.replace(hour=2, minute=30) >>> next - dt datetime.timedelta(0, 5400) >>> (next - dt).seconds 5400 >>> dt = datetime(2010, 1, 1, 3, 0) >>> next = dt.replace(hour=2, minute=30) >>> next - dt datetime.timedelta(-1, 84600) >>> (next - dt).seconds 84600 From jim.hefferon at gmail.com Fri Jul 23 19:36:43 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 16:36:43 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Thank you again to everyone; I greatly appreciate the help. I ended with essentially what Christian advised and it seems to work fine. FWIW, below is the rouine (I couldn't figure out how to do it without the kludgy x variable). The background is that this is a Django context processor that makes available the time until the next 2:30 because that is when the web site is rebuilt. I hope the code isn't too much mangled by the online editor, Jim ............................................................................. import time, datetime from django.conf import settings WARNING_MINS=10 # How many mins before update time should start warning? WARNING_SECS=60*WARNING_MINS def current_time_processor(req): """Add current time information to the Context """ # Calculate time until the next 2:30 am x=datetime.datetime(2010,7,23) # actual date doesn't matter? dt_localtime=x.fromtimestamp(time.time()) dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=settings.UPDATE_TIME_MINS,second=0,microsecond=0) dd_diff=dt_twothirty-dt_localtime secs_until_twothirty=dd_diff.seconds if secs_until_twothirty Hey Everyone, I had a question, programming sockets, what are the things that would degrade performance and what steps could help in a performance boost? I would also appreciate being pointed to some formal documentation or article. I am new to this. Warm regards, Nav From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:52 +0000 (UTC) Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: > Is there a more idiomatic way of loading in a configuration file > that's python code ... Is it really a good idea to have a configuration language that?s Turing- complete? From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:53 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: In message , Tim Harig wrote: > On 2010-07-05, Lawrence D'Oliveiro > wrote: >> >> I?ve never come across any system where you could string together >> multiple GUI apps, or even multiple GUI operations in the same app, in >> any sensible or effective way at all. GUIs just aren???t designed to work >> that way. > > You can if they are designed to be used externally. COM is an execellent > example of this ... But COM is an IPC architecture, which has nothing to do with GUI apps. Conflating the two leads to precisely the sort of inflexibility that is characteristic of GUIs. For example, things happening with the GUI on-screen while a script is running that are at best distracting to the user, or at worst vulnerable to breaking if the user accidentally presses a key or clicks in the wrong place. > I have worked with complex business process automation centered around > Excel and I have automated some really ugly AJAX style web based > applications that would only work inside of IE6 by accessing IE through > its COM interface. If those apps really were using AJAX, then why did you need to script a Web browser at all? You could just make direct HTTP requests to retrieve the data. > Automating GUI applications requires interal access to the program through > some kind of interface ... Some kind of interface that bypasses the GUI. This is why so many Open Source apps are structured as a GUI front end to a completely separate command-line tool (e.g. MPlayer). That way a script can use the latter without having to go through the former. From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:54 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: In message , Robert Kern wrote: > There are also utilities for mounting ISOs directly without burning them > to a physical disk. You need special utilities to do this?? From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:55 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> Message-ID: In message , Michael Torrie wrote: > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. Just be careful about properly escaping any special characters in the file names. See my other thread about escaping data, where some respondents have expressed a strong allergy to any form of embedding one language inside another. From robert.kern at gmail.com Fri Jul 23 20:31:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jul 2010 19:31:37 -0500 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> There are also utilities for mounting ISOs directly without burning them >> to a physical disk. > > You need special utilities to do this?? On at least some versions of Windows, Yes. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From python at mrabarnett.plus.com Fri Jul 23 20:52:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 01:52:10 +0100 Subject: time between now and the next 2:30 am? In-Reply-To: <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Message-ID: <4C4A393A.6050807@mrabarnett.plus.com> Jim wrote: > Thank you again to everyone; I greatly appreciate the help. I ended > with essentially what Christian advised and it seems to work fine. > FWIW, below is the rouine (I couldn't figure out how to do it without > the kludgy x variable). The background is that this is a Django > context processor that makes available the time until the next 2:30 > because that is when the web site is rebuilt. > > I hope the code isn't too much mangled by the online editor, > Jim > > ............................................................................. > > import time, datetime > from django.conf import settings > > WARNING_MINS=10 # How many mins before update time should start > warning? > WARNING_SECS=60*WARNING_MINS > > def current_time_processor(req): > """Add current time information to the Context > """ > # Calculate time until the next 2:30 am > x=datetime.datetime(2010,7,23) # actual date doesn't matter? > dt_localtime=x.fromtimestamp(time.time()) > Why not: dt_localtime = datetime.datetime.now() > dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=settings.UPDATE_TIME_MINS,second=0,microsecond=0) You're changing the time of day, but not the date. You might want to add a day to the shutdown time if it's earlier than the current time. > dd_diff=dt_twothirty-dt_localtime > secs_until_twothirty=dd_diff.seconds > if secs_until_twothirty w='This site shuts down every night at %02d:%02d local time, > to refresh the database. There are fewer than %d minutes until that > shutdown. If you have not completed your work when the site shuts > down then you will lose your work.' % > (settings.UPDATE_TIME_HOURS,settings.UPDATE_TIME_MINS,WARNING_MINS,) > else: > w=None > return {'CURRENT_LOCAL_TIME': time.asctime(time.localtime()), > 'TIME_WARNING':w} From ben+python at benfinney.id.au Fri Jul 23 20:53:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 24 Jul 2010 10:53:35 +1000 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <87mxth66pc.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: > > > Is there a more idiomatic way of loading in a configuration file > > that's python code ... > > Is it really a good idea to have a configuration language that?s Turing- > complete? I think not. Configuration files should be read as data; they should be declarative only, not executable languages. That way, a different program can read and parse them without having to be a parser for an entire programming language. As illustration of this point, I present the chronic headaches of the Python ?setup.py? file. It tries to be both setup program *and* configuration file, with the consequence that in the general case it's impossible to get configuration information without executing the setup program. Recent work (lots of it!) by the Distutils team has gone into separating the concerns so that the configuration data is all in a non-executable data file; that work is ongoing, and it's been a hard lesson to learn. -- \ ?If [a technology company] has confidence in their future | `\ ability to innovate, the importance they place on protecting | _o__) their past innovations really should decline.? ?Gary Barnett | Ben Finney From python at mrabarnett.plus.com Fri Jul 23 21:04:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 02:04:51 +0100 Subject: Socket performance In-Reply-To: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> Message-ID: <4C4A3C33.80407@mrabarnett.plus.com> Navkirat Singh wrote: > Hey Everyone, > > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? I > would also appreciate being pointed to some formal documentation or > article. > > I am new to this. > Interleaving processing and sending/receiving might reduce throughput because when you're processing the socket is idle (depending on how much buffering there is). You could do the socket stuff in another thread so that it's not waiting for the processing to finish while there is data available, and use a queue to transfer the data between that thread and the processing thread. From navkirats at gmail.com Fri Jul 23 22:22:53 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sat, 24 Jul 2010 07:52:53 +0530 Subject: Socket performance In-Reply-To: <4C4A3C33.80407@mrabarnett.plus.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> <4C4A3C33.80407@mrabarnett.plus.com> Message-ID: <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> Thanks for the info : ). I will look into it ! Right now I am having a strange problem. I am trying to use cookies and the import function returns an error: I am using python 3: from http import cookies importError: No module named http Is it my configuration or has something changed since the documentation was written? Sorry I might be asking too many question, I am pretty new to this stuff and kinda feel lost here and there : ( Thanks, Nav On 24-Jul-2010, at 6:34 AM, MRAB wrote: > Navkirat Singh wrote: >> Hey Everyone, >> I had a question, programming sockets, what are the things that >> would degrade performance and what steps could help in a >> performance boost? I would also appreciate being pointed to some >> formal documentation or article. >> I am new to this. > Interleaving processing and sending/receiving might reduce throughput > because when you're processing the socket is idle (depending on how > much > buffering there is). You could do the socket stuff in another thread > so > that it's not waiting for the processing to finish while there is data > available, and use a queue to transfer the data between that thread > and > the processing thread. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From darkrho at gmail.com Fri Jul 23 22:42:28 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 23 Jul 2010 22:42:28 -0400 Subject: understanding the mro (long) Message-ID: TL;DR: if you want to stay sane, don't inherit two classes that share same inheritance graph I recently got puzzled by a bug from a legacy lib (ClientForm) which have this code: class ParseError(sgmllib.SGMLParseError, HTMLParser.HTMLParseError, ): pass And fails because takes __init__ from sgmllib and __str__ from HTMLParser where __str__ uses attributes set by HTMLParser's init. At first look, I thought was just matter to swap the inherit classes. But a deeper look take me to the python's mro reading: http://www.python.org/download/releases/2.3/mro/ And to reproduce the error I code this: class Foo(object): def __init__(self, msg): self.msg = msg def __str__(self): return 'Foo: ' + self.msg class Bar(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return 'Bar: ' + self.msg class A(Exception): pass class B(RuntimeError): pass class AFoo(A, Foo): pass class ABar(A, Bar): pass class BFoo(B, Foo): pass class BBar(B, Bar): pass print AFoo('ok') # ok print ABar('ok') # Bar: ok print BFoo('ok') # ok print BBar('fail') # AttributeError: ... not attribute 'msg' # EOF After running the code I was still confused. So I read carefully again the mro stuff. And ended doing this inheritance tree: object (__init__, __str__) | \ | Foo (__init__, __str__) | BaseException (__init__, __str__) | | | Exception (__init__) / | \ A | Bar (__init__, __str__) | StandardError (__init__) | | | RuntimeError (__init__) / B Then I figure out the method resolution following the inheritance graph: * AFoo(A, Foo): __init__ from Exception __str__ from BaseException * ABar(A, Bar): __init__ from Bar __str__ from Bar * BFoo(B, Foo): __init__ from RuntimeError __str__ from BaseException * BBar(B, Bar): __init__ from RuntimeError __str__ from Bar Finally everything make sense. And make think about be careful when doing multiple inheritance. Any thoughts? ~Rolando From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 22:44:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 02:44:15 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c495b50$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4a537e$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 09:22:16 -0700, Stephen Hansen wrote: > On 7/23/10 2:05 AM, Steven D'Aprano wrote: >> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: >> >>> On 7/22/10 7:47 PM, wheres pythonmonks wrote: >> [...] >>>> The truth is that I don't intend to use these approaches in anything >>>> serious. However, I've been known to do some metaprogramming from >>>> time to time. >>> >>> Depending on how you define "metaprogramming", Python is pretty >>> notoriously ill-suited towards the task (more, its basically >>> considered a feature it doesn't let you go there) -- or, it allows you >>> to do vast amounts of stuff with its few dark magic hooks. I've never >>> had a satisfying definition of metaprogramming that more then 50% of >>> any group agree with, so I'm not sure which you're looking for. :) >> >> I disagree strongly at your characterisation that Python is notorious >> for being ill-suited towards metaprogramming. I'd say the complete >> opposite -- what is considered dark and scary metaprogramming tasks in >> other languages is considered too ordinary to even mention in Python. > > I rather think you missed my point entirely. > > 'Depending on how you define "metaprogramming"' > > The 'Depending' was the most important part of that sentence. Well, I suppose some folks might like to define words any way they like, so that "cat" means a reptile with no legs and "lunch time" means the thing you do in the shower, but I prefer to stick with common definitions. And the common definition of metaprogramming is that it is "programming about programming" -- programming where the data you are processing is itself programming code and data structures. http://en.wikipedia.org/wiki/Metaprogramming I did not miss your proviso, nor did I miss the fact that there are some metaprogramming techniques that Python is not very good at, such as runtime modification of syntax. I wrote: "It is true that other languages (like Lisp, or Forth) allow you to write your own syntax. That's incredibly powerful, but it also has serious costs. If you can define your own syntax, that means every piece of code you look at is potentially a different language." But what makes you think that the OP is trying to do that? There's nothing in his comments to indicate that to me. Perhaps I missed something. > You go on > to talk about runtime modification of classes and the like. That, Python > lets you do quite readily, and then go on to do crazy amounts of without > any significant effort. > > That's one definition of metaprogramming. That one Python does well. No, it's not a *definition* of metaprogramming. It is an aspect of metaprogramming, in the same way that roasting food is not a definition of cooking, it is one out of many cooking techniques. > The other involves things like macros, or things where you basically > write a new sub-language in the language itself to achieve some commonly > desired task more efficiently (or just more succinctly). That's another > definition of metaprogramming: where its not so much structures > (classes, etc) which are modified at runtime (which Python lets you do > readily), but the syntax or semantics of the language itself. That > Python isn't game for. You can't modify Python's syntax at runtime, but you can create DSLs in Python quite readily provided you accept the limitation of Python's syntax. There was even a tutorial at PyCon about it: http://us.pycon.org/2010/tutorials/jensen_languages/ Although he doesn't use the term "DSL" anywhere in his essay, Guido's essay on creating graphs in Python essentially describes a DSL for graphs: http://www.python.org/doc/essays/graphs/ In the Python Cookbook, Paul Dubois also gives an "application-specific- language" for graphs in a section called "Using Python Itself as a Little Language". Yes, it's limited to Python syntax, but it's still a DSL. And of course there are applications like Cheetah: http://www.cheetahtemplate.org/ Python doesn't go all the way like Forth or Lisp, but there aren't very many metaprogramming techniques you can't do it in. -- Steven From python at mrabarnett.plus.com Fri Jul 23 22:48:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 03:48:39 +0100 Subject: Socket performance In-Reply-To: <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> <4C4A3C33.80407@mrabarnett.plus.com> <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> Message-ID: <4C4A5487.9030900@mrabarnett.plus.com> Navkirat Singh wrote: > Thanks for the info : ). I will look into it ! Right now I am having a > strange problem. I am trying to use cookies and the import function > returns an error: > > I am using python 3: > > from http import cookies > > *importError:* No module named http > > Is it my configuration or has something changed since the documentation > was written? Sorry I might be asking too many question, I am pretty new > to this stuff and kinda feel lost here and there : ( > It works for me (Python 3.1.2). From invalid at invalid.invalid Fri Jul 23 23:05:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 24 Jul 2010 03:05:12 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 2010-07-24, Lawrence D'Oliveiro wrote: > In message , Robert Kern > wrote: > >> There are also utilities for mounting ISOs directly without burning >> them to a physical disk. > > You need special utilities to do this?? Not if the OS and VFS are competently designed. In Linux all you need to do is this: mount -o loop /path/to/file.iso /mount/point Apparently you've got to jump through all sorts of hoops using 3rd party software to do something analgous in MS Windows. -- Grant From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 23:09:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 03:09:06 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4a5951$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 22:46:46 +0100, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. Aside: that's an awfully sweeping generalisation for all third-party libraries. Yes, the documentation is sometimes weak, but that doesn't stop you from being sensible. Catching any exception, no matter what, whether you've heard of it or seen it before or not, is almost never a good idea. The two problems with bare excepts are: * They mask user generated keyboard interrupts, which is rude. * They hide unexpected errors and disguise them as expected errors. You want unexpected errors to raise an exception as early as possible, because they probably indicate a bug in your code, and the earlier you see the exception, the easier it is to debug. And even if they don't indicate a bug in your code, but merely an under- documented function, it's still better to find out what that is rather than sweep it under the carpet. You will have learned something new ("oh, the httplib functions can raise socket.error as well can they?") which makes you a better programmer, you have the opportunity to improve the documentation, you might want to handle it differently ("should I try again, or just give up now, or reset the flubbler?"). If you decide to just mask the exception, rather than handle it in some other way, it is easy enough to add an extra check to the except clause. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 23:15:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 03:15:31 GMT Subject: understanding the mro (long) References: Message-ID: <4c4a5ad3$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 22:42:28 -0400, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph > > I recently got puzzled by a bug from a legacy lib (ClientForm) which > have this code: [...] > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? Wow. Nice work, thanks for taking the time for documenting this publicly. -- Steven From eldiener at tropicsoft.invalid Fri Jul 23 23:17:19 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 23 Jul 2010 23:17:19 -0400 Subject: Multiple versions of Python coexisting in the same OS Message-ID: Are there any documents about multiple versionsof Python coexisting in the same OS ( Windows in my case ) and what pitfalls to look out for ? I have already run into a number of them. I installed Python 2.7 and 3.1.2 into completely folders, but immediately ran into serious problems executing a Python script. The first problem is that just invoking Python will start whichever version is first in the PATH, and this is true from the command line or internally in a Python script. The second problem is that invoking a script ( some xxx.py ) will start whichever version of Python is associated with the .py extension. The third problem is if some software expects its scripts, which it puts in some Python subdirectory to be in the PATH. There may be other considerations but overall having to versions coexisting has turned out to be a big headache involving both changes in the PATH and in the .py association. Does anybody know of other things to look out for ? From zzbbaadd at aol.com Sat Jul 24 00:27:45 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Fri, 23 Jul 2010 21:27:45 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> Message-ID: <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> On Jul 23, 12:06?pm, Emmy Noether wrote: > Title ? Portable LISP interpreter > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > Publication Date ? ? ? ?1978 May 31 > OSTI Identifier OSTI ID: 7017786 > Report Number(s) ? ? ? ?UCRL-52417 > DOE Contract Number ? ? W-7405-ENG-48 > Resource Type ? Technical Report > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > Lab. > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > PROGRAMMING LANGUAGES > Description/Abstract ? ?A portable LISP interpreter that includes all the > major list-processing functions is described. A complete, annotated > listing of the program's code, written in PASCAL, is included. > Country of Publication ?United States > Language ? ? ? ?English > Format ?Medium: X; Size: Pages: 21 > Availability ? ?Dep. NTIS, PC A02/MF A01. > System Entry Date ? ? ? 2008 Feb 12 Is this available online? If only in hardcopy form, do they lend it out? From benjamin.kaplan at case.edu Sat Jul 24 00:28:55 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 21:28:55 -0700 Subject: understanding the mro (long) In-Reply-To: References: Message-ID: On Fri, Jul 23, 2010 at 7:42 PM, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph > > I recently got puzzled by a bug from a legacy lib (ClientForm) > which have this code: > > ? ?class ParseError(sgmllib.SGMLParseError, > ? ? ? ? ? ? ? ? ? ? HTMLParser.HTMLParseError, > ? ? ? ? ? ? ? ? ? ? ): > ? ? ? ?pass > > And fails because takes __init__ from sgmllib and __str__ from HTMLParser > where __str__ uses attributes set by HTMLParser's init. > > At first look, I thought was just matter to swap the inherit classes. > But a deeper > look take me to the python's mro reading: > http://www.python.org/download/releases/2.3/mro/ > > And to reproduce the error I code this: > > class Foo(object): > ? ?def __init__(self, msg): > ? ? ? ?self.msg = msg > > ? ?def __str__(self): > ? ? ? ?return 'Foo: ' + self.msg > > class Bar(Exception): > ? ?def __init__(self, msg): > ? ? ? ?self.msg = msg > > ? ?def __str__(self): > ? ? ? ?return 'Bar: ' + self.msg > > class A(Exception): > ? ?pass > > class B(RuntimeError): > ? ?pass > > class AFoo(A, Foo): pass > class ABar(A, Bar): pass > > class BFoo(B, Foo): pass > class BBar(B, Bar): pass > > print AFoo('ok') # ok > print ABar('ok') # Bar: ok > > print BFoo('ok') # ok > print BBar('fail') # AttributeError: ... not attribute 'msg' > > # EOF > > After running the code I was still confused. So I read carefully again > the mro stuff. And ended doing this inheritance tree: > > ? ? ? object (__init__, __str__) > ? ? ? ? ?| ? ?\ > ? ? ? ? ?| ? ?Foo (__init__, __str__) > ? ? ? ? ?| > ?BaseException (__init__, __str__) > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ?Exception (__init__) > ? ? / ? ?| ? ? \ > ? ?A ? ?| ? ? Bar (__init__, __str__) > ? ? ? ? ?| > ?StandardError (__init__) > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ? ? ?| > ? ?RuntimeError (__init__) > ? ?/ > ? B > > Then I figure out the method resolution following the inheritance graph: > ?* AFoo(A, Foo): > ? ?__init__ from Exception > ? ?__str__ ?from BaseException > > ?* ABar(A, Bar): > ? ?__init__ from Bar > ? ?__str__ ?from Bar > > ?* BFoo(B, Foo): > ? ?__init__ from RuntimeError > ? ?__str__ ?from BaseException > > ?* BBar(B, Bar): > ? ?__init__ from RuntimeError > ? ?__str__ ?from Bar > > > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? > Two things: First of all, avoid multiple inheritance if you can. It's usually unnecessary in Python because of duck typing (unless you need to inherit the actual behavior and not just a list of methods), and as you've noticed, the MRO gets messy. And second, not to in any way diminish the work you did tracing out the inheritance tree and working through the inheritance, but Python has easier ways of doing it :) >>> BBar.__mro__ (, , , , , , , ) >>> '__str__' in BBar.__dict__ False >>> '__str__' in Bar.__dict__ True >>> for cls in BBar.__mro__ : if '__str__' in cls.__dict__ : print cls break > ~Rolando > -- > http://mail.python.org/mailman/listinfo/python-list > From kushal.kumaran+python at gmail.com Sat Jul 24 00:32:08 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 24 Jul 2010 10:02:08 +0530 Subject: non-blocking IO EAGAIN on write In-Reply-To: <8at354F51tU1@mid.individual.net> References: <8at354F51tU1@mid.individual.net> Message-ID: On Fri, Jul 23, 2010 at 2:15 PM, Thomas Guettler wrote: > Hi, > > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) > on write(). My working code looks like this. But I am unsure how many bytes have been written to the > pipe if I get an EAGAIN IOError. Up to now I retry with the same chunk. > > If I get EAGAIN can I just sleep, and then retry with the same data chunk? > > pipe=subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=-1) > fcntl.fcntl(pipe.stdin, fcntl.F_SETFL, os.O_NONBLOCK) > .... > chunk_size=1024 > ? ? ? ?while select.select([], [pipe.stdin], [], 5): Please read the documentation of the select.select function. You are not using it correctly. After the call returns, you need to check whether the descriptor you are interested in is actually ready. If select reaches your timeout, it will simply return three empty lists, and your write will get EAGAIN. In general, after select has told you a descriptor is ready, the first write after that should always succeed. BTW, from the documentation of file objects, it seems write always wants to write the entire string you give it, since it does not return anything. In that case, you might want to get the descriptor for the file object (using pipe.fileno()) and use that for writing. > -- regards, kushal From darkrho at gmail.com Sat Jul 24 00:43:19 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Sat, 24 Jul 2010 00:43:19 -0400 Subject: understanding the mro (long) In-Reply-To: References: Message-ID: On Sat, Jul 24, 2010 at 12:28 AM, Benjamin Kaplan wrote: [...] > > And second, not to in any way diminish the work you did tracing out > the inheritance tree and working through the inheritance, but Python > has easier ways of doing it :) > >>>> BBar.__mro__ > (, , 'exceptions.RuntimeError'>, , '__main__.Bar'>, , 'exceptions.BaseException'>, ) Yes, actually I looked at __mro__ to confirm that I was right. >>>> '__str__' in BBar.__dict__ > False >>>> '__str__' in Bar.__dict__ > True I see! I couldn't figure out how to find if a method is defined within given class. >>>> for cls in BBar.__mro__ : > ? ? ? ?if '__str__' in cls.__dict__ : > ? ? ? ? ? ? ? ?print cls > ? ? ? ? ? ? ? ?break > > > This is good one! It could save time figuring out where a method comes from. Anyway, was a good exercise to figure out the mro by hand :) Thanks for your comments Benjamin and Steven. ~Rolando From usernet at ilthio.net Sat Jul 24 01:24:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 24 Jul 2010 05:24:18 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 2010-07-24, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: > >> On 2010-07-05, Lawrence D'Oliveiro >> wrote: >>> >>> I???ve never come across any system where you could string together >>> multiple GUI apps, or even multiple GUI operations in the same app, in >>> any sensible or effective way at all. GUIs just aren???t designed to work >>> that way. >> >> You can if they are designed to be used externally. COM is an execellent >> example of this ... > > But COM is an IPC architecture, which has nothing to do with GUI apps. Not exactly. IPC allows you to send and receive information from another process; but, it doesn't give you internal access to the process. COM is much closer to an OO style of RPC. > Conflating the two leads to precisely the sort of inflexibility that is > characteristic of GUIs. For example, things happening with the GUI on-screen > while a script is running that are at best distracting to the user, or at > worst vulnerable to breaking if the user accidentally presses a key or > clicks in the wrong place. COM object have a visibility property that determines whether or not they are displayed to the user. >> I have worked with complex business process automation centered around >> Excel and I have automated some really ugly AJAX style web based >> applications that would only work inside of IE6 by accessing IE through >> its COM interface. > > If those apps really were using AJAX, then why did you need to script a Web > browser at all? You could just make direct HTTP requests to retrieve the > data. The first and primary reason was that the application server required a client side SSL certificate. We didn't have access to a certificate that we could get to work Python's SSL or HTTPS modules. The second reason was that we had considerable difficulty figuring out how the server side interfaces worked from the slew of horrible Javascript. You really have to have seen it to know just what a mess this really was. Every call was literally wrapped in dozens of almost identical wrapper functions that you had to follow to attempt to figure out what was going on. Parts of the rendered form which looked like text field entries really weren't until a series of events took place to change them. They were used as flags indicating the state of various information. I really can't overstate how ugly this application really was. I was working on trying to figure out the serverside interface while my partner was trying to get an open SSL connection. By the time he gave up trying to convert our key to something we could use, I decided it was simpler just to use COM and internet explorer. It worked pretty well. >> Automating GUI applications requires interal access to the program through >> some kind of interface ... > > Some kind of interface that bypasses the GUI. This is why so many Open > Source apps are structured as a GUI front end to a completely separate > command-line tool (e.g. MPlayer). That way a script can use the latter > without having to go through the former. Which is great where the a separate backend exists. That isn't the case for a *huge* number of GUI applications; but, You don't always get to pick what you are going to need to automate. From michele.simionato at gmail.com Sat Jul 24 02:32:35 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 23 Jul 2010 23:32:35 -0700 (PDT) Subject: understanding the mro (long) References: Message-ID: On Jul 24, 4:42?am, Rolando Espinoza La Fuente wrote: > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? > > ~Rolando I am not fond of multiple inheritance either and I wrote at length about the dangers of it. If you do not know it already, you may be interested in reading my "Mixins considered harmful" series http://www.artima.com/weblogs/viewpost.jsp?thread=246341 (together with any blog posts on super and related subjects). From dummey at gmail.com Sat Jul 24 02:33:55 2010 From: dummey at gmail.com (Dummey) Date: Fri, 23 Jul 2010 23:33:55 -0700 (PDT) Subject: 'as' keyword - when/how to use it Message-ID: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> I am having the hardest time trying to find documentation on proper use of the 'as' keyword (aside from . I initially thought that I would be allowed to do something such as: import shared.util as util The as statement seems to be causing a lot of ''module' object has no attribute'. Is it safe to assume that this is not the way to use it? From nagle at animats.com Sat Jul 24 03:11:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 00:11:09 -0700 Subject: time between now and the next 2:30 am? In-Reply-To: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> Message-ID: <4c4a921e$0$1661$742ec2ed@news.sonic.net> On 7/23/2010 10:01 AM, Jim wrote: > How can I calculate how much time is between now and the next 2:30 > am? Naturally I want the system to worry about leap years, etc. > > Thanks, > Jim DAYSECS = 24*60*60 GOALSECS = (2*60 + 30)*60 now = (GOALSECS + DAYSECS - (int(time.time()) % DAYSECS)) % DAYSECS This is for UT; the adjustment for timezone should be obvious. John Nagle From lacrima.maxim at gmail.com Sat Jul 24 03:47:04 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sat, 24 Jul 2010 00:47:04 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? Message-ID: Hi! I have two super classes: class SuperClass1(object): def __init__(self, word): print word class SuperClass2(object): def __init__(self, word, word2): print word, word2 Also I have subclass of these classes: class SubClass(SuperClass1, SuperClass2): def __init__(self): pass I have two questions. 1) Inside __init__ of SubClass how can I firstly call __init__ of SuperClass1, and then __init__ of SuperClass2, using builtin super() function. 2) Why should I use super() at all, if it is very easy to call methods of super class like this: class SubClass(SuperClass1, SuperClass2): def __init__(self): SuperClass1.__init__(self, 'Python') SuperClass2.__init__(self, 'Hello', 'world') Thanks in advance. From raymond.hettinger at gmail.com Sat Jul 24 04:20:40 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Sat, 24 Jul 2010 01:20:40 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: Message-ID: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> On Jul 24, 12:47?am, Lacrima wrote: > Hi! > > I have two super classes: > > class SuperClass1(object): > ? ? def __init__(self, word): > ? ? ? ? print word > > class SuperClass2(object): > ? ? def __init__(self, word, word2): > ? ? ? ? print word, word2 > > Also I have subclass of these classes: > > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self): > ? ? ? ? pass > > I have two questions. > 1) Inside __init__ of SubClass how can I firstly call __init__ of > SuperClass1, and then __init__ of SuperClass2, using builtin super() > function. I would write it like this: class SuperClass1(object): def __init__(self, **kwds): word = kwds.pop('word') print word super(SuperClass1, self).__init__(**kwds) class SuperClass2(object): def __init__(self, **kwds): word1 = kwds.pop('word1') word2 = kwds.pop('word2') print word1, word2 super(SuperClass2, self).__init__(**kwds) class SubClass(SuperClass1, SuperClass2): def __init__(self, **kwds): super(SubClass, self).__init__(**kwds) SubClass(word='Python', word1='Hello', word2='World') > 2) Why should I use super() at all, if it is very easy to call methods > of super class like this: > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self): > ? ? ? ? SuperClass1.__init__(self, 'Python') > ? ? ? ? SuperClass2.__init__(self, 'Hello', 'world') That works just fine in this case. The challenge arises in "diamond diagrams" such as A->B A->C B->D C->D where both B and C are written independently of D and both need to call A's __init__ but that method should only be called once (not once by B and again by C). In that case, the super() pattern shown above will let each parent's method be called exactly once and guarantee that parents are called before grandparents and guarantee that the left-to-right ordering of multiple bases is respected. Raymond From franco at grex.org Sat Jul 24 04:56:42 2010 From: franco at grex.org (francogrex) Date: Sat, 24 Jul 2010 10:56:42 +0200 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: In article , gneuner2 at comcast.net says... >I don't think it's accurate to say that [some] experts really "scorn" >newbies, but I do agree that newbies are occasionally mistreated. > >One thing newbies have to realize is that on Usenet you are quite >likely to be talking to people who were there at the beginning and, of >necessity, are largely self educated in whatever the subject matter >might be. Many - I'd even say most - are happy to clarify >understanding and help with complicated problems, but there is a >general expectation that newbies have some basic research skills and >that they have tried to solve their problem before asking for help. > >Unfortunately, there is a small percentage of people who think Usenet >and other online forums are for answering homework questions or for >digging out of a jam at work. Getting help depends a lot on how the >question is asked: strident pleas for quick help or demands for an >answer are immediate red flags, but so are questions that begin with >"X is crap, why can't I do ..." and even seemingly polite questions >that are vague or unfocused (possibly indicating little or no thought >behind them) or posts which are directed to a large number of groups >(such as this thread we're in now). > >And, of course, in the language forums, drawing comparisons to >non-subject languages is generally considered rude except when done to >illustrate a relevant discussion point. Introducing irrelevant >comparisons, deliberately proselytizing X in a Y group or doing a lot >of complaining about the subject language is bound to attract disdain. > >As the Internet has grown, the absolute number of people in that >"small percentage" has grown as well. A newbie can simply be unlucky >enough to ask a question at the wrong time. If there has been a >recent rash of problem posts then experts may accidentally respond >negatively to a legitimate question. > >Of course, there are cross-cultural issues too. Many of the technical >groups are English-language. English, even when polite, can seem >harsh and/or abrupt to non-native speakers. > >On the whole, moderated groups are more conducive to helping newbies >because the moderator(s) filter obvious red flag posts. > >And, finally, newbies themselves should realize that experts are >donating time to answer questions and do get frustrated answering the >same questions over and over. They should not be offended by "cold" >responses that direct them to FAQs or that just give links to study >material. Newbies who need hand-holding or warm welcoming responses >filled with detail should go find a tutor. > > >> ... you have the bad "professors" who are freaks >>(probably they have a lot of problems at home, their wives >>screwing all the males on the block, daughters drug addicts etc) >>and want to take their hatred out on you, > >Unquestionably, there are experts who need their dosages adjusted. But >the same can be said for some percentage of other users too. > >OTOH, newbies often aren't in the position to know who is an expert >... obviously, anyone able to correctly answer their question knows >more about that specific issue. That doesn't necessarily qualify the >responder as an "expert". Some people get defensive at the edges of >their comfort zones. > > >Just some thoughts. YMMV. >George Yes I agree, you expressed the thought better than I did. Then let's not go on with this thread any further and let the newsgroups carry on programming language support and discussions. Thanks From tjreedy at udel.edu Sat Jul 24 04:57:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jul 2010 04:57:09 -0400 Subject: 'as' keyword - when/how to use it In-Reply-To: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> Message-ID: On 7/24/2010 2:33 AM, Dummey wrote: > I am having the hardest time trying to find documentation on proper > use of the 'as' keyword (aside from . I initially thought that I would > be allowed to do something such as: > > import shared.util as util > > The as statement seems to be causing a lot of ''module' object has no > attribute'. Is it safe to assume that this is not the way to use it? Give an example of real code raising an exception when importing from the stdlib and the corresponding error traceback in its entirety. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Jul 24 06:25:07 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 11:25:07 +0100 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 24/07/2010 04:17, Edward Diener wrote: > Are there any documents about multiple versionsof Python coexisting in > the same OS ( Windows in my case ) and what pitfalls to look out for ? I > have already run into a number of them. I installed Python 2.7 and 3.1.2 > into completely folders, but immediately ran into serious problems > executing a Python script. > > The first problem is that just invoking Python will start whichever > version is first in the PATH, and this is true from the command line or > internally in a Python script. > > The second problem is that invoking a script ( some xxx.py ) will start > whichever version of Python is associated with the .py extension. > > The third problem is if some software expects its scripts, which it puts > in some Python subdirectory to be in the PATH. > > There may be other considerations but overall having to versions > coexisting has turned out to be a big headache involving both changes in > the PATH and in the .py association. > > Does anybody know of other things to look out for ? I found this only yesterday and found it extremely helpful, find the post by Gabriel Genellina. http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx HTH. Mark Lawrence From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 06:44:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 10:44:40 GMT Subject: 'as' keyword - when/how to use it References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> Message-ID: <4c4ac418$0$28641$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 23:33:55 -0700, Dummey wrote: > I am having the hardest time trying to find documentation on proper use > of the 'as' keyword (aside from . I initially thought that I would be > allowed to do something such as: > > import shared.util as util > > The as statement seems to be causing a lot of ''module' object has no > attribute'. Is it safe to assume that this is not the way to use it? It works for me. >>> import math as spam >>> spam >>> import email.mime.text as ham >>> ham My guess is that you are trying to import individual objects from a module using the package dot notation: >>> import math.sin as eggs Traceback (most recent call last): File "", line 1, in ImportError: No module named sin -- Steven From lacrima.maxim at gmail.com Sat Jul 24 06:56:05 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sat, 24 Jul 2010 03:56:05 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> Message-ID: <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> On Jul 24, 11:20?am, Raymond Hettinger wrote: > On Jul 24, 12:47?am, Lacrima wrote: > > > > > Hi! > > > I have two super classes: > > > class SuperClass1(object): > > ? ? def __init__(self, word): > > ? ? ? ? print word > > > class SuperClass2(object): > > ? ? def __init__(self, word, word2): > > ? ? ? ? print word, word2 > > > Also I have subclass of these classes: > > > class SubClass(SuperClass1, SuperClass2): > > ? ? def __init__(self): > > ? ? ? ? pass > > > I have two questions. > > 1) Inside __init__ of SubClass how can I firstly call __init__ of > > SuperClass1, and then __init__ of SuperClass2, using builtin super() > > function. > > I would write it like this: > > class SuperClass1(object): > ? ? def __init__(self, **kwds): > ? ? ? ? word = kwds.pop('word') > ? ? ? ? print word > ? ? ? ? super(SuperClass1, self).__init__(**kwds) > > class SuperClass2(object): > ? ? def __init__(self, **kwds): > ? ? ? ? word1 = kwds.pop('word1') > ? ? ? ? word2 = kwds.pop('word2') > ? ? ? ? print word1, word2 > ? ? ? ? super(SuperClass2, self).__init__(**kwds) > > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self, **kwds): > ? ? ? ? super(SubClass, self).__init__(**kwds) > > SubClass(word='Python', word1='Hello', word2='World') > > > 2) Why should I use super() at all, if it is very easy to call methods > > of super class like this: > > class SubClass(SuperClass1, SuperClass2): > > ? ? def __init__(self): > > ? ? ? ? SuperClass1.__init__(self, 'Python') > > ? ? ? ? SuperClass2.__init__(self, 'Hello', 'world') > > That works just fine in this case. > The challenge arises in "diamond diagrams" > such as A->B ?A->C ?B->D ?C->D where both B and C > are written independently of D and both need to call > A's __init__ but that method should only be called > once (not once by B and again by C). > > In that case, the super() pattern shown above will > let each parent's method be called exactly once > and guarantee that parents are called before grandparents > and guarantee that the left-to-right ordering of multiple > bases is respected. > > Raymond Hi, Raymond! Thank you for your answer. Some things are still not clear. Your example works great. But if I remove "super(SuperClass1, self).__init__(**kwds)" from SuperClass1's __init__, the example stops working. That is when I instantiate SubClass only __init__ of SuperClass1 is called and __init__ of SuperClass2 is omitted, i.e. only 'Python' is printed. Why is it so? So as I understand every parent should necessarily call super() at the end of its __init__ method in order for things to work properly. But what if SuperClass1 is from third party library? Then I can't modify it to follow this convention, that is when I instantiate my SubClass only __init__ from SuperClass1 will be called, and __init__ from SuperClass2 will be omitted. How to deal with that? My post is quite intricate, but this is because of my English. Sorry. Looking forward for help. Thank you. From jim.hefferon at gmail.com Sat Jul 24 07:21:40 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 24 Jul 2010 04:21:40 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Message-ID: <08e71b61-49bc-4cdf-a1fb-97a59cb56418@d17g2000yqb.googlegroups.com> On Jul 23, 8:52?pm, MRAB wrote: > > dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=se ttings.UPDATE_TIME_MINS,second=0,microsecond=0) > > You're changing the time of day, but not the date. You might want to add > a day to the shutdown time if it's earlier than the current time. I started out by finding the right date (I used a less-than test and toordinal and fromordinal() ). However, after some trials, I came to believe that I don't need to find the right date. The part of that calculation I need, and later refer to, is the .seconds attribute. I perceive that the way TimeDelta objects are laid out, the seconds attribute will be the same, regardless of whether I calculate it using 2:30 today or first finding which is the right date and using its 2:30. That is, as I understood it, if it is now 2:29 then the .seconds attribute will be 60. If it is now 2:31 then the .seconds attribute will be 24*60*60-60. I believe this holds regardless of which day I use. >>> import time,datetime >>> x=datetime.datetime(2010,7,23) >>> dt_localtime=x.fromtimestamp(time.time()) >>> dt_localtime datetime.datetime(2010, 7, 24, 7, 17, 46, 122642) >>> dt_twothirty=dt_localtime.replace(hour=2,minute=30,second=0,microsecond=0) >>> print dt_twothirty 2010-07-24 02:30:00 >>> dd_diff=dt_twothirty-dt_localtime >>> print dd_diff -1 day, 19:12:13.877358 >>> dt_tomorrow_twothirty=dt_localtime.replace(day=25,hour=2,minute=30,second=0,microsecond=0) >>> print dt_tomorrow_twothirty 2010-07-25 02:30:00 >>> dd_tomorrow_diff=dt_tomorrow_twothirty-dt_localtime >>> print dd_tomorrow_diff 19:12:13.877358 Tested it, of course. Not that I haven't gotten things wrong in the past, even though I tested them. :-} Jim From roy at panix.com Sat Jul 24 07:25:09 2010 From: roy at panix.com (Roy Smith) Date: Sat, 24 Jul 2010 07:25:09 -0400 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: In article , Kushal Kumaran wrote: > In general, after select has told you a descriptor is ready, the > first write after that should always succeed. I used to think that too. Over the last few years, I've been maintaining a large hunk of cross-platform C++ code which makes heavy use of select(), with both UDP and TCP sockets. I've seen lots of strange behavior. For the moment, assume we're talking about a single-threaded program. This simplifies things a lot. If you write (pseudo-code): select(fd) write(fd) when the select indicates fd is ready, it's not really saying, "The following i/o call will succeed". What it's saying is, "The following i/o call won't block". It could return an error, as long as it returns it immediately. Consider, for example, a write on a TCP connection. You are sitting in a select(), when the other side closes the connection. The select() should return, and the write should then immediately fail. If you're tempted to say that the select() should return some sort of error, consider the case where the remote end closes the connection after the select() returns but before your process gets to execute the following write() call. We also saw a case where (due to what we consider a kernel bug), a received UDP packet with a checksum error would cause the select() to wake up, *then* notice the checksum error and discard the packet, and thus the following read() would block. The bottom line is if you really want to make sure you never block in an I/O call, put your descriptor into non-blocking mode, and treat select() as a *hint*. A way to ask the kernel, "Tell me when you think it might be a good idea to try polling this descriptor again". From franco at grex.org Sat Jul 24 08:45:52 2010 From: franco at grex.org (francogrex) Date: Sat, 24 Jul 2010 14:45:52 +0200 Subject: Are those features still the same? Message-ID: Hi, I'm not a Python programmer but I'm interested in it and I found this table from Norvig that dates for some years (I re-posted it temporarily on my site below to take it out of context a little). I'm not interested in any comparisons only in the Python features ( last column), can someone whether the information in the Python features column is still correct today. Thanks http://francoatgrex.tripod.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 09:06:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 13:06:38 GMT Subject: Are those features still the same? References: Message-ID: <4c4ae55e$0$11117$c3e8da3@news.astraweb.com> On Sat, 24 Jul 2010 14:45:52 +0200, francogrex wrote: > Hi, I'm not a Python programmer but I'm interested in it and I found > this table from Norvig that dates for some years (I re-posted it > temporarily on my site below to take it out of context a little). I'm > not interested in any comparisons only in the Python features ( last > column), can someone whether the information in the Python features > column is still correct today. Thanks > > http://francoatgrex.tripod.com/ I could quibble on a few minor wordings, but yes, it is broadly correct. -- Steven From __peter__ at web.de Sat Jul 24 09:14:12 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 15:14:12 +0200 Subject: Are those features still the same? References: Message-ID: francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks The original page is here: http://norvig.com/python-lisp.html Yes, the table is fairly up-to-date and general enough to stay up-to-date for the next few years. Peter From thomas at jollans.com Sat Jul 24 09:19:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 15:19:33 +0200 Subject: Are those features still the same? In-Reply-To: References: Message-ID: <4C4AE865.3010503@jollans.com> On 07/24/2010 02:45 PM, francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks Mostly all true, with a few changes and inaccuracies. And a definite bias towards the LISP. (and the author didn't even specify a dialect on lisp. My my...) > "Support heterogeneous lists" ==> "Yes (array)" This is nonsense, and has always been. Python lists (not arrays) have always been heterogeneous. They store objects and don't care about the type. Python arrays (from the array module) are homogeneous, and limited to storing numerical data. Quite a different beast. > "Number of implementations" ==> [...]branches[...] I wouldn't cann Jython a branch. You could say that there are currently two major branches of the Python language, and the CPython interpreter: Python 2.x and Python 3.x. There are a number of implementations of Python, the big names being CPython, Jython, IronPython, and PyPy > Data types: Python 2's int and long (there called integer and bignum) are now (Python 3.x) a single type. Again, the author of the table reveals that he is is a lisp programmer only passingly acquainted with Python: Python lists are *not* arrays. They are (linked) lists. They're not identical to lisp (cons'd) lists, but they are, nonetheless, lists, not arrays. > Exceptions: string exceptions, as demonstrated in the table, are gone in Python 3. > "no other control structures" now that's a bit hard on Python. Technically true perhaps, but the author could have mentioned generators somewhere. > function application apply is gone in Python 3.x -- use the fn(*args) syntax instead. Also, execfile("file.py") is NOT identical to import file. > other high-order functions Check out itertools and functools. (std library) > "close over writable var" Can be done in Python 3.x with the nonlocal keyword. Also, to a point, objects have always supported the same behaviour, with a twist. > FEATURES > "quotation" The way this is presented doesn't really fit with Python. Very lisp way to look at quotation. > "operations on arrays" ahem. From brian at sweetapp.com Sat Jul 24 09:48:06 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 24 Jul 2010 23:48:06 +1000 Subject: Are those features still the same? In-Reply-To: <4C4AE865.3010503@jollans.com> References: <4C4AE865.3010503@jollans.com> Message-ID: On 24 Jul 2010, at 23:19, Thomas Jollans wrote: >> "Support heterogeneous lists" ==> "Yes (array)" > > This is nonsense, and has always been. > Python lists (not arrays) have always been heterogeneous. They store > objects and don't care about the type. Python arrays (from the array > module) are homogeneous, and limited to storing numerical data. > Quite a > different beast. He means that Python lists are implemented using arrays, not that the Python "array" module provides the functionality. Cheers, Brian From __peter__ at web.de Sat Jul 24 09:56:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 15:56:31 +0200 Subject: Are those features still the same? References: Message-ID: Thomas Jollans wrote: >> "Support heterogeneous lists" ==> "Yes (array)" > > This is nonsense, and has always been. I think you are misunderstanding that statement. Python's list stores its items in a continuous chunk of memory, a layout that is called array in common CS terminology as opposed to lists which are typically linked lists. Peter From thomas at jollans.com Sat Jul 24 10:11:06 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 16:11:06 +0200 Subject: Are those features still the same? In-Reply-To: References: <4C4AE865.3010503@jollans.com> Message-ID: <4C4AF47A.2050902@jollans.com> On 07/24/2010 03:48 PM, Brian Quinlan wrote: > > On 24 Jul 2010, at 23:19, Thomas Jollans wrote: >>> "Support heterogeneous lists" ==> "Yes (array)" >> >> This is nonsense, and has always been. >> Python lists (not arrays) have always been heterogeneous. They store >> objects and don't care about the type. Python arrays (from the array >> module) are homogeneous, and limited to storing numerical data. Quite a >> different beast. > > He means that Python lists are implemented using arrays, not that the > Python "array" module provides the functionality. Oh dear, and all this time I thought python lists where implemented as lists, without ever checking the code. From be.krul at gmail.com Sat Jul 24 10:17:54 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:17:54 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Jul 17, 10:40?pm, Stephen Hansen wrote: > On 7/17/10 10:01 PM, be.krul wrote: > > > why is this group being spammed? > > Because while God created the Internet, the Devil twisted it by creating > spammers. > > What do you expect? Adam just didn't pay enough attention when Eve made > him a waldorf salad; we descendants of Seth have gone and tried to > devour not only the knowledge of good and evil but all knowledge of all > things, most notably breasts. > > Of course there'd be a dire consequence for our hubris. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload Interesting, I thought Al Gore creted Internet!? From be.krul at gmail.com Sat Jul 24 10:20:11 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:20:11 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> On Jul 17, 10:09?pm, Chris Rebert wrote: > On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > > why is this group being spammed? > > Because that's what happens in unmoderated USENET newsgroups. > > Cheers, > Chris I thought this group can be moderated, but turns out this is USENET Group.. From be.krul at gmail.com Sat Jul 24 10:21:35 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:21:35 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <874ofx9xbx.fsf@benfinney.id.au> Message-ID: <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> On Jul 17, 10:24?pm, Ben Finney wrote: > "be.krul" writes: > > why is this group being spammed? > > What kind of answer are you looking for? Are you asking about the > motives of spammers, or the technical explanation for how the spam > arrives, or something else? > > -- > ?\ ? ? ? ? ? ? ? ? ? ?The best ad-libs are rehearsed.? ?Graham Kennedy | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney Why not moderate this group? From be.krul at gmail.com Sat Jul 24 10:24:18 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:24:18 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <7150244a-749b-4f0d-93b1-fbf67f487d9c@q21g2000prm.googlegroups.com> On Jul 17, 10:57?pm, "Alf P. Steinbach /Usenet" wrote: > * be.krul, on 18.07.2010 07:01: > > > why is this group being spammed? > > It depends a little on what you're asking, e.g. technical versus motivation. > > But I'll answer about something you probably didn't mean to ask, namely what > human trait enables and almost forces that kind of behavior. > > And I believe it is the same trait that let hypnotists do funny TV-shows with > quite normal folks behaving in ridiculous ways, the same trait that causes wars, > the same trait that causes religion, the same trait that holds back science so > that "paradigm shifts" only occur when new generations take over, a trait that > /makes/ your feet start moving to the rhythm when you hear the right kind of > music, and so on. Namely the instinctual drive to fit in in a social group by > sharing that group's behavior and values. This instinct is possibly stronger > than the sex drive, e.g., wars are seldom fought over sex ("surrender, and give > us sex!", no, that's not it, it's "surrender, and become part of us!"). > > Consider, there would be almost no spam if spamming didn't pay. > > And the only way that spam can pay is if there are at least some suckers with > good money. > > And the only way that there can be a reasonable number of suckers of such > monumental stupidity, who also have good money, is, as I see it, if intelligence > and good sense is not a requirement for succeeding in society. > > But what is required, then, for succeeding in society? > > Some of it is no doubt blind chance, but I believe that the main requirement is > simply one of fitting in, conformance. Thus, if my hypothesis is right, almost > any idiot can rise to any level of responsibility and social standing simply by > fitting in, conforming. This idiot then has good money and might be one of the > suckers responding to spam. > > Cheers, > > - Alf > > -- > blog at Alf - You re my next hero! Who could answer so eloquently. From be.krul at gmail.com Sat Jul 24 10:32:30 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:32:30 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> On Jul 17, 10:01?pm, "be.krul" wrote: > why is this group being spammed? What I was asking is why not moderate the group. this is the only Python group I could find.. But maybe owner of this group do no care in that case we *all* get spammed! From thomas at jollans.com Sat Jul 24 10:39:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 16:39:33 +0200 Subject: why is this group being spammed? In-Reply-To: <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> Message-ID: <4C4AFB25.4030003@jollans.com> On 07/24/2010 04:20 PM, be.krul wrote: > On Jul 17, 10:09 pm, Chris Rebert wrote: >> On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: >>> why is this group being spammed? >> >> Because that's what happens in unmoderated USENET newsgroups. >> >> Cheers, >> Chris > > I thought this group can be moderated, but turns out this is USENET > Group.. What did you think it was? From be.krul at gmail.com Sat Jul 24 10:54:26 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:54:26 -0700 (PDT) Subject: Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ References: <233c48c4-2eb5-43a6-bedc-7a396d31228a@w12g2000yqj.googlegroups.com> Message-ID: <0c9eef2e-050f-4739-8492-2703cd5fdec4@x1g2000prc.googlegroups.com> On Jul 23, 3:14?pm, nais-saudi wrote: > Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ > > The Qur?an tells us a lot of wonderful things about Jesus. As a > result, believers in the Qur?an love Jesus, honour him, and believe in > him. In fact, no Muslim can be a Muslim unless he or she believes in > Jesus, on whom be peace. > > The Qur?an says that Jesus was born of a virgin, that he spoke while > he was still only a baby, that he healed the blind and the leper by > God?s leave, and that he raised the dead by God?s leave. > > What then is the significance of these miracles? First, the virgin > birth. God demonstrates his power to create in every way. God created > everyone we know from a man and a woman. But how about Adam, on whom > be peace? God created him from neither a man nor a woman. And Eve from > only a man, but not a woman. And, finally, to complete the picture, > God created Jesus from a woman, but not a man. > > What about the other miracles? These were to show that Jesus was not > acting on his own behalf, but that he was backed by God. The Qur?an > specifies that these miracles were performed by God?s leave. This may > be compared to the Book of Acts in the Bible, chapter 2, verse 22, > where it says that the miracles were done by God to show that he > approved of Jesus. Also, note that Jesus himself is recorded in the > Gospel of John to have said, ?I can do nothing of my own > authority? (5:30). The miracles, therefore, were done not by his own > authority, but by God?s authority. > > What did Jesus teach? The Qur?an tells us that Jesus came to teach the > same basic message which was taught by previous prophets from God?that > we must shun every false god and worship only the one true God. Jesus > taught that he is the servant and messenger of that one true God, the > God of Abraham. These Quranic teachings can be compared with the Bible > ( Mark 10:18; Matthew 26:39; John 14:28, 17:3, and 20:17) where Jesus > teaches that the one he worshipped is the only true God. See also > Matthew 12:18; Acts 3:13, and 4:27 where we find that his disciples > knew him as Servant of God. > > The Qur?an tells us that some of the Israelites rejected Jesus, and > conspired to kill him, but Allah (God) rescued Jesus and raised him to > Himself. Allah will cause Jesus to descend again, at which time Jesus > will confirm his true teachings and everyone will believe in him as he > is and as the Qur?an teaches about him. > > Jesus is the Messiah. He is a word from Allah, and a spirit from Him. > He is honoured in this world and in the hereafter, and he is one of > those brought nearest to Allah. > > Jesus was a man who spoke the truth which he heard from God. This can > be compared with the Gospel According to John where Jesus says to the > Israelites: ?You are determined to kill me, a man who has told you the > truth that I heard from God? (John 8:40). > > The Virgin Birth of Jesus > Muslims believe in the virgin birth of Jesus. When the angels > announced to Mary (peace be upon her) about Allah?s promise that she > will have a son, she was surprised, since she was a virgin. ?How can > this be?? she thought. She was reminded that it is easy for Allah to > create whatever he wills. > > She said: My Lord! How can I have a child when no mortal hath touched > me? He said: So (it will be). Allah createth what He will. If He > decreeth a thing, He saith unto it only: Be! and it is (Qur?an 3:47). > > It is not difficult for Allah to do anything he wants. He can create a > child with both human parents or only one. No miracle is beyond His > power. After all, He had created Adam (peace be upon him) from neither > a man nor a woman. He created the rest of us from both man and woman. > What is so hard if Allah decides to create a human being from a woman > only? He only commands ?Be!? and it occurs. > > Some people think that since Jesus, peace be upon him, had no human > father then God must be his father. The Qur?an rejects this view. The > position of Jesus with Allah is comparable to the position of Adam > with Allah. Just because Adam had no human parent does not mean we > should call him the Son of God. > > Lo! the likeness of Jesus with Allah is as the likeness of Adam. He > created him from dust, then He said unto him: Be! and he is. (Qur?an > 3:59). > > According to the Qur?an, everyone except Allah are His servants. > > And they say: the Beneficent hath taken unto Himself a Son. Assuredly > ye utter a disastrous thing, whereby almost the heavens are torn, and > the earth is split asunder and the mountains fall to ruins, that ye > ascribe to the Beneficent a son, when it is not meet for (the Majesty > of) the Beneficent that He should chose a son. There is none in the > heavens and the earth but cometh unto the Beneficent as a slave. > (Qur?an 19:88-93) > > The Miracles of Jesus > According to the Qur?an, Jesus, on whom be peace, performed the > following miracles by Allah?s leave: > > 1. Spoke while he was only a baby. > 2. Healed those born blind. > 3. Healed the lepers. > 4. Revived the dead. > 5. Breathed life into a bird made of clay. > > In the Qur?an Allah quotes Jesus, peace be upon him, as saying: > > Lo! I come unto you with a sign from your Lord. Lo! I fashion for you > out of clay the likeness of a bird, and I breathe into it and it is a > bird by Allah?s leave. I heal him who was born blind, and the leper, > and I raise the dead, by Allah?s leave. And I announce to you what you > eat and what you store up in your houses. Lo! herein verily is a > portent for you if you are to be believers. > And (I come) confirming that which was before me of the Torah, and to > make lawful some of that which was forbidden unto you. I come unto you > with a sign from your Lord, so keep your duty to Allah and obey me. > Lo! Allah is my Lord and your Lord, so worship Him. That is a straight > path. (Qur?an 3: 49-51). > > Again, in the Qur?an Allah tells us about the situation on the Day of > Judgement: > > In the day when Allah gathers together the messengers and says: What > was your response (from mankind)? they say: We have no knowledge. Lo! > Thou, only Thou art the Knower of Things Hidden. > When Allah says: O Jesus, son of Mary! Remember My favour unto you and > unto your mother; how I strengthened you with the holy Spirit, so that > you spoke unto mankind in the cradle as in maturity; and how I taught > you the ******ure and Wisdom and the Torah and the Gospel; and how you > did shape of clay as it were the likeness of a bird by My permission, > and did blow upon it and it was a bird by My permission, and you did > heal him who was born blind and the leper by My permission . . . > (Qur?an 5:109-110) > > Not all of these miracles are recorded in the canonical gospels, the > four gospels contained in the Christian Bible. > > The fact that Jesus spoke while he was yet a baby is not written > anywhere in the Bible. This should not be surprising, because none of > the Gospels can claim to recover every single event in the life of > Jesus. Instead, the gospel According to John seeks to emphasize that > the events were too many to record. > > Similarly, the miracle of breathing life into a bird made of clay is > not attested by the Christian Bible. This too should not make us > wonder. It is obvious that the writers of the gospels could write down > only the tradition that was available to them. Furthermore, they could > not write down everything they knew about Jesus for they were writing > on papyrus material that were very limited in length. > > What is worthy to notice here is that the Prophet Muhammad, may peace > and the blessings of Allah be upon him, was honest enough to > promulgate this information about Jesus. The religion taught by God > through Muhammad would deny the divinity of Jesus. Any human being, > therefore, who wished to deny the divinity of Jesus would have tried > to belittle Jesus. Since Christians looked upon the miracles of Jesus > as a proof of his divinity, we might expect that any human being who > tries to deny the divinity of Jesus would not have informed people of > miracles not previously known to them. He might have even tried to > deny some of the miracles recorded in the canonical gospels. On the > other hand, the prophet Muhammad honestly conveyed the message > delivered to him from Allah. (May the peace and blessings of Allah be > upon him.) > > Allah tells us the truth without fear. Human beings trying to win > followers tell us only what is conducive to winning us over. They > usually withhold information that could lead to opposite conclusions. > On the other hand, Allah informs us about the miracles of Jesus even > if people use this information to support their prior commitment to > the doctrine of the divinity of Jesus. Allah does not need to win > worshippers. Those who worship Allah does so for their own good. And > those who worship false gods do so to their own detriment. > > What Allah emphasizes, though, is that the miracles of Jesus do not > prove he was divine. The miracles he performed were a sign, a proof, > that he was God?s messenger. He performed them with God?s help and > permission. Those who use his miracles as proof of his divinity would > choose to forget the following sayings of Jesus: > > I can of my own authority do nothing. (John 5:30) > > They also forget the declaration of Peter: > > Jesus of Nazareth, a man approved of God among you by miracles and > wonders and signs, which God did by him in the midst of you, as ye > yourselves know. (Acts 2:22 KJV). > > These passages suggest that Jesus did not do miracles on his own. > These, rather were accomplished by God?s leave. Allah reminds us of > this. Jesus also constantly repeated to his audience that the miracles > he performed were by God?s leave. > > ------------------------------------------------------------------------------------------------------------------------------------------------------------ > > ?The True Message of Jesus Christ > ????? ???? ?????? ?????? > > ?????? ????? ????? ???? ??????? > > The True Message of Jesus Christ > > Auther: Dr. Bilal Philips > > *******: > > Introduction > > Chapter One: The ******ures > > Authentic Manu******s > > Contradictions > > Chapter Two: The Person > > A Man > > "Evidence"For Jesus Divinity > > Chapter Three: The Message > > Chapter Four: The Way > > Conclusion > > Bibliography > > CHAPTER TWO: JESUS, THE PERSON > > As has been shown in the previous chapter, the Biblical ******ures, > both New and Old Testaments, are unreliable sources and cannot, > therefore, be used as an authentic means of knowing the truth about > the man called Jesus Christ or about his mission and message. However, > a close examination of these ******ures in the light of Qur?aanic > verses will reveal some of the truths about Jesus that have survived > in the Bible. > > A Messenger > > Throughout the Qur?aan, Jesus is identified fundamentally as a > Messenger of God. In Chapter as-Saff (61):6, God quotes Jesus as > follows: > > { ?????? ????? ?????? ????? ???????? ???????? ??????????? ?????? > ??????? ????? ?????????? ?????????? ?????? ?????? ??????? ???? > ??????????? } > > ?And [remember] when Jesus, son of Mary, said: ?O Children of Israel, > I am the messenger of Allaah sent to you, confirming the Torah [which > came] before me.? > > There are many verses in the New Testament supporting the > messengership / prophethood of Jesus. The following are only a few: In > Matthew 21:11, the people of his time are recorded as referring to > Jesus as a prophet: ?And the crowds said, ?This is the prophet Jesus > of Nazareth of Galilee.? ? In Mark, 6:4, it is stated that Jesus > referred to himself as a prophet: ?And Jesus said to them, ?A prophet > is not without honour, except in his own country, and among his own > kin, and in his own house.? ? In the following verses, Jesus is > referred to as having been sent as a messenger is sent. In Matthew > 10:40, Jesus was purported to have said: ?He that receiveth you > receiveth me, and he that receiveth me receiveth him that sent me.? In > John 17:3, Jesus is also quoted as saying: ?And this is life eternal, > that they might know thee the only true God, and Jesus Christ, whom > thou hast sent.? [1] > > ==================== > > A Man > > The Qur?aanic revelation not only affirms Jesus? prophethood, but it > also clearly denies Jesus? divinity. In Chapter al-Maa?idah, (5): 75, > God points out that Jesus ate food, which is a human act, obviously > not befitting to God. > > { ??? ?????????? ????? ???????? ?????? ??????? ???? ?????? ???? > ???????? ????????? ????????? ?????????? ?????? ??????????? ?????????? > ??????? ?????? ????????? ?????? ????????? ????? ??????? ?????? > ???????????} > > ?The Messiah, Son of Mary, was no more than a messenger and many > messengers passed away before him. His mother was exceedingly > truthful, and they both ate food. See how I have made the signs clear > for them, yet see how they are deluded.? > > There are numerous accounts in the New Testament which also deny > Jesus? divinity. > > For example, in Matthew 19:17, Jesus responded to one who addressed > him as ?O good master?, saying: ?Why callest thou me good? There is > none good but one, that is God.? If he rejected being called ?good?, > [2] and stated that only God is truly good, he clearly implies that he > is not God. > > In John 14:28, Jesus was saying: ?The Father is greater than I.? By > stating that the ?Father? is greater than himself, Jesus distinguishes > himself from God. Also in John 20:17, Jesus told Mary Magdalene to > tell his followers: ?I ascend unto my Father and your Father; and to > my God and your God.? Jesus? reference to God as ?my Father and your > Father? further emphasizes the distinction between himself and God. > Furthermore, by referring to God as ?his God?, he left no room for > anyone to intelligently claim that he was God. > > Even in some of the writings of Paul, which the Church has taken to be > sacred, Jesus is referred to as a ?man?, distinct and different from > God. In 1st Timothy, 2:5, Paul writes: ?For there is one God, and one > mediator between God and men, the man Christ Jesus.? > > There are also verses in the Qur?aan which confirm Prophet Muhammad?s > humanity, in order to prevent his followers from elevating him to a > divine or semi-divine status, as was done to Prophet Jesus. For > example, in Chapter al-Kahf (18):110, Allaah instructs the Prophet > Muhammad (e) to inform all who hear his message: > > { ???? ???????? ?????? ?????? ?????????? ?????? ??????? ???????? > ?????????? ????? ??????? } > > ?Say: ?Indeed, I am only a man like you to whom it has been revealed > that your God is only one God.? ? > > In Chapter al-A?raaf (7):187, Allaah also directed Prophet Muhammad > (e) to acknowledge that the time of the Judgement is known only to > God. > > {????????????? ???? ?????????? ???????? ?????????? ???? ???????? > ????????? ?????? ?????? ??? ??????????? ??????????? ?????? ???? } > > ?They ask you about the Final Hour: 'When will its apointed time be?? > Say: ?Knowledge of it is with my Lord. None can reveal its time > besides Him.? ? > > In the Gospel according to Mark 13:31-32, Jesus is also reported to > have denied having knowledge of when the final hour of this world > would be, saying: ?Heaven and the earth shall pass away but my word > shall not pass away, but of that day or hour no man knoweth, neither > the angels in the heaven nor the Son but the Father.? One of the > attributes of God is omniscience, knowledge of all things. Therefore, > his denial of knowledge of the Day of Judgement is also a denial of > divinity, for one who does not know the time of the final hour cannot > possibly be God .[3] > > An Immaculate Conception > > The Qur?aan confirms the Biblical story of Jesus? virgin birth. > However, in the Qur?aanic account of Jesus? birth, Mary was an > unmarried maiden whose life was dedicated to the worship of God by her > mother. While she was worshipping in a place of religious seclusion, > angels came and informed her of her impending pregnancy. > > { ???? ??????? ???????????? ??? ???????? ????? ????? ??????????? > ?????????? ?????? ??????? ??????????? ?????? ????? ???????? ???????? > ??? ????????? ?? ?????????? ?????? ??????????????} > > ?When the angels said: ?O Mary, indeed Allaah gives you glad tidings > of a Word from Him, whose name will be the Messiah, Jesus the son of > Mary. He will be honored in this world and the next and will be of > those close to Allaah.? ? Qur?aan, (3):45 > > { ??????? ????? ?????? ??????? ??? ?????? ?????? ??????????? ?????? > ????? ???????? ????? ???????? ??? ??????? ????? ????? ??????? > ?????????? ??????? ???? ???? ????????? } > > ?She said: ?O my Lord, how can I have a son when no man has touched > me?? He said: ?Even so?Allaah creates what He wishes. When He decrees > something, He only has to say to it: ?Be!? and it is.? ? Qur?aan, (3): > 47 > > However, the Qur?aan clarifies that Jesus? virgin birth did not change > the state of his humanity. His creation was like the creation of > Aadam, who had neither father nor mother. > > { ????? ?????? ?????? ?????? ????? ???????? ????? ???????? ???? > ??????? ????? ????? ???? ???? ????????? } > > ?Surely, the example of Jesus, in Allaah?s sight, is like that of > Aadam. He created him from dust and said: ?Be!? and he was.? Qur?aan, > (3):59 > > The Miracles > > The Qur?aanic account of Jesus? ministry confirms most[4] of his > miracles mentioned in the Bible and identifies some not mentioned in > the Bible. For example, the Qur?aan informs that Jesus was a messenger > of God from his birth, and his first miracle was speaking as a child > in the cradle. After Mary had given birth to Jesus, people accused her > of fornication. Instead of responding to their accusations, she > pointed to her newly born child: > > { ??????????? ???????? ??????? ?????? ????????? ???? ????? ??? > ????????? ???????? ????? ?????? ?????? ????? ???????? ?????????? > ??????????? ????????} > > ?[When] she pointed to him, they asked, ?How can we talk to a child in > the cradle?? He [Jesus] said: ?Indeed, I am a servant of Allaah. He > gave me the ******ure and made me a prophet.? ? > > Qur?aan, (19):29-30 > > Among his other miracles of bringing the dead back to life, healing > lepers, and making the blind see, the Qur?aan records another miracle > not mentioned in the Bible. Prophet Jesus fashioned birds out of clay, > blew on them and they flew away, living birds. But the point which is > emphasized throughout the Qur?aan is that whenever Jesus performed a > miracle, he informed the people that it was by God?s permission. He > made it clear to his followers that he was not doing the miracles by > himself, in the same way that the earlier Prophets made it clear to > those around them. > > Unfortunately, those who claim divinity for Jesus, usually hold up his > miracles as evidence. However, other prophets were recorded to have > done the same or similar miracles in the Old Testament. > > Jesus fed 5,000 people with five loaves of bread and two fishes. > Elisha fed 100 people with twenty barley loaves and a few ears of corn > (II Kings 4:44) > > Jesus healed lepers. > Elisha cured Naaman the leper (II Kings 5:14). > > Jesus caused the blind to see. > Elisha caused the blind to see (II Kings 6:17&20). > > Jesus raised the dead. > Elijah did the same (I Kings 17:22). So did Elisha (II Kings 4:34). > Even Elisha?s bones could restore the dead (II Kings 13:21). > > Jesus walked on water. > Moses and his people crossed the dead sea (Exodus 14:22). > > There are also ****s in the New Testament which confirm that Jesus did > not act on his own. Jesus is quoted in John 5:30, as saying: ?I can of > mine own self do nothing...? and in Luke 11:20, as saying, ?But if I > with the finger of God cast out devils, no doubt the Kingdom of God is > come upon you.? In Acts 2:22, Paul writes: ?Men of Israel, hear these > words: Jesus of Nazareth, a man attested to you by God with mighty > works and wonders and signs which God did through him in your midst, > as you yourselves know...? > > Is the message of Prophet Jesus to the worlds or the children of > Israel only?http://www.imanway.com/vb/showthread...5500# post85500 > > Jesus said, "I am the way and no one up to the father except through > me"http://www.imanway.com/vb/showthread...2091# post92091 > > The Bible itself shows a lack of Christ's crucifixion and that no one > else has the hearthttp://www.imanway.com/vb/showthread...2282# post82282 > > Gospel of Judas (to prove that the heart of Jesus Christ peace be upon > him)http://www.imanway.com/vb/showthread.php?t=14478 > > Do you send Christ to be crucified?http://www.imanway.com/vb/showthread.php?t=2588 > > Proof of the prophethood of the Prophet Jesus in the Biblehttp://www.imanway.com/vb/showthread.php?t=2610 > > Meaning of the word "Christ"http://www.imanway.com/vb/showthread.php?t=2607 > > Jesus between Islam and Christianityhttp://www.imanway.com/vb/showthread.php?t=13716 > > Prophet Jesus peace be upon him (Abdullah) in the Qur'an and the > Biblehttp://www.imanway.com/vb/showthread.php?t=10772 > > Paul is the invention of modern Christianity and destroyed the > original message of Christhttp://www.imanway.com/vb/showthread...0361# post80361 > > Confessions of the Christians themselves not credible Gospelshttp://www.imanway.com/vb/showthread.php?t=2626 > > Christian scholars recognize contradictory texts in the Biblehttp://www.imanway.com/vb/showthread.php?t=2625 > > Description of God (exalted above what they attribute) in the Biblehttp://www.imanway.com/vb/showthread.php?t=2640 > > Muslims pray as the Prophet Jesus prayedhttp://www.imanway.com/vb/showthread.php?t=2656 > > Muslim Peace Xlam prophet Jesus peace be upon himhttp://www.imanway.com/vb/showthread.php?t=2655 > > Who is the "Emmanuel" (Emmanuel: God with us means) Christians believe > that Jesus Christ but it is only the name of another person, the name > of a person shows God's help us and not the fact (that God is with us > and us in the form of human being)http://www.imanway.com/vb/showthread.php?t=2653 > > Who is the "Melchizedek" or the king of peace (not the prophet Jesus > given that he mentioned (the guide was born))http://www.imanway.com/vb/showthread.php?t=2652 > > Is the Bible the Word of God? (Sheikh Ahmed Deedat God's mercy)http://jamaat.net/bible/BibleIntro.html > > Recognition of the founder of Christianity distorted (Paul) twisting > the Biblehttp://www.imanway.com/vb/showthread.php?t=2623 > > Destruction of the principles and instructions of the prophet Jesus > peace be upon him Graphicallyhttp://www.imanway.com/vb/showthread.php?t=2622 > > History of the foundation, "Trinity or Triangulation"http://www.imanway.com/vb/showthread.php?t=2621 > > Random evidence of modern Christian thoughthttp://www.imanway.com/vb/showthread.php?t=2620 > > Prophet Jesus did not say never "was the right", he was calling to > worship God alone (according to the Bible)http://www.imanway.com/vb/showthread.php?t=2619 > > Erroneous translation of the Bible word for "worship of Christ"http://www.imanway.com/vb/showthread.php?t=2618 > > What the Bible says the sin of Adam?http://www.imanway.com/vb/showthread...3994# post83994 > > Who forgives sins?http://www.imanway.com/vb/showthread.php?t=2617 > > Lifting of the prophet Jesus does not indicate his divinityhttp://www.imanway.com/vb/showthread.php?t=2616 > > What about the previous nations that have not contemporary with Jesus > Christ? Has not been invited to the faith and the Trinity Steelhttp://www.imanway.com/vb/showthread.php?t=2615 > > Evidence to refute the divinity of Christ, peace be upon himhttp://www.imanway.com/vb/showthread.php?t=2614 > > God calls Christ "Abdi (according to the Gospel)" so it is not > unreasonable to have his son and call him sohttp://www.imanway.com/vb/showthread.php?t=2613 > > May God, "Isa (as they claim)," he prayed for himself?http://www.imanway.com/vb/showthread.php?t=2612 > > Code is "Da Vinci"http://www.imanway.com/vb/showthread.php?t=15166 > > Discuss the idea of "text from the Bible" Itallon the divinity of > Christhttp://www.imanway.com/vb/showthread.php?t=2608 > > The word "father" in the Bible did not mean the real father of Christ > and the directory as stated more than one personhttp://www.imanway.com/vb/showthread.php?t=2605 > > Miracles of the Prophet Jesus does not indicate his divinity and the > evidence that more than a prophet had miracleshttp://www.imanway.com/vb/showthread.php?t=2604 > > Some churches believe in the Prophethood of Jesus Christ peace be upon > himhttp://www.imanway.com/vb/showthread.php?t=2603 > > Refute the idea of the Trinity scientifically (analogy with water, ice > and steam)http://www.imanway.com/vb/showthread.php?t=2602 > > Logical analysishttp://www.imanway.com/vb/showthread.php?t=2599 > > Discuss the idea of triangulation and the greatest sinhttp://www.imanway.com/vb/showthread.php?t=2598 > > How the son of God? (I ask forgiveness from God)http://www.imanway.com/vb/showthread.php?t=2589 > > How mixed with polytheistic religion Christianity ideas?http://www.imanway.com/vb/showthread.php?t=2586 > > Questions from a Christian to Sheikh Mohammed Lockethttp://www.imanway.com/vb/showthread...0169# post80169 > > Answer Question: Why do Muslims hate Jesushttp://www.imanway.com/vb/showthread.php?t=16150 > > What Jesus said about the celebration of Christmas?http://www.imanway.com/vb/showthread...2283# post92283 Religion kills! From raynald.levesque at gmail.com Sat Jul 24 10:59:40 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 07:59:40 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) Message-ID: Hi I am working on a program that generates various pdf files in the / results folder. "scenario1.pdf" results from scenario1 "scenario2.pdf" results from scenario2 etc Once I am happy with scenario1.pdf and scenario2.pdf files, I would like to save them in the /check folder. Now after having developed/modified the program to produce scenario3.pdf, I would like to be able to re-generate files /results/scenario1.pdf /results/scenario2.pdf and compare them with /check/scenario1.pdf /check/scenario2.pdf I tried using the md5 module to compare these files but md5 reports differences even though the code has *not* changed at all. Is there a way to compare 2 pdf files generated at different time but identical in every other respect and validate by program that the files are identical (for all practical purposes)? From be.krul at gmail.com Sat Jul 24 11:05:12 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 08:05:12 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> Message-ID: <6e53d2d0-1a13-4a44-9585-995ff422cdd5@x1g2000prc.googlegroups.com> On Jul 24, 7:39?am, Thomas Jollans wrote: > On 07/24/2010 04:20 PM, be.krul wrote: > > > On Jul 17, 10:09 pm, Chris Rebert wrote: > >> On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > >>> why is this group being spammed? > > >> Because that's what happens in unmoderated USENET newsgroups. > > >> Cheers, > >> Chris > > > I thought this group can be moderated, but turns out this is USENET > > Group.. > > What did you think it was? Because i joined from Goggle Groups and not the Usenet Client. From REMpeteOVE at petezilla.co.uk Sat Jul 24 11:38:52 2010 From: REMpeteOVE at petezilla.co.uk (Peter Chant) Date: Sat, 24 Jul 2010 16:38:52 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: <8b0fogF90cU2@mid.individual.net> rlevesque wrote: > Is there a way to compare 2 pdf files generated at different time but > identical in every other respect and validate by program that the > files are identical (for all practical purposes)? I wonder, do the PDFs have a timestamp within them from when they are created? That would ruin your MD5 plan. Pete -- http://www.petezilla.co.uk From __peter__ at web.de Sat Jul 24 11:50:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 17:50:31 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: rlevesque wrote: > Hi > > I am working on a program that generates various pdf files in the / > results folder. > > "scenario1.pdf" results from scenario1 > "scenario2.pdf" results from scenario2 > etc > > Once I am happy with scenario1.pdf and scenario2.pdf files, I would > like to save them in the /check folder. > > Now after having developed/modified the program to produce > scenario3.pdf, I would like to be able to re-generate > files > /results/scenario1.pdf > /results/scenario2.pdf > > and compare them with > /check/scenario1.pdf > /check/scenario2.pdf > > I tried using the md5 module to compare these files but md5 reports > differences even though the code has *not* changed at all. > > Is there a way to compare 2 pdf files generated at different time but > identical in every other respect and validate by program that the > files are identical (for all practical purposes)? Here's a naive approach, but it may be good enough for your purpose. I've printed the same small text into 1.pdf and 2.pdf (Bad practice warning: this session is slightly doctored; I hope I haven't introduced an error) >>> a = open("1.pdf").read() >>> b = open("2.pdf").read() >>> diff = [i for i, (x, y) in enumerate(zip(a, c)) if x != y] >>> len(diff) 2 >>> diff [160, 161] >>> a[150:170] '0100724151412)\n>>\nen' >>> a[140:170] 'nDate (D:20100724151412)\n>>\nen' >>> a[130:170] ')\n/CreationDate (D:20100724151412)\n>>\nen' OK, let's ignore "lines" starting with "/CreationDate " for our custom comparison function: >>> def equal_pdf(fa, fb): ... with open(fa) as a: ... with open(fb) as b: ... for la, lb in izip_longest(a, b, fillvalue=""): ... if la != lb: ... if not la.startswith("/CreationDate "): return False ... if not lb.startswith("/CreationDate "): return False ... return True ... >>> from itertools import izip_longest >>> equal_pdf("1.pdf", "2.pdf") True Peter From paulgtd at gmail.com Sat Jul 24 11:56:01 2010 From: paulgtd at gmail.com (Peo) Date: Sat, 24 Jul 2010 08:56:01 -0700 (PDT) Subject: Library versions Message-ID: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Hi, I'm writing a library for doing sysadmin tasks at my workplace. These kind of scripts have a tendency to live for decades and I want to make sure that I don't break anything when I'm updating the library. My current plan is to call the library something like 'foo1' and import it into scripts like 'import foo1 as foo'. Releases that change the API would be installed as 'foo2', 'foo3' and so on. This works fine but it will be quite difficult to create new releases (documentation and library code are littered with references to 'foo1'). Is there some other smart way to do acheive this? Thanks / Paul From brian.mingus at Colorado.EDU Sat Jul 24 11:59:22 2010 From: brian.mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 24 Jul 2010 09:59:22 -0600 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 11:01 PM, be.krul wrote: > why is this group being spammed? > -- > http://mail.python.org/mailman/listinfo/python-list > Here's a few of theories: 1) This isn't a strong enough community to warrant a group of people who moderate the list and make sure spam doesn't come through 2) Thousands of python hackers aren't smart enough to figure out how to stop spam 3) Whenever people post threads asking why this list is getting spammed they get heckled 4) Uber leet old skool script kiddies read the list through some mechanism that allows them to get rid of the spam, unlike the other 99% of us. -------------- next part -------------- An HTML attachment was scrubbed... URL: From be.krul at gmail.com Sat Jul 24 12:43:55 2010 From: be.krul at gmail.com (nero janick) Date: Sat, 24 Jul 2010 09:43:55 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: Brian, would you like to volunteer? On Sat, Jul 24, 2010 at 8:59 AM, Brian J Mingus wrote: > > > On Sat, Jul 17, 2010 at 11:01 PM, be.krul wrote: > >> why is this group being spammed? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Here's a few of theories: > > 1) This isn't a strong enough community to warrant a group of people who > moderate the list and make sure spam doesn't come through > 2) Thousands of python hackers aren't smart enough to figure out how to > stop spam > 3) Whenever people post threads asking why this list is getting spammed > they get heckled > 4) Uber leet old skool script kiddies read the list through some mechanism > that allows them to get rid of the spam, unlike the other 99% of us. > -- \|||||/ ( ~ ~ ) @( 0 0 )@ ( C ) \ \_/ / |___| | | -------------- next part -------------- An HTML attachment was scrubbed... URL: From raynald.levesque at gmail.com Sat Jul 24 12:49:56 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 09:49:56 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> On Jul 24, 11:50?am, Peter Otten <__pete... at web.de> wrote: > rlevesque wrote: > > Hi > > > I am working on a program that generates various pdf files in the / > > results folder. > > > "scenario1.pdf" ?results from scenario1 > > "scenario2.pdf" results from scenario2 > > etc > > > Once I am happy with scenario1.pdf and scenario2.pdf files, I would > > like to save them in the /check folder. > > > Now after having developed/modified the program to produce > > scenario3.pdf, I would like to be able to re-generate > > files > > /results/scenario1.pdf > > /results/scenario2.pdf > > > and compare them with > > /check/scenario1.pdf > > /check/scenario2.pdf > > > I tried using the md5 module to compare these files but md5 reports > > differences even though the code has *not* changed at all. > > > Is there a way to compare 2 pdf files generated at different time but > > identical in every other respect and validate by program that the > > files are identical (for all practical purposes)? > > Here's a naive approach, but it may be good enough for your purpose. > I've printed the same small text into 1.pdf and 2.pdf > > (Bad practice warning: this session is slightly doctored; I hope I haven't > introduced an error) > > >>> a = open("1.pdf").read() > >>> b = open("2.pdf").read() > >>> diff = [i for i, (x, y) in enumerate(zip(a, c)) if x != y] > >>> len(diff) > 2 > >>> diff > [160, 161] > >>> a[150:170] > > '0100724151412)\n>>\nen'>>> a[140:170] > > 'nDate (D:20100724151412)\n>>\nen'>>> a[130:170] > > ')\n/CreationDate (D:20100724151412)\n>>\nen' > > OK, let's ignore "lines" starting with "/CreationDate " for our custom > comparison function: > > >>> def equal_pdf(fa, fb): > > ... ? ? with open(fa) as a: > ... ? ? ? ? ? ? with open(fb) as b: > ... ? ? ? ? ? ? ? ? ? ? for la, lb in izip_longest(a, b, fillvalue=""): > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? if la != lb: > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not la.startswith("/CreationDate > "): return False > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not lb.startswith("/CreationDate > "): return False > ... ? ? ? ? ? ? ? ? ? ? return True > ...>>> from itertools import izip_longest > >>> equal_pdf("1.pdf", "2.pdf") > > True > > Peter Thanks a lot Peter. Unfortunately there is an other pair of values that does not match and it is not obvious to me how to exclude it (as is done with the " / CreationDate" pair). To illustrate the problem, I have modified your code as follows: def equal_pdf(fa, fb): idx=0 with open(fa) as a: with open(fb) as b: for la, lb in izip_longest(a, b, fillvalue=""): idx+=1 #print idx if la != lb: #if not la.startswith(" /CreationDate"): print "***", idx , la,'\n',lb #return False print "Last idx:",idx return True from itertools import izip_longest file1='K/results/Test2.pdf' file1c='K:/check/Test2.pdf' print equal_pdf(file1, file1c) I got the following output: *** 237 /CreationDate (D:20100724123129+05'00') /CreationDate (D:20100724122802+05'00') *** 324 [(,\315'\347\003_\253\325\365\265\006\)J\216\252\215) (, \315'\347\003_\253\325\365\265\006\)J\216\252\215)] [(~s\211VIA\3426}\242XuV2\302\002) (~s\211VIA \3426}\242XuV2\302\002)] Last idx: 331 True As you can see, there are 331 pair comparisons and 2 of the comparisons do not match. Your code correctly handles the " /CreationDate" pair but the other one does not have a common element that can be used to handle it. :-( As additional information in case it matters, the first pair compared equals '%PDF-1.4\n' and the pdf document is created using reportLab. One hope I have is that item 324 which is near to the last item (331) could be part of the 'trailing code' of the pdf file and might not reflect actual differences between the 2 files. In other words, maybe it would be sufficient for me to check all but the last 8 pairs... From __peter__ at web.de Sat Jul 24 13:34:36 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 19:34:36 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: rlevesque wrote: > Unfortunately there is an other pair of values that does not match and > it is not obvious to me how to exclude it (as is done with the " / > CreationDate" pair). > and the pdf document is created using reportLab. I dug into the reportlab source and in reportlab/rl_config.py found the line invariant= 0 #produces repeatable,identical PDFs with same timestamp info (for regression testing) I suggest that you edit that file or add from reportlab import rl_config rl_config.invariant = True to your code. Peter From raynald.levesque at gmail.com Sat Jul 24 14:09:13 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 11:09:13 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: On Jul 24, 1:34?pm, Peter Otten <__pete... at web.de> wrote: > rlevesque wrote: > > Unfortunately there is an other pair of values that does not match and > > it is not obvious to me how to exclude it (as is done with the " / > > CreationDate" pair). > > and the pdf document is created using reportLab. > > I dug into the reportlab source and in > > reportlab/rl_config.py > > found the line > > invariant= ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? #produces > repeatable,identical PDFs with same timestamp info (for regression testing) > > I suggest that you edit that file or add > > from reportlab import rl_config > rl_config.invariant = True > > to your code. > > Peter WOW!! You are good! Your suggested solution works perfectly. Given your expertise I will not be able to 'repay' you by helping on Python problems but if you ever need help with SPSS related problems I will be pleased to provide the assistance you need. (I am the author of "SPSS Programming and Data Management" published by SPSS Inc. (an IBM company)) Regards, Raynald Levesque www.spsstools.net From nagle at animats.com Sat Jul 24 14:23:49 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 11:23:49 -0700 Subject: non-blocking IO EAGAIN on write In-Reply-To: <8at354F51tU1@mid.individual.net> References: <8at354F51tU1@mid.individual.net> Message-ID: <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> On 7/23/2010 1:45 AM, Thomas Guettler wrote: > Hi, > > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) > on write(). My working code looks like this. But I am unsure how many bytes have been written to the > pipe if I get an EAGAIN IOError. At the OS level, if you get EAGAIN, no bytes have been written. If you get EOK from a non-blocking request, you must check the number of bytes written to see if everything was written. You may have to write more after an EOK. Ref: http://www.opengroup.org/onlinepubs/009695399/functions/write.html "If the O_NONBLOCK flag is set, write() shall not block the thread. If some data can be written without blocking the thread, write() shall write what it can and return the number of bytes written. Otherwise, it shall return -1 and set errno to [EAGAIN]." At the Python level, it's different. http://docs.python.org/library/stdtypes.html#file-objects says that "file.write(s)" returns nothing. If a non-blocking write can't complete, you get an "io.BlockingIOError" exception (ref "http://docs.python.org/release/3.0.1/library/io.html") from which you can retrieve the number of bytes written. This is only in Python 3.x, and may not be working right (ref "http://bugs.python.org/issue7786"). It's unclear what happens in this situation in Python 2.x, but it's probably not what you wanted to happen. However, "socket.send(s)" returns the number of bytes sent. "send" and "recv" do work on pipes (with problems; see "http://bugs.python.org/issue5573"). So use "send", not "write", and pay attention to the number of bytes sent. > If I get EAGAIN can I just sleep, and then retry with the same data chunk? Yes. But if you've filled the pipe, you may have to wait until the program reading from the pipe reads more. This can take however long the other program needs. Incidentally, "select" apparently doesn't work on pipes under Windows. Since your code isn't doing anything else while waiting for a write to complete on the pipe, why use non-blocking I/O at all? (I know, the Python I/O timeout logic is broken in some versions. You're probably working around that.) John Nagle From pavlovevidence at gmail.com Sat Jul 24 14:57:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jul 2010 11:57:33 -0700 (PDT) Subject: Library versions References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: On Jul 24, 8:56?am, Peo wrote: > Hi, > > I'm writing a library for doing sysadmin tasks at my workplace. These > kind of > scripts have a tendency to live for decades and I want to make sure > that I don't break anything when I'm updating the library. > > My current plan is to call the library something like 'foo1' and > import it into > scripts like 'import foo1 as foo'. Releases that change the API would > be installed > as 'foo2', 'foo3' and so on. This works fine but it will be quite > difficult > to create new releases (documentation and library code are littered > with > references to 'foo1'). > > Is there some other smart way to do acheive this? The typical way to do this is to delegate responsibility to load the most recent release to another module. Create a module called foo.py, and it have it import all the objects from the most recent release module. IOW, you should have a foo.py module that looks like this: from foo1 import * Which you update whenever there's a new release. Then in your code you simply use: import foo This is, incidentally, one of the few cases where it's recommended to use from module import *. Carl Banks From breamoreboy at yahoo.co.uk Sat Jul 24 15:16:26 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 20:16:26 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: On 24/07/2010 18:01, Dennis Lee Bieber wrote: > On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" > declaimed the following in gmane.comp.python.general: > >> But maybe owner of this group do no care in that case we *all* get >> spammed! > > There is NO OWNER of comp.lang.python; and turning a comp.* group > into moderated takes a fairly long time assuming you can find someone > willing to be the moderators -- what would likely happen is that > comp.lang.python.moderated would be created and then take a few months > to be picked up by the servers, and a few more months for the real users > to leave comp.lang.python to use it. > > Oh, and also the hassle of the mailing-list<>usenet gateway (does it > pass traffic to both groups, drop the existing one, etc.). And readers > on Google may still see spam if Google takes posts stuff before it > passes through the moderation board. For the benefit of those who might have missed it, I'll repeat that I'm reading this from gmane.comp.python.general and see little or no spam. Regards. Mark Lawrence. From hujia06 at gmail.com Sat Jul 24 15:22:33 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 15:22:33 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: Hi, can I subscribe this by gmail? On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence wrote: > On 24/07/2010 18:01, Dennis Lee Bieber wrote: > >> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >> declaimed the following in gmane.comp.python.general: >> >> But maybe owner of this group do no care in that case we *all* get >>> spammed! >>> >> >> There is NO OWNER of comp.lang.python; and turning a comp.* group >> into moderated takes a fairly long time assuming you can find someone >> willing to be the moderators -- what would likely happen is that >> comp.lang.python.moderated would be created and then take a few months >> to be picked up by the servers, and a few more months for the real users >> to leave comp.lang.python to use it. >> >> Oh, and also the hassle of the mailing-list<>usenet gateway (does >> it >> pass traffic to both groups, drop the existing one, etc.). And readers >> on Google may still see spam if Google takes posts stuff before it >> passes through the moderation board. >> > > For the benefit of those who might have missed it, I'll repeat that I'm > reading this from gmane.comp.python.general and see little or no spam. > > Regards. > > Mark Lawrence. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Jul 24 15:23:38 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jul 2010 12:23:38 -0700 (PDT) Subject: understanding the mro (long) References: Message-ID: On Jul 23, 7:42?pm, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph [snip rest] If you want to stay sane, don't inherit from ANY class unless A. you own it, or B. it's explicitly documented as supporting inheritance Furthermore, if you want to stay sane, don't mulitply inherit from any class unless A. you own it, or B. it's explicitly documented as supporting MULTIPLE inheritance Inheritance is always risky if you don't know what you're inheriting from. Carl Banks From hujia06 at gmail.com Sat Jul 24 15:28:06 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 15:28:06 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: I subscribe for this mailing list at http://mail.python.org/mailman/listinfo/python-list On Sat, Jul 24, 2010 at 3:22 PM, Jia Hu wrote: > Hi, can I subscribe this by gmail? > > On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence wrote: > >> On 24/07/2010 18:01, Dennis Lee Bieber wrote: >> >>> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >>> declaimed the following in gmane.comp.python.general: >>> >>> But maybe owner of this group do no care in that case we *all* get >>>> spammed! >>>> >>> >>> There is NO OWNER of comp.lang.python; and turning a comp.* group >>> into moderated takes a fairly long time assuming you can find someone >>> willing to be the moderators -- what would likely happen is that >>> comp.lang.python.moderated would be created and then take a few months >>> to be picked up by the servers, and a few more months for the real users >>> to leave comp.lang.python to use it. >>> >>> Oh, and also the hassle of the mailing-list<>usenet gateway (does >>> it >>> pass traffic to both groups, drop the existing one, etc.). And readers >>> on Google may still see spam if Google takes posts stuff before it >>> passes through the moderation board. >>> >> >> For the benefit of those who might have missed it, I'll repeat that I'm >> reading this from gmane.comp.python.general and see little or no spam. >> >> Regards. >> >> Mark Lawrence. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dummey at gmail.com Sat Jul 24 16:00:40 2010 From: dummey at gmail.com (Dummey) Date: Sat, 24 Jul 2010 13:00:40 -0700 (PDT) Subject: 'as' keyword - when/how to use it References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> <4c4ac418$0$28641$c3e8da3@news.astraweb.com> Message-ID: On Jul 24, 3:44?am, Steven D'Aprano wrote: > On Fri, 23 Jul 2010 23:33:55 -0700, Dummey wrote: > > I am having the hardest time trying to find documentation on proper use > > of the 'as' keyword (aside from . I initially thought that I would be > > allowed to do something such as: > > > import shared.util as util > > > The as statement seems to be causing a lot of ''module' object has no > > attribute'. Is it safe to assume that this is not the way to use it? > > It works for me. > > >>> import math as spam > >>> spam > > >>> import email.mime.text as ham > >>> ham > > > > My guess is that you are trying to import individual objects from a > module using the package dot notation: > > >>> import math.sin as eggs > > Traceback (most recent call last): > ? File "", line 1, in > ImportError: No module named sin > > -- > Steven I was being an idiot and doing a circular import. I erroneously thought it was the "as" part of the statement. For some reason, removing the "as" part of the statement remove/delayed the error from popping up which made me thought it was the culprit. Thanks for the help. From chrisj at puffin.com Sat Jul 24 16:17:21 2010 From: chrisj at puffin.com (Chris Jewell) Date: Sat, 24 Jul 2010 13:17:21 -0700 Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> Message-ID: <7r1vasiqi6.fsf@puffin.com> rantingrick writes: > On Jul 23, 9:49?am, Steven D'Aprano In the land of the blind, the one eyed man is king! ;-) "... And across the way, in the country of the witless, the half-wit is king." Richard Mitchell (a/k/a The Undeground Grammarian.) http://www.sourcetext.com/grammarian/graves-of-academe/01.htm -- Chris Jewell chrisj at puffin.com PO Box 1396 Gualala CA USA 95445-1396 From sjmachin at lexicon.net Sat Jul 24 18:37:26 2010 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jul 2010 22:37:26 +0000 (UTC) Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: dirknbr gmail.com> writes: > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' As Steven has pointed out, if the .encode('latin-1') works, the result is thrown away. This would be very fortunate. It appears that your goal was to encode the text in latin1 if possible, otherwise in UTF-8, with no indication of which encoding was used. Your second posting confirmed that you were doing this in a loop, ending up with the possibility that your output file would have records with mixed encodings. Did you consider what a programmer writing code to READ your output file would need to do, e.g. attempt to decode each record as UTF-8 with a fall-back to latin1??? Did you consider what would be the result of sending a stream of mixed-encoding text to a display device? As already advised, the short answer to avoid all of that hassle; just encode in UTF-8. From emmynoether3 at gmail.com Sat Jul 24 18:42:41 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 24 Jul 2010 15:42:41 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> Message-ID: On Jul 23, 9:27?pm, TheFlyingDutchman wrote: > On Jul 23, 12:06?pm, Emmy Noether wrote: > > > > > Title ? Portable LISP interpreter > > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date ? ? ? ?1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) ? ? ? ?UCRL-52417 > > DOE Contract Number ? ? W-7405-ENG-48 > > Resource Type ? Technical Report > > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract ? ?A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication ?United States > > Language ? ? ? ?English > > Format ?Medium: X; Size: Pages: 21 > > Availability ? ?Dep. NTIS, PC A02/MF A01. > > System Entry Date ? ? ? 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? I am glad to share with everyone. However its useless without the ability to compile and run. Also with text, its easy to read and discuss the code which has a listing of 900 lines. I have already spent 4 hours scanning/processing to a stage where I got a decent OCR which needs hand-verification of pages. I need 4 or 8 volunteers depending on whether one want to do two pages each or 1 page each. Its an hour of joyful work each for two pages. Explanation are good quality. We will re-write to C, python etc. It must be edited in emacs in fundamental mode to override pascal mode indentation. Go to pascal mode periodically to colorize to indicate errors, and then revert before inserting anything. Stay close to the original page. Email me to receive image and initial ocr and lots of fixes I did by hand for more than 4hrs. Send only plain text message or it goes to spam. Then we share with everyone here or put it on some site. E.N. From emmynoether3 at gmail.com Sat Jul 24 18:43:44 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 24 Jul 2010 15:43:44 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> Message-ID: <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> On Jul 23, 9:27?pm, TheFlyingDutchman wrote: > On Jul 23, 12:06?pm, Emmy Noether wrote: > > > > > Title ? Portable LISP interpreter > > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date ? ? ? ?1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) ? ? ? ?UCRL-52417 > > DOE Contract Number ? ? W-7405-ENG-48 > > Resource Type ? Technical Report > > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract ? ?A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication ?United States > > Language ? ? ? ?English > > Format ?Medium: X; Size: Pages: 21 > > Availability ? ?Dep. NTIS, PC A02/MF A01. > > System Entry Date ? ? ? 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? Are you willing to do some work on this ? On Jul 23, 9:27 pm, TheFlyingDutchman wrote: > On Jul 23, 12:06 pm, Emmy Noether wrote: > > > > > Title Portable LISP interpreter > > Creator/Author Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date 1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) UCRL-52417 > > DOE Contract Number W-7405-ENG-48 > > Resource Type Technical Report > > Research Org California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication United States > > Language English > > Format Medium: X; Size: Pages: 21 > > Availability Dep. NTIS, PC A02/MF A01. > > System Entry Date 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? I am glad to share with everyone. However its useless without the ability to compile and run. Also with text, its easy to read and discuss the code which has a listing of 900 lines. I have already spent 4 hours scanning/processing to a stage where I got a decent OCR which needs hand-verification of pages. I need 4 or 8 volunteers depending on whether one want to do two pages each or 1 page each. Its an hour of joyful work each for two pages. Explanation are good quality. We will re-write to C, python etc. It must be edited in emacs in fundamental mode to override pascal mode indentation. Go to pascal mode periodically to colorize to indicate errors, and then revert before inserting anything. Stay close to the original page. Email me to receive image and initial ocr and lots of fixes I did by hand for more than 4hrs. Send only plain text message or it goes to spam. Then we share with everyone here or put it on some site. E.N. From breamoreboy at yahoo.co.uk Sat Jul 24 18:46:05 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 23:46:05 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: On 24/07/2010 20:28, Jia Hu wrote: > I subscribe for this mailing list at > http://mail.python.org/mailman/listinfo/python-list > I read through Thunderbird on Windows direct to gmane.comp.python.general. I'm no expert on such things, but assume that they are simply better [or less profitable :)] at filtering spam than the diabolical google groups. I'm unsure as to how the main mailing list that is given above works, I'm sure that someone more knowledgable than myself will soon let us know. Regards. Mark Lawrence. From navkirats at gmail.com Sat Jul 24 19:07:16 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 04:37:16 +0530 Subject: Multiprocessing zombie processes Message-ID: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Hi, I have been meddling around with forking and multiprocessing. Now both of them spawn new processes from parent (atleast from what I have understood). I have been able to reproduce a zombie state in a fork with: import os,time print('before fork',os.getpid()) pid = os.fork() if pid: print('child: ',pid) time.sleep(120) Now doing a ps ax | grep I can find a zombie child process, but I am not being able to reproduce the same with multiprocessing. Am I missing something? Or multiprocessing does not have the zombie problem? Regards, Nav From navkirats at gmail.com Sat Jul 24 19:11:39 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 04:41:39 +0530 Subject: Multiprocessing zombie processes In-Reply-To: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. Nav On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: > Hi, > > I have been meddling around with forking and multiprocessing. Now both of them spawn new processes from parent (atleast from what I have understood). I have been able to reproduce a zombie state in a fork with: > > import os,time > > print('before fork',os.getpid()) > > pid = os.fork() > > if pid: > print('child: ',pid) > time.sleep(120) > > Now doing a ps ax | grep I can find a zombie child process, but I am not being able to reproduce the same with multiprocessing. Am I missing something? Or multiprocessing does not have the zombie problem? > > Regards, > Nav From tjreedy at udel.edu Sat Jul 24 19:30:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jul 2010 19:30:56 -0400 Subject: Are those features still the same? In-Reply-To: References: Message-ID: On 7/24/2010 8:45 AM, francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks > > http://francoatgrex.tripod.com/ As other have said, mostly, but I would change the following: Number of implementations should be "Many, one main' add Set ............?? set() before Hashtable/dict change Function entry to def f(x): return x+x \n lambda x: x+x or even remove mention of lambda. Anyone who thinks the table is the whole story and tries Python without knowing about def will think Python braindead. Other loops: '## works on any sequence ' change sequence to iterable. Assignment: add x,*y = 1,2,3 Add augmented assignment: x += 1 "No other control structures" is simply wrong. 'and' and 'or' are control structures as much as if-else expressions. Ditto for list/set/dict comprehensions and generator expressions. Comments "## hash mark to end of line" just one hash mark Someone mentioned apply, execfile is now(3.x) exec(open()) "No other higher-order functions built-in" wrong. func.partial, decorators, others mentioned 'No keywords on map/reduce/filter' ?? I do not know what these are, but I suspect Python can produce the same effect somehow. this looks like some lisp detail picked out as something Python does not directly have. Someone mention nonlocal to write enclosed vars. Compilation is an implementation, not a language feature. There have been lisp inerpreters in the past, if not now, and there are Python compilers now, if not in the past. Declarations Standard Python has 2, the Cython dialect has 'declarations for efficiency' just as do some lisp dialects. Quotation: lambda quotes an entire expression, and is used for one of the same purposes as list quotation, to suppress immediate execution. Lisp has one The Python equivalent of (cons x y) should just be the direct equivalent y.append(x). Python grows and shrinks list as the 'tail', lisp at the 'head'. Or, the lisp column should include the O(n) lisp code equivalent to [x]+y. The python equivalent (car x) is x.pop(). That for (cdr x) is x.pop();x, which is O(1), not O(n). Again, if the table ha the O(n) way to operate on a Python list as the 'wrong' end, it should have the same slow way to operate on the 'wrong' end of a lisp list. What that would show is that it is a lot easier to operation on the 'wrong' end of a Python list that the 'wrong' end of a Lisp list. Comparing the wrong Python way with the right Lisp way is unfair if not dishonest. -- Terry Jan Reedy From clp2 at rebertia.com Sat Jul 24 19:38:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 24 Jul 2010 16:38:29 -0700 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: > OK I wanted zombie processes > Now lets see how I can handle them. "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." Cheers, Chris -- Most people try to /avoid/ making zombies. From navkirats at gmail.com Sat Jul 24 19:43:01 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 05:13:01 +0530 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> I want to kill Zombies....so first I have to create them...simple law of nature.... On 25-Jul-2010, at 5:08 AM, Chris Rebert wrote: > On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: >> OK I wanted zombie processes > >> Now lets see how I can handle them. > > "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." > > Cheers, > Chris > -- > Most people try to /avoid/ making zombies. From john at castleamber.com Sat Jul 24 19:45:03 2010 From: john at castleamber.com (John Bokma) Date: Sat, 24 Jul 2010 18:45:03 -0500 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: <871vasla0w.fsf@castleamber.com> "be.krul" writes: > On Jul 17, 10:01?pm, "be.krul" wrote: >> why is this group being spammed? > > What I was asking is why not moderate the group. this is the only > Python group I could find.. Controlling spam starts by you! Report it. And certainly don't reply to spam by qouting the entire (religious) spam message. Moron. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From thomas at jollans.com Sat Jul 24 19:51:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 01:51:37 +0200 Subject: Multiprocessing zombie processes In-Reply-To: <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> Message-ID: <4C4B7C89.8070503@jollans.com> On 07/25/2010 01:43 AM, Navkirat Singh wrote: > I want to kill Zombies....so first I have to create them...simple law of nature.... You can't kill a zombie. That's why we call them zombies, as opposed to, say, daemons. > > > On 25-Jul-2010, at 5:08 AM, Chris Rebert wrote: > >> On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: >>> OK I wanted zombie processes >> >>> Now lets see how I can handle them. >> >> "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." >> >> Cheers, >> Chris >> -- >> Most people try to /avoid/ making zombies. > From cs at zip.com.au Sat Jul 24 19:55:00 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 25 Jul 2010 09:55:00 +1000 Subject: Multiprocessing zombie processes In-Reply-To: References: Message-ID: <20100724235500.GA19364@cskk.homeip.net> [ Please don't top post. Post below so that things read like a conversation. (And trim excess quoted junk.) It doesn't take long and makes things a lot easier for your readers. ] On 25Jul2010 04:41, Navkirat Singh wrote: | On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: | > I have been meddling around with forking and multiprocessing. Now | > both of them spawn new processes from parent (atleast from what I have | > understood). I have been able to reproduce a zombie state in a fork with: | > | > import os,time | > print('before fork',os.getpid()) | > pid = os.fork() | > if pid: | > print('child: ',pid) | > time.sleep(120) | > | > Now doing a ps ax | grep I can find a zombie child process, | > but I am not being able to reproduce the same with multiprocessing. Am | > I missing something? Or multiprocessing does not have the zombie problem? | | OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. A zombie process is a fairly common thing and nothing to panic about usually. When you have a normal, running process it has an entry in the system process table (that "ps" shows) that points at it and shows its state. When a process exits, its exit status (exit code, whether it exited normally or from a signal, and if so which signal, some stats) _remain_ in the process table as a record of the exit status. This is shown as a "zombie" process in "ps" - a process which has exited and whose exit status is hanging around waiting to be collected. After the process' parent has issued a wait() call to collect the status the process slot if released and the :zombie" is gone. In your fork() example above, if that's the whole program, the child exits immediately and the parent has not waited for it. If the parent exits without waiting for all its children, the init process (process 1) inherits them, and it collects the statuses. Having a few zombies lying around isn't a disaster provided your program does get around to waiting for them at some point (or if your main program is short lived, so they get reaped by init after it exits). It's only a process table slot after all - little memory is needed for it. A program that spawns a lot of children and never waits for them _is_ bad in the long run. Process ids are often 2-byte integers on many systems for it's quite feasible to fill the table, and depending on the kernel's process table implementation a big process table might have other performance side effects. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I'm behind a corporate Exchange Server which seems to have changed recently to converting everything it sees to HTML. How embarrassing. - Dan Espen From debatem1 at gmail.com Sat Jul 24 20:03:45 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 24 Jul 2010 17:03:45 -0700 Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. In-Reply-To: <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> Message-ID: On Sat, Jul 24, 2010 at 3:43 PM, Emmy Noether wrote: > On Jul 23, 9:27?pm, TheFlyingDutchman wrote: >> On Jul 23, 12:06?pm, Emmy Noether wrote: >> >> >> >> > Title ? Portable LISP interpreter >> > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. >> > Publication Date ? ? ? ?1978 May 31 >> > OSTI Identifier OSTI ID: 7017786 >> > Report Number(s) ? ? ? ?UCRL-52417 >> > DOE Contract Number ? ? W-7405-ENG-48 >> > Resource Type ? Technical Report >> > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore >> > Lab. >> > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND >> > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; >> > PROGRAMMING LANGUAGES >> > Description/Abstract ? ?A portable LISP interpreter that includes all the >> > major list-processing functions is described. A complete, annotated >> > listing of the program's code, written in PASCAL, is included. >> > Country of Publication ?United States >> > Language ? ? ? ?English >> > Format ?Medium: X; Size: Pages: 21 >> > Availability ? ?Dep. NTIS, PC A02/MF A01. >> > System Entry Date ? ? ? 2008 Feb 12 >> >> Is this available online? If only in hardcopy form, do they lend it >> out? > > Are you willing to do some work on this ? > > On Jul 23, 9:27 pm, TheFlyingDutchman wrote: >> On Jul 23, 12:06 pm, Emmy Noether wrote: >> >> >> >> > Title ? Portable LISP interpreter >> > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. >> > Publication Date ? ? ? ?1978 May 31 >> > OSTI Identifier OSTI ID: 7017786 >> > Report Number(s) ? ? ? ?UCRL-52417 >> > DOE Contract Number ? ? W-7405-ENG-48 >> > Resource Type ? Technical Report >> > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore >> > Lab. >> > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND >> > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; >> > PROGRAMMING LANGUAGES >> > Description/Abstract ? ?A portable LISP interpreter that includes all the >> > major list-processing functions is described. A complete, annotated >> > listing of the program's code, written in PASCAL, is included. >> > Country of Publication ?United States >> > Language ? ? ? ?English >> > Format ?Medium: X; Size: Pages: 21 >> > Availability ? ?Dep. NTIS, PC A02/MF A01. >> > System Entry Date ? ? ? 2008 Feb 12 >> >> Is this available online? If only in hardcopy form, do they lend it >> out? > > I am glad to share with everyone. However its useless without the > ability to compile and run. Also with text, its easy to read and > discuss the code which has a listing of 900 lines. > > I have already spent 4 hours scanning/processing to a stage where I > got a decent OCR which needs hand-verification of pages. I need 4 or 8 > volunteers depending on whether one want to do two pages each or 1 > page each. Its an hour of joyful work each for two pages. Explanation > are good quality. We will re-write to C, python etc. > > It must be edited in emacs in fundamental mode to override pascal mode > indentation. Go to pascal mode periodically to colorize to indicate > errors, and then revert before inserting anything. Stay close to the > original page. > > Email me to receive image and initial ocr and lots of fixes I did by > hand for more than 4hrs. Send only plain text message or it goes to > spam. > > Then we share with everyone here or put it on some site. Why is this on python-list? Geremy Condra From navkirats at gmail.com Sat Jul 24 21:01:23 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 06:31:23 +0530 Subject: Multiprocessing zombie processes In-Reply-To: <20100724235500.GA19364@cskk.homeip.net> References: <20100724235500.GA19364@cskk.homeip.net> Message-ID: <942DBAA4-1A29-4770-B4B2-26B143628E36@gmail.com> On 25-Jul-2010, at 5:25 AM, Cameron Simpson wrote: > [ Please don't top post. Post below so that things read like a > conversation. (And trim excess quoted junk.) It doesn't take long and > makes things a lot easier for your readers. ] > > On 25Jul2010 04:41, Navkirat Singh wrote: > | On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: > | > I have been meddling around with forking and multiprocessing. Now > | > both of them spawn new processes from parent (atleast from what I have > | > understood). I have been able to reproduce a zombie state in a fork with: > | > > | > import os,time > | > print('before fork',os.getpid()) > | > pid = os.fork() > | > if pid: > | > print('child: ',pid) > | > time.sleep(120) > | > > | > Now doing a ps ax | grep I can find a zombie child process, > | > but I am not being able to reproduce the same with multiprocessing. Am > | > I missing something? Or multiprocessing does not have the zombie problem? > | > | OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. > > A zombie process is a fairly common thing and nothing to panic about > usually. > > When you have a normal, running process it has an entry in the > system process table (that "ps" shows) that points at it and shows its > state. > > When a process exits, its exit status (exit code, whether it exited > normally or from a signal, and if so which signal, some stats) _remain_ > in the process table as a record of the exit status. This is shown as a > "zombie" process in "ps" - a process which has exited and whose exit > status is hanging around waiting to be collected. > > After the process' parent has issued a wait() call to collect the status > the process slot if released and the :zombie" is gone. > > In your fork() example above, if that's the whole program, the child > exits immediately and the parent has not waited for it. > > If the parent exits without waiting for all its children, the init > process (process 1) inherits them, and it collects the statuses. > > Having a few zombies lying around isn't a disaster provided your program > does get around to waiting for them at some point (or if your main > program is short lived, so they get reaped by init after it exits). > It's only a process table slot after all - little memory is needed for > it. > > A program that spawns a lot of children and never waits for them _is_ > bad in the long run. Process ids are often 2-byte integers on many > systems for it's quite feasible to fill the table, and depending on the > kernel's process table implementation a big process table might have other > performance side effects. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > I'm behind a corporate Exchange Server which seems to have > changed recently to converting everything it sees to HTML. > How embarrassing. - Dan Espen Thanks a lot for all the information. It cleared a lot of my doubts. Nav From gelonida at gmail.com Sat Jul 24 21:05:53 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 03:05:53 +0200 Subject: pyqt Error with qtdesigner button groups Message-ID: Hi, I have have a layout with qt designer, which contains radio buttons. Now I want to add three buttons into a button group. doing this manually works fine with manually I mean adding a few lines in my widget class. example: bg = self.buttongroup = Qg.QButtonGroup() bg.addButton(self.radioButton, 1) bg.addButton(self.radioButton_2, 2) bg.addButton(self.radioButton_3, 3) When I try to create a button group from qt designer, then python code is created which fails when running: How I create a button group with qtdesigner. - I select my three radio buttons - I right click in the object inspector and select "Assign to Button Group" -> "New Button Group" I create my python file with pyuic4 -o mywidget.py -x mywidget.ui When I try to use my widget I receive follwoing error: Traceback (most recent call last): . . . line 37 self.QtGui.QApplication.translate("FormGridState", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(FormGridState) SyntaxError: can't assign to function call The generated code lines for the buttongroup look like: self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(Form1) self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8).setObjectName("QtGui.QApplication.translate(\"Form1\", \"buttonGroup\", None, QtGui.QApplication.UnicodeUTF8)") self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8).addButton(self.radioButton) Am I doing something wrong or is this a bug? I'm running ubuntu 10.4 , and python 2.6 From ldo at geek-central.gen.new_zealand Sat Jul 24 21:15:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 25 Jul 2010 13:15:55 +1200 Subject: Socket performance References: Message-ID: In message , Navkirat Singh wrote: > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? Remember the old saying, ?premature optimization is the root of all evil?. Have you actually got some code working properly first, before worrying about how good or bad its performance is? -- Lawrence trying not to say ?performant? :) From greg.ewing at canterbury.ac.nz Sat Jul 24 21:58:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 25 Jul 2010 13:58:00 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> Message-ID: <8b1jgbFgbdU1@mid.individual.net> Lacrima wrote: > But what if SuperClass1 is from third party library? If it hasn't been designed for super(), then you can't use super() with it. super() only works when *every* class in the hierarchy has been designed with it in mind. -- Greg From navkirats at gmail.com Sat Jul 24 22:16:09 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 07:46:09 +0530 Subject: Socket performance In-Reply-To: References: Message-ID: <7CA752B1-75A4-4101-AD8D-970C11E477AF@gmail.com> On 25-Jul-2010, at 6:45 AM, Lawrence D'Oliveiro wrote: > In message > , Navkirat Singh wrote: > >> I had a question, programming sockets, what are the things that would >> degrade performance and what steps could help in a performance boost? > > Remember the old saying, ?premature optimization is the root of all evil?. > > Have you actually got some code working properly first, before worrying > about how good or bad its performance is? > > -- > Lawrence > trying not to say ?performant? :) > -- > http://mail.python.org/mailman/listinfo/python-list I agree with you, it was just for the sake of knowledge. Its always good to have a map right? From eldiener at tropicsoft.invalid Sat Jul 24 22:40:58 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sat, 24 Jul 2010 22:40:58 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/24/2010 6:25 AM, Mark Lawrence wrote: > On 24/07/2010 04:17, Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >> have already run into a number of them. I installed Python 2.7 and 3.1.2 >> into completely folders, but immediately ran into serious problems >> executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line or >> internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will start >> whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it puts >> in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes in >> the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > I found this only yesterday and found it extremely helpful, find the > post by Gabriel Genellina. > > http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx I found the solutions too exotic for actual use, and completely ineffectual for the cases I originally cited. The people in that thread seem to have completely forgotten that Python can be invoked externally and internally both through executing 'python(w) xxx' and through executing a file with the file extension(s) associated with Python. They seem to have forgotten this can be within scripts or any other program using Python, both written by themselves and by others, and not just by their typing 'python(w) xxx' somewhere. Their solutions seem to believe that only they will externally be i9nvoking Python and only for their own written scripts, as opposed to the many libraries using Python as well as the Python distribution itself. The best solution is some program which changes the PATH and the Python file type associations depending on which version of Python one wants to use on one's own system when more than one Python version must coexist with others. I will probably write such a program for myself. Are the .py and .pyc extensions the only ones which are associated with Python or are there others, for a normal Python installation in Windows ? From eldiener at tropicsoft.invalid Sat Jul 24 22:46:14 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sat, 24 Jul 2010 22:46:14 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/24/2010 6:25 AM, Mark Lawrence wrote: > On 24/07/2010 04:17, Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >> have already run into a number of them. I installed Python 2.7 and 3.1.2 >> into completely folders, but immediately ran into serious problems >> executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line or >> internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will start >> whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it puts >> in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes in >> the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > I found this only yesterday and found it extremely helpful, find the > post by Gabriel Genellina. > > http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx I found the solutions too exotic for actual use, and completely ineffectual for the cases I originally cited. The people in that thread seem to have completely forgotten that Python can be invoked externally and internally both through executing 'python(w) xxx' and through executing a file with the file extension(s) associated with Python. They seem to have forgotten this can be within scripts or any other program using Python, both written by themselves and by others, and not just by their typing 'python(w) xxx' somewhere. Their solutions seem to believe that only they will externally be i9nvoking Python and only for their own written scripts, as opposed to the many libraries using Python as well as the Python distribution itself. The best solution is some program which changes the PATH and the Python file type associations depending on which version of Python one wants to use on one's own system when more than one Python version must coexist with others. I will probably write such a program for myself. Are the .py and .pyc extensions the only ones which are associated with Python or are there others, for a normal Python installation in Windows ? From hujia06 at gmail.com Sat Jul 24 23:01:32 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 23:01:32 -0400 Subject: numpy installation Message-ID: Hello: I tried to install numpy 1.4.1 from source under ubuntu following instruction at http://docs.scipy.org/doc/numpy/user/install.html I type "" python setup.py build ?help-fcompiler "" and it says gnu95 is found. Then I run ""python setup.py build ?fcompiler=gnu95"". There is error. Does anyone know how to fix it?? Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdwjfndjbdgfyg at gmail.com Sat Jul 24 23:35:27 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Sat, 24 Jul 2010 20:35:27 -0700 (PDT) Subject: SUPER HOT VIDOES Message-ID: FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 23:48:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 03:48:27 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> Message-ID: <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 13:58:00 +1200, Gregory Ewing wrote: > Lacrima wrote: > >> But what if SuperClass1 is from third party library? > > If it hasn't been designed for super(), then you can't use super() with > it. > > super() only works when *every* class in the hierarchy has been designed > with it in mind. That incorrect. You can certainly use super() with classic classes in the hierarchy, and super() didn't even exist when they were created. >>> class Parent: ... def method(self, arg): ... return repr(arg) ... >>> class Classic(Parent): ... def method(self, arg): ... return "argument was %s" % Parent.method(self, arg) ... >>> class New(object, Classic): ... def method(self, arg): ... return super(New, self).method(arg).upper() ... >>> x = New() >>> x.method('spam') "ARGUMENT WAS 'SPAM'" The problem isn't super(), and people who give glib advise "don't use super()" are just compounding the problem. The problem is with multiple inheritance where methods have different method signatures. If you don't change the method signatures, super() will work fine. Advising people not to use super() might make people feel virtuous, but it doesn't do anything to help the reader write non-buggy MI hierarchies. It pushes the effort of dealing with multiple inheritance onto them, forcing them to re-implement the MRO, probably badly. Can you re- implement the C3 algorithm? Have you even heard of it? If you answer No to either of those questions, chances are high that trying to deal with the MRO manually will lead to worse bugs than using super(). Should you use super()? 1. If you're doing multiple inheritance with metaclasses, you MUST use super(). 2. If you're using single inheritance only, and never modify method signatures, there is no reason not to use super(). 3. If you're using mixins, you should use super(). 4. If you never modify method signatures, then you should use super(). 5. If you do modify method signatures, you shouldn't do that (except possibly in constructors, and even there only cautiously). But if you do it anyway, then you should use super() *except* in the methods where you modify the signature. 6. If you don't use super(), chances are that your class hierarchy is still buggy, but instead of failing loudly and noisily with an exception, it's silently giving the wrong results. 7. If you can avoid multiple inheritance in favour of another technique (such as composition), you should strongly consider that. -- Steven From kushal.kumaran at gmail.com Sun Jul 25 00:22:30 2010 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Sun, 25 Jul 2010 09:52:30 +0530 Subject: non-blocking IO EAGAIN on write In-Reply-To: References: <8at354F51tU1@mid.individual.net> Message-ID: <1280031750.3257.10.camel@Nokia-N900> ----- Original message ----- > In article , >? Kushal Kumaran wrote: > > > In general, after select has told you a descriptor is ready, the > > first write after that should always succeed. > > > > Consider, for example, a write on a TCP connection.? You are sitting in > a select(), when the other side closes the connection.? The select() > should return, and the write should then immediately fail.? If you're > tempted to say that the select() should return some sort of error, > consider the case where the remote end closes the connection after the > select() returns but before your process gets to execute the following > write() call. > > We also saw a case where (due to what we consider a kernel bug), a > received UDP packet with a checksum error would cause the select() to > wake up, *then* notice the checksum error and discard the packet, and > thus the following read() would block. > > Thanks Roy. That was educational. -- regards, kushal -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Jul 25 01:03:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 24 Jul 2010 22:03:48 -0700 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On Sat, Jul 24, 2010 at 7:40 PM, Edward Diener wrote: > On 7/24/2010 6:25 AM, Mark Lawrence wrote: >> On 24/07/2010 04:17, Edward Diener wrote: >>> Are there any documents about multiple versionsof Python coexisting in >>> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >>> have already run into a number of them. I installed Python 2.7 and 3.1.2 >>> into completely folders, but immediately ran into serious problems >>> executing a Python script. > The best solution is some program which changes the PATH and the Python file > type associations depending on which version of Python one wants to use on > one's own system when more than one Python version must coexist with others. > I will probably write such a program for myself. > > Are the .py and .pyc extensions the only ones which are associated with > Python or are there others, for a normal Python installation in Windows ? There's also .pyw Cheers, Chris From nagle at animats.com Sun Jul 25 01:50:25 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 22:50:25 -0700 Subject: Socket performance In-Reply-To: References: Message-ID: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> On 7/23/2010 5:06 PM, Navkirat Singh wrote: > Hey Everyone, > > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? I > would also appreciate being pointed to some formal documentation or > article. 1. When writing to a TCP socket, write everything you have to write with one "send" or "write" operation if at all possible. Don't write a little at a time. That results in sending small packets, because sockets are "flushed" after each write. 2. Wait for input from multiple sources by using "select". (But be aware that "select" doesn't work for Windows pipes.) John Nagle From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 02:20:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 06:20:07 GMT Subject: Multiple versions of Python coexisting in the same OS References: Message-ID: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> On Sat, 24 Jul 2010 22:03:48 -0700, Chris Rebert wrote: >> Are the .py and .pyc extensions the only ones which are associated with >> Python or are there others, for a normal Python installation in Windows >> ? > > There's also .pyw Also .pyo .py = Python source code, usually associated with command line Python .pyc = Python byte code .pyo = Python optimized byte code .pyw = is Windows only, and shouldn't open a console window. -- Steven From cournape at gmail.com Sun Jul 25 04:00:24 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 25 Jul 2010 17:00:24 +0900 Subject: numpy installation In-Reply-To: References: Message-ID: Hi Jia, On Sun, Jul 25, 2010 at 12:01 PM, Jia Hu wrote: > Hello: > > I tried to install numpy 1.4.1 from source under ubuntu following > instruction at http://docs.scipy.org/doc/numpy/user/install.html > I type "" python setup.py build ?help-fcompiler ""? and it says gnu95 is > found. Then I run ""python setup.py build ?fcompiler=gnu95"". There is > error. Please state the full error. Saying that there is an error is generally unhelpful. Also, you are more likely to receive good information on the numpy ML: http://www.scipy.org/Mailing_Lists David From ph4nut at gmail.com Sun Jul 25 04:05:43 2010 From: ph4nut at gmail.com (Twilight) Date: Sun, 25 Jul 2010 01:05:43 -0700 (PDT) Subject: Hi to the group Message-ID: <28189699-e4ed-4283-a436-3a95e6d9c0b7@a4g2000prm.googlegroups.com> I am new for Python & Django,willling to join yours! From ph4nut at gmail.com Sun Jul 25 04:05:49 2010 From: ph4nut at gmail.com (Twilight) Date: Sun, 25 Jul 2010 01:05:49 -0700 (PDT) Subject: Hi to the group Message-ID: I am new for Python & Django,willling to join yours! From franco at grex.org Sun Jul 25 05:02:40 2010 From: franco at grex.org (francogrex) Date: Sun, 25 Jul 2010 11:02:40 +0200 Subject: Are those features still the same? References: Message-ID: Terry Reedy wrote: >As other have said, mostly, but I would change the following... Thanks for all those who replied. I know these are not all the features but some of them and again this is not a comparison but a little taste of what python offers today, and the replies were very informative. By the way Peter Norvig is not biased, he works for Google research and is a supporter of programming in any language, especially in Python. From ldo at geek-central.gen.new_zealand Sun Jul 25 05:50:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 25 Jul 2010 21:50:47 +1200 Subject: Library versions References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: In message <2cb0c88b-58ea-4704-8578-2ebd766f1269 at t10g2000yqg.googlegroups.com>, Peo wrote: > My current plan is to call the library something like 'foo1' and > import it into scripts like 'import foo1 as foo'. Releases that change the > API would be installed as 'foo2', 'foo3' and so on. This works fine but it > will be quite difficult to create new releases (documentation and library > code are littered with references to 'foo1'). I don?t understand why this is a problem. The references to ?foo1? are because it is ?foo1? that implements those facilities, is it not? When ?foo2? comes along, you will introduce that name where specifying the facilities specific to it, will you not? Where both modules provide the same facilities, you will have to mention both names, and only in those cases. I don?t see how you can possibly short-cut this process and still produce correct documentation. From gelonida at gmail.com Sun Jul 25 06:07:10 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 12:07:10 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: Hi Edward, On 07/25/2010 04:40 AM, Edward Diener wrote: > I found the solutions too exotic for actual use, and completely > ineffectual for the cases I originally cited. The people in that thread > seem to have completely forgotten that Python can be invoked externally > and internally both through executing 'python(w) xxx' and through > executing a file with the file extension(s) associated with Python. They > seem to have forgotten this can be within scripts or any other program > using Python, both written by themselves and by others, and not just by > their typing 'python(w) xxx' somewhere. Their solutions seem to believe > that only they will externally be i9nvoking Python and only for their > own written scripts, as opposed to the many libraries using Python as > well as the Python distribution itself. > > The best solution is some program which changes the PATH and the Python > file type associations depending on which version of Python one wants to > use on one's own system when more than one Python version must coexist > with others. I will probably write such a program for myself. > Hi Edward, changing the path and is perfect for people who use consoles. (under linux there's virtuelenv for his and it's great) changing the file association is perfect for people who'd know at which time they want to use which version of python. The usecase, that I'm nore aware of however is somethig like having some scripts / directories, that should use one version of python and others that shoud use another. In unix you do this normally with the 'shebang line' ( e.g. #!/usr/bin/env/python2.6 ) There the windows solution could be something like a small 'pystarter' program, which would decide depending on the file's location / the file's first line which python should be started. From roy at panix.com Sun Jul 25 08:22:13 2010 From: roy at panix.com (Roy Smith) Date: Sun, 25 Jul 2010 08:22:13 -0400 Subject: Socket performance References: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> Message-ID: In article <4c4bd0b1$0$1624$742ec2ed at news.sonic.net>, John Nagle wrote: > 1. When writing to a TCP socket, write everything you have to write > with one "send" or "write" operation if at all possible. > Don't write a little at a time. That results in sending small > packets, because sockets are "flushed" after each write. There's nothing that guarantees that a single write won't be split into multiple packets, nor that multiple writes won't be coalesced into a single packet. Or any combination of splitting and coalescing that the kernel feels like. That being said, for any sane implementation, what John says is true most of the time, and is indeed a reasonable optimization. Just don't depend on it being true all the time. The most common case where it will not be true is if you're trying to send a large amount of data and exceed the MTU of the network. Then you are certain to get fragmentation. Depending on what you're doing, this can be a point of networking trivia, or it can be the difference between your application working and not working. If you're just streaming data from one place to another, you don't have to worry about it. But, if you're doing some sort of interactive protocol where you send a command, wait for a respond, send another command, etc, you really do need to be aware of how this works. Let's say you're writing something like a HTTP client. You send a bunch of headers, then expect to get back something like "200 OK\r\n", or "404 Not Found\r\n". You can't just do a read() on the socket and then examine the string to see if the first three characters are "200" or "404", because (regardless of how the server sent them), it is legal for your read() to return just a single character (i.e. "2"), and then for the next read() to get "00 OK\r\n". You need to do buffering inside your application which keeps doing read() until you find the "\r\n" (and stops there, even if the read() returned more data beyond that). From eldiener at tropicsoft.invalid Sun Jul 25 08:46:56 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 08:46:56 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 6:07 AM, Gelonida wrote: > Hi Edward, > > On 07/25/2010 04:40 AM, Edward Diener wrote: > >> I found the solutions too exotic for actual use, and completely >> ineffectual for the cases I originally cited. The people in that thread >> seem to have completely forgotten that Python can be invoked externally >> and internally both through executing 'python(w) xxx' and through >> executing a file with the file extension(s) associated with Python. They >> seem to have forgotten this can be within scripts or any other program >> using Python, both written by themselves and by others, and not just by >> their typing 'python(w) xxx' somewhere. Their solutions seem to believe >> that only they will externally be i9nvoking Python and only for their >> own written scripts, as opposed to the many libraries using Python as >> well as the Python distribution itself. >> >> The best solution is some program which changes the PATH and the Python >> file type associations depending on which version of Python one wants to >> use on one's own system when more than one Python version must coexist >> with others. I will probably write such a program for myself. >> > Hi Edward, > > changing the path and is perfect for people who use consoles. > (under linux there's virtuelenv for his and it's great) > > changing the file association is perfect for people who'd know at which > time they want to use which version of python. The problem with this is that you forget that a script can invoke Python internally. So whether one uses the console or file association method of invoking Python externally, any already written script can use either internally. > > The usecase, that I'm nore aware of however is somethig like having some > scripts / directories, that should use one version of python > and others that shoud use another. > In unix you do this normally with the 'shebang line' > ( e.g. #!/usr/bin/env/python2.6 ) > > There the windows solution could be something like a small 'pystarter' > program, which would decide depending on the file's location / the > file's first line which python should be started. This does not work when Python is invoked internally via a file association. That was the point of my saying that the simple solutions do not work. From as at sci.fi Sun Jul 25 08:47:07 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 25 Jul 2010 15:47:07 +0300 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: python at bdurham.com writes: > 1. Use an existing version control utility. There are lots of options > here(!), any recommendations on a light weight, open source one that > xcopy installs under Windows with lots of command line options? Personally, I like RCS. It seems fulfil your requirements. You can get it for Windows from http://www.cs.purdue.edu/homes/trinkle/RCS/. From eldiener at tropicsoft.invalid Sun Jul 25 08:48:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 08:48:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> References: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> Message-ID: On 7/25/2010 2:20 AM, Steven D'Aprano wrote: > On Sat, 24 Jul 2010 22:03:48 -0700, Chris Rebert wrote: > >>> Are the .py and .pyc extensions the only ones which are associated with >>> Python or are there others, for a normal Python installation in Windows >>> ? >> >> There's also .pyw > > Also .pyo > > .py = Python source code, usually associated with command line Python > .pyc = Python byte code > .pyo = Python optimized byte code > .pyw = is Windows only, and shouldn't open a console window. Thanks ! I had forgotten about .pyo and .pyw under Windows. From navkirats at gmail.com Sun Jul 25 08:50:32 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 18:20:32 +0530 Subject: Socket performance In-Reply-To: References: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> Message-ID: <80A20735-F648-454C-81E1-26B057D6D9FA@gmail.com> On 25-Jul-2010, at 5:52 PM, Roy Smith wrote: > In article <4c4bd0b1$0$1624$742ec2ed at news.sonic.net>, > John Nagle wrote: > >> 1. When writing to a TCP socket, write everything you have to write >> with one "send" or "write" operation if at all possible. >> Don't write a little at a time. That results in sending small >> packets, because sockets are "flushed" after each write. > > There's nothing that guarantees that a single write won't be split into > multiple packets, nor that multiple writes won't be coalesced into a > single packet. Or any combination of splitting and coalescing that the > kernel feels like. > > That being said, for any sane implementation, what John says is true > most of the time, and is indeed a reasonable optimization. Just don't > depend on it being true all the time. The most common case where it > will not be true is if you're trying to send a large amount of data and > exceed the MTU of the network. Then you are certain to get > fragmentation. > > Depending on what you're doing, this can be a point of networking > trivia, or it can be the difference between your application working and > not working. If you're just streaming data from one place to another, > you don't have to worry about it. But, if you're doing some sort of > interactive protocol where you send a command, wait for a respond, send > another command, etc, you really do need to be aware of how this works. > > Let's say you're writing something like a HTTP client. You send a bunch > of headers, then expect to get back something like "200 OK\r\n", or "404 > Not Found\r\n". You can't just do a read() on the socket and then > examine the string to see if the first three characters are "200" or > "404", because (regardless of how the server sent them), it is legal for > your read() to return just a single character (i.e. "2"), and then for > the next read() to get "00 OK\r\n". You need to do buffering inside > your application which keeps doing read() until you find the "\r\n" (and > stops there, even if the read() returned more data beyond that). > -- > http://mail.python.org/mailman/listinfo/python-list Thanks John, Roy. I really appreciate your valuable input. I have made a note of what you have said and will implement keeping the same in mind : ) Nav From nobody at nowhere.com Sun Jul 25 08:52:33 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 25 Jul 2010 13:52:33 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > But in the > meanwhile, once you get an error, you know what it is. You can > intentionally feed code bad data and see what you get. And then maybe > add a test to make sure your code traps such errors. That doesn't really help with exceptions which are triggered by external factors rather than explicit inputs. Also, if you're writing libraries (rather than self-contained programs), you have no control over the arguments. Coupled with the fact that duck typing is quite widely advocated in Python circles, you're stuck with the possibility that any method call on any argument can raise any exception. This is even true for calls to standard library functions or methods of standard classes if you're passing caller-supplied objects as arguments. From thomas at jollans.com Sun Jul 25 10:03:48 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 16:03:48 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C4444.6060104@jollans.com> On 07/25/2010 02:46 PM, Edward Diener wrote: > The problem with this is that you forget that a script can invoke Python > internally. So whether one uses the console or file association method > of invoking Python externally, any already written script can use either > internally. Maybe it's just me, but I think that a script that does this is quite simply badly written: it *will* break on systems that have multiple Python versions. If you let .py scripts specify which interpreter they'd like to be run with in the first line, with some sort of pystarter script that you map to the file extensions (or by using UNIX), this should work equally well no matter if the script being run by a script or by a user. If you invoke the Python interpreter directly, you should NEVER EVER assume that the interpreter is in a certain place, or on the PATH. It's a stupid idea: what if it's not? Instead, if you really must, invoke sys.executable instead of guessing. Obviously, Windows doesn't have fork(), but still, I don't see any reason to leave the comfort of your own running interpreter: you can use runpy to run python scripts. If you want them to run in the background, you can use threads, or, if you require (or want) separate processes, use multiprocessing. From news1234 at free.fr Sun Jul 25 10:31:20 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 16:31:20 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4c4c4ab8$0$8087$426a74cc@news.free.fr> On 07/25/2010 02:46 PM, Edward Diener wrote: > On 7/25/2010 6:07 AM, Gelonida wrote: >> There the windows solution could be something like a small 'pystarter' >> program, which would decide depending on the file's location / the >> file's first line which python should be started. > > This does not work when Python is invoked internally via a file > association. That was the point of my saying that the simple solutions > do not work. I'm not sure I understand. The ida is of course, that the file association would point to the pystarter and that pystarter would depending on directory / first line of the script identify the correct executable to be started with. Perhaps you could once more explain, what your intended solution would be. From gelonida at gmail.com Sun Jul 25 10:40:31 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 16:40:31 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 07/25/2010 02:46 PM, Edward Diener wrote: > On 7/25/2010 6:07 AM, Gelonida wrote: >> Hi Edward, >> >> There the windows solution could be something like a small 'pystarter' >> program, which would decide depending on the file's location / the >> file's first line which python should be started. > > This does not work when Python is invoked internally via a file > association. That was the point of my saying that the simple solutions > do not work. What do you mean with invoking python internally? call another python script? from a python script. You could start it again via a pystarter. or just with python (assuming the starter adapts the path) The problem, that I currently encounter are some scripts, which want to use python UNO (open office delivers ther own version of python) and others which want to use libraries of my 'normal' python. having the file association point to a python starter and let the python starter choose could be an option. However I never tried so far. the fast and easy option is to just have specific file suffixes for the open office python scripts (like e.g ) .oopy From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 10:47:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 14:47:11 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4c4e6f$0$11094$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 13:52:33 +0100, Nobody wrote: > On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > >> But in the >> meanwhile, once you get an error, you know what it is. You can >> intentionally feed code bad data and see what you get. And then maybe >> add a test to make sure your code traps such errors. > > That doesn't really help with exceptions which are triggered by external > factors rather than explicit inputs. Huh? What do you mean by "external factors"? Do you mean like power supply fluctuations, cosmic rays flipping bits in memory, bad hardware? You can't defend against that, not without specialist fault-tolerant hardware, so just don't worry about it. If you mean external factors like "the network goes down" or "the disk is full", you can still test for those with appropriate test doubles (think "stunt doubles", only for testing) such as stubs or mocks. It's a little bit more work (sometimes a lot more work), but it can be done. Or don't worry about it. Release early, release often, and take lots of logs. You'll soon learn what exceptions can happen and what can't. Your software is still useful even when it's not perfect, and there's always time for another bug fix release. > Also, if you're writing libraries (rather than self-contained programs), > you have no control over the arguments. You can't control what the caller passes to you, but once you have it, you have total control over it. You can reject it with an exception, stick it inside a wrapper object, convert it to something else, deal with it as best you can, or just ignore it. > Coupled with the fact that duck > typing is quite widely advocated in Python circles, you're stuck with > the possibility that any method call on any argument can raise any > exception. This is even true for calls to standard library functions or > methods of standard classes if you're passing caller-supplied objects as > arguments. That's a gross exaggeration. It's true that some methods could in theory raise any exception, but in practice most exceptions are vanishingly rare. And it isn't even remotely correct that "any" method could raise anything. If you can get something other than NameError, ValueError or TypeError by calling "spam".index(arg), I'd like to see it. Frankly, it sounds to me that you're over-analysing all the things that "could" go wrong rather than focusing on the things that actually do go wrong. That's your prerogative, of course, but I don't think you'll get much support for it here. -- Steven From targetsmart at gmail.com Sun Jul 25 11:03:06 2010 From: targetsmart at gmail.com (targetsmart) Date: Sun, 25 Jul 2010 08:03:06 -0700 (PDT) Subject: Compare two nested dictionaries Message-ID: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Hi, I am trying to compare two nested dictionaries, I want to know what is the exact difference between them. I tried this solution ... s1 = set(result1) s2 = set(result2) print s1 - s2 but it doesn't seem show any difference, but assert result1 == result2 fails could someone help me to find out the difference the two nested dictionaries. Any help is greatly appreciated. Thanks, Vivek. From kwutzke at web.de Sun Jul 25 11:41:56 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Sun, 25 Jul 2010 08:41:56 -0700 (PDT) Subject: Constructor call in the same class? Message-ID: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> What's wrong with: class Enum(RootFragment): __jpaTypes = { # complete! 'CascadeType': Enum("javax.persistence.CascadeType"), 'DiscriminatorType': Enum("javax.persistence.DiscriminatorType"), 'EnumType': Enum("javax.persistence.EnumType"), 'FetchType': Enum("javax.persistence.FetchType"), 'FlushModeType': Enum("javax.persistence.FlushModeType"), 'GenerationType': Enum("javax.persistence.GenerationType"), 'InheritanceType': Enum("javax.persistence.InheritanceType"), 'LockModeType': Enum("javax.persistence.LockModeType"), 'PersistenceContextType': Enum("javax.persistence.PersistenceContextType"), 'TemporalType': Enum("javax.persistence.TemporalType"), } # constructor def __init__(self, package, modifiers, name, superInterfaces = [], annotations = [], innerClasses = [], properties = [], methods = []): RootFragment.__init__(self, packageName, modifiers, "enum", name, superInterfaces, annotations, innerClasses, properties, methods) ? I get 'CascadeType': Enum("javax.persistence.CascadeType"), NameError: name 'Enum' is not defined What's wrong with calling a constructor in a dict initializer? How do I solve this? Karsten From thomas at jollans.com Sun Jul 25 11:53:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 17:53:01 +0200 Subject: Constructor call in the same class? In-Reply-To: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> References: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> Message-ID: <4C4C5DDD.3010004@jollans.com> On 07/25/2010 05:41 PM, Karsten Wutzke wrote: > What's wrong with: > > class Enum(RootFragment): > __jpaTypes = { > # complete! > 'CascadeType': Enum("javax.persistence.CascadeType"), > 'DiscriminatorType': > Enum("javax.persistence.DiscriminatorType"), > 'EnumType': Enum("javax.persistence.EnumType"), > 'FetchType': Enum("javax.persistence.FetchType"), > 'FlushModeType': Enum("javax.persistence.FlushModeType"), > 'GenerationType': Enum("javax.persistence.GenerationType"), > 'InheritanceType': Enum("javax.persistence.InheritanceType"), > 'LockModeType': Enum("javax.persistence.LockModeType"), > 'PersistenceContextType': > Enum("javax.persistence.PersistenceContextType"), > 'TemporalType': Enum("javax.persistence.TemporalType"), > } > > # constructor > def __init__(self, package, modifiers, name, superInterfaces = [], > annotations = [], innerClasses = [], properties = [], > methods = []): > RootFragment.__init__(self, packageName, modifiers, "enum", > name, superInterfaces, annotations, innerClasses, properties, methods) > > > ? > > I get > > 'CascadeType': Enum("javax.persistence.CascadeType"), > > NameError: name 'Enum' is not defined well, within the class statement, it's not defined. So you can't call Enum yet. You have to create your dict somewhere else. You can either set it from outside: class Enum(RootFragment): ... Enum._jpaTypes = { ... } Or, do exactly the same thing, but within a class method: class Enum(bla): @classmethod def contruct_jpatypes(cls): cls.__jpaTypes = { ... } Enum.construct_jpatypes() > > What's wrong with calling a constructor in a dict initializer? How do > I solve this? > > Karsten From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 12:21:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 16:21:14 GMT Subject: Compare two nested dictionaries References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Message-ID: <4c4c647a$0$11094$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 08:03:06 -0700, targetsmart wrote: > Hi, > I am trying to compare two nested dictionaries, I want to know what is > the exact difference between them. I tried this solution > > ... > s1 = set(result1) > s2 = set(result2) > print s1 - s2 > > but it doesn't seem show any difference, but > > assert result1 == result2 > fails > > could someone help me to find out the difference the two nested > dictionaries. Have you tried printing them and just looking for the differences? Calling set() on a dictionary will create a set from the keys only: >>> d1 = {"a": 1, "b": 2} >>> d2 = {"a": 1, "b": 999} >>> set(d1) == set(d2) True >>> d1 == d2 False If you want to know the difference between two dictionaries, you have to consider: (1) Keys that are in the first dict, but not the second; (2) Keys that are in the second dict, but not the first; and (3) Keys which are in both dicts, but have different values. -- Steven From news1234 at free.fr Sun Jul 25 12:30:30 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 18:30:30 +0200 Subject: Compare two nested dictionaries In-Reply-To: <4c4c647a$0$11094$c3e8da3@news.astraweb.com> References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> <4c4c647a$0$11094$c3e8da3@news.astraweb.com> Message-ID: <4c4c66a6$0$6823$426a74cc@news.free.fr> Hi, On 07/25/2010 06:21 PM, Steven D'Aprano wrote: > On Sun, 25 Jul 2010 08:03:06 -0700, targetsmart wrote: > >> Hi, >> I am trying to compare two nested dictionaries, I want to know what is >> the exact difference between them. I tried this solution >> >> ... >> s1 = set(result1) >> s2 = set(result2) >> print s1 - s2 >> I think you want to have the symmetric difference: try s1 ^ s2 >> but it doesn't seem show any difference, but >> From kwutzke at web.de Sun Jul 25 12:30:43 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Sun, 25 Jul 2010 09:30:43 -0700 (PDT) Subject: Constructor call in the same class? References: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> Message-ID: > > You have to create your dict somewhere else. You can either set it from > outside: > > class Enum(RootFragment): > ? ? ... > > Enum._jpaTypes = { ... } > THANKS for the quick help. Karsten From python at rcn.com Sun Jul 25 13:02:52 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 25 Jul 2010 10:02:52 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> Message-ID: <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> On Jul 24, 3:56?am, Lacrima wrote: > Thank you for your answer. You're welcome. > Some things are still not clear. Your example works great. But if I > remove "super(SuperClass1, self).__init__(**kwds)" from SuperClass1's > __init__, the example stops working. That is when I instantiate > SubClass only __init__ of SuperClass1 is called and __init__ of > SuperClass2 is omitted, i.e. only 'Python' is printed. Why is it so? > > So as I understand every parent should necessarily call super() at the > end of its __init__ method in order for things to work properly. Yes. That's correct. Python's super() was designed to support cooperative multiple inheritance. The "cooperative" part means that every class implementing the target method (such as __init__ in your example) needs to call super() in order to trigger the next method in the sequence (the method resolution order or MRO). > But what if SuperClass1 is from third party library? . . . > How to deal with that? Then, the odds are that that class isn't "cooperating". You can either wrap the third-party library to add a super() call or you can switch to an alternate design using composition instead of inheritance. Raymond P.S. Outside of the simple case of single inheritance, the one key to understanding super() is to forget about the concept of parent classes. Instead, super() is all about the MRO which is computed dynamically (unknowable at the time a class is written). Every class in the MRO implementing the target method *must* call super() to give the next class in the MRO a chance to run. IOW, using super() means "I'm in the MRO and I got a chance to run; now the next class in the MRO gets its chance." Since the MRO is only knowable at runtime, the sole job of super() is to figure out which is "the next class in the MRO". From python at rcn.com Sun Jul 25 13:20:01 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 25 Jul 2010 10:20:01 -0700 (PDT) Subject: Compare two nested dictionaries References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> <4c4c647a$0$11094$c3e8da3@news.astraweb.com> Message-ID: [targetsmart] > > I am trying to compare two nested dictionaries, I want to know what is > > the exact difference between them. I tried this solution [Steven D'Aprano] > If you want to know the difference between two dictionaries, you have to > consider: > > (1) Keys that are in the first dict, but not the second; > > (2) Keys that are in the second dict, but not the first; and > > (3) Keys which are in both dicts, but have different values. Steven, thanks for the excellent specification. Here's the code: s1 = set(d1) s2 = set(d2) first_not_second = s1 - s2 second_not_first = s2 - s1 difference_values = set(k for k in s1 & s2 if d1[k] != d2[k]) If the values are hashable, an alternate approach is: s1 = set(d1.items()) s2 = set(d2.items()) first_not_second = s1 - s2 second_not_first = s2 - s1 Raymond From joel.goldstick at columbuswebmakers.com Sun Jul 25 13:51:07 2010 From: joel.goldstick at columbuswebmakers.com (Joel Goldstick) Date: Sun, 25 Jul 2010 13:51:07 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C798B.6030100@columbuswebmakers.com> Edward Diener wrote: > Are there any documents about multiple versionsof Python coexisting in > the same OS ( Windows in my case ) and what pitfalls to look out for ? I > have already run into a number of them. I installed Python 2.7 and 3.1.2 > into completely folders, but immediately ran into serious problems > executing a Python script. > > The first problem is that just invoking Python will start whichever > version is first in the PATH, and this is true from the command line or > internally in a Python script. > > The second problem is that invoking a script ( some xxx.py ) will start > whichever version of Python is associated with the .py extension. > > The third problem is if some software expects its scripts, which it puts > in some Python subdirectory to be in the PATH. > > There may be other considerations but overall having to versions > coexisting has turned out to be a big headache involving both changes in > the PATH and in the .py association. > > Does anybody know of other things to look out for ? There is this: http://pypi.python.org/pypi/virtualenv We have a good group in NYC for python and django. That's where I learned about virtualevn. I admit I'm not fully up to speed on it, but it lets you set up multiple 'virtual environments' for python to do exactly what I think you are asking about Joel Goldstick From zooko at zooko.com Sun Jul 25 14:07:51 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Sun, 25 Jul 2010 12:07:51 -0600 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On Wed, Jul 7, 2010 at 3:32 AM, Jonathan Hartley wrote: > > I presume this problem would go away if future versions of Python > itself were compiled on Windows with something like MinGW gcc. You might want to track issue3871. Roumen Petrov has done a lot of work to make CPython compilable with mingw on Windows, as well as to make it possible to compile CPython on a different operating system and produce a CPython executable for Windows (cross-compile). And by the way, I've usually had success building my native extension modules with mingw. I understand (vaguely) that if a native extension module needs to pass FILE*'s or C++ iostreams back and forth to different extension modules or the the core CPython interpreter then this could lead to segfaults, but none of my extension modules need to do that. I would suggest that people try to build their native extension modules with mingw, and if it doesn't work report a bug (to mingw project and to the Python project) so that we can track more precisely what the issues are. Regards, Zooko http://bugs.python.org/issue3871# cross and native build of python for mingw32 with distutils From gd.usenet at spamfence.net Sun Jul 25 14:42:27 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 25 Jul 2010 20:42:27 +0200 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: python at bdurham.com wrote: >I have some very simple use cases[1] for adding some version control >capabilities to a product I'm working on. My product uses simple, text >(UTF-8) based scripts that are independent of one another. I would like >to "version control" these scripts on behalf of my users. By version >control, I mean *very-simple* version control with no branching or >merging - just the ability to store, list and restore a specific version >of a file. The data store should be a local file with the ability to >upsize to a multi-user database in the future. > >I'm looking for recommendations on possible solutions: > >1. Use an existing version control utility. There are lots of options >here(!), any recommendations on a light weight, open source one that >xcopy installs under Windows with lots of command line options? > >2. Interface to a hosted version control system (SaaS) that provides a >RESTful API. Any recommendations here? > >3. Build this capability myself using Python and Python's DBI layer to >store files in a local SQLite database at first (but with the ability to >upsize to a real client server database in the future). Seems like a fun >project to work on, but also smells like I'd be re-inventing the wheel >with very little value added other than simpler deployment? > >Any suggestions appreciated. Use Mercurial (). It is written in python, can be extended by python modules/packages and can be used by python programs directly. >1. Check a file in with optional comment and username; ideally >get a version number that can be used to reference this specific >check-in in the future. That's a basic task in mercurial (as probably in every version control system). >2. Get a history listing of all checkins for a specific file >(version number, timestamp, file size, user, comment) Also avalilable. I am not sure about file size and comment, but if you have the list of version numbers, you can extract this info from the repository easily. >3. Check out a specific version of a file by version number. See point 1. >4. Delete checked-in versions by version number, date range, >and/or username. I've never tried it with mercurial. There are a remove and a forget command. Maybe, one could use the rebase extension. But deleting changesets from a repository usually is a bad idea. >5. (Optional) Diff 2 versions of a file by version number and >return diff in richly formatted format that visually shows >changes via color and font effects (strikethru) (I'm thinking >of using BeyondCompare for this if not present in a simple >version control tool) Also available. Regards, G?nther From eldiener at tropicsoft.invalid Sun Jul 25 15:12:54 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:12:54 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 1:51 PM, Joel Goldstick wrote: > Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? >> I have already run into a number of them. I installed Python 2.7 and >> 3.1.2 into completely folders, but immediately ran into serious >> problems executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line >> or internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will >> start whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it >> puts in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes >> in the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > There is this: > http://pypi.python.org/pypi/virtualenv It appears to be only for Linux. From eldiener at tropicsoft.invalid Sun Jul 25 15:19:53 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:19:53 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 10:03 AM, Thomas Jollans wrote: > On 07/25/2010 02:46 PM, Edward Diener wrote: >> The problem with this is that you forget that a script can invoke Python >> internally. So whether one uses the console or file association method >> of invoking Python externally, any already written script can use either >> internally. > > Maybe it's just me, but I think that a script that does this is quite > simply badly written: it *will* break on systems that have multiple > Python versions. Whether it is badly written or not in your opinion it is legal and happens all the time. Are you going to refuse to use any script, no matter for what library or for what purpose, that internally invokes Python either through a 'python' command or through a file with a Python extension ? And how would you find out if a script did this or not ? Are going to search every script in every distribution and library to determine if it does this ? And when you find out a script does this, what will you do ? Be real. saying you do not like scripts that internally invoke Python does not solve anything if you have multiple coexisting versions of Python installed. From thomas at jollans.com Sun Jul 25 15:27:57 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:27:57 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C903D.9070902@jollans.com> On 07/25/2010 09:12 PM, Edward Diener wrote: > On 7/25/2010 1:51 PM, Joel Goldstick wrote: >> There is this: >> http://pypi.python.org/pypi/virtualenv > > It appears to be only for Linux. I don't know where you get that impression from. I don't know how well it works on which platforms, but the fact that there is a "Note for Windows:" does suggest that it does work on windows. From thomas at jollans.com Sun Jul 25 15:32:30 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:32:30 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C914E.307@jollans.com> On 07/25/2010 09:19 PM, Edward Diener wrote: > On 7/25/2010 10:03 AM, Thomas Jollans wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> The problem with this is that you forget that a script can invoke Python >>> internally. So whether one uses the console or file association method >>> of invoking Python externally, any already written script can use either >>> internally. >> >> Maybe it's just me, but I think that a script that does this is quite >> simply badly written: it *will* break on systems that have multiple >> Python versions. > > Whether it is badly written or not in your opinion it is legal and > happens all the time. Are you going to refuse to use any script, no > matter for what library or for what purpose, that internally invokes > Python either through a 'python' command or through a file with a Python > extension ? And how would you find out if a script did this or not ? Are > going to search every script in every distribution and library to > determine if it does this ? And when you find out a script does this, > what will you do ? > > Be real. saying you do not like scripts that internally invoke Python > does not solve anything if you have multiple coexisting versions of > Python installed. I doubt many scripts do it. The fact of the matter is: many systems have multiple Python versions installed in parallel, and it probably will break somewhere, which will get noticed, and probably fixed. If a script uses sys.executable instead of "python", there is no problem, at all. From eldiener at tropicsoft.invalid Sun Jul 25 15:33:00 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:33:00 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c4ab8$0$8087$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> Message-ID: On 7/25/2010 10:31 AM, News123 wrote: > On 07/25/2010 02:46 PM, Edward Diener wrote: >> On 7/25/2010 6:07 AM, Gelonida wrote: > >>> There the windows solution could be something like a small 'pystarter' >>> program, which would decide depending on the file's location / the >>> file's first line which python should be started. >> >> This does not work when Python is invoked internally via a file >> association. That was the point of my saying that the simple solutions >> do not work. > > I'm not sure I understand. The ida is of course, that the file > association would point to the pystarter and that pystarter would > depending on directory / first line of the script > identify the correct executable to be started with. > > > > Perhaps you could once more explain, what your intended solution would be. How does a 'pystarter' program know where the file's location is which is being invoked ? As to the first file line this is completely unrealistic. What are you going to do, alter the first file line of every script in a Python distribution and every script in every library installed in a Python distribution ? Sorry, but a less intrusive solution is much better and much less of a headache to say the least. My intended solution would be a simple program which understands where each co-existing Python distribution is installed on a system and what the "name" of that distribution is. Then you tell the program which Python distribution should be the current one by its "name", the current one meaning the distribution which you want to be invoked at any given time. The program then changes the PATH so that any references to the Python directory and its subdirectories point to the "name" Python directory tree, and changes the file associations so that the "name" Python executables handle the Python associations. This does have the weakness that I can not use more than one Python distribution while Python is executing scripts. But I can personally live with that since I have never encountered a situation where I must use more than one Python distribution at the same time. From lists at cheimes.de Sun Jul 25 15:39:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 25 Jul 2010 21:39:59 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4C4C914E.307@jollans.com> References: <4C4C914E.307@jollans.com> Message-ID: Am 25.07.2010 21:32, schrieb Thomas Jollans: > If a script uses sys.executable instead of "python", there is no > problem, at all. It's true that sys.executable is the best way if you have to start a new Python interpreter. However sys.executable may not be set for NT services. So there may be a problem after all. From thomas at jollans.com Sun Jul 25 15:48:14 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:48:14 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4C94FE.2060109@jollans.com> On 07/25/2010 09:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. Interesting. Does the multiprocessing module still work in that scenario? From news1234 at free.fr Sun Jul 25 16:04:35 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:04:35 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4c4c98d4$0$8275$426a74cc@news.free.fr> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. sys.executable will not work with scripts converted with py2exe, as sys.executable will not be the executable of the python interpreter, but with the main executable's name. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. > From thomas at jollans.com Sun Jul 25 16:18:27 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 22:18:27 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c98d4$0$8275$426a74cc@news.free.fr> References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> Message-ID: <4C4C9C13.3050404@jollans.com> On 07/25/2010 10:04 PM, News123 wrote: > sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>> If a script uses sys.executable instead of "python", there is no >>> problem, at all. > > > sys.executable will not work with scripts converted with py2exe, > as sys.executable will not be the executable of the python interpreter, > but with the main executable's name. Well, but a script converted with py2exe can't really ever assume that there is a Python interpreter, at all. From news1234 at free.fr Sun Jul 25 16:22:33 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:22:33 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> Message-ID: <4c4c9d09$0$5331$426a74cc@news.free.fr> On 07/25/2010 09:33 PM, Edward Diener wrote: > On 7/25/2010 10:31 AM, News123 wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> On 7/25/2010 6:07 AM, Gelonida wrote: > > How does a 'pystarter' program know where the file's location is which > is being invoked ? the file's location would be somewhere in sys.argv probably in sys.argv[1]. converting it to an abs path would return a directory which the python file belongs to. > As to the first file line this is completely > unrealistic. What are you going to do, alter the first file line of > every script in a Python distribution and every script in every library > installed in a Python distribution ? Sorry, but a less intrusive > solution is much better and much less of a headache to say the least. > Well I would at least do it for all of my self written scripts. It could allow a soft transition from 2.6 to 2.7 to 3.0 without having to upgrade all scripts at the same time. > My intended solution would be a simple program which understands where > each co-existing Python distribution is installed on a system and what > the "name" of that distribution is. Then you tell the program which > Python distribution should be the current one by its "name", the current > one meaning the distribution which you want to be invoked at any given > time. The program then changes the PATH so that any references to the > Python directory and its subdirectories point to the "name" Python > directory tree, and changes the file associations so that the "name" > Python executables handle the Python associations. > > This does have the weakness that I can not use more than one Python > distribution while Python is executing scripts. But I can personally > live with that since I have never encountered a situation where I must > use more than one Python distribution at the same time. > I guess it's rather difficult to find a solution which suits all. The above minor weakness, that you mention would be a killer for me. Currently I'm looking for solutions, where I can start python scripts requireing different python versions at the same time. Currently I'm staring the scripts manually from two different cmd line windows with a different path name and an explicit python call, Thus my idea of having a pystarter with a config file mentioning which directories (tools) should use which python executable From news1234 at free.fr Sun Jul 25 16:26:34 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:26:34 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> Message-ID: <4c4c9dfa$0$23878$426a74cc@news.free.fr> On 07/25/2010 10:18 PM, Thomas Jollans wrote: > On 07/25/2010 10:04 PM, News123 wrote: >> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>> If a script uses sys.executable instead of "python", there is no >>>> problem, at all. >> >> >> sys.executable will not work with scripts converted with py2exe, >> as sys.executable will not be the executable of the python interpreter, >> but with the main executable's name. > > Well, but a script converted with py2exe can't really ever assume that > there is a Python interpreter, at all. true :-) However, why I thought about this is, that I write sometimes python code, which tries to call other python files. later on for distribution I use py2exe. Therefore I use wrapper functions, which will work in either case. The wrapper could use sys.executable in 'python mode' and had to call the exe file in 'py2exe mode' From python at mrabarnett.plus.com Sun Jul 25 16:39:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jul 2010 21:39:14 +0100 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9d09$0$5331$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: <4C4CA0F2.3010203@mrabarnett.plus.com> News123 wrote: > On 07/25/2010 09:33 PM, Edward Diener wrote: >> On 7/25/2010 10:31 AM, News123 wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> On 7/25/2010 6:07 AM, Gelonida wrote: > >> How does a 'pystarter' program know where the file's location is which >> is being invoked ? > the file's location would be somewhere in sys.argv > probably in sys.argv[1]. > converting it to an abs path would return a directory which the python > file belongs to. > > >> As to the first file line this is completely >> unrealistic. What are you going to do, alter the first file line of >> every script in a Python distribution and every script in every library >> installed in a Python distribution ? Sorry, but a less intrusive >> solution is much better and much less of a headache to say the least. >> > Well I would at least do it for all of my self written scripts. > > It could allow a soft transition from 2.6 to 2.7 to 3.0 without having > to upgrade all scripts at the same time. > >> My intended solution would be a simple program which understands where >> each co-existing Python distribution is installed on a system and what >> the "name" of that distribution is. Then you tell the program which >> Python distribution should be the current one by its "name", the current >> one meaning the distribution which you want to be invoked at any given >> time. The program then changes the PATH so that any references to the >> Python directory and its subdirectories point to the "name" Python >> directory tree, and changes the file associations so that the "name" >> Python executables handle the Python associations. > > >> This does have the weakness that I can not use more than one Python >> distribution while Python is executing scripts. But I can personally >> live with that since I have never encountered a situation where I must >> use more than one Python distribution at the same time. >> > > I guess it's rather difficult to find a solution which suits all. > > The above minor weakness, that you mention would be a killer for me. > > Currently I'm looking for solutions, where I can start python scripts > requireing different python versions at the same time. > > Currently I'm staring the scripts manually from two different cmd line > windows with a different path name and an explicit python call, > > Thus my idea of having a pystarter with a config file > mentioning which directories (tools) should use which python executable > I think that's the wrong way round. A pystarter should ask the _tool_ which version of Python it needs. From eldiener at tropicsoft.invalid Sun Jul 25 17:09:00 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:09:00 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 3:32 PM, Thomas Jollans wrote: > On 07/25/2010 09:19 PM, Edward Diener wrote: >> On 7/25/2010 10:03 AM, Thomas Jollans wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> The problem with this is that you forget that a script can invoke Python >>>> internally. So whether one uses the console or file association method >>>> of invoking Python externally, any already written script can use either >>>> internally. >>> >>> Maybe it's just me, but I think that a script that does this is quite >>> simply badly written: it *will* break on systems that have multiple >>> Python versions. >> >> Whether it is badly written or not in your opinion it is legal and >> happens all the time. Are you going to refuse to use any script, no >> matter for what library or for what purpose, that internally invokes >> Python either through a 'python' command or through a file with a Python >> extension ? And how would you find out if a script did this or not ? Are >> going to search every script in every distribution and library to >> determine if it does this ? And when you find out a script does this, >> what will you do ? >> >> Be real. saying you do not like scripts that internally invoke Python >> does not solve anything if you have multiple coexisting versions of >> Python installed. > > I doubt many scripts do it. The fact of the matter is: many systems have > multiple Python versions installed in parallel, and it probably will > break somewhere, which will get noticed, and probably fixed. > > If a script uses sys.executable instead of "python", there is no > problem, at all. What a script uses to internally invoke Python I can not control. My solution seeks to be non-intrusive and lets me run a particular version of Python, among the co-existing versions installed, at any given time. I believe that is the best I can do. I neither can control, nor do I want to control, all of the Python scripts installed on my system, nor can I worry how they may internally invoke Python. But I do want to be able to say, at any given time, that when I run Python a particular version, amidst the co-existing ones on my system, needs to be executed and therafter all internally executed modules use that version. Trying to make rules for scripts, such as telling scripts they must use sys.executable, is pursuing an imaginary solution that can not work unless one is theoretically willing to manually inspect and change all Python scripts in some way. To me any intrusive changes to actual scripts is no solution at all. From eldiener at tropicsoft.invalid Sun Jul 25 17:10:47 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:10:47 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 3:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. > Once you start instrusively changing scripts to find a solution to multiple versions of Python co-existing in one system, you are heading down a path of endless problems. From eldiener at tropicsoft.invalid Sun Jul 25 17:19:04 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:19:04 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9d09$0$5331$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: On 7/25/2010 4:22 PM, News123 wrote: > On 07/25/2010 09:33 PM, Edward Diener wrote: >> On 7/25/2010 10:31 AM, News123 wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> On 7/25/2010 6:07 AM, Gelonida wrote: > >> >> How does a 'pystarter' program know where the file's location is which >> is being invoked ? > the file's location would be somewhere in sys.argv > probably in sys.argv[1]. > converting it to an abs path would return a directory which the python > file belongs to. > > >> As to the first file line this is completely >> unrealistic. What are you going to do, alter the first file line of >> every script in a Python distribution and every script in every library >> installed in a Python distribution ? Sorry, but a less intrusive >> solution is much better and much less of a headache to say the least. >> > Well I would at least do it for all of my self written scripts. > > It could allow a soft transition from 2.6 to 2.7 to 3.0 without having > to upgrade all scripts at the same time. Intrusively changing scripts is a path to Python hell. > >> My intended solution would be a simple program which understands where >> each co-existing Python distribution is installed on a system and what >> the "name" of that distribution is. Then you tell the program which >> Python distribution should be the current one by its "name", the current >> one meaning the distribution which you want to be invoked at any given >> time. The program then changes the PATH so that any references to the >> Python directory and its subdirectories point to the "name" Python >> directory tree, and changes the file associations so that the "name" >> Python executables handle the Python associations. > > >> >> This does have the weakness that I can not use more than one Python >> distribution while Python is executing scripts. But I can personally >> live with that since I have never encountered a situation where I must >> use more than one Python distribution at the same time. >> > > I guess it's rather difficult to find a solution which suits all. > > The above minor weakness, that you mention would be a killer for me. > > Currently I'm looking for solutions, where I can start python scripts > requireing different python versions at the same time. If you need that, then of course my intended solution would not work. > > Currently I'm staring the scripts manually from two different cmd line > windows with a different path name and an explicit python call, If you start scripts and point to a specific version of Python, this works in my solution also. But if an internal call to Python exists thwre is always a problem. > > Thus my idea of having a pystarter with a config file > mentioning which directories (tools) should use which python executable Well, good luck ! I don;t know how this is resolved for you when some scripts executes 'python xxx yyy' or 'someScript.py yyy'. From eldiener at tropicsoft.invalid Sun Jul 25 17:21:55 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:21:55 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9dfa$0$23878$426a74cc@news.free.fr> References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> <4c4c9dfa$0$23878$426a74cc@news.free.fr> Message-ID: On 7/25/2010 4:26 PM, News123 wrote: > On 07/25/2010 10:18 PM, Thomas Jollans wrote: >> On 07/25/2010 10:04 PM, News123 wrote: >>> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >>>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>>> If a script uses sys.executable instead of "python", there is no >>>>> problem, at all. >>> >>> >>> sys.executable will not work with scripts converted with py2exe, >>> as sys.executable will not be the executable of the python interpreter, >>> but with the main executable's name. >> >> Well, but a script converted with py2exe can't really ever assume that >> there is a Python interpreter, at all. > > true :-) > > > However, why I thought about this is, that > I write sometimes python code, which tries to call other python files. > > later on for distribution I use py2exe. > > Therefore I use wrapper functions, which will work in either case. > > The wrapper could use sys.executable in 'python mode' > and had to call the exe file in 'py2exe mode' > You can control what you do but how are you going to control what any givemn script does ? Attempting to intrusively change potentially every script in a distribution in any way is a path to Python hell IMO. From thomas at jollans.com Sun Jul 25 17:57:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 23:57:45 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4CB359.5040900@jollans.com> On 07/25/2010 11:10 PM, Edward Diener wrote: > On 7/25/2010 3:39 PM, Christian Heimes wrote: >> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>> If a script uses sys.executable instead of "python", there is no >>> problem, at all. >> >> It's true that sys.executable is the best way if you have to start a new >> Python interpreter. However sys.executable may not be set for NT >> services. So there may be a problem after all. >> > > Once you start instrusively changing scripts to find a solution to > multiple versions of Python co-existing in one system, you are heading > down a path of endless problems. What exactly is it that you're afraid to change? The standard library? There's certainly no need to change that in any way! Your own code? That'd just be nonsense. Someone else's then. Is there any problem at all when you start it with a specific Python interpreter? I expect that there probably isn't. If there is, if the code makes ANY assumptions about where to find a Python interpreter on your system, I would consider that a serious bug that should be reported. If it's only one or two affected lines of code, why not change them? There's nothing intrusive or wrong about fixing something on your own computer! If it turns out that you'd have to change a lot of code to make it work, THAT's the time to think about a complex workaround, like writing a batch file that sets up an environment in which it works, for that program. Otherwise, I don't think it's worth the effort. I'm on a Linux system with multiple Python interpreters. (Almost) all installed Python programs work with the system default interpreter (CPython 2.6). Those that don't have been fitted with shebang lines like "#!/usr/bin/python2.5". This tells the OS to use a different interpreter, like the pystarter script solution proposed in this very thread. From cournape at gmail.com Sun Jul 25 18:05:06 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 26 Jul 2010 07:05:06 +0900 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On Mon, Jul 26, 2010 at 3:07 AM, Zooko O'Whielacronx wrote: > > I would suggest that people try to build their native extension > modules with mingw, and if it doesn't work report a bug (to mingw > project and to the Python project) so that we can track more precisely > what the issues are. To be clear, building extensions with mingw for the official python works well. Numpy and scipy official binaries have been built with mingw for years. There are problems for 64 bits binaries, though David From sonicrules1234 at gmail.com Sun Jul 25 20:08:47 2010 From: sonicrules1234 at gmail.com (Westly Ward) Date: Sun, 25 Jul 2010 17:08:47 -0700 Subject: Python acting weird Message-ID: x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder", "name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py", "compressed":False, "contents":"blahblahfilecontents"}]}]} print x def setindict(dictionary, keys, value) : if len(keys) == 1 : if keys[0].isdigit() and int(keys[0]) == len(dictionary) : dictionary.append(keys[0]) else : dictionary[keys[0]] = value else : dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value) return dictionary a = x.copy() print id(a), id(x) y = setindict(a, ["data", 0, "data", 0, "compressed"], True) if y == x : print True else : print False print x print a How are x and a are ending up the same? I would think .copy() would make it completely seperate. From clp2 at rebertia.com Sun Jul 25 20:29:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 25 Jul 2010 17:29:33 -0700 Subject: Python acting weird In-Reply-To: References: Message-ID: On Sun, Jul 25, 2010 at 5:08 PM, Westly Ward wrote: > x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder", > "name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py", > "compressed":False, "contents":"blahblahfilecontents"}]}]} > print x > def setindict(dictionary, keys, value) : > ? ?if len(keys) == 1 : > ? ? ? ?if keys[0].isdigit() and int(keys[0]) == len(dictionary) ?: > ? ? ? ? ? ?dictionary.append(keys[0]) > ? ? ? ?else : > ? ? ? ? ? ?dictionary[keys[0]] = value > ? ?else : > ? ? ? ?dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value) > ? ?return dictionary > a = x.copy() > > print id(a), id(x) > y = setindict(a, ["data", 0, "data", 0, "compressed"], True) > if y == x : > ? ?print True > > else : > ? ?print False > print x > print a > > How are x and a are ending up the same? ?I would think .copy() would > make it completely seperate. Nope, .copy() only makes a "shallow" copy of the outermost dict, not a recursive "deep" copy; the 2 dictionaries initially point to the *exact* same objects for their keys and values. a = x.copy() assert x is not a # wouldn't be much of a copy otherwise assert x["data"] is a["data"] # no recursive copying though # separate dicts, so rebinding the items of one doesn't affect the other x[42] = 12 assert 42 not in a # mutating the items in one does affect the other however x["data"].append(7) assert a["data"].pop() == 7 # remember that x[y] = z === x.__setitem__(y, z) # so we can write a similar example thusly: x["data"][0] = 8 assert a["data"][0] == 8 # again, rebinding at the outermost level is independent x["data"] = 99 assert a["data"] != x["data"] For a deep copy, use copy.deepcopy() in the std lib: http://docs.python.org/library/copy.html#copy.deepcopy Cheers, Chris -- http://blog.rebertia.com From greg.ewing at canterbury.ac.nz Sun Jul 25 20:30:08 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 26 Jul 2010 12:30:08 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> Message-ID: <8b42njFemaU1@mid.individual.net> Raymond Hettinger wrote: > Every class > in the MRO implementing the target method *must* call super() to give > the next class in the MRO a chance to run. EXCEPT for the last one, which must NOT call super! The posted example happens to work because object has a default __init__ method that does nothing. But this is not generally true of other methods, which means you need a "terminating" class at the end of the MRO whose methods don't call super. -- Greg From eldiener at tropicsoft.invalid Sun Jul 25 20:40:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 20:40:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 5:57 PM, Thomas Jollans wrote: > On 07/25/2010 11:10 PM, Edward Diener wrote: >> On 7/25/2010 3:39 PM, Christian Heimes wrote: >>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>> If a script uses sys.executable instead of "python", there is no >>>> problem, at all. >>> >>> It's true that sys.executable is the best way if you have to start a new >>> Python interpreter. However sys.executable may not be set for NT >>> services. So there may be a problem after all. >>> >> >> Once you start instrusively changing scripts to find a solution to >> multiple versions of Python co-existing in one system, you are heading >> down a path of endless problems. > > What exactly is it that you're afraid to change? I do not want to intrusively change any script that has been installed as part of Python. I shouldn't even have to know about the code in these scripts other than what good documentation tells me in how to use them. That's not to say having source is worthless. I am just not going to change source to get a version of Python to work properly when I have 2 or more versions installed in their own separate folders. > > The standard library? There's certainly no need to change that in any way! So if a standard library module ( or distributed library ) executes a call internally to 'python xxx yyy' or executes a call internally to 'someScript.py yyy', you're fine with multiple co-existing versions of Python on your system ? Because under Windows the first call will look for the python.exe first found in the PATH while the second call will find the python.exe associated with the .py extension. And it does not matter in either case what version of the multiple installed versions of Python which are on my system is currently executing that script. And please don't say that there is some sort of guarantee that no library or installation would invoke Python in such a way as opposed to the normal 'import AScript.py' method of using functionality in Python scripts. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 20:41:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 00:41:25 GMT Subject: Multiple versions of Python coexisting in the same OS References: Message-ID: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 15:19:53 -0400, Edward Diener wrote: > On 7/25/2010 10:03 AM, Thomas Jollans wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> The problem with this is that you forget that a script can invoke >>> Python internally. So whether one uses the console or file association >>> method of invoking Python externally, any already written script can >>> use either internally. >> >> Maybe it's just me, but I think that a script that does this is quite >> simply badly written: it *will* break on systems that have multiple >> Python versions. > > Whether it is badly written or not in your opinion it is legal and > happens all the time. Yes, people write poorly written, buggy scripts all the time. Just because code is legal syntax doesn't mean it does what is intended, or that what is intended is sensible. If you have multiple versions of Python installed, and you call "python somescript.py" without knowing *which* Python will be called, it is neither sensible nor does it do what you intend. End of story. This is no different from calling any other application without knowing what version you will get, then relying on features that are only available in some versions. It is just buggy code. > Are you going to refuse to use any script, no > matter for what library or for what purpose, that internally invokes > Python either through a 'python' command or through a file with a Python > extension ? And how would you find out if a script did this or not ? Are > going to search every script in every distribution and library to > determine if it does this ? And when you find out a script does this, > what will you do ? Treat it like any script with a bug: fix the bug, stop using the script, or determine a work-around that masks the bug. All three are acceptable, the third being the least acceptable because it just leaves a bug waiting to bite you again in the future. > Be real. saying you do not like scripts that internally invoke Python > does not solve anything if you have multiple coexisting versions of > Python installed. No, it solves it completely. Treat it as a bug, and fix it. If you're not willing to treat it as a bug, then uninstall all but one of the Python versions, and the problem goes away. You might have a different problem, namely that some scripts stop working, but now the solution is obvious and straight-forward: fix the scripts that aren't working. Or rename the Python applications, so that scripts can easily call the right version without getting confused. Trying to make some brittle, Do-What-I-Mean solution for trying to auto- magically select between Python versions is pursuing a path of endless problems. Any solution that doesn't fix the actual problem, namely that the scripts are buggy, is at best just a work-around and at worst is no solution at all. -- Steven From ben+python at benfinney.id.au Sun Jul 25 21:04:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 26 Jul 2010 11:04:27 +1000 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: <87tynn3vfo.fsf@benfinney.id.au> "G?nther Dietrich" writes: > python at bdurham.com wrote: > > >I have some very simple use cases[1] for adding some version control > >capabilities to a product I'm working on. [?] > >I'm looking for recommendations on possible solutions: > > > >1. Use an existing version control utility. [?] > Use Mercurial (). It is written in > python, can be extended by python modules/packages and can be used by > python programs directly. Either of Mercurial or Bazaar will be good choices for the requirements specified. All of G?nther's comments (including those I trimmed in this reply) apply equally to both Mercurial and Bazaar. You might like to ask questions in each of the support forums for those tools for more information. -- \ ?To punish me for my contempt of authority, Fate has made me an | `\ authority myself.? ?Albert Einstein, 1930-09-18 | _o__) | Ben Finney From drobinow at gmail.com Sun Jul 25 22:42:52 2010 From: drobinow at gmail.com (David Robinow) Date: Sun, 25 Jul 2010 22:42:52 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener wrote: > On 7/25/2010 5:57 PM, Thomas Jollans wrote: > So if a standard library module ( or distributed library ) executes a call > internally to 'python xxx yyy' or executes a call internally to > 'someScript.py yyy', you're fine with multiple co-existing versions of > Python on your system ? > > Because under Windows the first call will look for the python.exe first > found in the PATH while the second call will find the python.exe associated > with the .py extension. And it does not matter in either case what version > of the multiple installed versions of Python which are on my system is > currently executing that script. > > And please don't say that there is some sort of guarantee that no library or > installation would invoke Python in such a way as opposed to the normal > 'import AScript.py' method of using functionality in Python scripts. Edward, I'm having a really hard time understanding your problem. Could you give an example of some real code that is causing you difficulty? From eldiener at tropicsoft.invalid Sun Jul 25 23:08:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 23:08:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> References: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> Message-ID: On 7/25/2010 8:41 PM, Steven D'Aprano wrote: > On Sun, 25 Jul 2010 15:19:53 -0400, Edward Diener wrote: > >> On 7/25/2010 10:03 AM, Thomas Jollans wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> The problem with this is that you forget that a script can invoke >>>> Python internally. So whether one uses the console or file association >>>> method of invoking Python externally, any already written script can >>>> use either internally. >>> >>> Maybe it's just me, but I think that a script that does this is quite >>> simply badly written: it *will* break on systems that have multiple >>> Python versions. >> >> Whether it is badly written or not in your opinion it is legal and >> happens all the time. > > Yes, people write poorly written, buggy scripts all the time. Just > because code is legal syntax doesn't mean it does what is intended, or > that what is intended is sensible. > > If you have multiple versions of Python installed, and you call "python > somescript.py" without knowing *which* Python will be called, it is > neither sensible nor does it do what you intend. End of story. Somebody is supplying you with a Python script and internally invoking Python again. But that somebody does not have to be myself. I am neither buying "End of story" nor that invoking Python internally is an error. But if you believe it to be then you can root out all such Python code, or correct it as you like. Even with co-existing versions of Python installed I have better things to do with my time and therefore will pursue a solution that will work for me in the face of such code. From michele.simionato at gmail.com Sun Jul 25 23:53:17 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 25 Jul 2010 20:53:17 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: Message-ID: <96c84ffc-b264-4226-802f-97bea8b9fd43@t2g2000yqe.googlegroups.com> Everything you ever wanted to know about super is collected here: http://micheles.googlecode.com/hg/artima/python/super.pdf M.S. From benjamin.kaplan at case.edu Sun Jul 25 23:54:30 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 25 Jul 2010 20:54:30 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: Python-list is comp.lang.python turned into mailing list form. gmane is python-list turned back into a newsgroup. The reason it gets less spam is because it's behind the mailing list's spam filters. Both the mailing list and gmane should see the same amount of spam. which is way less than the original newsgroup/Google Group sees. On Sat, Jul 24, 2010 at 12:28 PM, Jia Hu wrote: > I subscribe for this mailing list at > http://mail.python.org/mailman/listinfo/python-list > > On Sat, Jul 24, 2010 at 3:22 PM, Jia Hu wrote: >> >> Hi, can I subscribe this by gmail? >> >> On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence >> wrote: >>> >>> On 24/07/2010 18:01, Dennis Lee Bieber wrote: >>>> >>>> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >>>> declaimed the following in gmane.comp.python.general: >>>> >>>>> But maybe owner of this group do no care in that case we *all* get >>>>> spammed! >>>> >>>> ? ? ? ?There is NO OWNER of comp.lang.python; and turning a comp.* group >>>> into moderated takes a fairly long time assuming you can find someone >>>> willing to be the moderators -- what would likely happen is that >>>> comp.lang.python.moderated would be created and then take a few months >>>> to be picked up by the servers, and a few more months for the real users >>>> to leave comp.lang.python to use it. >>>> >>>> ? ? ? ?Oh, and also the hassle of the mailing-list<>usenet gateway (does >>>> it >>>> pass traffic to both groups, drop the existing one, etc.). And readers >>>> on Google may still see spam if Google takes posts stuff before it >>>> passes through the moderation board. >>> >>> For the benefit of those who might have missed it, I'll repeat that I'm >>> reading this from gmane.comp.python.general and see little or no spam. >>> >>> Regards. >>> >>> Mark Lawrence. >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From gunnyt100 at gmail.com Mon Jul 26 00:02:17 2010 From: gunnyt100 at gmail.com (gunny secondclass) Date: Sun, 25 Jul 2010 21:02:17 -0700 (PDT) Subject: Free dell laptops offered by bill gates foundation Message-ID: Free dell laptops offered by bill gates foundation?.no need money? No need registration fee?.no need transport charges?..details available on my blog. if you want to get free laptop, click A DELL IMAGE at the TOP Side of my BLOG. .then open full detais. Get it free 100% and enjoy. First 10,000 people only.hurry up. my blog is http://freelaptopsandfreewebhosting.blogspot.com/ From tazimkolhar at gmail.com Mon Jul 26 00:02:55 2010 From: tazimkolhar at gmail.com (tazimk) Date: Sun, 25 Jul 2010 21:02:55 -0700 (PDT) Subject: obtaining pid of child process Message-ID: Hi, I am using python's multiprocessing module to spawn new process as follows : import multiprocessing import os d = multiprocessing.Process(target=os.system,args=('iostat 2 > a.txt',)) d.start() I want to obtain pid of iostat command or the command executed using multiprocessing module When I execute : d.pid it gives me pid of subshell in which this command is running . Any help will be valuable . Thanks in advance From nobody at nowhere.com Mon Jul 26 00:27:50 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 26 Jul 2010 05:27:50 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> <4c4c4e6f$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Sun, 25 Jul 2010 14:47:11 +0000, Steven D'Aprano wrote: >>> But in the >>> meanwhile, once you get an error, you know what it is. You can >>> intentionally feed code bad data and see what you get. And then maybe >>> add a test to make sure your code traps such errors. >> >> That doesn't really help with exceptions which are triggered by external >> factors rather than explicit inputs. > > Huh? What do you mean by "external factors"? I mean this: > If you mean external factors like "the network goes down" or "the disk is > full", > you can still test for those with appropriate test doubles (think > "stunt doubles", only for testing) such as stubs or mocks. It's a little > bit more work (sometimes a lot more work), but it can be done. I'd say "a lot" is more often the case. >> Also, if you're writing libraries (rather than self-contained programs), >> you have no control over the arguments. > > You can't control what the caller passes to you, but once you have it, > you have total control over it. Total control insofar as you can wrap all method calls in semi-bare excepts (i.e. catch any Exception but not Interrupt). >> Coupled with the fact that duck >> typing is quite widely advocated in Python circles, you're stuck with >> the possibility that any method call on any argument can raise any >> exception. This is even true for calls to standard library functions or >> methods of standard classes if you're passing caller-supplied objects as >> arguments. > > That's a gross exaggeration. It's true that some methods could in theory > raise any exception, but in practice most exceptions are vanishingly > rare. Now *that* is a gross exaggeration. Exceptions are by their nature exceptional, in some sense of the word. But a substantial part of Python development is playing whac-a-mole with exceptions. Write code, run code, get traceback, either fix the cause (LBYL) or handle the exception (EAFP), wash, rinse, repeat. > And it isn't even remotely correct that "any" method could raise > anything. If you can get something other than NameError, ValueError or > TypeError by calling "spam".index(arg), I'd like to see it. How common is it to call methods on a string literal in real-world code? It's far, far more common to call methods on an argument or expression whose value could be any "string-like object" (e.g. UserString or a str subclass). IOW, it's "almost" correct that any method can raise any exception. The fact that the number of counter-examples is non-zero doesn't really change this. Even an isinstance() check won't help, as nothing prohibits a subclass from raising exceptions which the original doesn't. Even using "type(x) == sometype" doesn't help if x's methods involve calling methods of user-supplied values (unless those methods are wrapped in catch-all excepts). Java's checked exception mechanism was based on real-world experience of the pitfalls of abstract types. And that experience was gained in environments where interface specifications were far more detailed than is the norm in the Python world. > Frankly, it sounds to me that you're over-analysing all the things that > "could" go wrong rather than focusing on the things that actually do go > wrong. See Murphy's Law. > That's your prerogative, of course, but I don't think you'll get > much support for it here. Alas, I suspect that you're correct. Which is why I don't advocate using Python for "serious" software. Neither the language nor its "culture" are amenable to robustness. From clp2 at rebertia.com Mon Jul 26 00:29:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 25 Jul 2010 21:29:09 -0700 Subject: obtaining pid of child process In-Reply-To: References: Message-ID: On Sun, Jul 25, 2010 at 9:02 PM, tazimk wrote: > Hi, > > I am using python's multiprocessing module to spawn new process > > as follows : > > import multiprocessing > import os > d = multiprocessing.Process(target=os.system,args=('iostat 2 > > a.txt',)) > d.start() > > I want to obtain pid of iostat command or the command executed using > multiprocessing module `multiprocessing` isn't the best module for this; use `subprocess` instead: from subprocess import Popen, PIPE process = Popen(["iostat"], stderr=open("a.txt", 'w'), stdout=PIPE) print("the PID is", process.pid) `multiprocessing` is used for parallelism in Python code, as an alternative to threads. `subprocess` is used for running external commands, as a preferred alternative to os.system() among other things. Cheers, Chris -- http://blog.rebertia.com From eldiener at tropicsoft.invalid Mon Jul 26 00:36:47 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 26 Jul 2010 00:36:47 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 10:42 PM, David Robinow wrote: > On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener > wrote: >> On 7/25/2010 5:57 PM, Thomas Jollans wrote: >> So if a standard library module ( or distributed library ) executes a call >> internally to 'python xxx yyy' or executes a call internally to >> 'someScript.py yyy', you're fine with multiple co-existing versions of >> Python on your system ? >> >> Because under Windows the first call will look for the python.exe first >> found in the PATH while the second call will find the python.exe associated >> with the .py extension. And it does not matter in either case what version >> of the multiple installed versions of Python which are on my system is >> currently executing that script. >> >> And please don't say that there is some sort of guarantee that no library or >> installation would invoke Python in such a way as opposed to the normal >> 'import AScript.py' method of using functionality in Python scripts. > Edward, I'm having a really hard time understanding your problem. > Could you give an example of some real code that is causing you > difficulty? I start a Python script for version X by going to X's root directory and invoking 'python someScript.py' from the command line. Does that not sound reasonable ? In SomeScript.py there is an internal call to 'python someOtherScript.y someParameters'. But the call invokes another version of Python because it is that version which is in the PATH. Or in SomeScript.py there is an internal call to 'someOtherScript.py someParameters'. But the call invokes another version of Python because the .py extension is associated with a different version. My solution is that I will write some code which sets a particular version of Python as the current version for a particular time, meaning that version will be in the PATH and associated with Python extensions. The way I do not have to worry when I externally invoke Python from the command line that internal calls are going to some other version. From animator333 at gmail.com Mon Jul 26 01:32:57 2010 From: animator333 at gmail.com (King) Date: Sun, 25 Jul 2010 22:32:57 -0700 (PDT) Subject: Undo-Redo, copy instance, custom events and a problem Message-ID: <9e3b430e-c672-4ea9-8fd0-79f852732ec3@g6g2000pro.googlegroups.com> Hi, I am developing an app using wxPython. The Undo-Redo implementation is based on storing pre & post state of an attribute. You store the instance before changing the value and store the instance after changing the values. While undoing or redoing, you copy/replace the current state with stored once. For color attribute as soon as you choose a color, here is the code: # Custom Event evt = ValueChangeEvent(EVT_COLOR_CHANGED.typeId, self.GetId()) # Store Pre State evt.SetPreState(copy.copy(self.attribute)) # Change the newly selected color self.attribute.setValue(R,G,B) # Store Post State evt.SetPostState(copy.copy(self.attribute)) # Throw Custom Event self.GetEventHandler().ProcessEvent(evt) Both states are copied as new instance with correct values. The problem is when this event is getting fired. evt.GetPreState().GetValue() is showing the post color value. Although GetPreState() & GetPostState() are showing two different instances but I have no idea why values are not coming/stored correctly. Some where in between is messed up and post-state values are copied in pre-state. On a side note, self.attribute.setValue takes three floating values for R,G & B colors but stored them as a text. Similarly self.attribute.getValue() converts text into float and returns. Is there anything related to scope or something? Cheers Prashant From steve-REMOVE-THIS at cybersource.com.au Mon Jul 26 01:34:00 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 05:34:00 GMT Subject: Multiple versions of Python coexisting in the same OS References: <4C4C914E.307@jollans.com> Message-ID: <4c4d1e48$0$11102$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 00:36:47 -0400, Edward Diener wrote: > On 7/25/2010 10:42 PM, David Robinow wrote: [...] >> Edward, I'm having a really hard time understanding your problem. Could >> you give an example of some real code that is causing you difficulty? > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? No it doesn't, it's a very unreasonable thing to do. If you have multiple versions of Python, you should name them appropriately so you can launch the appropriate version from any directory: python26 someScript.py # calls python31 secondScript.py internally python31 anotherScript.py # calls python25 thirdScript.py internally etc. Or give the full path to the executable: C:\Programs\python26\python.exe someScript.py # calls C:\Programs\python31\python.exe secondScript.py internally If a script doesn't do this, then the script should be treated as buggy. > In SomeScript.py there is an internal call to 'python someOtherScript.y > someParameters'. That's a pretty dodgy thing to do in the first place, unless you can guarantee that there's only one executable called python. Otherwise, how do you know which one will be called? You can't easily predict which one will be called, so don't do it unless you want your scripts to call arbitrary executables. > But the call invokes another version of Python because > it is that version which is in the PATH. Or in SomeScript.py there is an > internal call to 'someOtherScript.py someParameters'. But the call > invokes another version of Python because the .py extension is > associated with a different version. Exactly. The root of your problem is that there are multiple executables called "python" and you don't know which one you will get. So don't do that. > My solution is that I will write some code which sets a particular > version of Python as the current version for a particular time, meaning > that version will be in the PATH and associated with Python extensions. /facepalm > The way I do not have to worry when I externally invoke Python from the > command line that internal calls are going to some other version. Good luck with that. -- Steven From gelonida at gmail.com Mon Jul 26 03:24:08 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:24:08 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: >> >> Thus my idea of having a pystarter with a config file >> mentioning which directories (tools) should use which python executable > > Well, good luck ! I don;t know how this is resolved for you when some > scripts executes 'python xxx yyy' or 'someScript.py yyy'. both could be resolved with a python starter if one wanted. call the python starter python.exe and put it first in the path. set the python file associations to the python starter. By the way: Something similiar (not identical) has been used for linux hosts in big companies in order to easily switch between different projects. (which potentilly had different versions of development tools) instead of having multiple .cshrc / .bashrc files the first entry of path has been set to /_WRAPPER_/bin (or something similiar) in this directory one found a wrapper script for each tool to be wrapped. ( one script, many symlinks for each tool) the wrapper script took a global setup, the project name and a private setup to finally call the the desired script. What is missing is to choose the executable depending on the script to be called. If one has a wrapper this could be added. Just a question of style, whether the decision which script to be called should come from the - user - a config file ( No script to be intrusively changed, what Edward seems to prefer ) - some coding in the script or the tool's directory ( which MRAB seems to prefer ) From gelonida at gmail.com Mon Jul 26 03:26:27 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:26:27 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4C4CA0F2.3010203@mrabarnett.plus.com> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> <4C4CA0F2.3010203@mrabarnett.plus.com> Message-ID: On 07/25/2010 10:39 PM, MRAB wrote: > News123 wrote: >> Thus my idea of having a pystarter with a config file >> mentioning which directories (tools) should use which python executable >> > I think that's the wrong way round. A pystarter should ask the _tool_ > which version of Python it needs. Hm, it's dfifficult to think about a solution satisfying everyone. Edward seems to insist on a non intrusive solution, where no script is changed (thus my idea of a config file) I personally would probably add information to all of my self written scripts and create a config file for all other tools (or add a marker file n the path of these tools) From peterwfh2000 at gmail.com Mon Jul 26 03:36:03 2010 From: peterwfh2000 at gmail.com (PETER WONG F H (+971 50 8320722)) Date: Mon, 26 Jul 2010 00:36:03 -0700 (PDT) Subject: JBR , RENT TO OWN or BUY WITH NO MONEY DOWN ,050-8320722 Message-ID: <34039719-d1e6-4a08-bda0-734865f79a4b@d8g2000yqf.googlegroups.com> JBR , RENT TO OWN or BUY WITH NO MONEY DOWN ,050-8320722 JBR Lower market price AED800per/sqft 2 unit (3Bed + Maid) (1800sqft to 3000sqft) +Transfer Fee 2 % + Broker Fee 2% For a program which helped hundreds of tenants in DUBAI/UAE become homeowners who had NO MONEY for the down payment and legal fees? We at REAL ESTATE BROKER take great pleasure in extending our warmest welcome in what will prove to be the first step in owning your own home. Even on a starter home the costs of the down payment, surveys, appraisals, land transfer FEES, legal fees and other disbursements can easily amount to AED10,000 or AED12,000. If you find it impossible to save that amount of money while paying rent in addition to all your other day-to-day expenses this program may be the solution you've been looking for. Why RENT when you can OWN. Peter Wong F.H ??? (????RERA BRN: 8866) Mob ?? : +971 50 83 20 722 E-mail ?? : peterwfh2000 at gmail.com Website : http://groups.google.com/group/dubai-property-club From gelonida at gmail.com Mon Jul 26 03:45:45 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:45:45 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 07/26/2010 06:36 AM, Edward Diener wrote: > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? Do you have an example of two (not self written) applications requiring to change the python file association in order to be working? I never had problems with this, so would be curious about the tools to avoid. Apart from that my suggestion for you would be: Don't write a tool. Just create one .bat file for each sript to be started. The bat file should set the python search path. This should cover 90% of existing python scripts. (If you want, you could write a tool to create the bat files) Now the second problem. if a python script starts another python file without calling python.exe but via the file associations, then above solution would not be sufficient/ you had to additionally change the file associations, (which can easily be done from a bat file as well if you insist. The commands you need are 'assoc' and 'ftype') But does this really happen to you? Please note: Trying to develop a solution, which believes that you will never have two concurrent applications requiring two differnt python versions sounds a little dangerous. From hv at tbz-pariv.de Mon Jul 26 04:56:48 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 26 Jul 2010 10:56:48 +0200 Subject: non-blocking IO EAGAIN on write In-Reply-To: <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> References: <8at354F51tU1@mid.individual.net> <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> Message-ID: <8b50u2F8ijU1@mid.individual.net> John Nagle wrote: > On 7/23/2010 1:45 AM, Thomas Guettler wrote: >> Hi, >> >> I use non-blocking io to check for timeouts. Sometimes I get EAGAIN >> (Resource temporarily unavailable) >> on write(). My working code looks like this. But I am unsure how many >> bytes have been written to the >> pipe if I get an EAGAIN IOError. .... > Since your code isn't doing anything else while waiting for a > write to complete on the pipe, why use non-blocking I/O at all? > > (I know, the Python I/O timeout logic is broken in some versions. > You're probably working around that.) I want to handle timeouts. The app runs on linux, but I don't want to use signals, since it is in a wsgi context: http://code.google.com/p/modwsgi/wiki/ApplicationIssues > .. As a general rule therefore, no WSGI application component should > attempt to register its own signal handlers. > The hint of Kushal was right: The timeout was reached, and I didn't check the result of the select call. -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 06:20:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 12:20:59 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4c4d618b$0$9222$426a74cc@news.free.fr> dmitrey a ?crit : (snip) > This doesn't stack with the following issue: sometimes user can write > in code "myObject.size = (some integer value)" and then it will be > involved in future calculations as ordinary fixed value; if user > doesn't supply it, but myObject.size is involved in calculations, then > the oofun is created to behave like similar numpy.array attribute. IOW, you want a default value for the size if it has not been specified by the user, so you can safely use this attribute in computations. The more straightforward solution is to define this attribute (with the default value) in the initialiser, ie: class MyClass(object): def __init__(self, x, y): self.x = x self.y = y self.size = Whatever() If you don't want to create as many Whatever instances as MyClass instances, you can create a single Whatever instance before defining your class: DEFAULT_WHATEVER = Whathever() class MyClass(object): def __init__(self, x, y): self.x = x self.y = y self.size = DEFAULT_WHATEVER HTH From san82moon at gmail.com Mon Jul 26 06:25:19 2010 From: san82moon at gmail.com (lee) Date: Mon, 26 Jul 2010 03:25:19 -0700 (PDT) Subject: ValueError: invalid literal for int(): Message-ID: Hi, I have a value, partintid = int(Screw plugg (91_10 -> untitled)) but i get ValueError: invalid literal for int(): Screw plugg (91_10 - > untitled) any help? - Sunny From ldo at geek-central.gen.new_zealand Mon Jul 26 06:30:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 26 Jul 2010 22:30:34 +1200 Subject: Multiprocessing zombie processes References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: In message , Chris Rebert wrote: > "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. > Frankenstein." > > Most people try to /avoid/ making zombies. Is there some connection between Frankenstein and zombies? From clp2 at rebertia.com Mon Jul 26 06:40:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 03:40:39 -0700 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: On Mon, Jul 26, 2010 at 3:30 AM, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. >> Frankenstein." >> >> Most people try to /avoid/ making zombies. > > Is there some connection between Frankenstein and zombies? His monster is zombie-ish; it's made of reanimated corpse parts. It's also mentioned in Wikipedia's "Zombie" article as influencing future works about the undead. Cheers, Chris -- Not a perfect comedic reference, I admit. From duncan.booth at invalid.invalid Mon Jul 26 06:55:28 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Jul 2010 10:55:28 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > If you don't want to create as many Whatever instances as MyClass > instances, you can create a single Whatever instance before defining > your class: > > DEFAULT_WHATEVER = Whathever() > > class MyClass(object): > def __init__(self, x, y): > self.x = x > self.y = y > self.size = DEFAULT_WHATEVER > > Or you could create the default as a class attribute and it can be overridden in those instances which need a different value. class MyClass(object): size = Whatever() def __init__(self, x, y): self.x = x self.y = y -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Mon Jul 26 06:55:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 03:55:46 -0700 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: > Hi, > > I have a value, > > partintid = int(Screw plugg ?(91_10 -> untitled)) > > but i get ValueError: invalid literal for int(): Screw plugg ?(91_10 - >> untitled) > any help? That is most certainly not your actual exact code, since it has a few SyntaxErrors and thus Python would have bailed-out long before it ever got the chance to raise ValueError. Please copy-and-paste the *actual exact code* and exact error message. Also, next time say what the desired output/behavior you're seeking is. That being said, if your code is (as I suspect) in actuality: partintid = int("Screw plugg ?(91_10 -> untitled)") then I would agree with int() and say that that string is nowhere close to representing an integer (how precisely is "Screw" to be interpreted as an integer, pray tell?); so what's so surprising about getting an error when trying to convert it to one? I suspect you're trying to extract 91 or 10 from the string. Use string methods[1] to parse the desired numerical section out of the string, and then pass the resulting numerical string to int(), which will accept it without error and properly convert it. If you want more detailed help, please provide a specification of typical input strings and desired output integers. [1]: http://docs.python.org/library/stdtypes.html#string-methods Regards, Chris -- http://blog.rebertia.com From san82moon at gmail.com Mon Jul 26 07:03:19 2010 From: san82moon at gmail.com (Sunny chilgod) Date: Mon, 26 Jul 2010 16:33:19 +0530 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: Hi Chris, Thanks for your help. but i need to to convert the whole string to int. heres my full code, ptid = 'item_01bom' so item_01bom is a field name in form, so i get its value, partintid = int(form[ptid]). # the value of form[ptid] is 'Screw plugg (91_10 - untitled)' Hence i get the error. hope i am clear now. - Sunny On Mon, Jul 26, 2010 at 4:25 PM, Chris Rebert wrote: > On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: > > Hi, > > > > I have a value, > > > > partintid = int(Screw plugg (91_10 -> untitled)) > > > > but i get ValueError: invalid literal for int(): Screw plugg (91_10 - > >> untitled) > > any help? > > That is most certainly not your actual exact code, since it has a few > SyntaxErrors and thus Python would have bailed-out long before it ever > got the chance to raise ValueError. Please copy-and-paste the *actual > exact code* and exact error message. > Also, next time say what the desired output/behavior you're seeking is. > > That being said, if your code is (as I suspect) in actuality: > > partintid = int("Screw plugg (91_10 -> untitled)") > > then I would agree with int() and say that that string is nowhere > close to representing an integer (how precisely is "Screw" to be > interpreted as an integer, pray tell?); so what's so surprising about > getting an error when trying to convert it to one? > > I suspect you're trying to extract 91 or 10 from the string. Use > string methods[1] to parse the desired numerical section out of the > string, and then pass the resulting numerical string to int(), which > will accept it without error and properly convert it. > > If you want more detailed help, please provide a specification of > typical input strings and desired output integers. > > [1]: http://docs.python.org/library/stdtypes.html#string-methods > > Regards, > Chris > -- > http://blog.rebertia.com > -- All that we are is the result of what we have thought. The mind is everything. What we think we become. Regards, Sunny -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jul 26 07:12:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 04:12:33 -0700 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: > On Mon, Jul 26, 2010 at 4:25 PM, Chris Rebert wrote: >> On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: >> > Hi, >> > >> > I have a value, >> > >> > partintid = int(Screw plugg ?(91_10 -> untitled)) >> > >> > but i get ValueError: invalid literal for int(): Screw plugg ?(91_10 - >> >> untitled) >> > any help? >> I suspect you're trying to extract 91 or 10 from the string. Use >> string methods[1] to parse the desired numerical section out of the >> string, and then pass the resulting numerical string to int(), which >> will accept it without error and properly convert it. >> >> If you want more detailed help, please provide a specification of >> typical input strings and desired output integers. >> >> [1]: http://docs.python.org/library/stdtypes.html#string-methods On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod wrote: > Hi Chris, > Thanks for your help. but i need to to convert the whole string to int. > heres my full code, > ptid = 'item_01bom' > so item_01bom is a field name in form, so i get its value, > partintid = int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg > ?(91_10 -?untitled)' > Hence i get the error. hope i am clear now. Nope, still vague. Which is your desired value for partintid: 91? 10? 9110? "91_10"? Something else? Also, not to be unfriendly, but just note for future reference that top-posting ( http://en.wikipedia.org/wiki/Top-posting ) is generally avoided on this mailinglist/newsgroup. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 07:30:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 11:30:31 GMT Subject: ValueError: invalid literal for int(): References: Message-ID: <4c4d71d7$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 04:12:33 -0700, Chris Rebert wrote: > On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod > wrote: >> Hi Chris, >> Thanks for your help. but i need to to convert the whole string to int. >> heres my full code, >> ptid = 'item_01bom' >> so item_01bom is a field name in form, so i get its value, partintid = >> int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg >> ?(91_10 -?untitled)' >> Hence i get the error. hope i am clear now. > > Nope, still vague. Which is your desired value for partintid: 91? 10? > 9110? "91_10"? Something else? Well, if you interpret 'Screw plugg (91_10 -?untitled)' as a base-256 number, the correct answer is: 147,334,663,384,405,567,160,096,068,524,905,866,724,622,858,761,848,595,862,392,584,788,047,651,881 Obviously. -- Steven From san82moon at gmail.com Mon Jul 26 07:50:09 2010 From: san82moon at gmail.com (lee) Date: Mon, 26 Jul 2010 04:50:09 -0700 (PDT) Subject: ValueError: invalid literal for int(): References: <4c4d71d7$0$11091$c3e8da3@news.astraweb.com> Message-ID: <9ac06e96-fc15-4d95-bb7f-301fd18579b0@o7g2000prg.googlegroups.com> On Jul 26, 4:30?pm, Steven D'Aprano wrote: > On Mon, 26 Jul 2010 04:12:33 -0700, Chris Rebert wrote: > > On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod > > wrote: > >> Hi Chris, > >> Thanks for your help. but i need to to convert the whole string to int. > >> heres my full code, > >> ptid = 'item_01bom' > >> so item_01bom is a field name in form, so i get its value, partintid = > >> int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg > >> ?(91_10 -?untitled)' > >> Hence i get the error. hope i am clear now. > > > Nope, still vague. Which is your desired value for partintid: 91? 10? > > 9110? "91_10"? Something else? > > Well, if you interpret 'Screw plugg (91_10 -?untitled)' as a base-256 > number, the correct answer is: > > 147,334,663,384,405,567,160,096,068,524,905,866,724,622,858,761,848,595,862,392,584,788,047,651,881 > > Obviously. > > -- > Steven Hi, i got the value wrong. sorry for the mistake. i get a int value like "01", so no issue converting it to integer. thanks. From michele.simionato at gmail.com Mon Jul 26 08:03:29 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 26 Jul 2010 05:03:29 -0700 (PDT) Subject: Multiprocessing zombie processes References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: <722b4c73-e23f-4671-a74e-673c155eafe6@l14g2000yql.googlegroups.com> On Jul 25, 1:11?am, Navkirat Singh wrote: > OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. The multiprocessing docs say: """ Joining zombie processes On Unix when a process finishes but has not been joined it becomes a zombie. There should never be very many because each time a new process starts (or active_children() is called) all completed processes which have not yet been joined will be joined. Also calling a finished process?s Process.is_alive() will join the process. Even so it is probably good practice to explicitly join all the processes that you start. """ From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 09:07:49 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 15:07:49 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> Message-ID: <4c4d88a4$0$9187$426a74cc@news.free.fr> Duncan Booth a ?crit : > Bruno Desthuilliers wrote: > >> If you don't want to create as many Whatever instances as MyClass >> instances, you can create a single Whatever instance before defining >> your class: >> >> DEFAULT_WHATEVER = Whathever() >> >> class MyClass(object): >> def __init__(self, x, y): >> self.x = x >> self.y = y >> self.size = DEFAULT_WHATEVER >> >> > > Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. """ so this solution won't obviously work in this case !-) Also and FWIW, I wouldn't advocate this solution if the "default" class attribute is of a mutable type. From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 09:14:49 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 15:14:49 +0200 Subject: why is this group being spammed? In-Reply-To: <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <874ofx9xbx.fsf@benfinney.id.au> <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> Message-ID: <4c4d8a48$0$2793$426a74cc@news.free.fr> be.krul a ?crit : > > Why not moderate this group? This is a hi-traffic group, so it would require a huge team of moderators. From bayofbengal2011 at gmail.com Mon Jul 26 09:39:30 2010 From: bayofbengal2011 at gmail.com (paypal) Date: Mon, 26 Jul 2010 06:39:30 -0700 (PDT) Subject: I GOT $2,000 FROM ' PAYPAL' Message-ID: <03cc2893-eae9-4d8e-89ad-0f90aac123d5@u38g2000prh.googlegroups.com> I GOT $2,000 FROM ' PAYPAL' At http://veryhotguru.co.cc i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. From burton at userful.com Mon Jul 26 11:47:08 2010 From: burton at userful.com (Burton Samograd) Date: Mon, 26 Jul 2010 09:47:08 -0600 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: Grant Edwards writes: > On 2010-07-24, Lawrence D'Oliveiro wrote: >> In message , Robert Kern >> wrote: >> >>> There are also utilities for mounting ISOs directly without burning >>> them to a physical disk. >> >> You need special utilities to do this?? > > Not if the OS and VFS are competently designed. In Linux all you need > to do is this: > > mount -o loop /path/to/file.iso /mount/point > > Apparently you've got to jump through all sorts of hoops using 3rd > party software to do something analgous in MS Windows. In Windows you use DaemonTools. -- Burton Samograd From robin at reportlab.com Mon Jul 26 11:57:58 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jul 2010 16:57:58 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C4DB086.2060008@chamonix.reportlab.co.uk> On 26/07/2010 16:47, Burton Samograd wrote: > Grant Edwards writes: > >> On 2010-07-24, Lawrence D'Oliveiro wrote: >>> In message, Robert Kern >>> wrote: >>> >>>> There are also utilities for mounting ISOs directly without burning >>>> them to a physical disk. >>> >>> You need special utilities to do this?? >> >> Not if the OS and VFS are competently designed. In Linux all you need >> to do is this: >> >> mount -o loop /path/to/file.iso /mount/point >> >> Apparently you've got to jump through all sorts of hoops using 3rd >> party software to do something analgous in MS Windows. > > In Windows you use DaemonTools. > > -- > Burton Samograd > I use VCdControlTool.exe which is some kind of M$ utility, but perhaps that doesn't work for everyone. -- Robin Becker From ethan at stoneleaf.us Mon Jul 26 12:20:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 26 Jul 2010 09:20:06 -0700 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <8b42njFemaU1@mid.individual.net> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: <4C4DB5B6.3050209@stoneleaf.us> Gregory Ewing wrote: > Raymond Hettinger wrote: >> Every class >> in the MRO implementing the target method *must* call super() to give >> the next class in the MRO a chance to run. > > EXCEPT for the last one, which must NOT call super! > > The posted example happens to work because object has > a default __init__ method that does nothing. But this > is not generally true of other methods, which means you > need a "terminating" class at the end of the MRO whose > methods don't call super. Speaking of new-style classes only, don't they all end in object? And if the MRO is only known at run-time, how is one to know at code-time whether your (new-style) class is at the end of the line? ~Ethan~ From ethan at stoneleaf.us Mon Jul 26 12:47:19 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 26 Jul 2010 09:47:19 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4d88a4$0$9187$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> Message-ID: <4C4DBC17.4050805@stoneleaf.us> Bruno Desthuilliers wrote: > Duncan Booth a ?crit : >> Bruno Desthuilliers wrote: >> >>> If you don't want to create as many Whatever instances as MyClass >>> instances, you can create a single Whatever instance before defining >>> your class: >>> >>> DEFAULT_WHATEVER = Whathever() >>> >>> class MyClass(object): >>> def __init__(self, x, y): >>> self.x = x >>> self.y = y >>> self.size = DEFAULT_WHATEVER >>> >>> >> >> Or you could create the default as a class attribute > > from the OP: > """ > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > """ > > so this solution won't obviously work in this case !-) > > Also and FWIW, I wouldn't advocate this solution if the "default" class > attribute is of a mutable type. Well, it is Monday, so I may be missing something obvious, but what is the effective difference between these two solutions? ~Ethan~ From albert.tresens at gmail.com Mon Jul 26 12:54:23 2010 From: albert.tresens at gmail.com (alberttresens) Date: Mon, 26 Jul 2010 09:54:23 -0700 (PDT) Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? Message-ID: <29268605.post@talk.nabble.com> Hi, I am trying to get the creation time of a file to be able to correlate it's content timestamps with other log files. In order to get the creation time of the file one a Linux machine i used: return os.lstat(logFile)[ST_CTIME] That returns to me something like: 1279620166 I would like to know the meaning of this number. Is it in seconds since the epoch? Or is some other respresentation? Thanks, Albert -- View this message in context: http://old.nabble.com/What-does-the-output-of-return-os.lstat%28logFile%29-ST_CTIME--mean--tp29268605p29268605.html Sent from the Python - python-list mailing list archive at Nabble.com. From nagle at animats.com Mon Jul 26 13:08:43 2010 From: nagle at animats.com (John Nagle) Date: Mon, 26 Jul 2010 10:08:43 -0700 Subject: Compare two nested dictionaries In-Reply-To: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Message-ID: <4c4dc11a$0$1619$742ec2ed@news.sonic.net> On 7/25/2010 8:03 AM, targetsmart wrote: > Hi, > I am trying to compare two nested dictionaries, I want to know what is > the exact difference between them. d1 = {'a' : 1, 'b' : 2, 'c': 3 } d2 = {'a' : 1, 'b' : 3, 'd': 4 } diff = dict(set(d1.items()) - set(d2.items())) print (diff) {'c': 3, 'b': 2} That's the true "difference", with all entries in d1 not identically in d2 listed. Is that what you wanted? John Nagle From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 13:15:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 17:15:13 GMT Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? References: Message-ID: <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote: > Hi, > I am trying to get the creation time of a file to be able to correlate > it's content timestamps with other log files. In order to get the > creation time of the file one a Linux machine i used: You're out of luck. Neither Unix nor Linux store the creation time of files, at least not on any file system I know of. It stores three timestamps: mtime, ctime, and atime. atime is the simple one -- it is "access time", or when the file was last read. mtime is "modification time" -- it is when the file *contents* were last changed. But ctime is NOT creation time, as many people imagine. It is "change time", and it changes whenever EITHER the file contents are changed, OR when the file metadata (permissions, owner, name, etc.) change. So any time mtime changes, so does ctime. But not visa versa. > return os.lstat(logFile)[ST_CTIME] > > That returns to me something like: 1279620166 > > I would like to know the meaning of this number. Is it in seconds since > the epoch? Yes. -- Steven From albert.tresens at gmail.com Mon Jul 26 13:24:25 2010 From: albert.tresens at gmail.com (alberttresens) Date: Mon, 26 Jul 2010 10:24:25 -0700 (PDT) Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? In-Reply-To: <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> References: <29268605.post@talk.nabble.com> <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> Message-ID: <29268871.post@talk.nabble.com> Hi, thanks for the reply. But what i am more concerned about, as I am trying to correlate logs, is what is the timestamp: 1279620166 mean? Is it seconds since the epoch or the ISO time in seconds? Any idea? Thanks a lot!! Steven D'Aprano-7 wrote: > > On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote: > >> Hi, >> I am trying to get the creation time of a file to be able to correlate >> it's content timestamps with other log files. In order to get the >> creation time of the file one a Linux machine i used: > > You're out of luck. Neither Unix nor Linux store the creation time of > files, at least not on any file system I know of. It stores three > timestamps: mtime, ctime, and atime. > > atime is the simple one -- it is "access time", or when the file was last > read. > > mtime is "modification time" -- it is when the file *contents* were last > changed. > > But ctime is NOT creation time, as many people imagine. It is "change > time", and it changes whenever EITHER the file contents are changed, OR > when the file metadata (permissions, owner, name, etc.) change. > > So any time mtime changes, so does ctime. But not visa versa. > > >> return os.lstat(logFile)[ST_CTIME] >> >> That returns to me something like: 1279620166 >> >> I would like to know the meaning of this number. Is it in seconds since >> the epoch? > > Yes. > > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/What-does-the-output-of-return-os.lstat%28logFile%29-ST_CTIME--mean--tp29268605p29268871.html Sent from the Python - python-list mailing list archive at Nabble.com. From thomas at jollans.com Mon Jul 26 13:37:31 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 26 Jul 2010 19:37:31 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4DC7DB.2070102@jollans.com> On 07/26/2010 06:36 AM, Edward Diener wrote: > On 7/25/2010 10:42 PM, David Robinow wrote: >> On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener >> wrote: >>> On 7/25/2010 5:57 PM, Thomas Jollans wrote: >>> So if a standard library module ( or distributed library ) executes a >>> call >>> internally to 'python xxx yyy' or executes a call internally to >>> 'someScript.py yyy', you're fine with multiple co-existing versions of >>> Python on your system ? >>> >>> Because under Windows the first call will look for the python.exe first >>> found in the PATH while the second call will find the python.exe >>> associated >>> with the .py extension. And it does not matter in either case what >>> version >>> of the multiple installed versions of Python which are on my system is >>> currently executing that script. >>> >>> And please don't say that there is some sort of guarantee that no >>> library or >>> installation would invoke Python in such a way as opposed to the normal >>> 'import AScript.py' method of using functionality in Python scripts. >> Edward, I'm having a really hard time understanding your problem. >> Could you give an example of some real code that is causing you >> difficulty? > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? yeah, well, sort of. But for a system installation, not really. When hacking on the interpreter, this makes sense. Otherwise - not so much. > > In SomeScript.py there is an internal call to 'python someOtherScript.y > someParameters'. Is that a fact? Where on earth did you get this "SomeScript.py"? From thomas at jollans.com Mon Jul 26 14:13:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 26 Jul 2010 20:13:40 +0200 Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? In-Reply-To: <29268871.post@talk.nabble.com> References: <29268605.post@talk.nabble.com> <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> <29268871.post@talk.nabble.com> Message-ID: <4C4DD054.50308@jollans.com> On 07/26/2010 07:24 PM, alberttresens wrote: > > Hi, thanks for the reply. Alas, you didn't actually read it: > > But what i am more concerned about, as I am trying to correlate logs, is > what is the timestamp: > 1279620166 mean? > Is it seconds since the epoch or the ISO time in seconds? > > Any idea? > > Thanks a lot!! > [...] >>> I would like to know the meaning of this number. Is it in seconds since >>> the epoch? >> >> Yes. You quoted the answer to your question in the same e-mail. fascinating. A little side note: >> atime is the simple one -- it is "access time", or when the file was >> last read. You should never rely on this, though: some file systems don't store this (I think) and many users/sysadmins actually disable this (mount -o noatime) for performance reasons. (Also, on an SSD, I imagine enabling atime, and with it many, many additional writes, could noticeably detriment disk lifetime) From theran at gmail.com Mon Jul 26 14:36:16 2010 From: theran at gmail.com (Louis Theran) Date: Mon, 26 Jul 2010 11:36:16 -0700 (PDT) Subject: distutils question - building universal modules on OS X? Message-ID: Is there a standard recipe for getting distutils to built universal .so files for modules that have C/C++ source? From robert.kern at gmail.com Mon Jul 26 14:49:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 13:49:55 -0500 Subject: distutils question - building universal modules on OS X? In-Reply-To: References: Message-ID: On 7/26/10 1:36 PM, Louis Theran wrote: > Is there a standard recipe for getting distutils to built > universal .so files for modules that have C/C++ source? If your Python was built to be Universal, it will automatically use the same architecture flags to build the extension modules Universal. -- 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 philip at semanchuk.com Mon Jul 26 15:22:14 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 26 Jul 2010 15:22:14 -0400 Subject: Binary compatibility across Python versions? Message-ID: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Hi all, Does Python guarantee binary compatibility across major, minor and/or micro versions? I looked through the docs and even with Google's help I wasn't able to find any official statements on this subject. Specifically, I'm concerned with binaries created by SWIG for a C++ library that our project uses. We'd like to ship precompiled binaries for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it is sufficient to create binaries for each Python for each platform (3 * 2 == 6 total precompiled binaries). Thanks for any advice and pointers to official documentation on the subject. Cheers Philip From python at mrabarnett.plus.com Mon Jul 26 15:40:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 26 Jul 2010 20:40:30 +0100 Subject: Binary compatibility across Python versions? In-Reply-To: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: <4C4DE4AE.6060103@mrabarnett.plus.com> Philip Semanchuk wrote: > Hi all, > Does Python guarantee binary compatibility across major, minor and/or > micro versions? I looked through the docs and even with Google's help I > wasn't able to find any official statements on this subject. > > > Specifically, I'm concerned with binaries created by SWIG for a C++ > library that our project uses. We'd like to ship precompiled binaries > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > is sufficient to create binaries for each Python for each platform (3 * > 2 == 6 total precompiled binaries). > > Thanks for any advice and pointers to official documentation on the > subject. > There are differences between minor versions, but not, so far as I'm aware, between micro versions (and I'd be surprised if there were). From lists at cheimes.de Mon Jul 26 15:45:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 26 Jul 2010 21:45:05 +0200 Subject: Binary compatibility across Python versions? In-Reply-To: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: > Specifically, I'm concerned with binaries created by SWIG for a C++ > library that our project uses. We'd like to ship precompiled binaries > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > is sufficient to create binaries for each Python for each platform (3 > * 2 == 6 total precompiled binaries). For each platforms you have to provide binaries for the major CPU architectures (X86 and X64_86), too. Users or distributions may compile Python with UCS-2 or UCS-4 unicode width. That makes eight different binaries for Linux (two version * two archs * UCS2/4). Although most distributions follow the LSB standards, binaries aren't necessary ABI compatible. C++ binaries tend to break more often than C binaries. Have fun ;) Christian From robert.kern at gmail.com Mon Jul 26 15:46:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 14:46:22 -0500 Subject: Binary compatibility across Python versions? In-Reply-To: <4C4DE4AE.6060103@mrabarnett.plus.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> <4C4DE4AE.6060103@mrabarnett.plus.com> Message-ID: On 7/26/10 2:40 PM, MRAB wrote: > Philip Semanchuk wrote: >> Hi all, >> Does Python guarantee binary compatibility across major, minor and/or micro >> versions? I looked through the docs and even with Google's help I wasn't able >> to find any official statements on this subject. >> >> >> Specifically, I'm concerned with binaries created by SWIG for a C++ library >> that our project uses. We'd like to ship precompiled binaries for Linux, OS X >> and Windows for Python 2.5 and 2.6. I'm hoping that it is sufficient to create >> binaries for each Python for each platform (3 * 2 == 6 total precompiled >> binaries). >> >> Thanks for any advice and pointers to official documentation on the subject. >> > There are differences between minor versions, but not, so far as I'm > aware, between micro versions (and I'd be surprised if there were). As a matter of policy, micro versions are binary-compatible. It's a bug if a micro revision breaks binary compatibility. -- 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 dhruvbird at gmail.com Mon Jul 26 16:24:28 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 26 Jul 2010 13:24:28 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: On Jul 21, 8:17?pm, John Nagle wrote: > On 7/19/2010 9:56 AM, dhruvbird wrote: > > > On Jul 19, 9:12 pm, Brian Victor ?wrote: > >> dhruvbird wrote: > >> Having offered this, I don't recall ever seeing reduce used in real > >> python code, and explicit iteration is almost always preferred. > > > Yes, even I have noticed that reduce is a tad under-used function. > > ? ? ?Yes, I had a use case for it once, but it wasn't worth the trouble. > "map" is often useful, but "reduce", not so much. > > ? ? ?Python isn't really a functional language. ?There's no bias toward > functional solutions, lambdas aren't very general, and the performance > isn't any better. ?Nor is any concurrency provided by "map" or "reduce". > So there's no win in trying to develop cute one-liners. Yes agreed. However, there is: 1. now scope for optimization (for example returning generators instead of lists) at every stage if using functions -- these functions can be internally changed as long as the external guarantees they provide remain essentially unchanged. 2. readability wins because you express your intent (operations) rather than anything else. For example, if I want the product of the square roots of all odd integers in an array, I can say: answer = reduce(product, map(math.sqrt, filter(lambda x: x%2 == 0, some_array_with_ints))) While I agree that python may not have been initially seen as a functional language, it is powerful and flexible enough to be one or at least decently support such paradigms. Regards, -Dhruv. From nad at acm.org Mon Jul 26 17:19:02 2010 From: nad at acm.org (Ned Deily) Date: Mon, 26 Jul 2010 14:19:02 -0700 Subject: Binary compatibility across Python versions? References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: In article , Christian Heimes wrote: > [Philip Semanchuk wrote:] > > Specifically, I'm concerned with binaries created by SWIG for a C++ > > library that our project uses. We'd like to ship precompiled binaries > > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > > is sufficient to create binaries for each Python for each platform (3 > > * 2 == 6 total precompiled binaries). > For each platforms you have to provide binaries for the major CPU > architectures (X86 and X64_86), too. Users or distributions may compile > Python with UCS-2 or UCS-4 unicode width. That makes eight different > binaries for Linux (two version * two archs * UCS2/4). Although most > distributions follow the LSB standards, binaries aren't necessary ABI > compatible. C++ binaries tend to break more often than C binaries. And, on OS X, there are various Python binary distributions in common use: the Apple-supplied Pythons (2.5 for OS X 10.5, 2.6 & 2.5 for 10.6), the python.org OS X installers for 10.5 and 10.6, plus the ActiveState and EPD ones. It would likely be difficult to ship one binary extension that would easily work, if at all, with the most common ones. For instance, the Apple-supplied Python 2.6 is built with gcc 4.2, uses the 10.6 ABI (SDK deployment target), and x86_64 / i386 / ppc architectures (default 64-bit on capable machines). The python.org 2.6 uses gcc 4.0, the 10.4u ABI, and is 32-bit only (i386 / ppc) -- Ned Deily, nad at acm.org From pengyu.ut at gmail.com Mon Jul 26 17:52:06 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 16:52:06 -0500 Subject: python terminology on classes Message-ID: Hi I'm still kind of confused about the terminology on classes in python. Could you please let me know what the equivalent terms for the following C++ terms? constructor destructor member function member variable virtual member function function I think that C++ "function" is equivalent to python "function" and C++ "member function" is equivalent to python "method". But I couldn't locate where the original definitions of the corresponding python terms in the manual as these term appear many times. Could you please point me where to look for the definition of these python corresponding terms? -- Regards, Peng From 4g4trz802 at sneakemail.com Mon Jul 26 18:16:49 2010 From: 4g4trz802 at sneakemail.com (Michael Hoffman) Date: Mon, 26 Jul 2010 15:16:49 -0700 Subject: Updating path.py Message-ID: I have been using Jason Orendorff's path.py module for a long time. It is very useful. The only problem is that Python 2.6 deprecates the md5 module it imports, so I (and others using my software) now get this warning whenever they start, which is a little annoying. /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead The original web page is gone, and e-mails to the author have gone unanswered. It has a "public domain" license so I could easily fork it and make this small change. The question is what is the best way to do that and ensure continuity with the previous versions. Can I (or someone else) take over the PyPI entry in question? Other suggestions? Many thanks, Michael Hoffman From pengyu.ut at gmail.com Mon Jul 26 18:20:09 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 17:20:09 -0500 Subject: python styles: why Use spaces around arithmetic operators? Message-ID: This webpage http://www.python.org/dev/peps/pep-0008/ recommends the following. It looks to me that both styles are fine. Could anybody let me know what the rationale is behind this recommendation? - Use spaces around arithmetic operators: Yes: i = i + 1 submitted += 1 x = x * 2 - 1 hypot2 = x * x + y * y c = (a + b) * (a - b) No: i=i+1 submitted +=1 x = x*2 - 1 hypot2 = x*x + y*y c = (a+b) * (a-b) -- Regards, Peng From robert.kern at gmail.com Mon Jul 26 18:39:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 17:39:56 -0500 Subject: Updating path.py In-Reply-To: References: Message-ID: On 7/26/10 5:16 PM, Michael Hoffman wrote: > I have been using Jason Orendorff's path.py module for a long time. It is very > useful. The only problem is that Python 2.6 deprecates the md5 module it > imports, so I (and others using my software) now get this warning whenever they > start, which is a little annoying. > > /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > The original web page is gone, and e-mails to the author have gone unanswered. > It has a "public domain" license so I could easily fork it and make this small > change. The question is what is the best way to do that and ensure continuity > with the previous versions. Can I (or someone else) take over the PyPI entry in > question? Other suggestions? You cannot "take over" a project on PyPI. You can only fork the project with a new name. In fact, this has already been done: http://pypi.python.org/pypi/forked-path/0.1 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From thomas at jollans.com Mon Jul 26 19:00:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 27 Jul 2010 01:00:50 +0200 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: <4C4E13A2.4080804@jollans.com> On 07/27/2010 12:20 AM, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? Beauty is in the eye of the beholder, even when we call it "coding style". There is no rationale, except if you accept "easier to read", "looks better", or "that's what Guido has been doing for years". > > - Use spaces around arithmetic operators: > > Yes: > > i = i + 1 > submitted += 1 > x = x * 2 - 1 > hypot2 = x * x + y * y > c = (a + b) * (a - b) > > No: > > i=i+1 > submitted +=1 > x = x*2 - 1 > hypot2 = x*x + y*y > c = (a+b) * (a-b) > From rantingrick at gmail.com Mon Jul 26 19:06:22 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jul 2010 16:06:22 -0700 (PDT) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: On Jul 26, 5:20?pm, Peng Yu wrote: > This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? The rational is simple. Guido is God and if you don't follow his words then you will be tortured. His favorite means is by forcing you to wear Dutch wooden shoes every day whist programming Ruby! ;-) From martin.hellwig at dcuktec.org Mon Jul 26 19:15:05 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 27 Jul 2010 00:15:05 +0100 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: On 07/27/10 00:06, rantingrick wrote: > On Jul 26, 5:20 pm, Peng Yu wrote: >> This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the >> following. It looks to me that both styles are fine. Could anybody let >> me know what the rationale is behind this recommendation? > > The rational is simple. Guido is God and if you don't follow his words > then you will be tortured. His favorite means is by forcing you to > wear Dutch wooden shoes every day whist programming Ruby! ;-) Wat is er mis met klompen? -- mph From thomas at jollans.com Mon Jul 26 19:15:08 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 27 Jul 2010 01:15:08 +0200 Subject: python terminology on classes In-Reply-To: References: Message-ID: <4C4E16FC.5000005@jollans.com> On 07/26/2010 11:52 PM, Peng Yu wrote: > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? > > constructor constructor. This consists of the class constructor method, __new__, and of the instance initialization method, __init__ In practice, __init__ is really "the constructor". http://docs.python.org/py3k/reference/datamodel.html#object.__new__ > destructor destructor. http://docs.python.org/py3k/reference/datamodel.html#object.__del__ > member function method. Look for "instance method" below > member variable attribute, instance attribute, instance variable. > virtual member function all methods are virtual. > function function. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python > terms in the manual as these term appear many times. Could you please > point me where to look for the definition of these python > corresponding terms? http://docs.python.org/py3k/reference/datamodel.html should answer all your questions. From justin2009smith at gmail.com Mon Jul 26 19:19:59 2010 From: justin2009smith at gmail.com (Justin Smith) Date: Mon, 26 Jul 2010 16:19:59 -0700 (PDT) Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> Message-ID: <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Seeking industry expert candidates I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I am currently seeking candidates to fill Tech Positions for multiple A- List Clients: ? Quality Assurance Engineer, ? Senior Data Engineer, Search Experience ? Senior Software Development Engineer, UX / UI ? Software Dev Engineer ? Software Dev TEST Engineer ? Software Development Manager, ? Sr Applications Engineer ? Strong Linux Systems Administrator ? SR Technical PM, - ? Web Designer/Developer ? strong tech and art background ? Business Analyst, Many of our Clients work within a Linux environment. For greatest impact, on your resume highlight relevant skills and technologies used in an environment supported by Linux, languages that show you understand and know object oriented development, have experience with high volume sites that are notable and are continually learning new skills. Hot List that gets our attention ? LAMP Stack Experience, Linux, Perl and Java/JavaScript Experts that are current in the use and show expertise. Microsoft environment and dot net technologies are not added attractors to many of our clients. If you are interested in these roles, send me your resume, cover letter highlighting noteworthy skills and projects with expected base salary to justin.smith at expresspros.com and I can submit it ASAP. Justin(dot)Smith(at)ExpressPros(dot)com DO FEEL FREE TO REFER this on to a friend or colleague with strong skills as well. Qualifications: - Computer Science degree or equivalent work experience (5+ years). - Expert level fluency in at least one mainstream object-oriented programming language (C++, Java, Ruby, Python). - Proven coding skills in C++ and or Java on Unix/Linux platforms is a must. - Experience with MySQL or Oracle databases a plus. - Linux or LAMP Stack experience preferred. - Experience with HTML5, XML, XSD, WSDL, and SOAP and a history working with web client software - Experience with scalable distributed systems is a positive. Added value attractors if the qualifications are available: + Experience with the iPhone SDK and Objective-C. ? published app that is stable, engaging + Experience with the BlackBerry SDK and/or J2ME. ? published app that is stable, engaging + Experience with the Android SDK. ? published app that is stable, engaging If you are interested in these roles, send me your resume, cover letter highlighting noteworthy skills and projects with expected base salary to justin.smith at expresspros.com and I can submit it ASAP. Justin(dot)Smith(at)ExpressPros(dot)com DO FEEL FREE TO REFER this on to a friend or colleague with strong skills as well. On Jul 1, 7:18?am, Stephen Hansen wrote: > On 7/1/10 3:03 AM, Jean-Michel Pichavant wrote: > > > Re is part of the python standard library, for some purpose I guess. > > No, *really*? > > So all those people who have been advocating its useless and shouldn't > be are already too late? > > Damn. > > Well, there goes *that* whole crusade we were all out on. Since we can't > destroy re, maybe we can go club baby seals. > > -- > > ? ? ... Stephen Hansen > ? ? ... Also: Ixokai > ? ? ... Mail: me+list/python (AT) ixokai (DOT) io > ? ? ... Blog:http://meh.ixokai.io/ From rantingrick at gmail.com Mon Jul 26 19:24:16 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jul 2010 16:24:16 -0700 (PDT) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: > Martin wrote: > > Wat is er mis met klompen? Well specifically their made from wood and wood is a very hard substance. Also i did not go into detail but he makes sure to pick shoes that are three sizes too small. You know a good podiatrist can be tough to come by in these times. It's a pretty severe punishment if you ask me. From rhodri at wildebst.demon.co.uk Mon Jul 26 19:29:43 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 27 Jul 2010 00:29:43 +0100 Subject: python terminology on classes References: Message-ID: On Mon, 26 Jul 2010 22:52:06 +0100, Peng Yu wrote: > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? Seriously, we can't keep doing your thinking for you. The answers to all your questions are section 9 of the tutorial. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 19:31:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 23:31:23 GMT Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? > > - Use spaces around arithmetic operators: Because it looks better and is easier to read. Operators are small (single characters) and sometimes need space around them to stand out. > i=i+1 See? It's hideously ugly and cramped. It's much worse if you use larger names: sensiblynamedvariable=sensiblynamedvariable+1 But use your common sense. I usually group powers, multiplications and divisions, and separate additions and subtractions: y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2 And unary + and - operators should always be grouped with their operand: y = -2 # not "- 2" -- Steven From python.list at tim.thechases.com Mon Jul 26 19:31:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Jul 2010 18:31:29 -0500 Subject: python terminology on classes In-Reply-To: <4C4E16FC.5000005@jollans.com> References: <4C4E16FC.5000005@jollans.com> Message-ID: <4C4E1AD1.5040600@tim.thechases.com> On 07/26/10 18:15, Thomas Jollans wrote: >> destructor > > http://docs.python.org/py3k/reference/datamodel.html#object.__del__ One small caveat -- IIRC, in Java/C++ the destructor is guaranteed to be called with a certain amount of context. I find Python's __del__ almost useless since things it may rely upon can arbitrarily be destroyed before the __del__ is called. -tkc From pengyu.ut at gmail.com Mon Jul 26 19:36:12 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 18:36:12 -0500 Subject: How to capture all the environment variables from shell? Message-ID: Hi, R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm not sure what it does when os module is imported. But it seems that os.environ doesn't capture all the environment variable from the shell. Could anybody let me know what is the correct way to inherent all the environment variables form the shell? $ echo $R_HOME /opt/R-2.11.1 $ cat main.py #!/usr/bin/env python import os print os.environ['R_HOME'] $ ./main.py Traceback (most recent call last): File "./main.py", line 5, in print os.environ['R_HOME'] File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ raise KeyError(key) KeyError: 'R_HOME' -- Regards, Peng From clp2 at rebertia.com Mon Jul 26 20:02:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 17:02:06 -0700 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: On Mon, Jul 26, 2010 at 4:36 PM, Peng Yu wrote: > Hi, > > R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm > not sure what it does when os module is imported. But it seems that > os.environ doesn't capture all the environment variable from the > shell. Could anybody let me know what is the correct way to inherent > all the environment variables form the shell? > > $ echo $R_HOME > /opt/R-2.11.1 > $ cat main.py > #!/usr/bin/env python > > import os > > print os.environ['R_HOME'] > $ ./main.py > Traceback (most recent call last): > ?File "./main.py", line 5, in > ? ?print os.environ['R_HOME'] > ?File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ > ? ?raise KeyError(key) > KeyError: 'R_HOME' You need to "export R_HOME" in bash (probably in your .bashrc or .bash_profile). See http://www.ibm.com/developerworks/library/l-bash.html#N10074 Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Jul 26 20:02:57 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 27 Jul 2010 01:02:57 +0100 Subject: How to capture all the environment variables from shell? References: Message-ID: On Tue, 27 Jul 2010 00:36:12 +0100, Peng Yu wrote: > R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm > not sure what it does when os module is imported. But it seems that > os.environ doesn't capture all the environment variable from the > shell. Could anybody let me know what is the correct way to inherent > all the environment variables form the shell? os.environ does capture all the environment that the shell passes to it. In this case, you haven't exported R_HOME, so the shell doesn't export it, so os.environ has no chance to capture it. rhodri at gnudebst:~$ HELLO=world rhodri at gnudebst:~$ echo $HELLO world rhodri at gnudebst:~$ export HELLO rhodri at gnudebst:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ['HELLO'] 'world' -- Rhodri James *-* Wildebeest Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 20:04:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 00:04:22 GMT Subject: python terminology on classes References: Message-ID: <4c4e2286$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 16:52:06 -0500, Peng Yu wrote: > Could you please let me know what the equivalent terms for the following > C++ terms? > > constructor > destructor > member function > member variable > virtual member function > function (1) Python new-style classes have a constructor __new__ and an initialiser __init__. Some people describe both as constructors, but that's strictly incorrect because the instance has already been constructed by the time __init__ is called. (Old-style classes don't have __new__, only __init__.) (2) Python destructors are called __del__ , but you shouldn't use them unless you really know what you are doing. (3) "Member functions" are methods. (4) "Member variables" are attributes. If you have to distinguish between attributes which live on the instance from one that lives on the class, "instance attribute" and "class attribute". (5) I believe that all methods in Python are virtual. (6) Function. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python terms > in the manual as these term appear many times. Could you please point me > where to look for the definition of these python corresponding terms? I believe you are right, but I can't find a definition of C++ "member function" that makes sense. Can you please point me where to look for the definition of these C++ terms? I don't believe the Python Language Reference explicitly defines terms such as "attribute" and "method", but the tutorial may help: http://docs.python.org/tutorial/classes.html Quote: In C++ terminology, all class members (including the data members) are public, and all member functions are virtual. Note: although the docs occasionally use the term "members" for attributes, it is considered more standard to use "attribute" or "method" unless discussing data types defined at the C layer. -- Steven From cs at zip.com.au Mon Jul 26 20:06:02 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 27 Jul 2010 10:06:02 +1000 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: <20100727000602.GA22711@cskk.homeip.net> On 26Jul2010 18:36, Peng Yu wrote: | R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm | not sure what it does when os module is imported. But it seems that | os.environ doesn't capture all the environment variable from the | shell. Could anybody let me know what is the correct way to inherent | all the environment variables form the shell? | | $ echo $R_HOME | /opt/R-2.11.1 | $ cat main.py | #!/usr/bin/env python | | import os | | print os.environ['R_HOME'] | $ ./main.py | Traceback (most recent call last): | File "./main.py", line 5, in | print os.environ['R_HOME'] | File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ | raise KeyError(key) | KeyError: 'R_HOME' Sounds like R_HOME is not exported. Try these in your shell: set | grep R_HOME export | grep R_HOME Then, presuming it shows only in the first command: export R_HOME and then try your python script again. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is an approved maxim in war, never to do what the enemy wishes you to do, for this reason alone, that he desires it. - Napoleon From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 20:09:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 00:09:17 GMT Subject: python terminology on classes References: Message-ID: <4c4e23ac$0$11091$c3e8da3@news.astraweb.com> On Tue, 27 Jul 2010 01:15:08 +0200, Thomas Jollans wrote: > http://docs.python.org/py3k/reference/datamodel.html should answer all > your questions. It should, but as far as I can tell it doesn't. If it defines "attribute" or "method", I can't find it. -- Steven From python at rcn.com Mon Jul 26 20:46:11 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 26 Jul 2010 17:46:11 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: <6273b6b0-6c3a-4cca-9ac3-3d7b96819862@x24g2000pro.googlegroups.com> [Ethan Furman] > Speaking of new-style classes only, don't they all end in object? ?And > if the MRO is only known at run-time, how is one to know at code-time > whether your (new-style) class is at the end of the line? That is a bit of a PITA. One way of handling it is to design your diamond so that only one class inherits from object and that class doesn't use super(). Or you can wrap the super call in a try/except AttributeError. Cooperative multiple inheritance isn't pretty -- which is just another good reason to use composition rather that inheritance. Raymond From debatem1 at gmail.com Mon Jul 26 21:55:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 26 Jul 2010 18:55:34 -0700 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> References: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 26, 2010 at 4:31 PM, Steven D'Aprano wrote: > On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote: > >> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the >> following. It looks to me that both styles are fine. Could anybody let >> me know what the rationale is behind this recommendation? >> >> ? ? - Use spaces around arithmetic operators: > > Because it looks better and is easier to read. Operators are small > (single characters) and sometimes need space around them to stand out. > >> ? ? ? ? ? i=i+1 > > See? It's hideously ugly and cramped. It's much worse if you use larger > names: > > sensiblynamedvariable=sensiblynamedvariable+1 > > But use your common sense. I usually group powers, multiplications and > divisions, and separate additions and subtractions: > > y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2 > > And unary + and - operators should always be grouped with their operand: > > y = -2 ?# not "- 2" This is the rule that I use, with the exception that I will generally explicitly parenthesize the numerator in a division, since my eyes frequently gloss over the / symbol for some reason. Geremy Condra From steveo at syslang.net Mon Jul 26 22:26:27 2010 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Jul 2010 22:26:27 -0400 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: <4C4E43D3.9070203@syslang.net> On 07/26/10 20:02, quoth Chris Rebert: > On Mon, Jul 26, 2010 at 4:36 PM, Peng Yu wrote: > > You need to "export R_HOME" in bash (probably in your .bashrc or > .bash_profile). See > http://www.ibm.com/developerworks/library/l-bash.html#N10074 Please! Never export anything from your .bashrc unless you really know what you're doing. Almost all exports should be done in your .bash_profile -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Mon Jul 26 22:35:24 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 26 Jul 2010 19:35:24 -0700 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: <4C4E45EC.8030509@ixokai.io> On 7/26/10 3:20 PM, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? PEP8 is a style guide. Parts of style guides are rational judgements and decisions based on experience and can certainly be "explained" or justified, but parts are just... personal taste. Style is part rational thought and part intuition, and in the latter -- people will disagree quite a bit. There's no right or wrong there. There isn't always a rationale. Guido finds "x=a+1" less readable then "x = a + 1". Originally he wrote this down with other anecdotal little tidbits up into an eassy and posted it on the python.org website. Eventually, others decided that his intuitive sense of style actually tended to be rather spot on for them too (why wouldn't it, since that same sense of style brought Python into existence and most of us quite like it), and so that guide and some others were codified into PEP8, and tweaked from time to time. PEP8 is only a "rule" for the stdlib, and only for new code in the stdlib at that -- and its only really a rule to encourage consistency and maintainability, not because its objectively The Right Way To Code. Personally, while I agree with much of it, I disagree in several points and ignore PEP8 whenever it suits me (most notably on line length rules, and for a long time on methodNamingSchemes, but lately I've found I'm coming_around). -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From python at bdurham.com Mon Jul 26 22:41:53 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jul 2010 22:41:53 -0400 Subject: Python 2.7 for Windows: Same version of MS VC runtime as Python 2.6? Message-ID: <1280198513.5040.1386886575@webmail.messagingengine.com> Python 2.7 for Windows: Does Python 2.7 for Windows use the same version of the MS VC runtime as Python 2.6? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Jul 26 22:42:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Jul 2010 21:42:24 -0500 Subject: How to capture all the environment variables from shell? In-Reply-To: <4C4E43D3.9070203@syslang.net> References: <4C4E43D3.9070203@syslang.net> Message-ID: <4C4E4790.6030604@tim.thechases.com> On 07/26/10 21:26, Steven W. Orr wrote: > Please! Never export anything from your .bashrc unless you > really know what you're doing. Almost all exports should be > done in your .bash_profile Could you elaborate on your reasoning why (or why-not)? I've found that my .bash_profile doesn't get evaluated when I crank up another terminal window, while my bashrc does. Thus I tend to put my exports in my ~/.bashrc so they actually take effect in my shell... -tkc From steve-REMOVE-THIS at cybersource.com.au Mon Jul 26 23:01:04 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 03:01:04 GMT Subject: How to capture all the environment variables from shell? References: Message-ID: <4c4e4bf0$0$11110$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 22:26:27 -0400, Steven W. Orr wrote: > Please! Never export anything from your .bashrc unless you really know > what you're doing. Almost all exports should be done in your > .bash_profile Would you like to explain why, or should we just trust you? -- Steven From ben+python at benfinney.id.au Mon Jul 26 23:26:46 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Jul 2010 13:26:46 +1000 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Message-ID: <87pqy94nbd.fsf@benfinney.id.au> Justin Smith writes: > Seeking industry expert candidates Please don't reply in an existing thread with an unrelated message. If you want to start a new discussion, compose a new message, not a reply. For job advertisements, please don't use this forum at all; instead use the Python Jobs Board . -- \ ?We are stuck with technology when what we really want is just | `\ stuff that works.? ?Douglas Adams | _o__) | Ben Finney From urban.yoga.journeys at gmail.com Tue Jul 27 00:15:15 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Mon, 26 Jul 2010 21:15:15 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code Message-ID: 0 down vote favorite i've written a tool in python where you enter a title, content, then tags, and the entry is then saved in a pickle file. it was mainly designed for copy-paste functionality (you spot a piece of code you like on the net, copy it, and paste it into the program), not really for handwritten content, though it does that with no problem. i mainly did it because i'm always scanning through my pdf files, books, or the net for some coding example of solution that i'd already seen before, and it just seemed logical to have something where you could just put the content in, give it a title and tags, and just look it up whenever you needed to. i realize there are sites online that handle this ex. http://snippets.dzone.com, but i'm not always online when i code. i also admit that i didn't really look to see if anyone had written a desktop app, the project seemed like a fun thing to do so here i am. it wasn't designed with millions of entries in mind, so i just use a pickle file to serialize the data instead of one of the database APIs. the query is also very basic, only title and tags and no ranking based on the query. there is an issue that i can't figure out, when you are at the list of entries there's a try, except clause where it tries to catch a valid index (integer). if you enter an inavlid integer, it will ask you to enter a valid one, but it doesn't seem to be able to assign it to the variable. if you enter a valid integer straightaway, there are no problems and the entry will display. anyway let me know what you guys think. this is coded for python3. main file: #!usr/bin/python from archive_functions import Entry, choices, print_choice, entry_query import os def main(): choice = '' while choice != "5": os.system('clear') print("Mo's Archive, please select an option") print('====================') print('1. Enter an entry') print('2. Lookup an entry') print('3. Display all entries') print('4. Delete an entry') print('5. Quit') print('====================') choice = input(':') if choice == "1": entry = Entry() entry.get_data() entry.save_data() elif choice == "2": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "3": queryset = 'all' result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) elif choice == "4": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: entry = result[choices(result)] entry.del_data() else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "5": break else: input('please enter a valid choice...') main() if __name__ == "__main__": main() archive_functions.py: #!/bin/usr/python import sys import pickle import os import re class Entry(): def get_data(self): self.title = input('enter a title: ') print('enter the code, press ctrl-d to end: ') self.code = sys.stdin.readlines() self.tags = input('enter tags: ') def save_data(self): with open('entry.pickle', 'ab') as f: pickle.dump(self, f) def del_data(self): with open('entry.pickle', 'rb') as f: data_list = [] while True: try: entry = pickle.load(f) if self.title == entry.title: continue data_list.append(entry) except: break with open('entry.pickle', 'wb') as f: pass with open('entry.pickle', 'ab') as f: for data in data_list: data.save_data() def entry_query(file, queryset): '''returns a list of objects matching the query''' result = [] try: with open(file, 'rb') as f: entry = pickle.load(f) os.system('clear') if queryset == "all": while True: try: result.append(entry) entry = pickle.load(f) except: return result break while True: try: if re.search(queryset, entry.title) or re.search(queryset, entry.tags): result.append(entry) entry = pickle.load(f) else: entry = pickle.load(f) except: return result break except: print('no entries in file, please enter an entry first') pause = input('\nPress [Enter] to continue...') def choices(list_result): '''takes a list of objects and returns the index of the selected object''' os.system('clear') index = 0 for entry in list_result: print('{}. {}'.format(index, entry.title)) index += 1 try: choice = int(input('\nEnter choice: ')) return choice except: pause = input('\nplease enter a valid choice') choices(list_result) def print_choice(list_result, choice): '''takes a list of objects and an index and displays the index of the list''' os.system('clear') print('===================') print(list_result[choice].title) print('===================') for line in list_result[choice].code: print(line, end="") print('\n\n') back_to_choices(list_result) def back_to_choices(list_result): print('1. Back to entry list') print('2. Back to Main Menu') choice = input(':') if choice == "1": print_choice(list_result, choices(list_result)) elif choice == "2": pass else: print('\nplease enter a valid choice') back_to_choices(list_result) From mithrandiragainwiki at mailinator.com Tue Jul 27 00:27:41 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Mon, 26 Jul 2010 21:27:41 -0700 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On 07/18/2010 03:58 PM, Edward A. Falk wrote: > In article<334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, > be.krul wrote: >> why is this group being spammed? > > They're *all* being spammed. Why? Because they can, and because Google > doesn't care. > Not only does Google not care, but they've made Usenet more accessible to the general public. How is that bad? You go back in time, before Google bought out Deja News, and ask the average Tom, Dick, or Harry if they knew what Usenet was. Their response probably would have been "No" or "Maybe..." or "Isn't that dead?" Now more people know about Usenet and don't have to go through the hassle of finding a free server (or paying), getting a reliable newsreader (Thunderbird, XNews, etc.), and learning posting "COME TO MY WEBSITE!!111!!" anywhere (except misc.test) will get you mocked and ridiculed. ;) Now there's nothing wrong with making a newsserver publicly available and free, but when you maintain it like a throw-away blog, allowing child porn, spam, et al., you might as well kiss customer trust goodbye. Welcome to the Age of Google! :) A nice little page that I found that, unfortunately, is dead, has some info on Google Groups: http://web.archive.org/web/20080124152054/http://improve-usenet.org/ -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." From ldo at geek-central.gen.new_zealand Tue Jul 27 02:55:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 27 Jul 2010 18:55:54 +1200 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: In message , Roy Smith wrote: > Consider, for example, a write on a TCP connection. You are sitting in > a select(), when the other side closes the connection. The select() > should return, and the write should then immediately fail. Remember that select can return 3 different sets of file objects. I?ve yet to see a use for the third one. From ldo at geek-central.gen.new_zealand Tue Jul 27 02:58:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 27 Jul 2010 18:58:26 +1200 Subject: Are those features still the same? References: Message-ID: In message , francogrex wrote: > By the way Peter Norvig is not biased, he works for Google research and is > a supporter of programming in any language, especially in Python. Bias doesn?t have to be a conscious thing. From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:17:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:17:27 +0200 Subject: python terminology on classes In-Reply-To: References: Message-ID: <4c4e8801$0$14554$426a74cc@news.free.fr> Peng Yu a ?crit : > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? C++ and Python having very different semantics and object models, there's not necessarily a straight one to one mapping. > > constructor Python uses a smalltalk-like 2 phases instanciation / initialisation scheme. First the "proper" construction (__new__) is called with the class object as first argument, and it must return an unintialised instance of the class. Then the initialiser (__init__) is called on this instance. Now one usually only implements the initialiser, as the default object.__new__ method does what you would expect, so you'll often see people qualifying __init__ as the constructor. > destructor Python has no real destructor. You can implement a __del__ method that will _eventually_ be called before the instance gets garbage-collected, but you'd rather not rely on it. Also, implementing this method will prevent cycle detection. > member function => method. Note that Python's "methods" are really thin wrappers around function objects that are attributes of the class object. You'll find more on this here: http://wiki.python.org/moin/FromFunctionToMethod > member variable => Attribute > virtual member function All Python's methods are virtual. > function => function !-) Note that in Python, functions and classes are objects. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python > terms in the manual as these term appear many times. Could you please > point me where to look for the definition of these python > corresponding terms? You just cannot directly translate C++ into Python, and while there are similarities trying to write C++ in Python will not get you very far. From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:21:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:21:30 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> Message-ID: <4c4e88f4$0$14554$426a74cc@news.free.fr> Ethan Furman a ?crit : > Bruno Desthuilliers wrote: >> Duncan Booth a ?crit : (snip) >>> Or you could create the default as a class attribute >> >> from the OP: >> """ >> I have a class (FuncDesigner oofun) that has no attribute "size", but >> it is overloaded in __getattr__, so if someone invokes >> "myObject.size", it is generated (as another oofun) and connected to >> myObject as attribute. >> """ >> >> so this solution won't obviously work in this case !-) >> >> Also and FWIW, I wouldn't advocate this solution if the "default" >> class attribute is of a mutable type. > > Well, it is Monday, so I may be missing something obvious, but what is > the effective difference between these two solutions? Now it's Tuesday !-) Ok, let's see: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... whatever = Foo() ... Traceback (most recent call last): File "", line 1, in File "", line 2, in Foo NameError: name 'Foo' is not defined >>> From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:28:26 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:28:26 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4e88f4$0$14554$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> Message-ID: <4c4e8a95$0$24098$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Ethan Furman a ?crit : >> Bruno Desthuilliers wrote: >>> Duncan Booth a ?crit : > (snip) > >>>> Or you could create the default as a class attribute >>> >>> from the OP: >>> """ >>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>> it is overloaded in __getattr__, so if someone invokes >>> "myObject.size", it is generated (as another oofun) and connected to >>> myObject as attribute. >>> """ >>> >>> so this solution won't obviously work in this case !-) >>> >>> Also and FWIW, I wouldn't advocate this solution if the "default" >>> class attribute is of a mutable type. >> >> Well, it is Monday, so I may be missing something obvious, but what is >> the effective difference between these two solutions? > If you meant "what is the difference between creating the "whatever" attribute with a default value in the initializer and creating it on demand in the __getattr__ hook", the main difference is that in the first case, the instance is garanteed to have this attribute, so you get rid of "hasattr" checks (and the unwanted side effects) or, worse, direct check of the instance __dict__. Except for a couple of corner case, client code shouldn't have to worry about this kind of things - this breaks encapsulation. From __peter__ at web.de Tue Jul 27 04:23:20 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 10:23:20 +0200 Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: mo reina wrote: > i've written a tool in python where you enter a title, content, then > tags, and the entry is then saved in a pickle file. it was mainly > designed for copy-paste functionality (you spot a piece of code you > like on the net, copy it, and paste it into the program), not really > for handwritten content, though it does that with no problem. > > i mainly did it because i'm always scanning through my pdf files, > books, or the net for some coding example of solution that i'd already > seen before, and it just seemed logical to have something where you > could just put the content in, give it a title and tags, and just look > it up whenever you needed to. > > i realize there are sites online that handle this ex. > http://snippets.dzone.com, but i'm not always online when i code. i also > admit that i didn't really look to see if anyone had written a desktop > app, the project seemed like a fun thing to do so here i am. > > it wasn't designed with millions of entries in mind, so i just use a > pickle file to serialize the data instead of one of the database APIs. > the query is also very basic, only title and tags and no ranking based > on the query. > > there is an issue that i can't figure out, when you are at the list of > entries there's a try, except clause where it tries to catch a valid > index (integer). if you enter an inavlid integer, it will ask you to > enter a valid one, but it doesn't seem to be able to assign it to the > variable. if you enter a valid integer straightaway, there are no > problems and the entry will display. > > anyway let me know what you guys think. this is coded for python3. > def choices(list_result): > '''takes a list of objects and returns the index of the selected > object''' > os.system('clear') > index = 0 > for entry in list_result: > print('{}. {}'.format(index, entry.title)) > index += 1 > try: > choice = int(input('\nEnter choice: ')) > return choice > except: > pause = input('\nplease enter a valid choice') > choices(list_result) When the exception is triggered you call choices() recursively but discard the result. Therefore you get Python's default, None, which is not a valid index. Change the last line to return choices(list_result) for a minimal fix. However, I suggest that you use a while loop instead of the recursion: def choices(list_result): while True: os.system('clear') for index, entry in enumerate(list_result): print('{}. {}'.format(index, entry.title)) try: choice = int(input('\nEnter choice: ')) if 0 <= choice < len(list_result): return choice except ValueError: pass input('\nplease enter a valid choice') I've also added a test for the integer range and replaced the bare except with a more specific one. I recommend that you never use bare excepts because they can hide unexpected exceptions and lead to nasty bugs. You should also remove the recursive call of main(). Its only effect is that when you enter an invalid choice twice you will have to enter "5" twice to really exit your script. Peter From __peter__ at web.de Tue Jul 27 04:37:08 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 10:37:08 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: rlevesque wrote: > On Jul 24, 1:34 pm, Peter Otten <__pete... at web.de> wrote: >> rlevesque wrote: >> > Unfortunately there is an other pair of values that does not match and >> > it is not obvious to me how to exclude it (as is done with the " / >> > CreationDate" pair). >> > and the pdf document is created using reportLab. >> >> I dug into the reportlab source and in >> >> reportlab/rl_config.py >> >> found the line >> >> invariant= 0 #produces >> repeatable,identical PDFs with same timestamp info (for regression >> testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) Relax! Assistance on c.l.py is free as in beer ;) If you feel you have to give something back pick a question you can answer, doesn't matter who's asking. Given that I can't answer the majority of questions posted here chances are that I learn something from your response, too. Peter From kaklis at gmail.com Tue Jul 27 05:58:14 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 02:58:14 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: On Jul 22, 12:56?pm, Thomas Jollans wrote: > On 07/21/2010 03:38 PM, kak... at gmail.com wrote: > > > > > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: > >> On Jul 21, 8:58 am, Stefan Behnel wrote: > > >>> kak... at gmail.com, 21.07.2010 14:36: > > >>>> From the subject of my message it's clear that i get an xml message > >>>> from a socket, > > >>> Not at all, but now that you say it... > > >>>> i parse it and the result is a list like the one that > >>>> follows: > >>>> ID_Col > >>>> 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > >>>> 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > >>>> 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > >>>> 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > >>>> 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > >>>> 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > >>>> 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > >>> Doesn't look like a Python list to me... > > >>>> What i want is to print this list sorted by ID_Col? > >>>> Any Suggestions? > > >>> Assuming that the above is supposed to represent a list of tuples, you can > >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > >>> argument (see the sort() method and the operator module). > > >>> Stefan > > >> No it is not a Python list at all. This the way i print the parsed > >> items 'like a list'. > >> But i want them to be sorted. > > > Well i did this: > > > SortedServers = [] > > > for session in sessions: > > ? ? for IP in session.getElementsByTagName("ipAddress"): > > ? ? ? ? ?for iphn in session.getElementsByTagName("hostName"): > > ? ? ? ? ? ? ? tempTuple = session.getAttribute("id"), > > session.getAttribute("type"), iphn.childNodes[0].data, > > IP.childNodes[0].data, session.getAttribute("status") > > Please try to persuade your mail client to not mess up python code, if > you could. It would make this *so* much easier to read > > > > > ? ? ? ? ? ? ? SortedServers.append(tempTuple) > > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) > > Anyway, let's look at that key function of yours: > > key=lambda id: SortedServers[0] > > translated to traditional function syntax: > > def key(id): > ? ? return SortedServers[0] > > No matter which item sorted() examines, the key it sorts by is always > the same (the first item of the WHOLE LIST). > You want something more like this: > > def key(row): > ? ? return row[0] > > ergo, what you want, all in all, is either of these: > > Sorted = sorted(SortedServers, key=(lambda row: row[0])) # option 1 > SortedServers.sort(key=(lambda row: row[0])) ? ? ? ? ? ? # option 2 > > option 2, the in-place sort, might be faster. > > (and, as Stefan noted, as you probably want a numeric sort, you'll want > your key to be an int) > > > for item in Sorted: > > ? ? ?print item > > > but the list is still unsorted and with u' in front of each item > > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') > > > How do i remove the u' > > > Antonis > > Thank you so much for your detailed response! Antonis K. From kaklis at gmail.com Tue Jul 27 06:17:36 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 03:17:36 -0700 (PDT) Subject: parsing different xml messages Message-ID: Hello, I receive the following different Xml Messages from a socket: 5a62ded 101 Angie online Some IP Server server-1 is going down for redeploy! Which is the best way to make a distinction between them so that every time my app receives the one or the other, parse them correctly? Thanks Antonis K. From nobody at nowhere.com Tue Jul 27 06:21:29 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 27 Jul 2010 11:21:29 +0100 Subject: How to capture all the environment variables from shell? References: <4C4E43D3.9070203@syslang.net> Message-ID: On Mon, 26 Jul 2010 21:42:24 -0500, Tim Chase wrote: >> Please! Never export anything from your .bashrc unless you >> really know what you're doing. Almost all exports should be >> done in your .bash_profile > > Could you elaborate on your reasoning why (or why-not)? I've > found that my .bash_profile doesn't get evaluated when I crank up > another terminal window, while my bashrc does. Thus I tend to > put my exports in my ~/.bashrc so they actually take effect in my > shell... Ideally, whichever program spawns the terminal window should have all of the environment settings from your ~/.profile (although you may have to explicitly source it from e.g. ~/.xsession), so it shouldn't be necessary to export them again. Using ~/.bashrc is a band-aid in case your desktop session doesn't already have your environment settings. But it only works for shells (and only for bash shells, and only for interactive bash shells), while your environment settings should be available to everything, regardless of whether it was spawned from an interactive bash shell or from some other program. Also, if you update environment variables with e.g.: export PATH=$PATH:/usr/local/bin any nested shells end up getting multiple updates. From tania786786 at gmail.com Tue Jul 27 06:21:34 2010 From: tania786786 at gmail.com (tania tani) Date: Tue, 27 Jul 2010 03:21:34 -0700 (PDT) Subject: $$$$ YOU ARE JUST ONE CLICK TO MAKE DOLLAR ITS FREE Message-ID: http://www.bigextracash.com/aft/9b6cc578.html also click here to see and enjoy http://sitetalk.com/imranraza From urban.yoga.journeys at gmail.com Tue Jul 27 06:29:07 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Tue, 27 Jul 2010 03:29:07 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: > mo reina wrote: > > i've written a tool in python where you enter a title, content, then > > tags, and the entry is then saved in a pickle file. it was mainly > > designed for copy-paste functionality (you spot a piece of code you > > like on the net, copy it, and paste it into the program), not really > > for handwritten content, though it does that with no problem. > > > i mainly did it because i'm always scanning through my pdf files, > > books, or the net for some coding example of solution that i'd already > > seen before, and it just seemed logical to have something where you > > could just put the content in, give it a title and tags, and just look > > it up whenever you needed to. > > > i realize there are sites online that handle this ex. > >http://snippets.dzone.com, but i'm not always online when i code. i also > > admit that i didn't really look to see if anyone had written a desktop > > app, the project seemed like a fun thing to do so here i am. > > > it wasn't designed with millions of entries in mind, so i just use a > > pickle file to serialize the data instead of one of the database APIs. > > the query is also very basic, only title and tags and no ranking based > > on the query. > > > there is an issue that i can't figure out, when you are at the list of > > entries there's a try, except clause where it tries to catch a valid > > index (integer). if you enter an inavlid integer, it will ask you to > > enter a valid one, but it doesn't seem to be able to assign it to the > > variable. if you enter a valid integer straightaway, there are no > > problems and the entry will display. > > > anyway let me know what you guys think. this is coded for python3. > > def choices(list_result): > > ? ? '''takes a list of objects and returns the index of the selected > > object''' > > ? ? os.system('clear') > > ? ? index = 0 > > ? ? for entry in list_result: > > ? ? ? ? print('{}. {}'.format(index, entry.title)) > > ? ? ? ? index += 1 > > ? ? try: > > ? ? ? ? choice = int(input('\nEnter choice: ')) > > ? ? ? ? return choice > > ? ? except: > > ? ? ? ? pause = input('\nplease enter a valid choice') > > ? ? ? ? choices(list_result) > > When the exception is triggered you call choices() recursively but discard > the result. Therefore you get Python's default, None, which is not a valid > index. Change the last line to > > return choices(list_result) > > for a minimal fix. However, I suggest that you use a while loop instead of > the recursion: > > def choices(list_result): > ? ? while True: > ? ? ? ? os.system('clear') > ? ? ? ? for index, entry in enumerate(list_result): > ? ? ? ? ? ? print('{}. {}'.format(index, entry.title)) > ? ? ? ? try: > ? ? ? ? ? ? choice = int(input('\nEnter choice: ')) > ? ? ? ? ? ? if 0 <= choice < len(list_result): > ? ? ? ? ? ? ? ? return choice > ? ? ? ? except ValueError: > ? ? ? ? ? ? pass > ? ? ? ? input('\nplease enter a valid choice') > > I've also added a test for the integer range and replaced the bare except > with a more specific one. I recommend that you never use bare excepts > because they can hide unexpected exceptions and lead to nasty bugs. > > You should also remove the recursive call of main(). Its only effect is that > when you enter an invalid choice twice you will have to enter "5" twice to > really exit your script. > > Peter hi peter, i noticed the issue you mentioned but don't understand why they happen. for example, when the function is called in the case of an exception, the variable choice is re-assigned to whatever the next input is, so why is the default None assigned instead? and what' s the difference between just calling the function again (the variable list_result remains unchanged) and using a return statement? i also don' t understand what happens when main is called recursively, the variable choice should be re-assigned to whatever the next input is, and yet it seems that in the first call, after an invalid choice, it doesn't assign the input to the variable. thanks for taking the time to post and review the code by the way, i really appreciate it From stefan_ml at behnel.de Tue Jul 27 06:30:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 12:30:48 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 12:17: > I receive the following different Xml Messages from a socket: From a bare socket? TCP? UDP? Or what else? > Which is the best way to make a distinction between them so that every > time my app receives the one or the other, parse them correctly? Use an application level protocol? Stefan From debatem1 at gmail.com Tue Jul 27 06:54:07 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 27 Jul 2010 03:54:07 -0700 Subject: Accumulate function in python In-Reply-To: <4c470fa3$0$1583$742ec2ed@news.sonic.net> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote: > On 7/19/2010 9:56 AM, dhruvbird wrote: >> >> On Jul 19, 9:12 pm, Brian Victor ?wrote: >>> >>> dhruvbird wrote: > >>> Having offered this, I don't recall ever seeing reduce used in real >>> python code, and explicit iteration is almost always preferred. >> >> Yes, even I have noticed that reduce is a tad under-used function. > > ? ?Yes, I had a use case for it once, but it wasn't worth the trouble. > "map" is often useful, but "reduce", not so much. > > ? ?Python isn't really a functional language. ?There's no bias toward > functional solutions, lambdas aren't very general, and the performance > isn't any better. ?Nor is any concurrency provided by "map" or "reduce". > So there's no win in trying to develop cute one-liners. Too bad about the lack of concurrency, would be many places where that would be nice. Geremy Condra From me at here.com Tue Jul 27 07:07:09 2010 From: me at here.com (whitey) Date: Tue, 27 Jul 2010 11:07:09 GMT Subject: newb Message-ID: hi all. am totally new to python and was wondering if there are any newsgroups that are there specifically for beginners. i have bought a book for $2 called "learn to program using python" by alan gauld. starting to read it but it was written in 2001. presuming that the commands and info would still be valid? any websites or books that are a must for beginners? any input would be much appreciated...cheers From hanycv80 at gmail.com Tue Jul 27 07:13:53 2010 From: hanycv80 at gmail.com (=?windows-1256?B?KioqKioq48rd3Nzc3Nzc3MfG3Nzc3Nzc4SoqKioqKg==?=) Date: Tue, 27 Jul 2010 04:13:53 -0700 (PDT) Subject: Enjoy Thousands Of Tips and Trikes Message-ID: <2be45a25-7c77-4e0d-8a6b-b7b7cf7076ab@t19g2000vbf.googlegroups.com> Very Nice Tips and Trikes I am sure you are going to love it. Financing Information http://www.netcafee.com/finance/index.php Preparing For Your Vacation http://www.netcafee.com/travel/index.php Buying A Fuel-Efficient Car http://www.netcafee.com/car/index.php Computer Help http://www.netcafee.com/computer/index.php Shopping Online http://www.netcafee.com/shopping/index.php Using Online Video Websites to Promote Your Business http://www.netcafee.com/video/index.php Have Fun..... From sjmachin at lexicon.net Tue Jul 27 07:15:32 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jul 2010 04:15:32 -0700 (PDT) Subject: newb References: Message-ID: On Jul 27, 9:07?pm, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers 2001 is rather old. Most of what you'll want is on the web. See http://wiki.python.org/moin/BeginnersGuide From stefan_ml at behnel.de Tue Jul 27 07:16:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 13:16:59 +0200 Subject: Accumulate function in python In-Reply-To: References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: geremy condra, 27.07.2010 12:54: > On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote: >> On 7/19/2010 9:56 AM, dhruvbird wrote: >>> >>> On Jul 19, 9:12 pm, Brian Victor wrote: >>>> >>>> dhruvbird wrote: >> >>>> Having offered this, I don't recall ever seeing reduce used in real >>>> python code, and explicit iteration is almost always preferred. >>> >>> Yes, even I have noticed that reduce is a tad under-used function. >> >> Yes, I had a use case for it once, but it wasn't worth the trouble. >> "map" is often useful, but "reduce", not so much. >> >> Python isn't really a functional language. There's no bias toward >> functional solutions, lambdas aren't very general, and the performance >> isn't any better. Nor is any concurrency provided by "map" or "reduce". >> So there's no win in trying to develop cute one-liners. > > Too bad about the lack of concurrency, would be many places where that > would be nice. Besides the many places where the current properties match just fine, there are some places where concurrency would be helpful. So I wouldn't call it "lack" of concurrency, as that seems to imply that it's a missing feature in what both builtins are targeted to provide. Just use one of the map-reduce frameworks that are out there if you need concurrency in one way or another. Special needs are not what builtins are there for. Stefan From roy at panix.com Tue Jul 27 07:48:24 2010 From: roy at panix.com (Roy Smith) Date: Tue, 27 Jul 2010 07:48:24 -0400 Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: In article , Stephen Hansen wrote: > PEP8 is a style guide. Parts of style guides are rational judgements and > decisions based on experience and can certainly be "explained" or > justified, but parts are just... personal taste. Style is part rational > thought and part intuition, and in the latter -- people will disagree > quite a bit. There's no right or wrong there. There isn't always a > rationale. I strongly suggest that ALL Python projects adopt PEP-8. Here's why. Style, at one level, doesn't really matter. Yet, it's something people get worked up over. If you add up all the time people have wasted arguing about stupid shit like indenting and where the braces go (in languages that have them) and how to spell variable names, we could have sent a man to Mars and had time left over to solve P = NP. I don't agree with PEP-8 100%, but it's perfectly reasonable. Avoiding all that time wasting arguing about trivia like variableName vs VariableName vs variable_name more than pays me back for any minor arguments I might have with the style. If everybody in the entire world uses the same style, then as people and code move around from project to project, everybody benefits by fitting in better. As the old-time press pythonistas would say, "PEP-8 and be there". From robin at reportlab.com Tue Jul 27 07:55:47 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 27 Jul 2010 12:55:47 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) In-Reply-To: References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: <4C4EC943.50600@chamonix.reportlab.co.uk> .......... >> repeatable,identical PDFs with same timestamp info (for regression testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) > > Regards, ...... if you have any more reportlab related queries you can also get free advice on the reportlab mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users -- Robin Becker From robin at reportlab.com Tue Jul 27 07:55:47 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 27 Jul 2010 12:55:47 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) In-Reply-To: References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: <4C4EC943.50600@chamonix.reportlab.co.uk> .......... >> repeatable,identical PDFs with same timestamp info (for regression testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) > > Regards, ...... if you have any more reportlab related queries you can also get free advice on the reportlab mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users -- Robin Becker From kaklis at gmail.com Tue Jul 27 07:58:16 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 04:58:16 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: On Jul 27, 6:30?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 12:17: > > > I receive the following different Xml Messages from a socket: > > ?From a bare socket? TCP? UDP? Or what else? > > > Which is the best way to make a distinction between them so that every > > time my app receives the one or the other, parse them correctly? > > Use an application level protocol? > > Stefan >From a tcp socket using the twisted framework. Application level protocol... Such as? From __peter__ at web.de Tue Jul 27 08:06:34 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 14:06:34 +0200 Subject: Personal archive tool, looking for suggestions on improving the code References: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> Message-ID: mo reina wrote: > On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: >> mo reina wrote: >> > i've written a tool in python where you enter a title, content, then >> > tags, and the entry is then saved in a pickle file. it was mainly >> > designed for copy-paste functionality (you spot a piece of code you >> > like on the net, copy it, and paste it into the program), not really >> > for handwritten content, though it does that with no problem. >> >> > i mainly did it because i'm always scanning through my pdf files, >> > books, or the net for some coding example of solution that i'd already >> > seen before, and it just seemed logical to have something where you >> > could just put the content in, give it a title and tags, and just look >> > it up whenever you needed to. >> >> > i realize there are sites online that handle this ex. >> >http://snippets.dzone.com, but i'm not always online when i code. i also >> > admit that i didn't really look to see if anyone had written a desktop >> > app, the project seemed like a fun thing to do so here i am. >> >> > it wasn't designed with millions of entries in mind, so i just use a >> > pickle file to serialize the data instead of one of the database APIs. >> > the query is also very basic, only title and tags and no ranking based >> > on the query. >> >> > there is an issue that i can't figure out, when you are at the list of >> > entries there's a try, except clause where it tries to catch a valid >> > index (integer). if you enter an inavlid integer, it will ask you to >> > enter a valid one, but it doesn't seem to be able to assign it to the >> > variable. if you enter a valid integer straightaway, there are no >> > problems and the entry will display. >> >> > anyway let me know what you guys think. this is coded for python3. >> > def choices(list_result): >> > '''takes a list of objects and returns the index of the selected >> > object''' >> > os.system('clear') >> > index = 0 >> > for entry in list_result: >> > print('{}. {}'.format(index, entry.title)) >> > index += 1 >> > try: >> > choice = int(input('\nEnter choice: ')) >> > return choice >> > except: >> > pause = input('\nplease enter a valid choice') >> > choices(list_result) >> >> When the exception is triggered you call choices() recursively but >> discard the result. Therefore you get Python's default, None, which is >> not a valid index. Change the last line to >> >> return choices(list_result) >> >> for a minimal fix. However, I suggest that you use a while loop instead >> of the recursion: >> >> def choices(list_result): >> while True: >> os.system('clear') >> for index, entry in enumerate(list_result): >> print('{}. {}'.format(index, entry.title)) >> try: >> choice = int(input('\nEnter choice: ')) >> if 0 <= choice < len(list_result): >> return choice >> except ValueError: >> pass >> input('\nplease enter a valid choice') >> >> I've also added a test for the integer range and replaced the bare except >> with a more specific one. I recommend that you never use bare excepts >> because they can hide unexpected exceptions and lead to nasty bugs. >> >> You should also remove the recursive call of main(). Its only effect is >> that when you enter an invalid choice twice you will have to enter "5" >> twice to really exit your script. >> >> Peter > > hi peter, i noticed the issue you mentioned but don't understand why > they happen. > > for example, when the function is called in the case of an exception, > the variable choice is re-assigned to whatever the next input is, so > why is the default None assigned instead? and what' s the difference > between just calling the function again (the variable list_result > remains unchanged) and using a return statement? If you have a function def f(): return 42 and just call it from another function def g(): f() the result of f() is evaluated but immediately discarded. If you want to use it inside g() you have to assign it to a variable def g(): x = f() y = x * x print y and if you want to use it outside g() you can return it. def g(): return f() For recursion the same rules apply, only with the same function as f and g. Here's a simple example for you to work out the program flow: >>> def r1(n): ... print "entering level", n ... if n == 5: ... print "limit reached" ... print "exiting level", n ... print "returning 42" ... return 42 ... else: ... print "recursing" ... r1(n+1) ... print "exiting level", n ... print "(implicitly) returning None" ... >>> r1(0) entering level 0 recursing entering level 1 recursing entering level 2 recursing entering level 3 recursing entering level 4 recursing entering level 5 limit reached exiting level 5 returning 42 exiting level 4 (implicitly) returning None exiting level 3 (implicitly) returning None exiting level 2 (implicitly) returning None exiting level 1 (implicitly) returning None exiting level 0 (implicitly) returning None Try to change r1() to return the value from the innermost call (i. e. 42) to the outside world. Once you have understood what is going on you should be able to see what's wrong with your program. Peter From stefan_ml at behnel.de Tue Jul 27 08:14:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 14:14:39 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 13:58: > On Jul 27, 6:30 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 12:17: >> >>> I receive the following different Xml Messages from a socket: >> >> From a bare socket? TCP? UDP? Or what else? >> >>> Which is the best way to make a distinction between them so that every >>> time my app receives the one or the other, parse them correctly? >> >> Use an application level protocol? >> >> Stefan > >> From a tcp socket using the twisted framework. >> Application level protocol... Such as? Depends on what you *can* use. Do you control the sending side? Note: giving better details helps others in giving better answers. Stefan From kaklis at gmail.com Tue Jul 27 08:26:11 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 05:26:11 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: On Jul 27, 8:14?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 13:58: > > > > > On Jul 27, 6:30 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 12:17: > > >>> I receive the following different Xml Messages from a socket: > > >> ? From a bare socket? TCP? UDP? Or what else? > > >>> Which is the best way to make a distinction between them so that every > >>> time my app receives the one or the other, parse them correctly? > > >> Use an application level protocol? > > >> Stefan > > >> From a tcp socket using the twisted framework. > >> Application level protocol... Such as? > > Depends on what you *can* use. Do you control the sending side? > > Note: giving better details helps others in giving better answers. > > Stefan Well yes you are right! I can't control the sending side. The app i'm writing just accepts incoming xml messages. Like the ones above. When i receive a message I parse it and print the information. I know how to parse both xml messages. What i want is to distinguish them so that i can trigger the appropriate parsing method. A.K. From stefan_ml at behnel.de Tue Jul 27 08:41:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 14:41:59 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 14:26: > On Jul 27, 8:14 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 13:58: >> >>> On Jul 27, 6:30 am, Stefan Behnel wrote: >>>> kak... at gmail.com, 27.07.2010 12:17: >> >>>>> I receive the following different Xml Messages from a socket: >> >>>> From a bare socket? TCP? UDP? Or what else? >> >>>>> Which is the best way to make a distinction between them so that every >>>>> time my app receives the one or the other, parse them correctly? >> >>>> Use an application level protocol? >> >>>> From a tcp socket using the twisted framework. >>>> Application level protocol... Such as? >> >> Depends on what you *can* use. Do you control the sending side? >> >> Note: giving better details helps others in giving better answers. > > Well yes you are right! > I can't control the sending side. > The app i'm writing just accepts incoming xml messages. Like the ones > above. > When i receive a message I parse it and print the information. > I know how to parse both xml messages. > What i want is to distinguish them so that i can trigger the > appropriate parsing method. Do they come in concatenated or one per connection? Stefan From kaklis at gmail.com Tue Jul 27 08:43:13 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 05:43:13 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> On Jul 27, 8:41?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 14:26: > > > > > On Jul 27, 8:14 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 13:58: > > >>> On Jul 27, 6:30 am, Stefan Behnel wrote: > >>>> kak... at gmail.com, 27.07.2010 12:17: > > >>>>> I receive the following different Xml Messages from a socket: > > >>>> ? ?From a bare socket? TCP? UDP? Or what else? > > >>>>> Which is the best way to make a distinction between them so that every > >>>>> time my app receives the one or the other, parse them correctly? > > >>>> Use an application level protocol? > > >>>> ?From a tcp socket using the twisted framework. > >>>> Application level protocol... Such as? > > >> Depends on what you *can* use. Do you control the sending side? > > >> Note: giving better details helps others in giving better answers. > > > Well yes you are right! > > I can't control the sending side. > > The app i'm writing just accepts incoming xml messages. Like the ones > > above. > > When i receive a message I parse it and print the information. > > I know how to parse both xml messages. > > What i want is to distinguish them so that i can trigger the > > appropriate parsing method. > > Do they come in concatenated or one per connection? > > Stefan one per connection. From fetchinson at googlemail.com Tue Jul 27 08:54:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jul 2010 14:54:42 +0200 Subject: Why is there no platform independent way of clearing a terminal? Message-ID: Hi folks, If I'm only interested in linux and windows I know I can do ################################ import os import platform if platform.system( ) == 'Linux': clear = 'clear' else: clear = 'cls' os.system( clear ) ################################ or something equivalent using os.name and friends, but was wondering why there is no platform independent way (i.e. the platform dependence is taken care of by the python stdlib) of clearing a terminal. Sure, there are many different terminals and many different operating systems but in many areas python managed to hide all these complexities behind a well defined API. Why was clearing a terminal left out? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From stefan_ml at behnel.de Tue Jul 27 09:06:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 15:06:44 +0200 Subject: parsing different xml messages In-Reply-To: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> References: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> Message-ID: kaklis at gmail.com, 27.07.2010 14:43: > On Jul 27, 8:41 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 14:26: >> >>> On Jul 27, 8:14 am, Stefan Behnel wrote: >>>> kak... at gmail.com, 27.07.2010 13:58: >> >>>>> On Jul 27, 6:30 am, Stefan Behnel wrote: >>>>>> kak... at gmail.com, 27.07.2010 12:17: >> >>>>>>> I receive the following different Xml Messages from a socket: >> >>>>>> From a bare socket? TCP? UDP? Or what else? >> >>>>>>> Which is the best way to make a distinction between them so that every >>>>>>> time my app receives the one or the other, parse them correctly? >> >>>>>> Use an application level protocol? >> >>>>>> From a tcp socket using the twisted framework. >>>>>> Application level protocol... Such as? >> >>>> Depends on what you *can* use. Do you control the sending side? >> >>>> Note: giving better details helps others in giving better answers. >> >>> Well yes you are right! >>> I can't control the sending side. >>> The app i'm writing just accepts incoming xml messages. Like the ones >>> above. >>> When i receive a message I parse it and print the information. >>> I know how to parse both xml messages. >>> What i want is to distinguish them so that i can trigger the >>> appropriate parsing method. >> >> Do they come in concatenated or one per connection? >> >> Stefan > > one per connection. Ah, ok, then just parse the message using (c)ElementTree and look at the name of the first child below the root node (assuming that both messages were supposed to have the same root node, as you may have wanted to indicate in your original posting). A dict dispatch to a function or method will do just fine. Stefan From kaklis at gmail.com Tue Jul 27 09:10:53 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 06:10:53 -0700 (PDT) Subject: parsing different xml messages References: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> Message-ID: <3fe7d57c-cd8f-45b9-81d4-39dbab88c26b@c16g2000vbp.googlegroups.com> On Jul 27, 9:06?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 14:43: > > > > > On Jul 27, 8:41 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 14:26: > > >>> On Jul 27, 8:14 am, Stefan Behnel wrote: > >>>> kak... at gmail.com, 27.07.2010 13:58: > > >>>>> On Jul 27, 6:30 am, Stefan Behnel wrote: > >>>>>> kak... at gmail.com, 27.07.2010 12:17: > > >>>>>>> I receive the following different Xml Messages from a socket: > > >>>>>> ? ? From a bare socket? TCP? UDP? Or what else? > > >>>>>>> Which is the best way to make a distinction between them so that every > >>>>>>> time my app receives the one or the other, parse them correctly? > > >>>>>> Use an application level protocol? > > >>>>>> ? From a tcp socket using the twisted framework. > >>>>>> Application level protocol... Such as? > > >>>> Depends on what you *can* use. Do you control the sending side? > > >>>> Note: giving better details helps others in giving better answers. > > >>> Well yes you are right! > >>> I can't control the sending side. > >>> The app i'm writing just accepts incoming xml messages. Like the ones > >>> above. > >>> When i receive a message I parse it and print the information. > >>> I know how to parse both xml messages. > >>> What i want is to distinguish them so that i can trigger the > >>> appropriate parsing method. > > >> Do they come in concatenated or one per connection? > > >> Stefan > > > one per connection. > > Ah, ok, then just parse the message using (c)ElementTree and look at the > name of the first child below the root node (assuming that both messages > were supposed to have the same root node, as you may have wanted to > indicate in your original posting). A dict dispatch to a function or method > will do just fine. > > Stefan ok that's great, thanks Stefan i'll try it. Antonis From davea at ieee.org Tue Jul 27 09:35:22 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 27 Jul 2010 09:35:22 -0400 Subject: newb In-Reply-To: References: Message-ID: <4C4EE09A.8060105@ieee.org> whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers > > Welcome to the forum, Newsgroup: Send Tutor mailing list submissions to tutor at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-request at python.org For an updated Alan Gauld tutorial: the Learn to Program web site http://www.alan-g.me.uk/ The python.org website is a wealth of information, and also contains links to many other python-oriented sites. Before installing python, consider whether you want version 2.x or 3.x. The language changed a bit at 3.x, and while you're learning, you want a tutorial that matches the version you're running. Easiest way to recognize a particular script as being one or the other is if it has a print statement. print is a statement in version 1.x and 2.x, and is a function in version 3. Any recent tutorial will tell you which it's targeting, but since version 3 is only a year or so old, older tutorials or sample code might well not mention it. DaveA From sturlamolden at yahoo.no Tue Jul 27 09:51:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 27 Jul 2010 06:51:21 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: On 19 Jul, 13:18, dhruvbird wrote: > Hello, > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > ? And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > ? What is the best way (or pythonic way) to get this. At least for large arrays, this is the kind of task where NumPy will help. >>> import numpy as np >>> np.cumsum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]) array([ 0, 1, 3, 4, 5, 5, 5, 7, 10]) From dirknbr at gmail.com Tue Jul 27 10:00:53 2010 From: dirknbr at gmail.com (dirknbr) Date: Tue, 27 Jul 2010 07:00:53 -0700 (PDT) Subject: Urrlib2 IncompleteRead error Message-ID: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> I am running urllib2.request and get this response when I do the read. Any ideas what causes this? return response.read() File "C:\Python26\lib\socket.py", line 329, in read data = self._sock.recv(rbufsize) File "C:\Python26\lib\httplib.py", line 518, in read return self._read_chunked(amt) File "C:\Python26\lib\httplib.py", line 561, in _read_chunked raise IncompleteRead(''.join(value)) IncompleteRead: IncompleteRead(3235 bytes read) Dirk From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 10:02:23 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 16:02:23 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: Message-ID: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Daniel Fetchinson a ?crit : > Hi folks, > > If I'm only interested in linux and windows I know I can do > > ################################ > import os > import platform > > if platform.system( ) == 'Linux': > clear = 'clear' > else: > clear = 'cls' > > os.system( clear ) > ################################ > > or something equivalent using os.name and friends, but was wondering > why there is no platform independent way (i.e. the platform dependence > is taken care of by the python stdlib) of clearing a terminal. Sure, > there are many different terminals and many different operating > systems but in many areas python managed to hide all these > complexities behind a well defined API. > > Why was clearing a terminal left out? > What you're talking about is a shell, not a terminal (a terminal is a physical device). And the shell is not necessarily part of the OS itself (there's no shortage of shells for unices / linux systems), so it doesn't belong to the os or platform modules. FWIW, I can't tell for sure since I never used any other shell than bash, but I'm not sure your above code is garanteed to work on each and any possible unix shell. From gberbeglia at gmail.com Tue Jul 27 10:04:56 2010 From: gberbeglia at gmail.com (gerardob) Date: Tue, 27 Jul 2010 07:04:56 -0700 (PDT) Subject: string manipulation. Message-ID: <29276755.post@talk.nabble.com> I am trying to read an xml using minidom from python library xml.dom This is the xml file: --------------------------------- AB 100 2 ---------------------------------- This is the python code: -------------------------------- from xml.dom import minidom doc= minidom.parse("example.xml") resources_section = doc.getElementsByTagName('resources') list_resources = resources_section[0].getElementsByTagName('resource') for r in list_resources: name = r.childNodes[0].nodeValue print name print len(name) --------------------------------- The problem is that the nodeValue stored in the variable 'name' is not "AB" (what i want) but instead it is a string that has length of 8 and it seems it include the tabs and/or other things. How can i get the string "AB" without the other stuff? Thanks. -- View this message in context: http://old.nabble.com/string-manipulation.-tp29276755p29276755.html Sent from the Python - python-list mailing list archive at Nabble.com. From j.reid at mail.cryst.bbk.ac.uk Tue Jul 27 10:06:52 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 27 Jul 2010 15:06:52 +0100 Subject: Check in interpreter if running a debug version of python Message-ID: Can I check in the interpreter if I am running a debug version of python? I don't mean if __debug__ is set, I want to know if python was compiled in debug mode. Thanks, John. From neilc at norwich.edu Tue Jul 27 10:14:36 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Jul 2010 14:14:36 GMT Subject: string manipulation. References: Message-ID: <8b87ucFtlmU1@mid.individual.net> On 2010-07-27, gerardob wrote: > > I am trying to read an xml using minidom from python library xml.dom > > This is the xml file: > --------------------------------- > > > > AB > 100 > > 2 > > > > > ---------------------------------- > This is the python code: > -------------------------------- > from xml.dom import minidom > doc= minidom.parse("example.xml") > resources_section = doc.getElementsByTagName('resources') > list_resources = resources_section[0].getElementsByTagName('resource') > > for r in list_resources: > name = r.childNodes[0].nodeValue > print name > print len(name) > --------------------------------- > The problem is that the nodeValue stored in the variable 'name' is not "AB" > (what i want) but instead it is a string that has length of 8 and it seems > it include the tabs and/or other things. > How can i get the string "AB" without the other stuff? Check out the strip member function. name = r.childNodes[0].nodeValue.strip() -- Neil Cerutti From lists at cheimes.de Tue Jul 27 10:25:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jul 2010 16:25:44 +0200 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: > Can I check in the interpreter if I am running a debug version of > python? I don't mean if __debug__ is set, I want to know if python was > compiled in debug mode. Python has multiple flavors of debug builds. hasattr(sys, "gettotalrefcount") is only available if Py_REF_DEBUG is enabled. This should be sufficient to detect the most used debug variant. Christian From metolone+gmane at gmail.com Tue Jul 27 10:30:41 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 27 Jul 2010 07:30:41 -0700 Subject: string manipulation. References: <29276755.post@talk.nabble.com> Message-ID: "gerardob" wrote in message news:29276755.post at talk.nabble.com... > > I am trying to read an xml using minidom from python library xml.dom > > This is the xml file: > --------------------------------- > > > > AB > 100 > > 2 > > > > > ---------------------------------- > This is the python code: > -------------------------------- > from xml.dom import minidom > doc= minidom.parse("example.xml") > resources_section = doc.getElementsByTagName('resources') > list_resources = resources_section[0].getElementsByTagName('resource') > > for r in list_resources: > name = r.childNodes[0].nodeValue > print name > print len(name) > --------------------------------- > The problem is that the nodeValue stored in the variable 'name' is not > "AB" > (what i want) but instead it is a string that has length of 8 and it seems > it include the tabs and/or other things. > How can i get the string "AB" without the other stuff? > Thanks. Whitespace in XML is significant. If the file was: AB100 2 You would just read 'AB'. If you don't control the XML file, then: print name.strip() will remove leading and trailing whitespace. -Mark From invalid at invalid.invalid Tue Jul 27 10:32:52 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 27 Jul 2010 14:32:52 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: On 2010-07-27, Bruno Desthuilliers wrote: > Daniel Fetchinson a ?crit : >> Hi folks, >> >> If I'm only interested in linux and windows I know I can do >> >> ################################ >> import os >> import platform >> >> if platform.system( ) == 'Linux': >> clear = 'clear' >> else: >> clear = 'cls' >> >> os.system( clear ) >> ################################ >> >> or something equivalent using os.name and friends, but was wondering >> why there is no platform independent way (i.e. the platform dependence >> is taken care of by the python stdlib) of clearing a terminal. Sure, >> there are many different terminals and many different operating >> systems but in many areas python managed to hide all these >> complexities behind a well defined API. >> >> Why was clearing a terminal left out? >> > > What you're talking about is a shell, not a terminal (a terminal is a > physical device). No, what he's talking about is clearing a terminal (or a terminal emulator). They both work the same, the only difference is whether the terminal software is running on dedicated hardware or on general-purpose hardware. > And the shell is not necessarily part of the OS itself > (there's no shortage of shells for unices / linux systems), so it > doesn't belong to the os or platform modules. True, but clearing a terminal or terminal emulator has nothing to do with the shell. It's done using an in-band control/escape sequence that's indepedent of the shell being used. His example accomplishes this using an executable named 'clear' which knows how to use terminfo/termcap (I forget which one) to send the proper escape sequence to the terminal. > FWIW, I can't tell for sure since I never used any other shell than > bash, but I'm not sure your above code is garanteed to work on each > and any possible unix shell. Again, the shell is irrelevent. -- Grant Edwards grant.b.edwards Yow! Zippy's brain cells at are straining to bridge gmail.com synapses ... From python at bdurham.com Tue Jul 27 10:33:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:33:06 -0400 Subject: Best practice way to open files in Python 2.6+? Message-ID: <1280241186.27454.1386974299@webmail.messagingengine.com> What is the best practice way to open files in Python 2.6+ It looks like there are at least 3 different ways to open files: - built-in open() - io.open() - codecs.open() It seems like io.open() combines the best of the built-in open() and the codecs open(). Am I missing any obvious drawbacks to using io.open() except for backwards compatibility? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Jul 27 10:36:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:36:36 -0400 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? Message-ID: <1280241396.28353.1386974575@webmail.messagingengine.com> Windows: How can I detect whether a Python app/script is running in console/GUI mode? By app I mean a script compiled to an exe via py2exe or similar. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From phil at riverbankcomputing.com Tue Jul 27 10:36:55 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 27 Jul 2010 15:36:55 +0100 Subject: Why is there no platform independent way of clearing a =?UTF-8?Q?terminal=3F?= In-Reply-To: <4c4ee6e8$0$20965$426a74cc@news.free.fr> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: <67f0a4af61f6f83afccff2af8bfc0b94@localhost> On Tue, 27 Jul 2010 16:02:23 +0200, Bruno Desthuilliers wrote: > Daniel Fetchinson a ?crit : >> Hi folks, >> >> If I'm only interested in linux and windows I know I can do >> >> ################################ >> import os >> import platform >> >> if platform.system( ) == 'Linux': >> clear = 'clear' >> else: >> clear = 'cls' >> >> os.system( clear ) >> ################################ >> >> or something equivalent using os.name and friends, but was wondering >> why there is no platform independent way (i.e. the platform dependence >> is taken care of by the python stdlib) of clearing a terminal. Sure, >> there are many different terminals and many different operating >> systems but in many areas python managed to hide all these >> complexities behind a well defined API. >> >> Why was clearing a terminal left out? >> > > What you're talking about is a shell, not a terminal (a terminal is a > physical device). And the shell is not necessarily part of the OS itself > (there's no shortage of shells for unices / linux systems), so it > doesn't belong to the os or platform modules. > > FWIW, I can't tell for sure since I never used any other shell than > bash, but I'm not sure your above code is garanteed to work on each and > any possible unix shell. Sorry, but that is completely wrong - the shell is irrelevant. "clear" is just a normal command line program that queries the termcap/terminfo database (possibly via the curses library) for the terminal specific sequence of characters that will clear the screen. It then writes those characters to stdout. The terminal, or (more usually these days) terminal emulator, then interprets those characters and takes the appropriate action. I'm not sure what the POSIX status of the clear command is, but I'd be surprised if it wasn't present on a UNIX/Linux system of any vintage. Phil From brian.curtin at gmail.com Tue Jul 27 10:42:21 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:42:21 -0500 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: On Tue, Jul 27, 2010 at 09:06, John Reid wrote: > Can I check in the interpreter if I am running a debug version of python? I > don't mean if __debug__ is set, I want to know if python was compiled in > debug mode. > > Thanks, > John. Starting with Python 2.7 and 3.2 you can do this: >>> sysconfig.get_config_var("Py_DEBUG") 1 (returns None if the var doesn't exist) -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 10:44:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 16:44:10 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: <4c4ef0b2$0$5752$426a34cc@news.free.fr> Grant Edwards a ?crit : > On 2010-07-27, Bruno Desthuilliers wrote: >> Daniel Fetchinson a ?crit : (snip) >>> Why was clearing a terminal left out? >>> >> What you're talking about is a shell, not a terminal (a terminal is a >> physical device). > > No, what he's talking about is clearing a terminal (or a terminal > emulator). They both work the same, the only difference is whether > the terminal software is running on dedicated hardware or on > general-purpose hardware. (snip) I stand corrected. From urban.yoga.journeys at gmail.com Tue Jul 27 10:48:43 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Tue, 27 Jul 2010 07:48:43 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code References: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> Message-ID: <1bb1168b-6db0-49d8-9707-3b72ece5229c@o12g2000vbc.googlegroups.com> On Jul 27, 2:06?pm, Peter Otten <__pete... at web.de> wrote: > mo reina wrote: > > On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: > >> mo reina wrote: > >> > i've written a tool in python where you enter a title, content, then > >> > tags, and the entry is then saved in a pickle file. it was mainly > >> > designed for copy-paste functionality (you spot a piece of code you > >> > like on the net, copy it, and paste it into the program), not really > >> > for handwritten content, though it does that with no problem. > > >> > i mainly did it because i'm always scanning through my pdf files, > >> > books, or the net for some coding example of solution that i'd already > >> > seen before, and it just seemed logical to have something where you > >> > could just put the content in, give it a title and tags, and just look > >> > it up whenever you needed to. > > >> > i realize there are sites online that handle this ex. > >> >http://snippets.dzone.com, but i'm not always online when i code. i also > >> > admit that i didn't really look to see if anyone had written a desktop > >> > app, the project seemed like a fun thing to do so here i am. > > >> > it wasn't designed with millions of entries in mind, so i just use a > >> > pickle file to serialize the data instead of one of the database APIs. > >> > the query is also very basic, only title and tags and no ranking based > >> > on the query. > > >> > there is an issue that i can't figure out, when you are at the list of > >> > entries there's a try, except clause where it tries to catch a valid > >> > index (integer). if you enter an inavlid integer, it will ask you to > >> > enter a valid one, but it doesn't seem to be able to assign it to the > >> > variable. if you enter a valid integer straightaway, there are no > >> > problems and the entry will display. > > >> > anyway let me know what you guys think. this is coded for python3. > >> > def choices(list_result): > >> > '''takes a list of objects and returns the index of the selected > >> > object''' > >> > os.system('clear') > >> > index = 0 > >> > for entry in list_result: > >> > print('{}. {}'.format(index, entry.title)) > >> > index += 1 > >> > try: > >> > choice = int(input('\nEnter choice: ')) > >> > return choice > >> > except: > >> > pause = input('\nplease enter a valid choice') > >> > choices(list_result) > > >> When the exception is triggered you call choices() recursively but > >> discard the result. Therefore you get Python's default, None, which is > >> not a valid index. Change the last line to > > >> return choices(list_result) > > >> for a minimal fix. However, I suggest that you use a while loop instead > >> of the recursion: > > >> def choices(list_result): > >> while True: > >> os.system('clear') > >> for index, entry in enumerate(list_result): > >> print('{}. {}'.format(index, entry.title)) > >> try: > >> choice = int(input('\nEnter choice: ')) > >> if 0 <= choice < len(list_result): > >> return choice > >> except ValueError: > >> pass > >> input('\nplease enter a valid choice') > > >> I've also added a test for the integer range and replaced the bare except > >> with a more specific one. I recommend that you never use bare excepts > >> because they can hide unexpected exceptions and lead to nasty bugs. > > >> You should also remove the recursive call of main(). Its only effect is > >> that when you enter an invalid choice twice you will have to enter "5" > >> twice to really exit your script. > > >> Peter > > > hi peter, i noticed the issue you mentioned but don't understand why > > they happen. > > > for example, when the function is called in the case of an exception, > > the variable choice is re-assigned to whatever the next input is, so > > why is the default None assigned instead? ?and what' s the difference > > between just calling the function again (the variable list_result > > remains unchanged) and using a return statement? > > If you have a function > > def f(): > ? ? return 42 > > and just call it from another function > > def g(): > ? ? f() > > the result of f() is evaluated but immediately discarded. If you want to use > it inside g() you have to assign it to a variable > > def g(): > ? ? x = f() > ? ? y = x * x > ? ? print y > > and if you want to use it outside g() you can return it. > > def g(): > ? ?return f() > > For recursion the same rules apply, only with the same function as f and g. > Here's a simple example for you to work out the program flow: > > >>> def r1(n): > > ... ? ? print "entering level", n > ... ? ? if n == 5: > ... ? ? ? ? ? ? print "limit reached" > ... ? ? ? ? ? ? print "exiting level", n > ... ? ? ? ? ? ? print "returning 42" > ... ? ? ? ? ? ? return 42 > ... ? ? else: > ... ? ? ? ? ? ? print "recursing" > ... ? ? ? ? ? ? r1(n+1) > ... ? ? print "exiting level", n > ... ? ? print "(implicitly) returning None" > ...>>> r1(0) > > entering level 0 > recursing > entering level 1 > recursing > entering level 2 > recursing > entering level 3 > recursing > entering level 4 > recursing > entering level 5 > limit reached > exiting level 5 > returning 42 > exiting level 4 > (implicitly) returning None > exiting level 3 > (implicitly) returning None > exiting level 2 > (implicitly) returning None > exiting level 1 > (implicitly) returning None > exiting level 0 > (implicitly) returning None > > Try to change r1() to return the value from the innermost call (i. e. 42) to > the outside world. Once you have understood what is going on you should be > able to see what's wrong with your program. > > Peter ok i think i understand, the variable from the second function call is returned but not assigned to any variable. since the function was called by another function and not the main function, it returns the variable to the first function instead of the main function. From brian.curtin at gmail.com Tue Jul 27 10:54:08 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:54:08 -0500 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: <1280241186.27454.1386974299@webmail.messagingengine.com> References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:33, wrote: > What is the best practice way to open files in Python 2.6+ > > It looks like there are at least 3 different ways to open files: > - built-in open() > - io.open() > - codecs.open() > > It seems like io.open() combines the best of the built-in open() and the > codecs open(). Am I missing any obvious drawbacks to using io.open() except > for backwards compatibility? > > Thank you, > Malcolm > As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also 3.0, don't know). I don't know your use cases or what you get or don't get from any of those options, but the future is io.open. >>> io.open is open True -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Tue Jul 27 10:57:42 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 27 Jul 2010 16:57:42 +0200 Subject: Best practice way to open files in Python 2.6+? References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: <20100727165742.264f4b7d@pitrou.net> On Tue, 27 Jul 2010 10:33:06 -0400 python at bdurham.com wrote: > What is the best practice way to open files in Python 2.6+ > > It looks like there are at least 3 different ways to open files: > - built-in open() > - io.open() > - codecs.open() > It seems like io.open() combines the best of the built-in open() > and the codecs open(). Am I missing any obvious drawbacks to > using io.open() except for backwards compatibility? io.open() is quite slow in 2.6, although the performance issues are fixed in 2.7 (and in 3.1). io.open() is much stricter in what types it accepts and emits. Files opened in text mode, for example, will return unicode strings when reading and will only accept unicode strings for write(). (similarly, files opened in binary mode will only accept bytestrings for write()) Regards Antoine. From brian.curtin at gmail.com Tue Jul 27 10:58:13 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:58:13 -0500 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: <1280241396.28353.1386974575@webmail.messagingengine.com> References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:36, wrote: > Windows: How can I detect whether a Python app/script is running in > console/GUI mode? By app I mean a script compiled to an exe via py2exe or > similar. > > Thank you, > Malcolm > I don't remember much about py2exe, but you could check if ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) or just python.exe (regular console). -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Jul 27 10:59:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:59:42 -0400 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: <1280242782.1710.1386978505@webmail.messagingengine.com> Brian, > As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also 3.0, don't know). I don't know your use cases or > what you get or don't get from any of those options, but the future is io.open. > > >>> io.open is open > True Under Python 2.6.4 (Windows), "io.open is open" returns False. Retrieving help() on io.open and open() reinforces that these are 2 different implementations of open. My use case is reading and writing UTF-8 text files with universal newline support. I believe that the following io.open() parameter list is what I should be using: # mode set to 'rt' (read) or 'wt' (write) io.open( file, mode, encoding='utf-8', errors='ignore', newline=None ) Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Tue Jul 27 11:09:28 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 10:09:28 -0500 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: <1280242782.1710.1386978505@webmail.messagingengine.com> References: <1280241186.27454.1386974299@webmail.messagingengine.com> <1280242782.1710.1386978505@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:59, wrote: > Brian, > > Under Python 2.6.4 (Windows), "io.open is open" returns False. Retrieving > help() on io.open and open() reinforces that these are 2 different > implementations of open. > > My use case is reading and writing UTF-8 text files with universal newline > support. I believe that the following io.open() parameter list is what I > should be using: > > # mode set to 'rt' (read) or 'wt' (write) > io.open( file, mode, encoding='utf-8', errors='ignore', newline=None ) > > Malcolm > Precisely. I was just showing that in 3.x they are the same because one uses the other, and that reason might be enough for you to consider io.open. Your usage of io.open looks fine to me. If it works for you, keep doing it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Tue Jul 27 11:18:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jul 2010 17:18:44 +0200 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: > Starting with Python 2.7 and 3.2 you can do this: > >>>> sysconfig.get_config_var("Py_DEBUG") > 1 > > (returns None if the var doesn't exist) IIRC sysconfig.get_config_var() still depends on parsing the pyconfig.h file. This won't work on Windows because we are using project and config settings of VisualStudio. From harijay at gmail.com Tue Jul 27 11:22:15 2010 From: harijay at gmail.com (harijay) Date: Tue, 27 Jul 2010 08:22:15 -0700 (PDT) Subject: multicpu bzip2 using os.system or queue using python script Message-ID: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> I want to quickly bzip2 compress several hundred gigabytes of data using my 8 core , 16 GB ram workstation. Currently I am using a simple python script to compress a whole directory tree using bzip2 and a system call coupled to an os.walk call. I see that the bzip2 only uses a single cpu while the other cpus remain relatively idle. I am a newbie in queue and threaded processes . But I am wondering how I can implement this such that I can have four bzip2 running threads (actually I guess os.system threads ), each using probably their own cpu , that deplete files from a queue as they bzip them. Thanks for your suggestions in advance hari My single thread script is pasted here . import os import sys for roots, dirlist , filelist in os.walk(os.curdir): for file in [os.path.join(roots,filegot) for filegot in filelist]: if "bz2" not in file: print "Compressing %s" % (file) os.system("bzip2 %s" % file) print ":DONE" From mail at timgolden.me.uk Tue Jul 27 11:36:20 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 27 Jul 2010 16:36:20 +0100 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: <4C4EFCF4.9000302@timgolden.me.uk> On 27/07/2010 15:58, Brian Curtin wrote: > On Tue, Jul 27, 2010 at 09:36, wrote: > >> Windows: How can I detect whether a Python app/script is running in >> console/GUI mode? By app I mean a script compiled to an exe via py2exe or >> similar. >> >> Thank you, >> Malcolm >> > > I don't remember much about py2exe, but you could check if > ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) > or just python.exe (regular console). Don't know whether it's foolproof, but I suspect that checking whether win32console.GetConsoleWindow () returns zero is probably not a bad approach. TJG From emile at fenx.com Tue Jul 27 11:42:00 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 27 Jul 2010 08:42:00 -0700 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: <1280241396.28353.1386974575@webmail.messagingengine.com> References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: On 7/27/2010 7:36 AM python at bdurham.com said... > Windows: How can I detect whether a Python app/script is running > in console/GUI mode? By app I mean a script compiled to an exe > via py2exe or similar. > Once you've got an exe, you'll need to know the name you're looking for. There are several utilities available -- I use pslist from sysinternals, but there are others out there like process explorer, WMIC or tasklist. You could translate the VB found at http://support.microsoft.com/kb/187913 and use win32. You could program a pid file into your exe and check that. One cheap trick is to create a file and keep it open while your process runs. From the outside, if the file is missing or you can erase the file, you're process isn't active. This relies on windows requiring exclusive access to delete a file which it does, and doesn't rely on the presence of a particular windows version or installation of a third party utility. HTH, Emile From john at castleamber.com Tue Jul 27 11:47:31 2010 From: john at castleamber.com (John Bokma) Date: Tue, 27 Jul 2010 10:47:31 -0500 Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: <877hkh9bak.fsf@castleamber.com> mo reina writes: > i mainly did it because i'm always scanning through my pdf files, > books, or the net for some coding example of solution that i'd already > seen before, and it just seemed logical to have something where you > could just put the content in, give it a title and tags, and just look > it up whenever you needed to. Ages ago I wrote something like this in Perl, but now I use a local install of MediaWiki to keep notes, interesting links, code snippets, etc. One of the advantages is that I can reach it from each computer connected to my LAN, even virtual ones. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From nitinpawar432 at gmail.com Tue Jul 27 11:56:41 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 21:26:41 +0530 Subject: Urrlib2 IncompleteRead error In-Reply-To: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: Hi, Check if the webpage you are trying to access is redirecting the page to some other page? or the timeout is too less for the request to finish Thanks, Nitin On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: > I am running urllib2.request and get this response when I do the read. > Any ideas what causes this? > > return response.read() > File "C:\Python26\lib\socket.py", line 329, in read > data = self._sock.recv(rbufsize) > File "C:\Python26\lib\httplib.py", line 518, in read > return self._read_chunked(amt) > File "C:\Python26\lib\httplib.py", line 561, in _read_chunked > raise IncompleteRead(''.join(value)) > IncompleteRead: IncompleteRead(3235 bytes read) > > Dirk > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From TCalhoon at ochca.com Tue Jul 27 12:35:32 2010 From: TCalhoon at ochca.com (Calhoon, Tom) Date: Tue, 27 Jul 2010 09:35:32 -0700 Subject: Orange County, California Python User Group Message-ID: Dan: I am an instructor at Cal State Fullerton, and we are looking for a few industry leaders that would be willing to server on an advisory board for a Python programming class series. If you have a minute to talk or know of someone who is interested, please give me a call. Thanks Tom Calhoon (714) 834-6632 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dirknbr at gmail.com Tue Jul 27 12:39:50 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Tue, 27 Jul 2010 17:39:50 +0100 Subject: Urrlib2 IncompleteRead error In-Reply-To: References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: Thanks, I don't think it's redirecting, how can I increase the timeout? On 27 July 2010 16:56, Nitin Pawar wrote: > Hi, > > Check if the webpage you are trying to access is redirecting the page to > some other page? > or the timeout is too less for the request to finish > > > Thanks, > Nitin > > On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: > >> I am running urllib2.request and get this response when I do the read. >> Any ideas what causes this? >> >> return response.read() >> File "C:\Python26\lib\socket.py", line 329, in read >> data = self._sock.recv(rbufsize) >> File "C:\Python26\lib\httplib.py", line 518, in read >> return self._read_chunked(amt) >> File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >> raise IncompleteRead(''.join(value)) >> IncompleteRead: IncompleteRead(3235 bytes read) >> >> Dirk >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Nitin Pawar > > -- http://twitter.com/dirknbr http://maximum-likely.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Jul 27 12:46:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 27 Jul 2010 09:46:11 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4e8a95$0$24098$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> Message-ID: <4C4F0D53.5010107@stoneleaf.us> Bruno Desthuilliers wrote: > Bruno Desthuilliers a ?crit : >> Ethan Furman a ?crit : >>> Bruno Desthuilliers wrote: >>>> Duncan Booth a ?crit : >> (snip) >> >>>>> Or you could create the default as a class attribute >>>> >>>> from the OP: >>>> """ >>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>> it is overloaded in __getattr__, so if someone invokes >>>> "myObject.size", it is generated (as another oofun) and connected to >>>> myObject as attribute. >>>> """ >>>> >>>> so this solution won't obviously work in this case !-) >>>> >>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>> class attribute is of a mutable type. >>> >>> Well, it is Monday, so I may be missing something obvious, but what >>> is the effective difference between these two solutions? >> > > If you meant "what is the difference between creating the "whatever" > attribute with a default value in the initializer and creating it on > demand in the __getattr__ hook", the main difference is that in the > first case, the instance is garanteed to have this attribute, so you get > rid of "hasattr" checks (and the unwanted side effects) or, worse, > direct check of the instance __dict__. Except for a couple of corner > case, client code shouldn't have to worry about this kind of things - > this breaks encapsulation. Yay Tuesday! :D What I meant was what is the difference between: [Bruno Desthuilliers] > DEFAULT_WHATEVER = Whathever() > class MyClass(object): > def __init__(self, x, y): > self.size = DEFAULT_WHATEVER and [Duncan Booth] > class MyClass(object): > size = Whatever() > def __init__(self, x, y): > ... in both cases the object ends up with a size attribute and no further need of __getattr__. Of course, the warning about having a mutable object as a class attribute stands. To phrase it another way, why does your solution (Bruno) work, but Duncan's "obviously won't"? ~Ethan~ From nitinpawar432 at gmail.com Tue Jul 27 12:46:41 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 22:16:41 +0530 Subject: Urrlib2 IncompleteRead error In-Reply-To: References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: import socket # timeout in seconds timeout = 10 socket.setdefaulttimeout(timeout) On Tue, Jul 27, 2010 at 10:09 PM, Dirk Nachbar wrote: > Thanks, I don't think it's redirecting, how can I increase the timeout? > > > On 27 July 2010 16:56, Nitin Pawar wrote: > >> Hi, >> >> Check if the webpage you are trying to access is redirecting the page to >> some other page? >> or the timeout is too less for the request to finish >> >> >> Thanks, >> Nitin >> >> On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: >> >>> I am running urllib2.request and get this response when I do the read. >>> Any ideas what causes this? >>> >>> return response.read() >>> File "C:\Python26\lib\socket.py", line 329, in read >>> data = self._sock.recv(rbufsize) >>> File "C:\Python26\lib\httplib.py", line 518, in read >>> return self._read_chunked(amt) >>> File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >>> raise IncompleteRead(''.join(value)) >>> IncompleteRead: IncompleteRead(3235 bytes read) >>> >>> Dirk >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> Nitin Pawar >> >> > > > -- > http://twitter.com/dirknbr > http://maximum-likely.blogspot.com > > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Jul 27 12:58:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jul 2010 18:58:14 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <67f0a4af61f6f83afccff2af8bfc0b94@localhost> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: >>> Hi folks, >>> >>> If I'm only interested in linux and windows I know I can do >>> >>> ################################ >>> import os >>> import platform >>> >>> if platform.system( ) == 'Linux': >>> clear = 'clear' >>> else: >>> clear = 'cls' >>> >>> os.system( clear ) >>> ################################ >>> >>> or something equivalent using os.name and friends, but was wondering >>> why there is no platform independent way (i.e. the platform dependence >>> is taken care of by the python stdlib) of clearing a terminal. Sure, >>> there are many different terminals and many different operating >>> systems but in many areas python managed to hide all these >>> complexities behind a well defined API. >>> >>> Why was clearing a terminal left out? >>> >> >> What you're talking about is a shell, not a terminal (a terminal is a >> physical device). And the shell is not necessarily part of the OS itself > >> (there's no shortage of shells for unices / linux systems), so it >> doesn't belong to the os or platform modules. >> >> FWIW, I can't tell for sure since I never used any other shell than >> bash, but I'm not sure your above code is garanteed to work on each and >> any possible unix shell. > > Sorry, but that is completely wrong - the shell is irrelevant. > > "clear" is just a normal command line program that queries the > termcap/terminfo database (possibly via the curses library) for the > terminal specific sequence of characters that will clear the screen. It > then writes those characters to stdout. The terminal, or (more usually > these days) terminal emulator, then interprets those characters and takes > the appropriate action. > > I'm not sure what the POSIX status of the clear command is, but I'd be > surprised if it wasn't present on a UNIX/Linux system of any vintage. After getting the technicalities out of the way, maybe I should have asked: Is it only me or others would find a platform independent python API to clear the terminal useful? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From nagle at animats.com Tue Jul 27 13:02:47 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 10:02:47 -0700 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <4c4ef0b2$0$5752$426a34cc@news.free.fr> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <4c4ef0b2$0$5752$426a34cc@news.free.fr> Message-ID: <4c4f1135$0$1672$742ec2ed@news.sonic.net> On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote: > Grant Edwards a ?crit : >> On 2010-07-27, Bruno Desthuilliers >> wrote: >>> Daniel Fetchinson a ?crit : > (snip) >>>> Why was clearing a terminal left out? >>>> >>> What you're talking about is a shell, not a terminal (a terminal is a >>> physical device). >> >> No, what he's talking about is clearing a terminal (or a terminal >> emulator). They both work the same, the only difference is whether >> the terminal software is running on dedicated hardware or on >> general-purpose hardware. > > (snip) > > I stand corrected. I immediately thought of using the "curses" module, but that's UNIX-only, or at least it's not in the ActiveState Python distro. John Nagle From invalid at invalid.invalid Tue Jul 27 13:13:33 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 27 Jul 2010 17:13:33 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: On 2010-07-27, Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? I write a lot of command-line programs, and I can't remember the last time time I wanted to clear a terminal. But then again, pretty much all of my programs are designed so that they can be used as filters. About 10 years ago I did need to do a text-mode UI (menus, popups, text-entry, etc.), and I used newt. -- Grant Edwards grant.b.edwards Yow! Is a tattoo real, like at a curb or a battleship? gmail.com Or are we suffering in Safeway? From python at mrabarnett.plus.com Tue Jul 27 13:26:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 18:26:54 +0100 Subject: multicpu bzip2 using os.system or queue using python script In-Reply-To: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> References: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> Message-ID: <4C4F16DE.9020700@mrabarnett.plus.com> harijay wrote: > I want to quickly bzip2 compress several hundred gigabytes of data > using my 8 core , 16 GB ram workstation. > Currently I am using a simple python script to compress a whole > directory tree using bzip2 and a system call coupled to an os.walk > call. > > I see that the bzip2 only uses a single cpu while the other cpus > remain relatively idle. > > I am a newbie in queue and threaded processes . But I am wondering how > I can implement this such that I can have four bzip2 running threads > (actually I guess os.system threads ), each using probably their own > cpu , that deplete files from a queue as they bzip them. > > > Thanks for your suggestions in advance > [snip] Try this: import os import sys from threading import Thread, Lock from Queue import Queue def report(message): mutex.acquire() print message sys.stdout.flush() mutex.release() class Compressor(Thread): def __init__(self, in_queue, out_queue): Thread.__init__(self) self.in_queue = in_queue self.out_queue = out_queue def run(self): while True: path = self.in_queue.get() sys.stdout.flush() if path is None: break report("Compressing %s" % path) os.system("bzip2 %s" % path) report("Done %s" % path) self.out_queue.put(path) in_queue = Queue() out_queue = Queue() mutex = Lock() THREAD_COUNT = 4 worker_list = [] for i in range(THREAD_COUNT): worker = Compressor(in_queue, out_queue) worker.start() worker_list.append(worker) for roots, dirlist, filelist in os.walk(os.curdir): for file in [os.path.join(roots, filegot) for filegot in filelist]: if "bz2" not in file: in_queue.put(file) for i in range(THREAD_COUNT): in_queue.put(None) for worker in worker_list: worker.join() From nagle at animats.com Tue Jul 27 13:28:19 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 10:28:19 -0700 Subject: python terminology on classes In-Reply-To: <4c4e8801$0$14554$426a74cc@news.free.fr> References: <4c4e8801$0$14554$426a74cc@news.free.fr> Message-ID: <4c4f1731$0$1602$742ec2ed@news.sonic.net> On 7/27/2010 12:17 AM, Bruno Desthuilliers wrote: >> destructor > > Python has no real destructor. You can implement a __del__ method that > will _eventually_ be called before the instance gets garbage-collected, > but you'd rather not rely on it. Also, implementing this method will > prevent cycle detection. That's not correct. The Python language reference is at "http://docs.python.org/reference/datamodel.html". In CPython, either __del__ will be called when the reference count goes to zero, or it won't be called at all. The garbage collector that backs up the reference counting system doesn't delete objects with __del__ methods, because of the usual problems with deletion from a garbage collector. The defined semantics are that loop-free structures are deleted properly, but loops with one object that has a __del__ hang around forever. You can use weak pointers to avoid loops. IronPython and ShedSkin are garbage-collected implementations which have quite different __del__ semantics. That's considered non-standard. In C++, the RAII approach is popular and recommended. In C++, it's routine to create local objects which, when they go out of scope, close a file, unlock a lock, or close a window. It's also widely used in Python, but it's now somewhat deprecated. Python 2.6 has a recently added "with" clause, borrowed from LISP, for associating actions with scopes. This is supported for files and locks, but setting your own object up for "with" requires adding special methods to the object. "with" is less convenient and more limited than RAII, but that's the direction Python is going. This may be in preparation for a move to a real garbage collector. John Nagle From 4g4trz802 at sneakemail.com Tue Jul 27 13:28:38 2010 From: 4g4trz802 at sneakemail.com (Michael Hoffman) Date: Tue, 27 Jul 2010 10:28:38 -0700 Subject: Updating path.py References: Message-ID: Robert Kern wrote: > On 7/26/10 5:16 PM, Michael Hoffman wrote: >> I have been using Jason Orendorff's path.py module for a long time. It >> is very >> useful. The only problem is that Python 2.6 deprecates the md5 module it >> imports, so I (and others using my software) now get this warning >> whenever they >> start, which is a little annoying. >> >> /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: >> >> DeprecationWarning: the md5 module is deprecated; use hashlib instead >> >> The original web page is gone, and e-mails to the author have gone >> unanswered. >> It has a "public domain" license so I could easily fork it and make >> this small >> change. The question is what is the best way to do that and ensure >> continuity >> with the previous versions. Can I (or someone else) take over the PyPI >> entry in >> question? Other suggestions? > > You cannot "take over" a project on PyPI. You can only fork the project > with a new name. In fact, this has already been done: > > http://pypi.python.org/pypi/forked-path/0.1 Great, I'll start by trying that, I was hoping someone already had a solution. Thanks. From a.j.romanista at gmail.com Tue Jul 27 13:36:24 2010 From: a.j.romanista at gmail.com (ata.jaf) Date: Tue, 27 Jul 2010 10:36:24 -0700 (PDT) Subject: suitable py2app. Message-ID: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> Hi, I'm looking for a suitable tutorial for "py2app". I googled it but couldn't find anything. Can you help me please? Thanks Ata From nitinpawar432 at gmail.com Tue Jul 27 13:56:00 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 23:26:00 +0530 Subject: suitable py2app. In-Reply-To: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> References: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> Message-ID: see if this helps http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html On Tue, Jul 27, 2010 at 11:06 PM, ata.jaf wrote: > Hi, > I'm looking for a suitable tutorial for "py2app". I googled it but > couldn't find anything. > Can you help me please? > Thanks > Ata > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Jul 27 14:01:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Jul 2010 14:01:00 -0400 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: On 7/27/2010 12:58 PM, Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? One problem is, Where would you put it? The OS module is for system calls, mostly based on posix. The system call involved in clearing a terminal is a write string call. *nix puts terminal control in a separate library. Another is, what next? clear_line? Pretty soon, we are back to curses. Still another problem is that most of us do not have terminals; we have screens and use them as such. OS-independent full-screen graphics/game libraries have clear screen commands. Similary, GUI systems have means of clearing text and canvas widgets, but should not be able to clear the whole screen. The turtle module has a clear command for its canvas, which would be the same regardless of underlying gui. So we already have several OS independent clear commands. On Windows, the DOS clr command only works withing a text-mode command window (once called a dos window). The same thing (os.system('clr') within an IDLE shell uselessly flashes a blank command window, which then disappears. Yeah, it is too bad windows did not use the obvious 'clear' like everyone? else. If command windows still imitate or can be set to imitate ansi terminals, then I would think curses is your best bet. -- Terry Jan Reedy From martin at address-in-sig.invalid Tue Jul 27 14:02:37 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 27 Jul 2010 18:02:37 +0000 (UTC) Subject: pyodbc problem Message-ID: I have a small problem: I can't get pyodbc to connect to a PostgreSQL database. All it does is spit out a malformed error message. When I run this: ============================================== import pyodbc dsn = pyodbc.dataSources() print "Data sources: %s" % dsn conn = pyodbc.connect(dsn="marchive") print "ODBC connection: %s" % conn ============================================== I get this: ============================================== [kiwi at zappa python]$ python dsncheck.py Data sources: {'ma': 'PostgreSQL', 'marchive': 'PostgreSQL'} Traceback (most recent call last): File "dsncheck.py", line 6, in conn = pyodbc.connect(dsn="marchive") pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)') ============================================== so the data source exists and is evidently found by connect(), whiuch seems unable to make sense of it. The pgsql module works well, but I would prefer to use ODBC because its not so closely bound to a single RDBMS. unixODBC, which I understand underlies pyodbc, works OK too: ============================================== [kiwi at zappa python]$ isql marchive marchive n/a +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> select count(*) from address; +---------------------+ | count | +---------------------+ | 32 | +---------------------+ SQLRowCount returns 1 1 rows fetched SQL> quit ============================================== Questions: - Why does pyodbc blow up when its apparently trying to talk to unixODBC? - What does this mean: pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)') I'm new to Python, though not to Linux, PostgreSQL, ODBC, C or Java. My rig and software: Linux: Fedora 12 Where I'm running Python and ODBC, Lenovo Thinkpad R61i: Core Duo. Fedora 10 Where PostgreSQL is installed, IBM NetVista: Pentium III. PostgreSQL: 8.3.8 Python: 2.6.2 pyodbc 2.1.5-3.fc12 ) By yum from RH repository unixODBC 2.2.14-11.fc12 ) -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From harijay at gmail.com Tue Jul 27 14:10:34 2010 From: harijay at gmail.com (harijay) Date: Tue, 27 Jul 2010 11:10:34 -0700 (PDT) Subject: multicpu bzip2 using os.system or queue using python script References: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> Message-ID: <11ca89e7-5210-4676-b042-e645d5824092@t1g2000vbd.googlegroups.com> Thanks a tonne..That code works perfectly and also shows me how to think of using queue and threads in my python programs Hari On Jul 27, 1:26?pm, MRAB wrote: > harijay wrote: > > I want to quickly bzip2 compress several hundred gigabytes of data > > using my 8 core , 16 GB ram workstation. > > Currently I am using a simple python script to compress a whole > > directory tree using bzip2 and a system call coupled to an os.walk > > call. > > > I see that the bzip2 only uses a single cpu while the other cpus > > remain relatively idle. > > > I am a newbie in queue and threaded processes . But I am wondering how > > I can implement this such that I can have four bzip2 running threads > > (actually I guess os.system threads ), each using probably their own > > cpu , that deplete files from a queue as they bzip them. > > > Thanks for your suggestions in advance > > [snip] > Try this: > > import os > import sys > from threading import Thread, Lock > from Queue import Queue > > def report(message): > ? ? ?mutex.acquire() > ? ? ?print message > ? ? ?sys.stdout.flush() > ? ? ?mutex.release() > > class Compressor(Thread): > ? ? ?def __init__(self, in_queue, out_queue): > ? ? ? ? ?Thread.__init__(self) > ? ? ? ? ?self.in_queue = in_queue > ? ? ? ? ?self.out_queue = out_queue > ? ? ?def run(self): > ? ? ? ? ?while True: > ? ? ? ? ? ? ?path = self.in_queue.get() > ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ?if path is None: > ? ? ? ? ? ? ? ? ?break > ? ? ? ? ? ? ?report("Compressing %s" % path) > ? ? ? ? ? ? ?os.system("bzip2 %s" % path) > ? ? ? ? ? ? ?report("Done %s" % ?path) > ? ? ? ? ? ? ?self.out_queue.put(path) > > in_queue = Queue() > out_queue = Queue() > mutex = Lock() > > THREAD_COUNT = 4 > > worker_list = [] > for i in range(THREAD_COUNT): > ? ? ?worker = Compressor(in_queue, out_queue) > ? ? ?worker.start() > ? ? ?worker_list.append(worker) > > for roots, dirlist, filelist in os.walk(os.curdir): > ? ? ?for file in [os.path.join(roots, filegot) for filegot in filelist]: > ? ? ? ? ?if "bz2" not in file: > ? ? ? ? ? ? ?in_queue.put(file) > > for i in range(THREAD_COUNT): > ? ? ?in_queue.put(None) > > for worker in worker_list: > ? ? ?worker.join() From kevinar18 at hotmail.com Tue Jul 27 14:24:07 2010 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Tue, 27 Jul 2010 14:24:07 -0400 Subject: Which multiprocessing methods use shared memory? Message-ID: The multiprocessing module has 4 methods for sharing data between processes: Queues Pipes Shared Memory Map Server Process Which of these use shared memory? I understand that the 3rd (Shared Memory Map) does, but what about Queues? Thanks, Kevin _________________________________________________________________ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 From nagle at animats.com Tue Jul 27 14:40:16 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 11:40:16 -0700 Subject: Why are String Formatted Queries Considered So Magical? (Spammer analysis) In-Reply-To: <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Message-ID: <4c4f280e$0$1612$742ec2ed@news.sonic.net> On 7/26/2010 4:19 PM, Justin Smith wrote: > Seeking industry expert candidates > > I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I > am currently seeking candidates to fill Tech Positions for multiple A- > List Clients: Spammer detected. Injection-Info: r27g2000yqb.googlegroups.com; posting-host=63.170.35.94; posting-account=XlBkJgkAAAC7JNUw8ZEYCvz12vv6mGCK Reverse DNS: "franchisevpn.expresspersonnel.com" Site analysis: Domain "www.expresspersonnel.com" redirected to different domain "www.expresspros.com" Site analysis: From Secure certificate (Secure certificate, high confidence) Express Personnel Services, Inc. Oklahoma City, OK UNITED STATES Oklahoma corporation search: EXPRESS SERVICES, INC. Filing Number: 2400436307 Name Type: Legal Name Status: In Existence Corp type: Foreign For Profit Business Corporation Jurisdiction: COLORADO Formation Date: 28 Aug 1985 Colorado corporation search: ID: 19871524232 Name: EXPRESS SERVICES, INC. Principal Street Address: 8516 NW Expressway, Oklahoma City, OK 73162, United States Target coordinates: 35.56973,-97.668001 Corporate class: Franchiser From kevinar18 at hotmail.com Tue Jul 27 15:12:02 2010 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Tue, 27 Jul 2010 15:12:02 -0400 Subject: Which multiprocessing methods use shared memory? Message-ID: I'm not sure my previous message went through (I wasn't subscribe), so I'm gonna try again. The multiprocessing module has 4 methods for sharing data between processes: Queues Pipes Shared Memory Map Server Process Which of these use shared memory? I understand that the 3rd (Shared Memory Map) does, but what about Queues? Thanks, Kevin _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 From python at mrabarnett.plus.com Tue Jul 27 15:30:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 20:30:12 +0100 Subject: Which multiprocessing methods use shared memory? In-Reply-To: References: Message-ID: <4C4F33C4.8000007@mrabarnett.plus.com> Kevin Ar18 wrote: > I'm not sure my previous message went through (I wasn't subscribe), so I'm gonna try again. > > The multiprocessing module has 4 methods for sharing data between processes: > Queues > Pipes > Shared Memory Map > Server Process > > Which of these use shared memory? > > I understand that the 3rd (Shared Memory Map) does, but what about Queues? > The documentation says: """class multiprocessing.Queue([maxsize]) Returns a process shared queue implemented using a pipe and a few locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe.""" From jyoung79 at kc.rr.com Tue Jul 27 16:45:32 2010 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Tue, 27 Jul 2010 20:45:32 +0000 Subject: tkinter unicode question Message-ID: <20100727204532.R7GMZ.27213.root@cdptpa-web20-z02> Just curious if anyone could shed some light on this? I'm using tkinter, but I can't seem to get certain unicode characters to show in the label for Python 3. In my test, the label and button will contain the same 3 characters - a Greek Alpha, a Greek Omega with a circumflex and soft breathing accent, and then a Greek Alpha with a soft breathing accent. For Python 2.6, this works great: # -*- coding: utf-8 -*- from Tkinter import * root = Tk() Label(root, text=u'\u03B1 \u1F66 \u1F00').pack() Button(root, text=u'\u03B1 \u1F66 \u1F00').pack() root.mainloop() However, for Python 3.1.2, the button gets the correct characters, but the label only displays the first Greek Alpha character. The other 2 characters look like Chinese characters followed by an empty box. Here's the code for Python 3: # -*- coding: utf-8 -*- from tkinter import * root = Tk() Label(root, text='\u03B1 \u1F66 \u1F00').pack() Button(root, text='\u03B1 \u1F66 \u1F00').pack() root.mainloop() I've done some research and am wondering if it is because Python 2.6 comes with tk version 8.5, while Python 3.1.2 comes with tk version 8.4? I'm running this on OS X 10.6.4. Here's a link I found that mentions this same problem: http://www.mofeel.net/871-comp-lang-python/5879.aspx If I need to upgrade tk to 8.5, is it best to upgrade it or just install 'tiles'? From my readings it looks like upgrading to 8.5 can be a pain due to OS X still pointing back to 8.4. I haven't tried it yet in case someone might have an easier solution. Thanks for looking at my question. Jay From john at castleamber.com Tue Jul 27 16:52:05 2010 From: john at castleamber.com (John Bokma) Date: Tue, 27 Jul 2010 15:52:05 -0500 Subject: Why are String Formatted Queries Considered So Magical? (Spammer analysis) References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> <4c4f280e$0$1612$742ec2ed@news.sonic.net> Message-ID: <87iq40bqbu.fsf@castleamber.com> John Nagle writes: > On 7/26/2010 4:19 PM, Justin Smith wrote: >> Seeking industry expert candidates >> >> I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I >> am currently seeking candidates to fill Tech Positions for multiple A- >> List Clients: > > Spammer detected. But did you report it? (If so, it helps if you state so). > Injection-Info: r27g2000yqb.googlegroups.com; > posting-host=63.170.35.94; http://www.spamcop.net/sc?track=63.170.35.94 -> looks like abuse goes to the spammer... A whois gives sprint.net, so you could contact abuse at sprint.net (see: http://whois.domaintools.com/63.170.35.94 ) [snip address etc.] Spammers don't care about that. Best course of action, based on my experience, is to contact abuse at googlegroups.com (now and then it actually works), and sprint.net. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mrjean1 at gmail.com Tue Jul 27 17:01:39 2010 From: mrjean1 at gmail.com (MrJean1) Date: Tue, 27 Jul 2010 14:01:39 -0700 (PDT) Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: <4786847f-6834-4fb8-8aff-10656c442994@y32g2000prc.googlegroups.com> On Jul 27, 8:36?am, Tim Golden wrote: > On 27/07/2010 15:58, Brian Curtin wrote: > > > On Tue, Jul 27, 2010 at 09:36, ?wrote: > > >> Windows: How can I detect whether a Python app/script is running in > >> console/GUI mode? By app I mean a script compiled to an exe via py2exe or > >> similar. > > >> Thank you, > >> Malcolm > > > I don't remember much about py2exe, but you could check if > > ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) > > or just python.exe (regular console). > > Don't know whether it's foolproof, but I suspect that > checking whether win32console.GetConsoleWindow () > returns zero is probably not a bad approach. > > TJG ? ? Executables built with py2exe have an attribute sys.frozen and its value is 'console_exe' for console applications or 'windows_exe' for GUI applications. See for example . /Jean From usernet at ilthio.net Tue Jul 27 17:12:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 27 Jul 2010 21:12:50 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <4c4ef0b2$0$5752$426a34cc@news.free.fr> <4c4f1135$0$1672$742ec2ed@news.sonic.net> Message-ID: On 2010-07-27, John Nagle wrote: > On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote: >> Grant Edwards a ?crit : >>> On 2010-07-27, Bruno Desthuilliers >>> wrote: >>>> Daniel Fetchinson a ?crit : >> (snip) >>>>> Why was clearing a terminal left out? >>>>> >>>> What you're talking about is a shell, not a terminal (a terminal is a >>>> physical device). >>> >>> No, what he's talking about is clearing a terminal (or a terminal >>> emulator). They both work the same, the only difference is whether >>> the terminal software is running on dedicated hardware or on >>> general-purpose hardware. >> >> (snip) >> >> I stand corrected. > > I immediately thought of using the "curses" module, but that's > UNIX-only, or at least it's not in the ActiveState Python distro. pdcurses: http://pdcurses.sourceforge.net/ is a cross platform curses implementation that is available for Windows. I wonder how difficult it would be to embed into the Python curses module as a backup for systems where curses is not natively available. This would allow Python to provide cross platform charactor mode manipulation. From nad at acm.org Tue Jul 27 17:24:16 2010 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jul 2010 14:24:16 -0700 Subject: tkinter unicode question References: <20100727204532.R7GMZ.27213.root@cdptpa-web20-z02> Message-ID: In article <20100727204532.R7GMZ.27213.root at cdptpa-web20-z02>, wrote: > Just curious if anyone could shed some light on this? I'm using > tkinter, but I can't seem to get certain unicode characters to > show in the label for Python 3. > > In my test, the label and button will contain the same 3 > characters - a Greek Alpha, a Greek Omega with a circumflex and > soft breathing accent, and then a Greek Alpha with a soft > breathing accent. > > For Python 2.6, this works great: > > # -*- coding: utf-8 -*- > from Tkinter import * > root = Tk() > Label(root, text=u'\u03B1 \u1F66 \u1F00').pack() > Button(root, text=u'\u03B1 \u1F66 \u1F00').pack() > root.mainloop() > > However, for Python 3.1.2, the button gets the correct characters, > but the label only displays the first Greek Alpha character. > The other 2 characters look like Chinese characters followed by > an empty box. Here's the code for Python 3: > > # -*- coding: utf-8 -*- > from tkinter import * > root = Tk() > Label(root, text='\u03B1 \u1F66 \u1F00').pack() > Button(root, text='\u03B1 \u1F66 \u1F00').pack() > root.mainloop() > > I've done some research and am wondering if it is > because Python 2.6 comes with tk version 8.5, while Python 3.1.2 > comes with tk version 8.4? I'm running this on OS X 10.6.4. Most likely. Apparently you're using the Apple-supplied Python 2.6 which, as you say, uses Tk 8.5. If you had installed the python.org 2.6, it would likely fail for you in the same way as 3.1, since both use Tk 8.4. (They both fail for me.) > If I need to upgrade tk to 8.5, is it best to upgrade it or just > install 'tiles'? From my readings it looks like upgrading to > 8.5 can be a pain due to OS X still pointing back to 8.4. I > haven't tried it yet in case someone might have an easier > solution. OS X 10.6 comes with both Tk 8.4 and 8.5. The problem is that the Python Tkinter(2.6) or tkinter(3.1) is linked at build time, not install time, to one or the other. You would need to at least rebuild and relink tkinter for 3.1 to use Tk 8.5, which means downloading and building Python from source. New releases of python.org installers are now coming in two varieties: the second will be only for 10.6 or later and will link with Tk 8.5. The next new release of Python 3 is likely months away, though. In the meantime, a simpler solution might be to download and install the ActiveState Python 3.1 for OS X which does use Tk 8.5. And your test case works for me with it. -- Ned Deily, nad at acm.org From krdean at gmail.com Tue Jul 27 17:36:59 2010 From: krdean at gmail.com (kBob) Date: Tue, 27 Jul 2010 14:36:59 -0700 (PDT) Subject: urllib timeout Message-ID: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> I created a script to access weather satellite imagery fron NOAA's ADDS. It worked fine until recently with Python 2.6. The company changed the Internet LAN connections to "Accept Automatic settings" and "Use automatic configuration script" How do you get urllib.urlopen to use the the "automatic script" configuration? This code worked recently, until the company implemented these LAN connections... SAT_URL = "http://adds.aviationweather.gov/data/satellite/ latest_BWI_vis.jpg" satpic = urllib.urlopen(SAT_URL, proxies=0 ) satimg = satpic.read() Kelly Dean Fort Collins, CO From philip at semanchuk.com Tue Jul 27 17:44:32 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jul 2010 17:44:32 -0400 Subject: Binary compatibility across Python versions? In-Reply-To: References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: <0A4C9B21-6EFF-461A-B15C-415D1408DD88@semanchuk.com> On Jul 26, 2010, at 5:19 PM, Ned Deily wrote: > In article , > Christian Heimes wrote: >> [Philip Semanchuk wrote:] >>> Specifically, I'm concerned with binaries created by SWIG for a C++ >>> library that our project uses. We'd like to ship precompiled >>> binaries >>> for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping >>> that it >>> is sufficient to create binaries for each Python for each platform >>> (3 >>> * 2 == 6 total precompiled binaries). >> For each platforms you have to provide binaries for the major CPU >> architectures (X86 and X64_86), too. Users or distributions may >> compile >> Python with UCS-2 or UCS-4 unicode width. That makes eight different >> binaries for Linux (two version * two archs * UCS2/4). Although most >> distributions follow the LSB standards, binaries aren't necessary ABI >> compatible. C++ binaries tend to break more often than C binaries. > > And, on OS X, there are various Python binary distributions in common > use: the Apple-supplied Pythons (2.5 for OS X 10.5, 2.6 & 2.5 for > 10.6), > the python.org OS X installers for 10.5 and 10.6, plus the ActiveState > and EPD ones. It would likely be difficult to ship one binary > extension > that would easily work, if at all, with the most common ones. For > instance, the Apple-supplied Python 2.6 is built with gcc 4.2, uses > the > 10.6 ABI (SDK deployment target), and x86_64 / i386 / ppc > architectures > (default 64-bit on capable machines). The python.org 2.6 uses gcc > 4.0, > the 10.4u ABI, and is 32-bit only (i386 / ppc) Thanks to all who replied on this topic. A little more background -- these binaries are just a convenience for our users and we don't have to cover every possible permutation of Python, only the ones we think will be most common in our user base. That said, thanks to the things you pointed out, I'm beginning to think that our users might be such a varied group that precompiled binaries might not be worth the trouble. Ned, I'm on Mac and I was under the impression that the deployment target compiler option would control how the resulting binary (in this case, Python) called OS X but it wouldn't have any affect on how other code (like our library) called Python. Is that not the case? Thanks Philip From lie.1296 at gmail.com Tue Jul 27 18:13:14 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 28 Jul 2010 05:13:14 +0700 Subject: newb In-Reply-To: References: Message-ID: On Tue, 27 Jul 2010 11:07:09 GMT, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. Yes, Python Tutor list is specifically aimed for beginners. You can access it by subscribing to either tutor at python.org or gmane.comp.python.tutor > would still be valid? Mostly yes. However I'd recommend getting a more updated book especially if you're a beginner. From python at mrabarnett.plus.com Tue Jul 27 18:23:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 23:23:25 +0100 Subject: urllib timeout In-Reply-To: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <4C4F5C5D.3020007@mrabarnett.plus.com> kBob wrote: > > I created a script to access weather satellite imagery fron NOAA's > ADDS. > > It worked fine until recently with Python 2.6. > > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" > > How do you get urllib.urlopen to use the the "automatic script" > configuration? > > This code worked recently, until the company implemented these LAN > connections... > > SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > latest_BWI_vis.jpg" > satpic = urllib.urlopen(SAT_URL, proxies=0 ) > satimg = satpic.read() > For the record, I got: >>> import urllib >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\urllib.py", line 79, in urlopen opener = FancyURLopener(proxies=proxies) File "C:\Python26\lib\urllib.py", line 617, in __init__ URLopener.__init__(self, *args, **kwargs) File "C:\Python26\lib\urllib.py", line 129, in __init__ assert hasattr(proxies, 'has_key'), "proxies must be a mapping" AssertionError: proxies must be a mapping However, urllib.urlretrieve(...) works. From nad at acm.org Tue Jul 27 18:25:54 2010 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jul 2010 15:25:54 -0700 Subject: Binary compatibility across Python versions? References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> <0A4C9B21-6EFF-461A-B15C-415D1408DD88@semanchuk.com> Message-ID: In article <0A4C9B21-6EFF-461A-B15C-415D1408DD88 at semanchuk.com>, Philip Semanchuk wrote: [...] > Thanks to all who replied on this topic. A little more background -- > these binaries are just a convenience for our users and we don't have > to cover every possible permutation of Python, only the ones we think > will be most common in our user base. That said, thanks to the things > you pointed out, I'm beginning to think that our users might be such a > varied group that precompiled binaries might not be worth the trouble. > > Ned, I'm on Mac and I was under the impression that the deployment > target compiler option would control how the resulting binary (in this > case, Python) called OS X but it wouldn't have any affect on how other > code (like our library) called Python. Is that not the case? Even if your extension modules and libraries don't make a lot of system calls, I think it's a bit of a crap shoot since there are no guarantees of compatibility among the various popular distributions and there are the gcc-4.0 vs -4.2 and the arch differences. You'd have to try the various combinations and/or limit the configurations you support. The bottom line is that many (most?) package developers have given up on trying to supply binary distributions for OS X. Since Apple supplies the necessary developer tools for free with recent OS X releases and in most cases Distutils does the right thing, the burden on end users isn't particularly onerous (see, for example, http://appscript.sourceforge.net/py-appscript/install.html). Now, adding SWIG and C++ to the mix may result in a different answer. I don't have any practical experience with them to have an opnion. Good luck! -- Ned Deily, nad at acm.org From krdean at gmail.com Tue Jul 27 18:43:44 2010 From: krdean at gmail.com (kBob) Date: Tue, 27 Jul 2010 15:43:44 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> On Jul 27, 4:23?pm, MRAB wrote: > kBob wrote: > > > ?I created a script to access weather satellite imagery fron NOAA's > > ADDS. > > > ?It worked fine until recently with Python 2.6. > > > ?The company changed the Internet LAN connections to "Accept Automatic > > settings" and "Use automatic configuration script" > > > ?How do you get urllib.urlopen to use the the "automatic script" > > configuration? > > > ?This code worked recently, until the company implemented these LAN > > connections... > > > ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > latest_BWI_vis.jpg" > > ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > ? ? satimg = satpic.read() > > For the record, I got: > > ?>>> import urllib > ?>>> SAT_URL = > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > ? ? ?opener = FancyURLopener(proxies=proxies) > ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > ? ? ?URLopener.__init__(self, *args, **kwargs) > ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > AssertionError: proxies must be a mapping > > However, urllib.urlretrieve(...) works.- Hide quoted text - > > - Show quoted text - I saw that, but I still get the same error time out error ... >>> import urllib >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" >>> SAT_FILE = "latest_BWI_vis.jpg" >>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) Traceback (most recent call last): File "", line 1, in File "c:\python26\lib\urllib.py", line 93, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "c:\python26\lib\urllib.py", line 237, in retrieve fp = self.open(url, data) File "c:\python26\lib\urllib.py", line 205, in open return getattr(self, name)(url) File "c:\python26\lib\urllib.py", line 344, in open_http h.endheaders() File "c:\python26\lib\httplib.py", line 904, in endheaders self._send_output() File "c:\python26\lib\httplib.py", line 776, in _send_output self.send(msg) File "c:\python26\lib\httplib.py", line 735, in send self.connect() File "c:\python26\lib\httplib.py", line 716, in connect self.timeout) File "c:\python26\lib\socket.py", line 514, in create_connection raise error, msg IOError: [Errno socket error] [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or establis hed connection failed because connected host has failed to respond Kelly From python at mrabarnett.plus.com Tue Jul 27 18:56:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 23:56:01 +0100 Subject: urllib timeout In-Reply-To: <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> Message-ID: <4C4F6401.9090209@mrabarnett.plus.com> kBob wrote: > On Jul 27, 4:23 pm, MRAB wrote: >> kBob wrote: >> >>> I created a script to access weather satellite imagery fron NOAA's >>> ADDS. >>> It worked fine until recently with Python 2.6. >>> The company changed the Internet LAN connections to "Accept Automatic >>> settings" and "Use automatic configuration script" >>> How do you get urllib.urlopen to use the the "automatic script" >>> configuration? >>> This code worked recently, until the company implemented these LAN >>> connections... >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/ >>> latest_BWI_vis.jpg" >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) >>> satimg = satpic.read() >> For the record, I got: >> >> >>> import urllib >> >>> SAT_URL = >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" >> >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Python26\lib\urllib.py", line 79, in urlopen >> opener = FancyURLopener(proxies=proxies) >> File "C:\Python26\lib\urllib.py", line 617, in __init__ >> URLopener.__init__(self, *args, **kwargs) >> File "C:\Python26\lib\urllib.py", line 129, in __init__ >> assert hasattr(proxies, 'has_key'), "proxies must be a mapping" >> AssertionError: proxies must be a mapping >> >> However, urllib.urlretrieve(...) works.- Hide quoted text - >> >> - Show quoted text - > > I saw that, but I still get the same error time out error ... > >>>> import urllib >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" >>>> SAT_FILE = "latest_BWI_vis.jpg" >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > Traceback (most recent call last): > File "", line 1, in > File "c:\python26\lib\urllib.py", line 93, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "c:\python26\lib\urllib.py", line 237, in retrieve > fp = self.open(url, data) > File "c:\python26\lib\urllib.py", line 205, in open > return getattr(self, name)(url) > File "c:\python26\lib\urllib.py", line 344, in open_http > h.endheaders() > File "c:\python26\lib\httplib.py", line 904, in endheaders > self._send_output() > File "c:\python26\lib\httplib.py", line 776, in _send_output > self.send(msg) > File "c:\python26\lib\httplib.py", line 735, in send > self.connect() > File "c:\python26\lib\httplib.py", line 716, in connect > self.timeout) > File "c:\python26\lib\socket.py", line 514, in create_connection > raise error, msg > IOError: [Errno socket error] [Errno 10060] A connection attempt > failed because > the connected party did not properly respond after a period of time, > or establis > hed connection failed because connected host has failed to respond > It should be like this: SAT_URL = "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" SAT_FILE = r"C:\latest_BWI_vis.jpg" urllib.urlretrieve(SAT_URL, SAT_FILE) From tim_grove at sil.org Tue Jul 27 19:12:23 2010 From: tim_grove at sil.org (Timothy W. Grove) Date: Wed, 28 Jul 2010 00:12:23 +0100 Subject: subprocess module under python 2.7 Message-ID: <4C4F67D7.5090905@sil.org> I am using the following code to hide the console window when launching a subprocess under Windows. startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE self.mplayer = Popen(args, bufsize=0, #unbufferred stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False, universal_newlines=True, startupinfo=startupinfo ) This worked okay in using the subprocess module under python 2.6, but under python 2.7 I get the error: Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyo", line 530, in __bootstrap_inner File "gui\mplayer_ctrl.pyo", line 93, in run AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW' Anything changed between python versions to account for this? Best regards, Tim From clp2 at rebertia.com Tue Jul 27 19:36:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jul 2010 16:36:02 -0700 Subject: subprocess module under python 2.7 In-Reply-To: <4C4F67D7.5090905@sil.org> References: <4C4F67D7.5090905@sil.org> Message-ID: On Tue, Jul 27, 2010 at 4:12 PM, Timothy W. Grove wrote: > I am using the following code to hide the console window when launching a > subprocess under Windows. > > ? ? ? startupinfo = subprocess.STARTUPINFO() > ? ? ? startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW > ? ? ? startupinfo.wShowWindow = subprocess.SW_HIDE > > ? ? ? self.mplayer = Popen(args, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?bufsize=0, #unbufferred > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stdin=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stdout=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stderr=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?close_fds=False, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?universal_newlines=True, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?startupinfo=startupinfo > ? ? ? ? ? ? ? ? ? ? ? ? ? ?) > > This worked okay in using the subprocess module under python 2.6, but under > python 2.7 I get the error: > > Exception in thread Thread-1: > Traceback (most recent call last): > ?File "threading.pyo", line 530, in __bootstrap_inner > ?File "gui\mplayer_ctrl.pyo", line 93, in run > AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW' > > Anything changed between python versions to account for this? Yes, apparently the code importing that stuff got removed: http://svn.python.org/view/python/tags/r27/Lib/subprocess.py?r1=79064&r2=82504 FWIW, STARTUPINFO(), STARTF_USESHOWWINDOW, and SW_HIDE were/are undocumented in both Python versions and thus shouldn't be relied upon. They can be accessed via Python's win32-specific modules instead (see diff). Cheers, Chris -- http://blog.rebertia.com From thomas at jollans.com Tue Jul 27 19:41:20 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 01:41:20 +0200 Subject: Are those features still the same? In-Reply-To: References: Message-ID: <4C4F6EA0.7000505@jollans.com> On 07/25/2010 11:02 AM, francogrex wrote: > Terry Reedy wrote: >> As other have said, mostly, but I would change the following... > > Thanks for all those who replied. I know these are not all the features but > some of them and again this is not a comparison but a little taste of what > python offers today, and the replies were very informative. By the way Peter > Norvig is not biased, he works for Google research and is a supporter of > programming in any language, especially in Python. > Had I known the table was headed with "Python for Lisp programmers", I would have responded differently - but you chose to hide that ;-) From memilanuk at gmail.com Tue Jul 27 20:33:10 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Tue, 27 Jul 2010 17:33:10 -0700 Subject: newb In-Reply-To: References: Message-ID: On 7/27/10 4:07 AM, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers Alan Gauld posts fairly regularly over on the python-tutor mailing list, as well as here. He has newer material on his website @ http://www.alan-g.me.uk/, and if you google 'python tutorial' you'll probably find more material than you can shake a stick at - from web pages to books (both online and dead-tree) to You-Tube videos. One book that helps me out quite a bit is John Zelle's "Python Programming: An Introduction to Computer Science". Just be aware there is a first edition (covers python 2.x) and a newer second edition (python 3.x) - both available from Amazon. From mithrandiragainwiki at mailinator.com Tue Jul 27 22:19:59 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Tue, 27 Jul 2010 19:19:59 -0700 Subject: newb References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/27/2010 04:07 AM, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers It may also depend on which version of Python you wish to use. Since you're a "newb", I'd probably suggest starting off with Python 3. The version in your book is probably version 2.*. The difference is minor, but, when you're starting off (I assume with computer languages in general?) the difference in syntax can kick you where it hurts. Programs that work with Python 2.*, may not work with Python 3. However, I suggest Python 3 since it seems to be the "code of tomorrow." It may also depend on what you wish to do with your knowledge of Python (applications, games, web frameworks, etc.) If you want to make games, I suggest also learning about pyGame. As for book versus website, I started off with, as others have mentioned, learning online. Not only is it free, but the boundary between page and screen is broken. Note though that some off-sites (Wikibooks for instance) may not be complete in their writing. Python.org has a wealth of knowledge about almost everything involving Python. However, *some* of the documentation there may not be suitable for absolute beginners. There are several links there to other good websites for those with no experience in coding, all the way up to a ridiculously complicated level. I highly suggest poking around there. If you wish to read a book instead, try: http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002/ Or go to your local library and poke there. :) Good luck! - -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. - From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW -----END PGP SIGNATURE----- From mithrandiragainwiki at mailinator.com Tue Jul 27 22:26:27 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Tue, 27 Jul 2010 19:26:27 -0700 Subject: Are those features still the same? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/26/2010 11:58 PM, Lawrence D'Oliveiro wrote: > In message , francogrex wrote: > >> By the way Peter Norvig is not biased, he works for Google research and is >> a supporter of programming in any language, especially in Python. > > Bias doesn?t have to be a conscious thing. Correct. It just has to have a rainbow logo and own half the internet. :) - -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. - From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJMT5VTAAoJEKo37V1xH7gTobAH/1QY0SN6BulkNO3QUFrzg5cO OkeDTbTmI4BJ1M/hmkECU+T76KfnkQ13NobLroWt/UJU8YA4lOQ6KsJU/EsR/27n TFrUxs3gDVeWyiKdSbWtVSZ7b7BJ8Tr41hMPkA1wyK85qJW5mA19h0hndqs/BRtg j2GWPLNv9wx7+v0gQnv7ZgSQJHSlRvp8oi016QVl3W7OcO6B0rgwWx4i1hxz/oij Wd1jF5wwhtgw/0durTFFVt7mR31l3/6zz2WrwvC9fQkSKNQ0oaNgKXZOtctWVdcV XNm+W9I9Sx70F1qO+VfFrHIRJ+kzjCf6/48bumaygol4MnbLIJ3lJ1BNIESIFAg= =iv9B -----END PGP SIGNATURE----- From f2h2d2 at gmail.com Tue Jul 27 22:54:34 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Tue, 27 Jul 2010 19:54:34 -0700 (PDT) Subject: The Miracle and Challenge of the Quran Message-ID: The Miracle and Challenge of the Quran ---------------------------------------------------------------------------?--- http://www.youtube.com/watch?v=m3A8R...layer_embedded http://www.youtube.com/watch?v=m3A8R...layer_embedded ---------------------------------------------------------------------------?--------------------------------------- Do you know Islam ? Try VISIT THESE SITES ISLAM RELIGION http://www.islamreligion.com/ SCIENE ISLAM http://www.islamreligion.com/ YOUTUBE ISLAM http://youtubeislam.com/ BIBLE ISLAM http://www.bibleislam.com/ MINISTRY OF AWKAF http://www.islamic-council.org/ ISLAM WORD http://islamworld.net/ ISLAM HOUSE http://www.islamhouse.com/ SUNNAH ONLINE http://www.sunnahonline.com/ilm/dawah/index.htm ---------------------------------------------------------------------------?-------------------------------------- The Miracle and Challenge of the Quran With an introduction by Magdy Abd Al-SHafy The Holy Quran is a miracle that beggars de******ion , words fail to describe this miracle , it is a miracle in the full sense of the term . Different specialists , according to the branch of science they are specialized in , find it miraculous . Prophet Mohummed said commenting on the Holy Quran saying " it unfolds the secrets of the nations that preceded you , and secrets of the future treasured in it " It is the Holy Book that Jinnee , on hearing to it , did not leave their place till they believed in it . It is the book which unbelievers gave positive witness to . Dr. Keith L. Moore is a Professor of Anatomy and Cell Biology, University of Toronto, Toronto, Canada. He is a world renowned scientist and a distinguished researcher in the fields of anatomy and embryology, he has published more than 150 research articles, chapters and books in this field. He is the author of several medical ****books, such as the widely used and acclaimed "The Developing Human: Clinically oriented Embryology" (now in it's fifth edition, and translated into eight different languages), "Before We Are Born" and "Clinically Oriented Anatomy." He has also recently co-authored "Qur'an and Modern Science, Correlation Studies." Dr. Moore is the recipient of numerous awards and honors, including, in 1984, the J.C.B. Grant Award, which is the highest honor granted by the Canadian Association of Anatomists. He has served in many academic and administrative positions, including the President of the Canadian Association of Anatomists, 1968-1970. Let us see what Dr. Moore's opinion is on the scientific statements regarding embryology to be found in the Qur'an: Dr. Moore was contacted by a Muslim scholar by the name of Abdul- Majeed Azzindani. He was asked to participate in a three-year study of around twenty-five verses of the Qur'an and the Sunnah (sayings of Muhammad, pbuh) which speak about embryology, and to determine the their correspondence to modern scientific discoveries. Dr. Moore's conclusion regarding this matter was: "For the past three years, I have worked with the Embryology Committee of King Abdulaziz University in Jeddah, Saudi Arabia, helping them to interpret the many statements in the Qur'an and the Sunnah referring to human reproduction and prenatal development. At first I was astonished by the accuracy of the statements that were recorded in the seventh century AD, before the science of embryology was established. Although I was aware of the glorious history of Muslim scientists in the 10th century AD, and of some of their contributions to Medicine, I knew nothing about the religious facts and beliefs contained in the Qur'an and Sunnah. It is important for Islamic and other students to understand the meaning of these Qur'anic statements about human development, based on current scientific knowledge. The interpretations of the "verses" in the Qur'an and the Sunnah, translated by Shaikh Azzindani, are to the best of my knowledge accurate." >From the forward of "The Developing Human: Clinically oriented Embryology," third edition, by Dr. Keith L. Moore. The Qur'an and the Sunnah of the prophet Muhammad (Sallalahu Alayhi Wa Salam) provide a very detailed de******ion of the microscopic development of the human embryo from a mere sperm drop up to the stage of a completely formed human being. It is well known that microscopes were not developed until the sixteenth century AD, and even at that were very crude in design. Zacharias Janssen is credited with having invented the compound microscope in about 1590. With it, remarkable scientific discoveries were made in the 17th and 18th centuries. The Dutch naturalist Anthony van Leeuwenhoek produced lenses powerful enough to prove that many tiny creatures are not spontaneously generated but come from eggs. Before this period, theories on human reproduction ran rampant. Some scientist believed that the menstrual blood itself developed into the fetus. Later on, a new theory was developed wherein the sperm drop was popularly believed to contain a completely developed miniature human (homunculus) which later grew to the size of a baby. The science of embryology as we know it today did not discover many of the detailed aspects of human development which are taken for granted today until only about twenty years ago, or 1973 to be precise. Now we must ask the question: where did Muhammad (Sallalahu Alayhi Wasallam) get such detailed knowledge of the microscopic development of the human embryo in the 6th century AD without a microscope, technical training, a laboratory of any kind, or even the ability to write his own name? The only logical conclusion is that it came from exactly where he claimed it did. From the one who created mankind, God Almighty! Prof. Moore has since given numerous lectures on the topic of embryology in the Qur'an. He is quoted in one of these lectures as saying: "It is clear to me that these statements must have come to Muhammad from God, or Allah, because most of this knowledge was not discovered until many centuries later. This proves to me that Muhammad must have been a messenger of God, or Allah." Prof. Moore was so impressed with the Qur'anic classification of the stages of development of the human embryo, that he suggested the adoption of the Qur'anic system in place of the system currently in use by scientists today. Prof. Moore said: "Because the staging of the human embryo is complex owing to the continuous process of change during development. It is therefore suggested that a new system of classification could be developed using the terms mentioned in the Qur'an and the Sunnah. The proposed system is simple, comprehensive, and conforms with present embryological knowledge." When Dr. Moore first presented his findings in Toronto it caused quite a stir throughout Canada. It was on the front pages of some of the newspapers across Canada . One newspaper reporter asked Professor Moore, "Don't you think That maybe the Arabs might have known about these things - the de******ion of the embryo, its appearance and how it changes and grows? Maybe there were not scientists, but maybe they did some crude dissections on their own - carved up people and examined these things." Professor Morre immediately pointed out to him, however, that he had missed a very important point. All of the slides of the embryo that Dr. Moore had based his study upon had come from pictures taken through a microscope. He said, "It does not matter if someone had tried to discover embryology fourteen centuries ago, they could not have seen it!." Dr. Moore taunted, "Maybe fourteen centuries ago someone secretly had a microscope and did this research, making no mistakes anywhere. Then he somehow taught Muhammad and convinced him to put this information in his book. Then he destroyed his equipment and kept it a secret forever?. Do you believe that? You really should not unless you bring some proof because it is such a ridiculous theory." When he was asked "How do you explain this information in the Qur'an?" Dr. Moore's reply was, "It could only have been divinely revealed ????? ?????? ??? ??? ??????? The Effect of Prayer on the Human Body By : Dr Noha abo-krysha Translated By : Nassim Dhaher Revised By Magdy Abd Al-Shafy In fact , prayer is a strong connection to God . In prayer , one can find many meanings that beggar de******ion , man can find out the basic reason behind his existence . Allah the Exalted says in the Holy Quran what means : { Those who believe, and whose hearts find satisfaction in the remembrance of Allah. for without doubt in the remembrance of Allah do hearts find satisfaction} Sura Arraadverse28 God also says in the Holy Quran what means :{78-Establish regular prayers - at the sun's decline till the darkness of the night, and the morning prayer and reading: for the prayer and reading in the morning carry their testimony. 79-And pray in the small watches of the morning: (it would be) an additional prayer (or spiritual profit) for thee: soon will thy Lord raise thee to a Station of Praise and Glory!} Sura Al-israa verses 78,79 Prophet Mohammad (peace and blessings of Allah be upon him) used to say , when somthing distress him : (Oh Bilal(the prayer caller ), call for the prayer, relax us by it) [Sunan Abi Dawud] The Scientific Study It has become clear , through the results of several studies, the great effect that prayer and devotion have on brain stability and mode of function, and it has also become clear that several changes occur in the body ;among these is the effect that happens during blood systematization to certain parts in the brain prayer effect on cerebral activities This research was carried out by Dr. Newberg, the assistant Professor at X-Ray division of the Pennsylvania University Medical Center, on a group of faithful people who have faith in God , practice their prayers and come from different religious backgrounds. This as done using Single Photon C.T. scan that shows the flow of blood in the cerebrum using colors which are based on brain activity where the color Red represents high activity and Yellow and Green represent low activity. The First Image The image shows the brain before meditation and prayer(on the left) and during prayer (on the right) where we see that during the envolvement in prayers and meditation, blood flow has increased , frontal lobe region is responsible for controlling emotions and agitations in humans and a region also important for the acquisition and practice of complicated percetion-movement abilities. Terms used in the image Baseline: normal state without meditation Meditation: as name implies The Second Image The image shows a a blood flow decline in the the Parietal lobe at the region where humans sense their time and space limits. It was concluded from these results that during prayer, contemplation and seeking Allah, the limits of self-conciousness dissapear and a feeling of peace and freedom starts in the person and one feels closer to Allah in a way that no words can describe. Verses from The Quran Many are the verses that talked about the importance of prayer (Assalat), devotion and praise Allah the Almighty. The Quran has made a link between patience and prayer to make sure one does not get agitated. Allah The Exalted Says in the Holy Quran what means: {Nay, seek (Allah's) help with patient perseverance and prayer: It is indeed hard, except to those who bring a lowly spirit} SuraAl-Baqara verse 45 There are other verses that linked between prayer and tranquility. Allah The Exalted Says: {When ye pass (Congregational) prayers, celebrate Allah?s praises, standing, sitting down, or lying down on your sides; but when ye are free from danger, set up Regular Prayers: For such prayers are enjoined on believers at stated times.} Sura An-Nisa verse 103 {Successful indeed are the believers , Who are humble in their prayers} Sura Al Muminun verses 1,2 Results It becomes clear after these verses of the Noble Quran and scientific studies the importance of prayer in the life of the faithful, and the importance of devotion and glorification during the application of those prayers. From here the wisdom of Islam is apparent in focusing on the danger of ceasing to do the prayers. If experiments show stability of the brain during prayers for non- Muslims who don?t even read Al-Quran during their prayers, How then is it when one prays to Allah and reads the Book of Allah? Undoubtedly the stability will be greater. We remember this noble verse that confirms the importance of the channels of communication towards Allah, ie ,piety, submission, heart purification, and putting things in Allah?s command. Allah The Exalted Says in the Holy Quran what means: {Be guardians of your prayers, and of the midmost prayer, and stand up with devotion to Allah.} Sura Al-Baqara verse 238 Let us remember also the supplication of Prophet Abraham (peace be upon him) My Lord! Make me to establish proper worship, and some of my posterity (also); our Lord! and accept my prayer. Our Lord! Forgive me and my parents and believers on the day when the account is cast. ???? ???? ?????? ?? ?????? What does the Holy Quran say about Iron ? By Magdy Abd Al-Shafy The Holy Quran , the last revealed Holy book, carries within its holy verses the evidence toits Divine source . Among the many mitacles that the holy Quran contain is the scientific miracles , more than 1400 years ago , The Holy Quran gives scientific facts that have been discovered already and now are scientifically established . When the Holy Quran gives such facts it adds many dimensions to the question of faith in God ; in addition to the faith dimension there is a spiritual dimension that Only Moslems and reasonable non -moslems can feel . The Holy Quran stands in the face of the atheism claims . The other Holy books , being distorted and pregnant with scientific errors that may feed sckepticism , are no longer able to face atheism . Atheism are breeding and taking people away from the right path . The Holy Quran , being the most authenticated book , can be the challanger - No one can believe that a book with such astounding scientific miracles that revealed 1400 years ago can be man-mad . Such facts lead you to believe in God and to believe that the Holy Quran is God's book ...it is up to you to decide ......... Now to our scientific miracle The Holy Quran ststes in one of its Holy verses that ( iron ) we send down from high skies , i.e, it is not formed in the ground . That what science has aleady discovered . Let's read this short verse . God says in the Holy Quran what means "And We sent down iron in which there lies great force and which has many uses for mankind.... (Surat al-Hadid: 25) Modern astronomical findings have disclosed that the ****l of iron found in our world has come down from the giant stars in outer space. The Holy Quran verse used The Arabic word " Anzlna " which could be rendered " and we sent down " . Iron needs so high temperature to be formed ; Professor Armstrong works at NASA, otherwise known as the National Aeronautics and Space Administration, where he is a well-known scientist here. He was asked about Iron and how it was formed. He explained how all the elements in the earth were formed. He stated that the scientists have come only recently to discover the relevant facts about that formation process. He said that the energy of the early solar system was not sufficient to produce elemental Iron. In calculating the energy required to form one atom of iron, it was found to be about four times as much as the energy of the entire solar system. In other words, the entire energy of the earth or the moon or the planet Mars or any other planet is not sufficient to form one new atom of iron, even the energy of the entire solar system is not sufficient for that. That is why Professor Armstrong said that the scientists believe that iron is an extraterrestrial that was sent to earth and not formed therein. Unlike most of ****ls , iron needs so high temperature to be formed . such high temperature is found no where in our solar system . "Nova" and "supernova. Temperature in the Sun is inadequate for the formation of iron. The sun has a surface temperature of 6,000 degrees Celsius, and a core temperature of approximately 20 million degrees. Iron can only be produced in much larger stars than the Sun, where the temperature reaches a few hundred million degrees. When the amount of iron exceeds a certain level in a star, the star can no longer accommodate it, and it eventually explodes in what is called a "nova" or a "supernova." These explosions make it possible for iron to be given off into space. All this shows that iron did not form on the Earth, but was carried from Supernovas, and was "sent down," as stated in the verse. It is clear that this fact could not have been known in the 7th century, when the Qur'an was revealed. Nevertheless, this fact is related in the Qur'an, the Word of Allah, Who encompasses all things in His infinite knowledge. Science says that iron and other materials were attracted to the earh when enetered the earth garvity field ; iron fell down on the earth as if it were rain . the earth at that time was like ash , not completely solid as it is now . Iron found its way deep to the core of the earth . And We sent down iron in which there lies great force and which has many uses for mankind.... what is meant by ( and in which there lies great force and which has many uses for mankind.... In his book Nature's Destiny, the well-known microbiologist Michael Denton Of all the ****ls there is none more essential to life than iron. It is the accumulation of iron in the center of a star which triggers a supernova explosion and the subsequent scattering of the vital atoms of life throughout the cosmos. It was the drawing by gravity of iron atoms to the center of the primeval earth that generated the heat which caused the initial chemical differentiation of the earth, the outgassing of the early atmosphere, and ultimately the formation of the hydrosphere. It is molten iron in the center of the earth which, acting like a gigantic dynamo, generates the earth's magnetic field, which in turn creates the Van Allen radiation belts that shield the earth's surface from destructive high-energy-penetrating cosmic radiation and preserve the crucial ozone layer from cosmic ray destruction? in this connection the Holy Quran , to show God's blessings , in another verse which implies anew scientific miracle says " And we have made the heavens as a canopy well guarded: yet do they turn away from the Signs which these things (point to)!( Al-Anbyaa :32 ) Without the iron atom, there would be no carbon-based life in the cosmos; no supernovae, no heating of the primitive earth, no atmosphere or hydrosphere. There would be no protective magnetic field, no Van Allen radiation belts, no ozone layer, no ****l to make hemoglobin [in human blood], no ****l to tame the reactivity of oxygen, and no oxidative ****bolism. The intriguing and intimate relationship between life and iron, between the red color of blood and the dying of some distant star, not only indicates the relevance of ****ls to biology but also the biocentricity of the cosmos? This account clearly indicates the importance of the iron atom. The fact that particular attention is drawn to iron in the Qur'an also emphasises the importance of the element. In addition, there is another hidden truth in the Qur'an which draws attention to the importance of iron: Surat al-Hadid 25, which refers to iron, contains two rather interesting mathematical codes. "Al- Hadid" is the 57th sura in the Qur'an. The abjad of the word "Al- Hadid" in Arabic, when the numerological values of its letters are added up, is also 57. The numerological value of the word "hadid" alone is 26. And 26 is the atomic number of iron. Moreover, iron oxide particles were used in a cancer treatment in recent months and positive developments were observed. A team led by Dr. Andreas Jordan, at the world famous Charit? Hospital in Germany, succeeded in destroying cancer cells with this new technique developed for the treatment of cancer-magnetic fluid hyperthermia (high temperature magnetic liquid). As a result of this technique, first performed on the 26-year-old Nikolaus H., no new cancer cells were observed in the patient in the following three months. This method of treatment can be summarised as follows: 1. A liquid containing iron oxide particles is injected into the tumour by means of a special syringe. These particles spread throughout the tumour cells. This liquid consists of thousands of millions of particles, 1,000 times smaller than the red blood corpuscles, of iron oxide in 1 cm3 that can easily flow through all blood vessels.42 2. The patient is then placed in a machine with a powerful magnetic field. 3. This magnetic field, applied externally, begins to set the iron particles in the tumour in motion. During this time the temperature in the tumour containing the iron oxide particles rises by up to 45 degrees. In a few minutes the cancer cells, unable to protect themselves from the heat, are either weakened or destroyed. The tumour may then be completely eradicated with subsequent chemotherapy.43 In this treatment it is only the cancer cells that are affected by the magnetic field, since only they contain the iron oxide particles. The spread of this technique is a major development in the treatment of this potentially lethal disease. In the treatment of such a widespread disease as cancer, the use of the expression "iron in which there lies great force and which has many uses for mankind" (Qur'an, 57:25) in the Qur'an is particularly noteworthy. Indeed, in that verse, the Qur'an may be indicating the benefits of iron for human health. (Allah knows best.) From pengyu.ut at gmail.com Tue Jul 27 23:26:09 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 27 Jul 2010 22:26:09 -0500 Subject: Where is the help page for re.MatchObject? Message-ID: I know the library reference webpage for re.MatchObject is at http://docs.python.org/library/re.html#re.MatchObject But I don't find such a help page in python help(). Does anybody know how to get it in help()? >>> help(re.MatchObject) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'MatchObject' -- Regards, Peng From steveo at syslang.net Tue Jul 27 23:31:03 2010 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 27 Jul 2010 23:31:03 -0400 Subject: How to capture all the environment variables from shell? In-Reply-To: <4C4E4790.6030604@tim.thechases.com> References: <4C4E43D3.9070203@syslang.net> <4C4E4790.6030604@tim.thechases.com> Message-ID: <4C4FA477.6000308@syslang.net> On 07/26/10 22:42, quoth Tim Chase: > On 07/26/10 21:26, Steven W. Orr wrote: >> Please! Never export anything from your .bashrc unless you >> really know what you're doing. Almost all exports should be >> done in your .bash_profile > > Could you elaborate on your reasoning why (or why-not)? I've found that > my .bash_profile doesn't get evaluated when I crank up another terminal > window, while my bashrc does. Thus I tend to put my exports in my > ~/.bashrc so they actually take effect in my shell... > > -tkc > > I'm happy to elaborate, but people should feel free to stop me if they're not interested. The topic is bash: When you log in you get your .bash_profile and not the .bashrc. Subshells get the .bashrc and not the .bash_profile. If you set your envvars in your .bash_profile then you don't need to reset them in subshells because they all get inherited. (Inheritance of envvars is, after all, the reason that they are envvars and not just local variables.) The way you get your .bashrc to happen at login time is that you have to make it happen yourself. In your .bash_profile, just say this: . ~/.bashrc The one time that you should set an envvar in your .bashrc is when you are not an interactive shell. In that case you can set your PATH var in your .bashrc by first testing to see if you're interactive: In your .bashrc just say: [[ -z "$PS1" ]] && set_PATH_cmds # Of course, note that set_PATH_cmds is not a subprocess. It has to # be either a PATH= or function that accomplishes the same thing. This solves the problem of things like ssh somemachine cmd where cmd is something that you would only find on your PATH if you properly logged in. As far as X goes, I am starting from the premise that your X session will be set up to cause your .bash_profile to happen at login time. One last note: If you say something like export PATH=$PATH:/usr/local/bin then re-sourcing your .bash_profile will cause your PATH value to double up. That's why I set my PATH variable explicitly. After that, I encourage people to set up their PATH variables so that they are broken into four distinct sections in the following order. (The idea is to make your stuff override the system supplied stuff.) (The stuff below is just an example.) USERPERSONAL=~/bin:~/share/bin MACHINESPECIALS=/usr/local/bin:/usr/local/share/bin OPTIONALADDONS=/opt/Adobe/Reader9/bin:/opt/openoffice.org3/program VENDORPATHS=/bin:/usr/bin:/usr/X11R6/bin PATH=${USERPERSONAL}:${MACHINESPECIALS}:${OPTIONALADDONS}:${VENDORPATHS} -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From jeff at newz-china.org Tue Jul 27 23:56:32 2010 From: jeff at newz-china.org (Jeff Ro) Date: Wed, 28 Jul 2010 11:56:32 +0800 Subject: About " python " Internet intellectual Property Issue Message-ID: (If you are not in charge of this , please transfer this urgent email to your CEO. Thanks ) Dear CEO, We are a leading internet solutions organization in Asia, and we have something urgent to confirm with you. Yesterday we received a formal application from a company called " Yower Investment Co., Ltd". They were trying to apply for " python" as Brand Name and following Domain Names through our organization: www.python.com.hk www.python.tm After our initial examination, we found that the Brand Name and Domain Names above are similar to yours. These days we have been dealing with it. Now we hope to get your affirmation. If your company did not authorize the aforesaid company to register these, please contact us as soon as possible. In addition, we hereby declare that time limit for this issue is 7 workdays. If your company don?t respond within the time limit, we will unconditionally approve the application submitted by Yower Investment Co., Ltd. Best Regards, Jeff Ro Senior Examinant 2010-07-23 -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Wed Jul 28 01:26:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 22:26:21 -0700 Subject: Which multiprocessing methods use shared memory? In-Reply-To: References: Message-ID: <4c4fbf7b$0$1616$742ec2ed@news.sonic.net> On 7/27/2010 12:30 PM, MRAB wrote: > Kevin Ar18 wrote: >> I'm not sure my previous message went through (I wasn't subscribe), so >> I'm gonna try again. >> >> The multiprocessing module has 4 methods for sharing data between >> processes: >> Queues >> Pipes >> Shared Memory Map >> Server Process >> >> Which of these use shared memory? >> >> I understand that the 3rd (Shared Memory Map) does, but what about >> Queues? >> > The documentation says: > > """class multiprocessing.Queue([maxsize]) > Returns a process shared queue implemented using a pipe and a few > locks/semaphores. When a process first puts an item on the queue a > feeder thread is started which transfers objects from a buffer into the > pipe.""" Python's "shared memory" between processes is un-Pythonic. You can't share Python object, only C objects. The locking mechanisms are very limited, and slow; locking actually takes place via messages over pipes. There's no dynamic allocation in the shared area. Realistically, if you're using Python, you're not that concerned about compute speed. So don't bother with shared memory, which is a performance optimization. John Nagle From eckhardt at satorlaser.com Wed Jul 28 03:08:24 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jul 2010 09:08:24 +0200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: <8k15i7-jhs.ln1@satorlaser.homedns.org> Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have > asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? There are two kinds of programs: 1. Those that process input to output. If one of those suddenly started by clearing my screen, I'd just dump it. Also, if output is redirected to a file or piped into another program, that is basically useless or even hurting, since you then end up with control sequences in the file. 2. Those that provide a text-based interactive UI. Those typically not only clear the screen, but also control its whole layout and content, so there you don't only need ways to clear the screen but also to position the cursor or draw boxes etc. In that case you need a full "curses" library. Summary: No, I don't see the need for such an API. Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From sjmachin at lexicon.net Wed Jul 28 03:16:55 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jul 2010 00:16:55 -0700 (PDT) Subject: Where is the help page for re.MatchObject? References: Message-ID: <0863ebe2-4910-4693-8539-39633e652845@s24g2000pri.googlegroups.com> On Jul 28, 1:26?pm, Peng Yu wrote: > I know the library reference webpage for re.MatchObject is athttp://docs.python.org/library/re.html#re.MatchObject > > But I don't find such a help page in python help(). Does anybody know > how to get it in help()? Yes, but it doesn't tell you very much: | >>> import re | >>> help(re.match('x', 'x')) | Help on SRE_Match object: | | class SRE_Match(__builtin__.object) | | >>> From jbbrown at sunflower.kuicr.kyoto-u.ac.jp Wed Jul 28 03:41:38 2010 From: jbbrown at sunflower.kuicr.kyoto-u.ac.jp (J.B. Brown) Date: Wed, 28 Jul 2010 16:41:38 +0900 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: I personally prefer to be slightly excessive in the amount of spacing I used, especially when parentheses are involved. In no way do I assert that my code style is right for all situations, but here are a few examples of my personal style. --- myTuple = ( 1, 2, 3, 4, 5 ) # Comment about what this tuple will conceptually represent or store. myTuple2 = ( 1, 2, 3*myFunc(4), 4*myFunc2( "text arg" ), ) # Yes, I leave the tailing comma for spacing and to remind myself it is a tuple/list. textFieldWidth = 80 / numFields # Balance width of fields fileObject.write( "My text goes here. Value of some function = " + str( someFunc( argList ) ) ) # Write out results. --- Combining my code style with the parenthesis/brace/bracket highlighting feature of Vi/Vim makes it easy for me to figure out if I have closed all braces, and additionally what is the context in which I am nesting functions or arguments. Again, this is just my preference, but it emerged over time after many hours of development and debugging on remote machines where only a terminal environment and a text-based editor are available. Even in my comments, in which I _strongly_ believe in a minimum of 1 comment line per 3 code lines (1:3) though I often code 1:2 or 1:1, I use the parenthesis style above. Example: # The true positive rate of an experiment is calculated as: TPR = [ TP / ( TP + FN ) ] . Just food for thought. J.B. Brown Kyoto University From bruno.42.desthuilliers at websiteburo.invalid Wed Jul 28 03:48:26 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jul 2010 09:48:26 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> Message-ID: <4c4fe0bf$0$29093$426a74cc@news.free.fr> Ethan Furman a ?crit : > Bruno Desthuilliers wrote: >> Bruno Desthuilliers a ?crit : >>> Ethan Furman a ?crit : >>>> Bruno Desthuilliers wrote: >>>>> Duncan Booth a ?crit : >>> (snip) >>> >>>>>> Or you could create the default as a class attribute >>>>> >>>>> from the OP: >>>>> """ >>>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>>> it is overloaded in __getattr__, so if someone invokes >>>>> "myObject.size", it is generated (as another oofun) and connected to >>>>> myObject as attribute. >>>>> """ >>>>> >>>>> so this solution won't obviously work in this case !-) >>>>> >>>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>>> class attribute is of a mutable type. >>>> >>>> Well, it is Monday, so I may be missing something obvious, but what >>>> is the effective difference between these two solutions? >>> >> >> If you meant "what is the difference between creating the "whatever" >> attribute with a default value in the initializer and creating it on >> demand in the __getattr__ hook", the main difference is that in the >> first case, the instance is garanteed to have this attribute, so you >> get rid of "hasattr" checks (and the unwanted side effects) or, worse, >> direct check of the instance __dict__. Except for a couple of corner >> case, client code shouldn't have to worry about this kind of things - >> this breaks encapsulation. > > Yay Tuesday! :D > > What I meant was what is the difference between: > > [Bruno Desthuilliers] > > DEFAULT_WHATEVER = Whathever() > > class MyClass(object): > > def __init__(self, x, y): > > self.size = DEFAULT_WHATEVER > > and > > [Duncan Booth] > > class MyClass(object): > > size = Whatever() > > def __init__(self, x, y): > > ... > > in both cases the object ends up with a size attribute and no further > need of __getattr__. Of course, the warning about having a mutable > object as a class attribute stands. Indeed. > To phrase it another way, why does your solution (Bruno) work, but > Duncan's "obviously won't"? As it is written (and assuming the name "Whatever" is bound to a callable !-)), Duncan's code would work, even if it might not be the safest solution in the case of a mutable type. The problem here is that the OP stated that the "size" attribute was to be of the same type as the host class, so the code would look something like: class MyClass(object): size = MyClass() which will raise a NameError, since MyClass is not yet defined when "size=MyClass()" is executed. From tartley at tartley.com Wed Jul 28 05:49:25 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 02:49:25 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 I don't know much, but just in case the following is useful to anyone: There is a Windows program called 'ansicon', which when installed (run with '-i'), will modify all future Windows cmd shells to correctly intercept and interpret ANSI escape codes for colors, cursor movement, and: \e[#J ED: Erase Display which I presume is what is under discussion here. I understand there are other historical ANSI drivers which were responsible for achieving a similar thing under Windows, but this is the method I currently use (on XP) and am very happy with. Also, and probably less usefully, personally I do wish Python provided a cross platform mechanism for simple terminal control like clearing and colored text. Since ANSI codes are used everywhere except Windows, it would make sense to base such a system on them. So I started a pure Python implementation of a crude ANSI driver, on PyPI as 'colorama'. It does nothing on non-windows systems, but on Windows it patches sys.stdout with a stream-like object, in order to filter out ANSI codes and convert them into Win32 terminal control calls. It currently only works with colors and brightness, but I would love to extend it to cover other ANSI codes such as 'clear screen'. It is doubtless riddled with errors and misunderstandings, and I would love any feedback helping me do a better job. Best regards, Jonathan From lijia.jasperlee at gmail.com Wed Jul 28 06:10:00 2010 From: lijia.jasperlee at gmail.com (jia li) Date: Wed, 28 Jul 2010 18:10:00 +0800 Subject: Python parsing XML file problem with SAX Message-ID: I have an XML file with hundreds of elements. What's strange is only one of there elements could not be parsed correctly: REVERSE_INULL Dispose_ParameterList Dispose_ParameterList UNINSPECTED 146 1/146MMSLib_LinkedList.c I printed the data in "characters(self, data)" and after parsing. The result is one "\r\n" is inserted after "1/" and "146MMSLib_LinkedList.c" for the latter. But if I make my XML file only this element left, it could parse correctly. My script below: class CoverityErrorHandler(ContentHandler): def __init__(self): self.is_num = False self.num = "" self.is_func = False self.function = "" self.is_file = False self.filename = "" self.is_Report = False self.report = "" self.is_Checker = False self.checker = "" self.is_unmangled_func = False self.unmangled_func= "" self.is_Status = False self.Status = "" self.mapping = {} def startElement(self, name, attributes): if name == "num": self.is_num = True elif name == "unmangled_function": self.is_unmangled_func = True elif name == "checker": self.is_Checker = True elif name == "file": self.is_file = True elif name == "home": self.is_Report = True elif name == "function": self.is_func = True elif name == "status": self.is_Status = True def characters(self, data): if self.is_num: self.num = data elif self.is_func: self.function = data elif self.is_Checker: self.checker = data elif self.is_file: self.filename = data elif self.is_Report: self.report = data; print self.report; elif self.is_unmangled_func: self.unmangled_func = data elif self.is_Status: self.Status = data def endElement(self, name): if name == "error": self.mapping[self.num] = CoverityError(self.checker, self.filename, self.function, self.report) elif name == "num": self.is_num = False elif name == "unmangled_function": self.is_unmangled_func = False elif name == "checker": self.is_Checker = False elif name == "file": self.is_file = False elif name == "home": self.is_Report = False elif name == "function": self.is_func = False elif name == "status": self.is_Status = False Please any expert help to have a look. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Jul 28 06:48:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Jul 2010 12:48:54 +0200 Subject: Python parsing XML file problem with SAX In-Reply-To: References: Message-ID: jia li, 28.07.2010 12:10: > I have an XML file with hundreds of elements. > > What's strange is only one of there elements could not be parsed correctly: > > REVERSE_INULL > Dispose_ParameterList > Dispose_ParameterList > UNINSPECTED > 146 > 1/146MMSLib_LinkedList.c > > > I printed the data in "characters(self, data)" and after parsing. The result > is one "\r\n" is inserted after "1/" and "146MMSLib_LinkedList.c" for the > latter. > > But if I make my XML file only this element left, it could parse correctly. First of all: don't use SAX. Use ElementTree's iterparse() function. That will shrink you code down to a simple loop in a few lines. Then, the problem is likely that you are getting separate events for text nodes. The "\r\n" most likely only occurs due to your print statement, I doubt that it's really in the data returned from SAX. Again: using ElementTree instead of SAX will avoid this kind of problem. Stefan From fetchinson at googlemail.com Wed Jul 28 07:23:52 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 28 Jul 2010 13:23:52 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <8k15i7-jhs.ln1@satorlaser.homedns.org> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: >> After getting the technicalities out of the way, maybe I should have >> asked: >> >> Is it only me or others would find a platform independent python API >> to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. Okay, that makes perfect sense, thanks for the exaplanation! I'll just live with the platform.system( ) check for this particular problem then. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Jul 28 07:25:51 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 28 Jul 2010 13:25:51 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> Message-ID: >> > After getting the technicalities out of the way, maybe I should have >> > asked: >> >> > Is it only me or others would find a platform independent python API >> > to clear the terminal useful? > I don't know much, but just in case the following is useful to anyone: > > There is a Windows program called 'ansicon', which when installed (run > with '-i'), will modify all future Windows cmd shells to correctly > intercept and interpret ANSI escape codes for colors, cursor movement, > and: > > \e[#J ED: Erase Display > > which I presume is what is under discussion here. I understand there > are other historical ANSI drivers which were responsible for achieving > a similar thing under Windows, but this is the method I currently use > (on XP) and am very happy with. > > Also, and probably less usefully, personally I do wish Python provided > a cross platform mechanism for simple terminal control like clearing > and colored text. Since ANSI codes are used everywhere except Windows, > it would make sense to base such a system on them. So I started a pure > Python implementation of a crude ANSI driver, on PyPI as 'colorama'. > It does nothing on non-windows systems, but on Windows it patches > sys.stdout with a stream-like object, in order to filter out ANSI > codes and convert them into Win32 terminal control calls. It currently > only works with colors and brightness, but I would love to extend it > to cover other ANSI codes such as 'clear screen'. It is doubtless > riddled with errors and misunderstandings, and I would love any > feedback helping me do a better job. Thanks, I didn't know about 'colorama' before but it surely looks promising! I'll look into it for future reference, once in a while I like having pretty output without the hassle of 'curses' or other complicated stuff. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chenxiangmei89 at gmail.com Wed Jul 28 08:20:18 2010 From: chenxiangmei89 at gmail.com (cntrade08) Date: Wed, 28 Jul 2010 05:20:18 -0700 (PDT) Subject: Shox Allegria Glow, Shox FSM, Shox Dendara, Shox 45, Shox Propulsion, Shox XT,Shox Vivacity. (http://www.cntrade09.com) Message-ID: For more information,please contact karen, MSN:cntrade088 at hotmail.com Minimum order is one,factory price also! Paypal payment free shipping,ship time will take 4-7 working days. Shox TW,Shox Saya+,Shox Arraw+,Shox Pursuit+,Shox Turbo V+5,Shox NZ,Shox Turbo+IV 4,Shox Spotlight,Shox Saikano+,Shox Fleet,Shox Turn & Go,Shox Junga II 2,Shox Q'Vida,Shox Junga,Shox TL 4,Shox Monster,Shox TL 3,Shox Turb OH+SL,Shox TL 2,Shox CL,Shox TL,Shox Cognescenti,Shox Explodine,Shox R4,Nike Shox Basketball,Shox Disobey,Shox Turbo. Shox Go,Shox 2:40,Shox Respond,Shox Warrior,Shox Ride 2,Shox Glamour SW & SW II,Shox Andalucia,Shox Rhythmic,Shox Aprisa,Shox Energia,Shox Ride & Plus,Shox Allegria Glow,Shox FSM,Shox Dendara,Shox 45,Shox 2:45,Shox Legend Trainer,Shox VC,Shox Rollin,Shox BB4,Shox Bella IL,Shox Basketball,Shox Turbo OZ,Shox Electric,Shox TR,Shox D,Shox Propulsion,Shox XT,Shox Vivacity. (http:// www.cntrade09.com) Zoom Moire+,Nike Trainer Huarache,Nike Free Trainer 5.0, 7.0,Nike Air Tech Challenge - Andre Agassi,Nike Presto & Chanjo,Training & Running Shoes,Barry Sanders Zoom Turf,Basketball Shoes. www.cntrade09.com From me at here.com Wed Jul 28 08:50:47 2010 From: me at here.com (whitey) Date: Wed, 28 Jul 2010 12:50:47 GMT Subject: newb References: Message-ID: On Tue, 27 Jul 2010 19:19:59 -0700, Mithrandir wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 07/27/2010 04:07 AM, whitey wrote: >> hi all. am totally new to python and was wondering if there are any >> newsgroups that are there specifically for beginners. i have bought a >> book for $2 called "learn to program using python" by alan gauld. >> starting to read it but it was written in 2001. presuming that the >> commands and info would still be valid? any websites or books that are >> a must for beginners? any input would be much appreciated...cheers > > It may also depend on which version of Python you wish to use. Since > you're a "newb", I'd probably suggest starting off with Python 3. The > version in your book is probably version 2.*. The difference is minor, > but, when you're starting off (I assume with computer languages in > general?) the difference in syntax can kick you where it hurts. Programs > that work with Python 2.*, may not work with Python 3. However, I > suggest Python 3 since it seems to be the "code of tomorrow." > > It may also depend on what you wish to do with your knowledge of Python > (applications, games, web frameworks, etc.) If you want to make games, I > suggest also learning about pyGame. > > As for book versus website, I started off with, as others have > mentioned, learning online. Not only is it free, but the boundary > between page and screen is broken. Note though that some off-sites > (Wikibooks for instance) may not be complete in their writing. > Python.org has a wealth of knowledge about almost everything involving > Python. However, *some* of the documentation there may not be suitable > for absolute beginners. There are several links there to other good > websites for those with no experience in coding, all the way up to a > ridiculously complicated level. I highly suggest poking around there. > > If you wish to read a book instead, try: > http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/ dp/1435455002/ > Or go to your local library and poke there. :) > > Good luck! > > - -- > People should read more. > https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All > that is gold does not glitter, > not all those who wander are lost; > the old that is strong does not wither, deep roots are not reached by > the frost. - From the ashes a fire shall be woken, a light from the > shadows shall spring; renewed shall be blade that was broken, the > crownless again shall be king." > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI > 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH > yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim > Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw > pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 > x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW > -----END PGP SIGNATURE----- thank you all for the info. will definately check out your suggested links, really excited about learning to code and hopefully in the near future will be able to contribute somehow to the community. see you around... From wherespythonmonks at gmail.com Wed Jul 28 09:15:24 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Wed, 28 Jul 2010 09:15:24 -0400 Subject: Nice way to cast a homogeneous tuple Message-ID: A new python convert is now looking for a replacement for another perl idiom. In particular, since Perl is weakly typed, I used to be able to use unpack to unpack sequences from a string, that I could then use immediately as integers. In python, I find that when I use struct.unpack I tend to get strings. (Maybe I am using it wrong?) def f(x,y,z): print x+y+z; f( *struct.unpack('2s2s2s','123456')) 123456 (the plus concatenates the strings returned by unpack) But what I want is: f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) 102 But this seems too complicated. I see two resolutions: 1. There is a way using unpack to get out string-formatted ints? 2. There is something like map(lambda x: int(x).... without all the lambda function call overhead. (e.g., cast tuple)? [And yes: I know I can write my own "cast_tuple" function -- that's not my point. My point is that I want a super-native python inline solution like (hopefully shorter than) my "map" version above. I don't like defining trivial functions.] W From airscorp at otenet.gr Wed Jul 28 09:27:58 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Wed, 28 Jul 2010 16:27:58 +0300 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C50305E.3010603@otenet.gr> On 07/28/2010 04:15 PM, wheres pythonmonks wrote: > > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > But this seems too complicated. > > > Well, you don't need the lambda at all int === lambda x: int(x) So just write It's like writing: def myint(x): return int(x) Nick, Warm thanks to Steven D' Aprano who taught me that just yesterday in the Tutor list ;) From airscorp at otenet.gr Wed Jul 28 09:31:14 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Wed, 28 Jul 2010 16:31:14 +0300 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4C50305E.3010603@otenet.gr> References: <4C50305E.3010603@otenet.gr> Message-ID: <4C503122.3060208@otenet.gr> Ep, that missing line should be: On 07/28/2010 04:27 PM, Nick Raptis wrote: > On 07/28/2010 04:15 PM, wheres pythonmonks wrote: >> >> f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) >> 102 >> >> But this seems too complicated. >> >> > Well, you don't need the lambda at all > int === lambda x: int(x) > > So just write > f( *map(int, struct.unpack('2s2s2s', '123456'))) Pretty compact now, isn't it? > It's like writing: > def myint(x): > return int(x) > > > Nick, > > Warm thanks to Steven D' Aprano who taught me that just yesterday in > the Tutor list ;) From duncan.booth at invalid.invalid Wed Jul 28 09:31:21 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Jul 2010 13:31:21 GMT Subject: Nice way to cast a homogeneous tuple References: Message-ID: wheres pythonmonks wrote: > 2. There is something like map(lambda x: int(x).... without all the > lambda function call overhead. (e.g., cast tuple)? Yes there is: "lambda x: int(x)" is just a roundabout way of writing "int" -- Duncan Booth http://kupuguy.blogspot.com From wherespythonmonks at gmail.com Wed Jul 28 09:35:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Wed, 28 Jul 2010 09:35:52 -0400 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4C503122.3060208@otenet.gr> References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: Thanks ... I thought int was a type-cast (like in C++) so I assumed I couldn't reference it. On Wed, Jul 28, 2010 at 9:31 AM, Nick Raptis wrote: > Ep, that missing line should be: > > On 07/28/2010 04:27 PM, Nick Raptis wrote: >> >> On 07/28/2010 04:15 PM, wheres pythonmonks wrote: >>> >>> f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) >>> 102 >>> >>> But this seems too complicated. >>> >>> >> Well, you don't need the lambda at all >> int ? === ? ?lambda x: int(x) >> >> So just write >> > f( *map(int, struct.unpack('2s2s2s', '123456'))) > > Pretty compact now, isn't it? > >> It's like writing: >> def myint(x): >> ? ?return int(x) >> >> >> Nick, >> >> Warm thanks to Steven D' Aprano who taught me that just yesterday in the >> Tutor list ;) > > -- > http://mail.python.org/mailman/listinfo/python-list > From hexamorph at gmx.net Wed Jul 28 09:47:17 2010 From: hexamorph at gmx.net (Hexamorph) Date: Wed, 28 Jul 2010 15:47:17 +0200 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C5034E5.6080208@gmx.net> wheres pythonmonks wrote: > A new python convert is now looking for a replacement for another perl idiom. > > In particular, since Perl is weakly typed, I used to be able to use > unpack to unpack sequences from a string, that I could then use > immediately as integers. > > In python, I find that when I use struct.unpack I tend to get strings. > (Maybe I am using it wrong?) > > def f(x,y,z): print x+y+z; > > f( *struct.unpack('2s2s2s','123456')) > 123456 > > (the plus concatenates the strings returned by unpack) > > But what I want is: > > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > But this seems too complicated. > > I see two resolutions: > > 1. There is a way using unpack to get out string-formatted ints? > > 2. There is something like map(lambda x: int(x).... without all the > lambda function call overhead. (e.g., cast tuple)? > [And yes: I know I can write my own "cast_tuple" function -- that's > not my point. My point is that I want a super-native python inline > solution like (hopefully shorter than) my "map" version above. I > don't like defining trivial functions.] > > W In [31]: import re In [32]: sum(int(x) for x in re.findall("..", s)) Out[32]: 102 To get a tuple instead of the sum, just do: In [33]: tuple(int(x) for x in re.findall("..", s)) Out[33]: (12, 34, 56) From eckhardt at satorlaser.com Wed Jul 28 09:58:29 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jul 2010 15:58:29 +0200 Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <5lp5i7-f5u.ln1@satorlaser.homedns.org> wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Hopefully somebody correct me if I explain this badly, but I'll take a shot... Firstly, "int" is a class. Python doesn't make a distinction between builtin types and class types like C++, where you e.g. can't derive from builtin types. Secondly, the class is callable like a function. When called, it creates an instance of that class. Therefore, when you create an object it has a similar syntax as when calling a function. Lastly, classes are not special. Like any variable or function they can be referenced by a name or by multiple names, and thus be passed as parameters to a function. Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.42.desthuilliers at websiteburo.invalid Wed Jul 28 10:11:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jul 2010 16:11:22 +0200 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <4c503a7d$0$29585$426a34cc@news.free.fr> wheres pythonmonks a ?crit : > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Python has no C/C++ like "type-cast". "int" is the builtin integer type, and instanciating an object in Python is done by calling it's type. Remember that in Python, everything (at least everything you can bind to a name) is an object (including functions, types etc), and that functions are just one kind of callable objects (types - aka "classes" -, methods and a few other builtin objects are callable too, and you can of course define your own callable type). HTH From python.list at tim.thechases.com Wed Jul 28 10:14:06 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jul 2010 09:14:06 -0500 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C503B2E.7050902@tim.thechases.com> On 07/28/10 08:15, wheres pythonmonks wrote: > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > 1. There is a way using unpack to get out string-formatted ints? well, you can use >>> s = '123456' >>> [int(s[i:i+2]) for i in range(0, len(s), 2)] [12, 34, 56] >>> f(*_) 102 While your "f()" is just a boring placeholder I assume, you could also write that as sum(int(s[i:i+2]) for i in range(0, len(s), 2)) and skip creating f() altogether if all it does is add its arguments. -tkc From steve at REMOVE-THIS-cybersource.com.au Wed Jul 28 10:32:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jul 2010 14:32:22 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <4c503f75$0$11091$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Python doesn't have type-casts in the sense of "tell the compiler to treat object of type A as type B instead". The closest Python has to that is that if you have an instance of class A, you can do this: a = A() # make an instance of class A a.__class__ = B # tell it that it's now class B and hope that it won't explode when you try to use it :/ I make that seem like a dangerous thing to do, but it's not really. There actually are sensible use-cases for such a thing, you can't do it to built-ins (which would be dangerous!), and the worst that will happen with classes written in Python is they'll raise an exception when you try calling a method, rather than dump core. Otherwise, all type conversions in Python create a new instance of the new type, and the conversion functions themselves (int, str, etc.) are actual type objects which you can pass around to functions: >>> type(int) Calling int(x) calls the int constructor with argument x, and returns a new int object. (In the *specific* case of int, it will sometimes cache small integers and re-use the same one multiple times, but don't count on that behaviour since it's an implementation-specific optimization.) -- Steven From krdean at gmail.com Wed Jul 28 11:11:41 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 08:11:41 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> Message-ID: <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> On Jul 27, 4:56?pm, MRAB wrote: > kBob wrote: > > On Jul 27, 4:23 pm, MRAB wrote: > >> kBob wrote: > > >>> ?I created a script to access weather satellite imagery fron NOAA's > >>> ADDS. > >>> ?It worked fine until recently with Python 2.6. > >>> ?The company changed the Internet LAN connections to "Accept Automatic > >>> settings" and "Use automatic configuration script" > >>> ?How do you get urllib.urlopen to use the the "automatic script" > >>> configuration? > >>> ?This code worked recently, until the company implemented these LAN > >>> connections... > >>> ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > >>> latest_BWI_vis.jpg" > >>> ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > >>> ? ? satimg = satpic.read() > >> For the record, I got: > > >> ?>>> import urllib > >> ?>>> SAT_URL = > >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > >> ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > >> Traceback (most recent call last): > >> ? ?File "", line 1, in > >> ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > >> ? ? ?opener = FancyURLopener(proxies=proxies) > >> ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > >> ? ? ?URLopener.__init__(self, *args, **kwargs) > >> ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > >> ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > >> AssertionError: proxies must be a mapping > > >> However, urllib.urlretrieve(...) works.- Hide quoted text - > > >> - Show quoted text - > > > I saw that, but I still get the same error time out error ... > > >>>> import urllib > >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" > >>>> SAT_FILE = "latest_BWI_vis.jpg" > >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python26\lib\urllib.py", line 93, in urlretrieve > > ? ? return _urlopener.retrieve(url, filename, reporthook, data) > > ? File "c:\python26\lib\urllib.py", line 237, in retrieve > > ? ? fp = self.open(url, data) > > ? File "c:\python26\lib\urllib.py", line 205, in open > > ? ? return getattr(self, name)(url) > > ? File "c:\python26\lib\urllib.py", line 344, in open_http > > ? ? h.endheaders() > > ? File "c:\python26\lib\httplib.py", line 904, in endheaders > > ? ? self._send_output() > > ? File "c:\python26\lib\httplib.py", line 776, in _send_output > > ? ? self.send(msg) > > ? File "c:\python26\lib\httplib.py", line 735, in send > > ? ? self.connect() > > ? File "c:\python26\lib\httplib.py", line 716, in connect > > ? ? self.timeout) > > ? File "c:\python26\lib\socket.py", line 514, in create_connection > > ? ? raise error, msg > > IOError: [Errno socket error] [Errno 10060] A connection attempt > > failed because > > the connected party did not properly respond after a period of time, > > or establis > > hed connection failed because connected host has failed to respond > > It should be like this: > > SAT_URL = > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > SAT_FILE = r"C:\latest_BWI_vis.jpg" > urllib.urlretrieve(SAT_URL, SAT_FILE)- Hide quoted text - > > - Show quoted text - It doesn't matter, the same error 10060 appears . The connection problem has to do with the proxy settings. In order for me to use Internet Explorer, the LAN's Automatic configuration must be turned on and use a script found on the company's proxy server. I was wondering how to get urllib.urlopen to access the script on the proxy server. Thanks for your help. Kelly From emile at fenx.com Wed Jul 28 11:22:33 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 28 Jul 2010 08:22:33 -0700 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: On 7/28/2010 4:23 AM Daniel Fetchinson said... > > Okay, that makes perfect sense, thanks for the exaplanation! > I'll just live with the platform.system( ) check for this particular > problem then. > If all else fails, repeating 24 (or 40,60?) lines feeds clears the screen cross platform. Emile From tartley at tartley.com Wed Jul 28 11:45:46 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 08:45:46 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 Hey, Your point seems good and I don't mean to contradict, but out of interest, what do you think about an example like the following: I want to write a quick script which, notices whenever I save my source code, and re-runs the unit tests, displaying the output. I think I'd like it to clear the terminal before each re-run of the tests, so that it's immediately obvious what is output from the current run, as opposed to previous runs. Then I can keep my editor focussed, but leave that running in a terminal and trust it to simply display the current output from my tests. I did dash off a quick and dirty version of this once which did a system 'clear' or 'cls' depending on the platform, but to my dismay I found that on Windows this caused focus to jump briefly to the terminal every time it ran 'clear' (!), making it extremely annoying in use. So I wished there had been a simple cross-platform way to clear the terminal. (this, and printing colored text, was my initial use case for starting 'colorama') Is this a silly desire of mine, or simply an uncommon edge case that therefore isn't really significant? Best regards, Jonathan From pavlovevidence at gmail.com Wed Jul 28 11:47:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 28 Jul 2010 08:47:52 -0700 (PDT) Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Jul 28, 7:32?am, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > > couldn't reference it. > > Python doesn't have type-casts in the sense of "tell the compiler to > treat object of type A as type B instead". The closest Python has to that > is that if you have an instance of class A, you can do this: > > a = A() ?# make an instance of class A > a.__class__ = B ?# tell it that it's now class B > > and hope that it won't explode when you try to use it :/ Type casts in C and non-pathlogical C++ don't modify the object they are casting. int (and str, float, etc.) is the closest thing to a type cast in Python. Carl Banks From tartley at tartley.com Wed Jul 28 12:01:38 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 09:01:38 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Jul 28, 4:45?pm, Jonathan Hartley wrote: > On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > > > > > Daniel Fetchinson wrote: > > > After getting the technicalities out of the way, maybe I should have > > > asked: > > > > Is it only me or others would find a platform independent python API > > > to clear the terminal useful? > > > There are two kinds of programs: > > 1. Those that process input to output. If one of those suddenly started by > > clearing my screen, I'd just dump it. Also, if output is redirected to a > > file or piped into another program, that is basically useless or even > > hurting, since you then end up with control sequences in the file. > > > 2. Those that provide a text-based interactive UI. Those typically not only > > clear the screen, but also control its whole layout and content, so there > > you don't only need ways to clear the screen but also to position the > > cursor or draw boxes etc. In that case you need a full "curses" library. > > > Summary: No, I don't see the need for such an API. > > > Cheers! > > > Uli > > > -- > > Sator Laser GmbH > > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > Hey, > > Your point seems good and I don't mean to contradict, but out of > interest, what do you think about an example like the following: > > I want to write a quick script which, notices whenever I save my > source code, and re-runs the unit tests, displaying the output. I > think I'd like it to clear the terminal before each re-run of the > tests, so that it's immediately obvious what is output from the > current run, as opposed to previous runs. Then I can keep my editor > focussed, but leave that running in a terminal and trust it to simply > display the current output from my tests. > > I did dash off a quick and dirty version of this once which did a > system 'clear' or 'cls' depending on the platform, but to my dismay I > found that on Windows this caused focus to jump briefly to the > terminal every time it ran 'clear' (!), making it extremely annoying > in use. So I wished there had been a simple cross-platform way to > clear the terminal. (this, and printing colored text, was my initial > use case for starting 'colorama') > > Is this a silly desire of mine, or simply an uncommon edge case that > therefore isn't really significant? > > Best regards, > > ? Jonathan Oh, plus, while we're on this subject: Am I right that curses in Python stdlib doesn't work on Windows, and there is currently no simple way to fix this? Also, is it crazy to imagine that if colorama was pushed through to completion (ie. to support a majority of the relevant ANSI codes) then Python's stdlib curses module, unmodified, would suddenly just work on Windows? (after a call to 'colorama.init()') I presume these ideas are oversimplifications or just plain wrong. If anyone would care to correct my misunderstandings, I'd be very grateful. From neilc at norwich.edu Wed Jul 28 12:06:06 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Jul 2010 16:06:06 GMT Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <8bb2reF616U1@mid.individual.net> On 2010-07-28, Jonathan Hartley wrote: > I want to write a quick script which, notices whenever I save > my source code, and re-runs the unit tests, displaying the > output. I think I'd like it to clear the terminal before each > re-run of the tests, so that it's immediately obvious what is > output from the current run, as opposed to previous runs. Then > I can keep my editor focussed, but leave that running in a > terminal and trust it to simply display the current output from > my tests. Perhaps emailing the tests to yourself would be a good solution. Every tme the tests ran, you'd get a new email containing the results. -- Neil Cerutti From krdean at gmail.com Wed Jul 28 12:30:26 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 09:30:26 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> Message-ID: <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> On Jul 28, 9:11?am, kBob wrote: > On Jul 27, 4:56?pm, MRAB wrote: > > > > > > > kBob wrote: > > > On Jul 27, 4:23 pm, MRAB wrote: > > >> kBob wrote: > > > >>> ?I created a script to access weather satellite imagery fron NOAA's > > >>> ADDS. > > >>> ?It worked fine until recently with Python 2.6. > > >>> ?The company changed the Internet LAN connections to "Accept Automatic > > >>> settings" and "Use automatic configuration script" > > >>> ?How do you get urllib.urlopen to use the the "automatic script" > > >>> configuration? > > >>> ?This code worked recently, until the company implemented these LAN > > >>> connections... > > >>> ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > >>> latest_BWI_vis.jpg" > > >>> ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > >>> ? ? satimg = satpic.read() > > >> For the record, I got: > > > >> ?>>> import urllib > > >> ?>>> SAT_URL = > > >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > > >> ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > >> Traceback (most recent call last): > > >> ? ?File "", line 1, in > > >> ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > > >> ? ? ?opener = FancyURLopener(proxies=proxies) > > >> ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > > >> ? ? ?URLopener.__init__(self, *args, **kwargs) > > >> ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > > >> ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > > >> AssertionError: proxies must be a mapping > > > >> However, urllib.urlretrieve(...) works.- Hide quoted text - > > > >> - Show quoted text - > > > > I saw that, but I still get the same error time out error ... > > > >>>> import urllib > > >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" > > >>>> SAT_FILE = "latest_BWI_vis.jpg" > > >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ? File "c:\python26\lib\urllib.py", line 93, in urlretrieve > > > ? ? return _urlopener.retrieve(url, filename, reporthook, data) > > > ? File "c:\python26\lib\urllib.py", line 237, in retrieve > > > ? ? fp = self.open(url, data) > > > ? File "c:\python26\lib\urllib.py", line 205, in open > > > ? ? return getattr(self, name)(url) > > > ? File "c:\python26\lib\urllib.py", line 344, in open_http > > > ? ? h.endheaders() > > > ? File "c:\python26\lib\httplib.py", line 904, in endheaders > > > ? ? self._send_output() > > > ? File "c:\python26\lib\httplib.py", line 776, in _send_output > > > ? ? self.send(msg) > > > ? File "c:\python26\lib\httplib.py", line 735, in send > > > ? ? self.connect() > > > ? File "c:\python26\lib\httplib.py", line 716, in connect > > > ? ? self.timeout) > > > ? File "c:\python26\lib\socket.py", line 514, in create_connection > > > ? ? raise error, msg > > > IOError: [Errno socket error] [Errno 10060] A connection attempt > > > failed because > > > the connected party did not properly respond after a period of time, > > > or establis > > > hed connection failed because connected host has failed to respond > > > It should be like this: > > > SAT_URL = > > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > > SAT_FILE = r"C:\latest_BWI_vis.jpg" > > urllib.urlretrieve(SAT_URL, SAT_FILE)- Hide quoted text - > > > - Show quoted text - > > It doesn't matter, the same error 10060 appears . > > The connection problem has to do with the proxy settings. > > ?In order for me to use Internet Explorer, the LAN's Automatic > configuration must be turned on and use a script found on the > company's proxy server. I was wondering how to get urllib.urlopen to > access the script on the proxy server. > > Thanks for your help. > > Kelly- Hide quoted text - > > - Show quoted text - OK, looks like I need to start a new thread..... How to get urllib to work with a Web Proxy Auto-Discovery Protocol (WPAD)? Kelly From thomas at jollans.com Wed Jul 28 12:47:28 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 18:47:28 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <4C505F20.6010103@jollans.com> On 07/28/2010 06:01 PM, Jonathan Hartley wrote: > > Oh, plus, while we're on this subject: > > Am I right that curses in Python stdlib doesn't work on Windows, and > there is currently no simple way to fix this? > > Also, is it crazy to imagine that if colorama was pushed through to > completion (ie. to support a majority of the relevant ANSI codes) then > Python's stdlib curses module, unmodified, would suddenly just work on > Windows? (after a call to 'colorama.init()') > > I presume these ideas are oversimplifications or just plain wrong. If > anyone would care to correct my misunderstandings, I'd be very > grateful. Correct: it's not THAT simple. Python's curses module is a (I'm not sure how thin) wrapper around the good old UNIX curses (ncurses, ...) library. This is written in C, not Python, so it doesn't use Python's sys.stdout object to do I/O. I haven't had a look at colorama, but it sounds like it hooks into sys.stdout, or Python file objects anyway. Far, far above the layer curses does I/O on. So, if you ported a normal curses library to Windows, colorama wouldn't help you a bit. It might be possible to write a curses-compatible library that works with cmd.exe. Maybe. But, even if it's possible, I don't think it's easy, and I especially don't think it would be particularly rewarding. Also, I just stumbled upon http://adamv.com/dev/python/curses/ -- this is probably the only reasonable way to get a useful curses API on Windows: forget the DOS box. From schrabacke at web.de Wed Jul 28 12:57:42 2010 From: schrabacke at web.de (hardi) Date: Wed, 28 Jul 2010 09:57:42 -0700 (PDT) Subject: Linear nterpolation in 3D Message-ID: <29288748.post@talk.nabble.com> Hi, I'm trying to interpolate a 3D data (from the pic attached) with the interp2d command. What I have, are three vectors f, z, A (x, y, z respectively, A is the percentage data given on the isolines). I first put the f and z in a meshgrid and afterwards in the griddata to get a 3D-grid then started to interpolate. I plotted the the data after gridding, and I observed that almost all nodes are ignored. Do you have any idea how to prepare data to the interp2d command? my code so far is: import numpy as np from mpl_toolkits.mplot3d import axes3d from scipy.interpolate import interp2d import matplotlib.pyplot as plt from matplotlib import mlab plt.clf() fig = plt.figure(1) ax = axes3d.Axes3D(fig) #read data (ff,ZZ,A,a) = np.loadtxt("accuracy-map.txt", unpack=True) f=np.log10(ff) z=np.log10(ZZ) ##grid everything fgrid, zgrid=np.meshgrid(f,z) #define grid ef=np.linspace(min(f), max(f), len(f)) ez=np.linspace(min(z), max(z), len(f)) Agrid=mlab.griddata(f,z,A, ef,ez) int2d=interp2d(fgrid, zgrid, Agrid, kind='linear') ax.plot(f, z, A, 'ok', markerfacecolor='w') ax.plot_surface(fgrid, zgrid, Agrid) ax.set_xlim3d((min(f), max(f))) ax.set_ylim3d(min(z), max(z)) ax.set_zlim3d(0,100) plt.show() http://old.nabble.com/file/p29288748/novo-error.pdf novo-error.pdf -- View this message in context: http://old.nabble.com/Linear-nterpolation-in-3D-tp29288748p29288748.html Sent from the Python - python-list mailing list archive at Nabble.com. From ethan at stoneleaf.us Wed Jul 28 12:59:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Jul 2010 09:59:01 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4fe0bf$0$29093$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> <4c4fe0bf$0$29093$426a74cc@news.free.fr> Message-ID: <4C5061D5.7070802@stoneleaf.us> Bruno Desthuilliers wrote: > Ethan Furman a ?crit : >> Bruno Desthuilliers wrote: >>> Bruno Desthuilliers a ?crit : >>>> Ethan Furman a ?crit : >>>>> Bruno Desthuilliers wrote: >>>>>> Duncan Booth a ?crit : >>>> (snip) >>>> >>>>>>> Or you could create the default as a class attribute >>>>>> >>>>>> from the OP: >>>>>> """ >>>>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>>>> it is overloaded in __getattr__, so if someone invokes >>>>>> "myObject.size", it is generated (as another oofun) and connected to >>>>>> myObject as attribute. >>>>>> """ >>>>>> >>>>>> so this solution won't obviously work in this case !-) >>>>>> >>>>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>>>> class attribute is of a mutable type. >>>>> >>>>> Well, it is Monday, so I may be missing something obvious, but what >>>>> is the effective difference between these two solutions? >>>> >>> >>> If you meant "what is the difference between creating the "whatever" >>> attribute with a default value in the initializer and creating it on >>> demand in the __getattr__ hook", the main difference is that in the >>> first case, the instance is garanteed to have this attribute, so you >>> get rid of "hasattr" checks (and the unwanted side effects) or, >>> worse, direct check of the instance __dict__. Except for a couple of >>> corner case, client code shouldn't have to worry about this kind of >>> things - this breaks encapsulation. >> >> Yay Tuesday! :D >> >> What I meant was what is the difference between: >> >> [Bruno Desthuilliers] >> > DEFAULT_WHATEVER = Whathever() >> > class MyClass(object): >> > def __init__(self, x, y): >> > self.size = DEFAULT_WHATEVER >> >> and >> >> [Duncan Booth] >> > class MyClass(object): >> > size = Whatever() >> > def __init__(self, x, y): >> > ... >> >> in both cases the object ends up with a size attribute and no further >> need of __getattr__. Of course, the warning about having a mutable >> object as a class attribute stands. > > Indeed. > >> To phrase it another way, why does your solution (Bruno) work, but >> Duncan's "obviously won't"? > > As it is written (and assuming the name "Whatever" is bound to a > callable !-)), Duncan's code would work, even if it might not be the > safest solution in the case of a mutable type. > > The problem here is that the OP stated that the "size" attribute was to > be of the same type as the host class, so the code would look something > like: > > class MyClass(object): > size = MyClass() > > which will raise a NameError, since MyClass is not yet defined when > "size=MyClass()" is executed. Ah ha! I *knew* I was missing something. Thank you for the explanation. So the correct methods, then, would be to either include the size attribute in the __init__, or add it to the class /after/ the class was defined. I feel much better now... slightly silly, but better. ;) ~Ethan~ From tartley at tartley.com Wed Jul 28 13:02:52 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 10:02:52 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Jul 28, 5:47?pm, Thomas Jollans wrote: > On 07/28/2010 06:01 PM, Jonathan Hartley wrote: > > > > > Oh, plus, while we're on this subject: > > > Am I right that curses in Python stdlib doesn't work on Windows, and > > there is currently no simple way to fix this? > > > Also, is it crazy to imagine that if colorama was pushed through to > > completion (ie. to support a majority of the relevant ANSI codes) then > > Python's stdlib curses module, unmodified, would suddenly just work on > > Windows? (after a call to 'colorama.init()') > > > I presume these ideas are oversimplifications or just plain wrong. If > > anyone would care to correct my misunderstandings, I'd be very > > grateful. > > Correct: it's not THAT simple. > > Python's curses module is a (I'm not sure how thin) wrapper around the > good old UNIX curses (ncurses, ...) library. This is written in C, not > Python, so it doesn't use Python's sys.stdout object to do I/O. > > I haven't had a look at colorama, but it sounds like it hooks into > sys.stdout, or Python file objects anyway. Far, far above the layer > curses does I/O on. So, if you ported a normal curses library to > Windows, colorama wouldn't help you a bit. > > It might be possible to write a curses-compatible library that works > with cmd.exe. Maybe. But, even if it's possible, I don't think it's > easy, and I especially don't think it would be particularly rewarding. > > Also, I just stumbled uponhttp://adamv.com/dev/python/curses/-- this > is probably the only reasonable way to get a useful curses API on > Windows: forget the DOS box. > ncurses ... is written in C, not > Python, so it doesn't use Python's sys.stdout object to do I/O. Ah, I should have spotted that. Of course. Thanks for the enlightenment. And Neil Cerutti, I think I'll just email the whole source tree to myself, and have a script that scans my inbox, unzips source trees and runs their tests. Much nicer. :-) From thomas at jollans.com Wed Jul 28 13:31:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 19:31:37 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <4C506979.4030809@jollans.com> On 07/28/2010 07:02 PM, Jonathan Hartley wrote: > On Jul 28, 5:47 pm, Thomas Jollans wrote: >> On 07/28/2010 06:01 PM, Jonathan Hartley wrote: >> >> >> >>> Oh, plus, while we're on this subject: >> >>> Am I right that curses in Python stdlib doesn't work on Windows, and >>> there is currently no simple way to fix this? >> >>> Also, is it crazy to imagine that if colorama was pushed through to >>> completion (ie. to support a majority of the relevant ANSI codes) then >>> Python's stdlib curses module, unmodified, would suddenly just work on >>> Windows? (after a call to 'colorama.init()') >> >>> I presume these ideas are oversimplifications or just plain wrong. If >>> anyone would care to correct my misunderstandings, I'd be very >>> grateful. >> >> Correct: it's not THAT simple. >> >> Python's curses module is a (I'm not sure how thin) wrapper around the >> good old UNIX curses (ncurses, ...) library. This is written in C, not >> Python, so it doesn't use Python's sys.stdout object to do I/O. >> >> I haven't had a look at colorama, but it sounds like it hooks into >> sys.stdout, or Python file objects anyway. Far, far above the layer >> curses does I/O on. So, if you ported a normal curses library to >> Windows, colorama wouldn't help you a bit. >> >> It might be possible to write a curses-compatible library that works >> with cmd.exe. Maybe. But, even if it's possible, I don't think it's >> easy, and I especially don't think it would be particularly rewarding. >> >> Also, I just stumbled uponhttp://adamv.com/dev/python/curses/-- this >> is probably the only reasonable way to get a useful curses API on >> Windows: forget the DOS box. > > > >> ncurses ... is written in C, not >> Python, so it doesn't use Python's sys.stdout object to do I/O. > > Ah, I should have spotted that. Of course. Thanks for the > enlightenment. > > And Neil Cerutti, I think I'll just email the whole source tree to > myself, and have a script that scans my inbox, unzips source trees and > runs their tests. Much nicer. :-) use version control! Use mercurial, commit often, and add a commit-hook that runs tests. Then you can even set up a separate repository that your script automatically pushes your changes to if they pass the tests cleanly. From clp2 at rebertia.com Wed Jul 28 14:06:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 11:06:20 -0700 Subject: Linear nterpolation in 3D In-Reply-To: <29288748.post@talk.nabble.com> References: <29288748.post@talk.nabble.com> Message-ID: On Wed, Jul 28, 2010 at 9:57 AM, hardi wrote: > Hi, > > I'm trying to interpolate a 3D data (from the pic attached) with the > interp2d command. What I have, are three vectors f, z, A (x, y, z > respectively, A is the percentage data given on the isolines). I first put > the f and z in a meshgrid and afterwards in the griddata to get a 3D-grid > then started to interpolate. I plotted the the data after gridding, and I > observed that almost all nodes are ignored. > Do you have any idea how to prepare data to the interp2d command? Since interp2d() is part of SciPy, you may have better luck asking on the SciPy-specific mailinglist: http://mail.scipy.org/mailman/listinfo/scipy-user Cheers, Chris From clp2 at rebertia.com Wed Jul 28 14:11:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 11:11:20 -0700 Subject: urllib timeout In-Reply-To: <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> Message-ID: On Wed, Jul 28, 2010 at 9:30 AM, kBob wrote: > On Jul 28, 9:11?am, kBob wrote: >> The connection problem has to do with the proxy settings. >> >> ?In order for me to use Internet Explorer, the LAN's Automatic >> configuration must be turned on and use a script found on the >> company's proxy server. I was wondering how to get urllib.urlopen to >> access the script on the proxy server. >> >> Thanks for your help. >> >> Kelly- Hide quoted text - >> >> - Show quoted text - > > OK, looks like I need to start a new thread..... > > ?How to get urllib to work with a Web Proxy Auto-Discovery Protocol > (WPAD)? Would this be of any help?: http://code.google.com/p/pacparser/ Cheers, Chris From joe at goldthwaites.com Wed Jul 28 14:32:44 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 11:32:44 -0700 Subject: Ascii to Unicode. Message-ID: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Hi, I've got an Ascii file with some latin characters. Specifically \xe1 and \xfc. I'm trying to import it into a Postgresql database that's running in Unicode mode. The Unicode converter chokes on those two characters. I could just manually replace those to characters with something valid but if any other invalid characters show up in later versions of the file, I'd like to handle them correctly. I've been playing with the Unicode stuff and I found out that I could convert both those characters correctly using the latin1 encoder like this; import unicodedata s = '\xe1\xfc' print unicode(s,'latin1') The above works. When I try to convert my file however, I still get an error; import unicodedata input = file('ascii.csv', 'r') output = file('unicode.csv','w') for line in input.xreadlines(): output.write(unicode(line,'latin1')) input.close() output.close() Traceback (most recent call last): File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ output.write(unicode(line,'latin1')) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 295: ordinal not in range(128) I'm stuck using Python 2.4.4 which may be handling the strings differently depending on if they're in the program or coming from the file. I just haven't been able to figure out how to get the Unicode conversion working from the file data. Can anyone explain what is going on? From neilc at norwich.edu Wed Jul 28 14:37:15 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Jul 2010 18:37:15 GMT Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <8bbbmrFvakU1@mid.individual.net> On 2010-07-28, Jonathan Hartley wrote: > And Neil Cerutti, I think I'll just email the whole source tree > to myself, and have a script that scans my inbox, unzips source > trees and runs their tests. Much nicer. :-) Don't forget to clear the screen, though. That ties the whole program together. -- Neil Cerutti From nagle at animats.com Wed Jul 28 14:44:37 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 11:44:37 -0700 Subject: urllib timeout In-Reply-To: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <4c507a92$0$1643$742ec2ed@news.sonic.net> On 7/27/2010 2:36 PM, kBob wrote: > > > I created a script to access weather satellite imagery fron NOAA's > ADDS. > > It worked fine until recently with Python 2.6. > > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" > > How do you get urllib.urlopen to use the the "automatic script" > configuration? > > This code worked recently, until the company implemented these LAN > connections... > > SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > latest_BWI_vis.jpg" Try https://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg The aviationweather.gov site will accept a HTTPS request. Maybe that will bypass whatever lame web proxy is in the way. John Nagle From python at mrabarnett.plus.com Wed Jul 28 15:20:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jul 2010 20:20:33 +0100 Subject: Ascii to Unicode. In-Reply-To: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> References: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Message-ID: <4C508301.4020001@mrabarnett.plus.com> Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) > > input.close() > output.close() > > Traceback (most recent call last): > File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) > > I'm stuck using Python 2.4.4 which may be handling the strings differently > depending on if they're in the program or coming from the file. I just > haven't been able to figure out how to get the Unicode conversion working > from the file data. > > Can anyone explain what is going on? > What you need to remember is that files contain bytes. When you say "ASCII file" what you mean is that the file contains bytes which represent text encoded as ASCII, and such a file by definition can't contain bytes outside the range 0-127. Therefore your file isn't an ASCII file. So then you've decided to treat it as a file containing bytes which represent text encoded as Latin-1. You're reading bytes from a file, decoding them to Unicode, and then trying to write them to a file, but the output file expects bytes (did I say that files contain bytes? :-)), so it's trying to encode back to bytes using the default encoding, which is ASCII. u'\xe1' can't be encoded as ASCII, therefore UnicodeEncodeError is raised. From thomas at jollans.com Wed Jul 28 15:21:46 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 21:21:46 +0200 Subject: Ascii to Unicode. In-Reply-To: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> References: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Message-ID: <4C50834A.30900@jollans.com> On 07/28/2010 08:32 PM, Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') output is still a binary file - there are no unicode files. You need to encode the text somehow. > Traceback (most recent call last): > File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) by default, Python tries to encode strings using ASCII. This, obviously, won't work here. Do you know which encoding your database expects ? I'd assume it'd understand UTF-8. Everybody uses UTF-8. > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) unicode(line, 'latin1') is unicode, you need it to be a UTF-8 bytestring: unicode(line, 'latin1').encode('utf-8') or: line.decode('latin1').encode('utf-8') From nagle at animats.com Wed Jul 28 15:29:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 12:29:36 -0700 Subject: Ascii to Unicode. In-Reply-To: References: Message-ID: <4c50851c$0$1677$742ec2ed@news.sonic.net> On 7/28/2010 11:32 AM, Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) > > input.close() > output.close() > Try this, which will get you a UTF-8 file, the usual standard for Unicode in a file. for rawline in input : unicodeline = unicode(line,'latin1') # Latin-1 to Unicode output.write(unicodeline.encode('utf-8')) # Unicode to as UTF-8 John Nagle From thomas at jollans.com Wed Jul 28 15:40:23 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 21:40:23 +0200 Subject: Ascii to Unicode. In-Reply-To: <4c50851c$0$1677$742ec2ed@news.sonic.net> References: <4c50851c$0$1677$742ec2ed@news.sonic.net> Message-ID: <4C5087A7.6000300@jollans.com> On 07/28/2010 09:29 PM, John Nagle wrote: > for rawline in input : > unicodeline = unicode(line,'latin1') # Latin-1 to Unicode > output.write(unicodeline.encode('utf-8')) # Unicode to as UTF-8 you got your blocks wrong. From usernet at ilthio.net Wed Jul 28 16:28:04 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 28 Jul 2010 20:28:04 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On 2010-07-28, Thomas Jollans wrote: > It might be possible to write a curses-compatible library that works > with cmd.exe. Maybe. But, even if it's possible, I don't think it's > easy, and I especially don't think it would be particularly rewarding. http://pdcurses.sourceforge.net/ It would be rewarding as it would make writing cross-platform charactor mode applications possible. Using curses for the interface makes a lot of sense because it is already supported by almost every Unix/POSIX platorm, so re-implementation is only required for those odd platforms (Windows) where it does not exist natively,; because well documented on the internet and in print; and because a huge number of people are already familiar with its API. If licensing permits, I don't think it would be too difficult difficult to embed something like pdcurses into the existing curses module to use as a backup for platforms where curses does not already exist. If not, there cannot be much difference to writing a terminal emulator that runs inside the windows console and there are a *huge* number of terminal emulators available for ansi/vt100 terminals. Add a termcap database mechanism and an embedded emulator can easily convert the excape codes into actions for the console. From martin at address-in-sig.invalid Wed Jul 28 16:28:23 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 28 Jul 2010 20:28:23 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Wed, 28 Jul 2010 09:01:38 -0700, Jonathan Hartley wrote: > Also, is it crazy to imagine that if colorama was pushed through to > completion (ie. to support a majority of the relevant ANSI codes) then > Python's stdlib curses module, unmodified, would suddenly just work on > Windows? (after a call to 'colorama.init()') > Curses was originally built on top of termcap, a much simpler and more primitive library. Its abilities are: - read the termcap database to find and load the capability list of the terminal identified as the TERM environment variable. - write a named capability to the screen. If the capability isn't defined for the current terminal its silently ignored. - fill in x, y and write the cursor movement string - thats about it. Its easy enough to find termcap databases. They're just text files containing a block of attribute values for each terminal, normally including ANSI terminals, Linux consoles, X-terms etc. They are also fairly easy to parse, even in vanilla C, so parsing one on Python should be a breeze. Termcap format specs and lists of standard attribute names are easy enough to find too. IOW, if you extend colorama to read its codes from a termcap database you'll have a basic but easily portable character console handler that can at least clear the screen, move the cursor and, if the screen has the capability, change the colour of characters or make them bold/dim/blink etc. To give you an idea of how complex this is, I've re-implemented termcap in Java for my own purposes. It amounts to 1100 lines of fairly well spaced and commented Java or about 340 statements, which were estimated by counting lines containing semicolons. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From debatem1 at gmail.com Wed Jul 28 17:39:27 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 14:39:27 -0700 Subject: newb In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 5:50 AM, whitey wrote: > On Tue, 27 Jul 2010 19:19:59 -0700, Mithrandir wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> On 07/27/2010 04:07 AM, whitey wrote: >>> hi all. am totally new to python and was wondering if there are any >>> newsgroups that are there specifically for beginners. i have bought a >>> book for $2 called "learn to program using python" by alan gauld. >>> starting to read it but it was written in 2001. presuming that the >>> commands and info would still be valid? any websites or books that are >>> a must for beginners? any input would be much appreciated...cheers >> >> It may also depend on which version of Python you wish to use. Since >> you're a "newb", I'd probably suggest starting off with Python 3. The >> version in your book is probably version 2.*. The difference is minor, >> but, when you're starting off (I assume with computer languages in >> general?) the difference in syntax can kick you where it hurts. Programs >> that work with Python 2.*, may not work with Python 3. However, I >> suggest Python 3 since it seems to be the "code of tomorrow." >> >> It may also depend on what you wish to do with your knowledge of Python >> (applications, games, web frameworks, etc.) If you want to make games, I >> suggest also learning about pyGame. >> >> As for book versus website, I started off with, as others have >> mentioned, learning online. Not only is it free, but the boundary >> between page and screen is broken. Note though that some off-sites >> (Wikibooks for instance) may not be complete in their writing. >> Python.org has a wealth of knowledge about almost everything involving >> Python. However, *some* of the documentation there may not be suitable >> for absolute beginners. There are several links there to other good >> websites for those with no experience in coding, all the way up to a >> ridiculously complicated level. I highly suggest poking around there. >> >> If you wish to read a book instead, try: >> http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/ > dp/1435455002/ >> Or go to your local library and poke there. :) >> >> Good luck! >> >> - -- >> People should read more. >> https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All >> that is gold does not glitter, >> not all those who wander are lost; >> the old that is strong does not wither, deep roots are not reached by >> the frost. - From the ashes a fire shall be woken, a light from the >> shadows shall spring; renewed shall be blade that was broken, the >> crownless again shall be king." >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.10 (GNU/Linux) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ >> >> iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI >> 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH >> yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim >> Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw >> pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 >> x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW >> -----END PGP SIGNATURE----- > > thank you all for the info. will definately check out your suggested > links, really excited about learning to code and hopefully in the near > future will be able to contribute somehow to the community. see you > around... If you're new to programming overall, you might want to check out project euler too. Geremy Condra From sjmachin at lexicon.net Wed Jul 28 17:39:42 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jul 2010 14:39:42 -0700 (PDT) Subject: Ascii to Unicode. References: Message-ID: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> On Jul 29, 4:32?am, "Joe Goldthwaite" wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. ?I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > ? ? ? ? import unicodedata > > ? ? ? ? s = '\xe1\xfc' > ? ? ? ? print unicode(s,'latin1') > > The above works. ?When I try to convert my file however, I still get an > error; > > ? ? ? ? import unicodedata > > ? ? ? ? input = file('ascii.csv', 'r') > ? ? ? ? output = file('unicode.csv','w') > > ? ? ? ? for line in input.xreadlines(): > ? ? ? ? ? ? ? ? output.write(unicode(line,'latin1')) > > ? ? ? ? input.close() > ? ? ? ? output.close() > > Traceback (most recent call last): > ? File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > ? ? output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) > > I'm stuck using Python 2.4.4 which may be handling the strings differently > depending on if they're in the program or coming from the file. ?I just > haven't been able to figure out how to get the Unicode conversion working > from the file data. > > Can anyone explain what is going on? Hello hello ... you are running on Windows; the likelihood that you actually have data encoded in latin1 is very very small. Follow MRAB's answer but replace "latin1" by "cp1252". From krdean at gmail.com Wed Jul 28 17:44:04 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 14:44:04 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <4c507a92$0$1643$742ec2ed@news.sonic.net> Message-ID: <9147d851-d195-49d5-ad1b-ec1160324c71@u4g2000prn.googlegroups.com> On Jul 28, 12:44?pm, John Nagle wrote: > On 7/27/2010 2:36 PM, kBob wrote: > > > > > > > > > ? I created a script to access weather satellite imagery fron NOAA's > > ADDS. > > > ? It worked fine until recently with Python 2.6. > > > ? The company changed the Internet LAN connections to "Accept Automatic > > settings" and "Use automatic configuration script" > > > ? How do you get urllib.urlopen to use the the "automatic script" > > configuration? > > > ? This code worked recently, until the company implemented these LAN > > connections... > > > ? ? ?SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > latest_BWI_vis.jpg" > > ? ?Try > > https://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg > > ? ?The aviationweather.gov site will accept a HTTPS request. > > ? ?Maybe that will bypass whatever lame web proxy is in the way. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle- Hide quoted text - > > - Show quoted text - Same error - 10060. Thanks for the suggestion. Kelly From robert.faryabi at gmail.com Wed Jul 28 17:57:02 2010 From: robert.faryabi at gmail.com (Robert Faryabi) Date: Wed, 28 Jul 2010 17:57:02 -0400 Subject: Tabular Package: importing file Message-ID: Hi there; I'm using Tabular Package for manipulating tab-delimited data. There is a small problem that I cannot get my head around it. When I construct my tabarray from file, the black fields are replaced by "nan". Does any one knows how to just keep them as empty string (ie. ' ')? Thanks, -R -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 28 18:16:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Jul 2010 18:16:18 -0400 Subject: python terminology on classes In-Reply-To: <4c4f1731$0$1602$742ec2ed@news.sonic.net> References: <4c4e8801$0$14554$426a74cc@news.free.fr> <4c4f1731$0$1602$742ec2ed@news.sonic.net> Message-ID: On 7/27/2010 1:28 PM, John Nagle wrote: > Python 2.6 has a recently added "with" clause, borrowed from > LISP, for associating actions with scopes. This is supported for > files and locks, but setting your own object up for "with" > requires adding special methods to the object. "with" is less > convenient and more limited than RAII, but that's the direction > Python is going. This may be in preparation for a move to a real > garbage collector. I do not remember that being stated as part of the rationale for 'with', but just today someone noted that since 'with' replace most uses of deterministic refcount gc, there is not more scope for changing things, at least for builtin and user classes, as opposed to C-extension classes. -- Terry Jan Reedy From joe at goldthwaites.com Wed Jul 28 18:58:01 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 15:58:01 -0700 Subject: Ascii to Unicode. Message-ID: Thanks to all of you who responded. I guess I was working from the wrong premise. I was thinking that a file could write any kind of data and that once I had my Unicode string, I could just write it out with a standard file.write() operation. What is actually happening is the file.write() operation was generating the error until I re-encoded the string as utf-8. This is what worked; import unicodedata input = file('ascii.csv', 'rb') output = file('unicode.csv','wb') for line in input.xreadlines(): unicodestring = unicode(line, 'latin1') output.write(unicodestring.encode('utf-8')) # This second encode is what I was missing. input.close() output.close() A number of you pointed out what I was doing wrong but I couldn't understand it until I realized that the write operation didn't work until it was using a properly encoded Unicode string. I thought I was getting the error on the initial latin Unicode conversion not in the write operation. This still seems odd to me. I would have thought that the unicode function would return a properly encoded byte stream that could then simply be written to disk. Instead it seems like you have to re-encode the byte stream to some kind of escaped Ascii before it can be written back out. Thanks to all of you who took the time to respond. I really do appreciate it. I think with my mental block, I couldn't have figure it out without your help. From joe at goldthwaites.com Wed Jul 28 19:00:26 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 16:00:26 -0700 Subject: Ascii to Unicode. In-Reply-To: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> References: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> Message-ID: > Hello hello ... you are running on Windows; the likelihood that you > actually have data encoded in latin1 is very very small. Follow MRAB's > answer but replace "latin1" by "cp1252". I think you're right. The database I'm working with is a US zip code database. It gets updated monthly. The problem fields are some city names in Puerto Rico. I thought I had tried the cp1252 codec and that it didn't work. I tried it again and it works now so I was doing something else wrong. I agree that's probably what I should be using. Both latin1 and cp1252 produce the same output for the two characters I'm having the trouble with but I changed it to cp1252 anyway. I think it will avoid problems in the future Thanks John. From jgaynor at ncsa.uiuc.edu Wed Jul 28 19:41:37 2010 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Wed, 28 Jul 2010 18:41:37 -0500 (CDT) Subject: Newbie question regarding SSL and certificate verification Message-ID: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Hi, I am making a first large project in python and am having quite a bit of difficulty unscrambling various python versions and what they can/cannot do. To wit, I must communicate with certain services via https and am required to perform certificate verification on them. The problem is that I also have to do this under CentOS 5.5 which only uses python 2.4 as its default -- this is not negotiable. As near as I can tell from reading various posts, the https client does not do verification and there is no low-level SSL support to provide a workaround. Near as I can tell from reading, 2.6 does include this. Am I getting this right? Is there a simple way to do this? More to the point, I need to know pretty darn quick if this is impossible so we can try and plan for it. So the quick question: Has anyone done certificate verification using 2.4 and if so, how? Thanks! From debatem1 at gmail.com Wed Jul 28 21:26:05 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 18:26:05 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey Gaynor wrote: > Hi, > > I am making a first large project in python and am having quite a bit of difficulty unscrambling various python versions and what they can/cannot do. To wit, I must communicate with certain services via https and am required to perform ?certificate verification on them. > > The problem is that I also have to do this under CentOS 5.5 which only uses python 2.4 as its default -- this is not negotiable. As near as I can tell from reading various posts, the https client does not do verification and there is no low-level SSL ?support to provide a workaround. Near as I can tell from reading, 2.6 does include this. Am I getting this right? Is there a simple way to do this? More to the point, I need to know pretty darn quick if this is impossible so we can try and plan for it. > > So the quick question: Has anyone done certificate ?verification using 2.4 and if so, how? > > Thanks! M2Crypto is the way to go here. I think there's an example on their site. Geremy Condra From navkirats at gmail.com Wed Jul 28 21:47:17 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 07:17:17 +0530 Subject: Performance ordered dictionary vs normal dictionary Message-ID: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> Hi guys, I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? Regards, N4v From navkirats at gmail.com Wed Jul 28 22:00:34 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 07:30:34 +0530 Subject: Function parameter scope Message-ID: Hi, I had another question: What is the scope of a parameter passed to a function? I know its a very basic question, but I am just sharpening my basics :) def func_something(x) return print(x+1); Does x become a local variable or does it stay as a module scoped variable? Though I think its local, but just want to be sure. Thanks, Nav From clp2 at rebertia.com Wed Jul 28 22:01:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 19:01:10 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 6:47 PM, Navkirat Singh wrote: > Hi guys, > > I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? Your question is rather vague. Define "book keeping". Why do you feel an OrderedDict might be useful in solving your problem? Cheers, Chris From clp2 at rebertia.com Wed Jul 28 22:05:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 19:05:53 -0700 Subject: Function parameter scope In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 7:00 PM, Navkirat Singh wrote: > Hi, > > I had another question: > > What is the scope of ?a parameter passed to a function? I know its a very basic question, but I am just sharpening my basics :) > > def func_something(x) > > ? ? ? ?return print(x+1); > > Does x become a local variable or does it stay as a module scoped variable? > > Though I think its local, but just want to be sure. Yes, it's indeed local. Also, you may wish to instead direct similar basic questions to the Python Tutor mailinglist in the future: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 22:45:26 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 02:45:26 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c50eb46$0$28664$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > On Jul 28, 7:32?am, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: >> > Thanks ... I thought int was a type-cast (like in C++) so I assumed I >> > couldn't reference it. >> >> Python doesn't have type-casts in the sense of "tell the compiler to >> treat object of type A as type B instead". The closest Python has to >> that is that if you have an instance of class A, you can do this: >> >> a = A() ?# make an instance of class A a.__class__ = B ?# tell it that >> it's now class B >> >> and hope that it won't explode when you try to use it :/ > > Type casts in C and non-pathlogical C++ don't modify the object they are > casting. > > int (and str, float, etc.) is the closest thing to a type cast in > Python. Perhaps I have been misinformed, but my understanding of C type-casts is that (where possible), a cast like `int(var)` merely tells the compiler to temporarily disregard the type of var and treat it as if it were an int. In other words, it's a compiler instruction rather than a conversion function. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 22:51:42 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 02:51:42 GMT Subject: Function parameter scope References: Message-ID: <4c50ecbe$0$28664$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 07:30:34 +0530, Navkirat Singh wrote: > Hi, > > I had another question: > > What is the scope of a parameter passed to a function? I know its a > very basic question, but I am just sharpening my basics :) > > def func_something(x) > return print(x+1); > > Does x become a local variable or does it stay as a module scoped > variable? > > Though I think its local, but just want to be sure. Yes, x is local. However, be careful that Python does not make a copy of arguments passed to functions. So the local name refers to the same underlying object as the global name, and *modifications* to the *object* will be seen everywhere. But *reassignments* to the *name* are only seen locally. def test(local_name): print(local_name) local_name = 2 print(local_name) print(global_name) global_name = 1 test(global_name) => prints 1, 2, 1. def test(local_name): print(local_name) local_name.append(2) print(local_name) print(global_name) global_name = [1] test(global_name) => prints [1], [1, 2], [1, 2]. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 23:27:05 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 03:27:05 GMT Subject: Ascii to Unicode. References: Message-ID: <4c50f508$0$28664$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 15:58:01 -0700, Joe Goldthwaite wrote: > This still seems odd to me. I would have thought that the unicode > function would return a properly encoded byte stream that could then > simply be written to disk. Instead it seems like you have to re-encode > the byte stream to some kind of escaped Ascii before it can be written > back out. I'm afraid that's not even wrong. The unicode function returns a unicode string object, not a byte-stream, just as the list function returns a sequence of objects, not a byte-stream. Perhaps this will help: http://www.joelonsoftware.com/articles/Unicode.html Summary: ASCII is not a synonym for bytes, no matter what some English-speakers think. ASCII is an encoding from bytes like \x41 to characters like "A". Unicode strings are a sequence of code points. A code point is a number, implemented in some complex fashion that you don't need to care about. Each code point maps conceptually to a letter; for example, the English letter A is represented by the code point U+0041 and the Arabic letter Ain is represented by the code point U+0639. You shouldn't make any assumptions about the size of each code-point, or how they are put together. You shouldn't expect to write code points to a disk and have the result make sense, any more than you could expect to write a sequence of tuples or sets or dicts to disk in any sensible fashion. You have to serialise it to bytes first, and that's what the encode method does. Decode does the opposite, taking bytes and creating unicode strings from them. For historical reasons -- backwards compatibility with files already created, back in the Bad Old Days before unicode -- there are a whole slew of different encodings available. There is no 1:1 mapping between bytes and strings. If all you have are the bytes, there is literally no way of knowing what string they represent (although sometimes you can guess). You need to know what the encoding used was, or take a guess, or make repeated decodings until something doesn't fail and hope that's the right one. As a general rule, Python will try encoding/decoding using the ASCII encoding unless you tell it differently. Any time you are writing to disk, you need to serialise the objects, regardless of whether they are floats, or dicts, or unicode strings. -- Steven From sturlamolden at yahoo.no Thu Jul 29 00:06:13 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 28 Jul 2010 21:06:13 -0700 (PDT) Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: On 29 Jul, 03:47, Navkirat Singh wrote: > I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? It depends on the problem. A dictionary is a hash table. An ordered dictionary is a binary search tree (BST). Those are different data structures. The main things to note is that: - Access is best-case O(1) for the hash table and O(log n) for the BST. - Worst case behavior is for access is O(n) for both. The pathologic conditions are excessive collisions (hash) or an unbalanced tree (BST). In pathologic cases they both converge towards a linked list. - Searches are only meaningful for == and != for a hash table, but BST searches are also meaningful for >, <, <=, and >=. For this reason, databases are often implemented as BSTs. - A BST can be more friendly to cache than a hash table, particularly when they are large. (Remember that O(1) can be slower than O(log n). Big-O only says how run-time scales with n.) That said, I have not compared ordered dicts with normal dicts, as I still use 2.6. From navkirats at gmail.com Thu Jul 29 00:22:36 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 09:52:36 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: On 29-Jul-2010, at 9:36 AM, sturlamolden wrote: > On 29 Jul, 03:47, Navkirat Singh wrote: > >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Those are different data > structures. > > The main things to note is that: > > - Access is best-case O(1) for the hash table and O(log n) for the > BST. > > - Worst case behavior is for access is O(n) for both. The pathologic > conditions are excessive collisions (hash) or an unbalanced tree > (BST). In pathologic cases they both converge towards a linked list. > > - Searches are only meaningful for == and != for a hash table, but BST > searches are also meaningful for >, <, <=, and >=. For this reason, > databases are often implemented as BSTs. > > - A BST can be more friendly to cache than a hash table, particularly > when they are large. (Remember that O(1) can be slower than O(log n). > Big-O only says how run-time scales with n.) > > That said, I have not compared ordered dicts with normal dicts, as I > still use 2.6. > > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list Thanks for the insight. I am still in the thinking stage, so will let you know as and when I get down to implementation of my idea. Thanks for your time. : ) Regards, Nav From nagle at animats.com Thu Jul 29 01:08:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 22:08:57 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: <4c510ce5$0$1587$742ec2ed@news.sonic.net> On 7/28/2010 6:26 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey > Gaynor wrote: >> Hi, >> >> I am making a first large project in python and am having quite a >> bit of difficulty unscrambling various python versions and what >> they can/cannot do. To wit, I must communicate with certain >> services via https and am required to perform certificate >> verification on them. >> >> The problem is that I also have to do this under CentOS 5.5 which >> only uses python 2.4 as its default -- this is not negotiable. As >> near as I can tell from reading various posts, the https client >> does not do verification and there is no low-level SSL support to >> provide a workaround. Near as I can tell from reading, 2.6 does >> include this. Am I getting this right? Is there a simple way to do >> this? More to the point, I need to know pretty darn quick if this >> is impossible so we can try and plan for it. >> >> So the quick question: Has anyone done certificate verification >> using 2.4 and if so, how? >> >> Thanks! > > M2Crypto is the way to go here. I think there's an example on their > site. M2Crypto does that job quite well. Installing M2Crypto tends to be painful if you have to build it, though. See if you can find a pre- built version. You then need a "cacert.pem" file, with the root certificates you're going to trust. You can get one from http://curl.haxx.se/docs/caextract.html which converts Mozilla's format to a .pem file once a week. The actual Mozilla source file is at http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt but M2Crypto needs it in .pem format. The new Python SSL module in 2.6 and later has a huge built-in security hole - it doesn't verify the domain against the certificate. As someone else put it, this means "you get to talk securely with your attacker." As long as the site or proxy has some valid SSL cert, any valid SSL cert copied from anywhere, the new Python SSL module will tell you everything is just fine. John Nagle From debatem1 at gmail.com Thu Jul 29 01:23:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 22:23:48 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <4c510ce5$0$1587$742ec2ed@news.sonic.net> References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: On Wed, Jul 28, 2010 at 10:08 PM, John Nagle wrote: > On 7/28/2010 6:26 PM, geremy condra wrote: >> >> On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey >> Gaynor ?wrote: >>> >>> Hi, >>> >>> I am making a first large project in python and am having quite a >>> bit of difficulty unscrambling various python versions and what >>> they can/cannot do. To wit, I must communicate with certain >>> services via https and am required to perform ?certificate >>> verification on them. >>> >>> The problem is that I also have to do this under CentOS 5.5 which >>> only uses python 2.4 as its default -- this is not negotiable. As >>> near as I can tell from reading various posts, the https client >>> does not do verification and there is no low-level SSL ?support to >>> provide a workaround. Near as I can tell from reading, 2.6 does >>> include this. Am I getting this right? Is there a simple way to do >>> this? More to the point, I need to know pretty darn quick if this >>> is impossible so we can try and plan for it. >>> >>> So the quick question: Has anyone done certificate ?verification >>> using 2.4 and if so, how? >>> >>> Thanks! >> >> M2Crypto is the way to go here. I think there's an example on their >> site. > > ? M2Crypto does that job quite well. ?Installing M2Crypto tends to be > painful if you have to build it, though. ?See if you can find a pre- > built version. > > ? You then need a "cacert.pem" file, with the root certificates you're > going to trust. ?You can get one from > > ? ? ? ?http://curl.haxx.se/docs/caextract.html > > which converts Mozilla's format to a .pem file once a week. > The actual Mozilla source file is at > > http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt > > ? but M2Crypto needs it in .pem format. > > ? The new Python SSL module in 2.6 and later has a huge built-in > security hole - it doesn't verify the domain against the > certificate. ?As someone else put it, this means "you get to > talk securely with your attacker." As long as the site or proxy > has some valid SSL cert, any valid SSL cert copied from anywhere, > the new Python SSL module will tell you everything is just fine. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle Did anything ever come of the discussion that you and Antoine had? Geremy Condra PS- the quote is due to Justin Samuel From nagle at animats.com Thu Jul 29 01:45:19 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 22:45:19 -0700 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4c503f75$0$11091$c3e8da3@news.astraweb.com> References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c51156b$0$1604$742ec2ed@news.sonic.net> On 7/28/2010 7:32 AM, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> Thanks ... I thought int was a type-cast (like in C++) so I assumed I >> couldn't reference it. > > Python doesn't have type-casts in the sense of "tell the compiler to > treat object of type A as type B instead". The closest Python has to that > is that if you have an instance of class A, you can do this: > > a = A() # make an instance of class A > a.__class__ = B # tell it that it's now class B > > and hope that it won't explode when you try to use it :/ > > I make that seem like a dangerous thing to do, but it's not really. There > actually are sensible use-cases for such a thing, you can't do it to > built-ins (which would be dangerous!), and the worst that will happen > with classes written in Python is they'll raise an exception when you try > calling a method, rather than dump core. The main use for that sort of thing is in constructing objects without their cooperation. "copy" and "pickle" do that, as they build up objects without running their initializers. Arguably, that would be better done with a built-in function for creating arbitrary objects. Something like: x = new_object("classname", (("attr1", val1), ("attr2", val2))) to create a new object in one atomic operation. Storing into "__class__" may not be portable across Python implementations. The implications for multiple inheritance are difficult. It's really a hack for CPython. John Nagle From antonyjeevaraj at rediffmail.com Thu Jul 29 02:04:56 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Wed, 28 Jul 2010 23:04:56 -0700 (PDT) Subject: CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME Message-ID: <5dea4918-cce8-4a0c-b9f3-09540b6e90c9@z34g2000pro.googlegroups.com> CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME Work with online free cpa network learn how to work from your home by using cpa offers Great payout methods( cheque,paypal,wire transfer) No investment Earn from $2-$44 per lead EARN $5 PER REFERRED AFFILIATES Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://timmyurl.com/awesomeearnings Get paid for real work from online From clp2 at rebertia.com Thu Jul 29 02:05:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 23:05:29 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 9:06 PM, sturlamolden wrote: > On 29 Jul, 03:47, Navkirat Singh wrote: >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Er, if you're talking about collections.OrderedDict specifically, you're wrong. It's quite clearly implemented using a regular dictionary (i.e. hash table) and auxiliary list: See http://bugs.python.org/file13231/od7.diff from http://bugs.python.org/issue5397 Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Thu Jul 29 02:11:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 23:11:14 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh wrote: > Sorry, I might have been a bit vague: > (Also, I am new to pythong) > I am trying to do construct my own web session tracking algorithm for a web > server (which also I have constructed). The book keeping is for the session > information I track. The dictionary object will do this for me. I was > initially using a plain dictionary object, but I read this in the > documentation that made me think about the question I asked :- Does your program actually make use of the ordering? If so, then yes, using OrderedDict is obviously preferable (Why reimplement something needlessly?). If not, then why bother with the extra complication? (You are aware that the "ordered" in OrderedDict means that its keys are ordered, and not that, say, a list containing OrderedDicts can be sorted, right?) Cheers, Chris -- http://blog.rebertia.com From navkirats at gmail.com Thu Jul 29 02:18:37 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 11:48:37 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: <63EF7177-0A96-461E-BDD5-520FC1186EF0@gmail.com> On 29-Jul-2010, at 11:41 AM, Chris Rebert wrote: > On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh wrote: >> Sorry, I might have been a bit vague: >> (Also, I am new to pythong) >> I am trying to do construct my own web session tracking algorithm for a web >> server (which also I have constructed). The book keeping is for the session >> information I track. The dictionary object will do this for me. I was >> initially using a plain dictionary object, but I read this in the >> documentation that made me think about the question I asked :- > > Does your program actually make use of the ordering? If so, then yes, > using OrderedDict is obviously preferable (Why reimplement something > needlessly?). If not, then why bother with the extra complication? > > (You are aware that the "ordered" in OrderedDict means that its keys > are ordered, and not that, say, a list containing OrderedDicts can be > sorted, right?) > > Cheers, > Chris > -- > http://blog.rebertia.com I am still in the analysis phase/experimental phase and the need might arise. Hence, I just wanted to know my options. If a collections object will improve performance than an ordinary dictionary, then yes I would like to go with the OrderedDict. Thanks, Nav From steve-REMOVE-THIS at cybersource.com.au Thu Jul 29 02:24:36 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 06:24:36 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c51156b$0$1604$742ec2ed@news.sonic.net> Message-ID: <4c511ea4$0$11117$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 22:45:19 -0700, John Nagle wrote: [...] >> if you have an instance of class A, you can do this: >> >> a = A() # make an instance of class A >> a.__class__ = B # tell it that it's now class B >> >> and hope that it won't explode when you try to use it :/ [...] > The main use for that sort of thing is in constructing objects > without their cooperation. "copy" and "pickle" do that, as they build > up objects without running their initializers. True, but there are other use-cases as well, such as the recipe for ring buffer which made it into the Python Cookbook. I think this is it: http://code.activestate.com/recipes/68429-ring-buffer/ > Storing into "__class__" > may not be portable across Python implementations. The implications for > multiple inheritance are difficult. It's really a hack for CPython. I believe that it is intended as a language feature, not an implementation-specific hack: http://bytes.com/topic/python/answers/449635-assigning-self-__class__ While it's an advanced technique that isn't terribly common, I don't see any reason to avoid it. -- Steven From eckhardt at satorlaser.com Thu Jul 29 03:21:37 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 09:21:37 +0200 Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> Message-ID: <1pm7i7-473.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Perhaps I have been misinformed, but my understanding of C type-casts is > that (where possible), a cast like `int(var)` merely tells the compiler > to temporarily disregard the type of var and treat it as if it were an > int. In other words, it's a compiler instruction rather than a conversion > function. You are misinformed. The result of a cast in C or C++ behaves as if a temporary was created: int x = 0; unsigned(x)--; // invalid, compiler error Now, where this distinction gets blurred is when you are casting pointers: (*(unsigned*)&x)--; or, in C++, references: reinterpret_cast(x)--; Technically, these are still invalid though, only that they give you undefined behaviour at runtime instead of a compiler error, but those are already very fine details of the according standards. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From eckhardt at satorlaser.com Thu Jul 29 03:25:23 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 09:25:23 +0200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> <8bb2reF616U1@mid.individual.net> Message-ID: <30n7i7-473.ln1@satorlaser.homedns.org> Neil Cerutti wrote: > Perhaps emailing the tests to yourself would be a good solution. > Every tme the tests ran, you'd get a new email containing the > results. Nice idea, only that it's even less portable and requires manual setup... ;^) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From anand.shashwat at gmail.com Thu Jul 29 03:49:31 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 29 Jul 2010 13:19:31 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: > > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Those are different data > structures. > > The main things to note is that: > > - Access is best-case O(1) for the hash table and O(log n) for the > BST. > > - Worst case behavior is for access is O(n) for both. The pathologic > conditions are excessive collisions (hash) or an unbalanced tree > (BST). In pathologic cases they both converge towards a linked list. > > - Searches are only meaningful for == and != for a hash table, but BST > searches are also meaningful for >, <, <=, and >=. For this reason, > databases are often implemented as BSTs. > > - A BST can be more friendly to cache than a hash table, particularly > when they are large. (Remember that O(1) can be slower than O(log n). > Big-O only says how run-time scales with n.) > > Thanks, this was really insightful :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From raymond.hettinger at gmail.com Thu Jul 29 04:12:38 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Thu, 29 Jul 2010 01:12:38 -0700 (PDT) Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: On Jul 28, 6:47?pm, Navkirat Singh wrote: > I was wondering what would be better to do some medium > to heavy book keeping in memory - Ordered Dictionary > or a plain simple Dictionary object?? The current implementation of OrderedDict is based on regular dictionaries, so it performance cannot be better than a regular dictionary for the usual mapping operations. Some accessor methods like __getitem__(), __len__(), __contains__(), and get() are pass throughs, so their performance is the same. Most of the rest of the methods are order aware and are slower by a constant factor. So, if you don't need the ordering feature, then you're better-off with a regular dictionary. A potential future implementation for OrderedDict written in C would have nearly identical performance as regular dicts for most operations and slightly improved performance for iteration. Raymond From steve-REMOVE-THIS at cybersource.com.au Thu Jul 29 04:28:26 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 08:28:26 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> <1pm7i7-473.ln1@satorlaser.homedns.org> Message-ID: <4c513baa$0$11120$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 09:21:37 +0200, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: >> Perhaps I have been misinformed, but my understanding of C type-casts >> is that (where possible), a cast like `int(var)` merely tells the >> compiler to temporarily disregard the type of var and treat it as if it >> were an int. In other words, it's a compiler instruction rather than a >> conversion function. > > You are misinformed. The result of a cast in C or C++ behaves as if a > temporary was created: Fair enough. Thank you. -- Steven From pdwjfndjbdgfyg at gmail.com Thu Jul 29 04:42:34 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Thu, 29 Jul 2010 01:42:34 -0700 (PDT) Subject: HOT BEST YOUTH VIDEOS Message-ID: <81e337f9-fae9-42cb-8399-ae914f8c24be@q21g2000prm.googlegroups.com> FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From hniksic at xemacs.org Thu Jul 29 05:20:17 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 29 Jul 2010 11:20:17 +0200 Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: <87y6cuejam.fsf@busola.homelinux.net> sturlamolden writes: > On 29 Jul, 03:47, Navkirat Singh wrote: > >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). The ordered dictionary shipped with Python is also a hash table, with an internal list to keep track of item order. The one thing not mentioned in the thread is that ordered dict's deletion is O(n), which might impact "heavy bookkeeping". As Raymond said, where order doesn't matter, it's best to stick with dict. From jeanmichel at sequans.com Thu Jul 29 05:35:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 11:35:05 +0200 Subject: loading configuration files that are themselves python In-Reply-To: <87mxth66pc.fsf@benfinney.id.au> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> <87mxth66pc.fsf@benfinney.id.au> Message-ID: <4C514B49.4070607@sequans.com> Ben Finney wrote: > Lawrence D'Oliveiro writes: > > >> In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: >> >> >>> Is there a more idiomatic way of loading in a configuration file >>> that's python code ... >>> >> Is it really a good idea to have a configuration language that?s Turing- >> complete? >> > > I think not. Configuration files should be read as data; they should be > declarative only, not executable languages. That way, a different > program can read and parse them without having to be a parser for an > entire programming language. > For local non distributed applications, configuration files written in python are just fine. JM From jeanmichel at sequans.com Thu Jul 29 05:43:14 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 11:43:14 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C514D32.8040807@sequans.com> Robert Kern wrote: > On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: >> In message, >> Robert Kern >> wrote: >> >>> There are also utilities for mounting ISOs directly without burning >>> them >>> to a physical disk. >> >> You need special utilities to do this?? > > On at least some versions of Windows, Yes. > You need the "mount" utility with Linux. JM From jkordani at intlogsys.com Thu Jul 29 05:47:13 2010 From: jkordani at intlogsys.com (Joshua Kordani) Date: Thu, 29 Jul 2010 05:47:13 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C514D32.8040807@sequans.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> <4C514D32.8040807@sequans.com> Message-ID: <4C514E21.5040409@intlogsys.com> Jean-Michel Pichavant wrote: > Robert Kern wrote: >> On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: >>> In message, >>> Robert Kern >>> wrote: >>> >>>> There are also utilities for mounting ISOs directly without burning >>>> them >>>> to a physical disk. >>> >>> You need special utilities to do this?? >> >> On at least some versions of Windows, Yes. >> > You need the "mount" utility with Linux. > > JM On Windows see Daemon-tools lite. free, easy, no spyware. From jeanmichel at sequans.com Thu Jul 29 06:08:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 12:08:54 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> Message-ID: <4C515336.4030807@sequans.com> Steven D'Aprano wrote: > On Sun, 25 Jul 2010 13:58:00 +1200, Gregory Ewing wrote: > > >> Lacrima wrote: >> >> >>> But what if SuperClass1 is from third party library? >>> >> If it hasn't been designed for super(), then you can't use super() with >> it. >> >> super() only works when *every* class in the hierarchy has been designed >> with it in mind. >> > > > That incorrect. You can certainly use super() with classic classes in the > hierarchy, and super() didn't even exist when they were created. > > > >>>> class Parent: >>>> > ... def method(self, arg): > ... return repr(arg) > ... > >>>> class Classic(Parent): >>>> > ... def method(self, arg): > ... return "argument was %s" % Parent.method(self, arg) > ... > >>>> class New(object, Classic): >>>> > ... def method(self, arg): > ... return super(New, self).method(arg).upper() > ... > >>>> x = New() >>>> x.method('spam') >>>> > "ARGUMENT WAS 'SPAM'" > > > The problem isn't super(), and people who give glib advise "don't use > super()" are just compounding the problem. The problem is with multiple > inheritance where methods have different method signatures. If you don't > change the method signatures, super() will work fine. > > Advising people not to use super() might make people feel virtuous, but > it doesn't do anything to help the reader write non-buggy MI hierarchies. > It pushes the effort of dealing with multiple inheritance onto them, > forcing them to re-implement the MRO, probably badly. Can you re- > implement the C3 algorithm? Have you even heard of it? If you answer No > to either of those questions, chances are high that trying to deal with > the MRO manually will lead to worse bugs than using super(). > > Should you use super()? > > 1. If you're doing multiple inheritance with metaclasses, you MUST use > super(). > > 2. If you're using single inheritance only, and never modify method > signatures, there is no reason not to use super(). > > 3. If you're using mixins, you should use super(). > > 4. If you never modify method signatures, then you should use super(). > > 5. If you do modify method signatures, you shouldn't do that (except > possibly in constructors, and even there only cautiously). But if you do > it anyway, then you should use super() *except* in the methods where you > modify the signature. > > 6. If you don't use super(), chances are that your class hierarchy is > still buggy, but instead of failing loudly and noisily with an exception, > it's silently giving the wrong results. > > 7. If you can avoid multiple inheritance in favour of another technique > (such as composition), you should strongly consider that. > > > > I think you're missing the point that super for most of us is a dangerous guess game. It makes implicit what would *really* need to be explicit. class Base1(object): def foo(self): print 'Base1' class Base2(object): def foo(self): print 'Base1' class Sub(Base1, Base2): def foo(self): # which base version to call ??? # choice A # use super an pray that it will do what I need (better know exactly how the MRO works) # also pray that further readers know as much as I do about super # choice B # use explicit calls so I can choose which algorithm I want to use, calling Base1, Base2 or both of them # If the choice is too difficult, that means one thing => my inheritance design is crap => rewrite it properly. Super is known for being required for diamond inheritance, and this reputation is well earned. Outside this scope, super's not required. JM From navkirats at gmail.com Thu Jul 29 06:18:41 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 15:48:41 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <87y6cuejam.fsf@busola.homelinux.net> References: <87y6cuejam.fsf@busola.homelinux.net> Message-ID: On 29-Jul-2010, at 2:50 PM, Hrvoje Niksic wrote: > sturlamolden writes: > >> On 29 Jul, 03:47, Navkirat Singh wrote: >> >>> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? >> >> It depends on the problem. A dictionary is a hash table. An ordered >> dictionary is a binary search tree (BST). > > The ordered dictionary shipped with Python is also a hash table, with an > internal list to keep track of item order. > > The one thing not mentioned in the thread is that ordered dict's > deletion is O(n), which might impact "heavy bookkeeping". As Raymond > said, where order doesn't matter, it's best to stick with dict. > -- > http://mail.python.org/mailman/listinfo/python-list Thanks that was an excellent point : ) From eckhardt at satorlaser.com Thu Jul 29 07:50:25 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 13:50:25 +0200 Subject: Ascii to Unicode. References: Message-ID: <1h68i7-534.ln1@satorlaser.homedns.org> Joe Goldthwaite wrote: > import unicodedata > > input = file('ascii.csv', 'rb') > output = file('unicode.csv','wb') > > for line in input.xreadlines(): > unicodestring = unicode(line, 'latin1') > output.write(unicodestring.encode('utf-8')) # This second encode > is what I was missing. Actually, I see two problems here: 1. "ascii.csv" is not an ASCII file but a Latin-1 encoded file, so there starts the first confusion. 2. "unicode.csv" is not a "Unicode" file, because Unicode is not a file format. Rather, it is a UTF-8 encoded file, which is one encoding of Unicode. This is the second confusion. > A number of you pointed out what I was doing wrong but I couldn't > understand it until I realized that the write operation didn't work until > it was using a properly encoded Unicode string. The write function wants bytes! Encoding a string in your favourite encoding yields bytes. > This still seems odd to me. I would have thought that the unicode > function would return a properly encoded byte stream that could then > simply be written to disk. No, unicode() takes a byte stream and decodes it according to the given encoding. You then get an internal representation of the string, a unicode object. This representation typically resembles UCS2 or UCS4, which are more suitable for internal manipulation than UTF-8. This object is a string btw, so typical stuff like concatenation etc are supported. However, the internal representation is a sequence of Unicode codepoints but not a guaranteed sequence of bytes which is what you want in a file. > Instead it seems like you have to re-encode the byte stream to some > kind of escaped Ascii before it can be written back out. As mentioned above, you have a string. For writing, that string needs to be transformed to bytes again. Note: You can also configure a file to read one encoding or write another. You then get unicode objects from the input which you can feed to the output. The important difference is that you only specify the encoding in one place and it will probably even be more performant. I'd have to search to find you the according library calls though, but starting point is http://docs.python.org. Good luck! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From imran.raza460 at gmail.com Thu Jul 29 07:50:48 2010 From: imran.raza460 at gmail.com (tania) Date: Thu, 29 Jul 2010 04:50:48 -0700 (PDT) Subject: WHAT A CHICAGO SEX ON THE ROAD.ENJOY IT Message-ID: <5fa23dd2-fa90-4a12-875e-fec7cca47c7b@y32g2000prc.googlegroups.com> http://www.bigextracash.com/aft/9b6cc578.html also click here to see and enjoy From williamj at tenbase2.com Thu Jul 29 08:12:30 2010 From: williamj at tenbase2.com (William Johnston) Date: Thu, 29 Jul 2010 08:12:30 -0400 Subject: write xml to txt encoding Message-ID: <002101cb2f17$5318d240$f94a76c0$@com> Hello, I have a Python app that parses XML files and then writes to text files. However, the output text file is "sometimes" encoded in some Asian language. Here is my code: encoding = "iso-8859-1" clean_sent = nltk.clean_html(sent.text) clean_sent = clean_sent.encode(encoding, "ignore"); I also tried "UTF-8" encoding, but received the same results. Any suggestions? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nt_mahmood at yahoo.com Thu Jul 29 08:34:01 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Thu, 29 Jul 2010 05:34:01 -0700 (PDT) Subject: measuring a function time Message-ID: <831343.82061.qm@web50006.mail.re2.yahoo.com> Hi, I want to measure a function run time. I read http://docs.python.org/library/time.html?but I?am confused and don't know which one is suitable. I don't?know is daylight timing important or not.... or is?Y2K issue important for my case or not....?I also don't know how epoch time is related to my work. I just want to do this (pseudocode): start_time = get_current_time; function(); end_time = get_current_time; print (end_time - start_time) the output?should be 7600 (s) for example. What is the best and easiest way to do that? Thanks, ? // Naderan *Mahmood; -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Thu Jul 29 08:42:58 2010 From: landimatte at gmail.com (Matteo Landi) Date: Thu, 29 Jul 2010 14:42:58 +0200 Subject: measuring a function time In-Reply-To: <831343.82061.qm@web50006.mail.re2.yahoo.com> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: This should be enough >>>import time >>>tic = time.time() >>>function() >>>toc = time.time() >>>print toc - tic On Thu, Jul 29, 2010 at 2:34 PM, Mahmood Naderan wrote: > Hi, > I want to measure a function run time. I read > http://docs.python.org/library/time.html?but I?am confused and don't know > which one is suitable. I don't?know is daylight timing important or not.... > or is?Y2K issue important for my case or not....?I also don't know how epoch > time is related to my work. > > I just want to do this (pseudocode): > start_time = get_current_time; > function(); > end_time = get_current_time; > print (end_time - start_time) > > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? > > Thanks, > > // Naderan *Mahmood; > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From goon12 at gmail.com Thu Jul 29 08:45:23 2010 From: goon12 at gmail.com (Joe Riopel) Date: Thu, 29 Jul 2010 08:45:23 -0400 Subject: measuring a function time In-Reply-To: <831343.82061.qm@web50006.mail.re2.yahoo.com> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? Take a look at time.clock() http://docs.python.org/library/time.html#time.clock "this is the function to use for benchmarking Python or timing algorithms." From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 08:48:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 12:48:46 GMT Subject: measuring a function time References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <4c5178ae$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > This should be enough > >>>>import time >>>>tic = time.time() >>>>function() >>>>toc = time.time() >>>>print toc - tic You're typing that in the interactive interpreter, which means the timer is counting the seconds while you're typing subsequent commands. At the very least, you need to put that code into a function. More importantly, the above technique is acceptable if function() is very long-running (multiple seconds, at least). If it is quick, or a code- snippet, the time you measure will be dominated by random chance. The best way to time small code snippets and fast functions is with the timeit module. -- Steven From stefan_ml at behnel.de Thu Jul 29 08:54:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 29 Jul 2010 14:54:54 +0200 Subject: write xml to txt encoding In-Reply-To: <002101cb2f17$5318d240$f94a76c0$@com> References: <002101cb2f17$5318d240$f94a76c0$@com> Message-ID: William Johnston, 29.07.2010 14:12: > I have a Python app that parses XML files and then writes to text files. XML or HTML? > However, the output text file is "sometimes" encoded in some Asian language. > > Here is my code: > > > encoding = "iso-8859-1" > > clean_sent = nltk.clean_html(sent.text) > > clean_sent = clean_sent.encode(encoding, "ignore"); > > > I also tried "UTF-8" encoding, but received the same results. What result? Maybe the NLTK cannot determine the encoding of the HTML file (because the file is broken and/or doesn't correctly specify its own encoding) and thus fails to decode it? Stefan From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 08:55:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 12:55:53 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> Message-ID: <4c517a58$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 12:08:54 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> That incorrect. You can certainly use super() with classic classes in >> the hierarchy, and super() didn't even exist when they were created. >> The problem isn't super(), and people who give glib advise "don't use >> super()" are just compounding the problem. The problem is with multiple >> inheritance where methods have different method signatures. If you >> don't change the method signatures, super() will work fine. [...] > I think you're missing the point that super for most of us is a > dangerous guess game. It makes implicit what would *really* need to be > explicit. No, I'm not missing the point. I'm *disagreeing* with the point. I'm saying that for simple inheritance hierarchies, super() does no harm, and it is *required* for most complex inheritance hierarchies. Given that, why not use it? I suppose that, if you're inheriting from an existing class which doesn't use super(), there may be issues (although I'm not convinced that those issues go away if you avoid super!) but for a new class under your control, there are no negatives to super() that didn't already exist with the nature of multiple inheritance. There is, as far as I can tell, ONE use-case where super() must be avoided, and that is a use-case that is discouraged for other reasons: where you change the method signature. If you're changing the method signature, you're already in dubious territory and better know what you're doing. You're violating the Liskov Substitution Principle, and if so, you better have a good reason. (I'm a bit skeptical about the LSP, but many people much smarter than I think it's virtually gospel, so who knows?) But either way, if you change the method signature, you're going to have problems somewhere unless you've really careful. The problems with super() are merely symptoms of that change. If you don't change the method signature, then I don't believe super() does any harm, regardless of whether you have single inheritance or multiple inheritance, whether it is a diamond diagram or not. The worst that can be said about it is that super()'s signature is hard to understand. I would argue that your argument about "explicit" and "implicit" is incorrect. You shouldn't want to explicitly specify which class you are inheriting from, at least not under normal circumstances. It is enough to say that you are inheriting behaviour. If you have a Widget class, and you find yourself explicitly calling methods by *named* superclasses, you're probably doing something wrong. It should always be possible to insert a class higher up the hierarchy, or rename a grandparent, without effecting your class. (Obviously you can't expect to rename an immediate parent class.) super() is just as explicit as len(), or str.upper(). It says, explicitly, that it will call the method belonging to one or more superclass of the given class. That's no more implicit than mylist[5] is implicit merely because you didn't have to walk the list by hand. > class Base1(object): > def foo(self): > print 'Base1' > > > class Base2(object): > def foo(self): > print 'Base1' > > > class Sub(Base1, Base2): > def foo(self): > # which base version to call ??? > # choice A > # use super an pray that it will do what I need (better > know exactly how the MRO works) But the point is, super() knows exactly how the MRO works, so you don't have to. > # also pray that further readers know as much as I do > about super Now that's just silly. Do you write all your classes for the lowest common denominator? Do you assume all you users are ignorant? If you subclass dict, do you feel the need to "pray" that your users won't try to use mutable objects as keys? If you avoid super(), do you "pray" that your users won't try to use your class in a multiple inheritance situation, and have a buggy class? I bet you don't. If they misuse your class, that's their responsibility. > # choice B > # use explicit calls so I can choose which algorithm I > want to use, calling Base1, Base2 or both of them That's a fair point. super() uses the standard MRO algorithm, it isn't a "Do What I Mean" mind- reading function. If you want an unusual MRO, then you're responsible for managing it yourself. Go right ahead, this is Python and you have all the tools to do so. Nothing forces you to inherit behaviour from the superclasses at all -- super() is designed for overloading (extending) the behaviour of methods, and so the assumption is that you want to call the method in each superclass. But if you're overriding the method instead, or doing something unusual, then you're in charge. > # If the choice is too difficult, that means one thing > => my inheritance design is crap => rewrite it properly. > > Super is known for being required for diamond inheritance, and this > reputation is well earned. Outside this scope, super's not required. Of course it's not required. Nor does it do any harm. Far from it -- your single inheritance subclass might be just what another user needs for a multiple inheritance class, and by not using super(), you ruin it for him. -- Steven From nt_mahmood at yahoo.com Thu Jul 29 09:38:08 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Thu, 29 Jul 2010 06:38:08 -0700 (PDT) Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <810979.37037.qm@web50005.mail.re2.yahoo.com> Thanks, the first method worked. However clock() doesn't. tic = time.time() time.sleep( 2 ) toc = time.time() print toc - tic ? Result: 2.00269889832 >Take a look at time.clock() tic = time.clock() time.sleep( 2 ) toc = time.clock() print toc - tic ? result: 0.0 >More importantly, the above technique is acceptable if function() is very >long-running (multiple seconds, at least). yes, the code is long running. Thanks // Naderan *Mahmood; ________________________________ From: Matteo Landi To: Mahmood Naderan Cc: python mailing list Sent: Thu, July 29, 2010 5:12:58 PM Subject: Re: measuring a function time This should be enough >>>import time >>>tic = time.time() >>>function() >>>toc = time.time() >>>print toc - tic On Thu, Jul 29, 2010 at 2:34 PM, Mahmood Naderan wrote: > Hi, > I want to measure a function run time. I read > http://docs.python.org/library/time.html?but I?am confused and don't know > which one is suitable. I don't?know is daylight timing important or not.... > or is?Y2K issue important for my case or not....?I also don't know how epoch > time is related to my work. > > I just want to do this (pseudocode): > start_time = get_current_time; > function(); > end_time = get_current_time; > print (end_time - start_time) > > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? > > Thanks, > > // Naderan *Mahmood; > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgaynor at ncsa.uiuc.edu Thu Jul 29 10:07:08 2010 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Thu, 29 Jul 2010 09:07:08 -0500 (CDT) Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Thank you! This is what I was looking for. A final question -- how widely is M2Crypto used? Since I will have to now pitch to our group that this is preferable the first questions they will ask are about stability, who is using it and how secure is it really, especially since it is at version 0.20.2 (i.e. no major release yet). Thanks again! Jeff ----- Original Message ----- From: "John Nagle" To: python-list at python.org Sent: Thursday, July 29, 2010 12:08:57 AM Subject: Re: Newbie question regarding SSL and certificate verification On 7/28/2010 6:26 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey > Gaynor wrote: >> Hi, >> >> I am making a first large project in python and am having quite a >> bit of difficulty unscrambling various python versions and what >> they can/cannot do. To wit, I must communicate with certain >> services via https and am required to perform certificate >> verification on them. >> >> The problem is that I also have to do this under CentOS 5.5 which >> only uses python 2.4 as its default -- this is not negotiable. As >> near as I can tell from reading various posts, the https client >> does not do verification and there is no low-level SSL support to >> provide a workaround. Near as I can tell from reading, 2.6 does >> include this. Am I getting this right? Is there a simple way to do >> this? More to the point, I need to know pretty darn quick if this >> is impossible so we can try and plan for it. >> >> So the quick question: Has anyone done certificate verification >> using 2.4 and if so, how? >> >> Thanks! > > M2Crypto is the way to go here. I think there's an example on their > site. M2Crypto does that job quite well. Installing M2Crypto tends to be painful if you have to build it, though. See if you can find a pre- built version. You then need a "cacert.pem" file, with the root certificates you're going to trust. You can get one from http://curl.haxx.se/docs/caextract.html which converts Mozilla's format to a .pem file once a week. The actual Mozilla source file is at http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt but M2Crypto needs it in .pem format. The new Python SSL module in 2.6 and later has a huge built-in security hole - it doesn't verify the domain against the certificate. As someone else put it, this means "you get to talk securely with your attacker." As long as the site or proxy has some valid SSL cert, any valid SSL cert copied from anywhere, the new Python SSL module will tell you everything is just fine. John Nagle -- http://mail.python.org/mailman/listinfo/python-list From darcy at druid.net Thu Jul 29 10:43:39 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 29 Jul 2010 10:43:39 -0400 Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <20100729104339.ab45755a.darcy@druid.net> On Thu, 29 Jul 2010 08:45:23 -0400 Joe Riopel wrote: > On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: > > the output?should be 7600 (s) for example. What is the best and easiest way > > to do that? > > Take a look at time.clock() I don't know if that's what he wants. The clock() method returns processor time, not wall time. Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 Type "help", "copyright", "credits" or "license" for more information. >>> from time import time, clock, sleep >>> t = time() >>> print time() - t, clock() 0.000596046447754 0.03 >>> sleep(3) >>> print time() - t, clock() 3.03474903107 0.03 >>> x = open("BIGFILE").read() >>> print time() - t, clock() 10.2008538246 1.42 -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From drobinow at gmail.com Thu Jul 29 10:54:39 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 29 Jul 2010 10:54:39 -0400 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: On Thu, Jul 29, 2010 at 10:07 AM, Jeffrey Gaynor wrote: > ... > A final question -- how widely is M2Crypto used? Since I will have to now pitch to our group that this is preferable the first questions they will ask are about stability, who is using it and how secure is it really, especially since it is at version 0.20.2 (i.e. no major release yet). I know very little about security, but one thing I think I know. Never use security software version 1.0 or greater. It was written by an author insufficiently paranoid. From lists at cheimes.de Thu Jul 29 11:03:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 29 Jul 2010 17:03:07 +0200 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: > I know very little about security, but one thing I think I know. Never > use security software version 1.0 or greater. It was written by an > author insufficiently paranoid. OpenSSL 1.0.0a was released about a month ago. ;) From pavlovevidence at gmail.com Thu Jul 29 11:29:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 29 Jul 2010 08:29:01 -0700 (PDT) Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> Message-ID: <38592ade-2116-4122-b915-5177c2851601@y32g2000prc.googlegroups.com> On Jul 28, 7:45?pm, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > > On Jul 28, 7:32?am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > >> > couldn't reference it. > > >> Python doesn't have type-casts in the sense of "tell the compiler to > >> treat object of type A as type B instead". The closest Python has to > >> that is that if you have an instance of class A, you can do this: > > >> a = A() ?# make an instance of class A a.__class__ = B ?# tell it that > >> it's now class B > > >> and hope that it won't explode when you try to use it :/ > > > Type casts in C and non-pathlogical C++ don't modify the object they are > > casting. > > > int (and str, float, etc.) is the closest thing to a type cast in > > Python. > > Perhaps I have been misinformed, but my understanding of C type-casts is > that (where possible), a cast like `int(var)` (int)var > merely tells the compiler > to temporarily disregard the type of var and treat it as if it were an > int. In other words, it's a compiler instruction rather than a conversion > function. Even if it did, it would still be temporary. The type of the variable remains unchanged. But it doesn't disregard the original type: type casts try to preserve semantic value. (double)1 returns 1.0, which is not only a different bit pattern but a different size. That's exactly what float() does in Python. Carl Banks From nagle at animats.com Thu Jul 29 12:08:32 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 09:08:32 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <4c51a77c$0$1675$742ec2ed@news.sonic.net> On 7/28/2010 10:23 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 10:08 PM, John Nagle wrote: >> On 7/28/2010 6:26 PM, geremy condra wrote: >>> >>> On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey >>> Gaynor wrote: > >> The new Python SSL module in 2.6 and later has a huge built-in >> security hole - it doesn't verify the domain against the >> certificate. As someone else put it, this means "you get to >> talk securely with your attacker." As long as the site or proxy >> has some valid SSL cert, any valid SSL cert copied from anywhere, >> the new Python SSL module will tell you everything is just fine. >> >> John Nagle > > Did anything ever come of the discussion that you and Antoine had? > > Geremy Condra > > PS- the quote is due to Justin Samuel I had to write my own domain check. Did anyone re-open the bug report on that issue? John Nagle From solipsis at pitrou.net Thu Jul 29 12:13:27 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 29 Jul 2010 18:13:27 +0200 Subject: Newbie question regarding SSL and certificate verification References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <20100729181327.74211dc6@pitrou.net> On Wed, 28 Jul 2010 22:23:48 -0700 geremy condra wrote: > > > > ? The new Python SSL module in 2.6 and later has a huge built-in > > security hole - it doesn't verify the domain against the > > certificate. ?As someone else put it, this means "you get to > > talk securely with your attacker." As long as the site or proxy > > has some valid SSL cert, any valid SSL cert copied from anywhere, > > the new Python SSL module will tell you everything is just fine. > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > > Did anything ever come of the discussion that you and Antoine had? As I wrote in http://bugs.python.org/issue1589, I would support adding the necessary function(s) to the SSL module, and have urllib (and other stdlib modules) support them. Someone needs to write a patch, though. Regards Antoine. From jimgardener at gmail.com Thu Jul 29 12:51:13 2010 From: jimgardener at gmail.com (jimgardener) Date: Thu, 29 Jul 2010 09:51:13 -0700 (PDT) Subject: solving Tix problem in ubuntu jaunty Message-ID: <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20@q21g2000prm.googlegroups.com> hi, recently I switched to ubuntu jaunty and installed python 2.6.I installed lib-tk so that I can work on my gui apps using Tix and Tkinter.But ,it seems that the python version in jaunty ships a buggy tix version which gives a 'TclError:unknown color' error message (this happens when I try to use FileSelectBox in Tix). I tried to find if the installation is proper by >>root=Tix.Tk() >>root.tk.eval('package require Tix') This outputs the string '8.4' How do I correct the problem?I downloaded the source Tix8.4.3-src.tar from sourceforge site.Can somebody tell me how I can install this so I can use the bug free Tix from python2.6> thanks jim From jeanmichel at sequans.com Thu Jul 29 13:29:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 19:29:24 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c517a58$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C51BA74.2050105@sequans.com> Steven D'Aprano wrote: > [snip] > > super() is just as explicit as len(), or str.upper(). It says, > explicitly, that it will call the method belonging to one or more > superclass of the given class. > Come on Steven, you're better than this :) . Everybody can accurately guess what len and upper are doing without looking at the documentation. No one can guess for super without closely looking at the documention, or even at some good articles on the net which try to clear things up about super. And note there is no such article about len or upper. As someone already said in this list, the main problem with super is that it tends to refer to the superclass method while in fact it calls the next MRO method. "mro" would have been the proper name for "super". JM From joe at goldthwaites.com Thu Jul 29 13:48:16 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 29 Jul 2010 10:48:16 -0700 Subject: Ascii to Unicode. In-Reply-To: <4c50f508$0$28664$c3e8da3@news.astraweb.com> References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> Message-ID: <5A04846ED83745A8A99A944793792810@NewMBP> Hi Steven, I read through the article you referenced. I understand Unicode better now. I wasn't completely ignorant of the subject. My confusion is more about how Python is handling Unicode than Unicode itself. I guess I'm fighting my own misconceptions. I do that a lot. It's hard for me to understand how things work when they don't function the way I *think* they should. Here's the main source of my confusion. In my original sample, I had read a line in from the file and used the unicode function to create a unicodestring object; unicodestring = unicode(line, 'latin1') What I thought this step would do is translate the line to an internal Unicode representation. The problem character \xe1 would have been translated into a correct Unicode representation for the accented "a" character. Next I tried to write the unicodestring object to a file thusly; output.write(unicodestring) I would have expected the write function to request the byte string from the unicodestring object and simply write that byte string to a file. I thought that at this point, I should have had a valid Unicode latin1 encoded file. Instead get an error that the character \xe1 is invalid. The fact that the \xe1 character is still in the unicodestring object tells me it wasn't translated into whatever python uses for its internal Unicode representation. Either that or the unicodestring object returns the original string when it's asked for a byte stream representation. Instead of just writing the unicodestring object, I had to do this; output.write(unicodestring.encode('utf-8')) This is doing what I thought the other steps were doing. It's translating the internal unicodestring byte representation to utf-8 and writing it out. It still seems strange and I'm still not completely clear as to what is going on at the byte stream level for each of these steps. From pdl5000 at yahoo.com Thu Jul 29 13:57:05 2010 From: pdl5000 at yahoo.com (Paul Lemelle) Date: Thu, 29 Jul 2010 10:57:05 -0700 (PDT) Subject: stdout of external program. Message-ID: <958992.74508.qm@web52905.mail.re2.yahoo.com> HELP! :) I am trying to output the following program's output to either a file or variable, how can this be done? # Writing the output to a standard argv argument #1/usr/bin/python import sys for arg in sys.argv: ? print arg #END Thanks, Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at goldthwaites.com Thu Jul 29 13:59:48 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 29 Jul 2010 10:59:48 -0700 Subject: Ascii to Unicode. In-Reply-To: <1h68i7-534.ln1@satorlaser.homedns.org> References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: Hi Ulrich, Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a few characters above the 128 range that are causing Postgresql Unicode errors. Those characters work fine in the Windows world but they're not the correct byte representation for Unicode. What I'm attempting to do is translate those upper range characters into the correct Unicode representations so that they look the same in the Postgresql database as they did in the CSV file. I wrote up the source of my confusion to Steven so I won't duplicate it here. You're comment on defining the encoding of the file directly instead of using functions to encode and decode the data lead me to the codecs module. Using it, I can define the encoding a file open time and then just read and write the lines. I ended up with this; import codecs input = codecs.open('ascii.csv', encoding='cp1252') output = codecs.open('unicode.csv', mode='wb', encoding='utf-8') output.writelines(input.readlines()) input.close() output.close() This is doing exactly the same thing but it's much clearer to me. Readlines translates the input using the cp1252 codec and writelines encodes it to utf-8 and writes it out. And as you mentioned, it's probably higher performance. I haven't tested that but since both programs do the job in seconds, performance isn't and issue. Thanks again to everyone who posted. I really do appreciate it. From shailendra.vikas at gmail.com Thu Jul 29 14:08:17 2010 From: shailendra.vikas at gmail.com (Shailendra) Date: Thu, 29 Jul 2010 14:08:17 -0400 Subject: Multiprocessing taking too much time Message-ID: Hi All, I have a following situation. ==================PSUDO CODE START================== class holds_big_array: ? ? big_array ?#has a big array ? ? def get_some_element(self, cond) # return some data from the array from the big array ==================PSUDO CODE END==================== I wanted to use multiprocessing module to parallelise calling "get_some_element". I used following kind of code ==================PSUDO CODE START================== pool = Pool(processes=2) holder =holds_big_array() #class instantiation def callback_f(result): ? ? ? ? ?do something with result loop many times ? ?pool.apply_async(holder.get_some_element,args,callback=callback_f) pool.close() pool.join() ==================PSUDO CODE END==================== Note: Had to do something to enable instance method being pickled... I tested this with less than realistic size of big_array . My parallel version works much slower than than the normal serial version (10-20 sec vs 7-8 min). I was wonder what could be the possible reason. Is it something to do that it is a instance method and some locking will make other process wait for the locks. Any idea how to trace where the program is spending time? Let me know if the information give is inadequate. Thanks in advance. Shailendra Vikas From wherespythonmonks at gmail.com Thu Jul 29 14:12:09 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 29 Jul 2010 14:12:09 -0400 Subject: default behavior Message-ID: Why is the default value of an int zero? >>> x = int >>> print x >>> x() 0 >>> How do I build an "int1" type that has a default value of 1? [Hopefully no speed penalty.] I am thinking about applications with collections.defaultdict. What if I want to make a defaultdict of defaultdicts of lists? [I guess my Perl background is showing -- I miss auto-vivification.] W From ethan at stoneleaf.us Thu Jul 29 14:14:24 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Jul 2010 11:14:24 -0700 Subject: Ascii to Unicode. In-Reply-To: <5A04846ED83745A8A99A944793792810@NewMBP> References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: <4C51C500.8000206@stoneleaf.us> Joe Goldthwaite wrote: > Hi Steven, > > I read through the article you referenced. I understand Unicode better now. > I wasn't completely ignorant of the subject. My confusion is more about how > Python is handling Unicode than Unicode itself. I guess I'm fighting my own > misconceptions. I do that a lot. It's hard for me to understand how things > work when they don't function the way I *think* they should. > > Here's the main source of my confusion. In my original sample, I had read a > line in from the file and used the unicode function to create a > unicodestring object; > > unicodestring = unicode(line, 'latin1') > > What I thought this step would do is translate the line to an internal > Unicode representation. The problem character \xe1 would have been > translated into a correct Unicode representation for the accented "a" > character. Correct. At this point you have unicode string. > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from the > unicodestring object and simply write that byte string to a file. I thought > that at this point, I should have had a valid Unicode latin1 encoded file. > Instead get an error that the character \xe1 is invalid. Here's the problem -- there is no byte string representing the unicode string, they are completely different. There are dozens of different possible encodings to go from unicode to a byte-string (of which UTF-8 is one such possibility). > The fact that the \xe1 character is still in the unicodestring object tells > me it wasn't translated into whatever python uses for its internal Unicode > representation. Either that or the unicodestring object returns the > original string when it's asked for a byte stream representation. Wrong. It so happens that some of the unicode points are the same as some (but not all) of the ascii and upper-ascii values. When you attempt to write a unicode string without specifying which encoding you want, python falls back to ascii (not upper-ascii) so any character outside the 0-127 range is going to raise an error. > Instead of just writing the unicodestring object, I had to do this; > > output.write(unicodestring.encode('utf-8')) > > This is doing what I thought the other steps were doing. It's translating > the internal unicodestring byte representation to utf-8 and writing it out. > It still seems strange and I'm still not completely clear as to what is > going on at the byte stream level for each of these steps. Don't think of unicode as a byte stream. It's a bunch of numbers that map to a bunch of symbols. The byte stream only comes into play when you want to send unicode somewhere (file, socket, etc) and you then have to encode the unicode into bytes. Hope this helps! ~Ethan~ From jkordani at intlogsys.com Thu Jul 29 14:17:25 2010 From: jkordani at intlogsys.com (Joshua Kordani) Date: Thu, 29 Jul 2010 14:17:25 -0400 Subject: Multiprocessing taking too much time In-Reply-To: References: Message-ID: <4C51C5B5.3050400@intlogsys.com> The first thing that is generically tried when wishing to measure how long certain parts take is to record your own time snapshots in the code yourself. take the current time before an operation, take it after, subract, report it to yourself. Also, try working with an array that is actually big, so that you can see meaningful differences in approaches. Shailendra wrote: > Hi All, > I have a following situation. > ==================PSUDO CODE START================== > class holds_big_array: > big_array #has a big array > > def get_some_element(self, cond) # return some data from the array > from the big array > ==================PSUDO CODE END==================== > I wanted to use multiprocessing module to parallelise calling > "get_some_element". I used following kind of code > > ==================PSUDO CODE START================== > pool = Pool(processes=2) > holder =holds_big_array() #class instantiation > def callback_f(result): > do something with result > loop many times > pool.apply_async(holder.get_some_element,args,callback=callback_f) > pool.close() > pool.join() > ==================PSUDO CODE END==================== > Note: Had to do something to enable instance method being pickled... > > I tested this with less than realistic size of big_array . My parallel > version works much slower than than the normal serial version (10-20 > sec vs 7-8 min). I was wonder what could be the possible reason. Is it > something to do that it is a instance method and some locking will > make other process wait for the locks. Any idea how to trace where the > program is spending time? > > Let me know if the information give is inadequate. > > Thanks in advance. > Shailendra Vikas From no.email at nospam.invalid Thu Jul 29 14:18:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 29 Jul 2010 11:18:39 -0700 Subject: default behavior References: Message-ID: <7xeiem2lts.fsf@ruckus.brouhaha.com> wheres pythonmonks writes: > How do I build an "int1" type that has a default value of 1? > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. You can supply an arbitary function to collections.defaultdict. It doesn't have to be a class. E.g. d = collections.defaultdict(lambda: 1) will do what you are asking. From carey.tilden at gmail.com Thu Jul 29 14:18:41 2010 From: carey.tilden at gmail.com (Carey Tilden) Date: Thu, 29 Jul 2010 11:18:41 -0700 Subject: Ascii to Unicode. In-Reply-To: References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: On Thu, Jul 29, 2010 at 10:59 AM, Joe Goldthwaite wrote: > Hi Ulrich, > > Ascii.csv isn't really a latin-1 encoded file. ?It's an ascii file with a > few characters above the 128 range that are causing Postgresql Unicode > errors. ?Those characters work fine in the Windows world but they're not the > correct byte representation for Unicode. What I'm attempting to do is > translate those upper range characters into the correct Unicode > representations so that they look the same in the Postgresql database as > they did in the CSV file. Having bytes outside of the ASCII range means, by definition, that the file is not ASCII encoded. ASCII only defines bytes 0-127. Bytes outside of that range mean either the file is corrupt, or it's in a different encoding. In this case, you've been able to determine the correct encoding (latin-1) for those errant bytes, so the file itself is thus known to be in that encoding. Carey From ethan at stoneleaf.us Thu Jul 29 14:34:18 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Jul 2010 11:34:18 -0700 Subject: Ascii to Unicode. In-Reply-To: References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: <4C51C9AA.6070704@stoneleaf.us> Joe Goldthwaite wrote: > Hi Ulrich, > > Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a > few characters above the 128 range . . . It took me a while to get this point too (if you already have "gotten it", I apologize, but the above comment leads me to believe you haven't). *Every* file is an encoded file... even your UTF-8 file is encoded using the UTF-8 format. Someone correct me if I'm wrong, but I believe lower-ascii (0-127) matches up to the first 128 Unicode code points, so while those first 128 code-points translate easily to ascii, ascii is still an encoding, and if you have characters higher than 127, you don't really have an ascii file -- you have (for example) a cp1252 file (which also, not coincidentally, shares the first 128 characters/code points with ascii). Hopefully I'm not adding to the confusion. ;) ~Ethan~ From wherespythonmonks at gmail.com Thu Jul 29 14:35:06 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 29 Jul 2010 14:35:06 -0400 Subject: default behavior In-Reply-To: <7xeiem2lts.fsf@ruckus.brouhaha.com> References: <7xeiem2lts.fsf@ruckus.brouhaha.com> Message-ID: Thanks. I presume this will work for my nested example as well. Thanks again. On Thu, Jul 29, 2010 at 2:18 PM, Paul Rubin wrote: > wheres pythonmonks writes: >> How do I build an "int1" type that has a default value of 1? >> [Hopefully no speed penalty.] >> I am thinking about applications with collections.defaultdict. > > You can supply an arbitary function to collections.defaultdict. > It doesn't have to be a class. ?E.g. > > ? ?d = collections.defaultdict(lambda: 1) > > will do what you are asking. > -- > http://mail.python.org/mailman/listinfo/python-list > From airscorp at otenet.gr Thu Jul 29 14:43:05 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Thu, 29 Jul 2010 21:43:05 +0300 Subject: default behavior In-Reply-To: References: Message-ID: <4C51CBB9.4010909@otenet.gr> On 07/29/2010 09:12 PM, wheres pythonmonks wrote: > How do I build an "int1" type that has a default value of 1? You mean something like: >>> x = int() >>> x 0 >>> def myint(value=1): ... return int(value) ... >>> myint() 1 >>> That's ugly on so many levels.. Anyway, basic types (and almost everything else) in Python are classes. You can always subclass them to do whatever you like > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. > What if I want to make a defaultdict of defaultdicts of lists? [I > guess my Perl background is showing -- I miss auto-vivification.] > > > Ah, python is no perl. Then again, perl is no python either. ----- Random pseudo-Confucius quote Have fun, Nick From nagle at animats.com Thu Jul 29 15:04:33 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:04:33 -0700 Subject: Multiprocessing taking too much time In-Reply-To: References: Message-ID: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> On 7/29/2010 11:08 AM, Shailendra wrote: > Hi All, > I have a following situation. > ==================PSUDO CODE START================== > class holds_big_array: > big_array #has a big array > > def get_some_element(self, cond) # return some data from the array > from the big array > ==================PSUDO CODE END==================== > I wanted to use multiprocessing module to parallelise calling > "get_some_element". I used following kind of code > > ==================PSUDO CODE START================== > pool = Pool(processes=2) > holder =holds_big_array() #class instantiation > def callback_f(result): > do something with result > loop many times > pool.apply_async(holder.get_some_element,args,callback=callback_f) > pool.close() > pool.join() > ==================PSUDO CODE END==================== > Note: Had to do something to enable instance method being pickled... > > I tested this with less than realistic size of big_array . My parallel > version works much slower than than the normal serial version (10-20 > sec vs 7-8 min). I was wonder what could be the possible reason. It's hard to tell from your "PSUDO CODE", but it looks like each access to the "big array" involves calling another process. Calling a function in another process is done by creating an object to contain the request, running it through "pickle" to convert it to a stream of bytes, sending the stream of bytes through a socket or pipe to the other process, running the byte stream through "unpickle" to create an object like the original one, but in a different process, and calling a function on the newly created object in the receiving process. This entire sequence has to be done again in reverse to get a reply back. This is hundreds of times slower than a call to a local function. The "multiprocessing module" is not a replacement for thread-level parallelism. It looks like it is, but it isn't. It's only useful for big tasks which require large amounts of computation and little interprocess communication. Appropriately-sized tasks to send out to another process are things like "parse large web page" or "compress video file", not "access element of array". John Nagle From nagle at animats.com Thu Jul 29 15:17:14 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:17:14 -0700 Subject: Ascii to Unicode. In-Reply-To: References: Message-ID: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> On 7/28/2010 3:58 PM, Joe Goldthwaite wrote: > This still seems odd to me. I would have thought that the unicode function > would return a properly encoded byte stream that could then simply be > written to disk. Instead it seems like you have to re-encode the byte stream > to some kind of escaped Ascii before it can be written back out. Here's what's really going on. Unicode strings within Python have to be indexable. So the internal representation of Unicode has (usually) two bytes for each character, so they work like arrays. UTF-8 is a stream format for Unicode. It's slightly compressed; each character occupies 1 to 4 bytes, and the base ASCII characters (0..127 only, not 128..255) occupy one byte each. The format is described in "http://en.wikipedia.org/wiki/UTF-8". A UTF-8 file or stream has to be parsed from the beginning to keep track of where each Unicode character begins. So it's not a suitable format for data being actively worked on in memory; it can't be easily indexed. That's why it's necessary to convert to UTF-8 before writing to a file or socket. John Nagle From robert.kern at gmail.com Thu Jul 29 15:19:42 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jul 2010 14:19:42 -0500 Subject: Tabular Package: importing file In-Reply-To: References: Message-ID: On 7/28/10 4:57 PM, Robert Faryabi wrote: > Hi there; > > I'm using Tabular Package for manipulating tab-delimited data. > There is a small problem that I cannot get my head around it. > > When I construct my tabarray from file, the black fields are replaced by "nan". > Does any one knows how to just keep them as empty string (ie. ' ')? If you want the other values to be actual numbers instead of strings containing numerical values, then no, you cannot keep the blank fields as empty strings. There may be an option to have tabular parse the data into an object array, in which all of the items will be Python objects. Then you could mix and match the types. You will find better luck asking questions about tabular on the numpy-discussion mailing list. tabular is built on numpy, so many of your questions will really be questions about how numpy behaves. Also, the tabular authors hang out there. http://www.scipy.org/Mailing_Lists -- 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 Thu Jul 29 15:28:18 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:28:18 -0700 Subject: default behavior In-Reply-To: References: Message-ID: <4c51d64e$0$1609$742ec2ed@news.sonic.net> On 7/29/2010 11:12 AM, wheres pythonmonks wrote: > Why is the default value of an int zero? > >>>> x = int >>>> print x > >>>> x() > 0 >>>> > > How do I build an "int1" type that has a default value of 1? >>> class int1(object) : ... def __init__(self) : ... self.val = 1 ... def __call__(self) : ... return(self.val) ... >>> x = int1() >>> x() 1 This isn't useful; you'd also have to define all the numeric operators for this type. And then there are mixed-type conversion issues. Inheriting from "int" is not too helpful, because you can't assign to the value of the base class. "self=1" won't do what you want. [Hopefully no speed penalty.] In your dreams. Although all numbers in CPython are "boxed", so there's more of a speed penalty with "int" itself than you might expect. There are some C libraries for handling large arrays if you really need to crunch numbers. John Nagle From bjracine at glosten.com Thu Jul 29 15:39:01 2010 From: bjracine at glosten.com (Benjamin J. Racine) Date: Thu, 29 Jul 2010 12:39:01 -0700 Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) Message-ID: I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. I am not seeing how this might be done. Many thanks for your help... Ben Racine From lists at cheimes.de Thu Jul 29 15:40:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 29 Jul 2010 21:40:16 +0200 Subject: default behavior In-Reply-To: <4c51d64e$0$1609$742ec2ed@news.sonic.net> References: <4c51d64e$0$1609$742ec2ed@news.sonic.net> Message-ID: > Inheriting from "int" is not too helpful, because you can't assign > to the value of the base class. "self=1" won't do what you want. It's useful if you remember that you can set the default value by overwriting __new__. >>> class int1(int): ... def __new__(cls, value=1): ... return super(int1, cls).__new__(cls, value) ... >>> int1() 1 >>> int1(1) 1 >>> int1(2) 2 >>> int1(0) 0 From bjracine at glosten.com Thu Jul 29 15:43:28 2010 From: bjracine at glosten.com (Benjamin J. Racine) Date: Thu, 29 Jul 2010 12:43:28 -0700 Subject: measuring a function time In-Reply-To: <20100729104339.ab45755a.darcy@druid.net> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <20100729104339.ab45755a.darcy@druid.net> Message-ID: I just use ipython's functions (that are themselves just calls to the time module functions) for timing my functions... Enter: %timeit? or %time At the Ipython command prompt to get started. Ben R. On Jul 29, 2010, at 7:43 AM, D'Arcy J.M. Cain wrote: > On Thu, 29 Jul 2010 08:45:23 -0400 > Joe Riopel wrote: >> On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: >>> the output should be 7600 (s) for example. What is the best and easiest way >>> to do that? >> >> Take a look at time.clock() > > I don't know if that's what he wants. The clock() method returns > processor time, not wall time. > > Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) > [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 > Type "help", "copyright", "credits" or "license" for more information. >>>> from time import time, clock, sleep >>>> t = time() >>>> print time() - t, clock() > 0.000596046447754 0.03 >>>> sleep(3) >>>> print time() - t, clock() > 3.03474903107 0.03 >>>> x = open("BIGFILE").read() >>>> print time() - t, clock() > 10.2008538246 1.42 > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Thu Jul 29 15:46:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jul 2010 20:46:43 +0100 Subject: Ascii to Unicode. In-Reply-To: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> References: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> Message-ID: <4C51DAA3.4050201@mrabarnett.plus.com> John Nagle wrote: > On 7/28/2010 3:58 PM, Joe Goldthwaite wrote: >> This still seems odd to me. I would have thought that the unicode >> function >> would return a properly encoded byte stream that could then simply be >> written to disk. Instead it seems like you have to re-encode the byte >> stream >> to some kind of escaped Ascii before it can be written back out. > > Here's what's really going on. > > Unicode strings within Python have to be indexable. So the internal > representation of Unicode has (usually) two bytes for each character, > so they work like arrays. > > UTF-8 is a stream format for Unicode. It's slightly compressed; > each character occupies 1 to 4 bytes, and the base ASCII characters > (0..127 only, not 128..255) occupy one byte each. The format is > described in "http://en.wikipedia.org/wiki/UTF-8". A UTF-8 file or > stream has to be parsed from the beginning to keep track of where each > Unicode character begins. So it's not a suitable format for > data being actively worked on in memory; it can't be easily indexed. > Not entirely correct. The advantage of UTF-8 is that although different codepoints might be encoded into different numbers of bytes it's easy to tell whether a particular byte is the first in its sequence, so you don't have to parse from the start of the file. It is true, however, it can't be easily indexed. > That's why it's necessary to convert to UTF-8 before writing > to a file or socket. > From debatem1 at gmail.com Thu Jul 29 17:22:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 29 Jul 2010 14:22:24 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <20100729181327.74211dc6@pitrou.net> References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> <20100729181327.74211dc6@pitrou.net> Message-ID: On Thu, Jul 29, 2010 at 9:13 AM, Antoine Pitrou wrote: > On Wed, 28 Jul 2010 22:23:48 -0700 > geremy condra wrote: >> > >> > ? The new Python SSL module in 2.6 and later has a huge built-in >> > security hole - it doesn't verify the domain against the >> > certificate. ?As someone else put it, this means "you get to >> > talk securely with your attacker." As long as the site or proxy >> > has some valid SSL cert, any valid SSL cert copied from anywhere, >> > the new Python SSL module will tell you everything is just fine. >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle >> >> Did anything ever come of the discussion that you and Antoine had? > > As I wrote in http://bugs.python.org/issue1589, I would support adding > the necessary function(s) to the SSL module, and have urllib (and other > stdlib modules) support them. Someone needs to write a patch, though. > > Regards > > Antoine. Hmm, my understanding at the time was that there had been a decision to just adapt Heikki Toivonen's M2Crypto code, if that's just looking for someone to turn it into a patch I'll see if I can't find the time next week. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 18:43:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 22:43:43 GMT Subject: default behavior References: Message-ID: <4c52041e$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 21:43:05 +0300, Nick Raptis wrote: > On 07/29/2010 09:12 PM, wheres pythonmonks wrote: >> How do I build an "int1" type that has a default value of 1? > You mean something like: > >>> x = int() > >>> x > 0 > >>> def myint(value=1): > ... return int(value) > ... > >>> myint() > 1 > >>> > >>> > That's ugly on so many levels.. Why do you think it's ugly? It's a function that returns an int, and it provides a default value which is different from the default value of the int constructor. It's a really simple function, and it has an equally simple implementation, and it's an obvious way to do it. Not the *one* obvious way, because subclassing int is equally obvious, but still obvious. -- Steven From anushkaphotos at rediffmail.com Thu Jul 29 19:16:14 2010 From: anushkaphotos at rediffmail.com (anushkaphotos at rediffmail.com) Date: Thu, 29 Jul 2010 16:16:14 -0700 (PDT) Subject: ANUSHKA HOT PICTURES FOR BOLLYWOOD FANS Message-ID: ANUSHKA HOT PICTURES FOR BOLLYWOOD FANS ------------------------------------- http://sites.google.com/site/anushkaphotosalert From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 19:31:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 23:31:17 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c520f45$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> [snip] >> >> super() is just as explicit as len(), or str.upper(). It says, >> explicitly, that it will call the method belonging to one or more >> superclass of the given class. >> > Come on Steven, you're better than this :) . Everybody can accurately > guess what len and upper are doing without looking at the documentation. > No one can guess for super without closely looking at the documention, > or even at some good articles on the net which try to clear things up > about super. And note there is no such article about len or upper. super() is complex because the problem it is solving is a hard problem. That doesn't make it implicit, any more than (say) itertools.groupby() is implicit just because it's complex, or urllib2.request() is implicit just because some people don't know much about web protocols and have to read articles about it to learn. > As someone already said in this list, the main problem with super is > that it tends to refer to the superclass method while in fact it calls > the next MRO method. Why do you think that is a problem? That's what it is supposed to do, because that's what is needed to correctly implement multiple inheritance. > "mro" would have been the proper name for "super". That's your opinion. In any case, whether super() was called super() or mro() or aardvark() makes no difference to the functionality or whether it is useful. -- Steven From aahz at pythoncraft.com Thu Jul 29 19:38:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 29 Jul 2010 16:38:30 -0700 Subject: Possible to include \n chars in doctest code samples or output? References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <4c3ff6f7$0$11101$c3e8da3@news.astraweb.com> Message-ID: In article <4c3ff6f7$0$11101$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >Remember that doctests aren't intended for a comprehensive test suite. WDYM not intended? Disagree with Tim Peters much? ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 19:49:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 23:49:40 GMT Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: <4c521394$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 11:14:24 -0700, Ethan Furman wrote: > Don't think of unicode as a byte stream. It's a bunch of numbers that > map to a bunch of symbols. Not only are Unicode strings a bunch of numbers ("code points", in Unicode terminology), but the numbers are not necessarily all the same width. The full Unicode system allows for 1,114,112 characters, far more than will fit in a two-byte code point. The Basic Multilingual Plane (BMP) includes the first 2**16 (65536) of those characters, or code points U+0000 through U+FFFF; there are a further 16 supplementary planes of 2**16 characters each, or code points U+10000 through U+10FFFF. As I understand it (and I welcome corrections), some implementations of Unicode only support the BMP and use a fixed-width implementation of 16- bit characters for efficiency reasons. Supporting the entire range of code points would require either a fixed-width of 21-bits (which would then probably be padded to four bytes), or a more complex variable-width implementation. It looks to me like Python uses a 16-bit implementation internally, which leads to some rather unintuitive results for code points in the supplementary place... >>> c = chr(2**18) >>> c '\U00040000' >>> len(c) 2 -- Steven From rodrick.brown at gmail.com Thu Jul 29 19:53:33 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 29 Jul 2010 19:53:33 -0400 Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <20100729104339.ab45755a.darcy@druid.net> Message-ID: <81F19B09-0D5F-46A3-B7B3-6AFAC31C8ED6@gmail.com> Someone should port Perl's Benchmark.pm module to python that's such a useful module to measure a functions execution time and CPU usage. Sent from my iPhone 4. On Jul 29, 2010, at 3:43 PM, "Benjamin J. Racine" wrote: > I just use ipython's functions (that are themselves just calls to the time module functions) for timing my functions... > > Enter: > %timeit? > or > %time > > At the Ipython command prompt to get started. > > Ben R. > > On Jul 29, 2010, at 7:43 AM, D'Arcy J.M. Cain wrote: > >> On Thu, 29 Jul 2010 08:45:23 -0400 >> Joe Riopel wrote: >>> On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: >>>> the output should be 7600 (s) for example. What is the best and easiest way >>>> to do that? >>> >>> Take a look at time.clock() >> >> I don't know if that's what he wants. The clock() method returns >> processor time, not wall time. >> >> Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) >> [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from time import time, clock, sleep >>>>> t = time() >>>>> print time() - t, clock() >> 0.000596046447754 0.03 >>>>> sleep(3) >>>>> print time() - t, clock() >> 3.03474903107 0.03 >>>>> x = open("BIGFILE").read() >>>>> print time() - t, clock() >> 10.2008538246 1.42 >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolves >> http://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From metolone+gmane at gmail.com Thu Jul 29 20:43:07 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 29 Jul 2010 17:43:07 -0700 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: "Joe Goldthwaite" wrote in message news:5A04846ED83745A8A99A944793792810 at NewMBP... > Hi Steven, > > I read through the article you referenced. I understand Unicode better > now. > I wasn't completely ignorant of the subject. My confusion is more about > how > Python is handling Unicode than Unicode itself. I guess I'm fighting my > own > misconceptions. I do that a lot. It's hard for me to understand how > things > work when they don't function the way I *think* they should. > > Here's the main source of my confusion. In my original sample, I had read > a > line in from the file and used the unicode function to create a > unicodestring object; > > unicodestring = unicode(line, 'latin1') > > What I thought this step would do is translate the line to an internal > Unicode representation. Correct. > The problem character \xe1 would have been > translated into a correct Unicode representation for the accented "a" > character. Which just so happens to be u'\xe1', which probably adds to your confusion later :^) The first 256 Unicode code points map to latin1. > > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from > the > unicodestring object and simply write that byte string to a file. I > thought > that at this point, I should have had a valid Unicode latin1 encoded file. > Instead get an error that the character \xe1 is invalid. Incorrect. The unicodestring object doesn't save the original byte string, so there is nothing to "request". > The fact that the \xe1 character is still in the unicodestring object > tells > me it wasn't translated into whatever python uses for its internal Unicode > representation. Either that or the unicodestring object returns the > original string when it's asked for a byte stream representation. Both incorrect. As I mentioned earlier, the first Unicode code points map to latin1. It *was* translated to a Unicode code point whose value (but not internal representation!) is the same as latin1. > Instead of just writing the unicodestring object, I had to do this; > > output.write(unicodestring.encode('utf-8')) This is exactly what you need to do...explicitly encode the Unicode string into a byte string. > This is doing what I thought the other steps were doing. It's translating > the internal unicodestring byte representation to utf-8 and writing it > out. > It still seems strange and I'm still not completely clear as to what is > going on at the byte stream level for each of these steps. I'm surprised that by now no one has mentioned the codecs module. You original stated you are using Python 2.4.4, which I looked up and does support the codecs module. import codecs infile = codecs.open('ascii.csv,'r','latin1') outfile = codecs.open('unicode.csv','w','utf-8') for line in infile: outfile.write(line) infile.close() outfile.close() As you can see, codecs.open takes a parameter for the encoding of the file. Lines read are automatically decoded into Unicode; Unicode lines written are automatically encoded into a byte stream. -Mark From cappy2112 at gmail.com Thu Jul 29 20:54:22 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Thu, 29 Jul 2010 17:54:22 -0700 (PDT) Subject: Enabling/Disabling remote desktop - programmatically Message-ID: <2cd40dd7-4aeb-4839-9aa8-acacf71568b2@y12g2000prb.googlegroups.com> I've already posted this in the Python W32 list, but didn't get what I'm looking for. I want to know how to disable Remote Desktop after logging to into a remote machine, to prevent subsequent logins by other users logging me out. I currently have a Windows XP system configured for coworkers to connect to using VPN & remote desktop, so they can get diagnostic data for test failures. I can disable Remote Desktop manually in Ctrl Panel, but have to navigate through several screens to do this. If I could do this using Python it would be very convenient. Have any of the Windows users on this list done this? Thanks From cappy2112 at gmail.com Thu Jul 29 20:58:17 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Thu, 29 Jul 2010 17:58:17 -0700 (PDT) Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) References: Message-ID: <8ea2aad6-f3af-4b87-ac62-5a779a8021da@m17g2000prl.googlegroups.com> On Jul 29, 12:39?pm, "Benjamin J. Racine" wrote: > I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. > > I am not seeing how this might be done. ?Many thanks for your help... > > Ben Racine Ben You can actually use the sys module to do this, with just a few lines of code. This article shows you how http://www.doughellmann.com/PyMOTW/sys/tracing.html From nobody at nowhere.com Fri Jul 30 00:56:12 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 30 Jul 2010 05:56:12 +0100 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> <4c521394$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Thu, 29 Jul 2010 23:49:40 +0000, Steven D'Aprano wrote: > It looks to me like Python uses a 16-bit implementation internally, It typically uses the platform's wchar_t, which is 16-bit on Windows and (typically) 32-bit on Unix. IIRC, it's possible to build Python with 32-bit Unicode on Windows, but that will be inefficient (because it has to convert to/from 16-bit when calling Windows API functions) and will break any C modules which pass the pointer to the internal buffer directly to API functions. From greg.ewing at canterbury.ac.nz Fri Jul 30 03:35:52 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 19:35:52 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c517a58$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bfd5uF9gqU1@mid.individual.net> Steven D'Aprano wrote: > super() is just as explicit as len(), or str.upper(). It says, > explicitly, that it will call the method belonging to one or more > superclass of the given class. That's not strictly true. It will call a method belonging to some class in the mro of self, but that class is not necessarily in the base list of the class mentioned in the super() call. It's possible for a super() call to go "sideways" in the inheritance graph. -- Greg From greg.ewing at canterbury.ac.nz Fri Jul 30 03:37:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 19:37:29 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c520f45$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bfd8tF9gqU2@mid.individual.net> Steven D'Aprano wrote: > On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > >>"mro" would have been the proper name for "super". > > That's your opinion. In any case, whether super() was called super() or > mro() or aardvark() makes no difference to the functionality or whether > it is useful. I think the point is that the name is misleading, because it makes it *sound* like it's going to call a method in a superclass, when it fact it might not. -- Greg From greg.ewing at canterbury.ac.nz Fri Jul 30 04:04:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 20:04:42 +1200 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: <8bfes1Fiu1U1@mid.individual.net> David Robinow wrote: > Never > use security software version 1.0 or greater. It was written by an > author insufficiently paranoid. Hmmm. So to get people to trust your security software, you should start with version 0.0 and increment by 0.0000001 for each release. :-) -- Greg From gelonida at gmail.com Fri Jul 30 04:10:13 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 10:10:13 +0200 Subject: how to build same executabl with and without console output Message-ID: Hi, What I'd like to achieve ideally is to create a py2exe program, which will only display a window (so 'compiled' as 'windows'-application) if called normally. however if being called with the option --debug it should display the graphical window plus a debug console where I can print to. Is there any trick in adding a console window to an application, that was built as 'windows' application? If above is not possible: Is there any way to compile the same python script (myprog.py) from one py2exe script into once a 'windows' executable (myprog.exe) and once into a 'console' executable (myprog_debug.exe)? TIA From __peter__ at web.de Fri Jul 30 04:40:51 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 10:40:51 +0200 Subject: default behavior References: Message-ID: wheres pythonmonks wrote: > How do I build an "int1" type that has a default value of 1? > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. >>> from collections import defaultdict >>> d = defaultdict(1 .conjugate) >>> d["x"] += 2 >>> d["x"] 3 Isn't that beautiful? Almost like home;) It is also fast: $ python -m timeit -s"one = lambda: 1" "one()" 1000000 loops, best of 3: 0.213 usec per loop $ python -m timeit -s"one = 1 .conjugate" "one()" 10000000 loops, best of 3: 0.0972 usec per loop Micro-optimisation, the best excuse for ugly code... Peter From jimmy at retzlaff.com Fri Jul 30 05:00:37 2010 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Fri, 30 Jul 2010 02:00:37 -0700 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 1:10 AM, Gelonida wrote: > What I'd like to achieve ideally is to create a py2exe program, > which > will only display a window (so 'compiled' as 'windows'-application) if > called normally. > > however if being called with the option --debug it should display the > graphical window plus a debug console where I can print to. > > Is there any trick in adding a console window to an application, > that was built as 'windows' application? > > If above is not possible: > > Is there any way to compile the same python script (myprog.py) from one > py2exe script into once a 'windows' executable (myprog.exe) and once > into a 'console' executable (myprog_debug.exe)? I can't think of an easy way to achieve the first approach - I've always taken the second approach. The advanced example included with py2exe has an example of how to do this. Look at all the occurrences of test_wx in the following link to see all the pieces involved: http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup This uses an alternate form of the "windows" and "console" arguments where each target is an object with specially named member variables rather than a string that names the .py file (this string is one of the member variables). This is necessary so you can give different names to the console version and the windows version. Jimmy From jeanmichel at sequans.com Fri Jul 30 05:00:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 11:00:50 +0200 Subject: stdout of external program. In-Reply-To: <958992.74508.qm@web52905.mail.re2.yahoo.com> References: <958992.74508.qm@web52905.mail.re2.yahoo.com> Message-ID: <4C5294C2.9090704@sequans.com> Paul Lemelle wrote: > HELP! :) > > I am trying to output the following program's output to either a file > or variable, how can this be done? > > # Writing the output to a standard argv argument > > #1/usr/bin/python > > import sys > > for arg in sys.argv: > print arg > > #END > > Thanks, > Paul > > Hi Paul, after reading 4 times your post, I still don't see what you want to achieve. What are you calling a variable ? an os variable ? import sys file = open('testfile.txt', 'w') file.write(str(sys.argv)) file.close() second hit when googling your question: http://docs.python.org/tutorial/inputoutput.html JM From jeanmichel at sequans.com Fri Jul 30 05:09:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 11:09:20 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c520f45$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C5296C0.4070403@sequans.com> Steven D'Aprano wrote: > On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > > > [snip] >> As someone already said in this list, the main problem with super is >> that it tends to refer to the superclass method while in fact it calls >> the next MRO method. >> > > Why do you think that is a problem? That's what it is supposed to do, > because that's what is needed to correctly implement multiple inheritance. > > > >> "mro" would have been the proper name for "super". >> > > That's your opinion. In any case, whether super() was called super() or > mro() or aardvark() makes no difference to the functionality or whether > it is useful. > > > > I have no problem with dogs nor cats, however I have problem with cats called dogs and dogs called cats as I'm dealing with industrial programming, not litterature nor poetry. JM From duncan.booth at invalid.invalid Fri Jul 30 05:57:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Jul 2010 09:57:46 GMT Subject: default behavior References: Message-ID: Peter Otten <__peter__ at web.de> wrote: >>>> from collections import defaultdict >>>> d = defaultdict(1 .conjugate) >>>> d["x"] += 2 >>>> d["x"] > 3 > > Isn't that beautiful? Almost like home;) > > It is also fast: > > $ python -m timeit -s"one = lambda: 1" "one()" > 1000000 loops, best of 3: 0.213 usec per loop > $ python -m timeit -s"one = 1 .conjugate" "one()" > 10000000 loops, best of 3: 0.0972 usec per loop > > Micro-optimisation, the best excuse for ugly code... > Nice one, but if you are going to micro-optimise why not save a few keystrokes while you're at it and use '1 .real' instead? -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Fri Jul 30 06:21:39 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 12:21:39 +0200 Subject: default behavior References: Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >>>>> from collections import defaultdict >>>>> d = defaultdict(1 .conjugate) >>>>> d["x"] += 2 >>>>> d["x"] >> 3 >> >> Isn't that beautiful? Almost like home;) >> >> It is also fast: >> >> $ python -m timeit -s"one = lambda: 1" "one()" >> 1000000 loops, best of 3: 0.213 usec per loop >> $ python -m timeit -s"one = 1 .conjugate" "one()" >> 10000000 loops, best of 3: 0.0972 usec per loop >> >> Micro-optimisation, the best excuse for ugly code... >> > > Nice one, but if you are going to micro-optimise why not save a few > keystrokes while you're at it and use '1 .real' instead? >>> 1 .real 1 >>> 1 .conjugate >>> 1 .conjugate() real is a property, not a method. conjugate() was the first one that worked that was not __special__. I think it has the added benefit that it's likely to confuse the reader... Peter From duncan.booth at invalid.invalid Fri Jul 30 06:56:23 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Jul 2010 10:56:23 GMT Subject: default behavior References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > real is a property, not a method. conjugate() was the first one that > worked that was not __special__. I think it has the added benefit that > it's likely to confuse the reader... > Ah, silly me, I should have realised that. Yes, micro-optimisations that are also micro-obfuscations are always the best. :^) -- Duncan Booth http://kupuguy.blogspot.com From ldo at geek-central.gen.new_zealand Fri Jul 30 07:16:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 30 Jul 2010 23:16:47 +1200 Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: In message , J.B. Brown wrote: > I personally prefer to be slightly excessive in the amount of spacing > I used, especially when parentheses are involved. > > myTuple = ( 1, 2, 3, 4, 5 ) Parentheses are punctuation. Why not leave spaces around the commas as well, to be consistent? myTuple = ( 1 , 2 , 3 , 4 , 5 ) T,FTFY. From python at bdurham.com Fri Jul 30 07:29:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 30 Jul 2010 07:29:48 -0400 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: <1280489388.15025.1387504783@webmail.messagingengine.com> > Is there any trick in adding a console window to an application, that was built as 'windows' application? I was recently wondering the same thing myself. My research indicates that its not possible to have a single Windows application that can run in both console and GUI ("Windows") modes. Here are 2 links that explain this in more detail. Malcolm From ldo at geek-central.gen.new_zealand Fri Jul 30 07:46:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 30 Jul 2010 23:46:41 +1200 Subject: Normalizing A Vector Message-ID: Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize it (scale all components by the same factor) so its magnitude is 1. The usual way is something like this: L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) V = (V[0] / L, V[1] / L, V[2] / L) What I don?t like is having that intermediate variable L leftover after the computation. Here?s how to do it in one step: V = tuple \ ( x / math.sqrt ( reduce(lambda a, b : a + b, (y * y for y in V), 0) ) for x in V ) which, incidentally, also works for vectors with dimensions other than 3. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 07:49:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 11:49:01 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> Message-ID: <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 19:35:52 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> super() is just as explicit as len(), or str.upper(). It says, >> explicitly, that it will call the method belonging to one or more >> superclass of the given class. > > That's not strictly true. It will call a method belonging to some class > in the mro of self, but that class is not necessarily in the base list > of the class mentioned in the super() call. Yes, that's what I said. super() can visit any superclass of the given class, not just one of the immediate base class(es). That's why it's called super() rather than base() or parent(). It would be rather pointless if super() was limited to just the base classes. > It's possible for a super() > call to go "sideways" in the inheritance graph. I doubt that very much. A class F can't inherit behaviour from a class E merely by virtue of them both being subclasses of the same hierarchy. If it did, that would be... disturbing. Example: E inherits from D. D inherits from C and B. C and B both inherit from A. F also inherits from C. F and E are "sideways" to each other (sibling classes?), but they don't inherit from each other. Perhaps you're referring to the angled lines in a diagram such as: A / \ C B \ / D / \ E F F and E don't inherit from each other, because they are sidewards to each other (they are not in each other's MRO). Regardless of the angles we draw the lines, all of D, C, B, A are above E (and F). Or downwards if you prefer to reverse the diagram. Yes, a super call might jog left from C to B, but only when being called from one of the lower classes D-F. That's still an upwards call relative to the originator, not sidewards. -- Steven From wherespythonmonks at gmail.com Fri Jul 30 07:59:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 07:59:52 -0400 Subject: default behavior In-Reply-To: References: Message-ID: Instead of defaultdict for hash of lists, I have seen something like: m={}; m.setdefault('key', []).append(1) Would this be preferred in some circumstances? Also, is there a way to upcast a defaultdict into a dict? I have also heard some people use exceptions on dictionaries to catch key existence, so passing in a defaultdict (I guess) could be hazardous to health. Is this true? W On Fri, Jul 30, 2010 at 6:56 AM, Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: >> real is a property, not a method. conjugate() was the first one that >> worked that was not __special__. I think it has the added benefit that >> it's likely to confuse the reader... >> > Ah, silly me, I should have realised that. > > Yes, micro-optimisations that are also micro-obfuscations are always the > best. :^) > > -- > Duncan Booth http://kupuguy.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 08:04:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 12:04:21 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> Message-ID: <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > > >>>"mro" would have been the proper name for "super". >> >> That's your opinion. In any case, whether super() was called super() or >> mro() or aardvark() makes no difference to the functionality or whether >> it is useful. > > I think the point is that the name is misleading, because it makes it > *sound* like it's going to call a method in a superclass, when it fact > it might not. I'm not sure I understand your point here. If you call super() from a method that doesn't exist in any superclass, then you are correct, it won't call a method in a superclass, and will raise AttributeError. But in the more sensible case that you only call super() when there is actually something to inherit, then of course it calls the method in a superclass. It certainly doesn't call methods from arbitrary unrelated classes, only those which are in the MRO. That is, superclasses. If Z is below A in the hierarchy, then we have no difficulty in identifying Z as a subclass of A, and likewise we should have no problem with identifying A as *a* (and not "the") superclass of Z, no matter how distant they are or how tangled the DIG between them. The exception would be if you could have loops in the class hierarchy, in which case the concepts of super- and sub-classes breaks down completely. But even if some other languages allowed that, Python doesn't, so we're safe. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 08:19:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 12:19:52 GMT Subject: default behavior References: Message-ID: <4c52c368$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote: > Instead of defaultdict for hash of lists, I have seen something like: > > > m={}; m.setdefault('key', []).append(1) > > Would this be preferred in some circumstances? Sure, why not? Whichever you prefer. setdefault() is a venerable old technique, dating back to Python 2.0, and not a newcomer like defaultdict. > Also, is there a way to upcast a defaultdict into a dict? "Upcast"? Surely it is downcasting. Or side-casting. Or type-casting. Whatever. *wink* Whatever it is, the answer is Yes: >>> from collections import defaultdict as dd >>> x = dd(int) >>> x[1] = 'a' >>> x defaultdict(, {1: 'a'}) >>> dict(x) {1: 'a'} > I have also heard some people use > exceptions on dictionaries to catch key existence, so passing in a > defaultdict (I guess) could be hazardous to health. Is this true? Yes, it is true that some people use exceptions on dicts to catch key existence. The most common reason to do so is to catch the non-existence of a key so you can add it: try: mydict[x] = mydict[x] + 1 except KeyError: mydict[x] = 1 If mydict is a defaultdict with the appropriate factory, then the change is perfectly safe because mydict[x] will not raise an exception when x is missing, but merely return 0, so it will continue to work as expected and all is good. Of course, if you pass it an defaultdict with an *inappropriate* factory, you'll get an error. So don't do that :) Seriously, you can't expect to just randomly replace a variable with some arbitrarily different variable and expect it to work. You need to know what the code is expecting, and not break those expectations too badly. And now you have at least three ways of setting missing values in a dict. And those wacky Perl people say that Python's motto is "only one way to do it" :) -- Steven From V.vanBeveren at rijnhuizen.nl Fri Jul 30 08:22:33 2010 From: V.vanBeveren at rijnhuizen.nl (Vincent van Beveren) Date: Fri, 30 Jul 2010 14:22:33 +0200 Subject: The untimely dimise of a weak-reference Message-ID: <2926F4BC94217A43A2D21792DE88189339C58B6372@ex1.rijnh.nl> Hi everyone, I was working with weak references in Python, and noticed that it was impossible to create a weak-reference of bound methods. Here is a little python 3.0 program to prove my point: import weakref print("Creating object...") class A(object): def b(self): print("I am still here") a = A() def d(r): print("Aaah! Weakref lost ref") print("Creating weak reference") r = weakref.ref(a.b, d) print("Oh, wait, its already gone!") print("Ref == None, cause of untimely demise: %s" % r()) print("Object is still alive: %s" % a) print("Function is still exists: %s" % a.b) print("See:") a.b() I also tried this in Python 2.5 and 2.6 (with minor modifications to the syntax of course), and it yielded the exact same behavior. Why is this, and is there anything I can do about it? I wish to reference these bound functions, but I do not want to keep them in memory once the object they belong to is no longer referenced. Regards, Vincent van Beveren ___ Ing. V. van Beveren Software Engineer,?FOM Rijnhuizen E: V.vanBeveren at rijnhuizen.nl From hniksic at xemacs.org Fri Jul 30 08:28:59 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 30 Jul 2010 14:28:59 +0200 Subject: measuring a function time References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> Message-ID: <87tynhdugk.fsf@busola.homelinux.net> Steven D'Aprano writes: > On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > >> This should be enough >> >>>>>import time >>>>>tic = time.time() >>>>>function() >>>>>toc = time.time() >>>>>print toc - tic > > You're typing that in the interactive interpreter, which means the > timer is counting the seconds while you're typing subsequent > commands. At the very least, you need to put that code into a > function. Or, trivially improved as follows: >>> t0 = time.time(); function(); t1 = time.time() >>> print t1 - t0 This technique, while nowhere nearly as thorough as the timeit module, still gives useful results for simple measurements. From __peter__ at web.de Fri Jul 30 08:33:49 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 14:33:49 +0200 Subject: default behavior References: Message-ID: wheres pythonmonks wrote: > Instead of defaultdict for hash of lists, I have seen something like: > > > m={}; m.setdefault('key', []).append(1) > > Would this be preferred in some circumstances? In some circumstances, sure. I just can't think of them at the moment. Maybe if your code has to work in Python 2.4. > Also, is there a way to upcast a defaultdict into a dict? dict(some_defaultdict) > I have also > heard some people use exceptions on dictionaries to catch key > existence, so passing in a defaultdict (I guess) could be hazardous to > health. Is this true? A problem could arise when you swap a "key in dict" test with a "try...except KeyError". This would be an implementation detail for a dict but affect the contents of a defaultdict: >>> from collections import defaultdict >>> def update(d): ... for c in "abc": ... try: d[c] ... except KeyError: d[c] = c ... >>> d = defaultdict(lambda:"-") >>> update(d) >>> d defaultdict( at 0x7fd4ce32a320>, {'a': '-', 'c': '-', 'b': '-'}) >>> def update2(d): ... for c in "abc": ... if c not in d: ... d[c] = c ... >>> d = defaultdict(lambda:"-") >>> update2(d) >>> d defaultdict( at 0x7fd4ce32a6e0>, {'a': 'a', 'c': 'c', 'b': 'b'}) Peter From wherespythonmonks at gmail.com Fri Jul 30 08:34:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 08:34:52 -0400 Subject: default behavior In-Reply-To: <4c52c368$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: Sorry, doesn't the following make a copy? >>>> from collections import defaultdict as dd >>>> x = dd(int) >>>> x[1] = 'a' >>>> x > defaultdict(, {1: 'a'}) >>>> dict(x) > {1: 'a'} > > I was hoping not to do that -- e.g., actually reuse the same underlying data. Maybe dict(x), where x is a defaultdict is smart? I agree that a defaultdict is safe to pass to most routines, but I guess I could imagine that a try/except block is used in a bit of code where on the key exception (when the value is absent) populates the value with a random number. In that application, a defaultdict would have no random values. Besides a slightly different favor, does the following have applications not covered by defaultdict? m.setdefault('key', []).append(1) I think I am unclear on the difference between that and: m['key'] = m.get('key',[]).append(1) Except that the latter works for immutable values as well as containers. On Fri, Jul 30, 2010 at 8:19 AM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote: > >> Instead of defaultdict for hash of lists, I have seen something like: >> >> >> m={}; m.setdefault('key', []).append(1) >> >> Would this be preferred in some circumstances? > > Sure, why not? Whichever you prefer. > > setdefault() is a venerable old technique, dating back to Python 2.0, and > not a newcomer like defaultdict. > > >> Also, is there a way to upcast a defaultdict into a dict? > > "Upcast"? Surely it is downcasting. Or side-casting. Or type-casting. > Whatever. *wink* > > Whatever it is, the answer is Yes: > >>>> from collections import defaultdict as dd >>>> x = dd(int) >>>> x[1] = 'a' >>>> x > defaultdict(, {1: 'a'}) >>>> dict(x) > {1: 'a'} > > > >> I have also heard some people use >> exceptions on dictionaries to catch key existence, so passing in a >> defaultdict (I guess) could be hazardous to health. ?Is this true? > > Yes, it is true that some people use exceptions on dicts to catch key > existence. The most common reason to do so is to catch the non-existence > of a key so you can add it: > > try: > ? ?mydict[x] = mydict[x] + 1 > except KeyError: > ? ?mydict[x] = 1 > > > If mydict is a defaultdict with the appropriate factory, then the change > is perfectly safe because mydict[x] will not raise an exception when x is > missing, but merely return 0, so it will continue to work as expected and > all is good. > > Of course, if you pass it an defaultdict with an *inappropriate* factory, > you'll get an error. So don't do that :) Seriously, you can't expect to > just randomly replace a variable with some arbitrarily different variable > and expect it to work. You need to know what the code is expecting, and > not break those expectations too badly. > > And now you have at least three ways of setting missing values in a dict. > And those wacky Perl people say that Python's motto is "only one way to > do it" :) > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From hniksic at xemacs.org Fri Jul 30 08:38:32 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 30 Jul 2010 14:38:32 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> Message-ID: <87pqy5du0n.fsf@busola.homelinux.net> Gregory Ewing writes: > I think the point is that the name is misleading, because it makes it > *sound* like it's going to call a method in a superclass, when it fact > it might not. That is indeed confusing to some people, especially those who refuse to to accept the notion that "superclass" means the same as "next in MRO", maintaining instead that superclass refers to one of the base classes, their bases, etc. -- IMO a defensible position. super might have better been called next_in_mro, next_method, or next_class, except those are harder to type, and way less catchy than "super". The Dylan and CLOS operator that super is most closely based on is called (call-)next-method. From jeanmichel at sequans.com Fri Jul 30 08:43:07 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 14:43:07 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C52C8DB.8060305@sequans.com> Steven D'Aprano wrote: > On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote: > > >> Steven D'Aprano wrote: >> >>> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: >>> >> > >> >>>> "mro" would have been the proper name for "super". >>>> >>> That's your opinion. In any case, whether super() was called super() or >>> mro() or aardvark() makes no difference to the functionality or whether >>> it is useful. >>> >> I think the point is that the name is misleading, because it makes it >> *sound* like it's going to call a method in a superclass, when it fact >> it might not. >> > > I'm not sure I understand your point here. If you call super() from a > method that doesn't exist in any superclass, then you are correct, it > won't call a method in a superclass, and will raise AttributeError. > > But in the more sensible case that you only call super() when there is > actually something to inherit, then of course it calls the method in a > superclass. It certainly doesn't call methods from arbitrary unrelated > classes, only those which are in the MRO. That is, superclasses. > > If Z is below A in the hierarchy, then we have no difficulty in > identifying Z as a subclass of A, and likewise we should have no problem > with identifying A as *a* (and not "the") superclass of Z, no matter how > distant they are or how tangled the DIG between them. > > The exception would be if you could have loops in the class hierarchy, in > which case the concepts of super- and sub-classes breaks down completely. > But even if some other languages allowed that, Python doesn't, so we're > safe. > > > > Quoting Michele's article (I think he's still hanging around this list) "Readers familiar will single inheritance languages, such as Java or Smalltalk, will have a clear concept of superclass in mind. This concept, however, has /no useful meaning/ in Python or in other multiple inheritance languages". the complete article on super: http://www.artima.com/weblogs/viewpost.jsp?thread=236275 super is a strange name for something that makes no sense in python (talking about superclass here). It doesn't take away the usefulness of super, but it's a proof that you can ruin a good feature with a bad name. JM From durga.disc at gmail.com Fri Jul 30 08:48:09 2010 From: durga.disc at gmail.com (Durga D) Date: Fri, 30 Jul 2010 05:48:09 -0700 (PDT) Subject: Basic Information about Python Message-ID: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Hi All, I am new to python based application developement. I am using Windows XP. 1. Can I create desktop application (just hello world program) with Python language like exe in VC++? 2. If First statement is Yes, Can I include this application with my existing setup(assume 10 MB) for windows? 3. If Second statement is Yes, What will be the setup size? Thank in advance. Regards, Durga. From ldo at geek-central.gen.new_zealand Fri Jul 30 08:51:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:51:30 +1200 Subject: Ascii to Unicode. References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: In message , Joe Goldthwaite wrote: > Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a > few characters above the 128 range that are causing Postgresql Unicode > errors. Those characters work fine in the Windows world but they're not > the correct byte representation for Unicode. In other words, the encoding you want to decode from in this case is windows-1252. From ldo at geek-central.gen.new_zealand Fri Jul 30 08:52:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:52:36 +1200 Subject: Ascii to Unicode. References: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> Message-ID: In message <4c51d3b6$0$1638$742ec2ed at news.sonic.net>, John Nagle wrote: > UTF-8 is a stream format for Unicode. It's slightly compressed ... ?Variable-length? is not the same as ?compressed?. Particularly if you?re mainly using non-Roman scripts... From ldo at geek-central.gen.new_zealand Fri Jul 30 08:54:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:54:44 +1200 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> Message-ID: In message , Joe Goldthwaite wrote: > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from > the unicodestring object and simply write that byte string to a file. Encoded according to which encoding? From ldo at geek-central.gen.new_zealand Fri Jul 30 08:56:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:56:53 +1200 Subject: solving Tix problem in ubuntu jaunty References: <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20@q21g2000prm.googlegroups.com> Message-ID: In message <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20 at q21g2000prm.googlegroups.com>, jimgardener wrote: > How do I correct the problem? From ldo at geek-central.gen.new_zealand Fri Jul 30 09:03:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 01:03:46 +1200 Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: In message <43f464f9-3f8a-4bec-8d06-930092d5a936 at g6g2000pro.googlegroups.com>, kBob wrote: > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" Look at that configuration script, figure out what it?s returning for a proxy, and put that into your Python script. From jeanmichel at sequans.com Fri Jul 30 09:04:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 15:04:31 +0200 Subject: Basic Information about Python In-Reply-To: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Message-ID: <4C52CDDF.7000906@sequans.com> Durga D wrote: > Hi All, > > I am new to python based application developement. I am using > Windows XP. > > 1. Can I create desktop application (just hello world program) with > Python > language like exe in VC++? > yes http://www.py2exe.org/ > 2. If First statement is Yes, Can I include this application with > my > existing setup(assume 10 MB) for windows? > you mean include it in a windows installer ? If so yes. > 3. If Second statement is Yes, What will be the setup size? > > > Thank in advance. > > Regards, > Durga. > > JM From __peter__ at web.de Fri Jul 30 09:06:00 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 15:06 +0200 Subject: The untimely dimise of a weak-reference References: Message-ID: Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here is a little > python 3.0 program to prove my point: > > import weakref > > print("Creating object...") > class A(object): > > def b(self): > print("I am still here") > > a = A() > > def d(r): > print("Aaah! Weakref lost ref") > > print("Creating weak reference") > > r = weakref.ref(a.b, d) The instance doesn't keep a reference of its bound method. Rather the bound method keeps a reference of its instance. Every time you say a.b you get a different bound method. What do you think should keep it alive? > print("Oh, wait, its already gone!") > print("Ref == None, cause of untimely demise: %s" % r()) > print("Object is still alive: %s" % a) > print("Function is still exists: %s" % a.b) > print("See:") > a.b() > > I also tried this in Python 2.5 and 2.6 (with minor modifications to the > syntax of course), and it yielded the exact same behavior. Why is this, > and is there anything I can do about it? I wish to reference these bound > functions, but I do not want to keep them in memory once the object they > belong to is no longer referenced. I fear you have to manage the methods' lifetime explicitly. Peter From ed at leafe.com Fri Jul 30 09:11:29 2010 From: ed at leafe.com (Ed Leafe) Date: Fri, 30 Jul 2010 09:11:29 -0400 Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) In-Reply-To: References: Message-ID: <654B798C-D98A-4856-8692-088FD6245A91@leafe.com> On Jul 29, 2010, at 3:39 PM, Benjamin J. Racine wrote: > I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. > > I am not seeing how this might be done. Many thanks for your help... Check out PuDB - I use it all the time. http://pypi.python.org/pypi/pudb Intro screencast is at http://vimeo.com/5255125 -- Ed Leafe From wherespythonmonks at gmail.com Fri Jul 30 09:12:51 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 09:12:51 -0400 Subject: pylint scores Message-ID: I am starting to use pylint to look at my code and I see that it gives a rating. What values do experienced python programmers get on code not targeting the benchmark? I wrote some code, tried to keep it under 80 characters per line, reasonable variable names, and I got: 0.12 / 10. Is this a good score for one not targeting the benchmark? (pylint running in default mode) Somewhat related: Is the backslash the only way to extend arguments to statements over multiple lines? (e.g.) >>> def f(x,y,z): return(x+y+z); ... >>> f(1,2, ... 3) 6 >>> assert f(1,2,3)>0, File "", line 1 assert f(1,2,3)>0, ^ SyntaxError: invalid syntax >>> In the above, I could split the arguments to f (I guess b/c of the parens) but not for assert. I could use a backslash, but I find this ugly -- it that my only (best?) option? [I really like to assert my code to correctness and I like using the second argument to assert, but this resulted in a lot of long lines that I was unable to break except with an ugly backslash.] W From roland.hedberg at adm.umu.se Fri Jul 30 09:21:58 2010 From: roland.hedberg at adm.umu.se (Roland Hedberg) Date: Fri, 30 Jul 2010 15:21:58 +0200 Subject: Problem with Elementtree and XMLSchem instance type Message-ID: <4C52D1F6.7020209@adm.umu.se> Hi! I have the following XML snippet: .... This part after parsing with Elementtree gives me an Element instance with the following properties: > tree.tag {urn:oasis:names:tc:SAML:2.0:metadata}RoleDescriptor > tree.keys() ['{http://www.w3.org/2001/XMLSchema-instance}type'] > tree['{http://www.w3.org/2001/XMLSchema-instance}type'] fed:SecurityTokenServiceType And there is the problem, I've lost the coupling between the prefix 'fed' and the namespace "http://docs.oasis-open.org/wsfed/federation/200706". Is there any way I can get at the prefix <-> namespace mapping from an Element instance ? I've read the documentation I can find and there is nothing that tells me how to get at the mapping. If I print the Element instance the prefix 'fed' is replace by 'ns0' or something like that. Definitely something that has no connection to the original 'fed'. -- Roland From pdwjfndjbdgfyg at gmail.com Fri Jul 30 09:30:37 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 30 Jul 2010 06:30:37 -0700 (PDT) Subject: HOT SEXY VIDEOS X Message-ID: FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From __peter__ at web.de Fri Jul 30 09:45:37 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 15:45:37 +0200 Subject: pylint scores References: Message-ID: wheres pythonmonks wrote: > I am starting to use pylint to look at my code and I see that it gives a > rating. What values do experienced python programmers get on code not > targeting the benchmark? > > I wrote some code, tried to keep it under 80 characters per line, > reasonable variable names, and I got: > > 0.12 / 10. > > Is this a good score for one not targeting the benchmark? (pylint > running in default mode) No. About 5 is typically OK for undocumented code. I've heard. Ratings do not always make sense: $ for f in /usr/lib/python2.6/{glob,csv,doctest,collections}.py; do echo $f; pylint 2>/dev/null $f | grep "Your code has"; done /usr/lib/python2.6/glob.py Your code has been rated at 8.54/10 /usr/lib/python2.6/csv.py Your code has been rated at 6.45/10 /usr/lib/python2.6/doctest.py Your code has been rated at 7.77/10 /usr/lib/python2.6/collections.py Your code has been rated at -4.71/10 $ For mainstream code you can easily reach 10 by adding bogus docstrings and pointless long variable names, i. e. you can get higher scores for lower code quality. Peter PS: My favourite wtf message is "too few public methods" From alain at dpt-info.u-strasbg.fr Fri Jul 30 09:46:14 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 30 Jul 2010 15:46:14 +0200 Subject: Normalizing A Vector References: Message-ID: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Lawrence D'Oliveiro writes: > Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize > it (scale all components by the same factor) so its magnitude is 1. > > The usual way is something like this: > > L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > V = (V[0] / L, V[1] / L, V[2] / L) > > What I don?t like is having that intermediate variable L leftover after the > computation. Well, it also guarantees that the square root is computed once. > Here?s how to do it in one step: > > V = tuple \ > ( x / math.sqrt > ( > reduce(lambda a, b : a + b, (y * y for y in V), 0) > ) > for x in V > ) > > which, incidentally, also works for vectors with dimensions other than 3. And how many times does it call math.sqrt? (That's actually not easy to test. Does any insider know the answer? Does the compiler hoist the math.sqrt(...) out of the implicit loop? I guess not, because it can't assert that reduce has no side effect.) Your best bet is to define a function that does the normalization. Your (local) name will disappear at the end of the call. If you want it to work for any vector size: def norm(V): L = math.sqrt( sum( [x**2 for x in V] ) ) return [ x/L for x in V ] If you do a lot of such computations, have a look at numpy. -- Alain. From davea at ieee.org Fri Jul 30 09:51:08 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 30 Jul 2010 09:51:08 -0400 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: <1280489388.15025.1387504783@webmail.messagingengine.com> References: <1280489388.15025.1387504783@webmail.messagingengine.com> Message-ID: <4C52D8CC.6040104@ieee.org> python at bdurham.com wrote: >> Is there any trick in adding a console window to an application, that was built as 'windows' application? >> > > I was recently wondering the same thing myself. My research indicates > that its not possible to have a single Windows application that can run > in both console and GUI ("Windows") modes. > > Here are 2 links that explain this in more detail. > > > > > Malcolm > > Since we're talking MS Windows here, see: http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx You can access the AllocConsole and related functions with the win32 module: win32console This module is part of the win32 extensions, and also part of ActivePython distribution. DaveA From durga.disc at gmail.com Fri Jul 30 09:55:33 2010 From: durga.disc at gmail.com (Durga D) Date: Fri, 30 Jul 2010 06:55:33 -0700 (PDT) Subject: Basic Information about Python References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Message-ID: <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Hi JM, Thanks alot for your prompt response. If I include into windows setup, what will be setup size (assume before include 10 MB)? i mean, python supporting dlls/libs size for python exe. Regards, Durga. On Jul 30, 6:04?pm, Jean-Michel Pichavant wrote: > Durga D wrote: > > Hi All, > > > ? I am new to python based application developement. I am using > > Windows XP. > > > ? 1. Can I create desktop application (just hello world program) with > > Python > > language like exe in VC++? > > yeshttp://www.py2exe.org/> ? 2. If First statement is Yes, Can I include this application with > > my > > existing setup(assume 10 MB) for windows? > > you mean include it in a windows installer ? If so yes. > > > ? 3. If Second statement is Yes, What will be the setup size? > > > ? Thank in advance. > > > Regards, > > Durga. > > JM From V.vanBeveren at rijnhuizen.nl Fri Jul 30 10:06:17 2010 From: V.vanBeveren at rijnhuizen.nl (Vincent van Beveren) Date: Fri, 30 Jul 2010 16:06:17 +0200 Subject: The untimely dimise of a weak-reference In-Reply-To: References: Message-ID: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> Hi Peter, I did not know the object did not keep track of its bound methods. What advantage is there in creating a new bound method object each time its referenced? It seems kind of expensive. Regards, Vincent -----Original Message----- From: Peter Otten [mailto:__peter__ at web.de] Sent: vrijdag 30 juli 2010 15:06 To: python-list at python.org Subject: Re: The untimely dimise of a weak-reference Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here is a little > python 3.0 program to prove my point: > > import weakref > > print("Creating object...") > class A(object): > > def b(self): > print("I am still here") > > a = A() > > def d(r): > print("Aaah! Weakref lost ref") > > print("Creating weak reference") > > r = weakref.ref(a.b, d) The instance doesn't keep a reference of its bound method. Rather the bound method keeps a reference of its instance. Every time you say a.b you get a different bound method. What do you think should keep it alive? > print("Oh, wait, its already gone!") > print("Ref == None, cause of untimely demise: %s" % r()) > print("Object is still alive: %s" % a) > print("Function is still exists: %s" % a.b) > print("See:") > a.b() > > I also tried this in Python 2.5 and 2.6 (with minor modifications to the > syntax of course), and it yielded the exact same behavior. Why is this, > and is there anything I can do about it? I wish to reference these bound > functions, but I do not want to keep them in memory once the object they > belong to is no longer referenced. I fear you have to manage the methods' lifetime explicitly. Peter From __peter__ at web.de Fri Jul 30 10:18:39 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 16:18:39 +0200 Subject: The untimely dimise of a weak-reference References: Message-ID: Vincent van Beveren wrote: > I did not know the object did not keep track of its bound methods. What > advantage is there in creating a new bound method object each time its > referenced? It seems kind of expensive. While I didn't measure it I suppose that it saves a lot of memory. Peter From marduk at letterboxes.org Fri Jul 30 10:20:19 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 30 Jul 2010 10:20:19 -0400 Subject: measuring a function time In-Reply-To: <87tynhdugk.fsf@busola.homelinux.net> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> <87tynhdugk.fsf@busola.homelinux.net> Message-ID: <1280499619.659223.3.camel@paska> On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote: > Steven D'Aprano writes: > > > On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > > > >> This should be enough > >> > >>>>>import time > >>>>>tic = time.time() > >>>>>function() > >>>>>toc = time.time() > >>>>>print toc - tic > > > > You're typing that in the interactive interpreter, which means the > > timer is counting the seconds while you're typing subsequent > > commands. At the very least, you need to put that code into a > > function. > > Or, trivially improved as follows: > > >>> t0 = time.time(); function(); t1 = time.time() > >>> print t1 - t0 I'll just throw this out. I sometimes use a decorator to keep track of a functions execution times: def timed_function(f): """Function decorator that records the execution time of a function""" import time def funct(*args, **kwargs): __starttime = time.time() result = f(*args, **kwargs) __endtime = time.time() funct.runtime = __endtime - __starttime return result return funct Then >>> from goodies import timed_function >>> from time import sleep >>> @timed_function ... def test(n): ... sleep(n) ... >>> test(4) >>> test.runtime 4.003864049911499 Works for simple stuff anyway. -a From eliben at gmail.com Fri Jul 30 10:24:34 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 30 Jul 2010 17:24:34 +0300 Subject: Basic Information about Python In-Reply-To: <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Message-ID: On Fri, Jul 30, 2010 at 16:55, Durga D wrote: > Hi JM, > > Thanks alot for your prompt response. > > If I include into windows setup, what will be setup size (assume > before include 10 MB)? i mean, python supporting dlls/libs size for > python exe. > IIRC, the size of a simple "hello world" script packed with py2exe or PyInstaller is around 2-3 MB. If you use large GUI libraries (like PyQt or wxPython) it goes up to 6-10MB, and so on (more libraries -> larger .exe) Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri Jul 30 10:44:15 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jul 2010 16:44:15 +0200 Subject: The untimely dimise of a weak-reference In-Reply-To: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> References: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> Message-ID: Am 30.07.2010 16:06, schrieb Vincent van Beveren: > I did not know the object did not keep track of its bound methods. What advantage is there in creating a new bound method object each time its referenced? It seems kind of expensive. Instances of a class have no means of storing the bound method object. The or unbound bound method is a simple and small wrapper that keeps a reference to the class, "self" and the function object. Python keeps a pool of empty method objects in a free list. The creation of a new bound method just takes a few pointer assignments and three INCREFs. Christian From python at mrabarnett.plus.com Fri Jul 30 10:50:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jul 2010 15:50:56 +0100 Subject: measuring a function time In-Reply-To: <1280499619.659223.3.camel@paska> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> <87tynhdugk.fsf@busola.homelinux.net> <1280499619.659223.3.camel@paska> Message-ID: <4C52E6D0.3040503@mrabarnett.plus.com> Albert Hopkins wrote: > On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote: >> Steven D'Aprano writes: >> >>> On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: >>> >>>> This should be enough >>>> >>>>>>> import time >>>>>>> tic = time.time() >>>>>>> function() >>>>>>> toc = time.time() >>>>>>> print toc - tic >>> You're typing that in the interactive interpreter, which means the >>> timer is counting the seconds while you're typing subsequent >>> commands. At the very least, you need to put that code into a >>> function. >> Or, trivially improved as follows: >> >>>>> t0 = time.time(); function(); t1 = time.time() >>>>> print t1 - t0 > > I'll just throw this out. I sometimes use a decorator to keep track of > a functions execution times: > > > def timed_function(f): > """Function decorator that records the execution time of a > function""" > import time > def funct(*args, **kwargs): > __starttime = time.time() > result = f(*args, **kwargs) > __endtime = time.time() > funct.runtime = __endtime - __starttime > > return result > return funct > > Then > > >>> from goodies import timed_function > >>> from time import sleep > >>> @timed_function > ... def test(n): > ... sleep(n) > ... > >>> test(4) > >>> test.runtime > 4.003864049911499 > > Works for simple stuff anyway. > That won't work very well for functions which don't run for long. You could fix that by adding a counter for the number of times it's run and the total time. From pdl5000 at yahoo.com Fri Jul 30 12:19:32 2010 From: pdl5000 at yahoo.com (Paul Lemelle) Date: Fri, 30 Jul 2010 09:19:32 -0700 (PDT) Subject: Access stdout from external program. Message-ID: <771014.43405.qm@web52907.mail.re2.yahoo.com> JM, Thanks for the response.? I am trying to capture the stdout of a program from another program. Example, I want to launch the below program from a second python script then capture the first's program stdout to a file or variable. Is this possible? Thanks again, Paul Paul Lemelle wrote: > HELP! :) > > I am trying to output the following program's output to either a file > or variable, how can this be done? > > # Writing the output to a standard argv argument > > #1/usr/bin/python > > import sys > > for arg in sys.argv: >?? print arg > > #END > > Thanks, > Paul > > Hi Paul, after reading 4 times your post, I still don't see what you want to achieve. What are you calling a variable ? an os variable ? import sys file = open('testfile.txt', 'w') file.write(str(sys.argv)) file.close() second hit when googling your question: http://docs.python.org/tutorial/inputoutput.html JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Jul 30 12:28:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 18:28:30 +0200 Subject: Access stdout from external program. In-Reply-To: <771014.43405.qm@web52907.mail.re2.yahoo.com> References: <771014.43405.qm@web52907.mail.re2.yahoo.com> Message-ID: <4C52FDAE.6060803@sequans.com> Paul Lemelle wrote: > JM, > > Thanks for the response. > > I am trying to capture the stdout of a program from another program. > Example, I want to launch the below program from a second python > script then capture the first's program stdout to a file or variable. > > Is this possible? > > Thanks again, > Paul > use the subprocess module. import subprocess proc = subprocess.Popen(['echo', 'Hello World'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = proc.communicate() print out >> Hello World more details here http://docs.python.org/library/subprocess.html JM From python at rcn.com Fri Jul 30 12:34:13 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 30 Jul 2010 09:34:13 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: On Jul 25, 5:30?pm, Gregory Ewing wrote: > Raymond Hettinger wrote: > > Every class > > in the MRO implementing the target method *must* call super() to give > > the next class in the MRO a chance to run. > > EXCEPT for the last one, which must NOT call super! > > The posted example happens to work because object has > a default __init__ method that does nothing. But this > is not generally true of other methods, which means you > need a "terminating" class at the end of the MRO whose > methods don't call super. That is an important point and it is what Guido does in his examples: http://www.python.org/download/releases/2.2.3/descrintro/#cooperation The design options are: * if overriding a method provided by object() such as __init__(), __getattribute__() or __setattr__(), then you should call super() in each class that overrides or extends those methods. * if you know the whole class structure in advance, you call super() in every class except the last one -- that is what Guido does in the save() example. * if you don't know the whole class structure in advance, then you can't be sure which is that last class in the mro with the target method, so you need to wrap the super() call in a try / except AttributeError Raymond From kevinlcarlson at gmail.com Fri Jul 30 13:09:12 2010 From: kevinlcarlson at gmail.com (kevinlcarlson) Date: Fri, 30 Jul 2010 10:09:12 -0700 (PDT) Subject: Basic Information about Python References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Message-ID: <6ba18e21-b415-49f9-b96e-159d92e9b4a7@v32g2000prd.googlegroups.com> On Jul 30, 6:55?am, Durga D wrote: > Hi JM, > > ? ?Thanks alot for your prompt response. > > ? ?If I include into windows setup, what will be setup size (assume > before include 10 MB)? i mean, python supporting dlls/libs size for > python exe. > > Regards, > Durga. > > On Jul 30, 6:04?pm, Jean-Michel Pichavant > wrote: > > > Durga D wrote: > > > Hi All, > > > > ? I am new to python based application developement. I am using > > > Windows XP. > > > > ? 1. Can I create desktop application (just hello world program) with > > > Python > > > language like exe in VC++? > > > yeshttp://www.py2exe.org/> ? 2. If First statement is Yes, Can I include this application with > > > my > > > existing setup(assume 10 MB) for windows? > > > you mean include it in a windows installer ? If so yes. > > > > ? 3. If Second statement is Yes, What will be the setup size? > > > > ? Thank in advance. > > > > Regards, > > > Durga. > > > JM > > I use Pyinstaller with good results. The Python runtime dll is about two megs, plus a few others depending on what imports you are using. For example, using wxPython to create a Windows app will add several files totaling several megs. You can then simply copy the distribution file directory to the target machine, or use any good installer software. http://www.pyinstaller.org/ From subhakolkata1234 at gmail.com Fri Jul 30 13:23:44 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 30 Jul 2010 10:23:44 -0700 (PDT) Subject: Two minor questions on Class Message-ID: Dear Group, Hope everyone is fine. I was trying some examples of Python class. I took the following example from Ubuntu forum[http://ubuntuforums.org/ showthread.php?t=578930] class Person(object): def _init_(self,name,age): self.name=name self.age=age as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am getting the following error: >>> p=Person('Subha',40) Traceback (most recent call last): File "", line 1, in p=Person('Subha',40) TypeError: object.__new__() takes no parameters My question is, why the error is coming? Any problem in writing it? Can arguments be passed to class (other than inheritance) directly like this? As I was practising some early examples on class, does Python exist with any built in class, like the rich library of built in functions? Any good URL to learn examples? If any one can help, I would be grateful. As I pasted the code from GUI to notepad, there may be slight indentation problem, sorry for the same. Thanks in advance, Best Regards, Subhabrata. From nt_mahmood at yahoo.com Fri Jul 30 13:24:10 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 10:24:10 -0700 (PDT) Subject: how python works Message-ID: <953403.23661.qm@web50003.mail.re2.yahoo.com> I want to know how python?executes a .py file.?Sometimes when I run a file,?I get an error that?there is a syntax error. This shows that the parser read and parse the whole file. Sometimes?in the middle of the run I get an error that?another line has problem. So how does it work? if it doesn't compile and read line by line them why some times I get error?just before run? ? // Naderan *Mahmood; -------------- next part -------------- An HTML attachment was scrubbed... URL: From shashank.sunny.singh at gmail.com Fri Jul 30 13:36:28 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Fri, 30 Jul 2010 23:06:28 +0530 Subject: Two minor questions on Class In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 10:53 PM, joy99 wrote: > class Person(object): > def _init_(self,name,age): > self.name=name > self.age=age > > constructor has double underscores (both as prefix and suffix) __init__ -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jul 30 13:48:58 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 19:48:58 +0200 Subject: Two minor questions on Class References: Message-ID: joy99 wrote: > class Person(object): > def _init_(self,name,age): > self.name=name > self.age=age > > as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am > getting the following error: > > >>> p=Person('Subha',40) > > Traceback (most recent call last): > File "", line 1, in > p=Person('Subha',40) > TypeError: object.__new__() takes no parameters > > My question is, why the error is coming? Any problem in writing it? The so-called special methods in Python start with two underscores and end with two underscores, i. e. the initializer is called __init__ not _init_ > If any one can help, I would be grateful. As I pasted the code from > GUI to notepad, there may be slight indentation problem, sorry for the > same. It looks fine here. Peter From nagle at animats.com Fri Jul 30 14:04:52 2010 From: nagle at animats.com (John Nagle) Date: Fri, 30 Jul 2010 11:04:52 -0700 Subject: Use cases for "setattr" in existing code Message-ID: <4C531444.6010103@animats.com> I've been looking at existing code, using Google Code search, to see what use cases for "setattr" are actually used in production code. High-performance implementations like Shed Skin try to avoid dynamic creation of attributes, so it's worth seeing where this feature is used in production. 1. Copying "setattr" is used by "copy" and "pickle" to construct new objects without calling their constructors. This is seen only in code which also uses the CPython feature that the class of an object can be changed by storing into the "__class__" attribute. 2. Proxying A local object is being created as a proxy for some remote object. This shows up in the Python shim for Remember the Milk, in the wrapper for a restricted execution shell "rexec.py" 3. Representation of some other data structure. This is typically seen where some XML or JSON structure has been translated into a tree of Python objects, and attribute access is being used to access the data from the original object. This can result in name clashes with existing attributes and keywords. Used by BeautifulSoup. 4. Ordered dictionaries "odict.py" uses "setattr", but with the comment "FIXME", noting that unrestricted "setattr" can break the built-in attributes. 5. Enums The Google Wave API uses "setattr" in StringEnum, which creates an enumeration-like object. 6. Test platforms "setattr" is used in "Mocker" to insert shim objects for test purposes. This is a special case of proxying. Note that in all the above cases, "setattr" is being used during (or even prior to) object construction. It's rarely used on "live" objects. For the above cases, a mechanism for constructing general objects would do the job. Something like attrdict = { 'a' : 1, 'b' : 2 } obj = make_object('classname', attrdict) There are clearly use cases for dynamic object construction, but modifying the structure of an object after creation is quite rare. John Nagle From burton at userful.com Fri Jul 30 14:06:56 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 30 Jul 2010 12:06:56 -0600 Subject: how python works References: <953403.23661.qm@web50003.mail.re2.yahoo.com> Message-ID: Mahmood Naderan writes: > I want to know how python executes a .py file. Sometimes when I run a > file, I get an error that there is a syntax error. This shows that the > parser read and parse the whole file. Sometimes in the middle of the > run I get an error that another line has problem. So how does it work? > if it doesn't compile and read line by line them why some times I get > error just before run? Python first complies the file, which will find any syntax errors that you have in your code. If there are any, then it will stop there before executing the resulting compiled code. If the compilation is successful, it will then run the code, where you might have run-time errors, which are code with a proper syntax but errors during execution. -- Burton Samograd From nt_mahmood at yahoo.com Fri Jul 30 14:16:53 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 11:16:53 -0700 (PDT) Subject: how python works In-Reply-To: References: <953403.23661.qm@web50003.mail.re2.yahoo.com> Message-ID: <930269.70649.qm@web50002.mail.re2.yahoo.com> So is it a compiler or interpreter? ? // Naderan *Mahmood; ________________________________ From: Burton Samograd To: python-list at python.org Sent: Fri, July 30, 2010 10:36:56 PM Subject: Re: how python works Mahmood Naderan writes: > I want to know how python executes a .py file. Sometimes when I run a > file, I get an error that there is a syntax error. This shows that the > parser read and parse the whole file. Sometimes in the middle of the > run I get an error that another line has problem. So how does it work? > if it doesn't compile and read line by line them why some times I get > error just before run? Python first complies the file, which will find any syntax errors that you have in your code.? If there are any, then it will stop there before executing the resulting compiled code.? If the compilation is successful, it will then run the code, where you might have run-time errors, which are code with a proper syntax but errors during execution. -- Burton Samograd -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Fri Jul 30 14:17:58 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 30 Jul 2010 19:17:58 +0100 Subject: Library versions In-Reply-To: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: <4C531756.3040401@simplistix.co.uk> Peo wrote: > Is there some other smart way to do acheive this? Just turn them info python packages, and use buildout, pip or some other python package management tool to create the versions. You may, of course, just be able to svn the lot of them... (then you don't need to worry about numbering them at all) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From burton at userful.com Fri Jul 30 14:25:37 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 30 Jul 2010 12:25:37 -0600 Subject: how python works References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> Message-ID: Mahmood Naderan writes: > So is it a compiler or interpreter? There's a compiler that compiles python to bytecode which is then interpreted. This saves the interpreter from having to re-parse the code at run time. So, it's an interpreter that compiles the code first. -- Burton Samograd From clp2 at rebertia.com Fri Jul 30 14:37:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jul 2010 11:37:00 -0700 Subject: Normalizing A Vector In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 4:46 AM, Lawrence D'Oliveiro wrote: > Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize > it (scale all components by the same factor) so its magnitude is 1. > > The usual way is something like this: > > ? ?L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > ? ?V = (V[0] / L, V[1] / L, V[2] / L) > > What I don?t like is having that intermediate variable L leftover after the > computation. Here?s how to do it in one step: I suppose you'd be a fan of the proposed "given"/"where" statement then (but its prognosis isn't great): http://www.python.org/dev/peps/pep-3150/ Cheers, Chris -- http://blog.rebertia.com From me+list/python at ixokai.io Fri Jul 30 14:43:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 30 Jul 2010 11:43:27 -0700 Subject: how python works In-Reply-To: <930269.70649.qm@web50002.mail.re2.yahoo.com> References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> Message-ID: <4C531D4F.7080108@ixokai.io> On 7/30/10 11:16 AM, Mahmood Naderan wrote: > So is it a compiler or interpreter? Neither/both, depending on your definition of either word. It does not compile to machine code: it compiles to byte code (which it then usually, but not always, stores in a pyc file alongside the py file). It does not interpret the Python code on the fly, it is a VM which "interprets" the byte code. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From dieterbest at gmail.com Fri Jul 30 15:15:14 2010 From: dieterbest at gmail.com (Dieter) Date: Fri, 30 Jul 2010 12:15:14 -0700 (PDT) Subject: ImportError: No module named binascii Message-ID: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Hi there, I installed python 2.7 from the tar ball on python.org. the installation was pretty uneventful. However, I need to run someone elses python code and get the error message ImportError: No module named binascii Any recommendations how to correct this? Is there another tar file somewhere that I can download to install this missing module? Thanks a lot in advance. From news1234 at free.fr Fri Jul 30 15:18:15 2010 From: news1234 at free.fr (News123) Date: Fri, 30 Jul 2010 21:18:15 +0200 Subject: pylint scores In-Reply-To: References: Message-ID: <4C532577.8010906@free.fr> On 07/30/2010 03:12 PM, wheres pythonmonks wrote: > I am starting to use pylint to look at my code and I see that it gives a rating. > What values do experienced python programmers get on code not > targeting the benchmark? > > I wrote some code, tried to keep it under 80 characters per line, > reasonable variable names, and I got: > > 0.12 / 10. > > Is this a good score for one not targeting the benchmark? (pylint > running in default mode) > It's not a goodf core, but arrives easily if you never ran pylint before. With very little effort you should be able to be above 5 with a little more effort above 7 > Somewhat related: Is the backslash the only way to extend arguments > to statements over multiple lines? (e.g.) if you have an opening parenthesis, or bracked, then you don't need a backslash so instead of if longlonglonglonglonglonglonglongvar == \ otherlonglonglonglongvar: you could also write: if (longlonglonglonglonglonglonglongvar == otherlonglonglonglongvar): same works of course with asserts. > >>>> def f(x,y,z): return(x+y+z); > ... >>>> f(1,2, > ... 3) > 6 >>>> assert f(1,2,3)>0, > File "", line 1 > assert f(1,2,3)>0, > ^ > SyntaxError: invalid syntax >>>> > > In the above, I could split the arguments to f (I guess b/c of the > parens) but not for assert. I could use a backslash, but I find this > ugly -- it that my only (best?) option? > > [I really like to assert my code to correctness and I like using the > second argument to assert, but this resulted in a lot of long lines > that I was unable to break except with an ugly backslash.] > > W From nt_mahmood at yahoo.com Fri Jul 30 15:19:18 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 12:19:18 -0700 (PDT) Subject: how python works In-Reply-To: <4C531D4F.7080108@ixokai.io> References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> <4C531D4F.7080108@ixokai.io> Message-ID: <687136.2977.qm@web50003.mail.re2.yahoo.com> >Neither/both, depending on your definition of either word. It does not >compile to machine code: it compiles to byte code (which it then >usually, but not always, stores in a pyc file alongside the py file). It >does not interpret the Python code on the fly, it is a VM which >"interprets" the byte code. >So, it's an interpreter that compiles the code first. Thanks. I got it. ? // Naderan *Mahmood; ________________________________ From: Stephen Hansen To: python-list at python.org Sent: Fri, July 30, 2010 11:13:27 PM Subject: Re: how python works On 7/30/10 11:16 AM, Mahmood Naderan wrote: > So is it a compiler or interpreter? Neither/both, depending on your definition of either word. It does not compile to machine code: it compiles to byte code (which it then usually, but not always, stores in a pyc file alongside the py file). It does not interpret the Python code on the fly, it is a VM which "interprets" the byte code. -- ? Stephen Hansen ? ... Also: Ixokai ? ... Mail: me+list/python (AT) ixokai (DOT) io ? ... Blog: http://meh.ixokai.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Fri Jul 30 15:26:27 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 21:26:27 +0200 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: <4C52D8CC.6040104@ieee.org> References: <1280489388.15025.1387504783@webmail.messagingengine.com> <4C52D8CC.6040104@ieee.org> Message-ID: Hi, On 07/30/2010 03:51 PM, Dave Angel wrote: > python at bdurham.com wrote: >>> Is there any trick in adding a console window to an application, that >>> was built as 'windows' application? ,,, >>> Since we're talking MS Windows here, see: > > http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx > > You can access the AllocConsole and related functions with the win32 > module: > win32console > > This module is part of the win32 extensions, and also part of > ActivePython distribution. > Thanks a lot for your answer I'll check this out. From aahz at pythoncraft.com Fri Jul 30 15:26:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Jul 2010 12:26:42 -0700 Subject: py2app with weave fails References: <4f6430e5-31ea-450d-a2b9-56442a7141fa@k19g2000yqc.googlegroups.com> Message-ID: In article <4f6430e5-31ea-450d-a2b9-56442a7141fa at k19g2000yqc.googlegroups.com>, Soren wrote: > >I'm trying to create a standalone app using py2app, but it seems no >matter what I do I get this error: Try pythonmac-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From gelonida at gmail.com Fri Jul 30 15:27:48 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 21:27:48 +0200 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: On 07/30/2010 11:00 AM, Jimmy Retzlaff wrote: > On Fri, Jul 30, 2010 at 1:10 AM, Gelonida wrote: >> What I'd like to achieve ideally is to create a py2exe program, >> which >> will only display a window (so 'compiled' as 'windows'-application) if >> called normally. >> ... >> >> Is there any way to compile the same python script (myprog.py) from one >> py2exe script into once a 'windows' executable (myprog.exe) and once >> into a 'console' executable (myprog_debug.exe)? > > I can't think of an easy way to achieve the first approach - I've > always taken the second approach. The advanced example included with > py2exe has an example of how to do this. Look at all the occurrences > of test_wx in the following link to see all the pieces involved: > > http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup > > This uses an alternate form of the "windows" and "console" arguments > where each target is an object with specially named member variables > rather than a string that names the .py file (this string is one of > the member variables). This is necessary so you can give different > names to the console version and the windows version. > Thanks, I'll read thorugh it. From Space998 at hotmail.com Fri Jul 30 15:30:11 2010 From: Space998 at hotmail.com (spudnik) Date: Fri, 30 Jul 2010 12:30:11 -0700 (PDT) Subject: trace of Thermite (tm) at WTC, almost no asbestos: if the main beams had been clad, they mightn't have weakened enough to collapse! References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> <9b6a9f32-333c-4e2a-a621-47f7770bb88e@x20g2000pro.googlegroups.com> Message-ID: <36e42adf-cd1e-4387-8d65-3170b3fa7799@h17g2000pri.googlegroups.com> here are some speeches about the British World Wars, collected in one book on http://tarpley.net: How the Venetian System Was Transplanted Into England New Federalist, June 3, 1996 The British Empire Bid for Undisputed World Domination, 1850-1870 Schiller Institute Food For Peace Conference, Chicago, February 22-23, 1992 Lord Palmerston?s Multicultural Human Zoo ICLC Conference, February 20, 1994 King Edward VII: Evil Demiurge of the Triple Entente and World War 1 ICLC Conference, February, 1995 Sir Edward Grey Turned Sarajevo Crisis Into War Printed in The American Almanac, March, 1995 The Versailles Thesis: The Roots of WWI, and WWII Conference Speech by Webster Tarpley, Schiller Institute Food For Peace Conference, Chicago, Illinois, February 22-23, 1992. The Versailles Treaty: The War Guilt Clause Printed in the American Almanac, March, 1995 British Financial Warfare: 1929; 1931-33; How The City Of London Created The Great Depression thus: we aren't all einsteinians; you are the one, who insists upon his reification of the corpuscle, which is just a willy-nilly, mere interpretation of "quantum of light," vis-a-vu Planck's great idea and the electonic trace in the photo-electrical effect.... well, his and Infeld's acoustic fridge was pretty cool! thus: there are two 3d versions of the pythag.thm., each with different dimensional attributes. iff you don't study Fermat's numbertheorie, you're up Shitz Creek without a paddle; however, it is better to start with his "reconstruction of Euclid's porisms," although they are just planar (synthetic geometry: see "Geometrical Fragments," belowsville .-) > NO! thus: and, the other half d'oil evaporates, as has been shown of late (again) in the newspapers. Congress and the Administration are a bit behind, in using Iran Oil's big blow-out in the Gulf, to leverage BP's cap&trade nostrum; eh? a-yup: Such microbes have been found in every ocean of the world sampled, from the Arctic to Antarctica. But there are reasons to think that the process may occur more quickly in the Gulf than in other oceans. --les ducs d'oil! http://tarpley.net/online-books/ --Light, A History! http://wlym.com/~animations/fermat/index.html From python at mrabarnett.plus.com Fri Jul 30 16:06:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jul 2010 21:06:52 +0100 Subject: ImportError: No module named binascii In-Reply-To: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> References: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Message-ID: <4C5330DC.1030606@mrabarnett.plus.com> Dieter wrote: > Hi there, > > I installed python 2.7 from the tar ball on python.org. the > installation was pretty uneventful. However, I need to run someone > elses python code and get the error message > > ImportError: No module named binascii > > Any recommendations how to correct this? Is there another tar file > somewhere that I can download to install this missing module? > > Thanks a lot in advance. > There isn't a separate binascii module. Have you tried: >>> import binascii at the Python prompt? That works for me (Windows XP) and will show whether it's missing somehow. From davea at ieee.org Fri Jul 30 17:04:08 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 30 Jul 2010 17:04:08 -0400 Subject: ImportError: No module named binascii In-Reply-To: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> References: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Message-ID: <4C533E48.1080609@ieee.org> Dieter wrote: > Hi there, > > I installed python 2.7 from the tar ball on python.org. the > installation was pretty uneventful. However, I need to run someone > elses python code and get the error message > > ImportError: No module named binascii > > Any recommendations how to correct this? Is there another tar file > somewhere that I can download to install this missing module? > > Thanks a lot in advance. > > > You should include the whole error message, including the traceback. But perhaps first you should try importing binascii yourself, in the interpreter. DaveA From rui.vapps at gmail.com Fri Jul 30 18:03:04 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 30 Jul 2010 15:03:04 -0700 (PDT) Subject: os.fork on linux defunct Message-ID: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> I'm running python 2.4 on linux. I use python os.fork run tcpdump, but after I kill the forked process (tcpdump) in linux it shows defunct here is the code: #!/usr/bin/python import time, os class Test: def fork(self): self.pid=os.fork() if self.pid=0: args=['tcpdump', '-i', 'eth0', 'port', '80' ''] os.execl("/usr/sbin/tcpdump", *args) os._exit(0) def kill(self): os.kill(self.pid, 15) if __name__=='__main__': while True: test=Test() test.fork() time.sleep(2) test.kill() time.sleep(30) after I call kill() it will kill tcpdump (capture will stop) but on linux, ps shows tcpdump as defunct process what am I missing? thanks for any help. From rui.vapps at gmail.com Fri Jul 30 18:09:28 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 30 Jul 2010 15:09:28 -0700 (PDT) Subject: os.fork on linux defunct References: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> Message-ID: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> On Jul 30, 6:03?pm, Ray wrote: > I'm running python 2.4 on linux. I use python os.fork run tcpdump, but > after I kill the forked process (tcpdump) in linux it shows defunct > > here is the code: > > #!/usr/bin/python > import time, os > class Test: > ? ? def fork(self): > ? ? ? ? self.pid=os.fork() > ? ? ? ? if self.pid=0: > ? ? ? ? ? ? args=['tcpdump', '-i', 'eth0', 'port', '80' ''] > ? ? ? ? ? ? os.execl("/usr/sbin/tcpdump", *args) > ? ? ? ? ? ? os._exit(0) > ? ? def kill(self): > ? ? ? ? os.kill(self.pid, 15) > if __name__=='__main__': > ? ? while True: > ? ? ? ? test=Test() > ? ? ? ? test.fork() > ? ? ? ? time.sleep(2) > ? ? ? ? test.kill() > ? ? ? ? time.sleep(30) > > after I call kill() it will kill tcpdump (capture will stop) but on > linux, ps shows tcpdump as defunct process > what am I missing? > > thanks for any help. I think I found it. need to call os.wait() From ajuffali at yahoo.com Fri Jul 30 19:52:51 2010 From: ajuffali at yahoo.com (AJ) Date: Fri, 30 Jul 2010 16:52:51 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 Message-ID: Dear users, I have written a sample program that ran correctly with earlier than Mac OS 10.6. The answer field Label does not align correctly. I downloaded the latest Python 2.7 release but still did not solve the problem. Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" #!/usr/bin/env python from Tkinter import * from tkMessageBox import * import sys win = Tk() #win.tk.call('console', 'hide') try: win.tk.call('after','idle','console','hide') except TclError: pass ScreenX = win.winfo_screenwidth() ScreenY = win.winfo_screenheight() ScreenX = (ScreenX/2) - 250 ScreenY = (ScreenY/2) - 200 win.geometry('500x300%+d%+d' %(ScreenX, ScreenY)) win.title("'Place' Geometry Test") win.resizable(width=False, height=False) FirstN = StringVar() SecondN = StringVar() Answer = StringVar() Verd12 = ("Verdana","11") Verd16 = ("Verdana","16") Verd25 = ("Verdana","25") Sys16 = ("System" ,"16") #----------------- AboutDialog ---------------------------- class AboutDialog(Toplevel): def __init__(self, parent): Toplevel.__init__(self, parent) self.configure(bg = 'white', borderwidth=3) self.geometry('200x300%+d%+d' %(ScreenX, ScreenY)) self.title('About...') self.resizable(height=FALSE, width=FALSE) self.transient(parent) self.grab_set() self.protocol("WM_DELETE_WINDOW", self.OkToExit) self.parent = parent self.FillDialog() self.Btn.focus_set() self.bind('',self.OkToExit) self.bind('',self.OkToExit) self.bind('', Done) self.bind('', Done) self.wait_window() def FillDialog(self): self.AboutText = "\n\n\nPlace Geometry Test\n\nBy\n\nAmin Aljuffali" self.Lbl = Label(self, text=self.AboutText, font=Verd16, bg = 'white') self.Lbl.pack(side=TOP) self.Lb2 = Label(self, text="April 1, 2007", height = 1, font=Verd12, bg = 'white') self.Lb2.pack(side=TOP) self.Lb3 = Label(self, text=" ", height = 3, font=Verd12, bg = 'white') self.Lb3.pack(side=TOP) self.Btn = Button(self, text='Done', font=Sys16, width=8, height=1, command=self.OkToExit) self.Btn.pack(side=TOP) self.Lb4 = Label(self, text=" ", height = 3, font=Verd12, bg = 'white') self.Lb4.pack(side=BOTTOM) self.update() def OkToExit(self, event=None): self.destroy() #---------------------------------------------------------- def ShowDialog(): AboutDialog(win) def done(): win.destroy() win.quit def Done(e): win.destroy() win.quit def CheckAlfanumeric(x): if x == '': return False for ch in x: if ch not in['.','-','+','0','1','2','3','4','5','6','7','8','9','e','E']: return False return True def Multiply(): #global FirstN, SecondN, Answer try: a = FirstN.get().strip() if not CheckAlfanumeric(a): raise ValueError b = SecondN.get().strip() if not CheckAlfanumeric(b): raise ValueError FirstN.set(a) SecondN.set(b) Answer.set(str(float(a) * float(b))) except ValueError: showwarning("Warning...","Input Error!") return def MakeToplevelMenu(topwin): top = Menu(topwin) topwin.config(menu=top) if sys.platform == 'darwin' and '.app' in sys.executable: application = Menu(top, name='apple') application.add_command(label='About...', command=ShowDialog, underline=0) top.add_cascade(label='PlaceTest', menu=application, underline=0) fileMenu = Menu(top, tearoff=0) fileMenu.add_command(label='Exit', command=done, underline=0) top.add_cascade(label='File', menu=fileMenu, underline=0) helpMenu = Menu(top, tearoff=0) helpMenu.add_command(label='About...', command=ShowDialog, underline=0) top.add_cascade(label='Help', menu=helpMenu, underline=0) return MakeToplevelMenu(win) L1 = Label(win, text='Multiply Two Numbers', font=Verd25, bg = 'white') L2 = Label(win, text='First Number:', font=Verd16, bg = 'white') L3 = Label(win, text='Second Number:', font=Verd16, bg = 'white') L4 = Label(win, text='', textvariable=Answer, font=Sys16, bg = 'white', bd=1, width=20, height=1, anchor=W, relief=SOLID) L5 = Label(win, text='Written by Amin Aljuffali', font=Verd12,padx=2, bg = 'white', anchor=W, relief=FLAT) B1 = Button(win, text='Multiply', font=Sys16, width=19, height=1, command=Multiply) B2 = Button(win, text='Quit', font=Sys16, width=19, height=1, command=done) F1 = Frame(win, relief=FLAT, bd=0, bg='#336699') F2 = Frame(win, relief=FLAT, bd=0, bg='#336699') F3 = Frame(win, relief=FLAT, bd=0, bg='#336699') E1 = Entry(win, textvariable=FirstN, relief=SOLID, font=Sys16, bg = 'white',bd=1) E2 = Entry(win, textvariable=SecondN, relief=SOLID, font=Sys16, bg = 'white', bd=1) win.bind('', Done) win.bind('', Done) F1.place(relx=0.0,rely=0.01, anchor=NW, width=600, height=5) L1.place(relx=0.5,rely=0.09, anchor=CENTER) F2.place(relx=0.0,rely=0.16, anchor=NW, width=600, height=5) E1.place(relx=0.32,rely=0.32, anchor=W) E2.place(relx=0.32,rely=0.44, anchor=W) L2.place(relx=0.3,rely=0.32, anchor=E) L3.place(relx=0.3,rely=0.44, anchor=E) L4.place(relx=0.32,rely=0.56, anchor=W) B1.place(relx=0.525,rely=0.69, anchor=CENTER) B2.place(relx=0.525,rely=0.81, anchor=CENTER) F3.place(relx=0.0,rely=0.9, anchor=W, width=600, height=5) L5.place(relx=0.01,rely=0.95, anchor=W) E1.focus_set() win.update() win.mainloop() sys.exit(0) From rantingrick at gmail.com Fri Jul 30 20:07:24 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 30 Jul 2010 17:07:24 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> On Jul 30, 6:52?pm, AJ wrote: > Dear users, > > I have written a sample program that ran correctly with earlier than > Mac OS 10.6. The answer field Label does not align correctly. I > downloaded the latest Python 2.7 release but still did not solve the > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" DO YOURSELF A HUGE FAVOR AJ... Learn how to use the "pack" and "grid" geometry managers available in Tkinter before it's too late. Well, unless of course your a sadist. In that case just ignore my post completely. 8^O http://effbot.org/tkinterbook/tkinter-index.htm#introduction From cs at zip.com.au Fri Jul 30 20:39:24 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 31 Jul 2010 10:39:24 +1000 Subject: os.fork on linux defunct In-Reply-To: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> References: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> Message-ID: <20100731003924.GA17823@cskk.homeip.net> On 30Jul2010 15:09, Ray wrote: | On Jul 30, 6:03?pm, Ray wrote: | > I'm running python 2.4 on linux. I use python os.fork run tcpdump, but | > after I kill the forked process (tcpdump) in linux it shows defunct [...] | > after I call kill() it will kill tcpdump (capture will stop) but on | > linux, ps shows tcpdump as defunct process | > what am I missing? | > thanks for any help. | | I think I found it. need to call os.wait() Yep. "defunct" == "zombie". See: http://code.activestate.com/lists/python-list/580569/ Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Talk is the bastard redheaded stepchild of email and the telephone. - Geoff Miller, geoffm at purplehaze.Corp.Sun.COM From drsalists at gmail.com Fri Jul 30 20:48:52 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 17:48:52 -0700 Subject: pylint scores In-Reply-To: <4C532577.8010906@free.fr> References: <4C532577.8010906@free.fr> Message-ID: On Fri, Jul 30, 2010 at 12:18 PM, News123 wrote: > On 07/30/2010 03:12 PM, wheres pythonmonks wrote: > > I am starting to use pylint to look at my code and I see that it gives a > rating. > > What values do experienced python programmers get on code not > > targeting the benchmark? > > > > I wrote some code, tried to keep it under 80 characters per line, > > reasonable variable names, and I got: > > > > 0.12 / 10. > > > > Is this a good score for one not targeting the benchmark? (pylint > > running in default mode) > > > It's not a goodf core, but arrives easily if you never ran pylint before. > With very little effort you should be able to be above 5 > with a little more effort above 7 > > > > Somewhat related: Is the backslash the only way to extend arguments > > to statements over multiple lines? (e.g.) > > if you have an opening parenthesis, or bracked, then you don't need a > backslash > > so instead of > if longlonglonglonglonglonglonglongvar == \ > otherlonglonglonglongvar: > > you could also write: > > if (longlonglonglonglonglonglonglongvar == > otherlonglonglonglongvar): > > > same works of course with asserts. > > > > >>>> def f(x,y,z): return(x+y+z); > > ... > >>>> f(1,2, > > ... 3) > > 6 > >>>> assert f(1,2,3)>0, > > File "", line 1 > > assert f(1,2,3)>0, > > ^ > > SyntaxError: invalid syntax > >>>> > > > > In the above, I could split the arguments to f (I guess b/c of the > > parens) but not for assert. I could use a backslash, but I find this > > ugly -- it that my only (best?) option? > > > > [I really like to assert my code to correctness and I like using the > > second argument to assert, but this resulted in a lot of long lines > > that I was unable to break except with an ugly backslash.] > > > > W > > IMO, the important thing about pylint's scoring is that it's but one way of many of producing good Python code. However, it's also one of the easier ways of producing good python code. I personally like to get my scores up near 10, by annotating in comments about the few things that pylint flags that I can't just code around. This requires jumping through some slightly silly hoops (EG the previously mentioned "too few public methods", which my various container classes always trip over), but going through this process is worthwhile for highlighting the hoops pylint can detect that -aren't- so silly. The one thing I like to leave unfixed is FIXME's - otherwise my preference would be to go for a score of 10 for production code. I also like to create a ./this-pylint script for my various projects, that have global overrides - things like identifier rules, line length, and... I don't get blanks instead of tabs. Blanks are fine if you don't understand tabs (or think someone in the future who doesn't understand tabs will need to work on your code), but tabs allow everyone to see code indented the way -they- want to see it, not just the way the original author wanted to see it. This script (./this-pylint) will also save output from the test in a text file, for make (or other dependency handling program) to use to avoid re-pylint'ing unmodified code. It'll give an error typically, if pytlint detects any errors other than FIXME's (excluding ones, as I mentioned before, that have a comment disabling the warning, of course). I'm more than a little sad that pylint doesn't seem to be moving to python 3 in any big hurry. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Jul 30 20:52:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 12:52:29 +1200 Subject: os.fork on linux defunct References: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> Message-ID: In message <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d at q16g2000prf.googlegroups.com>, Ray wrote: > I think I found it. need to call os.wait() The rule on Unix/Linux systems is: ?always remember to gobble your zombie children?. From anushkaphotos1 at rediffmail.com Fri Jul 30 20:58:10 2010 From: anushkaphotos1 at rediffmail.com (ANUSHKA) Date: Fri, 30 Jul 2010 17:58:10 -0700 (PDT) Subject: Anushka for Shape FX Hot Shot Thigh Gel Message-ID: Anushka for Shape FX Hot Shot Thigh Gel ************************************** http://sites.google.com/site/anushkaphotosalert From cousinstanley at gmail.com Fri Jul 30 21:00:00 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sat, 31 Jul 2010 01:00:00 +0000 (UTC) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: > Parentheses are punctuation. Why not leave spaces around the commas as well, > to be consistent? > > myTuple = ( 1 , 2 , 3 , 4 , 5 ) Personally, I do use this particular style with commas as I find it more readable to my old and tired eyes .... Mandate m o r e whitespace .... :-) -- Stanley C. Kitching Human Being Phoenix, Arizona From drsalists at gmail.com Fri Jul 30 21:12:47 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 18:12:47 -0700 Subject: Multiprocessing taking too much time In-Reply-To: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> References: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 29, 2010 at 12:04 PM, John Nagle wrote: > On 7/29/2010 11:08 AM, Shailendra wrote: > >> Hi All, >> I have a following situation. >> ==================PSUDO CODE START================== >> class holds_big_array: >> big_array #has a big array >> >> def get_some_element(self, cond) # return some data from the array >> from the big array >> ==================PSUDO CODE END==================== >> I wanted to use multiprocessing module to parallelise calling >> "get_some_element". I used following kind of code >> >> ==================PSUDO CODE START================== >> pool = Pool(processes=2) >> holder =holds_big_array() #class instantiation >> def callback_f(result): >> do something with result >> loop many times >> pool.apply_async(holder.get_some_element,args,callback=callback_f) >> pool.close() >> pool.join() >> ==================PSUDO CODE END==================== >> Note: Had to do something to enable instance method being pickled... >> >> I tested this with less than realistic size of big_array . My parallel >> version works much slower than than the normal serial version (10-20 >> sec vs 7-8 min). I was wonder what could be the possible reason.\ > > I think the place to start when code is slow, is usually to use a profiler. However, in this case it's likely as you say, a pickling issue. > It's hard to tell from your "PSUDO CODE", but it looks like each > access to the "big array" involves calling another process. > > Calling a function in another process is done by creating an > object to contain the request, running it through "pickle" to convert > it to a stream of bytes, sending the stream of bytes through a socket or > pipe to the other process, running the byte stream through "unpickle" to > create an object like the original one, but in a different process, and > calling a function on the newly created object in the receiving process. > This entire sequence has to be done again in reverse > to get a reply back. > > This is hundreds of times slower than a call to a local function. > > The "multiprocessing module" is not a replacement for thread-level > parallelism. It looks like it is, but it isn't. It's only useful for > big tasks which require large amounts of computation and little > interprocess communication. Appropriately-sized tasks to send out > to another process are things like "parse large web page" or > "compress video file", not "access element of array". Well, multiprocessing'll replace threading in many scenarios, including some where CPython's threading isn't very useful. The O.P. might look into storing their array in shared memory - multiprocessing facilitates that pretty well. Or, as John has suggested, chunk up the work into larger pieces than individual array accesses. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jul 30 22:06:27 2010 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jul 2010 19:06:27 -0700 (PDT) Subject: Ascii to Unicode. References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: <9ea0e0e4-ad04-4d3c-b289-011cf5146e8f@p22g2000pre.googlegroups.com> On Jul 30, 4:18?am, Carey Tilden wrote: > In this case, you've been able to determine the > correct encoding (latin-1) for those errant bytes, so the file itself > is thus known to be in that encoding. The most probably "correct" encoding is, as already stated, and agreed by the OP to be, cp1252. From greg.ewing at canterbury.ac.nz Fri Jul 30 22:25:39 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 31 Jul 2010 14:25:39 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bhfcaF6ftU1@mid.individual.net> Steven D'Aprano wrote: > A > / \ > C B > \ / > D > / \ > E F > > Yes, a super call might jog left from > C to B, but only when being called from one of the lower classes D-F. > That's still an upwards call relative to the originator, not sidewards. But it's not an upward call relative to the class mentioned in the super() call, which is why I say it's misleading. -- Greg From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:07:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:07:25 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> <8bhfcaF6ftU1@mid.individual.net> Message-ID: <4c53936d$0$11091$c3e8da3@news.astraweb.com> On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> A >> / \ >> C B >> \ / >> D >> / \ >> E F >> >> Yes, a super call might jog left from C to B, but only when being >> called from one of the lower classes D-F. That's still an upwards call >> relative to the originator, not sidewards. > > But it's not an upward call relative to the class mentioned in the > super() call, which is why I say it's misleading. Which class would that be? I think I'm going to need an example that demonstrates what you mean, because I can't make heads or tails of it. Are you suggesting that a call to super(C, self).method() from within C might call B.method(self)? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:08:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:08:44 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c5393bb$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 14:43:07 +0200, Jean-Michel Pichavant wrote: > Quoting Michele's article (I think he's still hanging around this list) > > "Readers familiar will single inheritance languages, such as Java or > Smalltalk, will have a clear concept of superclass in mind. This > concept, however, has /no useful meaning/ in Python or in other multiple > inheritance languages". I have read Michelle Simionato's articles on super in Python. He has taught me a lot. But on that specific matter, I think he is wrong. Of course, he is right to say that the concept of *the* superclass is meaningless in a MI language like Python. If MyClass inherits method spam() from class A, and inherits method ham() from class B, which is "the" superclass of MyClass? But Michelle is wrong to conclude that the problem lies with the concept of *superclass*. The problem lies with the idea that there is ONE superclass. By dismissing the entire concept, he is throwing out the baby with the bathwater. The useful, and I would argue *correct*, concept of superclass is very simple. It is a reflection of subclass: if Z is a subclass of A, then A is a superclass of Z. This follows e.g. superset and subset. We don't have any problem understanding that a class can have many subclasses. Why the resistance to the idea that a class can have many superclasses? Even in a single inheritance language, if we had a class hierarchy A -> B -> C -> ... -> Y -> Z it makes perfect sense to describe *all* of A-Y as superclasses of Z, just as we describe all of B-Z as subclasses of A. -- Steven From greg.ewing at canterbury.ac.nz Fri Jul 30 23:11:30 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 31 Jul 2010 15:11:30 +1200 Subject: The untimely dimise of a weak-reference In-Reply-To: References: Message-ID: <8bhi2fFifjU1@mid.individual.net> Vincent van Beveren wrote: > I was working with weak references in Python, and noticed that it > was impossible to create a weak-reference of bound methods. > is there anything I can do about it? You can create your own wrapper that keeps a weak reference to the underlying object. Here's an example. import weakref class weakmethod(object): def __init__(self, bm): self.ref = weakref.ref(bm.im_self) self.func = bm.im_func def __call__(self, *args, **kwds): obj = self.ref() if obj is None: raise ValueError("Calling dead weak method") self.func(obj, *args, **kwds) if __name__ == "__main__": class A(object): def foo(self): print "foo method called on", self a = A() m = weakmethod(a.foo) m() del a m() From ian.g.kelly at gmail.com Fri Jul 30 23:40:21 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 30 Jul 2010 21:40:21 -0600 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <87pqy5du0n.fsf@busola.homelinux.net> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: On Fri, Jul 30, 2010 at 6:38 AM, Hrvoje Niksic wrote: > Gregory Ewing writes: > >> I think the point is that the name is misleading, because it makes it >> *sound* like it's going to call a method in a superclass, when it fact >> it might not. > > That is indeed confusing to some people, especially those who refuse to > to accept the notion that "superclass" means the same as "next in MRO", > maintaining instead that superclass refers to one of the base classes, > their bases, etc. -- IMO a defensible position. > > super might have better been called next_in_mro, next_method, or > next_class, except those are harder to type, and way less catchy than > "super". ?The Dylan and CLOS operator that super is most closely based > on is called (call-)next-method. I have to chime in and agree that the name "super" is problematic. I'm reading this thread with a sense of alarm because I apparently never read the super() documentation too closely (why would I? "Oh, it just accesses an attribute from a superclass. Moving on.") and have been writing code for the past four years under the impression that super() will always refer to a superclass of the current class. Fortunately, I don't use multiple inheritance often, and when I do I prefer to write the superclasses explicitly (perhaps because of the same misconception), so I probably haven't really abused it terribly. On a tangent, is it just me, or is the super() documentation incorrect, or at least unclear? Quoting from the first two paragraphs: super(type[, object-or-type]) Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped. The __mro__ attribute of the type lists the method resolution search order used by both getattr() and super(). The attribute is dynamic and can change whenever the inheritance hierarchy is updated. In the first paragraph, "type" refers to "type", the first parameter in the function signature. In the second paragraph, "type" refers to the type instance or the type of the object passed as the second argument. If it also referred to the first parameter, then super() would always access a superclass as I initially thought; I wonder if this might have been partially responsible for my confusion. Cheers, Ian From ajuffali at yahoo.com Fri Jul 30 23:45:12 2010 From: ajuffali at yahoo.com (AJ) Date: Fri, 30 Jul 2010 20:45:12 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> Message-ID: <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> On Jul 30, 5:07?pm, rantingrick wrote: > On Jul 30, 6:52?pm, AJ wrote: > > > Dear users, > > > I have written a sample program that ran correctly with earlier than > > Mac OS 10.6. The answer field Label does not align correctly. I > > downloaded the latest Python 2.7 release but still did not solve the > > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" > > DO YOURSELF A HUGE FAVOR AJ... Learn how to use the "pack" and "grid" > geometry managers available in Tkinter before it's too late. Well, > unless of course your a sadist. In that case just ignore my post > completely. 8^O > > http://effbot.org/tkinterbook/tkinter-index.htm#introduction I know the pack and grid. They do not allow me to position my widget the way I want. You have to go back to first grade and relearn the phrase ?If you have nothing nice to say do not say anything at all?. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:47:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:47:49 GMT Subject: default behavior References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c539ce4$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote: > Sorry, doesn't the following make a copy? > >>>>> from collections import defaultdict as dd x = dd(int) >>>>> x[1] = 'a' >>>>> x >> defaultdict(, {1: 'a'}) >>>>> dict(x) >> {1: 'a'} >> >> >> > > I was hoping not to do that -- e.g., actually reuse the same underlying > data. It does re-use the same underlying data. >>> from collections import defaultdict as dd >>> x = dd(list) >>> x[1].append(1) >>> x defaultdict(, {1: [1]}) >>> y = dict(x) >>> x[1].append(42) >>> y {1: [1, 42]} Both the defaultdict and the dict are referring to the same underlying key:value pairs. The data itself isn't duplicated. If they are mutable items, a change to one will affect the other (because they are the same item). An analogy for C programmers would be that creating dict y from dict y merely copies the pointers to the keys and values, it doesn't copy the data being pointed to. (That's pretty much what the CPython implementation does. Other implementations may do differently, so long as the visible behaviour remains the same.) > Maybe dict(x), where x is a defaultdict is smart? I agree that a > defaultdict is safe to pass to most routines, but I guess I could > imagine that a try/except block is used in a bit of code where on the > key exception (when the value is absent) populates the value with a > random number. In that application, a defaultdict would have no random > values. If you want a defaultdict with a random default value, it is easy to provide: >>> import random >>> z = dd(random.random) >>> z[2] += 0 >>> z defaultdict(, {2: 0.30707092626033605}) The point which I tried to make, but obviously failed, is that any piece of code has certain expectations about the data it accepts. If take a function that expects an int between -2 and 99, and instead decide to pass a Decimal between 100 and 150, then you'll have problems: if you're lucky, you'll get an exception, if you're unlucky, it will silently give the wrong results. Changing a dict to a defaultdict is no different. If you have code that *relies* on getting a KeyError for missing keys: def who_is_missing(adict): for person in ("Fred", "Barney", "Wilma", "Betty"): try: adict[person] except KeyError: print person, "is missing" then changing adict to a defaultdict will cause the function to misbehave. That's not unique to dicts and defaultdicts. > Besides a slightly different favor, does the following have applications > not covered by defaultdict? > > m.setdefault('key', []).append(1) defaultdict calls a function of no arguments to provide a default value. That means, in practice, it almost always uses the same default value for any specific dict. setdefault takes an argument when you call the function. So you can provide anything you like at runtime. > I think I am unclear on the difference between that and: > > m['key'] = m.get('key',[]).append(1) Have you tried it? I guess you haven't, or you wouldn't have thought they did the same thing. Hint -- what does [].append(1) return? -- Steven From drsalists at gmail.com Sat Jul 31 00:18:20 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 21:18:20 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 11:11 PM, Chris Rebert wrote: > On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh > wrote: > > Sorry, I might have been a bit vague: > > (Also, I am new to pythong) > > I am trying to do construct my own web session tracking algorithm for a > web > > server (which also I have constructed). The book keeping is for the > session > > information I track. The dictionary object will do this for me. I was > > initially using a plain dictionary object, but I read this in the > > documentation that made me think about the question I asked :- > > Does your program actually make use of the ordering? If so, then yes, > using OrderedDict is obviously preferable (Why reimplement something > needlessly?). If not, then why bother with the extra complication? > > (You are aware that the "ordered" in OrderedDict means that its keys > are ordered, and not that, say, a list containing OrderedDicts can be > sorted, right?) Actually, a collections.OrderedDict saves things not in key order, but in chronological order: $ /usr/local/python27/bin/python Python 2.7rc1 (r27rc1:81772, Jun 10 2010, 14:28:26) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import collections >>> d = collections.OrderedDict() >>> d OrderedDict() >>> d[5] = 'a' >>> d[3] = 'b' >>> d[8] = 'c' >>> print d.keys() [5, 3, 8] >>> If you want things saved in key order, you might try my treap or duptreap module: http://stromberg.dnsalias.org/~dstromberg/treap/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From wherespythonmonks at gmail.com Sat Jul 31 01:02:47 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sat, 31 Jul 2010 01:02:47 -0400 Subject: default behavior In-Reply-To: <4c539ce4$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> Message-ID: > > Hint -- what does [].append(1) return? > Again, apologies from a Python beginner. It sure seems like one has to do gymnastics to get good behavior out of the core-python: Here's my proposed fix: m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) Yuck! So I guess I'll use defaultdict with upcasts to dict as needed. On a side note: does up-casting always work that way with shared (common) data from derived to base? (I mean if the data is part of base's interface, will b = base(child) yield a new base object that shares data with the child?) Thanks again from a Perl-to-Python convert! W On Fri, Jul 30, 2010 at 11:47 PM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote: > >> Sorry, doesn't the following make a copy? >> >>>>>> from collections import defaultdict as dd x = dd(int) >>>>>> x[1] = 'a' >>>>>> x >>> defaultdict(, {1: 'a'}) >>>>>> dict(x) >>> {1: 'a'} >>> >>> >>> >> >> I was hoping not to do that -- e.g., actually reuse the same underlying >> data. > > > It does re-use the same underlying data. > >>>> from collections import defaultdict as dd >>>> x = dd(list) >>>> x[1].append(1) >>>> x > defaultdict(, {1: [1]}) >>>> y = dict(x) >>>> x[1].append(42) >>>> y > {1: [1, 42]} > > Both the defaultdict and the dict are referring to the same underlying > key:value pairs. The data itself isn't duplicated. If they are mutable > items, a change to one will affect the other (because they are the same > item). An analogy for C programmers would be that creating dict y from > dict y merely copies the pointers to the keys and values, it doesn't copy > the data being pointed to. > > (That's pretty much what the CPython implementation does. Other > implementations may do differently, so long as the visible behaviour > remains the same.) > > > >> Maybe dict(x), where x is a defaultdict is smart? ?I agree that a >> defaultdict is safe to pass to most routines, but I guess I could >> imagine that a try/except block is used in a bit of code where on the >> key exception (when the value is absent) ?populates the value with a >> random number. ?In that application, a defaultdict would have no random >> values. > > If you want a defaultdict with a random default value, it is easy to > provide: > >>>> import random >>>> z = dd(random.random) >>>> z[2] += 0 >>>> z > defaultdict(, {2: > 0.30707092626033605}) > > > The point which I tried to make, but obviously failed, is that any piece > of code has certain expectations about the data it accepts. If take a > function that expects an int between -2 and 99, and instead decide to > pass a Decimal between 100 and 150, then you'll have problems: if you're > lucky, you'll get an exception, if you're unlucky, it will silently give > the wrong results. Changing a dict to a defaultdict is no different. > > If you have code that *relies* on getting a KeyError for missing keys: > > def who_is_missing(adict): > ? ?for person in ("Fred", "Barney", "Wilma", "Betty"): > ? ? ? ?try: > ? ? ? ? ? ?adict[person] > ? ? ? ?except KeyError: > ? ? ? ? ? ?print person, "is missing" > > then changing adict to a defaultdict will cause the function to > misbehave. That's not unique to dicts and defaultdicts. > > > >> Besides a slightly different favor, does the following have applications >> not covered by defaultdict? >> >> m.setdefault('key', []).append(1) > > defaultdict calls a function of no arguments to provide a default value. > That means, in practice, it almost always uses the same default value for > any specific dict. > > setdefault takes an argument when you call the function. So you can > provide anything you like at runtime. > > >> I think I am unclear on the difference between that and: >> >> m['key'] = m.get('key',[]).append(1) > > Have you tried it? I guess you haven't, or you wouldn't have thought they > did the same thing. > > Hint -- what does [].append(1) return? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From xahlee at gmail.com Sat Jul 31 01:47:21 2010 From: xahlee at gmail.com (Xah Lee) Date: Fri, 30 Jul 2010 22:47:21 -0700 (PDT) Subject: have you read emacs manual cover to cover?; (was Do we need a "Stevens" book?) References: <093d461d-5402-4226-80d5-6e3d8df2b922@j8g2000yqd.googlegroups.com> <35282104-5b51-4ba4-8745-4fae239ce0ee@q21g2000prm.googlegroups.com> Message-ID: <63e9cab8-17da-4f1a-b055-e172a3ffeb47@o7g2000prg.googlegroups.com> cleaned up and extended my previous post. Sentences and ideas made more precise and detailed. ? Emacs Idolization: Have You Read the Emacs Manual From Cover to Cover? http://xahlee.org/emacs/emacs_manual_cover_to_cover.html plain text version follows: -------------------------------------------------- Thien-Thi Nguyen wrote: Why does the search start with Google (and continue with other downstream, non-terminating, whirlpool-shaped, out of date, referenda)? Why not go to the source? The Emacs Lisp manual, the Emacs Lisp code, the Emacs customization facility, the Emacs *scratch* buffer, the Emacs! Elena wrote: Surprisingly enough - or not? - it seems few users do read the manuals... I'm guilty of this too (and Emacs' manuals will be my reading on my next vacations). I always thought of doing this, but it never happened. Not the emacs manual, nor the elisp manual. Over the past 12 years of using emacs daily, i have read perhaps 1/3 of the emacs manual and 1/2 elisp manual, counted in a accumulative way. However, i have read cover to cover, word for word, systematically in a continued setting, several programing lang or software manuals. Some of these software are quite more deeper than emacs. Here they are from my recollection. (Note: emacs manual for emacs 22 is 589 pages in printed form, and elisp manual for emacs 21 is 900 pages.) ------------------------- Microsoft Word Manual Microsoft Word manual i think i've read most of it in about 1992. Though, i can't remember i actually read the manual systematically or just become expert by using and scanning it when needed. (i stopped using Microsoft Word about 1998.) ------------------------- HP-28S Advanced Scientific Calculator HP-28S Advanced Scientific Calculator manual. (2 books) I read cover to cover, twice, in about 1991. In fact this is how i learned programing, my first computer language, and the first i mastered. (See: HP-28S Advanced Scientific Calculator and Xah Lee's Computing Experience Bio. ) ------------------------- The Mathematica Book Mathematica manual (aka the Mathematica Book amazon ). I've read it 3 times in separate years, systematically, from cover to cover. This all happened in 1990s. Note that Mathematica the language, the subject it deals with, is inherently a order of magnitude more complex than emacs. The Mathematica book is 1381 pages, 3 kilograms. Heavy enough to hit someone to cause concussion. This 4th edition published in 1999, is the last printed edition. They no longer print it nor come with the software. Note how commercial orgs have adopted changes with the changing industry. ------------------------- The Perl Book The Perl Book. I've read basically cover to cover in about 1998, 1999. (yes, i own the printed book. The printed book aka The Camel Book is edited version of Perl's man pages. Actually i've read all major perl books from 1997 to ~2000. (See: Pathetically Elational Regex Language (PERL)) ------------------------- PHP manual The PHP manual (online). Roughly read reasonably all of it in about a week, in 2005. (scanned in detail on parts that do not require detailed understanding at first.) ------------------------- MySQL manual MySQL manual, online. Read it at the same time i read PHP manual from cover to cover, in 2005. Took me about week or two. I've been working with SQL or variants daily in a day job during 1998 to 2002, but haven't touched it for 2 years. So this reading is to brush up my SQL, as well as first time comprehensive reading of MySQL documentation in particular. ------------------------- Habit of Reading Manuals Reading manuals systematically is kinda a habit, developed from early 1990s as part of a method to study English, and also somewhat a old- fashioned and stubburn mindset of wanting to learn everything from ground up, throughly, and from the original source. Reading manuals, is also how i learned most of my proprograming. Just about any software, language, OS, i used from about 1991 to about early 2000s, i tried to read their manuals systematically from cover to cover, not missing any word. This mentality and its severity, very gradually declined over the past 20 years. Today, i do not take the pain to systematically read their manuals of any new software i have to learn. (if it exists at all; or isn't some haphazard wiki, or random notes by student joe (such as Python's docs. See: Python Documentation Problems).) (other manuals i've read quite a lot for example: vast unix man pages, Apache 1.x, Sun Microsystem's Solaris (3 volumes) (2000), Scheme R4RS (1998), Java, Microsoft's JScript (~2005), Python (~2005), Mac OS X Server official doc from Apple, ... (See: Examples Of Quality Documentation In The Computing Industry) ) ================================= Is Emacs Godsend? Elena wrote: Emacs is too much a complex (not difficult) and powerful software to be used by intuition alone, unlike many softwares we are used to. This is simply not true. For example, from personal experience, Blender, Second Life both are more complex than emacs, both for learning it, as well in terms of effort or complexity of their implementation, as well as inherent complexity by the nature of what these software's purpose. Second Life i've been using for about 3 years now. (See: A Photographic Tour of Life in Second Life.) Blender i started to learn this year... but quite too complex and difficult to get started. I'd say, Blender or Second Life, each, are a order magnitude more complex and rich than emacs. Either considered from simple use aspect, or in-depth use aspect such as coding in their scripting languages to use them fully. (akin to coding emacs lisp.) Also, depending on what you mean by use... for example, if you take perspective of emacs lisp as a language, then, compared to programing Java, C, C++, all are quite deeper than elisp and takes longer to explore before reaching diminishing returns. If you take the perspective of emacs as programing framework for creating applications such as file manager, ftp client, irc client, mp3 manager, etc, then, compared to proper software frameworks such as Mac OS and Windows, both are a order far more complex, of bottomless learning depth, as well far more powerful. ================================= Emacs Cult and Idolization Am writing this because i want to dispel the cult phenomenon surrounding emacs. On the net we often hear some magical qualities about emacs, but i think if you look at it seriously, usually much of it are not scientifically meaningful. Since this issue kept cropping up in my mind over the past ~5 years, in argument with many old-time emacs users, i thought about the question: whether there is any superiority or god-like quality about emacs that we can actually claim and be justified. I think to that question we need to be concrete and specific. If a claim is made concrete, then its veracity can be more easily judged. For examples, the following i think can be reasonably claimed: * Emacs is the most suitable tool for text manipulation tasks that are complex and not-well-defined and requires interactive human watch. (See: Why Emacs is Still so Useful Today.) * Emacs is most flexible, customizable, user extensible text editor. * Emacs is the most well known and widely used editor that has a embedded programing language for text editing. * The Emacs system with Emacs Lisp is probably the most versatile computer language for text processing. (See: Text Processing: Elisp vs Perl.) The above claims are still not so precise, but are items i think can be reasonably justified. Or can be made more precise, so that the sum of them can make sense, and conclude that emacs is quite powerful and versatile. On the other hand, the following i think are in the category of myths: * ? Emacs manual would rank among the top 100 best in today's software. * ? Emacs's keyboard system is among the better designed, in its efficiency, or extensibility, or consistency, or ergonomics. * ? Emacs keyboard shortcuts and the way they are mapped to emacs's text manipulation commands, is a very efficient system. (e.g. ratio of number of commands to call over arbitrary text manipulation tasks) * ? Emacs is among the top one thousand major software today. * ? Emacs and system is among the top one thousand software with respect to the software's power, or versatility, or usefulness. * ? Emacs's implementation considered as a software project today is among the top one thousand software in terms of complexity, size, or achievement. ... There are a lot such myths going around different communities. In perl community, it's filled to the brim about how perl is everything and great. In the Common Lisp community, you hear fantastic things about lisp being the god of all programing languages, while they almost never mention emacs lisp as a language, and if they do, it's all sneer and spits and attacks to no ends. In the Scheme community, likewise you hear how it is the most beautiful, the most elegant, and the most powerful, of all, with its call-cc and tail recursion and whatnot. ( See: Scheme & Failure and Language, Purity, Cult, and Deception ) In unix community, which is usually hated by lispers of any faction, you hear how unix is the most versatile, the greatness of its ?Unix philosophy? and ?KISS? principles. (See: The Nature of the Unix Philosophy.) Likewise, there's also commercially generated myths, e.g. Java, about how it solves all cross-platform problems, and how OOP solves the world's programing problems, etc. (See: What are OOP's Jargons and Complexities) All these spur from communities that developed certain cult following. Ultimately, it's more harmful than good. What i'd like to say, is that, yes i love emacs and you love emacs. However, when praising, be concrete and specific on what you like about it, and avoid idolization. Because, idolization cultivates cult- like mindset, and that is ultimately damaging. Xah ? http://xahlee.org/ ? From nagle at animats.com Sat Jul 31 03:50:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 31 Jul 2010 00:50:09 -0700 Subject: Normalizing A Vector In-Reply-To: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <4c53d5ac$0$1665$742ec2ed@news.sonic.net> On 7/30/2010 6:46 AM, Alain Ketterlin wrote: > Does the compiler hoist the math.sqrt(...) out of the implicit loop? Global optimization in Python? Not in CPython. The program might redefine math.sqrt from another thread while the program is running, which would invalidate the hoisting of the function. That has to be supported. Shed Skin might do it, but it restricts the language and doesn't allow the full dynamism of Python. John Nagle From __peter__ at web.de Sat Jul 31 03:55:48 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 31 Jul 2010 09:55:48 +0200 Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: AJ wrote: > I have written a sample program that ran correctly with earlier than > Mac OS 10.6. The answer field Label does not align correctly. I > downloaded the latest Python 2.7 release but still did not solve the > problem. Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" The underlying Tcl/Tk is more likely to be the cause of your problem, so you'd have to look at that. I'm on Linux with Python2.6 and Tcl/Tk 8.5, and don't see a misalignment. Stab in the dark: try creating L4 with explicit padding: L4 = Label(..., padx=0) Peter PS: Rantingrick is right; you should use one of the other geometry managers From marky1991 at gmail.com Sat Jul 31 03:56:37 2010 From: marky1991 at gmail.com (Mark Young) Date: Sat, 31 Jul 2010 03:56:37 -0400 Subject: Tkinter Label alignment problem using OS 10.6 In-Reply-To: <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> References: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> Message-ID: That seems a bit harsh. Place, in general, isn't as useful as pack and grid. Yelling at him for suggesting you use them is unnecessary. When I looked at when your script generates, I don't see why you couldn't just use grid. I can fairly easily see a grid layout. But, I guess it's supposed to be a place test anyway. Anyway, how are you expecting it to be aligned? How is it aligned on your computer? When I ran the script, it lined up with the first and second number entries, as I would expect. -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Sat Jul 31 05:04:49 2010 From: landimatte at gmail.com (Matteo Landi) Date: Sat, 31 Jul 2010 11:04:49 +0200 Subject: pylint scores In-Reply-To: References: <4C532577.8010906@free.fr> Message-ID: What are the messages one should really care about while evaluating its code using pylint? It's easy to get 5 scored with a "lot of public methods" or bad named variables such as 'x' or 'y' .. Have you got any config file to share? On Sat, Jul 31, 2010 at 2:48 AM, Dan Stromberg wrote: > > On Fri, Jul 30, 2010 at 12:18 PM, News123 wrote: >> >> On 07/30/2010 03:12 PM, wheres pythonmonks wrote: >> > I am starting to use pylint to look at my code and I see that it gives a >> > rating. >> > What values do experienced python programmers get on code not >> > targeting the benchmark? >> > >> > I wrote some code, tried to keep it under 80 characters per line, >> > reasonable variable names, and I got: >> > >> > 0.12 / 10. >> > >> > Is this a good score for one not targeting the benchmark? ?(pylint >> > running in default mode) >> > >> It's not a goodf core, but arrives easily if you never ran pylint before. >> With very little effort you should be able to be above 5 >> with a little more effort above 7 >> >> >> > Somewhat related: ?Is the backslash the only way to extend arguments >> > to statements over multiple lines? ?(e.g.) >> >> if you have an opening parenthesis, or bracked, then you don't need a >> backslash >> >> so instead of >> if longlonglonglonglonglonglonglongvar == \ >> ? ? ? ?otherlonglonglonglongvar: >> >> you could also write: >> >> if (longlonglonglonglonglonglonglongvar == >> ? ? ? ?otherlonglonglonglongvar): >> >> >> same works of course with asserts. >> >> > >> >>>> def f(x,y,z): return(x+y+z); >> > ... >> >>>> f(1,2, >> > ... 3) >> > 6 >> >>>> assert f(1,2,3)>0, >> > ? File "", line 1 >> > ? ? assert f(1,2,3)>0, >> > ? ? ? ? ? ? ? ? ? ? ?^ >> > SyntaxError: invalid syntax >> >>>> >> > >> > In the above, I could split the arguments to f (I guess b/c of the >> > parens) but not for assert. ?I could use a backslash, but I find this >> > ugly -- it that my only (best?) option? >> > >> > [I really like to assert my code to correctness and I like using the >> > second argument to assert, but this resulted in a lot of long lines >> > that I was unable to break except with an ugly backslash.] >> > >> > W >> > IMO, the important thing about pylint's scoring is that it's but one way of > many of producing good Python code. ?However, it's also one of the easier > ways of producing good python code. > I personally like to get my scores up near 10, by annotating in comments > about the few things that pylint flags that I can't just code around. ?This > requires jumping through some slightly silly hoops (EG the previously > mentioned "too few public methods", which my various container classes > always trip over), but going through this process is worthwhile for > highlighting the hoops pylint can detect that -aren't- so silly. > The one thing I like to leave unfixed is FIXME's - otherwise my preference > would be to go for a score of 10 for production code. > I also like to create a ./this-pylint script for my various projects, that > have global overrides - things like identifier rules, line length, and... ?I > don't get blanks instead of tabs. ?Blanks are fine if you don't understand > tabs (or think someone in the future who doesn't understand tabs will need > to work on your code), but tabs allow everyone to see code indented the way > -they- want to see it, not just the way the original author wanted to see > it. > This script (./this-pylint) will also save output from the test in a text > file, for make (or other dependency handling program) to use to avoid > re-pylint'ing unmodified code. ?It'll give an error typically, if pytlint > detects any errors other than FIXME's (excluding ones, as I mentioned > before, that have a comment disabling the warning, of course). > I'm more than a little sad that pylint doesn't seem to be moving to python 3 > in any big hurry. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From siraj.ansari88 at gmail.com Sat Jul 31 05:21:54 2010 From: siraj.ansari88 at gmail.com (SIRAJ ANSARI) Date: Sat, 31 Jul 2010 02:21:54 -0700 (PDT) Subject: "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ Message-ID: <04916d7c-dc72-422e-9b35-3053903e28f0@h17g2000pri.googlegroups.com> "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Jul 31 05:55:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 09:55:22 GMT Subject: default behavior References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c53f30a$0$11091$c3e8da3@news.astraweb.com> On Sat, 31 Jul 2010 01:02:47 -0400, wheres pythonmonks wrote: >> Hint -- what does [].append(1) return? >> >> > Again, apologies from a Python beginner. It sure seems like one has to > do gymnastics to get good behavior out of the core-python: > > Here's my proposed fix: > > m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) > > Yuck! Yuk is right. What's wrong with the simple, straightforward solution? L = m.get('key', []) L.append(1) m['key'] = L Not everything needs to be a one-liner. But if you insist on making it a one-liner, that's what setdefault and defaultdict are for. > So I guess I'll use defaultdict with upcasts to dict as needed. You keep using that term "upcast". I have no idea what you think it means, so I have no idea whether or not Python does it. Perhaps you should explain what you think "upcasting" is. > On a side note: does up-casting always work that way with shared > (common) data from derived to base? (I mean if the data is part of > base's interface, will b = base(child) yield a new base object that > shares data with the child?) Of course not. It depends on the implementation of the class. -- Steven From srini605 at gmail.com Sat Jul 31 06:13:26 2010 From: srini605 at gmail.com (srinivasan munisamy) Date: Sat, 31 Jul 2010 15:43:26 +0530 Subject: Get perl method documentation in python wrapper Message-ID: Hi, I would like to get the documentation of a perl method inside python wrapper. To say it with example, there is a perl module ?X.pm?. It has a method ?print_hello()?. x.py is a wrapper module over X.pm. when I say x.print_hello.__doc__ then I need to get the documentation of X::print_hello. The main reason why i want to do that i do not want to re-write the whole documentation again in python. Is there a way to do that? Thanks, Srini -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sat Jul 31 06:15:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 22:15:57 +1200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: In message <877hkdhyl5.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Lawrence D'Oliveiro writes: > >> What I don?t like is having that intermediate variable L leftover after >> the computation. > > Well, it also guarantees that the square root is computed once. OK, this version should solve that problem, without requiring any new language features: V = tuple \ ( x / l for x in V for l in (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), 0)),) ) From steve at REMOVE-THIS-cybersource.com.au Sat Jul 31 06:22:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 10:22:40 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > I have to chime in and agree that the name "super" is problematic. I'm > reading this thread with a sense of alarm because I apparently never > read the super() documentation too closely (why would I? "Oh, it just > accesses an attribute from a superclass. Moving on.") and have been > writing code for the past four years under the impression that super() > will always refer to a superclass of the current class. In Python 2.x, super() doesn't know what the current class is. You have to explicitly tell it. If you tell it a lie, surprising things will happen. Assuming you accurately tell it the current class, can you give an example where super() doesn't refer to a superclass of the current class? [...] > On a tangent, is it just me, or is the super() documentation incorrect, > or at least unclear? Quoting from the first two paragraphs: Yes, it's a bit unclear, because it's a complex function for dealing with a complicated situation. But if you have single inheritance, it's simple. Anywhere you would write class C(B): def method(self, *args): B.method(*args) you can write class C(B): def method(self, *args): super(C, self).method(*args) and it will Just Work. > super(type[, object-or-type]) > > Return a proxy object that delegates method calls to a parent or > sibling class of type. I think that the bit about sibling class refers to super(type, type2) calls, rather than the super(type, instance) calls which I've been discussing. I've never needed, and don't understand, the two type version of super(), so I can't comment on it. -- Steven From navegadorjhom2 at hotmail.com Sat Jul 31 06:33:07 2010 From: navegadorjhom2 at hotmail.com (jhom) Date: Sat, 31 Jul 2010 03:33:07 -0700 (PDT) Subject: Electronic purchase with the latest technology know this fantastic store you make your purchase and receive in five days at home buy to resell or use propio Message-ID: <0c898159-94ac-4a19-98ca-4e83e8d4a948@l14g2000yql.googlegroups.com> Electronic purchase with the latest technology know this fantastic store you make your purchase and receive in five days at home buy to resell or use propio http://www.internationaleletronicos.com/ From thomas at jollans.com Sat Jul 31 06:44:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 31 Jul 2010 12:44:15 +0200 Subject: Normalizing A Vector In-Reply-To: References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <4C53FE7F.4020900@jollans.com> On 07/31/2010 12:15 PM, Lawrence D'Oliveiro wrote: >reduce(lambda a, b : a + b, (y * y for y in V), 0)) > This is a lot more verbose than it has to be, and probably slower too. firstly: (lambda a,b: a+b) is equivalent to operator.add. ==> reduce(operator.add, (y*y for y in V), 0) However - reduce with operator.add ? we have a special name for this: ==> sum(y*y for y in V) From alain at dpt-info.u-strasbg.fr Sat Jul 31 07:18:04 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 31 Jul 2010 13:18:04 +0200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <87sk2zhpcj.fsf@dpt-info.u-strasbg.fr> Lawrence D'Oliveiro writes: >>> What I don?t like is having that intermediate variable L leftover after >>> the computation. >> >> Well, it also guarantees that the square root is computed once. > > OK, this version should solve that problem, without requiring any new > language features: > > V = tuple \ > ( > x > / > l > for x in V > for l in > (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), 0)),) > ) You got the order wrong (it has to be for l ... for x ...) You're kind of lucky here, because the arglist to tuple() provides a scope that hides x and l. Be careful if you ever change tuple(...) to [...], because x and l would leak to the outer scope (with python 2.*). In the general case for L in [...some-expr...]: ... whatever doesn't hide L. Python doesn't provide a "let" construct (? la Lisp or *ML). -- Alain. From homeusenet4 at brianhv.org Sat Jul 31 09:29:25 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Sat, 31 Jul 2010 13:29:25 +0000 (UTC) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> <8bhfcaF6ftU1@mid.individual.net> <4c53936d$0$11091$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> A >>> / \ >>> C B >>> \ / >>> D >>> / \ >>> E F >>> >>> Yes, a super call might jog left from C to B, but only when being >>> called from one of the lower classes D-F. That's still an upwards call >>> relative to the originator, not sidewards. >> >> But it's not an upward call relative to the class mentioned in the >> super() call, which is why I say it's misleading. > > Which class would that be? > > I think I'm going to need an example that demonstrates what you mean, > because I can't make heads or tails of it. Are you suggesting that a call > to super(C, self).method() from within C might call B.method(self)? Yes, it would. class A(object): def test_mro(self): print "In A" class B(A): def test_mro(self): print "In B" super(B, self).test_mro() raise Exception() class C(A): def test_mro(self): print "In C" super(C, self).test_mro() class D(C, B): def test_mro(self): print "In D" super(D, self).test_mro() D().test_mro() Notice the exception being raised in B. This results in the following traceback: Traceback (most recent call last): File "mro.py", line 21, in D().test_mro() File "mro.py", line 19, in test_mro super(D, self).test_mro() File "mro.py", line 14, in test_mro super(C, self).test_mro() File "mro.py", line 9, in test_mro raise Exception() Exception Since the idea of super() as I understand it is to make sure every class in an object's hierarchy gets its method called, there's really no way to implement super() in a way that didn't involve a non-superclass being called by some class's super() call. -- Brian From wherespythonmonks at gmail.com Sat Jul 31 11:00:53 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sat, 31 Jul 2010 11:00:53 -0400 Subject: default behavior In-Reply-To: <4c53f30a$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> <4c53f30a$0$11091$c3e8da3@news.astraweb.com> Message-ID: I think of an upcast as casting to the base-class (casting up the inheritance tree). http://en.wiktionary.org/wiki/upcast But really, what I am thinking of doing is overriding the virtual methods of a derived class with the base class behavior in an object that I can then pass into methods that are base/derived agnostic. defaultdict is the way to go. W Sadly, there are guidelines that I program by that are perhaps anti-pythonic: 1. Don't use "extra" variables in code. Don't use global variables. Keep the scopes of local variables at a minimum to reduce state (the exception being for inner loops) or variables explicitly identified as part of the algorithm before implementation. [In python, just about everything is a variable which is terrifying to me. I never want the Alabama version of math.pi i.e., http://www.snopes.com/religion/pi.asp, or math.sin being "666".] 2. Use built-in functions/features as much as possible, as this are the most tested. Don't roll your own -- you're not that good, instead master the language. (How often do I invent a noun in English? Not even "upcast"!) [Plus, guys with phds probably already did what you need.] Use only very well known libraries -- numpy is okay (I hope!) for example. An exception can be made while interfacing external data, because others who create data may not have abided by rule #2. In most cases (except gui programming, which again tackles the external interfacing program) the more heavy-weight your API, the more wrong you are. 3. In interpreted languages, avoid function calls, unless the function does something significant. [e.g., Functional call overhead tends to be worse that a dictionary lookup -- and yes I used timeit, the overhead can be 100%.] Small functions and methods (and callbacks) hamper good interpreted code. When writing functions, make them operate on lists/dicts. It is because of the above that I stopped writing object-oriented Perl. So I want "big" functions that do a lot of work with few variable names. Ideally, I'd create only variables that are relevant based on the description of the algorithm. [Oh yeah, real programming is done before the implementation in python or C++.] My problems are compounded by the lack of indention-based scope, but I see this as simply enforcing the full use of functional-programming approaches. On Sat, Jul 31, 2010 at 5:55 AM, Steven D'Aprano wrote: > On Sat, 31 Jul 2010 01:02:47 -0400, wheres pythonmonks wrote: > > >>> Hint -- what does [].append(1) return? >>> >>> >> Again, apologies from a Python beginner. ?It sure seems like one has to >> do gymnastics to get good behavior out of the core-python: >> >> Here's my proposed fix: >> >> ?m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) >> >> Yuck! > > Yuk is right. What's wrong with the simple, straightforward solution? > > L = m.get('key', []) > L.append(1) > m['key'] = L > > > Not everything needs to be a one-liner. But if you insist on making it a > one-liner, that's what setdefault and defaultdict are for. > > > >> So I guess I'll use defaultdict with upcasts to dict as needed. > > You keep using that term "upcast". I have no idea what you think it > means, so I have no idea whether or not Python does it. Perhaps you > should explain what you think "upcasting" is. > > >> On a side note: ?does up-casting always work that way with shared >> (common) data from derived to base? ?(I mean if the data is part of >> base's interface, will ?b = base(child) yield a new base object that >> shares data with the child?) > > Of course not. It depends on the implementation of the class. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Sat Jul 31 11:04:22 2010 From: rt8396 at gmail.com (r) Date: Sat, 31 Jul 2010 08:04:22 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <0962c07c-87ff-4618-9aec-707fb1a413f4@u26g2000yqu.googlegroups.com> On Jul 31, 2:55?am, Peter Otten <__pete... at web.de> wrote: > PS: Rantingrick is right; you should use one of the other geometry managers Incidentally I was actually writing a version of the OP's script using the grid manager when i found his nasty response. So I think i'll just keep it for me self now. Good luck AJ. ;-) From lists at cheimes.de Sat Jul 31 11:08:11 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jul 2010 17:08:11 +0200 Subject: default behavior In-Reply-To: References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: Am 30.07.2010 14:34, schrieb wheres pythonmonks: > I was hoping not to do that -- e.g., actually reuse the same > underlying data. Maybe dict(x), where x is a defaultdict is smart? I > agree that a defaultdict is safe to pass to most routines, but I guess > I could imagine that a try/except block is used in a bit of code where > on the key exception (when the value is absent) populates the value > with a random number. In that application, a defaultdict would have > no random values. defaultdict not only behaves like an ordinary dict except for missing keys, it's also a subclass of Python's builtin dict type. You are able to use a defaultdict just like a normal dict all over Python. You can also provide your own custom implementation of a defaultdict that fits your needs. All you have to do is subclass dict and implement a __missing__ method. See http://docs.python.org/library/stdtypes.html?highlight=__missing__#mapping-types-dict Christian From conversationalhypnosis.101 at gmail.com Sat Jul 31 12:59:36 2010 From: conversationalhypnosis.101 at gmail.com (Bolaleman) Date: Sat, 31 Jul 2010 09:59:36 -0700 (PDT) Subject: International IT Consultant Jobs from 14 Countries Message-ID: Looking for IT consultant jobs? Maybe you find your new job in the USA, Canada, Australia, India or in Europe using this IT consultant job database: http://2ajobguide.com/consulting_IT_job_database.aspx This service is free and you can apply directly without intermediates. From jjposner at optimum.net Sat Jul 31 13:31:35 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 31 Jul 2010 13:31:35 -0400 Subject: default behavior In-Reply-To: References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C545DF7.6040104@optimum.net> On 7/31/2010 11:08 AM, Christian Heimes wrote: > ... All you have to do is subclass dict and implement a > __missing__ method. See > http://docs.python.org/library/stdtypes.html?highlight=__missing__#mapping-types-dict > Caveat -- there's another description of defaultdict here: http://docs.python.org/library/collections.html#collections.defaultdict ... and it's bogus. This other description claims that __missing__ is a method of defaultdict, not of dict. This might cause considerable confusion, leading the reader to suspect that __missing__ and default_factory fight it out for the right to supply a default value. (__missing__ would win -- I tried it.) The truth, as Christian says above and as Raymond Hettinger recently pointed out [1], is that __missing__ is used to *define* defaultdict as a subclass of dict -- it's not used *by* defaultdict. -John [1] http://mail.python.org/pipermail/python-list/2010-July/1248896.html From lists at cheimes.de Sat Jul 31 14:00:08 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jul 2010 20:00:08 +0200 Subject: default behavior In-Reply-To: <4C545DF7.6040104@optimum.net> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4C545DF7.6040104@optimum.net> Message-ID: > The truth, as Christian says above and as Raymond Hettinger recently > pointed out [1], is that __missing__ is used to *define* defaultdict as > a subclass of dict -- it's not used *by* defaultdict. Your answer is confusing even me. ;) Let me try an easier to understand explanation. defaultdict *implements* __missing__() to provide the default dict behavior. You don't have to subclass from defaultdict to get the __missing__() feature. It's part of the dict interface since Python 2.5. Christian From hjtoi-better-remove-before-reply at comcast.net Sat Jul 31 14:06:39 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Sat, 31 Jul 2010 11:06:39 -0700 Subject: Newbie question regarding SSL and certificate verification References: Message-ID: Jeffrey Gaynor wrote: > A final question -- how widely is M2Crypto used? Since I will have to now pitch >to our group that this is preferable the first questions they will ask are about >stability, who is using it and how secure is it really, especially since it is >at version 0.20.2 (i.e. no major release yet). The M2Crypto homepage lists dozens of applications and libraries that use M2Crypto. Additionally I believe certain Linux distros use it as more or less required piece. I know it has been used at some of the world's most largest companies. As for version number, that is pretty much irrelevant in open source. Take a look at the number and frequency of releases, how long the project has existed and so forth, and community around the project. M2Crypto is over 7 years old, has had at least one release a year, and although it doesn't have a large community around it, most of the changes over the last few years have been submitted by someone else than the maintainer. -- Heikki Toivonen - http://heikkitoivonen.net From ian.g.kelly at gmail.com Sat Jul 31 14:16:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 31 Jul 2010 12:16:07 -0600 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 31, 2010 at 4:22 AM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > >> I have to chime in and agree that the name "super" is problematic. I'm >> reading this thread with a sense of alarm because I apparently never >> read the super() documentation too closely (why would I? ?"Oh, it just >> accesses an attribute from a superclass. ?Moving on.") and have been >> writing code for the past four years under the impression that super() >> will always refer to a superclass of the current class. > > In Python 2.x, super() doesn't know what the current class is. You have > to explicitly tell it. If you tell it a lie, surprising things will > happen. > > Assuming you accurately tell it the current class, can you give an > example where super() doesn't refer to a superclass of the current class? Brian gave a good example, so I refer you to that. >> On a tangent, is it just me, or is the super() documentation incorrect, >> or at least unclear? ?Quoting from the first two paragraphs: > > Yes, it's a bit unclear, because it's a complex function for dealing with > a complicated situation. But if you have single inheritance, it's simple. > Anywhere you would write > > class C(B): > ? ?def method(self, *args): > ? ? ? ?B.method(*args) > > you can write > > class C(B): > ? ?def method(self, *args): > ? ? ? ?super(C, self).method(*args) > > > and it will Just Work. Until somebody else comes along and creates class E that inherits from both C and D and also uses super(), and now suddenly the super() call in C becomes equivalent to "D.method(*args)" instead for instances of E, potentially with unexpected results. Or worse, E.method incorrectly calls both C.method and D.method explicitly, and now D.method gets invoked twice, once implicitly from C.method, and once explicitly from E.method. I realize that it is the responsibility of the person writing class E to make sure they're working with class C correctly, but in order for them to do that, ultimately every method in class C should be documented as to whether it calls super() or not, and if so whether it is designed only for single inheritance or with the MRO in mind. That really shouldn't be necessary, and in my current view from a maintenance perspective, best practice is to only use super() in the multiple-inheritance scenarios it was specifically designed for >> super(type[, object-or-type]) >> >> ? ? Return a proxy object that delegates method calls to a parent or >> sibling class of type. > > I think that the bit about sibling class refers to super(type, type2) > calls, rather than the super(type, instance) calls which I've been > discussing. I've never needed, and don't understand, the two type version > of super(), so I can't comment on it. I understand the two-type version works the same way, but is intended for class methods, like so: class A(object): @classmethod def f(cls, *args): print "A.f" class B(A): @classmethod def f(cls, *args): print "B.f" return super(B, cls).f(*args) class C(A): @classmethod def f(cls, *args): print "C.f" return super(C, cls).f(*args) class D(B, C): @classmethod def f(cls, *args): print "D.f" return super(D, cls).f(*args) Cheers, Ian From ajuffali at yahoo.com Sat Jul 31 14:54:38 2010 From: ajuffali at yahoo.com (AJ) Date: Sat, 31 Jul 2010 11:54:38 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <7f0a4cd5-195a-4d3f-9f52-7f357a7432a9@b4g2000pra.googlegroups.com> On Jul 31, 12:55?am, Peter Otten <__pete... at web.de> wrote: > AJ wrote: > > I have written a sample program that ran correctly with earlier than > > Mac OS 10.6. The answer field Label does not align correctly. I > > downloaded the latest Python 2.7 release but still did not solve the > > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" > > The underlying Tcl/Tk is more likely to be the cause of your problem, so > you'd have to look at that. > > I'm on Linux with Python2.6 and Tcl/Tk 8.5, and don't see a misalignment. > > Stab in the dark: try creating L4 with explicit padding: > > L4 = Label(..., padx=0) > > Peter > > PS: Rantingrick is right; you should use one of the other geometry managers Thank you Peter. I?ve tried the padding but it does not solve the issue. It only does it with Mac OS 10.6. it works fine with Windows and Linux and earlier Mac OS than 10.6. To write professional GUI one needs to have full control over the placement of the Widgets. Some programmers have switched to wxPython because of this issue and I am trying not to. From ajuffali at yahoo.com Sat Jul 31 15:05:09 2010 From: ajuffali at yahoo.com (AJ) Date: Sat, 31 Jul 2010 12:05:09 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: <0962c07c-87ff-4618-9aec-707fb1a413f4@u26g2000yqu.googlegroups.com> Message-ID: On Jul 31, 8:04?am, r wrote: > On Jul 31, 2:55?am, Peter Otten <__pete... at web.de> wrote: > > > PS: Rantingrick is right; you should use one of the other geometry managers > > Incidentally I was actually writing a version of the OP's script using > the grid manager when i found his nasty response. So I think i'll just > keep it for me self now. Good luck AJ. ;-) Thank you. Do not let it get to you. There are some people like that. If you have an idea or need help do not be distracted by this. Just post it and hope someone can help you. This is more beneficial for you and others who have the same questions and some day you may be helping others. Cheers! From legard4d at gmail.com Sat Jul 31 15:09:15 2010 From: legard4d at gmail.com (legard_new) Date: Sat, 31 Jul 2010 12:09:15 -0700 (PDT) Subject: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem Message-ID: <70faf0b4-fead-49ac-bf18-e182fd63bbff@j8g2000yqd.googlegroups.com> Hello, I have a problem with calling Callback function with Python. I have a DLL file. Below is a description in documentation. FUNCTION Callback Arguments: Callback ID integer read-only, immediate value CBackProc address read-only, immediate value Returns: status The Callback routine registers the callback routine for notification of a link state change. The callback procedure provided by the application must accept one parameter: the address of the structure containing the data. CallbackID An integer identifying the callback routine being provided to the API. Can be one of 1 or 2. CBackProc The address of the callback procedure that the API will execute. This procedure must accept one parameter, of type LinkStateStruct, passed by reference. LinkStateStruct read-only, by reference OldState: byte NewState byte The routine will return one of the following error codes: 1 - The callback address was successfully registered by the API. 2 - The API has not been initialised. 3 - The CallbackID value was not recognised as a valid link state callback. Here is my little code in Python: from ctypes import * class LinkStateStruct(Structure): _fields_ = [("OldState", c_byte), ("NewState", c_byte)] demoapi=windll.LoadLibrary("D:\\DEMO.dll") #DECLARE CALLBACK FUNCTION g_HLSC = CFUNCTYPE(c_int, POINTER(LinkStateStruct)) def py_g_HLSC(x): print "CALLBACK__py_g_HLSC_FIRED->", x return 0 g__HLSC = g_HLSC(py_g_HLSC) status=demoapi.Callback(1,g__HLSC) print "Status=",status My result is: Status= 1 But Callback function is not executed. If think that i call g__HLSC witohout paramter that in document "The callback procedure provided by the application must accept one parameter: the address of the structure containing the data.". I don't now how to do. Please help. Best regards, Gregory From timr at probo.com Sat Jul 31 15:45:45 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 31 Jul 2010 12:45:45 -0700 Subject: Normalizing A Vector References: Message-ID: Lawrence D'Oliveiro wrote: > >Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize >it (scale all components by the same factor) so its magnitude is 1. > >The usual way is something like this: > > L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > V = (V[0] / L, V[1] / L, V[2] / L) > >What I don?t like is having that intermediate variable L leftover after the >computation. Here?s how to do it in one step: > > V = tuple \ > ( > x > / > math.sqrt > ( > reduce(lambda a, b : a + b, (y * y for y in V), 0) > ) > for x in V > ) > >which, incidentally, also works for vectors with dimensions other than 3. What is the matter with having a temporary variable hang around? It's only one double, and it far better performance than the one you posted. As far as I know, Python doesn't do common subexpression elimination, which means the version you posted is doing to run the entire magnitude computation once for every element in V. A better solution would be to put this in a function: def Normalize(V): L = math.sqrt( sum(a*a for a in V) ) return (a/L for a in V) Now the temporary goes away at the end of the function. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From metolone+gmane at gmail.com Sat Jul 31 16:22:48 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 31 Jul 2010 13:22:48 -0700 Subject: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem References: <70faf0b4-fead-49ac-bf18-e182fd63bbff@j8g2000yqd.googlegroups.com> Message-ID: "legard_new" wrote in message news:70faf0b4-fead-49ac-bf18-e182fd63bbff at j8g2000yqd.googlegroups.com... > Hello, > > I have a problem with calling Callback function with Python. I have a > DLL file. > > Below is a description in documentation. > FUNCTION Callback > Arguments: Callback ID integer read-only, immediate value > CBackProc address read-only, immediate value > Returns: status > The Callback routine registers the callback routine for > notification of a link state change. > The callback procedure provided by the application must accept one > parameter: > the address of the structure containing the data. > > CallbackID An integer identifying the callback routine being > provided to the API. Can be one of 1 or 2. > CBackProc The address of the callback procedure that the API will > execute. > > This procedure must accept one parameter, of type LinkStateStruct, > passed by reference. > > LinkStateStruct read-only, by reference > OldState: byte > NewState byte > > The routine will return one of the following error codes: > 1 - The callback address was successfully registered by the API. > 2 - The API has not been initialised. > 3 - The CallbackID value was not recognised as a valid link state > callback. > > Here is my little code in Python: > > from ctypes import * > class LinkStateStruct(Structure): > _fields_ = [("OldState", c_byte), > ("NewState", c_byte)] > demoapi=windll.LoadLibrary("D:\\DEMO.dll") > #DECLARE CALLBACK FUNCTION > g_HLSC = CFUNCTYPE(c_int, POINTER(LinkStateStruct)) > def py_g_HLSC(x): > print "CALLBACK__py_g_HLSC_FIRED->", x > return 0 > g__HLSC = g_HLSC(py_g_HLSC) > status=demoapi.Callback(1,g__HLSC) > print "Status=",status > > My result is: > Status= 1 > > But Callback function is not executed. If think that i call g__HLSC > witohout paramter that in document "The callback procedure > > provided by the application must accept one parameter: the address of > the structure containing the data.". I don't now how to do. I don't see anything wrong with your declarations. It indicates you registered the callback successfully. Since the callback sounds like it monitors changes in "link state" maybe it isn't changing. Perhaps you need to call another function that causes this change. Here's a DLL I wrote to test your code, but I added a ChangeLinkState function. When I call it after running your code the callback gets called, so your code is working properly. (Compiled with Visual Studio 2008 "cl /MD /LD demo.c" typedef unsigned char BYTE; typedef struct tagLINKSTATE { BYTE OldState, NewState; } LINKSTATE; typedef int (*CB)(LINKSTATE*); CB g_cb; BYTE g_linkState; __declspec(dllexport) int __stdcall Callback(int a,CB cb) { g_cb = cb; return 1; } __declspec(dllexport) void __stdcall ChangeLinkState(BYTE newState) { LINKSTATE state; state.OldState = g_linkState; state.NewState = newState; g_linkState = newState; g_cb(&state); } -Mark From charlesj at sonic.net Sat Jul 31 17:07:50 2010 From: charlesj at sonic.net (Charles Jo) Date: Sat, 31 Jul 2010 21:07:50 -0000 Subject: Google job leads Message-ID: Dear Colleagues, I recently started a recruiter project at Google and am working with Partner Solutions Organization and recruiting Technical Account Managers for the group so I am actively networking with those who may know great software engineers with client-facing experience (or wanting to move in that direction) for career-defining opportunities. If there are individuals and organizations that I should reach out to, please do let me know -- my office contact information is below. Google office: Charles Jo Sales Recruiter, Google 650.253.0375 office 408.668.4226 cell charlesjo at google.com Feedback is always welcome! Best, Charles --? Message sent by: Charles Jo 408.668.4226 charlesj at sonic.net http://bit.ly/zooqdesk http://www.linkedin.com/in/charlesjo http://twitter.com/charlesjo http://www.facebook.com/profile.php?id=603461791 From oswald_eppers at hotmail.com Sat Jul 31 17:32:35 2010 From: oswald_eppers at hotmail.com (David) Date: Sat, 31 Jul 2010 14:32:35 -0700 (PDT) Subject: HCL Jobs database Message-ID: <3015a62e-c54b-4f81-aa59-91f1e69a5f80@m1g2000yqo.googlegroups.com> If you are looking for Jobs at HCL America Inc. ("HCL Jobs") check out http://2ajobguide.com/hcl_jobs.aspx You?ll get free access to a comprehensive database of HCL jobs and you can apply directly online without intermediates. From greg.ewing at canterbury.ac.nz Sat Jul 31 21:13:18 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Aug 2010 13:13:18 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bjvglFl4U1@mid.individual.net> Steven D'Aprano wrote: > Assuming you accurately tell it the current class, can you give an > example where super() doesn't refer to a superclass of the current class? I think we're all confusing each other in this discussion by not being clear enough about what we mean by the "current class". In a call super(C, self), there are two possible things it could mean: the class C, or the type of self. Obviously it will return some class in the mro of self, but as Brian Victor's example demonstrates, it *doesn't* necessarily return a class in the mro of C. -- Greg From greg.ewing at canterbury.ac.nz Sat Jul 31 21:18:04 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Aug 2010 13:18:04 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: <8bjvpjF202U1@mid.individual.net> Ian Kelly wrote: > super(type[, object-or-type]) > > ... > > The __mro__ attribute of the type lists the method resolution > search order used by both getattr() and super(). The attribute is > dynamic and can change whenever the inheritance hierarchy is updated. That explanation does seem to be rather confusing. It would certainly confuse *me* if I didn't already know what super() did. +1 on getting this part of the docs re-written to be several times clearer. -- Greg From ldo at geek-central.gen.new_zealand Sat Jul 31 21:41:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:41:08 +1200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> <87sk2zhpcj.fsf@dpt-info.u-strasbg.fr> Message-ID: In message <87sk2zhpcj.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Lawrence D'Oliveiro writes: > >> V = tuple \ >> ( >> x >> / >> l >> for x in V >> for l in >> (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), >> 0)),) >> ) > > You got the order wrong (it has to be for l ... for x ...) No, I deliberately put it in that order to ensure that the value for l can only ever be evaulated once. > You're kind of lucky here, because the arglist to tuple() provides a > scope that hides x and l. Be careful if you ever change tuple(...) to > [...], because x and l would leak to the outer scope (with python 2.*). Interesting. However, using ?list( ... )? instead of ?[ ... ]? also prevents the leakage. From ldo at geek-central.gen.new_zealand Sat Jul 31 21:52:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:52:13 +1200 Subject: Problem with Elementtree and XMLSchem instance type References: Message-ID: In message , Roland Hedberg wrote: > And there is the problem, I've lost the coupling between the prefix > 'fed' and the namespace > "http://docs.oasis-open.org/wsfed/federation/200706". Why is this a problem? From ldo at geek-central.gen.new_zealand Sat Jul 31 21:56:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:56:52 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: Message-ID: In message , Daniel Fetchinson wrote: > Sure, there are many different terminals and many different operating > systems but in many areas python managed to hide all these complexities > behind a well defined API. Once upon a time, there were indeed many different kinds of actual physical terminals. However, they are all extinct now. All that?s left is software emulations. And the one emulation they all have in common is the DEC VT100. So just assume you?re displaying on one of those: sys.stdout.write("\x1b[2J") From ldo at geek-central.gen.new_zealand Sat Jul 31 21:59:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:59:55 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: In message , Tim Harig wrote: > It would be rewarding as it would make writing cross-platform charactor > mode applications possible. I thought Windows users were allergic to command lines. From ldo at geek-central.gen.new_zealand Sat Jul 31 22:01:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 14:01:13 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: In message , Emile van Sebille wrote: > If all else fails, repeating 24 (or 40,60?) lines feeds clears the > screen cross platform. Depending on the height of the terminal window... From rashadkm at gmail.com Sat Jul 31 22:49:46 2010 From: rashadkm at gmail.com (Rashad) Date: Sat, 31 Jul 2010 19:49:46 -0700 (PDT) Subject: python and swig Message-ID: <4e1bddbf-23ff-40c4-94d1-af2fbcc32721@g21g2000prn.googlegroups.com> I have a swig object of type int* (an integer array) how to covert this swig object to python list now : print self.buffer[0] gives swig object of type int* i want to access the elements of array self.buffer[0] like print self.buffer[0][0] , self.buffer[0][1], self.buffer[0][2] etc... From pavlovevidence at gmail.com Sat Jul 31 22:52:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 19:52:05 -0700 (PDT) Subject: Docstrings and PEP 3174 Message-ID: PEP 3174 got me to thinking. There is now a subdirectory to deposit as many *.pyc files as you want without cluttering the source directory (never mind the default case). Which means you can pretty much write files with impunity. So I was wondering: what about a separate file just for docstrings. __doc__ would become a descriptor that loads the docstring from the file whenever it is referenced. The vast majority of the time docstrings just take up memory and do nothing, so why not lazy load those things? Yes I know you can use the -OO switch to omit docstrings--but who does that anyway? I know I never use -O because I don't know if the people who wrote the library code I'm using were careful enough not to perform general checks with assert or to avoid relying on the docstring's presense. Yeah, it's probably a miniscule optimization, but whatever, I'm just throwing it out there. Carl Banks From pavlovevidence at gmail.com Sat Jul 31 23:48:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 20:48:40 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: <34301a26-e5d4-43ab-ac46-e07f9c0cd10b@p11g2000prf.googlegroups.com> On Jul 31, 11:16?am, Ian Kelly wrote: > On Sat, Jul 31, 2010 at 4:22 AM, Steven D'Aprano > > > > wrote: > > On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > > >> I have to chime in and agree that the name "super" is problematic. I'm > >> reading this thread with a sense of alarm because I apparently never > >> read the super() documentation too closely (why would I? ?"Oh, it just > >> accesses an attribute from a superclass. ?Moving on.") and have been > >> writing code for the past four years under the impression that super() > >> will always refer to a superclass of the current class. > > > In Python 2.x, super() doesn't know what the current class is. You have > > to explicitly tell it. If you tell it a lie, surprising things will > > happen. > > > Assuming you accurately tell it the current class, can you give an > > example where super() doesn't refer to a superclass of the current class? > > Brian gave a good example, so I refer you to that. > > > > >> On a tangent, is it just me, or is the super() documentation incorrect, > >> or at least unclear? ?Quoting from the first two paragraphs: > > > Yes, it's a bit unclear, because it's a complex function for dealing with > > a complicated situation. But if you have single inheritance, it's simple. > > Anywhere you would write > > > class C(B): > > ? ?def method(self, *args): > > ? ? ? ?B.method(*args) > > > you can write > > > class C(B): > > ? ?def method(self, *args): > > ? ? ? ?super(C, self).method(*args) > > > and it will Just Work. > > Until somebody else comes along and creates class E that inherits from > both C and D and also uses super(), and now suddenly the super() call > in C becomes equivalent to "D.method(*args)" instead for instances of > E, potentially with unexpected results. ?Or worse, E.method > incorrectly calls both C.method and D.method explicitly, and now > D.method gets invoked twice, once implicitly from C.method, and once > explicitly from E.method. > > I realize that it is the responsibility of the person writing class E > to make sure they're working with class C correctly, but in order for > them to do that, ultimately every method in class C should be > documented as to whether it calls super() or not, and if so whether it > is designed only for single inheritance or with the MRO in mind. ?That > really shouldn't be necessary, I was with you up to here. It's *manifestly* necessary. One cannot inherit from a class reliably without knowing how it's implemented. Knowing the interface is not enough. This is not limited to multiple inheritance; it happens with single inheritance as well, just less often. It's not limited to Python, this is true of Java, C++, and every other OOP language I know of. Take list. Say you want a singly inherit from list to implement some kind of observer that emits a signal every time an item is set. How do you do it? You can't tell by looking at the interface. Do you only have to override __setattr__? Or do you also have to override other methods (insert, append, etc)? That depends on whether insert et al. call __setattr__ or operate at a lower level. You can't tell simply by looking at the interface. You have to have knowledge of the internals of list. It's the same problem with multiple inheritance, only exacerbated. The issues with super is a new dimension, but it's the same problem: you have to know what you're inheriting from. This is a fundamental issue with all inheritance. The problem, in my mind, is that people use inheritance for stuff that doesn't need it. class MyFoo(SomebodyElsesFoo): def my_tacked_on_method(self): self.call_this_method() self.then_call_that_method() Unnecessary and risky. Do this: my_tacked_on_function(foo): foo.call_this_method() foo.then_call_that_method() The only reason to inherit in a situation like this is if you need polymorphism (you want to pass your MyFoo to a function that operates on objects that define a my_tacked_on_method). A lot Michele Simionato's objections to inheritance are based on the idea that you don't necessarily know what you're inheriting from. I say, if you don't know what you're inheriting from, you shouldn't be inheriting. I say this as a strong proponent of inheritance and multiple inheritance in particular. I believe it's the best way in general for objects of different types to share large portions of their behavior. But it has its place. When you have a class you that don't anything about the implementation of, that is NOT the place for inheritance. In that case you should either use composition, or learn what it is you're inheriting from and take responsibility if the owner changes it. Or just don't try to share behavior. My view of inheritance is a lot like the orthodox Catholic view of sex. To Catholics, sex between married people is a wonderful, holy thing. To me, inheriting from classes you know the implementation of is a wonderful, holy thing. But, sex outside of marriage, and inheriting from classes you don't know, is deadly sin and you will burn in Hell. > and in my current view from a > maintenance perspective, best practice is to only use super() in the > multiple-inheritance scenarios it was specifically designed for I use super() exclusively for all types of inheritance, unless I'm inheriting from a class I know uses old form (which is none of mine, and I only rarely inherit from classes I don't own). Carl Banks From pavlovevidence at gmail.com Sat Jul 31 23:54:35 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 20:54:35 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> <34301a26-e5d4-43ab-ac46-e07f9c0cd10b@p11g2000prf.googlegroups.com> Message-ID: <7e09f51e-6334-44e1-ada4-e95b9e4609d9@q21g2000prm.googlegroups.com> On Jul 31, 8:48?pm, Carl Banks wrote: > When you have a class you that don't anything about the implementation > of, that is NOT the place for inheritance. And, just to be clear, if the class is explicity documented as being subclassable and the documentation states the proper procedure for doing so, that counts as "knowing about the implementation"--even if you don't know the exact implementation, you do have sufficient knowledge. I just don't want someone following up saying, "Well I think it's ok to inherit from a class you know nothing about if it's documented properly." I agree, and that is knowing something about it. Carl Banks From me+list/python at ixokai.io Thu Jul 1 00:04:28 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 30 Jun 2010 21:04:28 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2C13CC.3000309@ixokai.io> On 6/30/10 8:50 PM, Mladen Gogala wrote: >>>> x="quick brown fox jumps over a lazy dog" >>>> y=''.join(list(x).reverse()) > Traceback (most recent call last): > File "", line 1, in > TypeError >>>> > > Why is TypeError being thrown? The reason for throwing the type error is > the fact that the internal expression evaluates to None and cannot, > therefore, be joined: The "reverse" method, like "sort" and a couple others, are in-place operations. Meaning, they do not return a new list but modify the existing list. All methods that are "in-place" modifications return None to indicate this. This way you can't make a mistake and think its returning a sorted / reversed copy but it isn't. However, you can easily get what you want by using the 'reversed' function (and similarly, the 'sorted' function), a la: >>> y = ''.join(reversed(list(x))) The 'reversed' and 'sorted' functions are generators that lazilly convert an iterable as needed. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From zubin.mithra at gmail.com Thu Jul 1 00:09:52 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 1 Jul 2010 09:39:52 +0530 Subject: Composition of functions In-Reply-To: References: Message-ID: Hello, >>> y=list(x).reverse() > >>> print y > None > >>> L = ["a", "b", "c"] >>> L.reverse() >>> L ["c", "b", "a"] As you can see, L.reverse() performs the operation on itself and returns nothing. Hence, the return type None. Instead of y=''.join(list(x).reverse()) you should probably do, >>> t = list(x).reverse() >>> y = ''.join(t) Cheers! Zubin -------------- next part -------------- An HTML attachment was scrubbed... URL: From mtigges at gmail.com Thu Jul 1 00:12:12 2010 From: mtigges at gmail.com (m) Date: Wed, 30 Jun 2010 21:12:12 -0700 (PDT) Subject: Very odd output from subprocess Message-ID: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> I have this function: def GetMakeOutput(make, rules, out=None): p = subprocess.Popen('%s %s' % (make,rules), shell=True, bufsize=1024, stderr=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=False) ret = [] line = p.stdout.readline() while len(line): if line[:5] not in ['make[','make:']: if out: out.write(line) out.flush() else: ret.append(line) line = p.stdout.readline() return string.join(map(string.strip,ret),'\n') Very simple ... it cleans any line that is output from make itself. Now, I have used it for quite awhile with no problem. But, I noticed today that it wasn't doing its job on my 64 bit machine. If I add the line: for l in line: print ord(l),'\t',l after the first readline, I get the following: 27  91 [ 48 0 48 0 109 m 27  91 [ 51 3 55 7 109 m before the codes begin for the string as it appears if I just print it. So, what is this sequence? They seem like some sort of escape codes, I've never seen this before at all. Can anyone enlighten me as to what is going on? And, can I safely strip sets of 5 characters from the front as long as they start with Escape (27)? Thanks, Mark. From clp2 at rebertia.com Thu Jul 1 00:16:43 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 21:16:43 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: On Wed, Jun 30, 2010 at 9:09 PM, Zubin Mithra wrote: > Hello, > >> >>> y=list(x).reverse() >> >>> print y >> None > >>>> L = ["a", "b", "c"] >>>> L.reverse() >>>> L > ["c", "b", "a"] > > As you can see, L.reverse() performs the operation on itself and returns > nothing. Hence, the return type None. > > Instead of > > y=''.join(list(x).reverse()) > > you should probably do, > >>>> t = list(x).reverse() >>>> y = ''.join(t) Er, I don't think you thought that one entirely through (/ tried it out): chris at morpheus ~ $ python Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x = "hello" >>> t = list(x).reverse() >>> print t None >>> ''.join(t) Traceback (most recent call last): File "", line 1, in TypeError Cheers, Chris -- http://blog.rebertia.com From zubin.mithra at gmail.com Thu Jul 1 00:22:27 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 1 Jul 2010 09:52:27 +0530 Subject: Composition of functions In-Reply-To: References: Message-ID: > Er, I don't think you thought that one entirely through (/ tried it out): > > My Apologies. Here is a working one. >>> x="123" >>> t = list(x) >>> t.reverse() >>> print ''.join(t) 321 But of course, the method which was suggested earlier is far more elegant. >>> print ''.join(reversed(list(x))) Cheers! Zubin -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 1 00:27:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 21:27:41 -0700 Subject: Very odd output from subprocess In-Reply-To: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Wed, Jun 30, 2010 at 9:12 PM, m wrote: > I have this function: > > > def GetMakeOutput(make, rules, out=None): > ? ?p = subprocess.Popen('%s %s' % (make,rules), > ? ? ? ? ? ? ? ? ? ? ? ? shell=True, > ? ? ? ? ? ? ? ? ? ? ? ? bufsize=1024, > ? ? ? ? ? ? ? ? ? ? ? ? stderr=subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? stdout=subprocess.PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? close_fds=False) > ? ?ret = [] > ? ?line = p.stdout.readline() > ? ?while len(line): > ? ? ? ?if line[:5] not in ['make[','make:']: > ? ? ? ? ? ?if out: > ? ? ? ? ? ? ? ?out.write(line) > ? ? ? ? ? ? ? ?out.flush() > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?ret.append(line) > ? ? ? ?line = p.stdout.readline() > ? ?return string.join(map(string.strip,ret),'\n') > > Very simple ... it cleans any line that is output from make itself. > > Now, I have used it for quite awhile with no problem. ?But, I noticed > today that it wasn't doing its job on my 64 bit machine. > > If I add the line: > ? ? for l in line: print ord(l),'\t',l > after the first readline, I get the following: > > > 27 > 91 ? ? ?[ > 48 ? ? ?0 > 48 ? ? ?0 > 109 ? ? m > 27 > 91 ? ? ?[ > 51 ? ? ?3 > 55 ? ? ?7 > 109 ? ? m > > before the codes begin for the string as it appears if I just print > it. ?So, what is this sequence? ?They seem like some sort of escape > codes, I've never seen this before at all. > > Can anyone enlighten me as to what is going on? http://en.wikipedia.org/wiki/ANSI_escape_code Running make directly, rather than through the shell, might disable the use of the codes in whatever program is outputting them. It's worth a try. Cheers, Chris -- http://blog.rebertia.com From gogala.mladen at gmail.com Thu Jul 1 00:32:57 2010 From: gogala.mladen at gmail.com (Mladen Gogala) Date: Thu, 1 Jul 2010 04:32:57 +0000 (UTC) Subject: Composition of functions References: Message-ID: On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: > On 6/30/10 8:50 PM, Mladen Gogala wrote: >>>>> x="quick brown fox jumps over a lazy dog" >>>>> y=''.join(list(x).reverse()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError >>>>> >>>>> >> >> Why is TypeError being thrown? The reason for throwing the type error >> is the fact that the internal expression evaluates to None and cannot, >> therefore, be joined: > > The "reverse" method, like "sort" and a couple others, are in-place > operations. Meaning, they do not return a new list but modify the > existing list. All methods that are "in-place" modifications return None > to indicate this. This way you can't make a mistake and think its > returning a sorted / reversed copy but it isn't. Thanks. > > However, you can easily get what you want by using the 'reversed' > function (and similarly, the 'sorted' function), a la: > > >>> y = ''.join(reversed(list(x))) > > The 'reversed' and 'sorted' functions are generators that lazilly > convert an iterable as needed. Ah, that is even better. Thanks. -- http://mgogala.byethost5.com From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 00:47:51 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 04:47:51 GMT Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> Message-ID: <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> But, honestly, is there anyone here, even the most heavy users of >> print, who would seriously expect that adding parentheses to print >> calls will do more than add a tiny fraction to the amount of typing >> effort already required to use Python? I suppose in principle those >> extra three key presses (shift-9 shift-0 vs space) could be the straw >> that breaks the camel's back, but I doubt it. > > There's also Fitt's Law to consider: the space bar is big and > easily-placed and hence easy to type in the middle of a stream of other > keystrokes. None of that is true for the parens. This is true, but there's nothing unique to print about that. Personally, I think that the parentheses should be where the square brackets are, square brackets should be moved to where curly brackets are, and curly brackets moved to shift-9 and shift-0. But I don't care enough to remap my keyboard. -- Steven From ben+python at benfinney.id.au Thu Jul 1 01:02:51 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 15:02:51 +1000 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> Message-ID: <87eifniykk.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: > > > Steven D'Aprano writes: > >> I suppose in principle those extra three key presses (shift-9 > >> shift-0 vs space) could be the straw that breaks the camel's back, > >> but I doubt it. > > > > There's also Fitt's Law to consider: the space bar is big and > > easily-placed and hence easy to type in the middle of a stream of > > other keystrokes. None of that is true for the parens. > > This is true, but there's nothing unique to print about that. Non sequitur. The issue is one of the *difference* being observed (from Python 2 to Python 3): between the use of spaces versus parens for delimiting an argument sequence. Merely counting keystrokes isn't enough, in light of Fitt's Law. > Personally, I think that the parentheses should be where the square > brackets are, square brackets should be moved to where curly brackets > are, and curly brackets moved to shift-9 and shift-0. But I don't care > enough to remap my keyboard. Right. I'm much more concerned about the position of my Ctrl key, to avoid hand injury from all the key chording done as a programmer. -- \ ?Books and opinions, no matter from whom they came, if they are | `\ in opposition to human rights, are nothing but dead letters.? | _o__) ?Ernestine Rose | Ben Finney From debatem1 at gmail.com Thu Jul 1 01:16:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 1 Jul 2010 01:16:57 -0400 Subject: I strongly dislike Python 3 In-Reply-To: <87eifniykk.fsf@benfinney.id.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> Message-ID: On Thu, Jul 1, 2010 at 1:02 AM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 01 Jul 2010 13:13:53 +1000, Ben Finney wrote: >> >> > Steven D'Aprano writes: >> >> I suppose in principle those extra three key presses (shift-9 >> >> shift-0 vs space) could be the straw that breaks the camel's back, >> >> but I doubt it. >> > >> > There's also Fitt's Law to consider: the space bar is big and >> > easily-placed and hence easy to type in the middle of a stream of >> > other keystrokes. None of that is true for the parens. >> >> This is true, but there's nothing unique to print about that. > > Non sequitur. The issue is one of the *difference* being observed (from > Python 2 to Python 3): between the use of spaces versus parens for > delimiting an argument sequence. > > Merely counting keystrokes isn't enough, in light of Fitt's Law. > >> Personally, I think that the parentheses should be where the square >> brackets are, square brackets should be moved to where curly brackets >> are, and curly brackets moved to shift-9 and shift-0. But I don't care >> enough to remap my keyboard. > > Right. I'm much more concerned about the position of my Ctrl key, to > avoid hand injury from all the key chording done as a programmer. Not saying its a cure-all, but I broke my hand pretty badly a few years ago and had a lot of luck with a homemade foot switch for each of the meta keys. Was pretty fun to do (all things considered) and worked pretty well. I'm sure if you're willing to do some shopping around you could get a prefab one fairly cheaply. Geremy Condra From aahz at pythoncraft.com Thu Jul 1 01:37:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Jun 2010 22:37:09 -0700 Subject: Python dynamic attribute creation References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: In article <4c29ad38$0$26210$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Aahz a ?crit : >> In article <4c285e7c$0$17371$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> Aahz a ?crit : >>>> In article <4c2747c1$0$4545$426a74cc at news.free.fr>, >>>> Bruno Desthuilliers wrote: >>>>> >>>>> Python has no pretention at "elegance". >>>> That's not true at all. More precisely, I would agree with you if the >>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >> >> ...and this implies that Python has no focus on elegance because...? > >Nope, that was an answer about where the emphasis was in my previous >statement. I don't mean Python don't care about or is devoid of >elegance, just that it's not the primary concern - hence the "has no >pretention at" part. It may not be "the" primary concern, but elegance certainly is *a* primary concern. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From torriem at gmail.com Thu Jul 1 01:40:06 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 30 Jun 2010 23:40:06 -0600 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4C2C2A36.2030507@gmail.com> On 06/30/2010 06:36 PM, Lawrence D'Oliveiro wrote: > In message , > Michael Torrie wrote: > >> Okay, I will. Your code passes a char** when a char* is expected. > > No it doesn?t. You're right; it doesn't. Your code passes char (*)[512]. warning: passing argument 1 of ?snprintf? from incompatible pointer type /usr/include/stdio.h:385: note: expected ?char * __restrict__? but argument is of type ?char (*)[512]? > And so you misunderstand the difference between a C array and a > pointer. You make a pretty big assumption. Given "char buf[512]", buf's type is char * according to the compiler and every C textbook I know of. With a static char array, there's no need to take it's address since it *is* the address of the first element. Taking the address can lead to problems if you ever substitute a dynamically-allocated buffer for the statically-allocated one. For one-dimensional arrays at least, static arrays and pointers are interchangeable when calling snprinf. You do not agree? Anyway, this is far enough away from Python. From wuwei23 at gmail.com Thu Jul 1 01:42:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 30 Jun 2010 22:42:06 -0700 (PDT) Subject: Need instruction on how to use isinstance References: <4C28045F.6020007@syslang.net> <4C280809.1080507@ixokai.io> <4C28113D.2000603@syslang.net> <777cb6f7-41ae-42f8-ae9a-0b700555545a@e12g2000prh.googlegroups.com> <4c2bd5c9$0$22936$e4fe514c@news.xs4all.nl> Message-ID: <8ad7db9e-1043-4155-8bd6-b69bf0d5b707@a30g2000yqn.googlegroups.com> Hans Mulder wrote: > There's also: hasattr(, '__call__'). ?It works in both 2.x and 3.x. Good work, Hans. I do find that to be a more pythonic approach, personally, being more concerned with an object's ability than its abstract type. From me+list/python at ixokai.io Thu Jul 1 01:49:57 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 30 Jun 2010 22:49:57 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4C2C2C85.2060805@ixokai.io> On 6/30/10 10:37 PM, Aahz wrote: > In article<4c29ad38$0$26210$426a74cc at news.free.fr>, > Bruno Desthuilliers wrote: >> Aahz a ?crit : >>> In article<4c285e7c$0$17371$426a74cc at news.free.fr>, >>> Bruno Desthuilliers wrote: >>>> Aahz a ?crit : >>>>> In article<4c2747c1$0$4545$426a74cc at news.free.fr>, >>>>> Bruno Desthuilliers wrote: >>>>>> >>>>>> Python has no pretention at "elegance". >>>>> That's not true at all. More precisely, I would agree with you if the >>>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >>> >>> ...and this implies that Python has no focus on elegance because...? >> >> Nope, that was an answer about where the emphasis was in my previous >> statement. I don't mean Python don't care about or is devoid of >> elegance, just that it's not the primary concern - hence the "has no >> pretention at" part. > > It may not be "the" primary concern, but elegance certainly is *a* > primary concern. I concur. Its not explicitly stated, but it is the Zen 0. This is further supported by its implied presence in many of the Axioms and Truths of the Bots. "Beautiful is better then ugly"; and then the praise of the explicit, of simplicity, of readability. Elegance is a prime concern of Python, as it is the natural result of the Doctrines of Pythonicity. It may not be stated as a rule, but it a the reward that we are given for following the path of enlightenment. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ P.S. Yes, my wording is intentionally silly-religious. Not meant to be taken as anything but tongue-in-cheek. From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 01:50:35 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 05:50:35 GMT Subject: Reversing backslashed escape sequences Message-ID: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> I have a byte-string which is an escape sequence, that is, it starts with a backslash, followed by either a single character, a hex or octal escape sequence. E.g. something like one of these in Python 2.5: '\\n' '\\xFF' '\\023' If s is such a string, what is the right way to un-escape them to single character byte strings? I could decode them to unicode first, then encode to ASCII: >>> s = '\\n' >>> assert len(s) == 2 >>> s.decode('unicode-escape').encode() '\n' but this fails for non-ASCII bytes: >>> '\\xFF'.decode('unicode-escape').encode() Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128) -- Steven From ben+python at benfinney.id.au Thu Jul 1 02:08:39 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 16:08:39 +1000 Subject: Solutions for hand injury from computer use (was: I strongly dislike Python 3) References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> Message-ID: <87aaqbiviw.fsf_-_@benfinney.id.au> geremy condra writes: > > Right. I'm much more concerned about the position of my Ctrl key, to > > avoid hand injury from all the key chording done as a programmer. > > Not saying its a cure-all, but I broke my hand pretty badly a few years > ago and had a lot of luck with a homemade foot switch for each of the > meta keys. Was pretty fun to do (all things considered) and worked > pretty well. I'm sure if you're willing to do some shopping around you > could get a prefab one fairly cheaply. My current solution is: * Never use a notepad on the couch, but only ever at a properly adjusted table/desk and chair. * Remap CapsLock as an additional Ctrl key, on every computer I use (nobody has ever minded this, because they don't use that key at all :-) * Use my left hand for operating the mouse, since this brings it much closer to the home position on the keyboard, and a standard keyboard design forces the right hand to do disproportionately more work. * Use a wrist support, consisting of two plastic discs that are separated and move freely against each other, that allows my whole arm to move for moving the mouse and hence avoid bending my wrist for that operation. Quite cheap and simple, and I've thereby had no recurrence of injury for the past 3 years. -- \ ?The way to build large Python applications is to componentize | `\ and loosely-couple the hell out of everything.? ?Aahz | _o__) | Ben Finney From clp2 at rebertia.com Thu Jul 1 02:11:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 30 Jun 2010 23:11:59 -0700 Subject: Reversing backslashed escape sequences In-Reply-To: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jun 30, 2010 at 10:50 PM, Steven D'Aprano wrote: > I have a byte-string which is an escape sequence, that is, it starts with > a backslash, followed by either a single character, a hex or octal escape > sequence. E.g. something like one of these in Python 2.5: > > '\\n' > '\\xFF' > '\\023' > > If s is such a string, what is the right way to un-escape them to single > character byte strings? > > I could decode them to unicode first, then encode to ASCII: > >>>> s = '\\n' >>>> assert len(s) == 2 >>>> s.decode('unicode-escape').encode() > '\n' > > but this fails for non-ASCII bytes: > >>>> '\\xFF'.decode('unicode-escape').encode() > Traceback (most recent call last): > ?File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in > position 0: ordinal not in range(128) Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) >>> '\\xFF'.decode('string_escape') '\xff' Cheers, Chris -- http://blog.rebertia.com From ryan at rfk.id.au Thu Jul 1 02:16:23 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 01 Jul 2010 16:16:23 +1000 Subject: A question about the posibility of raise-yield in Python In-Reply-To: References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <4c2b7551$0$1672$742ec2ed@news.sonic.net> Message-ID: <1277964983.1798.1.camel@rambutan> On Wed, 2010-06-30 at 16:20 -0700, rurpy at yahoo.com wrote: > On Jun 30, 10:48 am, John Nagle wrote: > > On 6/30/2010 12:13 AM, ?????? ??????????? wrote: > > > > >> A 'raise-yield' expression would break the flow of a program just like > > >> an exception, going up the call stack until it would be handled, but > > >> also like yield it would be possible to continue the flow of the > > >> program from where it was raise-yield-ed. > > > > Bad idea. Continuing after an exception is generally troublesome. > > This was discussed during the design phase of Ada, and rejected. > > Since then, it's been accepted that continuing after an exception > > is a terrible idea. The stack has already been unwound, for example. > > > > What you want, in in the situation you describe, is an optional > > callback, to be called in case of a fixable problem. Then the > > caller gets control, but without stack unwinding. I've tried my hand at implementing the "condition/handler/restart" paradigm of common lisp, which is very similar to what you describe. You might find it useful: http://pypi.python.org/pypi/withrestart/ Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details From metolone+gmane at gmail.com Thu Jul 1 02:20:17 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 30 Jun 2010 23:20:17 -0700 Subject: Reversing backslashed escape sequences References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c2c2cab$0$14136$c3e8da3 at news.astraweb.com... >I have a byte-string which is an escape sequence, that is, it starts with > a backslash, followed by either a single character, a hex or octal escape > sequence. E.g. something like one of these in Python 2.5: > > '\\n' > '\\xFF' > '\\023' > > If s is such a string, what is the right way to un-escape them to single > character byte strings? > > I could decode them to unicode first, then encode to ASCII: > >>>> s = '\\n' >>>> assert len(s) == 2 >>>> s.decode('unicode-escape').encode() > '\n' > > but this fails for non-ASCII bytes: > >>>> '\\xFF'.decode('unicode-escape').encode() > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in > position 0: ordinal not in range(128) Use 'string-escape': >>> s=['\\n','\\xff','\\023'] >>> for n in s: n.decode('string-escape') ... '\n' '\xff' '\x13' -Mark From steve-REMOVE-THIS at cybersource.com.au Thu Jul 1 02:20:20 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 06:20:20 GMT Subject: Reversing backslashed escape sequences References: <4c2c2cab$0$14136$c3e8da3@news.astraweb.com> Message-ID: <4c2c33a4$0$14136$c3e8da3@news.astraweb.com> On Wed, 30 Jun 2010 23:11:59 -0700, Chris Rebert wrote: > Python 2.6.5 (r265:79063, May 25 2010, 18:21:57) >>>> '\\xFF'.decode('string_escape') > '\xff' I knew unicode-escape, obviously, and then I tried just 'escape', but never thought of 'string_escape'. Thanks for the quick answer. -- Steven From grahn+nntp at snipabacken.se Thu Jul 1 02:58:38 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 1 Jul 2010 06:58:38 GMT Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Wed, 2010-06-30, Steven D'Aprano wrote: > On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: > >> On Tue, 2010-06-29, Stephen Hansen wrote: >>> On 6/29/10 5:41 AM, Roy Smith wrote: >>>> Nobody wrote: >>>> >>>>>> And what about regular expressions? >>>>> >>>>> What about them? As the saying goes: >>>>> >>>>> Some people, when confronted with a problem, think "I know, I'll >>>>> use regular expressions." Now they have two problems. >>>> >>>> That's silly. RE is a good tool. Like all good tools, it is the >>>> right tool for some jobs and the wrong tool for others. >>> >>> There's nothing silly about it. >>> >>> It is an exaggeration though: but it does represent a good thing to >>> keep in mind. >> >> Not an exaggeration: it's an absolute. It literally says that any time >> you try to solve a problem with a regex, (A) it won't solve the problem >> and (B) it will in itself become a problem. And it doesn't tell you >> why: you're supposed to accept or reject this without thinking. > > It's a *two sentence* summary, not a reasoned and nuanced essay on the > pros and cons for REs. Well, perhaps you cannot say anything useful about REs in general in two sentences, and should use either more words, or not say anything at all. The way it was used in the quoted text above is one example of what I mean. (Unless other details have been trimmed -- I can't check right now.) If he meant to say "REs aren't really a good solution for this kind of problem, even though they look tempting", then he should have said that. > Sheesh, I can just imagine you as a child, arguing with your teacher on > being told not to run with scissors -- "but teacher, there may be > circumstances where running with scissors is the right thing to do, you > are guilty of over-simplifying a complex topic into a single simplified > sound-byte, instead of providing a detailed, rich heuristic for analysing > each and every situation in full before making the decision whether or > not to run with scissors". When I was a child I expected that kind of argumentation from adults. I expect something more as an adult. /Jorgen -- // Jorgen Grahn O o . From grahn+nntp at snipabacken.se Thu Jul 1 03:09:57 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 1 Jul 2010 07:09:57 GMT Subject: [OT] Re: Why Is Escaping Data Considered So Magical? References: <4C2AC27D.1040900@gmail.com> <4C2AC54D.4010700@gmail.com> Message-ID: On Wed, 2010-06-30, Michael Torrie wrote: > On 06/30/2010 03:00 AM, Jorgen Grahn wrote: >> On Wed, 2010-06-30, Michael Torrie wrote: >>> On 06/29/2010 10:17 PM, Michael Torrie wrote: >>>> On 06/29/2010 10:05 PM, Michael Torrie wrote: >>>>> #include >>>>> >>>>> int main(int argc, char ** argv) >>>>> { >>>>> char *buf = malloc(512 * sizeof(char)); >>>>> const int a = 2, b = 3; >>>>> snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); >>>> ^^^^^^^^^^ >>>> Make that 512*sizeof(buf) >>> >>> Sigh. Try again. How about "512 * sizeof(char)" ? Still doesn't make >>> a different. The code still crashes because the &buf is incorrect. >> >> I haven't tried to understand the rest ... but never write >> 'sizeof(char)' unless you might change the type later. 'sizeof(char)' >> is by definition 1 -- even on odd-ball architectures where a char is >> e.g. 16 bits. > > You're right. I normally don't use sizeof(char). This is obviously a > contrived example; I just wanted to make the example such that there's > no way the original poster could argue that the crash is caused by > something other than &buf. > > Then again, it's always a bad idea in C to make assumptions about > anything. There are some things you cannot assume, others which few fellow programmers can care to memorize, and others which you often can get away with (like assuming an int is more than 16 bits, when your code is tied to a modern Unix anyway). But sizeof(char) is always 1. > If you're on Windows and want to use the unicode versions of > everything, you'd need to do sizeof(). So using it here would remind > you that when you move to the 16-bit Microsoft unicode versions of > snprintf need to change the sizeof(char) lines as well to sizeof(wchar_t). Yes -- see "unless you might change the type later" above. /Jorgen -- // Jorgen Grahn O o . From animator333 at gmail.com Thu Jul 1 03:16:17 2010 From: animator333 at gmail.com (King) Date: Thu, 1 Jul 2010 00:16:17 -0700 (PDT) Subject: executable builder Message-ID: <26288884-27b8-4f48-8ee6-af4be4364f6e@d16g2000yqb.googlegroups.com> Hi, I am trying to build python a cross platform python executable builder to deploy python app. I tried various tools such as py2exe, pyinstaller, cx_freeze but some how they are not upto the mark except py2exe. Unfortunately py2exe is working only on windows based systems. The task is divide into 3 steps: 1. Collect all the modules(.pyo, .pyd, .dll, etc) required for your project. 2. set up temporary environment for python 3. run main.py using :python.exe main.py Initially I won't be creating an executable using main.py. I would be using shell scripting to execute the main.py. Q1. Which is most efficient way to fine all the modules required by your "main.py". Q2. For example, I have copied all the modules in "d:\project\lib\*.*" python.exe, python.dll, ms*.dll, main.py are copied to "d: \project". Before executing "python.exe main.py", I have to set up an environment var and point it to "d:\project\lib", so that python.exe can find the path for searching/loading modules. How do I do that? Q3. How do you convert your "main.py" into an executable? Prashant From me+list/python at ixokai.io Thu Jul 1 03:19:09 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 00:19:09 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2C416D.4010507@ixokai.io> On 6/30/10 11:58 PM, Jorgen Grahn wrote: > On Wed, 2010-06-30, Steven D'Aprano wrote: >> On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: >>> On Tue, 2010-06-29, Stephen Hansen wrote: >>>> >>>> There's nothing silly about it. >>>> >>>> It is an exaggeration though: but it does represent a good thing to >>>> keep in mind. >>> >>> Not an exaggeration: it's an absolute. It literally says that any time >>> you try to solve a problem with a regex, (A) it won't solve the problem >>> and (B) it will in itself become a problem. And it doesn't tell you >>> why: you're supposed to accept or reject this without thinking. >> >> It's a *two sentence* summary, not a reasoned and nuanced essay on the >> pros and cons for REs. > > Well, perhaps you cannot say anything useful about REs in general in > two sentences, and should use either more words, or not say anything > at all. > > The way it was used in the quoted text above is one example of what I > mean. (Unless other details have been trimmed -- I can't check right > now.) If he meant to say "REs aren't really a good solution for this > kind of problem, even though they look tempting", then he should have > said that. The way it is used above (Even with more stripping) is exactly where it is legitimate. Regular expressions are a powerful tool. The use of a powerful tool when a simple tool is available that achieves the same end is inappropriate, because power *always* has a cost. The entire point of the quote is that when you look at a problem, you should *begin* from the position that a complex, powerful tool is not what you need to solve it. You should always begin from a position that a simple tool will suffice to do what you need. The quote does not deny the power of regular expressions; it challenges widely held assumption and belief that comes from *somewhere* that they are the best way to approach any problem that is text related. Does it come off as negative towards regular expressions? Certainly. But not because of any fault of re's on their own, but because there is this widespread perception that they are the swiss army knife that can solve any problem by just flicking out the right little blade. Its about redefining perception. Regular expressions are not the go-to solution for anything to do with text. Regular expressions are the tool you reach for when nothing else will work. Its not your first step; its your last (or, at least, one that happens way later then most people come around expecting it to be). -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From nobody at nowhere.com Thu Jul 1 03:24:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 01 Jul 2010 08:24:06 +0100 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: > Given "char buf[512]", buf's type is char * according to the compiler > and every C textbook I know of. No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you use "buf" as an rvalue (rather than an lvalue), it will be implicitly converted to char*. If you take its address, you'll get a "pointer to array of 512 chars", i.e. a pointer to the array rather than to the first element. Converting this to a char* will yield a pointer to the first element. If buf was declared "char *buf", then taking its address will yield a char**, and converting this to a char* will produce a pointer to the first byte of the pointer, which is unlikely to be useful. From nobody at nowhere.com Thu Jul 1 03:42:03 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 01 Jul 2010 08:42:03 +0100 Subject: Very odd output from subprocess References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > If I add the line: > for l in line: print ord(l),'\t',l > after the first readline, I get the following: > > > 27  > 91 [ > 48 0 > 48 0 > 109 m > 27  > 91 [ > 51 3 > 55 7 > 109 m > > before the codes begin for the string as it appears if I just print > it. So, what is this sequence? They seem like some sort of escape > codes, I've never seen this before at all. [00m is the ANSI code to reset attributes to their default state. [37m is the ANSI code to set the foreground color to white. > Can anyone enlighten me as to what is going on? > > And, can I safely strip sets of 5 characters from the front as long as > they start with Escape (27)? No, escape sequences can be of arbitrary length. The first thing to try is: del os.environ['TERM'] Any correctly-written program uses the value of the TERM environment variable to select escape codes which are appropriate for the terminal being used. Unfortunately, there are many incorrectly written programs which assume that all terminals support certain escape sequences. The fact that the program is using escape sequences even when stdout/stderr isn't a tty indicates that it isn't correctly written, so it far from certain that clearing TERM will work. From tjreedy at udel.edu Thu Jul 1 03:45:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 03:45:51 -0400 Subject: Composition of functions In-Reply-To: References: Message-ID: On 7/1/2010 12:32 AM, Mladen Gogala wrote: > On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: >> However, you can easily get what you want by using the 'reversed' >> function (and similarly, the 'sorted' function), a la: >> >> >>> y = ''.join(reversed(list(x))) >> >> The 'reversed' and 'sorted' functions are generators that lazilly >> convert an iterable as needed. > > Ah, that is even better. Thanks. It is better if you do not mind making an unnecessary copy. If the list had 10 million elements, you might prefer your original. And by the way, sequential statements are a form of composition, even if strict functionalists do not like to see it that way. -- Terry Jan Reedy From lucaberto at libero.it Thu Jul 1 03:50:22 2010 From: lucaberto at libero.it (luca72) Date: Thu, 1 Jul 2010 00:50:22 -0700 (PDT) Subject: stupid question about html page Message-ID: hello with webbrowser i open the html or php etc page, how i can save the opened page with python? Thanks Luca From mithrandiragainwiki at mailinator.com Thu Jul 1 03:51:08 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 07:51:08 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> Message-ID: "D'Arcy J.M. Cain" wrote in news:mailman.46.1277931314.1673.python-list at python.org: > On Wed, 30 Jun 2010 13:10:43 -0700 (PDT) > garryTX wrote: >> On Jun 29, 5:31?pm, nanothermite911fbibustards > [...] >> you ignorant mf. stfu. > > You shouldn't be calling people ignorant for what they post if you are > just going to repost every word again. Everything that applies to him > applies to you. > > I have had it with GG. For the last few months I have been filtering > all mail from gmail.com that comes through the news gateway into a > separate folder to see where the spam and abuse comes from. Over that > time about 99% of all the useless crap has been caught in that filter. > It's unfortunate that there are some decent posts as well but I have > finally decided that the peace and quiet is worth more than the odd > missed gem. So, if you are accessing this list through GG and wonder > why I seem to be ignoring your brilliant arguments, this is why. > > If anyone is interested in the procmail recipe I will be using, here > it is in all it's glory. > >:0: Hir > * ^List-Id:.*python-list.python.org > * ^From:.*@gmail.com > * ^Newsgroups: > /dev/null > > Cheers. > I only use Google Groups for quick searchs in Usenet archives, but even then I still have to manually filter out all the spam. (Heck, I don't even have a "G-Account." I use news.ett.com.ua as my server and X-News as my reader.) I know spam has almost always been on Usenet, but it really picked up when G-Groups opened up. I really wish that Google would do something about it, but hey! It's not like anyone's interested in Usenet, right? Anyway, I'm glad I'm not the only "pissed customer" out there. And thanks for the code! :) (If you're as paranoid as I am about security and Google, try GoogleSharing for Firefox.) Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From me+list/python at ixokai.io Thu Jul 1 03:54:40 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 00:54:40 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2C49C0.5020900@ixokai.io> On 7/1/10 12:45 AM, Terry Reedy wrote: > On 7/1/2010 12:32 AM, Mladen Gogala wrote: >> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: > >>> However, you can easily get what you want by using the 'reversed' >>> function (and similarly, the 'sorted' function), a la: >>> >>> >>> y = ''.join(reversed(list(x))) >>> >>> The 'reversed' and 'sorted' functions are generators that lazilly >>> convert an iterable as needed. >> >> Ah, that is even better. Thanks. > > It is better if you do not mind making an unnecessary copy. If the list > had 10 million elements, you might prefer your original. The original that did not work? :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From no.email at nospam.invalid Thu Jul 1 04:07:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 01 Jul 2010 01:07:06 -0700 Subject: Composition of functions References: Message-ID: <7xy6dvbp79.fsf@ruckus.brouhaha.com> Terry Reedy writes: > sequential statements are a form of composition, even if > strict functionalists do not like to see it that way. They actually do like to see it that way: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html From mithrandiragainwiki at mailinator.com Thu Jul 1 04:16:05 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 08:16:05 +0000 (UTC) Subject: stupid question about html page References: Message-ID: luca72 wrote in news:abfb7720-6132-4b7b-8084- 5c1a481647e8 at y11g2000yqm.googlegroups.com: > hello > with webbrowser i open the html or php etc page, how i can save the > opened page with python? > > Thanks > > Luca Not sure of a way to capture info from a browser (like Firefox.) I know though that you can save the source of an page with: import urllib urllib.urlretrieve("http://www.example.com/", "Fun.html") You still need a web browser to read it formatted. (If you are on a web page in Firefox, and want to save it, click File>Save Page As...) If you want to save a picture from the Net see: http://www.daniweb.com/code/snippet216796.html Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From lucaberto at libero.it Thu Jul 1 04:31:48 2010 From: lucaberto at libero.it (luca72) Date: Thu, 1 Jul 2010 01:31:48 -0700 (PDT) Subject: stupid question about html page References: Message-ID: <62de7bae-d219-470b-b165-0142d741c1e8@w12g2000yqj.googlegroups.com> On 1 Lug, 10:16, Mithrandir wrote: > luca72 wrote in news:abfb7720-6132-4b7b-8084- > 5c1a48164... at y11g2000yqm.googlegroups.com: > > > hello > > with webbrowser i open the html or php etc page, how i can save the > > opened page with python? > > > Thanks > > > Luca > > Not sure of a way to capture info from a browser (like Firefox.) I know > though that you can save the source of an page with: > > import urllib > urllib.urlretrieve("http://www.example.com/", "Fun.html") > > You still need a web browser to read it formatted. (If you are on a web > page in Firefox, and want to save it, click File>Save Page As...) > > If you want to save a picture from the Net see: > > http://www.daniweb.com/code/snippet216796.html > > Good luck! > > -- > People should read more.https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain > "All that is gold does not glitter, > not all those who wander are lost; > the old that is strong does not wither, > deep roots are not reached by the frost. > From the ashes a fire shall be woken, > a light from the shadows shall spring; > renenwed shall be blade that was broken, > the crownless again shall be king." Thanks for your reply, the problem is that i don't want to save it with file-> save. there is any way to save the page by script. please note that when i save the page with firefox, it save the html page and also make a folder with the script used in the page, how i can make it also with python script? Thanks Luca From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:12:32 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:12:32 -0700 (PDT) Subject: Extract doc strings Message-ID: Hi all, when I have a PyCodeObject, is there any way to extract a doc string from the code? For instance the following script <---script----> """ Hello World! """ def main(): pass main() I would like to get "Hello World!". Any chance? Thanks in advance!! Bye, moerchendiser2k3 From ben+python at benfinney.id.au Thu Jul 1 05:27:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 19:27:20 +1000 Subject: Extract doc strings References: Message-ID: <871vbnimbr.fsf@benfinney.id.au> moerchendiser2k3 writes: > when I have a PyCodeObject, is there any way to extract a doc string > from the code? I'm not very familiar with using the C interface for Python, but does it help to know that a docstring for an object is available at that object's ?__doc__? attribute? -- \ ?Time is the great legalizer, even in the field of morals.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:31:48 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:31:48 -0700 (PDT) Subject: Extract doc strings References: <871vbnimbr.fsf@benfinney.id.au> Message-ID: Hi ben, thanks for your answer. Sure, __doc__ is the access point to the docstring, but in this case, I just get the docstring of the code object. So an explanation what a code object, but I need the docstring of real docstring of the script. bye, moerchendiser From jeanmichel at sequans.com Thu Jul 1 05:35:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 11:35:50 +0200 Subject: Extract doc strings In-Reply-To: References: Message-ID: <4C2C6176.6020407@sequans.com> moerchendiser2k3 wrote: > Hi all, > > when I have a PyCodeObject, is there any way to extract a doc string > from the code? > For instance the following script > > <---script----> > """ > Hello World! > """ > def main(): > pass > main() > > > I would like to get "Hello World!". Any chance? Thanks in advance!! > > Bye, moerchendiser2k3 > Hello, """Hello world!!""" import sys def main(): print sys.modules[__name__].__doc__ main() JM From googler.1.webmaster at spamgourmet.com Thu Jul 1 05:52:58 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 02:52:58 -0700 (PDT) Subject: tp_richcompare vs tp_compare Message-ID: Hi all, just another question. Can anyone explain me whats the real difference between tp_richcompare and tp_compare? I read some stuff, but sometimes I believe the author doesnt know either whats the real difference or they forget it to explain. The Function definition looks very similiar, except the one accepts POD types as return value, the other wants the same for PyObjects. Do I need to implement both? Looks very redundant, isnt it? Or is it just an extension and tp_richcompare is the better choice here? Can anyone please make the light on here? :) Really thanks in advance for your help!! Bye, moerchendiser2k3 From thomas at jollans.com Thu Jul 1 05:55:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 11:55:05 +0200 Subject: Extract doc strings In-Reply-To: References: Message-ID: <4C2C65F9.8030203@jollans.com> On 07/01/2010 11:12 AM, moerchendiser2k3 wrote: > Hi all, > > when I have a PyCodeObject, is there any way to extract a doc string > from the code? > For instance the following script Code objects don't have doc strings, as such. However, for functions at least (this may or may not be true for code originating elsewhere), it appears that the code's first constant is always the docstring, even if it's None: >>> def f(a=()): ... """doc string""" ... return 1,2,3,a ... >>> def g(a=[], b=0): ... return False ... >>> f.__code__.co_consts ('doc string', 1, 2, 3) >>> g.__code__.co_consts (None, False) >>> Why else would g.__code__.co_consts[0] be None if that wasn't a docstring-specific special place. I don't know how you're creating your codeobject, and I don't know if this holds for your case. -- Thomas > > <---script----> > """ > Hello World! > """ > def main(): > pass > main() > This looks like something that should usually be accessed as a module, and in that case, it's trivial, as others have pointed out. From ben+python at benfinney.id.au Thu Jul 1 06:02:59 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 01 Jul 2010 20:02:59 +1000 Subject: Extract doc strings References: <871vbnimbr.fsf@benfinney.id.au> Message-ID: <87wrtfh63w.fsf@benfinney.id.au> moerchendiser2k3 writes: > thanks for your answer. Sure, __doc__ is the access point to the > docstring, but in this case, I just get the docstring of the code > object. So an explanation what a code object, but I need the docstring > of real docstring of the script. I'm probably not understanding what you're asking, then. If you get the docstring of the code object, that seems to be what you asked for, no? The docstring ?of the script? might be the docstring of the module. If that's what you want, you can get the module, then access that module's ?__doc__? attribute. If you don't know how to get the module, then it seems you have a new question to ask: how to get from (whatever it is you currently have) to the module. But, not really knowing what it is you're starting with, I can't say better than that. -- \ ?I took it easy today. I just pretty much layed around in my | `\ underwear all day. ? Got kicked out of quite a few places, | _o__) though.? ?Bug-Eyed Earl, _Red Meat_ | Ben Finney From jeanmichel at sequans.com Thu Jul 1 06:03:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 12:03:24 +0200 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: <4C2C416D.4010507@ixokai.io> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> Message-ID: <4C2C67EC.5070905@sequans.com> Stephen Hansen wrote: > On 6/30/10 11:58 PM, Jorgen Grahn wrote: >> On Wed, 2010-06-30, Steven D'Aprano wrote: >>> On Wed, 30 Jun 2010 14:14:38 +0000, Jorgen Grahn wrote: >>>> On Tue, 2010-06-29, Stephen Hansen wrote: >>>>> >>>>> There's nothing silly about it. >>>>> >>>>> It is an exaggeration though: but it does represent a good thing to >>>>> keep in mind. >>>> >>>> Not an exaggeration: it's an absolute. It literally says that any time >>>> you try to solve a problem with a regex, (A) it won't solve the >>>> problem >>>> and (B) it will in itself become a problem. And it doesn't tell you >>>> why: you're supposed to accept or reject this without thinking. >>> >>> It's a *two sentence* summary, not a reasoned and nuanced essay on the >>> pros and cons for REs. >> >> Well, perhaps you cannot say anything useful about REs in general in >> two sentences, and should use either more words, or not say anything >> at all. >> >> The way it was used in the quoted text above is one example of what I >> mean. (Unless other details have been trimmed -- I can't check right >> now.) If he meant to say "REs aren't really a good solution for this >> kind of problem, even though they look tempting", then he should have >> said that. > > The way it is used above (Even with more stripping) is exactly where > it is legitimate. > > Regular expressions are a powerful tool. > > The use of a powerful tool when a simple tool is available that > achieves the same end is inappropriate, because power *always* has a > cost. > > The entire point of the quote is that when you look at a problem, you > should *begin* from the position that a complex, powerful tool is not > what you need to solve it. > > You should always begin from a position that a simple tool will > suffice to do what you need. > > The quote does not deny the power of regular expressions; it > challenges widely held assumption and belief that comes from > *somewhere* that they are the best way to approach any problem that is > text related. > > Does it come off as negative towards regular expressions? Certainly. > But not because of any fault of re's on their own, but because there > is this widespread perception that they are the swiss army knife that > can solve any problem by just flicking out the right little blade. > > Its about redefining perception. > > Regular expressions are not the go-to solution for anything to do with > text. Regular expressions are the tool you reach for when nothing else > will work. > > Its not your first step; its your last (or, at least, one that happens > way later then most people come around expecting it to be). > Guys, this dogmatic discussion already took place in this list. Why start again ? Re is part of the python standard library, for some purpose I guess. JM From egbertum at xs4all.nl Thu Jul 1 06:56:01 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 12:56:01 +0200 Subject: List-type attributes and name strings Message-ID: <20100701105601.GA6186@xs4all.nl> Normally you use setattr() if the name of the attribute is in a namestring: >>>> setattr(self, namestring, value) But my attributes are lists or dictionaries, and I don't seem to be able to use setattr anymore. Now I use for a list something like: >>> self.__dict__[namestring].append(value) and for a dictionary: >>> self.__dict__[namestring][keystring]=value But I have the impression that I am cheating, because users should not operate on __dict__ directly. Is that true ? And are there better solutions ? egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From alien8752 at gmail.com Thu Jul 1 07:01:00 2010 From: alien8752 at gmail.com (nuny@bid.nes) Date: Thu, 1 Jul 2010 04:01:00 -0700 (PDT) Subject: CONTROLLED DEMOLITION INC explosive-charge placement technician Tom Sullivan 911 TESTIMONIAL Video References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: On Jun 29, 9:31?am, nanothermite911fbibustards wrote: > On Jun 29, 5:24?am, "n... at bid.nes" wrote: > > > > > On Jun 26, 12:16?pm, nanothermite911fbibustards > > > wrote: > > > ? Let's talk about thermite. > > > ? Do you know anything about thermite? It's a powdered mixture of a > > metal oxide and another pure metal that, when raised to a specific > > minimum temperature, allows the metal to "steal" the oxygen from the > > metal oxide, evolving heat. Example, iron oxide loses its oxygen to > > aluminum, yielding aluminum oxide and metallic iron, plus heat. > > > ? Do you know what temperature it must be brought to in order to > > ignite it? > > > ? How do you propose the alleged "nanothermite" supposedly spread > > around the towers was raised to that temperature *simultaneously*? > > > ? Do you know what amount of heat (not temperature) a given mass of > > thermite can produce? > > > ? What amount of heat could the particles of your alleged > > "nanothermite" produce? Remember, each particle burns only as long as > > the oxide component can provide oxygen to the pure metal component of > > the thermite. > > > ? Mark L. Fergerson > > Spoook, Yeah, right, anyone who dares question you must work for the CIA. > All your QUESTIONS are answered in the papers by 911 truth > videos, by Dr Steven Jones and his VIDEOS !!! I didn't ask them what they think happened, I asked *you* what *you* know about thermite. Do *you* know anything about it, or do you simply believe what people claim on websites? > Go to st911.org and start looking !!! No. I'm not interested in wasting my time on predictable rants. > Go to 911blogger.com and start reading !!! No. I'm not interested in wasting my time on predictable rants. > Go to youtube and google for 911truth. No. I'm not interested in wasting my time on predictable rants. > They had military type wireless coordinated cutter charges that they > accessed from under the elevator shafts. One or all of CIA , MOSSAD , > Blackwater , Kroll etc may have been involved. Those are assertions without evidence, and are beside the point. "Cutter charges" have exactly nothing to do with thermite. > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? No. That's why we know about it. Let me guess, 9-11 was the jyeeews, right? What was that about racism again? Mark L. Fergerson From clp2 at rebertia.com Thu Jul 1 07:02:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 04:02:49 -0700 Subject: List-type attributes and name strings In-Reply-To: <20100701105601.GA6186@xs4all.nl> References: <20100701105601.GA6186@xs4all.nl> Message-ID: On Thu, Jul 1, 2010 at 3:56 AM, egbert wrote: > Normally you use setattr() if the name of the attribute is in a > namestring: >>>>> setattr(self, namestring, value) > But my attributes are lists or dictionaries, and I don't seem to be > able to use setattr anymore. Because you're not setting an attribute anymore, you're mutating an existing dict/list object (that just so happens to be the attribute of another object). > Now I use for a list something like: >>>> self.__dict__[namestring].append(value) getattr(self, namestring).append(value) > and for a dictionary: >>>> self.__dict__[namestring][keystring]=value getattr(self, namestring)[keystring] = value > But I have the impression that I am cheating, because users should not > operate on __dict__ directly. > Is that true ? And are there better solutions ? Yes and yes. See above. When dealing with nested stuff (e.g x.y[z]), switch to getattr() as demonstrated above. Cheers, Chris -- http://blog.rebertia.com From lie.1296 at gmail.com Thu Jul 1 07:20:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 01 Jul 2010 21:20:13 +1000 Subject: List-type attributes and name strings In-Reply-To: References: Message-ID: <4c2c79ee@dnews.tpgi.com.au> On 07/01/10 20:56, egbert wrote: >>>> self.__dict__[namestring][keystring]=value try this: getattr(self, namestring)[keystring] = value From jeanmichel at sequans.com Thu Jul 1 07:21:08 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Jul 2010 13:21:08 +0200 Subject: optphart (alpha2) In-Reply-To: <4C2A016F.8070509@ixokai.io> References: <4C2A016F.8070509@ixokai.io> Message-ID: <4C2C7A24.50507@sequans.com> Stephen Hansen wrote: > On 6/28/10 11:50 PM, rantingrick wrote: >>> You just don't get the point, do you? >> >> And just what *point* an i supposed to be "getting" Stephen? That you >> don't like my contribution? If thats your point then i very much "get" >> it. > > This garbage: > > "optphart is the nemisis of the asinine interfaces and bulky libraries > you may be accustomed to in the stdlib. All of which clog your scripts > with wasted lines and your memory with complex interfaces far worse > than any colon clogging putrifaction of junk food can hold a candle > to. Do yourself a favor and give your scripts an enema by harnessing > the simplistic elegance of the "optphart" module instead!" > > It doesn't advocate your solution; it doesn't describe the benefits of > using it; it doesn't provide a reasonable or technical basis by which > it is in some way superior to others. > > It just hand waves other solutions (which exist and are more fully > featured for *very* good reasons-- but you don't bother addressing why > less is more here, you basically just declare it all shit) all the > while being simply insulting to the authors and users of those solutions. > Come on guys :) relax. "elegance of the optphart module", can't you see it's nothing else but a joke ;) JM From egbertum at xs4all.nl Thu Jul 1 07:32:37 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 13:32:37 +0200 Subject: List-type attributes and name strings In-Reply-To: References: <20100701105601.GA6186@xs4all.nl> Message-ID: <20100701113237.GA7273@xs4all.nl> On Thu, Jul 01, 2010 at 04:02:49AM -0700, Chris Rebert wrote: > switch to getattr() as demonstrated above. > Thanks for opening my eyes, Chris. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:07:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:07:27 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: <4c2c8499$0$20848$426a74cc@news.free.fr> D'Arcy J.M. Cain a ?crit : > On Wed, 30 Jun 2010 14:06:05 -0700 > Stephen Hansen wrote: >> Gmail and Google Groups are not one and the same. There's a number of >> people who subscribe to the list directly, use Gmail, and don't go >> anywhere near Google Groups. > > I know that. My filter doesn't catch them. > >>> If anyone is interested in the procmail recipe I will be using, here it >>> is in all it's glory. >>> >>> :0: Hir >>> * ^List-Id:.*python-list.python.org >>> * ^From:.*@gmail.com >>> * ^Newsgroups: >>> /dev/null > > As you can see, to be caught in the filter you need to have a gmail > address and be sending through the news gateway. which doesn't mean they use Google groups... > People sending from > gmail.com directly to the mailing list don't get picked up. I'm pretty > sure that that defines everyone using Google Groups only. And AFAICT you're wrong. I read and post to c.l.py using my newsreader (so NOT going thru GG), and my personal address is @gmail.com. From roy at panix.com Thu Jul 1 08:11:03 2010 From: roy at panix.com (Roy Smith) Date: Thu, 01 Jul 2010 08:11:03 -0400 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: Stephen Hansen wrote: > The quote does not deny the power of regular expressions; it challenges > widely held assumption and belief that comes from *somewhere* that they > are the best way to approach any problem that is text related. Well, that assumption comes from historical unix usage where traditional tools like awk, sed, ed, and grep, made heavy use of regex, and therefore people learned to become proficient at them and use them all the time. Somewhat later, the next generation of tools such as vi and perl continued that tradition. Given the tools that were available at the time, regex was indeed likely to be the best tool available for most text-related problems. Keep in mind that in the early days, people were working on hard-copy terminals [[http://en.wikipedia.org/wiki/ASR-33]] so economy of expression was a significant selling point for regexes. Not trying to further this somewhat silly debate, just adding a bit of historical viewpoint to answer the implicit question you ask as to where the assumption came from. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 1 08:16:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jul 2010 12:16:49 GMT Subject: Extract doc strings References: Message-ID: <4c2c8731$0$28647$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 11:55:05 +0200, Thomas Jollans wrote: > On 07/01/2010 11:12 AM, moerchendiser2k3 wrote: >> Hi all, >> >> when I have a PyCodeObject, is there any way to extract a doc string >> from the code? >> For instance the following script > > Code objects don't have doc strings, as such. However, for functions at > least (this may or may not be true for code originating elsewhere), it > appears that the code's first constant is always the docstring, even if > it's None: Nope, you're misinterpreting what you're seeing. Here's a counter-example from Python 3.1: >>> def f(): ... 999 ... return 42 ... >>> f.__code__.co_consts (None, 42) The docstring is None, unless the function definition is immediately followed by a string literal, in which case the string literal is taken as the docstring. Any other object is removed by the keyhole optimizer: >>> import dis >>> dis.dis(f) 3 0 LOAD_CONST 1 (42) 3 RETURN_VALUE In older versions of Python, the keyhole optimizer was less clever. Here's an example from 2.4: >>> def f(): ... 999 ... return 42 ... >>> f.func_code.co_consts (None, 999, 42) >>> import dis >>> dis.dis(f) 2 0 LOAD_CONST 1 (999) 3 POP_TOP 3 4 LOAD_CONST 2 (42) 7 RETURN_VALUE Aside: Python's keyhole optimizer has removed unreachable string constants (other than doc strings) at least since Python 1.5. But doing the same to other object types had to wait until Python 2.5. -- Steven From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:28:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:28:37 +0200 Subject: List-type attributes and name strings In-Reply-To: References: Message-ID: <4c2c898e$0$20698$426a34cc@news.free.fr> egbert a ?crit : > Normally you use setattr() if the name of the attribute is in a > namestring: >>>>> setattr(self, namestring, value) > But my attributes are lists or dictionaries, and I don't seem to be > able to use setattr anymore. Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def __init__(self): ... self.attr1 = {} ... self.attr2 = [] ... >>> attr1 = dict((x, x) for x in 'abc') >>> attr2 = range(5) >>> f = Foo() >>> setattr(f, "attr1", attr1) >>> setattr(f, "attr2", attr2) >>> f.attr1 {'a': 'a', 'c': 'c', 'b': 'b'} >>> f.attr2 [0, 1, 2, 3, 4] >>> Either I failed to understand you or you overlooked some other problem in you code and jumped to the wrong conclusions. > Now I use for a list something like: >>>> self.__dict__[namestring].append(value) > and for a dictionary: >>>> self.__dict__[namestring][keystring]=value Duh. You're confusing *setting* an attribute and *getting it then mutating it*. Can you get the difference between: >>> f.attr2.append(42) and >>> f.attr2 = [7, 87, 98] ? If you don't, then you're in for serious trouble :-/ > But I have the impression that I am cheating, because users should not > operate on __dict__ directly. Client code shouldn't mess with implementation attribute, for sure. This bypasses all the lookup rules, and can break computed attributes (ie properties or other custom descriptors). At least use getattr() and then appropriate call or operator, ie: >>> getattr(f, "attr1")["w"] = "w" >>> getattr(f, "attr2").append(42) FWIW, it's usually better to hide the mere fact that f.attr1 is a list and f.attr2 a dict. Here a "clean" solution would be to make attr1 and attr2 implementation attributes and provide an API over it, but it might be overkill. HTH From wolfram.hinderer at googlemail.com Thu Jul 1 08:29:51 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Thu, 1 Jul 2010 05:29:51 -0700 (PDT) Subject: Composition of functions References: Message-ID: On 1 Jul., 06:04, Stephen Hansen wrote: > The 'reversed' and 'sorted' functions are generators that lazilly > convert an iterable as needed. 'sorted' returns a new list (and is not lazy). From darcy at druid.net Thu Jul 1 08:34:26 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 1 Jul 2010 08:34:26 -0400 Subject: Ignorance and Google Groups (again) In-Reply-To: <4c2c8499$0$20848$426a74cc@news.free.fr> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <4c2c8499$0$20848$426a74cc@news.free.fr> Message-ID: <20100701083426.3731564a.darcy@druid.net> On Thu, 01 Jul 2010 14:07:27 +0200 Bruno Desthuilliers wrote: > And AFAICT you're wrong. I read and post to c.l.py using my newsreader > (so NOT going thru GG), and my personal address is @gmail.com. But... > From: Bruno Desthuilliers -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:41:48 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:41:48 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4c2c8ca6$0$5338$426a74cc@news.free.fr> Stephen Hansen a ?crit : > On 6/30/10 10:37 PM, Aahz wrote: >> In article<4c29ad38$0$26210$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> Aahz a ?crit : >>>> In article<4c285e7c$0$17371$426a74cc at news.free.fr>, >>>> Bruno Desthuilliers wrote: >>>>> Aahz a ?crit : >>>>>> In article<4c2747c1$0$4545$426a74cc at news.free.fr>, >>>>>> Bruno Desthuilliers wrote: >>>>>>> >>>>>>> Python has no pretention at "elegance". >>>>>> That's not true at all. More precisely, I would agree with you if >>>>>> the >>>>>> emphasis is on "pretention" but not if the emphasis is on elegance; >>>>> Python Zen, #9 (or #8 if you're a TrueHacker !-)) >>>> >>>> ...and this implies that Python has no focus on elegance because...? >>> >>> Nope, that was an answer about where the emphasis was in my previous >>> statement. I don't mean Python don't care about or is devoid of >>> elegance, just that it's not the primary concern - hence the "has no >>> pretention at" part. >> >> It may not be "the" primary concern, but elegance certainly is *a* >> primary concern. > > I concur. > > Its not explicitly stated, but it is the Zen 0. This is further > supported by its implied presence in many of the Axioms and Truths of > the Bots. > > "Beautiful is better then ugly"; and then the praise of the explicit, of > simplicity, of readability. > > Elegance is a prime concern of Python, as it is the natural result of > the Doctrines of Pythonicity. It may not be stated as a rule, but it a > the reward that we are given for following the path of enlightenment. > "Elegance" (just like "beauty") is in the eyes of the beholder. Explicitness, simplicity and readability are indeed primary concerns in Python's design, but "elegance" is not. Now you'll of course find Python mostly elegant *if* you value expliciteness, simplicity and readability, but that's only because your definition of "elegant" happens to match Guido's. But please gentlemen, let's not fight on this. This no religion, there's no dogma here, and no heretic to burn. From drygalski at googlemail.com Thu Jul 1 08:55:03 2010 From: drygalski at googlemail.com (drygal) Date: Thu, 1 Jul 2010 05:55:03 -0700 (PDT) Subject: stupid question about html page References: <62de7bae-d219-470b-b165-0142d741c1e8@w12g2000yqj.googlegroups.com> Message-ID: <6138f256-8d8f-48a8-8f19-e64bd9cb3711@z10g2000yqb.googlegroups.com> On 1 July, 09:31, luca72 wrote: > On 1 Lug, 10:16, Mithrandir > wrote: > > > > > > > luca72 wrote in news:abfb7720-6132-4b7b-8084- > > 5c1a48164... at y11g2000yqm.googlegroups.com: > > > > hello > > > with webbrowser i open the html or php etc page, how i can save the > > > opened page with python? > > > > Thanks > > > > Luca > > > Not sure of a way to capture info from a browser (like Firefox.) I know > > though that you can save the source of an page with: > > > import urllib > > urllib.urlretrieve("http://www.example.com/", "Fun.html") > > > You still need a web browser to read it formatted. (If you are on a web > > page in Firefox, and want to save it, click File>Save Page As...) > > > If you want to save a picture from the Net see: > > >http://www.daniweb.com/code/snippet216796.html > > > Good luck! > > > -- > > People should read more.https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain > > "All that is gold does not glitter, > > not all those who wander are lost; > > the old that is strong does not wither, > > deep roots are not reached by the frost. > > From the ashes a fire shall be woken, > > a light from the shadows shall spring; > > renenwed shall be blade that was broken, > > the crownless again shall be king." > > Thanks for your reply, the problem is that i don't want to save it > with file-> save. > there is any way to save the page by script. > please note that when i save the page with firefox, it save the html > page and also make a folder with the script used in the page, how i > can make it also with python script? > Thanks > > Luca It is not quite possible. If python is used, it runs behind the scenes and generates html send to the browser. You could only see the .py file if the server was poorly configured so it would show the content of the .py file instead of actually executing it to generate the html code, but in that case you would not see any page either. Regards, From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 1 08:56:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 01 Jul 2010 14:56:08 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <4c2c8499$0$20848$426a74cc@news.free.fr> Message-ID: <4c2c9002$0$17075$426a34cc@news.free.fr> D'Arcy J.M. Cain a ?crit : > On Thu, 01 Jul 2010 14:07:27 +0200 > Bruno Desthuilliers wrote: >> And AFAICT you're wrong. I read and post to c.l.py using my newsreader >> (so NOT going thru GG), and my personal address is @gmail.com. > > But... > >> From: Bruno Desthuilliers > Sorry, there's a missing "sometimes" between "I" and "read" !-) Posting from office now. mmmm... Thinking again : I'm not sure the account I use to access usenet from home is a @gmail.com one neither. I'll check this out. From Bill at SynectixLtd.com Thu Jul 1 09:13:28 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Thu, 1 Jul 2010 14:13:28 +0100 Subject: python source code -> win/dos executable (on linux) References: <4c24c152$0$31381$4fafbaef@reader1.news.tin.it> <4c286d71$0$18654$4fafbaef@reader3.news.tin.it> Message-ID: <893ijnFmv1U1@mid.individual.net> "Stephen Hansen" wrote in message news:mailman.2344.1277821469.32709.python-list at python.org... > On 6/29/10 12:27 AM, Lawrence D'Oliveiro wrote: >> In message<4c286d71$0$18654$4fafbaef at reader3.news.tin.it>, superpollo >> wrote: >> >>> Lawrence D'Oliveiro ha scritto: >>>> >>>> Is it really such a hassle to install things on Windows? >>> >>> no, but it *IS* to explain it to dumb users... :-( >> >> Can't you create an installation package that specifies Python and all >> the >> other necessary dependencies, so the Windows package-management system >> will >> automatically pull the right versions in when the user does the >> installation? > > At first, on reading this, I assumed it was sarcastic (and sort of decided > not to reply, because anti-windows is too easy); but on reading again I'm > not so sure, you're writing it all out so .. dry. Then again, 'hearing' > tone in text is hard. > > If this isn't sarcastic: windows has no package management system. You > include every dependency manually (in varying forms) or things don't run. > > Windows has a way to track what you install, and the ability to uninstall > about three fourths of it later. That's it. > > -- > > ... Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > Not that I am a supporter of Windows nor an expert at MSI BUT later versions of Visual Studio do have a mechanism for building a package. I know it's not in VC6, but is in VS.2008. HTH, Bill From pecora at anvil.nrl.navy.mil Thu Jul 1 09:54:57 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 01 Jul 2010 09:54:57 -0400 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <3f35dcf5-25ff-4aa7-820c-592cbffa4b42@u26g2000yqu.googlegroups.com> Message-ID: In article <3f35dcf5-25ff-4aa7-820c-592cbffa4b42 at u26g2000yqu.googlegroups.com>, rantingrick wrote: > On Jun 30, 4:21?pm, geremy condra wrote: > > > Actually, I agree with this complaint though- it is much easier to type > > spaces than parens. > > Oh Geremy please. If you're going to whine about something at least > find something worth whining about! Yes a few more key strokes are > needed. But print should have been a function from day one. The > benefits of a print function over a print statement are obvious to > those who seek the truth and lost on those who wallow in self pity. If > it's that much trouble for you then pick up an editor that auto > inserts parenthesis for you, or *gasps* write a routine yourself. Look > i know masturbation makes you lazy, but geez! Hey, guys (gals?), Don't any of you have typing utilities that will fill in text after you hit a special key-combination? I get print " typed automatically by holding two modifier keys and hitting 'p' key. Sounds harder than it is and it's really fast. So if I switch to Python 3 I would change that to print(" . E.g. for the Mac there are programs (utilities that run in the background) like Quickeys and TypeItForMe that allow you to do all sorts of automatic inserting of commonly used text. They're cheap and easy to use. There must be something like this for Linux and Windows, no? -- -- Lou Pecora From xiyou.wangcong at gmail.com Thu Jul 1 10:13:29 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:13:29 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 06/30/10 01:25, Ethan Furman wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > Setattr and friends exist to work with dynamic attributes. > Yeah, my point is why setattr() for dynamic attributes while assignments for static attributes? Why not unify them? > "The Perfect Language" does not exist, and never will. I'm not even > sure it could exist for a single person, let alone a group of people > with disparate needs, patterns of thought, etc. > Agreed, but at least, the reason why I am being against so many people here is also trying to make Python be more perfect with my understanding. Thanks! -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 10:15:17 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:15:17 -0700 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2CA2F5.2090401@ixokai.io> On 7/1/10 5:29 AM, Wolfram Hinderer wrote: > On 1 Jul., 06:04, Stephen Hansen wrote: >> The 'reversed' and 'sorted' functions are generators that lazilly >> convert an iterable as needed. > > 'sorted' returns a new list (and is not lazy). Oops, you're right. Got the two crossed into one in my head. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From me+list/python at ixokai.io Thu Jul 1 10:18:53 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:18:53 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: <4C2C67EC.5070905@sequans.com> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> Message-ID: <4C2CA3CD.7000401@ixokai.io> On 7/1/10 3:03 AM, Jean-Michel Pichavant wrote: > Re is part of the python standard library, for some purpose I guess. No, *really*? So all those people who have been advocating its useless and shouldn't be are already too late? Damn. Well, there goes *that* whole crusade we were all out on. Since we can't destroy re, maybe we can go club baby seals. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From me+list/python at ixokai.io Thu Jul 1 10:27:23 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:27:23 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2CA5CB.80503@ixokai.io> On 7/1/10 5:11 AM, Roy Smith wrote: > Stephen Hansen wrote: > >> The quote does not deny the power of regular expressions; it challenges >> widely held assumption and belief that comes from *somewhere* that they >> are the best way to approach any problem that is text related. > > Well, that assumption comes from historical unix usage where traditional > tools like awk, sed, ed, and grep, made heavy use of regex, and > therefore people learned to become proficient at them and use them all > the time. Oh, I'm fully aware of the history of re's -- but its not those old hats and even their students and the unix geeks I'm talking about. It's the newbies and people wandering into the language with absolutely no idea about the history of unix, shell scripting and such, who so often arrive with the idea firmly planted in their head, that I wonder at. Sure, there's going to be a certain amount of cross-polination from unix-geeks to students-of-students-of-students-of unix geeks to spread the idea, but it seems more pervasive for that. I just picture a re-vangelist camping out in high schools and colleges selling the party line or something :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ P.S. And no, unix geeks is not a pejorative term. From xiyou.wangcong at gmail.com Thu Jul 1 10:31:29 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:31:29 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 06/30/10 01:20, Stephen Hansen wrote: >> But if so why setattr() still exists? What is it for if we can do the >> same thing via assignments? Also, in order to be perfect, Python should >> accept to add dynamic attributes dynamically, something like PEP >> 363. That doesn't happen. > > What does perfection have to do with anything? Python does not strive > for perfection. More then that, it rejects the entire idea of > perfection when it gets in the way of simply solving problems in an > easy, clean, readable, and reliable way. "Practicality beats purity". > I don't quite understand the spirit behind. IMHO, being purity should not harm the practicality, they are harmonious. :) > PEP 363 proposes adding new syntax: for new syntax to be accepted into > the language one must meet a *very* high bar. One must show a clear, > compelling reason why this new mental burden is worth increasing the > complexity of the language. > > Syntax won't get added to make the language more "perfect" to some > ideals (especially not ideals to some paradigm like OOP, as opposed to > its own internal ideals of readability, ease and practicality). > > Syntax is a burden. Every change in syntax, every addition in syntax, > requires everyone's to mental investment to increase: it costs more > mental energy to use the language, to fully understand it, then it did > before. > But how could the syntax could be a burden? It is easy to understand. And the reason why needs it is also clear, making class attributes more like a dictionary, isn't this why people insists we should have dynamic attribute creation via assigments? This seems to be unfair. :) > > Is Python perhaps less perfect, pure, with that addition to the > language denied? > > Who cares? Perfection is what the Borg* worship, I like understandable. :) Well, using setattr() rather than trivial assignments is also understandable, in fact, for me the former is even more understandable, it shows more clearly when I am adding a new attribute, I am programming classes, not non-classes. -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 10:39:10 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:39:10 -0700 Subject: Python dynamic attribute creation In-Reply-To: <4c2c8ca6$0$5338$426a74cc@news.free.fr> References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> <4c2c8ca6$0$5338$426a74cc@news.free.fr> Message-ID: <4C2CA88E.7090107@ixokai.io> On 7/1/10 5:41 AM, Bruno Desthuilliers wrote: > Stephen Hansen a ?crit : >> On 6/30/10 10:37 PM, Aahz wrote: >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. >> > > "Elegance" (just like "beauty") is in the eyes of the beholder. > > Explicitness, simplicity and readability are indeed primary concerns in > Python's design, but "elegance" is not. Now you'll of course find Python > mostly elegant *if* you value expliciteness, simplicity and readability, > but that's only because your definition of "elegant" happens to match > Guido's. But see, here I disagree with you, because I do think beauty -- as seen by Guido -- and elegance -- as seen by Guido -- *are* a prime concern of Python's design. Sure, those are subjective things, and not everyone will have the absolute same opinion on them. But there is an overriding sense of style and taste (in terms of code) which went into the design of the language and remained through its evolution, that is a very real and important part of the language we have today. A big difference between those people who like and really enjoy using Python verses those who prefer other solutions does come down to a sense of taste and compatibility with the Guido's taste. Some people never get past the revulsion of 'self' and whitespace. Certainly: there's a lot *more* then just taste at issue (I don't mean to trivialize those who select other solutions for reasons of more substance then style), and some people can be fans even without fully embracing Guido's definition of beauty and elegance. > But please gentlemen, let's not fight on this. This no religion, there's > no dogma here, and no heretic to burn. The religious-speak was a joke :) I'm not sure I remember fighting though, either way. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From xiyou.wangcong at gmail.com Thu Jul 1 10:44:40 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 22:44:40 +0800 Subject: Python dynamic attribute creation References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: On 07/01/10 13:49, Stephen Hansen wrote: Hi, Stephen, >> >> It may not be "the" primary concern, but elegance certainly is *a* >> primary concern. > > I concur. > > Its not explicitly stated, but it is the Zen 0. This is further > supported by its implied presence in many of the Axioms and Truths of > the Bots. > > "Beautiful is better then ugly"; and then the praise of the explicit, > of simplicity, of readability. > > Elegance is a prime concern of Python, as it is the natural result of > the Doctrines of Pythonicity. It may not be stated as a rule, but it a > the reward that we are given for following the path of enlightenment. Isn't elegance somewhat equalent to perfection? IMHO, if a language is perfect, it is elegant. However, in the other sub-thread, you seem to be against being perfect for Python. :) -- Live like a child, think like the god. From sitalsuneya at gmail.com Thu Jul 1 10:45:05 2010 From: sitalsuneya at gmail.com (Tiresh kumar K.C) Date: Thu, 1 Jul 2010 07:45:05 -0700 (PDT) Subject: TO CHANGE YOUR LIFE BY A SECOND : Message-ID: <6c85ae00-f39e-437e-b511-c665f7ea7b99@u26g2000yqu.googlegroups.com> DEAR ALL , VISIT: Click here http://successpsycho.blogspot.com AND TO CHANGE YOUR LIFE BY A SECOND : TO KNOW -NEW SECRET OF YOUR LIFE -SUCCESS FACTORS -THOUGHT EFFECT From ricaraoz at gmail.com Thu Jul 1 10:50:58 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Thu, 01 Jul 2010 11:50:58 -0300 Subject: I strongly dislike Python 3 In-Reply-To: <4c2b702c$1@dnews.tpgi.com.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <0291ae53-144e-497d-8762-3f420de92a58@q12g2000yqj.googlegroups.com> <4c2b702c$1@dnews.tpgi.com.au> Message-ID: <4C2CAB52.6070405@gmail.com> On 30/06/2010 01:23 p.m., Lie Ryan wrote: > On 07/01/10 01:42, Michele Simionato wrote: > >> On Jun 30, 2:52 pm, Lie Ryan wrote: >> >>> On 06/27/10 11:24, Steven D'Aprano wrote: >>> >>> >>>>>> Producing print function takes a little bit more effort than producing a >>>>>> print statement. >>>>>> >>> >>>> (1) The main use-cases for print are quick (and usually dirty) scripts, >>>> interactive use, and as a debugging aid. >>>> >>> That is precisely how the quick-and-dirty syntax of print statement can >>> be justified. While debugging, you'll need to be able to quickly add and >>> delete prints here and there, and the extra parens can quickly become >>> irritating. >>> >> Actually when debugging I use pdb which uses "p" (no parens) for >> printing, so having >> print or print() would not make any difference for me. >> > You mean I have to start a full-blown debugger to figure out the value > of a variable? No thanks, debugger has its use for stepping through > program, but not when printing values is sufficient. > Let's, as an exercise, count how many keystrokes and clicks you have spent on this thread and others complaining on the subject. How many programs do you think you could debug with this count (considering you spend a stroke in each print sentence, and I assume you being smart will not need many prints to figure out problem)? So let's say you'll keep complaining for a couple of years till you are ready to adopt Py3. You see what I mean? If you stop complaining right now the keystrokes you'll save will mean you'll have no extra typing to do at all. HTH From aahz at pythoncraft.com Thu Jul 1 10:51:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:51:11 -0700 Subject: Python dynamic attribute creation References: Message-ID: In article , Michael Torrie wrote: >On 06/28/2010 02:31 PM, Aahz wrote: >> In article , >> Michael Torrie wrote: >>> >>> True. But you can't really criticize a language's implementation of OOP >>> without a good understanding of the "pure" OO language. For example, in >>> Smalltalk If/Then statements are actually methods of Boolean objects. >>> >From a certain point of view that's extremely appealing (consistent, >>> anyway). Almost functional in nature. They are not implemented this >>> way in Python, so that's one thing you could argue is not OO about Python. >> >> Python is in no way a pure OOP language. (I assume you're aware of this, >> but your phrasing leaves that in doubt.) > >My phrasing leaves that in doubt? How does my example of how Smalltalk >implements if/then vs how Pyton's implementation leave that in doubt? >The last sentence alone is very clear. Actually, it's precisely the last sentence that creates doubt: by saying "one thing", it's easy for a careless reader to infer that otherwise you would think that Python is a pure OOP. Not a big deal, just thought it deserved clarification. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From me+list/python at ixokai.io Thu Jul 1 10:53:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 07:53:15 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <4C2CABDB.3090206@ixokai.io> On 7/1/10 7:31 AM, WANG Cong wrote: > On 06/30/10 01:20, Stephen Hansen wrote: > >>> But if so why setattr() still exists? What is it for if we can do the >>> same thing via assignments? Also, in order to be perfect, Python should >>> accept to add dynamic attributes dynamically, something like PEP >>> 363. That doesn't happen. >> >> What does perfection have to do with anything? Python does not strive >> for perfection. More then that, it rejects the entire idea of >> perfection when it gets in the way of simply solving problems in an >> easy, clean, readable, and reliable way. "Practicality beats purity". >> > > I don't quite understand the spirit behind. IMHO, being purity should > not harm the practicality, they are harmonious. :) The two are diametrically opposed in fact, quite often. Sometimes that's not the case, but that is the exception and not the rule. >> PEP 363 proposes adding new syntax: for new syntax to be accepted into >> the language one must meet a *very* high bar. One must show a clear, >> compelling reason why this new mental burden is worth increasing the >> complexity of the language. >> >> Syntax won't get added to make the language more "perfect" to some >> ideals (especially not ideals to some paradigm like OOP, as opposed to >> its own internal ideals of readability, ease and practicality). >> >> Syntax is a burden. Every change in syntax, every addition in syntax, >> requires everyone's to mental investment to increase: it costs more >> mental energy to use the language, to fully understand it, then it did >> before. >> > But how could the syntax could be a burden? Syntax is always a burden, by definition. Everything added to the language is a burden. Each has a cost. Some, that cost is light, and the benefits great-- but in others > It is easy to understand. For you. It makes it harder for someone to learn the language. _Every_ bit of syntax does. Its one more thing that you have to learn before you read down a piece of code and easily grok exactly what its doing. >> Is Python perhaps less perfect, pure, with that addition to the >> language denied? >> >> Who cares? Perfection is what the Borg* worship, I like understandable. :) > > Well, using setattr() rather than trivial assignments is also > understandable, in fact, for me the former is even more understandable, > it shows more clearly when I am adding a new attribute, I am programming > classes, not non-classes. For you. You find setattr() more understandable. Others do not. You make a distinction between "programming classes" and what you previously called "metaprogramming", others do not. The importance of "programming classes" is something that exists in your mind only -- well, yours and anyone who chooses to think so as well, which is certainly quite a few people. But I'll thank you to not impose your sense of importance of these things on me. There is nothing at all notable about the difference of "programming classes" verses "programming non-classes" to me. :) You're free to make the distinction in your own code; not everyone defines "programming classes" as anything special. As for setattr... sorry, but your assertion is simply untrue: there is nothing about it which says you are adding a new attribute. You can use it to set any attribute you want, even one that already exists and was defined previously. One uses assignment syntax when the name of the attribute they are setting is known at the time when one writes the code. One uses the setattr function when the name of the attribute is not known until runtime. The difference has *nothing at all* to do with "programming classes" or "dynamic" vs "static". The existence of one does *nothing at all* to invalidate the utiltiy of the other. You use one construct in the usual-case of setting the value of an attribute which is known at coding-time (irregardless of if that attribute existed before: /neither/ of these constructs make /any/ distinction between adding a new attribute and replacing an old one that already existed), and one when the name of that attribute is dependent on some runtime state. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From aahz at pythoncraft.com Thu Jul 1 10:55:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:55:15 -0700 Subject: Python dynamic attribute creation References: Message-ID: In article , WANG Cong wrote: >On 07/01/10 13:49, Stephen Hansen wrote: >>Wang Cong deleted the attribution for Aahz: >>> >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. > >Isn't elegance somewhat equalent to perfection? Not in the slightest. However, elegance is often achieved by aiming for perfection. >IMHO, if a language is perfect, it is elegant. Probably, but the converse is completely not true. P->Q does not imply Q->P, and if this isn't obvious to you, you need to study formal logic (which would be of assistance to you in your other programming endeavors). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From alanwilter at gmail.com Thu Jul 1 10:57:40 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 1 Jul 2010 15:57:40 +0100 Subject: drag & drop in a python GUI application Message-ID: Hello there, I know drag & drop is not possible with TK. Which widget could I use for my python application to be able to work with drag & drop? Thanks, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jul 1 10:58:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 07:58:26 -0700 Subject: I strongly dislike Python 3 References: <4C2623FF.8040104@googlemail.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> Message-ID: In article , geremy condra wrote: >On Wed, Jun 30, 2010 at 4:34 PM, Steven D'Aprano > wrote: >> On Wed, 30 Jun 2010 22:52:06 +1000, Lie Ryan wrote: >>> >>> That is precisely how the quick-and-dirty syntax of print statement can >>> be justified. While debugging, you'll need to be able to quickly add and >>> delete prints here and there, and the extra parens can quickly become >>> irritating. >> >> *rolls eyes* >> >> Not as irritating as people who complain about having to type parentheses. > >http://www.xkcd.net/297/ http://www.netfunny.com/rhf/jokes/90q2/lispcode.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From me+list/python at ixokai.io Thu Jul 1 11:01:25 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 08:01:25 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <4c285e7c$0$17371$426a74cc@news.free.fr> <4c29ad38$0$26210$426a74cc@news.free.fr> Message-ID: <4C2CADC5.8040205@ixokai.io> On 7/1/10 7:44 AM, WANG Cong wrote: > On 07/01/10 13:49, Stephen Hansen wrote: >>> It may not be "the" primary concern, but elegance certainly is *a* >>> primary concern. >> >> I concur. >> >> Its not explicitly stated, but it is the Zen 0. This is further >> supported by its implied presence in many of the Axioms and Truths of >> the Bots. >> >> "Beautiful is better then ugly"; and then the praise of the explicit, >> of simplicity, of readability. >> >> Elegance is a prime concern of Python, as it is the natural result of >> the Doctrines of Pythonicity. It may not be stated as a rule, but it a >> the reward that we are given for following the path of enlightenment. > > > Isn't elegance somewhat equalent to perfection? > IMHO, if a language is perfect, it is elegant. No. > However, in the other sub-thread, you seem to be against being perfect > for Python. :) Yes. Perfection, if it exists (it does not), would probably have the property of elegance. Unless by 'perfect' we mean, 'perfectly models this certain paradigm of thought', in which case 'perfect' is really very limited when someone wants to go do something with a different paradigm all together. Technical elegance (as opposed to like, the elegance of silk) is the clear execution of a thought or process in a concise, simple way. It's utterly impossible for any language to be perfect; no language can possibly express all thought and processes of thought in an ideal form. Every language will have things it is better at expressing then others-- thoughts and ways of thinking that flow better from it then others. A language can be elegant though (I don't even think Python is: it just tries to be): but not everything you do with it will then be elegant itself. Elegance happens in the specific: a certain solution, a key design of a system, there you find elegance. It doesn't exist in the general. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From xiyou.wangcong at gmail.com Thu Jul 1 11:02:57 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:02:57 +0800 Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: On 06/27/10 09:06, Steven D'Aprano wrote: >> In that situation, certainly: adding an attribute on the fly to that >> formal definition seems entirely strange and special of an activity. But >> that's only because you *chose* to *see* and *use* the object that way. >> The "special"ness of the activity is entirely in your head, and to >> Python, its an entirely normal event. > > Exactly. Things which other languages make scary and mysterious > "metaprogramming" are, in Python, normal and ordinary programming. It > doesn't seem to do us any harm. > As long as setattr() exists in Python, that will be not so ordinary. :) -- Live like a child, think like the god. From mathar at krypton.strw.leidenuniv.nl Thu Jul 1 11:06:07 2010 From: mathar at krypton.strw.leidenuniv.nl (Richard Mathar) Date: Thu, 1 Jul 2010 15:06:07 +0000 (UTC) Subject: Sphinx-1.0b compilation for python3.1 Message-ID: I am trying to install Sphinx-1.0b under a Python3 environment. Does anyone have experience with that task? cd *1.0b2 python3 setup.py build File "setup.py", line 50 print 'ERROR: Sphinx requires at least Python 2.4 to run.' So ../ 2to3 -w Sphinx-1.0b2 ....... RefactoringTool: Warnings/messages while refactoring: RefactoringTool: ### In file Sphinx-1.0b2/sphinx/writers/text.py ### RefactoringTool: Line 393: cannot convert map(None, ...) with multiple arguments because map() now truncates to the shortest sequence cd *1.0b2 python3 setup.py build --------------------------------------------------------------------------- This script requires setuptools version 0.6c9 to run (even to display help). I will attempt to download it for you (from http://pypi.python.org/packages/3.1/s/setuptools/), but you may need to enable firewall access for this script first. I will start the download in 15 seconds. (Note: if this machine does not have network access, please obtain the file http://pypi.python.org/packages/3.1/s/setuptools/setuptools-0.6c9-py3.1.egg and place it in this directory before rerunning this script.) --------------------------------------------------------------------------- Downloading http://pypi.python.org/packages/3.1/s/setuptools/setuptools-0.6c9-py3.1.egg Traceback (most recent call last): File "setup.py", line 3, in from setuptools import setup, find_packages ImportError: No module named setuptools During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 93, in use_setuptools import pkg_resources ImportError: No module named pkg_resources During handling of the above exception, another exception occurred: Traceback (most recent call last): File "setup.py", line 6, in ez_setup.use_setuptools() File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 95, in use_setuptools return do_download() File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 89, in do_download egg = download_setuptools(version, download_base, to_dir, download_delay) File "/home/mathar/Sphinx-1.0b2/ez_setup.py", line 150, in download_setuptools src = urllib.request.urlopen(url) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 121, in urlopen return _opener.open(url, data, timeout) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 355, in open response = meth(req, response) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 467, in http_response 'http', request, response, code, msg, hdrs) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 393, in error return self._call_chain(*args) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 327, in _call_chain result = func(*args) File "/home/mathar/work/lib/python3.1/urllib/request.py", line 475, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found How do I move on from here? From xiyou.wangcong at gmail.com Thu Jul 1 11:15:23 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:15:23 +0800 Subject: Python dynamic attribute creation References: <4c27483c$0$4545$426a74cc@news.free.fr> <72dd3dae-30b3-49b0-bf42-3b63178eb3b4@w31g2000yqb.googlegroups.com> <4c286e66$0$20686$426a74cc@news.free.fr> Message-ID: On 06/28/10 17:43, Bruno Desthuilliers wrote: > Carl Banks a ?crit : >> On Jun 27, 3:49 am, Bruno Desthuilliers >> wrote: >>> WANG Cong a ?crit : >>> >>>> On 06/26/10 00:11, Neil Hodgson wrote: >>>>> WANG Cong: >>>>>> 4) Also, this will _somewhat_ violate the OOP princples, in OOP, >>>>>> this is and should be implemented by inherence. >>>>> Most object oriented programming languages starting with Smalltalk >>>>> have allowed adding attributes (addInstVarName) to classes at runtime. >>>> Thanks, I have to admit that I know nothing about Smalltalk. >>> Then you really don't know much about OO. >> >> I don't really know much about Smalltalk either. >> > > Duh. I cancelled this totally stupid and useless post a couple seconds > after hitting the send button, but still too late :( > > So first let me present my apologies to WANG Cong and everyone else, > this was a crude, arrogant and totally stupid thing to say, and I > should know better. Sorry. > No problem. :) > Now on why I first wrote this (warning : personal opinions ahead): > > "object" started with Simula, but objects in Simula are mostly > glorified ADTs with type-based "polymorphic" dispatch. Smalltalk (and > all it's environment) got _way_ further by turning this into a > coherent whole by introducing messages (which are more than just > type-based polymorphic dispatch - Smalltalk's messages are objects > themselves) and "code blocks" - as the only mean to control "flow". I > believe that Smalltalk is (so far) the only "OO" language that was > innovative enough to really escape from good old procedural > programming, and as such possibly the only "True" OOPL. > > Now for various reasons (including implementation issues and > conservatism), it happened that the Simula approach to OO became the > mainstream with languages like C++ then Java, and that most of "OO" > litterature - "OOP principles", golden rules etc - is about this > somehow very restricted approach, so people being taught "OO" that way > have a very restricted - and incomplete - vision of what OO is really > about. That was how I was taught OO, and I always felt that there was > something wrong, inconsistant or missing. > > Studying Smalltalk (however briefly) was for me a real "AHA", > mind-opening moment - suddenly OO made sense as this coherent, > comprehensive and innovative approach to programming I so far failed > to find in Java or C++. > > Now I don't mean one has to master Smalltalk to be allowed to talk > about OO, nor that OO can't exist outside Smalltak (Python being IMHO > another exemple of an interesting and mostly coherent object system, > even if doesn't go as far as Smalltalk do), but - pardon me if this > seems arrogant (and please correct me if it really is) - I can't help > thinking that one cannot really understand OO whithout at least a > brief study of Smalltalk (and - once again - a full Smalltalk > environment, as Smalltalk the language is only one part of the 'full' > object system). > This sounds really cool, I think I should find some time to learn Smalltalk, even only considering historic reasons. Thanks for sharing your Smalltalk learning experience with us! -- Live like a child, think like the god. From me+list/python at ixokai.io Thu Jul 1 11:19:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 08:19:50 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4C2CB216.4050006@ixokai.io> On 7/1/10 8:02 AM, WANG Cong wrote: > On 06/27/10 09:06, Steven D'Aprano wrote: > >>> In that situation, certainly: adding an attribute on the fly to that >>> formal definition seems entirely strange and special of an activity. But >>> that's only because you *chose* to *see* and *use* the object that way. >>> The "special"ness of the activity is entirely in your head, and to >>> Python, its an entirely normal event. >> >> Exactly. Things which other languages make scary and mysterious >> "metaprogramming" are, in Python, normal and ordinary programming. It >> doesn't seem to do us any harm. >> > > As long as setattr() exists in Python, that will be not so ordinary. :) setattr is perfectly ordinary. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From python at mrabarnett.plus.com Thu Jul 1 11:29:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jul 2010 16:29:31 +0100 Subject: Composition of functions In-Reply-To: References: Message-ID: <4C2CB45B.4050804@mrabarnett.plus.com> Zubin Mithra wrote: > > Er, I don't think you thought that one entirely through (/ tried it > out): > > > My Apologies. > > Here is a working one. > > >>> x="123" > >>> t = list(x) > >>> t.reverse() > >>> print ''.join(t) > 321 > > > But of course, the method which was suggested earlier is far more elegant. > > >>> print ''.join(reversed(list(x))) > If you want even more elegance, try slicing: >>> x = "123" >>> print x[ : : -1] 321 From hema_111150 at yahoo.com Thu Jul 1 11:35:29 2010 From: hema_111150 at yahoo.com (eslam) Date: Thu, 1 Jul 2010 08:35:29 -0700 (PDT) Subject: hi hi hi hi Message-ID: <6bc2d6a1-1ecc-4c46-aa88-89f05ee42bd5@b35g2000yqi.googlegroups.com> How and why do people embrace Islam? ?Part One? People embrace Islam in the West (USA, Canada, UK, France and Germany), in the Middle Eastern countries (Saudi Arabia, the Gulf States, Jordan), in Africa and the Far East (Malaysia, Philippines, Hong Kong) and many other countries all over the world. According to Islam, there is only one revealed religion which has been revealed from the time of Adam until the last of the prophets, Mohammad (PBUH), yet it was revealed on stages. Consequently, the essential message of all the prophets was one and the same, Allah says in the Holy Qur?an: ?Verily, We have sent to every nation a messenger (saying), ?Worship Allah and avoid false gods.? All the Prophets that Allah has sent had one basic messages, for indeed the purpose of creation is only one, which is worshiping Allah. Allah says in the Holy Qur?an ?I did not create the jinn and mankind except for My worship.? This message addressed a basic and essential need in human beings; the need to worship. Such basic need was created in all human beings at the time of Adam?s creation. Man?s Natural Disposition : the Fitrah As Allah made all human beings swear to His Godhood when He first created Adam, this oath is printed on the human soul even before it enters the fetus in the fifth month of pregnancy. So when a child is born, he has a natural belief in Allah. This natural belief is called in Arabic the fitrah. If the child was left alone, he would grow with the same faith and believe in Allah. But what happens is that all children get affected by their surroundings, whether directly or indirectly. Prophet Mohammad (PBUH) said that Allah said: ?I created My servants in the right religion but the devils made them go astray.? Prophet Mohammad (PBUH) also said: ?Each child is born in a state of ?fitrah?, but his parents make him a Jew or a Christian. It is like the way an animal gives birth to a normal offspring. Have you noticed any (young animal) born mutilated before you mutilate them?? And since the child?s body submits to the physical laws which Allah has put in nature, his soul also submits naturally to the belief that Allah is its Lord and Creator. However, his family friends, and his surroundings affect him, and as he grows up, he may find himself following this or that?s way of life. The religion the child follows at early stages of his life (childhood) is one of custom and upbringing, and Allah does not punish him for this religion. However, by reaching maturity one starts differentiating between what?s right and what?s wrong, an adult must now follow the religion of knowledge and reason; Islam. At this point the devil starts doing his best and trying hard to encourage him to stay as he is ( encourage him to stay passive and not do any good deeds), or bring down. Evils are made pleasing to mankind and thus we live in a constant struggle between our fitrah and our desires till we find the right road. If one chooses his fitrah, Allah will help him control his desires, even though it may take most of his life to do so; for example some people embraced Islam in their old age, yet it is never too late. From mwilson at the-wire.com Thu Jul 1 11:36:46 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 1 Jul 2010 15:36:46 +0000 (UTC) Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: Nobody wrote: > On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: >> Given "char buf[512]", buf's type is char * according to the compiler >> and every C textbook I know of. References from Kernighan & Ritchie _The C Programming Language_ second edition: > No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you > use "buf" as an rvalue (rather than an lvalue), it will be implicitly > converted to char*. K&R2 A7.1 > If you take its address, you'll get a "pointer to array of 512 chars", > i.e. a pointer to the array rather than to the first element. Converting > this to a char* will yield a pointer to the first element. K&R2 A7.4.2 ????????Mel. From xiyou.wangcong at gmail.com Thu Jul 1 11:42:20 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:42:20 +0800 Subject: Python dynamic attribute creation References: Message-ID: On 07/01/10 22:53, Stephen Hansen wrote: > > One uses assignment syntax when the name of the attribute they are > setting is known at the time when one writes the code. > > One uses the setattr function when the name of the attribute is not > known until runtime. > > The difference has *nothing at all* to do with "programming classes" > or "dynamic" vs "static". > This is exactly what I am thinking. What we differ is that if using both assignment syntax and setattr() builtin function is a good design. You think the current design which lets them co-exist is more understandable, while I think this is less perfect and then not that more understandable. :) "Understandable" is hard to define, it differs so much from person to person. "Perfect" is a strong sense for which I enjoy programming and learn programming languages. Thanks much for your detailed answers, I like discussing this with you! -- Live like a child, think like the god. From xiyou.wangcong at gmail.com Thu Jul 1 11:46:55 2010 From: xiyou.wangcong at gmail.com (WANG Cong) Date: Thu, 01 Jul 2010 23:46:55 +0800 Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: On 07/01/10 23:19, Stephen Hansen wrote: >> >> As long as setattr() exists in Python, that will be not so ordinary. :) > > setattr is perfectly ordinary. If you think setattr() is as ordinary as a trivial assignment, I will argue with you, this is personal taste. However, I think setattr() is a builtin function, using it exposes the *magic* of metaprogramming (or class-programming, if more correct) at a first glance. -- Live like a child, think like the god. From torriem at gmail.com Thu Jul 1 12:10:16 2010 From: torriem at gmail.com (Michael Torrie) Date: Thu, 01 Jul 2010 10:10:16 -0600 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4C2CBDE8.3010305@gmail.com> On 07/01/2010 01:24 AM, Nobody wrote: > No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you > use "buf" as an rvalue (rather than an lvalue), it will be implicitly > converted to char*. Yes this is true. I misstated. I meant that most text books I've seen say to just use the variable in an *rvalue* as a pointer (can't think of any lvalue use of an array). K&R states that arrays (in C anyway) are always *passed* by pointer, hence when you pass an array to a function it automatically decays into a pointer. Which is what you said. So no need for & and the compiler warning you get with it. That's all. If the OP was striving for pedantic correctness, he would use &buf[0]. From dhilip.jec at gmail.com Thu Jul 1 12:21:40 2010 From: dhilip.jec at gmail.com (Dhilip S) Date: Thu, 1 Jul 2010 21:51:40 +0530 Subject: Python 2.4.2 Installation error Message-ID: Hello Everyone.. I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got error message while doing make command. anybody can tell tell, How to overcome this error.... -- with regards, Dhilip.S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Jul 1 12:35:31 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 01 Jul 2010 09:35:31 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <87aaqbiviw.fsf_-_@benfinney.id.au> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> Message-ID: <4C2CC3D3.3030100@stoneleaf.us> Ben Finney wrote: > geremy condra writes: > >>> Right. I'm much more concerned about the position of my Ctrl key, to >>> avoid hand injury from all the key chording done as a programmer. >> Not saying its a cure-all, but I broke my hand pretty badly a few years >> ago and had a lot of luck with a homemade foot switch for each of the >> meta keys. Was pretty fun to do (all things considered) and worked >> pretty well. I'm sure if you're willing to do some shopping around you >> could get a prefab one fairly cheaply. > > My current solution is: > > * Never use a notepad on the couch, but only ever at a properly adjusted > table/desk and chair. > > * Remap CapsLock as an additional Ctrl key, on every computer I use > (nobody has ever minded this, because they don't use that key at all > :-) > > * Use my left hand for operating the mouse, since this brings it much > closer to the home position on the keyboard, and a standard keyboard > design forces the right hand to do disproportionately more work. > > * Use a wrist support, consisting of two plastic discs that are > separated and move freely against each other, that allows my whole arm > to move for moving the mouse and hence avoid bending my wrist for that > operation. > > Quite cheap and simple, and I've thereby had no recurrence of injury for > the past 3 years. I'll have to give the left-handed mouse a try... hmmm -- not too bad so far. I also switched over to the Dvorak keyboard layout. Made a world of difference for me. ~Ethan~ From jdoe at usenetlove.invalid Thu Jul 1 12:39:46 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 01 Jul 2010 16:39:46 GMT Subject: OT Komodo Edit, line selection gutter is one pixel wide? Message-ID: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Is there a way to increase the line selection gutter width? It seems to be only one pixel wide. In other words... When I single click on the left side of the line, in order to automatically select the line, the pointer must be in a precise single pixel location immediately to the left of the line. Or am I doing something wrong? Thanks. By the way... I can see that clicking and dragging to select multiple lines can be done somewhere in the space of the first character on the lines, but I am talking about single clicking to select the single line. From me+list/python at ixokai.io Thu Jul 1 12:51:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 09:51:27 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4C2CC78F.8060109@ixokai.io> On 7/1/10 8:46 AM, WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. I'm going to try this one more time -- you place a great deal of importance and special properties on Classes and what they mean to object oriented programming. That is perfectly fine. In some languages, there is indeed a great deal of importance to Classes. They define a sort of formal structure, a contract, and the rules by which the program runs. Object Oriented Programming is ingrained in them as not just a means, but an end -- it's the Right Way to do things, the tenants of the OOP paradigm are ingrained as the rules of interaction between things. In these languages, modifying a class at runtime might indeed be strange, interesting, magical. In Python, none of this holds true. Python's classes are *created* at runtime. The 'class body' is executable code which is run when your program starts, the result of which is your class. Now, let me ask you a (rhetorical) question: exactly when are the attributes 'created' on a class? You say that adding attributes to an object is special, magical. Consider this relatively simple class: class Person(object): def __init__(self, name, age=21): self.name = name self.age = age I can instantiate that easily, of course: me = Person("Stephen", 29) This is all the normal, basic way we deal with classes and attributes right? Right. Here's the important detail. When __init__ is called, the person object has no attributes(*). None at all. Unlike in other more real OOP languages where they have attributes which are just basically uninitialized, here it has none. In the __init__, its adding attributes to that object which already exists on the fly-- at runtime. Now, here I do something "magic": me.hair_color = "brown" I've now added a new attribute to the existing instance, what you're calling something special called "class programming". The problem: that's the *exact same syntax* which was used in __init__. There's no difference between what happened in __init__, where we normally consider that we're defining our attributes, and what may happen later when you decide to add an attribute 'ont he fly'. The second case is special *only* if you *imagine* it is-- and it is special then *only* in your own mind. It is special, "adding an attribute to a previously defined class", if you decide for yourself, classes are things that are set in stone or pre-defined in some way. Classes aren't pre-defined, they're entirely created and defined on the fly. That a certain 'on the fly' may happen early (right after you create an instance) or another may happen at any point later-- Python doesn't and can't even tell the difference (not by itself without any jumping through hoops at least). It's all the same. There's nothing magical about it. Except to you, *personally*. In your head, only. Its fine to believe that and treat classes as special for you: but its your *choice* to do so. If you want magic, go learn about metaclasses, descriptors, and such. Othewrise, I give up. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From usenot at geekmail.INVALID Thu Jul 1 13:00:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 1 Jul 2010 19:00:33 +0200 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> Message-ID: <20100701190033.15ceaeea@geekmail.INVALID> On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman wrote: > I'll have to give the left-handed mouse a try... hmmm -- not too bad > so far. Since we're on the subject: I find the best solution for "lots of typing with a little mousing" to be a keyboard with a pointing stick (or track point or nav stick or whatever people call it). I'm not quite sure why they haven't become standard issue on keyboards. Shame, is what that is. /W -- INVALID? DE! From emile at fenx.com Thu Jul 1 13:09:30 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 10:09:30 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On 7/1/2010 10:00 AM Andreas Waldenburger said... > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > wrote: > >> I'll have to give the left-handed mouse a try... hmmm -- not too bad >> so far. > > Since we're on the subject: I find the best solution for "lots of > typing with a little mousing" to be a keyboard with a pointing stick > (or track point or nav stick or whatever people call it). I'm not quite > sure why they haven't become standard issue on keyboards. Shame, is > what that is. > > /W > When I started having trouble about ten years ago, I switched to a keyboard with integrated mouse pad. No problems since... Emile From marduk at letterboxes.org Thu Jul 1 13:10:26 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 01 Jul 2010 13:10:26 -0400 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <1278004226.9444.9.camel@paska> On Thu, 2010-07-01 at 21:51 +0530, Dhilip S wrote: > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 > got error message while doing make command. anybody can tell tell, How > to overcome this error.... "this" error apparently did not get included in your post. From vijay.nori at gmail.com Thu Jul 1 13:10:31 2010 From: vijay.nori at gmail.com (V N) Date: Thu, 1 Jul 2010 10:10:31 -0700 (PDT) Subject: escape character / csv module Message-ID: string "\x00" has a length of 1. When I use the csv module to write that to a file csv_f = csv.writer(file("test.csv","wb"),delimiter="|") csv_f.writerow(["\x00","zz"]) The output file looks like this: |zz Is it possible to force the writer to write that string? From thomas at jollans.com Thu Jul 1 13:11:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 19:11:07 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <4C2CCC2B.2000108@jollans.com> On 07/01/2010 06:21 PM, Dhilip S wrote: > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Which error? > -- > with regards, > Dhilip.S > > From nagle at animats.com Thu Jul 1 13:17:02 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 10:17:02 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> On 7/1/2010 8:36 AM, Mel wrote: > Nobody wrote: >> On Wed, 30 Jun 2010 23:40:06 -0600, Michael Torrie wrote: >>> Given "char buf[512]", buf's type is char * according to the compiler >>> and every C textbook I know of. > > References from Kernighan& Ritchie _The C Programming Language_ second > edition: > >> No, the type of "buf" is "char [512]", i.e. "array of 512 chars". If you >> use "buf" as an rvalue (rather than an lvalue), it will be implicitly >> converted to char*. Yes, unfortunately. The approach to arrays in C is just broken, for historical reasons. To understand C, you have to realize that in the early versions, function declarations weren't visible when function calls were compiled. That came later, in ANSI C. So parameter passing in C is very dumb. Billions of crashes due to buffer overflows later, we're still suffering from that mistake. But this isn't a Python issue. John Nagle From lists at cheimes.de Thu Jul 1 13:18:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 01 Jul 2010 19:18:22 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Perhaps somebody is able to help you if you provide the full error message and describe all steps that lead to the error mesage. http://catb.org/esr/faqs/smart-questions.html#beprecise Christian From usenot at geekmail.INVALID Thu Jul 1 13:19:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 1 Jul 2010 19:19:55 +0200 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: <20100701191955.54cd0aee@geekmail.INVALID> On Thu, 01 Jul 2010 10:09:30 -0700 Emile van Sebille wrote: > On 7/1/2010 10:00 AM Andreas Waldenburger said... > > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > > wrote: > > > >> I'll have to give the left-handed mouse a try... hmmm -- not too > >> bad so far. > > > > Since we're on the subject: I find the best solution for "lots of > > typing with a little mousing" to be a keyboard with a pointing stick > > (or track point or nav stick or whatever people call it). I'm not > > quite sure why they haven't become standard issue on keyboards. > > Shame, is what that is. > > > > /W > > > > When I started having trouble about ten years ago, I switched to a > keyboard with integrated mouse pad. No problems since... > Not bad, but you'll still have to move away your hand from the home row that way. Pointing stick, I tells ya, pointing stick! ;) /W -- INVALID? DE! From thomas at jollans.com Thu Jul 1 13:23:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 19:23:53 +0200 Subject: Python/C++ timer intermittent bug In-Reply-To: References: Message-ID: <4C2CCF29.3030209@jollans.com> On 06/30/2010 09:28 PM, Paul at mail.python.org wrote: > I have a problem with threading using the Python/C API. I have an > extension that implements a timer, and the C++ timer callback function > calls a Python function. The relevant code looks like this: > > [snip] > > static void CALLBACK PeriodicTimer(UINT wTimerID, UINT msg, > DWORD dwUser, DWORD dw1, DWORD dw2) This looks frightfully WIN32. How are you calling a timer? I'm guessing you're using some win32 function. So my tentative tip on where the problem might lie is the interaction of Python's PyThreads and the win32 threading primitives you're probably calling. > { > PyGILState_STATE pgs; > > pgs = PyGILState_Ensure(); > if(attrsetFlag) > { > pres = PyObject_CallFunction(attr,NULL); > if( pres == NULL )printf("CallFunction failed!\n"); > } > PyGILState_Release( pgs ); > > } > > The Python code that sets this up looks like this: > > fetimer.setmodname("Timeslice3") > fetimer.setprocname("Timetester") I'm sure this isn't the problem, but why aren't you just passing in an object? As in fetimer.setcallable(Timeslice3.Timetester)? > [ snip ] > > Fatal Python Error: This thread state must be current when releasing > > Fatal Python Error: PyThreadState_DeleteCurrent: no current tstate > > Fatal Python Error: PyEval_SaveThread: NULL tstate As I said, I'd expect there to be some irregularities between what PyThreads would normally do and what you're doing in the code you didn't post. > > Can anybody help me make this code stable, so that it works all the > time? I can't really help you - I have limited experience with the C API, let alone Python/C threading, and know next to nothing about Windows programming. Maybe you should ask in a more specialized (and quieter) forum, such as the CAPI-SIG mailing list, or python-win32. -- Thomas From googler.1.webmaster at spamgourmet.com Thu Jul 1 13:40:22 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 1 Jul 2010 10:40:22 -0700 (PDT) Subject: Extract doc strings References: <4c2c8731$0$28647$c3e8da3@news.astraweb.com> Message-ID: Great! Thanks a lot! This is what I was looking for. :) Bye, moerchendiser2k3 From homeusenet3 at brianhv.org Thu Jul 1 13:46:39 2010 From: homeusenet3 at brianhv.org (Brian Victor) Date: Thu, 1 Jul 2010 17:46:39 +0000 (UTC) Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: Emile van Sebille wrote: > When I started having trouble about ten years ago, I switched to a > keyboard with integrated mouse pad. No problems since... Where did you find that? I've been looking for one. (Assuming you mean a trackpad, and not a mouse pad.) That said, my own solution was the Kensington Expert Mouse. For some reason, the trackball hurts me much less than a real mouse, and keeps me from being disproportionately annoyed when I have to pick up my pointing device to move the cursor where I want it. ;) -- Brian From mithrandiragainwiki at mailinator.com Thu Jul 1 14:05:05 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 18:05:05 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <4c2c9002$0$17075$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote in news:4c2c9002$0$17075$426a34cc at news.free.fr: > D'Arcy J.M. Cain a ?crit : >> On Thu, 01 Jul 2010 14:07:27 +0200 >> Bruno Desthuilliers >> wrote: >>> And AFAICT you're wrong. I read and post to c.l.py using my >>> newsreader (so NOT going thru GG), and my personal address is >>> @gmail.com. >> >> But... >> >>> From: Bruno Desthuilliers >>> >> > > Sorry, there's a missing "sometimes" between "I" and "read" !-) > Posting from office now. > > mmmm... Thinking again : I'm not sure the account I use to access > usenet from home is a @gmail.com one neither. I'll check this out. Just thought of this last night: If you view the full header you can see this: Complaints-To: groups-abuse at google.com Try blocking posts with that in the header. :) Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From rami.chowdhury at gmail.com Thu Jul 1 14:11:54 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 1 Jul 2010 11:11:54 -0700 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <20100701181154.GC2267@tigris> On 2010-07-01 23:42, WANG Cong wrote: > On 07/01/10 22:53, Stephen Hansen wrote: > > > > > One uses assignment syntax when the name of the attribute they are > > setting is known at the time when one writes the code. > > > > One uses the setattr function when the name of the attribute is not > > known until runtime. > > > > The difference has *nothing at all* to do with "programming classes" > > or "dynamic" vs "static". > > > > This is exactly what I am thinking. > > What we differ is that if using both assignment syntax and setattr() > builtin function is a good design. You think the current design which > lets them co-exist is more understandable, while I think this is less > perfect and then not that more understandable. :) Is this not the practicality / purity discussion from another subthread? You think it's "less perfect" (by which I think you actually mean "less pure" - but please correct me if I'm wrong). But you admit that it's more under- standable (i.e. it's more practical). Practicality beats purity, so the "less pure" solution wins. > > "Understandable" is hard to define, it differs so much from person to > person. "Perfect" is a strong sense for which I enjoy programming and > learn programming languages. > > Thanks much for your detailed answers, I like discussing this with you! > > > -- > Live like a child, think like the god. > > -- > http://mail.python.org/mailman/listinfo/python-list ---- Rami Chowdhury "It always takes longer than you expect, even when you take Hofstadter's Law into account." -- Hofstadter's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From emile at fenx.com Thu Jul 1 14:17:22 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 11:17:22 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On 7/1/2010 10:46 AM Brian Victor said... > Emile van Sebille wrote: >> When I started having trouble about ten years ago, I switched to a >> keyboard with integrated mouse pad. No problems since... > > Where did you find that? I've been looking for one. (Assuming you mean > a trackpad, and not a mouse pad.) Actually, I guess it's called a touchpad? And they are hard to find with the ergonomic split keyboard and touchpad placement I prefer. I have three systems I do most of my work on, so when I spot the kind I like I buy four or more so I can update all the keyboards at once and still have a spare. A quick check on cdw.com doesn't show any at the moment. Froogle shows some, but none that match the layout I like. Emile From ian.g.kelly at gmail.com Thu Jul 1 14:20:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 1 Jul 2010 12:20:27 -0600 Subject: OT Komodo Edit, line selection gutter is one pixel wide? In-Reply-To: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 10:39 AM, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? I've been using Komodo for 3.5 years and didn't even realize there was such a gutter until you pointed it out. I don't see any way to make it larger either -- how odd. When I want to select full lines, I use the keyboard. I have Alt+Home mapped to the Beginning of Line command (the one that always takes you to the first column rather than the first character), and then Shift+Up/Down to select. From me+list/python at ixokai.io Thu Jul 1 14:20:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 01 Jul 2010 11:20:50 -0700 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <4c2c9002$0$17075$426a34cc@news.free.fr> Message-ID: <4C2CDC82.4040204@ixokai.io> On 7/1/10 11:05 AM, Mithrandir wrote: > Just thought of this last night: If you view the full header you can see > this: > > Complaints-To: groups-abuse at google.com > > Try blocking posts with that in the header. :) Better idea: auto-forward any messages with that header, to that address. Odds are it's accurate :) -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From thomas at jollans.com Thu Jul 1 14:30:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 20:30:01 +0200 Subject: OT Komodo Edit, line selection gutter is one pixel wide? In-Reply-To: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <4C2CDEA9.60004@jollans.com> On 07/01/2010 06:39 PM, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. Not sure if this factoid is of any use to you, but many editors support selecting lines by tripple-clicking. From thomas at jollans.com Thu Jul 1 14:33:13 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 01 Jul 2010 20:33:13 +0200 Subject: Ignorance and Google Groups (again) In-Reply-To: <4C2CDC82.4040204@ixokai.io> References: <4c2c9002$0$17075$426a34cc@news.free.fr> <4C2CDC82.4040204@ixokai.io> Message-ID: <4C2CDF69.6050407@jollans.com> On 07/01/2010 08:20 PM, Stephen Hansen wrote: > On 7/1/10 11:05 AM, Mithrandir wrote: > >> Just thought of this last night: If you view the full header you can see >> this: >> >> Complaints-To: groups-abuse at google.com >> >> Try blocking posts with that in the header. :) > > Better idea: auto-forward any messages with that header, to that > address. Odds are it's accurate :) > Brilliant! vim .procmailrc! Done! :0: * X-Complaints-To: groups-abuse at google.com !groups-abuse at google.com From dotancohen at gmail.com Thu Jul 1 14:34:15 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Thu, 1 Jul 2010 21:34:15 +0300 Subject: Ignorance and Google Groups (again) In-Reply-To: <4C2BB1BD.9000306@ixokai.io> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: On 1 July 2010 00:06, Stephen Hansen wrote: > Gmail and Google Groups are not one and the same. There's a number of people > who subscribe to the list directly, use Gmail, and don't go anywhere near > Google Groups. > I'm one of them. Gmail is great for mailing lists, though I would never use it as a personal email client. But I'm more of a lurker than a poster on this list, so D'Arcy won't miss me anyway. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From aahz at pythoncraft.com Thu Jul 1 14:35:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 11:35:21 -0700 Subject: Solutions for hand injury from computer use References: <4C2623FF.8040104@googlemail.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: In article <20100701190033.15ceaeea at geekmail.INVALID>, Andreas Waldenburger wrote: > >Since we're on the subject: I find the best solution for "lots of >typing with a little mousing" to be a keyboard with a pointing stick >(or track point or nav stick or whatever people call it). I'm not quite >sure why they haven't become standard issue on keyboards. Shame, is >what that is. My solution is to simply use the pointing device as little as possible. Keyboards rule! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From python at bdurham.com Thu Jul 1 14:48:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 01 Jul 2010 14:48:47 -0400 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? Message-ID: <1278010127.6605.1382869273@webmail.messagingengine.com> Curious if any of you are using GPG or PGP encryption and/or signatures in your Python apps? In particular are you: 1. clearsigning specific emails? 2. validating clearsigned emails from others? 3. encrypting/decrypting files? 4. generating signatures for files that you are exchanging/posting for download? 5. what public keyring services are you using? I'm also looking for recommendations on which 3rd party modules you're using for these tasks? In particular is there a particular module you prefer or have concerns about? Here's my short list of modules that *might* support encryption and signing in general: - m2crypto - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) - tlslite - pyme - evpy - python-gnupg (by developer of Python's logging module) Any comments on using the subprocess module to wrap the gpg or openssl command line utilities? This seems to be a common technique for encryption and signing solutions and appears to the technique used by python-gnupg (for example). Thank you, Malcolm From anon at blank.com Thu Jul 1 15:13:02 2010 From: anon at blank.com (anon) Date: Thu, 01 Jul 2010 20:13:02 +0100 Subject: escape character / csv module In-Reply-To: References: Message-ID: <6N5Xn.96826$NW.11876@hurricane> V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? This will do what you want: "\\x00" From cs at zip.com.au Thu Jul 1 15:58:07 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 2 Jul 2010 05:58:07 +1000 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: <20100701195807.GA2508@cskk.homeip.net> On 01Jul2010 19:00, Andreas Waldenburger wrote: | On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman | wrote: | > I'll have to give the left-handed mouse a try... hmmm -- not too bad | > so far. | | Since we're on the subject: I find the best solution for "lots of | typing with a little mousing" to be a keyboard with a pointing stick | (or track point or nav stick or whatever people call it). I'm not quite | sure why they haven't become standard issue on keyboards. Shame, is | what that is. I like the pointing stick too ("trackpoint" in IBM land), yea, even to the point of specially buying an IBM trackpoint keyboard several years ago for our computer room. I used to strongly favour ThinkPads for the same reason (they are/were decent in other ways too, but it was the trackpoint that was their killer feature for me). I've been pushed to a MacBook of late (changed jobs and death/tiredness of the thinkpads) and am getting by with the touchpad, whcih works fairly well; I used to always turn touchpads off in the past, so maybe my stance has changed slightly - I used to brush them all the time, and many systems doubled up a transient brush as a mouse click:-( The Mac's click-to-focus model may also be helping me here - my thinkpad desktop would be UNIX X11 in focus-follows-mouse mode, which is far more sensitive to trouble from accidental mouse movement. But yes, the trackpoint _greatly_ reduced my need to move my arms to reach for a mouse. Loved it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ "I'm a lawyer." "Honest?" "No, the usual kind." From python at mrabarnett.plus.com Thu Jul 1 16:04:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Jul 2010 21:04:06 +0100 Subject: escape character / csv module In-Reply-To: References: Message-ID: <4C2CF4B6.7060909@mrabarnett.plus.com> V N wrote: > string "\x00" has a length of 1. When I use the csv module to write > that to a file > > csv_f = csv.writer(file("test.csv","wb"),delimiter="|") > csv_f.writerow(["\x00","zz"]) > > The output file looks like this: > |zz > > Is it possible to force the writer to write that string? It can write "\x01" but not "\x00", and "\x00ABC" doesn't write anything either. The csv module imports from _csv, which suggests to me that there's code written in C which thinks that the "\x00" is a NUL terminator, so it's a bug, although it's very unusual to want to write characters like "\x00" to a CSV file, and I wouldn't be surprised if this is the first time it's been noticed! :-) From luke.leighton at gmail.com Thu Jul 1 16:22:38 2010 From: luke.leighton at gmail.com (lkcl) Date: Thu, 1 Jul 2010 13:22:38 -0700 (PDT) Subject: python ctypes to int main(int argc, char *argv[]) Message-ID: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> hi, i need to convert an application (fontforge) to a python library. yes, libfontforge is already done as is libgdraw (fontforge-pygtk) but i need to make fontforge the _application_ a python application, using the same ctypes trick that's already done. my question is, therefore, how do i specify a ctypes wrapper around the standard int main(int argc, char *argv[]) which i am (obviously) going to move to a (new) c library? many thanks, l. From stefan_ml at behnel.de Thu Jul 1 17:13:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 01 Jul 2010 23:13:34 +0200 Subject: python ctypes to int main(int argc, char *argv[]) In-Reply-To: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> References: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> Message-ID: lkcl, 01.07.2010 22:22: > i need to convert an application (fontforge) to a python library. > yes, libfontforge is already done as is libgdraw (fontforge-pygtk) but > i need to make fontforge the _application_ a python application, using > the same ctypes trick that's already done. > > my question is, therefore, how do i specify a ctypes wrapper around > the standard int main(int argc, char *argv[]) which i am (obviously) > going to move to a (new) c library? Why don't you just start the program as an external subprocess? Stefan From snorble at hotmail.com Thu Jul 1 17:15:36 2010 From: snorble at hotmail.com (snorble) Date: Thu, 1 Jul 2010 14:15:36 -0700 (PDT) Subject: Packaging question Message-ID: <933a4734-eeff-4d99-89d7-3bbdf7094b1f@e5g2000yqn.googlegroups.com> My question is, why do the modules bar and foo show up in mypack's dir()? I intend for Foo (the class foo.Foo) and Bar (the class bar.Bar) to be there, but was not sure about the modules foo and bar. My big picture intention is to create smaller modules, but more of them (like I am used to doing with C++), and then use a package to organize the namespace so I'm not typing out excessively long names and making the code less readable. Is that a reasonable approach to developing Python programs? $ ls mypack/*.py bar.py foo.py __init__.py $ cat mypack/__init__.py from foo import Foo from bar import Bar $ python Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import mypack >>> dir(mypack) ['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'bar', 'foo'] >>> From egbertum at xs4all.nl Thu Jul 1 17:22:45 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 1 Jul 2010 23:22:45 +0200 Subject: List-type attributes and name strings In-Reply-To: <4c2c898e$0$20698$426a34cc@news.free.fr> References: <4c2c898e$0$20698$426a34cc@news.free.fr> Message-ID: <20100701212245.GA18915@xs4all.nl> On Thu, Jul 01, 2010 at 02:28:37PM +0200, Bruno Desthuilliers wrote: > Either I failed to understand you or you overlooked some other > problem in you code and jumped to the wrong conclusions. > In my problem the the name of the list or dict to mutate arrives in namestring, so I could not use the hard coding of attr1 and attr2 like you did. And because of a blind spot for getattr() I modified __dict__. Thanks to you, Chris and Lie it will not happen again, I promise. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From joshua.r.english at gmail.com Thu Jul 1 17:30:54 2010 From: joshua.r.english at gmail.com (Josh English) Date: Thu, 1 Jul 2010 14:30:54 -0700 (PDT) Subject: Namespace problem? Message-ID: I have a script that generates a report from a bunch of data I've been collecting for the past year. I ran the script, successfully, for several weeks on test runs and creating more detailed reports. Today (back from vacation) and the script doesn't work. It's giving me a name error. I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. Eventually we'll be upgraded top Windows 7.) Here is the reduced code: fws_first_col = 6 for student in range(32): if True: idx = fws_first_col for _month in range(12): idx += 2 fws_last_col = idx print fws_last_col I get: NameError: name 'fws_last_col' is not defined This snippet of code works on it's own, but not in the main script. I know it looks funny, but this should preserve the appropriate nesting of things. Where else could I look to find this problem? From mithrandiragainwiki at mailinator.com Thu Jul 1 17:36:57 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Thu, 1 Jul 2010 21:36:57 +0000 (UTC) Subject: Ignorance and Google Groups (again) References: <20100630165550.2b57855f.darcy@druid.net> Message-ID: Thomas Jollans wrote in news:mailman.55.1277936519.1673.python-list at python.org: > On 06/30/2010 10:55 PM, D'Arcy J.M. Cain wrote: >> in all it's glory. >> >> :0: Hir >> * ^List-Id:.*python-list.python.org >> * ^From:.*@gmail.com >> * ^Newsgroups: >> /dev/null > > * X-Complaints-To: groups-abuse at google.com > > looks like a nice header to filter on > Oops. Didn't see that you had already posted that idea. I'm sorry. :) But anyway, I had another idea (which hasn't already been mentioned.) ;) Since there are a good deal of "gems" in Google groups, and not all of them are spam artists, how about a whitelist/blacklist in the program? That way some posts from "good" people come through from G-Groups, and others (the "bad" ones) don't. Plus, the ones that you do blacklist would auto-generate a message to groups-abuse at google.com. That'll show 'em. :D Good luck! -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. >From the ashes a fire shall be woken, a light from the shadows shall spring; renenwed shall be blade that was broken, the crownless again shall be king." From mccredie at gmail.com Thu Jul 1 17:50:10 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 1 Jul 2010 21:50:10 +0000 (UTC) Subject: Namespace problem? References: Message-ID: Josh English gmail.com> writes: > > I have a script that generates a report from a bunch of data I've been > collecting for the past year. I ran the script, successfully, for > several weeks on test runs and creating more detailed reports. > > Today (back from vacation) and the script doesn't work. It's giving me > a name error. > > I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. > 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. > Eventually we'll be upgraded top Windows 7.) > > Here is the reduced code: > > fws_first_col = 6 > > for student in range(32): > > if True: > idx = fws_first_col > > for _month in range(12): > idx += 2 > fws_last_col = idx > > print fws_last_col > > I get: > > NameError: name 'fws_last_col' is not defined > > This snippet of code works on it's own, but not in the main script. That doesn't give me enough information to help you with the issue. In general you need to provide enough code to reproduce the failure, not some modified version that doesn't fail. My guess is that the "if True" is actually something else, and it isn't being interpreted as "True". As such, "fws_last_col" never gets assigned, and thus never gets created. You can fix that by assigning fws_last_col to an appropriate default value before the for loop. But what do I know, that is just a guess. Matt From jaykoni at yahoo.com Thu Jul 1 17:52:49 2010 From: jaykoni at yahoo.com (Jay) Date: Thu, 1 Jul 2010 14:52:49 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> Message-ID: <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> pywinauto looks to be almost perfect. All I need now is to read the numbers uncovered when a minesweeper square is clicked on, or that I just hit a mine. On Jun 30, 6:51?pm, Paul McGuire wrote: > On Jun 30, 6:39?pm, Jay wrote: > > > I would like to create a python script that plays the Windows game > > minesweeper. > > > The python code logic and running minesweeper are not problems. > > However, "seeing" the 1-8 in the minesweeper map and clicking on > > squares is. I have no idea how to proceed. > > You can interact with a Windows application using pywinauto (http:// > pywinauto.openqa.org/). > > Sounds like a fun little project - good luck! > > -- Paul From Paul Thu Jul 1 18:00:03 2010 From: Paul (Paul) Date: Thu, 01 Jul 2010 15:00:03 -0700 Subject: Python/C++ timer intermittent bug References: Message-ID: Thanks, Thomas. The answer to most of your questions is that I'm very new at this! I'm asking this on the forums you suggested. - Paul On Thu, 01 Jul 2010 19:23:53 +0200, Thomas Jollans wrote: >On 06/30/2010 09:28 PM, Paul at mail.python.org wrote: >> I have a problem with threading using the Python/C API. I have an >> extension that implements a timer, and the C++ timer callback function >> calls a Python function. The relevant code looks like this: >> >> [snip] >> >> static void CALLBACK PeriodicTimer(UINT wTimerID, UINT msg, >> DWORD dwUser, DWORD dw1, DWORD dw2) > >This looks frightfully WIN32. How are you calling a timer? I'm guessing >you're using some win32 function. So my tentative tip on where the >problem might lie is the interaction of Python's PyThreads and the win32 >threading primitives you're probably calling. > >> { >> PyGILState_STATE pgs; >> >> pgs = PyGILState_Ensure(); >> if(attrsetFlag) >> { >> pres = PyObject_CallFunction(attr,NULL); >> if( pres == NULL )printf("CallFunction failed!\n"); >> } >> PyGILState_Release( pgs ); >> >> } >> >> The Python code that sets this up looks like this: >> >> fetimer.setmodname("Timeslice3") >> fetimer.setprocname("Timetester") > >I'm sure this isn't the problem, but why aren't you just passing in an >object? As in fetimer.setcallable(Timeslice3.Timetester)? > >> [ snip ] >> >> Fatal Python Error: This thread state must be current when releasing >> >> Fatal Python Error: PyThreadState_DeleteCurrent: no current tstate >> >> Fatal Python Error: PyEval_SaveThread: NULL tstate > >As I said, I'd expect there to be some irregularities between what >PyThreads would normally do and what you're doing in the code you didn't >post. > >> >> Can anybody help me make this code stable, so that it works all the >> time? > >I can't really help you - I have limited experience with the C API, let >alone Python/C threading, and know next to nothing about Windows >programming. Maybe you should ask in a more specialized (and quieter) >forum, such as the CAPI-SIG mailing list, or python-win32. > >-- Thomas From aahz at pythoncraft.com Thu Jul 1 18:02:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 15:02:30 -0700 Subject: Python v3.1.2 documentation question References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> Message-ID: In article , Ethan Furman wrote: >Stephen Hansen wrote: >> On 6/29/10 10:01 AM, Ethan Furman wrote: >>> In the glossary section it states: >>> >>> >>> nested scope >>> >>> The ability to refer to a variable in an enclosing definition. For >>> instance, a function defined inside another function can refer to >>> variables in the outer function. Note that nested scopes work only for >>> reference and not for assignment which will always write to the >>> innermost scope. In contrast, local variables both read and write in the >>> innermost scope. Likewise, global variables read and write to the global >>> namespace. >>> >>> >>> Doesn't the nonlocal keyword make variables in outer scopes writable? >> >> Yes. I'd submit a doc bug. > >Bug submitted. For the benefit of people following along at home, it's nice to provide the URL to the ticket. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From lists at cheimes.de Thu Jul 1 18:05:33 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 02 Jul 2010 00:05:33 +0200 Subject: python ctypes to int main(int argc, char *argv[]) In-Reply-To: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> References: <237d8458-67e3-4d1a-be03-220ffc4af5d2@5g2000yqz.googlegroups.com> Message-ID: > my question is, therefore, how do i specify a ctypes wrapper around > the standard int main(int argc, char *argv[]) which i am (obviously) > going to move to a (new) c library? Maybe I missing something here but libraries don't have a main() function. The main() function is the entry point of a program. Libraries have different means for initialization. Christian From joshua.r.english at gmail.com Thu Jul 1 18:07:53 2010 From: joshua.r.english at gmail.com (Josh English) Date: Thu, 1 Jul 2010 15:07:53 -0700 (PDT) Subject: Namespace problem? References: Message-ID: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> On Jul 1, 2:50?pm, Matt McCredie wrote: > > That doesn't give me enough information to help you with the issue. In general > you need to provide enough code to reproduce the failure, not some modified > version that doesn't fail. My guess is that the "if True" is actually something > else, and it isn't being interpreted as "True". As such, "fws_last_col" never > gets assigned, and thus never gets created. You can fix that by assigning > fws_last_col to an appropriate default value before the for loop. But what do I > know, that is just a guess. > > Matt This is the code snippet with more context, but it isn't runnable without creating a bunch of dummy objects: # data is a dictionary. The keys are student names, the values are Tracker object. # The tracker class defines the method hasFWS() which returns a boolean. # _monthnumbers is a list: [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6] I just cut out the code that doesn't have anything to do the variable fws_last_col fws_first_col = 6 for student in sorted(data.keys() ): #~ print student tracker = data[student] if tracker.hasFWS(): idx = fws_first_col for _month in iter(_monthnumbers): idx += 2 fws_last_col = idx fws_month_count_col = idx + 4 fwsrow += 1 print fws_last_col From gabriele.lanaro at gmail.com Thu Jul 1 18:09:59 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Fri, 2 Jul 2010 00:09:59 +0200 Subject: [ANN]: Emacs For Python 0.1, collection of emacs extensions for python development Message-ID: Emacs For Python 0.1 Emacs for python (epy) is a collection of emacs extensions for python development, yet ready and configured for you. It includes also tweaks to commonly used extension to provide extra functionality and fast bug correction. There are also sane configuration that helps you getting started pretty fast. Some of the most important extensions configured and included in the distribution are: - ido prompts - autocompletion + rope (if you have pymacs) - snippets, simplified and standard-compliant - automatic error/warning/info highlighting with flymake (powered by pyflakes) - custom keybindings - much more (really) I remaind you for further information to the home page: http://gabrielelanaro.github.com/emacs-for-python/ You'll find additional information on the github page (readme and wiki): http://github.com/gabrielelanaro/emacs-for-python Thank you for the attention! - Gabriele -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Jul 1 18:25:54 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 01 Jul 2010 23:25:54 +0100 Subject: Namespace problem? In-Reply-To: References: Message-ID: On 01/07/2010 22:30, Josh English wrote: > I have a script that generates a report from a bunch of data I've been > collecting for the past year. I ran the script, successfully, for > several weeks on test runs and creating more detailed reports. > > Today (back from vacation) and the script doesn't work. It's giving me > a name error. > > I'm running python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v. > 1310 32 bit (Intel)]. (Upgrading is not a possibility right now. > Eventually we'll be upgraded top Windows 7.) > > Here is the reduced code: > > fws_first_col = 6 So fws_first_col is set to 6. > > for student in range(32): student isn't used in the snippet below. > > if True: Isn't this always going to run? > idx = fws_first_col Effectively set idx to 6 each time around the for loop. > > for _month in range(12): > idx += 2 Add 24 to idx each time around the for loop. 24 + 6 == 30. > fws_last_col = idx set fws_last_col to 30 each time around the for loop. > > > print fws_last_col prints 30 only once. > > I get: > > NameError: name 'fws_last_col' is not defined > > This snippet of code works on it's own, but not in the main script. I > know it looks funny, but this should preserve the appropriate nesting > of things. Certainly doesn't look at all correct to me. > > Where else could I look to find this problem? In a mirror? :) Kindest regards. Mark Lawrence. From rhodri at wildebst.demon.co.uk Thu Jul 1 18:30:33 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 01 Jul 2010 23:30:33 +0100 Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: On Thu, 01 Jul 2010 23:07:53 +0100, Josh English wrote: > On Jul 1, 2:50 pm, Matt McCredie wrote: >> >> My guess is that the "if True" is actually something >> else, and it isn't being interpreted as "True". As such, "fws_last_col" >> never >> gets assigned, and thus never gets created. You can fix that by >> assigning >> fws_last_col to an appropriate default value before the for loop. > [snip] > fws_first_col = 6 > > for student in sorted(data.keys() ): > #~ print student > > tracker = data[student] > > if tracker.hasFWS(): > > idx = fws_first_col > > > for _month in iter(_monthnumbers): > idx += 2 > fws_last_col = idx > > fws_month_count_col = idx + 4 > fwsrow += 1 > > print fws_last_col [I snipped the explanations for brevity] If this is a version of your code that actually fails when you run it (rather than being another artistic interpretation of a photograph of your code :-), then I'd go with Matt's analysis. This will give you a NameError for fws_last_col if tracker.hasFWS() happens to return False for all students. -- Rhodri James *-* Wildebeeste Herder to the Masses From emile at fenx.com Thu Jul 1 18:42:49 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 15:42:49 -0700 Subject: automate minesweeper with python In-Reply-To: <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 2:52 PM Jay said... > pywinauto looks to be almost perfect. All I need now is to read the > numbers uncovered when a minesweeper square is clicked on, or that I > just hit a mine. > ... or, you could always win... http://www.daniweb.com/forums/thread186209.html Emile PS -- in about '77 I worked with a guy that had XYZZY as his personalized license plate... From ethan at stoneleaf.us Thu Jul 1 18:42:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 01 Jul 2010 15:42:54 -0700 Subject: Python v3.1.2 documentation question In-Reply-To: References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> Message-ID: <4C2D19EE.6060602@stoneleaf.us> Aahz wrote: > In article , > Ethan Furman wrote: >> Stephen Hansen wrote: >>> On 6/29/10 10:01 AM, Ethan Furman wrote: >>>> In the glossary section it states: >>>> >>>> >>>> nested scope >>>> >>>> The ability to refer to a variable in an enclosing definition. For >>>> instance, a function defined inside another function can refer to >>>> variables in the outer function. Note that nested scopes work only for >>>> reference and not for assignment which will always write to the >>>> innermost scope. In contrast, local variables both read and write in the >>>> innermost scope. Likewise, global variables read and write to the global >>>> namespace. >>>> >>>> >>>> Doesn't the nonlocal keyword make variables in outer scopes writable? >>> Yes. I'd submit a doc bug. >> Bug submitted. > > For the benefit of people following along at home, it's nice to provide > the URL to the ticket. Hmmm.... Well, as this is my first ever bug post (yay! ;) I *think* this is what you want: http://bugs.python.org/issue9121 ~Ethan~ From clp2 at rebertia.com Thu Jul 1 19:07:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 16:07:07 -0700 Subject: Solutions for hand injury from computer use In-Reply-To: <20100701190033.15ceaeea@geekmail.INVALID> References: <4C2623FF.8040104@googlemail.com> <4c263bd6$1@dnews.tpgi.com.au> <4c26a841$0$14145$c3e8da3@news.astraweb.com> <4c2b3eb1$1@dnews.tpgi.com.au> <4c2baa6d$0$28647$c3e8da3@news.astraweb.com> <4c2bc59b$0$28671$c3e8da3@news.astraweb.com> <4c2bf810$0$14136$c3e8da3@news.astraweb.com> <87mxubj3m6.fsf@benfinney.id.au> <4c2c1df7$0$14136$c3e8da3@news.astraweb.com> <87eifniykk.fsf@benfinney.id.au> <87aaqbiviw.fsf_-_@benfinney.id.au> <20100701190033.15ceaeea@geekmail.INVALID> Message-ID: On Thu, Jul 1, 2010 at 10:00 AM, Andreas Waldenburger wrote: > On Thu, 01 Jul 2010 09:35:31 -0700 Ethan Furman > wrote: > >> I'll have to give the left-handed mouse a try... hmmm -- not too bad >> so far. > > Since we're on the subject: I find the best solution for "lots of > typing with a little mousing" to be a keyboard with a pointing stick > (or track point or nav stick or whatever people call it). The appropriate term varies: http://xkcd.com/243/ Cheers, Chris -- http://blog.rebertia.com From ppearson at nowhere.invalid Thu Jul 1 19:12:29 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 1 Jul 2010 23:12:29 GMT Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: <894lmtFeqU1@mid.individual.net> On Thu, 01 Jul 2010 23:30:33 +0100, Rhodri James wrote: > On Thu, 01 Jul 2010 23:07:53 +0100, Josh English > wrote: > >> On Jul 1, 2:50 pm, Matt McCredie wrote: >>> >>> My guess is that the "if True" is actually something >>> else, and it isn't being interpreted as "True". As such, "fws_last_col" >>> never >>> gets assigned, and thus never gets created. You can fix that by >>> assigning >>> fws_last_col to an appropriate default value before the for loop. >> > [snip] >> fws_first_col = 6 >> >> for student in sorted(data.keys() ): >> #~ print student >> >> tracker = data[student] >> >> if tracker.hasFWS(): >> >> idx = fws_first_col >> >> >> for _month in iter(_monthnumbers): >> idx += 2 >> fws_last_col = idx >> >> fws_month_count_col = idx + 4 >> fwsrow += 1 >> >> print fws_last_col > [suggests that hasFWS() is always False] Another possibility is that data.keys() is empty. -- To email me, substitute nowhere->spamcop, invalid->net. From ldo at geek-central.gen.new_zealand Thu Jul 1 19:47:00 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 02 Jul 2010 11:47 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Michael Torrie wrote: > On 06/29/2010 06:26 PM, Lawrence D'Oliveiro wrote: >>> I'm not sure you understood me correctly, because I advocate >>> *not* doing input sanitization. Hard or not -- I don't want to know, >>> because I don't want to do it. >> >> But no-one has yet managed to come up with an alternative that involves >> less work. > > Your case is still not persuasive. So persuade me. I have given an example of code written the way I do it. Now let?s see you rewrite it using your preferred technique, just to prove that your way is simpler and easier to understand. Enough hand-waving, let?s see some code! From ldo at geek-central.gen.new_zealand Thu Jul 1 19:50:59 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 02 Jul 2010 11:50:59 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: In message <4c2ccd9c$0$1643$742ec2ed at news.sonic.net>, John Nagle wrote: > The approach to arrays in C is just broken, for historical reasons. Nevertheless, it it at least self-consistent. To return to my original macro: #define Descr(v) &v, sizeof v As written, this works whatever the type of v: array, struct, whatever. > So parameter passing in C is very dumb. Nothing to do with the above issue. From aahz at pythoncraft.com Thu Jul 1 20:00:53 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Jul 2010 17:00:53 -0700 Subject: Python v3.1.2 documentation question References: <4C2A26D5.8090507@stoneleaf.us> Message-ID: In article , Ethan Furman wrote: >Aahz wrote: >> In article , >> Ethan Furman wrote: >>> Stephen Hansen wrote: >>>> On 6/29/10 10:01 AM, Ethan Furman wrote: >>>>> In the glossary section it states: >>>>> >>>>> >>>>> nested scope >>>>> >>>>> The ability to refer to a variable in an enclosing definition. For >>>>> instance, a function defined inside another function can refer to >>>>> variables in the outer function. Note that nested scopes work only for >>>>> reference and not for assignment which will always write to the >>>>> innermost scope. In contrast, local variables both read and write in the >>>>> innermost scope. Likewise, global variables read and write to the global >>>>> namespace. >>>>> >>>>> >>>>> Doesn't the nonlocal keyword make variables in outer scopes writable? >>>> Yes. I'd submit a doc bug. >>> Bug submitted. >> >> For the benefit of people following along at home, it's nice to provide >> the URL to the ticket. > >Hmmm.... Well, as this is my first ever bug post (yay! ;) I *think* >this is what you want: > >http://bugs.python.org/issue9121 Congrats! And it's already marked closed! ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From andre.roberge at gmail.com Thu Jul 1 20:20:29 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 1 Jul 2010 17:20:29 -0700 (PDT) Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: On Jul 1, 1:39?pm, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > Assuming it is the same behavior as for Komodo IDE, if you set it up so that linenumbers are shown, then you get a much larger target to click and select the line. Andr? > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 1 21:10:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 01:10:47 GMT Subject: Python dynamic attribute creation References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> On Thu, 01 Jul 2010 23:46:55 +0800, WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. There's nothing magic about metaprogramming. If you're a programmer, you write programs. Some of those programs will be programs about text ("programming"), programs about numbers ("programming"), programs about databases ("programming"), programs about staff performance data ("programming"), and programs about programs ("metaprogramming"). But it's still just programming, and there's nothing magical about it. Languages that try to frighten you away from metaprogramming are doing you a disservice. That's like teaching an electrical engineer how to make all sorts of devices, but not how to make voltmeters or ammeters because they're "meta-electronics". I'm pretty sure that IT is the only discipline that cares about this distinction between "normal work" and "meta work". Engineers are quite happy to make the tools they need to make the tools they need to make the tools they need to make something. Carpenters would think you were crazy if you said that building a scaffold was "meta-carpentry" and therefore "magic" and something to be avoided. There's even a children's song about the sort of loops you can get into when you need a tool X to fix some item Y, but you need Y in order to fix the tool first: http://www.songsforteaching.com/folk/theresaholeinthebucket.htm It's only in IT that "meta work" is considered "special", and that (I think) is because of the influence of academia. Don't get me wrong, I'm a big fan of academia, but I think sometimes they need a good dose of reality. Back before IT was a discipline, people used to write self-modifying code and programs to generate programs and other metaprogramming all the time, and nobody thought twice about it. Now admittedly, *some* metaprogramming techniques (like self-modifying code) make debugging much, much harder, and therefore should be avoided *for that reason*, but that's nothing to do with metaprogramming. If you write code with variables like: a1649264273528924 = a1649269279528924 + a1645976427328924 that's just "programming" but it's damn near impossible to efficiently debug too. -- Steven From tjreedy at udel.edu Thu Jul 1 21:17:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 21:17:27 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 6:42 PM, Emile van Sebille wrote: > On 7/1/2010 2:52 PM Jay said... >> pywinauto looks to be almost perfect. All I need now is to read the >> numbers uncovered when a minesweeper square is clicked on, or that I >> just hit a mine. >> > > ... or, you could always win... > > http://www.daniweb.com/forums/thread186209.html Did you actually try it? Though skeptical, I did, briefly, until I decided that it probably should have been dated April 1. There is no way to enter text into minesweeper, nor to make it full screen, nor, as far as I know, for it to toggle pixels outside its window. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jul 1 21:18:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 21:18:49 -0400 Subject: Composition of functions In-Reply-To: <4C2C49C0.5020900@ixokai.io> References: <4C2C49C0.5020900@ixokai.io> Message-ID: On 7/1/2010 3:54 AM, Stephen Hansen wrote: > On 7/1/10 12:45 AM, Terry Reedy wrote: >> On 7/1/2010 12:32 AM, Mladen Gogala wrote: >>> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote: >> >>>> However, you can easily get what you want by using the 'reversed' >>>> function (and similarly, the 'sorted' function), a la: >>>> >>>> >>> y = ''.join(reversed(list(x))) >>>> >>>> The 'reversed' and 'sorted' functions are generators that lazilly >>>> convert an iterable as needed. >>> >>> Ah, that is even better. Thanks. >> >> It is better if you do not mind making an unnecessary copy. If the list >> had 10 million elements, you might prefer your original. > > The original that did not work? :) The revised original that did work with sequential statements. -- Terry Jan Reedy From clp2 at rebertia.com Thu Jul 1 22:02:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 19:02:37 -0700 Subject: Python dynamic attribute creation In-Reply-To: <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> <4c2d3c97$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 6:10 PM, Steven D'Aprano wrote: > Engineers are quite > happy to make the tools they need to make the tools they need to make the > tools they need to make something. Carpenters would think you were crazy > if you said that building a scaffold was "meta-carpentry" and therefore > "magic" and something to be avoided. +1 QOTW Cheers, Chris From tjreedy at udel.edu Thu Jul 1 22:07:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Jul 2010 22:07:59 -0400 Subject: Python v3.1.2 documentation question In-Reply-To: <4C2D19EE.6060602@stoneleaf.us> References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> <4C2D19EE.6060602@stoneleaf.us> Message-ID: On 7/1/2010 6:42 PM, Ethan Furman wrote: > Hmmm.... Well, as this is my first ever bug post (yay! ;) Great! > I *think* this is what you want: > > http://bugs.python.org/issue9121 I believe Benjamin meant that it was already fixed in http://docs.python.org/dev/py3k/ which is currently the 3.2a0 docs. Good to check there before reporting a doc bug. Terry Jan Reedy From darcy at druid.net Thu Jul 1 22:10:08 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 1 Jul 2010 22:10:08 -0400 Subject: Ignorance and Google Groups (again) In-Reply-To: References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> Message-ID: <20100701221008.d673a9d8.darcy@druid.net> On Thu, 1 Jul 2010 21:34:15 +0300 Dotan Cohen wrote: > I'm one of them. Gmail is great for mailing lists, though I would > never use it as a personal email client. But I'm more of a lurker than > a poster on this list, so D'Arcy won't miss me anyway. As the song says. "How can I miss you if you won't go away." :-) As I explained, I don't block just because you are on gmail.com. I only block if you use Google Groups to post via news. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From emile at fenx.com Thu Jul 1 22:18:08 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 01 Jul 2010 19:18:08 -0700 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 6:17 PM Terry Reedy said... > On 7/1/2010 6:42 PM, Emile van Sebille wrote: >> On 7/1/2010 2:52 PM Jay said... >>> pywinauto looks to be almost perfect. All I need now is to read the >>> numbers uncovered when a minesweeper square is clicked on, or that I >>> just hit a mine. >>> >> >> ... or, you could always win... >> >> http://www.daniweb.com/forums/thread186209.html > > Did you actually try it? Though skeptical, I did, briefly, until I > decided that it probably should have been dated April 1. There is no way > to enter text into minesweeper, nor to make it full screen, nor, as far > as I know, for it to toggle pixels outside its window. > Yes. It works. Emile From rami.chowdhury at gmail.com Thu Jul 1 23:17:55 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 1 Jul 2010 20:17:55 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: <201007012017.56063.rami.chowdhury@gmail.com> On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > Nevertheless, it it at least self-consistent. To return to my original > macro: > > #define Descr(v) &v, sizeof v > > As written, this works whatever the type of v: array, struct, whatever. > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly modified... [rami at tigris ~]$ cat example.c #include #define Descr(v) &v, sizeof v int main(int argc, char ** argv) { char *buf = malloc(512 * sizeof(char)); const int a = 2, b = 3; snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b); fprintf(stdout, buf); free(buf); return 0; } /*main*/ [rami at tigris ~]$ clang example.c example.c:11:18: warning: incompatible pointer types passing 'char **', expected 'char *' [-pedantic] snprintf(Descr(buf), "%d + %d = %d\n", a, b, a + b); ^~~~~~~~~~ example.c:4:18: note: instantiated from: #define Descr(v) &v, sizeof v ^~~~~~~~~~~~ <> [rami at tigris ~]$ ./a.out Segmentation fault ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 00:11:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 04:11:49 GMT Subject: Why defaultdict? Message-ID: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> I would like to better understand some of the design choices made in collections.defaultdict. Firstly, to initialise a defaultdict, you do this: from collections import defaultdict d = defaultdict(callable, *args) which sets an attribute of d "default_factory" which is called on key lookups when the key is missing. If callable is None, defaultdicts are *exactly* equivalent to built-in dicts, so I wonder why the API wasn't added on to dict rather than a separate class that needed to be imported. That is: d = dict(*args) d.default_factory = callable If you failed to explicitly set the dict's default_factory, it would behave precisely as dicts do now. So why create a new class that needs to be imported, rather than just add the functionality to dict? Is it just an aesthetic choice to support passing the factory function as the first argument? I would think that the advantage of having it built- in would far outweigh the cost of an explicit attribute assignment. Second, why is the factory function not called with key? There are three obvious kinds of "default values" a dict might want, in order of more-to- less general: (1) The default value depends on the key in some way: return factory(key) (2) The default value doesn't depend on the key: return factory() (3) The default value is a constant: return C defaultdict supports (2) and (3): defaultdict(factory, *args) defaultdict(lambda: C, *args) but it doesn't support (1). If key were passed to the factory function, it would be easy to support all three use-cases, at the cost of a slightly more complex factory function. E.g. the current idiom: defaultdict(factory, *args) would become: defaultdict(lambda key: factory(), *args) (There is a zeroth case as well, where the default value depends on the key and what else is in the dict: factory(d, key). But I suspect that's well and truly YAGNI territory.) Thanks in advance, -- Steven From jdoe at usenetlove.invalid Fri Jul 2 00:34:12 2010 From: jdoe at usenetlove.invalid (John Doe) Date: 02 Jul 2010 04:34:12 GMT Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <4c2d6c43$0$17900$c3e8da3@news.astraweb.com> Andr? wrote: > ... set it up so that linenumbers are shown, then you get a much > larger target to click and select the line. Yes... And it allows clicking and dragging the number area to select multiple lines. Thanks. From clp2 at rebertia.com Fri Jul 2 00:37:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 21:37:31 -0700 Subject: Why defaultdict? In-Reply-To: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 1, 2010 at 9:11 PM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. Perhaps python-dev should've been CC-ed... > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = defaultdict(callable, *args) > > which sets an attribute of d "default_factory" which is called on key > lookups when the key is missing. If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. > That is: > > d = dict(*args) > d.default_factory = callable > > If you failed to explicitly set the dict's default_factory, it would > behave precisely as dicts do now. So why create a new class that needs to > be imported, rather than just add the functionality to dict? Don't know personally, but here's one thought: If it was done that way, passing around a dict could result in it getting a default_factory set where there wasn't one before, which could lead to strange results if you weren't anticipating that. The defaultdict solution avoids this. > Second, why is the factory function not called with key? Agree, I've never understood this. Ruby's Hash::new does it better (http://ruby-doc.org/core/classes/Hash.html), and even supports your case 0; it calls the equivalent of default_factory(d, key) when generating a default value. > There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C > > defaultdict supports (2) and (3): > > defaultdict(factory, *args) > defaultdict(lambda: C, *args) > > but it doesn't support (1). If key were passed to the factory function, > it would be easy to support all three use-cases, at the cost of a > slightly more complex factory function. > (There is a zeroth case as well, where the default value depends on the > key and what else is in the dict: factory(d, key). But I suspect that's > well and truly YAGNI territory.) Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Fri Jul 2 00:50:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 21:50:49 -0700 Subject: Is there a reference manual for "pyparsing"? Message-ID: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Is there a reference manual for "pyparsing"? Not a tutorial. Not a wiki. Not a set of examples. Not a "getting started guide". Something that actually documents what each primitive does? John Nagle From clp2 at rebertia.com Fri Jul 2 01:02:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 22:02:35 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: <4c2d7037$0$1600$742ec2ed@news.sonic.net> References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 1, 2010 at 9:50 PM, John Nagle wrote: > ?Is there a reference manual for "pyparsing"? ?Not a tutorial. ?Not a wiki. > Not a set of examples. ?Not a "getting started guide". > Something that actually documents what each primitive does? http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 ? Cheers, Chris -- http://blog.rebertia.com From raymond.hettinger at gmail.com Fri Jul 2 01:06:42 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Thu, 1 Jul 2010 22:06:42 -0700 (PDT) Subject: Why defaultdict? References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <2f533b05-aa00-40c3-9be3-8a14434e2f74@m17g2000prl.googlegroups.com> On Jul 1, 9:11?pm, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. . . . > If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. . . . > Second, why is the factory function not called with key? There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C The __missing__() magic method lets you provide a factory with a key. That method is supported by dict subclasses, making it easy to create almost any desired behavior. A defaultdict is an example. It is a dict subclass that calls a zero argument factory function. But with __missing__() can roll your own dict subclass to meet your other needs. A defaultdict was provided to meet one commonly requested set of use cases (mostly ones using int() and list() as factory functions). >From the docs at http://docs.python.org/library/stdtypes.html#mapping-types-dict : '''New in version 2.5: If a subclass of dict defines a method __missing__(), if the key key is not present, the d[key] operation calls that method with the key key as argument. The d[key] operation then returns or raises whatever is returned or raised by the __missing__(key) call if the key is not present. No other operations or methods invoke __missing__(). If __missing__() is not defined, KeyError is raised. __missing__() must be a method; it cannot be an instance variable. For an example, see collections.defaultdict.''' Raymond From nagle at animats.com Fri Jul 2 01:08:18 2010 From: nagle at animats.com (John Nagle) Date: Thu, 01 Jul 2010 22:08:18 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c2d7450$0$1665$742ec2ed@news.sonic.net> On 7/1/2010 10:02 PM, Chris Rebert wrote: > On Thu, Jul 1, 2010 at 9:50 PM, John Nagle wrote: >> Is there a reference manual for "pyparsing"? Not a tutorial. Not a wiki. >> Not a set of examples. Not a "getting started guide". >> Something that actually documents what each primitive does? > > http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 > ? > That's a big help. Thanks. Perhaps the page "http://pyparsing.wikispaces.com/Documentation" should mention that. Because it's in Subversion, Google can't find that page. (robots.txt: User-agent: * Disallow: /) John Nagle From clp2 at rebertia.com Fri Jul 2 01:17:15 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Jul 2010 22:17:15 -0700 Subject: Is there a reference manual for "pyparsing"? In-Reply-To: <4c2d7450$0$1665$742ec2ed@news.sonic.net> References: <4c2d7037$0$1600$742ec2ed@news.sonic.net> <4c2d7450$0$1665$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 1, 2010 at 10:08 PM, John Nagle wrote: > On 7/1/2010 10:02 PM, Chris Rebert wrote: >> On Thu, Jul 1, 2010 at 9:50 PM, John Nagle ?wrote: >>> ?Is there a reference manual for "pyparsing"? ?Not a tutorial. ?Not a >>> wiki. >>> Not a set of examples. ?Not a "getting started guide". >>> Something that actually documents what each primitive does? >> >> http://pyparsing.svn.sourceforge.net/viewvc/pyparsing/src/HowToUsePyparsing.html?revision=200 >> ? >> > > ? ?That's a big help. ?Thanks. > > ? ?Perhaps the page "http://pyparsing.wikispaces.com/Documentation" > should mention that. Well, it does, indirectly: "Pyparsing ships with class diagrams and html documentation." But yeah, hyperlinks are always good. Cheers, Chris -- http://blog.rebertia.com From stephen.mc at gmail.com Fri Jul 2 01:45:09 2010 From: stephen.mc at gmail.com (Steve) Date: Thu, 1 Jul 2010 22:45:09 -0700 (PDT) Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? References: Message-ID: <2ef9965e-d6cd-4fe8-8155-45488124ff58@l25g2000prn.googlegroups.com> On Jul 2, 4:48?am, pyt... at bdurham.com wrote: > Curious if any of you are using GPG or PGP encryption and/or signatures > in your Python apps? > > In particular are you: > > 1. clearsigning specific emails? > 2. validating clearsigned emails from others? > 3. encrypting/decrypting files? > 4. generating signatures for files that you are exchanging/posting for > download? > 5. what public keyring services are you using? > > I'm also looking for recommendations on which 3rd party modules you're > using for these tasks? In particular is there a particular module you > prefer or have concerns about? > > Here's my short list of modules that *might* support encryption and > signing in general: > > - m2crypto > - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) > - tlslite > - pyme > - evpy > - python-gnupg (by developer of Python's logging module) > > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). > > Thank you, > Malcolm I used python-gnupg successfully to create some Django utilities for sending encrypted email. You can grab the source code at http://github.com/stephenmcd/django-email-extras Cheers, Steve From ian.g.kelly at gmail.com Fri Jul 2 02:09:53 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 2 Jul 2010 00:09:53 -0600 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On Thu, Jul 1, 2010 at 7:17 PM, Terry Reedy wrote: > Did you actually try it? Though skeptical, I did, briefly, until I decided > that it probably should have been dated April 1. There is no way to enter > text into minesweeper, nor to make it full screen, nor, as far as I know, > for it to toggle pixels outside its window. Your objections are invalid. The fact that Minesweeper does not have a text control does not mean that it cannot receive keypresses, and the exterior pixel could hypothetically be implemented as a 1-pixel borderless window belonging to the Minesweeper application. There are enough details from enough different persons on the web, with few if any dissenting opinions, that I'm inclined to believe it probably works. I can't test it myself, though, because it apparently no longer works in Windows Vista or 7, and I no longer have an XP box around. From dave.pawson at gmail.com Fri Jul 2 02:26:44 2010 From: dave.pawson at gmail.com (Dave Pawson) Date: Fri, 2 Jul 2010 07:26:44 +0100 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: Message-ID: I'm the OP btw. On 1 July 2010 18:10, Dennis Lee Bieber wrote: >> I think that Python "could" be a alternative to bash and have some >> advantages, but it's a long way off from being fully implemented. > > ? ? ? ?While a somewhat klutzier language in aspects (the , is both an > parameter separator, AND the continued line indicator, leading to lines > that end in , ,) I'd consider a decent* REXX implementation first... > ? ? ? ?Any program line that is not recognized as starting a REXX statement > is automatically passed to the currently defined command processor. And > one could ensure this by just quoting the first word on the line Useful. However, I know Python, never looked at Rexx, so not much use to me. Tks -- Dave Pawson XSLT XSL-FO FAQ. Docbook FAQ. http://www.dpawson.co.uk From marky1991 at gmail.com Fri Jul 2 03:32:56 2010 From: marky1991 at gmail.com (Mark Young) Date: Fri, 2 Jul 2010 03:32:56 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: Just tested it in XP, it works. -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Fri Jul 2 03:39:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 2 Jul 2010 00:39:12 -0700 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: <1278010127.6605.1382869273@webmail.messagingengine.com> References: <1278010127.6605.1382869273@webmail.messagingengine.com> Message-ID: On Thu, Jul 1, 2010 at 11:48 AM, wrote: > Curious if any of you are using GPG or PGP encryption and/or signatures > in your Python apps? Yes; disclaimer: I'm the author of evpy and am currently working on a openssl wrapper proposed for inclusion in the stdlib. > In particular are you: > > 1. clearsigning specific emails? Yes; I use python-gnupg. > 2. validating clearsigned emails from others? Yes, see above. > 3. encrypting/decrypting files? Yes, I use evpy. > 4. generating signatures for files that you are exchanging/posting for > download? Yes, evpy again. > 5. what public keyring services are you using? Can't comment on this as I don't use them. > I'm also looking for recommendations on which 3rd party modules you're > using for these tasks? In particular is there a particular module you > prefer or have concerns about? Obviously I'm biased towards evpy, but I'm a really, really big fan of people not rolling their own crypto. It sounds like for most of what you want to do gpg or python-gnupg are pretty good options. > Here's my short list of modules that *might* support encryption and > signing in general: > > - m2crypto Supports encryption and signing; a high quality library with much to recommend it, assuming you need the full power of openssl and are able to use SWIG'd software. I think you probably have easier to use alternatives here, though. > - pycrypto (standalone or with expycrypto or yawpycrypto wrappers) pycrypto is a good library as far as it goes, but I see a lot of nonexperts do things very badly with it, and AFAICS it hasn't seen the same level of scrutiny that something like openssl has, especially WRT side channel cryptanalysis. That's very worrying. > - tlslite > - pyme no experience here, can't comment. > - evpy I like it ;). It supports encryption (public and private key) as well as signing and verification routines, and as long as you know your threat model it's reasonably hard to screw up. Having said that, it doesn't do anything with the web of trust or key revocation etc OOTB, so if what you're really looking for is gpg in python, use the right tool for the job. > - python-gnupg (by developer of Python's logging module) I use it and like it for the reasons above. > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). Seems fine, just make sure you know and trust where your keys are going. Geremy Condra From mail at timgolden.me.uk Fri Jul 2 03:46:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 02 Jul 2010 08:46:36 +0100 Subject: Bento 0.0.3 (ex-toydist), a pythonic packaging solution In-Reply-To: <4C2D5135.5010909@silveregg.co.jp> References: <4C2D5135.5010909@silveregg.co.jp> Message-ID: <4C2D995C.40209@timgolden.me.uk> On 02/07/2010 03:38, David wrote: > I am pleased to announce the release 0.0.3 for Bento, the pythonic > packaging solution. > > Bento aims at being an alternative to distutils/setuptools/distribute, > based on a static metadata file format. Existing packages can be > converted from setup.py to bento format automatically. > > http://cournape.github.com/Bento/ Looks very interesting. Just one thing (which might just be me): the front page looks very stylish and is quite a nice summary. But I actually *missed* the (grey on grey) [Take me to Bento documentation] button, which is way below the fold on my screen. Rather, I hit the more evident Github flag at the top and started looking for docs there! Just in case it helps anyone else... TJG From one50123164ef19 at getonemail.com Fri Jul 2 04:06:21 2010 From: one50123164ef19 at getonemail.com (Maciej) Date: Fri, 2 Jul 2010 01:06:21 -0700 (PDT) Subject: GAE + recursion limit Message-ID: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Hi, I'm writing a small translator using pyparsing library v1.5.2 (http://pyparsing.wikispaces.com/) and I'm using it both from command line and on Google App Engine. Recently I checked one of my samples which runs perfect from CLI against GAE and it throws me "RuntimeError 'maximum recursion depth exceeded'". I did some investigation and found out that recursion limit is the same locally and inside GA (1000). I've also tested it locally decreasing this limit to 900 but the error didn't happen. The problem itself rises inside pyparsing lib, line 995. Does anyone have any clue what that might be? Why the problem is on GAE (even when run locally), when command line run works just fine (even with recursion limit decreased)? Thanks in advance for any help. Soltys From __peter__ at web.de Fri Jul 2 04:22:31 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Jul 2010 10:22:31 +0200 Subject: Packaging question References: <933a4734-eeff-4d99-89d7-3bbdf7094b1f@e5g2000yqn.googlegroups.com> Message-ID: snorble wrote: > My question is, why do the modules bar and foo show up in mypack's > dir()? I intend for Foo (the class foo.Foo) and Bar (the class > bar.Bar) to be there, but was not sure about the modules foo and bar. > $ ls mypack/*.py > bar.py > foo.py > __init__.py > > $ cat mypack/__init__.py > from foo import Foo > from bar import Bar > > $ python > Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import mypack >>>> dir(mypack) > ['Bar', 'Foo', '__builtins__', '__doc__', '__file__', '__name__', > '__package__', '__path__', 'bar', 'foo'] How is Python to know that you won't perform an import mypack.foo afterwards? After this statement foo must be an attribute of mypack. But when mypack.foo has been imported before this just performs mypack = sys.modules["mypack"] If the foo attribute weren't added by from foo import Foo the caching mechanism would not work. While import mypack.foo might also have been implemented as mypack = sys.modules["mypack"] if not hasattr(mypack", "foo"): mypack.foo = sys.modules["mypack.foo"] I think that would have been a solution to a non-problem. If you're sure you don't need to access mypack.foo directly you can add del foo to mypack/__init__.py, but don't complain when you get bitten by >>> import mypack.foo >>> mypack.foo Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'foo' > My big picture intention is to create smaller modules, but more of > them (like I am used to doing with C++), and then use a package to > organize the namespace so I'm not typing out excessively long names > and making the code less readable. Is that a reasonable approach to > developing Python programs? I like to put related classes and functions into a single file. As a rule of thumb, when a class needs a file of its own the class is too big... Peter From greg.ewing at canterbury.ac.nz Fri Jul 2 04:41:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 20:41:03 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <895mfgFje6U1@mid.individual.net> WANG Cong wrote: > If you think setattr() is as ordinary as a trivial assignment, I will > argue with you, this is personal taste. To my way of thinking, getattr() and setattr() are the fundamental way of accessing attributes in Python. The dot notation is just syntactic sugar for the overwhelmingly common case of a static attribute name. So the dot-notation is more "ordinary" in the sense of being more commonly used, but not in the sense of being a simpler operation. Both are doing exactly the same thing underneath. -- Greg From syockit at gmail.com Fri Jul 2 04:44:02 2010 From: syockit at gmail.com (syockit) Date: Fri, 2 Jul 2010 01:44:02 -0700 (PDT) Subject: Pool Module: iterator does not yield consistently with different chunksizes Message-ID: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> I've been playing around with custom iterators to map into Pool. When I run the code below: def arif(arr): return arr def permutate(n): k = 0 a = list(range(6)) while k References: Message-ID: <895n87FnsoU1@mid.individual.net> WANG Cong wrote: > Yeah, my point is why setattr() for dynamic attributes while assignments > for static attributes? I think there may be a misunderstanding here. You seem to be thinking of "dynamic attribute" vs. "static attribute" as the distinction between creating a new attribute and modifying an existing one. But that's not what it means in this context -- "dynamic" just means that the attribute name is being computed rather than written into the program. In either case, the attribute may or may not be pre-existing. > Why not unify them? If you mean using exactly the same syntax for both, that would require making the static case more verbose, e.g. instead of foo.blarg you would have to write something like foo.("blarg") just to allow for the possibility of writing foo.(some_arbitrary_expression) If you keep the existing static-attribute syntax, then you haven't really unified anything, you've just added a new syntax for dynamic attributes. And because dynamic attribute access is extremely rare, it's not considered worth having a special syntax for it. It's been suggested before, and rejected on those grounds. -- Greg From cournape at gmail.com Fri Jul 2 05:00:17 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 2 Jul 2010 18:00:17 +0900 Subject: Bento 0.0.3 (ex-toydist), a pythonic packaging solution In-Reply-To: <4C2D995C.40209@timgolden.me.uk> References: <4C2D5135.5010909@silveregg.co.jp> <4C2D995C.40209@timgolden.me.uk> Message-ID: On Fri, Jul 2, 2010 at 4:46 PM, Tim Golden wrote: > > Looks very interesting. Just one thing (which might just be me): > the front page looks very stylish and is quite a nice summary. > But I actually *missed* the (grey on grey) [Take me to Bento documentation] > button, which is way below the fold on my screen. Rather, I hit the > more evident Github flag at the top and started looking for docs there! Good point, I will think about a better way to display this, thanks, David From cournape at gmail.com Fri Jul 2 05:02:12 2010 From: cournape at gmail.com (David Cournapeau) Date: Fri, 2 Jul 2010 18:02:12 +0900 Subject: GAE + recursion limit In-Reply-To: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Message-ID: On Fri, Jul 2, 2010 at 5:06 PM, Maciej wrote: > Does anyone have any clue what that might be? > Why the problem is on GAE (even when run locally), when command line > run works just fine (even with recursion limit decreased)? > Thanks in advance for any help. Most likely google runs a customized python, with different settings to avoid requests to take too long. I doubt there is much you can do for this problem, but you should ask on GAE group. David From greg.ewing at canterbury.ac.nz Fri Jul 2 05:07:39 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 21:07:39 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> Message-ID: <895o1cFsajU1@mid.individual.net> WANG Cong wrote: > When I talked about OOP, it is general OOP, not related with > any concrete programming languages. There isn't really any such thing, though. There is no universally agreed set of features that a language must have in order to be considered OOP. Arguments of the form "Language L isn't really OOP because it doesn't have feature F" don't wash with anyone who has studied a sufficiently wide variety of languages. Every OOP language has its own take on what it means to be OOP, and none of them is any more correct about it than another. -- Greg From thomas at jollans.com Fri Jul 2 05:20:48 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 11:20:48 +0200 Subject: Why defaultdict? In-Reply-To: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2DAF70.8000808@jollans.com> On 07/02/2010 06:11 AM, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. > > Firstly, to initialise a defaultdict, you do this: > > from collections import defaultdict > d = defaultdict(callable, *args) > > which sets an attribute of d "default_factory" which is called on key > lookups when the key is missing. If callable is None, defaultdicts are > *exactly* equivalent to built-in dicts, so I wonder why the API wasn't > added on to dict rather than a separate class that needed to be imported. > That is: > > d = dict(*args) > d.default_factory = callable That's just not what dicts, a very simple and elementary data type, do. I know this isn't really a good reason. In addition to what Chris said, I expect this would complicate the dict code a great deal. > > If you failed to explicitly set the dict's default_factory, it would > behave precisely as dicts do now. So why create a new class that needs to > be imported, rather than just add the functionality to dict? > > Is it just an aesthetic choice to support passing the factory function as > the first argument? I would think that the advantage of having it built- > in would far outweigh the cost of an explicit attribute assignment. > The cost of this feature would be over-complication of the built-in dict type when a subclass would do just as well > > > Second, why is the factory function not called with key? There are three > obvious kinds of "default values" a dict might want, in order of more-to- > less general: > > (1) The default value depends on the key in some way: return factory(key) I agree, this is a strange choice. However, nothing's stopping you from being a bit verbose about what you want and just doing it: class mydict(defaultdict): def __missing__(self, key): # ... the __missing__ method is really the more useful bit the defaultdict class adds, by the looks of it. -- Thomas > (2) The default value doesn't depend on the key: return factory() > (3) The default value is a constant: return C > > defaultdict supports (2) and (3): > > defaultdict(factory, *args) > defaultdict(lambda: C, *args) > > but it doesn't support (1). If key were passed to the factory function, > it would be easy to support all three use-cases, at the cost of a > slightly more complex factory function. E.g. the current idiom: > > defaultdict(factory, *args) > > would become: > > defaultdict(lambda key: factory(), *args) > > > (There is a zeroth case as well, where the default value depends on the > key and what else is in the dict: factory(d, key). But I suspect that's > well and truly YAGNI territory.) From clp2 at rebertia.com Fri Jul 2 05:26:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Jul 2010 02:26:23 -0700 Subject: Why defaultdict? In-Reply-To: <4C2DAF70.8000808@jollans.com> References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> <4C2DAF70.8000808@jollans.com> Message-ID: On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: > On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >> I would like to better understand some of the design choices made in >> collections.defaultdict. >> Second, why is the factory function not called with key? There are three >> obvious kinds of "default values" a dict might want, in order of more-to- >> less general: >> >> (1) The default value depends on the key in some way: return factory(key) > > I agree, this is a strange choice. However, nothing's stopping you from > being a bit verbose about what you want and just doing it: > > class mydict(defaultdict): > ? ?def __missing__(self, key): > ? ? ? ?# ... > > the __missing__ method is really the more useful bit the defaultdict > class adds, by the looks of it. Nitpick: You only need to subclass dict, not defaultdict, to use __missing__(). See the part of the docs Raymond Hettinger quoted. Cheers, Chris From thomas at jollans.com Fri Jul 2 05:32:09 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 11:32:09 +0200 Subject: Why defaultdict? In-Reply-To: References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> <4C2DAF70.8000808@jollans.com> Message-ID: <4C2DB219.6010806@jollans.com> On 07/02/2010 11:26 AM, Chris Rebert wrote: > On Fri, Jul 2, 2010 at 2:20 AM, Thomas Jollans wrote: >> On 07/02/2010 06:11 AM, Steven D'Aprano wrote: >>> I would like to better understand some of the design choices made in >>> collections.defaultdict. > >>> Second, why is the factory function not called with key? There are three >>> obvious kinds of "default values" a dict might want, in order of more-to- >>> less general: >>> >>> (1) The default value depends on the key in some way: return factory(key) >> >> I agree, this is a strange choice. However, nothing's stopping you from >> being a bit verbose about what you want and just doing it: >> >> class mydict(defaultdict): >> def __missing__(self, key): >> # ... >> >> the __missing__ method is really the more useful bit the defaultdict >> class adds, by the looks of it. > > Nitpick: You only need to subclass dict, not defaultdict, to use > __missing__(). See the part of the docs Raymond Hettinger quoted. > Sorry Raymond, I didn't see you. This is where I cancel my "filter out google groups users" experiment. From greg.ewing at canterbury.ac.nz Fri Jul 2 05:42:53 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 02 Jul 2010 21:42:53 +1200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <895q3eF8oaU1@mid.individual.net> WANG Cong wrote: > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. But, in Python, creating instance variables is *not* class-programming. It doesn't touch the class at all. In many OO languages, such as Simula, C++ and Java, one of the responsibilities of a class is to define what attributes its instances have. However, that really comes about because those languages are statically typed -- it's not an essential principle of OO at all. In Python, restricting what attributes an object can have is *not* considered to be a responsibility of the class. The class is just a convenient place to put stuff (mostly methods) that some bunch of objects all need to have. Anything beyond that is up to the objects themselves. It so happens that, in most Python programs, all the instances of a given class will usually have a well- defined set of attributes. But Python doesn't go out of its way to enforce that. This is just a part of Python's general philosophy of not requiring declarations. There are very few declarative constructs in Python -- even class and function definitions are executable statements that construct data structures at run time. The only true declarations are the 'global' and 'nonlocal' statements, and they only exist because without them there would be no way to achieve certain things. They are not there to enforce any kind of static check. Why does Python not require declarations? Because it makes code easier and faster to develop. Instead of having to spend time and effort writing declarations, you just get straight on and write the code that does the actual work. And if you change your mind and need to move things around, you don't have to perform extra work to keep the declarations up to date. This can be a big help in the early stages of development, when you're feeling your way and the design is fluid. It also makes the program easier to extend and modify later. The downside is that certain kinds of error, that would be caught at compile time in a more static language, don't show up until you run the program. But if you're testing properly -- which you need to do anyway, whatever language you're using -- they usually show up pretty soon, and aren't much harder to fix when they do. Experience has shown that the overall process -- design, programming, testing and debugging -- tends to be faster using a dynamic, fluid language such as Python, than a static one such as C++ or Java. And, many people would say, more fun as well -- which is a good enough reason on its own for using Python! -- Greg From bruno.42.desthuilliers at websiteburo.invalid Fri Jul 2 05:59:20 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 02 Jul 2010 11:59:20 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: <2dedca00-fb21-403e-a21c-b6fb33b08daa@i28g2000yqa.googlegroups.com> <4C262477.6070100@web.de> <4c26a41e$0$14145$c3e8da3@news.astraweb.com> Message-ID: <4c2db80c$0$30015$426a74cc@news.free.fr> WANG Cong a ?crit : > On 07/01/10 23:19, Stephen Hansen wrote: > >>> As long as setattr() exists in Python, that will be not so ordinary. :) >> setattr is perfectly ordinary. > > If you think setattr() is as ordinary as a trivial assignment, setattr IS a trivial assignment. > > However, I think setattr() is a builtin function, using it exposes the > *magic* of metaprogramming (or class-programming, if more correct) at a > first glance. No "magic" and no "meta"whatever involved. setattr is as simple as: def setattr(obj, name, value): obj.__setattribute__(name, value) which is *exactly* what gets called when you use the binding statement form ie "obj.someattr = value" which FWIW is just syntactic sugar for the former (just like the 'class' statement is just syntactic sugar for a call to type, etc). I fail to understand why you insist on seeing something as trivial as "magic", "metaprogramming" or whatever. From bruno.42.desthuilliers at websiteburo.invalid Fri Jul 2 06:05:31 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 02 Jul 2010 12:05:31 +0200 Subject: Python dynamic attribute creation In-Reply-To: References: Message-ID: <4c2db97f$0$27941$426a34cc@news.free.fr> WANG Cong a ?crit : > On 06/30/10 01:25, Ethan Furman wrote: > >>> But if so why setattr() still exists? What is it for if we can do the >>> same thing via assignments? Also, in order to be perfect, Python should >>> accept to add dynamic attributes dynamically, something like PEP >>> 363. That doesn't happen. >> Setattr and friends exist to work with dynamic attributes. >> > > Yeah, my point is why setattr() for dynamic attributes while assignments > for static attributes? Why not unify them? What is a "dynamic" and what is a "static" attribute ???? > Agreed, but at least, the reason why I am being against so many people > here is also trying to make Python be more perfect with my > understanding. Please start with learning Python's execution model (what exactly happens at runtime, what most statement are syntactic sugar for etc) and Python's object model (how are Python objects, classes, methods etc implemented, attributes lookup rules, metaclasses, descriptors etc). Then PERHAPS you MIGHT have a chance to help making Python "more perfect". From macosx at rocteur.cc Fri Jul 2 06:07:51 2010 From: macosx at rocteur.cc (Jerry Rocteur) Date: Fri, 2 Jul 2010 12:07:51 +0200 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: Message-ID: <20100702100751.GA5284@incc-g5.local> * Dave Pawson [2010-07-02 08:22]: > I'm the OP btw. > > On 1 July 2010 18:10, Dennis Lee Bieber wrote: > > >> I think that Python "could" be a alternative to bash and have some > >> advantages, but it's a long way off from being fully implemented. > > Take a look at Python for Unix and Linux System Administration: http://www.amazon.com/Python-Unix-Linux-System-Administration/dp/0596515820 I quite like the book, I learned about Ipython from this book and I'm quite glad I did! Jerry From stef.mientki at gmail.com Fri Jul 2 06:15:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 02 Jul 2010 12:15:48 +0200 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: References: <1278010127.6605.1382869273@webmail.messagingengine.com> Message-ID: <4C2DBC54.7090004@gmail.com> On 02-07-2010 09:39, geremy condra wrote: > On Thu, Jul 1, 2010 at 11:48 AM, wrote: >> Curious if any of you are using GPG or PGP encryption and/or signatures >> in your Python apps? > Yes; disclaimer: I'm the author of evpy and am currently working on a > openssl wrapper proposed for inclusion in the stdlib. Great Geremy !, but it's difficult to find, and I couldn't find any documentation. Did I not look at the right places ? thanks Stef Mientki From __peter__ at web.de Fri Jul 2 06:22:17 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Jul 2010 12:22:17 +0200 Subject: Pool Module: iterator does not yield consistently with different chunksizes References: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> Message-ID: syockit wrote: > I've been playing around with custom iterators to map into Pool. When > I run the code below: > > def arif(arr): > return arr > > def permutate(n): > k = 0 > a = list(range(6)) > while k for i in range(6): > a.insert(0, a.pop(5)+6) > #yield a[:] <-- produces correct results > yield a > k += 1 > return > > def main(): > from multiprocessing import Pool > pool = Pool() > chksize = 15 > for x in pool.imap_unordered(arif, permutate(100), chksize): > print(x) > > if __name__=="__main__": > main() > > .... will output something like this: > > > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [144, 145, 146, 147, 148, 149] > > ... where results are duplicated number of times equal to chunk size, > and the results between the gap are lost. Using a[:] instead, i get: > > [6, 7, 8, 9, 10, 11] > [12, 13, 14, 15, 16, 17] > [18, 19, 20, 21, 22, 23] > [24, 25, 26, 27, 28, 29] > [30, 31, 32, 33, 34, 35] > [36, 37, 38, 39, 40, 41] > [42, 43, 44, 45, 46, 47] > [48, 49, 50, 51, 52, 53] > > .... it comes out okay. Any explanation for such behavior? > > Ahmad Syukri Python passes references araound, not copies. Consider it = permutate(100) chunksize = 15 from itertools import islice while True: chunk = tuple(islice(it, chunksize)) if not chunk: break # dispatch items in chunk print chunk chunksize items are calculated before they are dispatched. When you yield the same list every time in permutate() previous items in the chunk will see any changes you make on the list with the intention to update it to the next value. Peter From davea at ieee.org Fri Jul 2 07:55:34 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 02 Jul 2010 07:55:34 -0400 Subject: Pool Module: iterator does not yield consistently with different chunksizes In-Reply-To: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> References: <9b79904e-edf0-470a-8770-34c6601ceaa2@t5g2000prd.googlegroups.com> Message-ID: <4C2DD3B6.5030107@ieee.org> syockit wrote: > I've been playing around with custom iterators to map into Pool. When > I run the code below: > > def arif(arr): > return arr > > def permutate(n): > k = 0 > a = list(range(6)) > while k for i in range(6): > a.insert(0, a.pop(5)+6) > #yield a[:] <-- produces correct results > yield a > k += 1 > return > > def main(): > from multiprocessing import Pool > pool = Pool() > chksize = 15 > for x in pool.imap_unordered(arif, permutate(100), chksize): > print(x) > > if __name__=="__main__": > main() > > .... will output something like this: > > > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [36, 37, 38, 39, 40, 41] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [72, 73, 74, 75, 76, 77] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [108, 109, 110, 111, 112, 113] > [144, 145, 146, 147, 148, 149] > > ... where results are duplicated number of times equal to chunk size, > and the results between the gap are lost. Using a[:] instead, i get: > > [6, 7, 8, 9, 10, 11] > [12, 13, 14, 15, 16, 17] > [18, 19, 20, 21, 22, 23] > [24, 25, 26, 27, 28, 29] > [30, 31, 32, 33, 34, 35] > [36, 37, 38, 39, 40, 41] > [42, 43, 44, 45, 46, 47] > [48, 49, 50, 51, 52, 53] > > .... it comes out okay. Any explanation for such behavior? > > Ahmad Syukri > > While I didn't actually try to follow all your code, I suspect your problem is that when you yield the same object multiple times, they're being all saved, and then when evaluated, they all have the final value. If the values are really independent, somebody has to copy the list, and the [:] does that. DaveA From sjmachin at lexicon.net Fri Jul 2 08:12:04 2010 From: sjmachin at lexicon.net (John Machin) Date: Fri, 2 Jul 2010 05:12:04 -0700 (PDT) Subject: escape character / csv module References: Message-ID: <9309d748-c500-4124-8032-459ce0b47561@b4g2000pra.googlegroups.com> On Jul 2, 6:04?am, MRAB wrote: > The csv module imports from _csv, which suggests to me that there's code > written in C which thinks that the "\x00" is a NUL terminator, so it's a > bug, although it's very unusual to want to write characters like "\x00" > to a CSV file, and I wouldn't be surprised if this is the first time > it's been noticed! :-) Don't be surprised, read the documentation (http://docs.python.org/ library/csv.html#module-csv): """Note This version of the csv module doesn?t support Unicode input. Also, there are currently some issues regarding ASCII NUL characters. Accordingly, all input should be UTF-8 or printable ASCII to be safe; see the examples in section Examples. These restrictions will be removed in the future.""" The NUL/printable part of the note has been there since the module was introduced in Python 2.3.0. From dotancohen at gmail.com Fri Jul 2 08:38:40 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 2 Jul 2010 15:38:40 +0300 Subject: Ignorance and Google Groups (again) In-Reply-To: <20100701221008.d673a9d8.darcy@druid.net> References: <0a0a9d4d-658e-42d1-b718-44721178bff8@w12g2000yqj.googlegroups.com> <7895aa81-a1fc-40e0-84a7-fa91f92589e7@d8g2000yqf.googlegroups.com> <8f05bc5e-5c1e-41b4-acd9-42963e70e868@z10g2000yqb.googlegroups.com> <20100630165550.2b57855f.darcy@druid.net> <4C2BB1BD.9000306@ixokai.io> <20100701221008.d673a9d8.darcy@druid.net> Message-ID: On 2 July 2010 05:10, D'Arcy J.M. Cain wrote: > On Thu, 1 Jul 2010 21:34:15 +0300 > Dotan Cohen wrote: >> I'm one of them. Gmail is great for mailing lists, though I would >> never use it as a personal email client. But I'm more of a lurker than >> a poster on this list, so D'Arcy won't miss me anyway. > > As the song says. "How can I miss you if you won't go away." :-) > I've never heard that, but it sounds line a great line. Googling now! > As I explained, I don't block just because you are on gmail.com. ?I > only block if you use Google Groups to post via news. > Yes, I got to that part after I posted. I should have read to whole thread first. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From ethan at stoneleaf.us Fri Jul 2 08:53:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Jul 2010 05:53:42 -0700 Subject: Python v3.1.2 documentation question In-Reply-To: References: <4C2A26D5.8090507@stoneleaf.us> <4C2A2B8A.5080809@ixokai.io> <4C2D19EE.6060602@stoneleaf.us> Message-ID: <4C2DE156.4020404@stoneleaf.us> Terry Reedy wrote: > On 7/1/2010 6:42 PM, Ethan Furman wrote: > >> Hmmm.... Well, as this is my first ever bug post (yay! ;) > > > Great! > > I *think* this is what you want: > >> >> http://bugs.python.org/issue9121 > > > I believe Benjamin meant that it was already fixed in > http://docs.python.org/dev/py3k/ > which is currently the 3.2a0 docs. > Good to check there before reporting a doc bug. > > Terry Jan Reedy Thanks for the pointer, I didn't know about that. Checking it out, though, it seems the entry for nested scopes has been removed in its entirety -- not sure about fixed, but I guess it's definitely not broken anymore! ;) ~Ethan~ From ethan at stoneleaf.us Fri Jul 2 09:05:59 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Jul 2010 06:05:59 -0700 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <4C2DE437.4040205@stoneleaf.us> Terry Reedy wrote: > On 7/1/2010 6:42 PM, Emile van Sebille wrote: > >> On 7/1/2010 2:52 PM Jay said... >> >>> pywinauto looks to be almost perfect. All I need now is to read the >>> numbers uncovered when a minesweeper square is clicked on, or that I >>> just hit a mine. >>> >> >> ... or, you could always win... >> >> http://www.daniweb.com/forums/thread186209.html > > > Did you actually try it? Though skeptical, I did, briefly, until I > decided that it probably should have been dated April 1. There is no way > to enter text into minesweeper, nor to make it full screen, nor, as far > as I know, for it to toggle pixels outside its window. The pixel can be hard to see depending on your background colors and whether your screen is adjusted correctly (I could see the white, but not the black). But on XP Pro is still works. ~Ethan~ From utente at esempio.net Fri Jul 2 09:17:25 2010 From: utente at esempio.net (superpollo) Date: Fri, 02 Jul 2010 15:17:25 +0200 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <4c2de6e6$0$40293$4fafbaef@reader2.news.tin.it> Ethan Furman ha scritto: > Terry Reedy wrote: >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: >> >>> On 7/1/2010 2:52 PM Jay said... >>> >>>> pywinauto looks to be almost perfect. All I need now is to read the >>>> numbers uncovered when a minesweeper square is clicked on, or that I >>>> just hit a mine. >>>> >>> >>> ... or, you could always win... >>> >>> http://www.daniweb.com/forums/thread186209.html >> >> >> Did you actually try it? Though skeptical, I did, briefly, until I >> decided that it probably should have been dated April 1. There is no >> way to enter text into minesweeper, nor to make it full screen, nor, >> as far as I know, for it to toggle pixels outside its window. > > The pixel can be hard to see depending on your background colors and > whether your screen is adjusted correctly (I could see the white, but > not the black). But on XP Pro is still works. works for me too bye From kedra.marbun at gmail.com Fri Jul 2 09:28:59 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 2 Jul 2010 06:28:59 -0700 (PDT) Subject: delegation pattern via descriptor Message-ID: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> hello, friendliest prog lang community on earth ;) i'm feeling that (0) delegation pattern thru descriptor encourages dedicated delegate for each task, if feeling: print(benefits) (1) the delegate is designed to be blind about the class on which the delegate is attached to isn't that the two strengthen the coupling between delegator & delegate obviously __getattribute__ & his 2 friends of 'object' & 'type' have what it takes to make it not like that, it's just that they're not designed to pass it. thus i think it is by design yes i know there's a way around it, the most obvious to me is defining your own hooks (which is not trival, at least to me) , but like i said, it's encouraged wow, it's almost time for brazil to beat the dutch, sorry Guido ;) if fifa['wc']['2010'].winner is not brazil: raise SystemError From torriem at gmail.com Fri Jul 2 11:20:38 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 02 Jul 2010 09:20:38 -0600 Subject: drag & drop in a python GUI application In-Reply-To: References: Message-ID: <4C2E03C6.1070406@gmail.com> On 07/01/2010 08:57 AM, Alan wrote: > I know drag & drop is not possible with TK. Is this a Python Tk limitation or a Tk limitation in general? Google suggests that Tk itself supports some form of dnd. > Which widget could I use for my > python application to be able to work with drag & drop? PyQt will do drag and drop on all platforms. GTK does drag and drop on Unix/X11, and to a lesser degree Win32--not sure about OS X support. I believe wxWidgets also does some level of dnd on all platforms. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 11:35:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 15:35:10 GMT Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> Message-ID: <4c2e072e$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 06:28:59 -0700, kedra marbun wrote: > hello, friendliest prog lang community on earth ;) > > i'm feeling that > (0) delegation pattern thru descriptor encourages dedicated delegate for > each task, if feeling: print(benefits) (1) the delegate is designed to > be blind about the class on which the delegate is attached to > > isn't that the two strengthen the coupling between delegator & delegate > obviously __getattribute__ & his 2 friends of 'object' & 'type' have > what it takes to make it not like that, it's just that they're not > designed to pass it. thus i think it is by design > > yes i know there's a way around it, the most obvious to me is defining > your own hooks (which is not trival, at least to me) , but like i said, > it's encouraged I'm sorry, I don't understand a thing you're saying there. Can you explain what you mean? -- Steven From dhilip.jec at gmail.com Fri Jul 2 11:38:56 2010 From: dhilip.jec at gmail.com (Dhilip S) Date: Fri, 2 Jul 2010 21:08:56 +0530 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: Hello Everyone.. I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got error message while doing make command. anybody can tell tell, How to overcome this error.... Finally i got message like this ... 4036e000-403ad000 r--p 00000000 08:08 156978 /usr/lib/locale/en_IN/LC_CTYPE bff9a000-bffaf000 rw-p 00000000 00:00 0 [stack] Aborted make: ***[sharedmodes] Error 13 -- with regards, Dhilip.S -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 2 12:24:41 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 18:24:41 +0200 Subject: Python 2.4.2 Installation error In-Reply-To: References: Message-ID: <4C2E12C9.7030307@jollans.com> On 07/02/2010 05:38 PM, Dhilip S wrote: > > > Hello Everyone.. > > I'm using Ubuntu 10.04, i try to install Python 2.4.2 & Python 2.4.3 got > error message while doing make command. anybody can tell tell, How to > overcome this error.... Finally i got message like this ... > > 4036e000-403ad000 r--p 00000000 08:08 156978 > /usr/lib/locale/en_IN/LC_CTYPE > bff9a000-bffaf000 rw-p 00000000 00:00 0 [stack] > Aborted > make: ***[sharedmodes] Error 13 > That looks like the last line of a glibc backtrace, and doesn't tell us much. Please post the exact commands you entered to produce the problem. Best to try again, even if you're sure it will fail. Then post the complete error message, which can span several screenfuls with this kind of problem. Include at least a few lines of output that you can be sure are correct, to give us some context. It's better to post a bit too much than too little. -- Thomas From debatem1 at gmail.com Fri Jul 2 12:58:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 2 Jul 2010 12:58:13 -0400 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? In-Reply-To: References: <1278010127.6605.1382869273@webmail.messagingengine.com> <4C2DBC54.7090004@gmail.com> Message-ID: On Fri, Jul 2, 2010 at 6:15 AM, Stef Mientki wrote: > ?On 02-07-2010 09:39, geremy condra wrote: >> On Thu, Jul 1, 2010 at 11:48 AM, ? wrote: >>> Curious if any of you are using GPG or PGP encryption and/or signatures >>> in your Python apps? >> Yes; disclaimer: I'm the author of evpy and am currently working on a >> openssl wrapper proposed for inclusion in the stdlib. > Great Geremy !, > but it's difficult to find, > and I couldn't find any documentation. > Did I not look at the right places ? I assume you're talking about the proposed (and unnamed) crypto library, in which case I would be very surprised if you found it unless you looked on my hard drive ;). I don't usually release security-critical code for general use until I've done extensive testing and I simply haven't had time for that over the last week or so. If you're talking about evpy, the documentation for the three user-facing modules is in the docstrings, and I'm almost always here or available by email if you have any questions. Geremy Condra From me+list/python at ixokai.io Fri Jul 2 13:41:01 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 10:41:01 -0700 Subject: Decorators, with optional arguments Message-ID: <4C2E24AD.3040002@ixokai.io> Okay, so! I actually never quite got around to learning to do deep and useful magic with decorators. I've only ever done the most basic things with them. Its all been a little fuzzy in my head: things like what order decorators end up being called in if there's more then one, etc. But in my current situation, what I'm wanting to do is have a decorator that wraps a function but which takes an *optional* argument, and sets that argument as an attribute on said function if its there. Here's what some tweaking and playing around has gotten me, as a recipe: import functools def my_decorator(arg): if callable(arg): # Stuck on 2.5. Leavemealone. :) protocol = None else: protocol = arg def wrap(fn): print "Wrapping." fn.protocol = protocol @functools.wraps(fn) def wrapper(*args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return wrapper if not protocol: # argument-less decorator print "Calling wrap." return wrap(arg) else: print "Returning wrap." return wrap To be used as: class Thing(object): @expose def test1(self, arg1): return arg1 @expose("testing") def test2(self, arg2): return arg2 So, my question: am I doing this right? :) Some play-through testing appears to work. But, the dizzying array of nested def's up there leaves me a bit dazed, so I'm wondering if there's a simpler way to accomplish what I'm trying to do. Thanks. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ From no.email at please.post Fri Jul 2 14:00:03 2010 From: no.email at please.post (kj) Date: Fri, 2 Jul 2010 18:00:03 +0000 (UTC) Subject: Numerics question Message-ID: I define ninv = 1.0/n ...where n is some integer, and I want to write some function f such that f(m * ninv) returns the smallest integer that is >= m * ninv, where m is some other integer. And, in particular, if m is p*n for some integer p, then f((p*n) * ninv) should return the integer p. The first solution that comes to mind is something like def f(x): return int(math.ceil(x)) At first this seems to work: >>> f((7*2) * (1.0/2)) 7 >>> f((7*3) * (1.0/3)) 7 ...but there are values of n for which it fails: >>> f((7*75) * (1.0/75)) 8 The problem here is that, due to numerical error, the expression ((7*75) * (1.0/75)) evaluates to a number *just* above 7. The surrounding math.ceil then turns this into 8.0, etc. Is there a way to define f so that it behaves as expected? TIA! ~K From magnus.lycka at gmail.com Fri Jul 2 14:05:19 2010 From: magnus.lycka at gmail.com (magnus.lycka at gmail.com) Date: Fri, 2 Jul 2010 11:05:19 -0700 (PDT) Subject: Importing package with zip-archives Message-ID: <2b5ea92d-d3a3-4aeb-a68c-1d6ddc30010e@k39g2000yqd.googlegroups.com> I'd like to have the following structure of my Python code: I have a directory called 'mysystem'. In this directory, I have files 'comp1.zip' and 'comp2.zip' etc which are zipped archives with python packages and modules. I'd like to be able to use them like this in my code: import mysystem.comp1.module import mysystem.comp2.package.module etc. Can I do that? I guess it requires that the __init__.py in mysystem is written in a clever way, but it's not clear how to do this, and I don't find a lot on this in any Python books or on the net. I tried: mysystem/__init__.py: import sys import os dir = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.path.join(dir, 'comp1.zip')) import comp1 That doesn't do what I want. To access comp1 with this __init__.py I'll have to do import mysystem import comp1.module instead of import mysystem.comp1.module :-( Optionally, I'd like to be able to patch the system by putting a module.py in mysystem/comp2/package/ and get that to override the 'package/module.py' in comp2.zip. It's OK if I need to patch __init__.py in mysystem to do that. From no.email at please.post Fri Jul 2 14:14:10 2010 From: no.email at please.post (kj) Date: Fri, 2 Jul 2010 18:14:10 +0000 (UTC) Subject: Numerics question References: Message-ID: Please disregard my ineptly posed question. ~K In kj writes: >I define >ninv = 1.0/n >...where n is some integer, and I want to write some function f such >that f(m * ninv) returns the smallest integer that is >= m * ninv, >where m is some other integer. And, in particular, if m is p*n >for some integer p, then f((p*n) * ninv) should return the integer >p. >The first solution that comes to mind is something like >def f(x): > return int(math.ceil(x)) >At first this seems to work: >>>> f((7*2) * (1.0/2)) >7 >>>> f((7*3) * (1.0/3)) >7 >...but there are values of n for which it fails: >>>> f((7*75) * (1.0/75)) >8 >The problem here is that, due to numerical error, the expression >((7*75) * (1.0/75)) evaluates to a number *just* above 7. The >surrounding math.ceil then turns this into 8.0, etc. >Is there a way to define f so that it behaves as expected? >TIA! >~K From jdixon at omniti.com Fri Jul 2 14:39:52 2010 From: jdixon at omniti.com (Jason Dixon) Date: Fri, 2 Jul 2010 14:39:52 -0400 Subject: CFP for Surge Scalability Conference 2010 Message-ID: <20100702183952.GW29381@omniti.com> A quick reminder that there's one week left to submit your abstract for this year's Surge Scalability Conference. The event is taking place on Sept 30 and Oct 1, 2010 in Baltimore, MD. Surge focuses on case studies that address production failures and the re-engineering efforts that led to victory in Web Applications or Internet Architectures. Our Keynote speakers include John Allspaw and Theo Schlossnagle. We are currently accepting submissions for the Call For Papers through July 9th. You can find more information, including suggested topics and our current list of speakers, online: http://omniti.com/surge/2010 I'd also like to urge folks who are planning to attend, to get your session passes sooner rather than later. We have limited seating and we are on track to sell out early. For more information, including the CFP, sponsorship of the event, or participating as an exhibitor, please visit the Surge website or contact us at surge at omniti.com. Thanks, -- Jason Dixon OmniTI Computer Consulting, Inc. jdixon at omniti.com 443.325.1357 x.241 From gabriele.lanaro at gmail.com Fri Jul 2 14:48:43 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Fri, 2 Jul 2010 20:48:43 +0200 Subject: [ANN] Emacs For Python 0.1, collection of emacs extensions for python development Message-ID: Emacs For Python 0.1 Emacs for python (epy) is a collection of emacs extensions for python development, yet ready and configured for you. It includes also tweaks to commonly used extension to provide extra functionality and fast bug correction. There are also sane configuration that helps you getting started pretty fast. Some of the most important extensions configured and included in the distribution are: - ido prompts - autocompletion + rope (if you have pymacs) - snippets, simplified and standard-compliant - automatic error/warning/info highlighting with flymake (powered by pyflakes) - custom keybindings - much more (really) I remaind you for further information to the home page: http://gabrielelanaro.github.com/emacs-for-python/ You'll find additional information on the github page (readme and wiki): http://github.com/gabrielelanaro/emacs-for-python Thank you for the attention! - Gabriele -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 2 14:55:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 20:55:26 +0200 Subject: Decorators, with optional arguments In-Reply-To: <4C2E24AD.3040002@ixokai.io> References: <4C2E24AD.3040002@ixokai.io> Message-ID: <4C2E361E.3080602@jollans.com> On 07/02/2010 07:41 PM, Stephen Hansen wrote: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > import functools > > def my_decorator(arg): > if callable(arg): # Stuck on 2.5. Leavemealone. :) > protocol = None > else: > protocol = arg > > def wrap(fn): > print "Wrapping." > fn.protocol = protocol > > @functools.wraps(fn) > def wrapper(*args, **kwargs): > print "Calling." > result = fn(*args, **kwargs) > print "Called." > return result > > return wrapper > > if not protocol: # argument-less decorator > print "Calling wrap." > return wrap(arg) > else: > print "Returning wrap." > return wrap Looks good! You may still want to use functools.update_wrapper or functools.wraps on "wrap". PS: if you weren't stuck on 2.5, but were using 3.x, there's all kinds of fun stuff you could do with function annotations ;-) > > To be used as: > > class Thing(object): > @expose > def test1(self, arg1): > return arg1 > > @expose("testing") > def test2(self, arg2): > return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. > > Thanks. > From alf.p.steinbach+usenet at gmail.com Fri Jul 2 14:58:35 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 02 Jul 2010 20:58:35 +0200 Subject: Decorators, with optional arguments In-Reply-To: References: Message-ID: * Stephen Hansen, on 02.07.2010 19:41: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > import functools > > def my_decorator(arg): > if callable(arg): # Stuck on 2.5. Leavemealone. :) > protocol = None > else: > protocol = arg > > def wrap(fn): > print "Wrapping." > fn.protocol = protocol > > @functools.wraps(fn) > def wrapper(*args, **kwargs): > print "Calling." > result = fn(*args, **kwargs) > print "Called." > return result > > return wrapper > > if not protocol: # argument-less decorator > print "Calling wrap." > return wrap(arg) > else: > print "Returning wrap." > return wrap > > To be used as: > > class Thing(object): > @expose > def test1(self, arg1): > return arg1 > > @expose("testing") > def test2(self, arg2): > return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. If you're willing to have slightly more explicit usage code, consider e.g. #Py3 import functools class expose: def __init__( self, protocol = None ): self._protocol = protocol def __call__( self, f ): print( "Wrapping." ) f.protocol = self._protocol @functools.wraps( f ) def wrapper( *args, **kwargs ): print( "Calling." ) result = f( *args, **kwargs ) print( "Called." ) return result return wrapper class Thing(object): @expose() def test1(self, arg1): return arg1 @expose( "testing" ) def test2(self, arg2): return arg2 o = Thing() print( o.test1( 1.11 ) ) print( o.test2( 2.22 ) ) Cheers & hth., - Alf -- blog at From nathan.alexander.rice at gmail.com Fri Jul 2 14:58:46 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 2 Jul 2010 14:58:46 -0400 Subject: Decorators, with optional arguments In-Reply-To: <4C2E24AD.3040002@ixokai.io> References: <4C2E24AD.3040002@ixokai.io> Message-ID: I like to think of decorators with arguments as decorator factory functions. I try and unroll them as much as possible... I have some decorators that work like so (and please note that the wraps and returns_as_output are separate so that I can mutate the behavior as needed, if you just wanted a single decorator this could be condensed): def wrap(f, wrapping_function, *args): argspec = inspect.getargspec(f) without_defaults = len(argspec.args) - len(argspec.defaults or []) f._args = {} f._varkw = [] f._arg_defaults = (None,) * without_defaults + (argspec.defaults or tuple()) for arg in args: if arg in argspec.args: f._args[arg] = argspec.args.index(arg) else: if argspec.keywords: f._varkw.append(arg) return decorator.decorator(wrapping_function, f) def return_as_output(output_f): def func(f, *args, **kwargs): new_args = list(args) for (dict_name, index) in f._args.items(): if len(args) > index: new_args[index] = output_f(args[index]) else: d = f._arg_defaults[index] kwargs[dict_name] = output_f(kwargs.pop(dict_name, d)) for dict_name in f._varkw: kwargs[dict_name] = output_f(kwargs.pop(dict_name, None)) return f(*new_args, **kwargs) return func def iterables(*args): ''' Decorator that guarantees that the named arguments will be iterable. ''' as_iterables = return_as_output(iter_) return lambda f: wrap(f, as_iterables, *args) Just as an example... I have a family of decorators that check compliance with abstract base classes, then try to mutate variables to provide it if duck typing would fail. I don't know if this helps, it is kind of convoluted, but hopefully it gives you another example to work from. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Jul 2 15:07:33 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 12:07:33 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") Message-ID: <4C2E38F5.10708@animats.com> David Cournapeau wrote: > I think one point which needs to be emphasized more is what does > python 3 bring to people. The" what's new in python 3 page" gives > the impression that python 3 is about removing cruft. That's a very > poor argument to push people to switch. That's the real issue, not parentheses on the "print" statement. Where's the business case for moving to Python 3? It's not faster. It doesn't do anything you can't do in Python 2.6. There's no "killer app" for it. End of life for Python 2.x is many years away; most server Linux distros aren't even shipping with 2.6 yet. How can a business justify spending money on conversion to Python 3? If Python 3 came with Unladen Swallow, and ran several times faster than Python 2.x, there'd be a strong business case for conversion. Especially for large sites with racks of servers grinding through slow CPython code. But it looks like Unladen Swallow will be available for 2.6 before it's available for 3.x. So that's not a selling point for 3.x. Python 3 is a nice cleanup of some legacy syntax issues. But that's just not enough. Perl 6 is a nice cleanup of Perl 5, and look how that went. Ten years on, it's not even mainstream, let alone dominant. This has all been said before. See "Python 3.0: What?s The Point?" from December 2008: http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ Not much has changed since then. What I'm not seeing is a deployment plan along these lines: 1. Identify key modules which must be converted before Python 3 can be used in production environments. 2. Get those modules converted to Python 3. 3. Put together a distribution for the major platforms (at least Linux and Windows) with builds of those modules. This could be done on PyPi, which is at present is mostly a link farm, not a repository. 4. Get some major distros, like Debian and ActiveState, to include Python 3, as "python3", not as the primary Python, so there are no conflicts. (Debian already has a formal policy to keep Python versions separate.) 5. Get at least two major hosting services to put up Python 3. 6. Get at least two popular end-user programs (not modules) to support Python 3. 7. Publicize some success stories. Unless the Python 3 enthusiasts get their act together and work much harder on providing an easy transition experience, it's not going to happen. John Nagle From thomas at jollans.com Fri Jul 2 15:59:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 02 Jul 2010 21:59:45 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: <4C2E4531.1060809@jollans.com> On 07/02/2010 09:07 PM, John Nagle wrote: > > What I'm not seeing is a deployment plan along these lines: > > 1. Identify key modules which must be converted before Python 3 > can be used in production environments. That depends VERY strongly on the environment in question. > > 2. Get those modules converted to Python 3. The stdlib is there. The rocky bits are being fixed all the time. The other important modules all have strong development communities. Upstream numpy works with Python 3 already. (no release yet) That enables SciPy to update, which they will do. PyGObject is also working on Py3 support. > > 3. Put together a distribution for the major platforms (at least > Linux and Windows) with builds of those modules. This > could be done on PyPi, which is at present is mostly a link > farm, not a repository. The use cases for Python being as diverse as they are, this is utter nonsense. Also, I myself see no benefit in making PyPI a mirror of everything, as opposed to a useful index of packages that you may or may not want to use. > > 4. Get some major distros, like Debian and ActiveState, to > include Python 3, as "python3", not as the primary Python, > so there are no conflicts. (Debian already has a formal > policy to keep Python versions separate.) Current Ubuntu releases include Python 3.1 as /usr/bin/python3. So does Debian (not sure about stable at this point). I'm sure the other major Linux distributions are doing the same thing. It's happening! > > 5. Get at least two major hosting services to put up Python 3. Apparently, some hosters already support Python 3. Web development is a bit of a weak spot at the moment though, and this is problematic, due to WSGI not being quite unicode ready. > > 6. Get at least two popular end-user programs (not modules) to > support Python 3. > > 7. Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. It's not happening fast, it probably can't, but it *is* happening. Software distributions are including Python 3, and popular modules/packages are starting to support it. Other software is going to move on in its own time. From pavlovevidence at gmail.com Fri Jul 2 16:17:06 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 13:17:06 -0700 (PDT) Subject: Decorators, with optional arguments References: Message-ID: On Jul 2, 10:41?am, Stephen Hansen wrote: > Okay, so! > > I actually never quite got around to learning to do deep and useful > magic with decorators. I've only ever done the most basic things with > them. Its all been a little fuzzy in my head: things like what order > decorators end up being called in if there's more then one, etc. > > But in my current situation, what I'm wanting to do is have a decorator > that wraps a function but which takes an *optional* argument, and sets > that argument as an attribute on said function if its there. > > Here's what some tweaking and playing around has gotten me, as a recipe: > > ? ? ?import functools > > ? ? ?def my_decorator(arg): > ? ? ? ? ?if callable(arg): # Stuck on 2.5. Leavemealone. :) > ? ? ? ? ? ? ?protocol = None > ? ? ? ? ?else: > ? ? ? ? ? ? ?protocol = arg > > ? ? ? ? ?def wrap(fn): > ? ? ? ? ? ? ?print "Wrapping." > ? ? ? ? ? ? ?fn.protocol = protocol > > ? ? ? ? ? ? ?@functools.wraps(fn) > ? ? ? ? ? ? ?def wrapper(*args, **kwargs): > ? ? ? ? ? ? ? ? ?print "Calling." > ? ? ? ? ? ? ? ? ?result = fn(*args, **kwargs) > ? ? ? ? ? ? ? ? ?print "Called." > ? ? ? ? ? ? ? ? ?return result > > ? ? ? ? ? ? ?return wrapper > > ? ? ? ? ?if not protocol: # argument-less decorator > ? ? ? ? ? ? ?print "Calling wrap." > ? ? ? ? ? ? ?return wrap(arg) > ? ? ? ? ?else: > ? ? ? ? ? ? ?print "Returning wrap." > ? ? ? ? ? ? ?return wrap > > To be used as: > > ? ? ?class Thing(object): > ? ? ? ? ?@expose > ? ? ? ? ?def test1(self, arg1): > ? ? ? ? ? ? ?return arg1 > > ? ? ? ? ?@expose("testing") > ? ? ? ? ?def test2(self, arg2): > ? ? ? ? ? ? ?return arg2 > > So, my question: am I doing this right? :) Some play-through testing > appears to work. But, the dizzying array of nested def's up there leaves > me a bit dazed, so I'm wondering if there's a simpler way to accomplish > what I'm trying to do. I usually recommend to factoring out magic parts into their own little function, which then invoke the non-magical part in different ways: def expose_as(protocol): def wrap(fn): print "Wrapping." fn.protocol = protocol @functools.wraps(fn) def wrapper(*args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return wrapper return wrap def expose(arg): """Magic function to allow omitting argument.""" if type(arg) is types.FunctionType: print "Calling with arg as function" return expose_as(None)(arg) print "Calling with arg as protocol" return expose_as(arg) I believe it's a good practice to isolate magic so that it's easy to see, and also to ensure there's a non-magical way to do it if that is needed. However, the world won't come to an end if you do it your way. Carl Banks From solipsis at pitrou.net Fri Jul 2 16:26:03 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 2 Jul 2010 22:26:03 +0200 Subject: Lockless algorithms in python (Nothing to do with GIL) References: Message-ID: <20100702222603.26c5e4af@pitrou.net> On Mon, 28 Jun 2010 16:46:41 -0700 Zac Burns wrote: > In my experience it is far more expensive to allocate a lock in python then > it is the types that use them. Here are some examples: > > >>> timeit.timeit('Lock()', 'from threading import Lock') > 1.4449114807669048 > > >>> timeit.timeit('dict()') > 0.2821554294221187 > > >>> timeit.timeit('list()') > 0.17358153222312467 I'm not sure what Python version on what machine you are using, but here (Python 2.7): >>> timeit.timeit('Lock()', 'from threading import Lock') 0.09944796562194824 >>> timeit.timeit('dict()') 0.17817902565002441 >>> timeit.timeit('list()') 0.19633007049560547 >>> timeit.timeit('{}') 0.03823709487915039 >>> timeit.timeit('[]') 0.05156302452087402 From ptmcg at austin.rr.com Fri Jul 2 16:49:06 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 2 Jul 2010 13:49:06 -0700 (PDT) Subject: GAE + recursion limit References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> Message-ID: <70bd0175-f752-4714-a7d9-49a65fc13f75@e5g2000yqn.googlegroups.com> > Does anyone have any clue what that might be? > Why the problem is on GAE (even when run locally), when command line > run works just fine (even with recursion limit decreased)? Can't explain why you see different behavior on GAE vs. local, but it is unusual for a "small" translator to flirt with recursion limit. I don't usually see parsers come close to this with fewer than 40 or 50 sub-expressions. You may have some left-recursion going on. Can you post your translator somewhere, perhaps on pastebin, or on the pyparsing wiki Discussion page (pyparsing.wikispaces.com)? -- Paul From pavlovevidence at gmail.com Fri Jul 2 16:51:31 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 13:51:31 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: <065866d2-bd2c-4591-ae70-a5700c1e89c3@u36g2000prg.googlegroups.com> On Jul 2, 12:07?pm, John Nagle wrote: > ? ? This has all been said before. Yes, we know. And when no one did anything about it the first dozen times it's been said, it wasn't because we didn't hear it, it was because we didn't care. We still don't care now, and won't care no matter how many times you repeat it, because it's simply wrong. So, please do everyone a favor, and stop wasting your own time, and stop repeating this. Carl Banks From tjreedy at udel.edu Fri Jul 2 17:13:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jul 2010 17:13:25 -0400 Subject: automate minesweeper with python In-Reply-To: References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: On 7/1/2010 10:18 PM, Emile van Sebille wrote: > On 7/1/2010 6:17 PM Terry Reedy said... >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: >>> On 7/1/2010 2:52 PM Jay said... >>>> pywinauto looks to be almost perfect. All I need now is to read the >>>> numbers uncovered when a minesweeper square is clicked on, or that I >>>> just hit a mine. >>>> >>> >>> ... or, you could always win... >>> >>> http://www.daniweb.com/forums/thread186209.html >> >> Did you actually try it? Though skeptical, I did, briefly, until I >> decided that it probably should have been dated April 1. There is no way >> to enter text into minesweeper, nor to make it full screen, nor, as far >> as I know, for it to toggle pixels outside its window. >> > > Yes. It works. Thanks all. I tried again with other windows minimized so that the upper left pixel is medium brown from the wallpaper, and I can make out the white pixel. A maximized unfocued background window has that pixel normally black surrounded by light blue pixels that make one white pixel harder to see for imperfect eyes. Live, post errors, and learn ;-). -- Terry Jan Reedy From pavlovevidence at gmail.com Fri Jul 2 17:28:03 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 2 Jul 2010 14:28:03 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> <4c2de6e6$0$40293$4fafbaef@reader2.news.tin.it> Message-ID: On Jul 2, 6:17?am, superpollo wrote: > Ethan Furman ha scritto: > > > > > Terry Reedy wrote: > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: > > >>> On 7/1/2010 2:52 PM Jay said... > > >>>> pywinauto looks to be almost perfect. All I need now is to read the > >>>> numbers uncovered when a minesweeper square is clicked on, or that I > >>>> just hit a mine. > > >>> ... or, you could always win... > > >>>http://www.daniweb.com/forums/thread186209.html > > >> Did you actually try it? Though skeptical, I did, briefly, until I > >> decided that it probably should have been dated April 1. There is no > >> way to enter text into minesweeper, nor to make it full screen, nor, > >> as far as I know, for it to toggle pixels outside its window. > > > The pixel can be hard to see depending on your background colors and > > whether your screen is adjusted correctly (I could see the white, but > > not the black). ?But on XP Pro is still works. > > works for me too I'm confirming that it even works with Wine emulator in Linux. Carl Banks From jaykoni at yahoo.com Fri Jul 2 17:38:03 2010 From: jaykoni at yahoo.com (Jay) Date: Fri, 2 Jul 2010 14:38:03 -0700 (PDT) Subject: automate minesweeper with python References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> Message-ID: <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> On Jul 2, 2:13?pm, Terry Reedy wrote: > On 7/1/2010 10:18 PM, Emile van Sebille wrote: > > > > > > > On 7/1/2010 6:17 PM Terry Reedy said... > >> On 7/1/2010 6:42 PM, Emile van Sebille wrote: > >>> On 7/1/2010 2:52 PM Jay said... > >>>> pywinauto looks to be almost perfect. All I need now is to read the > >>>> numbers uncovered when a minesweeper square is clicked on, or that I > >>>> just hit a mine. > > >>> ... or, you could always win... > > >>>http://www.daniweb.com/forums/thread186209.html > > >> Did you actually try it? Though skeptical, I did, briefly, until I > >> decided that it probably should have been dated April 1. There is no way > >> to enter text into minesweeper, nor to make it full screen, nor, as far > >> as I know, for it to toggle pixels outside its window. > > > Yes. It works. > > Thanks all. I tried again with other windows minimized so that the upper > left pixel is medium brown from the wallpaper, and I can make out the > white pixel. A maximized unfocued background window has that pixel > normally black surrounded by light blue pixels that make one white pixel > harder to see for imperfect eyes. ?Live, post errors, and learn ;-). > > -- > Terry Jan Reedy- Hide quoted text - > > - Show quoted text - OK, so how does a program read the pixel? From aahz at pythoncraft.com Fri Jul 2 18:00:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 15:00:17 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: In article <4C2E38F5.10708 at animats.com>, John Nagle wrote: > > 5. Get at least two major hosting services to put up Python 3. webfaction.com has python3.1 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From joshua.r.english at gmail.com Fri Jul 2 18:00:50 2010 From: joshua.r.english at gmail.com (Josh English) Date: Fri, 2 Jul 2010 15:00:50 -0700 (PDT) Subject: Namespace problem? References: <76d15152-040c-4d24-90d5-6a96d2f60480@x24g2000pro.googlegroups.com> Message-ID: <3bdebf16-cf60-4d91-8070-24d24c114b5f@q40g2000prg.googlegroups.com> On Jul 1, 3:30?pm, "Rhodri James" wrote: > > If this is a version of your code that actually fails when you run it ? > (rather than being another artistic interpretation of a photograph of your ? > code :-), then I'd go with Matt's analysis. ?This will give you a ? > NameError for fws_last_col if tracker.hasFWS() happens to return False for ? > all students. > Actually, tracker.hasFWS() was returning False for an entirely different reason that I didn't expect until I had the script dump all the information it was processing. Thanks for the clue. I added one parameter to one function elsewhere and the thing seems to be working again. Thanks for the help. Josh From pauljefferson at gmail.com Fri Jul 2 18:35:58 2010 From: pauljefferson at gmail.com (Paul) Date: Fri, 2 Jul 2010 15:35:58 -0700 (PDT) Subject: IMAP Problems Message-ID: <1fd46692-b796-409e-ad43-88b1b13ac804@y11g2000yqm.googlegroups.com> Hi, I'm trying to write a simple script which displays the basic details of a person's mailbox. My problem is that it causes all the messages to be marked as read on the server, which is not what I'm after, and I also can't get the imap.sort command to work properly (currently commented out as I replaced it with a imap.search to get the thing working. These are probably very simple things, but I've not tried this library before so am a bit stuck so any help wwould be very gratefully received. Thanks, Paul Code: # -*- coding: cp1252 -*- import imaplib,email # you want to connect to a server; specify which server server= imaplib.IMAP4_SSL('imap.googlemail.com') # after connecting, tell the server who you are server.login('xxxx at gmail.com', 'xxxxxxx') # this will show you a list of available folders # possibly your Inbox is called INBOX, but check the list of mailboxes code, mailboxen= server.list() print mailboxen # if it's called INBOX, then? server.select("INBOX") typ, data = server.search(None, 'ALL') #typ, data = server.sort("Date","UTF-8", 'ALL') print len(data[0].split()) for num in data[0].split(): typ, data = server.fetch(num, '(RFC822)') #print 'Message %s\n%s\n' % (num, data[0][1]) msg = email.message_from_string(data[0][1]) print msg["From"] print msg["Subject"] print msg["Date"] print "_______________________________" server.close() server.logout() From emile at fenx.com Fri Jul 2 18:52:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 02 Jul 2010 15:52:18 -0700 Subject: automate minesweeper with python In-Reply-To: <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> References: <626b0cf8-6858-4209-bb5a-51ec3374d5be@x18g2000pro.googlegroups.com> <1520bfff-1a6c-45ff-a2eb-9b10b42afb96@k39g2000yqb.googlegroups.com> <1a817e4c-55ef-452b-92e1-9d13ca5d47a8@t5g2000prd.googlegroups.com> <6dd86bb2-34c3-4265-a30b-3a9f171d7685@m17g2000prl.googlegroups.com> Message-ID: On 7/2/2010 2:38 PM Jay said... > > OK, so how does a program read the pixel? Well, you start with a screen capture utility. I'd check is pywinauto provides that access... Emile From ben+python at benfinney.id.au Fri Jul 2 19:23:31 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 03 Jul 2010 09:23:31 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> Message-ID: <87630xh3ik.fsf@benfinney.id.au> John Nagle writes: > Where's the business case for moving to Python 3? It's not faster. It's faster to learn, because there's less to learn. How do you know that it's not faster? That's a matter of the speed of individual Python implementations. What data do you have? > It doesn't do anything you can't do in Python 2.6. In the trivial sense that Python doesn't do anything you can't do in pure assembly language, that's true. In the more interesting sense of what can the *programmer* do, there are a number of improvements (dealing with Unicde more sanely; keyword-only arguments; function annotations; etc.) that can't be done in Python 2. That set will only grow over time. > How can a business justify spending money on conversion to Python > 3? You'll have to ask the ones that *have* justified that expense. There are major libraries that work with Python 3 now because people have been funded to work on getting there, and others are happening now. > What I'm not seeing is a deployment plan along these lines: > > 1. Identify key modules which must be converted before Python 3 > can be used in production environments. This needs to be done by those who want to use Python. You can't expect a single ?key modules? for the whole of the Python ecosystem. > 2. Get those modules converted to Python 3. Many of them have been converted, and many more are under active development. But this is entirely dependent on which libraries the specific use case demands. > 3. Put together a distribution for the major platforms (at least > Linux and Windows) with builds of those modules. The better path for the GNU distributions is to get the package distributed by the operating system distributor, instead of expecting every developer to also get the packaging right. Fortunately, for a great many key libraries, that's already the case in Debian which is a huge share of the ?major platforms?. > 4. Get some major distros, like Debian and ActiveState, to > include Python 3, as "python3", not as the primary Python, > so there are no conflicts. (Debian already has a formal > policy to keep Python versions separate.) You know this is already the case; why are you saying you don't see it? > 5. Get at least two major hosting services to put up Python 3. > > 6. Get at least two popular end-user programs (not modules) to > support Python 3. And how is this part of a plan for the PYthon developers? What are you suggesting they do to ?get [someone] to support Python 3?? That's up to the someone, surely? > 7. Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. Since you clearly don't count yourself in the set of ?Python 3 enthusiasts?, why do you keep demanding that they do something you expressly don't care about? -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From astroultraman at gmail.com Fri Jul 2 19:24:43 2010 From: astroultraman at gmail.com (Robert William Hanks) Date: Fri, 2 Jul 2010 20:24:43 -0300 Subject: why python don't support "extended slice direct assignment" for lists? Message-ID: why pure python don't support "extended slice direct assignment" for lists? today we have to write like this, >>> aList=[0,1,2,3,4,5,6,7,8,9] >>> aList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's not always possible >>> aList [None, 1, None, 3, None, 5, None, 7, None, 9] why not accept syntax like this for extended slice aList[::2] = None when let's say, the left side is a list and the right side is bool, int or float. the laborious [nunber]*len(aList[::2]) seens to me less readable when you want to set lost of items of a list to the same number. Also correct me if i am wrong, calling len() and building a list to this kind of operation seems a waste. Just want some feedback. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Jul 2 19:44:06 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 16:44:06 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4c2e79d3$0$1663$742ec2ed@news.sonic.net> On 7/2/2010 3:00 PM, Aahz wrote: > In article<4C2E38F5.10708 at animats.com>, John Nagle wrote: >> >> 5. Get at least two major hosting services to put up Python 3. > > webfaction.com has python3.1 WebFaction's big thing is that they have a really good system for installing anything the user wants. They're doing semi-virtual machine hosting, where each user sees a somewhat different environment, but doesn't have their own copy of the Linux kernel. That's a nice advance in server management. Any user can install Python 3.x, but it's not there by default. See: "http://blog.webfaction.com/python-3-0-is-here" If that approach catches on, Python 3 deployment will be much easier. But for now, only a few smaller players like WebFaction are using it. John Nagle From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 19:57:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 23:57:51 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: > Where's the business case for moving to Python 3? It's not faster. It > doesn't do anything you can't do in Python 2.6. There's no "killer app" > for it. End of life for Python 2.x is many years away; most server Linux > distros aren't even shipping with 2.6 yet. How can a business justify > spending money on conversion to Python 3? If you (generic you, not John specifically) can't, then don't. It's as simple as that. Stick with 2.6, or 2.7, or even 1.5 if that's the version you're using. A client of mine is still using 2.3. That's okay. It's allowed. If your business case is best satisfied by staying with 2.x until the sun burns out, more power to you. Just don't expect security upgrades (let alone functional upgrades) for more than a few years. If they are important to you, then *that's* your business case for upgrading. But if you're starting a new project, there is no cost of conversion. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 2 19:59:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jul 2010 23:59:52 GMT Subject: Why defaultdict? References: <4c2d6705$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c2e7d77$0$28647$c3e8da3@news.astraweb.com> On Fri, 02 Jul 2010 04:11:49 +0000, Steven D'Aprano wrote: > I would like to better understand some of the design choices made in > collections.defaultdict. [...] Thanks to all who replied. -- Steven From anand.shashwat at gmail.com Fri Jul 2 20:02:31 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 3 Jul 2010 05:32:31 +0530 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: On Sat, Jul 3, 2010 at 4:54 AM, Robert William Hanks < astroultraman at gmail.com> wrote: > why pure python don't support "extended slice direct assignment" for lists? > > today we have to write like this, > > >>> aList=[0,1,2,3,4,5,6,7,8,9] > >>> aList > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's not > always possible > Can you show me a case where it really is cumbersome. > >>> aList > [None, 1, None, 3, None, 5, None, 7, None, 9] > > why not accept syntax like this for extended slice > > aList[::2] = None > > when let's say, the left side is a list and the right side is bool, int or > float. > the laborious [nunber]*len(aList[::2]) seens to me less readable when you > want to set lost of items of a list to the same number. > Also correct me if i am wrong, calling len() and building a list to this > kind of operation seems a waste. > >>> aList[::2] [0, 2, 4, 6, 8] Which means you are doing [0, 2, 4, 6, 8] = None, which is plain and simple - wrong. How will you define the legitimacy of this statement. What you are basically doing here is,, >>> [None]*len(aList[::2]) [None, None, None, None, None] >>> aList[::2] [0, 2, 4, 6, 8] Setting [0, 2, 4, 6, 8] to [None, None, None, None, None], thereby operating on two similar data structure (here list) > Just want some feedback. > Just my thoughts. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhijeet.thatte at gmail.com Fri Jul 2 20:17:36 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 2 Jul 2010 17:17:36 -0700 Subject: Sorting dicts inside dicts Message-ID: Hi, I have a huge dict structure like below: * {'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} * Module dict and reg_dicts contain many elements than shown. I want to sort this 'module' dictionary as per 'reg_addr' element in every 'reg_dict'. There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 can contain reg_address = 2000/72 (any number) I do not want output in a list format as the actual dict size is huge which I want to use based on key value pair. So, I want output as : * {'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} * * * Is it possible to sort the things? What I guess is Python stores dicts in a tree like structure but I am forcing it to store the way I want. Is it possible to do something like that. Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Jul 2 20:22:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 3 Jul 2010 05:52:46 +0530 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4c2e7cff$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 3, 2010 at 5:27 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: > > > Where's the business case for moving to Python 3? It's not faster. It > > doesn't do anything you can't do in Python 2.6. There's no "killer app" > > for it. End of life for Python 2.x is many years away; most server Linux > > distros aren't even shipping with 2.6 yet. How can a business justify > > spending money on conversion to Python 3? > The point is python2.7 is the last 2.x version. It will be supported, bugs will be fixed but no new feature will be added. Core devs will concentrate on python 3.x. You can still use 2.x, no one is stopping you. But assume that it is stagnant now. After some time only security related bugs will be fixed. So if you want to wait by then, it's all your wish. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From googler.1.webmaster at spamgourmet.com Fri Jul 2 20:56:35 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 2 Jul 2010 17:56:35 -0700 (PDT) Subject: Crash in PyThread_acquire_lock Message-ID: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Hi all, I have a serious problem I want to solve. My app, where Python is embedded crashs on OSX (10.6 SL). I can reproduce the crash sometimes with a script that makes use of Python threads ( module: threading). 'thelock->locked' is for sure still locked, but I can't identify the problem. Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the crash in PyThread_acquire_lock is the following one: while ( thelock->locked ) { status = pthread_cond_wait(&thelock->lock_released, &thelock- >mut); <<<<<<<<<< >From the view of my code, I can exclude that the GIL was ensured but not properly released by PyStateGIL_Ensure and PyStateGIL_Release. Any ideas how to get rid of this crash somehow? Thanks in advance!! Bye, moerchendiser2k3 #0 0x00007fff86c95316 in __semwait_signal () #1 0x00007fff86c99131 in _pthread_cond_wait () #2 0x000000011c89f8f4 in PyThread_acquire_lock (lock=0x1013803c0, waitflag=1) at thread_pthread.h:452 #3 0x000000011c84a414 in PyEval_RestoreThread (tstate=0x101380200) at Python/ceval.c:334 #4 0x000000011c889725 in PyGILState_Ensure () at Python/pystate.c:592 From python at mrabarnett.plus.com Fri Jul 2 21:25:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jul 2010 02:25:14 +0100 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: <4C2E917A.1090807@mrabarnett.plus.com> Robert William Hanks wrote: > why pure python don't support "extended slice direct assignment" for lists? > > today we have to write like this, > > >>> aList=[0,1,2,3,4,5,6,7,8,9] > >>> aList > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's > not always possible > >>> aList > [None, 1, None, 3, None, 5, None, 7, None, 9] > > why not accept syntax like this for extended slice > > aList[::2] = None > > when let's say, the left side is a list and the right side is bool, int > or float. > the laborious [nunber]*len(aList[::2]) seens to me less readable when > you want to set lost of items of a list to the same number. > Also correct me if i am wrong, calling len() and building a list to this > kind of operation seems a waste. > > Just want some feedback. > When you're assigning to a list slice, why should it duplicate an int but not a list? Or in general, duplicate something that's not iterable but not something that is iterable? A string is iterable, so what should: >>> a[ : : 2] = "abcde" do? It's just simpler and less surprising the way it is. From aahz at pythoncraft.com Fri Jul 2 21:30:33 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 18:30:33 -0700 Subject: tp_richcompare vs tp_compare References: Message-ID: In article , moerchendiser2k3 wrote: > >Do I need to implement both? Looks very redundant, isnt it? Or is it >just an extension and tp_richcompare is the better choice here? Can >anyone please make the light on here? :) Nobody else responded, so please take this non-expert advice: tp_compare is the older and now deprecated slot; you want to use tp_richcompare if you don't need to support older versions of Python. Don't implement both. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From python at mrabarnett.plus.com Fri Jul 2 21:34:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 03 Jul 2010 02:34:52 +0100 Subject: Sorting dicts inside dicts In-Reply-To: References: Message-ID: <4C2E93BC.5010309@mrabarnett.plus.com> abhijeet thatte wrote: > Hi, > I have a huge dict structure like below: > /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ > > Module dict and reg_dicts contain many elements than shown. > > I want to sort this 'module' dictionary as per 'reg_addr' element in > every 'reg_dict'. > > There is no relation between 'reg_dict' suffix and address. So, > reg_dict_0 can contain reg_address = 2000/72 (any number) > I do not want output in a list format as the actual dict size is huge > which I want to use based on key value pair. > > So, I want output as : > > /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ > /* > */ > > Is it possible to sort the things? What I guess is Python stores dicts > in a tree like structure but I am forcing it to store the way I want. Is > it possible to do something like that. > Python dicts are implemented as hash tables, not trees, for speed, and they are unordered. If the order matters then you should use an ordered dict instead. You should be able to find an implementation of one. From aahz at pythoncraft.com Fri Jul 2 21:36:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Jul 2010 18:36:49 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c2e79d3$0$1663$742ec2ed@news.sonic.net> Message-ID: In article <4c2e79d3$0$1663$742ec2ed at news.sonic.net>, John Nagle wrote: >On 7/2/2010 3:00 PM, Aahz wrote: >> In article<4C2E38F5.10708 at animats.com>, John Nagle wrote: >>> >>> 5. Get at least two major hosting services to put up Python 3. >> >> webfaction.com has python3.1 > > Any user can install Python 3.x, but it's not there by default. Yes, it is. I logged into my webfaction shell, typed python3.1, and got a standard Python prompt, without doing anything whatsoever to make Python 3.1 available. > "http://blog.webfaction.com/python-3-0-is-here" Is there some reason you're using a broken URL format? > If that approach catches on, Python 3 deployment will be much easier. >But for now, only a few smaller players like WebFaction are using it. In the hosting space that makes Python available, WebFaction is hardly a smaller player. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From mmanns at gmx.net Fri Jul 2 21:53:07 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 3 Jul 2010 03:53:07 +0200 Subject: Anyone using GPG or PGP encryption/signatures in your Python apps? References: Message-ID: <20100703035307.7e5ae2d3@Knock> On Thu, 01 Jul 2010 14:48:47 -0400 python at bdurham.com wrote: > Curious if any of you are using GPG or PGP encryption and/or > signatures in your Python apps? ... > 4. generating signatures for files that you are exchanging/posting for > download? I use pyme to create and check save file signatures. > 5. what public keyring services are you using? None > Any comments on using the subprocess module to wrap the gpg or openssl > command line utilities? This seems to be a common technique for > encryption and signing solutions and appears to the technique used by > python-gnupg (for example). pyme works great with Linux. However, I have never installed it on a Windows system. Martin From astroultraman at gmail.com Fri Jul 2 22:19:31 2010 From: astroultraman at gmail.com (Robert William Hanks) Date: Fri, 2 Jul 2010 23:19:31 -0300 Subject: why python don't support "extended slice direct assignment" for lists? Message-ID: to say is "wrong" i think is a bit too much, its just a different type of usage, this type of sintax is extensively used in numpy arrays (extended slice came from numerical python), just asking why not extend the sintax to python list. (not sure if you can use None as in the code i posted in numpy but numbers are ok). I was just rewriting some numpy code in pure python (no numpy for python3 yet), personally i think the pure python way is just ugly and more expensive. On Fri, Jul 2, 2010 at 10:55 PM, wrote: > 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: Why defaultdict? (Steven D'Aprano) > 2. Re: why python don't support "extended slice direct > assignment" for lists? (Shashwat Anand) > 3. Sorting dicts inside dicts (abhijeet thatte) > 4. Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") (Shashwat Anand) > 5. Crash in PyThread_acquire_lock (moerchendiser2k3) > 6. Re: why python don't support "extended slice direct > assignment" for lists? (MRAB) > 7. Re: Sorting dicts inside dicts (MRAB) > 8. Re: tp_richcompare vs tp_compare (Aahz) > 9. Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") (Aahz) > 10. Re: Anyone using GPG or PGP encryption/signatures in your > Python apps? (Martin Manns) > > > ---------- Forwarded message ---------- > From: Steven D'Aprano > To: python-list at python.org > Date: 02 Jul 2010 23:59:52 GMT > Subject: Re: Why defaultdict? > On Fri, 02 Jul 2010 04:11:49 +0000, Steven D'Aprano wrote: > > > I would like to better understand some of the design choices made in > > collections.defaultdict. > [...] > > > Thanks to all who replied. > > > -- > Steven > > > > > > ---------- Forwarded message ---------- > From: Shashwat Anand > To: Robert William Hanks > Date: Sat, 3 Jul 2010 05:32:31 +0530 > Subject: Re: why python don't support "extended slice direct assignment" > for lists? > > > On Sat, Jul 3, 2010 at 4:54 AM, Robert William Hanks < > astroultraman at gmail.com> wrote: > >> why pure python don't support "extended slice direct assignment" for >> lists? >> >> today we have to write like this, >> >> >>> aList=[0,1,2,3,4,5,6,7,8,9] >> >>> aList >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's >> not always possible >> > > Can you show me a case where it really is cumbersome. > > >> >>> aList >> [None, 1, None, 3, None, 5, None, 7, None, 9] >> >> why not accept syntax like this for extended slice >> >> aList[::2] = None >> >> when let's say, the left side is a list and the right side is bool, int or >> float. >> the laborious [nunber]*len(aList[::2]) seens to me less readable when you >> want to set lost of items of a list to the same number. >> Also correct me if i am wrong, calling len() and building a list to this >> kind of operation seems a waste. >> > > >>> aList[::2] > [0, 2, 4, 6, 8] > Which means you are doing [0, 2, 4, 6, 8] = None, which is plain and simple > - wrong. How will you define the legitimacy of this statement. > What you are basically doing here is,, > > >>> [None]*len(aList[::2]) > [None, None, None, None, None] > >>> aList[::2] > [0, 2, 4, 6, 8] > > Setting [0, 2, 4, 6, 8] to [None, None, None, None, None], thereby > operating on two similar data structure (here list) > > >> Just want some feedback. >> > > Just my thoughts. > > ~l0nwlf > > > > ---------- Forwarded message ---------- > From: abhijeet thatte > To: python-list at python.org > Date: Fri, 2 Jul 2010 17:17:36 -0700 > Subject: Sorting dicts inside dicts > Hi, > I have a huge dict structure like below: > * > {'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} > * > > Module dict and reg_dicts contain many elements than shown. > > I want to sort this 'module' dictionary as per 'reg_addr' element in every > 'reg_dict'. > > There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 > can contain reg_address = 2000/72 (any number) > I do not want output in a list format as the actual dict size is huge which > I want to use based on key value pair. > > So, I want output as : > > * > {'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}} > * > * > * > > Is it possible to sort the things? What I guess is Python stores dicts in a > tree like structure but I am forcing it to store the way I want. Is it > possible to do something like that. > > Thanks, > > > > > ---------- Forwarded message ---------- > From: Shashwat Anand > To: "Steven D'Aprano" > Date: Sat, 3 Jul 2010 05:52:46 +0530 > Subject: Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") > > > On Sat, Jul 3, 2010 at 5:27 AM, Steven D'Aprano < > steve at remove-this-cybersource.com.au> wrote: > >> On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: >> >> > Where's the business case for moving to Python 3? It's not faster. It >> > doesn't do anything you can't do in Python 2.6. There's no "killer app" >> > for it. End of life for Python 2.x is many years away; most server Linux >> > distros aren't even shipping with 2.6 yet. How can a business justify >> > spending money on conversion to Python 3? >> > > The point is python2.7 is the last 2.x version. It will be supported, bugs > will be fixed but no new feature will be added. Core devs will concentrate > on python 3.x. You can still use 2.x, no one is stopping you. But assume > that it is stagnant now. After some time only security related bugs will be > fixed. So if you want to wait by then, it's all your wish. > > ~l0nwlf > > > ---------- Forwarded message ---------- > From: moerchendiser2k3 > To: python-list at python.org > Date: Fri, 2 Jul 2010 17:56:35 -0700 (PDT) > Subject: Crash in PyThread_acquire_lock > Hi all, > > I have a serious problem I want to solve. My app, where > Python is embedded crashs on OSX (10.6 SL). I can reproduce the crash > sometimes with a script that makes use of Python threads ( module: > threading). > > 'thelock->locked' is for sure still locked, but I can't identify the > problem. > Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the > crash > in PyThread_acquire_lock is the following one: > > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, &thelock- > >mut); <<<<<<<<<< > > >From the view of my code, I can exclude that the GIL was ensured but > not properly released > by PyStateGIL_Ensure and PyStateGIL_Release. > > Any ideas how to get rid of this crash somehow? Thanks in advance!! > > Bye, moerchendiser2k3 > > #0 0x00007fff86c95316 in __semwait_signal () > #1 0x00007fff86c99131 in _pthread_cond_wait () > #2 0x000000011c89f8f4 in PyThread_acquire_lock (lock=0x1013803c0, > waitflag=1) at thread_pthread.h:452 > #3 0x000000011c84a414 in PyEval_RestoreThread (tstate=0x101380200) at > Python/ceval.c:334 > #4 0x000000011c889725 in PyGILState_Ensure () at Python/pystate.c:592 > > > > > ---------- Forwarded message ---------- > From: MRAB > To: python-list at python.org > Date: Sat, 03 Jul 2010 02:25:14 +0100 > Subject: Re: why python don't support "extended slice direct assignment" > for lists? > Robert William Hanks wrote: > >> why pure python don't support "extended slice direct assignment" for >> lists? >> >> today we have to write like this, >> >> >>> aList=[0,1,2,3,4,5,6,7,8,9] >> >>> aList >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's >> not always possible >> >>> aList >> [None, 1, None, 3, None, 5, None, 7, None, 9] >> >> why not accept syntax like this for extended slice >> >> aList[::2] = None >> >> when let's say, the left side is a list and the right side is bool, int or >> float. >> the laborious [nunber]*len(aList[::2]) seens to me less readable when you >> want to set lost of items of a list to the same number. >> Also correct me if i am wrong, calling len() and building a list to this >> kind of operation seems a waste. >> >> Just want some feedback. >> >> When you're assigning to a list slice, why should it duplicate an int > but not a list? Or in general, duplicate something that's not iterable > but not something that is iterable? A string is iterable, so what > should: > > >>> a[ : : 2] = "abcde" > > do? > > It's just simpler and less surprising the way it is. > > > > ---------- Forwarded message ---------- > From: MRAB > To: python-list at python.org > Date: Sat, 03 Jul 2010 02:34:52 +0100 > Subject: Re: Sorting dicts inside dicts > abhijeet thatte wrote: > >> Hi, >> I have a huge dict structure like below: >> >> /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> >> Module dict and reg_dicts contain many elements than shown. >> I want to sort this 'module' dictionary as per 'reg_addr' element in every >> 'reg_dict'. >> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 >> can contain reg_address = 2000/72 (any number) >> I do not want output in a list format as the actual dict size is huge >> which I want to use based on key value pair. >> >> So, I want output as : >> >> >> /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> /* >> */ >> >> Is it possible to sort the things? What I guess is Python stores dicts in >> a tree like structure but I am forcing it to store the way I want. Is it >> possible to do something like that. >> >> Python dicts are implemented as hash tables, not trees, for speed, and > they are unordered. > > If the order matters then you should use an ordered dict instead. You > should be able to find an implementation of one. > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 2 Jul 2010 18:30:33 -0700 > Subject: Re: tp_richcompare vs tp_compare > In article < > d52edb82-4de5-496d-8807-b5d15ee66195 at i31g2000yqm.googlegroups.com>, > moerchendiser2k3 wrote: > > > >Do I need to implement both? Looks very redundant, isnt it? Or is it > >just an extension and tp_richcompare is the better choice here? Can > >anyone please make the light on here? :) > > Nobody else responded, so please take this non-expert advice: > > tp_compare is the older and now deprecated slot; you want to use > tp_richcompare if you don't need to support older versions of Python. > Don't implement both. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you don't know what your program is supposed to do, you'd better not > start writing it." --Dijkstra > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 2 Jul 2010 18:36:49 -0700 > Subject: Re: The real problem with Python 3 - no business case for > conversion (was "I strongly dislike Python 3") > In article <4c2e79d3$0$1663$742ec2ed at news.sonic.net>, > John Nagle wrote: > >On 7/2/2010 3:00 PM, Aahz wrote: > >> In article<4C2E38F5.10708 at animats.com>, John Nagle > wrote: > >>> > >>> 5. Get at least two major hosting services to put up Python 3. > >> > >> webfaction.com has python3.1 > > > > Any user can install Python 3.x, but it's not there by default. > > Yes, it is. I logged into my webfaction shell, typed python3.1, and got > a standard Python prompt, without doing anything whatsoever to make > Python 3.1 available. > > > "http://blog.webfaction.com/python-3-0-is-here" > > Is there some reason you're using a broken URL format? > > > If that approach catches on, Python 3 deployment will be much easier. > >But for now, only a few smaller players like WebFaction are using it. > > In the hosting space that makes Python available, WebFaction is hardly a > smaller player. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you don't know what your program is supposed to do, you'd better not > start writing it." --Dijkstra > > > > ---------- Forwarded message ---------- > From: Martin Manns > To: python-list at python.org > Date: Sat, 3 Jul 2010 03:53:07 +0200 > Subject: Re: Anyone using GPG or PGP encryption/signatures in your Python > apps? > On Thu, 01 Jul 2010 14:48:47 -0400 > python at bdurham.com wrote: > > > Curious if any of you are using GPG or PGP encryption and/or > > signatures in your Python apps? > ... > > 4. generating signatures for files that you are exchanging/posting for > > download? > > I use pyme to create and check save file signatures. > > > 5. what public keyring services are you using? > > None > > > Any comments on using the subprocess module to wrap the gpg or openssl > > command line utilities? This seems to be a common technique for > > encryption and signing solutions and appears to the technique used by > > python-gnupg (for example). > > pyme works great with Linux. > However, I have never installed it on a Windows system. > > Martin > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Jul 2 22:20:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 03 Jul 2010 14:20:26 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: <4c2ccd9c$0$1643$742ec2ed@news.sonic.net> Message-ID: In message , Rami Chowdhury wrote: > On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > >> Nevertheless, it it at least self-consistent. To return to my original >> macro: >> >> #define Descr(v) &v, sizeof v >> >> As written, this works whatever the type of v: array, struct, whatever. > > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly > modified... > > char *buf = malloc(512 * sizeof(char)); Again, you misunderstand the difference between a C array and a pointer. Study the following example, which does work, and you might grasp the point: ldo at theon:hack> cat test.c #include int main(int argc, char ** argv) { char buf[512]; const int a = 2, b = 3; snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); fprintf(stdout, buf); return 0; } /*main*/ ldo at theon:hack> ./test 2 + 3 = 5 From clp2 at rebertia.com Fri Jul 2 22:43:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Jul 2010 19:43:01 -0700 Subject: why python don't support "extended slice direct assignment" for lists? In-Reply-To: References: Message-ID: On Fri, Jul 2, 2010 at 7:19 PM, Robert William Hanks wrote: > to say is "wrong" i think is a bit too much, its just a different type of > usage, this type of sintax is extensively used in numpy arrays (extended > slice came from numerical python), just asking why not extend the sintax to > python list. (not sure if you can use None as in the code i posted in numpy > but numbers are ok). I was just rewriting some numpy code in pure python (no > numpy for python3 yet), personally i think the pure python way is just ugly > and more expensive. > > On Fri, Jul 2, 2010 at 10:55 PM, wrote: >> >> 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: Please avoid replying to the list digest, especially without trimming, as it adds noise to the conversation (and can screw up threading). Cheers, Chris From rami.chowdhury at gmail.com Fri Jul 2 23:07:24 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 2 Jul 2010 20:07:24 -0700 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? In-Reply-To: References: Message-ID: <201007022007.24308.rami.chowdhury@gmail.com> On Friday 02 July 2010 19:20:26 Lawrence D'Oliveiro wrote: > In message , Rami > Chowdhury wrote: > > On Thursday 01 July 2010 16:50:59 Lawrence D'Oliveiro wrote: > >> Nevertheless, it it at least self-consistent. To return to my original > >> > >> macro: > >> #define Descr(v) &v, sizeof v > >> > >> As written, this works whatever the type of v: array, struct, whatever. > > > > Doesn't seem to, sorry. Using Michael Torrie's code example, slightly > > modified... > > > > char *buf = malloc(512 * sizeof(char)); > > Again, you misunderstand the difference between a C array and a pointer. > Study the following example, which does work, and you might grasp the > point: > > ldo at theon:hack> cat test.c > #include > > int main(int argc, char ** argv) > { > char buf[512]; > const int a = 2, b = 3; > snprintf(&buf, sizeof buf, "%d + %d = %d\n", a, b, a + b); > fprintf(stdout, buf); > return > 0; > } /*main*/ > ldo at theon:hack> ./test > 2 + 3 = 5 I'm sorry, perhaps you've misunderstood what I was refuting. You posted: > >> macro: > >> #define Descr(v) &v, sizeof v > >> > >> As written, this works whatever the type of v: array, struct, whatever. With my code example I found that, as others have pointed out, unfortunately it doesn't work if v is a pointer to a heap-allocated area. ---- Rami Chowdhury "A man with a watch knows what time it is. A man with two watches is never sure". -- Segal's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From cournape at gmail.com Fri Jul 2 23:09:45 2010 From: cournape at gmail.com (David Cournapeau) Date: Sat, 3 Jul 2010 12:09:45 +0900 Subject: Why Is Escaping Data Considered So Magical? In-Reply-To: <88r8n4Fn3qU1@mid.individual.net> References: <69c2e25c-f4d1-4a60-bda3-1b7a8e99a216@j4g2000yqh.googlegroups.com> <88r8n4Fn3qU1@mid.individual.net> Message-ID: On Mon, Jun 28, 2010 at 6:44 PM, Gregory Ewing wrote: > Carl Banks wrote: > >> Indeed, strncpy does not copy that final NUL if it's at or beyond the >> nth element. ?Probably the most mind-bogglingly stupid thing about the >> standard C library, which has lots of mind-boggling stupidity. > > I don't think it was as stupid as that back when C was > designed Actually, strncpy had a very specific use case when it was introduced (dealing with limited-size entries in very old unix filesystem). It should never be used for C string handling, and I don't think it is fair to say it is stupid: it does exactly what it was designed for. It just happens that most people don't know what it was designed for. David From tjreedy at udel.edu Fri Jul 2 23:50:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Jul 2010 23:50:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: On 7/2/2010 3:07 PM, John Nagle wrote: > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? It's not faster. > It doesn't do anything you can't do in Python 2.6. False. One cannot run code in 2.6 that depends on bugfixes in 3.1. Nor can one run code with unicode identifiers. The exclusive new features in 3.1 and 3.2 are less than they might have been because the developers expended extra effort, now ended, to backport new things developed for 3.x. (One result was some neglect of the stdlib, which is now the focus of efforts.) One reason was to make porting to 3.x easier should one wish to do so. The other reason was to make some thing available should one wish not to do so. Using that extra effort as a reason to put down 3.x is not very gracious. > There's no "killer app" for it. For some, unicode identifiers are 'killer reason' to use 3.1. Anyway, can you name me a "killer app" for each and every version of 2.x? > End of life for Python 2.x is many years away; Given that 1.x is still used, so what? > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? How can a business justify spending money on conversion to 2.0, 2,1, 2.2, 2.3, 2.4, 2.5, 2.6, or soon, 2.7? Some cannot for some projects and have not. Enough with strawman arguments against claims no sensible person has made. Python3 was developed for new Python programmers and current programmers who wished to add or switch. It was developed for new code and old code that would benefit from the changes. -- Terry Jan Reedy From darcy at druid.net Sat Jul 3 00:10:22 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 00:10:22 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <20100703001022.c8676aa6.darcy@druid.net> On 2 Jul 2010 15:00:17 -0700 aahz at pythoncraft.com (Aahz) wrote: > > 5. Get at least two major hosting services to put up Python 3. > > webfaction.com has python3.1 So does http://www.Vex.Net/ so there's your two. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From me+list/python at ixokai.io Sat Jul 3 01:31:36 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 22:31:36 -0700 Subject: Decorators, with optional arguments In-Reply-To: <4C2E361E.3080602@jollans.com> References: <4C2E24AD.3040002@ixokai.io> <4C2E361E.3080602@jollans.com> Message-ID: <4C2ECB38.9000504@ixokai.io> On 7/2/10 11:55 AM, Thomas Jollans wrote: > Looks good! You may still want to use functools.update_wrapper or > functools.wraps on "wrap". Are you sure? I've been doing a little bit of experimentation and I only did the 'wraps' on that inner function, because it seemed that it was all that was needed to get the propagation of function data I expected. I've since changed it to: def wrapper(fn, *args, **kwargs): print "Calling." result = fn(*args, **kwargs) print "Called." return result return decorator.decorator(wrapper, fn) Because the decorator library includes argspec propagation which was important for other parts of this code which does introspection. (This toy project is, I fully admit, going into very dark and evil places that I have at length advised people against, 'You don't want to do that!'). > PS: if you weren't stuck on 2.5, but were using 3.x, there's all kinds > of fun stuff you could do with function annotations ;-) Oh, believe me, I desperately wish I could go to 3.x. Between function annotations and the new metaclass power (Hi, __prepare__, I love you, please wait for me and I'll marry you when I migrate). I just can't yet. I can't quite figure out why people are all, '3.x brings you nothing'. Yes, the majority of the focus was cleaning, removing edges, but *lord* there's a LOT I am VERY looking forward to using. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sat Jul 3 01:37:00 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 02 Jul 2010 22:37:00 -0700 Subject: Decorators, with optional arguments In-Reply-To: References: Message-ID: <4C2ECC7C.5000107@ixokai.io> On 7/2/10 11:58 AM, Alf P. Steinbach /Usenet wrote: > > #Py3 I'm stuck on Python 2.x, as I mentioned (albeit only in a comment). That said this code does not seem to be including any Py3isms that aren't compatible. > class Thing(object): > @expose() > def test1(self, arg1): > return arg1 > > @expose( "testing" ) > def test2(self, arg2): > return arg2 Its the @expose() which bugs me. I have some decorators (made by me and others) which have no args, that look like @hello. Then some which always have args, that look like @hello("whatsup dude"). To then have a decorator which has no args as @hello(), I can't abide. For internal consistancy purposes, I want "no arguments" to always look like @hello, and "arguments" to look like @hello(something). I don't want to have to think, "Hey, does this no-arg version require parens or no?" -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From nagle at animats.com Sat Jul 3 01:40:34 2010 From: nagle at animats.com (John Nagle) Date: Fri, 02 Jul 2010 22:40:34 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4C2ECD52.5040005@animats.com> On 7/2/2010 9:10 PM, D'Arcy J.M. Cain wrote: > On 2 Jul 2010 15:00:17 -0700 > aahz at pythoncraft.com (Aahz) wrote: >>> 5. Get at least two major hosting services to put up Python 3. >> >> webfaction.com has python3.1 > > So does http://www.Vex.Net/ so there's your two. Not according to Vex's published package list: http://www.vex.net/info/tech/pkglist/ They list packages only for Python 2.6. "vex.net" isn't exactly a major hosting service. John Nagle From nanothermite911fbibustards at gmail.com Sat Jul 3 03:16:30 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Sat, 3 Jul 2010 00:16:30 -0700 (PDT) Subject: Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. A CHRISTIAN VIEW OF THE HOLOCAUST Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. It was made a short time ago before a large group in the Congressional `Room of the Willard Hotel in Washington, D.C. Both the speech and the question and answer period later so electrified the audience that a group of patriots has transferred it to two long-playing records which you may buy to play for friends, clubs, and your church group in your community. The speaker is Mr. Benjamin Freedman, noted authority on Zionism and all of its schemes. Mr. Freedman is a former Jew, and I mean a FORMER Jew. He has fought the Communist world conspiracy tooth and nail, and stands today as a leading American patriot. We now take you to the speaker's platform to present Benjamin Freedman. (applause) [Freedman's speech] What I intend to tell you tonight is something that you have never been able to learn from any other source, and what I tell you now concerns not only you, but your children and the survival of this country and Christianity. I'm not here just to dish up a few facts to send up your blood pressure, but I'm here to tell you things that will help you preserve what you consider the most sacred things in the world: the liberty, and the freedom, and the right to live as Christians, where you have a little dignity, and a little right to pursue the things that your conscience tells you are the right things, as Christians. Now, first of all, I'd like to tell you that on August 25th 1960 -- that was shortly before elections -- Senator Kennedy, who is now the President of the United States, went to New York, and delivered an address to the Zionist Organization of America. In that address, to reduce it to its briefest form, he stated that he would use the armed forces of the United States to preserve the existence of the regime set up in Palestine by the Zionists who are now in occupation of that area. In other words, Christian boys are going to be yanked out of their homes, away from their families, and sent abroad to fight in Palestine against the Christian and Moslem Arabs who merely want to return to their homes. And these Christian boys are going to be asked to shoot to kill these innocent [Arab Palestinians] people who only want to follow out fifteen resolutions passed by the United Nations in the last twelve years calling upon the Zionists to allow these people to return to their homes. Now, when United States troops appear in the Middle East to fight with the Zionists as their allies to prevent the return of these people who were evicted from their homes in the 1948 armed insurrection by the Zionists who were transplanted there from Eastern Europe... when that happens, the United States will trigger World War III. You say, when will that take place? The answer is, as soon as the difficulty between France and Algeria has been settled, that will take place. As soon as France and Algeria have been settled, that will take place. As soon as France and Algeria have settled their difficulty, and the Arab world, or the Moslem world, has no more war on their hands with France, they are going to move these people back into their homes, and when they do that and President kennedy sends your sons to fight over there to help the crooks hold on to what they stole from innocent men, women and children, we will trigger World War III; and when that starts you can be sure we cannot emerge from that war a victor. We are going to lose that war because there is not one nation in the world that will let one of their sons fight with us for such a cause. I know and speak to these ambassadors in Washington and the United Nations -- and of the ninety-nine nations there, I've consulted with maybe seventy of them -- and when we go to war in Palestine to help the thieves retain possession of what they have stolen from these innocent people we're not going to have a man there to fight with us as our ally. And who will these people have supporting them, you ask. Well, four days after President Kennedy -- or he was then Senator Kennedy -- made that statement on August 28, 1960, the Arab nations called a meeting in Lebanon and there they decided to resurrect, or reactivate, the government of Palestine, which has been dormant more or less, since the 1948 armed insurrection by the Zionists. Not only that... they ordered the creation of the Palestine Army, and they are now drilling maybe a half a million soldiers in that area of the world to lead these people back to their homeland. With them, they have as their allies all the nations of what is termed the Bandung Conference Group. That includes the Soviet Union and every Soviet Union satellite. It includes Red China; it includes every independent country in Asia and Africa; or eighty percent of the world's total population. Eighty percent of the world's population. Four out of five human beings on the face of the earth will be our enemies at war with us. And not alone are they four out of five human beings now on the face of this earth, but they are the non-Christian population of the world and they are the non-Caucasians... the non- white nations of the world, and that's what we face. And what is the reason? The reason is that here in the United States, the Zionists and their co-religionists have complete control of our government. For many reasons too many and too complex to go into here at this -- time I'll be glad to answer questions, however, to support that statement -- the Zionists and their co-religionists rule this United States as though they were the absolute monarchs of this country. Now, you say, 'well, that's a very broad statement to make', but let me show what happened while you were -- I don't want to wear that out --- let me show what happened while WE were all asleep. I'm including myself with you. We were all asleep. What happened? World War I broke out in the summer of 1914. Nineteen-hundred and fourteen was the year in which World War One broke out. There are few people here my age who remember that. Now that war was waged on one side by Great Britain, France, and Russia; and on the other side by Germany, Austria-Hungary, and Turkey. What happened? Within two years Germany had won that war: not alone won it nominally, but won it actually. The German submarines, which were a surprise to the world, had swept all the convoys from the Atlantic Ocean, and Great Britain stood there without ammunition for her soldiers, stood there with one week's food supply facing her -- and after that, starvation. At that time, the French army had mutinied. They lost 600,000 of the flower of French youth in the defense of Verdun on the Somme. The Russian army was defecting. They were picking up their toys and going home, they didn't want to play war anymore, they didn't like the Czar. And the Italian army had collapsed. Now Germany -- not a shot had been fired on the German soil. Not an enemy soldier had crossed the border into Germany. And yet, here was Germany offering England peace terms. They offered England a negotiated peace on what the lawyers call a status quo ante basis. That means: ?Let's call the war off, and let everything be as it was before the war started.? Well, England, in the summer of 1916 was considering that. Seriously! They had no choice. It was either accepting this negotiated peace that Germany was magnanimously offering them, or going on with the war and being totally defeated. While that was going on, the Zionists in Germany, who represented the Zionists from Eastern Europe, went to the British War Cabinet and -- I am going to be brief because this is a long story, but I have all the documents to prove any statement that I make if anyone here is curious, or doesn't believe what I'm saying is at all possible -- the Zionists in London went to the British war cabinet and they said: ?Look here. You can yet win this war. You don't have to give up. You don't have to accept the negotiated peace offered to you now by Germany. You can win this war if the United States will come in as your ally.? The United States was not in the war at that time. We were fresh; we were young; we were rich; we were powerful. They [Zionists] told England: ?We will guarantee to bring the United States into the war as your ally, to fight with you on your side, if you will promise us Palestine after you win the war.? In other words, they made this deal: ?We will get the United States into this war as your ally. The price you must pay us is Palestine after you have won the war and defeated Germany, Austria- Hungary, and Turkey.? Now England had as much right to promise Palestine to anybody, as the United States would have to promise Japan to Ireland for any reason whatsoever. It's absolutely absurd that Great Britain -- that never had any connection or any interest or any right in what is known as Palestine -- should offer it as coin of the realm to pay the Zionists for bringing the United States into the war. However, they made that promise, in October of 1916. October, nineteen hundred and sixteen. And shortly after that -- I don't know how many here remember it -- the United States, which was almost totally pro-German -- totally pro-German -- because the newspapers here were controlled by Jews, the bankers were Jews, all the media of mass communications in this country were controlled by Jews, and they were pro-German because their people, in the majority of cases came from Germany, and they wanted to see Germany lick the Czar. The Jews didn't like the Czar, and they didn't want Russia to win this war. So the German bankers -- the German-Jews -- Kuhn Loeb and the other big banking firms in the United States refused to finance France or England to the extent of one dollar. They stood aside and they said: ?As long as France and England are tied up with Russia, not one cent!? But they poured money into Germany, they fought with Germany against Russia, trying to lick the Czarist regime. Now those same Jews, when they saw the possibility of getting Palestine, they went to England and they made this deal. At that time, everything changed, like the traffic light that changes from red to green. Where the newspapers had been all pro-German, where they'd been telling the people of the difficulties that Germany was having fighting Great Britain commercially and in other respects, all of a sudden the Germans were no good. They were villains. They were Huns. They were shooting Red Cross nurses. They were cutting off babies' hands. And they were no good. Well, shortly after that, Mr. Wilson declared war on Germany. The Zionists in London sent these cables to the United States, to Justice Brandeis: ?Go to work on President Wilson. We're getting from England what we want. Now you go to work, and you go to work on President Wilson and get the United States into the war." And that did happen. That's how the United States got into the war. We had no more interest in it; we had no more right to be in it than we have to be on the moon tonight instead of in this room. Now the war -- World War One -- in which the United States participated had absolutely no reason to be our war. We went in there -- we were railroaded into it -- if I can be vulgar, we were suckered into -- that war merely so that the Zionists of the world could obtain Palestine. Now, that is something that the people in the United States have never been told. They never knew why we went into World War One. Now, what happened? After we got into the war, the Zionists went to Great Britain and they said: ?Well, we performed our part of the agreement. Let's have something in writing that shows that you are going to keep your bargain and give us Palestine after you win the war.? Because they didn't know whether the war would last another year or another ten years. So they started to work out a receipt. The receipt took the form of a letter, and it was worded in very cryptic language so that the world at large wouldn't know what it was all about. And that was called the Balfour Declaration. The Balfour Declaration was merely Great Britain's promise to pay the Zionists what they had agreed upon as a consideration for getting the United States into the war. So this great Balfour Declaration, that you hear so much about, is just as phony as a three dollar bill. And I don't think I could make it more emphatic than that. Now, that is where all the trouble started. The United States went in the war. The United States crushed Germany. We went in there, and it's history. You know what happened. Now, when the war was ended, and the Germans went to Paris, to the Paris Peace Conference in 1919, there were 117 Jews there, as a delegation representing the Jews, headed by Bernard Baruch. I was there: I ought to know. Now what happened? The Jews at that peace conference, when they were cutting up Germany and parceling out Europe to all these nations that claimed a right to a certain part of European territory, the Jews said, ?How about Palestine for us?? And they produced, for the first time to the knowledge of the Germans, this Balfour Declaration. So the Germans, for the first time realized, ?Oh, that was the game! That's why the United States came into the war.? And the Germans for the first time realized that they were defeated, they suffered this terrific reparation that was slapped onto them, because the Zionists wanted Palestine and they were determined to get it at any cost. Now, that brings us to another very interesting point. When the Germans realized this, they naturally resented it. Up to that time, the Jews had never been better off in any country in the world than they had been in Germany. You had Mr. Rathenau there, who was maybe 100 times as important in industry and finance as is Bernard Baruch in this country. You had Mr. Balin, who owned the two big steamship lines, the North German Lloyd's and the Hamburg-American Lines. You had Mr. Bleichroder, who was the banker for the Hohenzollern family. You had the Warburgs in Hamburg, who were the big merchant bankers -- the biggest in the world. The Jews were doing very well in Germany. No question about that. Now, the Germans felt: ?Well, that was quite a sellout.? It was a sellout that I can best compare -- suppose the United States was at war today with the Soviet Union. And we were winning. And we told the Soviet Union: ?Well, let's quit. We offer you peace terms. Let's forget the whole thing.? And all of a sudden Red China came into the war as an ally of the Soviet Union. And throwing them into the war brought about our defeat. A crushing defeat, with reparations the likes of which man's imagination cannot encompass. Imagine, then, after that defeat, if we found out that it was the Chinese in this country, our Chinese citizens, who all the time we thought they were loyal citizens working with us, were selling us out to the Soviet Union and that it was through them that Red China was brought into the war against us. How would we feel, in the United States against Chinese? I don't think that one of them would dare show his face on any street. There wouldn't be lampposts enough, convenient, to take care of them. Imagine how we would feel. Well, that's how the Germans felt towards these Jews. "We've been so nice to them"; and from 1905 on, when the first Communist revolution in Russia failed, and the Jews had to scramble out of Russia, they all went to Germany. And Germany gave them refuge. And they were treated very nicely. And here they sold Germany down the river for no reason at all other than they wanted Palestine as a so- called ?Jewish commonwealth.? Now, Nahum Sokolow -- all the great leaders, the big names that you read about in connection with Zionism today -- they, in 1919, 1920, '21, '22, and '23, they wrote in all their papers -- and the press was filled with their statements -- that "the feeling against the Jews in Germany is due to the fact that they realized that this great defeat was brought about by our intercession and bringing the United States into the war against them." The Jews themselves admitted that. It wasn't that the Germans in 1919 discovered that a glass of Jewish blood tasted better than Coca- Cola or Muenschner Beer. There was no religious feeling. There was no sentiment against those people merely on account of their religious belief. It was all political. It was economic. It was anything but religious. Nobody cared in Germany whether a Jew went home and pulled down the shades and said ?Shema' Yisrael? or ?Our Father.? No one cared in Germany any more than they do in the United States. Now this feeling that developed later in Germany was due to one thing: that the Germans held the Jews responsible for their crushing defeat, for no reason at all, because World War One was started against Germany for no reason for which they [Germans] were responsible. They were guilty of nothing. Only of being successful. They built up a big navy. They built up world trade. You must remember, Germany, at the time of Napoleon, at the time of the French Revolution, what was the German Reich consisted of 300 -- three hundred! -- small city-states, principalities, dukedoms, and so forth. Three hundred little separate political entities. And between that time, between the period of. . . between Napoleon and Bismarck, they were consolidated into one state. And within 50 years after that time they became one of the world's great powers. Their navy was rivalling Great Britain's, they were doing business all over the world, they could undersell anybody and make better products. And what happened? What happened as a result of that? There was a conspiracy between England, France, and Russia that: "We must slap down Germany", because there isn't one historian in the world that can find a valid reason why those three countries decided to wipe Germany off the map politically. Now, what happened after that? When Germany realized that the Jews were responsible for her defeat, they naturally resented it. But not a hair on the head of any Jew was harmed. Not a single hair. Professor Tansill, of Georgetown University, who had access to all the secret papers of the State Department, wrote in his book, and quoted from a State Department document written by Hugo Schoenfelt, a Jew who Cordell Hull sent to Europe in 1933 to investigate the so-called camps of political prisoners. And he wrote back that he found them in very fine condition. They were in excellent shape; everybody treated well. And they were filled with Communists. Well, a lot of them were Jews, because the Jews happened to be maybe 98 per cent of the Communists in Europe at that time. And there were some priests there, and ministers, and labor leaders, Masons, and others who had international affiliations. Now, the Jews sort of tried to keep the lid on this fact. They didn't want the world to really understand that they had sold out Germany, and that the Germans resented that. So they did take appropriate action against them [against the Jews]. They. . . shall I say, discriminated against them wherever they could? They shunned them. The same as we would the Chinese, or the Negroes, or the Catholics, or anyone in this country who had sold us out to an enemy and brought about our defeat. Now, after a while, the Jews of the world didn't know what to do, so they called a meeting in Amsterdam. Jews from every country in the world attended in July 1933. And they said to Germany: ?You fire Hitler! And you put every Jew back into his former position, whether he was a Communist, no matter what he was. You can't treat us that way! And we, the Jews of the world, are calling upon you, and serving this ultimatum upon you.? Well, the Germans told them. . . you can imagine. So what did they [the Jews] do? They broke up, and Samuel Untermyer, if the name means anything to people here. . . (You want to ask a question? --- Uh, there were no Communists in Germany at that time. they were called 'Social Democrats.) Well, I don't want to go by what they were called. We're now using English words, and what they were called in Germany is not very material. . . but they were Communists, because in 1917, the Communists took over Germany for a few days. Rosa Luxembourg and Karl Liebknecht, and a group of Jews in Germany took over the government for three days. In fact, when the Kaiser ended the war, he fled to Holland because he thought the Communists were going to take over Germany as they did Russia, and that he was going to meet the same fate that the Czar did in Russia. So he left and went to Holland for safety and for security. Now, at that time, when the Communist threat in Germany was quashed, it was quiet, the Jews were working, still trying to get back into their former -- their status -- and the Germans fought them in every way they could, without hurting a hair on anyone's head. The same as one group, the Prohibitionists, fought the people who were interested in liquor, and they didn't fight one another with pistols, they did it every way they could. Well, that's the way they were fighting the Jews in Germany. And, at that time, mind you, there were 80 to 90 million Germans and there were only 460,000 Jews. . . less than one half of one percent of Germany were Jews. And yet, they controlled all of the press, they controlled most of the economy, because they had come in and with cheap money -- you know the way the Mark was devalued -- they bought up practically everything. Well, in 1933 when Germany refused to surrender, mind you, to the World Conference of Jews in Amsterdam, they broke up and Mr. Untermeyer came back to the United States -- who was the head of the American delegation and the president of the whole conference -- and he went from the steamer to ABC and made a radio broadcast throughout the United States in which he said: "The Jews of the world now declare a Holy War against Germany. We are now engaged in a sacred conflict against the Germans. And we are going to starve them into surrender. We are going to use a world-wide boycott against them, that will destroy them because they are dependent upon their export business." And it is a fact that two thirds of Germany's food supply had to be imported, and it could only be imported with the proceeds of what they exported. Their labor. So if Germany could not export, two thirds of Germany's population would have to starve. There just was not enough food for more than one third of the population. Now in this declaration, which I have here, it was printed on page -- a whole page -- in the New York Times on August 7, 1933, Mr. Samuel Untermyer boldly stated that: ?this economic boycott is our means of self-defense. President Roosevelt has advocated its use in the NRA" . [National Recovery Administration] -- which some of you may remember, where everybody was to be boycotted unless they followed the rules laid down by the New Deal, which of course was declared unconstitutional by the Supreme Court at that time. Nevertheless, the Jews of the world declared a boycott against Germany, and it was so effective that you couldn't find one thing in any store anywhere in the world with the words "made in Germany" on it. In fact, an executive of the Woolworth Company told me that they had to dump millions of dollars worth of crockery and dishes into the river; that their stores were boycotted. If anyone came in and found a dish marked "made in Germany," they were picketed with signs: "Hitler", "murderer", and so forth, and like -- something like these sit-ins that are taking place in the South. R. H. Macy, which is controlled by a family called Strauss who also happen to be Jews. . . a woman found stockings there which came from Chemnitz, marked "made in Germany". Well, they were cotton stockings. They may have been there 20 years, because since I've been observing women's legs in the last twenty years, I haven't seen a pair with cotton stockings on them. So Macy! I saw Macy boycotted, with hundreds of people walking around with signs saying "MURDERS" and "HITLERITES", and so forth. Now up to that time, not one hair on the head of any Jew had been hurt in Germany. There was no suffering, there was no starvation, there was no murder, there was nothing. Now, that. . . naturally, the Germans said, "Why, who are these people to declare a boycott against us and throw all our people out of work, and our industries come to a standstill? Who are they to do that to us?" They naturally resented it. Certainly they painted swastikas on stores owned by Jews. Why should a German go in and give their money to a storekeeper who was part of a boycott who was going to starve Germany into surrender into the Jews of the world, who were going to dictate who their premier or chancellor was to be? Well, it was ridiculous. That continued for some time, and it wasn't until 1938, when a young Jew from Poland walked into the German embassy in Paris and shot one of the officials [a German official] that the Germans really started to get rough with the Jews in Germany. And you found them then breaking windows and having street fights and so forth. Now, for anyone to say that -- I don't like to use the word 'anti-Semitism' because it's meaningless, but it means something to you still, so I'll have to use it -- the only reason that there was any feeling in Germany against Jews was that they were responsible: number one, for World War One; number two, for this world-wide boycott, and number three -- did I say for World War One, they were responsible? For the boycott -- and also for World War II, because after this thing got out of hand, it was absolutely necessary for the Jews and Germany to lock horns in a war to see which one was going to survive. In the meanwhile, I had lived in Germany, and I knew that the Germans had decided [that] Europe is going to be Christian or Communist: there is no in between. It's going to be Christian or it's going to be Communist. And the Germans decided: "We're going to keep it Christian if possible". And they started to re-arm. And there intention was -- by that time the United States had recognized the Soviet Union, which they did in November, 1933 -- the Soviet Union was becoming very powerful, and Germany realized: "Well, our turn is going to come soon, unless we are strong." The same as we in this country are saying today, "Our turn is going to come soon, unless we are strong." And our government is spending 83 or 84 billion dollars of your money for defense, they say. Defense against whom? Defense against 40,000 little Jews in Moscow that took over Russia, and then, in their devious ways, took over control of many other governments of the world. Now, for this country to now be on the verge of a Third World War, from which we cannot emerge a victor, is something that staggers my imagination. I know that nuclear bombs are measured in terms of megatons. A megaton is a term used to describe one million tons of TNT. One million tons of TNT is a megaton. Now, our nuclear bombs have a capacity of 10 megatons, or 10 million tons of TNT. That was when they were first developed five or six years ago. Now, the nuclear bombs that are being developed have a capacity of 200 megatons, and God knows how many megatons the nuclear bombs of the Soviet Union have. So, what do we face now? If we trigger a world war that may develop into a nuclear war, humanity is finished. And why will it take place? It will take place because Act III. . . the curtain goes up on Act III. Act I was World War I. Act II was World War II. Act III is going to be World War III. The Jews of the world, the Zionists and their co-religionists everywhere, are determined that they are going to again use the United States to help them permanently retain Palestine as their foothold for their world government. Now, that is just as true as I am standing here, because not alone have I read it, but many here have read it, and it's known all over the world. Now, what are we going to do? The life you save may be your son's. Your boys may be on their way to that war tonight; and you you don't know it any more than you knew that in 1916 in London the Zionists made a deal with the British War Cabinet to send your sons to war in Europe. Did you know it at that time? Not a person in the United States knew it. You weren't permitted to know it. Who knew it? President Wilson knew it. Colonel House knew it. Other 's knew it. Did I know it? I had a pretty good idea of what was going on: I was liaison to Henry Morgenthau, Sr., in the 1912 campaign when President Wilson was elected, and there was talk around the office there. I was 'confidential man' to Henry Morgenthau, Sr., who was chairman of the Finance Committee, and I was liaison between him and Rollo Wells, the treasurer. So I sat in these meetings with President Wilson at the head of the table, and all the others, and I heard them drum into President Wilson's brain the graduated income tax and what has become the Federal Reserve, and also indoctrinate him with the Zionist movement. Justice Brandeis and President Wilson were just as close as the two fingers on this hand, and President Woodrow Wilson was just as incompetent when it came to determining what was going on as a newborn baby. And that's how they got us into World War I, while we all slept. Now, at this moment... at this moment they may be planning this World War III, in which we don't stand a chance even if they don't use nuclear bombs. How can the United States -- about five percent of the world -- go out and fight eighty to ninety percent of the world on their home ground? How can we do it... send our boys over there to be slaughtered? For what? So the Jews can have Palestine as their 'commonwealth'? They've fooled you so much that you don't know whether you're coming or going. Now any judge, when he charges a jury, says, "Gentlemen, any witness that you find has told a single lie, you can disregard all his testimony." That is correct. I don't know from what state you come, but in New York state that is the way a judge addresses a jury. If that witness said one lie, disregard his testimony. Now, what are the facts about the Jews? > > My Sig was missed > > http://www.youtube.com/watch?v=lX18zUp6WPY > > http://www.youtube.com/watch?v=XQapkVCx1HI > > http://www.youtube.com/watch?v=tXJ-k-iOg0M > > Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? > Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did > you release the 5 dancing Israelis compromising the whole 911 > investigation ? If the Dubai Police can catch Mossad Murderers and put > the videos and Iranian Police can why cant you put the Pentagon > Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and > puting on INTERNATIONAL MEDIA a day after catching him without > TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did > you have to LIE about Dr Afiya Siddiqui and torture that Innocent > little mother of 3 and smashing the skull of her one child ? > > http://www.youtube.com/watch?v=DhMcii8smxkhttp://www.youtube.com/watch?v=0SZ2lxDJmdg > > There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian > courts. > > FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but > only because he was a white. They got away with MURDER of thousands of > Non-whites in all parts of the world. > > Daily 911 news :http://911blogger.com > > http://www.youtube.com/watch?v=tRfhUezbKLw > > http://www.youtube.com/watch?v=x7kGZ3XPEm4 > > http://www.youtube.com/watch?v=lX18zUp6WPY On Jun 29, 9:31?am, nanothermite911fbibustards wrote: > On Jun 29, 5:24?am, "n... at bid.nes" wrote: > > > > > On Jun 26, 12:16?pm, nanothermite911fbibustards > > > wrote: > > > ? Let's talk about thermite. > > > ? Do you know anything about thermite? It's a powdered mixture of a > > metal oxide and another pure metal that, when raised to a specific > > minimum temperature, allows the metal to "steal" the oxygen from the > > metal oxide, evolving heat. Example, iron oxide loses its oxygen to > > aluminum, yielding aluminum oxide and metallic iron, plus heat. > > > ? Do you know what temperature it must be brought to in order to > > ignite it? > > > ? How do you propose the alleged "nanothermite" supposedly spread > > around the towers was raised to that temperature *simultaneously*? > > > ? Do you know what amount of heat (not temperature) a given mass of > > thermite can produce? > > > ? What amount of heat could the particles of your alleged > > "nanothermite" produce? Remember, each particle burns only as long as > > the oxide component can provide oxygen to the pure metal component of > > the thermite. > > > ? Mark L. Fergerson > > Spoook, All your QUESTIONS are answered in the papers by 911 truth > videos, by Dr Steven Jones and his VIDEOS !!! > > Go to st911.org and start looking !!! > > Go to 911blogger.com and start reading !!! > > Go to youtube and google for 911truth. > > They had military type wireless coordinated cutter charges that they > accessed from under the elevator shafts. One or all of CIA , MOSSAD , > Blackwater , Kroll etc may have been involved. > > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? > Wasn't Israeli attack and murder of US Soldiers and NSA employees on > USS Liberty covered up ? From smallpox911 at gmail.com Sat Jul 3 03:28:55 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 00:28:55 -0700 (PDT) Subject: The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. Message-ID: The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. Now, what are the facts about the Jews? The Jews -- I call them Jews to you, because they are known as Jews. I don't call them Jews. I refer to them as so-called Jews, because I know what they are. If Jesus was a Jew, there isn't a Jew in the world today, and if those people are Jews, certainly our Lord and Savior was not one of them, and I can prove that. Now what happened? The eastern European Jews, who form 92 per cent of the world's population of those people who call themselves Jews, were originally Khazars. They were a warlike tribe that lived deep in the heart of Asia. And they were so warlike that even the Asiatics drove them out of Asia into eastern Europe -- and to reduce this so you don't get too confused about the history of Eastern Europe -- they set up this big Khazar kingdom: 800,000 square miles. Only, there was no Russia, there were no other countries, and the Khazar kingdom was the biggest country in all Europe -- so big and so powerful that when the other monarchs wanted to go to war, the Khazars would lend them 40,000 soldiers. That's how big and powerful they were. Now, they were phallic worshippers, which is filthy. I don't want to go into the details of that now. It was their religion the way it was the religion of many other Pagans or Barbarians elsewhere in the world. Now, the [Khazar] king became so disgusted with the degeneracy of his kingdom that he decided to adopt a so-called monotheistic faith -- either Christianity, Islam -- the Moslem faith -- or what is known today as Judaism -- really Talmudism. So, like spinning a top and calling out "eeny, meeny, miney, moe," he picked out so-called Judaism. And that became the state religion. He sent down to the Talmudic schools of Pumbedita and Sura and brought up thousands of these rabbis with their teachings, and opened up synagogues and schools in his kingdom of 800,000 people -- 800,000 thousand square miles -- and maybe ten to twenty million people; and they became what we call Jews. There wasn't one of them that had an ancestor that ever put a toe in the Holy Land, not only in Old Testament history, but back to the beginning of time. Not one of them! And yet they come to the Christians and they ask us to support their armed insurrection in Palestine by saying: "Well, you want to certainly help repatriate God's chosen people to their Promised Land, their ancestral homeland, It's your Christian duty. We gave you one of our boys as your Lord and Savior. You now go to church on Sunday, and kneel and you worship a Jew, and we're Jews." Well, they were pagan Khazars who were converted just the same as the Irish [were converted]. And it's just as ridiculous to call them "people of the Holy Land," as it would be. . . there are 54 million Chinese Moslems. Fifty four million! And, Mohammed only died in 620 A.D., so in that time, 54 million Chinese have accepted Islam as their religious belief. Now imagine, in China, 2,000 miles away from Arabia, where the city of Mecca is located, where Mohammed was born. . . imagine if the 54 million Chinese called themselves 'Arabs'. Imagine! Why, you'd say they're lunatics. Anyone who believes that those 54 million Chinese are Arabs must be crazy. All they did was adopt as a religious faith; a belief that had its origin in Mecca, in Arabia. The same as the Irish. When the Irish became Christians, nobody dumped them in the ocean and imported from the Holy Land a new crop of inhabitants that were Christians. They weren't different people. They were the same people, but they had accepted Christianity as a religious faith. Now, these Pagans, these Asiatics, these Turko-Finns. . . they were a Mongoloid race who were forced out of Asia into eastern Europe. They likewise, because their king took the faith -- Talmudic faith -- they had no choice. Just the same as in Spain: If the king was Catholic, everybody had to be a Catholic. If not, you had to get out of Spain. So everybody -- they lived on the land just like the trees and the bushes; a human being belonged to the land under their feudal system -- so they [Khazars] all became what we call today, Jews! Now imagine how silly it was for the Christians. . . for the great Christian countries of the world to say, "We're going to use our power, our prestige to repatriate God's chosen people to their ancestral homeland, their Promised Land." Now, could there be a bigger lie than that? Could there be a bigger lie than that? And because they control the newspapers, the magazines, the radio, the television, the book publishing business, they have the ministers in the pulpit, they have the politicians on the soap boxes talking the same language . . . so naturally you'd believe black is white if you heard it often enough. You wouldn't call black black anymore -- you'd start to call black white. And nobody could blame you. Now, that is one of the great lies. . . that is the foundation of all the misery that has befallen the world. Because after two wars fought in Europe -- World War I and World War II -- if it wasn't possible for them to live in peace and harmony with the people in Europe, like their brethren are living in the United States, what were the two wars fought for? Did they have to -- like you flush the toilet -- because they couldn't get along, did they have to say, "Well, we're going back to our homeland and you Christians can help us"? I can't understand yet how the Christians in Europe could have been that dumb because every theologian, every history teacher, knew the things that I'm telling you. But, they naturally bribed them, shut them up with money, stuffed their mouths with money, and now. . . I don't care whether you know all this or not. It doesn't make any difference to me whether you know all these facts or not, but it does make a difference to me. I've got, in my family, boys that will have to be in the next war, and I don't want them to go and fight and die... like they died in Korea. Like they died in Japan. Like they've died all over the world. For what? To help crooks hold on to what they stole from innocent people who had been in peaceful possession of that land, those farms, those homes for hundreds and maybe thousands of years? Is that why the United States must go to war? Because the Democratic Party wants New York State -- the electoral vote? Illinois, the electoral vote? And Pennsylvania, the electoral vote?... which are controlled by the Zionists and their co-religionists?. . . the balance of power? In New York City there are 400,000 members of the liberal party, all Zionists and their co-religionists. And New York State went for Kennedy by 400,000 votes. Now, I don't blame Mr. Kennedy. I'm fond of Mr. Kennedy. I think he's a great man. I think he can really pull us out of this trouble if we get the facts to him. And I believe he knows a great deal more than his appointments indicate he knows. He's playing with the enemy. Like when you go fishing, you've got to play with the fish. Let 'em out and pull 'em in. Let 'em out and pull 'em in. But knowing Mr. Kennedy's father, and how well informed he is on this whole subject, and how close Kennedy is to his father, I don't think Mr. Kennedy is totally in the dark. But I do think that it is the duty of every mother, every loyal Christian , every person that regards the defense of this country as a sacred right, that they communicate -- not with their congressman, not with their senator, but with President Kennedy. And tell him, "I do not think you should send my boy, or our boys, wearing the uniform of the United States of America, and under the flag that you see here, our red, white and blue, to fight there to help keep in the hands of these that which they have stolen". I think everyone should not alone write once, but keep writing and get your friends to write. Now, I could go on endlessly, and tell you these things to support what I have just asked you to do. But I don't think it's necessary to do that. You're above the average group in intelligence and I don't think it's necessary to impress this any more. But. . . I want to tell you one more thing. You talk about... "Oh, the Jews. Why the Jews? Christianity. Why, we got Christianity from the Jews and the Jews gave us Jesus, and the Jews gave us our religion". But do you know that on the day of atonement that you think is so sacred to them, that on that day... and I was one of them! This is not hearsay. I'm not here to be a rabble-rouser. I'm here to give you facts. When, on the Day of Atonement, you walk into a synagogue, the very first prayer that you recite, you stand -- and it's the only prayer for which you stand -- and you repeat three times a short prayer. The Kol Nidre. In that prayer, you enter into an agreement with God Almighty that any oath, vow, or pledge that you may make during the next twelve months -- any oath, vow or pledge that you may take during the next twelve months shall be null and void. The oath shall not be an oath; the vow shall not be a vow; the pledge shall not be a pledge. They shall have no force and effect, and so forth and so on. And further than that, the Talmud teaches: "Don't forget -- whenever you take an oath, vow, and pledge -- remember the Kol Nidre prayer that you recited on the Day of Atonement, and that exempts you from fulfilling that". How much can you depend on their loyalty? You can depend upon their loyalty as much as the Germans depended upon it in 1916. And we're going to suffer the same fate as Germany suffered, and for the same reason. You can't depend upon something as insecure as the leadership that is not obliged to respect an oath, vow or pledge. Now I could go on and recite many other things to you, but I would have a little respect for your time, and you want to really, uh, get through with all of this. Tomorrow's going to be a long day. Now I want to say one thing. You ask me. . . well, you think to yourself: "well how did this fellow get mixed up in this the way he got mixed up in it." Well, I opened my mouth in 1945, and I took big pages in newspapers and tried to tell the American people what I'm telling you. And one newspaper after another refused the advertisement. And when I couldn't find a newspaper to take them -- I paid cash, not credit -- what happened? My lawyer told me, "There's an editor over in Jersey with a paper who will take your announcement". So, I was brought together with Mr. McGinley, and that's how I met him. So somebody told me the lawyer who introduced me, who was the son of the Dean of the Methodist Bishop, he said: "Well, I think he's a little anti-Semitic. I don't know whether I can get him over here. So he brought him over to my apartment and we hit it off wonderfully, and have since then. Now, I say this, and I say it without any qualifications. I say it without any reservations. And I say it without any hesitation. . . if it wasn't for the work that Mr. Conley McGinley did with "Common Sense" -- he's been sending out from 1,800,000 to 2,000,000 every year -- if it wasn't for the work he's been doing sending those out for fifteen years now, we would already be a communist country. Nobody has done what he did to light fires. Many of the other active persons in this fight learned all about if for the first time through "Common Sense". Now, I have been very active in helping him all I could. I'm not as flush as I was. I cannot go on spending the money. . . I'm not going to take up a collection. Don't worry. I see five people getting up to leave. (laughter) I haven't got the money that I used to spend. I used to print a quarter of a million of them out of my own pocket and send them out. Mr. McGinley, when I first met him, had maybe 5,000 printed and circulated them locally. So I said, "With what you know and what I know, we can really do a good job". So I started printing in outside shops of big newspaper companies, a quarter of a million, and paid for them. Well, there's always a bottom to the barrel. I suppose we've all reached that at times. I'm not so poor that I can't live without working and that's what worries the Anti-Defamation League. I can just get by without going and asking for a job or getting on the bread line. But Mr. McGinley is working. He's sick and he's going at this stronger than ever. And all I want to say is that they want to close up "Common Sense" more than any other single thing in the whole world, as a death-blow to the fight Christians are making to survive. So I just want to tell you this. All they do is circulate rumors: "Mr. Benjamin H. Freedman is the wealthy backer of 'Common Sense'." The reason they do that is to discourage the people in the United States: don't send any money to Common Sense. They don't need it. The've got the wealthy Mr. Freedman as a backer. That all has strategy. They don't want to advertise me so that people that have real estate or securities to sell will come and call on me. They just want people to lay off "Common Sense". And all I'm telling you is, I do try to help him, but I haven't been able to. And I will be very honest. One thing I won't do is lie. In the last year I've had so much sickness in my family that I could not give him one dollar. How he's managed to survive, I don't know. God alone knows. And he must be in God's care because how he's pulled through his sickness and with his financial troubles, I don't know. But that press is working. . . and every two weeks about a hundred or a hundred-fifty- thousand of "Common Sense" go out with a new message. And if that information could be multiplied. . . if people that now get it could buy ten or twenty five, or fifty, give them around. Plow that field. Sow those seeds, you don't know which will take root, but for God's sake, this is our last chance. [Freedman then discusses the importance of people forgoing unnecessary purchases to 'buy more stuff', play golf, etc., and use the money to keep "Common Sense" going. He explains that the paper is going in debt; could be closed down and he (Freedman) no longer has the funds, having spent some $2,400,000 in his attempt to bring the information to the American public and elected officials. He then asks for questions from the audience.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {Question inaudible] Freedman: All right, I'll comment on that. This is rather deep, but you all have a very high degree of intelligence, so I'm going to make an attempt. In the time of Bible history, there was a geographic area known as Judea. Judea was a province of the Roman Empire. Now, a person who lived in Judea was known as a Judean, and in Latin it was Judaeus; in Greek it was Judaius. Those are the two words, in Greek and Latin, for a Judean. Now, in Latin and Greek there is no such letter as 'j', and the first syllable of Judaeus and Judaius starts 'ghu'. Now, when the Bible was written, it was first written in Greek, Latin, Panantic, Syriac, Aramaic... all those languages. Never Was the word Jew in any of them because the word didn't exist. Judea was the country, and the people were Judeans, and Jesus was referred to only as a Judean. I've seen those early... the earliest scripts available. In 1345, a man by the name of Wycliffe in England thought that it was time to translate the Bible into English. There was no English edition of the Bible because who the Devil could read? It was only the educated church people who could read Latin and Greek, Syriac, Aramaic and the other languages. Anyhow, Wycliffe translated the Bible into English. But in it, he had to look around for some words for Judaeas and Judaius. There was no English word because Judea had passed out of existence. There was no Judea. People had long ago forgotten that. So in the first translation he used the word, in referring to Jesus, as 'gyu', "jew". At the time, there was no printing press. Then, between 1345 and the 17th century, when the press came into use, that word passed through so many changes... I have them all here. If you want I can read them to you. I will. That word 'gyu' which was in the Wycliffe Bible became. . . first it was ' gyu ', then ' giu ', then ' iu ' (because the ' i ' in Latin is pronounced like the ' j '. Julius Caesar is ' Iul ' because there is no 'j' in Latin) then ' iuw ', then ' ieuu ', then ' ieuy ', then ' iwe ', then ' iow ', then ' iewe ', all in Bibles as time went on. Then ' ieue ', then ' iue ', then ' ive ', and then ' ivw ', and finally in the 18th century... ' jew '. Jew. All the corrupt and contracted forms for Judaius, and Judaeas in Latin. Now, there was no such thing as 'Jew', and any theologian -- I've lectured in maybe 20 of the most prominent theological seminaries in this country, and two in Europe -- there was no such word as Jew. There only was Judea, and Jesus was a Judean and the first English use of a word in an English bible to describe him was 'gyu' -- Jew. A contracted and shortened form of Judaeus, just the same as we call a laboratory a 'lab', and gasoline 'gas'... a tendency to short up. So, in England there were no public schools; people didn't know how to read; it looked like a scrambled alphabet so they made a short word out of it. Now for a theologian to say that you can't harm the Jews, is just ridiculous. I'd like to know where in the scriptures it says that. I'd like to know the text. Look at what happened to Germany for touching Jews. What would you, as a citizen of the United States, do to people who did to you what the so-called Jews -- the Pollacks and Litvaks and Litzianers -- they weren't Jews, as I just explained to you. They were Eastern Europeans who'd been converted to Talmudism. There was no such thing as Judaism. Judaism was a name given in recent years to this religion known in Bible history as Torah [inaudible]. No Jew or no educated person ever heard of Judaism. It didn't exist. They pulled it out of the air. . . a meaningless word. Just like 'anti-Semitic'. The Arab is a Semite. And the Christians talk about people who don't like Jews as anti-Semites, and they call all the Arabs anti-Semites. The only Semites in the world are the Arabs. There isn't one Jew who's a Semite. They're all Turkothean Mongoloids. The Eastern european Jews. So, they brainwashed the public, and if you will invite me to meet this reverend who told you these things, I'll convince him and it'll be one step in the right direction. I'll go wherever I have to go to meet him. ~~~~~~~~~~~~~~~~~~~ Yes, ma'am. Well... I can answer that. First of all, your first premise is wrong. Your first premise that all the Jews are loyal to each other is wrong. Because, the Eastern European Jews outnumber all the rest by so many that they create the impression that they are the Jewish 'race'; that they are the Jewish nation; that they are the Jewish people. . . and the Christians swallow it like a cream puff. But in 1844 the German rabbis called a conference of rabbis from all over the world for the purpose of abolishing the Kol Nidre from the Day of Atonement religious ceremony. In Brunswick, Germany, where that conference was held in 1844, there was almost a terrific riot. A civil war. The Eastern Europeans said, "What the hell. We should give up Kol Nidre? That gives us our grip on our people. We give them a franchise so they can tell the Christians, 'Go to hell. We'll make any deal you want', but they don't have to carry it out. That gives us our grip on our people". So, they're not so united, and if you knew the feeling that exists. . . Now, I'll also show you from an official document by the man responsible for. . . uh, who baptized this race. Here is a paper that we obtained from the archives of the Zionist organization in New York City, and in it is the manuscript by Sir James A. Malcolm, who -- on behalf of the British Cabinet -- negotiated the deal with these Zionists. And in here he says that all the jews in England were against it. The Jews who had been there for years, the [inaudible - probably Sephardim], those who had Portuguese and Spanish ad Dutch ancestry... who were monotheists and believed in that religious belief. That was while the Eastern European Jews were still running around in the heart of Asia and then came into Europe. But they had no more to do with them than. . . can we talk about a Christian 'race'? or a Christian religion?... or are the Christians united? So the same disunity is among the Jews. And I'll show you in this same document that when they went to France to try and get the French government to back that Zionist venture, there was only one Jew in France who was for it. That was Rothschild, and they did it because they were interested in the oil and the Suez Canal ------------------------------------------------ [Question inaudible] Freedman: You know why? Because if they don't, they're decked up. They come around and they tell you how much you must give, and if you don't . . . oh, you're anti-Semitic. Then none of their friends will have anything to do with them, and they start a smear campaign. . . and you have got to give. In New York city, in the garment center, there are twelve manufacturers in the building. And when the drive is on to sell Israel Bonds, the United Jewish Drive, they put a big scoreboard with the names of the firms and opposite them, as you make the amount they put you down for, they put a gold star after the name. Then, the buyers are told, "When you come into that building to call on someone and they haven't got a gold star, tell them that you won't buy from them until they have the gold star". BLACKMAIL. I don't know what else you can call it. Then what do they do? They tell you it's for 'humanitarian purposes' and they send maybe $8 billion dollars to Israel, tax exempt, tax deductible. So if they hadn't sent that eight billion dollars to Israel, seven billion of it would have gone into the U.S. Treasury as income tax. So what happens? That seven billion dollars deficit -- that air pocket -- the gullible Christians have to make up. They put a bigger tax on gas or bread or corporation tax. Somebody has to pay the housekeeping expenses for the government. So why do you let these people send their money over there to buy guns to drive people out of their ancient homeland? And you say, "Oh, well. The poor Jews. They have no place to go and they've been persecuted all their lives". They've never been persecuted for their religion. And I wish I had two rows of Rabbis here to challenge me. Never once, in all of history, have they been persecuted for their religion. Do you know why the Jews were driven out of England? King Edward the First in 1285 drove them out, and they never came back until the Cromwell Revolution which was financed by the Rothschilds. For four- hundred years there wasn't a Jew. But do you know why they were driven out? Because in the Christian faith and the Moslem faith it's a sin to charge 'rent' for the use of money. In other words - what we call interest [usury] is a sin. So the Jews had a monopoly in England and they charged so much interest, and when the Lords and Dukes couldn't pay, they [Jews] foreclosed. And they were creating so much trouble that the king of England finally made himself their partner, because when they they came to foreclose, some of these dukes bumped off the Jews. . . the money-lenders. So the king finally said -- and this is all in history, look up Tianson [Tennyson?] or Rourke, the History of the Jews in England; two books you can find in your library. When the king found out what the trouble was all about, and how much money they were making, he declared himself a fifty-percent partner of the money lenders. Edward the First. And for many years, one-third of the revenues of the British Treasury came from the fifty-percent interest in money-lending by the Jews. But it got worse and worse. So much worse that when the Lords and Dukes kept killing the money-lenders, the King then said, "I declare myself the heir of all the money-lenders. If they're killed you have to pay me, because I'm his sole heir". That made so much trouble, because the King had to go out and collect the money with an army, so he told the Jews to get out. There were 15,000 of them, and they had to get out, and they went across to Ireland, and that's how Ireland got to be part of the United Kingdom. When King Edward found out what they were doing, he decided to take Ireland for himself before someone else did. He sent Robert Southgard with a mercenary army and conquered Ireland. So, show me one time where a Jew was persecuted in any country because of his religion. It has never happened. It's always their impact on the political, social, or economic customs and traditions of the community in which they settle. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Question inaudible] Freedman: Yes, sir. Well, they say most of those things themselves. It was unnecessary for Benjamin Franklin to say it. Most of those things they say themselves. But Benjamin Franklin observed, and by hearsay understood, what was happening in Europe. When Russia, in 920 was formed, and gradually surrounded the Khazar Kingdom, and absorbed them, most of the well-to-do Khazars fled to Western Europe and brought with them the very things to which you object and I object and a lot of other people object. The customs, the habits, the instincts with which they were endowed. When Benjamin Franklin referred to them as Jews because that's the name that they went by, and when the Christians first heard that these people who were fleeing from Russia -- who they were -- that they had practiced this Talmudic faith -- the Christians in Western Europe said, "They must be the remnants of the lost ten tribes!" And Mr. Grutz, the greatest historian amongst the Jews, said that -- and he's probably as good an authority on that subject as there is. So when Ben Franklin came to Europe in the 18th century, he already saw the results of what these people had done after they left their homeland. And every word of it is true... they say it themselves. I can give you half a dozen books they've written in which they say the same thing: When they have money they become tyrants. And when they become defeated, they become ruthless. They're only barbarians. They're the descendants of Asiatic Mongols and they will do anything to accomplish their purpose. What right did they have to take over Russia the way they did? The Czar had abdicated nine or ten months before that. There was no need for them. . . they were going to have a constitutional monarchy. But they didn't want that. When the constitutional monarchy was to assemble in November, they mowed them all down and established the Soviet Union. There was no need for that. But they thought, "Now is the time", and if you you will look in the Encyclopedia Britannica under the word 'Bolshevism', you'll find the five laws there that Lenin put down for a successful revolution. One of them is, "Wait for the right time, and then give them everything you've got". It would pay you to read that. You'd also find that Mr. Harold Blacktree, who wrote the article for the Encyclopedia Britannica states that the Jews conceived and created and cultivated the Communist movement. And that their energy made them the spearhead of the movement. Harold Blacktree wrote it and no one knew more about Communism than he. And the Encyclopedia Britannica for 25 years has been printing it. ~~~~~~~~~~~~~~~~~~~~~~~ [Question inaudible] Freedman: Well, I can't advocate that you do anything that's criminal, but I can tell you this. You can start what I call an endless chain. If you can get your friends to write, objectively, here is the statement: Mr. Kennedy's office gave me this himself. Mr. Smith, who succeeded Mr. Kennedy, took over his office -- was in his office -- and gave me this. He delivered this on the 25th, and it says here: "For release to AM (that means morning papers), August 25th". "Israel is here to stay. It is a national commitment, special obligation of the Democratic Party. The White House must take the lead. American intervention. We will act promptly and decisively against any nation in the Middle East which attacks its neighbor. I propose that we make clear to both Israel and the Arab states our guarantee that we will act with whatever force and speed are necessary to halt any aggression by any nation". Well, do you call the return of people to their homeland [the Arab Palestinians] aggression? Is Mr. Kennedy going to do that? Suppose three million Mexicans came into Texas and drove the six million Texans into the deserts of Arizona and New Mexico. Suppose these Mexicans were slipped in there armed -- the Texans were disarmed -- and one night they drove them all out of Texas and declared themselves the Republic of the Alamo. What would the United States say? Would we say it's aggression for these Texans to try to get their homes back from the Mexican thieves? Suppose the Negroes in Alabama were secretly armed by the Soviets and overnight they rose up and drove all the whites into the swamps of Mississippi and Georgia and Florida. . . drove them out completely, and declared themselves the Republic of Ham, or the Republic of something-or-other. Would we call it aggression if these people, the whites of Alabama, tried to go back to their homes? Would we. . . what would we think if the soviet Union said, "No, those Negroes now occupy them! Leave them there!", or "No, those Mexicans are in Texas. they declared themselves a sovereign state. Leave them there. You have plenty of room in Utah and Nevada. Settle somewhere else". Would we call it aggression if the Alabama whites or the Texans wanted to go back to their homes? So now, you've got to write to President Kennedy and say, "We do not consider it aggression in the sense that you use the word, if these people want to return to their homes as the United Nations -- fifteen times in the last twelve years -- called upon the Zionists in occupation of Palestine to allow the Arab Palestinians to return to their former homes and farms". [End of transcript of Benjamin Freedman speech, given in 1961 at the Willard Hotel in Washington, D.C., on behalf of Conde McGinley's patriotic newspaper of that time, Common Sense.] From smallpox911 at gmail.com Sat Jul 3 03:41:45 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 00:41:45 -0700 (PDT) Subject: SCHOLARLY TESTIMONIAL VIDEO : Joseph Moshe (MOSSAD Microbiologist) Swine flu vaccine 1 References: <74c18adb-e81f-4a79-948c-a55b253145c4@x21g2000yqa.googlegroups.com> Message-ID: Joseph Moshe (MOSSAD Microbiologist) Swine flu vaccine 1 http://www.youtube.com/watch?v=9ranNpzlXIo Part 1 Today, the MSM are not talking about this case any more. Yesterday, they wanted us to believe that Joseph Moshe was a nutcase and a terrorist, arrested for threatening to bomb the White House. Interesting detail about his arrest (the Westwood standoff) was that he seemed to be immune to the 5 cans of tear gas and 5 gallons of law- enforcement grade pepper spray they pumped into his face. He very calmly remained in his car, as the video footage of his arrest shows. Professor Moshe had called into a live radio show by Dr. A. True Ott, (explanation of Joseph Moshes call at 06:00) broadcast on Republic Broadcasting claiming to be a microbiologist who wanted to supply evidence to a States Attorney regarding tainted H1N1 Swine flu vaccines being produced by Baxter BioPharma Solutions. He said that Baxters Ukrainian lab was in fact producing a bioweapon disguised as a vaccine. He claimed that the vaccine contained an adjuvant (additive) designed to weaken the immune system, and replicated RNA from the virus responsible for the 1918 pandemic Spanish flu, causing global sickness and mass death. Joseph Moshe was soon after his arrest sent or let go to Israel. Nothing has been heard from him since. The Secret Service was not the agency involved in the surveillance of Moshe at his home in California. This was done by the FBI, who had orders to detain or arrest him. Mounted on top of a large black vehicle used in his arrest was a microwave weapon that possibly damaged the electronics in Moshes car as well as any communication devices he had which might have been used to contact the media or others who could help him. Baxter Pharmaceutical has been caught, red-handed, in spreading a live, genetically engineered H5N1 Bird flu vaccine as a lethal biological weapon all over the world, destined to be used for human vaccinations. This happened just a few months ago. Baxter International Inc. had mixed live, genetically engineered avian flue viruses in vaccine material shipped to 18 countries. Baxter knew full well that their vaccine was lethal, because the year before they had tested it on a few hundred homeless Polish people dozens died as a result. Qui bono? We think it may be profit-motivated, but for the conspiracy- minded: The latter complaint alludes to intentional culling of the herd. Have you heard of the Georgia Guidestones? An enormous monument loaded with Masonic symbolism costing millions of dollars, it has been erected by unknown, powerful elites (multimillionaires with the clout to erect monuments wherever they please, obviously) around 30 years ago. It gives an alternative ten commandments, of which the first is the extermination of six and a half billion people from the face of the Earth. Half a billion will remain. This is the number of people the planet can sustain indefinitely, so that the descendents of the Rothschilds and Rockefellers can live in peace and affluence indefinitely. Slaves are needed to produce that luxury, but 500 million will do just fine. But how does one go about killing off most of the world? Vaccinating the planet with a bioweapon with near-100% mortality would do the trick. Baxter would provide both the bioweapon as well as the vaccine against it to civilized Western peoples. Result: We can plunder Africa, we have no more competition from SE Asia, the oil is for our taking and only Western and perhaps Chinese sheeple remain. Rockefeller said this in 1994 at a U.N. dinner: We are on the verge of a global transformation. All we need is the right major crisis, and the nations will accept the New World Order. PNAC said something similar right before 9/11. A Spanish Doctor in Internal Medicine largely agrees with the above article: From kedra.marbun at gmail.com Sat Jul 3 04:59:06 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sat, 3 Jul 2010 01:59:06 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: if we limit our discussion to py: why __{get|set|delete}__ don't receive the 'name' & 'class' from __{getattribute|{set|del}attr}__ 'name' is the name that is searched 'class' is the class whose __dict__ has 'name' bound to descriptor delegator & delegator are terms from delegation pattern (oop) which is a specialized area of IoC delegate refers to helper obj, which is descriptor obj in the case of descriptor delegator is the obj that delegates task to helper obj oh crap, brazil lost, but i admit effort of the dutch is awesome if fifa['wc']['2010'].winner is not netherlands: raise SystemError #bugfix From bdesth.quelquechose at free.quelquepart.fr Sat Jul 3 05:06:31 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jul 2010 11:06:31 +0200 Subject: loading configuration files that are themselves python In-Reply-To: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <4c2f1920$0$23926$426a74cc@news.free.fr> Matthew Vernon a ?crit : > Hi, > > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere At least you have a way to do it, so you should be happy !-) Another solution would be to add the path to sys.path, but it wouldn't necessarily be the best thing to do here. From breamoreboy at yahoo.co.uk Sat Jul 3 05:08:04 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 03 Jul 2010 10:08:04 +0100 Subject: delegation pattern via descriptor In-Reply-To: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> Message-ID: On 02/07/2010 14:28, kedra marbun wrote: > hello, friendliest prog lang community on earth ;) Flattery will get you everywhere. > [snip] > > wow, it's almost time for brazil to beat the dutch, sorry Guido ;) > if fifa['wc']['2010'].winner is not brazil: raise SystemError Have you run this and get your SystemError yet? :) Kindest regards. Mark Lawrence From bdesth.quelquechose at free.quelquepart.fr Sat Jul 3 05:15:18 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 03 Jul 2010 11:15:18 +0200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c2f1b2f$0$17371$426a74cc@news.free.fr> kedra marbun a ?crit : > if we limit our discussion to py: > why __{get|set|delete}__ don't receive the 'name' & 'class' from > __{getattribute|{set|del}attr}__ > 'name' is the name that is searched While it would have been technically possible, I fail to imagine any use case for this. From matthew at debian.org Sat Jul 3 05:15:28 2010 From: matthew at debian.org (Matthew Vernon) Date: 03 Jul 2010 10:15:28 +0100 Subject: loading configuration files that are themselves python Message-ID: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Hi, Is there a more idiomatic way of loading in a configuration file that's python code than: _temp=__import__(path,fromlist='cachestrs') cachestrs=_temp.cachestrs ? I mean, that's pretty ugly...Plain "import" doesn't work in this case because 'path' is a variable defined elsewhere TIA, Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org From thomas at jollans.com Sat Jul 3 05:16:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 03 Jul 2010 11:16:19 +0200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C2EFFE3.7070109@jollans.com> On 07/03/2010 10:59 AM, kedra marbun wrote: > if we limit our discussion to py: > why __{get|set|delete}__ don't receive the 'name' & 'class' from > __{getattribute|{set|del}attr}__ > 'name' is the name that is searched > 'class' is the class whose __dict__ has 'name' bound to descriptor http://users.rcn.com/python/download/Descriptor.htm#descriptor-protocol descr.__get__(self, obj, type=None) --> value descr.__set__(self, obj, value) --> None descr.__delete__(self, obj) --> None These methods are passed the object they're operating on. If the name is in any way important, which is almost certainly is not, it can either be passed in to the constructor of the descriptor or determined by introspection. > > delegator & delegator are terms from delegation pattern (oop) which is > a specialized area of IoC > delegate refers to helper obj, which is descriptor obj in the case of > descriptor > delegator is the obj that delegates task to helper obj you are making no sense. > > oh crap, brazil lost, but i admit effort of the dutch is awesome > if fifa['wc']['2010'].winner is not netherlands: raise SystemError > #bugfix From __peter__ at web.de Sat Jul 3 05:46:03 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 03 Jul 2010 11:46:03 +0200 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: Matthew Vernon wrote: > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere execfile(path) in a module with a fixed name that you can import wherever you need access to your configuration data? Peter From antonyjeevaraj at rediffmail.com Sat Jul 3 05:50:01 2010 From: antonyjeevaraj at rediffmail.com (antonyjeevaraj at rediffmail.com) Date: Sat, 3 Jul 2010 02:50:01 -0700 (PDT) Subject: Make $1500 per month No sign up fee! Message-ID: Make $1500 per month No sign up fee! A new online money making program has been unleashed that is completely rocking the net. But free site sign ups have the best offer that Karen has for you. Setting up is 5minutes and in 15 minutes money is pouring to your account. This is why free site signup is the best money making site in the internet believe me: You get customercare support and they take you step by step in how to fully edit your website You get free wesite where you get products they have choosen for you if you are in the free site The best news is if you order the upgraded package you get 35 money making websites plus comlpete step by step on how to rank in the search engines When you sign up for the affiliate program the deal is so good. For every sale you make a cool $40 your for the keeping but if you upgrade for only $9 before you make your first sale you get to get $50 for each sale. FreeSiteSignUp is a service offering Cash Pulling Affiliate websites which enables you to have your own website business Live WITHOUT having to pay a single penny for the service... http://www.freesitesignup.com/a/coupon.php?id=3448 That is not the end, its made better than anything else out there, by making it possible to have the website up and running within 5 minutes along with necessary guidelines to fetch traffic for free. This conceptual masterpiece has already been PROVEN to be the This is how it works: Enter you personal details like email and names Free site sign up will build you a affiliate website and thats all you are ready to start. That is not the end, its made better than anything else out there, by making it possible to have the website up and running within 5 minutes along with necessary guidelines to fetch traffic for free. This conceptual masterpiece has already been PROVEN to be the best way to make money online, and the users who manage to get their hands on it are going to be at huge monetary benefits with an extra edge to their life. http://www.freesitesignup.com/a/coupon.php?id=3448 Not only you get a free website but also the guidance to get traffic to your website to fetch cash as soon as you have your business live. It's basically a cash machine which never sleeps and keeps w The sad news is the deal is almost gone because they are almost clossing there doors for free sitesA few places are remaining so hurry up http://www.freesitesignup.com/a/coupon.php?id=3448 From eliben at gmail.com Sat Jul 3 06:13:06 2010 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 3 Jul 2010 12:13:06 +0200 Subject: Sorting dicts inside dicts In-Reply-To: <4C2E93BC.5010309@mrabarnett.plus.com> References: <4C2E93BC.5010309@mrabarnett.plus.com> Message-ID: On Sat, Jul 3, 2010 at 03:34, MRAB wrote: > abhijeet thatte wrote: > >> Hi, >> I have a huge dict structure like below: >> >> /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> >> Module dict and reg_dicts contain many elements than shown. >> I want to sort this 'module' dictionary as per 'reg_addr' element in every >> 'reg_dict'. >> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0 >> can contain reg_address = 2000/72 (any number) >> I do not want output in a list format as the actual dict size is huge >> which I want to use based on key value pair. >> >> So, I want output as : >> >> >> /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/ >> /* >> */ >> >> Is it possible to sort the things? What I guess is Python stores dicts in >> a tree like structure but I am forcing it to store the way I want. Is it >> possible to do something like that. >> >> Python dicts are implemented as hash tables, not trees, for speed, and > they are unordered. > > If the order matters then you should use an ordered dict instead. You > should be able to find an implementation of one. > > The easiest way to find such an implementation is in the standard library of Python, starting with Python 3.1 (collections.OrderedDict) Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_re at fastmail.us Sat Jul 3 06:44:59 2010 From: john_re at fastmail.us (giovanni_re) Date: Sat, 03 Jul 2010 03:44:59 -0700 Subject: Join July Global Python meetings via VOIP - Free SW HW Culture Mtgs - BerkeleyTIP Message-ID: <1278153900.18707.1383107391@webmail.messagingengine.com> Watch some videos. Mark your calendar. Invite your friends. Join in on IRC or Voice. Join the mailing list, say "Hi. :)" ===== 1) 2010.7 Videos: Building the Python Community, Steve Holden, PyCon 2010 How Python, TurboGears, and MongoDB are Transforming SourceForge.net, Rick Copeland, PyCon Introducing Numpy Arrays, unpingco Motorola Droid Metro PCS Apps, makeitcricket.com How to write VOIP client in less then 2 minutes, rpdammu Open Wonderland virtual worlds platform, Nicole Yankelovich, iED How to Succeed in Mobile, Girl Geek Dinner, Kris Corzine Using KDE Marble to research your next vacation, Justin Kirby Schizophrenic Firewalls - virtualized net stack OpenBSD, Claudio Jeker Meet Google Founder Larry Page, Google Faculty Summit 2009 http://sites.google.com/site/berkeleytip/talk-videos/2010-7-videos == July Meetings - Mark your calendar: 3 Sat 12N-3P PST = 3-6P EST = 19-22 UTC 12 Mon 5 -6P PST = 8-9P EST = 0- 1 UTC Tues 13 18 Sun 12N-3P PST = 3-6P EST = 19-22 UTC 27 Tue 5 -6P PST = 8-9P EST = 0- 1 UTC Wed 28 ===== You're invited to join in with the friendly people at the BerkeleyTIP global meeting - newbie to Ph.D. - everyone is invited. Get a headset & join using VOIP online, or come to Berkeley. 1st step: Join the mailing list: http://groups.google.com/group/BerkTIPGlobal Watch the videos. Discuss them on VOIP. 10 great videos/talks this month. Join with us at the Golden Bear Cafe, Upper Sproul Plaza, UCB at the University of California at Berkeley, or join from your home via VOIP, or send this email locally, create a local meeting, & join via VOIP: Tip: a wifi cafe is a great place to meet. :) PLEASE VIEW THE BTIP WEBSITE & MAILING LIST FOR LATEST DETIALS. http://sites.google.com/site/berkeleytip BerkeleyTIP - Educational, Productive, Social For Learning about, Sharing, & Producing, All Free SW HW & Culture. TIP == Talks, Installfest, Project & Programming Party ===== CONTENTS: 1) 2010 JULY VIDEOS; 2) 2010 JULY MEETING DAYS, TIMES, LOCATIONS; 3) LOCAL MEETING AT U. C. Berkeley; 4) HOT TOPICS; 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) ; 6) INSTALLFEST; 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN; 8) IRC: #berkeleytip on irc.freenode.net; 9) VOIP FOR GLOBAL MEETING; 10) VOLUNTEERING, TO DOs; 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce; 12) ANYTHING I FORGOT TO MENTION?; 13) FOR FORWARDING ======================================================================= ===== 1) - See videos list at top of this email. Thanks to all the speakers, organizations, & videographers. :) [Please alert the speakers that their talks are scheduled for BTIP (if you are with the group that recorded their talk), because I may not have time to do that. Thanks. :) ] Download & watch these talks before the BTIP meetings. Discuss at the meeting. Email the mailing list, tell us what videos you'll watch & want to discuss. Know any other video sources? - please email me. _Your_ group should video record & post online your meeting's talks! ===== 2) 2010 JULY MEETING DAYS, TIMES, LOCATIONS http://sites.google.com/site/berkeleytip/schedule http://sites.google.com/site/berkeleytip/directions In person meetings on 1st Saturday & 3rd Sunday, every month. July 3 & 18, 12N-3P USA-Pacific time, Saturday, Sunday July 3 = Golden Bear Cafe, Upper Sproul Plaza, UCB July 18 = Free Speech Cafe, Moffitt Library, UCB Online only meeting using VOIP - 9 days after weekend meetings: July 12 & 27, 5-6P USA-Pacific time, Monday, Tuesday Mark your calendars. ===== 3) LOCAL MEETING AT U. C. BERKELEY http://sites.google.com/site/berkeleytip/directions RSVP please. See below. It greatly helps my planning. But, _do_ come if you forgot to RSVP. ALWAYS BE SURE TO CHECK THE BTIP WEBSITE _&_ MAILING LIST FOR THE LATEST LAST MINUTE DETAILS & CHANGES, BEFORE COMING TO THE MEETING! :) DO BRING A VOIP HEADSET, available for $10-30 at most electronics retail stores, & a laptop computer, so you are able to communicate with the global BTIP community via VOIP. It is highly recommended that you have a voip headset, & not rely on a laptop's built in microphone & speakers, because the headphones keep the noise level down. Bringing a headset is not required, but is a great part of the being able to communicate with the global community. :) Clothing: Typically 55-80 degrees F. Weather: http://www.wunderground.com/auto/sfgate/CA/Berkeley.html Other location local meeting possibilities: http://sites.google.com/site/berkeleytip/local-meetings Create a local meeting in your town. Invite your friends. :) ===== 4) HOT TOPICS Android phones - Besting iPhone? worthwhile? How knowable is the hw? iPad, iPhone4 & iPod- rooting & running GNU(Linux) Skype for group video conferencing? Open Wonderland virtual worlds platform ===== 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) If you think there is a >70% chance ("likely") you'll come to the in person meeting in Berkeley, please RSVP to me. Thanks. It helps my planning. Please _do_ come even if you haven't RSVP'd, it's not required. Better yet, join the BerkeleyTIP-Global mailing list, send the RSVP there, & tell us what things you're interested in, or what videos you'll try to watch - so we can know what videos are popular, & we might watch them too. :) http://groups.google.com/group/BerkTIPGlobal ===== 6) INSTALLFEST Get help installing & using Free Software, Hardware & Culture. Laptops only, typically. There isn't easy access for physically bringing desktop boxes here. RSVP _HIGHLY RECOMMENDED_ if you want installfest help. Please RSVP to me, Giovanni, at the from address for this announcement, or better, join & send email to the BTIP-Global mailing list telling us what you'd like help with. This way we can be better prepared to help you, & you might get valuable advice from the mailing list members. If you are new to using free software, an excellent system would be the KUbuntu GNU(Linux) software. It is very comprehensive, fairly easy to use (similar to Windows or Mac), & suitable for personal, home, university, or business use. We are also glad to try to help people with software who join via VOIP. Please email the mailing list with requests that you want help with, so we can try to be prepared better to help you. Installfest volunteers/helpers always welcome, in person, or via VOIP. :) ===== 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN If you get to the meeting & don't see a "BerkeleyTIP" sign up yet, please: 1) Make a BTIP sign on an 8x11 paper & put it at your table, 2) Email the mailing list, or join on IRC, & let us know you are there. Ask someone if you could use their computer for a minute to look something up, or send an email. People are usually very friendly & willing to help. We can also email you a temporary guest AirBears account login. We will have wifi guest accounts available for BTIP attendees. Be sure you have wifi capable equipment. Be Prepared: Bring a multi-outlet extension power cord. ===== 8) IRC: #berkeleytip on irc.freenode.net For help with anything, especially how to get VOIP working, & text communication. ===== 9) VOIP FOR GLOBAL MEETING Speak & listen to everyone globally using VOIP. Get a headset! See some VOIP instructions here: http://sites.google.com/site/berkeleytip/voice-voip-conferencing ===== 10) VOLUNTEERING, TO DOs Enjoy doing or learning something(s)? Help out BTIP in that area. Website development, mailing list management, video locating, VOIP server (FreeSwitch, Asterisk) or client (Ekiga, SFLPhone,...), creating a local meeting. Join the mailing list & let us know. Your offers of free help are always welcome here. :) ===== 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce Everyone should join the BerkeleyTIP-Global list: http://groups.google.com/group/BerkTIPGlobal Say "hi", tell us your interests, & what videos you'll like to watch. Info on all lists here: http://sites.google.com/site/berkeleytip/mailing-lists ===== 12) ANYTHING I FORGOT TO MENTION? Please join & email the BerkeleyTIP-Global mailing list. ===== 13) FOR FORWARDING You are invited to forward this message anywhere it would be appreciated. Better yet, use it to create a local meeting. Invite & get together with your friends locally, & join in with us all globally. :) Looking forward to meeting with you in person, or online. :) Giovanni == Join in the Global weekly meetings, via VOIP, about all Free SW HW & Culture http://sites.google.com/site/berkeleytip/ From matthew at debian.org Sat Jul 3 07:10:15 2010 From: matthew at debian.org (Matthew Vernon) Date: 03 Jul 2010 12:10:15 +0100 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <7j39w0zuty.fsf@rapun.sel.cam.ac.uk> Peter Otten <__peter__ at web.de> writes: > Matthew Vernon wrote: > > > Is there a more idiomatic way of loading in a configuration file > > that's python code than: > > > > _temp=__import__(path,fromlist='cachestrs') > > cachestrs=_temp.cachestrs > > > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > > case because 'path' is a variable defined elsewhere > > execfile(path) > > in a module with a fixed name that you can import wherever you need access > to your configuration data? That looks like what I want, thanks :) Matthew -- Rapun.sel - outermost outpost of the Pick Empire http://www.pick.ucam.org From nobody at nowhere.com Sat Jul 3 07:31:14 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 03 Jul 2010 12:31:14 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote: >> I think one point which needs to be emphasized more is what does >> python 3 bring to people. The" what's new in python 3 page" gives >> the impression that python 3 is about removing cruft. That's a very >> poor argument to push people to switch. > > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? If you're going to be doing a lot of Unicode text processing, I would expect that using Python 3 would make the task somewhat simpler. From darcy at druid.net Sat Jul 3 08:39:44 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 08:39:44 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4C2ECD52.5040005@animats.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <20100703083944.33d28746.darcy@druid.net> On Fri, 02 Jul 2010 22:40:34 -0700 John Nagle wrote: > Not according to Vex's published package list: > > http://www.vex.net/info/tech/pkglist/ As it says on that page it may not be up to date. Look at the generated list link. I guess I should update the static page as well. > "vex.net" isn't exactly a major hosting service. OK, I'll give you that. It is on the backbone of the net at 151 Front Street in Toronto, has almost 100% uptime and uses high speed servers but we don't have 15 layers of bureaucracy between the owner and the user and I certainly know of no "real" hosting provider that invites all their clients out for dinner once a year. And how can we be a real ISP when the president knows most of his clients on a first name basis? I know what being "major" means to the owners and stockholders but what features of being major matter to the client? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Sat Jul 3 08:46:57 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 08:46:57 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4C2ECD52.5040005@animats.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <20100703084657.af4b5700.darcy@druid.net> On Fri, 02 Jul 2010 22:40:34 -0700 John Nagle wrote: > Not according to Vex's published package list: > > http://www.vex.net/info/tech/pkglist/ Hold on. That *is* the generated list and Python 3.1 is on it. We have both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. The page is generated from pkg_info(1) and includes everything we have installed from FreeBSD ports. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at REMOVE-THIS-cybersource.com.au Sat Jul 3 10:24:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jul 2010 14:24:49 GMT Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> On Sat, 03 Jul 2010 08:46:57 -0400, D'Arcy J.M. Cain wrote: > On Fri, 02 Jul 2010 22:40:34 -0700 > John Nagle wrote: >> Not according to Vex's published package list: >> >> http://www.vex.net/info/tech/pkglist/ > > Hold on. That *is* the generated list and Python 3.1 is on it. We have > both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. > The page is generated from pkg_info(1) and includes everything we have > installed from FreeBSD ports. Pfft! Facts! You can prove anything you like with facts! -- Steven From inbox1.sudheer at gmail.com Sat Jul 3 10:33:49 2010 From: inbox1.sudheer at gmail.com (Sudheer) Date: Sat, 3 Jul 2010 10:33:49 -0400 Subject: subprocess query Message-ID: Hi, What's wrong with the following code. The program waits indefenitely at 'output = p2.stdout.read()' from subprocess import * p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) p1.stdin.write("hello") p1.stdin.close() output = p2.stdout.read() print output -- Thanks Sudheer From alf.p.steinbach+usenet at gmail.com Sat Jul 3 10:37:04 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 03 Jul 2010 16:37:04 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f4830$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 03.07.2010 16:24: > On Sat, 03 Jul 2010 08:46:57 -0400, D'Arcy J.M. Cain wrote: > >> On Fri, 02 Jul 2010 22:40:34 -0700 >> John Nagle wrote: >>> Not according to Vex's published package list: >>> >>> http://www.vex.net/info/tech/pkglist/ >> >> Hold on. That *is* the generated list and Python 3.1 is on it. We have >> both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 one. >> The page is generated from pkg_info(1) and includes everything we have >> installed from FreeBSD ports. > > Pfft! Facts! You can prove anything you like with facts! :-) -- blog at From clp2 at rebertia.com Sat Jul 3 10:39:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Jul 2010 07:39:40 -0700 Subject: subprocess query In-Reply-To: References: Message-ID: On Sat, Jul 3, 2010 at 7:33 AM, Sudheer wrote: > Hi, > ?What's wrong with the following code. The program waits indefenitely > at ?'output = p2.stdout.read()' > > > from subprocess import * > > p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) > p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) > p1.stdin.write("hello") > p1.stdin.close() > > output = p2.stdout.read() > > print output Try using .communicate() instead of reading and writing to .stdin and .stdout. Adding a newline (i.e. "hello\n") may also help. Cheers, Chris -- http://blog.rebertia.com From solipsis at pitrou.net Sat Jul 3 10:43:50 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 3 Jul 2010 16:43:50 +0200 Subject: Crash in PyThread_acquire_lock References: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Message-ID: <20100703164350.123bf02b@pitrou.net> Hello, > 'thelock->locked' is for sure still locked, but I can't identify the > problem. > Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the > crash > in PyThread_acquire_lock is the following one: > > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, &thelock- > >mut); <<<<<<<<<< Are you sure the crash happens in this thread and not another one? From aahz at pythoncraft.com Sat Jul 3 11:09:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Jul 2010 08:09:21 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Fri, 02 Jul 2010 22:40:34 -0700 >John Nagle wrote: >> >> "vex.net" isn't exactly a major hosting service. > >OK, I'll give you that. It is on the backbone of the net at 151 Front >Street in Toronto, has almost 100% uptime and uses high speed servers >but we don't have 15 layers of bureaucracy between the owner and the >user and I certainly know of no "real" hosting provider that invites >all their clients out for dinner once a year. And how can we be a real >ISP when the president knows most of his clients on a first name basis? vex.net is Canada's Panix. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From jjposner at optimum.net Sat Jul 3 11:14:17 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 03 Jul 2010 11:14:17 -0400 Subject: drag & drop in a python GUI application In-Reply-To: References: Message-ID: <4C2F53C9.4070104@optimum.net> On 7/2/2010 11:20 AM, Michael Torrie wrote: > On 07/01/2010 08:57 AM, Alan wrote: >> I know drag& drop is not possible with TK. > > Is this a Python Tk limitation or a Tk limitation in general? Google > suggests that Tk itself supports some form of dnd. > >> Which widget could I use for my >> python application to be able to work with drag& drop? > > PyQt will do drag and drop on all platforms. GTK does drag and drop on > Unix/X11, and to a lesser degree Win32--not sure about OS X support. I > believe wxWidgets also does some level of dnd on all platforms. Drag-and-drop *is* quite doable with Tkinter. But it's certainly easier in PyQt: self.setFlag(G.QGraphicsItem.ItemIsMovable, True) You can contact me off-list if you'd like to see a drag-and-drop application that I first wrote using Tkinter, then reimplemented using PyQt. HTH, John From darcy at druid.net Sat Jul 3 11:55:34 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 11:55:34 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f4830$0$28647$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f4830$0$28647$c3e8da3@news.astraweb.com> Message-ID: <20100703115534.ea95ec99.darcy@druid.net> On 03 Jul 2010 14:24:49 GMT Steven D'Aprano wrote: > Pfft! Facts! You can prove anything you like with facts! Argumentum ad Dragnet? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nagle at animats.com Sat Jul 3 12:48:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 03 Jul 2010 09:48:09 -0700 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> Message-ID: <4c2f69d6$0$1582$742ec2ed@news.sonic.net> On 7/3/2010 5:46 AM, D'Arcy J.M. Cain wrote: > On Fri, 02 Jul 2010 22:40:34 -0700 > John Nagle wrote: >> Not according to Vex's published package list: >> >> http://www.vex.net/info/tech/pkglist/ > > Hold on. That *is* the generated list and Python 3.1 is on it. We > have both 2.6 and 3.1. The 3.1 version is listed right below the 2.6 > one. The page is generated from pkg_info(1) and includes everything we > have installed from FreeBSD ports. The base Python 3.1 is installed there, but without any modules. Below is the list of Python 2.6 modules installed. Search that page for "py3", and you get nothing. On a hosting service, a raw Python with none of those modules isn't very useful. This is what I mean about Python 3 not being ready for prime time. John Nagle Python packages on Vex: py26-MySQLdb-1.2.2 Access a MySQL database through Python py26-PyGreSQL-4.0,1 A Python interface to PostgreSQL, both classic and DP-API 2.0 py26-gdbm-2.6.4 Python bindings to the GNU dbm library py26-psycopg-1.1.21_1 The high performance Python adapter for PostgreSQL py26-pyPgSQL-2.5.1_3 A Python DB-API 2 compliant library for using PostgreSQL databases py26-rrdtool_lgpl-1.0b1 Python interface to RRDTool, the graphing and logging utility py26-sqlite3-2.6.4_1 Standard Python binding to the SQLite3 library py26-asn1-0.0.9a_1 ASN.1 toolkit for Python py26-cElementTree-1.0.5_1 A fast C implementation of the ElementTree API py26-cheetah-2.2.1 HTML template engine for Python py26-elementtree-1.2.6_1 Container for hierarchical data structures written in Python py26-setuptools-0.6c11 Download, build, install, upgrade, and uninstall Python packages py26-statgrab-0.5 A set of Python bindings for libstatgrab py26-twisted-8.2.0 Metaport of Twisted, an event-driven networking engine py26-twistedCore-8.2.0 An asynchronous networking framework for Python - Core module py26-twistedFlow-8.0.0 Generator based asynchronous result flows py26-twistedRunner-8.2.0 Runner has process management, including an inetd replacement py26-zopeInterface-3.5.2 Zope.interface package from Zope 3 py26-twistedMail-8.2.0 An SMTP, IMAP and POP protocol implementation with clients and servers py26-twistedPair-8.0.0 Twisted Pair can do low level TCP work py26-twistedWords-8.2.0 Twisted Words has more chat than you can handle py26-snmp-3.4.4 SNMP framework for Python py26-twistedSNMP-0.3.13 Twisted Python framework for doing SNMP stuff news py26-twistedNews-8.2.0 An NNTP protocol implementation with client and server py26-fail2ban-0.8.3_2 scans log files and bans IP that makes too many password failures. py26-openssl-0.8_1 Python interface to the OpenSSL library py26-paramiko-1.7.6 A python library for making SSH2 connections py26-posix1e-0.4.0 Python module for manipulating POSIX.1e ACLs py26-pycrack-0.5.1 Python bindings to cracklib py26-pycrypto-2.1.0_1 The Python Cryptography Toolkit py26-twistedConch-8.2.0 An SSH and SFTP protocol implementation with clients and servers py26-docutils-0.5 Python Documentation Utilities py26-dsv-1.4.0 A Python module to parse or write delimeter-separated (e.g. CSV) files py26-twistedLore-8.2.0 Documentation generator with HTML and LaTeX support py26-xml-0.8.4_2 PyXML: Python XML library enhancements py26-cherrypy-3.1.2 A pythonic, object-oriented web development framework py26-django-1.1.1 High-level Python Web framework py26-flup-1.0.2 Random assortment of WSGI servers, middleware py26-twistedWeb-8.2.0 An HTTP protocol implementation together with clients and servers py26-twistedWeb2-8.1.0 The next generation Web Server Framework built with Twisted From rouslank at msn.com Sat Jul 3 13:22:39 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 13:22:39 -0400 Subject: My extension code generator for C++ Message-ID: It's still in the rough, but I wanted to give an update on my C++ extension generator. It's available at http://github.com/Rouslan/PyExpose The documentation is a little slim right now but there is a comprehensive set of examples in test/test_kompile.py (replace the k with a c. For some reason, if I post this message with the correct name, it doesn't show up). The program takes an input file like module doc string class doc string and generates the code for a Python extension. The goal has been to generate code with zero overhead. In other words I wanted to eliminate the tedium of creating an extension without sacrificing anything. In addition to generating a code file, the previous input would result in a header file with the following: extern PyTypeObject obj_DVectorType; inline PyTypeObject *get_obj_DVectorType() { return &obj_DVectorType; } struct obj_DVector { PyObject_HEAD storage_mode mode; std::vector > base; PY_MEM_NEW_DELETE obj_DVector() : base() { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(std::allocator const & _0) : base(_0) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(long unsigned int _0,double const & _1,std::allocator const & _2) : base(_0,_1,_2) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } obj_DVector(std::vector > const & _0) : base(_0) { PyObject_Init(reinterpret_cast(this),get_obj_DVectorType()); mode = CONTAINS; } }; so the object can be allocated in your own code as a single block of memory rather than having a PyObject contain a pointer to the exposed type. storage_type is an enumeration, adding very little to the size of the Python object (or maybe nothing depending on alignment), but if you add new-initializes="true" to the tag and the exposed type never needs to be held by a pointer/reference (as is the case when the exposed type is inside another class/struct), even that variable gets omitted. The code also never uses PyArg_ParseTuple or its variants. It converts every argument using the appropriate PyX_FromY functions. I noticed PyBindGen does the following when a conversion is needed for one argument: py_retval = Py_BuildValue((char *) "(O)", value); if (!PyArg_ParseTuple(py_retval, (char *) "i", &self->obj->y)) { Py_DECREF(py_retval); return -1; } Py_DECREF(py_retval); On the other hand, here's the implementation for __sequence__getitem__: PyObject * obj_DVector___sequence__getitem__(obj_DVector *self,Py_ssize_t index) { try { std::vector > &base = cast_base_DVector(reinterpret_cast(self)); return PyFloat_FromDouble(base.at(py_ssize_t_to_ulong(index))); } EXCEPT_HANDLERS(0) } (cast_base_DVector checks that base is initialized and gets a reference to it with regard to how it's stored in obj_DVector. If the class is new-initialized and only needs one means of storage, it's code will just be "return obj_DVector->base;" and should be inlined by an optimizing compiler.) I'm really interested in what people think of this little project. From urban.yoga.journeys at gmail.com Sat Jul 3 13:48:05 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Sat, 3 Jul 2010 10:48:05 -0700 (PDT) Subject: python app development Message-ID: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> an anyone recommend a resource (book,tutorial,etc.) that focuses on application development in python? something similar to Practical Django Projects, but for stand alone applications instead of web apps (for now). i'm in a bit of a funny place, i have a decent/good grasp of python syntax and my logic isn't bad, but i have no clue on how to assemble an application, i seem to be stuck on writing scripts. i've looked at the source of a few projects but the flow is way over my head, i understand the syntax but not the logic, which is why i'm looking for a project-cenetered learning resource, instead of a reference or language-feature resource. also, it seems that a lot of app programming is 90% gui bindings, with very little actual code, or am i totally way off mark? i recently picked up the django practical projects book, and in a few days i re-wrote a website i did with django. i feel it was the book's project-centric approach that made this possible. From thomas at jollans.com Sat Jul 3 13:54:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 03 Jul 2010 19:54:47 +0200 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: <4C2F7967.20908@jollans.com> On 07/03/2010 07:22 PM, Rouslan Korneychuk wrote: > It's still in the rough, but I wanted to give an update on my C++ > extension generator. It's available at http://github.com/Rouslan/PyExpose Question that pops to mind immediately: How does this differentiate itself from SWIG? ( I can't say I'm familiar with SWIG, but the question had to be posed. ) > > The documentation is a little slim right now but there is a > comprehensive set of examples in test/test_kompile.py (replace the k > with a c. For some reason, if I post this message with the correct name, > it doesn't show up). The program takes an input file like > > > > module doc string > > > class doc string > > > > > return-semantic="copy"/> func="operator[]" would also work, I assume? > > > > > and generates the code for a Python extension. > > [snip] > > I'm really interested in what people think of this little project. How does it deal with pointers? What if something returns a const pointer - is const correctness enforced? All in all, it looks rather neat. Thomas From post at andre-bell.de Sat Jul 3 14:02:25 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Sat, 03 Jul 2010 20:02:25 +0200 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <4C2F7B31.4010903@andre-bell.de> On 07/03/2010 07:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). I think you are referring to GUI applications. There are plenty of GUI Libraries out there. One of my favorites is the Qt library by Nokia (former by Trolltech) for which you can get python bindings PyQt and PySide. http://doc.qt.nokia.com/4.7-snapshot/index.html http://www.riverbankcomputing.co.uk http://www.pyside.org You might want to read through the tutorials given in the documentation at the Nokia site and possibly take a look at the examples provided with, e.g. PyQt. I'm sure other will add in more valuable links and suggestions. Best regards Andre From darcy at druid.net Sat Jul 3 14:22:38 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 3 Jul 2010 14:22:38 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <4c2f69d6$0$1582$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4C2ECD52.5040005@animats.com> <4c2f69d6$0$1582$742ec2ed@news.sonic.net> Message-ID: <20100703142238.33d1f51b.darcy@druid.net> On Sat, 03 Jul 2010 09:48:09 -0700 John Nagle wrote: > The base Python 3.1 is installed there, but without any modules. We install modules as clients ask for them. No one has yet requested a Python 3 module. > On a hosting service, a raw Python with none of those modules isn't > very useful. Well, it isn't useless. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From nanothermite911fbibustards at gmail.com Sat Jul 3 14:49:21 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Sat, 3 Jul 2010 11:49:21 -0700 (PDT) Subject: The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 d Message-ID: <2612aaa2-607c-40af-8021-943ec27e1d1a@i28g2000yqa.googlegroups.com> The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From tjreedy at udel.edu Sat Jul 3 15:02:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 Jul 2010 15:02:16 -0400 Subject: loading configuration files that are themselves python In-Reply-To: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: On 7/3/2010 5:15 AM, Matthew Vernon wrote: > Hi, > > Is there a more idiomatic way of loading in a configuration file > that's python code than: > > _temp=__import__(path,fromlist='cachestrs') > cachestrs=_temp.cachestrs > > ? I mean, that's pretty ugly...Plain "import" doesn't work in this > case because 'path' is a variable defined elsewhere cachestrs=__import__(path,fromlist='cachestrs').cachestrs ? -- Terry Jan Reedy From jyoung79 at kc.rr.com Sat Jul 3 15:29:51 2010 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Sat, 3 Jul 2010 14:29:51 -0500 Subject: drag & drop in a python GUI application Message-ID: <20100703192951.GPWAQ.101331.root@cdptpa-web27-z02> Hi Alan, What OS are you running on? And by 'drag and drop' are you meaning you want to drag and drop on a GUI window, or are you wanting a droplet where you can drop your file/folder on the application icon? Jay -- > Hello there, > I know drag & drop is not possible with TK. Which widget could > I use for my python application to be able to work with drag & > drop? > Thanks, > Alan From tjreedy at udel.edu Sat Jul 3 15:59:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 03 Jul 2010 15:59:00 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: On 7/3/2010 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. > > i've looked at the source of a few projects but the flow is way over > my head, i understand the syntax but not the logic, which is why i'm > looking for a project-cenetered learning resource, instead of a > reference or language-feature resource. also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? If the app is a gui app and if logic is overly intermixed with gui stuff, I am sure it can seem like that. Many recommend the MVC model-view-controller model for app design. Even that can be confusing; to me it should be model-controller-view, even though that is harder to say. What are the data (values and objects) and how are they stored? What are the rules for manipulating the data and objects? And then, and only then, how to communicate with the user? > > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. Another issue is who controls the flow of interactions, the user or the code. For instance, a gui form used for input tends to direct the user along a linear path. The same form, used for edit, presents existing data and allows the user to pick and choose the fields to edit. This distinction, along with MVC ideas, is important for reading source code. I have mostly seen this issue discussed in game reviews and game design writing. In computer games, there is the same general difference between a linear obstacle course game and a world to be explored in whatever order one wants. (And there are some with both an explorable world *and* a (somewhat optional) linear main quest line.) I am not familiar with any general app design books, but I have seen game design articles and books that are on a par with writing about web design. There are other books on business apps. -- Terry Jan Reedy From nobody at nowhere.com Sat Jul 3 16:11:41 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 03 Jul 2010 21:11:41 +0100 Subject: subprocess query References: Message-ID: On Sat, 03 Jul 2010 10:33:49 -0400, Sudheer wrote: > What's wrong with the following code. The program waits indefenitely > at 'output = p2.stdout.read()' > > > from subprocess import * > > p1=Popen(['tr', 'a-z', 'A-Z'],stdin=PIPE,stdout=PIPE) > p2=Popen(['tr','A-Z', 'a-z'],stdin=p1.stdout,stdout=PIPE) > p1.stdin.write("hello") > p1.stdin.close() > > output = p2.stdout.read() > > print output The problem is that p2 is inheriting Python's copy of the write end of the pipe corresponding to p1.stdin, which means that it's impossible to generate EOF on the pipe (i.e. p1.stdin.close() is a no-op): PID TTY STAT TIME COMMAND 30437 pts/1 S+ 0:00 /usr/bin/python2.6 ./test.py 30438 pts/1 S+ 0:00 tr a-z A-Z 30439 pts/1 S+ 0:00 tr A-Z a-z /proc/30437/fd: total 0 lrwx------ 1 user users 64 Jul 3 20:51 0 -> /dev/pts/1 lrwx------ 1 user users 64 Jul 3 20:51 1 -> /dev/pts/1 lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 lr-x------ 1 user users 64 Jul 3 20:51 3 -> pipe:[31472684] /proc/30438/fd: total 0 lr-x------ 1 user users 64 Jul 3 20:51 0 -> pipe:[31472681] <= *** l-wx------ 1 user users 64 Jul 3 20:51 1 -> pipe:[31472682] lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 /proc/30439/fd: total 0 lr-x------ 1 user users 64 Jul 3 20:51 0 -> pipe:[31472682] l-wx------ 1 user users 64 Jul 3 20:51 1 -> pipe:[31472684] lrwx------ 1 user users 64 Jul 3 20:51 2 -> /dev/pts/1 l-wx------ 1 user users 64 Jul 3 20:51 4 -> pipe:[31472681] <= *** On Unix, you can add close_fds=True when creating p2, but that won't work on Windows (it prevents redirection of stdin/stdout/stderr). OTOH, I don't know whether the problem exists on Windows; if it doesn't just set close_fds to True on Unix and False on Windows. Alternatively, on Unix you should be able to use: fcntl(fd, F_SETFD, FD_CLOEXEC) (from the fcntl module) to prevent the write end of the pipe from being inherited. Worse still, killing the script with Ctrl-C will leave both of the child processes behind. In C, you would typically close the unused ends of the pipes within the child half of the fork(), before the exec(), but you don't have that degree of control with subprocess. On Windows, you can chose whether a handle is inheritable or not, but I don't know whether you can do that from within Python. From rouslank at msn.com Sat Jul 3 16:46:00 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 16:46:00 -0400 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: On 07/03/2010 01:54 PM, Thomas Jollans wrote: > On 07/03/2010 07:22 PM, Rouslan Korneychuk wrote: >> It's still in the rough, but I wanted to give an update on my C++ >> extension generator. It's available at http://github.com/Rouslan/PyExpose > > Question that pops to mind immediately: How does this differentiate > itself from SWIG? ( I can't say I'm familiar with SWIG, but the question > had to be posed. ) > I have never tried swig, but as far as I understand, SWIG uses a layered approach where part of the extension is defined C/C++ and that is wrapped in Python code. Mine implements the extension completely in C++. >> >> The documentation is a little slim right now but there is a >> comprehensive set of examples in test/test_kompile.py (replace the k >> with a c. For some reason, if I post this message with the correct name, >> it doesn't show up). The program takes an input file like >> >> >> >> module doc string >> >> >> class doc string >> >> >> >> >> > return-semantic="copy"/> > > func="operator[]" would also work, I assume? > >> >> >> >> >> and generates the code for a Python extension. >> >> [snip] >> >> I'm really interested in what people think of this little project. > > How does it deal with pointers? What if something returns a const > pointer - is const correctness enforced? > When returning pointers or references, you either have to specify a conversion explicitly or use the "return-semantic" attribute. The current options are "copy", which dereferences the pointer and copies by value, and "managed-ref" which is for exposed classes, where the returned PyObject stores the value as a reference and holds on to a reference-counted pointer to the object the returned the value (there is also "self" which has nothing to do with returning pointers. With "self", the return value of the wrapped method is ignored and a pointer to the class is returned). I can easily add other options for "return-semantic", such as keeping a pointer and deleting it upon destruction. I just implemented the ones I need for the thing I'm working on. As far as returning const pointers and const correctness, I'm not sure exactly what you mean. If you mean is there a mechanism to hold on to const objects and prevent them form being modified, the answer is no. It's not something I need. > All in all, it looks rather neat. > > Thomas Thanks for the comment. From rouslank at msn.com Sat Jul 3 16:52:05 2010 From: rouslank at msn.com (Rouslan Korneychuk) Date: Sat, 03 Jul 2010 16:52:05 -0400 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: I missed one: >> func="operator[]" would also work, I assume? >> Yes, you can also supply a function if the first parameter accepts the type being wrapped (__rop__ methods will even accept the second parameter taking the wrapped type). From pauljefferson at gmail.com Sat Jul 3 18:01:31 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Sat, 3 Jul 2010 23:01:31 +0100 Subject: IMAP Problems Message-ID: Hi, I'm trying to write a simple script which displays the basic details of a person's mailbox. My problem is that it causes all the messages to be marked as read on the server, which is not what I'm after, and I also can't get the imap.sort command to work properly (currently commented out as I replaced it with a imap.search to get the thing working. These are probably very simple things, but I've not tried this library before so am a bit stuck so any help wwould be very gratefully received. Thanks, Paul Code: # -*- coding: cp1252 -*- import imaplib,email # you want to connect to a server; specify which server server= imaplib.IMAP4_SSL('imap.googlemail.com') # after connecting, tell the server who you are server.login('x... @gmail.com', 'xxxxxxx') # this will show you a list of available folders # possibly your Inbox is called INBOX, but check the list of mailboxes code, mailboxen= server.list() print mailboxen # if it's called INBOX, then? server.select("INBOX") typ, data = server.search(None, 'ALL') #typ, data = server.sort("Date","UTF-8", 'ALL') print len(data[0].split()) for num in data[0].split(): typ, data = server.fetch(num, '(RFC822)') #print 'Message %s\n%s\n' % (num, data[0][1]) msg = email.message_from_string(data[0][1]) print msg["From"] print msg["Subject"] print msg["Date"] print "_______________________________" server.close() server.logout() -------------- next part -------------- An HTML attachment was scrubbed... URL: From kylotan at gmail.com Sat Jul 3 18:12:04 2010 From: kylotan at gmail.com (Ben Sizer) Date: Sat, 3 Jul 2010 15:12:04 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator Message-ID: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> It seems that getiterator isn't returning the tags I ask for. >>> tree = parse('gdlibs.html') >>> root = tree.getroot() >>> for el in root.getiterator(): ... print el [much output snipped] >>> it = root.getiterator('script') >>> all_scripts = list(it) >>> print len(all_scripts) 0 I would have expected at least 2 script tags to be found, considering iterating over the whole lot found at least 2 at the end there. What am I doing wrong? >>> import sys >>> print sys.version 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] I will upgrade to 2.6.5 ASAP, but I don't see anything in the changelog that implies a bug that has been fixed here. -- Ben Sizer From kylotan at gmail.com Sat Jul 3 18:32:33 2010 From: kylotan at gmail.com (Ben Sizer) Date: Sat, 3 Jul 2010 15:32:33 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> Message-ID: <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> On Jul 3, 11:12?pm, Ben Sizer wrote: > >>> for el in root.getiterator(): > > ... ? ? ? ?print el > [much output snipped] > > > > Hmm, I think I've worked it out. Apparently the XML namespace forms part of the tag name in this case. Is that what is intended? I didn't see any examples of this in the docs. -- Ben Sizer From nathan.alexander.rice at gmail.com Sat Jul 3 18:36:06 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 3 Jul 2010 18:36:06 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: Expert Python Programming by Tarek Ziade is a fairly good book, covers a lot of core stuff, though it doesn't really cover gui app development at all. On Sat, Jul 3, 2010 at 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. > > i've looked at the source of a few projects but the flow is way over > my head, i understand the syntax but not the logic, which is why i'm > looking for a project-cenetered learning resource, instead of a > reference or language-feature resource. also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? > > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From smallpox911 at gmail.com Sat Jul 3 19:12:09 2010 From: smallpox911 at gmail.com (small Pox) Date: Sat, 3 Jul 2010 16:12:09 -0700 (PDT) Subject: Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards Message-ID: <16ef11cf-7b5a-470a-bea2-52e298ec2aaf@s9g2000yqd.googlegroups.com> Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards Watch Russian Spies in REAL TIME !!! - Video Evidence For Icompetento FBI Bustards http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html Russia Watched 9/11 In Real Time On Satellite By Jon Carlson Your countrymen have been murdered and the more you delve into it the more it looks as though they were murdered by our government, who used it as an excuse to murder other people thousands of miles away. If you ridicule others who have sincere doubts and who know factual information that directly contradicts the official report and who want explanations from those who hold the keys to our government, and have motive, means, and opportunity to pull off a 9/11, but you are too lazy or fearful, or ... to check into the facts yourself, what does that make you? Full Statement of Lt. Col. Shelton F. Lankford, US Marine Corps (ret) Retired U.S. Marine Corps Fighter Pilot February 20, 2007 http://www.patriotsquestion911.com/Statement%20Lankford.html In April, 2006, Journalist Webster Tarpley interviewed Thierry Meyssan, President of the Voltaire Network, an organization of 20 different news agencies in Europe, Middle East and Africa, with correspondents in many countries. Thierry trumped America's pseudo-journalists with his 2002 book, Pentagate, drawing first blood on the Pentagon 9/11 Hoax. TM:. He (Gen. Ivashov) was the chief of armed forces in Russia on 9/11. He says the Russian forces were watching North America because of the large military exercises being carried out by the US that day, so they saw in real time by satellite what was happening on that day. TM: When they heard about the attacks, Pres. Putin tried to call Bush to tell him that the Russians were not involved. He was not able to reach him. But they understood already that the collapse of the buildings could not have been done by the planes. They already realized it was controlled demolition - an internal problem and not an external attack WGT. How did US government, the State Dept respond to your (Pentagate) critique? TM. First they said I would not be allowed to go your country any more. Then Ms. Clark of State Dept said that if any journalist talks about my book in the US they will not be allowed to attend press conferences at the Pentagon. They published on their website a page trying to refute my book. http://www.waronfreedom.org/tarpley/rbn/RBN-42206-Meyssan.html In April, 2005, writer Chevalier D?sire?, from France but formerly USA, revealed that Russia watched on their satellite as the A3 Skywarrior left a carrier and impacted the Pentagon: It seems that it is common knowledge in these circles that Russian satellites photographed a ship-launched craft (seems to have been a drone type plane rather than a missle) that ended up impacting the Pentagon on Sept 11, 2001, and that, for various reasons this information has been withheld from the public. I was naturally startled to hear this even though I have long held the opinion that it was NOT a commercial jetliner that hit the Pentagon. I think the thing that startled me was the fact that, if Russia (and perhaps other countries with satellites?) had proof that Flight 77 did not hit the Pentagon, why weren't they revealing this? http://web.archive.org/web/20050728121017/http://perfectinfidel.blogspot.com/2005/04/david-beckham-and-flight-77-in-paris.html In 2002 some US spy satellite photos from the sixties were released to the public domain: "It's a welcome move," said Steven Aftergood of the Project on Government Secrecy, an effort of the Federation of American Scientists and based in Washington, D.C. "First and foremost, these images are of historical interest. They feature images of national security significance that served as an important input to the U.S. Government policy process. So they can help historians shed some light on that process," Aftergood told SPACE.com. Considering that the Pentagon STILL hasn't released over 80 videos of the Pentagon Hoax, release of the satellite photos of the 9/11 mass murder is not in the cards. In our last installment the strong case was made that aircraft carrier USS George Washington anchored off Long Island just a short helicopter ride from Manhattan served as base of operations for 9/11: The 9/11 Base Of Operations: Aircraft Carrier USS George Washington http://home.att.net/~south.tower/911AirBase1.htm Of course, a satellite image of the USS George Washington plying the waters off Long Island during the 9/11 mass murder would be the final nail in the coffin. SPOT Satellite Images of World Trade Center Fires on September 11 at 11:55 AM: http://www.globalsecurity.org/eye/html/wtc_nyc-091101-2.htm Image from NASA's Terra Satellite shows the fire plume from Manhattan: http://www.globalsecurity.org/eye/html/wtc_modis-0912_redplumex500.htm NASA's Terra Satellite True-Color Image, taken Sept. 12, 2001: http://www.globalsecurity.org/eye/html/wtc_0913_ny_true.htm International Space Station still image, taken from video sent from the International Space Station September 11, 2001: http://www.globalsecurity.org/eye/html/wtc_074602b1.htm The Space Station website has several more 9/11 photos taken with just a video camera all following the pattern of CROPPING OUT THE AREA THE AIRCRAFT CARRIER USS GEORGE WASHINGTON IS ANCHORED. NASA is a branch of the US Navy, the kingpin of 9/11. http://spaceflight.nasa.gov/gallery/images/station/crew-3/in-flight/ndxpage6.html On 9/16/01, USA Today reported the presence of the USS George Washington: "The Pentagon refuses to say how many aircraft, ships and troops are defending U.S. territory or where they are ? even after TV cameras showed the carrier USS George Washington off New York". http://www.usatoday.com/news/nation/2001/09/16/military-home-front.htm The Jersey Girls want to Raise More Hell on Capitol Hill about 9/11 Truth. Many signers to their petition are leaving short, interesting comments. http://www.petitiononline.com/july10/ Drunken Bush Hurls Vile Insult At Wife (In Public) http://www.rense.com/general75/drunken.htm Edgar J. Steele's lucid and entertaining writing style lays the wood on Bush 9/11 and other crimes: We Hung the Wrong Guy! http://www.conspiracypenpal.com/rants/hung.htm MP Galloway Blasts Organized Attacks On Heroic Chavez http://www.rense.com/general75/cahv.htm As most MSM writers have no practical political party experience and are merely entertainers with no journalistic standards, most of what they say can be taken with a grain of salt. Former GOP insider Karl Schwarz has analyzed the state of American policies that are turning the US into the most hated country in the world even by Americans. Karl's views will be supported by most intelligent Americans: A Platform for America http://www.rense.com/general74/true.htm BBC Photos Corroborate A3 Skywarrior 9/11 Pentagon Hit http://home.att.net/~south.tower/BBCA3photos1.htm Latest analysis of the Pentagon Doubletree Video corroborates that a substitute A3 Skywarrior struck the Pentagon: The Doubletree Hotel 9/11 Pentagon Video http://home.att.net/~south.tower/KCDoubletree1.htm INVESTIGATOR Karl Schwarz was the originator of Intelligence that an A3 SKYWARRIOR, not a Flight AA77 Boeing 757 airliner, HIT THE PENTAGON ON 9/11. Now Karl tells the rest of the story: WHAT HIT THE PENTAGON? By Karl Schwarz http://home.att.net/~carlson.jon/911Pentagon.htm EXCLUSIVE 9/11 Pentagon A3 Skywarrior Wreckage Photos http://home.att.net/~carlson.jon/PentagonA3wreckage1.htm FBI Hides 911 Pentagon Hoax A3 Skywarrior Fuselage, Engine, & 9/11 Truth http://home.att.net/~carlson.jon/FBIHidesA3.htm CNN, Pentagon Videos Expose 9/11 White Jet & Helicopter http://home.att.net/~carlson.jon/Pentagonhelicopter.htm Smoking Gun Photos SHUT 9/11 Pentagon Coffin http://home.att.net/~carlson.jon/coffin.htm 9/11 A3 Skywarrior Wing Impact Caused Pentagon Fire Truck Fire http://home.att.net/~carlson.jon/A3firetruck.htm Rare German Photos Expose 911 Pentagon Hoax http://www.rense.com/general70/3o.htm Of course, DON'T MISS more 9/11 photos and analysis: The 9/11 Base Of Operations: Aircraft Carrier USS George Washington http://home.att.net/~south.tower/911AirBase1.htm Original WTC Design Document Spills NIST 9/11 Demolition Beans http://home.att.net/~south.tower/NISTdemolition1.htm The Flight Of The South Tower Drone Engine http://home.att.net/~south.tower/STengineroute1.htm A Close Look: The North Tower Napalm Bomb http://home.att.net/~south.tower/NTnapalmbombs1.htm CBS Video Shows Military Helicopter Leaving At South Tower Demolition http://home.att.net/~south.tower/STdemolition1.htm CNN Photos Catch South Tower 9/11 Show Director White Jet http://home.att.net/~south.tower/STWhiteJet1.htm Pentagon 9/11 Flight AA77 Left Telltale Engine http://home.att.net/~south.tower/PentagonWrongEngine1.htm Dirty Little 9/11 Secrets Exposed II http://home.att.net/~south.tower/KCDirtyLittle911SecretsII1.htm The 9/11 Keystone Cops Crime The Pavel Hlava Video http://home.att.net/~south.tower/KCPavelHlava1.htm The 9/11 Keystone Cops Crime The Missing Bush I Alibi http://home.att.net/~south.tower/KCBushIalibi1.htm The 9/11 Nutshell Timeline http://home.att.net/~south.tower/911NutshellTimeline1.htm North Tower Napalm Bombs: Two Misses, Two Duds http://home.att.net/~south.tower/NTnapalm1.htm South Tower Flight UA175 Dropped WRONG Engine In NYC Street http://home.att.net/~south.tower/STengine1.htm The NBC News Helicopter Views The South Tower Napalm Bomb http://home.att.net/~south.tower/NBCnapalmbomb10th1.htm The South Tower Crash Videos: COMMON ELEMENTS http://home.att.net/~carlson.jon/STCommonElements1.htm The South Tower Napalm Bomb SEVENTH VIEW http://home.att.net/~carlson.jon/WTCnapalmbomb7th1.htm The South Tower Napalm Bomb SIXTH VIEW http://home.att.net/~carlson.jon/WTCnapalmbomb6th1.htm The South Tower Napalm Bomb FIVE VIEWS http://home.att.net/~carlson.jon/ST5views.htm A CLOSE LOOK: The 9/11 Pentagon TARGET WALL http://home.att.net/~carlson.jon/Pentagondemolition1.htm CNN, Pentagon Videos Expose 9/11 White Jet & Helicopter http://home.att.net/~carlson.jon/Pentagonhelicopter.htm Smoking Gun Photos SHUT 9/11 Pentagon Coffin http://home.att.net/~carlson.jon/coffin.htm 9/11 A3 Skywarrior Wing Impact Caused Pentagon Fire Truck Fire http://home.att.net/~carlson.jon/A3firetruck.htm FBI Hides 911 Pentagon Hoax A3 Skywarrior Fuselage, Engine, & 9/11 Truth http://home.att.net/~carlson.jon/FBIHidesA3.htm Rare German Photos Expose 911 Pentagon Hoax http://www.rense.com/general70/3o.htm Karl Schwarz gives his insight http://www.rense.com/general70/more.htm On 911 An Ill Wind Blew Clinton To Australia: http://www.rense.com/general69/on911.htm Pentagon 9/11 Blue Tarp Photo Uncovered http://www.rense.com/general70/tarp.htm Showtime - Look Inside The 911 Smoke Plume http://www.rense.com/general69/show911.htm 911 Timeline Missing Pieces http://www.rense.com/general69/911ms.htm Hunt The Cherokee - The 9/11 Pentagon Impact http://www.rense.com/general69/hunt911.htm The 911 North Tower Air Show http://www.rense.com/general69/911hh.htm Professor Jones Teaches Tucker About 911 http://www.rense.com/general68/911nul.htm German Intel Agent Von Bulow Solves 9/11 http://www.rense.com/general68/911jh.htm Positive ID: The 9/11 South Tower Airliner 'PODS' http://www.rense.com/general68/poss911.htm FBI Claims 84 Videos Show NO Flight 77 Impact http://www.rense.com/general67/fbicl.htm 9/11 Flight 93 Passengers 'Lost' http://www.rense.com/general67/911pass.htm The 9/11 Pentagon Engine Story http://www.rense.com/general67/911eng.htm The 911 North Tower Demolition Explained http://www.rense.com/general67/9118.htm The Rest Of The 911 Flight 93 Story http://www.rense.com/general67/rest911.htm South Tower Exit Wounds Tell 9/11 Tale http://www.rense.com/general67/911uu.htm Dirty Little 9/11 Secrets Exposed http://www.rense.com/general66/dirt.htm Bush Responds To 911 Fireworks http://www.rense.com/general66/ressp.htm Hollywood-like Fake Smoke Made 9/11 http://www.rense.com/general65/911mir.htm WTC 7 Smoke & Mirrors On 9/11 http://www.rense.com/general65/911m.htm CBC 9/11 Video Secrets Revealed http://www.rense.com/general65/911b.htm 911 CNN Reports Boeing 737s Struck WTC http://www.rense.com/general65/911h.htm Sneak Preview - 911 Pentagon Tapes http://www.rense.com/general64/911et.htm The Rest Of The 9/11 Street Engine Story http://www.rense.com/general64/wth.htm NYC Photos, Flight 93 Witnesses Identify 9/11 White Jet http://www.rense.com/general64/white.htm On 9/11 An Ill Wind Blew to Booker School http://www.rense.com/general63/wte.htm WTC Jet Engine Confirmed NOT From Boeing 767 http://www.rense.com/general63/wtcc.htm Second 911 Remote Control Antenna Verified http://www.rense.com/general63/secnd.htm Avionics Expert-A 911 Remote Control Lesson for PM http://www.rense.com/general63/remo.htm WTC Cutter Charges Clearly Visible http://www.rense.com/general63/cutt.htm Real 911 Science For PM - The ST Airliner Photo http://www.rense.com/general63/st.htm PM Claims Landing Gear Made Pentagon 12 Foot Hole http://www.rense.com/general63/pmm.htm PM Missed NASA 911-type Airliner Crash 20 Years Ago http://www.rense.com/general63/pm.htm Is Popular Mechanics Hiding 911 NYC Engine In Street Photo? http://www.rense.com/general63/hiding.htm Missing Pentagon Jet Engine Identified? http://www.rense.com/general63/ident.htm Missing Pentagon Unobstructed Citgo Videos http://www.rense.com/general63/unob.htm From python at mrabarnett.plus.com Sat Jul 3 19:28:57 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 04 Jul 2010 00:28:57 +0100 Subject: IMAP Problems In-Reply-To: References: Message-ID: <4C2FC7B9.5070706@mrabarnett.plus.com> Paul Jefferson wrote: > Hi, > I'm trying to write a simple script which displays the basic details > of a person's mailbox. My problem is that it causes all the messages > to be marked as read on the server, which is not what I'm after, and > I also can't get the imap.sort command to work properly (currently > commented out as I replaced it with a imap.search to get the thing > working. > These are probably very simple things, but I've not tried this library > before so am a bit stuck so any help wwould be very gratefully > received. > Thanks, > Paul > > Code: > > # -*- coding: cp1252 -*- > import imaplib,email > > # you want to connect to a server; specify which server > server= imaplib.IMAP4_SSL('imap.googlemail.com > ') > # after connecting, tell the server who you are > server.login('x... > @gmail.com > ', 'xxxxxxx') > # this will show you a list of available folders > # possibly your Inbox is called INBOX, but check the list of mailboxes > code, mailboxen= server.list() > print mailboxen > # if it's called INBOX, then? > server.select("INBOX") > > typ, data = server.search(None, 'ALL') > #typ, data = server.sort("Date","UTF-8", 'ALL') > print len(data[0].split()) > for num in data[0].split(): > typ, data = server.fetch(num, '(RFC822)') > #print 'Message %s\n%s\n' % (num, data[0][1]) > msg = email.message_from_string(data[0][1]) > print msg["From"] > print msg["Subject"] > print msg["Date"] > print "_______________________________" > > server.close() > server.logout() > You might want to read what it says here: http://tools.ietf.org/html/rfc2060.html#page-41 If you can use '(BODY[])' instead of '(RFC822)' then you could use '(BODY.PEEK[])'. Alternatively, try: server.store(num, '-FLAGS', r'\Seen') to mark it as unread after fetching. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:23:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:23:21 +1200 Subject: [farther OT] Re: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Rami Chowdhury wrote: > I'm sorry, perhaps you've misunderstood what I was refuting. You posted: >> >> macro: >> >> #define Descr(v) &v, sizeof v >> >> >> >> As written, this works whatever the type of v: array, struct, >> >> whatever. > > With my code example I found that, as others have pointed out, > unfortunately it doesn't work if v is a pointer to a heap-allocated area. It still correctly passes the address and size of that pointer variable. It that?s not what you intended, you shouldn?t use it. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:25:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:25:46 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Robert Kern wrote: > On 2010-06-25 19:47 , Lawrence D'Oliveiro wrote: > >> In message, Cameron >> Simpson wrote: >> >>> On 25Jun2010 15:38, Lawrence >>> D'Oliveiro wrote: >>> >>> | In message<2010062422432660794-angrybaldguy at gmailcom>, Owen Jacobson >>> | wrote: >>> >>> |> Why would I write this when SQLAlchemy, even without using its ORM >>> |> features, can do it for me? >>> | >>> | SQLAlchemy doesn?t seem very flexible. Looking at the code examples >>> |, they?re very >>> |procedural: build object, then do a string of separate method calls to >>> |add data to it. I prefer the functional approach, as in my table-update >>> |example. >>> >>> He said "without using its ORM". >> >> I noticed that. So were those examples I referenced above ?using its >> ORM?? Can you offer better examples ?without using its ORM?? > > http://www.sqlalchemy.org/docs/sqlexpression.html Still full of very repetitive boilerplate. Doesn?t look like it can create a simpler alternative to my example at all. From ldo at geek-central.gen.new_zealand Sat Jul 3 21:28:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 13:28:20 +1200 Subject: Why Is Escaping Data Considered So Magical? References: Message-ID: In message , Robert Kern wrote: > On 2010-06-25 19:49 , Lawrence D'Oliveiro wrote: > >> Why do people consider input sanitization so hard? > > It's not hard per se; it's just repetitive, prone to the occasional > mistake, and, frankly, really boring. But as a programmer, I?m not in the habit of doing ?repetitive? and ?boring?. Look at the example I posted, and you?ll see. It?s the ones trying to come up with alternatives to my code who produce things that look ?reptitive? and ?boring?. From maaindia13 at gmail.com Sat Jul 3 21:44:50 2010 From: maaindia13 at gmail.com (quick money) Date: Sat, 3 Jul 2010 18:44:50 -0700 (PDT) Subject: See Hot College Girls Sex images Message-ID: <312c389a-48cb-465b-880f-818c149862f8@i16g2000prn.googlegroups.com> :See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. at http://ukcollegegirls.co.cc Due to high sex content,i have hidden the videos in an image. in that website on left side below search box click on image and watch videos in all angles.please dont tell to anyone. From ldo at geek-central.gen.new_zealand Sat Jul 3 22:33:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 04 Jul 2010 14:33:44 +1200 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> Message-ID: In message , Nobody wrote: > On Tue, 29 Jun 2010 12:30:36 +1200, Lawrence D'Oliveiro wrote: > >>> Seriously, almost every other kind of library uses a binary API. What >>> makes databases so special that they need a string-command based API? >> >> HTML is also effectively a string-based API. > > HTML is a data format. The sane way to construct or manipulate HTML is via > the DOM, not string operations. What is this ?DOM? of which you speak? I looked here , but can find nothing that sounds like that, that is relevant to HTML. >> And what about regular expressions? > > What about them? As the saying goes: > > Some people, when confronted with a problem, think > "I know, I'll use regular expressions." > Now they have two problems. > > They have some uses, e.g. defining tokens[1]. Using them to match more > complex constructs is error-prone ... What if they?re NOT more complex, but they can simply contain user-entered data? >> And all the functionality available through the subprocess >> module and its predecessors? > > The main reason why everyone recommends subprocess over its predecessors > is that it allows you to bypass the shell, which is one of the most > common sources of the type of error being discussed in this thread. How would you deal with this, then: I wrote a script called ExtractMac, to convert various old Macintosh-format documents accumulated over the years (stored in AppleDouble form by uploading to a Netatalk server) to more cross-platform formats. This has a table of conversion commands to use. For example, the entries for PICT and TEXT Macintosh file types look like this: "PICT" : { "type" : "image", "ext" : ".png", "act" : "convert %(src)s %(dst)s", }, "TEXT" : { "type" : "text", "ext" : ".txt", "act" : "LineEndings unix <%(src)s >%(dst)s", }, The conversion code that uses this table looks like Cmd = \ ( Act.get("act", "cp -p %(src)s %(dst)s") % { "src" : ShellEscape(Src), "dst" : ShellEscape(DstFileName), } ) sys.stderr.write("Doing: %s\n" % Cmd) Status = os.system(Cmd) How much simpler would your alternative be? I don?t think it would be simpler at all. From rami.chowdhury at gmail.com Sat Jul 3 22:43:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 3 Jul 2010 19:43:44 -0700 Subject: Why are String Formatted Queries Considered So Magical? In-Reply-To: References: Message-ID: <201007031943.44611.rami.chowdhury@gmail.com> On Saturday 03 July 2010 19:33:44 Lawrence D'Oliveiro wrote: > In message , Nobody wrote: > > On Tue, 29 Jun 2010 12:30:36 +1200, Lawrence D'Oliveiro wrote: > >>> Seriously, almost every other kind of library uses a binary API. What > >>> makes databases so special that they need a string-command based API? > >> > >> HTML is also effectively a string-based API. > > > > HTML is a data format. The sane way to construct or manipulate HTML is > > via the DOM, not string operations. > > What is this ?DOM? of which you speak? I looked here > , but can find nothing that sounds like > that, that is relevant to HTML. > The Document Object Model - I don't think the standard library has an HTML DOM module but there's certainly one for XML (and XHTML): http://docs.python.org/library/xml.dom.html ---- Rami Chowdhury "Any sufficiently advanced incompetence is indistinguishable from malice." -- Grey's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From greg.ewing at canterbury.ac.nz Sat Jul 3 22:50:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 04 Jul 2010 14:50:38 +1200 Subject: delegation pattern via descriptor In-Reply-To: <4c2f1b2f$0$17371$426a74cc@news.free.fr> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> Message-ID: <89aamgF7vdU1@mid.individual.net> Bruno Desthuilliers wrote: > kedra marbun a ?crit : > >>if we limit our discussion to py: >>why __{get|set|delete}__ don't receive the 'name' & 'class' from >>__{getattribute|{set|del}attr}__ >>'name' is the name that is searched > > > While it would have been technically possible, I fail to imagine any use > case for this. I think he wants to have generic descriptors that are shared between multiple attributes, but have them do different things based on the attribute name. That's not the way property descriptors are designed to be used -- it's assumed that each attribute will have its own descriptor, tailored for that particular attribute. If you want to handle attributes more generically, you need to intervene at the level of __getattribute__, __getattr__ and __setattr__. -- Greg From invalid at invalid.invalid Sat Jul 3 23:12:00 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 4 Jul 2010 03:12:00 +0000 (UTC) Subject: IMAP Problems References: Message-ID: > I'm trying to write a simple script which displays the basic details > of a person's mailbox. My problem is that it causes all the messages > to be marked as read on the server, > > code, mailboxen= server.list() > print mailboxen > # if it's called INBOX, then > server.select("INBOX") You probably want to try examine() instead of select(). That opens the mailbox in a read-only mode which and should avoid changing any flag values. >From RFC3501: The EXAMINE command is identical to SELECT and returns the same output; however, the selected mailbox is identified as read-only. No changes to the permanent state of the mailbox, including per-user state, are permitted; in particular, EXAMINE MUST NOT cause messages to lose the \Recent flag. -- Grant From sturlamolden at yahoo.no Sat Jul 3 23:30:30 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 3 Jul 2010 20:30:30 -0700 (PDT) Subject: Lua is faster than Fortran??? Message-ID: I was just looking at Debian's benchmarks. It seems LuaJIT is now (on median) beating Intel Fortran! C (gcc) is running the benchmarks faster by less than a factor of two. Consider that Lua is a dynamically typed scripting language very similar to Python. LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and SBCL. I know it's "just a benchmark" but this has to count as insanely impressive. Beating Intel Fortran with a dynamic scripting language, how is that even possible? And what about all those arguments that dynamic languages "have to be slow"? If this keeps up we'll need a Python to Lua bytecode compiler very soon. And LuaJIT 2 is rumoured to be much faster than the current... Looking at median runtimes, here is what I got: gcc 1.10 LuaJIT 1.96 Java 6 -server 2.13 Intel Fortran 2.18 OCaml 3.41 SBCL 3.66 JavaScript V8 7.57 PyPy 31.5 CPython 64.6 Perl 67.2 Ruby 1.9 71.1 The only comfort for CPython is that Ruby and Perl did even worse. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 00:15:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jul 2010 04:15:57 GMT Subject: Lua is faster than Fortran??? References: Message-ID: <4c300afc$0$28647$c3e8da3@news.astraweb.com> On Sat, 03 Jul 2010 20:30:30 -0700, sturlamolden wrote: > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, how > is that even possible? By being clever, using Just In Time compilation as much as possible, and almost certainly using masses of memory at runtime. (The usual trade-off between space and time.) See the PyPy project, which aims to do the same thing for Python as Lua have done. Their ultimate aim is to beat the C compiler and be faster than C. So far they've got a bit to go, but they're currently about twice as fast as CPython. > And what about all those arguments that dynamic > languages "have to be slow"? They're bullshit, of course. It depends on the nature of the dynamicism. Some things are inherently slow, but not everything. Fast, tight, dynamic: pick any two. > If this keeps up we'll need a Python to Lua bytecode compiler very soon. "Need" is a bit strong. There are plenty of applications where if your code takes 0.1 millisecond to run instead of 0.001, you won't even notice. Or applications that are limited by the speed of I/O rather than the CPU. But I'm nitpicking... this is a nice result, the Lua people should be proud, and I certainly wouldn't say no to a faster Python :) [...] > The only comfort for CPython is that Ruby and Perl did even worse. It's not like this is a race, and speed is not the only thing which a language is judged by. Otherwise you'd be programming in C, not Python, right? -- Steven From sturlamolden at yahoo.no Sun Jul 4 01:05:56 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 3 Jul 2010 22:05:56 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> Message-ID: <7c61eacb-4a85-4f90-a080-fe073488df2f@g19g2000yqc.googlegroups.com> On 4 Jul, 06:15, Steven D'Aprano wrote: > "Need" is a bit strong. There are plenty of applications where if your > code takes 0.1 millisecond to run instead of 0.001, you won't even > notice. Or applications that are limited by the speed of I/O rather than > the CPU. > But I'm nitpicking... this is a nice result, the Lua people should be > proud, and I certainly wouldn't say no to a faster Python :) Need might be too strong, sorry. I'm not a native speaker of English :) Don't read this as a complaint about Python being too slow. I don't care about milliseconds either. But I do care about libraries like Python's standard library, wxPython, NumPy, and matplotlib. And when I need C, C++ or Fortran I know where to fint it. Nobody in the scientific community would be sad if Python was so fast that no C or Fortran would have to be written. And I am sure Google and many other users of Python would not mind either. And this is kind of a proof that it can be. Considering that Lua is to Python what C is to C++ (more or less), it means that it is possible to make Python run very fast as well. Yes the LuaJIT team should be proud. Making a scripting language run faster than Fortran on CPU-bound work is a superhuman result. From sridharr at activestate.com Sun Jul 4 01:12:48 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sat, 03 Jul 2010 22:12:48 -0700 Subject: How to disable readline when building Python? Message-ID: <4C301850.5000204@activestate.com> For licensing reasons, I need to disable readline, except editline on OSX, when building Python. For the life of me, I cannot figure out how this can be done ("./configure --help" does not show anything relevant); I've tried the following, and readline.so will still be built: - ./configure --without-readline - ./configure --disable-readline - Set `do_readline = False` in setup.py This is for Python 2.6; and I am yet to port the same to 2.7. -srid From stefan_ml at behnel.de Sun Jul 4 02:33:17 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 08:33:17 +0200 Subject: Confusion over etree.ElementTree.Element.getiterator In-Reply-To: <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> Message-ID: Ben Sizer, 04.07.2010 00:32: > On Jul 3, 11:12 pm, Ben Sizer wrote: > >> >>> for el in root.getiterator(): >> >> ... print el >> [much output snipped] >> >> >> >> > > Hmm, I think I've worked it out. Apparently the XML namespace forms > part of the tag name in this case. Is that what is intended? Sure. > I didn't see any examples of this in the docs. Admittedly, it's three clicks away from the library docs on docs.python.org. http://effbot.org/zone/element.htm#xml-namespaces Stefan From stefan_ml at behnel.de Sun Jul 4 02:38:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 08:38:34 +0200 Subject: My extension code generator for C++ In-Reply-To: References: Message-ID: Rouslan Korneychuk, 03.07.2010 19:22: > The code also never uses PyArg_ParseTuple or its variants. It converts > every argument using the appropriate PyX_FromY functions. I noticed > PyBindGen does the following when a conversion is needed for one argument: > > py_retval = Py_BuildValue((char *) "(O)", value); > if (!PyArg_ParseTuple(py_retval, (char *) "i", &self->obj->y)) { > Py_DECREF(py_retval); > return -1; > } > Py_DECREF(py_retval); > > On the other hand, here's the implementation for __sequence__getitem__: > > PyObject * obj_DVector___sequence__getitem__(obj_DVector > *self,Py_ssize_t index) { > try { > std::vector > &base = > cast_base_DVector(reinterpret_cast(self)); > return PyFloat_FromDouble(base.at(py_ssize_t_to_ulong(index))); > > } EXCEPT_HANDLERS(0) > } Check the code that Cython uses for these things. It generates specialised type conversion code that has received a lot of careful benchmarking and testing on different platforms. Stefan From rami.chowdhury at gmail.com Sun Jul 4 03:12:30 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sun, 4 Jul 2010 00:12:30 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <201007040012.31112.rami.chowdhury@gmail.com> On Saturday 03 July 2010 20:30:30 sturlamolden wrote: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! That's amazing! Congrats to the Lua team! > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: [snip] > The only comfort for CPython is that Ruby and Perl did even worse. Out of curiosity, does anyone know how the Unladen Swallow version of Python does by comparison? ---- Rami Chowdhury "Given enough eyeballs, all bugs are shallow." -- Linus' Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From cmpython at gmail.com Sun Jul 4 03:26:24 2010 From: cmpython at gmail.com (CM) Date: Sun, 4 Jul 2010 00:26:24 -0700 (PDT) Subject: python app development References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <28b6246b-0c8c-4660-8882-4f1d325c0e1f@x27g2000yqb.googlegroups.com> On Jul 3, 1:48?pm, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). > > i'm in a bit of a funny place, i have a decent/good grasp of python > syntax and my logic isn't bad, but i have no clue on how to assemble > an application, i seem to be stuck on writing scripts. Do you have a particular project in mind? Getting unstuck, I think, is about having a goal and then you'll begin to seek out what you need to make that happen (see below). > also, it seems that a lot of > app programming is 90% gui bindings, with very little actual code, or > am i totally way off mark? I'm sure it varies greatly depending on the application. Depending on the complexity of the GUI and how much care goes into it, that can be a lot of code (it seems to me). > i recently picked up the django practical projects book, and in a few > days i re-wrote a website i did with django. i feel it was the book's > project-centric approach that made this possible. I don't know of a book oriented that way (sounds like a good idea), but you might take a look at this video "learning path" from the ShowMeDo website: http://showmedo.com/learningpaths/14/view It is focused on GUI (desktop and web) application development. There is a super basic starter video in there about making a Python image viewer application. Then the video series about building emol seems very thorough (there are 35 videos!), though I haven't watched it yet. What I would suggest is that you first decide what you want to accomplish. Then research and pick a GUI framework first (Tkinter, wxPython, PyQT, PyGTK), then whatever other tools you'll need (database? drawing? math/science?), which will either be in the standard library or in a 3rd party library. Any of the research on what tools to use can be Googled with bountiful results, as those questions are asked a lot. Then just jump in. This will prompt you to learn in a directed way. From stefan_ml at behnel.de Sun Jul 4 04:03:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 10:03:05 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: sturlamolden, 04.07.2010 05:30: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. Sort of. One of the major differences is the "number" type, which is (by default) a floating point type - there is no other type for numbers. The main reason why Python is slow for arithmetic computations is its integer type (int in Py3, int/long in Py2), which has arbitrary size and is an immutable object. So it needs to be reallocated on each computation. If it was easily mappable to a CPU integer, Python implementations could just do that and be fast. But its arbitrary size makes this impossible (or requires a noticeable overhead, at least). The floating point type is less of a problem, e.g. Cython safely maps that to a C double already. But the integer type is. So it's not actually surprising that Lua beats CPython (and the other dynamic languages) in computational benchmarks. It's also not surprising to me that a JIT compiler beats a static compiler. A static compiler can only see static behaviour of the code, potentially with an artificially constructed idea about the target data. A JIT compiler can see the real data that flows through the code and can optimise for that. Stefan From tlikonen at iki.fi Sun Jul 4 04:28:32 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Sun, 04 Jul 2010 11:28:32 +0300 Subject: Lua is faster than Fortran??? References: Message-ID: <87d3v3irbj.fsf@mithlond.arda> * 2010-07-04 10:03 (+0200), Stefan Behnel wrote: > The main reason why Python is slow for arithmetic computations is its > integer type (int in Py3, int/long in Py2), which has arbitrary size > and is an immutable object. So it needs to be reallocated on each > computation. If it was easily mappable to a CPU integer, Python > implementations could just do that and be fast. But its arbitrary size > makes this impossible (or requires a noticeable overhead, at least). > The floating point type is less of a problem, e.g. Cython safely maps > that to a C double already. But the integer type is. You may be right. I'll just add that Common Lisp's integers are of arbitrary size too but programmer can declare them as fixnums. Such declarations kind of promise that the numbers really are between most-negative-fixnum and most-positive-fixnum. Compiler can then optimize the code to efficient machine instructions. I guess Python might have use for some sort of (defun foo (variable) (declare (type fixnum variable)) ...) From wxjmfauth at gmail.com Sun Jul 4 04:31:41 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 4 Jul 2010 01:31:41 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? Message-ID: Python all versions. It's not a bug, but I'm suprised the following does not raise a SyntaxError (missing space between '9' and 'for'). >>> [9for c in 'abc'] [9, 9, 9] >>> Side effect: If this behaviour is considered as correct, it makes a correct Python code styling (IDLE, editors, ...) practically impossible to realise. From detlev at die-offenbachs.de Sun Jul 4 04:54:46 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sun, 04 Jul 2010 10:54:46 +0200 Subject: [ANN] eric 5.0.0 released Message-ID: Hi, I just uploaded eric 5.0.0. This is the first official release. It is available via the eric web site. http://eric-ide.python-projects.org/index.html What is it? ----------- eric5 is the Python3 variant of the well know eric4 Python IDE and is the first development environment, that runs natively with Python3. It comes with all batteries included. The features are too much to be listed in this announcement. Please see the eric web site for details. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From dickinsm at gmail.com Sun Jul 4 04:55:16 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jul 2010 01:55:16 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: Message-ID: <169d86ca-70b6-4c3b-915b-99bed39b5373@y4g2000yqy.googlegroups.com> On Jul 4, 9:31?am, jmfauth wrote: > Python all versions. > > It's not a bug, but I'm suprised the following does > not raise a SyntaxError (missing space between > '9' and 'for'). > > > > >>> [9for c in 'abc'] > [9, 9, 9] > > Side effect: If this behaviour is considered as correct, > it makes a correct Python code styling (IDLE, editors, ...) > practically impossible to realise. Why? If Python itself has no problem parsing this code, why should it be so difficult for editors? Python's grammar is fairly simple: it's LL(1) (unlike C's, for example), so can be parsed with only 1 token of lookahead. -- Mark From dickinsm at gmail.com Sun Jul 4 05:02:10 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 4 Jul 2010 02:02:10 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <169d86ca-70b6-4c3b-915b-99bed39b5373@y4g2000yqy.googlegroups.com> Message-ID: <609ea5de-f88d-4948-9b7b-7b81ecb2695d@y11g2000yqm.googlegroups.com> On Jul 4, 9:55?am, Mark Dickinson wrote: > Why? ?If Python itself has no problem parsing this code, why should it > be so difficult for editors? ?Python's grammar is fairly simple: ?it's > LL(1) (unlike C's, for example), so can be parsed with only 1 token of > lookahead. Bah. Ignore the bit about C. I was thinking that the dangling else issue made this a problem, but now I'm not sure that's true. -- Mark From pauljefferson at gmail.com Sun Jul 4 05:50:25 2010 From: pauljefferson at gmail.com (Paul Jefferson) Date: Sun, 4 Jul 2010 10:50:25 +0100 Subject: IMAP Problems In-Reply-To: References: Message-ID: Brilliant! Thanks guys I will have to have a play around later On 4 July 2010 04:12, Grant Edwards wrote: > > > I'm trying to write a simple script which displays the basic details > > of a person's mailbox. My problem is that it causes all the messages > > to be marked as read on the server, > > > > code, mailboxen= server.list() > > print mailboxen > > # if it's called INBOX, then? > > server.select("INBOX") > > You probably want to try examine() instead of select(). That opens > the mailbox in a read-only mode which and should avoid changing any > flag values. > > >From RFC3501: > > The EXAMINE command is identical to SELECT and returns the same > output; however, the selected mailbox is identified as > read-only. No changes to the permanent state of the mailbox, > including per-user state, are permitted; in particular, EXAMINE > MUST NOT cause messages to lose the \Recent flag. > > -- > Grant > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kedra.marbun at gmail.com Sun Jul 4 06:26:36 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 4 Jul 2010 03:26:36 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> Message-ID: <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> i'm confused which part that doesn't make sense? this is my 2nd attempt to py, the 1st was on april this year, it was just a month, i'm afraid i haven't got the fundamentals right yet. so i'm gonna lay out how i got to this conclusion, CMIIW **explanation of feeling (0) on my 1st post** to me, descriptor is a particular kind of delegation, it takes the job of coding the delegation by having a contract with programmers that the tree meta operations (get, set, del) on attr are delegated to the obj that is bound to the attr are we agree that descriptor is a kind of delegation? the mechanism that makes descriptor works is in __getattribute__, __setattr__, __delattr__ of 'object' & 'type' now, if i want a single descriptor obj to be delegated to multiple tasks, i can't do it since __get__ doesn't get info that can be used to determine which task to do i must have diff descriptor obj for each task class Helper: def __init__(self, name): self.name = name def __get__(self, ins, cls): if self.name == 'task0': ... elif self.name == 'task1': ... else: ... class a: task0 = Helper('task0') task1 = Helper('task1') if __get__ receives the name, then i could do class Helper: def __get__(self, ins, cls, name): ... class a: task0 = task1 = Helper() but after explaining this, i have more doubt on my own stmt in the 1st post "not passing name strengthens the coupling between delegator & delegate". now i think it's more likely the opposite, it weakens the coupling at the expense of more objs. moreover, is it wrong to justify that descriptor is a kind of delegation? my ego speaks: - i think, if the name is passed on, programmers can choose to use it or not (i don't know if it brokes any py principle, i only know KISS) - i realize that using name as the info that descriptors use to determine which task to do, is going to strongly couple the descriptor & the classes that use it, meaning that the descriptor & the user classes must agree on attr names to be used. a simple solution to it is by mapping attr names & names used in the descriptor class Helper: def __init__(self, name_map=None): self.name_map = name_map def __get__(self, ins, cls, name): if self.name_map is None: if name == 'task0': ... ... else: if self.name_map[name] == 'task0': ... ... class a: do_this = do_that = Helper({'do_this':'task0', 'do_that':'task1'}) finally, like all shared things, shared descriptor objs require more effort for synchronization From pavlovevidence at gmail.com Sun Jul 4 06:35:31 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 4 Jul 2010 03:35:31 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: Message-ID: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> On Jul 4, 1:31?am, jmfauth wrote: > Python all versions. > > It's not a bug, but I'm suprised the following does > not raise a SyntaxError (missing space between > '9' and 'for'). > > >>> [9for c in 'abc'] > [9, 9, 9] It does seem strange that Python's lexer wouldn't consider 9for as a single token. Even tough it's not a valid token in Python, your eye kind of sees it as one, so wouldn't it be better to raise a syntax error? Some other places were keyword can follow a number: 9if 0 else 1 (but not "9if 0else 1") 9and 0 9or 0 9in (1,2,3) 9is None > Side effect: If this behaviour is considered as correct, > it makes a correct Python code styling (IDLE, editors, ...) > practically impossible to realise. I'm not sure why an odd corner of the grammar would mess the whole thing up. Most code stylers only approximate the actual grammar anyway. Carl Banks From kedra.marbun at gmail.com Sun Jul 4 06:35:37 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 4 Jul 2010 03:35:37 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: thanks Greg, you get most of what i meant like i said before, i suspect descriptor encourages dedicated / not shared descriptor obj. this encouragement is expressed in the design, and the reasons behind the design were the ones that i was asking about, not how to get around it now, i'm asking another favor, what about the 2nd point in my 1st post? From cournape at gmail.com Sun Jul 4 08:29:59 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 4 Jul 2010 21:29:59 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: On Sun, Jul 4, 2010 at 5:03 PM, Stefan Behnel wrote: > sturlamolden, 04.07.2010 05:30: >> >> I was just looking at Debian's benchmarks. It seems LuaJIT is now (on >> median) beating Intel Fortran! >> >> C (gcc) is running the benchmarks faster by less than a factor of two. >> Consider that Lua is a dynamically typed scripting language very >> similar to Python. > > Sort of. One of the major differences is the "number" type, which is (by > default) a floating point type - there is no other type for numbers. The > main reason why Python is slow for arithmetic computations is its integer > type (int in Py3, int/long in Py2), which has arbitrary size and is an > immutable object. So it needs to be reallocated on each computation. If it > was easily mappable to a CPU integer, Python implementations could just do > that and be fast. But its arbitrary size makes this impossible (or requires > a noticeable overhead, at least). The floating point type is less of a > problem, e.g. Cython safely maps that to a C double already. But the integer > type is. Actually, I think the main reason why Lua is much faster than other dynamic languages is its size. The language is small. You don't list, dict, tuples, etc... Making 50 % of python fast is "easy" (in the sense that it has been done). I would not be surprised if it is exponentially harder the closer you get to 100 %. Having a small language means that the interpreter is small - small enough to be kept in L1, which seems to matter a lot (http://www.reddit.com/r/programming/comments/badl2/luajit_2_beta_3_is_out_support_both_x32_x64/c0lrus0). If you are interested in facts and technical details (rather than mere speculations), this thread is interesting http://lambda-the-ultimate.org/node/3851. It has participation of LuaJIT author, Pypy author and Brendan Eich :) > It's also not surprising to me that a JIT compiler beats a static compiler. > A static compiler can only see static behaviour of the code, potentially > with an artificially constructed idea about the target data. A JIT compiler > can see the real data that flows through the code and can optimise for that. Although I agree that in theory, it is rather obvious that a JIT compiler can do many things that static analysis cannot, this is the first time it has happened in practice AFAIK. Even hotspot was not faster than fortran and C, and it has received tons of work by people who knew what they were doing. The only example of a dynamic language being as fast/faster than C that I am aware of so far is Staline, the aggressive compiler for scheme (used in signal processing in particular). David From m.1ahesh at gmail.com Sun Jul 4 09:44:36 2010 From: m.1ahesh at gmail.com (manoj kumar) Date: Sun, 4 Jul 2010 06:44:36 -0700 (PDT) Subject: High Revenue Keywords Message-ID: <9dbfef3c-8edb-4f78-818a-a537035609dc@18g2000prq.googlegroups.com> Check Out High Revenue Keywords In All Niche's At, http://highrevenuekeywords.blogspot.com/ . Stuff Your Content With These High Revenue Keywords And Maximize Your PPC Pay Per Click Value Doubling Your Revenue For All Clicks.. From wxjmfauth at gmail.com Sun Jul 4 09:49:28 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 4 Jul 2010 06:49:28 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: On 4 juil, 12:35, Carl Banks wrote: > On Jul 4, 1:31?am, jmfauth wrote: > Thanks for having explained in good English my feelings. > > Some other places were keyword can follow a number: > Note, that this does not envolve numbers only. >>> ['z' for c in 'abc'] ['z', 'z', 'z'] >>> 'z'if True else 'a' z >>> > > Side effect: If this behaviour is considered as correct, > > it makes a correct Python code styling (IDLE, editors, ...) > > practically impossible to realise. > > I'm not sure why an odd corner of the grammar would mess the whole > thing up. ?Most code stylers only approximate the actual grammar > anyway. > I guess, most editors (so do I) are mainly using a "re" engine for their styling. --- Not a keyword, but space related, what should I thing about this? >>> print9 Traceback (most recent call last): File "", line 1, in NameError: name 'print9' is not defined >>> print+9 9 >>> print'abc' abc >>> print9.0 File "", line 1 print9.0 ^ SyntaxError: invalid syntax >>> Regards, jmf From darcy at druid.net Sun Jul 4 10:23:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 10:23:48 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: <4c300afc$0$28647$c3e8da3@news.astraweb.com> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> Message-ID: <20100704102348.6e25c22e.darcy@druid.net> On 04 Jul 2010 04:15:57 GMT Steven D'Aprano wrote: > "Need" is a bit strong. There are plenty of applications where if your > code takes 0.1 millisecond to run instead of 0.001, you won't even > notice. Or applications that are limited by the speed of I/O rather than > the CPU. Which is 99% of the real-world applications if you factor out the code already written in C or other compiled languages. That's the point of Python after all. You speed up programming rather than programs but allow for refactoring into C when necessary. And it's not call CPython for nothing. off-the-shelf benchmarks are fun but mostly useless for choosing a language, priogram, OS or machine unless you know that it checks the actual things that you need in the proportion that you need. > But I'm nitpicking... this is a nice result, the Lua people should be > proud, and I certainly wouldn't say no to a faster Python :) Ditto, ditto, ditto and ditto. > It's not like this is a race, and speed is not the only thing which a > language is judged by. Otherwise you'd be programming in C, not Python, > right? Or assembler. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From cournape at gmail.com Sun Jul 4 10:46:10 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 4 Jul 2010 23:46:10 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <20100704102348.6e25c22e.darcy@druid.net> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: > On 04 Jul 2010 04:15:57 GMT > Steven D'Aprano wrote: >> "Need" is a bit strong. There are plenty of applications where if your >> code takes 0.1 millisecond to run instead of 0.001, you won't even >> notice. Or applications that are limited by the speed of I/O rather than >> the CPU. > > Which is 99% of the real-world applications if you factor out the code > already written in C or other compiled languages. This may be true, but there are areas where the percentage is much lower. Not everybody uses python for web development. You can be a python fan, be reasonably competent in the language, and have good reasons to wish for python to be one order of magnitude faster. I find LUA quite interesting: instead of providing a language simple to develop in, it focuses heavily on implementation simplicity. Maybe that's the reason why it could be done at all by a single person. David From bartc at freeuk.com Sun Jul 4 10:47:31 2010 From: bartc at freeuk.com (bart.c) Date: Sun, 4 Jul 2010 15:47:31 +0100 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: "sturlamolden" wrote in message news:daa07acb-d525-4e32-91f0-16490027cc42 at w12g2000yqj.googlegroups.com... > > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: > > gcc 1.10 > > LuaJIT 1.96 > > Java 6 -server 2.13 > Intel Fortran 2.18 > OCaml 3.41 > SBCL 3.66 > > JavaScript V8 7.57 > > PyPy 31.5 > CPython 64.6 > Perl 67.2 > Ruby 1.9 71.1 > > The only comfort for CPython is that Ruby and Perl did even worse. I didn't see the same figures; LuaJIT seem to be 4-5 times as slow as one of the C's, on average. Some benchmarks were slower than that. But I've done my own brief tests and I was quite impressed with LuaJIT which seemed to outperform C on some tests. I'm developing my own language and LuaJIT is a new standard to beat for this type of language. However, Lua is quite a lightweight language with minimalist data types, it doesn't suit everybody. I suspect also the Lua JIT compiler optimises some of the dynamicism out of the language (where it can see, for example, that something is always going to be a number, and Lua only has one numeric type with a fixed range), so that must be a big help. -- Bartc From darcy at druid.net Sun Jul 4 11:00:47 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 11:00:47 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: <20100704110047.d7d77cae.darcy@druid.net> On Sun, 4 Jul 2010 23:46:10 +0900 David Cournapeau wrote: > On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: > > Which is 99% of the real-world applications if you factor out the code > > already written in C or other compiled languages. > > This may be true, but there are areas where the percentage is much > lower. Not everybody uses python for web development. You can be a > python fan, be reasonably competent in the language, and have good > reasons to wish for python to be one order of magnitude faster. I wish it was orders of magnitude faster for web development. I'm just saying that places where we need compiled language speed that Python already has that in C. But, as I said in the previous message, in the end it is up to you to write your own benchmark based on the operations you need and the usage patterns you predict that it will need as well. If your application needs to calculate Pi to 100 places but only needs to do it once there is no need to include that in your benchmark a million times. A language that is optimized for calculating Pi shouln't carry a lot of weight for you. > I find LUA quite interesting: instead of providing a language simple > to develop in, it focuses heavily on implementation simplicity. Maybe > that's the reason why it could be done at all by a single person. Is that really true about LUA? I haven't looked that closely at it but that paragraph probably turned off most people on this list to LUA. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Sun Jul 4 11:05:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 4 Jul 2010 11:05:04 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <20100704110504.dbd8342e.darcy@druid.net> On Sat, 3 Jul 2010 20:30:30 -0700 (PDT) sturlamolden wrote: > CPython 64.6 By the way, I assume that that's Python 2.x. I wonder how Python 3.1 would fare. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From thomas at jollans.com Sun Jul 4 11:08:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 04 Jul 2010 17:08:50 +0200 Subject: SyntaxError not honoured in list comprehension? In-Reply-To: References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: <4C30A402.3030005@jollans.com> On 07/04/2010 03:49 PM, jmfauth wrote: > On 4 juil, 12:35, Carl Banks wrote: >> On Jul 4, 1:31 am, jmfauth wrote: >> > > > Thanks for having explained in good English my feelings. > > >> >> Some other places were keyword can follow a number: >> > > Note, that this does not envolve numbers only. > >>>> ['z' for c in 'abc'] > ['z', 'z', 'z'] >>>> 'z'if True else 'a' > z >>>> > > > >>> Side effect: If this behaviour is considered as correct, >>> it makes a correct Python code styling (IDLE, editors, ...) >>> practically impossible to realise. >> >> I'm not sure why an odd corner of the grammar would mess the whole >> thing up. Most code stylers only approximate the actual grammar >> anyway. >> > > I guess, most editors (so do I) are mainly using > a "re" engine for their styling. > > --- > > Not a keyword, but space related, what should I thing > about this? > >>>> print9 looks like an identifier > Traceback (most recent call last): > File "", line 1, in > NameError: name 'print9' is not defined >>>> print+9 can't be a single identifier. Maybe it's a print statement followed by stuff? (stop being a statement, print!) > 9 >>>> print'abc' can't be an identifier or string literal. Maybe it's a print statement followed by stuff? > abc >>>> print9.0 looks like getattr(print9, '0') - but '0' is not a valid name. Impossible. Error! > File "", line 1 > print9.0 > ^ > SyntaxError: invalid syntax >>>> somewhat strange, yes. From cournape at gmail.com Sun Jul 4 11:25:58 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 00:25:58 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <20100704110047.d7d77cae.darcy@druid.net> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On Mon, Jul 5, 2010 at 12:00 AM, D'Arcy J.M. Cain wrote: > On Sun, 4 Jul 2010 23:46:10 +0900 > David Cournapeau wrote: >> On Sun, Jul 4, 2010 at 11:23 PM, D'Arcy J.M. Cain wrote: >> > Which is 99% of the real-world applications if you factor out the code >> > already written in C or other compiled languages. >> >> This may be true, but there are areas where the percentage is much >> lower. Not everybody uses python for web development. You can be a >> python fan, be reasonably competent in the language, and have good >> reasons to wish for python to be one order of magnitude faster. > > I wish it was orders of magnitude faster for web development. ?I'm just > saying that places where we need compiled language speed that Python > already has that in C. Well, I wish I did not have to use C, then :) For example, as a contributor to numpy, it bothers me at a fundamental level that so much of numpy is in C. Also, there are some cases where using C for speed is very difficult, because the marshalling cost almost entirely alleviate the speed advantages - that means you have to write in C more than you anticipated. Granted, those may be quite specific to scientific applications, and cython already helps quite a fair bit in those cases. > > But, as I said in the previous message, in the end it is up to you to > write your own benchmark based on the operations you need and the usage > patterns you predict that it will need as well. ?If your application > needs to calculate Pi to 100 places but only needs to do it once there > is no need to include that in your benchmark a million times. I would question the sanity of anyone choosing a language because it can compute Pi to 100 places very quickly :) I am sure google search would beat most languages if you count implementation + running time anyway. > >> I find LUA quite interesting: instead of providing a language simple >> to develop in, it focuses heavily on implementation simplicity. Maybe >> that's the reason why it could be done at all by a single person. > > Is that really true about LUA? ?I haven't looked that closely at it but > that paragraph probably turned off most people on this list to LUA. I hope I did not turn anyone off - but it is definitely not the same set of tradeoff as python. LUA runtime is way below 1 Mb, for example, which is one reason why it is so popular for video games. The following presentation gives a good overview (by LUA creator): http://www.stanford.edu/class/ee380/Abstracts/100310-slides.pdf To go back to the original topic: a good example is numeric types. In python, you have many different numerical types with different semantics. In LUA, it is much simpler. This makes implementation simpler, and some aggressive optimizations very effective. The fact that a LUA interpreter can fit in L1 is quite impressive. David From benjamin at python.org Sun Jul 4 11:34:57 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 4 Jul 2010 10:34:57 -0500 Subject: [RELEASE] Python 2.7 released Message-ID: On behalf of the Python development team, I'm jocund to announce the second release candidate of Python 2.7. Python 2.7 will be the last major version in the 2.x series. However, it will also have an extended period of bugfix maintenance. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7 visit: http://www.python.org/download/releases/2.7/ 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a production release and should be suitable for all libraries and applications. Please report any bugs you find, so they can be fixed in the next maintenance releases. The bug tracker is at: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From jml at mumak.net Sun Jul 4 11:36:19 2010 From: jml at mumak.net (Jonathan Lange) Date: Sun, 4 Jul 2010 16:36:19 +0100 Subject: Twisted 10.1.0 released Message-ID: On behalf of Twisted Matrix Laboratories, I am honored to announce the release of Twisted 10.1.0. Highlights include: * Deferreds now support cancellation * A new "endpoint" interface which can abstractly describe stream transport endpoints such as TCP and SSL * inotify support for Linux, which allows monitoring of file system events. * AMP supports transferring timestamps Note also that this is the *last* supported release of Twisted for Python 2.4 on Windows. For more information, see the NEWS file. It's stable, backwards compatible, well tested and in every way an improvement. Download it now from: http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.tar.bz2 http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.5.msi http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.6.msi Many thanks to Glyph Lefkowitz, who helped do the release preparation, and the PyCon 2010 sprinters, who did so much of the work for this release. jml From sturlamolden at yahoo.no Sun Jul 4 12:00:23 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:00:23 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <303c834a-3737-4f57-8de5-2bb23fa883e5@5g2000yqz.googlegroups.com> On 4 Jul, 16:47, "bart.c" wrote: > I suspect also the Lua JIT compiler optimises some of the dynamicism out of > the language (where it can see, for example, that something is always going > to be a number, and Lua only has one numeric type with a fixed range), so > that must be a big help. Python could do the same, replace int and float with a "long double". It is 80 bit and has a 64 bit mantissa. So it can in theory do the job of all floating point types and integers up to 64 bit (signed and unsigned). A long double can 'duck type' all the floating point and integer types we use. There is really no need for more than one number type. For an interpreted language, it's just a speed killer. Other number types belong in e.g. the ctypes, array, struct and NumPy modules. Speed wise a long double (80 bit) is the native floating point type on x86 FPUs. There is no penalty memory-wise either, wrapping an int as PyObject takes more space. For a dynamic language it can be quite clever to just have one 'native' number type, observing that the mantissa of a floating point number is an unsigned integer. That takes a lot of the dynamicity out of the equation. Maybe you like to have integers and floating point types in the 'language'. But that does not mean it should be two types in the 'implementation' (i.e. internally in the VM). The implementation could duck type both with a suffciently long floating point type, and the user would not notice in the syntax. MATLAB does the same as Lua. Native number types are always double, you have to explicitly create the other. Previously they did not even exist. Scientists have been doing numerical maths with MATLAB for decades. MATLAB never prevented me from working with integers mathematically, even if I only worked with double. If I did not know, I would not have noticed. a = 1; % a is a double a = 1 + 1; % a is a double and exactly 2 a = int32(1); Sturla From benjamin at python.org Sun Jul 4 12:03:47 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 4 Jul 2010 11:03:47 -0500 Subject: [RELEASE] Python 2.7 released In-Reply-To: References: Message-ID: 2010/7/4 Benjamin Peterson : > On behalf of the Python development team, I'm jocund to announce the second > release candidate of Python 2.7. Arg!!! This should, of course, be "final release". -- Regards, Benjamin From sturlamolden at yahoo.no Sun Jul 4 12:12:05 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:12:05 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> On 4 Jul, 10:03, Stefan Behnel wrote: > Sort of. One of the major differences is the "number" type, which is (by > default) a floating point type - there is no other type for numbers. The > main reason why Python is slow for arithmetic computations is its integer > type (int in Py3, int/long in Py2), which has arbitrary size and is an > immutable object. So it needs to be reallocated on each computation. That is why Lua got it right. A floating point type has a mantissa and can duck type an integer. MATLAB does the same. Sturla If it > was easily mappable to a CPU integer, Python implementations could just do > that and be fast. But its arbitrary size makes this impossible (or requires > a noticeable overhead, at least). The floating point type is less of a > problem, e.g. Cython safely maps that to a C double already. But the > integer type is. > > So it's not actually surprising that Lua beats CPython (and the other > dynamic languages) in computational benchmarks. > > It's also not surprising to me that a JIT compiler beats a static compiler. > A static compiler can only see static behaviour of the code, potentially > with an artificially constructed idea about the target data. A JIT compiler > can see the real data that flows through the code and can optimise for that. > > Stefan From sturlamolden at yahoo.no Sun Jul 4 12:21:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:21:24 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> On 4 Jul, 14:29, David Cournapeau wrote: > Actually, I think the main reason why Lua is much faster than other > dynamic languages is its size. The language is small. You don't list, > dict, tuples, etc... They have managed to combine list and dict into one type (table) that does the job of both. And yes there are tuples. There are no classes, but there are closures and other building blocks that can be used to create any object-oriented type system (just like CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I imagine it would be possible to define an equivalent to the Python type system in Lua, and compile Python to Lua. Lua can be compiled to Lua byte code. Factoring Lua, out that means we should be able to compile Python to Lua byte code. From cournape at gmail.com Sun Jul 4 12:34:57 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 01:34:57 +0900 Subject: Lua is faster than Fortran??? In-Reply-To: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> References: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> Message-ID: On Mon, Jul 5, 2010 at 1:12 AM, sturlamolden wrote: > On 4 Jul, 10:03, Stefan Behnel wrote: > >> Sort of. One of the major differences is the "number" type, which is (by >> default) a floating point type - there is no other type for numbers. The >> main reason why Python is slow for arithmetic computations is its integer >> type (int in Py3, int/long in Py2), which has arbitrary size and is an >> immutable object. So it needs to be reallocated on each computation. > > That is why Lua got it right. A floating point type has a mantissa and > can duck type an integer. MATLAB does the same. I sincerly doubt it - where do take the information that matlab use float to represent int ? It would not be able to represent the full range of 64 bits integer for example. David From sturlamolden at yahoo.no Sun Jul 4 12:37:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:37:17 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> On 4 Jul, 09:12, Rami Chowdhury wrote: > Out of curiosity, does anyone know how the Unladen Swallow version of Python > does by comparison? Judging from their PyCon slides, it's roughly 1.5 times faster than CPython. That might be important to Google, but not to me. From sturlamolden at yahoo.no Sun Jul 4 12:50:00 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 09:50:00 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <32c10c35-7c62-4de9-946e-b1be96637923@j8g2000yqd.googlegroups.com> Message-ID: On 4 Jul, 18:34, David Cournapeau wrote: > I sincerly doubt it - where do take the information that matlab use > float to represent int ? I've used Matlab since 1994, so I know it rather well... Only the recent versions can do arithmetics with number types different from double (or complex double). > It would not be able to represent the full > range of 64 bits integer for example. There is a 53 bit mantissa plus a sign bit. Nobody complained on 32 bit systems. That is, when the signed 54 bit integer contained in a double was overflowed, there was a loss of precision but the numerical range would still be that of a double. You get an unsigned integer in MATLAB like this x = uint64(0) but until recently, MATLAB could not do any arithmetics with it. It was there for interaction with Java and C MEX files. A long double has a mantissa of 64 bit however, so it can represent signed 65 bit integers without loss of precision. From stefan_ml at behnel.de Sun Jul 4 13:02:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 19:02:13 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 18:37: > On 4 Jul, 09:12, Rami Chowdhury wrote: > >> Out of curiosity, does anyone know how the Unladen Swallow version of Python >> does by comparison? > > Judging from their PyCon slides, it's roughly 1.5 times faster than > CPython. A number like "1.5 times faster" is meaningless without a specific application and/or code section in mind. I'm pretty sure there are cases where they are much faster than that, and there are cases where the net gain is zero (or -0.x or whatever). Stefan From sturlamolden at yahoo.no Sun Jul 4 13:10:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 10:10:21 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: On 4 Jul, 19:02, Stefan Behnel wrote: > A number like "1.5 times faster" is meaningless without a specific > application and/or code section in mind. I'm pretty sure there are cases > where they are much faster than that, and there are cases where the net > gain is zero (or -0.x or whatever). Here is what they say: Benchmark CPython Unladen Change 2to3 25.13 s 24.87 s 1.01x faster django 1.08 s 0.68 s 1.59x faster html5lib 14.29 s 13.20 s 1.08x faster nbody 0.51 s 0.28 s 1.84x faster rietveld 0.75 s 0.55 s 1.37x faster slowpickle 0.75 s 0.55 s 1.37x faster slowspitfire 0.83 s 0.61 s 1.36x faster slowunpickle 0.33 s 0.26 s 1.26x faster spambayes 0.31 s 0.34 s 1.10x slower From stefan_ml at behnel.de Sun Jul 4 13:51:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 19:51:21 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 19:10: > On 4 Jul, 19:02, Stefan Behnel wrote: > >> A number like "1.5 times faster" is meaningless without a specific >> application and/or code section in mind. I'm pretty sure there are cases >> where they are much faster than that, and there are cases where the net >> gain is zero (or -0.x or whatever). > > Here is what they say: > > Benchmark CPython Unladen Change > 2to3 25.13 s 24.87 s 1.01x faster > django 1.08 s 0.68 s 1.59x faster > html5lib 14.29 s 13.20 s 1.08x faster > nbody 0.51 s 0.28 s 1.84x faster > rietveld 0.75 s 0.55 s 1.37x faster > slowpickle 0.75 s 0.55 s 1.37x faster > slowspitfire 0.83 s 0.61 s 1.36x faster > slowunpickle 0.33 s 0.26 s 1.26x faster > spambayes 0.31 s 0.34 s 1.10x slower Ok, so, which of those do you care about? Stefan From no.email at nospam.invalid Sun Jul 4 14:26:47 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 04 Jul 2010 11:26:47 -0700 Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> Message-ID: <7xhbkfje6w.fsf@ruckus.brouhaha.com> "D'Arcy J.M. Cain" writes: >> I find LUA quite interesting: instead of providing a language simple >> to develop in, it focuses heavily on implementation simplicity. Maybe >> that's the reason why it could be done at all by a single person. > > Is that really true about LUA? I haven't looked that closely at it but > that paragraph probably turned off most people on this list to LUA. I would say Lua focuses on implementation compactness; it's intended as an embedded scripting interpreter. It's easy to sandbox and uses just 50k or so of memory. It's running in a lot of mobile phones, cameras, etc. The language itself is nowhere near as featureful as Python and I wouldn't want to use it for large scale development, but it appears pretty good for what it was intended for. Interestingly, it doesn't have lists or arrays. Its only container structure is comparable to a Python dictionary. Arrays are just the special case of dictionaries indexed by numbers. There is a little bit of syntax sugar to help with that, but it's just the dict structure underneath. I wouldn't say it was all done by one person though, and in particular I think LuaJIT was done by a different group than the main Lua developers. From sturlamolden at yahoo.no Sun Jul 4 15:44:45 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 12:44:45 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: On 4 Jul, 19:51, Stefan Behnel wrote: > Ok, so, which of those do you care about? I have already said I don't care about unladen swallow. From luismgz at gmail.com Sun Jul 4 15:51:42 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 4 Jul 2010 12:51:42 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: On Jul 4, 12:30?am, sturlamolden wrote: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > Looking at median runtimes, here is what I got: > > ? ?gcc ? ? ? ? ? ? ? 1.10 > > ? ?LuaJIT ? ? ? ? ? ?1.96 > > ? ?Java 6 -server ? ?2.13 > ? ?Intel Fortran ? ? 2.18 > ? ?OCaml ? ? ? ? ? ? 3.41 > ? ?SBCL ? ? ? ? ? ? ?3.66 > > ? ?JavaScript V8 ? ? 7.57 > > ? ?PyPy ? ? ? ? ? ? 31.5 > ? ?CPython ? ? ? ? ?64.6 > ? ?Perl ? ? ? ? ? ? 67.2 > ? ?Ruby 1.9 ? ? ? ? 71.1 > > The only comfort for CPython is that Ruby and Perl did even worse. You should read this thread: http://lambda-the-ultimate.org/node/3851 There, you'll see this subject discussed and explained at length. Pay special attention to Mike Pall's comments (he is the creator of Luajit) and his opinion about python and pypy. You will read also about other projects, specially new javascript engines such as Mozila's Tracemonkey (the authors participate in this thread) and the pypy folks. It is a very good read for anyone interested in the subject. Very recommended! Good luck! Luis From stefan_ml at behnel.de Sun Jul 4 15:59:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Jul 2010 21:59:35 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: sturlamolden, 04.07.2010 21:44: > On 4 Jul, 19:51, Stefan Behnel wrote: >> Ok, so, which of those do you care about? > > I have already said I don't care about unladen swallow. What I meant, was: which of these benchmarks would have to be better to make you care? Because your decision not to care seems to be based on exactly these benchmarks. Stefan From luismgz at gmail.com Sun Jul 4 16:04:11 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sun, 4 Jul 2010 13:04:11 -0700 (PDT) Subject: Lua is faster than Fortran??? References: Message-ID: <3532d127-1908-496f-a336-ab6f3c9782be@t10g2000yqg.googlegroups.com> On Jul 4, 4:51?pm, Luis M. Gonz?lez wrote: > On Jul 4, 12:30?am, sturlamolden wrote: > > > > > > > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > > median) beating Intel Fortran! > > > C (gcc) is running the benchmarks faster by less than a factor of two. > > Consider that Lua is a dynamically typed scripting language very > > similar to Python. > > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > > SBCL. > > > I know it's "just a benchmark" but this has to count as insanely > > impressive. Beating Intel Fortran with a dynamic scripting language, > > how is that even possible? And what about all those arguments that > > dynamic languages "have to be slow"? > > > If this keeps up we'll need a Python to Lua bytecode compiler very > > soon. And LuaJIT 2 is rumoured to be much faster than the current... > > > Looking at median runtimes, here is what I got: > > > ? ?gcc ? ? ? ? ? ? ? 1.10 > > > ? ?LuaJIT ? ? ? ? ? ?1.96 > > > ? ?Java 6 -server ? ?2.13 > > ? ?Intel Fortran ? ? 2.18 > > ? ?OCaml ? ? ? ? ? ? 3.41 > > ? ?SBCL ? ? ? ? ? ? ?3.66 > > > ? ?JavaScript V8 ? ? 7.57 > > > ? ?PyPy ? ? ? ? ? ? 31.5 > > ? ?CPython ? ? ? ? ?64.6 > > ? ?Perl ? ? ? ? ? ? 67.2 > > ? ?Ruby 1.9 ? ? ? ? 71.1 > > > The only comfort for CPython is that Ruby and Perl did even worse. > > You should read this thread:http://lambda-the-ultimate.org/node/3851 > There, you'll see this subject discussed and explained at length. > Pay special attention to Mike Pall's comments (he is the creator of > Luajit) and his opinion about python and pypy. > You will read also about other projects, specially new javascript > engines such as Mozila's Tracemonkey (the authors participate in this > thread) and the pypy folks. > It is a very good read for anyone interested in the subject. Very > recommended! > Good luck! > > Luis To be more specific, check these comments on the above the above suggested thread: http://lambda-the-ultimate.org/node/3851#comment-57804 http://lambda-the-ultimate.org/node/3851#comment-57700 Luis From sturlamolden at yahoo.no Sun Jul 4 16:20:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 13:20:24 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On 2 Jul, 21:07, John Nagle wrote: > http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ He is right on. The only thing Python 3k will do for me, is break all my code and be incompatible with all extension modules I need. "What's the point?" indeed. From nagle at animats.com Sun Jul 4 16:58:17 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 13:58:17 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: <4c30f5e9$0$1586$742ec2ed@news.sonic.net> On 7/4/2010 12:51 PM, Luis M. Gonz?lez wrote: >> Looking at median runtimes, here is what I got: >> >> gcc 1.10 >> >> LuaJIT 1.96 >> >> Java 6 -server 2.13 >> Intel Fortran 2.18 >> OCaml 3.41 >> SBCL 3.66 >> >> JavaScript V8 7.57 >> >> PyPy 31.5 >> CPython 64.6 >> Perl 67.2 >> Ruby 1.9 71.1 >> >> The only comfort for CPython is that Ruby and Perl did even worse. It's embarrassing that Javascript is now 9x faster than Python. Javascript has almost all the dynamic problems that make CPython slow, but they've been overcome in the Javascript JIT compiler. Here's how the Javascript V8 system does it: http://code.google.com/apis/v8/design.html They get rid of unnecessary dictionary lookups for attributes by automatically creating "hidden classes" which, in Python terms, use "slots". If an attribute is added to an object, another hidden class is created with that attribute. Each such class is hard-compiled to machine code while the program is running. So attribute access never requires a dictionary lookup. Adding a new, not-previously-used attribute is a relatively expensive operation, but with most programs, after a while all the new attributes have been added and the program settles down to efficient operation. That's in Google's Chrome browser right now. The Unladen Swallow people should in theory be able to reach that level of performance. (Both groups are employed at Google. So their effectiveness will be compared.) John Nagle From toby at rcsreg.com Sun Jul 4 17:05:56 2010 From: toby at rcsreg.com (Tobiah) Date: Sun, 04 Jul 2010 21:05:56 GMT Subject: Getting the name of the file that imported current module Message-ID: foo.py: import bar bar.show_importer() output: 'foo' or 'foo.py' or 'path/to/foo' etc. Possible? Thanks, Tobiah From me+list/python at ixokai.io Sun Jul 4 17:09:52 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 04 Jul 2010 14:09:52 -0700 Subject: Lua is faster than Fortran??? In-Reply-To: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: <4C30F8A0.7070109@ixokai.io> On 7/4/10 9:21 AM, sturlamolden wrote: > On 4 Jul, 14:29, David Cournapeau wrote: > >> Actually, I think the main reason why Lua is much faster than other >> dynamic languages is its size. The language is small. You don't list, >> dict, tuples, etc... > > They have managed to combine list and dict into one type (table) that > does the job of both. You say "managed" as if it were some technical accomplishment, or that the result is able to actually do the job of both: neither of these assertions are true. Have you actually *used* Lua? I quite like the language in certain contexts where its appropriate, but if you've actually used it in real code and found tables to be at all a substitute for *either* dictionaries *or* lists, then I think somehow you've managed to actually miss using either data structure in Python to any real extent, somehow. Lua's tables are at very weak "dictionary-like" and "list-like" objects, which indeed have been folded into one. To the detriment of both, at least as far as they are an actual useful data structure. You can't even get the equivalent of len(dict) in it: you have to actually brute-force iterate the table and count manually. Even for a purely array-like table with onlyn umbered indexes, #table can be unreliable: its quite possible through normal list-like operations that you perform on it, it can end up with holes where #table will fail. Since it is *not* an list internally at *all*, but simply an associative array with numbered indexes. I could go on, and on, and on: but the fundamental *weakness* of Lua' data types as data-structures is irrefutable, from its tables to strings to numbers: they are incredibly weak on capabilities. You end up writing all kinds of "library" functions to just do the normal things that should be really easy to do. Now, of course, there's really good reason why Lua is so simple in these ways. Its entirely suitable for Lua as an embedded scripting language to keep things very light, so it can be simple and fast. Good for Lua to fill this niche superbly. But you can't start saying its simple alternatives are at all comparable to Python's extremely rich and capable data types. > And yes there are tuples. No, there isn't. There's ways to create a tuple-like-thing which kind of behaves like a braindead tuple, and functions have a positively bizarre capability of returning more then one value (and accepting variable values), so there's these points in the language where you have this sort of Immutable Sequence, but its opaque until you unwrap it -- and then it ceases to be. That's not the same thing as having an immutable sequence that you can store data in at your discretion, with a rich series of capabilities that you can leverage. > There are no classes, but there are closures and other building blocks > that can be used to create any object-oriented type system Not really. Above, I spoke of tables as data structures, things just storing data. But you're right, they are capable of more then that-- but you're over-selling just how far that capability goes, by a long shot (and underselling just how much work it takes to get it there). Yes, tables have a limited series of 'hooks' that you can tie into to alter their behavior, and through this you can simulate certain higher order type systems as defined in other languages. In fact, lots of people have done this: there's multiple "classy" libraries out there to bring some kind of Class-or-Object-Oriented-Programming to Lua. They work to varying degrees: but the hooks that Lua provides to tables is still significantly lacking to really replace Python's comprehensively dynamic object model, without a LOT of wasted cycles. For example, while you can use __newindex to 'catch' someone setting a new 'key' on a table, and and __index to replace or forward the actual lookup, you can't actually capture someone trying to set a value to a key which already exists. So, you end up having to do a full proxy approach, where your table never actually stores anything directly (except a reference to another hidden table), and so when someone goes to set something you have to set it on the proxied object instead. Because you can't let there ever be any real keys on the proxying / external table. So you're able to work around its lack a bit, to simulate something /like/ what it means to have __setattr__. But then you run into problems. There's no way now to iterate over the table now, because pairs() will only return your internal hidden keys that you're using to point to the proxied table (Although you can get around this with some more complexity by hiding said key into a closure-- but even then, you still can't iterate over the proxied table's keys instead). So what do you do? Well you go replace the global "pairs" function, that's what you do! So it learns your particular style of Classness, and interacts well. Hope you never use any third-party code which has even a vaguely different kind of Classness. Alternately, you can just decide to never use the standard idiom of iteration for your classes, and instead one must always "for x in my_table:iter()" -- so now you have one kind of code operating on 'real' tables, and a totally different kind operating on your 'classy tables'. And on and on. The point is, sure. Lua can sort of simulate different OOP approaches, and Lua-folk are very adept at tweaking, twisting, turning and ripping tables into all kinds of pseudo-data types that match other paradigms, but its all hacks on top of hacks on top of hacks. You end up with some *really* weird and/or messy code if you try. Better to do Lua in Lua, instead of Python in Lua, or Java in Lua. (just like > CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I > imagine it would be possible to define an equivalent to the Python > type system in Lua, and compile Python to Lua. Lua can be compiled to > Lua byte code. Factoring Lua, out that means we should be able to > compile Python to Lua byte code. > > > > -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sun Jul 4 17:17:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 04 Jul 2010 22:17:52 +0100 Subject: Getting the name of the file that imported current module In-Reply-To: References: Message-ID: On 04/07/2010 22:05, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah >>> import re >>> re.__file__ 'C:\\Python26\\lib\\re.pyc' HTH. Mark Lawrence. From sjmachin at lexicon.net Sun Jul 4 18:02:53 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 4 Jul 2010 15:02:53 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: On Jul 5, 1:08?am, Thomas Jollans wrote: > On 07/04/2010 03:49 PM, jmfauth wrote: > > ? File "", line 1 > > ? ? print9.0 > > ? ? ? ? ? ?^ > > SyntaxError: invalid syntax > > somewhat strange, yes. There are two tokens, "print9" (a name) and ".0" (a float constant) -- looks like SyntaxError to me. From tjreedy at udel.edu Sun Jul 4 19:14:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 04 Jul 2010 19:14:52 -0400 Subject: Python 3 put-downs: What's the point? Message-ID: From torriem at gmail.com Sun Jul 4 19:25:58 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 04 Jul 2010 17:25:58 -0600 Subject: Getting the name of the file that imported current module In-Reply-To: References: Message-ID: <4C311886.9050508@gmail.com> On 07/04/2010 03:17 PM, Mark Lawrence wrote: > On 04/07/2010 22:05, Tobiah wrote: >> foo.py: >> >> import bar >> bar.show_importer() >> >> output: >> >> 'foo' or 'foo.py' or 'path/to/foo' etc. >> >> Possible? >> >> Thanks, >> >> Tobiah > > >>> import re > >>> re.__file__ > 'C:\\Python26\\lib\\re.pyc' I think this is exactly opposite of what he was asking for. Given than any number of modules can import other modules but each module really only exists once in the Python object space (normally) would mean that what the OP is asking for isn't possible. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 19:29:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jul 2010 23:29:05 GMT Subject: Getting the name of the file that imported current module References: Message-ID: <4c311941$0$28647$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? I don't think so. Your question isn't even well-defined. Given three modules: # a.py import b import d # b.py import d # c.py import a import d import b print d.show_importer() and you run c.py, what do you expect d.show_importer() to return? And what about "from d import show_importer" -- does that count as "importing d"? Why do you think that a module needs to know what other modules imported it? I can't imagine why this would be necessary, what are you intending to do with it? -- Steven From tim at johnsons-web.com Sun Jul 4 19:46:50 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 04 Jul 2010 18:46:50 -0500 Subject: Shared object access problems Message-ID: Using python 2.6.4 on slackware 13.1 I have MySQLdb 'by hand', that is: by 1)downloading MySQL-python-1.2.3c1.tar.gz 2)unzipping tarfile 3)running python setup.py build 4)running python setup.py install The build and install seemed to proceded without error, but upon invoking the interpreter and running >>> import MySQLdb I get the following ImportError: ############################################################## Traceback (most recent call last): File "", line 1, in File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 19, in File "build/bdist.linux-i686/egg/_mysql.py", line 7, in File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__ ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory ############################################################## There was no libmysqlclient_r.so.15 on my machine, so I made symlinks at both /usr/lib/mysql/ and /usr/lib which are libmysqlclient_r.so.15 pointing to /usr/lib/mysql/libmysqlclient_r.so.16.0.0 Now when I run import MySQLdb, I get the following error: ############################################################## Traceback (most recent call last): File "", line 1, in File "MySQLdb/__init__.py", line 19, in import _mysql File "build/bdist.linux-i686/egg/_mysql.py", line 7, in File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__ ImportError: /usr/lib/libmysqlclient_r.so.15: version `libmysqlclient_15' not found (required by /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg-tmp /_mysql.so) ############################################################## # Note that the parenthesized expression beginning with "(required" # has been broken to accomodate the newsgroup - was one line [sigh!] I've been using python and mysql on linux for 10 years and have done many 'hand installs' and boy has it gotten complicated. Any ideas? thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From python.list at tim.thechases.com Sun Jul 4 19:51:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 04 Jul 2010 18:51:54 -0500 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: <4C311E9A.4090308@tim.thechases.com> I think it's the same venting of frustration that caused veteran VB6 developers to start calling VB.Net "Visual Fred" -- the language was too different and too non-backwards-compatible. The 2to3 tools are better (partly due to the less drastic language changes compared to the Fred'ification of VB) than the VB6->Fred conversion tools. I'd also agree that Py3 comes closer to the language ideals that Py2.x aspired to be, but Py2.x was held back by the fairly strict moratorium on the introduction of backwards incompatible changes. The language changes also introduce frustrations when searching for example code: what was "Python" code examples now may or may not now work in Py3 or Py2 (and more importantly, may not have a caveat regarding which interpreter to use). Finally, the slow transformation of the vast volume of existing Python libraries adds a bit of irritant to the masses. There was some dialog on the Django mailing list a while back about Py3 transitions, but it's still pretty distant on the roadmap. I've often wondered if changing the name of the language (such as "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in the crowd) would have mitigated some of the more vituperative slurs on what became Py3, designating a shared legacy without the expectation of 100% backwards-compatibility. -tkc From nagle at animats.com Sun Jul 4 19:58:04 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 16:58:04 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> Message-ID: <4c31200c$0$1600$742ec2ed@news.sonic.net> On 7/4/2010 1:20 PM, sturlamolden wrote: > On 2 Jul, 21:07, John Nagle wrote: > >> http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ > > He is right on. The only thing Python 3k will do for me, is break all > my code and be incompatible with all extension modules I need. "What's > the point?" indeed. Exactly. The "incompatible with all extension modules I need" part is the problem right now. A good first step would be to identify the top 5 or 10 modules that are blocking a move to Python 3 by major projects with many users. John Nagle From roy at panix.com Sun Jul 4 20:05:03 2010 From: roy at panix.com (Roy Smith) Date: Sun, 04 Jul 2010 20:05:03 -0400 Subject: Python 3 put-downs: What's the point? References: Message-ID: In article , Tim Chase wrote: > I've often wondered if changing the name of the language (such as > "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in > the crowd) would have mitigated some of the more vituperative > slurs on what became Py3, designating a shared legacy without the > expectation of 100% backwards-compatibility. Maybe it should have been "Python five, no, THREE!" From clp2 at rebertia.com Sun Jul 4 20:21:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Jul 2010 17:21:37 -0700 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: On Sun, Jul 4, 2010 at 5:05 PM, Roy Smith wrote: > In article , > ?Tim Chase wrote: >> I've often wondered if changing the name of the language (such as >> "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in >> the crowd) would have mitigated some of the more vituperative >> slurs on what became Py3, designating a shared legacy without the >> expectation of 100% backwards-compatibility. > > Maybe it should have been "Python five, no, THREE!" +1 QOTW Cheers, Chris From steve at REMOVE-THIS-cybersource.com.au Sun Jul 4 20:29:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 00:29:32 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c31276b$0$28647$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 16:58:04 -0700, John Nagle wrote: > The "incompatible with all extension modules I need" part > is the problem right now. A good first step would be to identify the > top 5 or 10 modules that are blocking a move to Python 3 by major > projects with many users. Are you volunteering to assist, or just belly-aching? Migration to Python 3 is occurring at about the speed that should be expected, modulo the setback that was the seriously flawed 3.0 release. 3.1 should be treated as the "early adopter" version. I would expect 3.3 will probably be the first "mainstream" version, where v3 users start to outnumber v2 users. If people have concrete, *specific* issues that are holding them back from serious plans to migrate to Python 3 then reporting them is a good first step: e.g. telling the author of extension module Foo that you need Python 3 compatibility. Complaining that "extension modules aren't compatible" is just bitching for the sake of bitching and isn't helpful. Please take it elsewhere. Start a blog "why I hate Python 3" or something. Or just stick with Python 2.x forever, without the negativity. There's no law that says you have to upgrade. There are people still using 1.5, and more power to them. -- Steven From sturlamolden at yahoo.no Sun Jul 4 20:34:04 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 4 Jul 2010 17:34:04 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 5 Jul, 01:58, John Nagle wrote: > ? ? ?Exactly. > > ? ? ?The "incompatible with all extension modules I need" part > is the problem right now. ?A good first step would be to > identify the top 5 or 10 modules that are blocking a move to > Python 3 by major projects with many users. The big danger is Python 2.x becoming abandonware (2.7 being the final release) before major projects are ported. Using Python 2.x for new projects is not advisable (at least many will think so), and using 3.x is not possible. What to do? It's not a helpful situation for Python. From ben+python at benfinney.id.au Sun Jul 4 20:38:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 05 Jul 2010 10:38:56 +1000 Subject: Python 3 put-downs: What's the point? References: Message-ID: <87lj9qg3tr.fsf@benfinney.id.au> Roy Smith writes: > Maybe it should have been "Python five, no, THREE!" +1 QOTW -- \ ?Our products just aren't engineered for security.? ?Brian | `\ Valentine, senior vice-president of Microsoft Windows | _o__) development, 2002 | Ben Finney From greg.ewing at canterbury.ac.nz Sun Jul 4 20:49:17 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 05 Jul 2010 12:49:17 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: <89cnv0FjnuU1@mid.individual.net> kedra marbun wrote: > now, i'm asking another favor, what about the 2nd point in my 1st post? Your original post has dropped off my newsscope, so you'll have to remind me what the 2nd point was. -- Greg From smallpox911 at gmail.com Sun Jul 4 20:52:21 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 4 Jul 2010 17:52:21 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies mislead the public on the facts References: <16ef11cf-7b5a-470a-bea2-52e298ec2aaf@s9g2000yqd.googlegroups.com> Message-ID: <7a3b2761-905b-41d0-b506-9ed1c7d5f1b0@t10g2000yqg.googlegroups.com> VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies mislead the public on the facts http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html http://www.gtr5.com/ From smallpox911 at gmail.com Sun Jul 4 20:56:54 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 4 Jul 2010 17:56:54 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts Message-ID: <71420572-82ad-4945-931a-3452eeebcb1d@5g2000yqz.googlegroups.com> VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.youtube.com/watch?v=0q7yEnMjQ6U&feature=related http://www.youtube.com/watch?v=a3E2NcC0x20&feature=related http://www.youtube.com/watch?v=fRZSzdQuOqM&feature=related http://www.venusproject.com/911/911RussianSatellite1.html http://www.gtr5.com/ From cmpython at gmail.com Sun Jul 4 21:20:38 2010 From: cmpython at gmail.com (CM) Date: Sun, 4 Jul 2010 18:20:38 -0700 (PDT) Subject: Python 3 put-downs: What's the point? References: Message-ID: On Jul 4, 7:14?pm, Terry Reedy wrote: > I think there's a good point to Python 3 put-downs (if I take put-down to mean generally reasonable criticism, which is what I've read here recently, and not trolling). And that is simply to register dissent. Any online group is an opportunity to register dissent in a way that is public, open, immediate, interactive, and will (probably) be preserved for historians to check. The fact is, some people have gripes with Python 3; they are letting it be known. If no one did, there could be no later time at which people could look back and know what the reaction was to its introduction--it would just be a blank. Aren't opinions that dissent from the prevailing ones important to register, whether one thinks they are right or wrong? Che From philip at semanchuk.com Sun Jul 4 21:36:06 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 4 Jul 2010 21:36:06 -0400 Subject: Shared object access problems In-Reply-To: References: Message-ID: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> hi Tim, This seems more likely to be a MySQLdb problem than a Python one. Have you considered asking in the MySQLdb forums? On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > Using python 2.6.4 on slackware 13.1 > I have MySQLdb 'by hand', that is: by > 1)downloading MySQL-python-1.2.3c1.tar.gz > 2)unzipping tarfile > 3)running python setup.py build > 4)running python setup.py install > > The build and install seemed to proceded without error, > but upon invoking the interpreter and running >>>> import MySQLdb > I get the following ImportError: > ############################################################## > Traceback (most recent call last): > File "", line 1, in > File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", > line 19, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 7, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 6, in __bootstrap__ > ImportError: libmysqlclient_r.so.15: > cannot open shared object file: No such file or directory > ############################################################## > There was no libmysqlclient_r.so.15 on my machine, so I made > symlinks at both /usr/lib/mysql/ and /usr/lib which > are libmysqlclient_r.so.15 pointing to > /usr/lib/mysql/libmysqlclient_r.so.16.0.0 > > Now when I run import MySQLdb, I get the following error: > ############################################################## > Traceback (most recent call last): > File "", line 1, in > File "MySQLdb/__init__.py", line 19, in > import _mysql > File "build/bdist.linux-i686/egg/_mysql.py", > line 7, in > File "build/bdist.linux-i686/egg/_mysql.py", > line 6, in __bootstrap__ > ImportError: /usr/lib/libmysqlclient_r.so.15: > version `libmysqlclient_15' not found > (required by > /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg- > tmp > /_mysql.so) > ############################################################## > # Note that the parenthesized expression beginning with "(required" > # has been broken to accomodate the newsgroup - was one line > [sigh!] I've been using python and mysql on linux for 10 years and > have done many 'hand installs' and boy has it gotten complicated. > Any ideas? > thanks > > -- > Tim > tim at johnsons-web.com or akwebsoft.com > http://www.akwebsoft.com > -- > http://mail.python.org/mailman/listinfo/python-list From nagle at animats.com Sun Jul 4 21:59:03 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 18:59:03 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c313c67$0$1646$742ec2ed@news.sonic.net> On 7/4/2010 5:34 PM, sturlamolden wrote: > On 5 Jul, 01:58, John Nagle wrote: > >> Exactly. >> >> The "incompatible with all extension modules I need" part is the >> problem right now. A good first step would be to identify the top >> 5 or 10 modules that are blocking a move to Python 3 by major >> projects with many users. > > The big danger is Python 2.x becoming abandonware (2.7 being the > final release) before major projects are ported. Using Python 2.x > for new projects is not advisable (at least many will think so), and > using 3.x is not possible. What to do? It's not a helpful situation > for Python. Projects have been known to get into a state where version N-1 is abandonware, and version N isn't usable yet. Then they die off. The VRML-Web3D transition is an example. VRML 97 was ahead of its time because few people had enough graphics power in 1997 to run it. During the dot-com boom, the "Web 3D Consortium" (http://www.web3d.org) was formed to put 3D on the web. The approach chosen was to recast VRML in XML notation. Users were starting to get 3D boards in quantity, and VRML was starting to really work. But the forced transition killed work on VRML, while there wasn't enough momentum to get people to use the XML version. The Web3D consortium is still around. They have conferences. They have something of a niche market in DoD training sims. But they're running on empty. Nobody is paying attention. There's no mainstream interest in either VRML or Web3D. It works fine; there are X3D players, and they work great on modern graphics processors. But nobody cares. That's what happens when you mismanage an incompatible transition. That could happen to Python. Python has strong competition. In the last two years, Javascript has become much faster, PHP is getting a JIT compiler, Lua, as recently mentioned, is getting up there with C in speed, and Google is promoting Go. The other scripting languages are becoming rocket-powered. Meanwhile, Python is in year 2 of a 5-year plan to transition to something that goes no faster (and maybe slower) than the previous version. (Yes, there's Unladen Swallow and PyPy, but neither of those projects seems to be anywhere near deployment, and even if they succeed, their claimed speed goals are well below where the competition is now.) That's just not good enough any more. Denying that there's a problem does not help. John Nagle From nagle at animats.com Sun Jul 4 22:24:12 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 19:24:12 -0700 Subject: Shared object access problems In-Reply-To: References: Message-ID: <4c31424c$0$1613$742ec2ed@news.sonic.net> On 7/4/2010 6:36 PM, Philip Semanchuk wrote: > hi Tim, > This seems more likely to be a MySQLdb problem than a Python one. Have > you considered asking in the MySQLdb forums? > > On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > >> Using python 2.6.4 on slackware 13.1 >> I have MySQLdb 'by hand', that is: by >> 1)downloading MySQL-python-1.2.3c1.tar.gz >> 2)unzipping tarfile >> 3)running python setup.py build >> 4)running python setup.py install >> >> The build and install seemed to proceded without error, >> but upon invoking the interpreter and running >>>>> import MySQLdb >> I get the following ImportError: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >> line 19, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: libmysqlclient_r.so.15: >> cannot open shared object file: No such file or directory Did you install the development libraries for MySQL first? Those are needed to build MySQLdb yourself. John Nagle From ggrp2.20.martineau at dfgh.net Sun Jul 4 22:27:14 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Sun, 4 Jul 2010 19:27:14 -0700 (PDT) Subject: Python 2.7 released References: Message-ID: On Jul 4, 8:34?am, Benjamin Peterson wrote: > On behalf of the Python development team, I'm jocund to announce the second > release candidate of Python 2.7. > > Python 2.7 will be the last major version in the 2.x series. However, it will > also have an extended period of bugfix maintenance. > > 2.7 includes many features that were first released in Python 3.1. The faster io > module, the new nested with statement syntax, improved float repr, set literals, > dictionary views, and the memoryview object have been backported from 3.1. Other > features include an ordered dictionary implementation, unittests improvements, a > new sysconfig module, auto-numbering of fields in the str/unicode format method, > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlor Misc/NEWS in the Python > distribution. > > To download Python 2.7 visit: > > ? ? ?http://www.python.org/download/releases/2.7/ > > 2.7 documentation can be found at: > > ? ? ?http://docs.python.org/2.7/ > > This is a production release and should be suitable for all libraries and > applications. ?Please report any bugs you find, so they can be fixed in the next > maintenance releases. ?The bug tracker is at: > > ? ? ?http://bugs.python.org/ > > Enjoy! > > -- > Benjamin Peterson > Release Manager > benjamin at python.org > (on behalf of the entire python-dev team and 2.7's contributors) Benjamin (or anyone else), do you know where I can get the Compiled Windows Help file -- python27.chm -- for this release? In the past I've been able to download it from the Python web site, but have been unable to locate it anywhere for this new release. I can't build it myself because I don't have the Microsoft HTML help file compiler. Thanks in advance. From sjmachin at lexicon.net Sun Jul 4 22:58:18 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 4 Jul 2010 19:58:18 -0700 (PDT) Subject: Python 2.7 released References: Message-ID: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> On Jul 5, 12:27?pm, Martineau wrote: > On Jul 4, 8:34?am, Benjamin Peterson wrote: > > > > > On behalf of the Python development team, I'm jocund to announce the second > > release candidate of Python 2.7. > > > Python 2.7 will be the last major version in the 2.x series. However, it will > > also have an extended period of bugfix maintenance. > > > 2.7 includes many features that were first released in Python 3.1. The faster io > > module, the new nested with statement syntax, improved float repr, set literals, > > dictionary views, and the memoryview object have been backported from 3.1. Other > > features include an ordered dictionary implementation, unittests improvements, a > > new sysconfig module, auto-numbering of fields in the str/unicode format method, > > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWS in the Python > > distribution. > > > To download Python 2.7 visit: > > > ? ? ?http://www.python.org/download/releases/2.7/ > > > 2.7 documentation can be found at: > > > ? ? ?http://docs.python.org/2.7/ > > > This is a production release and should be suitable for all libraries and > > applications. ?Please report any bugs you find, so they can be fixed in the next > > maintenance releases. ?The bug tracker is at: > > > ? ? ?http://bugs.python.org/ > > > Enjoy! > > > -- > > Benjamin Peterson > > Release Manager > > benjamin at python.org > > (on behalf of the entire python-dev team and 2.7's contributors) > > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? In the past > I've been able to download it from the Python web site, but have been > unable to locate it anywhere for this new release. I can't build it > myself because I don't have the Microsoft HTML help file compiler. > > Thanks in advance. If you have a Windows box, download the .msi installer for Python 2.7 and install it. The chm file will be in C:\Python27\Doc (if you choose the default installation directory). Otherwise ask a friendly local Windows user for a copy. From tim at johnsons-web.com Sun Jul 4 23:00:01 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Sun, 4 Jul 2010 19:00:01 -0800 Subject: Shared object access problems In-Reply-To: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> References: <672E4CF8-C0BF-4401-983B-D27D0FFE33D1@semanchuk.com> Message-ID: <20100705030001.GA1875@johnsons-web.com> * Philip Semanchuk [100704 18:13]: > hi Tim, > This seems more likely to be a MySQLdb problem than a Python one. You are correct > Have you considered asking in the MySQLdb forums? Didn't know there was one! where is it? I will join thanks tim > On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: > >> Using python 2.6.4 on slackware 13.1 >> I have MySQLdb 'by hand', that is: by >> 1)downloading MySQL-python-1.2.3c1.tar.gz >> 2)unzipping tarfile >> 3)running python setup.py build >> 4)running python setup.py install >> >> The build and install seemed to proceded without error, >> but upon invoking the interpreter and running >>>>> import MySQLdb >> I get the following ImportError: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >> line 19, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: libmysqlclient_r.so.15: >> cannot open shared object file: No such file or directory >> ############################################################## >> There was no libmysqlclient_r.so.15 on my machine, so I made >> symlinks at both /usr/lib/mysql/ and /usr/lib which >> are libmysqlclient_r.so.15 pointing to >> /usr/lib/mysql/libmysqlclient_r.so.16.0.0 >> >> Now when I run import MySQLdb, I get the following error: >> ############################################################## >> Traceback (most recent call last): >> File "", line 1, in >> File "MySQLdb/__init__.py", line 19, in >> import _mysql >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 7, in >> File "build/bdist.linux-i686/egg/_mysql.py", >> line 6, in __bootstrap__ >> ImportError: /usr/lib/libmysqlclient_r.so.15: >> version `libmysqlclient_15' not found >> (required by >> /home/tim/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg- >> tmp >> /_mysql.so) >> ############################################################## >> # Note that the parenthesized expression beginning with "(required" >> # has been broken to accomodate the newsgroup - was one line >> [sigh!] I've been using python and mysql on linux for 10 years and >> have done many 'hand installs' and boy has it gotten complicated. >> Any ideas? >> thanks >> >> -- >> Tim >> tim at johnsons-web.com or akwebsoft.com >> http://www.akwebsoft.com >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From rantingrick at gmail.com Sun Jul 4 23:40:47 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 4 Jul 2010 20:40:47 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c313c67$0$1646$742ec2ed@news.sonic.net> Message-ID: On Jul 4, 8:59?pm, John Nagle wrote: > That's what happens when you > mismanage an incompatible transition. +1 > ? ? Python has strong competition. ?In the last two years, > Javascript has become much faster, PHP is getting a JIT compiler, > Lua, as recently mentioned, is getting up there with C in speed, and > Google is promoting Go. ?The other scripting languages are becoming > rocket-powered. ? Meanwhile, Python is in year 2 of a 5-year plan to > transition to something that goes no faster (and maybe slower) than > the previous version. ?(Yes, there's Unladen Swallow and PyPy, but > neither of those projects seems to be anywhere near deployment, > and even if they succeed, their claimed speed goals are well below where > the competition is now.) ?That's just not good enough any more. > > ? ? Denying that there's a problem does not help. +1 Hmm, i myself railed against the changes in Python3.x about 1 year ago. Then, as i pondered the reasons behind such changes i began to believe that the BDFL is wiser than us all! However, i must agree that many of the points you bring up here are real. People ARE stuck in limbo right now and there is no good direction to go... Stick with 2.x and have all the 3rd party support but soon enough you will need to do a major bug fixing, or move to 3.x -- oh wait i can't move to 3.x because module xxyy is not 3.x compatible! What we have here gentlemen is a situation, a terrible situation made worse by our lack to understand it. From breamoreboy at yahoo.co.uk Mon Jul 5 00:42:35 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 05 Jul 2010 05:42:35 +0100 Subject: Getting the name of the file that imported current module In-Reply-To: <4C311886.9050508@gmail.com> References: <4C311886.9050508@gmail.com> Message-ID: On 05/07/2010 00:25, Michael Torrie wrote: > On 07/04/2010 03:17 PM, Mark Lawrence wrote: >> On 04/07/2010 22:05, Tobiah wrote: >>> foo.py: >>> >>> import bar >>> bar.show_importer() >>> >>> output: >>> >>> 'foo' or 'foo.py' or 'path/to/foo' etc. >>> >>> Possible? >>> >>> Thanks, >>> >>> Tobiah >> >> >>> import re >> >>> re.__file__ >> 'C:\\Python26\\lib\\re.pyc' > > I think this is exactly opposite of what he was asking for. > > Given than any number of modules can import other modules but each > module really only exists once in the Python object space (normally) > would mean that what the OP is asking for isn't possible. You're absolutely correct, thou shalt not post late at night when very tired. :) Cheers. Mark Lawrence From dr.cg at 126.com Mon Jul 5 00:56:25 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 5 Jul 2010 12:56:25 +0800 (CST) Subject: Why Python forbids multiple instances of one module? Message-ID: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Why Python forbids multiple instances of one module? If only Python allows multiple instances of one module, module will be enough to replace class in most cases. After all, it is much easier to write a module than a class, at least we do not have to write self everywhere. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 5 01:42:02 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 4 Jul 2010 23:42:02 -0600 Subject: Why Python forbids multiple instances of one module? In-Reply-To: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: 2010/7/4 CHEN Guang : > Why Python forbids multiple instances of one module? > If only Python allows multiple instances of one module, module will > be?enough to replace class in most cases. > After all, it is much easier to?write?a module than a class, at least we do > not have to write self everywhere. If you really want to do that, it should be possible by deleting the entry from sys.modules and re-importing it. You save yourself having to explicitly write self everywhere, but instead you have to declare all your "instance" variables as globals in each "method" that uses them, which isn't much less of a chore. You also lose inheritance, properties (and descriptors in general), magic method support, metaclasses, and pretty much all the other nice features that new-style classes have to offer. From tjreedy at udel.edu Mon Jul 5 01:44:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 01:44:46 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c31200c$0$1600$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 7/4/2010 7:58 PM, John Nagle wrote: > The "incompatible with all extension modules I need" part > is the problem right now. A good first step would be to > identify the top 5 or 10 modules that are blocking a move to > Python 3 by major projects with many users. Let me repeat. Last September, if not before, Guido identified numpy as a top package blocking moves by other packages and projects. I am not sure what he thought, but I consider it number 1. He encouraged the numpy people to produce a 3.x version even though some did not see any personal benefit. We supposedly will see numpy for 3.2. If we actually do, other dominoes will fall into place. I you have any other ideas about other top blockers, please share them. -- Terry Jan Reedy From clp2 at rebertia.com Mon Jul 5 01:49:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Jul 2010 22:49:54 -0700 Subject: Why Python forbids multiple instances of one module? In-Reply-To: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: 2010/7/4 CHEN Guang : > Why Python forbids multiple instances of one module? That's just how its import mechanism works. It allows for modules that need canonical program-wide state to rely on being singleton, and it's also an optimization. You can trick the import machinery and get around the restriction though. > If only Python allows multiple instances of one module, module will > be?enough to replace class in most cases. Why do classes need replacement in the first place? Modules and classes serve distinct purposes. Also: How would you specify a class-module's superclasses? And what if a class depends on other modules/classes/packages? Then the class-module's namespace would be polluted with all the stuff it imported; ick. > After all, it is much easier to?write?a module than a class, at least we do > not have to write self everywhere. That seems a relatively petty reason; see also Ian's excellent point about `global`. Cheers, Chris -- Yay, Fireworks! http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Mon Jul 5 02:31:46 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 06:31:46 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c317c52$0$28665$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 17:34:04 -0700, sturlamolden wrote: > Using Python 2.x for new > projects is not advisable (at least many will think so), and using 3.x > is not possible. What to do? It's not a helpful situation for Python. That's pure FUD. Python 2.7 will be supported longer than the normal support period for versions 2.6, 2.5, 2.4, ... so if you have a new project that requires libraries that aren't available for 3.1, then go right ahead and use 2.7. By the time 2.7 is no longer supported (probably around the time 3.4 comes out?), the library situation will be fixed. Those 3.1 features that can be backported to 2.x have been, specifically to reduce the pain in porting 2.7-based applications to 3.x. Feature- wise, 2.7 is designed to ease the transition from the 2.x series to the 3.x series. Claiming that it's not advisable to use 2.7 is simply nonsense. -- Steven From ldo at geek-central.gen.new_zealand Mon Jul 5 02:50:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:50:10 +1200 Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> <7xpqzbj8st.fsf@ruckus.brouhaha.com> Message-ID: In message <7xpqzbj8st.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > ... and argc/argv were passed to the child process on its stack. I?ve always felt that to be a misfeature. It means you can?t implement a self-contained argument-parsing library, it still needs the mainline to explicitly pass/put its arguments somewhere. From ldo at geek-central.gen.new_zealand Mon Jul 5 02:52:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:52:39 +1200 Subject: Python as a scripting language. Alternative to bash script? References: Message-ID: In message , Mithrandir wrote: > I think that Python "could" be a alternative to bash and have some > advantages, but it's a long way off from being fully implemented. Would you prefer to do the following sort of thing in Python or Bash? AudioParms = "-f s16le -ar 48000 -ac 2" # because I can't seem to pipe compressed audio ImportCmd = \ ( "ffmpeg -v 0 -i <(%(src_video)s)" " %(audio_parms)s -i <(%(src_audio)s)" " -vcodec copy -acodec %(audio_codec)s -y %(dstfile)s" % { "src_video" : "; ".join ( [ "ffmpeg -v 0 -i %(srcfile)s -f image2pipe -vcodec copy" " -y /dev/stdout" % {"srcfile" : ShellEscape(SrcFile)} for SrcFile in SrcFiles ] ), # pipe through compressed video without recompression "src_audio" : "; ".join ( [ "ffmpeg -v 0 -i %(srcfile)s %(audio_parms)s -y /dev/stdout" % { "srcfile" : ShellEscape(SrcFile), "audio_parms" : AudioParms, } for SrcFile in SrcFiles ] ), "dstfile" : ShellEscape(DstFile), "audio_parms" : AudioParms, "audio_codec" : "mp2", # assumption! } ) From ldo at geek-central.gen.new_zealand Mon Jul 5 02:56:02 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 05 Jul 2010 18:56:02 +1200 Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: In message , Rhodri James wrote: > Classic Unix programming is a matter of stringing a bunch of tools > together with pipes to get the output you want. This isn't a great > paradigm for GUIs (not without tweaking that hasn't really been done), but > then again it was never meant to be. I?ve never come across any system where you could string together multiple GUI apps, or even multiple GUI operations in the same app, in any sensible or effective way at all. GUIs just aren?t designed to work that way. The command line (or scripting, the difference isn?t that important) remains the only workable way to string together complex combinations of simpler operations. From nagle at animats.com Mon Jul 5 02:56:53 2010 From: nagle at animats.com (John Nagle) Date: Sun, 04 Jul 2010 23:56:53 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: <4c318235$0$1663$742ec2ed@news.sonic.net> On 7/4/2010 10:44 PM, Terry Reedy wrote: > On 7/4/2010 7:58 PM, John Nagle wrote: > >> The "incompatible with all extension modules I need" part >> is the problem right now. A good first step would be to >> identify the top 5 or 10 modules that are blocking a move to >> Python 3 by major projects with many users. > > Let me repeat. Last September, if not before, Guido identified numpy as > a top package blocking moves by other packages and projects. I am not > sure what he thought, but I consider it number 1. He encouraged the > numpy people to produce a 3.x version even though some did not see any > personal benefit. We supposedly will see numpy for 3.2. If we actually > do, other dominoes will fall into place. > > I you have any other ideas about other top blockers, please share them. The Twisted team has a list of what they need: "http://stackoverflow.com/questions/172306/how-are-you-planning-on-handling-the-migration-to-python-3" * Zope Interface * PyCrypto * PyOpenSSL * PyGTK John Nagle From steve-REMOVE-THIS at cybersource.com.au Mon Jul 5 03:07:22 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 05 Jul 2010 07:07:22 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c313c67$0$1646$742ec2ed@news.sonic.net> Message-ID: <4c3184a9$0$28665$c3e8da3@news.astraweb.com> On Sun, 04 Jul 2010 18:59:03 -0700, John Nagle wrote: > Denying that there's a problem does not help. Nobody is denying that there is a problem, but there are plenty of people denying that there are any solutions. The folks doing development of CPython are genuinely interested in constructive criticism. Go spend some time on the python-dev mailing list to see that they're serious about resolving problems. But harping on and on with the same old negatives and same old FUD ("Python is too slow, nothing works with Python 3, people will abandon Python, the transition is being mismanaged, blah blah blah blah") conspicuously lacking in *actual* details is not helping anyone. Let's hear specifics. What is your project, what is the project timeline, why did you want to use 3.1 (instead of, say, waiting for 3.2) and what *specific* problem stopped you? I'm not interested in hand-waving and vague generalities. I want to hear names and versions, not bitching. "We are planning on building an app to do Foo, and choose to target 2.6 instead of 3.1 because the 3rd party FooLib only supports 2.5 and 2.6..." "I wrote an app using 3.1, and ran into these really painful problems with this library..." That's the sort of thing that is helpful. By the same token, if you've successfully targeted 3.1, we'd love to hear your success stories too. -- Steven From solipsis at pitrou.net Mon Jul 5 03:28:45 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 5 Jul 2010 09:28:45 +0200 Subject: Python 3 put-downs: What's the point? References: Message-ID: <20100705092845.25702499@pitrou.net> On Sun, 4 Jul 2010 18:20:38 -0700 (PDT) CM wrote: > > Any online group is an opportunity to register dissent in a way that > is public, open, immediate, interactive, and will (probably) be > preserved for historians to check. The fact is, some people have > gripes with Python 3; they are letting it be known. If no one did, > there could be no later time at which people could look back and know > what the reaction was to its introduction--it would just be a blank. > Aren't opinions that dissent from the prevailing ones important to > register, whether one thinks they are right or wrong? Sure. As long as you don't record the same dissent from the same person ten times in a row. Then it becomes trolling. From dickinsm at gmail.com Mon Jul 5 03:44:52 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 5 Jul 2010 00:44:52 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> Message-ID: <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> On Jul 4, 11:02?pm, John Machin wrote: > On Jul 5, 1:08?am, Thomas Jollans wrote: > > > On 07/04/2010 03:49 PM, jmfauth wrote: > > > ? File "", line 1 > > > ? ? print9.0 > > > ? ? ? ? ? ?^ > > > SyntaxError: invalid syntax > > > somewhat strange, yes. > > There are two tokens, "print9" (a name) and ".0" (a float constant) -- > looks like SyntaxError to me. Yep. Looks that way to me, too. Python 2.7.0+ (release27-maint:82569, Jul 5 2010, 08:35:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from cStringIO import StringIO >>> import tokenize, token >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): ... print token.tok_name[tok[0]], tok[1] ... NAME print9 NUMBER .0 ENDMARKER -- Mark From gh at gregor-horvath.com Mon Jul 5 03:50:32 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Mon, 5 Jul 2010 09:50:32 +0200 Subject: Python 3 put-downs: What's the point? References: Message-ID: <20100705095032.6f7749fe@brasov> Am Sun, 04 Jul 2010 18:51:54 -0500 schrieb Tim Chase : > I think it's the same venting of frustration that caused veteran > VB6 developers to start calling VB.Net "Visual Fred" -- the > language was too different and too non-backwards-compatible. > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. VB6 and VB.NET are totally different languages and technologies, with some similarity in syntax. This is not true for Python 2->3. This is an healthy organic language growth, not an abandon of a language. -- Greg From benjamin.kaplan at case.edu Mon Jul 5 04:12:34 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 5 Jul 2010 01:12:34 -0700 Subject: Python 2.7 released In-Reply-To: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: On Sun, Jul 4, 2010 at 7:58 PM, John Machin wrote: > On Jul 5, 12:27?pm, Martineau wrote: >> On Jul 4, 8:34?am, Benjamin Peterson wrote: >> >> >> >> > On behalf of the Python development team, I'm jocund to announce the second >> > release candidate of Python 2.7. >> >> > Python 2.7 will be the last major version in the 2.x series. However, it will >> > also have an extended period of bugfix maintenance. >> >> > 2.7 includes many features that were first released in Python 3.1. The faster io >> > module, the new nested with statement syntax, improved float repr, set literals, >> > dictionary views, and the memoryview object have been backported from 3.1. Other >> > features include an ordered dictionary implementation, unittests improvements, a >> > new sysconfig module, auto-numbering of fields in the str/unicode format method, >> > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in >> > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWS in the Python >> > distribution. >> >> > To download Python 2.7 visit: >> >> > ? ? ?http://www.python.org/download/releases/2.7/ >> >> > 2.7 documentation can be found at: >> >> > ? ? ?http://docs.python.org/2.7/ >> >> > This is a production release and should be suitable for all libraries and >> > applications. ?Please report any bugs you find, so they can be fixed in the next >> > maintenance releases. ?The bug tracker is at: >> >> > ? ? ?http://bugs.python.org/ >> >> > Enjoy! >> >> > -- >> > Benjamin Peterson >> > Release Manager >> > benjamin at python.org >> > (on behalf of the entire python-dev team and 2.7's contributors) >> >> Benjamin (or anyone else), do you know where I can get the Compiled >> Windows Help file -- python27.chm -- for this release? In the past >> I've been able to download it from the Python web site, but have been >> unable to locate it anywhere for this new release. I can't build it >> myself because I don't have the Microsoft HTML help file compiler. >> >> Thanks in advance. > > If you have a Windows box, download the .msi installer for Python 2.7 > and install it. The chm file will be in C:\Python27\Doc (if you choose > the default installation directory). Otherwise ask a friendly local > Windows user for a copy. > -- Or you can just use 7-zip or cabextract on the MSi. Saves you from having to uninstall it later, and it works on non-Windows machines. From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 5 04:42:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 05 Jul 2010 10:42:13 +0200 Subject: delegation pattern via descriptor In-Reply-To: <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> Message-ID: <4c319ae6$0$14953$426a74cc@news.free.fr> kedra marbun a ?crit : > i'm confused which part that doesn't make sense? > this is my 2nd attempt to py, the 1st was on april this year, it was > just a month, i'm afraid i haven't got the fundamentals right yet. so > i'm gonna lay out how i got to this conclusion, CMIIW > > **explanation of feeling (0) on my 1st post** > to me, descriptor is a particular kind of delegation, it takes the job > of coding the delegation by having a contract with programmers that > the tree meta operations (get, set, del) on attr are delegated to the > obj that is bound to the attr > are we agree that descriptor is a kind of delegation? > > the mechanism that makes descriptor works is in __getattribute__, > __setattr__, __delattr__ of 'object' & 'type' > > now, if i want a single descriptor obj to be delegated to multiple > tasks, i can't do it since __get__ doesn't get info that can be used > to determine which task to do > i must have diff descriptor obj for each task > > class Helper: > def __init__(self, name): > self.name = name > def __get__(self, ins, cls): > if self.name == 'task0': ... > elif self.name == 'task1': ... > else: ... Replacing such "big switch" code with polymorphic dispatch is one of the goals (and feature) of OO. This should be: class Task0(object): def __get__(self, obj, cls): # code here class Task1(object): def __get__(self, obj, cls): # code here class A(object): task0 = Task0() task1 = Task1() If you have common code to share between TaskO and Task1 then factor it out into a base class. > if __get__ receives the name, then i could do > > class Helper: > def __get__(self, ins, cls, name): > ... > > class a: > task0 = task1 = Helper() Yuck. From anthra.norell at bluewin.ch Mon Jul 5 05:07:42 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 11:07:42 +0200 Subject: What is the name of the name space I am in? Message-ID: <4C31A0DE.7010907@bluewin.ch> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue what the "dict" of the current name space is. I can name dicts of imported modules, because their name exists in the current name space. If, for instance, I import a module "service" then that module's name space would be "service.__dict__". But if I import * from service, then I incorporate that name space into the current one and I cannot name it, because the current module's name is not part of the module's own name space. "dir (service)" is equivalent to "service.__dict__.keys ()" if service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" where "?" is the name of the current module, itself not part of the current module's name space. So the question mark stands for an implicit name that can be neither named nor dropped. So my question is: how does one name the dictionary of the name space one is in? Frederic From thomas at jollans.com Mon Jul 5 05:27:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 11:27:37 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A0DE.7010907@bluewin.ch> References: <4C31A0DE.7010907@bluewin.ch> Message-ID: <4C31A589.3070008@jollans.com> On 07/05/2010 11:07 AM, Anthra Norell wrote: > I try to use "new.new.classobj (name, baseclass, dict)" and have no clue > what the "dict" of the current name space is. I can name dicts of > imported modules, because their name exists in the current name space. > If, for instance, I import a module "service" then that module's name > space would be "service.__dict__". But if I import * from service, then > I incorporate that name space into the current one and I cannot name it, > because the current module's name is not part of the module's own name > space. "dir (service)" is equivalent to "service.__dict__.keys ()" if > service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" > where "?" is the name of the current module, itself not part of the > current module's name space. So the question mark stands for an implicit > name that can be neither named nor dropped. So my question is: how does > one name the dictionary of the name space one is in? either globals() or locals(), depending on what you mean. > > Frederic > From soltysh at gmail.com Mon Jul 5 05:31:20 2010 From: soltysh at gmail.com (Soltys) Date: Mon, 5 Jul 2010 02:31:20 -0700 (PDT) Subject: GAE + recursion limit References: <2b92c520-290d-47f8-94cb-d6291eca19bd@c33g2000yqm.googlegroups.com> <70bd0175-f752-4714-a7d9-49a65fc13f75@e5g2000yqn.googlegroups.com> Message-ID: <5dd9cd31-9d57-4a99-94cf-7818e305df1e@5g2000yqz.googlegroups.com> On 2 Lip, 22:49, Paul McGuire wrote: > > Does anyone have any clue what that might be? > > Why the problem is onGAE(even when run locally), when command line > > run works just fine (even withrecursionlimitdecreased)? > > Can't explain why you see different behavior onGAEvs. local, but it > is unusual for a "small" translator to flirt withrecursionlimit. ?I > don't usually see parsers come close to this with fewer than 40 or 50 > sub-expressions. ?You may have some left-recursiongoing on. ?Can you > post your translator somewhere, perhaps on pastebin, or on the > pyparsing wiki Discussion page (pyparsing.wikispaces.com)? > > -- Paul @David, thanks for the advice, I did ask on GAE list, id not get answer till now though. @Paul, I think I solved it. I did extensive test during weekend and it appears that my regular translator almost reaches 1000 recursion limit. Probably the last time I've tried to increase the recursion limit for GAE app I did it in the wrong place. (For future, if you'd like to do it, the best and working is to set that right before call to run_wsgi_app(application)). The only think that remains is, I need to review the grammar and how processing happens that I reach that limit with GAE. Thanks guys, Soltys From jeanmichel at sequans.com Mon Jul 5 05:52:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Jul 2010 11:52:58 +0200 Subject: [ANN] eric 5.0.0 released In-Reply-To: References: Message-ID: <4C31AB7A.2000107@sequans.com> Detlev Offenbach wrote: > Hi, > > I just uploaded eric 5.0.0. This is the first official release. It > is available via the eric web site. > > http://eric-ide.python-projects.org/index.html > > What is it? > ----------- > eric5 is the Python3 variant of the well know eric4 Python IDE and is > the first development environment, that runs natively with Python3. It > comes with all batteries included. The features are too much to be > listed in this announcement. Please see the eric web site for details. > > Regards, > Detlev > Nice work, thanks for sharing. JM From clp2 at rebertia.com Mon Jul 5 06:03:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 03:03:13 -0700 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A0DE.7010907@bluewin.ch> References: <4C31A0DE.7010907@bluewin.ch> Message-ID: On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell wrote: > I try to use "new.new.classobj (name, baseclass, dict)" and have no clue Slight tangent: Note that both the `new` module and old-style classes (which are what `classobj` produces) are deprecated. To produce new-style classes dynamically, use `type`. Cheers, Chris -- http://blog.rebertia.com From cournape at gmail.com Mon Jul 5 06:04:35 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 5 Jul 2010 17:04:35 +0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On Mon, Jul 5, 2010 at 12:44 PM, Terry Reedy wrote: > On 7/4/2010 7:58 PM, John Nagle wrote: > >> The "incompatible with all extension modules I need" part >> is the problem right now. A good first step would be to >> identify the top 5 or 10 modules that are blocking a move to >> Python 3 by major projects with many users. > > Let me repeat. Last September, if not before, Guido identified numpy as a > top package blocking moves by other packages and projects. I am not sure > what he thought, but I consider it number 1. He encouraged the numpy people > to produce a 3.x version even though some did not see any personal benefit. > We supposedly will see numpy for 3.2. I think numpy will work for 3.1 as well (I don't know about 3.0, but my understanding is that there is no point into even looking at that release). With the scipy conferences going on, it will certainly be a good occasion to synchronize a bit faster - nothing beats face to face as a communication medium after all :) David From ncauderan at gmail.com Mon Jul 5 06:07:16 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 03:07:16 -0700 (PDT) Subject: SMTPHandler and Unicode Message-ID: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Hello, I want to send error messages with SMTPHandler logging. But SMTPHandler does not seem to be unicode aware. Is there something doable without playing with sys.setdefaultencoding ? import logging,logging.handlers smtpHandler = logging.handlers.SMTPHandler(mailhost=("smtp.example.com",25), fromaddr="toto at example.com", toaddrs="toto at example.com", subject=u"error message") LOG = logging.getLogger() LOG.addHandler(smtpHandler) LOG.error(u"sans accent") LOG.error(u"accentu\u00E9") gives : UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 117: ordinal not in range(128) Thank you ! From googler.1.webmaster at spamgourmet.com Mon Jul 5 06:38:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 5 Jul 2010 03:38:37 -0700 (PDT) Subject: Crash in PyThread_acquire_lock References: <4714dd95-3d44-4d25-b44f-41613e4bd86e@y4g2000yqy.googlegroups.com> Message-ID: <4c47da20-5203-441a-b6aa-da5f0cdc9f3a@w31g2000yqb.googlegroups.com> Thanks Antoine! :) You were right. It was the wrong thread...uhmm... Bye! :) From kylotan at gmail.com Mon Jul 5 06:40:53 2010 From: kylotan at gmail.com (Ben Sizer) Date: Mon, 5 Jul 2010 03:40:53 -0700 (PDT) Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> Message-ID: <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> On Jul 4, 7:33?am, Stefan Behnel wrote: > BenSizer, 04.07.2010 00:32: > > > On Jul 3, 11:12 pm,BenSizer ?wrote: > > >> >>> for el in root.getiterator(): > > >> ... ? ? ? ?print el > >> [much output snipped] > >> > >> > >> > >> > > > Hmm, I think I've worked it out. Apparently the XML namespace forms > > part of the tag name in this case. Is that what is intended? > > Sure. > > > I didn't see any examples of this in the docs. > > Admittedly, it's three clicks away from the library docs on docs.python.org. > > http://effbot.org/zone/element.htm#xml-namespaces Hopefully someone will see fit to roll this important documentation into docs.python.org before the next release... oops, too late. ;) It's one of those things that's easy to fix when you know what the problem is. Unfortunately it makes the examples a bit awkward. The example on http://docs.python.org/library/xml.etree.elementtree.html opens up an xhtml file and reads a "p" tag within a "body" tag, but the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states that 'The root element of the document must contain an xmlns declaration for the XHTML namespace'. Therefore I don't see how the example Python code given could work on a proper xhtml file, given that there should always be a namespace in effect but the code doesn't allow for it. That's my excuse anyway! :) -- Ben Sizer From fetchinson at googlemail.com Mon Jul 5 06:47:15 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 5 Jul 2010 12:47:15 +0200 Subject: Twisted 10.1.0 released In-Reply-To: References: Message-ID: > On behalf of Twisted Matrix Laboratories, I am honored to announce the > release of Twisted 10.1.0. > > Highlights include: > > * Deferreds now support cancellation > > * A new "endpoint" interface which can abstractly describe stream > transport endpoints such as TCP and SSL > > * inotify support for Linux, which allows monitoring of file system events. > > * AMP supports transferring timestamps > > Note also that this is the *last* supported release of Twisted for > Python 2.4 on Windows. > > For more information, see the NEWS file. > > It's stable, backwards compatible, well tested and in every way an > improvement. Download it now from: > > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.tar.bz2 > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.5.msi > http://tmrc.mit.edu/mirror/twisted/Twisted/10.1/Twisted-10.1.0.winxp32-py2.6.msi > > Many thanks to Glyph Lefkowitz, who helped do the release preparation, > and the PyCon 2010 sprinters, who did so much of the work for this > release. > The twisted website at http://twistedmatrix.com/ seems to be having issues (trac can not connect to its database?). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chris at simplistix.co.uk Mon Jul 5 07:17:02 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 12:17:02 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Message-ID: <4C31BF2E.8060907@simplistix.co.uk> norbert wrote: > I want to send error messages with SMTPHandler logging. But > SMTPHandler does not seem to be unicode aware. Is there something > doable without playing with sys.setdefaultencoding ? try MailingLogger: http://www.simplistix.co.uk/software/python/mailinglogger If you have unicode problems with that, I'd be interested in fixing them! cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From ritchy_gato at hotmail.com Mon Jul 5 07:45:13 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Mon, 5 Jul 2010 04:45:13 -0700 (PDT) Subject: Plot problem.. ?? No sign at all Message-ID: hello guys.. I'm new at python programming and i'm having some problems with a script that i have been developing for my final project of my graduation. I have a script that is supposed to make a plot of a "Residuo" (waveform) witch is an output of a ADC ( Analogic To Digital Converter) for the first stage of the Flash pipiline ADC structure.This script doesn't show any syntax errors but it doesn't show no waveform at all at the plot window. I'm worried about this situation so I came here looking for help since I am new to the Python language. ----------------------------------------------------------------------- from pylab import* Vref = arange(1, 20, 0.02) Vi = arange(1, 10,0.1) for i in Vref: for n in Vi: if n > i/4: V0 = 2*n-i elif (-i/4) <= n and n <= i/4: V0 = 2*n elif Vi < -i/4: V0 = 2*n+i else: print "Try Again" ##print V0 plot (V0)boboz10 -------------------------------------------------------------------------------- From anthra.norell at bluewin.ch Mon Jul 5 08:16:25 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 14:16:25 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <4C31A589.3070008@jollans.com> References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> Message-ID: <4C31CD19.9040405@bluewin.ch> Thomas Jollans wrote: > On 07/05/2010 11:07 AM, Anthra Norell wrote: > >> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >> what the "dict" of the current name space is. I can name dicts of >> imported modules, because their name exists in the current name space. >> If, for instance, I import a module "service" then that module's name >> space would be "service.__dict__". But if I import * from service, then >> I incorporate that name space into the current one and I cannot name it, >> because the current module's name is not part of the module's own name >> space. "dir (service)" is equivalent to "service.__dict__.keys ()" if >> service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" >> where "?" is the name of the current module, itself not part of the >> current module's name space. So the question mark stands for an implicit >> name that can be neither named nor dropped. So my question is: how does >> one name the dictionary of the name space one is in? >> > > either globals() or locals(), depending on what you mean. > > >> Frederic >> >> Thomas, Thanks a million. Just the tip I needed. Frederic From ncauderan at gmail.com Mon Jul 5 08:22:17 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 05:22:17 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> Message-ID: <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> On 5 juil, 13:17, Chris Withers wrote: > try MailingLogger: > > If you have unicode problems with that, I'd be interested in fixing them! Your package has the same unicode problem : import logging,logging.handlers from mailinglogger.MailingLogger import MailingLogger mailingLogger = MailingLogger(mailhost=('smtp.example.com', 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) LOG = logging.getLogger() LOG.addHandler(mailingLogger) LOG.error(u"sans accent") LOG.error(u"accentu\u00E9") --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128) From chris at simplistix.co.uk Mon Jul 5 08:32:13 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 13:32:13 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> Message-ID: <4C31D0CD.4040607@simplistix.co.uk> norbert wrote: > Your package has the same unicode problem : > import logging,logging.handlers > from mailinglogger.MailingLogger import MailingLogger > mailingLogger = MailingLogger(mailhost=('smtp.example.com', > 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) > LOG = logging.getLogger() > LOG.addHandler(mailingLogger) > LOG.error(u"sans accent") > LOG.error(u"accentu\u00E9") > > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' > in position 7: ordinal not in range(128) Interesting, I don't know what the logging framework's position is on unicode... What happens when you try the same logging with just a FileHandler registered? What encoding does the log file use? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From python at mrabarnett.plus.com Mon Jul 5 08:49:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 05 Jul 2010 13:49:39 +0100 Subject: Plot problem.. ?? No sign at all In-Reply-To: References: Message-ID: <4C31D4E3.5050500@mrabarnett.plus.com> Ritchy lelis wrote: > hello guys.. > > I'm new at python programming and i'm having some problems with a > script that i have been developing for my final project of my > graduation. > > I have a script that is supposed to make a plot of a > "Residuo" (waveform) witch is an output of a ADC ( Analogic To Digital > Converter) for the first stage of the Flash pipiline ADC > structure.This script doesn't show any syntax errors but it doesn't > show no waveform at all at the plot window. > > I'm worried about this situation so I came here looking for help since > I am new to the Python language. > > > ----------------------------------------------------------------------- > > from pylab import* > > Vref = arange(1, 20, 0.02) > Vi = arange(1, 10,0.1) > > for i in Vref: > for n in Vi: > if n > i/4: > V0 = 2*n-i > elif (-i/4) <= n and n <= i/4: > V0 = 2*n > elif Vi < -i/4: > V0 = 2*n+i > else: > print "Try Again" > ##print V0 > plot (V0)boboz10 > > -------------------------------------------------------------------------------- > Only the first 2 'if' conditions are ever true, so nothing is ever plotted. Also, I don't know what you're trying to do here: elif Vi < -i/4: because Vi is an array and i is a float. If Python ever tried to execute it there would be a ValueError exception: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() From ncauderan at gmail.com Mon Jul 5 09:17:38 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 06:17:38 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> Message-ID: <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> On 5 juil, 14:32, Chris Withers wrote: > norbert wrote: > > Your package has the same unicode problem : > > import logging,logging.handlers > > from mailinglogger.MailingLogger import MailingLogger > > mailingLogger = MailingLogger(mailhost=('smtp.example.com', > > 25),fromaddr='t... at example.com',toaddrs=('t... at example.com',)) > > LOG = logging.getLogger() > > LOG.addHandler(mailingLogger) > > LOG.error(u"sans accent") > > LOG.error(u"accentu\u00E9") > > > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' > > in position 7: ordinal not in range(128) > > Interesting, I don't know what the logging framework's position is on > unicode... > > What happens when you try the same logging with just a FileHandler > registered? What encoding does the log file use? > a FileHandler works as expected, the log file being UTF-8 encoded. The SMTPHandler is the only logger I know with this problem, maybe connected to SMTPLib implementation ? From anthra.norell at bluewin.ch Mon Jul 5 09:26:03 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 05 Jul 2010 15:26:03 +0200 Subject: What is the name of the name space I am in? In-Reply-To: References: <4C31A0DE.7010907@bluewin.ch> Message-ID: <4C31DD6B.2060306@bluewin.ch> Chris Rebert wrote: > On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell wrote: > >> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >> > > Slight tangent: > Note that both the `new` module and old-style classes (which are what > `classobj` produces) are deprecated. > To produce new-style classes dynamically, use `type`. > > Cheers, > Chris > -- > http://blog.rebertia.com > > Chris, I noticed the deprecation situation reading the doc, but opted for what I thought might be more backward-compatible. Your suggestion prompted me to take a closer look and it turns out that "types" is compatible as far back as I have to go (2.5). So I use "types" with thanks to you. From solipsis at pitrou.net Mon Jul 5 09:35:32 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 5 Jul 2010 15:35:32 +0200 Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <20100705153532.210103be@pitrou.net> On Mon, 5 Jul 2010 06:17:38 -0700 (PDT) norbert wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. Ouch. Implicit encoding sounds like a bad behaviour. > The > SMTPHandler is the only logger I know with this problem, maybe > connected to SMTPLib implementation ? I suggest you report an issue on http://bugs.python.org From roy at panix.com Mon Jul 5 09:51:53 2010 From: roy at panix.com (Roy Smith) Date: Mon, 05 Jul 2010 09:51:53 -0400 Subject: Python 3 put-downs: What's the point? References: Message-ID: In article , Dennis Lee Bieber wrote: > On Sun, 04 Jul 2010 20:05:03 -0400, Roy Smith declaimed > the following in gmane.comp.python.general: > > > In article , > > Tim Chase wrote: > > > > > I've often wondered if changing the name of the language (such as > > > "Adder", "Served", "Dwarf" or "Fawlty" for the Britcom fans in > > > the crowd) would have mitigated some of the more vituperative > > > slurs on what became Py3, designating a shared legacy without the > > > expectation of 100% backwards-compatibility. > > > > Maybe it should have been "Python five, no, THREE!" > > But Adder works on two levels... The BritCom, and the serpentine... Not to mention that the same main characters show up in each version :-) From 88pigs at gmail.com Mon Jul 5 10:19:36 2010 From: 88pigs at gmail.com (=?GB2312?B?1uzW2LDL?=) Date: Mon, 5 Jul 2010 22:19:36 +0800 Subject: black console window of executing os.chmod() and os.access() Message-ID: Hi all, I want to use os.chmod or os.access to check the permission of a folder on remote Windows computer: os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) or os.access("\\1.1.1.1\sharedfolder", os.W_OK) I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a black console window display one second. Only remote folder has this problem, local folder has no this problem. Anybody know how to remove the black console window? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bill at SynectixLtd.com Mon Jul 5 10:35:59 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Mon, 5 Jul 2010 15:35:59 +0100 Subject: ImportError: DLL load failed: The specified module could not be found, SWIG, life, etc Message-ID: <89e8ueFuc6U1@mid.individual.net> I am struggling :-( I have used SWIG to build a module called SHIP. So I have a directory containing SHIP.py and _SHIP.pyd, as follows: H:\Viper\HostPC\V1\SHIP\Release>dir Volume in drive H has no label. Volume Serial Number is B83B-76F2 Directory of H:\Viper\HostPC\V1\SHIP\Release 05/07/2010 14:43 . 05/07/2010 14:43 .. 03/07/2010 16:28 41,079 SHIP.py 03/07/2010 14:36 495,616 _SHIP.pyd 2 File(s) 536,695 bytes 2 Dir(s) 58,270,535,680 bytes free I have a test Python program which imports sys and os and then attempts to import SHIP; it begins as follows: ## D for John's notebook ## E for Rod's notebook ## H for Bill's notebook DRIVE = 'H:' import sys import os if ( not os.path.exists(DRIVE) ): print "Drive \'%s\' does not exist on this machine; edit top of file" % (DRIVE) sys.exit(0) # Prepend our path sys.path[:0] = [DRIVE + r'\Viper\HostPC\V1\SHIP\Release'] import SHIP SHIP.Initialise(); I then create a Command Prompt window and enter: H:\Viper\HostPC\V1\SHIP>C:\Python26\python -vv Test1.py >tmp.txt 2>&1 In tmp.txt, I see the following: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. # trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyd # trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.py # H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc matches H:\Viper\HostPC\V1\SHIP\Release\SHIP.py import SHIP # precompiled from H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc # trying H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd # clear[2] __name__ # clear[2] __file__ Traceback (most recent call last): File "Test1.py", line 15, in import SHIP File "H:\Viper\HostPC\V1\SHIP\Release\SHIP.py", line 7, in import _SHIP ImportError: DLL load failed: The specified module could not be found. It would seem the "import SHIP" is finding SHIP.py without any trouble. SHIP.py begins by "import _SHIP". Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for some reason, which I cannot fathom, says "DLL load failed". Can anyone offer me any suggestion where I am going wrong or how to tackle this problem? Could it be that the Python 2.6 I am running did not use the same compiler (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this without moving on from VC6? TIA, Bill From alan.isaac at gmail.com Mon Jul 5 10:38:04 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 05 Jul 2010 10:38:04 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: References: Message-ID: On 7/5/2010 7:45 AM, Ritchy lelis wrote: > from pylab import* > > Vref = arange(1, 20, 0.02) > Vi = arange(1, 10,0.1) > > for i in Vref: > for n in Vi: > if n> i/4: > V0 = 2*n-i > elif (-i/4)<= n and n<= i/4: > V0 = 2*n > elif Vi< -i/4: > V0 = 2*n+i > else: > print "Try Again" > ##print V0 > plot (V0) Your data manipulations don't make sense to me, and plotting one point at a time is probably not what you want to do. As a rule, use arange only with integer arguments. Finally, if you want to see your plot, you need to show it (or save it). So create an **array** V0 and then do something like the following: import numpy as np import matplotlib.pyplot as plt Vref = np.linspace(1,20, 1000) Vi = np.linspace(1,10,100) #replace the next line V0 = ... #create an array plt.plot(V0) plt.show() hth, Alan Isaac From thomas at jollans.com Mon Jul 5 10:38:27 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 16:38:27 +0200 Subject: black console window of executing os.chmod() and os.access() In-Reply-To: References: Message-ID: <4C31EE63.3080001@jollans.com> On 07/05/2010 04:19 PM, ??? wrote: > Hi all, > I want to use os.chmod or os.access to check the permission of a > folder on remote Windows computer: > os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) > or > os.access("\\1.1.1.1\sharedfolder", os.W_OK) That won't work: >>> print("\\1.1.1.1\sharedfolder") \1.1.1.1\sharedfolder >>> > > I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a > black console window display one second. > Only remote folder has this problem, local folder has no this problem. > > Anybody know how to remove the black console window? Does the script actually work for remote folders? Does the same problem occur for other file operations on remote systems? Maybe someone else knows an answer, otherwise maybe my thoughts will be of some help. Thomas From 88pigs at gmail.com Mon Jul 5 11:01:02 2010 From: 88pigs at gmail.com (=?GB2312?B?1uzW2LDL?=) Date: Mon, 5 Jul 2010 23:01:02 +0800 Subject: black console window of executing os.chmod() and os.access() In-Reply-To: <4C31EE63.3080001@jollans.com> References: <4C31EE63.3080001@jollans.com> Message-ID: Sorry, I mean "\\\\1.1.1.1\\sharedfolder" Seems os.chmod(), os.access() and os.makedirs() all have this problem when the path is a remote path. 2010/7/5 Thomas Jollans > On 07/05/2010 04:19 PM, ??? wrote: > > Hi all, > > I want to use os.chmod or os.access to check the permission of a > > folder on remote Windows computer: > > os.chmod("\\1.1.1.1\sharedfolder", stat.S_IWRITE) > > or > > os.access("\\1.1.1.1\sharedfolder", os.W_OK) > > That won't work: > > >>> print("\\1.1.1.1\sharedfolder") > \1.1.1.1\sharedfolder > >>> > > > > > > I saved this python file as a.pyw, run it with pythonw.exe a.pyw, then a > > black console window display one second. > > Only remote folder has this problem, local folder has no this problem. > > > > Anybody know how to remove the black console window? > > Does the script actually work for remote folders? Does the same problem > occur for other file operations on remote systems? > > Maybe someone else knows an answer, otherwise maybe my thoughts will be > of some help. > > Thomas > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 5 11:01:28 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 05 Jul 2010 17:01:28 +0200 Subject: ImportError: DLL load failed: The specified module could not be found, SWIG, life, etc In-Reply-To: <89e8ueFuc6U1@mid.individual.net> References: <89e8ueFuc6U1@mid.individual.net> Message-ID: <4C31F3C8.5010402@jollans.com> On 07/05/2010 04:35 PM, Bill Davy wrote: > I am struggling :-( smile! > > I have used SWIG to build a module called SHIP. So I have a directory > containing SHIP.py and _SHIP.pyd, as follows: > > [ ...] > > Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for > some reason, which I cannot fathom, says "DLL load failed". > Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd depends on some other DLL? Since you used SWIG, I'm guessing that you're wrapping some other library. Maybe that's what it can't find. > > > Can anyone offer me any suggestion where I am going wrong or how to tackle > this problem? > > > > Could it be that the Python 2.6 I am running did not use the same compiler > (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this > without moving on from VC6? > Shouldn't be a problem, as long as the calling convention hasn't change, which it hasn't. If you're on a 64-bit system there might be a problem there with Python and some DLLs being built for different architectures? Cheers, Thomas From nanothermite911fbibustards at gmail.com Mon Jul 5 11:58:19 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Mon, 5 Jul 2010 08:58:19 -0700 (PDT) Subject: VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - Bellies ripped open and numerous injured - call for TRUE PATRIOTS . The deep undercover spies agents of influence mislead the public on the facts References: <71420572-82ad-4945-931a-3452eeebcb1d@5g2000yqz.googlegroups.com> Message-ID: <83cc2a04-296f-4f84-9633-ccb768095f5c@x27g2000yqb.googlegroups.com> http://www.veteranstoday.com/2010/06/16/jim-w-dean-faked-israeli-flotilla-v= ideos-provide-opening-to-expose-israeli-expionage-here/ JIM W. DEAN: FAKED ISRAELI FLOTILLA VIDEOS PROVIDE OPENING TO EXPOSE ISRAELI EXPIONAGE HERE June 16, 2010 posted by Gordon Duff =B7 20 Comments Share Faked Israeli Flotilla videos provide opening to expose Israeli Espionage here By Jim W. Dean for Veterans Today Dear Friends, The Zionists shot themselves in both feet with this rushed spin job to deflect attention on their slaughter of the Gaza Flotilla activists. We can thank the retired Intel folks for the frame analysis exposing the fraud on the Veterans Today link above. Fortunately more and more retired Intel and security people are getting into the life or death struggle defending the country from our =91domestic enemies=92. These Photo shopped videos were done so poorly as to be almost comical if they were not done to cover up murders. You will have to watch the video several times to really visually catch their mistakes. Don=92t be afraid to use the pause button to study the images. The ending scenes on the fantail immediately struck me as a studio shoot. The lighting was way to bright for a ship in that situation. The actors=85well=85they did a really poor job. In the real videos you see more confusion=85the clothes are not right. If was a completely staged event, even down to the tiny slingshot one guy raises up so it can be noticed. Also, the camera is stationary (on a tripod)=85a huge mistake. YouTube - Veterans Today - That the radical Zionists would lie, cheat or steal to gain some benefit for themselves is not even a news event. Our own American declassified intelligence lays this all out in spades. The best one book read on it is Steven Green=92s Taking Sides, if you can find a used one online. The real news here is how such an obvious fraud was pipelined into American mass media. Any experienced news video editor would have spotted the obvious fraud on these tapes. But they pushed it right out onto unsuspecting Americans who wrongly think that mass media would not pedal something they know to be totally bogus. And how wrong they are. But it gets worse. Our Intel and security agencies always do frame by frame analysis of important video material like this. They also had to have spotted this=85yet they did not warn the American people that this was a fraud. Why not? The answer is that Israel espionage has penetrated American government, media, politics, and even our security institutions to the point that the Zios have no fear of those responsible for our national security protecting us from the Israeli 5th column operating here. They are protected by powerful interests. The military, veteran and intelligence communities are really the only American institutions who can take the lead on tearing the Israeli espionage networks out by the roots. All the other institutions are already compromised. And they will fight like hell as they know that the 5th column could not have been as effective as they have been without more than a few disloyal Americans helping them, many who are well known names. They will do anything to protect themselves from exposure=85anything=85and they have. The USS Liberty is just one example, where dead and wounded servicemen were literally abandoned on the battlefield so as to not reveal to the American public that they were murdered by the Israelis. You might remember that the last whistleblower reform legislation was slapped down a while back. The Congresscritters know what a threat that is. So do the Israelis. We have loyal Intel people who know that the Israelis have been given key Homeland Security contracts that actually have the American taxpayer funding their espionage operations. Oh yes, the Israelis make us pay for it=85smart folks they. Michael Chertoff flew to Israel a few years back to put on a =91fast track=92 seminar for Israeli security companies (staffed by Mussed and military Intel people) to make sure they can the key contracts that they wanted, like airport security and communications plums. This is a huge national scandal, and one that a Congressional investigation would not put a dent into as those folks have sold us out to the Israelis in return for political support. John McCain is one of the worst examples, but he has lots of company. I listened to General Russel Honore give a great Memorial Day speech in Atlanta recently. It was short and sweet in his normal style. =93We were born by accident, based on where our parents were. To live free is a privilege. But to die free is an obligation that we leave to each generation.=94 Folks, If we don=92t join hands and root out this the Israeli 5th column here we will be breaking the chain, and it is getting late in the day. Their numbers are small, so they have put the fix it at the top, political espionage. But we have the numbers to beat them. They have just not been brought to bear due to their divide and conquer, smoke and mirrors tactics. Our political establishment is more afraid of the Israel Lobby than they are of us. We must reverse that situation or we will have betrayed the next generation. So let=92s roll up our sleeves, and get on with the work. First up is going to go see your Congresscritters with a small group of vets/Intel people and go through this video with them step by step, and demand to know why our people did nothing to expose the fraud, including Obama possibly even having been sand bagged on it. Did Rahm Emanuel and David Axelrod know? Did Hillary, Defense and the CIA? Why no official exposure by those sworn to protect us. And ask them what they have done to combat Israeli espionage here? You will enjoy the look on their faces. I promise you that. Jim Dean Heritage TV=85Atlanta Assoc. for Intelligence Officers On Jul 4, 6:05=A0pm, gaze... at shell.xmission.com (Kenny McCormack) wrote: > In article , > small Pox =A0 wrote: > > >VICIOUS Enemy Insurgents kill 34 US soldiers after 9 hrs attack - > >Bellies ripped open and numerous injured - call for TRUE PATRIOTS . > >The deep undercover spies agents of influence mislead the public on > >the facts > > >http://www.youtube.com/watch?v=3DfRZSzdQuOqM&feature=3Drelated > >http://www.youtube.com/watch?v=3D0q7yEnMjQ6U&feature=3Drelated > >http://www.youtube.com/watch?v=3Da3E2NcC0x20&feature=3Drelated > >http://www.youtube.com/watch?v=3DfRZSzdQuOqM&feature=3Drelated > > >http://www.venusproject.com/911/911RussianSatellite1.html > > >http://www.gtr5.com/ > > Your C question was? JIM W. DEAN: FAKED ISRAELI FLOTILLA VIDEOS PROVIDE OPENING TO EXPOSE ISRAELI EXPIONAGE HERE From timcoote at gmail.com Mon Jul 5 13:01:14 2010 From: timcoote at gmail.com (Tim) Date: Mon, 5 Jul 2010 10:01:14 -0700 (PDT) Subject: throwing exceptions from csv.DictReader or even csv.reader Message-ID: Hullo Csv is a very common format for publishing data as a form of primitive integration. It's an annoyingly brittle approach, so I'd like to ensure that I capture errors as soon as possible, so that I can get the upstream processes fixed, or at worst put in some correction mechanisms and avoid getting polluted data into my analyses. A symptom of several types of errors is that the number of fields being interpreted varies over a file (eg from wrongly embedded quote strings or mishandled embedded newlines). My preferred approach would be to get DictReader to throw an exception when encountering such oddities, but at the moment it seems to try to patch over the error and fill in the blanks for short lines, or ignore long lines. I know that I can use the restval parameter and then check for what's been parsed when I get my results back, but this seems brittle as whatever I use for restval could legitimately be in the data. Is there any way to get csv.DictReader to throw and exception on such simple line errors, or am I going to have to use csv.reader and explicitly check for the number of fields read in on each line? cheers Tim From chris at simplistix.co.uk Mon Jul 5 13:21:39 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Jul 2010 18:21:39 +0100 Subject: SMTPHandler and Unicode In-Reply-To: <20100705153532.210103be@pitrou.net> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: <4C3214A3.3070700@simplistix.co.uk> Antoine Pitrou wrote: > On Mon, 5 Jul 2010 06:17:38 -0700 (PDT) > norbert wrote: >> a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. Yes indeed, hence my question on python-dev... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Mon Jul 5 13:32:50 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 05 Jul 2010 19:32:50 +0200 Subject: throwing exceptions from csv.DictReader or even csv.reader References: Message-ID: Tim wrote: > Csv is a very common format for publishing data as a form of primitive > integration. It's an annoyingly brittle approach, so I'd like to > ensure that I capture errors as soon as possible, so that I can get > the upstream processes fixed, or at worst put in some correction > mechanisms and avoid getting polluted data into my analyses. > > A symptom of several types of errors is that the number of fields > being interpreted varies over a file (eg from wrongly embedded quote > strings or mishandled embedded newlines). My preferred approach would > be to get DictReader to throw an exception when encountering such > oddities, but at the moment it seems to try to patch over the error > and fill in the blanks for short lines, or ignore long lines. I know > that I can use the restval parameter and then check for what's been > parsed when I get my results back, but this seems brittle as whatever > I use for restval could legitimately be in the data. > > Is there any way to get csv.DictReader to throw and exception on such > simple line errors, or am I going to have to use csv.reader and > explicitly check for the number of fields read in on each line? I think you have to use csv.reader. Untested: def DictReader(f, fieldnames=None, *args, **kw): reader = csv.reader(f, *args, **kw) if fieldnames is None: fieldnames = next(reader) for row in reader: if row: if len(fieldnames) != len(row): raise ValueError yield dict(zip(fieldnames, row)) Peter From Bill at SynectixLtd.com Mon Jul 5 13:51:07 2010 From: Bill at SynectixLtd.com (Bill Davy) Date: Mon, 5 Jul 2010 18:51:07 +0100 Subject: ImportError: DLL load failed: The specified module could notbe found, SWIG, life, etc References: <89e8ueFuc6U1@mid.individual.net> Message-ID: <89ekcaF5kqU1@mid.individual.net> "Thomas Jollans" wrote in message news:mailman.265.1278342154.1673.python-list at python.org... > On 07/05/2010 04:35 PM, Bill Davy wrote: >> I am struggling :-( > > smile! > >> >> I have used SWIG to build a module called SHIP. So I have a directory >> containing SHIP.py and _SHIP.pyd, as follows: >> >> [ ...] >> >> Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for >> some reason, which I cannot fathom, says "DLL load failed". >> > > Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd > depends on some other DLL? Since you used SWIG, I'm guessing that you're > wrapping some other library. Maybe that's what it can't find. > Well, there's no mention of another librarary, and "import _SHIP" is the first (non-comment) statement in SHIP.py But when I run Dependency Walker against _SHIP.pyd it does say there's a missing DLL (WINUSB.DLL) so I suspect I've got to sort that out. >> >> >> Can anyone offer me any suggestion where I am going wrong or how to >> tackle >> this problem? >> >> >> >> Could it be that the Python 2.6 I am running did not use the same >> compiler >> (VC6) with which I buiult _SHIP.pyd and if so, is there a way round this >> without moving on from VC6? >> > > Shouldn't be a problem, as long as the calling convention hasn't change, > which it hasn't. If you're on a 64-bit system there might be a problem > there with Python and some DLLs being built for different architectures? Yep, all for the same architetcure. I suspect it's a dependency problem. Oh well. > > Cheers, > Thomas From eric.promislow at gmail.com Mon Jul 5 14:01:52 2010 From: eric.promislow at gmail.com (Eric Promislow) Date: Mon, 5 Jul 2010 11:01:52 -0700 (PDT) Subject: OT Komodo Edit, line selection gutter is one pixel wide? References: <4c2cc4d2$0$4953$c3e8da3@news.astraweb.com> Message-ID: <7b86e51d-32f9-4a4f-8f66-e09be6142f33@w15g2000pro.googlegroups.com> On Jul 1, 9:39?am, John Doe wrote: > Is there a way to increase the line selection gutter width? It > seems to be only one pixel wide. In other words... When I single > click on the left side of the line, in order to automatically > select the line, the pointer must be in a precise single pixel > location immediately to the left of the line. Or am I doing > something wrong? > > Thanks. > > By the way... I can see that clicking and dragging to select > multiple lines can be done somewhere in the space of the first > character on the lines, but I am talking about single clicking to > select the single line. You can easily do this with a Komodo macro. First you get a reference to the current buffer like so. In JS: var view = ko.views.manager.currentView; var scimoz = view.scimoz; // the editor In Python code: currentView = components.classes["@activestate.com/koViewService;1"].\ getService(Components.interfaces.koIViewService).currentView view = currentView.QueryInterface(Components.interfaces.koIScintillaView) scimoz = view.scimoz To get the current width of the line-selection margin: oldValue = scimoz.getMarginWidth(2) # Margin #2, width given in pixels To set a new value: scimoz.setMarginWidth(2, newValue) # 4 looks like a good value There is no boundary between the breakpoint margin (1) and the line- selection margin. If you want this behaviour in general, you can write a post-file-open macro that will set the margin after a file is opened. You currently can't write a post-file-open trigger in Python, (see bug http://bugs.activestate.com/show_bug.cgi?id=45265) Hope this helps, Eric Promislow Komodo Team Member From usernet at ilthio.net Mon Jul 5 14:02:17 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 5 Jul 2010 18:02:17 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 2010-07-05, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: >> Classic Unix programming is a matter of stringing a bunch of tools >> together with pipes to get the output you want. This isn't a great >> paradigm for GUIs (not without tweaking that hasn't really been done), but >> then again it was never meant to be. > > I???ve never come across any system where you could string together multiple > GUI apps, or even multiple GUI operations in the same app, in any sensible > or effective way at all. GUIs just aren???t designed to work that way. You can if they are designed to be used externally. COM is an execellent example of this as is script-fu and any number of other technologies that allow external access to the subroutines or automation capability of a GUI application. The problem is not that it cannot be done; but, that it must be explicilty designed to be used this way. I have worked with complex business process automation centered around Excel and I have automated some really ugly AJAX style web based applications that would only work inside of IE6 by accessing IE through its COM interface. > The command line (or scripting, the difference isn???t that important) remains > the only workable way to string together complex combinations of simpler > operations. The difference is that it is almost always possible to automate using text based applications, even when the author of the software never designed the software to be scripted. Text based IO streams are easy to capture and manipulate. Automating GUI applications requires interal access to the program through some kind of interface and, ideally, decent documention of the interface, something that is missing from many, if not most, GUIs. Anything else relies on ugly and, generally fragile, mechanisms to intercept the programs output and send event triggers to the application. The recent thread to automate Minesweeper by processing its screenshot is an example of this. From tjreedy at udel.edu Mon Jul 5 14:09:37 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:09:37 -0400 Subject: Confusion over etree.ElementTree.Element.getiterator In-Reply-To: <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <7e237012-7b4d-49af-9d38-a011c4f267e5@d16g2000yqb.googlegroups.com> <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> Message-ID: On 7/5/2010 6:40 AM, Ben Sizer wrote: >> Admittedly, it's three clicks away from the library docs on docs.python.org. >> >> http://effbot.org/zone/element.htm#xml-namespaces > > Hopefully someone will see fit to roll this important documentation > into docs.python.org before the next release... oops, too late. ;) Not too late for next release. Open a doc issue with as specific a suggestion as possible. > > It's one of those things that's easy to fix when you know what the > problem is. Unfortunately it makes the examples a bit awkward. The > example on http://docs.python.org/library/xml.etree.elementtree.html > opens up an xhtml file and reads a "p" tag within a "body" tag, but > the xhtml specification (http://www.w3.org/TR/xhtml1/#strict) states > that 'The root element of the document must contain an xmlns > declaration for the XHTML namespace'. Therefore I don't see how the > example Python code given could work on a proper xhtml file, given > that there should always be a namespace in effect but the code doesn't > allow for it. > > That's my excuse anyway! :) -- Terry Jan Reedy From wxjmfauth at gmail.com Mon Jul 5 14:12:19 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 5 Jul 2010 11:12:19 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> Message-ID: <06231c4e-a405-42b1-b0ee-f0c104057e3e@i31g2000yqm.googlegroups.com> Thank you all for the discussion and the explanations. > Mark Dickinson I toyed a littled bit this afternoon and I wrote a colouriser (British spelling?) with the tokenize module. It is quite simple and easy. BTW, if I understand correctly the module tokenize import the module token. So your example becomes: >>> from cStringIO import StringIO >>> import tokenize >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): print tokenize.tok_name[tok[0]], tok[1] NAME print9 NUMBER .0 ENDMARKER >>> From tjreedy at udel.edu Mon Jul 5 14:33:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:33:02 -0400 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: Message-ID: On 7/4/2010 9:20 PM, CM wrote: > On Jul 4, 7:14 pm, Terry Reedy wrote: >> > > I think there's a good point to Python 3 put-downs (if I take put-down > to mean generally reasonable criticism, which is what I've read here > recently, and not trolling). And that is simply to register > dissent. But dissent from what? Dissent from something obviously true? (like 'Pythonx.y is useful to some people') Dissent from something obvious false, that no one has said? (like 'Everyone should switch to Pythonx.y') > Any online group is an opportunity to register dissent in a way that > is public, open, immediate, interactive, and will (probably) be > preserved for historians to check. The fact is, some people have > gripes with Python 3; they are letting it be known. I have several 'gripes' with 2.7 and it is currently useless to me. Should I let them be known? How many times? > If no one did, > there could be no later time at which people could look back and know > what the reaction was to its introduction--it would just be a blank. > Aren't opinions that dissent from the prevailing ones important to > register, whether one thinks they are right or wrong? Do you agree with me that the same criteria for gripe legitimacy should be applied equally to all Python versions (even if we should disagree on what those criteria should be)? -- Terry Jan Reedy From tjreedy at udel.edu Mon Jul 5 14:42:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:42:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c318235$0$1663$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 2:56 AM, John Nagle wrote: > On 7/4/2010 10:44 PM, Terry Reedy wrote: >> I you have any other ideas about other top blockers, please share them. > > The Twisted team has a list of what they need: > > "http://stackoverflow.com/questions/172306/how-are-you-planning-on-handling-the-migration-to-python-3" > > > * Zope Interface > * PyCrypto > * PyOpenSSL > * PyGTK Good start. Now what is blocking those four? Lack of developer interest/time/ability? or something else that they need? -- Terry Jan Reedy From emile at fenx.com Mon Jul 5 14:43:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 05 Jul 2010 11:43:55 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 11:02 AM Tim Harig said... > Automating GUI applications requires interal > access to the program through some kind of interface and, ideally, decent > documention of the interface, something that is missing from many, if > not most, GUIs. Anything else relies on ugly and, generally fragile, > mechanisms to intercept the programs output and send event triggers to > the application. I've been doing the 'anything else...' stuff for years now without issue, so ugly, yes, but fragile, not really. Unless you let users on the same machine... Emile From tjreedy at udel.edu Mon Jul 5 14:49:04 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Jul 2010 14:49:04 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On 7/5/2010 6:04 AM, David Cournapeau wrote: > On Mon, Jul 5, 2010 at 12:44 PM, Terry Reedy wrote: [snip] > I think numpy will work for 3.1 as well If numpy were released today for 3.1 (or even anytime before 3.2), that would be great. It would let those waiting for it that it is real and that they can go ahead on their ports. Part of the reason for the 3.2 core-change moratorium was to let 3rd-party packages target 3.2 by working with 3.1. If they finish and release sooner (as some have), even better. Unless they depend on something that changes in the stdlib, porting for one should pretty much be porting for both. > (I don't know about 3.0, but > my understanding is that there is no point into even looking at that > release). Agreed. -- Terry Jan Reedy From hema_111150 at yahoo.com Mon Jul 5 15:03:05 2010 From: hema_111150 at yahoo.com (eslam) Date: Mon, 5 Jul 2010 12:03:05 -0700 (PDT) Subject: vidio***** Message-ID: <0bf3eca7-c4c0-4017-b866-2c938dc9d627@i31g2000yqm.googlegroups.com> http://www.kavalec.com/thisisislam.swf From python.list at tim.thechases.com Mon Jul 5 15:32:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Jul 2010 14:32:13 -0500 Subject: Python 3 put-downs: What's the point? In-Reply-To: <20100705095032.6f7749fe@brasov> References: <20100705095032.6f7749fe@brasov> Message-ID: <4C32333D.5020702@tim.thechases.com> On 07/05/2010 02:50 AM, Gregor Horvath wrote: > Am Sun, 04 Jul 2010 18:51:54 -0500 > schrieb Tim Chase: > >> I think it's the same venting of frustration that caused veteran >> VB6 developers to start calling VB.Net "Visual Fred" -- the >> language was too different and too non-backwards-compatible. >> > > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. > > VB6 and VB.NET are totally different languages and technologies, with > some similarity in syntax. This is not true for Python 2->3. > This is an healthy organic language growth, not an abandon of a > language. The quintessential example is Py3's breaking of Hello World. It's a spectrum of language changes -- Visual Fred just happens to be MUCH further down the same spectrum having more dramatic changes. Only a subset of $OLD_VER (whether Py2 or VB6) code will run unmodified under $NEW_VER (whether Py3 or VB.Net). It just happens that the subset for Python is considerably larger than the subset for VB (and Python's conversion tools seem a little more useful than VB's, IMHO). IIRC, neither raw VB6 nor Py2 byte-code will run raw in the new environment (old VB .exe files don't make use of .Net libraries/CLR, nor do Py2 .pyc files run under Py3) so a project-rebuild is a minimum (though in Py3, s/minimum/negligible/) requirement. A little defensive coding in $OLD_VER also helps, and here I'd say Python developers had a MUCH longer lead-time to understand scope & magnitude of the coming changes; VB6 developers (former self included) had VB.Net foisted on them with much less heralding about the areas-of-breakage. I'm very much +0 on Py3...it doesn't impact my life yet and it's not a regular part of my coding, but the changes I've seen are good for the language and the future of Python. But breaking-changes freak some folks out, leading to the put-downs referenced by the OP. As a former VB6 developer, the shift to VB.Net was enough to send me packing. The shift from Py2 to Py3 will be bumpy, but not enough to lose me as a developer. -tkc From kw at codebykevin.com Mon Jul 5 15:35:13 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 05 Jul 2010 15:35:13 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c318235$0$1663$742ec2ed@news.sonic.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <11e61$4c323409$4275d90a$16304@FUSE.NET> On 7/5/10 2:56 AM, John Nagle wrote: > * PyCrypto > * PyOpenSSL These, and Mark Pilgrim's feedparser, need to be 3.x compatible before I can think about Python 3.x. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From dickinsm at gmail.com Mon Jul 5 15:56:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 5 Jul 2010 12:56:23 -0700 (PDT) Subject: SyntaxError not honoured in list comprehension? References: <09f1be02-9068-4168-b079-1fd1b0655fc1@k1g2000prl.googlegroups.com> <18b6bc46-4d88-4c46-8dde-c961d5f9dfba@y11g2000yqm.googlegroups.com> <06231c4e-a405-42b1-b0ee-f0c104057e3e@i31g2000yqm.googlegroups.com> Message-ID: On Jul 5, 7:12?pm, jmfauth wrote: > BTW, if I understand correctly the module tokenize import > the module token. So your example becomes: > > >>> from cStringIO import StringIO > >>> import tokenize > >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): > > ? ? ? ? print tokenize.tok_name[tok[0]], tok[1] Ah yes; you're right. Thanks! Mark From ggrp2.20.martineau at dfgh.net Mon Jul 5 15:59:00 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 12:59:00 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: On Jul 5, 1:12?am, Benjamin Kaplan wrote: > On Sun, Jul 4, 2010 at 7:58 PM, John Machin wrote: > > On Jul 5, 12:27?pm, Martineau wrote: > >> On Jul 4, 8:34?am, Benjamin Peterson wrote: > > >> > On behalf of the Python development team, I'm jocund to announce the second > >> > release candidate of Python 2.7. > > >> > Python 2.7 will be the last major version in the 2.x series. However, it will > >> > also have an extended period of bugfix maintenance. > > >> > 2.7 includes many features that were first released in Python 3.1. The faster io > >> > module, the new nested with statement syntax, improved float repr, set literals, > >> > dictionary views, and the memoryview object have been backported from 3.1. Other > >> > features include an ordered dictionary implementation, unittests improvements, a > >> > new sysconfig module, auto-numbering of fields in the str/unicode format method, > >> > and support for ttk Tile in Tkinter. ?For a more extensive list of changes in > >> > 2.7, seehttp://doc.python.org/dev/whatsnew/2.7.htmlorMisc/NEWSin the Python > >> > distribution. > > >> > To download Python 2.7 visit: > > >> > ? ? ?http://www.python.org/download/releases/2.7/ > > >> > 2.7 documentation can be found at: > > >> > ? ? ?http://docs.python.org/2.7/ > > >> > This is a production release and should be suitable for all libraries and > >> > applications. ?Please report any bugs you find, so they can be fixed in the next > >> > maintenance releases. ?The bug tracker is at: > > >> > ? ? ?http://bugs.python.org/ > > >> > Enjoy! > > >> > -- > >> > Benjamin Peterson > >> > Release Manager > >> > benjamin at python.org > >> > (on behalf of the entire python-dev team and 2.7's contributors) > > >> Benjamin (or anyone else), do you know where I can get the Compiled > >> Windows Help file -- python27.chm -- for this release? In the past > >> I've been able to download it from the Python web site, but have been > >> unable to locate it anywhere for this new release. I can't build it > >> myself because I don't have the Microsoft HTML help file compiler. > > >> Thanks in advance. > > > If you have a Windows box, download the .msi installer for Python 2.7 > > and install it. The chm file will be in C:\Python27\Doc (if you choose > > the default installation directory). Otherwise ask a friendly local > > Windows user for a copy. > > -- > > Or you can just use 7-zip or cabextract on the MSi. Saves you from > having to uninstall it later, and it works on non-Windows machines. Perhaps it's hidden somewhere, but I couldn't find the .chm help file in the python-2.7.msi file using 7-zip, nor saw anything that looked like a Doc folder embedded within it -- so I doubt installing it on a Windows machine would work any better. I'd like to view the contents of the help file without actually installing the release which would wipe out any currently installed version (I'm one of those rare people who actually reads manuals *before* using or installing most things.) So my original question stands -- where can one get the Windows Help file for v2.7? From darcy at druid.net Mon Jul 5 16:30:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 5 Jul 2010 16:30:43 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <20100705163043.f4c8d085.darcy@druid.net> On Mon, 05 Jul 2010 14:42:13 -0400 Terry Reedy wrote: > Good start. Now what is blocking those four? > Lack of developer interest/time/ability? > or something else that they need? How about a basic how-to document? I maintain PyGreSQL and would like to move it to 3.x right now but I don't even know what the issues are. I can see on the site the 2.x documents and the 3.x documents for extending with C modules and I can read both from end to end but that hits the time issue above. If there was a relatively simple document that showed what needed to be changed in the C code we could get started on the transition sooner. Or is there no change at the C level? That would make things easy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alex.kapps at web.de Mon Jul 5 16:31:52 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 05 Jul 2010 22:31:52 +0200 Subject: Python 2.7 released In-Reply-To: References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <4C324138.7040202@web.de> Martineau wrote: > Perhaps it's hidden somewhere, but I couldn't find the .chm help file > in the python-2.7.msi file using 7-zip, nor saw anything that looked > like a Doc folder embedded within it -- so I doubt installing it on a > Windows machine would work any better. I don't know much about the .msi format or how 7-Zip handles it, but on my XP box, 7-Zip lists a "python" sub-archive (a 7-Zip "compound"). Within is the python27.chm From cmpython at gmail.com Mon Jul 5 16:41:48 2010 From: cmpython at gmail.com (CM) Date: Mon, 5 Jul 2010 13:41:48 -0700 (PDT) Subject: Python 3 put-downs: What's the point? References: Message-ID: On Jul 5, 2:33?pm, Terry Reedy wrote: > On 7/4/2010 9:20 PM, CM wrote: > > > On Jul 4, 7:14 pm, Terry Reedy ?wrote: > > > I think there's a good point to Python 3 put-downs (if I take put-down > > to mean generally reasonable criticism, which is what I've read here > > recently, and not trolling). ?And that is simply to register > > dissent. > > But dissent from what? > > Dissent from something obviously true? > (like 'Pythonx.y is useful to some people') > > Dissent from something obvious false, that no one has said? > (like 'Everyone should switch to Pythonx.y') I was thinking more like dissent from something that is not obviously true or false, but a matter of debate, like some of the decisions behind Python 3 itself or how the transition is being managed. I got the sense that was about where the complaints lie. Some of the responses to those complaints were educational to me, so I didn't mind reading the exchanges. > > Any online group is an opportunity to register dissent in a way that > > is public, open, immediate, interactive, and will (probably) be > > preserved for historians to check. ?The fact is, some people have > > gripes with Python 3; they are letting it be known. > > I have several 'gripes' with 2.7 and it is currently useless to me. > Should I let them be known? How many times? Maybe you should; maybe it can be constructive criticism to developers or can jog someone to tell you something that you didn't know. How many times? Once, maybe twice. I agree one can overdo it, and maybe you've read more of the gripes than I have and it seems repetitive by now. > > ?If no one did, > > there could be no later time at which people could look back and know > > what the reaction was to its introduction--it would just be a blank. > > Aren't opinions that dissent from the prevailing ones important to > > register, whether one thinks they are right or wrong? > > Do you agree with me that the same criteria for gripe legitimacy should > be applied equally to all Python versions (even if we should disagree on > what those criteria should be)? I think so, sure. From ncauderan at gmail.com Mon Jul 5 16:49:40 2010 From: ncauderan at gmail.com (norbert) Date: Mon, 5 Jul 2010 13:49:40 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: > > Ouch. Implicit encoding sounds like a bad behaviour. Looking at the FileHandler source ( http://svn.python.org/view/python/trunk/Lib/logging/__init__.py?view=markup ) : the utf-8 encoding is a fallback. But *FileHandler family let you specify the encoding you want, so that's OK I think. But SMTPHandler does not have such a thing it sends its email with : msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % ( self.fromaddr, ",".join(self.toaddrs), self.getSubject(record), formatdate(), msg) ... smtp.sendmail(from,to,msg) And there is no encoding in all this. It seems pretty dangerous to me (so my first post) because your application will work without any problem with a FileHandler and the day you'll decide to send email in case of serious problem, it will crash with a UnicodeError. I can't see any workaround, except by subclassing SMTPHandler's emit method to be unicode-aware or at least URF-8 aware. From martin at v.loewis.de Mon Jul 5 17:57:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 05 Jul 2010 23:57:23 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <4C325543.6010408@v.loewis.de> Am 05.07.2010 22:30, schrieb D'Arcy J.M. Cain: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. > I can see on the site the 2.x documents and the 3.x documents for > extending with C modules and I can read both from end to end but that > hits the time issue above. If there was a relatively simple document > that showed what needed to be changed in the C code we could get > started on the transition sooner. > > Or is there no change at the C level? That would make things easy. If somebody would move that into a narrative form, I'd be happy to list the changes I know of, and the approaches I took to make C modules work on both 2.x and 3.x (actually, I did the port of psycopg2, so I expect PyGreSQL might be similar). However, I'm not willing to maintain such a document - I have too many projects already, and English is not my native language. Regards, Martin From mtigges at gmail.com Mon Jul 5 18:01:10 2010 From: mtigges at gmail.com (m) Date: Mon, 5 Jul 2010 15:01:10 -0700 (PDT) Subject: Very odd output from subprocess References: <8b3b4a96-4fc3-4b69-b3fa-eb00c30bdb5b@a6g2000pro.googlegroups.com> Message-ID: On Jul 1, 12:42?am, Nobody wrote: > On Wed, 30 Jun 2010 21:12:12 -0700, m wrote: > > If I add the line: > > ? ? ?for l in line: print ord(l),'\t',l > > after the first readline, I get the following: > > > 27 ? ? ? ? ? > > 91 ? ? ? ? [ > > 48 ? ? ? ? 0 > > 48 ? ? ? ? 0 > > 109 ? ? ? ?m > > 27 ? ? ? ? ? > > 91 ? ? ? ? [ > > 51 ? ? ? ? 3 > > 55 ? ? ? ? 7 > > 109 ? ? ? ?m > > > before the codes begin for the string as it appears if I just print > > it. ?So, what is this sequence? ?They seem like some sort of escape > > codes, I've never seen this before at all. > > [00m is the ANSI code to reset attributes to their default state. > [37m is the ANSI code to set the foreground color to white. > > > Can anyone enlighten me as to what is going on? > > > And, can I safely strip sets of 5 characters from the front as long as > > they start with Escape (27)? > > No, escape sequences can be of arbitrary length. > It turned out that make was aliased to colourmake, and the escape codes were being put in there for beautifying the console output. Sorry to bother everyone. From thudfoo at opensuse.us Mon Jul 5 18:15:34 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 5 Jul 2010 15:15:34 -0700 Subject: using the netflix api Message-ID: Has anyone had success using the netflix api with Netflix.py? Especially getting access? From nagle at animats.com Mon Jul 5 18:19:53 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 15:19:53 -0700 Subject: Getting pyparsing to backtrack Message-ID: <4c325a88$0$1672$742ec2ed@news.sonic.net> I'm working on street address parsing again, and I'm trying to deal with some of the harder cases. Here's a subparser, intended to take in things like "N MAIN" and "SOUTH", and break out the "directional" from street name. Directionals = ['southeast', 'northeast', 'north', 'northwest', 'west', 'east', 'south', 'southwest', 'SE', 'NE', 'N', 'NW', 'W', 'E', 'S', 'SW'] direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameParser = Optional(direction.setResultsName("predirectional")) + Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") This parses something like "N WEBB" fine; "N" is the "predirectional", and "WEBB" is the street name. "SOUTH" (which, when not followed by another word, is a streetname, not a predirectional), raises a parsing exception: Street address line parse failed for SOUTH : Expected W:(abcd...) (at char 5), (line:1, col:6) The problem is that "direction" matched SOUTH, and even though "direction" is within an "Optional" and followed by another word, the parser didn't back up when it hit the end of the expression without satisfying the OneOrMore clause. Pyparsing does some backup, but I'm not clear on how much, or how to force it to happen. There's some discussion at "http://www.mail-archive.com/python-list at python.org/msg169559.html". Apparently the "Or" operator will force some backup, but it's not clear how much lookahead and backtracking is supported. John Nagle From nagle at animats.com Mon Jul 5 18:28:47 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 15:28:47 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <11e61$4c323409$4275d90a$16304@FUSE.NET> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <11e61$4c323409$4275d90a$16304@FUSE.NET> Message-ID: <4c325c9e$0$1605$742ec2ed@news.sonic.net> On 7/5/2010 12:35 PM, Kevin Walzer wrote: > On 7/5/10 2:56 AM, John Nagle wrote: > >> * PyCrypto >> * PyOpenSSL > > These, and Mark Pilgrim's feedparser, need to be 3.x compatible before I > can think about Python 3.x. There's been an attempt to port "feedparser" to 3.0, but that needed a port of BeautifulSoup: http://code.google.com/p/feedparser/issues/detail?id=215 They also had some problems with "chardet". John Nagle From philip at semanchuk.com Mon Jul 5 18:38:20 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 5 Jul 2010 18:38:20 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20100705163043.f4c8d085.darcy@druid.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. > I can see on the site the 2.x documents and the 3.x documents for > extending with C modules and I can read both from end to end but that > hits the time issue above. If there was a relatively simple document > that showed what needed to be changed in the C code we could get > started on the transition sooner. > > Or is there no change at the C level? That would make things easy. There are definitely changes at the C level. I ported two pure C extensions from 2 to 3 and was even able to keep a single C codebase. I'd be willing to contribute my experiences to a document somewhere. (Is there a Wiki?) I would have found such a document very helpful before I started porting. Cheers Philip From clp2 at rebertia.com Mon Jul 5 18:41:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 15:41:31 -0700 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> Message-ID: On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk wrote: > On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: >> On Mon, 05 Jul 2010 14:42:13 -0400 >> Terry Reedy wrote: >>> Good start. Now what is blocking those four? >>> Lack of developer interest/time/ability? >>> or something else that they need? >> >> How about a basic how-to document? ?I maintain PyGreSQL and would like >> to move it to 3.x right now but I don't even know what the issues are. >> I can see on the site the 2.x documents and the 3.x documents for >> extending with C modules and I can read both from end to end but that >> hits the time issue above. ?If there was a relatively simple document >> that showed what needed to be changed in the C code we could get >> started on the transition sooner. >> >> Or is there no change at the C level? ?That would make things easy. > > There are definitely changes at the C level. > > I ported two pure C extensions from 2 to 3 and was even able to keep a > single C codebase. I'd be willing to contribute my experiences to a document > somewhere. (Is there a Wiki?) Indeed there is: http://wiki.python.org/moin/ Cheers, Chris From googler.1.webmaster at spamgourmet.com Mon Jul 5 19:49:49 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 5 Jul 2010 16:49:49 -0700 (PDT) Subject: Python Embedding Importing relative modules Message-ID: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Hi all, I have a serious problem I haven't solved yet, hope one of you can help me. The first thing is, I embedded Python into my app and I execute several scripts in this environment. The problem is, the scripts don't import modules from their relative path. I guess this is related to the sys.path ['',...] and the current working directory which is set to the directory of my host application. I could set that path manually, but all the scripts might be stored in different locations. So now I try to find a way to handle that. Any suggestions? A solution would be, that each script, appends its own directory to the system path, but this might lead to problems. Imagine all of them have a module called 'foo.py' and its not the same. This might lead to name conflicts, wouldnt it? Btw, I found a source code line in the documentation, where I should really get rid of the ['', ...] path in the system path due to security reasons. import sys; sys.path.pop(0) Hope one of you can help me out here. Really thanks!! Bye, moerchendiser2k3 From greg.ewing at canterbury.ac.nz Mon Jul 5 19:59:54 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 06 Jul 2010 11:59:54 +1200 Subject: What is the name of the name space I am in? In-Reply-To: References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> Message-ID: <89f9edFuavU1@mid.individual.net> >> On 07/05/2010 11:07 AM, Anthra Norell wrote: >> >>> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue >>> what the "dict" of the current name space is. Are you sure that's what you really want to know? The 'dict' argument to classobj() defines the attributes that you want the new class to have. It's not meant to be the namespace in which the code creating the class is executing. -- Greg From andrew at acooke.org Mon Jul 5 20:10:46 2010 From: andrew at acooke.org (andrew cooke) Date: Mon, 5 Jul 2010 17:10:46 -0700 (PDT) Subject: Another Regexp Question Message-ID: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> As ever, I guess it's most likely I've misunderstood something, but in Python 2.6 lookback seems to actually be lookahead. All the following tests pass: from re import compile assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc') assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc') assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc') assert compile('(a)b(?=(?(2)x|c))(c)').match('abc') assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc') assert compile('(a)b(?=(?(1)c|x))(c)').match('abc') But it seems to me that the first block should fail, because they check the match *before* the point in question. Note that without group references these work as I would expected: assert compile('(a)b(?<=b)(c)').match('abc') assert not compile('(a)b(?<=c)(c)').match('abc') assert not compile('(a)b(?=b)(c)').match('abc') assert compile('(a)b(?=c)(c)').match('abc') in which lookback does indeed lookback (note the asymmetry, while the first examples were symmetrical). What am I missing this time? :o( Thanks, Andrew From steve at REMOVE-THIS-cybersource.com.au Mon Jul 5 20:15:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 00:15:19 GMT Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <4c327596$0$28647$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > I'd like to view the contents of the help file without actually > installing the release which would wipe out any currently installed > version (I'm one of those rare people who actually reads manuals > *before* using or installing most things.) When you say "wipe out any currently installed version", do you mean an older version of 2.7, or an older version such as 2.6, 2.5, 2.4, ... ? If the first, I don't know of any simple way to keep multiple installations with the same major and minor version number (e.g. 2.7.0a and 2.7.0.b). Sorry. But if you mean the second, that you don't want to over-write 2.6, I'd be shocked if the Python installer does that. Doesn't it install Python to something like C:\Programs\Python ? Performing a source install under Linux, by default existing versions remain in place, but there's a soft link "python" which points to the most recent version. Doing a regular install over-writes the soft link. But there's an "altinstall" option which leaves the link untouched, so (for example) I have python -> python 2.5 while still having other versions installed and accessible directly with python2.6, python2.4 etc. I would be stunned if Windows didn't support an equivalent to altinstall. Are there any Windows users out there who can confirm that the installer does or doesn't leave existing versions in place? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jul 5 20:22:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 00:22:06 GMT Subject: Python 3 put-downs: What's the point? References: <20100705095032.6f7749fe@brasov> Message-ID: <4c32772e$0$28647$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 14:32:13 -0500, Tim Chase wrote: > On 07/05/2010 02:50 AM, Gregor Horvath wrote: >> Am Sun, 04 Jul 2010 18:51:54 -0500 >> schrieb Tim Chase: >> >>> I think it's the same venting of frustration that caused veteran VB6 >>> developers to start calling VB.Net "Visual Fred" -- the language was >>> too different and too non-backwards-compatible. >>> >>> >> VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. >> >> VB6 and VB.NET are totally different languages and technologies, with >> some similarity in syntax. This is not true for Python 2->3. This is an >> healthy organic language growth, not an abandon of a language. > > The quintessential example is Py3's breaking of Hello World. It's a > spectrum of language changes -- Visual Fred just happens to be MUCH > further down the same spectrum having more dramatic changes. Only a > subset of $OLD_VER (whether Py2 or VB6) code will run unmodified under > $NEW_VER (whether Py3 or VB.Net). The same holds for older versions of Python to Python 2.5 or 2.6, it's just that you have to work harder to find the incompatibilities. Try running this under later versions: [steve at sylar ~]$ python2.0 Python 2.0.1 (#1, Jan 14 2010, 15:43:17) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "copyright", "credits" or "license" for more information. >>> None = "Hello world" >>> print None Hello world > It just happens that the subset for > Python is considerably larger than the subset for VB (and Python's > conversion tools seem a little more useful than VB's, IMHO). IIRC, > neither raw VB6 nor Py2 byte-code will run raw in the new environment > (old VB .exe files don't make use of .Net libraries/CLR, nor do Py2 .pyc > files run under Py3) Python byte-code has never been compatible across minor version numbers, let alone major ones. -- Steven From tim at johnsons-web.com Mon Jul 5 20:44:17 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 05 Jul 2010 16:44:17 -0800 Subject: Shared object access problems References: <4c31424c$0$1613$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > On 7/4/2010 6:36 PM, Philip Semanchuk wrote: >> hi Tim, >> This seems more likely to be a MySQLdb problem than a Python one. Have >> you considered asking in the MySQLdb forums? >> >> On Jul 4, 2010, at 7:46 PM, Tim Johnson wrote: >> >>> Using python 2.6.4 on slackware 13.1 >>> I have MySQLdb 'by hand', that is: by >>> 1)downloading MySQL-python-1.2.3c1.tar.gz >>> 2)unzipping tarfile >>> 3)running python setup.py build >>> 4)running python setup.py install >>> >>> The build and install seemed to proceded without error, >>> but upon invoking the interpreter and running >>>>>> import MySQLdb >>> I get the following ImportError: >>> ############################################################## >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", >>> line 19, in >>> File "build/bdist.linux-i686/egg/_mysql.py", >>> line 7, in >>> File "build/bdist.linux-i686/egg/_mysql.py", >>> line 6, in __bootstrap__ >>> ImportError: libmysqlclient_r.so.15: >>> cannot open shared object file: No such file or directory > > Did you install the development libraries for MySQL first? > Those are needed to build MySQLdb yourself. > > John Nagle By that I think you mean libmysqlclient_r.so* and so forth, if so, yes. The question has become moot, as I recently did an upgrade from slack 13.0 to 13.1, and I've decided to procede with a clean install. So I'm dropping this inquiry and I'll keep my development on ubuntu for the time being. thanks for the help From drobinow at gmail.com Mon Jul 5 20:53:48 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 5 Jul 2010 20:53:48 -0400 Subject: Python 2.7 released In-Reply-To: <4c327596$0$28647$c3e8da3@news.astraweb.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 5, 2010 at 8:15 PM, Steven D'Aprano wrote: > On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > >> I'd like to view the contents of the help file without actually >> installing the release which would wipe out any currently installed >> version (I'm one of those rare people who actually reads manuals >> *before* using or installing most things.) ... > Are there any Windows users out there who can confirm that the installer > does or doesn't leave existing versions in place? The installer does leave existing versions in place. I have no idea what the OP is referring to. From python at mrabarnett.plus.com Mon Jul 5 20:56:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jul 2010 01:56:40 +0100 Subject: Another Regexp Question In-Reply-To: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> Message-ID: <4C327F48.2040100@mrabarnett.plus.com> andrew cooke wrote: > As ever, I guess it's most likely I've misunderstood something, but in > Python 2.6 lookback seems to actually be lookahead. All the following > tests pass: > > from re import compile > > assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc') > assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc') > assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc') > > assert compile('(a)b(?=(?(2)x|c))(c)').match('abc') > assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc') > assert compile('(a)b(?=(?(1)c|x))(c)').match('abc') > > But it seems to me that the first block should fail, because they > check the match *before* the point in question. > Both the first and third should fail, but they pass. > Note that without group references these work as I would expected: > > assert compile('(a)b(?<=b)(c)').match('abc') > assert not compile('(a)b(?<=c)(c)').match('abc') > > assert not compile('(a)b(?=b)(c)').match('abc') > assert compile('(a)b(?=c)(c)').match('abc') > > in which lookback does indeed lookback (note the asymmetry, while the > first examples were symmetrical). > > What am I missing this time? :o( > Nothing. It's a bug. :-( From philip at semanchuk.com Mon Jul 5 21:00:17 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 5 Jul 2010 21:00:17 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> Message-ID: <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk > wrote: >> On Jul 5, 2010, at 4:30 PM, D'Arcy J.M. Cain wrote: >>> On Mon, 05 Jul 2010 14:42:13 -0400 >>> Terry Reedy wrote: >>>> Good start. Now what is blocking those four? >>>> Lack of developer interest/time/ability? >>>> or something else that they need? >>> >>> How about a basic how-to document? I maintain PyGreSQL and would >>> like >>> to move it to 3.x right now but I don't even know what the issues >>> are. >>> I can see on the site the 2.x documents and the 3.x documents for >>> extending with C modules and I can read both from end to end but >>> that >>> hits the time issue above. If there was a relatively simple >>> document >>> that showed what needed to be changed in the C code we could get >>> started on the transition sooner. >>> >>> Or is there no change at the C level? That would make things easy. >> >> There are definitely changes at the C level. >> >> I ported two pure C extensions from 2 to 3 and was even able to >> keep a >> single C codebase. I'd be willing to contribute my experiences to a >> document >> somewhere. (Is there a Wiki?) > > Indeed there is: http://wiki.python.org/moin/ Thanks. I don't want to appear ungrateful, but I was hoping for something specific to the 2-to-3 conversion. I guess someone has to start somewhere... From andrew at acooke.org Mon Jul 5 21:25:36 2010 From: andrew at acooke.org (andrew cooke) Date: Mon, 5 Jul 2010 18:25:36 -0700 (PDT) Subject: Another Regexp Question References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> Message-ID: <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> On Jul 5, 8:56?pm, MRAB wrote: > andrew cooke wrote: > > What am I missing this time? :o( > Nothing. It's a bug. :-( Sweet :o) Thanks - do you want me to raise an issue or will you? Cheers, Andrew From python at mrabarnett.plus.com Mon Jul 5 21:38:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 06 Jul 2010 02:38:36 +0100 Subject: Another Regexp Question In-Reply-To: <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> Message-ID: <4C32891C.20901@mrabarnett.plus.com> andrew cooke wrote: > On Jul 5, 8:56 pm, MRAB wrote: >> andrew cooke wrote: >>> What am I missing this time? :o( >> Nothing. It's a bug. :-( > > Sweet :o) > > Thanks - do you want me to raise an issue or will you? > You found it. You can have the pleasure. From clp2 at rebertia.com Mon Jul 5 22:46:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 5 Jul 2010 19:46:42 -0700 Subject: markmin 0.1 In-Reply-To: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> References: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> Message-ID: On Mon, Jul 5, 2010 at 4:56 PM, Massimo Di Pierro wrote: > Markmin is a wiki markup language > implemented in less than 100 lines of code (one file, no dependencies) > easy to read > secure > support table, ul, ol, code > support html5 video and audio elements > can align images and resize them > CSS friendly (can specify class for tables and code elements) > can add anchors anywhere > does not use _ for markup (since it creates odd behavior) > automatically links urls > fast > with tests Okay, but where can it be downloaded from? You didn't include a link. Cheers, Chris From ggrp2.20.martineau at dfgh.net Mon Jul 5 22:52:06 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 19:52:06 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> Message-ID: <70e08284-c2c3-4e8e-8e44-d0c0285680c8@h40g2000pro.googlegroups.com> On Jul 5, 1:31?pm, Alexander Kapps wrote: > Martineau wrote: > > Perhaps it's hidden somewhere, but I couldn't find the .chm help file > > in the python-2.7.msi file using 7-zip, nor saw anything that looked > > like a Doc folder embedded within it -- so I doubt installing it on a > > Windows machine would work any better. > > I don't know much about the .msi format or how 7-Zip handles it, but > on my XP box, 7-Zip lists a "python" sub-archive (a 7-Zip > "compound"). Within is the python27.chm My mistake -- you're quite right the .chm *is* in the .msi where you indicated. FWIW I actually did look in that sub-section before posting yet somehow missed it. Sorry about that and thanks to all involved for your help. From ggrp2.20.martineau at dfgh.net Mon Jul 5 23:14:49 2010 From: ggrp2.20.martineau at dfgh.net (Martineau) Date: Mon, 5 Jul 2010 20:14:49 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> Message-ID: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> On Jul 5, 5:53?pm, David Robinow wrote: > On Mon, Jul 5, 2010 at 8:15 PM, Steven D'Aprano wrote: > > On Mon, 05 Jul 2010 12:59:00 -0700, Martineau wrote: > > >> I'd like to view the contents of the help file without actually > >> installing the release which would wipe out any currently installed > >> version (I'm one of those rare people who actually reads manuals > >> *before* using or installing most things.) > ... > > Are there any Windows users out there who can confirm that the installer > > does or doesn't leave existing versions in place? > > ?The installer does leave existing versions in place. I have no idea > what the OP is referring to. Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so would have interfered with the currently installed version because I always install Python in the same directory, one named just "Python", to minimize the number of changes I have to make to to other parts of the system. Some trivial examples are desktop shortcuts I've set up which point to the commandline version of the interpreter and another for the help file. I also believe the Windows installer makes registry changes that also involve paths to the currently installed version, which again, is something I wanted to avoid until I'm actually ready to commit to upgrading. If there are better ways on Windows to accomplish this, I'd like to hear about them. I suppose I could use hardlinks or junctions but they're not well supported on most versions of Windows. BTW, my original problem -- getting a copy of the Windows format compiled help file fro v2/7 without installing it has been taken care by suggestions from other, so this discussion is starting to way off- topic... Thanks, Martin From martin at v.loewis.de Mon Jul 5 23:28:00 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 06 Jul 2010 05:28:00 +0200 Subject: Python 2.7 released In-Reply-To: References: Message-ID: <4C32A2C0.1060703@v.loewis.de> > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? I have now put that file separately on the release page. Regards, Martin From kedra.marbun at gmail.com Tue Jul 6 00:10:51 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:10:51 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> Message-ID: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> On Jul 5, 3:42?pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > i'm confused which part that doesn't make sense? > > this is my 2nd attempt to py, the 1st was on april this year, it was > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > i'm gonna lay out how i got to this conclusion, CMIIW > > > **explanation of feeling (0) on my 1st post** > > to me, descriptor is a particular kind of delegation, it takes the job > > of coding the delegation by having a contract with programmers that > > the tree meta operations (get, set, del) on attr are delegated to the > > obj that is bound to the attr > > are we agree that descriptor is a kind of delegation? > > > the mechanism that makes descriptor works is in __getattribute__, > > __setattr__, __delattr__ of 'object' & 'type' > > > now, if i want a single descriptor obj to be delegated to multiple > > tasks, i can't do it since __get__ doesn't get info that can be used > > to determine which task to do > > i must have diff descriptor obj for each task > > > class Helper: > > ? ?def __init__(self, name): > > ? ? ? ? ? ?self.name = name > > ? ?def __get__(self, ins, cls): > > ? ? ? ? ? ?if self.name == 'task0': ... > > ? ? ? ? ? ?elif self.name == 'task1': ... > > ? ? ? ? ? ?else: ... > > Replacing such "big switch" code with polymorphic dispatch is one of the > ? goals (and feature) of OO. This should be: > > class Task0(object): > ? ? ?def __get__(self, obj, cls): > ? ? ? ? ?# code here > > class Task1(object): > ? ? ?def __get__(self, obj, cls): > ? ? ? ? ?# code here > > class A(object): > ? ? ?task0 = Task0() > ? ? ?task1 = Task1() > > If you have common code to share between TaskO and Task1 then factor it > out into a base class. > > > if __get__ receives the name, then i could do > > > class Helper: > > ? ?def __get__(self, ins, cls, name): > > ? ? ? ? ? ?... > > > class a: > > ? ?task0 = task1 = Helper() > > Yuck. what's so 'Yuck' about it? ;) i guess i need a strong stmt: is descriptor a kind of delegation? or is it not? * if it is a kind of delegation, then the code that you labeled as 'Yuck' is just a result of applying delegation what's wrong with delegating multiple tasks to a single obj? that code is similar to this class Helper: def do_this(self, ins): ... def do_that(self, ins): ... class a: delegate = Helper() def task0(self): self.delegate.do_that(self) def task1(self): self.delegate.do_this(self) the diff is that this code manually code the delegation, that's why it can branches to 2 funcs. while descriptor takes all to __get__, because it works on more meta lv * if it's not, then there's nothing to be argued, the name 'descriptor' is perfectly fit: descriptor obj describes attr of class, with 'describe' translates to: . = del, in py vocabularies. then, to think a single descriptor obj describing a single attr is acceptable, it's a common sense From kedra.marbun at gmail.com Tue Jul 6 00:12:47 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:12:47 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: On Jul 5, 7:49?am, Gregory Ewing wrote: > kedra marbun wrote: > > now, i'm asking another favor, what about the 2nd point in my 1st post? > > Your original post has dropped off my newsscope, so > you'll have to remind me what the 2nd point was. > > -- > Greg it's like 'name', it's about info that i think should be passed to descriptor's __{get|set|delete}__. i wonder what are the reasons for not passing the class on which the descriptor is attached to, what pattern is encouraged by this? From kedra.marbun at gmail.com Tue Jul 6 00:15:33 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:15:33 -0700 (PDT) Subject: Getting the name of the file that imported current module References: <4c311941$0$28647$c3e8da3@news.astraweb.com> Message-ID: <52be73ef-363f-47cc-bff7-63f1027f280d@y12g2000prb.googlegroups.com> On Jul 5, 6:29?am, Steven D'Aprano wrote: > On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > > foo.py: > > > import bar > > bar.show_importer() > > > output: > > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > > Possible? > > I don't think so. Your question isn't even well-defined. Given three > modules: > > # a.py > import b > import d > > # b.py > import d > > # c.py > import a > import d > import b > print d.show_importer() > > and you run c.py, what do you expect d.show_importer() to return? > > And what about "from d import show_importer" -- does that count as > "importing d"? > > Why do you think that a module needs to know what other modules imported > it? I can't imagine why this would be necessary, what are you intending > to do with it? > > -- > Steven i guess he just likes to play things around, entertains his imagination, no need for practical reason for that From kedra.marbun at gmail.com Tue Jul 6 00:25:26 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 21:25:26 -0700 (PDT) Subject: Getting the name of the file that imported current module References: Message-ID: <0abdf4a8-a2bb-4800-a166-866964335eb9@q21g2000prm.googlegroups.com> On Jul 5, 4:05?am, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah if what you mean by 'importer' is the one that really cause py to load the mod, then why not dynamically set it? foo.py ------ import bar, sys if '_importer' not in bar.__dict__: bar._importer = sys.modules[__name__] bar.py ------ def show_importer(): return _importer or you could borrow space from builtins. i don't know if it breaks any rule ;) foo.py ------ def set_importer(mod): bdict = (__builtins__.__dict__ if __name__ == '__main__' else __builtins__) if '_importer' not in bdict: bdict['_importer'] = {mod : sys.modules[__name__]} else: if mod not in bdict: bdict['_importer'][mod] = sys.modules[__name__] import bar set_importer(bar) From nagle at animats.com Tue Jul 6 00:45:07 2010 From: nagle at animats.com (John Nagle) Date: Mon, 05 Jul 2010 21:45:07 -0700 Subject: Getting pyparsing to backtrack In-Reply-To: <4c325a88$0$1672$742ec2ed@news.sonic.net> References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: <4c32b4d2$0$1677$742ec2ed@news.sonic.net> On 7/5/2010 3:19 PM, John Nagle wrote: > I'm working on street address parsing again, and I'm trying to deal > with some of the harder cases. The approach below works for the cases given. The "Or" operator ("^") supports backtracking, but "Optional()" apparently does not. direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameOnly = Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") streetNameParser = ((direction.setResultsName("predirectional") + streetNameOnly) ^ streetNameOnly) John Nagle From steve-REMOVE-THIS at cybersource.com.au Tue Jul 6 01:11:09 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 05:11:09 GMT Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: <4c32baec$0$28649$c3e8da3@news.astraweb.com> On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > On Jul 5, 7:49?am, Gregory Ewing wrote: >> kedra marbun wrote: >> > now, i'm asking another favor, what about the 2nd point in my 1st >> > post? >> >> Your original post has dropped off my newsscope, so you'll have to >> remind me what the 2nd point was. >> >> -- >> Greg > > it's like 'name', it's about info that i think should be passed to > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > passing the class on which the descriptor is attached to, what pattern > is encouraged by this? Perhaps I'm missing the context, but since the descriptor is passed the instance, you can easily get the class with type(self) or self.__class__. There's no need to pass the class as a separate argument. -- Steven From tjreedy at udel.edu Tue Jul 6 01:37:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jul 2010 01:37:41 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On 7/5/2010 9:00 PM, Philip Semanchuk wrote: > > On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > >> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk >>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>> single C codebase. I'd be willing to contribute my experiences to a >>> document >>> somewhere. (Is there a Wiki?) >> >> Indeed there is: http://wiki.python.org/moin/ > > Thanks. I don't want to appear ungrateful, but I was hoping for > something specific to the 2-to-3 conversion. I guess someone has to > start somewhere... There is an existing 2to3 and other pages for Python code conversion. I do not know of any for CAPI conversion. The need for such has been acknowledged among the devs but if there is nothing yet, we need someone with specialized experience and a bit of time to make a first draft. If you start one, give it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from the 2to3 page In his post on this thread, Martin Loewis volunteered to list what he knows from psycopg2 if someone else will edit. -- Terry Jan Reedy From rami.chowdhury at gmail.com Tue Jul 6 01:40:03 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 5 Jul 2010 22:40:03 -0700 Subject: delegation pattern via descriptor In-Reply-To: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> Message-ID: <201007052240.03452.rami.chowdhury@gmail.com> On Monday 05 July 2010 21:10:51 kedra marbun wrote: > On Jul 5, 3:42 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > kedra marbun a ?crit : > > > i'm confused which part that doesn't make sense? > > > this is my 2nd attempt to py, the 1st was on april this year, it was > > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > > i'm gonna lay out how i got to this conclusion, CMIIW > > > > > > **explanation of feeling (0) on my 1st post** > > > to me, descriptor is a particular kind of delegation, it takes the job > > > of coding the delegation by having a contract with programmers that > > > the tree meta operations (get, set, del) on attr are delegated to the > > > obj that is bound to the attr > > > are we agree that descriptor is a kind of delegation? > > > > > > the mechanism that makes descriptor works is in __getattribute__, > > > __setattr__, __delattr__ of 'object' & 'type' > > > > > > now, if i want a single descriptor obj to be delegated to multiple > > > tasks, i can't do it since __get__ doesn't get info that can be used > > > to determine which task to do > > > i must have diff descriptor obj for each task > > > > > > class Helper: > > > def __init__(self, name): > > > self.name = name > > > def __get__(self, ins, cls): > > > if self.name == 'task0': ... > > > elif self.name == 'task1': ... > > > else: ... > > > > Replacing such "big switch" code with polymorphic dispatch is one of the > > goals (and feature) of OO. This should be: > > > > class Task0(object): > > def __get__(self, obj, cls): > > # code here > > > > class Task1(object): > > def __get__(self, obj, cls): > > # code here > > > > class A(object): > > task0 = Task0() > > task1 = Task1() > > > > If you have common code to share between TaskO and Task1 then factor it > > out into a base class. > > > > > if __get__ receives the name, then i could do > > > > > > class Helper: > > > def __get__(self, ins, cls, name): > > > ... > > > > > > class a: > > > task0 = task1 = Helper() > > > > Yuck. > > what's so 'Yuck' about it? ;) > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? Thanks for posting the code sample -- it makes your meaning a great deal clearer. No, descriptors are not delegation as in your sample**, although they are very flexible and could be used to implement that if you wanted. > * if it's not, then there's nothing to be argued, the name > 'descriptor' is perfectly fit: descriptor obj describes attr of class, > with 'describe' translates to: . = del, in py vocabularies. then, to > think a single descriptor obj describing a single attr is acceptable, > it's a common sense ** As I understand it, anyway -- someone please correct me if I'm wrong. ---- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity." -- Hanlon's Razor +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From db3l.net at gmail.com Tue Jul 6 02:06:21 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 06 Jul 2010 02:06:21 -0400 Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: Martineau writes: > Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so > would have interfered with the currently installed version because I > always install Python in the same directory, one named just "Python", > to minimize the number of changes I have to make to to other parts of > the system. That's fine, you're just making a conscious choice to only support (yourself) a single version installed at a time. I tend to need multiple versions around when developing, so I keep a bunch of versions all installed in separate directories as \Python\x.y (so I only have a single root directory). With 2.7, my current box has 6 Python interpreters (2.4-3.1) installed at the moment. I use Cygwin (wouldn't try to work on a Windows system without it), so just use bash aliases to execute the right interpreter, but a batch file could be used with the cmd interpreter, and you could link GUI shortcuts to that batch file. Not sure there's a good solution to your help file link, other than the existing Start menu links installed per Python version. Even with local links you'd probably want separate links per version anyway since they're different documents. Of course, since this started by just considering installing it to get at a single file (which I know was since solved), it's probably an acceptable use case for violating your standard policy and picking a different directory name just in this case, and then blowing it away later. :-) > I also believe the Windows installer makes registry > changes that also involve paths to the currently installed version, > which again, is something I wanted to avoid until I'm actually ready > to commit to upgrading. The path information installed in the registry (Software\Python\PythonCore under HLKM or HKCU depending on installation options) is structured according to major.minor release (e.g., 2.6 vs. 2.7 are distinct), but you're right Windows only supports one file extension mapping, so by default the last Python to be installed gets associated with .py/.pyw etc... by default. But you can optionally disable this during installation. On the customize screen showing during installation. de-select the "Register Extensions" option, and the active install won't change any existing mappings and thus have no impact on your current default installation. > If there are better ways on Windows to accomplish this, I'd like to > hear about them. I suppose I could use hardlinks or junctions but > they're not well supported on most versions of Windows. If you're still using the basic Windows command prompt or GUI links then a batch file is the simplest way to go. With something like Cygwin (which I personally would never do without), then you have a variety of techniques available including links, shell aliases, etc... -- David From vinay_sajip at yahoo.co.uk Tue Jul 6 02:22:05 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 5 Jul 2010 23:22:05 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <8d33b35b-26bf-4288-8133-669d318ecafa@a30g2000yqn.googlegroups.com> On Jul 5, 2:35?pm, Antoine Pitrou wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. UTF-8 is only used as a fallback in an exception handler, you can use any supported encoding using the encoding= keyword argument to a FileHandler. > > I suggest you report an issue onhttp://bugs.python.org Yes, please do that and I will investigate. Regards, Vinay Sajip From kedra.marbun at gmail.com Tue Jul 6 02:26:16 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Mon, 5 Jul 2010 23:26:16 -0700 (PDT) Subject: Why Python forbids multiple instances of one module? References: <19cb8af.59f6.129a0f65716.Coremail.dr.cg@126.com> Message-ID: module obj is instance of types.ModuleType, which is instance of 'type', where class obj is instance of 'type'. even only at this point, they're diff in to many ways. there are so many things to do when you truly want module to replace class, as pointed by 2 posts above i'm also a beginner, so i can offer you a tip in learning it: follow the design, py usually has good reasons about it, i've lost in every challenge i put against py design, luckily i find the reasons through my own experiment. yes, it's better to find it through hacking, rather than people talking about it, the reason is the same as coding to learn programming, not only reading book. it will become more understandable when people say py has clean design as for 'self', yes i admit it seems troublesome at first, you'll have reason for it once you know that method is simply a func, you'll embrace the more general design (py requires you to specify a name for the caller) when you learn about metaclass. a nice argument to this is that human beings are visual creatures, it becomes so much easier to have a name that desribes the obj it points to (like 'self', 'cls', 'metacls') than implicit name that trying to be as general as possible (like 'this') From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 6 04:05:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 06 Jul 2010 10:05:47 +0200 Subject: delegation pattern via descriptor In-Reply-To: <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <4c319ae6$0$14953$426a74cc@news.free.fr> <55c6e673-f7d9-40c5-9fef-59096f8c092e@i16g2000prn.googlegroups.com> Message-ID: <4c32e3d6$0$661$426a34cc@news.free.fr> kedra marbun a ?crit : > On Jul 5, 3:42 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> kedra marbun a ?crit : >> >> >> >>> i'm confused which part that doesn't make sense? >>> this is my 2nd attempt to py, the 1st was on april this year, it was >>> just a month, i'm afraid i haven't got the fundamentals right yet. so >>> i'm gonna lay out how i got to this conclusion, CMIIW >>> **explanation of feeling (0) on my 1st post** >>> to me, descriptor is a particular kind of delegation, it takes the job >>> of coding the delegation by having a contract with programmers that >>> the tree meta operations (get, set, del) on attr are delegated to the >>> obj that is bound to the attr >>> are we agree that descriptor is a kind of delegation? >>> the mechanism that makes descriptor works is in __getattribute__, >>> __setattr__, __delattr__ of 'object' & 'type' >>> now, if i want a single descriptor obj to be delegated to multiple >>> tasks, i can't do it since __get__ doesn't get info that can be used >>> to determine which task to do >>> i must have diff descriptor obj for each task >>> class Helper: >>> def __init__(self, name): >>> self.name = name >>> def __get__(self, ins, cls): >>> if self.name == 'task0': ... >>> elif self.name == 'task1': ... >>> else: ... >> Replacing such "big switch" code with polymorphic dispatch is one of the >> goals (and feature) of OO. This should be: >> >> class Task0(object): >> def __get__(self, obj, cls): >> # code here >> >> class Task1(object): >> def __get__(self, obj, cls): >> # code here >> >> class A(object): >> task0 = Task0() >> task1 = Task1() >> >> If you have common code to share between TaskO and Task1 then factor it >> out into a base class. >> >>> if __get__ receives the name, then i could do >>> class Helper: >>> def __get__(self, ins, cls, name): >>> ... >>> class a: >>> task0 = task1 = Helper() >> Yuck. > > what's so 'Yuck' about it? ;) It's an implicit, obfuscated and overcomplicated way to do a very simple thing. To be true, I just don't see the point of this pattern - Python has better solutions for delegation (cf the __getattr__ method), and that's not what descriptors are for. > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? The descriptor protocol is the primary support for computed attributes. As such it can be used as a support for delegation, but it's not "a kind of delegation" by itself. > * if it is a kind of delegation, then the code that you labeled as > 'Yuck' is just a result of applying delegation > what's wrong with delegating multiple tasks to a single obj? Nothing wrong with delegating multiple tasks to a single object - but not that way. If you want to use descriptors to specify which tasks should be delegated, you'd be better doing it more explicitely - that is, only use the descriptor as a gateway, and use one descriptor per task. Else just use __getattr__ !-) Sorry, I don't have much time to elaborate on this now. > that code is similar to this > > class Helper: > def do_this(self, ins): ... > def do_that(self, ins): ... > > class a: > delegate = Helper() > def task0(self): self.delegate.do_that(self) > def task1(self): self.delegate.do_this(self) > It's not similar. This second example is explicit, and doesn't couple Helper to a. My 2 cents. From mail at timgolden.me.uk Tue Jul 6 04:07:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 06 Jul 2010 09:07:48 +0100 Subject: Python 2.7 released In-Reply-To: References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: <4C32E454.4000006@timgolden.me.uk> On 06/07/2010 07:06, David Bolen wrote: > I tend to need multiple versions around when developing, so I keep a > bunch of versions all installed in separate directories as \Python\x.y > (so I only have a single root directory). With 2.7, my current box > has 6 Python interpreters (2.4-3.1) installed at the moment. > > I use Cygwin (wouldn't try to work on a Windows system without it), so > just use bash aliases to execute the right interpreter, but a batch > file could be used with the cmd interpreter, and you could link GUI > shortcuts to that batch file. I, too, have multiple versions installed -- newer ones for running code I haven't upgraded; older ones for compatibility testing where needed. I just install to the default c:\pythonxy directories (although I like the idea of a common root) and I put NTFS hardlinks into my general c:\tools directory which is on the path. The out-of-context hardlinks work because of the registry settings which pick up the correct context for each version. (I've never quite clicked with cygwin or MingW despite giving them several goes on the basis of others' enthusiasm...) TJG From cournape at gmail.com Tue Jul 6 04:30:34 2010 From: cournape at gmail.com (David Cournapeau) Date: Tue, 6 Jul 2010 16:30:34 +0800 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <20100705163043.f4c8d085.darcy@druid.net> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > On Mon, 05 Jul 2010 14:42:13 -0400 > Terry Reedy wrote: >> Good start. Now what is blocking those four? >> Lack of developer interest/time/ability? >> or something else that they need? > > How about a basic how-to document? ?I maintain PyGreSQL and would like > to move it to 3.x right now but I don't even know what the issues are. One thing that would be very useful is how to maintain something that works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up versions below 2.6 is out of the question for most projects with a significant userbase IMHO. As such, the idea of running the python 3 warnings is not so useful IMHO - unless it could be made to work better for python 2.x < 2.6, but I am not sure the idea even makes sense. > > Or is there no change at the C level? ?That would make things easy. There are quite a few, but outside of the big pain point of strings/byte/unicode which is present at python level as well, a lot of the issues are not so big (and even simpler to deal with). For example, although numpy took time to port (and is still experimental in nature), it took me a couple of hours to get a basic scipy working (numpy uses a lot of C api dark corners, whereas scipy is much more straightforward in its usage of the C API). David From thomas at jollans.com Tue Jul 6 05:02:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 11:02:07 +0200 Subject: Getting pyparsing to backtrack In-Reply-To: References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: <4C32F10F.7020006@jollans.com> On 07/06/2010 04:21 AM, Dennis Lee Bieber wrote: > On Mon, 05 Jul 2010 15:19:53 -0700, John Nagle > declaimed the following in gmane.comp.python.general: > >> I'm working on street address parsing again, and I'm trying to deal >> with some of the harder cases. >> > > Hasn't it been suggested before, that the sanest method to parse > addresses is from the end backwards... > > So that: > > 123 N South St. > > is parsed as > > St. South N 123 You will of course need some trickery for that to work with Hauptstr. 12 From stefan_ml at behnel.de Tue Jul 6 05:02:55 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Jul 2010 11:02:55 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4c317c52$0$28665$c3e8da3@news.astraweb.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c317c52$0$28665$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 05.07.2010 08:31: > On Sun, 04 Jul 2010 17:34:04 -0700, sturlamolden wrote: > >> Using Python 2.x for new >> projects is not advisable (at least many will think so), and using 3.x >> is not possible. What to do? It's not a helpful situation for Python. > > That's pure FUD. > > Python 2.7 will be supported longer than the normal support period for > versions 2.6, 2.5, 2.4, ... so if you have a new project that requires > libraries that aren't available for 3.1, then go right ahead and use 2.7. > By the time 2.7 is no longer supported (probably around the time 3.4 > comes out?), the library situation will be fixed. > > Those 3.1 features that can be backported to 2.x have been, specifically > to reduce the pain in porting 2.7-based applications to 3.x. Feature- > wise, 2.7 is designed to ease the transition from the 2.x series to the > 3.x series. Claiming that it's not advisable to use 2.7 is simply > nonsense. Not to forget about the 2to3 tool. If you write code for 2.6 or 2.7 now, you can actually port it automatically and continuously, and do the final switch when you think it's time. So both choices (2 or 3) are real and available. Stefan From matt.j.warren at gmail.com Tue Jul 6 05:55:25 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 02:55:25 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions Message-ID: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> Hi, I'm using datetime.strptime(string,format) to convert dates parsed from a file into datetime objects. However, the files come from various places around the world, and strptime fails when non-english month names are used. strptime says it converts month names using the current locales version of the name. I've looked into the locale module but can't see how I would setup.change a locales date/time representations, I can only see categories related to decimal number / currency representations. Can anyone show how I could change the locale such that strptime could parse a date string that used say, German month names? Thankyou From certifiedlover at hotmail.com Tue Jul 6 06:03:26 2010 From: certifiedlover at hotmail.com (francisco dorset) Date: Tue, 6 Jul 2010 11:03:26 +0100 Subject: Python-list Digest, Vol 82, Issue 48 In-Reply-To: References: Message-ID: i need resources or books on how to embedding python into c/c++...and also extending it am allergic to cheating, i hate failures, but am in love with achievements <.???`?.F?an???C?`?.???.???`?.?><((((?> From: python-list-request at python.org Subject: Python-list Digest, Vol 82, Issue 48 To: python-list at python.org Date: Tue, 6 Jul 2010 08:25:02 +0200 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..." --Forwarded Message Attachment-- From: martin at v.loewis.de To: python-list at python.org Date: Tue, 6 Jul 2010 05:28:00 +0200 Subject: Re: Python 2.7 released > Benjamin (or anyone else), do you know where I can get the Compiled > Windows Help file -- python27.chm -- for this release? I have now put that file separately on the release page. Regards, Martin --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:10:51 -0700 Subject: Re: delegation pattern via descriptor On Jul 5, 3:42 pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > i'm confused which part that doesn't make sense? > > this is my 2nd attempt to py, the 1st was on april this year, it was > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > i'm gonna lay out how i got to this conclusion, CMIIW > > > **explanation of feeling (0) on my 1st post** > > to me, descriptor is a particular kind of delegation, it takes the job > > of coding the delegation by having a contract with programmers that > > the tree meta operations (get, set, del) on attr are delegated to the > > obj that is bound to the attr > > are we agree that descriptor is a kind of delegation? > > > the mechanism that makes descriptor works is in __getattribute__, > > __setattr__, __delattr__ of 'object' & 'type' > > > now, if i want a single descriptor obj to be delegated to multiple > > tasks, i can't do it since __get__ doesn't get info that can be used > > to determine which task to do > > i must have diff descriptor obj for each task > > > class Helper: > > def __init__(self, name): > > self.name = name > > def __get__(self, ins, cls): > > if self.name == 'task0': ... > > elif self.name == 'task1': ... > > else: ... > > Replacing such "big switch" code with polymorphic dispatch is one of the > goals (and feature) of OO. This should be: > > class Task0(object): > def __get__(self, obj, cls): > # code here > > class Task1(object): > def __get__(self, obj, cls): > # code here > > class A(object): > task0 = Task0() > task1 = Task1() > > If you have common code to share between TaskO and Task1 then factor it > out into a base class. > > > if __get__ receives the name, then i could do > > > class Helper: > > def __get__(self, ins, cls, name): > > ... > > > class a: > > task0 = task1 = Helper() > > Yuck. what's so 'Yuck' about it? ;) i guess i need a strong stmt: is descriptor a kind of delegation? or is it not? * if it is a kind of delegation, then the code that you labeled as 'Yuck' is just a result of applying delegation what's wrong with delegating multiple tasks to a single obj? that code is similar to this class Helper: def do_this(self, ins): ... def do_that(self, ins): ... class a: delegate = Helper() def task0(self): self.delegate.do_that(self) def task1(self): self.delegate.do_this(self) the diff is that this code manually code the delegation, that's why it can branches to 2 funcs. while descriptor takes all to __get__, because it works on more meta lv * if it's not, then there's nothing to be argued, the name 'descriptor' is perfectly fit: descriptor obj describes attr of class, with 'describe' translates to: . = del, in py vocabularies. then, to think a single descriptor obj describing a single attr is acceptable, it's a common sense --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:12:47 -0700 Subject: Re: delegation pattern via descriptor On Jul 5, 7:49 am, Gregory Ewing wrote: > kedra marbun wrote: > > now, i'm asking another favor, what about the 2nd point in my 1st post? > > Your original post has dropped off my newsscope, so > you'll have to remind me what the 2nd point was. > > -- > Greg it's like 'name', it's about info that i think should be passed to descriptor's __{get|set|delete}__. i wonder what are the reasons for not passing the class on which the descriptor is attached to, what pattern is encouraged by this? --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:15:33 -0700 Subject: Re: Getting the name of the file that imported current module On Jul 5, 6:29 am, Steven D'Aprano wrote: > On Sun, 04 Jul 2010 21:05:56 +0000, Tobiah wrote: > > foo.py: > > > import bar > > bar.show_importer() > > > output: > > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > > Possible? > > I don't think so. Your question isn't even well-defined. Given three > modules: > > # a.py > import b > import d > > # b.py > import d > > # c.py > import a > import d > import b > print d.show_importer() > > and you run c.py, what do you expect d.show_importer() to return? > > And what about "from d import show_importer" -- does that count as > "importing d"? > > Why do you think that a module needs to know what other modules imported > it? I can't imagine why this would be necessary, what are you intending > to do with it? > > -- > Steven i guess he just likes to play things around, entertains his imagination, no need for practical reason for that --Forwarded Message Attachment-- From: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:25:26 -0700 Subject: Re: Getting the name of the file that imported current module On Jul 5, 4:05 am, Tobiah wrote: > foo.py: > > import bar > bar.show_importer() > > output: > > 'foo' or 'foo.py' or 'path/to/foo' etc. > > Possible? > > Thanks, > > Tobiah if what you mean by 'importer' is the one that really cause py to load the mod, then why not dynamically set it? foo.py ------ import bar, sys if '_importer' not in bar.__dict__: bar._importer = sys.modules[__name__] bar.py ------ def show_importer(): return _importer or you could borrow space from builtins. i don't know if it breaks any rule ;) foo.py ------ def set_importer(mod): bdict = (__builtins__.__dict__ if __name__ == '__main__' else __builtins__) if '_importer' not in bdict: bdict['_importer'] = {mod : sys.modules[__name__]} else: if mod not in bdict: bdict['_importer'][mod] = sys.modules[__name__] import bar set_importer(bar) --Forwarded Message Attachment-- From: nagle at animats.com To: python-list at python.org Date: Mon, 5 Jul 2010 21:45:07 -0700 Subject: Re: Getting pyparsing to backtrack On 7/5/2010 3:19 PM, John Nagle wrote: > I'm working on street address parsing again, and I'm trying to deal > with some of the harder cases. The approach below works for the cases given. The "Or" operator ("^") supports backtracking, but "Optional()" apparently does not. direction = Combine(MatchFirst(map(CaselessKeyword, directionals)) + Optional(".").suppress()) streetNameOnly = Combine(OneOrMore(Word(alphanums)), adjacent=False, joinString=" ").setResultsName("streetname") streetNameParser = ((direction.setResultsName("predirectional") + streetNameOnly) ^ streetNameOnly) John Nagle --Forwarded Message Attachment-- From: steve-REMOVE-THIS at cybersource.com.au To: python-list at python.org Date: Tue, 6 Jul 2010 05:11:09 +0000 Subject: Re: delegation pattern via descriptor On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > On Jul 5, 7:49 am, Gregory Ewing wrote: >> kedra marbun wrote: >> > now, i'm asking another favor, what about the 2nd point in my 1st >> > post? >> >> Your original post has dropped off my newsscope, so you'll have to >> remind me what the 2nd point was. >> >> -- >> Greg > > it's like 'name', it's about info that i think should be passed to > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > passing the class on which the descriptor is attached to, what pattern > is encouraged by this? Perhaps I'm missing the context, but since the descriptor is passed the instance, you can easily get the class with type(self) or self.__class__. There's no need to pass the class as a separate argument. -- Steven --Forwarded Message Attachment-- From: rami.chowdhury at gmail.com CC: kedra.marbun at gmail.com To: python-list at python.org Date: Mon, 5 Jul 2010 22:40:03 -0700 Subject: Re: delegation pattern via descriptor On Monday 05 July 2010 21:10:51 kedra marbun wrote: > On Jul 5, 3:42 pm, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > kedra marbun a ?crit : > > > i'm confused which part that doesn't make sense? > > > this is my 2nd attempt to py, the 1st was on april this year, it was > > > just a month, i'm afraid i haven't got the fundamentals right yet. so > > > i'm gonna lay out how i got to this conclusion, CMIIW > > > > > > **explanation of feeling (0) on my 1st post** > > > to me, descriptor is a particular kind of delegation, it takes the job > > > of coding the delegation by having a contract with programmers that > > > the tree meta operations (get, set, del) on attr are delegated to the > > > obj that is bound to the attr > > > are we agree that descriptor is a kind of delegation? > > > > > > the mechanism that makes descriptor works is in __getattribute__, > > > __setattr__, __delattr__ of 'object' & 'type' > > > > > > now, if i want a single descriptor obj to be delegated to multiple > > > tasks, i can't do it since __get__ doesn't get info that can be used > > > to determine which task to do > > > i must have diff descriptor obj for each task > > > > > > class Helper: > > > def __init__(self, name): > > > self.name = name > > > def __get__(self, ins, cls): > > > if self.name == 'task0': ... > > > elif self.name == 'task1': ... > > > else: ... > > > > Replacing such "big switch" code with polymorphic dispatch is one of the > > goals (and feature) of OO. This should be: > > > > class Task0(object): > > def __get__(self, obj, cls): > > # code here > > > > class Task1(object): > > def __get__(self, obj, cls): > > # code here > > > > class A(object): > > task0 = Task0() > > task1 = Task1() > > > > If you have common code to share between TaskO and Task1 then factor it > > out into a base class. > > > > > if __get__ receives the name, then i could do > > > > > > class Helper: > > > def __get__(self, ins, cls, name): > > > ... > > > > > > class a: > > > task0 = task1 = Helper() > > > > Yuck. > > what's so 'Yuck' about it? ;) > i guess i need a strong stmt: is descriptor a kind of delegation? or > is it not? Thanks for posting the code sample -- it makes your meaning a great deal clearer. No, descriptors are not delegation as in your sample**, although they are very flexible and could be used to implement that if you wanted. > * if it's not, then there's nothing to be argued, the name > 'descriptor' is perfectly fit: descriptor obj describes attr of class, > with 'describe' translates to: . = del, in py vocabularies. then, to > think a single descriptor obj describing a single attr is acceptable, > it's a common sense ** As I understand it, anyway -- someone please correct me if I'm wrong. ---- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity." -- Hanlon's Razor +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 --Forwarded Message Attachment-- From: tjreedy at udel.edu To: python-list at python.org Date: Tue, 6 Jul 2010 01:37:41 -0400 Subject: Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") On 7/5/2010 9:00 PM, Philip Semanchuk wrote: > > On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: > >> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk >>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>> single C codebase. I'd be willing to contribute my experiences to a >>> document >>> somewhere. (Is there a Wiki?) >> >> Indeed there is: http://wiki.python.org/moin/ > > Thanks. I don't want to appear ungrateful, but I was hoping for > something specific to the 2-to-3 conversion. I guess someone has to > start somewhere... There is an existing 2to3 and other pages for Python code conversion. I do not know of any for CAPI conversion. The need for such has been acknowledged among the devs but if there is nothing yet, we need someone with specialized experience and a bit of time to make a first draft. If you start one, give it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from the 2to3 page In his post on this thread, Martin Loewis volunteered to list what he knows from psycopg2 if someone else will edit. -- Terry Jan Reedy --Forwarded Message Attachment-- From: db3l.net at gmail.com To: python-list at python.org Date: Tue, 6 Jul 2010 02:06:21 -0400 Subject: Re: Python 2.7 released Martineau writes: > Some clarification. I meant installed 2.7 on top of 2.6.x. Doing so > would have interfered with the currently installed version because I > always install Python in the same directory, one named just "Python", > to minimize the number of changes I have to make to to other parts of > the system. That's fine, you're just making a conscious choice to only support (yourself) a single version installed at a time. I tend to need multiple versions around when developing, so I keep a bunch of versions all installed in separate directories as \Python\x.y (so I only have a single root directory). With 2.7, my current box has 6 Python interpreters (2.4-3.1) installed at the moment. I use Cygwin (wouldn't try to work on a Windows system without it), so just use bash aliases to execute the right interpreter, but a batch file could be used with the cmd interpreter, and you could link GUI shortcuts to that batch file. Not sure there's a good solution to your help file link, other than the existing Start menu links installed per Python version. Even with local links you'd probably want separate links per version anyway since they're different documents. Of course, since this started by just considering installing it to get at a single file (which I know was since solved), it's probably an acceptable use case for violating your standard policy and picking a different directory name just in this case, and then blowing it away later. :-) > I also believe the Windows installer makes registry > changes that also involve paths to the currently installed version, > which again, is something I wanted to avoid until I'm actually ready > to commit to upgrading. The path information installed in the registry (Software\Python\PythonCore under HLKM or HKCU depending on installation options) is structured according to major.minor release (e.g., 2.6 vs. 2.7 are distinct), but you're right Windows only supports one file extension mapping, so by default the last Python to be installed gets associated with .py/.pyw etc... by default. But you can optionally disable this during installation. On the customize screen showing during installation. de-select the "Register Extensions" option, and the active install won't change any existing mappings and thus have no impact on your current default installation. > If there are better ways on Windows to accomplish this, I'd like to > hear about them. I suppose I could use hardlinks or junctions but > they're not well supported on most versions of Windows. If you're still using the basic Windows command prompt or GUI links then a batch file is the simplest way to go. With something like Cygwin (which I personally would never do without), then you have a variety of techniques available including links, shell aliases, etc... -- David --Forwarded Message Attachment-- From: vinay_sajip at yahoo.co.uk To: python-list at python.org Date: Mon, 5 Jul 2010 23:22:05 -0700 Subject: Re: SMTPHandler and Unicode On Jul 5, 2:35 pm, Antoine Pitrou wrote: > > a FileHandler works as expected, the log file being UTF-8 encoded. > > Ouch. Implicit encoding sounds like a bad behaviour. UTF-8 is only used as a fallback in an exception handler, you can use any supported encoding using the encoding= keyword argument to a FileHandler. > > I suggest you report an issue onhttp://bugs.python.org Yes, please do that and I will investigate. Regards, Vinay Sajip _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.j.warren at gmail.com Tue Jul 6 06:03:34 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 03:03:34 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> Message-ID: <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> On 6 July, 10:55, AlienBaby wrote: > Hi, > > I'm using datetime.strptime(string,format) to convert dates parsed > from a file into datetime objects. > > However, the files come from various places around the world, and > strptime fails when non-english month names are used. > > strptime says it converts month names using the current locales > version of the name. ?I've looked into the locale module but can't see > how I would setup.change a locales date/time representations, I can > only see categories related to decimal number / currency > representations. > > Can anyone show how I could change the locale such that strptime could > parse a date string that used say, German month names? > > Thankyou I just solved this I believe. I didnt spot LC_ALL or LC_TIME previously. From sturlamolden at yahoo.no Tue Jul 6 06:12:08 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 03:12:08 -0700 (PDT) Subject: Python as a scripting language. Alternative to bash script? References: Message-ID: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> On 28 Jun, 19:39, Michael Torrie wrote: > In python I could simply take the output of "ps ax" and use python's > own, superior, cutting routines (using my module): > > (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) > for x in stdout.split('\n'): > ? ? print x.strip().split()[0] Or you just pass the stdout of one command as stdin to another. That is equivalent of piping with bash. From certifiedlover at hotmail.com Tue Jul 6 06:15:45 2010 From: certifiedlover at hotmail.com (francisco dorset) Date: Tue, 6 Jul 2010 11:15:45 +0100 Subject: No subject Message-ID: hey am a programmer i have good knowledge of the c language and i will like to now how i can use to python to provide graphical user-interface for my c programs and or the steps involved in doing this and is it possible???? if yes i will also like some resources or books to learn from..... any info will be useful thankss!!!! _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.j.warren at gmail.com Tue Jul 6 06:21:21 2010 From: matt.j.warren at gmail.com (AlienBaby) Date: Tue, 6 Jul 2010 03:21:21 -0700 (PDT) Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> Message-ID: I'm still having a bit of trouble, for example trying to set the locale to Denmark locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) returns with locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) File "C:\Python26\lib\locale.py", line 494, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting Though, from the docs I understand normalize should return a local formatted for use with setlocale? From gh at gregor-horvath.com Tue Jul 6 06:27:42 2010 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 6 Jul 2010 12:27:42 +0200 Subject: Python 3 put-downs: What's the point? In-Reply-To: References: <20100705095032.6f7749fe@brasov> Message-ID: <20100706122742.6ae5cf3a@brasov> Am Mon, 05 Jul 2010 14:32:13 -0500 schrieb Tim Chase : > On 07/05/2010 02:50 AM, Gregor Horvath wrote: > > Am Sun, 04 Jul 2010 18:51:54 -0500 > > schrieb Tim Chase: > > > >> I think it's the same venting of frustration that caused veteran > >> VB6 developers to start calling VB.Net "Visual Fred" -- the > >> language was too different and too non-backwards-compatible. > >> > > > > VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison. > > > > VB6 and VB.NET are totally different languages and technologies, > > with some similarity in syntax. This is not true for Python 2->3. > > This is an healthy organic language growth, not an abandon of a > > language. > > The quintessential example is Py3's breaking of Hello World. > It's a spectrum of language changes -- Visual Fred just happens > to be MUCH further down the same spectrum having more dramatic > changes. Only a subset of $OLD_VER (whether Py2 or VB6) code > will run unmodified under $NEW_VER (whether Py3 or VB.Net). It Don't you think that there is a really huge difference in an evolutionary development of a language with some well founded incompatibilities due to some muck outs on one side and and on the other side stopping the development of a language and replacing it with one derived from a completely different one and giving it a related name and syntax? And that such a big difference forbids any comparison, although there are some superficial similarities? -- Greg From andrew at acooke.org Tue Jul 6 06:37:52 2010 From: andrew at acooke.org (andrew cooke) Date: Tue, 6 Jul 2010 03:37:52 -0700 (PDT) Subject: Another Regexp Question References: <24f95573-6ed2-4b92-a1b9-90501fd46a25@d37g2000yqm.googlegroups.com> <68b4e9ba-a8a4-40f8-88b7-8cc30a2e3456@x27g2000yqb.googlegroups.com> Message-ID: http://bugs.python.org/issue9179 On Jul 5, 9:38?pm, MRAB wrote: > andrew cooke wrote: > > On Jul 5, 8:56 pm, MRAB wrote: > >> andrew cooke wrote: > >>> What am I missing this time? :o( > >> Nothing. It's a bug. :-( > > > Sweet :o) > > > Thanks - do you want me to raise an issue or will you? > > You found it. You can have the pleasure. From solipsis at pitrou.net Tue Jul 6 06:38:14 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jul 2010 12:38:14 +0200 Subject: Changing Locale for datetime.strptime conversions References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> Message-ID: <20100706123814.6ac10518@pitrou.net> On Tue, 6 Jul 2010 03:21:21 -0700 (PDT) AlienBaby wrote: > I'm still having a bit of trouble, for example trying to set the > locale to Denmark > > > locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) > > returns with > > locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) > File "C:\Python26\lib\locale.py", line 494, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting > > > Though, from the docs I understand normalize should return a local > formatted for use with setlocale? I think normalize works ok, but setlocale then fails (*). You can only use a locale if it's installed on the computer. That, and other issues (such as the fact that the locale setting is process-wide and can interfere with other parts of your program, or third-party libraries; or the fact that a given locale can have differences depending on the vendor) make the locale mechanism very fragile and annoying. If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ (*): >>> import locale >>> locale.normalize('da_DK') 'da_DK.ISO8859-1' >>> locale.setlocale(locale.LC_ALL, locale.normalize('da_DK')) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/locale.py", line 513, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting From thomas at jollans.com Tue Jul 6 07:31:58 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 13:31:58 +0200 Subject: Python-list Digest, Vol 82, Issue 48 In-Reply-To: References: Message-ID: <4C33142E.8060506@jollans.com> On 07/06/2010 12:03 PM, francisco dorset wrote: > i need resources or books on how to embedding python into c/c++...and > also extending it > > [snip] What is the digest doing at the end of your message then? Anyway: http://docs.python.org/py3k/c-api/index.html http://docs.python.org/py3k/extending/index.html or, if you feel like using the archaic 2.x series of CPython, http://docs.python.org/c-api/index.html http://docs.python.org/extending/index.html Have fun From thomas at jollans.com Tue Jul 6 07:45:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 13:45:15 +0200 Subject: Python GUI for C program [was: ] In-Reply-To: References: Message-ID: <4C33174B.7090902@jollans.com> On 07/06/2010 12:15 PM, francisco dorset wrote: > hey am a programmer i have good knowledge of the c language and i will > like to now how i can use to python to provide graphical user-interface > for my c programs and or the steps involved in doing this and is it > possible???? > > if yes i will also like some resources or books to learn from..... > > any info will be useful thankss!!!! Three ways of doing this: 1. Turn your C program into a library, and write a Python extension module to interface it. 2. Embed Python in your C program. 3. If you're talking command-line programs, you can interface the compiled programs with the subprocess module. For (1) and (2), start with the Extending/Embedding section at http://docs.python.org/py3k/ (or http://docs.python.org/). With (1), using Cython or SWIG might make writing the "glue" between Python and your C code easier. For (3), check the docs of the subprocess module. It might, however, be best to simply write the GUI in C as well, which would avoid the overhead of loading Python and isn't all that difficult either. If you know C++, check out wxWidgets and Qt4. To stick with plain C, have a look at GTK+. Cheers, Thomas From darcy at druid.net Tue Jul 6 08:30:35 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 6 Jul 2010 08:30:35 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <20100706083035.d9ef928b.darcy@druid.net> On Tue, 6 Jul 2010 16:30:34 +0800 David Cournapeau wrote: > One thing that would be very useful is how to maintain something that > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > versions below 2.6 is out of the question for most projects with a Yes, PyGreSQL officially supports 2.3 and up. That means that we can't use "from __future__". We might be able to bump that to 2.4 in the next release but I wouldn't want to jump all the way to 2.6 in one version release. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From icanbob at gmail.com Tue Jul 6 08:56:50 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 6 Jul 2010 05:56:50 -0700 (PDT) Subject: Python GUI for C program [was: ] References: Message-ID: <6a8cbf98-eb2a-4a5d-9588-c3227f8d2728@u26g2000yqu.googlegroups.com> On Jul 6, 7:45 am, Thomas Jollans wrote: > On 07/06/2010 12:15 PM, francisco dorset wrote: > > > hey am a programmer i have good knowledge of the c language and i will > > like to now how i can use to python to provide graphical user-interface > > for my c programs and or the steps involved in doing this and is it > > possible???? > > > if yes i will also like some resources or books to learn from..... > > > any info will be useful thankss!!!! > > Three ways of doing this: > > 1. Turn your C program into a library, and write a Python extension > module to interface it. > > 2. Embed Python in your C program. > > 3. If you're talking command-line programs, you can interface the > compiled programs with the subprocess module. > > For (1) and (2), start with the Extending/Embedding section athttp://docs.python.org/py3k/(orhttp://docs.python.org/). With (1), > using Cython or SWIG might make writing the "glue" between Python and > your C code easier. > > For (3), check the docs of the subprocess module. > > It might, however, be best to simply write the GUI in C as well, which > would avoid the overhead of loading Python and isn't all that difficult > either. If you know C++, check out wxWidgets and Qt4. To stick with > plain C, have a look at GTK+. > > Cheers, > Thomas You might want to also look at the SIMPL toolkit (http:// www.icanprogram.com/06py/lesson1/lesson1.html). You could use Send/ Receive/Reply (QNX style) messaging to add a Python GUI to a C program. There are examples of just this at the link above. bob From Steven.Rumbalski at fiserv.com Tue Jul 6 09:17:02 2010 From: Steven.Rumbalski at fiserv.com (Steven) Date: Tue, 6 Jul 2010 06:17:02 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> Message-ID: <4ba793ae-e80e-4de2-afb5-23fdc3a31561@c10g2000yqi.googlegroups.com> On Jul 5, 2:56?am, John Nagle wrote: > ? ? The Twisted team has a list of what they need: > > "http://stackoverflow.com/questions/172306/how-are-you-planning-on-han..." Here's what I got from a quick google review of the below four projects and python 3. > ? ? ?* Zope Interface Here's a blog from a core contributer to Zope, Lennart Regebro claiming Zope Interface now works with Python 3: http://regebro.wordpress.com/2010/04/29/zope-interface-3-6-0-released-with-python-3-support/ I have no idea if this is official Zope, but it does indicate strong progress. > ? ? ?* PyCrypto Couldn't find much. Found this from an email on Pycrypto mailing list: http://lists.dlitz.net/pipermail/pycrypto/2010q2/000244.html """ Hi Tobias > Does Pycrypto work with Python 3.x now? To my knowledge PyCrypto doesn't work yet with Python 3.x. Around 30% of the test cases are still fail. If you want me to check which of the components are pass, please let me know. Cheers, Christoph""" So someone has been looking at Python 3, but doesn't look like much is being done. > ? ? ?* PyOpenSSL Couldn't find anything. > ? ? ?* PyGTK This one shows real progress. There is a bug filed for Python 3 support: https://bugzilla.gnome.org/show_bug.cgi?id=566641 Key comment on that bug: """John Ehresman [developer] 2010-04-17 16:02:43 UTC I just pushed to the py3k branch a couple of fixes to bugs that are independent of the changes for python3 so all tests pass under both python 2.5 and python3.1. It's probably time to think about landing this on the master branch; obviously we want to avoid regressions in python2 support. What needs to be done before this lands on master?""" A couple of comments follow about when to merge Python 3 support. So it looks like they are almost there. Conclusion: 2 of 4 dependencies that Twisted needs to port to Python 3 show strong progress towards completing the port. Steven Rumbalski From torriem at gmail.com Tue Jul 6 09:40:19 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 06 Jul 2010 07:40:19 -0600 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> Message-ID: <4C333243.7040205@gmail.com> On 07/06/2010 04:12 AM, sturlamolden wrote: > On 28 Jun, 19:39, Michael Torrie wrote: > >> In python I could simply take the output of "ps ax" and use python's >> own, superior, cutting routines (using my module): >> >> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >> for x in stdout.split('\n'): >> print x.strip().split()[0] > > Or you just pass the stdout of one command as stdin to another. That > is equivalent of piping with bash. Consider this contrived example: tail -f /var/log/messages | grep openvpn While it's possible to set up pipes and spawn programs in parallel to operate on the pipes, in practice it's simpler to tell subprocess.Popen to use a shell and then just rely on Bash's very nice syntax for setting up the pipeline. Then just read the final output in python. If you set the stdout descriptor to non-blocking, you could read output as it came. From sri_annauni at yahoo.co.in Tue Jul 6 10:00:08 2010 From: sri_annauni at yahoo.co.in (srinivasan srinivas) Date: Tue, 6 Jul 2010 19:30:08 +0530 (IST) Subject: Pdf download using mechanize Message-ID: <812496.50589.qm@web7903.mail.in.yahoo.com> HI, I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? Thanks, Srini From aahz at pythoncraft.com Tue Jul 6 10:15:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 07:15:54 -0700 Subject: Confusion over etree.ElementTree.Element.getiterator References: <447fa6b8-7302-4772-a5c7-20d06004ddfb@d8g2000yqf.googlegroups.com> <0baa78e2-df75-4249-bd41-0a9c2cce41d5@z8g2000yqz.googlegroups.com> Message-ID: In article , Terry Reedy wrote: >On 7/5/2010 6:40 AM, Ben Sizer wrote: > >>> Admittedly, it's three clicks away from the library docs on docs.python.org. >>> >>> http://effbot.org/zone/element.htm#xml-namespaces >> >> Hopefully someone will see fit to roll this important documentation >> into docs.python.org before the next release... oops, too late. ;) > >Not too late for next release. Open a doc issue with as specific a >suggestion as possible. Actually, it's not too late for this release, either (or at least it used not to be): the docs on the website can be updated even if the downloadable package itself can't be. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From ed at leafe.com Tue Jul 6 10:32:01 2010 From: ed at leafe.com (Ed Leafe) Date: Tue, 6 Jul 2010 10:32:01 -0400 Subject: python app development In-Reply-To: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: <92216C2C-6EFD-4BA6-873A-F280ADF5990C@leafe.com> On Jul 3, 2010, at 1:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). You should definitely check out Dabo. Several years ago we were looking for something in Python for developing desktop apps, and while there were several useful tools, there wasn't anything that integrated them together. That was our motivation for creating Dabo. We have a few screencasts to help you get acquainted with Dabo; I'd recommend these two to start: http://cdn.cloudfiles.mosso.com/c129431/dataenvironment1.html http://cdn.cloudfiles.mosso.com/c129432/dataenvironment1.html We also have a pretty comprehensive tutorial document, available at: http://dabodev.com/pycon_tutorial If you have any other questions, join our email discussion list and post them there. There are many helpful people there to answer your questions. http://leafe.com/mailman/listinfo/dabo-users -- Ed Leafe From alan.isaac at gmail.com Tue Jul 6 11:18:00 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 06 Jul 2010 11:18:00 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> Message-ID: <4C334928.4020105@gmail.com> On 7/6/2010 8:05 AM, Ritchy lelis wrote: > 1 - "import numpy as np > import matplotlib.pyplot as plt" > > In what help's me making the call's of the libraries that way? http://bytebaker.com/2008/07/30/python-namespaces/ > 2 - What's the instruction linspace means/does? >>> help(np.linspace) Help on function linspace in module numpy.core.function_base: linspace(start, stop, num=50, endpoint=True, retstep=False) Return evenly spaced numbers over a specified interval. Returns `num` evenly spaced samples, calculated over the interval [`start`, `stop` ]. > 3 - Last but more important: "V0 = ... #create an array" if I > understood, there i'm supposed to introduce the for loop as in my > initial example. correct? It is better to create your arrays without looping, if possible. But create it however you wish. (Note than numpy arrays have a fixed length; create a Python list if you wish to append to it.) Cheers, Alan Isaac From g.rodola at gmail.com Tue Jul 6 11:19:19 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Tue, 6 Jul 2010 17:19:19 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: 2010/7/6 David Cournapeau : >> Or is there no change at the C level? ?That would make things easy. > > There are quite a few, but outside of the big pain point of > strings/byte/unicode which is present at python level as well, a lot > of the issues are not so big (and even simpler to deal with). For > example, although numpy took time to port (and is still experimental > in nature), it took me a couple of hours to get a basic scipy working > (numpy uses a lot of C api dark corners, whereas scipy is much more > straightforward in its usage of the C API). > > David > -- > http://mail.python.org/mailman/listinfo/python-list As for this aspect, I made a port as such (C extension) for psutil, and it hasn't been too difficult, I must admit. For those interested here is a detailed explanation of all the steps I faced, along with revision changes: http://code.google.com/p/psutil/issues/detail?id=75&can=1&q=python%203&colspec=ID%20Summary%20Type%20Opsys%20Status%20Milestone%20Opened%20Owner%20Progress#c9 --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From sturlamolden at yahoo.no Tue Jul 6 11:50:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 08:50:11 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP Message-ID: Just a little reminder: Microsoft has withdrawn VS2008 in favor of VS2010. The express version is also unavailable for download. >:(( We can still get a VC++ 2008 compiler required to build extensions for the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK for .NET 3.5 SP1): http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en Download today, before it goes away! Microsoft has now published a download for Windows 7 SDK for .NET 4. It has the VC++ 2010 compiler. It can be a matter of days before the VC ++ 2008 compiler is totally unavailable. It is possible to build C and Fortran extensions for official Python 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is required for C++ or amd64 though. (Intel's compiler requires VS2008, which has now perished.) Remember Python on Windows will still require VS2008 for a long time. Just take a look at the recent Python 3 loath threads. From python at bdurham.com Tue Jul 6 11:54:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 06 Jul 2010 11:54:46 -0400 Subject: Changing Locale for datetime.strptime conversions In-Reply-To: <20100706123814.6ac10518@pitrou.net> References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com><5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> <20100706123814.6ac10518@pitrou.net> Message-ID: <1278431686.10469.1383542271@webmail.messagingengine.com> Antoine, > If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ Not the OP, but has Babel implemented parsing support? Last time I looked, Babel did a great job with locale specific formatting, but locale specific formatting was still incomplete. Malcolm From aaron.watters at gmail.com Tue Jul 6 11:59:24 2010 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 6 Jul 2010 08:59:24 -0700 (PDT) Subject: Pdf download using mechanize References: Message-ID: <58f1ee32-993c-4e8a-92f5-31a01fe152ed@y11g2000yqm.googlegroups.com> On Jul 6, 10:00?am, srinivasan srinivas wrote: > HI, > I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. > Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? > > Thanks, > Srini Mechanize seems to have a mailing list ;c) https://lists.sourceforge.net/lists/listinfo/wwwsearch-general Also, it would be helpful to know what specific problems you are having. Have you tried following the excellent documentation? http://wwwsearch.sourceforge.net/mechanize/doc.html It looks like downloading any sort of file and saving it should be straightforward to me, but I haven't tried it. Aaron Watters http://whiffdoc.appspot.com === % man less less is more. From alf.p.steinbach+usenet at gmail.com Tue Jul 6 12:00:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 06 Jul 2010 18:00:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: * sturlamolden, on 06.07.2010 17:50: > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download.>:(( > > We can still get a VC++ 2008 compiler required to build extensions for > the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days before the VC > ++ 2008 compiler is totally unavailable. > > It is possible to build C and Fortran extensions for official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > required for C++ or amd64 though. (Intel's compiler requires VS2008, > which has now perished.) > > Remember Python on Windows will still require VS2008 for a long time. > Just take a look at the recent Python 3 loath threads. Perhaps this all for the good. There is no *technical* problem creating a compiler-independent C/C++ language binding. I believe that Java's JNI works fine no matter what compiler you use, although it's many many years since I've done JNI things. Similarly, Python should IMHO just have a well defined compiler independent native code interface, e.g. "PNI", or "pynacoin", the PYthon NAtive COde INterface :-) Cheers, - Alf -- blog at From solipsis at pitrou.net Tue Jul 6 12:03:22 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 6 Jul 2010 18:03:22 +0200 Subject: Changing Locale for datetime.strptime conversions In-Reply-To: <1278431686.10469.1383542271@webmail.messagingengine.com> References: <66c8b5f4-c7ed-4735-bb14-31a21cbc3894@i28g2000yqa.googlegroups.com> <5d2a8619-f01b-4560-9886-2f7aa0636af4@d8g2000yqf.googlegroups.com> <20100706123814.6ac10518@pitrou.net> <1278431686.10469.1383542271@webmail.messagingengine.com> Message-ID: <20100706180322.6fee23e3@pitrou.net> On Tue, 06 Jul 2010 11:54:46 -0400 python at bdurham.com wrote: > Antoine, > > > If you want to do this seriously, I suggest you instead take a look at third-party libraries such as Babel: http://babel.edgewall.org/ > > Not the OP, but has Babel implemented parsing support? Last time I > looked, Babel did a great job with locale specific formatting, but > locale specific formatting was still incomplete. No idea, but if you just want to recognize month names, you can produce all the month names in the desired natural language and then recognize them yourself (using e.g. a regexp). Probably imperfect, but probably sufficient in many cases too. From ceccarelli.aldo at gmail.com Tue Jul 6 12:06:01 2010 From: ceccarelli.aldo at gmail.com (Aldo Ceccarelli) Date: Tue, 6 Jul 2010 09:06:01 -0700 (PDT) Subject: Pdf download using mechanize References: Message-ID: On 6 Lug, 16:00, srinivasan srinivas wrote: > HI, > I am using mechanize module for web scraping projects. One of y tasks is to download pdf file from a page and store it. > Is there a way to download pdf file using mechanize how we do it in Perl's WWW::Mechanize? > > Thanks, > Srini Hi, Srini: unfortunately I have no direct experience of downloading PDF with mechanize but I'd like to share this IBM article which gives some mechanize snippet and hint (in case of any help to your research) http://www.ibm.com/developerworks/linux/library/l-python-mechanize-beautiful-soup/index.html kind regards, Aldo From ritchy_gato at hotmail.com Tue Jul 6 12:11:32 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 6 Jul 2010 09:11:32 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> Message-ID: <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> On 6 jul, 16:18, Alan G Isaac wrote: > On 7/6/2010 8:05 AM, Ritchy lelis wrote: > > > ?1 - "import numpy as np > > ? ? ? import matplotlib.pyplot as plt" > > > ? ? ? In what help's me making the call's of the libraries that way? > > http://bytebaker.com/2008/07/30/python-namespaces/ > > > ?2 - What's the instruction linspace means/does? > > ?>>> help(np.linspace) > ? ? ? ? ?Help on function linspace in module numpy.core.function_base: > > ? ? ? ? ?linspace(start, stop, num=50, endpoint=True, retstep=False) > ? ? ? ? ? ? ?Return evenly spaced numbers over a specified interval. > > ? ? ? ? ? ? ?Returns `num` evenly spaced samples, calculated over the > ? ? ? ? ? ? ?interval [`start`, `stop` ]. > > > ?3 - Last but more important: "V0 = ... #create an array" if I > > ?understood, there i'm supposed to introduce the for loop as in my > > ?initial example. correct? > > It is better to create your arrays without looping, > if possible. ?But create it however you wish. > (Note than numpy arrays have a fixed length; > create a Python list if you wish to append to it.) > > Cheers, > Alan Isaac ------------------------------------------------- My intention with de for loop was to iterate each point of the arrays Vi and Vref at the math calculations. The V0 it's the result of the math expressions between the Vi and Vref. I can't just create one V0 by a function set by parametters (i don't see how). Could you give a clue? Cheers Ritchy From vlastimil.brom at gmail.com Tue Jul 6 12:16:32 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 6 Jul 2010 18:16:32 +0200 Subject: markmin 0.1 In-Reply-To: References: <4F0DB70E-0116-4335-AA40-691DD57D622A@cs.depaul.edu> Message-ID: 2010/7/6 Chris Rebert : > On Mon, Jul 5, 2010 at 4:56 PM, Massimo Di Pierro > wrote: >> Markmin is a wiki markup language >> implemented in less than 100 lines of code (one file, no dependencies) >> easy to read >> secure >> ... > > Okay, but where can it be downloaded from? You didn't include a link. > > Cheers, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list > It looks like http://www.web2py.com/examples/static/markmin.html vbr From thomas at jollans.com Tue Jul 6 12:21:32 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 18:21:32 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33580C.9030609@jollans.com> On 07/06/2010 05:50 PM, sturlamolden wrote: > It is possible to build C and Fortran extensions for official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > required for C++ or amd64 though. (Intel's compiler requires VS2008, > which has now perished.) mingw gcc should work for building C++ extensions if it also works for C extensions. There's no difference on the binding side - you simply have to include everything as extern "C", which I am sure the header does for you. As for amd64 - I do not know if there is a mingw64 release for windows already. If there isn't, there should be ;-) But that doesn't really change anything: the express edition of Microsoft's VC++ doesn't include an amd64 compiler anyway, AFAIK. Also, VS2010 should work as well - doesn't it? > > Remember Python on Windows will still require VS2008 for a long time. > Just take a look at the recent Python 3 loath threads. > From alan.isaac at gmail.com Tue Jul 6 12:29:48 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Tue, 06 Jul 2010 12:29:48 -0400 Subject: Plot problem.. ?? No sign at all In-Reply-To: <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> Message-ID: On 7/6/2010 12:11 PM, Ritchy lelis wrote: > My intention with de for loop was to iterate each point of the arrays > Vi and Vref at the math calculations. The V0 it's the result of the > math expressions between the Vi and Vref. I can't just create one V0 > by a function set by parametters (i don't see how). Unfortunately I cannot make sense of the code you posted. Provide a detailed description in words (or psuedocode) of what you are trying to accomplish. Be very careful and detailed is you want a useful response. Alan Isaac From sturlamolden at yahoo.no Tue Jul 6 12:39:52 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 09:39:52 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <84b7f040-b4b6-478c-b8d9-2737fabcaf91@a30g2000yqn.googlegroups.com> On 6 Jul, 18:00, "Alf P. Steinbach /Usenet" wrote: > There is no *technical* problem creating a compiler-independent C/C++ language > binding. I believe that Java's JNI works fine no matter what compiler you use, > although it's many many years since I've done JNI things. Similarly, Python > should IMHO just have a well defined compiler independent native code interface, > e.g. "PNI", or "pynacoin", the PYthon NAtive COde INterface :-) Yes but Python currently does not, due to dependency on VS2003 (2.5) or VS2008 (2.6, 2.7, 3.1) C and C++ runtime DLLs. It's not the binary interface that is the trouble, but CRT versioning. C++ is extra troublesome due to name mangling, standard runtime and exceptions. Here are the issues: C++: VS2010 - does not link with msvcp90.dll but msvcp100.dll. mingw - linkes statically with its own C++ library. Win32, ANSI C: VS2010 - does not link with msvcr90.dll but msvcr100.dll. mingw - ok for C if passed -lmsvcr90 on linking step Win64, ANSI C: VS2010 - does not link with msvcr90.dll but msvcr100.dll. mingw - missing import libraries (libmsvcr90.a and libpython26.a) Visual Studio 2008's C/C++ compiler is the only sane solution. It is still there so go get it if you don't already have a copy (I guess Alf does). From sturlamolden at yahoo.no Tue Jul 6 12:49:15 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 09:49:15 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 18:21, Thomas Jollans wrote: > mingw gcc should work for building C++ extensions if it also works for C > extensions. No, it uses an incompatible statically linked C++ runtime. We need to use msvcp90.dll with Python 2.6/2.7. > As for amd64 - I do not know if there is a mingw64 release for windows > already. If there isn't, there should be ;-) There is. But it does not have an import library for msvcr90.dll. It's omitted from mingw-w64. Also libpython26.a is missing from Python on Windows 64. > Also, VS2010 should work as well - doesn't it? The problem with Microsoft's compilers is that they just let you pick between two CRTs (single- or multi-threaded). We need to specify the version number as well. So no, VS2010 will not work. (At least not without some ugly hacks.) From lists at cheimes.de Tue Jul 6 12:58:31 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 18:58:31 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33580C.9030609@jollans.com> References: <4C33580C.9030609@jollans.com> Message-ID: Am 06.07.2010 18:21, schrieb Thomas Jollans: > mingw gcc should work for building C++ extensions if it also works for C > extensions. There's no difference on the binding side - you simply have > to include everything as extern "C", which I am sure the header does for > you. You need unofficial version of MinGW with gcc 4.x for several C++ extension like PyLucene's JCC. Some project like pywin32 don't work with MinGW, too. > Also, VS2010 should work as well - doesn't it? It may work, it may segfault. The official Python binaries are build with VS 2008. Although you are able to build and use extensions build with other versions of VS it can lead to segfaults. So far every version of VS has introduced its own C runtime library (MSVCRT). If you try to close a FILE* from one MSVCRT with fclose() from another MSVCRT your program SEGFAULT. malloc() and free() suffer from the same problem. From zac256 at gmail.com Tue Jul 6 13:06:18 2010 From: zac256 at gmail.com (Zac Burns) Date: Tue, 6 Jul 2010 10:06:18 -0700 Subject: Lockless algorithms in python (Nothing to do with GIL) In-Reply-To: <20100702222603.26c5e4af@pitrou.net> References: <20100702222603.26c5e4af@pitrou.net> Message-ID: I'm not an expert on this, but wouldn't it be more dependent on the platform than python version? Perhaps it is Windows 7 that is very slow. Perhaps my processor architecture. Not sure... Here are some for 3.1.2x64 >>> import timeit >>> timeit.timeit('Lock()', 'from threading import Lock') 1.4162585386092708 >>> timeit.timeit('dict()', 'from threading import Lock') 0.2730348901369162 >>> timeit.timeit('list()', 'from threading import Lock') 0.1719480219512306 -Zac On Fri, Jul 2, 2010 at 1:26 PM, Antoine Pitrou wrote: > On Mon, 28 Jun 2010 16:46:41 -0700 > Zac Burns wrote: > > In my experience it is far more expensive to allocate a lock in python > then > > it is the types that use them. Here are some examples: > > > > >>> timeit.timeit('Lock()', 'from threading import Lock') > > 1.4449114807669048 > > > > >>> timeit.timeit('dict()') > > 0.2821554294221187 > > > > >>> timeit.timeit('list()') > > 0.17358153222312467 > > I'm not sure what Python version on what machine you are using, but > here (Python 2.7): > > >>> timeit.timeit('Lock()', 'from threading import Lock') > 0.09944796562194824 > >>> timeit.timeit('dict()') > 0.17817902565002441 > >>> timeit.timeit('list()') > 0.19633007049560547 > >>> timeit.timeit('{}') > 0.03823709487915039 > >>> timeit.timeit('[]') > 0.05156302452087402 > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Tue Jul 6 13:09:21 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:09:21 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> Message-ID: <4C336341.4070800@jollans.com> On 07/06/2010 06:58 PM, Christian Heimes wrote: > Am 06.07.2010 18:21, schrieb Thomas Jollans: >> mingw gcc should work for building C++ extensions if it also works for C >> extensions. There's no difference on the binding side - you simply have >> to include everything as extern "C", which I am sure the header does for >> you. > > You need unofficial version of MinGW with gcc 4.x for several C++ > extension like PyLucene's JCC. Some project like pywin32 don't work with > MinGW, too. aha - why is that? But - if you write code that builds with [whatever gcc version you have], the compiler Python is built with shouldn't matter, should it? > >> Also, VS2010 should work as well - doesn't it? > > It may work, it may segfault. > > The official Python binaries are build with VS 2008. Although you are > able to build and use extensions build with other versions of VS it can > lead to segfaults. So far every version of VS has introduced its own C > runtime library (MSVCRT). If you try to close a FILE* from one MSVCRT > with fclose() from another MSVCRT your program SEGFAULT. malloc() and > free() suffer from the same problem. Okay, you need to be careful with FILE*s. But malloc and free? You'd normally only alloc & free something within the same module, using the same functions (ie not mixing PyMem_Malloc and malloc), would you not? You have to code quite defensively, true. But, IF you keep all non-Python data structures local to your module, you should be fine? Coming from a system where I can generally rely on the system gcc to work for everything, I may be a bit na?ve wrt certain questions ;-) Cheers, Thomas PS: Windows CPython programming scares me. From javier.collado at gmail.com Tue Jul 6 13:10:17 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 6 Jul 2010 19:10:17 +0200 Subject: re.sub unexpected behaviour Message-ID: Hello, Let's imagine that we have a simple function that generates a replacement for a regular expression: def process(match): return match.string If we use that simple function with re.sub using a simple pattern and a string we get the expected output: re.sub('123', process, '123') '123' However, if the string passed to re.sub contains a trailing new line character, then we get an extra new line character unexpectedly: re.sub(r'123', process, '123\n') '123\n\n' If we try to get the same result using a replacement string, instead of a function, the strange behaviour cannot be reproduced: re.sub(r'123', '123', '123') '123' re.sub('123', '123', '123\n') '123\n' Is there any explanation for this? If I'm skipping something when using a replacement function with re.sub, please let me know. Best regards, Javier From thomas at jollans.com Tue Jul 6 13:11:06 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:11:06 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C3363AA.5080801@jollans.com> On 07/06/2010 06:49 PM, sturlamolden wrote: > On 6 Jul, 18:21, Thomas Jollans wrote: > >> mingw gcc should work for building C++ extensions if it also works for C >> extensions. > > No, it uses an incompatible statically linked C++ runtime. We need to > use msvcp90.dll with Python 2.6/2.7. Python is written in C. How does the C++ runtime enter into it? > >> As for amd64 - I do not know if there is a mingw64 release for windows >> already. If there isn't, there should be ;-) > > There is. But it does not have an import library for msvcr90.dll. It's > omitted from mingw-w64. Also libpython26.a is missing from Python on > Windows 64. > > >> Also, VS2010 should work as well - doesn't it? > > The problem with Microsoft's compilers is that they just let you pick > between two CRTs (single- or multi-threaded). We need to specify the > version number as well. > > So no, VS2010 will not work. (At least not without some ugly hacks.) From anthra.norell at bluewin.ch Tue Jul 6 13:15:05 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Tue, 06 Jul 2010 19:15:05 +0200 Subject: What is the name of the name space I am in? In-Reply-To: <89f9edFuavU1@mid.individual.net> References: <4C31A0DE.7010907@bluewin.ch> <4C31A589.3070008@jollans.com> <89f9edFuavU1@mid.individual.net> Message-ID: <4C336499.8020806@bluewin.ch> Gregory Ewing wrote: >>> On 07/05/2010 11:07 AM, Anthra Norell wrote: >>> >>>> I try to use "new.new.classobj (name, baseclass, dict)" and have no >>>> clue >>>> what the "dict" of the current name space is. > > Are you sure that's what you really want to know? The > 'dict' argument to classobj() defines the attributes > that you want the new class to have. It's not meant > to be the namespace in which the code creating the > class is executing. > No indeed I'm not sure. The doc explains the argument "dict" as "name space", a term I associated with the enclosing module's name space, because it is also visible from inside enclosed blocks. But how right you are! Passing locals () works fine inasmuch as the constructor doesn't complain. Looking subsequently at the class attributes with dir (c) or c.__dict__keys (), however, dumps the entire inventory of the module in addition to the attributes of the base class. Clearly, that can't be right. So, thanks to you! I very much appreciate the guidance along the right path. Frederic From tjreedy at udel.edu Tue Jul 6 13:17:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Jul 2010 13:17:02 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On 7/6/2010 11:19 AM, Giampaolo Rodol? wrote: > 2010/7/6 David Cournapeau: >>> Or is there no change at the C level? That would make things easy. >> >> There are quite a few, but outside of the big pain point of >> strings/byte/unicode which is present at python level as well, a lot >> of the issues are not so big (and even simpler to deal with). For >> example, although numpy took time to port (and is still experimental >> in nature), it took me a couple of hours to get a basic scipy working >> (numpy uses a lot of C api dark corners, whereas scipy is much more >> straightforward in its usage of the C API). > > As for this aspect, I made a port as such (C extension) for psutil, > and it hasn't been too difficult, I must admit. > > For those interested here is a detailed explanation of all the steps I > faced, along with revision changes: > http://code.google.com/p/psutil/issues/detail?id=75&can=1&q=python%203&colspec=ID%20Summary%20Type%20Opsys%20Status%20Milestone%20Opened%20Owner%20Progress#c9 That post refers to docs.python.org / dev/3.0/howto/cporting.html [without added space] but that is currently 404 missing. -- Terry Jan Reedy From ritchy_gato at hotmail.com Tue Jul 6 13:18:17 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 6 Jul 2010 10:18:17 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> Message-ID: <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> On 6 jul, 17:29, Alan G Isaac wrote: > On 7/6/2010 12:11 PM, Ritchy lelis wrote: > > > My intention with de for loop was to iterate each point of the arrays > > Vi and Vref at the math calculations. The V0 it's the result of the > > math expressions between the Vi and Vref. I can't just create one V0 > > by a function set by parametters (i don't see how). > > Unfortunately I cannot make sense of the code you posted. > Provide a detailed description in words (or psuedocode) > of what you are trying to accomplish. ?Be very careful > and detailed is you want a useful response. > > Alan Isaac hummm... ok, i will try to make that detailed description. Maybe i have not been so clear because my inglish suck's :D However i have a tutorial and another document that my teacher gave me, i could send you it if you allowed me. It's the 2 best document's i've seen about ADC. Ritchy From vinay_sajip at yahoo.co.uk Tue Jul 6 13:22:04 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Jul 2010 17:22:04 +0000 (UTC) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: norbert gmail.com> writes: > > crash with a UnicodeError. I can't see any workaround, except by > subclassing SMTPHandler's emit method to be unicode-aware or at least > URF-8 aware. > Well, you could use an approach like the one suggested here: http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal-with.html From steve at REMOVE-THIS-cybersource.com.au Tue Jul 6 13:32:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jul 2010 17:32:07 GMT Subject: re.sub unexpected behaviour References: Message-ID: <4c336897$0$28647$c3e8da3@news.astraweb.com> On Tue, 06 Jul 2010 19:10:17 +0200, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern and a > string we get the expected output: > re.sub('123', process, '123') > '123' > > However, if the string passed to re.sub contains a trailing new line > character, then we get an extra new line character unexpectedly: > re.sub(r'123', process, '123\n') > '123\n\n' I don't know why you say it is unexpected. The regex "123" matched the first three characters of "123\n". Those three characters are replaced by a copy of the string you are searching "123\n", which gives "123\n\n" exactly as expected. Perhaps these examples might help: >>> re.sub('W', process, 'Hello World') 'Hello Hello Worldorld' >>> re.sub('o', process, 'Hello World') 'HellHello World WHello Worldrld' Here's a simplified pure-Python equivalent of what you are doing: def replace_with_match_string(target, s): n = s.find(target) if n != -1: s = s[:n] + s + s[n+len(target):] return s > If we try to get the same result using a replacement string, instead of > a function, the strange behaviour cannot be reproduced: re.sub(r'123', > '123', '123') > '123' > > re.sub('123', '123', '123\n') > '123\n' The regex "123" matches the first three characters of "123\n", which is then replaced by "123", giving "123\n", exactly as expected. >>> re.sub("o", "123", "Hello World") 'Hell123 W123rld' -- Steven From thomas at jollans.com Tue Jul 6 13:32:29 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:32:29 +0200 Subject: re.sub unexpected behaviour In-Reply-To: References: Message-ID: <4C3368AD.4060902@jollans.com> On 07/06/2010 07:10 PM, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern and > a string we get the expected output: > re.sub('123', process, '123') > '123' > > However, if the string passed to re.sub contains a trailing new line > character, then we get an extra new line character unexpectedly: > re.sub(r'123', process, '123\n') > '123\n\n' process returns match.string, which is, according to the docs: """The string passed to match() or search()""" You passed "123\n" to sub(), which may not be explicitly listed here, but there's no difference. Process correctly returns "123\n", which is inserted. Let me demonstrate again with a longer string: >>> import re >>> def process(match): ... return match.string ... >>> re.sub(r'\d+', process, "start,123,end") 'start,start,123,end,end' >>> > > If we try to get the same result using a replacement string, instead > of a function, the strange behaviour cannot be reproduced: > re.sub(r'123', '123', '123') > '123' > > re.sub('123', '123', '123\n') > '123\n' Again, the behaviour is correct: you're not asking for "whatever was passed to sub()", but for '123', and that's what you're getting. > > Is there any explanation for this? If I'm skipping something when > using a replacement function with re.sub, please let me know. What you want is grouping: >>> def process(match): ... return "<<" + match.group(1) + ">>" ... >>> re.sub(r'(\d+)', process, "start,123,end") 'start,<<123>>,end' >>> or better, without a function: >>> re.sub(r'(\d+)', r'<<\1>>', "start,123,end") 'start,<<123>>,end' >>> Cheers, Thomas From thomas at jollans.com Tue Jul 6 13:34:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 19:34:26 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <4C336922.6080300@jollans.com> On 07/06/2010 07:17 PM, Terry Reedy wrote: > docs.python.org / dev/3.0/howto/cporting.html http://docs.python.org/py3k/howto/cporting.html From sturlamolden at yahoo.no Tue Jul 6 13:35:50 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 10:35:50 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> Message-ID: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> On 6 Jul, 19:09, Thomas Jollans wrote: > Okay, you need to be careful with FILE*s. But malloc and free? You'd > normally only alloc & free something within the same module, using the > same functions (ie not mixing PyMem_Malloc and malloc), would you not? You have to be sure PyMem_Malloc is not an preprocessor alias for malloc (I haven't chaecked). In general, CRT objects cannot be shared across CRT boundaries. Also remember the C and C++ standard libraries interact. g++ from links statically with an incompatible C++ standard library (read: it will segfault, it's just a question of when). > Coming from a system where I can generally rely on the system gcc to > work for everything, I may be a bit na?ve wrt certain questions ;-) On sane operating systems you generally have one version of libc installed. Windows did this too (msvcrt.dll) up to the VS2003 release, which came with msvcr71.dll in addition. Since then, M$ (pronounced Megadollar Corp.) have published msvcr80.dll, msvcr90.dll, and msvcr100.dll (and corresponding C++ versions) to annoy C and C++ developers into converting to C# .NET. (And yes, programs using third-party DLL and OCX components become unstable from this. You have to check each DLL/ OCX you use, and each DLL used by each DLL, etc. How fun...) From sturlamolden at yahoo.no Tue Jul 6 13:43:51 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 10:43:51 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <77985134-cd90-4b18-b6d9-ae4dc7e84680@z10g2000yqb.googlegroups.com> On 6 Jul, 19:11, Thomas Jollans wrote: > Python is written in C. How does the C++ runtime enter into it? The C and C++ runtimes interact (e.g. stdlib.h and ), malloc and new, etc. With g++ you have a C++ standard library compiled against msvcrt.dll, whereas Python is using msvcr90.dll. We can use the C++ runtime msvcp90.dll used by VC++ 2008, but this DLL is binary incompatible with g++ (GNU uses a different ABI for C++). From martin.hellwig at dcuktec.org Tue Jul 6 13:46:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 06 Jul 2010 18:46:34 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On 07/06/10 16:50, sturlamolden wrote: > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download.>:(( Public download that is, people like me who have a MSDN subscription can still download old versions like Visual Studio 2005. So I would say that there is no particular hurry. I would think that everyone really serious about MS development with MS tools should get an MSDN subscription anyway, it saves you a lot of money in the long run. -- mph From lists at cheimes.de Tue Jul 6 13:49:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 19:49:32 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C336341.4070800@jollans.com> References: <4C33580C.9030609@jollans.com> <4C336341.4070800@jollans.com> Message-ID: >> You need unofficial version of MinGW with gcc 4.x for several C++ >> extension like PyLucene's JCC. Some project like pywin32 don't work with >> MinGW, too. > > aha - why is that? > > But - if you write code that builds with [whatever gcc version you > have], the compiler Python is built with shouldn't matter, should it? Unless I'm mistaken, official MinGW32 packages still have GCC 3.x. Some projects like JCC need recent C++ compilers. MinGW doesn't provide some features that pywin32 requires. The compiler must create ABI compatible object files and the linker needs to support the latest CRT. Three years ago it took several months until MinGW supported the 9.0 CRT. > Okay, you need to be careful with FILE*s. But malloc and free? You'd > normally only alloc & free something within the same module, using the > same functions (ie not mixing PyMem_Malloc and malloc), would you not? > > You have to code quite defensively, true. But, IF you keep all > non-Python data structures local to your module, you should be fine? You must be carefully with functions like PyFile_FromFile(), too. If you expose the FILE* from the alien CRT to Python somehow you can get into trouble. Lukely PyFile_FromFile() works around most issues but it's still problematic. These kind of SEGFAULTs are hard to debug, too. > Coming from a system where I can generally rely on the system gcc to > work for everything, I may be a bit na?ve wrt certain questions ;-) > > PS: Windows CPython programming scares me. Yeah, it's a pain. From e_d_k at yahoo.com Tue Jul 6 13:52:59 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Tue, 6 Jul 2010 10:52:59 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: Message-ID: <91295.91066.qm@web120510.mail.ne1.yahoo.com> I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! This seems odd to me, has anyone else had this problem? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Tue, 7/6/10, sturlamolden wrote: > From: sturlamolden > Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP > To: python-list at python.org > Date: Tuesday, July 6, 2010, 11:50 AM > > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The > express version > is also unavailable for download. >:(( > > We can still get a VC++ 2008 compiler required to build > extensions for > the official Python 2.6 and 2.7 binary installers here > (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK > for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days > before the VC > ++ 2008 compiler is totally unavailable. > > It is possible to build C and Fortran extensions for > official Python > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's > compiler is > required for C++ or amd64 though. (Intel's compiler > requires VS2008, > which has now perished.) > > Remember Python on Windows will still require VS2008 for a > long time. > Just take a look at the recent Python 3 loath threads. > > -- > http://mail.python.org/mailman/listinfo/python-list > From javier.collado at gmail.com Tue Jul 6 13:58:58 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 6 Jul 2010 19:58:58 +0200 Subject: re.sub unexpected behaviour In-Reply-To: <4c336897$0$28647$c3e8da3@news.astraweb.com> References: <4c336897$0$28647$c3e8da3@news.astraweb.com> Message-ID: Thanks for your answers. They helped me to realize that I was mistakenly using match.string (the whole string) when I should be using math.group(0) (the whole match). Best regards, Javier From rantingrick at gmail.com Tue Jul 6 14:10:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 11:10:38 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On Jul 6, 12:37?am, Terry Reedy wrote: > In his post on this thread, Martin Loewis volunteered to list what he > knows from psycopg2 if someone else will edit. Now we are getting somewhere! This is the community spirit i want to see. You don't have to give much people, every little bit counts. But for Google's sake we need to work together to get this thing done. Let's get a list together of 3rd party modules that are "must haves" and start knocking on doors, evangelizing, air dropping leaflets, spreading the word, whatever it takes! The revolution is not going to happen whilst we sleep -- not the Python revolution that is! Get the lead out c.l.p! From aahz at pythoncraft.com Tue Jul 6 14:12:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 11:12:11 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Message-ID: In article <8f5014f6-9aa8-44e2-afe1-a1175bcdd591 at w31g2000yqb.googlegroups.com>, moerchendiser2k3 wrote: > >I have a serious problem I haven't solved yet, hope one of you can >help me. The first thing is, I embedded Python into my app and I >execute several scripts in this environment. > >The problem is, the scripts don't import modules from their relative >path. I guess this is related to the sys.path ['',...] and the current >working directory which is set to the directory of my host >application. > >I could set that path manually, but all the scripts might be stored in >different locations. So now I try to find a way to handle that. Any >suggestions? Set sys.path to include each script's base dir before running it, then restore after each script. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From sturlamolden at yahoo.no Tue Jul 6 14:14:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 11:14:21 -0700 (PDT) Subject: Python GUI for C program [was: ] References: Message-ID: <6255259b-3c26-4222-b03f-f73403ee1c46@z10g2000yqb.googlegroups.com> On 6 Jul, 13:45, Thomas Jollans wrote: > 1. Turn your C program into a library, and write a Python extension Note that using ctypes, Cython or Boost.Python is much less painful than using Python's C API directly. > It might, however, be best to simply write the GUI in C as well, which > would avoid the overhead of loading Python and isn't all that difficult > either. If you know C++, check out wxWidgets and Qt4. To stick with > plain C, have a look at GTK+. You will hardly notice the overhead of loading Python. (It's not Java...) Also a good GUI builder is far more important than language when it comes to making a GUI. Depending on toolkit my preferences are wxFormBuilder, Qt Designer, GLADE or MS Visual Studio. - wxFormBuilder are beginning to be ok for wxPython development without XRC, finally. - PyQt has licensing issues, although Qt is LGPL. PySide is still incomplete. - GLADE/PyGTK has issues on Windows (e.g. need to supply a GTK+ run- time). - Visual Studio can be used for IronPython .NET and native MFC (pywin32 has MFC bindings). - tkinter generally sucks (tedious to use, looks bad). From sturlamolden at yahoo.no Tue Jul 6 14:15:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 11:15:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <481a9a5b-b5ca-4e6d-a07c-919a90b0408a@d37g2000yqm.googlegroups.com> On 6 Jul, 19:52, Ed Keith wrote: > This seems odd to me, has anyone else had this problem? DVD? From me+list/python at ixokai.io Tue Jul 6 14:19:06 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 11:19:06 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <91295.91066.qm@web120510.mail.ne1.yahoo.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C33739A.2080003@ixokai.io> On 7/6/10 10:52 AM, Ed Keith wrote: > I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! The website says its a DVD iso. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Tue Jul 6 14:23:48 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 11:23:48 -0700 (PDT) Subject: Python GUI for C program [was: ] References: <6255259b-3c26-4222-b03f-f73403ee1c46@z10g2000yqb.googlegroups.com> Message-ID: <3aa7c05b-b54c-4b2e-9933-8c84db972ab2@d16g2000yqb.googlegroups.com> On Jul 6, 1:14?pm, sturlamolden wrote: > Also a good GUI builder is far more important than language when it > comes to making a GUI. Depending on toolkit my preferences are > wxFormBuilder, Qt Designer, GLADE or MS Visual Studio. Thats only true when using any language EXCEPT Python. With Python, Python is all you need. Python GUI builders are for pansies. However when using the redundantly asinine C, C++, and Java... well your already getting bent over, might as well bring some lubrication to ease the pain! From robert.kern at gmail.com Tue Jul 6 14:28:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 06 Jul 2010 14:28:32 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <91295.91066.qm@web120510.mail.ne1.yahoo.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 7/6/10 1:52 PM, Ed Keith wrote: > I downloaded the ISO, but it seems to be just a bit too big to fit on a CD! > > This seems odd to me, has anyone else had this problem? These days, ISOs are destined for DVD-Rs. :-) There are also utilities for mounting ISOs directly without burning them to a physical disk. Here is a decent list: http://www.techsupportalert.com/best-free-cd-emulator.htm -- 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 googler.1.webmaster at spamgourmet.com Tue Jul 6 14:50:21 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 6 Jul 2010 11:50:21 -0700 (PDT) Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> Message-ID: <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> >Set sys.path to include each script's base dir before running it, then >restore after each script. That works, but doesnt solve the problem. ScriptA.py has a module in its directory called 'bar.py' ScriptB.py has a module in its directory called 'bar.py' Imagine the 'bar.py' modules dont have the same content, so they are not equal. Now when the first bar.py is imported, the second import for a "import bar" imports the first one, because its already stored in sys.modules. From gdamjan at gmail.com Tue Jul 6 14:56:37 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 06 Jul 2010 20:56:37 +0200 Subject: A question about the posibility of raise-yield in Python References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <28847956-9af7-4280-acc9-dd7eca8dd1c3@t10g2000yqg.googlegroups.com> Message-ID: <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> >> > I'm writing this as a complete newbie (on the issue), so don't be >> > surprised if it's the stupidest idea ever. >> >> > I was wondering if there was ever a discusision in the python >> > community on a 'raise-yield' kind-of combined expression. I'd like >> > to know if it was proposed/rejected/discussed/not-decided yet?? >> >> Recently (ok, several hours ago) I've come up to Greenlets [1] and it >> seems they implement exactly what I was asking for, in a C >> extension!! >> >> It's too bad that Python doesn't support this by default and many >> libraries won't make use of it by default. Gevent [2] for example, >> has to monkey-patch Python's socket, time.sleep and other modules so >> that things like urllib work with it. >> >> I'll continue to read now. > > Ah, if I had seen your original post I probably could have pointed you > to some good reading right away. What you've described is called a > continuation, and is natively supported by some languages (like > Scheme). It's usually not done with exceptions, though. In Scheme > it's a special form that looks like an ordinary function call, but you > can "return" from the call any number of times. I thought they were called coroutines? Anyway, here's the Lua implementation of coroutines. It's basically a yield but it will return back several frames. http://lua-users.org/wiki/CoroutinesTutorial -- ?????? ((( http://damjan.softver.org.mk/ ))) Today we create the legacy of tomorrow. From aahz at pythoncraft.com Tue Jul 6 15:11:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 12:11:01 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, moerchendiser2k3 wrote: >Aahz: >> >>Set sys.path to include each script's base dir before running it, then >>restore after each script. > >That works, but doesnt solve the problem. > >ScriptA.py has a module in its directory called 'bar.py' >ScriptB.py has a module in its directory called 'bar.py' > >Imagine the 'bar.py' modules dont have the same content, so they are >not equal. > >Now when the first bar.py is imported, the second import for a "import >bar" imports the first one, because its already stored in sys.modules. Good point, you'll need to save/restore sys.modules, too. That gets you 90-95% of complete namespace separation; if you need more than that, your best bet is to use separate processes. Full-blown namepace isolation is a *hard* problem, just look at all the past attempts to create secure Python (and what you're trying to do is roughly equivalent). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From tim at johnsons-web.com Tue Jul 6 15:16:50 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 06 Jul 2010 11:16:50 -0800 Subject: Recommend a MySQLdb Forum Message-ID: Greetings: I would appreciate it if some could recommend a MySQLdb forum. thanks tim From sturlamolden at yahoo.no Tue Jul 6 15:33:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 12:33:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 19:46, "Martin P. Hellwig" wrote: > Public download that is, people like me who have a MSDN subscription can > still download old versions like Visual Studio 2005. That's nice to know, but I personally don't have an MSDN subscription. Many scientists don't have access to development tools like VS2008. Many hobby developers don't have access expensive MSDN subscriptions. Many don't develop C personally, but just "needs a compiler" to build an extension with distutils. And for all of us not subscribing to MSDN, this is the only remaining source. From drobinow at gmail.com Tue Jul 6 15:40:04 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 6 Jul 2010 15:40:04 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On Tue, Jul 6, 2010 at 1:46 PM, Martin P. Hellwig wrote: > Public download that is, people like me who have a MSDN subscription can > still download old versions like Visual Studio 2005. > > So I would say that there is no particular hurry. > I would think that everyone really serious about MS development with MS > tools should get an MSDN subscription anyway, it saves you a lot of money in > the long run. Amazing! From bdesth.quelquechose at free.quelquepart.fr Tue Jul 6 15:46:41 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 06 Jul 2010 21:46:41 +0200 Subject: delegation pattern via descriptor In-Reply-To: <89aamgF7vdU1@mid.individual.net> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> Message-ID: <4c33a3a6$0$23067$426a74cc@news.free.fr> Gregory Ewing a ?crit : > Bruno Desthuilliers wrote: >> kedra marbun a ?crit : >> >>> if we limit our discussion to py: >>> why __{get|set|delete}__ don't receive the 'name' & 'class' from >>> __{getattribute|{set|del}attr}__ >>> 'name' is the name that is searched >> >> >> While it would have been technically possible, I fail to imagine any use >> case for this. > > I think he wants to have generic descriptors that are > shared between multiple attributes, but have them do > different things based on the attribute name. I already understood this, but thanks !-) What I dont understand is what problem it could solve that couldn't be solved more simply using the either _getattr__ hook or hand-coded delegation, since such a descriptor would be so tightly coupled to the host class that it just doesn't make sense writing a descriptor for this. From lists at cheimes.de Tue Jul 6 15:49:50 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 06 Jul 2010 21:49:50 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: > That's nice to know, but I personally don't have an MSDN subscription. > Many scientists don't have access to development tools like VS2008. > Many hobby developers don't have access expensive MSDN subscriptions. > Many don't develop C personally, but just "needs a compiler" to build > an extension with distutils. And for all of us not subscribing to > MSDN, this is the only remaining source. I agree, the situation isn't ideal. I see if I can get in contact with Microsoft's open source team. Perhaps they can keep the download link to VS 2008 EE working. By the way lot's of universities participate in the MSDN Academy Alliance program. Students, scientists and employees of the university can get most MSDN packages. From casevh at gmail.com Tue Jul 6 15:52:17 2010 From: casevh at gmail.com (casevh) Date: Tue, 6 Jul 2010 12:52:17 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On Jul 6, 9:21?am, Thomas Jollans wrote: > On 07/06/2010 05:50 PM, sturlamolden wrote: > > > It is possible to build C and Fortran extensions for official Python > > 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is > > required for C++ or amd64 though. (Intel's compiler requires VS2008, > > which has now perished.) > > mingw gcc should work for building C++ extensions if it also works for C > extensions. There's no difference on the binding side - you simply have > to include everything as extern "C", which I am sure the header does for > you. > > As for amd64 - I do not know if there is a mingw64 release for windows > already. If there isn't, there should be ;-) But that doesn't really > change anything: the express edition of Microsoft's VC++ doesn't include > an amd64 compiler anyway, AFAIK. The original version of the Windows 7 SDK includes the command line version of the VS 2008 amd64 compiler. I've used it compile MPIR and GMPY successfully. The GMPY source includes a text file describing the build process using the SDK tools. casevh > > Also, VS2010 should work as well - doesn't it? > > > > > > > Remember Python on Windows will still require VS2008 for a long time. > > Just take a look at the recent Python 3 loath threads.- Hide quoted text - > > - Show quoted text - From googler.1.webmaster at spamgourmet.com Tue Jul 6 16:02:12 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 6 Jul 2010 13:02:12 -0700 (PDT) Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: <33affa14-ded1-4742-a98f-c478df353352@w31g2000yqb.googlegroups.com> Good idea. Just one thing I thought about: Imagine I load them parallel so the GIL might interrupt the save-process of sys.modules, [ENSURE GIL] Load Script Save sys.modules [interrupt] Load Script Save sys.modules ... so this might run into several other problems. But maybe I change that so I load the scripts in a row. Thanks for your shoulder I can cry on ;) Bye, moerchendiser2k3 From sturlamolden at yahoo.no Tue Jul 6 16:19:57 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 13:19:57 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> On 6 Jul, 21:49, Christian Heimes wrote: > I agree, the situation isn't ideal. I see if I can get in contact with > Microsoft's open source team. Perhaps they can keep the download link to > VS 2008 EE working. It seems the MSDN subscription required to get VS 2008 costs one dollar less than $1200. So it does not fit within everyone's budget. From thudfoo at opensuse.us Tue Jul 6 16:35:40 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Tue, 6 Jul 2010 13:35:40 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C333243.7040205@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: > On 07/06/2010 04:12 AM, sturlamolden wrote: >> On 28 Jun, 19:39, Michael Torrie wrote: >> >>> In python I could simply take the output of "ps ax" and use python's >>> own, superior, cutting routines (using my module): >>> >>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>> for x in stdout.split('\n'): >>> ? ? print x.strip().split()[0] >> >> Or you just pass the stdout of one command as stdin to another. That >> is equivalent of piping with bash. > > Consider this contrived example: > > tail -f /var/log/messages | grep openvpn > > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. ?Then just read the final output in python. ?If you set > the stdout descriptor to non-blocking, you could read output as it came. > -- > http://mail.python.org/mailman/listinfo/python-list > Is this a discussion about the pipes module in the std library? From sturlamolden at yahoo.no Tue Jul 6 16:49:40 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 13:49:40 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: On 6 Jul, 21:52, casevh wrote: > On Jul 6, 9:21?am, Thomas Jollans wrote: > > But that doesn't really > > change anything: the express edition of Microsoft's VC++ doesn't include > > an amd64 compiler anyway, AFAIK. See here: http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/ The express edition can be used as is for x86 though (it might not have an optimizing compiler). It can also be used for C++, unlike g++ (at least VC++ is safer). > The original version of the Windows 7 SDK includes the command line > version of the VS 2008 amd64 compiler. C:\Program Files\Microsoft SDKs\Windows\v7.0>cl Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64 Copyright (C) Microsoft Corporation. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] C:\Program Files\Microsoft SDKs\Windows\v7.0> Need any more proof? :D Also note that the Windows 7 SDK can still be used with IDEs, like Qt Creator, KDEvelop (yes there is a Windows version), Eclipse, Visual Studio, and even Visual C++ Express (a little PITA for amd64, but possible too). I'm still fan of a tiny text editor for typing (Kate from KDE tends to be my favorite) and a Python script for building, though. From love_ram2040 at yahoo.com Tue Jul 6 17:06:54 2010 From: love_ram2040 at yahoo.com (porxy) Date: Tue, 6 Jul 2010 14:06:54 -0700 (PDT) Subject: save your money and open all blocked sites now Message-ID: save your money and open all blocked sites now just enter to this proxy http://prog2010.zxq.net/proxy/ and put your site for free From pthibault33 at yahoo.ca Tue Jul 6 17:17:03 2010 From: pthibault33 at yahoo.ca (Pierre Thibault) Date: Tue, 6 Jul 2010 14:17:03 -0700 (PDT) Subject: Python install has difficulties with accented characters in path Message-ID: I am building from the source and installing Python on my machine. I added these tests failed: test_doctest test_httpservers test_logging But I moved the Python installation folder on another directory and the failed tests vanished when I tried again. The difference? The new directory does not have any accented characters in its name while the other one was having one. Should I flag this has a bug? I am installing Python 2.6.5. I am running OpenSuse 11.2 AMD64. From aahz at pythoncraft.com Tue Jul 6 17:29:20 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 14:29:20 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> <33affa14-ded1-4742-a98f-c478df353352@w31g2000yqb.googlegroups.com> Message-ID: In article <33affa14-ded1-4742-a98f-c478df353352 at w31g2000yqb.googlegroups.com>, moerchendiser2k3 wrote: > >Imagine I load them parallel so the GIL might interrupt the >save-process of sys.modules, > >[ENSURE GIL] >Load Script >Save sys.modules >[interrupt] >Load Script >Save sys.modules >... > >so this might run into several other problems. Very yes; if you're trying to maintain script independence, you should either run them sequentially (so you can safely save/restore the environment) or use processes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From thomas at jollans.com Tue Jul 6 17:34:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:34:40 +0200 Subject: Python Embedding Importing relative modules In-Reply-To: References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: <4C33A170.6060802@jollans.com> On 07/06/2010 09:11 PM, Aahz wrote: > In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, > moerchendiser2k3 wrote: >> Aahz: >>> >>> Set sys.path to include each script's base dir before running it, then >>> restore after each script. >> >> That works, but doesnt solve the problem. >> >> ScriptA.py has a module in its directory called 'bar.py' >> ScriptB.py has a module in its directory called 'bar.py' >> >> Imagine the 'bar.py' modules dont have the same content, so they are >> not equal. >> >> Now when the first bar.py is imported, the second import for a "import >> bar" imports the first one, because its already stored in sys.modules. > > Good point, you'll need to save/restore sys.modules, too. That gets you > 90-95% of complete namespace separation; if you need more than that, your > best bet is to use separate processes. Full-blown namepace isolation is > a *hard* problem, just look at all the past attempts to create secure > Python (and what you're trying to do is roughly equivalent). I believe Python (at least in the 3.x series) supports multiple interpreter instances per process. From thomas at jollans.com Tue Jul 6 17:37:24 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:37:24 +0200 Subject: Python install has difficulties with accented characters in path In-Reply-To: References: Message-ID: <4C33A214.2080208@jollans.com> On 07/06/2010 11:17 PM, Pierre Thibault wrote: > I am building from the source and installing Python on my machine. > > I added these tests failed: > > test_doctest > test_httpservers > test_logging > > But I moved the Python installation folder on another directory and > the failed tests vanished when I tried again. The difference? The new > directory does not have any accented characters in its name while the > other one was having one. > > Should I flag this has a bug? > > I am installing Python 2.6.5. I am running OpenSuse 11.2 AMD64. Before filing a bug, best test it with Python 2.7 (just released), 3.1, and, if possible, py3k trunk. I just tried to reproduce this with a current py3k checkout, where it worked. Probably not an issue in Python 3.x due to the changed unicode handling, but it might be a bug that has been fixed since 2.6. From thomas at jollans.com Tue Jul 6 17:45:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 06 Jul 2010 23:45:05 +0200 Subject: A question about the posibility of raise-yield in Python In-Reply-To: <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> References: <29hj97-9k4.ln1@archaeopteryx.softver.org.mk> <28847956-9af7-4280-acc9-dd7eca8dd1c3@t10g2000yqg.googlegroups.com> <5sacg7-g86.ln1@archaeopteryx.softver.org.mk> Message-ID: <4C33A3E1.1070601@jollans.com> On 07/06/2010 08:56 PM, ?????? ??????????? wrote: >>>> I'm writing this as a complete newbie (on the issue), so don't be >>>> surprised if it's the stupidest idea ever. >>> >>>> I was wondering if there was ever a discusision in the python >>>> community on a 'raise-yield' kind-of combined expression. I'd like >>>> to know if it was proposed/rejected/discussed/not-decided yet?? >>> >>> Recently (ok, several hours ago) I've come up to Greenlets [1] and it >>> seems they implement exactly what I was asking for, in a C >>> extension!! >>> >>> It's too bad that Python doesn't support this by default and many >>> libraries won't make use of it by default. Gevent [2] for example, >>> has to monkey-patch Python's socket, time.sleep and other modules so >>> that things like urllib work with it. >>> >>> I'll continue to read now. >> >> Ah, if I had seen your original post I probably could have pointed you >> to some good reading right away. What you've described is called a >> continuation, and is natively supported by some languages (like >> Scheme). It's usually not done with exceptions, though. In Scheme >> it's a special form that looks like an ordinary function call, but you >> can "return" from the call any number of times. > > I thought they were called coroutines? The scheme call-with-current-continuation facility is a lot more powerful than python generator-coroutines or, I expect, than whatever it is that Lua has. In Python, you can return to a "yield" expression exactly once, then the code continues, and the state is lost. In Scheme, you can pass the state around, save it, and return there as often as you want. Kind of "go-back-to-this-particular-frame-state" as opposed to "go-back-into-that-(co)routine" Everything that you can do with the coroutine facilities in languages like Python, Ruby, and Lua, Scheme's call/cc allows you to do as well. Thomas From aahz at pythoncraft.com Tue Jul 6 17:56:53 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jul 2010 14:56:53 -0700 Subject: Python Embedding Importing relative modules References: <8f5014f6-9aa8-44e2-afe1-a1175bcdd591@w31g2000yqb.googlegroups.com> <4a3f0ca7-fef0-4f9c-b265-5370e61edc16@d8g2000yqf.googlegroups.com> Message-ID: In article , Thomas Jollans wrote: >On 07/06/2010 09:11 PM, Aahz wrote: >> In article <4a3f0ca7-fef0-4f9c-b265-5370e61edc16 at d8g2000yqf.googlegroups.com>, >> moerchendiser2k3 wrote: >>> Aahz: >>>> >>>> Set sys.path to include each script's base dir before running it, then >>>> restore after each script. >>> >>> That works, but doesnt solve the problem. >>> >>> ScriptA.py has a module in its directory called 'bar.py' >>> ScriptB.py has a module in its directory called 'bar.py' >>> >>> Imagine the 'bar.py' modules dont have the same content, so they are >>> not equal. >>> >>> Now when the first bar.py is imported, the second import for a "import >>> bar" imports the first one, because its already stored in sys.modules. >> >> Good point, you'll need to save/restore sys.modules, too. That gets you >> 90-95% of complete namespace separation; if you need more than that, your >> best bet is to use separate processes. Full-blown namepace isolation is >> a *hard* problem, just look at all the past attempts to create secure >> Python (and what you're trying to do is roughly equivalent). > >I believe Python (at least in the 3.x series) supports multiple >interpreter instances per process. Perhaps things have changed in 3.x, but although 2.x supposedly supported multiple interpreter instances per process, the impression I got was that most people would rather poke their eyes out with a dull stick than try to make multiple interpreters per process actually work. Multiple processes are easy, OTOH. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From cournape at gmail.com Tue Jul 6 18:08:00 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 7 Jul 2010 00:08:00 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet wrote: > * sturlamolden, on 06.07.2010 17:50: >> >> Just a little reminder: >> >> Microsoft has withdrawn VS2008 in favor of VS2010. The express version >> is also unavailable for download.>:(( >> >> We can still get a VC++ 2008 compiler required to build extensions for >> the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK >> for .NET 3.5 SP1): >> >> >> http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en >> >> Download today, before it goes away! >> >> Microsoft has now published a download for Windows 7 SDK for .NET 4. >> It has the VC++ 2010 compiler. It can be a matter of days before the VC >> ++ 2008 compiler is totally unavailable. >> >> It is possible to build C and Fortran extensions for official Python >> 2.6/2.7 binaries on x86 using mingw. AFAIK, Microsoft's compiler is >> required for C++ or amd64 though. (Intel's compiler requires VS2008, >> which has now perished.) >> >> Remember Python on Windows will still require VS2008 for a long time. >> Just take a look at the recent Python 3 loath threads. > > Perhaps this all for the good. > > There is no *technical* problem creating a compiler-independent C/C++ > language binding. It is quite hard, though, or would require changes in the API to be entirely safe. When I asked the question a few months ago to see if we could fix those issues once and for all for numpy, the most common answer I got was to pass all the related functions in a structure: http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. The problem is not compiler, but really C runtimes. By itself, the issues are not windows specific (using malloc from one C library and one free from another one is trouble everywhere), but on windows: - multiple C runtimes are *very* common on windows - many things which are runtime independent on unix are not on windows (file descriptor: AFAIK, a file descriptor as returned from open can be dealt with in any C runtime on unix) - the MS standard C library is clearly not a priority: win32 specific objects can be shared across runtimes, but standard C rarely can. - the recent manifest concept (which can improve or worsen the issues) is incredibly convoluted, and poorly documented (they expect you to use MS tool and not to try to understand how it works). David From thomas at jollans.com Tue Jul 6 18:26:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 00:26:53 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33ADAD.9090606@jollans.com> On 07/07/2010 12:08 AM, David Cournapeau wrote: > On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet > wrote: >> There is no *technical* problem creating a compiler-independent C/C++ >> language binding. > > It is quite hard, though, or would require changes in the API to be > entirely safe. When I asked the question a few months ago to see if we > could fix those issues once and for all for numpy, the most common > answer I got was to pass all the related functions in a structure: > http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. > > The problem is not compiler, but really C runtimes. By itself, the > issues are not windows specific (using malloc from one C library and > one free from another one is trouble everywhere), but on windows: > - multiple C runtimes are *very* common on windows I'm also rather sure that it's pretty much impossible to have multiple C libraries in one process on UNIX, but it's obviously quite possible on Windows. > - many things which are runtime independent on unix are not on > windows (file descriptor: AFAIK, a file descriptor as returned from > open can be dealt with in any C runtime on unix) Are you telling me that file descriptors (it's a flippin int!) can't be passed around universally on Windows?? Now Windows programming *really* scares me. > - the MS standard C library is clearly not a priority: win32 specific > objects can be shared across runtimes, but standard C rarely can. And, as has already been said in this thread, this does not concern the .net developer, or any developer that sticks to managed code, be it .net, CPython, or something-else based. > - the recent manifest concept (which can improve or worsen the > issues) is incredibly convoluted, and poorly documented (they expect > you to use MS tool and not to try to understand how it works). Cheers, Thomas From martin at v.loewis.de Tue Jul 6 18:38:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 00:38:06 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C33B04E.8040303@v.loewis.de> >> - many things which are runtime independent on unix are not on >> windows (file descriptor: AFAIK, a file descriptor as returned from >> open can be dealt with in any C runtime on unix) > > Are you telling me that file descriptors (it's a flippin int!) can't be > passed around universally on Windows?? There are really three things of concern here: a) operating system file handles, of type HANDLE (which is an unsigned 32-bit value); they are not contiguous, and stdin/stdout/stderr may have arbitrary numbers b) C runtime file handles, of type int. They are contiguous, and stdin/stdout/stderr are 0/1/2. c) C FILE*. OS handles can be passed around freely within a process; across processes, they lose their meaning It's the data of types b) and c) that cause problems: the CRT handle 4 means different things depending on what copy of the CRT is interpreting it. It's worse with FILE*: passing a FILE* of one CRT to the fread() implementation of a different CRT will cause a segfault. > And, as has already been said in this thread, this does not concern the > .net developer, or any developer that sticks to managed code, be it > .net, CPython, or something-else based. Since when is CPython managed code? Regards, Martin From sturlamolden at yahoo.no Tue Jul 6 18:41:04 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 15:41:04 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <2b9aa6a5-757d-4fc8-8f51-49706594a82d@y4g2000yqy.googlegroups.com> On 6 Jul, 21:52, casevh wrote: > The original version of the Windows 7 SDK includes the command line > version of the VS 2008 amd64 compiler. I've used it compile MPIR and > GMPY successfully. The GMPY source includes a text file describing the > build process using the SDK tools. It should also be mentioned that the Windows 7 SDK includes vcbuild.exe, so it can be used to compile Visual Studio 2008 projects (I'm going to try Python). From martin.hellwig at dcuktec.org Tue Jul 6 18:41:10 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 06 Jul 2010 23:41:10 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> References: <59647d89-ee89-4001-94f7-07a80bfcca8e@a30g2000yqn.googlegroups.com> Message-ID: On 07/06/10 21:19, sturlamolden wrote: > On 6 Jul, 21:49, Christian Heimes wrote: > >> I agree, the situation isn't ideal. I see if I can get in contact with >> Microsoft's open source team. Perhaps they can keep the download link to >> VS 2008 EE working. > > It seems the MSDN subscription required to get VS 2008 costs one > dollar less than $1200. So it does not fit within everyone's budget. > > Take in the cost of your operating system, and the ones you want to test against, perhaps you also like to use office. Although I am not a windows developer per se, I do use windows XP, 2000 2003, 2008, Vista and 7 for testing. I also use office for all those clients who think that this is the only format. 1200 USD is actually quite cheap, but then again I didn't pay that because I am either always been in an academic license (about 70 EUR a year) or like now in a program for businesses who just start up (free with my bank as supporting agent). When this 3 year subscription is over I fall anyway in the cheaper renewals and if not I am sure that there is some other brand new scheme like they did for the last decade. Anyway, if you want to provide tools for platforms that are closed source that means that there are costs for the developer and the client. Although the cost for MS platforms are reasonable (as a developer and you know you way around, that means go a couple of times to those free MS events and it is quite likely you get an MSDN subscription for being such a good loyal puppy), there are always costs. If you don't like that better convince your target audience about an open source operating system, whichever that may be. -- mph From ssquma at gmail.com Tue Jul 6 18:50:10 2010 From: ssquma at gmail.com (=?ISO-8859-1?Q?Jose_=C1ngel_Quintanar_Morales?=) Date: Tue, 6 Jul 2010 17:50:10 -0500 Subject: Help with movie module Message-ID: Hi, I'm sorry by my bad english. I have a little problem with pygame.movie module when I try work whit him show this problem [joseangel at qumax reproductor]$ python packbox.py packbox.py:64: RuntimeWarning: use mixer: No module named mixer (ImportError: No module named mixer) pygame.mixer.quit() Traceback (most recent call last): File "packbox.py", line 98, in main() File "packbox.py", line 95, in main publicidad_show(screen) File "packbox.py", line 64, in publicidad_show pygame.mixer.quit() File "/usr/lib/python2.6/site-packages/pygame/__init__.py", line 70, in __getattr__ raise NotImplementedError(MissingPygameModule) NotImplementedError: mixer module not available (ImportError: No module named mixer) anybody help me please, I'm search in the web and I found this email list. thanks Jos? angel -------------- next part -------------- An HTML attachment was scrubbed... URL: From sturlamolden at yahoo.no Tue Jul 6 18:57:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 15:57:21 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <2b9aa6a5-757d-4fc8-8f51-49706594a82d@y4g2000yqy.googlegroups.com> Message-ID: On 7 Jul, 00:41, sturlamolden wrote: > It should also be mentioned that the Windows 7 SDK includes > vcbuild.exe, so it can be used to compile Visual Studio 2008 projects > (I'm going to try Python). Not sure why I forgot to mention, but we can (or even should?) use CMake to generate these project files. We don't need Visual Studio for that. From thomas at jollans.com Tue Jul 6 19:07:22 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 01:07:22 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33B04E.8040303@v.loewis.de> References: <4C33B04E.8040303@v.loewis.de> Message-ID: <4C33B72A.3020109@jollans.com> On 07/07/2010 12:38 AM, Martin v. Loewis wrote: >>> - many things which are runtime independent on unix are not on >>> windows (file descriptor: AFAIK, a file descriptor as returned from >>> open can be dealt with in any C runtime on unix) >> >> Are you telling me that file descriptors (it's a flippin int!) can't be >> passed around universally on Windows?? > > There are really three things of concern here: > a) operating system file handles, of type HANDLE (which is an unsigned > 32-bit value); they are not contiguous, and stdin/stdout/stderr may > have arbitrary numbers > b) C runtime file handles, of type int. They are contiguous, and > stdin/stdout/stderr are 0/1/2. > c) C FILE*. > > OS handles can be passed around freely within a process; across > processes, they lose their meaning > > It's the data of types b) and c) that cause problems: the CRT handle 4 > means different things depending on what copy of the CRT is interpreting it. Ah, okay. On UNIX systems, of course, a) and b) are identical. > > It's worse with FILE*: passing a FILE* of one CRT to the fread() > implementation of a different CRT will cause a segfault. > >> And, as has already been said in this thread, this does not concern the >> .net developer, or any developer that sticks to managed code, be it >> .net, CPython, or something-else based. > > Since when is CPython managed code? It's not managed code in the "runs on .net" sense, but in principle, it is managed, in that garbage collection is managed for you. From sturlamolden at yahoo.no Tue Jul 6 19:14:28 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 6 Jul 2010 16:14:28 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33B04E.8040303@v.loewis.de> Message-ID: <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> On 7 Jul, 01:07, Thomas Jollans wrote: > It's not managed code in the "runs on .net" sense, but in principle, it > is managed, in that garbage collection is managed for you. I think you are confusing Python and C code. From thomas at jollans.com Tue Jul 6 19:26:54 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 01:26:54 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> References: <4C33B04E.8040303@v.loewis.de> <9196ceca-d925-4a2e-ab8f-709f7d9bd256@x27g2000yqb.googlegroups.com> Message-ID: <4C33BBBE.7030805@jollans.com> On 07/07/2010 01:14 AM, sturlamolden wrote: > On 7 Jul, 01:07, Thomas Jollans wrote: > >> It's not managed code in the "runs on .net" sense, but in principle, it >> is managed, in that garbage collection is managed for you. > > I think you are confusing Python and C code. Or somebody's confusing something anyway I meant "CPython based", which, in hindsight, might have not have been clear from the grammatically obfuscated sentence I posted. From rodrick.brown at gmail.com Tue Jul 6 20:22:58 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 6 Jul 2010 20:22:58 -0400 Subject: Help with movie module In-Reply-To: References: Message-ID: Did you try emailing the author of this application? 2010/7/6 Jose ?ngel Quintanar Morales > Hi, I'm sorry by my bad english. > > I have a little problem with pygame.movie module when I try work whit him > show this problem > > [joseangel at qumax reproductor]$ python packbox.py > packbox.py:64: RuntimeWarning: use mixer: No module named mixer > (ImportError: No module named mixer) > pygame.mixer.quit() > Traceback (most recent call last): > File "packbox.py", line 98, in > main() > File "packbox.py", line 95, in main > publicidad_show(screen) > File "packbox.py", line 64, in publicidad_show > pygame.mixer.quit() > File "/usr/lib/python2.6/site-packages/pygame/__init__.py", line 70, in > __getattr__ > raise NotImplementedError(MissingPygameModule) > NotImplementedError: mixer module not available > (ImportError: No module named mixer) > > > anybody help me please, I'm search in the web and I found this email list. > > thanks > > Jos? angel > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 6 20:27:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jul 2010 17:27:57 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 1:35 PM, member thudfoo wrote: > On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >> On 07/06/2010 04:12 AM, sturlamolden wrote: >>> On 28 Jun, 19:39, Michael Torrie wrote: >>>> In python I could simply take the output of "ps ax" and use python's >>>> own, superior, cutting routines (using my module): >>>> >>>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>>> for x in stdout.split('\n'): >>>> ? ? print x.strip().split()[0] >>> >>> Or you just pass the stdout of one command as stdin to another. That >>> is equivalent of piping with bash. >> >> Consider this contrived example: >> >> tail -f /var/log/messages | grep openvpn >> >> While it's possible to set up pipes and spawn programs in parallel to >> operate on the pipes, in practice it's simpler to tell subprocess.Popen >> to use a shell and then just rely on Bash's very nice syntax for setting >> up the pipeline. ?Then just read the final output in python. ?If you set >> the stdout descriptor to non-blocking, you could read output as it came. > > Is this a discussion about the pipes module in the std library? No, though that module is not irrelevant to Mr. Torrie's argument. Cheers, Chris -- http://blog.rebertia.com From pthibault33 at yahoo.ca Tue Jul 6 20:39:33 2010 From: pthibault33 at yahoo.ca (Pierre Thibault) Date: Tue, 6 Jul 2010 17:39:33 -0700 (PDT) Subject: Python install has difficulties with accented characters in path References: Message-ID: On 6 juil, 17:37, Thomas Jollans wrote: > Before filing a bug, best test it with Python 2.7 (just released), 3.1, > and, if possible, py3k trunk. > > I just tried to reproduce this with a current py3k checkout, where it > worked. Probably not an issue in Python 3.x due to the changed unicode > handling, but it might be a bug that has been fixed since 2.6. I've tested with the version 2.7 and the issue is gone. From luismgz at gmail.com Tue Jul 6 22:09:14 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 6 Jul 2010 19:09:14 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> Message-ID: On Jul 2, 4:07?pm, John Nagle wrote: > David Cournapeau wrote: > > I think one point which needs to be emphasized more is what does > > python 3 bring to people. The" what's new in python 3 page" gives > > the impression that python 3 is about removing cruft. That's a very > > poor argument to push people to switch. > > ? ? That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? ? It's not faster. > It doesn't do anything you can't do in Python 2.6. ?There's no > "killer app" for it. End of life for Python 2.x is many years away; > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? > > ? ? If Python 3 came with Unladen Swallow, and ran several times > faster than Python 2.x, there'd be a strong business case for > conversion. ?Especially for large sites with racks of servers > grinding through slow CPython code. ?But it looks like Unladen > Swallow will be available for 2.6 before it's available for 3.x. > So that's not a selling point for 3.x. > > ? ? Python 3 is a nice cleanup of some legacy syntax issues. ?But > that's just not enough. ?Perl 6 is a nice cleanup of Perl 5, and > look how that went. ?Ten years on, it's not even mainstream, let > alone dominant. > > ? ? This has all been said before. See "Python 3.0: What s The Point?" > from December 2008: > > http://jens.mooseyard.com/2008/12/python-30-whats-the-point/ > > ? ? Not much has changed since then. > > ? ? What I'm not seeing is a deployment plan along these lines: > > ? ? 1. ?Identify key modules which must be converted before Python 3 > ? ? ? ? can be used in production environments. > > ? ? 2. ?Get those modules converted to Python 3. > > ? ? 3. ?Put together a distribution for the major platforms (at least > ? ? ? ? Linux and Windows) with builds of those modules. ?This > ? ? ? ? could be done on PyPi, which is at present is mostly a link > ? ? ? ? farm, not a repository. > > ? ? 4. ?Get some major distros, like Debian and ActiveState, to > ? ? ? ? include Python 3, as "python3", not as the primary Python, > ? ? ? ? so there are no conflicts. ?(Debian already has a formal > ? ? ? ? policy to keep Python versions separate.) > > ? ? 5. ?Get at least two major hosting services to put up Python 3. > > ? ? 6. ?Get at least two popular end-user programs (not modules) to > ? ? ? ? support Python 3. > > ? ? 7. ?Publicize some success stories. > > Unless the Python 3 enthusiasts get their act together and work much > harder on providing an easy transition experience, it's not going to > happen. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle What's the problem? Python 2.xx will he around for a long time. It will be supported and you can use it for your existing projects for as long a you want. On the other hand, if you have a new project and you plan to make it successful and usable for many years to come, you should seriously consider using Python 3. From alf.p.steinbach+usenet at gmail.com Tue Jul 6 22:11:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 04:11:10 +0200 Subject: Argh! Name collision! Message-ID: Donald Knuth once remarked (I think it was him) that what matters for a program is the name, and that he'd come up with a really good name, now all he'd had to do was figure out what it should be all about. And so considering Sturla Molden's recent posting about unavailability of MSVC 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and my unimaginative reply proposing names like "pni" and "pynacoin" for a compiler independent Python native code interface, suddenly, as if out of thin air, or perhaps out of fish pudding, the name "pyni" occurred to me. "pyni"! Pronounced like "tiny"! Yay! I sat down and made my first Python extension module, following the tutorial in the docs. It worked! But, wait, perhaps some other extension is already named "piny"? Google. , "PyNI is [a] config file reader/writer". Argh! - Alf -- blog at From chardster at gmail.com Tue Jul 6 22:51:30 2010 From: chardster at gmail.com (Richard Thomas) Date: Tue, 6 Jul 2010 19:51:30 -0700 (PDT) Subject: Argh! Name collision! References: Message-ID: On Jul 7, 3:11?am, "Alf P. Steinbach /Usenet" wrote: > Donald Knuth once remarked (I think it was him) that what matters for a program > is the name, and that he'd come up with a really good name, now all he'd had to > do was figure out what it should be all about. > > And so considering Sturla Molden's recent posting about unavailability of MSVC > 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and my > unimaginative reply proposing names like "pni" and "pynacoin" for a compiler > independent Python native code interface, suddenly, as if out of thin air, or > perhaps out of fish pudding, the name "pyni" occurred to me. > > "pyni"! Pronounced like "tiny"! Yay! > > I sat down and made my first Python extension module, following the tutorial in > the docs. It worked! > > But, wait, perhaps some other extension is already named "piny"? > > Google. > > , "PyNI is [a] config file reader/writer". > > Argh! > > - Alf > > -- > blog at PyNI seems to perform the same function as ConfigParser. I prefer the pronunciation like tiny to Py-N-I. The latter seems clunky. On a possibly related note I was disappointed to discover that Python's QT bindings are called PyQT not QTPy. :-) Chard. From anand.shashwat at gmail.com Tue Jul 6 23:25:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 7 Jul 2010 08:55:12 +0530 Subject: Argh! Name collision! In-Reply-To: References: Message-ID: On Wed, Jul 7, 2010 at 8:21 AM, Richard Thomas wrote: > On Jul 7, 3:11 am, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > > Donald Knuth once remarked (I think it was him) that what matters for a > program > > is the name, and that he'd come up with a really good name, now all he'd > had to > > do was figure out what it should be all about. > > > > And so considering Sturla Molden's recent posting about unavailability of > MSVC > > 9.0 (aka Visual C++ 2008) for creating Python extensions in Windows, and > my > > unimaginative reply proposing names like "pni" and "pynacoin" for a > compiler > > independent Python native code interface, suddenly, as if out of thin > air, or > > perhaps out of fish pudding, the name "pyni" occurred to me. > > > > "pyni"! Pronounced like "tiny"! Yay! > > > > I sat down and made my first Python extension module, following the > tutorial in > > the docs. It worked! > > > > But, wait, perhaps some other extension is already named "piny"? > > > > Google. > > > > , "PyNI is [a] config file > reader/writer". > > > > Argh! > > > > - Alf > > > > -- > > blog at > > PyNI seems to perform the same function as ConfigParser. I prefer the > pronunciation like tiny to Py-N-I. The latter seems clunky. > > On a possibly related note I was disappointed to discover that > Python's QT bindings are called PyQT not QTPy. :-) > Isn't this the standard. Qt -> PyQt crypto -> pycrypto MT -> PyMT ..... and the list goes on and on .. :) ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 6 23:34:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Jul 2010 20:34:06 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C333243.7040205@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: > On 07/06/2010 04:12 AM, sturlamolden wrote: >> On 28 Jun, 19:39, Michael Torrie wrote: >>> In python I could simply take the output of "ps ax" and use python's >>> own, superior, cutting routines (using my module): >>> >>> (err, stdout, stderr) = runcmd.run( [ 'ps', 'ax' ] ) >>> for x in stdout.split('\n'): >>> ? ? print x.strip().split()[0] >> >> Or you just pass the stdout of one command as stdin to another. That >> is equivalent of piping with bash. > > Consider this contrived example: > > tail -f /var/log/messages | grep openvpn > > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. Until there's a Python variable involved that is, unless you want to overlook all the edge cases or do the escaping all by yourself (and then pray you did it right). Cheers, Chris -- http://blog.rebertia.com From me+list/python at ixokai.io Tue Jul 6 23:35:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 20:35:15 -0700 Subject: Argh! Name collision! In-Reply-To: References: Message-ID: <4C33F5F3.4060704@ixokai.io> On 7/6/10 8:25 PM, Shashwat Anand wrote: > On Wed, Jul 7, 2010 at 8:21 AM, Richard Thomas > wrote: > On a possibly related note I was disappointed to discover that > Python's QT bindings are called PyQT not QTPy. :-) > Isn't this the standard. > Qt -> PyQt > crypto -> pycrypto > MT -> PyMT I think the point is QTPy would be pronounced "cutie pie" :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From cournape at gmail.com Tue Jul 6 23:40:43 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 7 Jul 2010 05:40:43 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C33ADAD.9090606@jollans.com> References: <4C33ADAD.9090606@jollans.com> Message-ID: On Wed, Jul 7, 2010 at 12:26 AM, Thomas Jollans wrote: > On 07/07/2010 12:08 AM, David Cournapeau wrote: >> On Tue, Jul 6, 2010 at 6:00 PM, Alf P. Steinbach /Usenet >> wrote: >>> There is no *technical* problem creating a compiler-independent C/C++ >>> language binding. >> >> It is quite hard, though, or would require changes in the API to be >> entirely safe. When I asked the question a few months ago to see if we >> could fix those issues once and for all for numpy, the most common >> answer I got was to pass all the related functions in a structure: >> http://stackoverflow.com/questions/1052491/c-runtime-objects-dll-boundaries. >> >> The problem is not compiler, but really C runtimes. By itself, the >> issues are not windows specific (using malloc from one C library and >> one free from another one is trouble everywhere), but on windows: >> ?- multiple C runtimes are *very* common on windows > > I'm also rather sure that it's pretty much impossible to have multiple C > libraries in one process on UNIX, but it's obviously quite possible on > Windows. I am not sure why you think it is not possible. It is rare, though. > >> ?- many things which are runtime independent on unix are not on >> windows (file descriptor: AFAIK, a file descriptor as returned from >> open can be dealt with in any C runtime on unix) > > Are you telling me that file descriptors (it's a flippin int!) can't be > passed around universally on Windows?? Yes. The reason why it does not work on windows is because file descriptor are not "native": in every unix I have heard of, file descriptor are indexes in a table of the process "structure", hence can be shared freely (no dependency on the C runtime structures). On windows, I have heard they are emulated (the native one is the win32 file handle). David From alf.p.steinbach+usenet at gmail.com Wed Jul 7 00:54:41 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 06:54:41 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 06.07.2010 19:35: > On 6 Jul, 19:09, Thomas Jollans wrote: > >> Okay, you need to be careful with FILE*s. But malloc and free? You'd >> normally only alloc& free something within the same module, using the >> same functions (ie not mixing PyMem_Malloc and malloc), would you not? > > You have to be sure PyMem_Malloc is not an preprocessor alias for > malloc (I haven't chaecked). Python 3.1.1, file [pymem.h]: PyAPI_FUNC(void *) PyMem_Malloc(size_t); #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ : malloc((n) ? (n) : 1)) The problem with the latter that it seems that it's intended for safety but does the opposite... Perhaps (if it isn't intentional) this is a bug of the oversight type, that nobody remembered to update the macro? *** Except for the problems with file descriptors I think a practical interim solution for extensions implemented in C could be to just link the runtime lib statically. For a minimal extension this increased the size from 8 KiB to 49 KiB. And generally with MS tools the size is acceptably small. I think that this would be safe because since the C API has to access things in the interpreter I think it's a given that all the relevant functions delegate to shared library (DLL) implementations, but I have not checked the source code. As a more longterm solution, perhaps python.org could make available the redistributables for various MSVC versions, and then one could introduce some scheme for indicating the runtime lib dependencies of any given extension. Then when installing an extension the installer (distutils package functionality) could just check whether the required runtime is present, and if not give the user the choice of automatically downloading from python.org, or perhaps direct from Microsoft. This scheme would support dependencies on new runtime lib versions not yet conceived when the user's version of Python was installed. Cheers, - Alf -- blog at From rantingrick at gmail.com Wed Jul 7 01:42:25 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 6 Jul 2010 22:42:25 -0700 (PDT) Subject: Argh! Name collision! References: Message-ID: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> On Jul 6, 9:11?pm, "Alf P. Steinbach /Usenet" wrote: > "pyni"! Pronounced like "tiny"! Yay! hmm, how's about an alternate spelling... "pyknee", or "pynee", or "pynie" ... considering those are not taken either? From timr at probo.com Wed Jul 7 02:21:49 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 06 Jul 2010 23:21:49 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: sturlamolden wrote: > >Just a little reminder: > >Microsoft has withdrawn VS2008 in favor of VS2010. Nonsense. They have released VS2010, but they certainly have not "withdrawn" VS2008, and I have heard of no plans to do so. >The express version is also unavailable for download. >:(( Also nonsense. Get it from right here: http://www.microsoft.com/express/downloads/ Note the three tabs: VS2010, SQL Server R2, and VS2008. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From me+list/python at ixokai.io Wed Jul 7 02:46:46 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Tue, 06 Jul 2010 23:46:46 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: Message-ID: <4C3422D6.9030702@ixokai.io> On 7/6/10 11:21 PM, Tim Roberts wrote: > sturlamolden wrote: >> >> Just a little reminder: >> >> Microsoft has withdrawn VS2008 in favor of VS2010. > > Nonsense. They have released VS2010, but they certainly have not > "withdrawn" VS2008, and I have heard of no plans to do so. Its not nonsense; Microsoft has historically made unavailable fairly quickly previous versions of the suite after a new release is out. There hasn't been any serious notification of this before it happens. The concern here is not at all without precedent. There has been some very real pain for Python extension authors/maintainers directly related to what compilers and SDK's Microsoft makes available: generally, Python is 'behind' the times of what's the latest version of VS and their SDK that is available. >> The express version is also unavailable for download. >:(( > > Also nonsense. Get it from right here: > http://www.microsoft.com/express/downloads/ > > Note the three tabs: VS2010, SQL Server R2, and VS2008. Again, not nonsense. That's available now. However, very real experience has made certain people *very* reasonably cautious about when "now" becomes "the past" in this situation: what is available now may change as soon as tomorrow or later with very little real notice. Yeah, you can get a MSDN subscription and get access to a lot. Lots of people can't afford that just to compile an extension they support. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From durumdara at gmail.com Wed Jul 7 03:18:18 2010 From: durumdara at gmail.com (durumdara) Date: Wed, 7 Jul 2010 00:18:18 -0700 (PDT) Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? Message-ID: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Hi! I have an environment under Python 2.6 (WinXP). That is based on PIL, wxPython/PyWin32. In the project's pages I see official installer for only PyWin32. I don't know that PIL or wxPython supports Python 3 or not. May with some trick these packages are working. Does anybody know about it? Can I replace my Py2.6 without lost PIL/wxPython? Thanks for your help: dd From stefan_ml at behnel.de Wed Jul 7 03:19:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Jul 2010 09:19:07 +0200 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: John Nagle, 28.06.2010 19:57: > Programs have "argv" and "argc", plus environment variables, > going in. So, going in, there are essentially subroutine parameters. > But all that comes back is an exit code. They should have had > something similar coming back, with arguments to "exit()" returning > the results. Then the "many small intercommunicating programs" > concept would have worked much better. Except that you just broke the simplicity of the pipe mechanism. Stefan From johan.gronqvist at gmail.com Wed Jul 7 03:38:21 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Wed, 07 Jul 2010 09:38:21 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> Message-ID: 2010-07-06 19:18, Ritchy lelis skrev: > On 6 jul, 17:29, Alan G Isaac wrote: >> Unfortunately I cannot make sense of the code you posted. >> Provide a detailed description in words (or psuedocode) >> of what you are trying to accomplish. Be very careful >> and detailed is you want a useful response. >> >> Alan Isaac > > hummm... > > ok, i will try to make that detailed description. I can tell you why I do not understand from your posted code what you are trying to do. Firstly, I do not understand if you are trying to plot a surface, a set of curves, or a curve, or just a set of points? In your posted code, the plot command is part of the else clause, and my guess is that you never intend the else-clause to be executed at all. In your code snippet you loop over two arrays (Vi and Vref), compute a scalar value V0, and all plot-commands you issue are of the form plot(V0). This will probably draw a line of one point (for each value in Vi and Vref), which may not be what you want, and if it draws anything at all, then all points will be drawn at the same x-value, which is also probably not what you want. Secondly, how are the Vi and Vref related to your axes? I assume you want to plot all values you compute for V0, but as a function of what? When I use the plot command, I usually give it (at least) two arguments, where the first is the x-axis, and the second is the y-axis. After I have understood those things, the next question would be about the maths relating the Vi and Vref values to the V0 values, but I do not think I will understand those until after the above points are explained clearer. I definitely think your english is not a problem here. Johan From ptmcg at austin.rr.com Wed Jul 7 04:31:50 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 7 Jul 2010 01:31:50 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 6, 3:30 am, David Cournapeau wrote: > On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > > One thing that would be very useful is how to maintain something that > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > versions below 2.6 is out of the question for most projects with a > significant userbase IMHO. As such, the idea of running the python 3 > warnings is not so useful IMHO - unless it could be made to work > better for python 2.x < 2.6, but I am not sure the idea even makes > sense. > This is exactly how I felt about my support for pyparsing, that I was trying continue to provide support for 2.3 users, up through 3.x users, with a single code base. (This would actually have been possible if I had been willing to introduce a performance penalty for Python 2 users, but performance is such a critical issue for parsing I couldn't justify it to myself.) This meant that I had to constrain my implementation, while trying to incorporate forward-looking support features (such as __bool__ and __dir__), which have no effect on older Python versions, but support additions in newer Pythons. I just couldn't get through on the python-dev list that I couldn't just upgrade my code to 2.6 and then use 2to3 to keep in step across the 2-3 chasm, as this would leave behind my faithful pre-2.6 users. Here are some of the methods I used: - No use of sets. Instead I defined a very simple set simulation using dict keys, which could be interchanged with set for later versions. - No generator expressions, only list comprehensions. - No use of decorators. BUT, pyparsing includes a decorator method, traceParseAction, which can be used by users with later Pythons as @traceParseAction in their own code. - No print statements. As pyparsing is intended to be an internal module, it does no I/O as part of its function - it only processes a given string, and returns a data structure. - Python 2-3 compatible exception syntax. This may have been my trickiest step. The change of syntax for except from except ExceptionType, ex: to: except ExceptionType as ex: is completely forward and backward incompatible. The workaround is to rewrite as: except ExceptionType: ex = sys.exc_info()[0] which works just fine in 2.x and 3.x. However, there is a slight performance penalty in doing this, and pyparsing uses exceptions as part of its grammar success/failure signalling and backtracking; I've used this technique everywhere I can get away with it, but there is one critical spot where I can't use it, so I have to keep 2 code bases with slight differences between them. - Implement __bool__, followed by __nonzero__ = __bool__. This will give you boolean support for your classes in 2.3-3.1. - Implement __dir__, which is unused by old Pythons, but supports customization of dir() output for your own classes. - Implement __len__, __contains__, __iter__ and __reversed__ for container classes. - No ternary expressions. Not too difficult really, there are several well-known workarounds for this, either by careful use of and's and or's, or using the bool-as-int to return the value from (falseValue,trueValue)[condition]. - Define a version-sensitive portion of your module, to define synonyms for constants that changed name between versions. Something like: _PY3K = sys.version_info[0] > 2 if _PY3K: _MAX_INT = sys.maxsize basestring = str _str2dict = set alphas = string.ascii_lowercase + string.ascii_uppercase else: _MAX_INT = sys.maxint range = xrange _str2dict = lambda strg : dict( [(c,0) for c in strg] ) alphas = string.lowercase + string.uppercase The main body of my code uses range throughout (for example), and with this definition I get the iterator behavior of xrange regardless of Python version. In the end I still have 2 source files, one for Py2 and one for Py3, but there is only a small and manageable number of differences between them, and I expect at some point I will move forward to supporting Py3 as my primary target version. But personally I think this overall Python 2-3 migration process is moving along at a decent rate, and I should be able to make my switchover in another 12-18 months. But in the meantime, I am still able to support all versions of Python NOW, and I plan to continue doing so (albeit "support" for 2.x versions will eventually mean "continue to offer a frozen feature set, with minimal bug-fixing if any"). I realize that pyparsing is a simple-minded module in comparison to others: it is pure Python, so it has no issues with C extensions; it does no I/O, so print-as-statement vs. print-as-function is not an issue; and it imports few other modules, so the ones it does have not been dropped in Py3; and overall it is only a few thousand lines of code. But I just offer this post as a concrete data point in this discussion. -- Paul From no.email at nospam.invalid Wed Jul 7 04:58:51 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 01:58:51 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <7xiq4racs4.fsf@ruckus.brouhaha.com> Paul McGuire writes: > is completely forward and backward incompatible. The workaround is to > rewrite as: > > except ExceptionType: > ex = sys.exc_info()[0] > > which works just fine in 2.x and 3.x. Are you sure? I wonder if there might be some race condition that could make it fail. I didn't even know about (or forgot) this change. Yucch. From thomas at jollans.com Wed Jul 7 05:06:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 11:06:40 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <7xiq4racs4.fsf@ruckus.brouhaha.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <7xiq4racs4.fsf@ruckus.brouhaha.com> Message-ID: <4C3443A0.4020800@jollans.com> On 07/07/2010 10:58 AM, Paul Rubin wrote: > Paul McGuire writes: >> is completely forward and backward incompatible. The workaround is to >> rewrite as: >> >> except ExceptionType: >> ex = sys.exc_info()[0] >> >> which works just fine in 2.x and 3.x. > > Are you sure? I wonder if there might be some race condition that could > make it fail. Luckily, no: (lib. docs on exc_info()) This function returns a tuple of three values that give information about the exception that is currently being handled. The information returned is specific both to the current thread and to the current stack frame. > > I didn't even know about (or forgot) this change. Yucch. From debatem1 at gmail.com Wed Jul 7 05:29:05 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 05:29:05 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: > On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >> >> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >> >>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchuk > >>>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>>> single C codebase. I'd be willing to contribute my experiences to a >>>> document >>>> somewhere. (Is there a Wiki?) >>> >>> Indeed there is: http://wiki.python.org/moin/ >> >> Thanks. I don't want to appear ungrateful, but I was hoping for >> something specific to the 2-to-3 conversion. I guess someone has to >> start somewhere... > > There is an existing 2to3 and other pages for Python code conversion. I do > not know of any for CAPI conversion. The need for such has been acknowledged > among the devs but if there is nothing yet, we need someone with specialized > experience and a bit of time to make a first draft. If you start one, give > it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from > the 2to3 page > > In his post on this thread, Martin Loewis volunteered to list what he knows > from psycopg2 if someone else will edit. I'm not sure why I don't have this post, but I'm happy to help edit etc if Martin wants to put together a rough draft. Geremy Condra From tartley at tartley.com Wed Jul 7 05:32:14 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 7 Jul 2010 02:32:14 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: Message-ID: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> On Jul 6, 4:50?pm, sturlamolden wrote: > Just a little reminder: > > Microsoft has withdrawn VS2008 in favor of VS2010. The express version > is also unavailable for download. >:(( > > We can still get a VC++ 2008 compiler required to build extensions for > the official Python 2.6 and 2.7 binary installers here (Windows 7 SDK > for .NET 3.5 SP1): > > http://www.microsoft.com/downloads/details.aspx?familyid=71DEB800-C59... > > Download today, before it goes away! > > Microsoft has now published a download for Windows 7 SDK for .NET 4. > It has the VC++ 2010 compiler. It can be a matter of days before the VC > ++ 2008 compiler is totally unavailable. I presume this problem would go away if future versions of Python itself were compiled on Windows with something like MinGW gcc. Also, this would solve the pain of Python developers attempting to redistribute py2exe versions of their programs (i.e. they have to own a Visual Studio license to legally be able to redistribute the required C runtime) I don't understand enough to know why Visual Studio was chosen instead of MinGW. Can anyone shed any light on that decision? Many thanks Jonathan Hartley From hnsri49 at gmail.com Wed Jul 7 05:53:50 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Wed, 7 Jul 2010 15:53:50 +0600 Subject: Problem With the PyRtf Footers Message-ID: Hi all, Am using the pyrtf for the generating the rtf documents from the html.Am able to generate the documents the problem is with the footer.Its coming only for the first page for the rest of the pages it is coming empty.Am using the section.FirstFooter for the first page footer and section.Footer for the subsequent pages.I am not able to figure out what is exactly the problem.If any body knows please help me. Thanks in Advance ! Srinivas HN ph-9986229891 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dm at tu-clausthal.de Wed Jul 7 07:52:12 2010 From: dm at tu-clausthal.de (david mainzer) Date: Wed, 07 Jul 2010 13:52:12 +0200 Subject: Python -- floating point arithmetic Message-ID: <4C346A6C.5090903@tu-clausthal.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA384 Dear Python-User, today i create some slides about floating point arithmetic. I used an example from http://docs.python.org/tutorial/floatingpoint.html so i start the python shell on my linux machine: dm at maxwell $ python Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sum = 0.0 >>> for i in range(10): ... sum += 0.1 ... >>> sum 0.99999999999999989 >>> But thats looks a little bit wrong for me ... i must be a number greater then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 in python ... if i print it. So i create an example program: sum = 0.0 n = 10 d = 1.0 / n print "%.60f" % ( d ) for i in range(n): print "%.60f" % ( sum ) sum += d print sum print "%.60f" % ( sum ) - -------- RESULTs ------ 0.100000000000000005551115123125782702118158340454101562500000 0.000000000000000000000000000000000000000000000000000000000000 0.100000000000000005551115123125782702118158340454101562500000 0.200000000000000011102230246251565404236316680908203125000000 0.300000000000000044408920985006261616945266723632812500000000 0.400000000000000022204460492503130808472633361816406250000000 0.500000000000000000000000000000000000000000000000000000000000 0.599999999999999977795539507496869191527366638183593750000000 0.699999999999999955591079014993738383054733276367187500000000 0.799999999999999933386618522490607574582099914550781250000000 0.899999999999999911182158029987476766109466552734375000000000 1.0 0.999999999999999888977697537484345957636833190917968750000000 and the jump from 0.50000000000000*** to 0.59999999* looks wrong for me ... do i a mistake or is there something wrong in the representation of the floating points in python? my next question, why could i run print "%.66f" % ( sum ) but not print "%.67f" % ( sum ) can anybody tell me how python internal represent a float number?? Best and many thanks in advanced, David -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) iQIcBAEBCQAGBQJMNGpsAAoJEJ82b5xvAlAYYMYP/RTaRcB2NCawBQ25V463+pkO /YtTqsamrFqENrljqpsPrwOOqR02TQrOvZrV72snDPkkcN36tZHKwbmcnOS0tOAc kjX0/oNQOvvEMyJUuHJt9kdNjxMEvUUlENEZHLtpxbypIAo3Waf0FBxKo9F4fJJS PaDIuDgXiLOiaTTUCwa5kKowzjUe8BJOczpUulvGiIvbUac4cxwkPiGvv6L4wzmI /4x1mG5FSibEzcI2zFRsQNHfTqxuKC3a49DuSPtXZo4YWdqVeSXLntQk70uTa78K q4cBVEIDqETQyG0mcRABJpcTMPsnGgbgJD74uhDSTARuyHh405XbjKlic7pe1M12 AhuN71QjpGFl80OOXxCja4OKJCAhPEkfhNsJjrlFnSXAoFWg5YvhDbSVkjW6ftt0 tzyGZEoBpRSjGSIeAojYaqt1Xdxwldz2qFjRLX03io3Fgr8PKRbcLRgg1FXaMFPc gYaY0UEh4dEjt/5afp3ET0LkOhZVMbbi2oSkkFQpRMAzik63zSJRwRxiQXWunlSi HhKqL4sAICf6MODzquuNzJO9wH8Fkpwi+JPEAwnQm/S6Ty00dN22GezG4TWGfepH AhKOIEtRIcMgI7kyBfUdOQe6sifKGGuTEeXK12Td9znZN+wKfqG+Ch1mq4Rwy6P7 p2xwF7ZUWNgRU+5Y/bLG =aS+I -----END PGP SIGNATURE----- From dm at tu-clausthal.de Wed Jul 7 08:05:52 2010 From: dm at tu-clausthal.de (david mainzer) Date: Wed, 07 Jul 2010 14:05:52 +0200 Subject: Python -- floating point arithmetic Message-ID: <4C346DA0.1070708@tu-clausthal.de> Dear Python-User, today i create some slides about floating point arithmetic. I used an example from http://docs.python.org/tutorial/floatingpoint.html so i start the python shell on my linux machine: dm at maxwell $ python Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> sum = 0.0 >>> >>> for i in range(10): ... sum += 0.1 ... >>> >>> sum 0.99999999999999989 >>> >>> But thats looks a little bit wrong for me ... i must be a number greater then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 in python ... if i print it. So i create an example program: sum = 0.0 n = 10 d = 1.0 / n print "%.60f" % ( d ) for i in range(n): print "%.60f" % ( sum ) sum += d print sum print "%.60f" % ( sum ) -------- RESULTs ------ 0.100000000000000005551115123125782702118158340454101562500000 0.000000000000000000000000000000000000000000000000000000000000 0.100000000000000005551115123125782702118158340454101562500000 0.200000000000000011102230246251565404236316680908203125000000 0.300000000000000044408920985006261616945266723632812500000000 0.400000000000000022204460492503130808472633361816406250000000 0.500000000000000000000000000000000000000000000000000000000000 0.599999999999999977795539507496869191527366638183593750000000 0.699999999999999955591079014993738383054733276367187500000000 0.799999999999999933386618522490607574582099914550781250000000 0.899999999999999911182158029987476766109466552734375000000000 1.0 0.999999999999999888977697537484345957636833190917968750000000 and the jump from 0.50000000000000*** to 0.59999999* looks wrong for me ... do i a mistake or is there something wrong in the representation of the floating points in python? my next question, why could i run print "%.66f" % ( sum ) but not print "%.67f" % ( sum ) can anybody tell me how python internal represent a float number?? Best and many thanks in advanced, David From philip at semanchuk.com Wed Jul 7 08:32:27 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jul 2010 08:32:27 -0400 Subject: Recommend a MySQLdb Forum In-Reply-To: References: Message-ID: <838AF739-C880-437A-AF6D-CB3F9E3EC2F5@semanchuk.com> On Jul 6, 2010, at 3:16 PM, Tim Johnson wrote: > Greetings: > I would appreciate it if some could recommend a MySQLdb forum. The one associated the sourceforge project seems like a good bet. 1) go here: http://sourceforge.net/projects/mysql-python/ 2) click support From dickinsm at gmail.com Wed Jul 7 08:55:55 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 7 Jul 2010 05:55:55 -0700 (PDT) Subject: Python -- floating point arithmetic References: Message-ID: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> On Jul 7, 1:05?pm, david mainzer wrote: > Dear Python-User, > > today i create some slides about floating point arithmetic. I used an > example from > > http://docs.python.org/tutorial/floatingpoint.html > > so i start the python shell on my linux machine: > > dm at maxwell $ python > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 > >>> >>> for i in range(10): > > ... ? ? sum += 0.1 > ...>>> >>> sum > 0.99999999999999989 > > But thats looks a little bit wrong for me ... i must be a number greater > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. So you've identified one source of error here, namely that 0.1 isn't exactly representable (and you're correct that the value stored internally is actually a little greater than 0.1). But you're forgetting about the other source of error in your example: when you do 'sum += 0.1', the result typically isn't exactly representable, so there's another rounding step going on. That rounding step might produce a number that's smaller than the actual exact sum, and if enough of your 'sum += 0.1' results are rounded down instead of up, that would easily explain why the total is still less than 1.0. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > ? ? print "%.60f" % ( sum ) > ? ? sum += d > > print sum > print "%.60f" % ( sum ) > > -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? Look at this more closely: you're adding 0.500000000000000000000000.... to 0.1000000000000000055511151231257827021181583404541015625 The *exact* result is, of course 0.6000000000000000055511151231257827021181583404541015625 However, that's not a number that can be exactly represented as a C double (which is how Python stores floats internally). This value falls between the two (consecutive) representable values: 0.59999999999999997779553950749686919152736663818359375 and 0.600000000000000088817841970012523233890533447265625 But of these two, the first is closer to the exact value than the second, so that's the result that you get. You can convince yourself of these results by using the fractions module to do exact arithmetic: >>> from fractions import Fraction >>> tenth = Fraction.from_float(0.1) >>> half = Fraction.from_float(0.5) >>> point_six = Fraction.from_float(0.6) # 0.599999999999 >>> point_six_plus = Fraction.from_float(0.6 + 2**-53) # next float up, 0.6000000 >>> sum = tenth + half # exact value of the sum >>> point_six < sum < point_six_plus # lies between point_six and point_six_plus True >>> sum - point_six < point_six_plus - sum # but it's closer to point_six True > my next question, why could i run > > print "%.66f" % ( sum ) > > but not > > print "%.67f" % ( sum ) That's a historical artefact resulting from use of a fixed-length buffer somewhere deep in Python's internals. This restriction is removed in Python 2.7 and Python 3.x. > can anybody tell me how python internal represent a float number?? In CPython, it's stored as a C double, which typically means in IEEE 754 binary64 format. (Of course, since it's a Python object, it's not just storing the C double itself; it also has fields for the object type and the reference count, so a Python float typically takes 16 bytes of memory on a 32-bit machine, and 24 bytes on a 64-bit machine.) -- Mark From thomas at jollans.com Wed Jul 7 09:08:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 15:08:07 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4C347C37.7060909@jollans.com> On 07/07/2010 02:05 PM, david mainzer wrote: > today i create some slides about floating point arithmetic. I used an > example from > > http://docs.python.org/tutorial/floatingpoint.html > > so i start the python shell on my linux machine: > > dm at maxwell $ python > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>>>>> sum = 0.0 >>>>>>> for i in range(10): > ... sum += 0.1 > ... >>>>>>> sum > 0.99999999999999989 >>>>>>> > But thats looks a little bit wrong for me ... i must be a number greater > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. The simple fact of the matter is: floating point arithmetic isn't accurate. This has nothing to do with Python, it's the fault of your processor's floating point handling. It's good enough in most cases, but you should never rely on a floating-point number to have exactly a certain value. It won't work. To generalize your example a bit: >>> def test_floating_product(a, b): ... sum = 0 ... for _ in range(int(b)): ... sum += a ... return sum, a * int(b), sum == a * b ... >>> test_floating_product(0.1, 1) (0.1, 0.1, True) >>> test_floating_product(0.1, 10) (0.9999999999999999, 1.0, False) >>> test_floating_product(0.2, 4) (0.8, 0.8, True) >>> test_floating_product(0.2, 5) (1.0, 1.0, True) >>> test_floating_product(0.2, 6) (1.2, 1.2000000000000002, False) >>> > -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? the difference is almost exactly 0.1, so that looks okay > > my next question, why could i run > > print "%.66f" % ( sum ) > > but not > > print "%.67f" % ( sum ) I can run either... with Python 3.1. Using 2.6, I get a nice error message: >>> "%.129f" % 0.1 Traceback (most recent call last): File "", line 1, in OverflowError: formatted float is too long (precision too large?) There just isn't anything like 67 decimals of information available. Having that information wouldn't help you a bit. basically, floating point number are stored in the format N * (2 ** E) And use a lot of guesswork. as E gets larger, the precision decreases. Rounding errors occur at the last few decimals, in either direction, depending on the numbers. > > can anybody tell me how python internal represent a float number?? > From lists at cheimes.de Wed Jul 7 09:24:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 15:24:35 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: > can anybody tell me how python internal represent a float number?? It's an IEEE 754 double precision float on all hardware platforms that support IEEE 754 semantics. Python follows the C99 standards for double and complex numbers. Christian From raltbos at xs4all.nl Wed Jul 7 09:50:06 2010 From: raltbos at xs4all.nl (Richard Bos) Date: Wed, 07 Jul 2010 13:50:06 GMT Subject: C interpreter in Lisp/scheme/python References: <28b50375-3331-4717-bb9e-b7f795fe3d76@j4g2000yqh.googlegroups.com> Message-ID: <4c347608.4515218@news.xs4all.nl> Tim Rentsch wrote: > nanothermite911fbibustards > > > How to make Lisp go faster than C > > Didier Verna > > Asking whether Lisp is faster than C is like asking why it's > colder in the mountains than it is in the summer. YM warmer. HTH; HAND. Richard From fetchinson at googlemail.com Wed Jul 7 09:55:45 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 7 Jul 2010 15:55:45 +0200 Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? In-Reply-To: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> References: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Message-ID: > I don't know that PIL or wxPython supports Python 3 or not. May with > some trick these packages are working. > > Does anybody know about it? > Can I replace my Py2.6 without lost PIL/wxPython? PIL currently does not support python 3 but release 1.1.7 will in the future. Don't ask me when, I don't know. I have no idea about the rest. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From philip at semanchuk.com Wed Jul 7 10:05:22 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 7 Jul 2010 10:05:22 -0400 Subject: Python -- floating point arithmetic In-Reply-To: <4C347C37.7060909@jollans.com> References: <4C346DA0.1070708@tu-clausthal.de> <4C347C37.7060909@jollans.com> Message-ID: On Jul 7, 2010, at 9:08 AM, Thomas Jollans wrote: > On 07/07/2010 02:05 PM, david mainzer wrote: >> today i create some slides about floating point arithmetic. I used an >> example from >> >> http://docs.python.org/tutorial/floatingpoint.html >> >> so i start the python shell on my linux machine: >> >> dm at maxwell $ python >> Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) >> [GCC 4.3.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information. >>>>>>>> sum = 0.0 >>>>>>>> for i in range(10): >> ... sum += 0.1 >> ... >>>>>>>> sum >> 0.99999999999999989 >>>>>>>> >> But thats looks a little bit wrong for me ... i must be a number >> greater >> then 1.0 because 0.1 = >> 0.100000000000000005551115123125782702118158340454101562500000000000 >> in python ... if i print it. > > The simple fact of the matter is: floating point arithmetic isn't > accurate. This has nothing to do with Python, it's the fault of your > processor's floating point handling. It's good enough in most cases, > but > you should never rely on a floating-point number to have exactly a > certain value. It won't work. Yes, this might be a good time to review the dense but interesting document, "What Every Computer Scientist Should Know About Floating- Point Arithmetic": http://docs.sun.com/source/806-3568/ncg_goldberg.html Cheers Philip From dr.cg at 126.com Wed Jul 7 10:28:56 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 7 Jul 2010 22:28:56 +0800 (CST) Subject: Why Python forbids multiple instances of one module? Message-ID: <1365e96.c236.129ad4f3627.Coremail.dr.cg@126.com> >> Why Python forbids multiple instances of one module? >> If only Python allows multiple instances of one module, module will >> be enough to replace class in most cases. >> After all, it is much easier to write a module than a class, at least we do >> not have to write self everywhere. > If you really want to do that, it should be possible by deleting the > entry from sys.modules and re-importing it. You save yourself having > to explicitly write self everywhere, but instead you have to declare > all your "instance" variables as globals in each "method" that uses > them, which isn't much less of a chore. You also lose inheritance, > properties (and descriptors in general), magic method support, > metaclasses, and pretty much all the other nice features that > new-style classes have to offer. Wow, it works! Thanks a lot for the good idea. It is cool to write, test, debug and maintain POP codes, while realizing the OOP power. I think inheritance might be simulated with: from parentModule import * I really expect for the day when operator overloading and new-style class features find their way into module. Thans again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bartc at freeuk.com Wed Jul 7 11:00:25 2010 From: bartc at freeuk.com (bart.c) Date: Wed, 7 Jul 2010 16:00:25 +0100 Subject: Python -- floating point arithmetic In-Reply-To: References: Message-ID: david mainzer wrote: >>>> sum = 0.0 >>>> for i in range(10): > ... sum += 0.1 > ... >>>> sum > 0.99999999999999989 >>>> > > But thats looks a little bit wrong for me ... i must be a number > greater > then 1.0 because 0.1 = > 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > print "%.60f" % ( sum ) > sum += d > > print sum > print "%.60f" % ( sum ) > > > - -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? I think the main problem is, as sum gets bigger, the less significant bits of the 0.1 representation fall off the end (enough to make it effectively just under 0.1 you're adding instead of just over). > can anybody tell me how python internal represent a float number?? Try "google ieee floating point". The problems aren't specific to Python. -- Bartc From bartc at freeuk.com Wed Jul 7 11:02:38 2010 From: bartc at freeuk.com (bart.c) Date: Wed, 7 Jul 2010 16:02:38 +0100 Subject: Python -- floating point arithmetic In-Reply-To: References: Message-ID: david mainzer wrote: >>>> sum = 0.0 >>>> for i in range(10): > ... sum += 0.1 > ... >>>> sum > 0.99999999999999989 >>>> > > But thats looks a little bit wrong for me ... i must be a number > greater > then 1.0 because 0.1 = > 0.100000000000000005551115123125782702118158340454101562500000000000 > in python ... if i print it. > > So i create an example program: > > sum = 0.0 > n = 10 > d = 1.0 / n > print "%.60f" % ( d ) > for i in range(n): > print "%.60f" % ( sum ) > sum += d > > print sum > print "%.60f" % ( sum ) > > > - -------- RESULTs ------ > 0.100000000000000005551115123125782702118158340454101562500000 > 0.000000000000000000000000000000000000000000000000000000000000 > 0.100000000000000005551115123125782702118158340454101562500000 > 0.200000000000000011102230246251565404236316680908203125000000 > 0.300000000000000044408920985006261616945266723632812500000000 > 0.400000000000000022204460492503130808472633361816406250000000 > 0.500000000000000000000000000000000000000000000000000000000000 > 0.599999999999999977795539507496869191527366638183593750000000 > 0.699999999999999955591079014993738383054733276367187500000000 > 0.799999999999999933386618522490607574582099914550781250000000 > 0.899999999999999911182158029987476766109466552734375000000000 > 1.0 > 0.999999999999999888977697537484345957636833190917968750000000 > > and the jump from 0.50000000000000*** to 0.59999999* looks wrong > for me ... do i a mistake or is there something wrong in the > representation of the floating points in python? I think the main problem is, as sum gets bigger, the less significant bits of the 0.1 representation fall off the end (enough to make it effectively just under 0.1 you're adding instead of just over). > can anybody tell me how python internal represent a float number?? Try "google ieee floating point". The problems aren't specific to Python. -- Bartc From michele.simionato at gmail.com Wed Jul 7 11:06:58 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 7 Jul 2010 08:06:58 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <050e5476-662f-4176-9675-8941e109a3fe@k39g2000yqb.googlegroups.com> On Jun 14, 1:07?am, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega This look like a huge project for an evaluation of expressiveness which result is obvious. Lisp (including Scheme) is more expressive than Python, for many definitions of expressiveness (see for instance http://www.ccs.neu.edu/scheme/pubs/scp91-felleisen.ps.gz if you like academic papers). However, who cares? What matters in everyday life are other things, like the availability of libraries, tools, easy of maintenance, etc. In your proposed project the choice of the parsing library would matter a lot. Writing languages is a domain where Lisp is traditionally strong, so you may find good libraries to help you with the task. My guess is that it would take more or less the same amount of effort both in Python and in Lisp. The place where Lisp has an advantage is writing an *embedded* language: then thanks to macros you could write a *compiled* sublanguage. Doing the same in Python is essentially impossible. Michele Simionato From qtvali at gmail.com Wed Jul 7 11:10:27 2010 From: qtvali at gmail.com (Tambet) Date: Wed, 7 Jul 2010 18:10:27 +0300 Subject: Error message repetition Message-ID: Hello! I have such problem that: - My console shows maximally x last lines, then truncates - Error message takes 2 line - In case of very big stack trace, there will be 2*x error lines - In such case I do not see any debug output In this case, it's about recursion: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) and so on... I think it should be instead: File "b2.py", line 124, in seek_solution [*repeated x times*] solution = self.seek_solution(weight + U.gravity, len(test), test) Getting big strack trace is most probable with functions calling themselves - thus, long stack traces usually contain such repetitions. As those functions might not call themselves directly, one cycle of recursion might become four lines long, in such case: Stack item 1: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) Stack item 2: File "b2.py", line 124, in seek_solution solution = self.seek_solution(weight + U.gravity, len(test), test) Stack item repetitions: [#1, #2] * x This could simply enumerate stack items and then create formulas of repetitions, like: [[#1, #2] * 15, #3 * 15] * 3 If it shows each message written-out at least one and max two or three times, but over that gives it an id and shows patterns of those instead, it will be a lot better. I have, sometimes, gone through some four pages of Java stack traces etc., but I think that having such long array of errors does not make it more readable or simple - if you can see everything in one page, then it's good enough for pondering. And scrolling up and looking at output would be a nice feature ;) Especially now, as I am going to raise recursion limit - this program would be perfectly possible without relying on built-in loop constructions so much, but I did it yesterday in such manner and it simply raised into unmanageable complexity. Thus, now I am trying to encapsulate it's logic into pieces, which maximize the use of Pythons overloads and function-based iterators etc., but this makes error messages that long when I do something wrong - and I can't even check if that was really some mistake in code or just the recursion actually needs to be deeper than I hoped. Tambet -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Wed Jul 7 11:20:27 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 07 Jul 2010 11:20:27 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <4C2E38F5.10708@animats.com> References: <4C2E38F5.10708@animats.com> Message-ID: <5325a$4c349b5b$4275d90a$27439@FUSE.NET> On 7/2/10 3:07 PM, John Nagle wrote: > > That's the real issue, not parentheses on the "print" statement. > Where's the business case for moving to Python 3? It's not faster. > It doesn't do anything you can't do in Python 2.6. There's no > "killer app" for it. End of life for Python 2.x is many years away; > most server Linux distros aren't even shipping with 2.6 yet. How can a > business justify spending money on conversion to Python 3? That's decision for each business to make. My guess is that many businesses won't upgrade for some time, until the major libraries/modules support Python 3. I don't plan to move to Python 3 for at least a couple of years. > > Python 3 is a nice cleanup of some legacy syntax issues. But > that's just not enough. Perl 6 is a nice cleanup of Perl 5, and > look how that went. Ten years on, it's not even mainstream, let > alone dominant. The Perl analogy isn't really useful here. Perl 6 is somewhere between the HURD and Duke Nukem Forever in terms of being viable. Even the Perl website says, "If you are looking for production ready code please use Perl 5." That's one reason why Perl 5 development has recently undergone a resurgence. Python 3, by contrast, is production-ready in itself; libraries are gradually moving to support it, and Python 2 has a definite end-of-life release in 2.7, with an extended maintenance period for 2.7. The Python developers are providing a much stronger and clearer path forward for Python 3. The transition period may last five years, but the path is clear. As a Mac developer, I'm sympathetic to your frustration. A few years ago Apple deprecated one of its major API's (Carbon), on which my own development depended, and there was a lot of uncertainty about major libraries that use Carbon being updated. This is normal in any transition period. Eventually, the major libraries I depend on were updated by their developers (i.e. ported to the Cocoa API), I was able to migrate my own applications to the updated libraries, and life went on. I think the same thing will happen with Python. It's useful to note the libraries that are not yet ported to support Python 3, and to share best practices for moving forward. Past a certain point, however, I don't see much point in attacking the existence of Python 3 or questioning the need to move toward Python 3. It's here, it's the way forward, and that's not going to change. Might as well accept it. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From python at lonely-star.org Wed Jul 7 11:23:22 2010 From: python at lonely-star.org (Nathan Huesken) Date: Wed, 7 Jul 2010 11:23:22 -0400 Subject: tarfile and progress information Message-ID: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> Hi, I am packing large files with tarfile. Is there any way I can get progress information while packing? Thanks! Nathan From thomas at jollans.com Wed Jul 7 11:28:25 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 07 Jul 2010 17:28:25 +0200 Subject: Error message repetition In-Reply-To: References: Message-ID: <4C349D19.3040203@jollans.com> On 07/07/2010 05:10 PM, Tambet wrote: > Hello! > > I have such problem that: > > * My console shows maximally x last lines, then truncates > * Error message takes 2 line > * In case of very big stack trace, there will be 2*x error lines > * In such case I do not see any debug output > > In this case, it's about recursion: > > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > and so on... Depending on how far this goes up, you might just be able to change the backlog your terminal emulator saves? that would allow you to scroll up. If you can't do that, you should get a proper console. Anyway, if you want to customise the traceback output, you can! simply replace sys.excepthook with your own version. http://docs.python.org/dev/py3k/library/sys.html#sys.excepthook > > I think it should be instead: > File "b2.py", line 124, in seek_solution [*repeated x times*] > solution = self.seek_solution(weight + U.gravity, len(test), test) > > Getting big strack trace is most probable with functions calling > themselves - thus, long stack traces usually contain such repetitions. > > As those functions might not call themselves directly, one cycle of > recursion might become four lines long, in such case: > > Stack item 1: File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > Stack item 2: File "b2.py", line 124, in seek_solution > solution = self.seek_solution(weight + U.gravity, len(test), test) > Stack item repetitions: [#1, #2] * x > > This could simply enumerate stack items and then create formulas of > repetitions, like: > [[#1, #2] * 15, #3 * 15] * 3 > > If it shows each message written-out at least one and max two or three > times, but over that gives it an id and shows patterns of those instead, > it will be a lot better. I have, sometimes, gone through some four pages > of Java stack traces etc., but I think that having such long array of > errors does not make it more readable or simple - if you can see > everything in one page, then it's good enough for pondering. And > scrolling up and looking at output would be a nice feature ;) Especially > now, as I am going to raise recursion limit - this program would be > perfectly possible without relying on built-in loop constructions so > much, but I did it yesterday in such manner and it simply raised into > unmanageable complexity. Thus, now I am trying to encapsulate it's logic > into pieces, which maximize the use of Pythons overloads and > function-based iterators etc., but this makes error messages that long > when I do something wrong - and I can't even check if that was really > some mistake in code or just the recursion actually needs to be deeper > than I hoped. > > Tambet > From torriem at gmail.com Wed Jul 7 11:31:02 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 07 Jul 2010 09:31:02 -0600 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> Message-ID: <4C349DB6.8080001@gmail.com> On 07/06/2010 09:34 PM, Chris Rebert wrote: > On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >> While it's possible to set up pipes and spawn programs in parallel to >> operate on the pipes, in practice it's simpler to tell subprocess.Popen >> to use a shell and then just rely on Bash's very nice syntax for setting >> up the pipeline. > > Until there's a Python variable involved that is, unless you want to > overlook all the edge cases or do the escaping all by yourself (and > then pray you did it right). Very good point. This is a problem that the pipes module suffers from as well. Although we learned in the other thread on escaping SQL statements that escaping is faster, easier and just as safe as other parameterization mechanisms. Uh huh. Back on target, a library similar to pipes that was safe (pipes is not) and had a pythonic syntax would be cool. pipes module works alright, syntax wise, but it's not a clean syntax. From qtvali at gmail.com Wed Jul 7 11:53:53 2010 From: qtvali at gmail.com (Tambet) Date: Wed, 7 Jul 2010 18:53:53 +0300 Subject: Error message repetition In-Reply-To: References: Message-ID: > Depending on how far this goes up, you might just be able to change the > backlog your terminal emulator saves? that would allow you to scroll up. > If you can't do that, you should get a proper console. > I use bash, which allows to do that. This was rather a case example - actually this output gets pretty annoying anyway and should contain only most important information at any given moment. Scrollbar getting too small is another example of the same case ...the case that if something outputs 2000 lines of repetition, it's not very much of use. This could be that someone does not understand the cryptic output, but I think that anyone having that long traceback is probably intelligent enough to google for "Python traceback what those cryptic things mean" ;) I think that this functionality should be triggered only by traceback bigger than, say, 20 lines or so. Also, this is not the point, where processor usage costs anything. Anyway, if you want to customise the traceback output, you can! > simply replace sys.excepthook with your own version. > > http://docs.python.org/dev/py3k/library/sys.html#sys.excepthook > Ok, I should have thought of that - anyway, such thing should be standard functionality. I personally love nonverbose output - if it can't say it in 1 A4, it should just tell me that it could if I asked. I mean, normally I like to have one sight over the traceback and another over program itself. Thanks for that hook ...I will use it in case I get four of five more similar errors today ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Wed Jul 7 12:29:55 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 07 Jul 2010 17:29:55 +0100 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > you should never rely on a floating-point number to have exactly a > certain value. "Never" is an overstatement. There are situations where you can rely upon a floating-point number having exactly a certain value. First, floating-point values are exact. They may be an approximation to some other value, but they are still exact values, not some kind of indeterminate quantum state. Specifically, a floating-point value is a rational number whose denominator is a power of two. Second, if the result of performing a primitive arithmetic operation (addition, subtraction, multiplication, division, remainder) or the square-root function on the equivalent rational values is exactly representable as a floating-point number, then the result will be exactly that value. Third, if the result of performing a primitive arithmetic operation or the square-root function on the equivalent rational values *isn't* exactly representable as a floating-point number, then the floating-point result will be obtained by rounding the exact value according to the FPU's current rounding mode. All of this is entirely deterministic, and follows relatively simple rules. Even if the CPU has a built-in random number generator, it will *not* be used to generate the least-significant bits of a floating-point arithmetic result. The second and third cases above assume that floating-point arithmetic follows IEEE-754 (the second case is likely to be true even for systems which don't strictly adhere to IEEE-754). This is true for most modern architectures, provided that: 1. You aren't using Borland C, which forcibly "optimises" x/y to x*(1/y), so 12/3 isn't exactly equal to 4, as 1/3 isn't exactly representable. Real compilers won't use this sort of approximation unless specifically instructed (e.g. -funsafe-math-optimizations for gcc). 2. You aren't using one of the early Pentium chips. In spite of this, there are some "gotcha"s. E.g. on x86, results are computed to 80-bit (long double) precision internally. These will be truncated to 64 bits if stored in memory. Whether the truncation occurs is largely up to the compiler, although it can be forced with -ffloat-store with gcc. More complex functions (trigonometric, etc) are only accurate to within a given relative error (e.g. +/- the value of the least significant bit), as it isn't always possible to determine the correct value for the least significant bit for a given rounding mode (and even if it is theoretically possible, there is no limit to the number of bits of precision which would be required). From rivkaumiller at gmail.com Wed Jul 7 12:38:40 2010 From: rivkaumiller at gmail.com (Rivka Miller) Date: Wed, 7 Jul 2010 09:38:40 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> On Jun 13, 4:07?pm, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega You should probably narrow down your project to one. For example, write a LISt Processor Meta Circular Evaluator in C. You can take Paul Graham's rendition as a start and forget about garbage collection. Start with getchar()/putchar() for I/O. Although C comes with a regex library, you probably do not need a regex or parser at all for this. This is the beauty of LISP which is why McCarthy was able to bypass the several man years of effort involved in FORmula TRANslator. Even as a young boy like L. Peter Deutsch was able to write it in assembly for one of the PDP's. You will have go implement an associative array or a symbol-value table probably as a stack or linked list. You will have to decide how you implement the trees, as cons cells or some other method. Dynamic scoping is easy to implement and that is what elisp has. I am not aware of any book that provides implementation of LISP in C and explains it at the same time. This is the extent of help I can provide, someone else can probably help you more. Anyone know what the first initial of L. Peter Deutsch stand for ? Rivka From roy at panix.com Wed Jul 7 12:46:53 2010 From: roy at panix.com (Roy Smith) Date: Wed, 07 Jul 2010 12:46:53 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <5325a$4c349b5b$4275d90a$27439@FUSE.NET> Message-ID: In article <5325a$4c349b5b$4275d90a$27439 at FUSE.NET>, Kevin Walzer wrote: > That's decision for each business to make. My guess is that many > businesses won't upgrade for some time, until the major > libraries/modules support Python 3. I don't plan to move to Python 3 for > at least a couple of years. It takes a long time for big businesses to upgrade. It's not like me or you. I just download the latest and greatest, run the installer, and I'm good to go. A big company has to install it in a test lab, certify it, get approval from IT, log a change request, etc. You need to get approval from your manager, your director, your VP, and so on up the management chain until you finally reach somebody who has no clue what's going on and either sits on the request or denies it out of ignorance. Or, more likely, you just hit some middle-management layer where the guy doesn't have the authority to approve it himself, and isn't willing to expend the political capital it would take to get approval from the next layer up. Somebody might decide they don't want to disturb any existing production systems (not a bad idea, really), so you need to order new hardware for it. Even if you can get capital approval for that, it mushrooms into finding rack space, and the UPS is already oversubscribed, and so is the cooling, and there's no available network ports, and so on. Suddenly, downloading some free software has become a 5-figure project. Big businesses have lots of ways to ensure that no progress is ever made. If you think any of the above is made up, you've never worked for a big company. From wolfgang.riedel52 at web.de Wed Jul 7 13:00:04 2010 From: wolfgang.riedel52 at web.de (wolfgang.riedel) Date: Wed, 7 Jul 2010 10:00:04 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <28b50375-3331-4717-bb9e-b7f795fe3d76@j4g2000yqh.googlegroups.com> Message-ID: On 20 June, 03:48, Tim Rentsch wrote: > nanothermite911fbibustards > writes: > > Asking whether Lisp is faster than C is like asking why it's > colder in the mountains than it is in the summer. original Karl Valentin would be but yours is in his sense. Wolfgang From ethan at stoneleaf.us Wed Jul 7 13:32:50 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 07 Jul 2010 10:32:50 -0700 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4C34BA42.5030906@stoneleaf.us> Nobody wrote: > On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > >> you should never rely on a floating-point number to have exactly a >> certain value. > > "Never" is an overstatement. There are situations where you can rely > upon a floating-point number having exactly a certain value. It's not much of an overstatement. How many areas are there where you need the number 0.100000000000000005551115123125782702118158340454101562500000000000? If I'm looking for 0.1, I will *never* (except by accident ;) say if var == 0.1: it'll either be <= or >=. By contrast, if I'm dealing with integers I can say if var == 4 because I *know* that there are values that var can hold that are *exactly* 4. Not 3.999999999817263 or 4.0000000019726. ~Ethan~ From g.rodola at gmail.com Wed Jul 7 13:37:56 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Wed, 7 Jul 2010 19:37:56 +0200 Subject: Python 3 - Is PIL/wxPython/PyWin32 supported? In-Reply-To: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> References: <48b86adc-6a55-404d-a4e9-567cfa74e8bd@z10g2000yqb.googlegroups.com> Message-ID: 2010/7/7 durumdara : > Hi! > > I have an environment under Python 2.6 (WinXP). That is based on PIL, > wxPython/PyWin32. > > In the project's pages I see official installer for only PyWin32. > > I don't know that PIL or wxPython supports Python 3 or not. May with > some trick these packages are working. > > Does anybody know about it? > Can I replace my Py2.6 without lost PIL/wxPython? > > Thanks for your help: > ? dd > > -- > http://mail.python.org/mailman/listinfo/python-list No, as of now you just can't. Now that 2.7 is out and is officially declared as the last 2.x release it's likely that there will be a lot more traction in porting such big names to Python 3. --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ > From python at rcn.com Wed Jul 7 14:08:18 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 7 Jul 2010 11:08:18 -0700 (PDT) Subject: Python -- floating point arithmetic References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: On Jul 7, 5:55?am, Mark Dickinson wrote: > On Jul 7, 1:05?pm, david mainzer wrote: > > > > > Dear Python-User, > > > today i create some slides about floating point arithmetic. I used an > > example from > > >http://docs.python.org/tutorial/floatingpoint.html > > > so i start the python shell on my linux machine: > > > dm at maxwell $ python > > Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) > > [GCC 4.3.4] on linux2 > > Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 > > >>> >>> for i in range(10): > > > ... ? ? sum += 0.1 > > ...>>> >>> sum > > 0.99999999999999989 > > > But thats looks a little bit wrong for me ... i must be a number greater > > then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 > > in python ... if i print it. [Mark Dickinson] > So you've identified one source of error here, namely that 0.1 isn't > exactly representable (and you're correct that the value stored > internally is actually a little greater than 0.1). ?But you're > forgetting about the other source of error in your example: when you > do 'sum += 0.1', the result typically isn't exactly representable, so > there's another rounding step going on. ?That rounding step might > produce a number that's smaller than the actual exact sum, and if > enough of your 'sum += 0.1' results are rounded down instead of up, > that would easily explain why the total is still less than 1.0. One key for understanding floating point mysteries is to look at the actual binary sums rather that their approximate representation as a decimal string. The hex() method can make it easier to visualize Mark's explanation: >>> s = 0.0 >>> for i in range(10): ... s += 0.1 ... print s.hex(), repr(s) 0x1.999999999999ap-4 0.10000000000000001 0x1.999999999999ap-3 0.20000000000000001 0x1.3333333333334p-2 0.30000000000000004 0x1.999999999999ap-2 0.40000000000000002 0x1.0000000000000p-1 0.5 0x1.3333333333333p-1 0.59999999999999998 0x1.6666666666666p-1 0.69999999999999996 0x1.9999999999999p-1 0.79999999999999993 0x1.cccccccccccccp-1 0.89999999999999991 0x1.fffffffffffffp-1 0.99999999999999989 Having used hex() to understand representation error (how the binary partial sums are displayed), you can use the Fractions module to gain a better understanding of rounding error introduced by each addition: >>> s = 0.0 >>> for i in range(10): exact = Fraction.from_float(s) + Fraction.from_float(0.1) s += 0.1 actual = Fraction.from_float(s) error = actual - exact print '%-35s%-35s\t%s' % (actual, exact, error) 3602879701896397/36028797018963968 3602879701896397/36028797018963968 0 3602879701896397/18014398509481984 3602879701896397/18014398509481984 0 1351079888211149/4503599627370496 10808639105689191/36028797018963968 1/36028797018963968 3602879701896397/9007199254740992 14411518807585589/36028797018963968 -1/36028797018963968 1/2 18014398509481985/36028797018963968 -1/36028797018963968 5404319552844595/9007199254740992 21617278211378381/36028797018963968 -1/36028797018963968 3152519739159347/4503599627370496 25220157913274777/36028797018963968 -1/36028797018963968 7205759403792793/9007199254740992 28823037615171173/36028797018963968 -1/36028797018963968 2026619832316723/2251799813685248 32425917317067569/36028797018963968 -1/36028797018963968 9007199254740991/9007199254740992 36028797018963965/36028797018963968 -1/36028797018963968 Hope this helps your slides, Raymond From clp2 at rebertia.com Wed Jul 7 14:27:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Jul 2010 11:27:07 -0700 Subject: Python as a scripting language. Alternative to bash script? In-Reply-To: <4C349DB6.8080001@gmail.com> References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> <4C333243.7040205@gmail.com> <4C349DB6.8080001@gmail.com> Message-ID: On Wed, Jul 7, 2010 at 8:31 AM, Michael Torrie wrote: > On 07/06/2010 09:34 PM, Chris Rebert wrote: >> On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie wrote: >>> While it's possible to set up pipes and spawn programs in parallel to >>> operate on the pipes, in practice it's simpler to tell subprocess.Popen >>> to use a shell and then just rely on Bash's very nice syntax for setting >>> up the pipeline. >> >> Until there's a Python variable involved that is, unless you want to >> overlook all the edge cases or do the escaping all by yourself (and >> then pray you did it right). > > Very good point. ?This is a problem that the pipes module suffers from > as well. > > Although we learned in the other thread on escaping SQL statements that > escaping is faster, easier and just as safe as other parameterization > mechanisms. ?Uh huh. > > Back on target, a library similar to pipes that was safe (pipes is not) > and had a pythonic syntax would be cool. ?pipes module works alright, > syntax wise, but it's not a clean syntax. Actually, your original post inspired me to take a crack at writing something like that yesterday: http://rebertia.com/code/subproc_pipelines.py Thoughts anyone? (Written on a whim, so no tests or docs at present.) Cheers, Chris -- http://blog.rebertia.com From victorsubervi at gmail.com Wed Jul 7 14:38:17 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 7 Jul 2010 14:08:17 -0430 Subject: Is This Open To SQL Injection? Message-ID: Hi; I have this code: sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, user, ', %s'.join('%s' * len(col_vals)) cursor.execute(sql, col_vals) Is this open to injection attacks? If so, how correct? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Wed Jul 7 14:52:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 07 Jul 2010 11:52:27 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4C34CCEB.1060901@ixokai.io> On 7/7/10 11:38 AM, Victor Subervi wrote: > Hi; > I have this code: > > sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, > user, ', %s'.join('%s' * len(col_vals)) > cursor.execute(sql, col_vals) First, its always best to be explicit with insert statements. Meaning, don't rely on the underlining structure of a table, as in: INSERT INTO YourRandomTable VALUES ("my", "value", "here"); Instead, do: INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", "value", "here"); > Is this open to injection attacks? If so, how correct? Secondly, I'd say: probably yes. Maybe. You're doing string formatting to construct your SQL, which is where the trouble comes from. Its possible to do safely, but takes exquisite care -- which is why we've been nudging you away from it. But I can't be a whole lot more specific because I can't for the life of me figure out what you're actually doing with it. I can't figure out why you're passing the store and user variables into the SQL statement, instead of just passing them into the .execute as you are supposed to. I.e., cursor.execute(sql, [store, user] + col_vals) or something. It looks like you're sort of trying to get one generic SQL statement which can set some arbitrary number of random columns-- if so, why? I can't picture just what this table layout is or what kind of data it holds to advise better. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From sturlamolden at yahoo.no Wed Jul 7 15:01:09 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:01:09 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On 7 Jul, 11:32, Jonathan Hartley wrote: > Also, > this would solve the pain of Python developers attempting to > redistribute py2exe versions of their programs (i.e. they have to own > a Visual Studio license to legally be able to redistribute the > required C runtime) http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en If this is not sufficient, ask Microsoft for permission or buy a copy of Visual Studio (any will do, you can rebuild Python). I don't understand enough to know why Visual > Studio was chosen instead of MinGW. Can anyone shed any light on that > decision? It the standard C and C++ compiler on Windows. From martin at v.loewis.de Wed Jul 7 15:10:43 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:10:43 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <4C34D133.9060802@v.loewis.de> > Python 3.1.1, file [pymem.h]: > > PyAPI_FUNC(void *) PyMem_Malloc(size_t); > > #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > : malloc((n) ? (n) : 1)) > > The problem with the latter that it seems that it's intended for safety > but does the opposite... Why do you say that? It certainly *does* achieve safety, wrt. to certain errors, specifically: - passing sizes that are out-of-range - supporting malloc(0) on all systems > Perhaps (if it isn't intentional) this is a bug of the oversight type, > that nobody remembered to update the macro? Update in what way? > Except for the problems with file descriptors I think a practical > interim solution for extensions implemented in C could be to just link > the runtime lib statically. For a minimal extension this increased the > size from 8 KiB to 49 KiB. And generally with MS tools the size is > acceptably small. If you think that's fine for your extension module (which may well be the case), go ahead. But then, you could also just link with a different DLL version of the CRT instead. > I think that this would be safe because since the C API has to access > things in the interpreter I think it's a given that all the relevant > functions delegate to shared library (DLL) implementations, but I have > not checked the source code. There are certainly more cases than the ones mentioned so far, in particular the time zone and the locale. The CRT carries global variables for these, so if you set them in the copy of the CRT that Python links with, you won't see the change in your extension module - which may or may not be a problem. > As a more longterm solution, perhaps python.org could make available the > redistributables for various MSVC versions, and then one could introduce > some scheme for indicating the runtime lib dependencies of any given > extension. My preferred long-term solution is to reduce the usage of the C library in CPython as much as reasonable, atleast on Windows. Memory management could directly use the heap functions (or even more directly VirtualAlloc); filenos could be OS handles, and so on. There are probably limitations to what you can achieve, but I think it's worth trying. Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 15:12:14 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:12:14 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: On 7 Jul, 06:54, "Alf P. Steinbach /Usenet" wrote: > PyAPI_FUNC(void *) PyMem_Malloc(size_t); > > #define PyMem_MALLOC(n) ? ? ? ? (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((n) ? (n) : 1)) I was afraid of that :( > Except for the problems with file descriptors I think a practical interim > solution for extensions implemented in C could be to just link the runtime lib > statically. You still have two CRTs linked into the same process. From martin at v.loewis.de Wed Jul 7 15:22:38 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:22:38 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: <4C34D3FE.6000905@v.loewis.de> > I presume this problem would go away if future versions of Python > itself were compiled on Windows with something like MinGW gcc. Also, > this would solve the pain of Python developers attempting to > redistribute py2exe versions of their programs (i.e. they have to own > a Visual Studio license to legally be able to redistribute the > required C runtime) I don't understand enough to know why Visual > Studio was chosen instead of MinGW. Can anyone shed any light on that > decision? sturlamolden has already given the primary reason: Python, traditionally, attempts to use and work with the system vendor's compiler. On Windows, that's MSC. It's typically the one that best knows about platform details that other compilers might be unaware of. In addition, it's also the compiler and IDE that Windows developers (not just Python core people, but also extension developers and embedders) prefer to use, as it has quite good IDE support (in particular debugging and code browsing). Perhaps more importantly, none of the other compilers is really an alternative. GCC in particular cannot build the Win32 extensions, since it doesn't support the COM and ATL C++ features that they rely on (and may not support other MSC extensions, either). So the Win32 extensions must be built with VS, which means Python itself needs to use the same compiler. Likewise important: gcc/mingw is *not* a complete C compiler on Windows. A complete C compiler would have to include a CRT (on Windows); mingw doesn't (cygwin does, but I think you weren't proposing that Python be built for cygwin - you can easily get cygwin Python anyway). Instead, mingw relies on users having a CRT available to them - and this will be a Microsoft one. So even if gcc was used, we would have versioning issues with Microsoft CRTs, plus we would have to rely on target systems including the right CRT, as we couldn't include it in the distribution. HTH, Martin From python at mrabarnett.plus.com Wed Jul 7 15:26:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 20:26:17 +0100 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C34D4D9.4080406@mrabarnett.plus.com> Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) > > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); > >> Is this open to injection attacks? If so, how correct? > > Secondly, I'd say: probably yes. Maybe. You're doing string formatting > to construct your SQL, which is where the trouble comes from. Its > possible to do safely, but takes exquisite care -- which is why we've > been nudging you away from it. > > But I can't be a whole lot more specific because I can't for the life of > me figure out what you're actually doing with it. > > I can't figure out why you're passing the store and user variables into > the SQL statement, instead of just passing them into the .execute as you > are supposed to. I.e., cursor.execute(sql, [store, user] + col_vals) or > something. > > It looks like you're sort of trying to get one generic SQL statement > which can set some arbitrary number of random columns-- if so, why? I > can't picture just what this table layout is or what kind of data it > holds to advise better. > Not only that, there's a missing ")" and the .join is wrong. For example, if 'store' is "STORE", 'user' is "USER" and 'col_vals' has, say, 3 members, then what you get is: insert into personalDataKeys values (STORE, USER, %, %ss, %s%, %ss, %s%, %ss) From sturlamolden at yahoo.no Wed Jul 7 15:32:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:32:11 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> On 7 Jul, 21:12, sturlamolden wrote: > > #define PyMem_MALLOC(n) ? ? ? ? (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((n) ? (n) : 1)) > > I was afraid of that :( Also observe that this macro is very badly written (even illegal) C. Consider what this would do: PyMem_MALLOC(n++) According to Linus Thorvalds using macros like this is not even legal C: http://www.linuxfocus.org/common/src/January2004_linus.html This would be ok, and safe as long as we use the GIL: register Py_ssize_t __pymem_malloc_tmp; #define PyMem_MALLOC(n)\ (__pymem_malloc_tmp = n, (((__pymem_malloc_tmp) < 0 || (__pymem_malloc_tmp) > PY_SSIZE_T_MAX) ? NULL \ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : malloc((__pymem_malloc_tmp) ? (__pymem_malloc_tmp) : 1))) An inline function is a better solution, but not ANSI C standard: inline void *PyMem_MALLOC(Py_ssize_t n) { return (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL : malloc((n) ? (n) : 1)); } From alf.p.steinbach+usenet at gmail.com Wed Jul 7 15:41:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 21:41:09 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34D133.9060802@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: * Martin v. Loewis, on 07.07.2010 21:10: >> Python 3.1.1, file [pymem.h]: >> >> PyAPI_FUNC(void *) PyMem_Malloc(size_t); >> >> #define PyMem_MALLOC(n) (((n)< 0 || (n)> PY_SSIZE_T_MAX) ? NULL \ >> : malloc((n) ? (n) : 1)) >> >> The problem with the latter that it seems that it's intended for safety >> but does the opposite... > > Why do you say that? It certainly *does* achieve safety, wrt. to certain > errors, specifically: > - passing sizes that are out-of-range > - supporting malloc(0) on all systems It uses malloc instead of PyMem_Malloc. malloc may well be different and use a different heap in an extension DLL than in the Python interpreter and other extensions. That's one thing that the docs (rightly) warn you about. >> Perhaps (if it isn't intentional) this is a bug of the oversight type, >> that nobody remembered to update the macro? > > Update in what way? I was guessing that at one time there was no PyMem_Malloc. And that it was introduced to fix Windows-specific problems, but inadvertently without updating the macro. It's just a guess as to reasons why the macro uses malloc directly. >> Except for the problems with file descriptors I think a practical >> interim solution for extensions implemented in C could be to just link >> the runtime lib statically. For a minimal extension this increased the >> size from 8 KiB to 49 KiB. And generally with MS tools the size is >> acceptably small. > > If you think that's fine for your extension module (which may well be > the case), go ahead. I have no comment on that except pointing it out as a somewhat stupid, somewhat evil social inclusion/exclusion argument, talking to the audience. Argh. You're wasting my time. But anyway, 49 KiB is small by today's standards. For example, you get 20 of those in a single MiB, and about 20.000 in a single GiB. > But then, you could also just link with a different > DLL version of the CRT instead. When I wrote "link the runtime lib statically" that was an alternative to the usual link-as-DLL. It wouldn't make sense to link the runtime lib statically as an alternative to linking it statically. As for linking to a different /version/ of the CRT, if you really mean that, I think that's difficult. It's not necessarily impossible, after all there's STLPort. But I think that it must at the very least be rather difficult to do with Microsoft's tools, for otherwise people would have employed that solution before, and so I wouldn't trust the result, and wouldn't waste the time trying. Cheers, - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Wed Jul 7 15:41:52 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 21:41:52 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 07.07.2010 21:12: > On 7 Jul, 06:54, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> PyAPI_FUNC(void *) PyMem_Malloc(size_t); >> >> #define PyMem_MALLOC(n) (((n)< 0 || (n)> PY_SSIZE_T_MAX) ? NULL \ >> : malloc((n) ? (n) : 1)) > > I was afraid of that :( > > > >> Except for the problems with file descriptors I think a practical interim >> solution for extensions implemented in C could be to just link the runtime lib >> statically. > > You still have two CRTs linked into the same process. So? Cheers, - Alf -- blog at From sturlamolden at yahoo.no Wed Jul 7 15:46:29 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:46:29 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: On 7 Jul, 21:41, "Alf P. Steinbach /Usenet" wrote: > > You still have two CRTs linked into the same process. > > So? CRT resources cannot be shared across CRT borders. That is the problem. Multiple CRTs are not a problem if CRT resources are never shared. From martin at v.loewis.de Wed Jul 7 15:47:59 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:47:59 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> Message-ID: <4C34D9EF.1080603@v.loewis.de> > Also observe that this macro is very badly written (even illegal) C. > Consider what this would do: > > PyMem_MALLOC(n++) > > According to Linus Thorvalds using macros like this is not even legal > C: > > http://www.linuxfocus.org/common/src/January2004_linus.html [Please don't use "legal" wrt. programs - it's not "illegal" to violate the language's rules; you don't go to jail when doing so. Linus said "not allowed"] You are misinterpreting that statement. Linus said that the isdigit macro was non-conforming, *and meant that specifically for isdigit()*. That's because the C standard says that isdigit is a function. Under the as-if rule, you may implement it as a macro as long as nobody can tell the difference. However, in the presented implementation, there is a notable difference. However, the C standard is silent wrt. to PyMem_MALLOC, and it certainly allows the definition of macros which use the macro arguments more than once. > This would be ok, and safe as long as we use the GIL: The macro is ok as it stands (minus the issues with multiple heaps). The Python convention is that you clearly recognize PyMem_MALLOC as a macro, so you should know not to pass parameters with side effects. > register Py_ssize_t __pymem_malloc_tmp; > #define PyMem_MALLOC(n)\ > (__pymem_malloc_tmp = n, (((__pymem_malloc_tmp) < 0 || > (__pymem_malloc_tmp) > PY_SSIZE_T_MAX) ? NULL \ > : malloc((__pymem_malloc_tmp) ? > (__pymem_malloc_tmp) : 1))) That would partially defeat the purpose, namely it would require the compiler to put the size into a variable in memory, and possibly prevent optimizations from taking place that rely on constant propagation (depending on how smart the compiler is). Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 15:51:24 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 12:51:24 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: <6f380eb2-8c1f-47b5-b65f-bae91de29c54@x27g2000yqb.googlegroups.com> On 7 Jul, 21:47, "Martin v. Loewis" wrote: > That would partially defeat the purpose, namely it would require the > compiler to put the size into a variable in memory, and possibly prevent > optimizations from taking place that rely on constant propagation > (depending on how smart the compiler is). Also after reading carefully what Linus said, it would still be incorrect if n is a complex expression. So, an inline function is the "correct" one here. From martin at v.loewis.de Wed Jul 7 15:56:36 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 21:56:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: <4C34DBF4.8020606@v.loewis.de> >>> Perhaps (if it isn't intentional) this is a bug of the oversight type, >>> that nobody remembered to update the macro? >> >> Update in what way? > > I was guessing that at one time there was no PyMem_Malloc. And that it > was introduced to fix Windows-specific problems, but inadvertently > without updating the macro. It's just a guess as to reasons why the > macro uses malloc directly. It might indeed be that the function version was introduced specifically for Windows. However, the macro was left intentionally: both for backwards compatibility, and for use inside Python itself. >>> Except for the problems with file descriptors I think a practical >>> interim solution for extensions implemented in C could be to just link >>> the runtime lib statically. [...] > > When I wrote "link the runtime lib statically" that was an alternative > to the usual link-as-DLL. Ok, I lost the thread. When you said "a practical interim solution" you were talking about what problem? I thought the discussion was about the need to link with the same DLL version as Python. > It wouldn't make sense to link the runtime lib statically as an > alternative to linking it statically. However, it would surely make sense to link with a different DLL than the one that Python links with, assuming that would actually work. > As for linking to a different /version/ of the CRT, if you really mean > that, I think that's difficult. It's not necessarily impossible, after > all there's STLPort. But I think that it must at the very least be > rather difficult to do with Microsoft's tools, for otherwise people > would have employed that solution before, and so I wouldn't trust the > result, and wouldn't waste the time trying. It's actually straight-forward (or used to be, until they came up with the SxS madness). It was actually the case that people did so unexpectingly, and it seemed to work fine, except that it crashed when passing FILE*. Then we started explaining that mixing CRTs is risky. Regards, Martin From alf.p.steinbach+usenet at gmail.com Wed Jul 7 16:04:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 22:04:36 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: * sturlamolden, on 07.07.2010 21:46: > On 7 Jul, 21:41, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >>> You still have two CRTs linked into the same process. >> >> So? > > CRT resources cannot be shared across CRT borders. That is the > problem. Multiple CRTs are not a problem if CRT resources are never > shared. Yeah, but then we're down to file descriptors, C library locales and such as the remaining problems. Cheers, - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Wed Jul 7 16:07:24 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 22:07:24 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34DBF4.8020606@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Martin v. Loewis, on 07.07.2010 21:56: >>>> Perhaps (if it isn't intentional) this is a bug of the oversight type, >>>> that nobody remembered to update the macro? >>> >>> Update in what way? >> >> I was guessing that at one time there was no PyMem_Malloc. And that it >> was introduced to fix Windows-specific problems, but inadvertently >> without updating the macro. It's just a guess as to reasons why the >> macro uses malloc directly. > > It might indeed be that the function version was introduced specifically > for Windows. However, the macro was left intentionally: both for > backwards compatibility, and for use inside Python itself. > >>>> Except for the problems with file descriptors I think a practical >>>> interim solution for extensions implemented in C could be to just link >>>> the runtime lib statically. > [...] >> >> When I wrote "link the runtime lib statically" that was an alternative >> to the usual link-as-DLL. > > Ok, I lost the thread. When you said "a practical interim solution" > you were talking about what problem? I thought the discussion was > about the need to link with the same DLL version as Python. The main problem that the required MSVC redistributables are not necessarily present on the end user's system. >> It wouldn't make sense to link the runtime lib statically as an >> alternative to linking it statically. > > However, it would surely make sense to link with a different DLL than > the one that Python links with, assuming that would actually work. > >> As for linking to a different /version/ of the CRT, if you really mean >> that, I think that's difficult. It's not necessarily impossible, after >> all there's STLPort. But I think that it must at the very least be >> rather difficult to do with Microsoft's tools, for otherwise people >> would have employed that solution before, and so I wouldn't trust the >> result, and wouldn't waste the time trying. > > It's actually straight-forward (or used to be, until they came up with > the SxS madness). It was actually the case that people did so > unexpectingly, and it seemed to work fine, except that it crashed when > passing FILE*. Then we started explaining that mixing CRTs is risky. Oh. Well then. :-) Cheers, - Alf -- blog at From sturlamolden at yahoo.no Wed Jul 7 16:10:00 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 13:10:00 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: On 7 Jul, 21:47, "Martin v. Loewis" wrote: > However, the C standard is silent wrt. to PyMem_MALLOC, and it certainly > allows the definition of macros which use the macro arguments more than > once. Ok, I knew there was something odd here. PyMem_Malloc is indeed a function, whilst PyMem_MALLOC is a deprecated macro. :) From hobson42 at gmaiil.com Wed Jul 7 16:10:36 2010 From: hobson42 at gmaiil.com (Ian) Date: Wed, 07 Jul 2010 21:10:36 +0100 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4C34DF3C.1040009@gmaiil.com> On 07/07/2010 19:38, Victor Subervi wrote: > Hi; > I have this code: > > sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, > user, ', %s'.join('%s' * len(col_vals)) > cursor.execute(sql, col_vals) > > Is this open to injection attacks? If so, how correct? > TIA, > beno Yes, it is trivially open to injection attacks. What would happen if someone enters the next line into one of your col_vals x,y);DROP DATABASE personalDataKeys; ha ha Your sql statement would be closed early by the semicolon, and the DROP TABLE personalDataKeys is then executed and would cause some unexpected data loss. Things could be more serious - DROP DATABASE mysql; for a mysql installation for example. You must always always every time and without any exceptions what-so-ever, put all and every piece of data that comes from outside the program through the appropriate routine to make whatever has been entered into storable data and not part of the sql statement. In php this is mysql_real_escape_string(). In your favourite language there will be an equivalent. If you miss just one occurrence its like leaving the side window unlocked! Someone will get in one day. Regards Ian p.s. Did I mention that there are no exceptions to the "sanitise every piece of data" rule? From invalid at invalid.invalid Wed Jul 7 16:22:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 20:22:32 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4d0adff2-2362-46dd-92c6-efaff11f3c86@g19g2000yqc.googlegroups.com> <4C34D9EF.1080603@v.loewis.de> Message-ID: On 2010-07-07, Martin v. Loewis wrote: > >> Also observe that this macro is very badly written (even illegal) C. >> Consider what this would do: >> >> PyMem_MALLOC(n++) >> >> According to Linus Thorvalds using macros like this is not even legal >> C: >> >> http://www.linuxfocus.org/common/src/January2004_linus.html > > [Please don't use "legal" wrt. programs - it's not "illegal" to violate > the language's rules; you don't go to jail when doing so. Linus said > "not allowed"] Nonsense. The world "illegal" doesn't mean "you'll go to jail". "Legal" and "illegal" are used to indicate conformance or nonconformace with respect to some set of rules -- be they a programming language standard, FIFA footbal rules, or Forumula 1 technical regulations. It's perfectly standard usage to refer to an "illegal forward pass" in American football, to "illegal tires" used during a race, or to an "illegal operation" in a program. -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!! From lists at cheimes.de Wed Jul 7 16:26:40 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 22:26:40 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: > Yeah, but then we're down to file descriptors, C library locales and such as the > remaining problems. Don't forget errno! Every CRT might have its own errno thread local. I don't know how its handled on Windows but I suspect it suffers from the same problem. Christia From sturlamolden at yahoo.no Wed Jul 7 16:35:33 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 13:35:33 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: mailman.372.1278534414.1673.python-list@python.org Message-ID: On 7 Jul, 22:26, Christian Heimes wrote: > Don't forget errno! Every CRT might have its own errno thread local. I > don't know how its handled on Windows but I suspect it suffers from the > same problem. The Windows API "errno" is GetLastError. But a delinquent CRT might map GetLastError() to other integers. From lists at cheimes.de Wed Jul 7 16:47:24 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 07 Jul 2010 22:47:24 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: > The main problem that the required MSVC redistributables are not necessarily > present on the end user's system. It's not a problem for Python anymore. It took a while to sort all problems out. Martin and other developers have successfully figured out how to install the CRT for system wide and local user installations. A system wide installation installs the CRT in the side by side cache (WinSxS). A local installation keeps the msvcrt90.dll and the Microsoft.VC90.CRT.manifest next to the python.exe. Python extensions no longer embed a manifest so they share the CRT from the python.exe process. In order to ship a standalone exe you have to keep the CRT next to your exe. This should work for py2exe binaries as well. At our company we install our application stack entirely from subversion including Python 2.6.5, Sun JRE and lots of other stuff. This works perfectly fine for us even for servers without the MSVCRT redistributable. Christian From pavlovevidence at gmail.com Wed Jul 7 16:55:38 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jul 2010 13:55:38 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 7, 1:31?am, Paul McGuire wrote: > On Jul 6, 3:30 am, David Cournapeau wrote:> On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > > > One thing that would be very useful is how to maintain something that > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > versions below 2.6 is out of the question for most projects with a > > significant userbase IMHO. As such, the idea of running the python 3 > > warnings is not so useful IMHO - unless it could be made to work > > better for python 2.x < 2.6, but I am not sure the idea even makes > > sense. > > This is exactly how I felt about my support for pyparsing, that I was > trying continue to provide support for 2.3 users, up through 3.x > users, with a single code base. ?(This would actually have been > possible if I had been willing to introduce a performance penalty for > Python 2 users, but performance is such a critical issue for parsing I > couldn't justify it to myself.) ?This meant that I had to constrain my > implementation, while trying to incorporate forward-looking support > features (such as __bool__ and __dir__), which have no effect on older > Python versions, but support additions in newer Pythons. ?I just > couldn't get through on the python-dev list that I couldn't just > upgrade my code to 2.6 and then use 2to3 to keep in step across the > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. > > Here are some of the methods I used: > > - No use of sets. ?Instead I defined a very simple set simulation > using dict keys, which could be interchanged with set for later > versions. > > - No generator expressions, only list comprehensions. > > - No use of decorators. ?BUT, pyparsing includes a decorator method, > traceParseAction, which can be used by users with later Pythons as > @traceParseAction in their own code. > > - No print statements. ?As pyparsing is intended to be an internal > module, it does no I/O as part of its function - it only processes a > given string, and returns a data structure. > > - Python 2-3 compatible exception syntax. ?This may have been my > trickiest step. ?The change of syntax for except from > > ? ? except ExceptionType, ex: > > to: > > ? ? except ExceptionType as ex: > > is completely forward and backward incompatible. ?The workaround is to > rewrite as: > > ? ? except ExceptionType: > ? ? ? ? ex = sys.exc_info()[0] > > which works just fine in 2.x and 3.x. ?However, there is a slight > performance penalty in doing this, and pyparsing uses exceptions as > part of its grammar success/failure signalling and backtracking; I've > used this technique everywhere I can get away with it, but there is > one critical spot where I can't use it, so I have to keep 2 code bases > with slight differences between them. > > - Implement __bool__, followed by __nonzero__ = __bool__. ?This will > give you boolean support for your classes in 2.3-3.1. > > - Implement __dir__, which is unused by old Pythons, but supports > customization of dir() output for your own classes. > > - Implement __len__, __contains__, __iter__ and __reversed__ for > container classes. > > - No ternary expressions. ?Not too difficult really, there are several > well-known workarounds for this, either by careful use of and's and > or's, or using the bool-as-int to return the value from > (falseValue,trueValue)[condition]. > > - Define a version-sensitive portion of your module, to define > synonyms for constants that changed name between versions. ?Something > like: > > ? ? _PY3K = sys.version_info[0] > 2 > ? ? if _PY3K: > ? ? ? ? _MAX_INT = sys.maxsize > ? ? ? ? basestring = str > ? ? ? ? _str2dict = set > ? ? ? ? alphas = string.ascii_lowercase + string.ascii_uppercase > ? ? else: > ? ? ? ? _MAX_INT = sys.maxint > ? ? ? ? range = xrange > ? ? ? ? _str2dict = lambda strg : dict( [(c,0) for c in strg] ) > ? ? ? ? alphas = string.lowercase + string.uppercase > > The main body of my code uses range throughout (for example), and with > this definition I get the iterator behavior of xrange regardless of > Python version. > > In the end I still have 2 source files, one for Py2 and one for Py3, > but there is only a small and manageable number of differences between > them, and I expect at some point I will move forward to supporting Py3 > as my primary target version. ?But personally I think this overall > Python 2-3 migration process is moving along at a decent rate, and I > should be able to make my switchover in another 12-18 months. ?But in > the meantime, I am still able to support all versions of Python NOW, > and I plan to continue doing so (albeit "support" for 2.x versions > will eventually mean "continue to offer a frozen feature set, with > minimal bug-fixing if any"). > > I realize that pyparsing is a simple-minded module in comparison to > others: it is pure Python, so it has no issues with C extensions; it > does no I/O, so print-as-statement vs. print-as-function is not an > issue; and it imports few other modules, so the ones it does have not > been dropped in Py3; and overall it is only a few thousand lines of > code. ?But I just offer this post as a concrete data point in this > discussion. Thanks for the helpful post. However it looks like, other than the except syntax, all of these are things you're already doing to support 2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a little more work than supporting 2.3 and 2.6. We all know that Python is quite successful even with a history of backward-incompatible changes and feature additions and even minor paradigm shifts. What I'm interested in is, what things about the 2 to 3 transition is harder than already exists? >From Paul's post it looks like not as much as you'd think--but as he says it's a pretty simple package. Carl Banks From gnuist006 at gmail.com Wed Jul 7 16:56:39 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 7 Jul 2010 13:56:39 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV Message-ID: "Democracy is sick in the US, government monitors your Internet" http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr Enjoy ..... From gnuist006 at gmail.com Wed Jul 7 16:57:48 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 7 Jul 2010 13:57:48 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV Message-ID: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> "Democracy is sick in the US, government monitors your Internet" http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr Enjoy ..... From 007brendan at gmail.com Wed Jul 7 17:10:57 2010 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 7 Jul 2010 14:10:57 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> > > > One thing that would be very useful is how to maintain something that > > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > > versions below 2.6 is out of the question for most projects with a > > > significant userbase IMHO. As such, the idea of running the python 3 > > > warnings is not so useful IMHO - unless it could be made to work > > > better for python 2.x < 2.6, but I am not sure the idea even makes > > > sense. The entire fact that 3.x was *designed* to be incompatible should tell you that supporting 2.x and 3.x with a single code base is a bad idea, except for the very smallest of projects. This is the point where a project should fork and provide two different versions. From alf.p.steinbach+usenet at gmail.com Wed Jul 7 17:19:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 23:19:13 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Christian Heimes, on 07.07.2010 22:47: >> The main problem that the required MSVC redistributables are not necessarily >> present on the end user's system. > > It's not a problem for Python anymore. It took a while to sort all > problems out. Martin and other developers have successfully figured out > how to install the CRT for system wide and local user installations. A > system wide installation installs the CRT in the side by side cache > (WinSxS). A local installation keeps the msvcrt90.dll and the > Microsoft.VC90.CRT.manifest next to the python.exe. Python extensions no > longer embed a manifest so they share the CRT from the python.exe process. > > In order to ship a standalone exe you have to keep the CRT next to your > exe. This should work for py2exe binaries as well. At our company we > install our application stack entirely from subversion including Python > 2.6.5, Sun JRE and lots of other stuff. This works perfectly fine for us > even for servers without the MSVCRT redistributable. I think you're talking about a different problem. The CRT installed along with CPython works for extensions using the MSVC 9.0 CRT. However developing an extension with MSVC 10 the extension will use the 10.0 CRT, which is not necessarily present on the end user's system. As I see it there are five solutions with different trade-offs: A Already having Visual Studio 2008 (MSVC 9.0), or coughing up the money for an MSDN subscription, or visiting trade shows, so as to obtain that compiler version. -> Not an option for everybody. B Linking the CRT statically. -> Increased size, problems with CRT state such as file descriptors. C Linking the CRT dynamically and bundling the MSVC redistributables with the extension. -> Even more increased size for the download, but smaller total footprint for extensions in sum; same CRT state problems. D Linking the CRT dynamically and providing an optional download and install of the redistributables if they're not present. This would best be done with some support from the Python installation machinery. -> Small nice size for extensions, still same CRT state problems. E As D + a new compiler-independent native code interface that does not carry dependencies on CRT state such as file descriptors, like JNI. -> Really huge effort, and cannot be applied until some new Python version. And I think the clue here is that the CRT state problems can be avoided by careful coding. Hence, for those who cannot do A I think B is a realistic practical option, and D would be nice... Cheers, - Alf -- blog at From tim at bart.johnson.com Wed Jul 7 17:21:56 2010 From: tim at bart.johnson.com (Tim Johnson) Date: Wed, 07 Jul 2010 16:21:56 -0500 Subject: Recommend a MySQLdb Forum References: Message-ID: <8b-dnfRFFKVpcqnRnZ2dnUVZ_vydnZ2d@supernews.com> On 2010-07-07, Philip Semanchuk wrote: > > On Jul 6, 2010, at 3:16 PM, Tim Johnson wrote: > >> Greetings: >> I would appreciate it if some could recommend a MySQLdb forum. > > The one associated the sourceforge project seems like a good bet. > > 1) go here: http://sourceforge.net/projects/mysql-python/ > 2) click support Thanks Philip -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From ncauderan at gmail.com Wed Jul 7 17:30:14 2010 From: ncauderan at gmail.com (norbert) Date: Wed, 7 Jul 2010 14:30:14 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> <20100705153532.210103be@pitrou.net> Message-ID: > Well, you could use an approach like the one suggested here: > > http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-dea... That's nice, thanks. I'll use something like this. Just a thought : I will use "errors=replace" in the call to the encode method to be sure that the logger does not raise any exception. From martin at v.loewis.de Wed Jul 7 17:33:57 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 23:33:57 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: mailman.372.1278534414.1673.python-list@python.org Message-ID: <4C34F2C5.6040404@v.loewis.de> Am 07.07.2010 22:35, schrieb sturlamolden: > On 7 Jul, 22:26, Christian Heimes wrote: > >> Don't forget errno! Every CRT might have its own errno thread local. I >> don't know how its handled on Windows but I suspect it suffers from the >> same problem. > > The Windows API "errno" is GetLastError. But a delinquent CRT might > map GetLastError() to other integers. Please check the source before posting. msvcrt defines errno as _CRTIMP extern int * __cdecl _errno(void); #define errno (*_errno()) where _errno is (see dosmap.c) int * __cdecl _errno(void) { _ptiddata ptd = _getptd_noexit(); if (!ptd) { return &ErrnoNoMem; } else { return ( &ptd->_terrno ); } } where _getptd_noexit returns the CRT's per-thread data (see tidtable.c). So it *is* a mapping to other integers, and, even though it's called dosmap.c, it is maintained because of the (limited) POSIX support in the CRT. In particular, there is a mapping between GetLastError values and errno values that can't be implemented through simple defines (e.g. both ERROR_FILE_NOT_FOUND and ERROR_PATH_NOT_FOUND map to ENOENT). In addition, a standard C implementation can rely on only certain APIs changing errno, which MS perhaps might not be able to guarantee for GetLastError values in exactly the same manner. So with the way the Windows API is defined, a C implementation has no alternative but to be delinquent. Regards, Martin From alf.p.steinbach+usenet at gmail.com Wed Jul 7 17:40:54 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 07 Jul 2010 23:40:54 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: * Alf P. Steinbach /Usenet, on 07.07.2010 23:19: > > However developing an extension with MSVC 10 the extension will use the > 10.0 CRT, which is not necessarily present on the end user's system. > > As I see it there are five solutions with different trade-offs: > > A Already having Visual Studio 2008 (MSVC 9.0), or coughing up the > money for an MSDN subscription, or visiting trade shows, so as to > obtain that compiler version. > -> Not an option for everybody. > > B Linking the CRT statically. > -> Increased size, problems with CRT state such as file descriptors. > > C Linking the CRT dynamically and bundling the MSVC redistributables > with the extension. > -> Even more increased size for the download, but smaller total > footprint for extensions in sum; same CRT state problems. > > D Linking the CRT dynamically and providing an optional download and > install of the redistributables if they're not present. This would > best be done with some support from the Python installation machinery. > -> Small nice size for extensions, still same CRT state problems. > > E As D + a new compiler-independent native code interface that > does not carry dependencies on CRT state such as file descriptors, like > JNI. > -> Really huge effort, and cannot be applied until some new Python version. > > And I think the clue here is that the CRT state problems can be avoided > by careful coding. > > Hence, for those who cannot do A I think B is a realistic practical > option, and D would be nice... Wait... F Possibly, as the docs say, "Developer Studio will throw in a lot of import libraries that you do not really need, adding about 100K to your executable. To get rid of them, use the Project Settings dialog, Link tab, to specify ignore default libraries. Add the correct msvcrtxx.lib to the list of libraries." Can anyone confirm whether this works in practice with MSVC 10? Cheers, - Alf -- blog at From python at lonely-star.org Wed Jul 7 17:48:11 2010 From: python at lonely-star.org (Nathan Huesken) Date: Wed, 7 Jul 2010 17:48:11 -0400 Subject: Storing a callback function as a class member Message-ID: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Hi, I have a class, where I want to store a callback function as a member to access later: class CallbackClass: def setCallback(self,cb): self.cb = cb def callCallback(self, para): self.cb(para) Doing so, I get the error: callbackFunc() takes exactly 1 parameter (2 given) self is given as parameter this way, is it not? How can this be done? Thanks! Nathan From sturlamolden at yahoo.no Wed Jul 7 17:49:43 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 14:49:43 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: mailman.372.1278534414.1673.python-list@python.org <4C34F2C5.6040404@v.loewis.de> Message-ID: On 7 Jul, 23:33, "Martin v. Loewis" wrote: > > The Windows API "errno" is GetLastError. But a delinquent CRT might > > map GetLastError() to other integers. > > Please check the source before posting. msvcrt defines errno as I don't have the source to msvcrt, at least not to my knowledge. From martin at v.loewis.de Wed Jul 7 17:56:04 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 07 Jul 2010 23:56:04 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: mailman.372.1278534414.1673.python-list@python.org <4C34F2C5.6040404@v.loewis.de> Message-ID: <4C34F7F4.3010509@v.loewis.de> Am 07.07.2010 23:49, schrieb sturlamolden: > On 7 Jul, 23:33, "Martin v. Loewis" wrote: > >>> The Windows API "errno" is GetLastError. But a delinquent CRT might >>> map GetLastError() to other integers. >> >> Please check the source before posting. msvcrt defines errno as > > I don't have the source to msvcrt, at least not to my knowledge. If you have Visual Studio, and opted to install the CRT sources, you'll find them in VC/crt/src (or VC7/crt/src, depending on VS version). I'm not 100% sure whether they are included in VS Express as well. Regards, Martin From sturlamolden at yahoo.no Wed Jul 7 17:59:48 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 7 Jul 2010 14:59:48 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C34DBF4.8020606@v.loewis.de> Message-ID: On 7 Jul, 23:19, "Alf P. Steinbach /Usenet" wrote: > ? ?D Linking the CRT dynamically and providing an optional download and > ? ? ?install of the redistributables if they're not present. This would > ? ? ?best be done with some support from the Python installation machinery. > ? ? ?-> Small nice size for extensions, still same CRT state problems. This was a problem for py2exe'd apps before Python 2.6 (i.e. no public download for Visual C++ 2003 runtime files.) But for Visual C++ 2008 and 2010, the CRTs can be downloaded from Microsoft and need not be shipped with the application. http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en http://www.microsoft.com/downloads/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BD512D9E-43C8-4655-81BF-9350143D5867&displaylang=en From python at mrabarnett.plus.com Wed Jul 7 18:00:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 23:00:37 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4C34F905.5020301@mrabarnett.plus.com> Brendan Abel wrote: >>>> One thing that would be very useful is how to maintain something that >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>> versions below 2.6 is out of the question for most projects with a >>>> significant userbase IMHO. As such, the idea of running the python 3 >>>> warnings is not so useful IMHO - unless it could be made to work >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>> sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. This is the point where a > project should fork and provide two different versions. I wouldn't say that 3.x was designed to be incompatible. It was designed to tidy the language, and the incompatibilities are an unfortunate result. From invalid at invalid.invalid Wed Jul 7 18:01:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 22:01:28 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? Message-ID: I'm trying to use python bindings for libconfig. There appear to be three very slightly different bindings: http://code.google.com/p/python-libconfig/ http://wiki.github.com/cnangel/python-libconfig/ http://github.com/azeey/python-libconfig/ I'm using the latter with libconfig 1.4.5 http://www.hyperrealm.com/libconfig/ The python bindings appear to come with test cases, but I can't figure out how to run them. From reading the Python docs, it would appear that this should do something useful, but it doesn't: $ python -m unittest pylibconfig ---------------------------------------------------------------------- Ran 0 tests in 0.000s Trying to run the test script directory doesn't work either: $ python tests/test.py Traceback (most recent call last): File "tests/test.py", line 8, in from x64.pylibconfig import Config ImportError: No module named x64.pylibconfig Importing the module seems to be OK, but creating an instance barfs: Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pylibconfig >>> conf = pylibconfig.Config() *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Where to go from here? -- Grant Edwards grant.b.edwards Yow! Do you like "TENDER at VITTLES"? gmail.com From john at castleamber.com Wed Jul 7 18:04:34 2010 From: john at castleamber.com (John Bokma) Date: Wed, 07 Jul 2010 17:04:34 -0500 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> Message-ID: <87wrt7gd8t.fsf@castleamber.com> John Nagle writes: > Python 3 is a nice cleanup of some legacy syntax issues. But > that's just not enough. Perl 6 is a nice cleanup of Perl 5, Eh, I wouldn't call Perl 6 a "nice cleanup". It's much better to consider it a new language with roots in Perl 5 (amongst others). Or to quote from http://dev.perl.org/perl6/: "Perl 5 and Perl 6 are two languages in the Perl family, but of different lineages." > and look how that went. Ten years on, it's not even mainstream, let > alone dominant. I don't think that's the point of Perl 6 (if one can even say such a thing, that is). Right now, (I) think of Perl 6 as a test bed for features that couldn't be put in Perl 5 in an easy manner. Or (I) think of it as a programming language lab. My best guess is that with coming Christmas there will be a Perl 6 comparable to Python 3. But huge disclaimer: I hardly follow Perl 6 development. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From python at mrabarnett.plus.com Wed Jul 7 18:09:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Jul 2010 23:09:28 +0100 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: <4C34FB18.7040904@mrabarnett.plus.com> Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? > Could you provide a short program which we could run to reproduce the problem? From invalid at invalid.invalid Wed Jul 7 18:12:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 7 Jul 2010 22:12:29 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-07, Grant Edwards wrote: > I'm trying to use python bindings for libconfig. There appear to be > three very slightly different bindings: > > http://code.google.com/p/python-libconfig/ > http://wiki.github.com/cnangel/python-libconfig/ > http://github.com/azeey/python-libconfig/ > > I'm using the latter with libconfig 1.4.5 > > http://www.hyperrealm.com/libconfig/ [...] > Importing the module seems to be OK, but creating an instance barfs: > > Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import pylibconfig > > >>> conf = pylibconfig.Config() > *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Oops. Those Python bindings are for version 1.3.2 of libconfig (which does work). They don't work with the current version of libconfig. I guess it's time to figure out how boost works... -- Grant Edwards grant.b.edwards Yow! ... I think I'd at better go back to my DESK gmail.com and toy with a few common MISAPPREHENSIONS ... From rhodri at wildebst.demon.co.uk Wed Jul 7 18:23:24 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 07 Jul 2010 23:23:24 +0100 Subject: Storing a callback function as a class member References: Message-ID: On Wed, 07 Jul 2010 22:48:11 +0100, Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? rhodri at gnudebst:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class CBClass: ... def set_cb(self, cb): ... self.cb = cb ... def call_cb(self, para): ... self.cb(para) ... >>> def trivial(arg): ... print arg ... >>> c = CBClass() >>> c.set_cb(trivial) >>> c.call_cb("Hello, world") Hello, world Works for me. Which version of Python are you using? -- Rhodri James *-* Wildebeeste Herder to the Masses From emile at fenx.com Wed Jul 7 18:31:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 07 Jul 2010 15:31:48 -0700 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: On 7/7/2010 2:48 PM Nathan Huesken said... > class CallbackClass: > def setCallback(self,cb): > self.cb = cb > > def callCallback(self, para): > self.cb(para) > You'll have to show how you're invoking this -- the following works for me (ie, I don't get an error): class CallbackClass: def setCallback(self,cb): self.cb = cb def callCallback(self, para): self.cb(para) a = CallbackClass() def test(param): return 2*param a.setCallback(test) a.callCallback(3) Emile From tartley at tartley.com Wed Jul 7 18:35:25 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 7 Jul 2010 15:35:25 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> <4C34D3FE.6000905@v.loewis.de> Message-ID: On Jul 7, 8:22?pm, "Martin v. Loewis" wrote: > > I presume this problem would go away if future versions of Python > > itself were compiled on Windows with something like MinGW gcc. Also, > > this would solve the pain of Python developers attempting to > > redistribute py2exe versions of their programs (i.e. they have to own > > a Visual Studio license to legally be able to redistribute the > > required C runtime) I don't understand enough to know why Visual > > Studio was chosen instead of MinGW. Can anyone shed any light on that > > decision? > > sturlamolden has already given the primary reason: Python, > traditionally, attempts to use and work with the system vendor's > compiler. On Windows, that's MSC. It's typically the one that best knows > about platform details that other compilers might be unaware of. > > In addition, it's also the compiler and IDE that Windows developers (not > just Python core people, but also extension developers and embedders) > prefer to use, as it has quite good IDE support (in particular debugging > and code browsing). > > Perhaps more importantly, none of the other compilers is really an > alternative. GCC in particular cannot build the Win32 extensions, since > it doesn't support the COM and ATL C++ features that they rely on (and > may not support other MSC extensions, either). So the Win32 extensions > must be built with VS, which means Python itself needs to use the same > compiler. > > Likewise important: gcc/mingw is *not* a complete C compiler on Windows. > A complete C compiler would have to include a CRT (on Windows); mingw > doesn't (cygwin does, but I think you weren't proposing that Python be > built for cygwin - you can easily get cygwin Python anyway). Instead, > mingw relies on users having a CRT available to > them - and this will be a Microsoft one. So even if gcc was used, we > would have versioning issues with Microsoft CRTs, plus we would have to > rely on target systems including the right CRT, as we couldn't include > it in the distribution. > > HTH, > Martin I see. Thanks very much to both of you for the info, much appreciated. From sturla at molden.no Wed Jul 7 18:55:50 2010 From: sturla at molden.no (sturlamolden) Date: Wed, 7 Jul 2010 15:55:50 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> <4C34D3FE.6000905@v.loewis.de> Message-ID: <7f718cfd-aad3-4e0c-a372-67885a5678ca@i28g2000yqa.googlegroups.com> On 8 Jul, 00:35, Jonathan Hartley wrote: > I see. Thanks very much to both of you for the info, much appreciated. The problem you referred to for py2exe despaired with Python 2.6. For Python 2.5, there was no public download option for msvcr71.dll and msvcp71.dll. There was also the unsolved SxS issue. Thus a license for Visual Studio 2003 was required to distribute py2exe apps for Python 2.5. That is now history. For py2exe apps using Python 2.6, 2.7 or 3.1, you can just ask your clients to install this: http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en http://www.microsoft.com/downloads/details.aspx?familyid=BA9257CA-337F-4B40-8C14-157CFDFFEE4E&displaylang=en There are similar downloads for Visual C++ 2010 run-time files as well. Python 3.2 will probably be built with Visual Studio 2010. From rami.chowdhury at gmail.com Wed Jul 7 19:10:45 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 7 Jul 2010 16:10:45 -0700 Subject: Argh! Name collision! In-Reply-To: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: <201007071610.45700.rami.chowdhury@gmail.com> On Tuesday 06 July 2010 22:42:25 rantingrick wrote: > On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" > +use... at gmail.com> wrote: > > "pyni"! Pronounced like "tiny"! Yay! > > hmm, how's about an alternate spelling... "pyknee", or "pynee", or > "pynie" ... considering those are not taken either? Pynie's taken too -- it's the Python implementation on the Parrot VM. ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From wolfram.hinderer at googlemail.com Wed Jul 7 19:13:25 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Wed, 7 Jul 2010 16:13:25 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> On 7 Jul., 19:32, Ethan Furman wrote: > Nobody wrote: > > On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > > >> you should never rely on a floating-point number to have exactly a > >> certain value. > > > "Never" is an overstatement. There are situations where you can rely > > upon a floating-point number having exactly a certain value. > > It's not much of an overstatement. ?How many areas are there where you > need the number > 0.100000000000000005551115123125782702118158340454101562500000000000? > > If I'm looking for 0.1, I will *never* (except by accident ;) say > > if var == 0.1: > > it'll either be <= or >=. The following is an implementation of a well-known algorithm. Why would you want to replace the floating point comparisons? With what? (This is toy-code.) ##### from random import random def min_cost_path(cost_right, cost_up): """ return minimal cost and its path in a rectangle - going up and right only """ cost = dict() size_x, size_y = max(cost_right) #compute minimal cost cost[0, 0] = 0.0 for x in range(size_x): cost[x + 1, 0] = cost[x, 0] + cost_right[x, 0] for y in range(size_y): cost[0, y + 1] = cost[0, y] + cost_up[0, y] for x in range(size_x): cost[x + 1, y + 1] = min(cost[x, y + 1] + cost_right[x, y + 1], cost[x + 1, y] + cost_up[x + 1, y]) #compute path (reversed) x = size_x y = size_y path = [] while x != 0 and y != 0: if x == 0: y -= 1 path.append("u") elif y == 0: x -= 1 path.append("r") elif cost[x - 1, y] + cost_right[x - 1, y] == cost[x, y]: # fp compare x -= 1 path.append("r") elif cost[x, y - 1] + cost_up[x, y - 1] == cost[x, y]: # fp compare y -= 1 path.append("u") else: raise ValueError return cost[size_x, size_y], "".join(reversed(path)) if __name__ == "__main__": size = 100 cost_right = dict(((x, y), random()) for x in range(size) for y in range(size)) cost_up = dict(((x, y), random()) for x in range(size) for y in range(size)) print min_cost_path(cost_right, cost_up) From python at mrabarnett.plus.com Wed Jul 7 19:36:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jul 2010 00:36:51 +0100 Subject: Argh! Name collision! In-Reply-To: <201007071610.45700.rami.chowdhury@gmail.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> <201007071610.45700.rami.chowdhury@gmail.com> Message-ID: <4C350F93.2040207@mrabarnett.plus.com> Rami Chowdhury wrote: > On Tuesday 06 July 2010 22:42:25 rantingrick wrote: >> On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" > >> +use... at gmail.com> wrote: >>> "pyni"! Pronounced like "tiny"! Yay! >> hmm, how's about an alternate spelling... "pyknee", or "pynee", or >> "pynie" ... considering those are not taken either? > > Pynie's taken too -- it's the Python implementation on the Parrot VM. > "PyNatInt" gets no hits on Google. From kedra.marbun at gmail.com Wed Jul 7 19:42:26 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Wed, 7 Jul 2010 16:42:26 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> Message-ID: <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> On Jul 7, 2:46?am, Bruno Desthuilliers wrote: > Gregory Ewing a ?crit : > > > Bruno Desthuilliers wrote: > >> kedra marbun a ?crit : > > >>> if we limit our discussion to py: > >>> why __{get|set|delete}__ don't receive the 'name' & 'class' from > >>> __{getattribute|{set|del}attr}__ > >>> 'name' is the name that is searched > > >> While it would have been technically possible, I fail to imagine any use > >> case for this. > > > I think he wants to have generic descriptors that are > > shared between multiple attributes, but have them do > > different things based on the attribute name. > > I already understood this, but thanks !-) > > What I dont understand is what problem it could solve that couldn't be > solved more simply using the either _getattr__ hook or hand-coded > delegation, since such a descriptor would be so tightly coupled to the > host class that it just doesn't make sense writing a descriptor for this. yeah, i finally can agree descriptor isn't supposed to be used as delegation in general, it should be the job of __getattr__ however i still think passing name would open up some other possibilities of use (not necessarily on the basis of sharing descriptor), surely some of them (all of it?) are bad. sure as hell, my example is an example of bad use. for now, i conclude that passing name is too risky, it easily allows bad practices particularly against the law of Demeter thanks Bruno btw, is there a common approach to let the interface of a class that uses __getattr__, to include names that are delegated? class A: def do_this(self): ... class B: a = A() def do_that(self): ... def __getattr__(self, name): try: return types.MethodType(getattr(self.a, name), self) except AttributeError: raise AttributeError how to make 'dir(B)' includes 'do_this', do i have to use __dir__? and if i use __dir__, somewhat 'help(B)' doesn't work as usual, i haven't check pydoc.py ;) From cousinstanley at gmail.com Wed Jul 7 19:46:13 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 7 Jul 2010 23:46:13 +0000 (UTC) Subject: Getting pyparsing to backtrack References: <4c325a88$0$1672$742ec2ed@news.sonic.net> Message-ID: > I'm working on street address parsing again, > and I'm trying to deal with some of the harder cases. > .... For yet another test case my actual address includes .... ... East South Mountain Avenue Sometimes written as .... ... E. South Mtn Ave -- Stanley C. Kitching Human Being Phoenix, Arizona From alf.p.steinbach+usenet at gmail.com Wed Jul 7 19:47:01 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 01:47:01 +0200 Subject: Argh! Name collision! In-Reply-To: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: * rantingrick, on 07.07.2010 07:42: > On Jul 6, 9:11 pm, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> "pyni"! Pronounced like "tiny"! Yay! > > hmm, how's about an alternate spelling... "pyknee", or "pynee", or > "pynie" ... considering those are not taken either? Hm, for pure shock value I think I'll use the acronym PYthon Native Interface Support. pynis! :-) A set of C++ classes to ease the writing of extensions. Like, // progrock.pynis -- "Python Native Interface Support" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef PYNIS_PTR_H #define PYNIS_PTR_H #include //----------------------------------------- Dependencies: #include #include #include //----------------------------------------- Interface: namespace progrock{ namespace pynis { enum DoAddRef { doAddRef }; class Ptr { private: PyObject* p_; public: Ptr( PyObject* p = 0 ): p_( p ) {} Ptr( PyObject* p, DoAddRef ): p_( p ) { assert( p != 0 ); Py_INCREF( p_ ); } Ptr( Ptr const& other ): p_( other.p_ ) { Py_XINCREF( p_ ); } ~Ptr() { Py_XDECREF( p_ ); } void swapWith( Ptr& other ) { std::swap( p_, other.p_ ); } Ptr& operator=( Ptr other ) { swapWith( other ); return *this; } PyObject* get() const { return p_; } PyObject* release() { PyObject* const result = p_; Py_XDECREF( p_ ); p_ = 0; return result; } }; } } // namespace progrock::pynis #endif Cheers, - Alf (shocked) PS: Darn, forgot to google it. But I think it's unlikely the name's already in use! -- blog at From kedra.marbun at gmail.com Wed Jul 7 19:52:50 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Wed, 7 Jul 2010 16:52:50 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <4c32baec$0$28649$c3e8da3@news.astraweb.com> Message-ID: <4c5d3d09-4cf5-483e-96e2-ce0fade5a471@b4g2000pra.googlegroups.com> On Jul 6, 12:11?pm, Steven D'Aprano wrote: > On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote: > > On Jul 5, 7:49?am, Gregory Ewing wrote: > >> kedra marbun wrote: > >> > now, i'm asking another favor, what about the 2nd point in my 1st > >> > post? > > >> Your original post has dropped off my newsscope, so you'll have to > >> remind me what the 2nd point was. > > >> -- > >> Greg > > > it's like 'name', it's about info that i think should be passed to > > descriptor's __{get|set|delete}__. i wonder what are the reasons for not > > passing the class on which the descriptor is attached to, what pattern > > is encouraged by this? > > Perhaps I'm missing the context, but since the descriptor is passed the > instance, you can easily get the class with type(self) or self.__class__. > There's no need to pass the class as a separate argument. > > -- > Steven no, the class that i meant is the one that actually has the descriptor in its __dict__, not instance.__class__ the class obj that you said unecessary-as-arg is what __get__ receives as the 3rd arg class Desc: def __get__(*args): print(args) class a: v0 = Desc() class b(a): pass b().v0 #(desc, b(), b) From kee at kagi.com Wed Jul 7 20:14:58 2010 From: kee at kagi.com (Kee Nethery) Date: Wed, 7 Jul 2010 17:14:58 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: Yes, you SQL would be trivial to manipulate via SQL injection. Not only do you need to validate each piece of data submitted by a user, you need to escape all the wildcard characters that your database uses. If the text string supplied by a user has quotes or parens or wildcard characters, the text could be interpreted as SQL and that is what you must avoid. Kee Nethery From 007brendan at gmail.com Wed Jul 7 20:26:20 2010 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 7 Jul 2010 17:26:20 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> On Jul 7, 3:00?pm, MRAB wrote: > Brendan Abel wrote: > >>>> One thing that would be very useful is how to maintain something that > >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > >>>> versions below 2.6 is out of the question for most projects with a > >>>> significant userbase IMHO. As such, the idea of running the python 3 > >>>> warnings is not so useful IMHO - unless it could be made to work > >>>> better for python 2.x < 2.6, but I am not sure the idea even makes > >>>> sense. > > > The entire fact that 3.x was *designed* to be incompatible should tell > > you that supporting 2.x and 3.x with a single code base is a bad idea, > > except for the very smallest of projects. ?This is the point where a > > project should fork and provide two different versions. > > I wouldn't say that 3.x was designed to be incompatible. It was designed > to tidy the language, and the incompatibilities are an unfortunate > result. You're missing the point, and arguing semantics. It's a good thing I didn't misspell anything. Python 3.x will continue to change. The incompatibilities between 3.x and 2.x will only become more numerous. If your goal is to support 2.x, and 3.x, you'd be best supporting them separately. From ian.g.kelly at gmail.com Wed Jul 7 20:35:25 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Jul 2010 18:35:25 -0600 Subject: Storing a callback function as a class member In-Reply-To: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: On Wed, Jul 7, 2010 at 3:48 PM, Nathan Huesken wrote: > Hi, > > I have a class, where I want to store a callback function as a member > to access later: > > class CallbackClass: > ? ?def setCallback(self,cb): > ? ? ? ?self.cb = cb > > ? ?def callCallback(self, para): > ? ? ? ?self.cb(para) > > Doing so, I get the error: > callbackFunc() takes exactly 1 parameter (2 given) > > self is given as parameter this way, is it not? How can this be done? No, self will not be passed as a parameter. A function is only treated as a method when it is present in the class dict. If it is in the instance dict as you have above, then it's just a normal function. If you want it to receive self in this case, then you should have your callCallback method pass it in explicitly. HTH, Ian From debatem1 at gmail.com Wed Jul 7 20:54:39 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 20:54:39 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: > On Jul 7, 3:00?pm, MRAB wrote: >> Brendan Abel wrote: >> >>>> One thing that would be very useful is how to maintain something that >> >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >> >>>> versions below 2.6 is out of the question for most projects with a >> >>>> significant userbase IMHO. As such, the idea of running the python 3 >> >>>> warnings is not so useful IMHO - unless it could be made to work >> >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >> >>>> sense. >> >> > The entire fact that 3.x was *designed* to be incompatible should tell >> > you that supporting 2.x and 3.x with a single code base is a bad idea, >> > except for the very smallest of projects. ?This is the point where a >> > project should fork and provide two different versions. >> >> I wouldn't say that 3.x was designed to be incompatible. It was designed >> to tidy the language, and the incompatibilities are an unfortunate >> result. > > You're missing the point, and arguing semantics. ?It's a good thing I > didn't misspell anything. > > Python 3.x will continue to change. ?The incompatibilities between 3.x > and 2.x will only become more numerous. ?If your goal is to support > 2.x, and 3.x, you'd be best supporting them separately. I maintain two projects that have to work from 2.5 to 3.1. On one of them (~5kloc) we took the separate support route, and on the other (~30kloc) I decided to keep a single codebase. IME the maintenance burden on the former is substantially higher than the latter. Is the difference in difficulty perhaps domain-related, or a result of a certain style of coding? Could you give us some more details about what you were working on that caused you to conclude this? Geremy Condra From sridharr at activestate.com Wed Jul 7 21:08:07 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Wed, 07 Jul 2010 18:08:07 -0700 Subject: ANN: ActivePython 2.7.0.1 is now available Message-ID: <4C3524F7.7030005@activestate.com> We are pleased to announce the availability of ActivePython 2.7.0.1. http://www.activestate.com/activepython This release corresponds to the recently released Python 2.7, and, like ActivePython 2.6, includes the Python Package Manager (PyPM) with essential packages such as Distribute (a compatible fork of setuptools), virtualenv, pip and SQLAlchemy. See the release notes for full details: http://docs.activestate.com/activepython/2.7/relnotes.html#changes For a high-level overview of this release, please see our blog post: http://www.activestate.com/blog/2010/07/activepython-27-released This is also the first ActivePython release with 64-bit support on MacOSX. What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6 and 2.7 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business, Enterprise or OEM edition only) - Solaris/x86 (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (Enterprise or OEM edition only) - AIX/PowerPC (Business, Enterprise or OEM edition only) - AIX/PowerPC 64-bit (Business, Enterprise or OEM edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From ben+python at benfinney.id.au Wed Jul 7 21:14:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 11:14:15 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <87tyoabwrc.fsf@benfinney.id.au> geremy condra writes: > On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: > > Python 3.x will continue to change. ?The incompatibilities between > > 3.x and 2.x will only become more numerous. ?If your goal is to > > support 2.x, and 3.x, you'd be best supporting them separately. > > I maintain two projects that have to work from 2.5 to 3.1. On one of > them (~5kloc) we took the separate support route, and on the other > (~30kloc) I decided to keep a single codebase. IME the maintenance > burden on the former is substantially higher than the latter. The point, one more time with feeling, is that the incompatibilities between 2.x and 3.x will *increase* over time. If you now have a code base that is relatively easy to maintain for both Python 2.x and 3.x, that is a result of much back-porting efforts and of a new-feature moratorium that is currently in effect. Enjoy that situation as you may, because it is guaranteed not to last. Indeed, the feature moratorium is designed in part to help slow-moving codebases migrate to Python 3.x before Python resumes its normal pace of change again. If you're choosing to use that time to further entrench codebases for Python 2.x, I think that's a short-sighted choice. Python 2.7 is the last 2.x, no further 3.x features will be back-ported. New 3.x features will begin to appear after the moratorium ends. The combination of those two means that *the single-codebase burden will only increase over time* as Python 3.x diverges further from what Python 2.x can support. -- \ ?Programs must be written for people to read, and only | `\ incidentally for machines to execute.? ?Abelson & Sussman, | _o__) _Structure and Interpretation of Computer Programs_ | Ben Finney From python at mrabarnett.plus.com Wed Jul 7 21:22:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 08 Jul 2010 02:22:13 +0100 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <4C352845.4080709@mrabarnett.plus.com> geremy condra wrote: > On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: >> On Jul 7, 3:00 pm, MRAB wrote: >>> Brendan Abel wrote: >>>>>>> One thing that would be very useful is how to maintain something that >>>>>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>>>>> versions below 2.6 is out of the question for most projects with a >>>>>>> significant userbase IMHO. As such, the idea of running the python 3 >>>>>>> warnings is not so useful IMHO - unless it could be made to work >>>>>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>>>>> sense. >>>> The entire fact that 3.x was *designed* to be incompatible should tell >>>> you that supporting 2.x and 3.x with a single code base is a bad idea, >>>> except for the very smallest of projects. This is the point where a >>>> project should fork and provide two different versions. >>> I wouldn't say that 3.x was designed to be incompatible. It was designed >>> to tidy the language, and the incompatibilities are an unfortunate >>> result. >> You're missing the point, and arguing semantics. It's a good thing I >> didn't misspell anything. >> >> Python 3.x will continue to change. The incompatibilities between 3.x >> and 2.x will only become more numerous. If your goal is to support >> 2.x, and 3.x, you'd be best supporting them separately. > > I maintain two projects that have to work from 2.5 to 3.1. On one of > them (~5kloc) we took the separate support route, and on the other > (~30kloc) I decided to keep a single codebase. IME the maintenance > burden on the former is substantially higher than the latter. Is the > difference in difficulty perhaps domain-related, or a result of a > certain style of coding? Could you give us some more details about > what you were working on that caused you to conclude this? > In my work on the regex module I use a single codebase and generate the sources for Python 2.5-2.7 and for Python 3.1 from it. It works easily enough for me. From fuzzyman at gmail.com Wed Jul 7 21:44:01 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 7 Jul 2010 18:44:01 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> Message-ID: On Jul 5, 1:34?am, sturlamolden wrote: > On 5 Jul, 01:58, John Nagle wrote: > > > ? ? ?Exactly. > > > ? ? ?The "incompatible with all extension modules I need" part > > is the problem right now. ?A good first step would be to > > identify the top 5 or 10 modules that are blocking a move to > > Python 3 by major projects with many users. > > The big danger is Python 2.x becoming abandonware (2.7 being the final > release) before major projects are ported. Using Python 2.x for new > projects is not advisable (at least many will think so), and using 3.x > is not possible. What to do? It's not a helpful situation for Python. But Python 2.3, 2.4 & 2.5 are *already* abandonware and see *major* use in many systems and businesses. Python development has always gone ahead of what *some* people use - and they don't seem to mind that they're using essentially abandoned versions of Python. Now that 2.7 is out I *might* be able to persuade my current company to migrate to 2.6 on the servers, and they're far faster at adopting tech than many companies I know. All the best, Michael Foord -- http://www.voidspace.org.uk From pavlovevidence at gmail.com Wed Jul 7 22:01:49 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 7 Jul 2010 19:01:49 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: On Jul 7, 2:10?pm, Brendan Abel <007bren... at gmail.com> wrote: > > > > One thing that would be very useful is how to maintain something that > > > > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > > > > versions below 2.6 is out of the question for most projects with a > > > > significant userbase IMHO. As such, the idea of running the python 3 > > > > warnings is not so useful IMHO - unless it could be made to work > > > > better for python 2.x < 2.6, but I am not sure the idea even makes > > > > sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. ?This is the point where a > project should fork and provide two different versions. Well, I think it could be a reasonable thing to maintain a single codebase in 2.x and use 2to3 (and/or a custom translator) to translate to 3.x version for quite a while. For the humble library I maintain, I plan to release a Python 3 version as soon as a Python 3 version of numpy is released, maintain a single codebase (translating from 2 version to 3) for awhile, then at some point fork them and maintain them separately. Given that I add features about once every 2 years I don't think it'll be too much of a burden, though. Carl Banks From imageguy1206 at gmail.com Wed Jul 7 22:17:02 2010 From: imageguy1206 at gmail.com (imageguy) Date: Wed, 7 Jul 2010 19:17:02 -0700 (PDT) Subject: Python 2.7 released References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> > I, too, have multiple versions installed -- newer ones for running code > I haven't upgraded; older ones for compatibility testing where needed. > I just install to the default c:\pythonxy directories (although I like > the idea of a common root) and I put NTFS hardlinks into my general > c:\tools directory which is on the path. The out-of-context hardlinks > work because of the registry settings which pick up the correct context > for each version. Sorry to be daft here, but what do you mean by a "hardlink" ? A windows "Shortcut" ? I have just installed 2.7 and want to start upgrading some code, but alas still want to maintain some 2.5 code too. From no.email at nospam.invalid Wed Jul 7 22:27:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 19:27:45 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <7xoceiaese.fsf@ruckus.brouhaha.com> Ben Finney writes: > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. The issue is less the "incompatibilities" than the -backwards- incompatibilities. Yes, Python 3 may introduce forward incompatibilities by adding features absent from Python 2. But it will be possible to maintain a common codebase simply by not using those features. On the other hand, the door appears closed for Python 3 adding more stuff that breaks Python 2 code. From debatem1 at gmail.com Wed Jul 7 22:32:44 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 22:32:44 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: > geremy condra writes: > >> On Wed, Jul 7, 2010 at 8:26 PM, Brendan Abel <007brendan at gmail.com> wrote: >> > Python 3.x will continue to change. ?The incompatibilities between >> > 3.x and 2.x will only become more numerous. ?If your goal is to >> > support 2.x, and 3.x, you'd be best supporting them separately. >> >> I maintain two projects that have to work from 2.5 to 3.1. On one of >> them (~5kloc) we took the separate support route, and on the other >> (~30kloc) I decided to keep a single codebase. IME the maintenance >> burden on the former is substantially higher than the latter. > > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. ...and? I don't get to use features from 2.7, why would I expect to use features from 3.3? > If you now have a code base that is relatively easy to maintain for both > Python 2.x and 3.x, that is a result of much back-porting efforts and of > a new-feature moratorium that is currently in effect. Enjoy that > situation as you may, because it is guaranteed not to last. I have to target the oldest version of Python I want to support. New features are irrelevant. I'm not sure why I should need to explain that to you. > Indeed, the feature moratorium is designed in part to help slow-moving > codebases migrate to Python 3.x before Python resumes its normal pace of > change again. If you're choosing to use that time to further entrench > codebases for Python 2.x, I think that's a short-sighted choice. I welcome the day that I can stop supporting 2.x. Until then, I have to support both and your argument is irrelevant. > Python 2.7 is the last 2.x, no further 3.x features will be back-ported. > New 3.x features will begin to appear after the moratorium ends. The > combination of those two means that *the single-codebase burden will > only increase over time* as Python 3.x diverges further from what Python > 2.x can support. See above. Geremy Condra From alf.p.steinbach+usenet at gmail.com Wed Jul 7 22:42:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 04:42:59 +0200 Subject: Argh! Name collision! In-Reply-To: References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: * Alf P. Steinbach /Usenet, on 08.07.2010 01:47: > > enum DoAddRef { doAddRef }; > > class Ptr > { > private: > PyObject* p_; > > public: > Ptr( PyObject* p = 0 ): p_( p ) > {} > > Ptr( PyObject* p, DoAddRef ): p_( p ) > { > assert( p != 0 ); > Py_INCREF( p_ ); > } > > Ptr( Ptr const& other ): p_( other.p_ ) > { > Py_XINCREF( p_ ); > } > > ~Ptr() > { > Py_XDECREF( p_ ); > } > > void swapWith( Ptr& other ) { std::swap( p_, other.p_ ); } > Ptr& operator=( Ptr other ) { swapWith( other ); return *this; } > > PyObject* get() const { return p_; } > > PyObject* release() > { > PyObject* const result = p_; > Py_XDECREF( p_ ); Hark. This Py_XDECREF shouldn't be there, I don't know how it got there. The whole point of 'release', with conventional semantics, is to /not/ decrement the reference count. > p_ = 0; > return result; > } > }; Sorry for posting unfinished code, - Alf PS: "pyni" was a good name. But in use! When I thought about adding the "s" as disambiguation I thought the pure shock value of that was funny in a way, but now it doesn't seem funny. Is "pytes" (Python Extension Support) a good name? -- blog at From ben+python at benfinney.id.au Wed Jul 7 22:49:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 12:49:23 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> Message-ID: <87pqyybscs.fsf@benfinney.id.au> Paul Rubin writes: > Ben Finney writes: > > The point, one more time with feeling, is that the incompatibilities > > between 2.x and 3.x will *increase* over time. > > The issue is less the "incompatibilities" than the -backwards- > incompatibilities. Yes, that's what I meant. Python 3 is deliberately under no obligation to support code that works in Python 2. If something needs fixing, and that fix would involve breaking Python 2 code, then that's not a consideration any more. The predictable result is that Python 3 will continue to gain backward-incompatible changes in future. > On the other hand, the door appears closed for Python 3 adding more > stuff that breaks Python 2 code. What gives you that idea? Can you reference a specific statement from the PYthon developers that says that? -- \ ?Not to be absolutely certain is, I think, one of the essential | `\ things in rationality.? ?Bertrand Russell | _o__) | Ben Finney From cournape at gmail.com Wed Jul 7 22:50:47 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 04:50:47 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Wed, Jul 7, 2010 at 10:55 PM, Carl Banks wrote: > On Jul 7, 1:31?am, Paul McGuire wrote: >> On Jul 6, 3:30 am, David Cournapeau wrote:> On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: >> >> > One thing that would be very useful is how to maintain something that >> > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >> > versions below 2.6 is out of the question for most projects with a >> > significant userbase IMHO. As such, the idea of running the python 3 >> > warnings is not so useful IMHO - unless it could be made to work >> > better for python 2.x < 2.6, but I am not sure the idea even makes >> > sense. >> >> This is exactly how I felt about my support for pyparsing, that I was >> trying continue to provide support for 2.3 users, up through 3.x >> users, with a single code base. ?(This would actually have been >> possible if I had been willing to introduce a performance penalty for >> Python 2 users, but performance is such a critical issue for parsing I >> couldn't justify it to myself.) ?This meant that I had to constrain my >> implementation, while trying to incorporate forward-looking support >> features (such as __bool__ and __dir__), which have no effect on older >> Python versions, but support additions in newer Pythons. ?I just >> couldn't get through on the python-dev list that I couldn't just >> upgrade my code to 2.6 and then use 2to3 to keep in step across the >> 2-3 chasm, as this would leave behind my faithful pre-2.6 users. >> >> Here are some of the methods I used: >> >> - No use of sets. ?Instead I defined a very simple set simulation >> using dict keys, which could be interchanged with set for later >> versions. >> >> - No generator expressions, only list comprehensions. >> >> - No use of decorators. ?BUT, pyparsing includes a decorator method, >> traceParseAction, which can be used by users with later Pythons as >> @traceParseAction in their own code. >> >> - No print statements. ?As pyparsing is intended to be an internal >> module, it does no I/O as part of its function - it only processes a >> given string, and returns a data structure. >> >> - Python 2-3 compatible exception syntax. ?This may have been my >> trickiest step. ?The change of syntax for except from >> >> ? ? except ExceptionType, ex: >> >> to: >> >> ? ? except ExceptionType as ex: >> >> is completely forward and backward incompatible. ?The workaround is to >> rewrite as: >> >> ? ? except ExceptionType: >> ? ? ? ? ex = sys.exc_info()[0] >> >> which works just fine in 2.x and 3.x. ?However, there is a slight >> performance penalty in doing this, and pyparsing uses exceptions as >> part of its grammar success/failure signalling and backtracking; I've >> used this technique everywhere I can get away with it, but there is >> one critical spot where I can't use it, so I have to keep 2 code bases >> with slight differences between them. >> >> - Implement __bool__, followed by __nonzero__ = __bool__. ?This will >> give you boolean support for your classes in 2.3-3.1. >> >> - Implement __dir__, which is unused by old Pythons, but supports >> customization of dir() output for your own classes. >> >> - Implement __len__, __contains__, __iter__ and __reversed__ for >> container classes. >> >> - No ternary expressions. ?Not too difficult really, there are several >> well-known workarounds for this, either by careful use of and's and >> or's, or using the bool-as-int to return the value from >> (falseValue,trueValue)[condition]. >> >> - Define a version-sensitive portion of your module, to define >> synonyms for constants that changed name between versions. ?Something >> like: >> >> ? ? _PY3K = sys.version_info[0] > 2 >> ? ? if _PY3K: >> ? ? ? ? _MAX_INT = sys.maxsize >> ? ? ? ? basestring = str >> ? ? ? ? _str2dict = set >> ? ? ? ? alphas = string.ascii_lowercase + string.ascii_uppercase >> ? ? else: >> ? ? ? ? _MAX_INT = sys.maxint >> ? ? ? ? range = xrange >> ? ? ? ? _str2dict = lambda strg : dict( [(c,0) for c in strg] ) >> ? ? ? ? alphas = string.lowercase + string.uppercase >> >> The main body of my code uses range throughout (for example), and with >> this definition I get the iterator behavior of xrange regardless of >> Python version. >> >> In the end I still have 2 source files, one for Py2 and one for Py3, >> but there is only a small and manageable number of differences between >> them, and I expect at some point I will move forward to supporting Py3 >> as my primary target version. ?But personally I think this overall >> Python 2-3 migration process is moving along at a decent rate, and I >> should be able to make my switchover in another 12-18 months. ?But in >> the meantime, I am still able to support all versions of Python NOW, >> and I plan to continue doing so (albeit "support" for 2.x versions >> will eventually mean "continue to offer a frozen feature set, with >> minimal bug-fixing if any"). >> >> I realize that pyparsing is a simple-minded module in comparison to >> others: it is pure Python, so it has no issues with C extensions; it >> does no I/O, so print-as-statement vs. print-as-function is not an >> issue; and it imports few other modules, so the ones it does have not >> been dropped in Py3; and overall it is only a few thousand lines of >> code. ?But I just offer this post as a concrete data point in this >> discussion. > > Thanks for the helpful post. ?However it looks like, other than the > except syntax, all of these are things you're already doing to support > 2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a > little more work than supporting 2.3 and 2.6. > > We all know that Python is quite successful even with a history of > backward-incompatible changes and feature additions and even minor > paradigm shifts. ?What I'm interested in is, what things about the 2 > to 3 transition is harder than already exists? The 2->3 transition is harder because backward incompatibilities are much more pervasive. In Numpy, adapting the code for python 2.6 was mostly trivial, for example (removing variables named "as" or "with"). For 3.x, it required much more work. The question really is one of cost vs benefit: for any new version of 2.x, supporting it was very useful because new python 2.x would become the default of popular linux distribution, and that's what most casual windows users would get since it was the default download. Python 3.x required much more work, for a much smaller perceived benefit as far as I am concerned (I don't claim to represent anyone but myself here for numpy transition to 3.x). In particular, assuming the main argument of python 3.x is a cleaner language, it evaporates for projects which need to support both 2.x and 3.x projects. Unless you maintain 2 codebases, this means the project code is less clean, not cleaner because of compatibility requirements. As most people I guess, I find discussion about print vs print() completely pointless - certainly, this is the simplest and most trivial change to apply to a codebase. But I think python 3.x needs to bring more tangible advantages to make the cost more bearable. I am hopeful that python 3.4 or 3.5 will have features/improvements which will make this worthwhile, but 3.1, not so much, David From alf.p.steinbach+usenet at gmail.com Wed Jul 7 22:57:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 04:57:13 +0200 Subject: How do I add method dynamically to module using C API? Message-ID: The code below, very much work in progress, just trying things, is C++. Sorry about the formatting, I had to reformat manually for this posting: class Module { private: Ptr p_; public: Module( PyModuleDef const& def ) : p_( ::PyModule_Create( const_cast< PyModuleDef* >( &def ) ) ) { (p_.get() != 0) || cppx::throwX( "Module::: failed" ); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "PyUnicode_FromWideChar failed" ); int const _ = ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ); (_ != -1 ) || cppx::throwX( "PyObject_SetAttrString failed" ); } void setRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef def = { name, f, METH_VARARGS, doc }; Ptr const pyName = ::PyUnicode_FromString( name ); Ptr r = ::PyCFunction_NewEx( &def, p_.get(), pyName.get() ); int const _ = ::PyModule_AddObject( p_.get(), name, r.release() ); (_ != -1 ) || cppx::throwX( "PyModule_AddObject failed" ); } }; Problem: when a routine installed by 'setRoutine' above is called from Python, then it fails with e.g. "SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!" And since things work for a single method when I declare 'def' as 'static', I suspect that means that the function object created by PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? I'm unable to find documentation of PyCFunction_NewEx, and more criticially, I'm unable to find any documented way to turn a C or C++ function into a Python function object? Cheers, - Alf -- blog at From tjreedy at udel.edu Wed Jul 7 23:26:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:26:22 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: On 7/7/2010 5:29 AM, geremy condra wrote: > On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: >> On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >>> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >>>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchu >>>>> I ported two pure C extensions from 2 to 3 and was even able to keep a >>>>> single C codebase. I'd be willing to contribute my experiences to a >>>>> document >>>>> somewhere. (Is there a Wiki?) >>>> Indeed there is: http://wiki.python.org/moin/ >>> Thanks. I don't want to appear ungrateful, but I was hoping for >>> something specific to the 2-to-3 conversion. I guess someone has to >>> start somewhere... >> There is an existing 2to3 and other pages for Python code conversion. I do >> not know of any for CAPI conversion. The need for such has been acknowledged >> among the devs but if there is nothing yet, we need someone with specialized >> experience and a bit of time to make a first draft. If you start one, give >> it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from >> the 2to3 pag >> In his post on this thread, Martin Loewis volunteered to list what he knows >> from psycopg2 if someone else will edit. > I'm not sure why I don't have this post, but I'm happy to help edit > etc if Martin > wants to put together a rough draft. Since I wrote that, someone pointed out the the Python How-to collection includes Porting Extension Modules to 3.0 by Benjamim Peterson. So all Pyilip or Martin need to do is read that and suggest additions. Since it is part of the doc set, I presume an issue could be opened on the tracker. -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Jul 7 23:32:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 13:32:03 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <87lj9mbqdo.fsf@benfinney.id.au> geremy condra writes: > On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: > > [backward-]incompatibilities between 2.x and 3.x will *increase* > > over time. > > ...and? I don't get to use features from 2.7, why would I expect to > use features from 3.3? Conversely, why would you support Python 3.1? > > Indeed, the feature moratorium is designed in part to help > > slow-moving codebases migrate to Python 3.x before Python resumes > > its normal pace of change again. If you're choosing to use that time > > to further entrench codebases for Python 2.x, I think that's a > > short-sighted choice. > > I welcome the day that I can stop supporting 2.x. Until then, I have > to support both and your argument is irrelevant. Why do you have to support Python 3 at all? Will you expect to continue maintaining a single code base that supports PYthon 2.x and Python 3.2, then 3.3, and so on? The only point being made here is to answer the question of why people are saying that a single code base for both 2.x and 3.x is a maintenance burden. If, in your case, at the present time, that's not the case, then good for you! But it will get increasingly harder to do, and the reasons why have now been explained. Apply them as you see fit. -- \ ?I'm a born-again atheist.? ?Gore Vidal | `\ | _o__) | Ben Finney From zooko at zooko.com Wed Jul 7 23:41:29 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 21:41:29 -0600 Subject: Python -- floating point arithmetic In-Reply-To: <4C346DA0.1070708@tu-clausthal.de> References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: I'm starting to think that one should use Decimals by default and reserve floats for special cases. This is somewhat analogous to the way that Python provides arbitrarily-big integers by default and Python programmers only use old-fashioned fixed-size integers for special cases, such as interoperation with external systems or highly optimized pieces (in numpy or in native extension modules, for example). Floats are confusing. I've studied them more than once over the years but I still can't really predict confidently what floats will do in various situations. And most of the time (in my experience) the inputs and outputs to your system and the literals in your code are actually decimal, so converting them to float immediately introduces a lossy data conversion before you've even done any computation. Decimal doesn't have that problem. >From now on I'll probably try to use Decimals exclusively in all my new Python code and switch to floats only if I need to interoperate with an external system that requires floats or I have some tight inner loop that needs to be highly optimized. Regards, Zooko From cournape at gmail.com Wed Jul 7 23:42:19 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 05:42:19 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C34D133.9060802@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: On Wed, Jul 7, 2010 at 9:10 PM, Martin v. Loewis wrote: > > My preferred long-term solution is to reduce the usage of the C library > in CPython as much as reasonable, atleast on Windows. Memory management > could directly use the heap functions (or even more directly > VirtualAlloc); filenos could be OS handles, and so on. There are > probably limitations to what you can achieve, but I think it's worth trying. I saw you already mentioned work toward this a few months (years ?) ago. Is there some kind of roadmap, or could you use some help ? I would really like to solve this issue as much as we possibly can, David From tjreedy at udel.edu Wed Jul 7 23:44:58 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:44:58 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On 7/7/2010 4:31 AM, Paul McGuire wrote: [snip interesting report on how Paul suppost pyparsing for 2.3 to 3.1] Thank you for this. Do you think such cross-version support would have been easier or harder if the major changes and deletions in 3.0 has been spread over several versions, such as 2.5 - 2.7. In other words, suppose the Python 3 idea never occurred to anyone and 2.5 dropped the old int division and finished the unification of int and long. 2.6 dropped classic classes and switched range, filter, and map to their iterator versions. 2.7 made unicode the text type This is not purely a hypothetical question since the issue of spreading or bunching changes may arise again in the future. -- Terry Jan Reedy From no.email at nospam.invalid Wed Jul 7 23:49:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Jul 2010 20:49:42 -0700 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> <87pqyybscs.fsf@benfinney.id.au> Message-ID: <7x4ogapr8p.fsf@ruckus.brouhaha.com> Ben Finney writes: >> On the other hand, the door appears closed for Python 3 adding more >> stuff that breaks Python 2 code. > > What gives you that idea? Can you reference a specific statement from > the PYthon developers that says that? It's just logic. As I understand it, future versions of Python 3 are supposed to not break programs that work under current versions of Python 3. So any Python 2 program that is a valid Python 3 program today has to stay valid. From debatem1 at gmail.com Wed Jul 7 23:52:13 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 7 Jul 2010 23:52:13 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87lj9mbqdo.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <87lj9mbqdo.fsf@benfinney.id.au> Message-ID: On Wed, Jul 7, 2010 at 11:32 PM, Ben Finney wrote: > geremy condra writes: > >> On Wed, Jul 7, 2010 at 9:14 PM, Ben Finney wrote: >> > [backward-]incompatibilities between 2.x and 3.x will *increase* >> > over time. >> >> ...and? I don't get to use features from 2.7, why would I expect to >> use features from 3.3? > > Conversely, why would you support Python 3.1? Because in 10 years the percentage of people who have Python 2.x installed will be the same as the percentage that have Python 1.x installed today. >> > Indeed, the feature moratorium is designed in part to help >> > slow-moving codebases migrate to Python 3.x before Python resumes >> > its normal pace of change again. If you're choosing to use that time >> > to further entrench codebases for Python 2.x, I think that's a >> > short-sighted choice. >> >> I welcome the day that I can stop supporting 2.x. Until then, I have >> to support both and your argument is irrelevant. > > Why do you have to support Python 3 at all? See above. > Will you expect to continue > maintaining a single code base that supports PYthon 2.x and Python 3.2, > then 3.3, and so on? Yes, with the occasional feature or bugfix. Is there an alternate interpretation I'm missing? > The only point being made here is to answer the question of why people > are saying that a single code base for both 2.x and 3.x is a maintenance > burden. If, in your case, at the present time, that's not the case, then > good for you! But it will get increasingly harder to do, and the reasons > why have now been explained. Apply them as you see fit. I see you stating that it will become harder but I don't see why that should be the case. Geremy Condra From tjreedy at udel.edu Wed Jul 7 23:52:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Jul 2010 23:52:27 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: On 7/7/2010 9:14 PM, Ben Finney wrote: > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. For the purpose of maintaining least-common-denominator multi-version code, it is only deletions and semantic changes that matter. Feature additions will be more common, at least for awhile. The problem of backporting 3.x code that uses 3.x features definitely will increase. -- Terry Jan Reedy From cournape at gmail.com Thu Jul 8 00:04:33 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Jul 2010 06:04:33 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Thu, Jul 8, 2010 at 5:41 AM, Zooko O'Whielacronx wrote: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. > > This is somewhat analogous to the way that Python provides > arbitrarily-big integers by default and Python programmers only use > old-fashioned fixed-size integers for special cases, such as > interoperation with external systems or highly optimized pieces (in > numpy or in native extension modules, for example). I don't think it is analogous at all. Arbitrary-bit integers have a simple tradeoff: you are willing to lose performance and memory for bigger integer. If you leave performance aside, there is no downside that I know of for using big int instead of "machine int". Since you are using python, you already bought this kind of tradeoff anyway. Decimal vs float is a different matter altogether: decimal has downsides compared to float. First, there is this irreconcilable fact that no matter how small your range is, it is impossible to represent exactly all (even most) numbers exactly with finite memory - float and decimal are two different solutions to this issue, with different tradeoffs. Decimal are more "intuitive" than float for numbers that can be represented as decimal - but most numbers cannot be represented as (finite) decimal. Except for some special usecases, you cannot expect to exactly represent real numbers. Once you accept that fact, you can make a decision on decimal, fraction, float or whatever format you see fit. > And most of the time (in my experience) the inputs and outputs to your > system and the literals in your code are actually decimal, so > converting them to float immediately introduces a lossy data > conversion before you've even done any computation. Decimal doesn't > have that problem. That's not true anymore once you start doing any computation, if by decimal you mean finite decimal. And that will be never true once you start using non trivial computation (i.e. transcendental functions like log, exp, etc...). David From zooko at zooko.com Thu Jul 8 00:07:10 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 22:07:10 -0600 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: Dear Paul McGuire: Thank you very much for these notes! See also a few other notes: Michael Foord: http://www.voidspace.org.uk/python/weblog/arch_d7_2010_03_20.shtml#e1167 Ned Batchelder: http://nedbatchelder.com/blog/200910/running_the_same_code_on_python_2x_and_3x.html I was wondering if it would be useful to have a library that implements these hacks so that people like me who prefer to maintain a single codebase instead of using a tool like 2to3 could easily adopt them. Oh look! Here is one: http://pybites.blogspot.com/2010/06/six-python-23-compatibility-helpers.html :-) Regards, Zooko From tjreedy at udel.edu Thu Jul 8 00:11:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Jul 2010 00:11:54 -0400 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87pqyybscs.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <7xoceiaese.fsf@ruckus.brouhaha.com> <87pqyybscs.fsf@benfinney.id.au> Message-ID: On 7/7/2010 10:49 PM, Ben Finney wrote: > Yes, that's what I meant. Python 3 is deliberately under no obligation > to support code that works in Python 2. If something needs fixing, and > that fix would involve breaking Python 2 code, then that's not a > consideration any more. Code that works in 3.1 *is* 3.1 code. Leaving aside bug fixes and additions that makes code that once raised an exception do something instead, I do not know that 3.1 broke and 3.0 code and I do not know of any deprecations in 3.1 that will become removals in 3.2. > The predictable result is that Python 3 will continue to gain > backward-incompatible changes in future. For the core syntax, not too likely. In any case, the usually 3 version pending-deprecation, deprecation, removal process would apply. Some of the library modules that do not work well for 3.1 will see more changes. >> On the other hand, the door appears closed for Python 3 adding more >> stuff that breaks Python 2 code. > > What gives you that idea? Can you reference a specific statement from > the PYthon developers that says that? 3.0 was stated to be a special case. I will let you look. -- Terry Jan Reedy From martin at v.loewis.de Thu Jul 8 00:46:15 2010 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 08 Jul 2010 06:46:15 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> Message-ID: <4C355817.1010105@v.loewis.de> > I saw you already mentioned work toward this a few months (years ?) > ago. Is there some kind of roadmap, or could you use some help ? I > would really like to solve this issue as much as we possibly can, Well, Python 3 has already dropped stdio for its own io library, and I do want to get rid of the remaining FILE* usage for 3.2. Any other change needs to be discussed on python-dev first; contributions are welcome. Regards, Martin From martin at v.loewis.de Thu Jul 8 00:50:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 06:50:34 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4C35591A.2090503@v.loewis.de> Am 07.07.2010 23:10, schrieb Brendan Abel: >>>> One thing that would be very useful is how to maintain something that >>>> works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up >>>> versions below 2.6 is out of the question for most projects with a >>>> significant userbase IMHO. As such, the idea of running the python 3 >>>> warnings is not so useful IMHO - unless it could be made to work >>>> better for python 2.x < 2.6, but I am not sure the idea even makes >>>> sense. > > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. This is the point where a > project should fork and provide two different versions. I completely disagree. My personal experience is that this is well possible even for large code bases, and I would recommend having a single code base for 2.x and 3.x *in particular* for large projects, which probably need to support 2.x users for quite some time, but simultaneously need to support 3.x users. Regards, Martin From michele.simionato at gmail.com Thu Jul 8 00:51:34 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 7 Jul 2010 21:51:34 -0700 (PDT) Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: On Jul 7, 10:55?pm, Carl Banks wrote: > On Jul 7, 1:31?am, Paul McGuire wrote: > > I just > > couldn't get through on the python-dev list that I couldn't just > > upgrade my code to 2.6 and then use 2to3 to keep in step across the > > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. This is a point I do not understand. My recent module plac is meant to work from Python 2.3 to Python 3.1 and to this goal I make use of 2to3 at the *client* side. Users of Python 2.X get the original code with no magic whatsoever; users of Python 3.X get the same code, but at installation time 2to3 is run by the setup.py script. The mechanism requires distribute to be installed, but I would say that having distribute is a must for Python 3.X users; Python 2.X users do not need anything, so the approach is backward compatible. I thought this was the recommended way of using 2to3 and so far is working for me. M. Simionato From martin at v.loewis.de Thu Jul 8 00:52:09 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 06:52:09 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> Message-ID: <4C355979.8080407@v.loewis.de> > Python 3.x will continue to change. The incompatibilities between 3.x > and 2.x will only become more numerous. If your goal is to support > 2.x, and 3.x, you'd be best supporting them separately. I don't think that's a particularly good approach. Having a single code base for both likely reduced the maintenance burden significantly compared to a code fork. Regards, Martin From zooko at zooko.com Thu Jul 8 00:53:20 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Wed, 7 Jul 2010 22:53:20 -0600 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: On Wed, Jul 7, 2010 at 10:04 PM, David Cournapeau wrote: > > Decimal vs float is a different matter altogether: decimal has > downsides compared to float. First, there is this irreconcilable fact > that no matter how small your range is, it is impossible to represent > exactly all (even most) numbers exactly with finite memory - float and > decimal are two different solutions to this issue, with different > tradeoffs. Decimal are more "intuitive" than float for numbers that > can be represented as decimal - but most numbers cannot be represented > as (finite) decimal. This is not a downside of decimal as compared to float, since most numbers also cannot be represented as float. >> And most of the time (in my experience) the inputs and outputs to your >> system and the literals in your code are actually decimal, so >> converting them to float immediately introduces a lossy data >> conversion before you've even done any computation. Decimal doesn't >> have that problem. > > That's not true anymore once you start doing any computation, if by > decimal you mean finite decimal. I don't understand. I described two different problems: problem one is that the inputs, outputs and literals of your program might be in a different encoding (in my experience they have most commonly been in decimal). Problem two is that your computations may be lossy. If the inputs, outputs and literals of your program are decimal (as they have been for most of my programs) then using decimal is better than using float because of problem one. Neither has a strict advantage over the other in terms of problem two. (There is also problem zero, which is that floats more confusing, which is how this thread got started. Problem zero is probably the most important problem for many cases.) > And that will be never true once you > start using non trivial computation (i.e. transcendental functions > like log, exp, etc...). I'm sorry, what will never be true? Are you saying that decimals have a disadvantage compared to floats? If so, what is their disadvantage? (And do math libraries like http://code.google.com/p/dmath/ help ?) Regards, Zooko From martin at v.loewis.de Thu Jul 8 01:01:48 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:01:48 +0200 Subject: The real problem with Python 3 - no business case for conversion In-Reply-To: <87tyoabwrc.fsf@benfinney.id.au> References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> Message-ID: <4C355BBC.7050003@v.loewis.de> > The point, one more time with feeling, is that the incompatibilities > between 2.x and 3.x will *increase* over time. I think this is unfounded, and actually false. Instead, the incompatibilities will *decrease* over the next few years. Suppose you support 2.x and 3.x from a single code base. Today, you might support 2.3 up to 3.1. In a year, you might drop 2.3, and start support 3.2. That will lead to a reduction of incompatibilities: you can start using 2.4 features, and drop work-arounds for 2.3 limitations. Likewise when you then, later, drop 2.4. As a specific example, since 2.5, the modules in the email package are in lower case, in compliance with PEP 8. 2.x has backwards compatibility so that you can continue to use the uppercase module names, which you need for 2.3/2.4 compat. In 3.x, you can't use these spelling anymore, so your code might use try/except as a work-around. When you drop 2.4, you can drop the work-around. > If you now have a code base that is relatively easy to maintain for both > Python 2.x and 3.x, that is a result of much back-porting efforts and of > a new-feature moratorium that is currently in effect. Enjoy that > situation as you may, because it is guaranteed not to last. On the contrary: it's getting better. The back-porting efforts only become available in 2.6, and you would have to support at least 2.5 today (at least, that's how many maintainers feel). Only when you can drop 2.5 support, you can actually start *using* these backport features, allowing you to make the 2.x and 3.x code more similar. Eventually, the difference will get larger again. Hopefully, by that time, 2.7 got out of use. Regards, Martin From martin at v.loewis.de Thu Jul 8 01:13:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:13:54 +0200 Subject: Python 2.7 released In-Reply-To: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C355E92.3060403@v.loewis.de> Am 08.07.2010 04:17, schrieb imageguy: > >> I, too, have multiple versions installed -- newer ones for running code >> I haven't upgraded; older ones for compatibility testing where needed. >> I just install to the default c:\pythonxy directories (although I like >> the idea of a common root) and I put NTFS hardlinks into my general >> c:\tools directory which is on the path. The out-of-context hardlinks >> work because of the registry settings which pick up the correct context >> for each version. > > Sorry to be daft here, but what do you mean by a "hardlink" ? > A windows "Shortcut" ? > No, he means a hardlink (file system level directory entries pointing to the same MFT record number), as created by "fsutil hardlink", "mklink /H", or Cygwin "ln". Regards, Martin From martin at v.loewis.de Thu Jul 8 01:23:15 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:23:15 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: Message-ID: <4C3560C3.8090707@v.loewis.de> > And since things work for a single method when I declare 'def' as > 'static', I suspect that means that the function object created by > PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? Correct; it doesn't make a copy of the struct. So when you want the function object to outlive the setRoutine call, you need to allocate the PyMethodDef on the heap. Regards, Martin From me+list/python at ixokai.io Thu Jul 8 01:30:03 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 07 Jul 2010 22:30:03 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C355817.1010105@v.loewis.de> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C355817.1010105@v.loewis.de> Message-ID: <4C35625B.60606@ixokai.io> On 7/7/10 9:46 PM, "Martin v. L?wis" wrote: >> I saw you already mentioned work toward this a few months (years ?) >> ago. Is there some kind of roadmap, or could you use some help ? I >> would really like to solve this issue as much as we possibly can, > > Well, Python 3 has already dropped stdio for its own io library, and > I do want to get rid of the remaining FILE* usage for 3.2. Any other > change needs to be discussed on python-dev first; contributions are welcome. Really? I wasn't entirely aware of this effect of the "io" module. Somehow, without at all paying attention (because certain third party modules blocking me for awhile, I never looked close enough), I just sort of thought the "io" module was mostly thin wrappers around stdio primitives, into a more Pythonic API. This actually makes me long for Python 3 more. And adjust agendas to push my day-job work to 2.7 as soon as possible, and start a preemptive reconfiguration to support a future Py3k migration. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wuwei23 at gmail.com Thu Jul 8 01:31:43 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 7 Jul 2010 22:31:43 -0700 (PDT) Subject: Is This Open To SQL Injection? References: Message-ID: Stephen Hansen wrote: > You're doing string formatting > to construct your SQL, which is where the trouble comes from. You're wasting your breath, this topic has been discussed ad nauseum with Victor for well over a year now. He appears to be teaching himself relational db based web-development within a paid project and the pressure to produce seems to be greatly overwhelming his need to learn. (Yes, I am aware that I'm a bad evil man because I don't believe that blindly restating the same answer for someone over and over and over is really helping them) From martin at v.loewis.de Thu Jul 8 01:58:18 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 07:58:18 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: <4C3568FA.5030000@v.loewis.de> > I just > couldn't get through on the python-dev list that I couldn't just > upgrade my code to 2.6 and then use 2to3 to keep in step across the > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. Not sure whom you had been talking to. But I would have tried to explain that you don't *have* to port to 2.6 to use 2to3 - it will work just as fine with 2.3 code, and earlier. > - No use of sets. Instead I defined a very simple set simulation > using dict keys, which could be interchanged with set for later > versions. This I don't understand. IIUC, you want to support 2.3 and later. Now, 2.3 already has a set module, even though set is not a builtin. So you could use sets just as well. > - No generator expressions, only list comprehensions. Ok. Not sure how this causes problems, though - just don't use them, then. > - No use of decorators. BUT, pyparsing includes a decorator method, > traceParseAction, which can be used by users with later Pythons as > @traceParseAction in their own code. Of course, users of older Python versions could explicitly wrap the functions with the decorator if they wanted to. > - No print statements. As pyparsing is intended to be an internal > module, it does no I/O as part of its function - it only processes a > given string, and returns a data structure. If you don't need them, fine. If you do, I'd just let 2to3 transform them. > - Python 2-3 compatible exception syntax. This may have been my > trickiest step. The change of syntax for except from > > except ExceptionType, ex: > > to: > > except ExceptionType as ex: > > is completely forward and backward incompatible. The workaround is to > rewrite as: > > except ExceptionType: > ex = sys.exc_info()[0] Likewise, and more importantly so: use 2to3. It can be done this way, but I find the 2to3 solution much cleaner. > But in > the meantime, I am still able to support all versions of Python NOW, > and I plan to continue doing so (albeit "support" for 2.x versions > will eventually mean "continue to offer a frozen feature set, with > minimal bug-fixing if any"). The same would have been possible if you had chosen to use 2to3. Regards, Martin From alf.p.steinbach+usenet at gmail.com Thu Jul 8 02:47:01 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 08:47:01 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: <4C3560C3.8090707@v.loewis.de> References: <4C3560C3.8090707@v.loewis.de> Message-ID: * Martin v. Loewis, on 08.07.2010 07:23: >> And since things work for a single method when I declare 'def' as >> 'static', I suspect that means that the function object created by >> PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure? > > Correct; it doesn't make a copy of the struct. So when you want the > function object to outlive the setRoutine call, you need to allocate > the PyMethodDef on the heap. Thanks! That's the direction I tentatively had started to investigate. But second problem now is cleanup: I'd like to deallocate when the module is freed. I tried (1) adding a __del__, but no dice, I guess because it wasn't really an object method but just a free function in a module; and (2) the m_free callback in the module definition structure, but it was not called. Perhaps I don't need to to clean up? Anyway, current looks like this: // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef CPPY_MODULE_H #define CPPY_MODULE_H #include //----------------------------------------- Dependencies: #include "Ptr.h" #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { namespace detail { inline PyModuleDef* moduleDefPtr() { static PyMethodDef methodDefs[] = { //... //{ "system", &pyni_system, METH_VARARGS, "Execute a shell command." }, //{ "__del__", &onModuleDestroy, METH_NOARGS, "Destructor" }, //... { NULL, NULL, 0, NULL } // Sentinel }; static PyModuleDef moduleDef = { PyModuleDef_HEAD_INIT, "cppy", // name of module NULL, // m_doc, // module documentation in UTF-8 sizeof(void*), // size of per-interpreter state of the module, // or -1 if the module keeps state in global variables. methodDefs, NULL, // m_reload NULL, // m_traverse NULL, // m_clear NULL // m_free }; return &moduleDef; } } class Module { private: struct InstanceData { std::list< PyMethodDef > methodDefs; }; void* instanceMemory() const { void* const result = PyModule_GetState( p_.get() ); assert( result != 0 ); return result; } InstanceData*& instanceDataPtr() const { return *reinterpret_cast< InstanceData** >( instanceMemory() ); } Ptr p_; InstanceData* data_; public: Module() : p_( ::PyModule_Create( detail::moduleDefPtr() ) ) { assert( def.m_size == sizeof( void* ) ); (p_.get() != 0) || cppx::throwX( "Module::: failed" ); instanceDataPtr() = data_ = new InstanceData(); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "Module::setDocString: PyUnicode_FromWideChar failed" ); ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::setDocString: PyObject_SetAttrString failed" ); } void addRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef const defData = { name, f, METH_VARARGS, doc }; data_->methodDefs.push_back( defData ); try { PyMethodDef* pDef = &data_->methodDefs.back(); Ptr const pyName = ::PyUnicode_FromString( name ); Ptr r = ::PyCFunction_NewEx( pDef, p_.get(), pyName.get()); ::PyModule_AddObject( p_.get(), name, r.release() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::addRoutine: PyModule_AddObject failed" ); } catch( ... ) { data_->methodDefs.pop_back(); throw; } } }; } } // namespace progrock::cppy #endif I changed the module name from "pyni*" to "cppy"... ;-) Cheers & thanks!, but how to clean up, or must I? - Alf -- blog at From lavanya.msra at gmail.com Thu Jul 8 02:55:46 2010 From: lavanya.msra at gmail.com (lavanya) Date: Wed, 7 Jul 2010 23:55:46 -0700 (PDT) Subject: Appending to a file using Python API Message-ID: <586afe86-cc9b-4c0b-90ea-64c9ed2a7f26@m40g2000prc.googlegroups.com> Hello all, How do you append to a file using Python os::file APIs. So that it appends to the content of the file. Not adding the content to the new line. But just appends next to the exiting content of the file. Example : current content of file A B C if we append D to it, it should be A B C D Not like: A B C D regards, lavanya From nick_keighley_nospam at hotmail.com Thu Jul 8 03:08:23 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 8 Jul 2010 00:08:23 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> Message-ID: On 7 July, 17:38, Rivka Miller wrote: > Although C comes with a regex library, C does not come with a regexp library > Anyone know what the first initial of L. Peter Deutsch stand for ? Laurence according to wikipedia (search time 2s) From nick_keighley_nospam at hotmail.com Thu Jul 8 03:10:31 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Thu, 8 Jul 2010 00:10:31 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> Message-ID: <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> On 8 July, 08:08, Nick Keighley wrote: > On 7 July, 17:38, Rivka Miller wrote: > > Anyone know what the first initial of L. Peter Deutsch stand for ? > > Laurence according to wikipedia (search time 2s) oops! He was born Laurence but changed it legally to "L." including the dot From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:10:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:10:58 GMT Subject: Appending to a file using Python API References: <586afe86-cc9b-4c0b-90ea-64c9ed2a7f26@m40g2000prc.googlegroups.com> Message-ID: <4c357a01$0$28634$c3e8da3@news.astraweb.com> On Wed, 07 Jul 2010 23:55:46 -0700, lavanya wrote: > Hello all, > > How do you append to a file using Python os::file APIs. So that it > appends to the content of the file. Not adding the content to the new > line. But just appends next to the exiting content of the file. > > Example : current content of file > A B C > if we append D to it, it should be > A B C D > > Not like: > A B C > D f = open("myfile.txt", "a") f.write("D") will append to the end of myfile.txt, regardless of what is already in myfile.txt. If it ends with a newline: "A B C\n" then you will end up with: "A B C\nD" If there is no newline, you will end up with: "A B CD" If you need anything more complicated than that, the easiest solution is something like this: # read the entire file # modify the last line in memory # write the lines back to the file f = open("myfile.txt", "r") lines = f.readlines() f.close() if not lines: # file exists but is empty lines.append('') last_line = lines[-1] last_line = last_line.rstrip() # remove all trailing whitespace if last_line: last_line += " D\n" else: last_line = "D\n" lines[-1] = last_line f = open("myfile.txt", "w") f.writelines(lines) f.close() -- Steven From martin at v.loewis.de Thu Jul 8 03:13:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 08 Jul 2010 09:13:50 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: <4C3560C3.8090707@v.loewis.de> Message-ID: > I tried (1) adding a __del__, but no dice, I guess > because it wasn't really an object method but just a free function in a > module; and (2) the m_free callback in the module definition structure, > but it was not called. m_free will be called if the module object gets deallocated. So if m_free really isn't called, the module got never deallocated. Regards, Martin From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:32:24 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:32:24 GMT Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <4c357f08$0$28634$c3e8da3@news.astraweb.com> On Thu, 08 Jul 2010 06:04:33 +0200, David Cournapeau wrote: > On Thu, Jul 8, 2010 at 5:41 AM, Zooko O'Whielacronx > wrote: >> I'm starting to think that one should use Decimals by default and >> reserve floats for special cases. >> >> This is somewhat analogous to the way that Python provides >> arbitrarily-big integers by default and Python programmers only use >> old-fashioned fixed-size integers for special cases, such as >> interoperation with external systems or highly optimized pieces (in >> numpy or in native extension modules, for example). > > I don't think it is analogous at all. Arbitrary-bit integers have a > simple tradeoff: you are willing to lose performance and memory for > bigger integer. If you leave performance aside, there is no downside > that I know of for using big int instead of "machine int". Well, sure, but that's like saying that if you leave performance aside, there's no downside to Bubblesort instead of Quicksort. However, I believe that in Python at least, the performance cost of arbitrary-sized longs is quite minimal compared to the benefit, at least for "reasonable" sized ints, and so the actual real-world cost of unifying the int and long types is minimal. On the other hand, until Decimal is re-written in C, it will always be *significantly* slower than float. $ python -m timeit "2.0/3.0" 1000000 loops, best of 3: 0.139 usec per loop $ python -m timeit -s "from decimal import Decimal as D" "D(2)/D(3)" 1000 loops, best of 3: 549 usec per loop That's three orders of magnitude difference in speed. That's HUGE, and *alone* is enough to disqualify changing to Decimal as the default floating point data type. Perhaps in the future, if and when Decimal has a fast C implementation, this can be re-thought. > Since you are > using python, you already bought this kind of tradeoff anyway. > > Decimal vs float is a different matter altogether: decimal has downsides > compared to float. First, there is this irreconcilable fact that no > matter how small your range is, it is impossible to represent exactly > all (even most) numbers exactly with finite memory - float and decimal > are two different solutions to this issue, with different tradeoffs. Yes, but how is this a downside *compared* to float? In what way does Decimal have downsides that float doesn't? Neither can represent arbitrary real numbers exactly, but if anything float is *worse* compared to Decimal for two reasons: * Python floats are fixed to a single number of bits, while the size of Decimals can be configured by the user; * floats can represent sums of powers of two exactly, while Decimals can represent sums of powers of ten exactly. Not only does that mean that any number exactly representable as a float can also be exactly represented as a Decimal, but Decimals can *additionally* represent exactly many numbers of human interest that floats cannot. > Decimal are more "intuitive" than float for numbers that can be > represented as decimal - but most numbers cannot be represented as > (finite) decimal. True, but any number that can't be, also can't be exactly represented as a float either, so how does using float help? [...] >> And most of the time (in my experience) the inputs and outputs to your >> system and the literals in your code are actually decimal, so >> converting them to float immediately introduces a lossy data conversion >> before you've even done any computation. Decimal doesn't have that >> problem. > > That's not true anymore once you start doing any computation, if by > decimal you mean finite decimal. And that will be never true once you > start using non trivial computation (i.e. transcendental functions like > log, exp, etc...). But none of those complications are *inputs*, and, again, floats suffer from exactly the same problem. -- Steven From ben+python at benfinney.id.au Thu Jul 8 03:43:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Jul 2010 17:43:11 +1000 Subject: The real problem with Python 3 - no business case for conversion References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> <7f3c9f8c-62ba-4bf2-807e-14489765aebc@7g2000prh.googlegroups.com> <87tyoabwrc.fsf@benfinney.id.au> <4C355BBC.7050003@v.loewis.de> Message-ID: <87hbkaber4.fsf@benfinney.id.au> "Martin v. Loewis" writes: > > The point, one more time with feeling, is that the incompatibilities > > between 2.x and 3.x will *increase* over time. > > I think this is unfounded, and actually false. Since many other people have responded with similar sentiments, I can only think I must have been expressing myself very poorly today. I agree with everything you say here, but it doesn't go against what I've been saying. If I cared about the issue more, I might have another crack at putting my meaning into words; but those who want to support a broad stride of Python versions are more motivated than I to figure it out, so instead I depart the field. -- \ ?People's Front To Reunite Gondwanaland: Stop the Laurasian | `\ Separatist Movement!? ?wiredog, http://kuro5hin.org/ | _o__) | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Thu Jul 8 03:44:47 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 08 Jul 2010 07:44:47 GMT Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <2660dc2d-9a75-453a-9fcf-75feba815673@x20g2000pro.googlegroups.com> Message-ID: <4c3581ef$0$28634$c3e8da3@news.astraweb.com> On Wed, 07 Jul 2010 14:10:57 -0700, Brendan Abel wrote: > The entire fact that 3.x was *designed* to be incompatible should tell > you that supporting 2.x and 3.x with a single code base is a bad idea, > except for the very smallest of projects. I don't see that follows at all. If the incompatibilities are designed to be mechanically translatable (e.g. "x.keys()" -> "list(x.keys())" then you can start with a single code-base and run the translator. If only there were some sort of Python program that could be used to translate code from 2 to 3... *wink* -- Steven From mail at timgolden.me.uk Thu Jul 8 04:07:04 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 08 Jul 2010 09:07:04 +0100 Subject: Python 2.7 released In-Reply-To: <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> References: <901e1b30-6822-4c4e-99ae-cb685879cdf9@a4g2000prm.googlegroups.com> <4c327596$0$28647$c3e8da3@news.astraweb.com> <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C358728.60704@timgolden.me.uk> On 08/07/2010 03:17, imageguy wrote: > >> I, too, have multiple versions installed -- newer ones for running code >> I haven't upgraded; older ones for compatibility testing where needed. >> I just install to the default c:\pythonxy directories (although I like >> the idea of a common root) and I put NTFS hardlinks into my general >> c:\tools directory which is on the path. The out-of-context hardlinks >> work because of the registry settings which pick up the correct context >> for each version. > > Sorry to be daft here, but what do you mean by a "hardlink" ? > A windows "Shortcut" ? > > I have just installed 2.7 and want to start upgrading some code, but > alas still want to maintain some 2.5 code too. Hardlinks have always been present on NTFS, just not very widely advertised. They are a way of saying that *this* file and *that* file are actually the *same* file. (They must be on the same volume as they underlying implementation relies on pointing to the volume's master index -- the MFT). They're not copies: if one changes, the other changes. They're not shortcuts, which are a Shell (ie Desktop) mechanism, not a filesystem one I have hardlinks called python26.exe, python31.exe, etc. which point to c:\python26\python.exe, c:\python31\python.exe etc. and also a python3.exe which is another link to c:\python31\python.exe but which will move when python 3.2 is released. However, this is simply a convenience I use. It's perfectly possible to have and to use several versions of Python concurrently without this. How you do it depends on your working practice: whether you use an IDE or double-click on .py files or run from a cmd window, etc. TJG From animator333 at gmail.com Thu Jul 8 04:21:43 2010 From: animator333 at gmail.com (King) Date: Thu, 8 Jul 2010 01:21:43 -0700 (PDT) Subject: simple python deployment tool Message-ID: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Hi, I am writing a python package deployment tool for linux based platforms. I have tried various existing tool sets but none of them is up to the mark and they have their own issues. Initially I'll start with simple approach. 1. Find all the modules/packages and copy to "lib" directory. 2. Find python's *.so dependencies(system libs) and copy them to "syslib" 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" directory. 4. Set up temp environment 5. Run main script using "python
.py" The idea is to produce a cleaner directory structure. Neither I am creating a boot loader nor I am converting main script file into executable. It's plain vanilla stuff. Using above steps I have pulled down a package using wxPython's demo example "pySketch.py". You can download the archive from here: http://rapidshare.com/files/405255400/dist.zip (Note : It's for linux users.) After extracting the contents, run the executable file using "./run". This file sets temporary environment variables and execute "pySketch.py". I apologize for the archive size as all the systems libs are also included. This is eventually not working. I think I am not able to set up temporary environment properly or may be missing some other stuff. I would appreciate if some one can point out mistakes. Here is the practical approach: /lib (all python libs, files and third party modules.) /syslib (all the system libs. libX*.*, cairo, etc.) python (executable) pySketch.py run.sh Contents of "run.sh". ------------------------------ set LD_LIBRARY_PATH="syslib/" set PYTHONPATH="/lib" python pySketch.py Cheers Prashant From g.rodola at gmail.com Thu Jul 8 04:25:36 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 8 Jul 2010 10:25:36 +0200 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> Message-ID: 2010/7/8 Michele Simionato : > On Jul 7, 10:55?pm, Carl Banks wrote: >> On Jul 7, 1:31?am, Paul McGuire wrote: >> > I just >> > couldn't get through on the python-dev list that I couldn't just >> > upgrade my code to 2.6 and then use 2to3 to keep in step across the >> > 2-3 chasm, as this would leave behind my faithful pre-2.6 users. > > This is a point I do not understand. My recent module plac is meant to > work from Python 2.3 to Python 3.1 and to this goal I make use of 2to3 > at the *client* side. > Users of Python 2.X get the original code with no magic whatsoever; > users of Python 3.X > get the same code, but at installation time 2to3 is run by the > setup.py script. The mechanism requires distribute to be installed, > but I would say that having distribute is a must for Python 3.X users; > Python 2.X users do not need anything, so the approach is backward > compatible. I thought this was the recommended way of using 2to3 and > so far is working for me. > > ? ? ? ? ? ?M. Simionato > -- > http://mail.python.org/mailman/listinfo/python-list > I used the same approach (2.x default code base which gets translated by 2to3 at installation time) and I managed to do this with distutils alone by doing a little hack in setup.py. Take a look at: http://code.google.com/p/psutil/source/browse/tags/release-0.1.3/setup.py#11 Regards, --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From pjb at informatimago.com Thu Jul 8 04:39:45 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Thu, 08 Jul 2010 10:39:45 +0200 Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> Message-ID: <87lj9mfju6.fsf@kuiper.lan.informatimago.com> Nick Keighley writes: > On 8 July, 08:08, Nick Keighley > wrote: >> On 7 July, 17:38, Rivka Miller wrote: > > >> > Anyone know what the first initial of L. Peter Deutsch stand for ? >> >> Laurence according to wikipedia (search time 2s) > > oops! He was born Laurence but changed it legally to "L." including > the dot Too bad, "Laurence" is a nice name. -- __Pascal Bourguignon__ http://www.informatimago.com/ From alf.p.steinbach+usenet at gmail.com Thu Jul 8 04:48:54 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Thu, 08 Jul 2010 10:48:54 +0200 Subject: How do I add method dynamically to module using C API? In-Reply-To: References: <4C3560C3.8090707@v.loewis.de> Message-ID: * Martin v. Loewis, on 08.07.2010 09:13: >> I tried (1) adding a __del__, but no dice, I guess >> because it wasn't really an object method but just a free function in a >> module; and (2) the m_free callback in the module definition structure, >> but it was not called. > > m_free will be called if the module object gets deallocated. So if > m_free really isn't called, the module got never deallocated. Thanks again. I don't know what I did wrong. Now it's called. :-) But I wasted much time googling to try to find out the /responsibilities/ of the m_free callback, and what its void* argument was. E.g., should it deallocate the module object, and if so, via what deallocation routine? I found some info, but even your PEP, otherwise clear, was silent about this fine point. Finally I looked at the source code that invokes it and found that it has no responsibilities whatsoever, just a use-as-you-wish finalization callback. Nice! But I think that could be more clear in the docs... Code, for those who might be interested: // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (C) Alf P. Steinbach, 2010. #ifndef CPPY_MODULE_H #define CPPY_MODULE_H #include //----------------------------------------- Dependencies: #include "Ptr.h" #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { namespace detail { struct InstanceData { std::list< PyMethodDef > methodDefs; }; inline void* instanceMemoryOf( PyObject* pObject ) { void* const result = PyModule_GetState( pObject ); assert( result != 0 ); return result; } inline InstanceData*& instanceDataPtrOf( PyObject* pObject ) { return *reinterpret_cast< InstanceData** >( instanceMemoryOf( pObject ) ); } inline void on_freeModule( void* p ) { PyObject* const pModule = reinterpret_cast< PyObject* >( p ); InstanceData* const pData = instanceDataPtrOf( pModule ); delete pData; printf( "Deallocated!\n" ); // TODO: Remove. } inline PyModuleDef* moduleDefPtr() { static PyMethodDef methodDefs[] = { //... //{ "system", &pyni_system, METH_VARARGS, "Execute a shell command." }, //{ "__del__", &onModuleDestroy, METH_NOARGS, "Destructor" }, //... { NULL, NULL, 0, NULL } // Sentinel }; static PyModuleDef moduleDef = { PyModuleDef_HEAD_INIT, "cppy", // name of module NULL, // m_doc, // module documentation in UTF-8 sizeof(void*), // size of per-interpreter state of the module, // or -1 if the module keeps state in global variables. methodDefs, NULL, // m_reload NULL, // m_traverse NULL, // m_clear &on_freeModule // m_free }; return &moduleDef; } } class Module { private: Ptr p_; detail::InstanceData* data_; detail::InstanceData*& instanceDataPtr() const { return detail::instanceDataPtrOf( p_.get() ); } public: Module() : p_( ::PyModule_Create( detail::moduleDefPtr() ) ) , data_( 0 ) { assert( detail::moduleDefPtr()->m_size == sizeof( void* ) ); (p_.get() != 0) || cppx::throwX( "Module::: failed" ); instanceDataPtr() = data_ = new detail::InstanceData(); } PyObject* rawPtr() const { return p_.get(); } PyObject* release() { return p_.release(); } void setDocString( wchar_t const s[] ) { Ptr const v = ::PyUnicode_FromWideChar( s, -1 ); (v.get() != 0) || cppx::throwX( "Module::setDocString: PyUnicode_FromWideChar failed" ); ::PyObject_SetAttrString( p_.get(), "__doc__", v.get() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::setDocString: PyObject_SetAttrString failed" ); } void addRoutine( char const name[], PyCFunction f, char const doc[] = "" ) { PyMethodDef const defData = { name, f, METH_VARARGS, doc }; data_->methodDefs.push_back( defData ); try { PyMethodDef* const pDef = &data_->methodDefs.back(); Ptr const pyName = ::PyUnicode_FromString( name ); (pyName.get() != 0) || cppx::throwX( "Module::addRoutine: PyUnicode_FromString failed" ); Ptr r = ::PyCFunction_NewEx( pDef, p_.get(), pyName.get()); (r.get() != 0) || cppx::throwX( "Module::addRoutine: PyCFunction_NewEx failed" ); ::PyModule_AddObject( p_.get(), name, r.release() ) >> cppx::is( cppx::notMinusOne ) || cppx::throwX( "Module::addRoutine: PyModule_AddObject failed" ); } catch( ... ) { data_->methodDefs.pop_back(); throw; } } }; } } // namespace progrock::cppy #endif Cheers, - Alf -- blog at From bruno.42.desthuilliers at websiteburo.invalid Thu Jul 8 05:02:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 08 Jul 2010 11:02:47 +0200 Subject: delegation pattern via descriptor In-Reply-To: <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> Message-ID: <4c359425$0$2629$426a74cc@news.free.fr> kedra marbun a ?crit : > On Jul 7, 2:46 am, Bruno Desthuilliers > wrote: >> Gregory Ewing a ?crit : >> >>> Bruno Desthuilliers wrote: >>>> kedra marbun a ?crit : >>>>> if we limit our discussion to py: >>>>> why __{get|set|delete}__ don't receive the 'name' & 'class' from >>>>> __{getattribute|{set|del}attr}__ >>>>> 'name' is the name that is searched >>>> While it would have been technically possible, I fail to imagine any use >>>> case for this. >>> I think he wants to have generic descriptors that are >>> shared between multiple attributes, but have them do >>> different things based on the attribute name. >> I already understood this, but thanks !-) >> >> What I dont understand is what problem it could solve that couldn't be >> solved more simply using the either _getattr__ hook or hand-coded >> delegation, since such a descriptor would be so tightly coupled to the >> host class that it just doesn't make sense writing a descriptor for this. > > yeah, i finally can agree descriptor isn't supposed to be used as > delegation in general, it should be the job of __getattr__ > > however i still think passing name would open up some other > possibilities of use Nothing prevents you to pass a "name" to the descriptor instance when instanciating it, ie: class Desc(object): def __init__(self, name): self.name = name def __get__(self, inst, cls): # ... def __set__(self, inst, value): # ... class Foo(object): bar = Desc("bar") baaz = Desc("baaz") Ok, this is not necessarily what you were looking for, but it's IMHO less brittle than relying on which attribute name was looked up (which is something the descriptor shouldn't have to care about). > > btw, is there a common approach to let the interface of a class that > uses __getattr__, to include names that are delegated? In Python 2.x, not that I know (but it may have passed under my radar). If what you want it to automate delegation of a set of methods without too much manual coding, you can use a custom metaclass that will add the relevant methods to the class, based on (ie) a list (or mapping) of methods names. But that might be a bit overkill. > class A: > def do_this(self): ... > > class B: > a = A() I don't see the point of using delegation on a class attribute. That's typically what inheritance is for. > def do_that(self): ... > > def __getattr__(self, name): > try: > return types.MethodType(getattr(self.a, name), self) Err... Did you try the simple way ? return getattr(self.a, name) From newsuser at stacom-software.de Thu Jul 8 05:08:46 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 11:08:46 +0200 Subject: Howto write XML file with comments? Message-ID: Hello, - I've to write a XML document including comments - the document should be formatted that it could be viewed with a text editor What is the fastest (time for realization) approach doing it in python 2.5? Any help or hints are very welcome Thanks Alexander From alex.kapps at web.de Thu Jul 8 05:21:35 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 08 Jul 2010 11:21:35 +0200 Subject: simple python deployment tool In-Reply-To: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Message-ID: <4C35989F.8040904@web.de> King wrote: > Hi, > > I am writing a python package deployment tool for linux based > platforms. I have tried various existing > tool sets but none of them is up to the mark and they have their own > issues. Initially I'll start with simple approach. I'm sorry, but your approach is not going to work. The Right Way(tm) is to not ship any external libraries, but let the user install the dependencies with the distro's package manager. And to not try to build custom packages, but to let the package maintainers of the different distros package your application for you. > 1. Find all the modules/packages and copy to "lib" directory. > 2. Find python's *.so dependencies(system libs) and copy them to > "syslib" That would include all the way down to libc, your archive is going to be huge, but the actual problem is, what if the libc isn't compatible with the kernel, what if the WX, GTK, X11, etc libraries aren't compatible with the running Xserver? End of the story is, you would need to package a minimal (but almost complete) Linux system into your package, which of course is not want you want. > 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" > directory. > 4. Set up temp environment > 5. Run main script using "python
.py" > > The idea is to produce a cleaner directory structure. Neither I am > creating a boot loader nor I am converting main script > file into executable. It's plain vanilla stuff. It's not vanilla stuff, but a very hard problem. In fact you are fighting against the whole system structure. From stefan_ml at behnel.de Thu Jul 8 05:43:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Jul 2010 11:43:29 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Alexander Eisenhuth, 08.07.2010 11:08: > - I've to write a XML document including comments "write" in the sense of typing in a text editor? Or constructing one programmatically in memory? Or ... ? And what kind of data from what kind of source do you want to put into the document? All of that has an impact on the 'right' answer. > - the document should be formatted that it could be viewed with a text > editor > > What is the fastest (time for realization) approach doing it in python 2.5? If you mean to build an XML document programmatically, potentially using data that you get from somewhere, take a look at cElementTree. There's also a short recipe for pretty printing the tree before writing it out. Stefan From animator333 at gmail.com Thu Jul 8 05:44:00 2010 From: animator333 at gmail.com (King) Date: Thu, 8 Jul 2010 02:44:00 -0700 (PDT) Subject: simple python deployment tool References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> Message-ID: <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> On Jul 8, 2:21?pm, Alexander Kapps wrote: > King wrote: > > Hi, > > > I am writing a python package deployment tool for linux based > > platforms. I have tried various existing > > tool sets but none of them is up to the mark and they have their own > > issues. Initially I'll start with simple approach. > > I'm sorry, but your approach is not going to work. The Right Way(tm) > is to not ship any external libraries, but let the user install the > dependencies with the distro's package manager. And to not try to > build custom packages, but to let the package maintainers ?of the > different distros package your application for you. Yes, you an do this by creating a .deb package that will take care of installing the required libraries. It may possible that either required version is not available in the distro's repository or the one available is older one then required. So best deal would be to ship at least all the python's libs along with your package. > > 1. Find all the modules/packages and copy to "lib" directory. > > 2. Find python's *.so dependencies(system libs) and copy them to > > "syslib" > > That would include all the way down to libc, your archive is going > to be huge, but the actual problem is, what if the libc isn't > compatible with the kernel, what if the WX, GTK, X11, etc libraries > aren't compatible with the running Xserver? You are right here. It seems there is no standard definition of system libraries on linux. To over come the problem of binary compatibility, I am using ubuntu (hardy) which is on glibc 2.7. Every other external python library including python is compiled on hardy. This is would give you maximum chances that libs would be compatible in case if you run on any other distro which is using glibc >=2.7 > End of the story is, you would need to package a minimal (but almost > complete) Linux system into your package, which of course is not > want you want. > > > 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" > > directory. > > 4. Set up temp environment > > 5. Run main script using "python
.py" > > > The idea is to produce a cleaner directory structure. Neither I am > > creating a boot loader nor I am converting main script > > file into executable. It's plain vanilla stuff. > > It's not vanilla stuff, but a very hard problem. In fact you are > fighting against the whole system structure. Ok, forget about system libs(libX*.* etc.), I don't know why it sounds too complicated. I am hoping it should work and eventually it's easier then tools that create an executable using bootloader. The problem is in setting the correct python environment. Prashant From lists at cheimes.de Thu Jul 8 05:48:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jul 2010 11:48:35 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C35625B.60606@ixokai.io> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <4C34D133.9060802@v.loewis.de> <4C355817.1010105@v.loewis.de> <4C35625B.60606@ixokai.io> Message-ID: > Really? I wasn't entirely aware of this effect of the "io" module. > Somehow, without at all paying attention (because certain third party > modules blocking me for awhile, I never looked close enough), I just > sort of thought the "io" module was mostly thin wrappers around stdio > primitives, into a more Pythonic API. Yes, really. :) The new io modules doesn't use stdio. It operates solely on file descriptors and low level functions like open(2) instead of fopen(3). All high level functions like buffering is implemented in Python (and some C for speed). Christian From newsuser at stacom-software.de Thu Jul 8 06:07:16 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 12:07:16 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Stefan Behnel schrieb: > Alexander Eisenhuth, 08.07.2010 11:08: >> - I've to write a XML document including comments > > "write" in the sense of typing in a text editor? Or constructing one > programmatically in memory? Or ... ? write means write to a file > > And what kind of data from what kind of source do you want to put into > the document? Data is present as tags and attributes > > All of that has an impact on the 'right' answer. > > >> - the document should be formatted that it could be viewed with a text >> editor >> >> What is the fastest (time for realization) approach doing it in python >> 2.5? > > If you mean to build an XML document programmatically, potentially using > data that you get from somewhere, take a look at cElementTree. There's > also a short recipe for pretty printing the tree before writing it out. Is the API of cElementTree different from ElementTree in the python standard library? > > Stefan > From greg.ewing at canterbury.ac.nz Thu Jul 8 06:10:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 08 Jul 2010 22:10:48 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> Message-ID: <89llvrFflvU1@mid.individual.net> kedra marbun wrote: > i wonder what are the reasons for > not passing the class on which the descriptor is attached to, what > pattern is encouraged by this? The same answer applies. It's assumed that you will be writing a custom piece of code for each attribute of each class, and giving each one its own descriptor. By the time you get to the get or set method of a descriptor, you've already dispatched on both the class and attribute name. There is not usually any point in funnelling things back into a single function and then dispatching on the class or name again. Passing the class or name would just add overhead that was unnecessary in the majority of use cases. -- Greg From stefan_ml at behnel.de Thu Jul 8 06:26:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Jul 2010 12:26:23 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Alexander Eisenhuth, 08.07.2010 12:07: > Stefan Behnel schrieb: >> Alexander Eisenhuth, 08.07.2010 11:08: >>> - I've to write a XML document including comments >> >> "write" in the sense of typing in a text editor? Or constructing one >> programmatically in memory? Or ... ? > > write means write to a file You seam to imply that it's obvious what you want to do. From the little information that you give us, it's not. >> And what kind of data from what kind of source do you want to put into >> the document? > > Data is present as tags and attributes Whatever that is supposed to mean in this context. >> All of that has an impact on the 'right' answer. ... and it still does. >>> - the document should be formatted that it could be viewed with a text >>> editor >>> >>> What is the fastest (time for realization) approach doing it in >>> python 2.5? >> >> If you mean to build an XML document programmatically, potentially >> using data that you get from somewhere, take a look at cElementTree. >> There's also a short recipe for pretty printing the tree before >> writing it out. > > Is the API of cElementTree different from ElementTree in the python > standard library? Same thing, different import. Note that both were updated in Py2.7, BTW. Stefan From dr.mtarver at ukonline.co.uk Thu Jul 8 06:27:03 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Thu, 8 Jul 2010 03:27:03 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <61bbe9c0-f9e3-4b44-ba09-81435ce4b924@k39g2000yqb.googlegroups.com> On 14 June, 00:07, bolega wrote: > I am trying to compare LISP/Scheme/Python for their expressiveness. > > For this, I propose a vanilla C interpreter. I have seen a book which > writes C interpreter in C. > > The criteria would be the small size and high readability of the code. > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > Bolega Probably you want to look at this thread http://groups.google.co.uk/group/comp.lang.lisp/browse_frm/thread/7b1ab36f5d5cce0a/54afe11153025e27?hl=en&lnk=gst&q=minim#54afe11153025e27 where I specified a toy language Minim (much simpler than C) and the goal was to construct an interpreter for it. Similar problem. Many solutions were given in different languages. The thread is very long. One thing you might look at is whether some sort of lexer/parser is supported in any of your targets. Qi supports a compiler-compiler Qi- YACC that allows you to write in BNF which makes this kind of project much easier. See http://www.lambdassociates.org/Book/page404.htm for an overview Mark From steve at holdenweb.com Thu Jul 8 06:49:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Jul 2010 06:49:51 -0400 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel In-Reply-To: References: Message-ID: <4C35AD4F.6020305@holdenweb.com> Vicky Twomey-Lee wrote: > Hi All, > > Join us for drinks and a chat (a warm-up session to PyCon Ireland ;-) ). > > When: Wed 14th July, from 7pm > Where: Trinity Capital Hotel > > More details at: > http://www.python.ie/meetup/2010/python_ireland_meetup_-_july_2010/ > Hope you all had a good piss-up! See you a week on Saturday. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 DjangoCon US September 7-9, 2010 http://djangocon.us/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From newsuser at stacom-software.de Thu Jul 8 06:54:34 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Thu, 08 Jul 2010 12:54:34 +0200 Subject: Howto write XML file with comments? In-Reply-To: References: Message-ID: Sorry for my little riddle, but you solved it quite good with: - http://effbot.org/zone/element-lib.htm#prettyprint and comments are also in ElementTree (xml.etree.ElementTree.Comment) Thanks Stefan Behnel schrieb: > Alexander Eisenhuth, 08.07.2010 12:07: >> Stefan Behnel schrieb: >>> Alexander Eisenhuth, 08.07.2010 11:08: >>>> - I've to write a XML document including comments >>> >>> "write" in the sense of typing in a text editor? Or constructing one >>> programmatically in memory? Or ... ? >> >> write means write to a file > > You seam to imply that it's obvious what you want to do. From the little > information that you give us, it's not. > > >>> And what kind of data from what kind of source do you want to put into >>> the document? >> >> Data is present as tags and attributes > > Whatever that is supposed to mean in this context. > > >>> All of that has an impact on the 'right' answer. > > ... and it still does. > > >>>> - the document should be formatted that it could be viewed with a text >>>> editor >>>> >>>> What is the fastest (time for realization) approach doing it in >>>> python 2.5? >>> >>> If you mean to build an XML document programmatically, potentially >>> using data that you get from somewhere, take a look at cElementTree. >>> There's also a short recipe for pretty printing the tree before >>> writing it out. >> >> Is the API of cElementTree different from ElementTree in the python >> standard library? > > Same thing, different import. > > Note that both were updated in Py2.7, BTW. > > Stefan > From askutt at gmail.com Thu Jul 8 06:58:27 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 03:58:27 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> On Jul 8, 12:53?am, "Zooko O'Whielacronx" wrote: > I don't understand. I described two different problems: problem one is > that the inputs, outputs and literals of your program might be in a > different encoding (in my experience they have most commonly been in > decimal). Problem two is that your computations may be lossy. If the > inputs, outputs and literals of your program are decimal (as they have > been for most of my programs) then using decimal is better than using > float because of problem one. Neither has a strict advantage over the > other in terms of problem two. I can't think of any program I've ever written where the inputs are actually intended to be decimal. Consider a simple video editing program, and the user specifies a frame rate 23.976 fps. Is that what they really wanted? No, they wanted 24000/1001 but didn't feel like typing that. It should be instructive and telling that mplayer now strongly prefers the rational expressions over the decimal ones. Just because you haven't rounded your input in parsing it doesn't change the fact your input may have be rounded before it was presented to the program, which is the reality of the matter more often than not. Even in fields where the numbers are decimal, like finance, the rules are considerably more complicated than what you were taught in the "schoolbook". This is one of the reasons IBM can still make a killing selling mainframes, they got all of those rules right decades ago. > > And that will be never true once you > > start using non trivial computation (i.e. transcendental functions > > like log, exp, etc...). > > I'm sorry, what will never be true? Are you saying that decimals have > a disadvantage compared to floats? If so, what is their disadvantage? He's saying that once you get past elementary operations, you quickly run into irrational numbers, which you will not be representing accurately. Moreover, in general, it's impossible to even round operations involving transcendental functions to an arbitrary fixed- precision, you may need effectively infinite precision in order to the computation. In practice, this means the error induced by a lossy input conversion (assuming you hadn't already lost information) is entirely negligible compared to inherent inability to do the necessary calculations. From dlanorslegov at rocketmail.com Thu Jul 8 07:30:09 2010 From: dlanorslegov at rocketmail.com (Dlanor Slegov) Date: Thu, 8 Jul 2010 04:30:09 -0700 (PDT) Subject: Writing Out from 2 Lists Message-ID: <37807.88947.qm@web120104.mail.ne1.yahoo.com> Hi, I am trying to find a python solution for an informatics problem I have at work.?Generalized equivalent of my problem is: I have an excel sheet with column 1 and column 2 having corresponding information (much like a dictionary, however with repeating "keys"). Its like if you read down column 1: a,b,a,a,b,c and if you read down column 2: 1,2,3,4,5,6. I would like to write "unique" files such as a.txt, b.txt and c.txt with matching information (from column 2) in a.txt in separate rows like: 1,3,4 and in b.txt like: 2,5, etc. What I have been able to do until now is the following: import sys sys.path.append("C:/Downloads/Python/xlrd-0.6.1") import xlrd wb = xlrd.open_workbook("myexcelsheet.xls") sheet = wb.sheet_by_index(0) clmn1 = sheet.col_values(1,1) clmn2 = sheet.col_values(2,1) #NOW WHAT IS HAVE ARE TWO LISTS WITH CORRESPONDING INDICES #My thought is now to write a counter and for each value in clmn1, write a text file with the name of the value and add data from clmn2 in this file. I want to start with index[0], i.e. value 1 of clmn1 and then go to 2nd value and compare (==) it with 1st value and if its equal then append to the same file 2nd value from clmn2...like this with 3rd value in clmn1, i want to compare it to 1st and 2nd value....wrap this whole in to a nice loop. #Don't know if this is the "easy" way, but this is what my mind came up with. Now I am stuck in colored line below, where I am unable to "create a new filename with string coming from a variable": l = len(clmn1) c = 0 while (c < l): filename = clmn1[c] fhdl1 = open('/mypythonfolder/%(filename)s_appendsomename.txt','w') fhdl1.write(clmn2(c)+'\n') print filename ... c = c + 1 ... ... ... I would appreciate comments and suggestions on how can I get through this problem and also would like to know if there are any methods for lists to solve this problem in a different way. Many Thanks, Ronald. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dm at tu-clausthal.de Thu Jul 8 08:16:36 2010 From: dm at tu-clausthal.de (David Mainzer) Date: Thu, 08 Jul 2010 14:16:36 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: On 07/07/2010 08:08 PM, Raymond Hettinger wrote: > On Jul 7, 5:55 am, Mark Dickinson wrote: >> On Jul 7, 1:05 pm, david mainzer wrote: >> >> >> >>> Dear Python-User, >> >>> today i create some slides about floating point arithmetic. I used an >>> example from >> >>> http://docs.python.org/tutorial/floatingpoint.html >> >>> so i start the python shell on my linux machine: >> >>> dm at maxwell $ python >>> Python 2.6.5 (release26-maint, May 25 2010, 12:37:06) >>> [GCC 4.3.4] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information.>>> >>> sum = 0.0 >>>>>>>>> for i in range(10): >> >>> ... sum += 0.1 >>> ...>>> >>> sum >>> 0.99999999999999989 >> >>> But thats looks a little bit wrong for me ... i must be a number greater >>> then 1.0 because 0.1 = 0.100000000000000005551115123125782702118158340454101562500000000000 >>> in python ... if i print it. > > [Mark Dickinson] >> So you've identified one source of error here, namely that 0.1 isn't >> exactly representable (and you're correct that the value stored >> internally is actually a little greater than 0.1). But you're >> forgetting about the other source of error in your example: when you >> do 'sum += 0.1', the result typically isn't exactly representable, so >> there's another rounding step going on. That rounding step might >> produce a number that's smaller than the actual exact sum, and if >> enough of your 'sum += 0.1' results are rounded down instead of up, >> that would easily explain why the total is still less than 1.0. > > One key for understanding floating point mysteries is to look at the > actual binary sums rather that their approximate representation as a > decimal string. The hex() method can make it easier to visualize > Mark's explanation: > >>>> s = 0.0 >>>> for i in range(10): > ... s += 0.1 > ... print s.hex(), repr(s) > > > 0x1.999999999999ap-4 0.10000000000000001 > 0x1.999999999999ap-3 0.20000000000000001 > 0x1.3333333333334p-2 0.30000000000000004 > 0x1.999999999999ap-2 0.40000000000000002 > 0x1.0000000000000p-1 0.5 > 0x1.3333333333333p-1 0.59999999999999998 > 0x1.6666666666666p-1 0.69999999999999996 > 0x1.9999999999999p-1 0.79999999999999993 > 0x1.cccccccccccccp-1 0.89999999999999991 > 0x1.fffffffffffffp-1 0.99999999999999989 > > Having used hex() to understand representation error (how the binary > partial sums are displayed), you can use the Fractions module to gain > a better understanding of rounding error introduced by each addition: > >>>> s = 0.0 >>>> for i in range(10): > exact = Fraction.from_float(s) + Fraction.from_float(0.1) > s += 0.1 > actual = Fraction.from_float(s) > error = actual - exact > print '%-35s%-35s\t%s' % (actual, exact, error) > > > 3602879701896397/36028797018963968 3602879701896397/36028797018963968 > 0 > 3602879701896397/18014398509481984 3602879701896397/18014398509481984 > 0 > 1351079888211149/4503599627370496 10808639105689191/36028797018963968 > 1/36028797018963968 > 3602879701896397/9007199254740992 > 14411518807585589/36028797018963968 -1/36028797018963968 > 1/2 > 18014398509481985/36028797018963968 -1/36028797018963968 > 5404319552844595/9007199254740992 > 21617278211378381/36028797018963968 -1/36028797018963968 > 3152519739159347/4503599627370496 > 25220157913274777/36028797018963968 -1/36028797018963968 > 7205759403792793/9007199254740992 > 28823037615171173/36028797018963968 -1/36028797018963968 > 2026619832316723/2251799813685248 > 32425917317067569/36028797018963968 -1/36028797018963968 > 9007199254740991/9007199254740992 > 36028797018963965/36028797018963968 -1/36028797018963968 > > Hope this helps your slides, > > > Raymond Thanks to all for your help :) All your comments helped me and now i know how it works in python ! Best David From alex.kapps at web.de Thu Jul 8 08:17:36 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 08 Jul 2010 14:17:36 +0200 Subject: simple python deployment tool In-Reply-To: <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> References: <36f5649e-5f64-48b7-8718-993e2c4560f1@b4g2000pra.googlegroups.com> <319242a4-0a64-43d0-adf4-cd3e241acf6c@h40g2000pro.googlegroups.com> Message-ID: <4C35C1E0.9020609@web.de> King wrote: > On Jul 8, 2:21 pm, Alexander Kapps wrote: >> King wrote: >>> Hi, >>> I am writing a python package deployment tool for linux based >>> platforms. I have tried various existing >>> tool sets but none of them is up to the mark and they have their own >>> issues. Initially I'll start with simple approach. >> I'm sorry, but your approach is not going to work. The Right Way(tm) >> is to not ship any external libraries, but let the user install the >> dependencies with the distro's package manager. And to not try to >> build custom packages, but to let the package maintainers of the >> different distros package your application for you. > > Yes, you an do this by creating a .deb package that will take care of > installing the required libraries. > It may possible that either required version is not available in the > distro's repository or the one available is > older one then required. Yes, that may happen. > So best deal would be to ship at least all > the python's libs along with your package. No, IMHO, the best way to cope with this, is to be a little conservative on what library versions you use. Don't use the most cutting edge versions, but those who are most wildly available. Even if you must use the most recent versions, you should leave the packaging to the distro maintainers. They know their distro a lot better and know how to maintain compatiblity with the rest of the system. >>> 1. Find all the modules/packages and copy to "lib" directory. >>> 2. Find python's *.so dependencies(system libs) and copy them to >>> "syslib" >> That would include all the way down to libc, your archive is going >> to be huge, but the actual problem is, what if the libc isn't >> compatible with the kernel, what if the WX, GTK, X11, etc libraries >> aren't compatible with the running Xserver? > > You are right here. It seems there is no standard definition of system > libraries on linux. To over come the problem of binary > compatibility, I am using ubuntu (hardy) which is on glibc 2.7. Every > other external python library including python is compiled on > hardy. This is would give you maximum chances that libs would be > compatible in case if you run on any other distro which is using glibc >> =2.7 Just because any other disto is based on glibc 2.7 doesn't ensure, that the other parts (like gtk libs vs. X11) are compatible. Actually by doing so, you are limiting your package to Hardy only. Any compatiblity with other Ubuntu versions or other distros would be purely by accident. >> End of the story is, you would need to package a minimal (but almost >> complete) Linux system into your package, which of course is not >> want you want. >> >>> 3. Copy python(executable) and libpython2.6.so.1.0 into "dist" >>> directory. >>> 4. Set up temp environment >>> 5. Run main script using "python
.py" >>> The idea is to produce a cleaner directory structure. Neither I am >>> creating a boot loader nor I am converting main script >>> file into executable. It's plain vanilla stuff. >> It's not vanilla stuff, but a very hard problem. In fact you are >> fighting against the whole system structure. > > Ok, forget about system libs(libX*.* etc.), I don't know why it sounds > too complicated. I am hoping it should work and eventually it's easier > then tools that create an executable using bootloader. The problem is > in setting the correct python environment. It sounds complicated, because it is complicated. :-) Now, imagine, everybody would do this. There would be dozens, maybe hundreds of redundant copies of Python, libXYZ, etc. I don't know what you mean by "create an executable using bootloader", but really, the correct way is to leave the dependency management to the distro and it's package manager. From clp2 at rebertia.com Thu Jul 8 08:36:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jul 2010 05:36:34 -0700 Subject: Writing Out from 2 Lists In-Reply-To: <37807.88947.qm@web120104.mail.ne1.yahoo.com> References: <37807.88947.qm@web120104.mail.ne1.yahoo.com> Message-ID: On Thu, Jul 8, 2010 at 4:30 AM, Dlanor Slegov wrote: > Hi, > > I am trying to find a python solution for an informatics problem I have at > work.?Generalized equivalent of my problem is: > > I have an excel sheet with column 1 and column 2 having corresponding > information (much like a dictionary, however with repeating "keys"). Its > like if you read down column 1: a,b,a,a,b,c and if you read down column 2: > 1,2,3,4,5,6. I would like to write "unique" files such as a.txt, b.txt and > c.txt with matching information (from column 2) in a.txt in separate rows > like: 1,3,4 and in b.txt like: 2,5, etc. > > What I have been able to do until now is the following: > > import sys > sys.path.append("C:/Downloads/Python/xlrd-0.6.1") > import xlrd > > wb = xlrd.open_workbook("myexcelsheet.xls") > sheet = wb.sheet_by_index(0) > > clmn1 = sheet.col_values(1,1) > clmn2 = sheet.col_values(2,1) > > #NOW WHAT IS HAVE ARE TWO LISTS WITH CORRESPONDING INDICES > > #My thought is now to write a counter and for each value in clmn1, write a > text file with the name of the value and add data from clmn2 in this file. I > want to start with index[0], i.e. value 1 of clmn1 and then go to 2nd value > and compare (==) it with 1st value and if its equal then append to the same > file 2nd value from clmn2...like this with 3rd value in clmn1, i want to > compare it to 1st and 2nd value....wrap this whole in to a nice loop. > > #Don't know if this is the "easy" way, but this is what my mind came up > with. Now I am stuck in colored line below, where I am unable to "create a > new filename with string coming from a variable": > > l = len(clmn1) > c = 0 > while (c < l): > filename = clmn1[c] > fhdl1 = open('/mypythonfolder/%(filename)s_appendsomename.txt','w') fhdl1 = open('/mypythonfolder/%s_appendsomename.txt' % filename,'w') > fhdl1.write(clmn2(c)+'\n') > print filename > ... > c = c + 1 Personally, I'd rewrite the loop like this, using zip() and a for-loop: for name, value in zip(clmn1, clmn2): filepath = '/mypythonfolder/' + name + '_appendsomename.txt' with open(filepath, 'a') as f: f.write(str(value)) f.write('\n') Cheers, Chris -- http://blog.rebertia.com From rantingrick at gmail.com Thu Jul 8 08:54:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 8 Jul 2010 05:54:46 -0700 (PDT) Subject: Argh! Name collision! References: <962b7531-72b2-4a48-981b-0f5d9290bfa1@i31g2000yqm.googlegroups.com> Message-ID: <473a10e4-09df-4c39-b74b-e7cb6e4bb7ea@d16g2000yqb.googlegroups.com> On Jul 7, 6:47?pm, "Alf P. Steinbach /Usenet" wrote: > Hm, for pure shock value I think I'll use the acronym PYthon Native Interface > Support. > > pynis! :-) Well as long as you don't put your "pynis" *pointers* in "pynie" then everything will be Ok! ;-) From askutt at gmail.com Thu Jul 8 09:00:48 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 06:00:48 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> On Jul 8, 7:23?am, Mark Dickinson wrote: > On Jul 8, 11:58?am, Adam Skutt wrote: > > > accurately. ?Moreover, in general, it's impossible to even round > > operations involving transcendental functions to an arbitrary fixed- > > precision, you may need effectively infinite precision in order to the > > computation. > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > decimal module do exactly that, giving correctly-rounded exp() and > log() results to arbitrary precision? You run into the table-maker's dilemma: there's no way to know in advance how many digits you need in order to have n bits of precision in the result. For some computations, the number of bits required to get the desired precision can quickly overwhelm the finite limitations of your machine (e.g., you run out of RAM first or the time to compute the answer is simply unacceptable). Adam From ethan at stoneleaf.us Thu Jul 8 09:10:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Jul 2010 06:10:06 -0700 Subject: Python -- floating point arithmetic In-Reply-To: <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> Message-ID: <4C35CE2E.9020607@stoneleaf.us> Wolfram Hinderer wrote: > On 7 Jul., 19:32, Ethan Furman wrote: > >>Nobody wrote: >> >>>On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: >> >>>>you should never rely on a floating-point number to have exactly a >>>>certain value. >> >>>"Never" is an overstatement. There are situations where you can rely >>>upon a floating-point number having exactly a certain value. >> >>It's not much of an overstatement. How many areas are there where you >>need the number >>0.100000000000000005551115123125782702118158340454101562500000000000? >> >>If I'm looking for 0.1, I will *never* (except by accident ;) say >> >>if var == 0.1: >> >>it'll either be <= or >=. > > > The following is an implementation of a well-known algorithm. > Why would you want to replace the floating point comparisons? With > what? Interesting. I knew when I posted my above comment that I was ignoring such situations. I cannot comment on the code itself as I am unaware of the algorithm, and haven't studied numbers extensively (although I do find them very interesting). So while you've made your point, I believe mine still stands -- comparing floats using == to absolute numbers is almost always a mistake. ~Ethan~ From victorsubervi at gmail.com Thu Jul 8 09:20:00 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 08:50:00 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: On Wed, Jul 7, 2010 at 2:22 PM, Stephen Hansen wrote: > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); > > By following this advice, I realized I didn't need to do that fancy multiplying out the '%s' which was screwing me up anyway, and then I didn't need to create an sql using a '%', and then I didn't need to open the door to injection attack! However, I now have another error. Here is my current command: cursor.execute("insert into personalDataKeys (Store, User, useFirstName, useLastName, usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) I get this error from MySQL which I am having a hard time understanding: LATEST FOREIGN KEY ERROR ------------------------ 100708 6:15:01 Transaction: TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id 1169992000 inserting, thread declared inside InnoDB 500 mysql tables in use 1, locked 1 3 lock struct(s), heap size 368, undo log entries 1 MySQL thread id 1502, query id 23700 localhost beno update insert into personalDataKeys (Store, User, useFirstName, useLastName, usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, 1, 1, 1) Foreign key constraint fails for table `test/personalDataKeys`: , CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES `products` (`Store`) Trying to add in child table, in index `Store` tuple: DATA TUPLE: 2 fields; 0: len 9; hex 7370656369616c7479; asc specialty;; 1: len 6; hex 0000000003b7; asc ;; But in parent table `test/products`, in index `Store`, the closest match we can find is record: PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 696e66696d756d00; asc infimum ;; What is this tuple? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Thu Jul 8 09:22:39 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 06:22:39 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> On Jul 8, 2:00?pm, Adam Skutt wrote: > On Jul 8, 7:23?am, Mark Dickinson wrote:> On Jul 8, 11:58?am, Adam Skutt wrote: > > > > accurately. ?Moreover, in general, it's impossible to even round > > > operations involving transcendental functions to an arbitrary fixed- > > > precision, you may need effectively infinite precision in order to the > > > computation. > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > decimal module do exactly that, giving correctly-rounded exp() and > > log() results to arbitrary precision? > > You run into the table-maker's dilemma: there's no way to know in > advance how many digits you need in order to have n bits of precision > in the result. Sure. But it's a bit of a stretch to go from not knowing what resources you'll need in advance to calling something 'impossible'. :) >?For some computations, the number of bits required to > get the desired precision can quickly overwhelm the finite limitations > of your machine (e.g., you run out of RAM first or the time to compute > the answer is simply unacceptable). Perhaps in theory. In practice, though, it's very rare to need to increase precision more than once or twice beyond an initial first guesstimate, and the amount of extra precision needed is small. That increase is unlikely to cause problems unless you were operating right up against your machine's limits in the first place. -- Mark From DierkErdmann at mail.com Thu Jul 8 09:42:48 2010 From: DierkErdmann at mail.com (DierkErdmann at mail.com) Date: Thu, 8 Jul 2010 06:42:48 -0700 (PDT) Subject: Debugging a segmentation fault Message-ID: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Hi, my python project crashes in a non reproducible way. With gdb I got the backtraces given below. How can I possibly figure out the reason for the segfaults that occur under Linux and Windows, using Python 2.6 in both cases. Thanks Dierk Program received signal SIGSEGV, Segmentation fault. 0x080902bf in dict_dealloc (mp=0xbfbf0b4) at ../Objects/dictobject.c: 911 911 ../Objects/dictobject.c: No such file or directory. in ../Objects/dictobject.c (gdb) bt #0 0x080902bf in dict_dealloc (mp=0xbfbf0b4) at ../Objects/ dictobject.c:911 #1 0x08090304 in dict_dealloc (mp=0xa805d74) at ../Objects/ dictobject.c:911 #2 0x08090304 in dict_dealloc (mp=0xbc2768c) at ../Objects/ dictobject.c:911 #3 0x08090304 in dict_dealloc (mp=0xbc27c64) at ../Objects/ dictobject.c:911 #4 0x080ab611 in subtype_dealloc (self= to continue, or q to quit--- Frame 0x969ddb4, for file analyse.py, line 398, in analyseall (options=, TIMEFMT='%d.%m.%Y', TIMESPAN_DAYS=365, projects=[('ant', 2002, 2008), ('apache', 1995, 2009), ('gcc', 2003, 2009), ('gimp', 2003, 2009), ('gnucash', 2001, 2009), ('gnumeric', 2000, 2009), ('gtk', 2000, 2009), ('kde', 2003, 2009), ('maemo', 2006, 2009), ('python', 1999, 2009), ('samba', 2004, 2009), ('tomcat', 2000, 2009), ('wine', 2003, 2009)], ra=: {'grClusterCoeff': , 'grDensity': , 'grNumberMails': 1593, 'mailsPerDay': , 'grMedianDegree': , 'productivity': , 'grDistKSTest': , 'grEdges': 269, 'grBetweenCentNetw': , 'grNumberNodes': 122, 'grBetweenCentNodeMedian': , 'gr...(truncated), throwflag=0) at ../Python/ ceval.c:1010 #8 0x080e1bb0 in fast_function (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:3836 #9 call_function (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:3771 #10 PyEval_EvalFrameEx (f= Frame 0x82eda8c, for file analyse.py, line 472, in (), throwflag=0) at ../Python/ceval.c:2412 Program received signal SIGSEGV, Segmentation fault. visit_decref (op=, data=0x0) at ../Modules/ gcmodule.c:271 271 ../Modules/gcmodule.c: No such file or directory. in ../Modules/gcmodule.c (gdb) bt #0 visit_decref (op=, data=0x0) at ../ Modules/gcmodule.c:271 #1 0x0809223d in dict_traverse (op= {'_sa_adapter': , owner_state=, _strong_obj=None, callables={}, session_id=158970732, modified=False, class_=]), _validators={}, _inheriting_mappers=set([]), _with_polymorphic_selectable=<...>, single=False, allow_partial_pks=True, _dependency_processors=[, direction=, parent=]), _validators={}, _inheriting_mappers=set([]), single=False, allow_partial_pks=True, _dependency_processors=[], tables=[<...>], order_by=False, primary_key=]), index=None, server_onupdate=None, name='id', is_literal=False, nullable=False, default=None, quote=None, autoincrement=True, onupdate=None, foreign_keys=, _...(truncated), visit=0x810c460 , arg=0x0) at ../Objects/dictobject.c:2003 #2 0x0810cebc in subtract_refs (generation=) at ../Modules/gcmodule.c:296 #3 collect (generation=) at ../Modules/ gcmodule.c:817 #4 0x0810d8eb in collect_generations (basicsize=28) at ../Modules/ gcmodule.c:924 #5 _PyObject_GC_Malloc (basicsize=28) at ../Modules/gcmodule.c:1363 #6 0x080ab65b in PyType_GenericAlloc (type=0x8236be0, nitems=0) at ../ Objects/typeobject.c:758 #7 0x080bc9a7 in weakref___new__ (type=0x8236be0, args= (, ), kwargs=0x0) at ../Objects/weakrefobject.c:300 #8 0x080ad0dd in type_call (type=0x8236be0, args= (, ), kwds=0x0) at ../Objects/typeobject.c:726 #9 0x0806245a in PyObject_Call (func=, arg= (, ), kw=0x0) at ../Objects/abstract.c:2492 #10 0x080e0471 in do_call (f= Frame 0x9aabb04, for file /usr/local/lib/python2.6/dist-packages/ SQLAlchemy-0.6.0-py2.6.egg/sqlalchemy/orm/state.py, line 29, in __init__ (self=]), _validators={}, _inheriting_mappers=set([]), _with_polymorphic_selectable=<...>, single=False, allow_partial_pks=True, _dependency_processors=[, direction=, parent=<...>, post_update=False, passive_updates=True, prop=, <...>)], _compile_finished=True, lazy=True, uselist=False, collection_class=None, back_populates=None, table=<...>, innerjoin=False, order_by=False, join_depth=None, strategy=, target=<...>, parent=<...>, use_get=True, uselist=False, _LazyLoader__lazywhere=<_BinaryExpression(negate=, modifiers={}, right=<...>, opera...(truncated), throwflag=0) at ../Python/ceval.c:3968 From philip at semanchuk.com Thu Jul 8 09:44:43 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 8 Jul 2010 09:44:43 -0400 Subject: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3") In-Reply-To: References: <4C2E38F5.10708@animats.com> <4c31200c$0$1600$742ec2ed@news.sonic.net> <4c318235$0$1663$742ec2ed@news.sonic.net> <20100705163043.f4c8d085.darcy@druid.net> <0668D27A-F562-4268-B78C-147AB5B1BF87@semanchuk.com> <20CD005C-DCAA-453C-981A-41CADF1E19D4@semanchuk.com> Message-ID: <162EBD90-A792-49CF-99E0-DB34BD53F728@semanchuk.com> On Jul 7, 2010, at 11:26 PM, Terry Reedy wrote: > On 7/7/2010 5:29 AM, geremy condra wrote: >> On Tue, Jul 6, 2010 at 1:37 AM, Terry Reedy wrote: >>> On 7/5/2010 9:00 PM, Philip Semanchuk wrote: >>>> On Jul 5, 2010, at 6:41 PM, Chris Rebert wrote: >>>>> On Mon, Jul 5, 2010 at 3:38 PM, Philip Semanchu > >>>>>> I ported two pure C extensions from 2 to 3 and was even able to >>>>>> keep a >>>>>> single C codebase. I'd be willing to contribute my experiences >>>>>> to a >>>>>> document >>>>>> somewhere. (Is there a Wiki?) > >>>>> Indeed there is: http://wiki.python.org/moin/ > >>>> Thanks. I don't want to appear ungrateful, but I was hoping for >>>> something specific to the 2-to-3 conversion. I guess someone has to >>>> start somewhere... > >>> There is an existing 2to3 and other pages for Python code >>> conversion. I do >>> not know of any for CAPI conversion. The need for such has been >>> acknowledged >>> among the devs but if there is nothing yet, we need someone with >>> specialized >>> experience and a bit of time to make a first draft. If you start >>> one, give >>> it an easy to remember name C2to3? 2to3Capi? You choose. And link >>> to it from >>> the 2to3 pag >>> In his post on this thread, Martin Loewis volunteered to list what >>> he knows >>> from psycopg2 if someone else will edit. > >> I'm not sure why I don't have this post, but I'm happy to help edit >> etc if Martin >> wants to put together a rough draft. > > Since I wrote that, someone pointed out the the Python How-to > collection includes Porting Extension Modules to 3.0 > by Benjamim Peterson. So all Pyilip or Martin need to do is read > that and suggest additions. That document is here: http://wiki.python.org/moin/PortingExtensionModulesToPy3k It took me a while to find. It's a shame it's not better known; I looked for such a document before I started porting sysv_ipc and posix_ipc and didn't find this one. Thanks for the pointer. Cheers Philip From python at lonely-star.org Thu Jul 8 09:56:51 2010 From: python at lonely-star.org (Nathan Huesken) Date: Thu, 8 Jul 2010 09:56:51 -0400 Subject: Storing a callback function as a class member In-Reply-To: References: <20100707174811.182e8b5b@SamZwo.tch.harvard.edu> Message-ID: <20100708095651.7a973168@SamZwo.tch.harvard.edu> Hey, Sorry, I tried to sent only the relevant parts of the example, but the part where the error was, was left out. I defined the function, used as callback like this: class SomeClass: def callback(param): ... So I forgot the "self" parameter, and therefor the callback had a different number of parameters than I expected. Thanks for the effort! Nathan From stefan-usenet at bytereef.org Thu Jul 8 09:59:40 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 15:59:40 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <20100708135940.GA29032@yoda.bytereef.org> Adam Skutt wrote: > On Jul 8, 7:23?am, Mark Dickinson wrote: > > On Jul 8, 11:58?am, Adam Skutt wrote: > > > > > accurately. ?Moreover, in general, it's impossible to even round > > > operations involving transcendental functions to an arbitrary fixed- > > > precision, you may need effectively infinite precision in order to the > > > computation. > > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > decimal module do exactly that, giving correctly-rounded exp() and > > log() results to arbitrary precision? > > You run into the table-maker's dilemma: there's no way to know in > advance how many digits you need in order to have n bits of precision > in the result. For some computations, the number of bits required to > get the desired precision can quickly overwhelm the finite limitations > of your machine (e.g., you run out of RAM first or the time to compute > the answer is simply unacceptable). Yes, this appears to be unsolved yet, see also: http://www.cs.berkeley.edu/~wkahan/LOG10HAF.TXT "Is it time to quit yet? That's the Table-Maker's Dilemma. No general way exists to predict how many extra digits will have to be carried to compute a transcendental expression and round it _correctly_ to some preassigned number of digits. Even the fact (if true) that a finite number of extra digits will ultimately suffice may be a deep theorem." However, in practice, mpfr rounds correctly and seems to be doing fine. In addition to this, I've been running at least 6 months of continuous tests comparing cdecimal and decimal, and neither log() nor exp() poses a problem. pow() is trickier. Exact results have to be weeded out before attempting the correction loop for correct rounding, and this is complicated. For example, in decimal this expression takes a long time (in cdecimal the power function is not correctly rounded): Decimal('100.0') ** Decimal('-557.71e-742888888') Stefan Krah From askutt at gmail.com Thu Jul 8 10:29:41 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 07:29:41 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> Message-ID: <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> On Jul 8, 9:22?am, Mark Dickinson wrote: > On Jul 8, 2:00?pm, Adam Skutt wrote: > > > On Jul 8, 7:23?am, Mark Dickinson wrote:> On Jul 8, 11:58?am, Adam Skutt wrote: > > > > > accurately. ?Moreover, in general, it's impossible to even round > > > > operations involving transcendental functions to an arbitrary fixed- > > > > precision, you may need effectively infinite precision in order to the > > > > computation. > > > > Impossible? ?Can you explain what you mean by this? ?Doesn't the > > > decimal module do exactly that, giving correctly-rounded exp() and > > > log() results to arbitrary precision? > > > You run into the table-maker's dilemma: there's no way to know in > > advance how many digits you need in order to have n bits of precision > > in the result. > > Sure. ?But it's a bit of a stretch to go from not knowing what > resources you'll need in advance to calling something 'impossible'. :) > > >?For some computations, the number of bits required to > > get the desired precision can quickly overwhelm the finite limitations > > of your machine (e.g., you run out of RAM first or the time to compute > > the answer is simply unacceptable). > > Perhaps in theory. ?In practice, though, it's very rare to need to > increase precision more than once or twice beyond an initial first > guesstimate, and the amount of extra precision needed is small. ?That > increase is unlikely to cause problems unless you were operating right > up against your machine's limits in the first place. I suspect your platitude isn't especially comforting for those who need more computing capability than we can currently construct. However, I wouldn't call the amount of extra needed precision "small" for most transcendental functions, as it's frequently more than double in the worse-case situations and increases non-linearly as the number of desired digits increases. Which almost brings us full circle to where I was originally pointing: the "rounding" problem is inherent in the finite nature of a physical computer, so you cannot make the rounding problem go away. As such, talking about differences in rounding between decimal and binary representations is somewhat of a corner case. Replacing "float" with "decimal" won't get rid of the problems that floating-point brings to the table in the first place. The issues that come up all have to do with lack of human understanding of what the computer is doing. Take even as something as innocent as equality between two floating-point numbers: even exact rounding of all operations doesn't solve this entirely common problem. Accordingly, once we explain why this doesn't work, we frequently don't need the enhanced functionality decimal provides and hopefully can make the determination on our own. If you want to make elementary arithmetic (add, subtract, multiple, divide) behave intuitively then you (arguably) want an arbitrary- precision fractional/rational number class. After that, the right solution is education. Adam From vincent at vincentdavis.net Thu Jul 8 10:34:58 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 8 Jul 2010 08:34:58 -0600 Subject: Python script to install python Message-ID: I would like to have a python script that would download the most recent svn of python, configure, make, install and cleanup after itself. I am not replacing the python version I would be using to run the script. I was struggling to get this to work and I assume someone else has done it better. Any pointers? Thanks Vincent From Bryan.Stopp at argushealth.com Thu Jul 8 10:36:34 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 09:36:34 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> I've seen other threads on this issue, but the resolution still doesn't seem to exist for me. I'm running the configure script with these parameters: ./configure --prefix=/build/tools \ --exec-prefix=/build/tools \ --enable-shared \ --enable-ipv6 \ --with-gcc \ --with-pth I also want to state that I already edited all of the configure & config.guess scripts to comprehend AIX6.1 (they're not updated yet). And as you can see, I'm running this using the "-with-gcc" option. The configure seems to have no problems; so I run a: make clean && make This results in a completed compile. If I go back and look I see a lot of this: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so collect2: library libpython2.6 not found Notice that it can't find the Python lib.. well, it's not installed yet. It's built and in the current directory I'm working out of, but that's not in my LiBPATH. I'll come back to that. If I don't do anything and try to "make install" it pushes the python & libpython libraries to the appropriate locations, and then it appears it tries to re-make the modules: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so However this time it results in a mass of: ld: 0711-224 WARNING: Duplicate symbol: I mean I get like 1000+ of these warnings. But they all culminate in: ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. Fatal Python error: Interpreter not initialized (version mismatch?) make: The signal code from the last command is 6. Now, I said I'd get back to the LIBPATH issue. I thought that if it was looking for that libpython file to compile the modules, it just wasn't finding it. So I executed a: LIBPATH=.:$LIBPATH make This resulted in: building '_struct' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o build/lib.aix-6.1-2.6/_struct.so ld: 0706-006 Cannot find or open library file: -l python2.6 ld:open(): No such file or directory collect2: ld returned 255 exit status Huh? Can't find the library now? In any event, I can't get Python to compile and/or install on my machine. Does anyone have any insight into what is happening to cause this problem? -B PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Jul 8 10:54:10 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Jul 2010 14:54:10 GMT Subject: Is This Open To SQL Injection? References: Message-ID: Ian wrote: > On 07/07/2010 19:38, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % >> (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) >> >> Is this open to injection attacks? If so, how correct? >> TIA, >> beno > Yes, it is trivially open to injection attacks. > > What would happen if someone enters the next line into one of your > col_vals > > x,y);DROP DATABASE personalDataKeys; ha ha > > Your sql statement would be closed early by the semicolon, and the > DROP TABLE personalDataKeys is then executed and would cause some > unexpected data loss. > > Things could be more serious - DROP DATABASE mysql; for a mysql > installation for example. > > You must always always every time and without any exceptions > what-so-ever, put all and every piece of data that comes from outside > the program through the appropriate routine to make whatever has been > entered into storable data and not part of the sql statement. > > In php this is mysql_real_escape_string(). In your favourite language > there will be an equivalent. > > If you miss just one occurrence its like leaving the side window > unlocked! Someone will get in one day. > Try reading the code more carefully. You don't need to escape the strings so long as you use cursor.execute properly. In this case it is being used properly: there is no danger of injection attacks from col_vals. If `store` or `user` come from user input there is a danger as they are being inserted into the generated sql. As has already been pointed out the code to generate the sql is broken, but the principle behind it is sound. In this case the correct thing to do would appear to be: sql = 'insert into personalDataKeys values (%%s, %%s, %s)' % (','.join (['%s'] * len(col_vals))) cursor.execute(sql, (store, user) + col_vals) which safely sanitises all of the data passed to the database. -- Duncan Booth http://kupuguy.blogspot.com From love_ram2040 at yahoo.com Thu Jul 8 10:57:57 2010 From: love_ram2040 at yahoo.com (porxy) Date: Thu, 8 Jul 2010 07:57:57 -0700 (PDT) Subject: open all sites free now Message-ID: <820ac731-5b6a-40f7-8baa-c641c3d2d33f@e5g2000yqn.googlegroups.com> open all sites free now no blocked sites now with this site ,just put your blocked site and it will open free http://openfree.zzl.org/here From invalid at invalid.invalid Thu Jul 8 11:00:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 15:00:29 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-07, Grant Edwards wrote: > Oops. Those Python bindings are for version 1.3.2 of libconfig (which > does work). They don't work with the current version of libconfig. I've stripped the python bindings down to a minimal point, and I've decided there may be a memory corruption problem in the 1.4.5 version of the library. Here's the current boost binding: ---------------------------------pylibconfig.cc------------------------------ #include #include using namespace boost::python; using namespace libconfig; class pyConfig { public: pyConfig() { config = new Config(); } ~pyConfig () { delete config; } private: Config *config; }; BOOST_PYTHON_MODULE(pylibconfig) { class_("Config"); } ---------------------------------pylibconfig.cc------------------------------ That builds without warnings and installs fine, but attempting to actually create an instance of the class in Python causes a glibc memory corruption message: Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pylibconfig >>> conf = pylibconfig.Config() *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** Am I correct in concluding it has to be a memory corruption problem in the library itself? -- Grant Edwards grant.b.edwards Yow! I want the presidency at so bad I can already taste gmail.com the hors d'oeuvres. From jwhughes at hughesconcepts.com Thu Jul 8 11:00:49 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Thu, 8 Jul 2010 11:00:49 -0400 Subject: Issue with logging.config Message-ID: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Hi Python Help: I'm doing some work with logging.config and I'm running into an interesting situation. I've run this by python-help, but that didn't help so I thought I would send to the list. Here is the config file [loggers] keys=root,log,syslog [handlers] keys=console,log,syslog [formatters] keys=rootFormat,logFormat,syslogFormat [logger_root] level=DEBUG handlers=console [logger_log] level=DEBUG handlers=log qualname=log [logger_syslog] level=DEBUG handlers=syslog qualname=syslog [handler_console] class=StreamHandler level=DEBUG formatter=rootFormat args=(sys.stdout,) [handler_log] class=handlers.RotatingFileHandler level=DEBUG formatter=logFormat args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) propagate=0 [handler_syslog] class=handlers.SysLogHandler level=DEBUG formatter=syslogFormat host=141.232.41.205 port=handlers.SYSLOG_UDP_PORT facility=LOG_LOCAL0 args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) [formatter_rootFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s [formatter_logFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s [formatter_syslogFormat] format=%(asctime)s - %(name)s - %(levelname)s - %(message)s and the python code ######################################################################## # Imports ######################################################################## import logging import logging.config import os import re from threading import Thread ######################################################################## # Constants ######################################################################## CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' ######################################################################## # Classes ######################################################################## ######## # PingIt ######## class PingIt(Thread): def __init__(self, mcuIP): Thread.__init__(self) self.ip = mcuIP self.status = -1 def run(self): pinging = os.popen("ping -n 2 " + self.ip, 'r') while 1: line = pinging.readline() if not line: break gotResponse = re.findall(PingIt.lifeline, line) if gotResponse: self.status = int(gotResponse[0]) ######################################################################## # Main Routine ######################################################################## # # Get the logger configuration information # logging.config.fileConfig(CONFIG_FILENAME) # # Check if running from command line and create logger # if os.environ.get('PROMPT'): # # create logger for output to stdout # logger = logging.getLogger('root') else: # # create logger for output to logfile # logger = logging.getLogger('log') # # Create logger for syslog output # syslog = logging.getLogger('syslog') # # Declare variables # PingIt.lifeline = re.compile(r"Received = (\d)") mcu_dict = {} ping_list = [] status = ("Not responding", "Responded to only 1 ping of 2", "Alive") # # Open the MCU file # mcu_file = open(MCU_LIST_FILENAME, 'r') # # Loop through the contents of the MCU file and ping the IPs # for mcu in mcu_file: # # mcu file contents example # 192.168.97.227 MCU_HMSTD # # mcu_info[0] = MCU IP Address # mcu_info[1] = MCU Name # mcu_info = mcu.split() mcu_dict[mcu_info[0]] = mcu_info[1] current = PingIt(mcu_info[0]) logger.info("Pinging " + mcu_info[1]) ping_list.append(current) current.start() # # Loop through ping list and print the response # for pinged in ping_list: pinged.join() logger.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) This is the output from the code 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not responding address = ('141.232.41.205', 514) Traceback (most recent call last): File "C:\Python31\lib\logging\handlers.py", line 786, in emit self.socket.sendto(msg, self.address) TypeError: sendto() takes exactly 3 arguments (2 given) 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not responding This is the handlers.py code from the library. I added the print statement to figure out why it is asking for three args but only getting two. Line 777 of handlers.py try: if self.unixsocket: try: self.socket.send(msg) except socket.error: self._connect_unixsocket(self.address) self.socket.send(msg) else: print('msg = ', msg, '\naddress = ', self.address) self.socket.sendto(msg, self.address) except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) line 790 of handlers.py This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea about why this happening I would appreciate knowing what the issue is. Thanks, Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Thu Jul 8 11:04:05 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Jul 2010 08:04:05 -0700 Subject: Python 2.7 released References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> Message-ID: In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, imageguy wrote: > >Sorry to be daft here, but what do you mean by a "hardlink" ? >A windows "Shortcut" ? Just to be clear, a hardlink on NTFS functions almost exactly the same as a hardlink on a Unix filesystem -- it's a pointer to the same underlying file. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From invalid at invalid.invalid Thu Jul 8 11:07:31 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 15:07:31 +0000 (UTC) Subject: Python 2.7 released References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: On 2010-07-08, Aahz wrote: > In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, > imageguy wrote: >> >>Sorry to be daft here, but what do you mean by a "hardlink" ? >>A windows "Shortcut" ? > > Just to be clear, a hardlink on NTFS functions almost exactly the same as > a hardlink on a Unix filesystem -- it's a pointer to the same underlying > file. A windows shortcut is more like a Unix symlink (symbolic link), where the real destination path is a string contained in the link/shortcut file. That destination path is then evaluated and "dereferenced" when the link/shortcut is accessed. -- Grant Edwards grant.b.edwards Yow! Of course, you at UNDERSTAND about the PLAIDS gmail.com in the SPIN CYCLE -- From fetchinson at googlemail.com Thu Jul 8 11:11:59 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 8 Jul 2010 17:11:59 +0200 Subject: Python script to install python In-Reply-To: References: Message-ID: > I would like to have a python script that would download the most > recent svn of python, configure, make, install and cleanup after > itself. I am not replacing the python version I would be using to run > the script. > I was struggling to get this to work and I assume someone else has > done it better. Any pointers? Assuming you are on linux I recommend not using a python script for this but rather a shell script. From a python script you would most of the time be calling shell commands anyway. In a shell script you would do something like this: ################################ #!/bin/bash svn checkout ........................ cd whatever ./configure --whatever-options-you-like make # you probably want to run this as root make install # you probably don't want to be root anymore cd .. rm -rf whatever ################################ If you are on windows I assume a similar strategy is best. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From me+list/python at ixokai.io Thu Jul 8 11:15:53 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 08:15:53 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C35EBA9.2040703@ixokai.io> On 7/8/10 6:20 AM, Victor Subervi wrote: > However, I now have another error. Here is my current command: > > cursor.execute("insert into personalDataKeys (Store, User, > useFirstName, useLastName, usePhone, useCell, useFax, useAddress, > useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, > %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) Quick point: why the parens around [store, user] + col_vars? They're redundant. > > I get this error from MySQL which I am having a hard time understanding: > > LATEST FOREIGN KEY ERROR > ------------------------ > 100708 6:15:01 Transaction: > TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id > 1169992000 inserting, thread declared inside InnoDB 500 > mysql tables in use 1, locked 1 > 3 lock struct(s), heap size 368, undo log entries 1 > MySQL thread id 1502, query id 23700 localhost beno update > insert into personalDataKeys (Store, User, useFirstName, useLastName, > usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, > useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, > 1, 1, 1) > Foreign key constraint fails for table `test/personalDataKeys`: > , > CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES > `products` (`Store`) A foreign key is a constraint, a restriction, which says that rows in TableA ("personalDataKeys") depend on certain *matching* rows to already exist and always be valid in TableB ("products"); the exact match is a column they have in common ("Store"). The purpose of foreign keys is to keep data consistent. Here, it appears as if you have established a key such that the 'store' column in your personalDataKeys table must point to a certain row in the products table which has a 'store' column of the exact same value. This error message is indicating that when you do this INSERT, there is no corresponding row in the products table. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From see at sig.for.address Thu Jul 8 11:19:37 2010 From: see at sig.for.address (Victor Eijkhout) Date: Thu, 8 Jul 2010 10:19:37 -0500 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <1jlb3bc.faswymguv56oN%see@sig.for.address> Zooko O'Whielacronx wrote: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. Only if one has Power6 (or 7) which has hardware support for BCD. Otherwise you will have slow applications. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From me+list/python at ixokai.io Thu Jul 8 11:29:35 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 08:29:35 -0700 Subject: Python 2.7 released In-Reply-To: References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C35EEDF.2040607@ixokai.io> On 7/8/10 8:07 AM, Grant Edwards wrote: > On 2010-07-08, Aahz wrote: >> In article <1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, >> imageguy wrote: >>> >>> Sorry to be daft here, but what do you mean by a "hardlink" ? >>> A windows "Shortcut" ? >> >> Just to be clear, a hardlink on NTFS functions almost exactly the same as >> a hardlink on a Unix filesystem -- it's a pointer to the same underlying >> file. > > A windows shortcut is more like a Unix symlink (symbolic link), where > the real destination path is a string contained in the link/shortcut > file. That destination path is then evaluated and "dereferenced" when > the link/shortcut is accessed. This is true, but a windows shortcut is more limited: its a feature of higher level code in the UI (I don't want to say just Explorer, as the standard dialogs deal with it too), and not the filesystem. So it only really works if there's a user specifically clicking through it -- or if you have code made to look for the .lnk files, parse them (they're really simple INI files) and deference it manually. At least, IIUC. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From mail at timgolden.me.uk Thu Jul 8 11:30:59 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 08 Jul 2010 16:30:59 +0100 Subject: Python 2.7 released In-Reply-To: References: <679b8ac8-d79f-4862-8706-229d61b6d81a@s24g2000pri.googlegroups.com> <1450078b-d5ee-437f-bd8b-8da26900f254@x27g2000yqb.googlegroups.com> Message-ID: <4C35EF33.9030703@timgolden.me.uk> On 08/07/2010 16:07, Grant Edwards wrote: > On 2010-07-08, Aahz wrote: >> In article<1450078b-d5ee-437f-bd8b-8da26900f254 at x27g2000yqb.googlegroups.com>, >> imageguy wrote: >>> >>> Sorry to be daft here, but what do you mean by a "hardlink" ? >>> A windows "Shortcut" ? >> >> Just to be clear, a hardlink on NTFS functions almost exactly the same as >> a hardlink on a Unix filesystem -- it's a pointer to the same underlying >> file. > > A windows shortcut is more like a Unix symlink (symbolic link), where > the real destination path is a string contained in the link/shortcut > file. That destination path is then evaluated and "dereferenced" when > the link/shortcut is accessed. Goodness knows I'm probably teaching my grandmother etc. etc. but I would clarify that a Windows shortcut is a *shell* concept: from the NTFS point of view, it's just a something.lnk with some opaque contents. A (>= Vista) NTFS smbolic link is documented as designed "to function just like Unix links". TJG From dickinsm at gmail.com Thu Jul 8 11:36:24 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 08:36:24 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> Message-ID: <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> On Jul 8, 3:29?pm, Adam Skutt wrote: > On Jul 8, 9:22?am, Mark Dickinson wrote: > > On Jul 8, 2:00?pm, Adam Skutt wrote: > > >?For some computations, the number of bits required to > > > get the desired precision can quickly overwhelm the finite limitations > > > of your machine (e.g., you run out of RAM first or the time to compute > > > the answer is simply unacceptable). > > > Perhaps in theory. ?In practice, though, it's very rare to need to > > increase precision more than once or twice beyond an initial first > > guesstimate, and the amount of extra precision needed is small. ?That > > increase is unlikely to cause problems unless you were operating right > > up against your machine's limits in the first place. > > I suspect your platitude isn't especially comforting for those who > need more computing capability than we can currently construct. > However, I wouldn't call the amount of extra needed precision "small" I think that's because we're talking at cross-purposes. To clarify, suppose you want to compute some value (pi; log(2); AGM(1, sqrt(2)); whatever...) to 1000 significant decimal places. Then typically the algorithm (sometimes known as Ziv's onion-peeling method) looks like: (1) Compute an initial approximation to 1002 digits (say), with known absolute error (given by a suitable error analysis); for the sake of argument, let's say that you use enough intermediate precision to guarantee an absolute error of < 0.6 ulps. (2) Check to see whether that approximation unambiguously gives you the correctly-rounded 1000 digits that you need. (3) If not, increase the target precision (say by 3 digits) and try again. It's the precision increase in (3) that I was calling small, and similarly it's step (3) that isn't usually needed more than once or twice. (In general, for most functions and input values; I dare say there are exceptions.) Step (1) will often involve using significantly more than the target precision for intermediate computations, depending very much on what you happen to be trying to compute. IIUC, it's the extra precision in step (1) that you don't want to call 'small', and I agree. IOW, I'm saying that the extra precision required *due to the table- maker's dilemma* generally isn't a concern. I actually agree with much of what you've said. It was just the "impossible" claim that went over the top (IMO). The MPFR library amply demonstrates that computing many transcendental functions to arbitrary precision, with correctly rounded results, is indeed possible. -- Mark From giacomo.boffi at polimi.it Thu Jul 8 11:52:13 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Thu, 08 Jul 2010 17:52:13 +0200 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> Message-ID: <86vd8qq8cy.fsf@aiuole.stru.polimi.it> "Zooko O'Whielacronx" writes: > I'm starting to think that one should use Decimals by default and > reserve floats for special cases. would you kindly lend me your Decimals ruler? i need to measure the sides of the triangle whose area i have to compute From vincent at vincentdavis.net Thu Jul 8 11:54:10 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 8 Jul 2010 09:54:10 -0600 Subject: Python script to install python In-Reply-To: References: Message-ID: On Thu, Jul 8, 2010 at 9:11 AM, Daniel Fetchinson wrote: >> I would like to have a python script that would download the most >> recent svn of python, configure, make, install and cleanup after >> itself. I am not replacing the python version I would be using to run >> the script. >> I was struggling to get this to work and I assume someone else has >> done it better. ?Any pointers? > > Assuming you are on linux I recommend not using a python script for > this but rather a shell script. From a python script you would most of > the time be calling shell commands anyway. In a shell script you would > do something like this: > > ################################ > #!/bin/bash > > svn checkout ........................ > cd whatever > ./configure --whatever-options-you-like > make > # you probably want to run this as root > make install > # you probably don't want to be root anymore > cd .. > rm -rf whatever > > ################################ Ok I'll take your advice and just use a shell script. I am on osx by the way. Thanks Vincent > > If you are on windows I assume a similar strategy is best. > > Cheers, > Daniel > > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > From victorsubervi at gmail.com Thu Jul 8 12:03:21 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 11:33:21 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C35EBA9.2040703@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> Message-ID: On Thu, Jul 8, 2010 at 10:45 AM, Stephen Hansen wrote: > On 7/8/10 6:20 AM, Victor Subervi wrote: > > However, I now have another error. Here is my current command: > > > > cursor.execute("insert into personalDataKeys (Store, User, > > useFirstName, useLastName, usePhone, useCell, useFax, useAddress, > > useShippingAddress, useDOB, useEmail, usePW) values (%s, %s, %s, %s, %s, > > %s, %s, %s, %s, %s, %s, %s)", ([store, user] + col_vals)) > > Quick point: why the parens around [store, user] + col_vars? They're > redundant. > > > > > I get this error from MySQL which I am having a hard time understanding: > > > > LATEST FOREIGN KEY ERROR > > ------------------------ > > 100708 6:15:01 Transaction: > > TRANSACTION 0 9382, ACTIVE 0 sec, process no 5326, OS thread id > > 1169992000 inserting, thread declared inside InnoDB 500 > > mysql tables in use 1, locked 1 > > 3 lock struct(s), heap size 368, undo log entries 1 > > MySQL thread id 1502, query id 23700 localhost beno update > > insert into personalDataKeys (Store, User, useFirstName, useLastName, > > usePhone, useCell, useFax, useAddress, useShippingAddress, useDOB, > > useEmail, usePW) values ('specialty', 'patients', 1, 1, 1, 1, 1, 1, 0, > > 1, 1, 1) > > Foreign key constraint fails for table `test/personalDataKeys`: > > , > > CONSTRAINT `personalDataKeys_ibfk_1` FOREIGN KEY (`Store`) REFERENCES > > `products` (`Store`) > > A foreign key is a constraint, a restriction, which says that rows in > TableA ("personalDataKeys") depend on certain *matching* rows to already > exist and always be valid in TableB ("products"); the exact match is a > column they have in common ("Store"). > > The purpose of foreign keys is to keep data consistent. Here, it appears > as if you have established a key such that the 'store' column in your > personalDataKeys table must point to a certain row in the products table > which has a 'store' column of the exact same value. > > This error message is indicating that when you do this INSERT, there is > no corresponding row in the products table. > mysql> describe products Store; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> describe personalDataKeys Store; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.00 sec) They both use innodb. They're both indexed. I was thinking after getting your email that maybe I'd set the varchars to different lengths, but no. However... mysql> select * from products; Empty set (0.00 sec) Is it that I can't insert into personalDataKeys until I've first done so in products? After rethinking this, it occurred to me that I probably made a mistake in copying my create table command from personalData to personalDataKeys, both of which had the foreign key of Store referenced to table products. That wasn't necessary, since personalDataKeys only needs to be associated with personalData, so I dropped and recreated the table, updating personalDataKeys foreign key to reference personalData; however, once again: mysql> select * from personalData; Empty set (0.00 sec) Here's the deal: mysql> describe personalData; +-------------------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+------------------+------+-----+------------+----------------+ | ID | int(10) unsigned | NO | PRI | NULL | auto_increment | | Store | varchar(40) | NO | MUL | NULL | | | User | varchar(50) | NO | MUL | NULL | | | FirstName | varchar(100) | NO | | NULL | | | LastName | varchar(100) | NO | | NULL | | | Phone | varchar(13) | YES | | NULL | | | Cell | varchar(13) | YES | | NULL | | | Fax | varchar(13) | YES | | NULL | | | AddressID | int(11) | NO | MUL | NULL | | | ShippingAddressID | int(11) | NO | MUL | NULL | | | DOB | date | YES | | 2000-01-01 | | | Email | varchar(100) | NO | | NULL | | | PW | varchar(12) | NO | | NULL | | +-------------------+------------------+------+-----+------------+----------------+ 13 rows in set (0.00 sec) mysql> describe personalDataKeys; +--------------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+-------------+------+-----+---------+-------+ | Store | varchar(40) | NO | MUL | NULL | | | User | varchar(50) | NO | MUL | NULL | | | useFirstName | tinyint(1) | NO | | NULL | | | useLastName | tinyint(1) | NO | | NULL | | | usePhone | tinyint(1) | NO | | NULL | | | useCell | tinyint(1) | NO | | NULL | | | useFax | tinyint(1) | NO | | NULL | | | useAddress | tinyint(1) | NO | | NULL | | | useShippingAddress | tinyint(1) | NO | | NULL | | | useDOB | tinyint(1) | NO | | NULL | | | useEmail | tinyint(1) | NO | | NULL | | | usePW | tinyint(1) | NO | | NULL | | +--------------------+-------------+------+-----+---------+-------+ 12 rows in set (0.00 sec) In personalDataKeys I store which fields will be required for a given store as it relates to personal data. For example, if there is a pharmacy with users 'doctors' and 'patients', certain fields in personalData will be required for one but not the other, and this needs to be inserted into personalDataKeys. All of this, however, obviously happens before any data is actually entered into either personalData or products. It now seems to me that I have mistakenly put the constraint on the wrong table; that it should be on personalData and not personalDataKeys, but before I do that I would like confirmation that this looks correct. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 8 12:31:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 8 Jul 2010 09:31:32 -0700 Subject: Python -- floating point arithmetic In-Reply-To: <86vd8qq8cy.fsf@aiuole.stru.polimi.it> References: <4C346DA0.1070708@tu-clausthal.de> <86vd8qq8cy.fsf@aiuole.stru.polimi.it> Message-ID: On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi wrote: > "Zooko O'Whielacronx" writes: >> I'm starting to think that one should use Decimals by default and >> reserve floats for special cases. > > would you kindly lend me your Decimals ruler? i need to measure the > sides of the triangle whose area i have to compute If your ruler doesn't have a [second] set of marks for centimeters and millimeters, that's really one cheap/cruddy ruler you're using. Cheers, Chris -- Metrication! http://blog.rebertia.com From nagle at animats.com Thu Jul 8 12:35:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 09:35:49 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: Message-ID: <4c35fe68$0$1666$742ec2ed@news.sonic.net> On 7/7/2010 11:52 AM, Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) Bad approach. Don't put actual data into an SQL statement using string parameter substitution. Try this: values = (store, user) + tuple(col_vals) # all values to be inserted valuesql = ",".join(["%s"]*len(values)) # '%s,%s,%s,%s,%s,%s' sql = "INSERT INTO personaldatakeys VALUES (" + valuesql + ")" cursor.execute(sql, values) # execute INSERT "valuefields" is always some number of repeats of comma-separated "%s" Anything in "values" will be escaped properly. No SQL injection vulnerability. John Nagle From zooko at zooko.com Thu Jul 8 12:38:24 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Thu, 8 Jul 2010 10:38:24 -0600 Subject: Python -- floating point arithmetic In-Reply-To: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Thu, Jul 8, 2010 at 4:58 AM, Adam Skutt wrote: > > I can't think of any program I've ever written where the inputs are > actually intended to be decimal. ?Consider a simple video editing > program, and the user specifies a frame rate 23.976 fps. ?Is that what > they really wanted? ?No, they wanted 24000/1001 but didn't feel like > typing that. Okay, so there was a lossy conversion from the user's intention (24000/1001) to what they typed in (23.976). >>> instr = '23.976' Now as a programmer you have two choices: 1. accept what they typed in and losslessly store it in a decimal: >>> from decimal import Decimal as D >>> x = D(instr) >>> print x 23.976 2. accept what they typed in and lossily convert it to a float: >>> x = float(instr) >>> print "%.60f" % (x,) 23.975999999999999090505298227071762084960937500000000000000000 option 2 introduces further "error" between what you have stored in your program and what the user originally wanted and offers no advantages except for speed, right? >> I'm sorry, what will never be true? Are you saying that decimals have >> a disadvantage compared to floats? If so, what is their disadvantage? > > He's saying that once you get past elementary operations, you quickly > run into irrational numbers, which you will not be representing > accurately. ?Moreover, in general, it's impossible to even round > operations involving transcendental functions to an arbitrary fixed- > precision, you may need effectively infinite precision in order to the > computation. ?In practice, this means the error induced by a lossy > input conversion (assuming you hadn't already lost information) is > entirely negligible compared to inherent inability to do the necessary > calculations. But this is not a disadvantage of decimal compared to float is it? These problems affect both representations. Although perhaps they affect them differently, I'm not sure. I think sometimes people conflate the fact that decimals can easily have higher and more variable precision than floats with the fact that decimals are capable of losslessly storing decimal values but floats aren't. Regards, Zooko From nagle at animats.com Thu Jul 8 12:42:40 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 09:42:40 -0700 Subject: How is Unladen Swallow coming along? Message-ID: <4c360004$0$1607$742ec2ed@news.sonic.net> How is Unladen Swallow coming along? Looking at the site, code is being checked in and issues are being reported, but the last quarterly release was 2009 Q3. They missed their January 2010 release date for "2009 Q4", so they're now about 6 months behind their project plan. ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") John Nagle From me+list/python at ixokai.io Thu Jul 8 12:50:08 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 09:50:08 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> Message-ID: <4C3601C0.6090501@ixokai.io> On 7/8/10 9:03 AM, Victor Subervi wrote: > mysql> describe products Store; > +-------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +-------+-------------+------+-----+---------+-------+ > | Store | varchar(40) | NO | MUL | NULL | | > +-------+-------------+------+-----+---------+-------+ > 1 row in set (0.00 sec) > > mysql> describe personalDataKeys Store; > +-------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +-------+-------------+------+-----+---------+-------+ > | Store | varchar(40) | NO | MUL | NULL | | > +-------+-------------+------+-----+---------+-------+ > 1 row in set (0.00 sec) > > They both use innodb. They're both indexed. I was thinking after getting > your email that maybe I'd set the varchars to different lengths, but no. A foreign key isn't about the schema, per se; its not about the varchar's being different lengths (as they discard trailing padding)-- its about *data*. True, if you had varchar(20) and varchar(40), then if any string longer then 20 wouldn't ever pass -- but that's really secondary. (That's not saying a database may refuse to accept a FK if data types are mismatched) If "personalDataKeys" has a foreign key connecting it to "products", then you can't add something to personalDataKeys with store = "specialty" unless something already exists in "products" with store = "speciality"; > However... > > mysql> select * from products; > Empty set (0.00 sec) > > Is it that I can't insert into personalDataKeys until I've first done so > in products? Yes, that's precisely what foreign keys do. > That wasn't necessary, since personalDataKeys only > needs to be associated with personalData, so I dropped and recreated the > table, updating personalDataKeys foreign key to reference personalData; > however, once again: Are you certain this is what you want? It sounds like you may be using foreign keys without fully understanding what they are. Think of them like a big arrow. If you define a foreign key in personalDataKeys, referencing personalData, you should picture a large arrow pointing from personalDataKeys to personalData. It's pointing because the "constraint" created by the foreign key means, "Every record in this table, personalDataKeys, has a column which *must* exist in its referenced table, personalData, before that record is allowed to be added." A foreign key isn't just a description of a relationship: its a strict rule, declaring that a certain field in one table *actually* refers directly to a *specific* row in *another* table: therefore, this field can't be allowed to be any value which doesn't exist already in that other table. A "primary key" lets you uniquely identify a certain row in one table. A "foreign key" lets you identify a certain row in *another table*, that this table ultimately depends on. > In personalDataKeys I store which fields will be required for a given > store as it relates to personal data. For example, if there is a > pharmacy with users 'doctors' and 'patients', certain fields in > personalData will be required for one but not the other, and this needs > to be inserted into personalDataKeys. My concern here is that you're making *columns* which are "store-dependent", such as sometimes in one store, personalData will have a column/field named "foo", but another store it won't use "foo" but instead use "bar", depending on how the store itself is configured. I'd refer you back to my previous email which described two schemes to record "store-dependant" data: one using a separate table for each store type, another using a generic key/value table. Having one big table with a big mix of columns that various store configurations pick and choose seems like a very inflexible design. Additionally (if you do keep this design), these two tables you described seem to make the columns that are used tied to *users*, not *stores*. The key for personalDataKeys is (Store, User): but isn't it the case that for a certain kind of store (i.e., a pharmacy), /all/ users in that store will have the same fields in personalData be relevant? So shouldn't "personalDataKeys" really be "storeDataKeys"? I.e., a configuration of the store itself of what data keys it considers relevant. > All of this, however, obviously > happens before any data is actually entered into either personalData or > products. Yeah, the constraints and such happen before data is entered. But once they are created, you have to actual enter data in the correct order. The constraints enforce consistency so programmer-error can't introduce data into the tables which is out of whack with the data layout. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Thu Jul 8 12:51:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 08 Jul 2010 18:51:15 +0200 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> Message-ID: <4C360203.8060309@jollans.com> On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I?ve seen other threads on this issue, but the resolution still doesn?t > seem to exist for me. > > > > I?m running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they?re not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas From me+list/python at ixokai.io Thu Jul 8 13:00:43 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 10:00:43 -0700 Subject: Is This Open To SQL Injection? In-Reply-To: <4C34CCEB.1060901@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> Message-ID: <4C36043B.1070303@ixokai.io> On 7/7/10 11:52 AM, Stephen Hansen wrote: > On 7/7/10 11:38 AM, Victor Subervi wrote: >> Hi; >> I have this code: >> >> sql = 'insert into personalDataKeys values (%s, %s, %s)' % (store, >> user, ', %s'.join('%s' * len(col_vals)) >> cursor.execute(sql, col_vals) > > First, its always best to be explicit with insert statements. Meaning, > don't rely on the underlining structure of a table, as in: > > INSERT INTO YourRandomTable VALUES ("my", "value", "here"); > > Instead, do: > > INSERT INTO YourRandomTable (field1, field2, field3) VALUES ("my", > "value", "here"); I suddenly feel a need to come back and explain *why* I make the claim to 'best' above: the explicit naming of the fields in the INSERT, specifically, since others have shown how to do the INSERT safely while keeping the essentially variable number of items in the values clause. I still would advise against that approach even if it is safe from a SQL Injection standpoint: but for a different reason entirely, that of long-term maintainability. No design is perfect; no customer specification (no matter how vetted, analyzed, and approved by stakeholders) survives implementation and real-life usage. If you always select specific columns in a specific order (i.e., always SELECT this, that, other; and never SELECT *), and always insert with your columns specified (i.e., always INSERT INTO blah (this, that, other) and never INSERT INTO blah VALUES (..)), then it lets you adapt your application in the future when something comes up. Specifically, it lets you add new columns without breaking everything :) Now, those new columns would need to either allow NULL's or have a default value of course. But some day down the road you can go and do an ALTER TABLE to add say, "my_whatever" to the above, and you don't suddenly have to vet every single piece of code which accesses that table. All the existing code will still work: its getting the pieces of data it knows how to use. As you need to, you can adjust that code to take into account this new piece of data. But by making any new additions "optional" in your SQL, and making all your other accesses explicit, it just eases migration and maintenance in future updates. Some may disagree, I dunno. I just find in my experience that following that practice has saved a lot of time and effort down the road. (Especially during migrations from old versions to new versions, and running versions concurrently during some test-phase, etc, or rolling back a new version if a critical bug is found: the changes made to the database to support the new versions can safely persist without you having to do a much more expensive / time-consuming restoration of the database from a backup). -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From no.email at nospam.invalid Thu Jul 8 13:03:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 08 Jul 2010 10:03:30 -0700 Subject: Debugging a segmentation fault References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: <7x7hl5kisd.fsf@ruckus.brouhaha.com> "DierkErdmann at mail.com" writes: > my python project crashes in a non reproducible way. With gdb I got > the backtraces given below. > How can I possibly figure out the reason for the segfaults that occur > under Linux and Windows, using Python 2.6 in both cases. It's a big C program and you have to debug it as one. Well, first of all try upgrading to the newest versions and see if there is already a fix. Be especially suspicious of any C extension modules you're using. There are also some compile time options that let you rebuild Python with extra consistency checks for reference counts. Turn those on and see what happens. From askutt at gmail.com Thu Jul 8 13:04:38 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 10:04:38 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: On Jul 8, 11:36?am, Mark Dickinson wrote: > I think that's because we're talking at cross-purposes. > > To clarify, suppose you want to compute some value (pi; ?log(2); > AGM(1, sqrt(2)); whatever...) to 1000 significant decimal places. > Then typically the algorithm (sometimes known as Ziv's onion-peeling > method) looks like: > > (1) Compute an initial approximation to 1002 digits (say), with known > absolute error (given by a suitable error analysis); for the sake of > argument, let's say that you use enough intermediate precision to > guarantee an absolute error of < 0.6 ulps. > > (2) Check to see whether that approximation unambiguously gives you > the correctly-rounded 1000 digits that you need. > > (3) If not, increase the target precision (say by 3 digits) and try > again. > > It's the precision increase in (3) that I was calling small, and > similarly it's step (3) that isn't usually needed more than once or > twice. ?(In general, for most functions and input values; ?I dare say > there are exceptions.) > > Step (1) will often involve using significantly more than the target > precision for intermediate computations, depending very much on what > you happen to be trying to compute. ?IIUC, it's the extra precision in > step (1) that you don't want to call 'small', and I agree. > > IOW, I'm saying that the extra precision required *due to the table- > maker's dilemma* generally isn't a concern. Yes, though I think attributing only the precision added in step 3 to the table-maker's dilemma isn't entirely correct. While it'd be certainly less of a dilemma if we could precompute the necessary precision, it doesn't' help us if the precision is generally unbounded. As such, I think it's really two dilemmas for the price of one. > > I actually agree with much of what you've said. ?It was just the > "impossible" claim that went over the top (IMO). ?The MPFR library > amply demonstrates that computing many transcendental functions to > arbitrary precision, with correctly rounded results, is indeed > possible. That's because you're latching onto that word instead of the whole sentence in context and making a much bigger deal out of than is appropriate. The fact that I may not be able to complete a given calculation for an arbitrary precision is not something that can be ignored. It's the same notional problem with arbitrary-precision integers: is it better to run out of memory or overflow the calculation? The answer, of course, is a trick question. Adam From dickinsm at gmail.com Thu Jul 8 13:07:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 10:07:23 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> Message-ID: <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> On Jul 8, 2:59?pm, Stefan Krah wrote: > pow() is trickier. Exact results have to be weeded out before > attempting the correction loop for correct rounding, and this is > complicated. > > For example, in decimal this expression takes a long time (in cdecimal > the power function is not correctly rounded): > > Decimal('100.0') ** Decimal('-557.71e-742888888') Hmm. So it does. Luckily, this particular problem is easy to deal with. Though I dare say that you have more up your sleeve. :)? -- Mark From askutt at gmail.com Thu Jul 8 13:22:29 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 10:22:29 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Jul 8, 12:38?pm, "Zooko O'Whielacronx" wrote: > On Thu, Jul 8, 2010 at 4:58 AM, Adam Skutt wrote: > > > I can't think of any program I've ever written where the inputs are > > actually intended to be decimal. ?Consider a simple video editing > > program, and the user specifies a frame rate 23.976 fps. ?Is that what > > they really wanted? ?No, they wanted 24000/1001 but didn't feel like > > typing that. > > Okay, so there was a lossy conversion from the user's intention > (24000/1001) to what they typed in (23.976). > > >>> instr = '23.976' > > Now as a programmer you have two choices: > > 1. accept what they typed in and losslessly store it in a decimal: > > >>> from decimal import Decimal as D > >>> x = D(instr) > >>> print x > > 23.976 > > 2. accept what they typed in and lossily convert it to a float: > > >>> x = float(instr) > >>> print "%.60f" % (x,) > > 23.975999999999999090505298227071762084960937500000000000000000 > > option 2 introduces further "error" between what you have stored in > your program and what the user originally wanted and offers no > advantages except for speed, right? No, you have a third choice, and it's the only right choice: 3. Convert the input to user's desired behavior and behave accordingly. Anything else, here, will result in A/V sync issues. Which is really my point, just because we write '23.976' on the command-line doesn't necessarily mean that's what we meant. Humans are pretty lazy, and we write rational numbers as incomplete decimals all of the time. > But this is not a disadvantage of decimal compared to float is it? > These problems affect both representations. Although perhaps they > affect them differently, I'm not sure. > > I think sometimes people conflate the fact that decimals can easily > have higher and more variable precision than floats with the fact that > decimals are capable of losslessly storing decimal values but floats > aren't. > No, it's not a specific disadvantage of decimal compared to float. I'm not sure why David C. choose to phrase it in those specific terms, though I'm not sure it matters all that much. What I believe is one must understand that the underlying issues are fundamental, and the only way to solve the issues is to educate programmers so they can write code that behaves correctly in the face of rounding. And I do believe you're correct that programmers frequently see one desirable behavior of decimal FP over binary FP and therefore assume all the badness must have gone away. Adam From invalid at invalid.invalid Thu Jul 8 13:24:19 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 17:24:19 +0000 (UTC) Subject: How to test/troubshoot an extension (pylibconfig)? References: Message-ID: On 2010-07-08, Grant Edwards wrote: > On 2010-07-07, Grant Edwards wrote: > >> Oops. Those Python bindings are for version 1.3.2 of libconfig (which >> does work). They don't work with the current version of libconfig. > Python 2.6.5 (release26-maint, Jun 22 2010, 12:58:11) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pylibconfig > >>> conf = pylibconfig.Config() > *** glibc detected *** /usr/bin/python2.6: corrupted double-linked list: 0x08065c48 *** > > Am I correct in concluding it has to be a memory corruption problem in > the library itself? Nope. That problem was cause by having two versions of the library installed -- one under /usr and the other under /usr/local. -- Grant Edwards grant.b.edwards Yow! Gee, I feel kind of at LIGHT in the head now, gmail.com knowing I can't make my satellite dish PAYMENTS! From sridharr at activestate.com Thu Jul 8 13:28:43 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 8 Jul 2010 10:28:43 -0700 Subject: ANN: ActivePython 2.6.5.14 is now available Message-ID: <4B67B387-6AFE-4A5E-9F0D-0E9E070D4FC7@activestate.com> We are pleased to announce the availability of ActivePython 2.6.5.14. http://www.activestate.com/activepython This is a minor release with several bug fixes. As usual, it includes an updated Python Package Manager (PyPM) with updates to essential packages such as Distribute (a compatible fork of setuptools), virtualenv, pip and SQLAlchemy. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6 and 2.7 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business, Enterprise or OEM edition only) - Solaris/x86 (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (Enterprise or OEM edition only) - AIX/PowerPC (Business, Enterprise or OEM edition only) - AIX/PowerPC 64-bit (Business, Enterprise or OEM edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From lists at cheimes.de Thu Jul 8 13:32:15 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 08 Jul 2010 19:32:15 +0200 Subject: Debugging a segmentation fault In-Reply-To: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: > my python project crashes in a non reproducible way. With gdb I got > the backtraces given below. > How can I possibly figure out the reason for the segfaults that occur > under Linux and Windows, using Python 2.6 in both cases. One of your third party C extension has a reference count bug. It looks like it has an Py_INCREF() to little or a Py_DECREF() too much. The first segfaults occurs in a decref macro: Objects/dictobject.c:911 Py_XDECREF(ep->me_value); , the second is a bit more obscure and hidden in the cyclic GC. The error is either introduced by the same reference counting bug or in error in the type definition and initialization. Which third party products with C extensions do you use? Have you updated your database adapter and NumPy yet? Christian From jnoller at gmail.com Thu Jul 8 13:47:27 2010 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 8 Jul 2010 13:47:27 -0400 Subject: Call for Applications - PSF Sponsored Sprints Message-ID: The PSF is happy to open our first call for applications for sprint funding! Have you ever had a group of people together to hack towards a common goal? You've hosted a sprint! Have you ever wanted to get a group of like minded Pythonistas together to hack for a day? You're going to want to hold a sprint! Whether you call them Sprints, Hackfests, Hack-a-thons, or any other name, they're a great way to hang out with like-minded developers and work on common code. Sprints are an unbeatable way to build friendships and contacts that will last for years to come, and they're a great way to learn about something new if you're just starting out. The Python Software Foundation has set aside funds to be distributed to world-wide sprint efforts. We're anticipating 2-3 events per month focused on covering topics to help the entire community: - Python Core bug triage and patch submission (on-boarding new contributors) - Python Core documentation (including process documentation) improvements - Porting libraries/applications to Python 3 - Python website/wiki content improvements - PyPI packaging hosting site improvements - Contribution to other "core" projects, such as packaging related issues. If you are interested in holding a sprint on any of the topics above and you're looking for some money to help out with sprint costs, we can help (up to a max of $250 USD). Prepare an application including the following information: - Date and Location: Where will the event be? What day and time? - Organizers: Who are the event organizers and sprint coach? Is the sprint being run by a Python user group? - Attendees: How many participants do you expect? - Goal: What is the focus and goal of the sprint? - Budget: How much funding you are requesting, and what will you use it for? - Applications should be sent to: sprints at python.org with the subject "Sprint Funding Application - " We encourage anyone - even those who have never held, or been to a sprint - to consider holding one. We will help you as much as we can with welcome packets, advertising, and hooking you up with required resources - anything to make it possible. As part of being approved, the you will need to agree to deliver a report (hopefully, with pictures!) of the sprint to the Sprint Committee, so we can post it on the sprint blog and site: http://www.pythonsprints.com If you have any questions or need more information, contact us by email at sprints at python.org. More information is up on our blog: http://pythonsprints.com/2010/07/8/call-applications-now-open/ From victorsubervi at gmail.com Thu Jul 8 13:48:13 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 8 Jul 2010 13:18:13 -0430 Subject: Is This Open To SQL Injection? In-Reply-To: <4C3601C0.6090501@ixokai.io> References: <4C34CCEB.1060901@ixokai.io> <4C35EBA9.2040703@ixokai.io> <4C3601C0.6090501@ixokai.io> Message-ID: I've come to the realization that I don't need FKs at all here. Essentially, what I need to do is consult personalDataKeys simply to determine what data should be loaded into and retrieved from personalData. I was mistaken because the data are not interdependent, it only appeared that way superficially. No, the data aren't loaded into one big table. There are about 10 fields each in these tables. Yes, I should rename it to storeUserDataKeys. Thanks again, Stephen. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From xcr4cx at googlemail.com Thu Jul 8 13:56:29 2010 From: xcr4cx at googlemail.com (christian schulze) Date: Thu, 8 Jul 2010 10:56:29 -0700 (PDT) Subject: pySimpleSessions - PHP sessions implemented in Python Message-ID: Hey, since there is no standalone sessions module for python (at least a properly working one), I created one and thought i'd share it with you. This is the project: http://code.google.com/p/pysimplesessions/ This is the introduction: http://code.google.com/p/pysimplesessions/wiki/Introduction And finally the module source: http://code.google.com/p/pysimplesessions/source/browse/trunk/sessions.py If you need, there are some examples (partly working *g*): http://code.google.com/p/pysimplesessions/source/browse/trunk/#trunk/examples It would be great if I could get some feedback from you. ;) cheers, From stefan-usenet at bytereef.org Thu Jul 8 14:00:14 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 20:00:14 +0200 Subject: Python -- floating point arithmetic In-Reply-To: References: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: <20100708180014.GA32099@yoda.bytereef.org> Adam Skutt wrote: > > > I actually agree with much of what you've said. ?It was just the > > "impossible" claim that went over the top (IMO). ?The MPFR library > > amply demonstrates that computing many transcendental functions to > > arbitrary precision, with correctly rounded results, is indeed > > possible. > That's because you're latching onto that word instead of the whole > sentence in context and making a much bigger deal out of than is > appropriate. The fact that I may not be able to complete a given > calculation for an arbitrary precision is not something that can be > ignored. It's the same notional problem with arbitrary-precision > integers: is it better to run out of memory or overflow the > calculation? The answer, of course, is a trick question. In the paper describing his strategy for correct rounding Ziv gives an estimate for abnormal cases, which is very low. This whole argument is a misunderstanding. Mark and I argue that correct rounding is quite feasible in practice, you argue that you want guaranteed execution times and memory usage. This is clear now, but was not so apparent in the "impossible" paragraph that Mark responded to. I think asking for strictly bounded resource usage is reasonable. In cdecimal there is a switch to turn off correct rounding for exp() and log(). Stefan Krah From Bryan.Stopp at argushealth.com Thu Jul 8 14:01:33 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 13:01:33 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C360203.8060309@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C360203.8060309@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935B2@ARG-EXVS03.corp.argushealth.com> These are good points, but I've fixed the configure & config.guess on about 10 other OSS projects that I needed to compile on this machine. So I know that my changes are correct. The changes boil down to: There are a number of lines in the files that reference AIX versions for configuring details about the system. Specifically, it'll be "if" or "case" statements that look like: *-ibm-aix5*) *aix4*|*aix5*) I just add the aix6 clause: *-ibm-aix5* | *-ibm-aix6*) *aix4*|*aix5*|*aix6*) As Aix6 is binary compatible with 5, but the configure defaults it to an unknown AIX version and completely mis-configures the compiler. As for using the autoconf tool for my system, I'm not really sure if it's even installed or if the latest autoconf supports this version. Oddly enough I'm not the sys admin, but I do play one on TV. I do want to stick with Python 2.6 if I can, but I will give compiling 2.7 a shot to see what, if anything, changes/is fixed. Thanks for the feedback! -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Thursday, July 08, 2010 11:51 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I've seen other threads on this issue, but the resolution still doesn't > seem to exist for me. > > > > I'm running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they're not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From stefan-usenet at bytereef.org Thu Jul 8 14:11:34 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Thu, 8 Jul 2010 20:11:34 +0200 Subject: Python -- floating point arithmetic In-Reply-To: <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <5ca66045-2fbc-4e5d-8aa3-c06d2155781f@y11g2000yqm.googlegroups.com> Message-ID: <20100708181134.GA32553@yoda.bytereef.org> Mark Dickinson wrote: > On Jul 8, 2:59?pm, Stefan Krah wrote: > > pow() is trickier. Exact results have to be weeded out before > > attempting the correction loop for correct rounding, and this is > > complicated. > > > > For example, in decimal this expression takes a long time (in cdecimal > > the power function is not correctly rounded): > > > > Decimal('100.0') ** Decimal('-557.71e-742888888') > > Hmm. So it does. Luckily, this particular problem is easy to deal > with. Though I dare say that you have more up your sleeve. :)? Not at the moment, but I'll keep trying. :) Stefan Krah From Bryan.Stopp at argushealth.com Thu Jul 8 14:46:38 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Thu, 8 Jul 2010 13:46:38 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C360203.8060309@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C360203.8060309@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935B5@ARG-EXVS03.corp.argushealth.com> I just wanted to follow up my previous email: I tried compiling 2.7 (without editing any config.guess or configure files as they are up to date for AIX6) and it failed with the exact same errors. So I'm still stuck and not sure what I should to do get this to compile. Any other ideas out there? -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Thursday, July 08, 2010 11:51 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > I've seen other threads on this issue, but the resolution still doesn't > seem to exist for me. > > > > I'm running the configure script with these parameters: > > > > ./configure --prefix=/build/tools \ > > --exec-prefix=/build/tools \ > > --enable-shared \ > > --enable-ipv6 \ > > --with-gcc \ > > --with-pth > > > > I also want to state that I already edited all of the configure & > config.guess scripts to comprehend AIX6.1 (they're not updated yet). This smells horribly like rather risky business. I don't know what you changed or how experienced you are when it comes to editing these auto-generated, system-specific files. Have you tried with Python 2.7, or do you need 2.6? Python 2.7 might work here? Since configure and config.guess are auto-generated, maybe you can regenerate them with a newer/updated version of autoconf that supports your system. Quite frankly, it surprises me that changes to configure would be necessary. Is the system that unusual? What happens if you --disable-shared ? I expect you want the shared library, but - does it work? Just some random thoughts -- I know nothing about AIX and little about cross-UNIX portability beyond, to an extent, GNU vs BSD. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From luismgz at gmail.com Thu Jul 8 14:52:39 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 11:52:39 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c30f5e9$0$1586$742ec2ed@news.sonic.net> Message-ID: On Jul 4, 5:58?pm, John Nagle wrote: > ? ? TheUnladenSwallowpeople should in theory be able to reach > that level of performance. ?(Both groups are employed at Google. > So their effectiveness will be compared.) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle No. Collin Winter said that they will never be as fast as Chrome's V8 or similar JS engines, since they were created from scratch to be super fast above all else. On the other hand, US is a project to enhance an existing interpreter, carrying a lot of the burden of early design decisions. From zooko at zooko.com Thu Jul 8 15:15:08 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Thu, 8 Jul 2010 13:15:08 -0600 Subject: Python -- floating point arithmetic In-Reply-To: References: <4C346DA0.1070708@tu-clausthal.de> <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> Message-ID: On Thu, Jul 8, 2010 at 11:22 AM, Adam Skutt wrote: > On Jul 8, 12:38?pm, "Zooko O'Whielacronx" wrote: >> Now as a programmer you have two choices: ? >> 1. accept what they typed in and losslessly store it in a decimal: ? >> 2. accept what they typed in and lossily convert it to a float: > No, you have a third choice, and it's the only right choice: > 3. Convert the input to user's desired behavior and behave > accordingly. ?Anything else, here, will result in A/V sync issues. Okay, please tell me about how this is done. I've never dealt with this sort of issue directly. As far as I can imagine, any way to implement option 3 will involve accepting the user's input and storing it in memory somehow and then computing on it. As far as I can tell, doing so with a decimal instead of a float will never be worse for your outcome and will often be better. But, please explain in more detail how this works. Thanks! Regards, Zooko From subterraneus at gmail.com Thu Jul 8 15:17:57 2010 From: subterraneus at gmail.com (Alex Karpinski) Date: Thu, 8 Jul 2010 15:17:57 -0400 Subject: Python Multi-Channel Audio Message-ID: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> I'm looking for some module or system of modules that can help me do a few things with audio 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) 2. Seek within the file 3. Control volume 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. (For the curious: This is part of the audio system for a larger immersive theater project, ) From luismgz at gmail.com Thu Jul 8 15:19:22 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 12:19:22 -0700 (PDT) Subject: How is Unladen Swallow coming along? References: <4c360004$0$1607$742ec2ed@news.sonic.net> Message-ID: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> On Jul 8, 1:42?pm, John Nagle wrote: > ? ? How is Unladen Swallow coming along? ?Looking at the site, code is > being checked in and issues are being reported, but the last quarterly > release was 2009 Q3. ?They missed their January 2010 release date > for "2009 Q4", so they're now about 6 months behind their project > plan. > > ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Don't be shy. Ask this question in Unladen Swallow's google group. They don't bite! Luis From askutt at gmail.com Thu Jul 8 15:33:09 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 8 Jul 2010 12:33:09 -0700 (PDT) Subject: Python -- floating point arithmetic References: <6d32add5-a956-4b13-af73-3946cd47652e@g19g2000yqc.googlegroups.com> <7bdfce73-c36e-4bdc-9e82-fe62d0cffc72@c33g2000yqm.googlegroups.com> <895e6996-d1c3-47c1-be22-f470e859781b@w31g2000yqb.googlegroups.com> <9f034dba-a9e4-44c1-a5e4-75229909988a@d16g2000yqb.googlegroups.com> <9c76f343-5edd-4b15-83cd-a32e0fad1c27@c33g2000yqm.googlegroups.com> Message-ID: <6c6f0bc4-040c-4092-9adc-acbac99d45e2@r27g2000yqb.googlegroups.com> On Jul 8, 2:00?pm, Stefan Krah wrote: > > This whole argument is a misunderstanding. Mark and I argue that correct > rounding is quite feasible in practice, you argue that you want guaranteed > execution times and memory usage. This is clear now, but was not so apparent > in the "impossible" paragraph that Mark responded to. No, that's what I'm arguing for, though such a feature is important. I'm pointing out that the feasibility of correct rounding is entirely dependent on what you're doing. For IEEE-754 double, it's feasible for the elementary functions if you can tolerate intermediate calculations that are more than twice as large as your double in the corner cases. Certainly, for a single calculation, this is acceptable, but at how many calculations is it no longer acceptable? Adam From invalid at invalid.invalid Thu Jul 8 15:55:03 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 8 Jul 2010 19:55:03 +0000 (UTC) Subject: Question about odd code in libconfig bindings Message-ID: I'm playign with Python bindings for libconfig, and one of the methods does something that seems very odd to me. The purpose of the method is to fetch the value found a a particular path within the configuration namespace. If the path exists and has a scalar value the method returns the tuple (,True). Otherwise it returns ('',False). AFAICT, the latter happens in either of two cases: the path doesn't exist at all, or the path exists but doesn't have a scalar value (it's an aggretate object such as a list, group, or array). This seems distinctly un-pythonic. I would think that the right thing to do would be to either return the requested value or raise an exception. The libconfig C++ API defines a "SettingNotFound" exception and "SettingTypeException" that seem appropriate in the two failure cases. Is there something about implementing bindings using Boost that makes this sort of (,) return tuple a desirable way to do things? FWIW, here's the method I find puzzling: tuple value ( const char * path ) { std::string v_string; if ( config->lookupValue ( path, v_string ) ) return make_tuple ( v_string.c_str(), true ); unsigned int v_uint; if ( config->lookupValue ( path, v_uint ) ) return make_tuple ( v_uint, true ); int v_int; if ( config->lookupValue ( path, v_int ) ) return make_tuple ( v_int, true ); bool v_bool; if ( config->lookupValue ( path, v_bool ) ) return make_tuple ( v_bool, true ); unsigned long long v_ulonglong; if ( config->lookupValue ( path, v_ulonglong ) ) return make_tuple ( v_ulonglong, true ); long long v_longlong; if ( config->lookupValue ( path, v_longlong ) ) return make_tuple ( v_longlong, true ); float v_float; if ( config->lookupValue ( path, v_float ) ) return make_tuple ( v_float, true ); double v_double; if ( config->lookupValue ( path, v_double ) ) return make_tuple ( v_double, true ); return make_tuple ( "", false ); } -- Grant Edwards grant.b.edwards Yow! Don't SANFORIZE me!! at gmail.com From sturlamolden at yahoo.no Thu Jul 8 16:10:30 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:10:30 -0700 (PDT) Subject: "is not" operator? Message-ID: What happens here? Does Python (2.6.5) have an "is not" operator? >>> a = 5 >>> print (a is not False) True >>> print (a is (not False)) False >>> print (not (a is False)) True It seems "y is not x" fits well with spoken English, but it is also a bit surprising that "y is not x" does not mean "y is (not x)" but "not (y is x)". Why does Python reorder is and not operators, and what are the formal rules for this behavior? From sturlamolden at yahoo.no Thu Jul 8 16:15:40 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:15:40 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <8fc76020-ad45-40f4-9dbe-2b21c541be8d@e5g2000yqn.googlegroups.com> Message-ID: <04a74fe4-b731-4faf-8621-7c49f8c6a209@z10g2000yqb.googlegroups.com> On 4 Jul, 21:59, Stefan Behnel wrote: > > I have already said I don't care about unladen swallow. > > What I meant, was: which of these benchmarks would have to be better to > make you care? Because your decision not to care seems to be based on > exactly these benchmarks. Those are the only one I've seen. From jkrukoff at ltgc.com Thu Jul 8 16:29:13 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Thu, 08 Jul 2010 14:29:13 -0600 Subject: "is not" operator? In-Reply-To: References: Message-ID: <1278620953.7825.1.camel@localhost.localdomain> On Thu, 2010-07-08 at 13:10 -0700, sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? > > >>> a = 5 > >>> print (a is not False) > True > >>> print (a is (not False)) > False > >>> print (not (a is False)) > True > > It seems "y is not x" fits well with spoken English, but it is also a > bit surprising that "y is not x" does not mean "y is (not x)" but "not > (y is x)". Why does Python reorder is and not operators, and what are > the formal rules for this behavior? Don't forget about the similar "not in", as in: >>> 'a' not in 'abc' False This is probably the section of documentation you want: http://docs.python.org/reference/expressions.html#notin -- John Krukoff Land Title Guarantee Company From robert.kern at gmail.com Thu Jul 8 16:32:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Jul 2010 16:32:10 -0400 Subject: "is not" operator? In-Reply-To: References: Message-ID: On 7/8/10 4:10 PM, sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? Yes. From Grammar/Grammar: comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' '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 sturlamolden at yahoo.no Thu Jul 8 16:41:43 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:41:43 -0700 (PDT) Subject: "is not" operator? References: Message-ID: On 8 Jul, 22:32, Robert Kern wrote: > > What happens here? Does Python (2.6.5) have an "is not" operator? > > Yes. From Grammar/Grammar: > > comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' Thanks :) From nagle at animats.com Thu Jul 8 16:44:29 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 13:44:29 -0700 Subject: How is Unladen Swallow coming along? In-Reply-To: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> Message-ID: <4c3638b0$0$1660$742ec2ed@news.sonic.net> On 7/8/2010 12:19 PM, Luis M. Gonz?lez wrote: > On Jul 8, 1:42 pm, John Nagle wrote: >> How is Unladen Swallow coming along? Looking at the site, code is >> being checked in and issues are being reported, but the last quarterly >> release was 2009 Q3. They missed their January 2010 release date >> for "2009 Q4", so they're now about 6 months behind their project >> plan. >> >> ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") >> >> John Nagle > > Don't be shy. > Ask this question in Unladen Swallow's google group. They don't bite! Found this: "http://www.python.org/dev/peps/pep-3146/#performance-retrospective" It's starting to work, but the performance improvement is tiny, well under 2x faster than CPython. Only 1.08x on "html5lib". That's far less than they expected. They were going for 5x, which is far less than Shed Skin (which restricts Python) already achieves. John Nagle From sturlamolden at yahoo.no Thu Jul 8 16:44:35 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 13:44:35 -0700 (PDT) Subject: "is not" operator? References: mailman.442.1278621575.1673.python-list@python.org Message-ID: <28c0e59c-baaf-416a-9e24-9f55e4febc60@j4g2000yqh.googlegroups.com> On 8 Jul, 22:29, John Krukoff wrote: > Don't forget about the similar "not in", as in: I noticed that in the grammar Robert posted. It never occurred to me as being a special operator too, but it is. From wolfram.hinderer at googlemail.com Thu Jul 8 16:52:56 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Thu, 8 Jul 2010 13:52:56 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> Message-ID: <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> On 8 Jul., 15:10, Ethan Furman wrote: > Interesting. ?I knew when I posted my above comment that I was ignoring > such situations. ?I cannot comment on the code itself as I am unaware of > the algorithm, and haven't studied numbers extensively (although I do > find them very interesting). > > So while you've made your point, I believe mine still stands -- > comparing floats using == to absolute numbers is almost always a mistake. JFTR, it works because a+b == a+b (while I don't think that a+b == b+a holds for all a and b). In general, I totally agree with you. From tompelka at gmail.com Thu Jul 8 17:07:18 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Thu, 08 Jul 2010 23:07:18 +0200 Subject: object exported through manager from multiprocess module Message-ID: <4C363E06.6000103@gmail.com> Hi all, have troubles with exporting objects through managers from multiprocess module, see example: Worker.py: ################################### from multiprocessing import Process from multiprocessing.managers import BaseManager import pcapy from impacket.ImpactDecoder import EthDecoder __all__ = ['Worker'] class Worker(Process): ''' Class for sniffing packets, runnig as root ''' public = ['go', 'terminate'] def __init__(self): super(Worker, self).__init__() self.iface = '' self.expr = '' self.pcap = '' # define packet decoder self.decoder = EthDecoder() # key for queue daemon, remotely on localhost:5000 self._keyQ = '10b222970537b97919db36ec757370d2' class QueueManager(BaseManager): pass QueueManager.register('get_dataQueue') self._m = QueueManager(address=('127.0.0.1', 5000), authkey=self._keyQ) self._m.connect() self.dataQueue = self._m.get_dataQueue() def go(self, iface, expr): ''' start sniffer ''' print "Starting sniffer" self.iface = iface self.expr = expr super(Worker, self).start() def terminate(self): ''' terminate sniffer ''' super(Worker, self).terminate() def run(self): print "sniffing ..." print self.iface print self.expr self.pcap = pcapy.open_live(self.iface, 1500, 1, 0) self.pcap.setfilter(self.expr) self.pcap.loop(0, self.__packetHandler) print "... done" def __packetHandler(self, hdr, data): ''' handles packets and put them in to the queue ''' print "Handling packets" #print data print "Queue size: %i" % self.dataQueue.qsize() print self.decoder.decode(data) self.dataQueue.put(data) Export object (Worker): ################################### from Worker import Worker class SniffManager(BaseManager): pass SniffManager.register('Worker', callable=Worker) Sm = SniffManager(address=('127.0.0.1', 5001), authkey='f1f16683f3e0208131b46d37a79c8921') Ss = Sm.get_server() Ss.serve_forever() Call object methods remotely: ################################### # get remote object class WorkerManager(BaseManager): pass WorkerManager.register('Worker') w = WorkerManager(address=('127.0.0.1', 5001), authkey='f1f16683f3e0208131b46d37a79c8921') w.connect() worker = w.Worker() worker.go(iface="ethx", expr="whatever") # WORKS FINE but worker.terminate() File "/home/tom/web2py/applications/init/controllers/sniffer.py", line 143, in index worker.terminate() File "", line 2, in terminate File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in _callmethod raise convert_to_error(kind, result) AttributeError: 'NoneType' object has no attribute 'terminate' Which is strange from my point of view, don't you think? Thanks for advices, cheers -- Tomas Pelka -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Thu Jul 8 17:11:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 08 Jul 2010 23:11:50 +0200 Subject: Python Multi-Channel Audio In-Reply-To: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> References: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> Message-ID: <4C363F16.4030301@jollans.com> On 07/08/2010 09:17 PM, Alex Karpinski wrote: > I'm looking for some module or system of modules that can help me do a few things with audio > > 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) > 2. Seek within the file > 3. Control volume > 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 > > I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. First of all, allow me to point to a something I hacked together (mostly) a few weeks ago: http://bitbucket.org/jollybox/pyaudiogen/wiki/Home It's something of a library, VERY minimal/skeletal at the moment, for audio generation (and/or processing) in Python. No idea if this is of any help to you. Python 3 only. Multiple channel support is there, though to be useful it'd still need a bit of glue. Not much to see there yet all in all. > > (For the curious: This is part of the audio system for a larger immersive theater project, ) Though really, what I think you want is jack. It basically allows you to plug things together in any way, and I'm sure you can control the volume of individual "plugs". I expect there is a Python API, but I haven't checked. From gneuner2 at comcast.net Thu Jul 8 17:13:58 2010 From: gneuner2 at comcast.net (George Neuner) Date: Thu, 08 Jul 2010 17:13:58 -0400 Subject: C interpreter in Lisp/scheme/python References: <5032d354-3017-45c2-b4f3-417457ac5247@z8g2000yqz.googlegroups.com> <734278b3-f5c0-49b8-a1a1-c54919231631@c10g2000yqi.googlegroups.com> <87lj9mfju6.fsf@kuiper.lan.informatimago.com> Message-ID: On Thu, 08 Jul 2010 10:39:45 +0200, pjb at informatimago.com (Pascal J. Bourguignon) wrote: >Nick Keighley writes: >> Nick Keighley wrote: >>> Rivka Miller wrote: >> >>>> Anyone know what the first initial of L. Peter Deutsch stand for ? >>> >>> Laurence according to wikipedia (search time 2s) >> >> oops! He was born Laurence but changed it legally to "L." including >> the dot > >Too bad, "Laurence" is a nice name. He probably hates the nickname "Larry". From daniel at stutzbachenterprises.com Thu Jul 8 17:14:01 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 8 Jul 2010 16:14:01 -0500 Subject: ANN: winreg_unicode 0.5.0 Message-ID: I'm pleased to announce the release of winreg_unicode 0.5.0, the first release of winreg_unicode. The winreg_unicode package aims to be a drop-in replacement for Python 2's _winreg module. However, it returns unicode values where possible, similar to Python 3's winreg module. To illustrate the need for the winreg_unicode package, suppose an application must query the registry to discover a filename and the registry contains the string "me?uresorna.txt". Python 2's _winreg module will return "meduresorna.txt" instead, which is not the actual name of the file. The winreg_unicode package does not yet contain all of _winreg's functions. In particular, functions that write to the registry are not yet included. Code contributions are welcome. PyPi: http://pypi.python.org/pypi/winreg_unicode Bug tracker: http://github.com/DanielStutzbach/winreg_unicode/issues Source code: http://github.com/DanielStutzbach/winreg_unicode -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From huhai101 at gmail.com Thu Jul 8 17:29:21 2010 From: huhai101 at gmail.com (wholesale football clothes) Date: Thu, 8 Jul 2010 14:29:21 -0700 (PDT) Subject: cheap sale NBA caps and hats ( www.nike-black.com ) Message-ID: Discount smet caps( www.nike-black.com ) cheapsale NBA caps and hats ( www.nike-black.com ) Supply AFF CAPS and hat ( www.nike-black.com ) cheapsale winter warm caps ( www.nike-black.com ) Discount ed hardy hats and caps ( www.nike-black.com ) Discount juicy caps ( www.nike-black.com ) Discount dc hats and caps ( www.nike-black.com ) Discount ca caps ( www.nike-black.com ) Cheap ny caps ( www.nike-black.com ) Cheap polo caps and hats ( www.nike-black.com ) Cheap bape caps ( www.nike-black.com ) Supply Caddice caps ( www.nike-black.com ) New Fasion Hats & Caps Monster Energy ( www.nike-black.com ) Monster Energy Hats ( www.nike-black.com ) Monster Energy Drink Hats ( www.nike-black.com ) White Monster Energy Hats ( www.nike-black.com ) Monster Energy Fitted Hats ( www.nike-black.com ) Youth Monster Energy Hats Monster Energy New Era Hats ( www.nike-black.com ) Monster Energy Cap ( www.nike-black.com ) Monster Energy Drink Cap ( www.nike-black.com ) White Monster Energy Cap ( www.nike-black.com ) Monster Energy Fitted Cap ( www.nike-black.com ) Youth Monster Energy Cap Red Bull Hats ( www.nike-black.com ) Monster Energy New Era Cap ( www.nike-black.com ) Red Bull New Era ( www.nike-black.com ) Red Bull Caps ( www.nike-black.com ) Red Bull Fitted Hat ( www.nike-black.com ) Red Bull New Era Hats ( www.nike-black.com ) Red Bull Energy Hats ( www.nike-black.com ) White Red Bull Hats ( www.nike-black.com ) Black Red Bull Hats Blue Red Bull Hats ( www.nike-black.com ) Red Bull Hats Ebay ( www.nike-black.com ) Buy Red Bull Hats ( www.nike-black.com ) Team Red Bull Hats ( www.nike-black.com ) Red Bull New Era Hats ( www.nike-black.com ) Red Bull Baseball Hats ( www.nike-black.com ) New Era Caps New Era Hats ( www.nike-black.com ) New Era NY Caps ( www.nike-black.com ) New Era NY Hats ( www.nike-black.com ) Website: http://www.nike-black.com From debatem1 at gmail.com Thu Jul 8 17:41:57 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 8 Jul 2010 14:41:57 -0700 Subject: Python Multi-Channel Audio In-Reply-To: <4C363F16.4030301@jollans.com> References: <2F9C069E-AF4E-400F-8B20-1F4C673B9DB9@gmail.com> <4C363F16.4030301@jollans.com> Message-ID: On Thu, Jul 8, 2010 at 2:11 PM, Thomas Jollans wrote: > On 07/08/2010 09:17 PM, Alex Karpinski wrote: >> I'm looking for some module or system of modules that can help me do a few things with audio >> >> 1. Playback of files (at least .wavs, other codecs would be nice but, hey, converting to a wav is easy) >> 2. Seek within the file >> 3. Control volume >> 3. Do all of these things by channel, e.g. play sound effect 1 on channels 1&2 at equal volume and play effect #2 on only channel 2 >> >> I've got a setup with gstreamer and alsa right now, but I don't have any way of getting control of individual channels at the gstreamer level. I can easily do it at the alsa level and just manipulate the master left/right output, but that's not very helpful if it modifies all currently playing effects. I'm not even sure if this is possible to do with python, butsome pointers would really be great. > > First of all, allow me to point to a something I hacked together > (mostly) a few weeks ago: > http://bitbucket.org/jollybox/pyaudiogen/wiki/Home > > It's something of a library, VERY minimal/skeletal at the moment, for > audio generation (and/or processing) in Python. No idea if this is of > any help to you. Python 3 only. Multiple channel support is there, > though to be useful it'd still need a bit of glue. Not much to see there > yet all in all. > >> >> (For the curious: This is part of the audio system for a larger immersive theater project, ) > > Though really, what I think you want is jack. It basically allows you to > plug things together in any way, and I'm sure you can control the volume > of individual "plugs". > I expect there is a Python API, but I haven't checked. Untried: http://sourceforge.net/projects/py-jack/ Geremy Condra From no.email at nospam.invalid Thu Jul 8 17:44:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 08 Jul 2010 14:44:37 -0700 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> Message-ID: <7xbpahd4xm.fsf@ruckus.brouhaha.com> Wolfram Hinderer writes: > JFTR, it works because a+b == a+b (while I don't think that a+b == b+a > holds for all a and b). I'm pretty sure IEEE 754 addition is always commutative (except maybe in the presence of infinity or NaN and maybe not even then). It differs from rational or real-number arithmetic in that it is not always associative. You can have (a+b)+c != a+(b+c). From luismgz at gmail.com Thu Jul 8 17:51:39 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 8 Jul 2010 14:51:39 -0700 (PDT) Subject: How is Unladen Swallow coming along? References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> <4c3638b0$0$1660$742ec2ed@news.sonic.net> Message-ID: <754462d1-6a2f-4b3e-a206-3dbc55975920@w12g2000yqj.googlegroups.com> On Jul 8, 5:44?pm, John Nagle wrote: > On 7/8/2010 12:19 PM, Luis M. Gonz?lez wrote: > > > On Jul 8, 1:42 pm, John Nagle ?wrote: > >> ? ? ?How is Unladen Swallow coming along? ?Looking at the site, code is > >> being checked in and issues are being reported, but the last quarterly > >> release was 2009 Q3. ?They missed their January 2010 release date > >> for "2009 Q4", so they're now about 6 months behind their project > >> plan. > > >> ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > > > Don't be shy. > > Ask this question in Unladen Swallow's google group. They don't bite! > > ? ? Found this: > > "http://www.python.org/dev/peps/pep-3146/#performance-retrospective" > > ? ? It's starting to work, but the performance improvement is tiny, > well under 2x faster than CPython. ?Only 1.08x on "html5lib". > That's far less than they expected. ?They were going for 5x, > which is far less than Shed Skin (which restricts Python) > already achieves. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Shedskin is an heroic effort by Mark Dufour, but comparing it to Cpython is like comparing oranges to apples. Shedskin is not an interpreter, it's just a way to compile implicitly statically typed python code to c++. So the project is more along the lines of Pyrex/Cython in its goals. I believe it's a great way to compile extension modules written in restricted python, although it could compile entire programs provided they don't rely on non supported libraries or modules. Only a few are supported to different degrees of completeness. At this moment, it seems that Pypy is the project holding more promises. Although I guess Guido has strong reasons to support Unladen Swallow. Lets see what happens... Luis From dickinsm at gmail.com Thu Jul 8 17:54:27 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 8 Jul 2010 14:54:27 -0700 (PDT) Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <7cb304c9-8df2-4533-8f4e-634372867dca@j8g2000yqd.googlegroups.com> <44d44dce-1bfc-4329-9441-2e800f473393@b35g2000yqi.googlegroups.com> Message-ID: <1b9dded9-75dc-4cf2-a872-6b26e1ac6ab3@t10g2000yqg.googlegroups.com> On Jul 8, 9:52?pm, Wolfram Hinderer wrote: > JFTR, it works because a+b == a+b (while I don't think that a+b == b+a > holds for all a and b). Actually, that's one of the few identities that's safe. Well, for non- NaN IEEE 754 floating-point, at any rate. And assuming that there's no use of extended precision to compute intermediate results (in which case one side could conceivably be computed with different precision from the other; but that applies to a+b == a+b, too). And assuming that no FPE signals occur and halt the program... (e.g., for overflow, or from doing -inf + inf). Okay, maybe not that safe, then. :) For NaNs, there are two problems: first, if exactly one of a and b is a NaN then a+b and b+a will both be NaNs, so a + b == b + a will be false, even though they're identical. Second, if a and b are *both* NaNs, and you're feeling really fussy and care about signs and payloads, then a + b and b + a won't even necessarily be bitwise identical: a + b will have the sign and payload of a, while b + a has the sign and payload of b. You can see something similar with the Decimal module: >>> Decimal('NaN123') + Decimal('-NaN456') Decimal('NaN123') >>> Decimal('-NaN456') + Decimal('NaN123') Decimal('-NaN456') Or more directly (just for fun), using the struct module to create particular nans: >>> import struct >>> x = struct.unpack('>> y = struct.unpack('>> x nan >>> y nan >>> struct.pack('>> struct.pack(' References: Message-ID: On 19-6-2010 23:45, Shashwat Anand wrote: > Terry: Thanks for bringing this to notice. > Mark: Kudos for your effort in cleaning up bugs.python.org > Like I've said elsewhere, flattery will get you everywhere. :) FYI there are now 480 orphans and I've managed to get 8 issues closed. After one week I even got promoted to the triage team, although I found the pay increase rather disappointing. :) Kindest regards. Mark Lawrence. From ncauderan at gmail.com Thu Jul 8 18:20:44 2010 From: ncauderan at gmail.com (norbert) Date: Thu, 8 Jul 2010 15:20:44 -0700 (PDT) Subject: SMTPHandler and Unicode References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <99526b81-1a71-4503-b61b-94dc4dc882ff@w12g2000yqj.googlegroups.com> Message-ID: <7ebf6973-4900-4865-85b1-78231f8396ad@w12g2000yqj.googlegroups.com> On Jul 5, 3:35?pm, Antoine Pitrou wrote: > I suggest you report an issue onhttp://bugs.python.org done : http://bugs.python.org/issue9208 From nyamatongwe+thunder at gmail.com Thu Jul 8 20:02:30 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 09 Jul 2010 10:02:30 +1000 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: sturlamolden: > Windows did this too (msvcrt.dll) up to the VS2003 release, which came > with msvcr71.dll in addition. Since then, M$ (pronounced Megadollar > Corp.) have published msvcr80.dll, msvcr90.dll, and msvcr100.dll (and > corresponding C++ versions) to annoy C and C++ developers into > converting to C# .NET. (And yes, programs using third-party DLL and > OCX components become unstable from this. You have to check each DLL/ > OCX you use, and each DLL used by each DLL, etc. How fun...) One of the benefits to COM is that it acts as a C runtime firewall - it has its own memory allocation interface (IMalloc / CoGetMalloc) and file I/O is performed through interfaces like IStream. It is quite common to use an OCX compiled with one compiler in an application compiled with another. If you break the rules by using malloc rather than IMalloc for memory that is deallocated by a different component to that which allocated it or try to pass around FILE* objects then you will see failures. So, always follow the COM rules. Neil From pavlovevidence at gmail.com Thu Jul 8 21:35:36 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 8 Jul 2010 18:35:36 -0700 (PDT) Subject: "is not" operator? References: Message-ID: <267fcbfd-9cfa-4193-9bd8-78a932afe20b@m40g2000prc.googlegroups.com> On Jul 8, 1:32?pm, Robert Kern wrote: > On 7/8/10 4:10 PM, sturlamolden wrote: > > > What happens here? Does Python (2.6.5) have an "is not" operator? > > Yes. From Grammar/Grammar: > > comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' Happy thing, too. I use "is not" a lot more than "is" and am happy to avoid the extra set of parentheses. Carl Banks From anand.shashwat at gmail.com Thu Jul 8 21:37:08 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 9 Jul 2010 07:07:08 +0530 Subject: 500 tracker orphans; we need more reviewers In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 3:28 AM, Mark Lawrence wrote: > On 19-6-2010 23:45, Shashwat Anand wrote: > >> Terry: Thanks for bringing this to notice. >> Mark: Kudos for your effort in cleaning up bugs.python.org >> >> > Like I've said elsewhere, flattery will get you everywhere. :) > I think acknowledgement != flattery, but then you are free to have a different point of view :| > FYI there are now 480 orphans and I've managed to get 8 issues closed. > After one week I even got promoted to the triage team, although I found the > pay increase rather disappointing. :) > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jul 8 22:02:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 09 Jul 2010 03:02:36 +0100 Subject: "is not" operator? In-Reply-To: References: Message-ID: <4C36833C.5020509@mrabarnett.plus.com> sturlamolden wrote: > What happens here? Does Python (2.6.5) have an "is not" operator? > >>>> a = 5 >>>> print (a is not False) > True >>>> print (a is (not False)) > False >>>> print (not (a is False)) > True > > It seems "y is not x" fits well with spoken English, but it is also a > bit surprising that "y is not x" does not mean "y is (not x)" but "not > (y is x)". Why does Python reorder is and not operators, and what are > the formal rules for this behavior? > In English the negative comes after the verb (or the auxiliary, if there is one), so: x is not y If you wanted to abbreviate: x is in y the natural result would be: x in y and the opposite: x is not in y: would be abbreviated to: x not in y The resulting inconsistency in Python is somewhat unfortunate, but in practice it's not a problem because: not y returns either False or True, and how often would you write: x is False or: x is True ? From jackdied at gmail.com Thu Jul 8 22:16:27 2010 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 8 Jul 2010 22:16:27 -0400 Subject: "is not" operator? In-Reply-To: <4C36833C.5020509@mrabarnett.plus.com> References: <4C36833C.5020509@mrabarnett.plus.com> Message-ID: On Thu, Jul 8, 2010 at 10:02 PM, MRAB wrote: > sturlamolden wrote: >> It seems "y is not x" fits well with spoken English, but it is also a >> bit surprising that "y is not x" does not mean "y is (not x)" but "not >> (y is x)". Why does Python reorder is and not operators, and what are >> the formal rules for this behavior? >> > In English the negative comes after the verb (or the auxiliary, if there > is one), so: The right way to think about python syntax is not to consider what is obvious to an LL(1) compiler, or what makes sense in English, but rather "what was the obvious way to write an LL(1) syntax if you are a Dutchman who speaks English?" Hope-that-clears-things-up-ly, -Jack From tim.leslie at gmail.com Thu Jul 8 22:21:10 2010 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 9 Jul 2010 12:21:10 +1000 Subject: "is not" operator? In-Reply-To: References: <4C36833C.5020509@mrabarnett.plus.com> Message-ID: On Fri, Jul 9, 2010 at 12:16 PM, Jack Diederich wrote: > > The right way to think about python syntax is not to consider what is > obvious to an LL(1) compiler, or what makes sense in English, but > rather "what was the obvious way to write an LL(1) syntax if you are a > Dutchman who speaks English?" +1 QOTW > > Hope-that-clears-things-up-ly, > > -Jack > -- > http://mail.python.org/mailman/listinfo/python-list > From schlesin at cshl.edu Thu Jul 8 23:39:52 2010 From: schlesin at cshl.edu (Felix) Date: Thu, 8 Jul 2010 20:39:52 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On Jul 4, 11:25?am, David Cournapeau wrote: > On Mon, Jul 5, 2010 at 12:00 AM, D'Arcy J.M. Cain wrote: > > I wish it was orders of magnitude faster for web development. ?I'm just > > saying that places where we need compiled language speed that Python > > already has that in C. > > Well, I wish I did not have to use C, then :) For example, as a > contributor to numpy, it bothers me at a fundamental level that so > much of numpy is in C. This is something that I have been thinking about recently. Python has won quite a following in the scientific computing area, probably especially because of great libraries such as numpy, scipy, pytables etc. But it also seems python itself is falling further and further behind in terms of performance and parallel processing abilities. Of course all that can be fixed by writing C modules (e.g. with the help of cython), but that weakens the case for using python in the first place. For an outsider it does not look like a solution to the GIL mess or a true breakthrough for performance are around the corner (even though there seem to be many different attempts at working around these problems or helping with parts). Am I wrong? If not, what is the perspective? Do we need to move on to the next language and loose all the great libraries that have been built around python? Felix From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 00:37:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 04:37:52 GMT Subject: Opinions please -- how big should a single module grow? Message-ID: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> This is a style question rather than a programming question. How large (how many KB, lines, classes, whatever unit of code you like to measure in) should a module grow before I should break it up into a package? I see that, for example, decimal.py is > 3000 lines of code, so I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. Where do you draw the line? For the purposes of the discussion, you should consider that the code in the module really does belong together, and that splitting it into sub- modules would mean arbitrarily separating code into separate files. -- Steven From timr at probo.com Fri Jul 9 00:39:44 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 08 Jul 2010 21:39:44 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Christian Heimes wrote: >> Yeah, but then we're down to file descriptors, C library locales and such as the >> remaining problems. > >Don't forget errno! Every CRT might have its own errno thread local. I >don't know how its handled on Windows but I suspect it suffers from the >same problem. No. The multi-thread-aware CRT in Visual C++ (which is the only option since VS2008) puts errno in thread-local storage, so it's shared by all CRTs. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stefan_ml at behnel.de Fri Jul 9 00:44:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 Jul 2010 06:44:07 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: Felix, 09.07.2010 05:39: > On Jul 4, 11:25 am, David Cournapeau wrote: >> Well, I wish I did not have to use C, then :) For example, as a >> contributor to numpy, it bothers me at a fundamental level that so >> much of numpy is in C. > > This is something that I have been thinking about recently. Python has > won quite a following in the scientific computing area, probably > especially because of great libraries such as numpy, scipy, pytables > etc. But it also seems python itself is falling further and further > behind in terms of performance and parallel processing abilities. Well, at least its "parallel processing abilities" are quite good actually. If you have really large computations, they usually run on more than one computer (not just more than one processor). So you can't really get around using something like MPI, in which case an additional threading layer is basically worthless, regardless of the language you use. For computations, threading keeps being highly overrated. WRT a single machine, you should note that GPGPUs are a lot faster these days than even multi-core CPUs. And Python has pretty good support for GPUs, too. > Of course all that can be fixed by writing C modules (e.g. with the help > of cython), but that weakens the case for using python in the first > place. Not at all. Look at Sage, for example. It's attractive because it provides tons of functionality, all nicely glued together through a simple language that even non-programmers can use efficiently and effectively. And its use of Cython makes all of this easily extensible without crossing the gap of a language border. Stefan From stefan_ml at behnel.de Fri Jul 9 00:48:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 Jul 2010 06:48:40 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 09.07.2010 06:37: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. Well, if that's the case, then there's no reason to split it up. However, for any module of substantial growth, I'd expect there to be some point where you start adding section separation comments (Meta-80-#) to make the structure clearer. That might be the time when you should also consider breaking it up into separate source files. Stefan From me+list/python at ixokai.io Fri Jul 9 01:16:08 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 08 Jul 2010 22:16:08 -0700 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36B098.1000409@ixokai.io> On 7/8/10 9:37 PM, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. If that is really true, then it belongs as one module, regardless of size -- I don't believe there's any certain count where you should draw this line. Now, once you get up to say, 5-10 KLOC, I find it hard to believe that everything there really does belong together and there's not a substantial subset of code which really belongs "more" together then it does with the surrounding code. That would then lend itself to be a new file in a package. But that can happen at 1 KLOC too. But then it can still be 5-10 KLOC which, to me, fits perfectly together still. Its just more likely the higher the count that you have subsets that would benefit from logical separation. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From sturlamolden at yahoo.no Fri Jul 9 01:16:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 22:16:11 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: On 9 Jul, 05:39, Felix wrote: > This is something that I have been thinking about recently. Python has > won quite a following in the scientific computing area, probably > especially because of great libraries such as numpy, scipy, pytables > etc. Python is much more friendly to memory than Matlab, and a much nicer language to work in. It can also be used to program more than just linear algebra. If you have to read data from a socket, Matlab is not so fun anymore. > But it also seems python itself is falling further and further > behind in terms of performance and parallel processing abilities. First, fine-grained parallelism really belongs in libraries like MKL, GotoBLAS and FFTW. Python can manage the high-level routines just like Matlab. You can call a NumPy routine like np.dot, and the BLAS library (e.g. Intel MKL) will do the multi-threading for you. We almost always use Python to orchestrate C and Fortran. We can use OpenMP in C or Fortran, or we can just release the GIL and use Python threads. Second, the GIL it does not matter for MPI, as it works with processes. Nor does it matter for os.fork or multiprocessing. On clusters, which are as common in high-performance computing as SMP systems, one has to use processes (usually MPI) rather than threads, as there is no shared memory between processors. On SMP systems, MPI can use shared-memory and be just as efficient as threads (OpenMP). (MPI is usually faster due to cache problems with threads.) Consider that Matlab does not even have threads (or did not last time I checked). Yet it takes advantage of multi-core CPUs for numerical computing. It's not the high-level interface that matters, it's the low-level libraries. And Python is just that: a high-level "glue" language. > For an outsider it does not look like a solution to the GIL mess or a > true breakthrough for performance are around the corner (even though > there seem to be many different attempts at working around these > problems or helping with parts). Am I wrong? Yes you are. We don't do CPU intensive work in "pure Python". We use Python to control C and Fortran libraries. That gives us the opportunity to multi-thread in C, release the GIL and multi-thread in Python, or both. From sturlamolden at yahoo.no Fri Jul 9 01:25:39 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 8 Jul 2010 22:25:39 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> On 9 Jul, 06:44, Stefan Behnel wrote: > WRT a single machine, you should note that GPGPUs are a lot faster these > days than even multi-core CPUs. And Python has pretty good support for > GPUs, too. With OpenCL, Python is better than C for heavy computing. The Python or C/C++ program has to supply OpenCL code (structured text) to the OpenCL driver, which does the real work on GPU or CPU. Python is much better than C or C++ at processing text. There will soon be OpenCL drivers for most processors on the market. But OpenCL drivers will not be pre-installed on Windows, as Microsoft has a competing COM-based technology (DirectX Compute, with an atrocious API and syntax). From roy at panix.com Fri Jul 9 01:30:12 2010 From: roy at panix.com (Roy Smith) Date: Fri, 09 Jul 2010 01:30:12 -0400 Subject: Opinions please -- how big should a single module grow? References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: In article <4c36a7a0$0$28647$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. To paraphrase Einstein, A module should be as large as it needs to be, but no larger. There's no hard and fast rule. More important than counting lines of code is that all the things in a module should represent some coherent set of related functionality. Beyond that, I would say the only hard limit on line count is when common editing tools start to balk at opening the file. From nagle at animats.com Fri Jul 9 01:41:50 2010 From: nagle at animats.com (John Nagle) Date: Thu, 08 Jul 2010 22:41:50 -0700 Subject: Inheriting from "dict" (was: Python dynamic attribute creation) In-Reply-To: <895n87FnsoU1@mid.individual.net> References: <895n87FnsoU1@mid.individual.net> Message-ID: <4c36b6a4$0$1663$742ec2ed@news.sonic.net> On 7/2/2010 1:54 AM, Gregory Ewing wrote: > WANG Cong wrote: > >> Yeah, my point is why setattr() for dynamic attributes while assignments >> for static attributes? > > If you mean using exactly the same syntax for both, that would > require making the static case more verbose, e.g. instead of > > foo.blarg > > you would have to write something like > > foo.("blarg") > > just to allow for the possibility of writing > > foo.(some_arbitrary_expression) Instead of dynamically adding attributes, there's another option: deriving a class from "dict": class HTMLtag(dict) : def __init__(self, tagtype) : self.tagtype = tagtype def __str__(self) : # generate source HTML tag return("<" + self.tagtype + " " + " ".join(map(lambda item: '%s="%s"' % item, self.items())) + ">" tag1 = HTMLtag(a) tag1['href'] = "http://www.example.com" tag1['class'] = "adurl" s = str(tag1) # converts to string This has some advantages. The elements of the dictionary aren't in the same namespace as the attributes of object, so there's no problem with name clashes. Nor is there a problem with reserved words. BeautifulSoup stores HTML tag attributes as object attributes, and they have to special case things like "class". You can iterate over all the elements of the dictionary (as the "__str__" function does above) without interference from attributes which aren't data items. There's no problem with values that aren't valid attribute strings. (Python 2.x won't accept Unicode attributes, for example.) There's no risk of security injection problems because external data overrode a member name or some crucial data attribute. If you find yourself having to write code to avoid any of those problems, like prefixing dynamic attribute names with some symbol to avoid name clashes (or realize, after reading this, that your code has a vulnerability because it's not doing that), it may be better to inherit from "dict" rather than setting attributes explicitly. John Nagle From timr at probo.com Fri Jul 9 03:16:16 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 09 Jul 2010 00:16:16 -0700 Subject: Python -- floating point arithmetic References: <9aacf5ff-c2ec-4a67-b707-cb30c464564f@w31g2000yqb.googlegroups.com> Message-ID: <24jd369ns1ui96vg02h8pe7llo2mi233ab@4ax.com> David Mainzer wrote: > >All your comments helped me and now i know how it works in python ! This has nothing to do with Python. What you're seeing is the way IEEE-754 floating point arithmetic works. You'd see these same results in any programming language, including assembly language (assuming it hasn't changed the rounding mode). -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From davea at ieee.org Fri Jul 9 03:49:10 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 03:49:10 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36D476.7070604@ieee.org> Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > > > I don't have a number for you, but the measure I'd suggest is the size of the documentation. DaveA From davea at ieee.org Fri Jul 9 03:55:45 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 03:55:45 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Message-ID: <4C36D601.9060709@ieee.org> Tim Roberts wrote: > Christian Heimes wrote: > > >>> Yeah, but then we're down to file descriptors, C library locales and such as the >>> remaining problems. >>> >> Don't forget errno! Every CRT might have its own errno thread local. I >> don't know how its handled on Windows but I suspect it suffers from the >> same problem. >> > > No. The multi-thread-aware CRT in Visual C++ (which is the only option > since VS2008) puts errno in thread-local storage, so it's shared by all > CRTs. > I didn't know specifically that errno is in TLS, but I will disagree with the conclusion that a TLS entry is implicitly shared by all CRT's. Unless the CRT for each DLL explicitly does some extra work to allow sharing, each will have its own set of TLS variables. DaveA From nospam at nospam.com Fri Jul 9 04:18:47 2010 From: nospam at nospam.com (Gilles Ganault) Date: Fri, 09 Jul 2010 10:18:47 +0200 Subject: Only one forum app in Python? Message-ID: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Hello I'd like to write a small web app in Python which must include a forum. So I checked the relevant article in Wikipedia, which says that only one forum app is available for Python: http://en.wikipedia.org/wiki/Comparison_of_internet_forum_software_(other) Is Pocoo really the only solution available out there? Thank you. From prologic at shortcircuit.net.au Fri Jul 9 04:29:17 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 9 Jul 2010 18:29:17 +1000 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: On Fri, Jul 9, 2010 at 6:18 PM, Gilles Ganault wrote: > Is Pocoo really the only solution available out there? Did you bother to check pypi ? cheers James 1. http://pypi.python.org/ -- -- James Mills -- -- "Problems are solved by method" From stef.mientki at gmail.com Fri Jul 9 05:21:44 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 09 Jul 2010 11:21:44 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C36EA28.4020502@gmail.com> On 09-07-2010 06:37, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > > > interesting question. >From the answers already given, I assume it doesn't matter, as long as all the functionality in that module is related. Would it be a good idea to split a module in 2 parts, part 1 : everything that would normally accessible from the outside part 2 : everything that is only used inside the module I think in this way a user of the module (that doesn't know the module yet) has a far more easier entrance. cheers, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Fri Jul 9 05:37:07 2010 From: alt.mcarter at gmail.com (Mark Carter) Date: Fri, 9 Jul 2010 02:37:07 -0700 (PDT) Subject: Python scripts from DOS Message-ID: On my machine, I can go to a DOS shell, and type myscript.py This will cause the script to be run as a python script. So that bit works. On another machine, on which python was set up without admin privileges, if I type myscript.py it will open the "Open With" dialog box. It wont let me execute it with python.exe. It asks me the same question every time, too. If I type python myscript.py then everything works fine. Is there a way of setting up the "other" machine so that it replicates the behaviour of my machine? From thomas at jollans.com Fri Jul 9 05:49:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 11:49:33 +0200 Subject: Python scripts from DOS In-Reply-To: References: Message-ID: <4C36F0AD.3050408@jollans.com> On 07/09/2010 11:37 AM, Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type Which operating systems are we talking about? > myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. What does that mean, exactly? What happens when you try to select python? > It asks me the same question every time, too. If I > type > python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? Depends on which OS we're talking about. I'm guessing you're using Windows, but I don't know which version, and I don't possess the Registry-fu you'll probably need. From asmodai at in-nomine.org Fri Jul 9 05:55:17 2010 From: asmodai at in-nomine.org (Jeroen Ruigrok van der Werven) Date: Fri, 9 Jul 2010 11:55:17 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <20100709095517.GL70600@nexus.in-nomine.org> -On [20100709 10:22], Gilles Ganault (nospam at nospam.com) wrote: >Is Pocoo really the only solution available out there? Pocoo as a forum app has been dead for years. Maybe Vithon (http://bitbucket.org/vithon/vithon-forum/src) does what you want/need. http://www.vithon.org/forum should be a live instance of it. -- Jeroen Ruigrok van der Werven / asmodai ????? ?????? ??? ?? ?????? http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B All for one, one for all... From pdwjfndjbdgfyg at gmail.com Fri Jul 9 06:20:28 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 9 Jul 2010 03:20:28 -0700 (PDT) Subject: HOT N JOBS Message-ID: <4d11cce1-4914-4791-ac46-f1f9192a8747@m17g2000prl.googlegroups.com> hot kiss http://photoseefree.blogspot.com/2009/12/hot-kiss.html hot lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-kiss.html hot navel kiss http://photoseefree.blogspot.com/2009/12/hot-navel-kiss.html hot lip to lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-to-lip-kiss.html super lip kiss http://photoseefree.blogspot.com/2009/12/super-lip-kiss.html lip kiss club http://photoseefree.blogspot.com/2009/12/lip-kiss-club.html kiss club http://photoseefree.blogspot.com/2009/12/kiss-club.html FOR JOBS work from home http://anyjobseehere.blogspot.com/2009/12/work-from-home.html online jobs http://anyjobseehere.blogspot.com/2009/12/online-jobs.html java jobs http://anyjobseehere.blogspot.com/2009/12/java-jobs.html oracle jobs http://anyjobseehere.blogspot.com/2009/12/oracle-jobs.html web designing jobs http://anyjobseehere.blogspot.com/2009/12/web-designing-jobs.html From pdwjfndjbdgfyg at gmail.com Fri Jul 9 06:53:41 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 9 Jul 2010 03:53:41 -0700 (PDT) Subject: HOT N SEX Message-ID: <41ff3db9-402e-42d5-8a95-fc18862ffc7a@w15g2000pro.googlegroups.com> hot kiss http://photoseefree.blogspot.com/2009/12/hot-kiss.html hot lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-kiss.html hot navel kiss http://photoseefree.blogspot.com/2009/12/hot-navel-kiss.html hot lip to lip kiss http://photoseefree.blogspot.com/2009/12/hot-lip-to-lip-kiss.html super lip kiss http://photoseefree.blogspot.com/2009/12/super-lip-kiss.html lip kiss club http://photoseefree.blogspot.com/2009/12/lip-kiss-club.html kiss club http://photoseefree.blogspot.com/2009/12/kiss-club.html FOR JOBS work from home http://anyjobseehere.blogspot.com/2009/12/work-from-home.html online jobs http://anyjobseehere.blogspot.com/2009/12/online-jobs.html java jobs http://anyjobseehere.blogspot.com/2009/12/java-jobs.html oracle jobs http://anyjobseehere.blogspot.com/2009/12/oracle-jobs.html web designing jobs http://anyjobseehere.blogspot.com/2009/12/web-designing-jobs.html From puntabluda at gmail.com Fri Jul 9 07:05:49 2010 From: puntabluda at gmail.com (Rebelo) Date: Fri, 9 Jul 2010 04:05:49 -0700 (PDT) Subject: Python scripts from DOS References: Message-ID: On 9 srp, 11:37, Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > ? ?myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type > ? ?myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. It asks me the same question every time, too. If I > type > ? ?python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? http://docs.python.org/release/2.6.5/using/windows.html for python 2.6.5 on windows especially chapter 3.3.4. Executing scripts for python 2.7 : http://docs.python.org/using/windows.html same chapter for python 3.0 : http://docs.python.org/py3k/using/windows.html#executing-scripts From kedra.marbun at gmail.com Fri Jul 9 07:51:30 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 9 Jul 2010 04:51:30 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <4c33a3a6$0$23067$426a74cc@news.free.fr> <21ed810d-a1e5-40d8-b124-eb586d7b92d0@t5g2000prd.googlegroups.com> <4c359425$0$2629$426a74cc@news.free.fr> Message-ID: <18e1d431-6edf-4034-9eaa-69da66842cba@w37g2000prc.googlegroups.com> On Jul 8, 4:02?pm, Bruno Desthuilliers wrote: > kedra marbun a ?crit : > > > > > On Jul 7, 2:46 am, Bruno Desthuilliers > > wrote: > >> Gregory Ewing a ?crit : > > >>> Bruno Desthuilliers wrote: > >>>> kedra marbun a ?crit : > >>>>> if we limit our discussion to py: > >>>>> why __{get|set|delete}__ don't receive the 'name' & 'class' from > >>>>> __{getattribute|{set|del}attr}__ > >>>>> 'name' is the name that is searched > >>>> While it would have been technically possible, I fail to imagine any use > >>>> case for this. > >>> I think he wants to have generic descriptors that are > >>> shared between multiple attributes, but have them do > >>> different things based on the attribute name. > >> I already understood this, but thanks !-) > > >> What I dont understand is what problem it could solve that couldn't be > >> solved more simply using the either _getattr__ hook or hand-coded > >> delegation, since such a descriptor would be so tightly coupled to the > >> host class that it just doesn't make sense writing a descriptor for this. > > > yeah, i finally can agree descriptor isn't supposed to be used as > > delegation in general, it should be the job of __getattr__ > > > however i still think passing name would open up some other > > possibilities of use > > Nothing prevents you to pass a "name" to the descriptor instance when > instanciating it, ie: > > class Desc(object): > ? ? ?def __init__(self, name): > ? ? ? ? ?self.name = name > ? ? def __get__(self, inst, cls): > ? ? ? ? # ... > ? ? def __set__(self, inst, value): > ? ? ? ? # ... > > class Foo(object): > ? ? ?bar = Desc("bar") > ? ? ?baaz = Desc("baaz") > > Ok, this is not necessarily what you were looking for, but it's IMHO > less brittle than relying on which attribute name was looked up (which > is something the descriptor shouldn't have to care about). > > > > > btw, is there a common approach to let the interface of a class that > > uses __getattr__, to include names that are delegated? > > In Python 2.x, not that I know (but it may have passed under my radar). > If what you want it to automate delegation of a set of methods without > too much manual coding, you can use a custom metaclass that will add the > relevant methods to the class, based on (ie) a list (or mapping) of > methods names. But that might be a bit overkill. > > > class A: > > ? ?def do_this(self): ... > > > class B: > > ? ?a = A() > > I don't see the point of using delegation on a class attribute. That's > typically what inheritance is for. ah, our friend mixin, it's just a sample though > > > ? ?def do_that(self): ... > > > ? ?def __getattr__(self, name): > > ? ? ? ? ? ?try: > > ? ? ? ? ? ? ? ? ? ?return types.MethodType(getattr(self.a, name), self) > > Err... Did you try the simple way ? > ? ? ? ? ? ? ? ? ? ? ? ? ?return getattr(self.a, name) argh, that should be class A: def do_this(self, ins): ... From thomas at jollans.com Fri Jul 9 08:10:25 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 14:10:25 +0200 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> Message-ID: <4C3711B1.1070006@jollans.com> On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > collect2: library libpython2.6 not found What really stumps me (and you too, I expect) about this is the two different error messages. Above, it looks like collect2 simply doesn't find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > ld:open(): No such file or directory > > collect2: ld returned 255 exit status But what on earth is this? It looks like collect2 found the library, and told it's mate ld, which can't open it. collect2 thinks it find a file, ld hits "No such file or directory" on the same file. Maybe it's a dead symlink? Looking for a file with the right name and location would find it, while opening it would hit a dead end, and probably return "No such file " From davea at ieee.org Fri Jul 9 08:22:51 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 08:22:51 -0400 Subject: Python scripts from DOS In-Reply-To: References: Message-ID: <4C37149B.1090308@ieee.org> Mark Carter wrote: > On my machine, I can go to a DOS shell, and type > myscript.py > This will cause the script to be run as a python script. So that bit > works. > > On another machine, on which python was set up without admin > privileges, if I type > myscript.py > it will open the "Open With" dialog box. It wont let me execute it > with python.exe. It asks me the same question every time, too. If I > type > python myscript.py > then everything works fine. > > Is there a way of setting up the "other" machine so that it replicates > the behaviour of my machine? > > Assuming you're talking Windows XP, Vista or Win7 you can do the following: There are registry settings in two places, hklm and hkcu. If you only have one user on the machine, it probably doesn't matter. in that case, there's a nice commandline way to make these associations. assoc creates associations beteween a file extension and a string ftype creates an association between that string and an executable program. On my machine, assoc .py shows .py=Python.File and ftype Python.File shows python.file="C:\PrgFiles\APYTHO~1\python.exe" "%1" %* Or you can read the following link: http://msdn.microsoft.com/en-us/library/ms724475(VS.85).aspx DaveA From kedra.marbun at gmail.com Fri Jul 9 08:32:14 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Fri, 9 Jul 2010 05:32:14 -0700 (PDT) Subject: delegation pattern via descriptor References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <89llvrFflvU1@mid.individual.net> Message-ID: On Jul 8, 5:10?pm, Gregory Ewing wrote: > kedra marbun wrote: > > i wonder what are the reasons for > > not passing the class on which the descriptor is attached to, what > > pattern is encouraged by this? > > The same answer applies. It's assumed that you will be > writing a custom piece of code for each attribute of > each class, and giving each one its own descriptor. > > By the time you get to the get or set method of a > descriptor, you've already dispatched on both the > class and attribute name. There is not usually any > point in funnelling things back into a single function > and then dispatching on the class or name again. > Passing the class or name would just add overhead that > was unnecessary in the majority of use cases. > > -- > Greg True, unnecessary overhead. this 'passing class' thing comes from, IIRC, learning python 4ed by Mark Lutz, it's stated there that the 3rd arg to __get__ is the class to which the descriptor instance is attached so if i want the host class, i should do it the way builtin descriptors do (bind it manually)? for example, type.__dict__['__getattribute__'].__class__ is wrapper_descriptor. wrapper_descriptor has member __objclass__ pointing to instance of types.MemberDescriptorType, which disallows set & del, get returns the host class ('type' in this case) *** about the 3rd arg of __get__ i guess py has chosen __get__(self, ins, cls) over __get__(self, ins) to make it easier for decriptor-implementor to find out whether the caller (the left-side operand of dot operator) is instance of obj on which the descriptor obj is found or not this conclusion is based on the fact that: - it is only __get__ that receives the redundant class obj - if the caller is a class obj & descriptor is found on obj that is in its __mro__, the fetch is still routed to __get__: __get__(desc, None, CLASS). this doesn't happen for __{set|delete}__ note that the builtin descriptors even allow their's __get__ to be given only the instance (2nd arg): object.__getattribute__.__get__(obj) is it correct? From youngung.jeong at gmail.com Fri Jul 9 08:33:36 2010 From: youngung.jeong at gmail.com (youngung) Date: Fri, 9 Jul 2010 05:33:36 -0700 (PDT) Subject: ipython problem in opening a file Message-ID: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Hello pythoners! I just dived into ipython since I'd like to make use of matplotlib. Over the trials, I came across a problem. One of the scripts that I have is not working with ipython, while it has been and still is working well with Python GUI. The problem is, even though I have the file in the c:\python26 folder, IPython can't fine it. One of the many things I tried, is as below. ************************************************* f=open('od.txt','w') --------------------------------------------------------------------------- IOError Traceback (most recent call last) C:\Windows\system32\ in () IOError: [Errno 13] Permission denied: 'od.txt' What should I do further to solve this problem? From rtomek at ceti.com.pl Fri Jul 9 08:41:06 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 14:41:06 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Fri, 9 Jul 2010, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with comments) - if something takes a lot of place to comment, then maybe it should go to a separate unit. As of the other side of scale, this 3000 KLOC thing, I believe you would have encountered a performance hit. And probably a big one - I would be afraid of some O(n^2) dragon or something bigger, waiting deeply in CPython code to eat your performance. But, I am just fantasizing - I have no idea of CPython internals and how big is the biggest Python code written so far. Python code tends to be very concise, so 3 MLOC sounds rather extremal to me. On the other hand, it is possible nobody tested CPython for such extreme case. Speaking of performance, there is also target user, and her needs (CGI? desktop? etc). So I would take this under consideration, too - how many times per second (minute, day) this code will be executed? Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From python at bdurham.com Fri Jul 9 08:47:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 09 Jul 2010 08:47:46 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4C36EA28.4020502@gmail.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> <4C36EA28.4020502@gmail.com> Message-ID: <1278679666.9335.1384063345@webmail.messagingengine.com> Steven, Interesting question. I've seen even small modules (in terms of code size) grow quite large with embedded documentation, developer comments, and unit tests. The unit tests can be split to another module. Sometimes classes can be artificially split into separate classes (and thus split across modules) and then combined through inheritance or aggragration. And yes, I recognize I haven't answered your original question :) Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bryan.Stopp at argushealth.com Fri Jul 9 08:54:21 2010 From: Bryan.Stopp at argushealth.com (Stopp, Bryan) Date: Fri, 9 Jul 2010 07:54:21 -0500 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <4C3711B1.1070006@jollans.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C3711B1.1070006@jollans.com> Message-ID: <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> I checked, none of the files are symlinks. The install process never got to the point where it created sym-links for libraries (if it even does, I haven't gotten to that point in the install process.) -B -----Original Message----- From: python-list-bounces+cbds=argushealth.com at python.org [mailto:python-list-bounces+cbds=argushealth.com at python.org] On Behalf Of Thomas Jollans Sent: Friday, July 09, 2010 7:10 AM To: python-list at python.org Subject: Re: Issues compiling 2.6.5 on AIX 6.1 On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > collect2: library libpython2.6 not found What really stumps me (and you too, I expect) about this is the two different error messages. Above, it looks like collect2 simply doesn't find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > building '_struct' extension > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > -I/build/tools/src/Python-2.6.5/Include -I/build/tools/src/Python-2.6.5 > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > build/lib.aix-6.1-2.6/_struct.so > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > ld:open(): No such file or directory > > collect2: ld returned 255 exit status But what on earth is this? It looks like collect2 found the library, and told it's mate ld, which can't open it. collect2 thinks it find a file, ld hits "No such file or directory" on the same file. Maybe it's a dead symlink? Looking for a file with the right name and location would find it, while opening it would hit a dead end, and probably return "No such file " -- http://mail.python.org/mailman/listinfo/python-list PRIVILEGED AND CONFIDENTIAL This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at argushealth.com. Thank you. From anthra.norell at bluewin.ch Fri Jul 9 09:02:25 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 15:02:25 +0200 Subject: 'reload M' doesn't update 'from M inport *' Message-ID: <1278680545.2376.30.camel@hatchbox-one> I develop in an IDLE window. Module M says 'from service import *'. Next I correct a mistake in function 'service.f'. Now 'service.f' works fine. I do 'reload (service); reload (M)'. The function 'M.f' still misbehaves. 'print inspect.getsource (service.f)' and 'print inspect.getsource (M.f)' shows the same corrected code. 'print service.f' and 'print M.f' show different ids. So I do 'del M; reload (M)'. Nothing changes. I delete M again and run gc.collect () to really clean house. I reload M again and still nothing changes. The id of the reloaded function 'M.f' is still the same as it was before the purge and so M.f still isn't fixed. I know I have more radical options, such as starting a new IDLE window. That would save me time, but I'd like to take the opportunity to understand what is happening. Surely someone out there knows. Frederic From eliben at gmail.com Fri Jul 9 09:02:57 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 9 Jul 2010 16:02:57 +0300 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: > One of the many things I tried, is as below. > > ************************************************* > > > f=open('od.txt','w') > --------------------------------------------------------------------------- > IOError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call > last) > > C:\Windows\system32\ in () > > IOError: [Errno 13] Permission denied: 'od.txt' > > It appears that your ipython runs in C:\Windows\system32 You can find it out for sure by executing "os.getcwd()" after importing the "os" module. You may not have permissions in C:\Windows\system32, which is why the error is printed. Eli From eliben at gmail.com Fri Jul 9 09:17:05 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 9 Jul 2010 16:17:05 +0300 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: On Fri, Jul 9, 2010 at 16:07, Youngung Jeong wrote: > Thank you for your kindness. > I found you're right. It's running in that folder. > What should I do for making this work? > Could you please tell me a bit more... > > Youngung You can change the "current directory" ipython executes in, by either executing it directly (from the command line) in the directory of your choice, or calling the os.chdir function with the path of your choice. Eli From kaklis at gmail.com Fri Jul 9 09:17:29 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Fri, 9 Jul 2010 06:17:29 -0700 (PDT) Subject: Load/Performance Testing of a Web Server Message-ID: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Hi to all, i want to stress test a tomcat web server, so that i could find out its limits. e.g how many users can be connected and request a resource concurrently. I used JMeter which is an excellent tool, but i would like to use a more pythonic approach. Any hints Antonis From rene7705 at gmail.com Fri Jul 9 09:24:32 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Fri, 9 Jul 2010 15:24:32 +0200 Subject: how do you print an object? Message-ID: hi. i'm a recent convert from php because google appengine runs python. i have a whole cms backend to convert (also to bigtable, but thats another story) to python now. the first item on my agenda is the printing of python objects to json objects. i have this nifty xhtml dataviewer (htmlMicroscope, see the downloads page in my signature) that accepts json objects for display in the browser. i also have an xhtml error viewer, logAndHandler, that does sort of the same. i want to use both of these with python, and i will promise to release the python sources for hm() and lah() as well. so my question is simple: how do you go from python object to json representation of that object, preferably keeping everything including function code in the json output? i'll have many more questions, if i decide to convert my cms backend to python. but it seems i'm without option on this ;) side question: anybody know a cloud hosting service that does php? i really have a ton of code already ;) -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From nathan.alexander.rice at gmail.com Fri Jul 9 09:25:57 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 9 Jul 2010 09:25:57 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: I start to look at whether some subset of functions or classes are not referenced by other subsets of functions or classes in a module when it gets to about 1K LoC, and if I don't find any by the time it gets to about 1500 LoC, I start to look at ways I can refactor the code in the module to be less coupled. This might just be anecdotal, but in all the python libraries I've looked at (including the larger 30K+ LoC ones) the quality of code in a module tends to be lower if the module is over around 1500 LoC. -------------- next part -------------- An HTML attachment was scrubbed... URL: From schlesin at cshl.edu Fri Jul 9 09:25:58 2010 From: schlesin at cshl.edu (Felix) Date: Fri, 9 Jul 2010 06:25:58 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <25863592-e417-4157-bbfb-1743e6889fb1@z10g2000yqb.googlegroups.com> On Jul 9, 1:16?am, sturlamolden wrote: > On 9 Jul, 05:39, Felix wrote: > > For an outsider it does not look like a solution to the GIL mess or a > > true breakthrough for performance are around the corner (even though > > there seem to be many different attempts at working around these > > problems or helping with parts). Am I wrong? > > Yes you are. > > We don't do CPU intensive work in "pure Python". We use Python to > control C and Fortran libraries. That gives us the opportunity to > multi-thread in C, release the GIL and multi-thread in Python, or > both. Yes, this setup works very well and is (as I said) probably the reason python is so widely used in scientific computing these days. However I find that I can almost never do everything with vector operations, but have to iterate over data structures at some point. And here the combination of CPython slowness and the GIL means either bad performance or having to write this in C (with which cython helps fortunately). If it were possible to write simple, parallel, reasonably fast loops in (some subset of) python directly that would certainly be a great advantage. Given the performance of other JITs it sounds like it should be possible, but maybe python is too complex to make this realistic. Felix PS: No need to convince me that MATLAB is not the solution. From thomas at jollans.com Fri Jul 9 09:42:44 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 15:42:44 +0200 Subject: how do you print an object? In-Reply-To: References: Message-ID: <4C372754.4090000@jollans.com> On 07/09/2010 03:24 PM, Rene Veerman wrote: > hi. > > i'm a recent convert from php because google appengine runs python. > i have a whole cms backend to convert (also to bigtable, but thats > another story) to python now. > > the first item on my agenda is the printing of python objects to json objects. > i have this nifty xhtml dataviewer (htmlMicroscope, see the downloads > page in my signature) that accepts json objects for display in the > browser. i also have an xhtml error viewer, logAndHandler, that does > sort of the same. > i want to use both of these with python, and i will promise to release > the python sources for hm() and lah() as well. > > so my question is simple: how do you go from python object to json > representation of that object, preferably keeping everything including > function code in the json output? http://docs.python.org/py3k/library/json.html To get function code, have a look at the inspect module docs. > > i'll have many more questions, if i decide to convert my cms backend to python. > but it seems i'm without option on this ;) > > side question: anybody know a cloud hosting service that does php? i > really have a ton of code already ;) > > From schlesin at cshl.edu Fri Jul 9 09:43:03 2010 From: schlesin at cshl.edu (Felix) Date: Fri, 9 Jul 2010 06:43:03 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> Message-ID: <43a6038e-1954-438d-90af-da78fecd73ae@d16g2000yqb.googlegroups.com> On Jul 9, 12:44?am, Stefan Behnel wrote: > Felix, 09.07.2010 05:39: > Well, at least its "parallel processing abilities" are quite good actually. > If you have really large computations, they usually run on more than one > computer (not just more than one processor). So you can't really get around > using something like MPI, in which case an additional threading layer is > basically worthless, regardless of the language you use. For computations, > threading keeps being highly overrated. That is certainly true for large computations. But many smaller tasks are run on single machines and it does make a difference if they take 1 minute per run or 10. The average number of cores per computer has been increasing for quite a while now. It seems unfortunate to be restricted to using only one of them at a time (for regular loops, not mathematical vector operations). Python has made so many complicated things easy, but I have not seen an easy way to parallelize a simple loop on a multicore CPU without having to set up infrastructure and/or incurring large overhead from many interpreters and marshalling data. Just the fact that there is such a large number of attempts out there to fix this suggests that something important is missing. From simon at brunningonline.net Fri Jul 9 09:44:23 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 9 Jul 2010 14:44:23 +0100 Subject: Load/Performance Testing of a Web Server In-Reply-To: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> References: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Message-ID: On 9 July 2010 14:17, kaklis at gmail.com wrote: > Hi to all, i want to stress test ? a tomcat web server, so that i > could find out its limits. e.g how many users can be connected and > request a resource concurrently. > I used JMeter which is an excellent tool, but i would like to use a > more pythonic approach. The Grinder? -- Cheers, Simon B. From gfiske at gmail.com Fri Jul 9 10:09:13 2010 From: gfiske at gmail.com (Greg) Date: Fri, 9 Jul 2010 07:09:13 -0700 (PDT) Subject: python instructor Message-ID: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> We're looking for a first-rate python trainer to come to our organization for a day or two. We are a small group of geospatial/ remote sensing scientists whose research spans the gap between environmental accounting/monitoring and policy and human interaction. We have about 5-10 (or so) python users (and potential python users) who could potentially apply new skills to several in-house projects. The difficulty for the teacher would be covering breadth of experience we have currently. Any thoughts or advice would be greatly appreciated. Thanks very much, Greg From christian.sperandio at gmail.com Fri Jul 9 10:26:24 2010 From: christian.sperandio at gmail.com (Chrix) Date: Fri, 9 Jul 2010 07:26:24 -0700 (PDT) Subject: Netbeans plugin and Python 3 Message-ID: <9ed2c37d-bce6-4dd5-9b0b-4f35aa81aa55@c33g2000yqm.googlegroups.com> Hi, Someone knows if Netbeans will support Python 3 language features? Nowadays, I tried Netbeans 6.9 but it only supports Python 2.5 :( And I'd like really to develop with Python 3. Thanks. From youngung.jeong at gmail.com Fri Jul 9 10:27:08 2010 From: youngung.jeong at gmail.com (Youngung Jeong) Date: Fri, 9 Jul 2010 23:27:08 +0900 Subject: ipython problem in opening a file In-Reply-To: References: <924144c7-9258-428e-b413-b7ef685e0455@x2g2000prk.googlegroups.com> Message-ID: Thanks a lot! Youngung On Fri, Jul 9, 2010 at 10:17 PM, Eli Bendersky wrote: > On Fri, Jul 9, 2010 at 16:07, Youngung Jeong > wrote: > > Thank you for your kindness. > > I found you're right. It's running in that folder. > > What should I do for making this work? > > Could you please tell me a bit more... > > > > Youngung > > You can change the "current directory" ipython executes in, by either > executing it directly (from the command line) in the directory of your > choice, or calling the os.chdir function with the path of your choice. > > Eli > -------------- next part -------------- An HTML attachment was scrubbed... URL: From e_d_k at yahoo.com Fri Jul 9 10:49:05 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Fri, 9 Jul 2010 07:49:05 -0700 (PDT) Subject: python instructor In-Reply-To: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> Message-ID: <199679.68964.qm@web120501.mail.ne1.yahoo.com> Where are you located? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com --- On Fri, 7/9/10, Greg wrote: > From: Greg > Subject: python instructor > To: python-list at python.org > Date: Friday, July 9, 2010, 10:09 AM > We're looking for a first-rate python > trainer to come to our > organization for a day or two.? We are a small group > of geospatial/ > remote sensing scientists whose research spans the gap > between > environmental accounting/monitoring and policy and human > interaction. > We have about 5-10 (or so) python users (and potential > python users) > who could potentially apply new skills to several in-house > projects. > The difficulty for the teacher would be covering breadth of > experience > we have currently. > > Any thoughts or advice would be greatly appreciated.? > Thanks very > much, > > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > From massi_srb at msn.com Fri Jul 9 11:07:23 2010 From: massi_srb at msn.com (Massi) Date: Fri, 9 Jul 2010 08:07:23 -0700 (PDT) Subject: SqlAlchemy: remote connection on problem on mysql database Message-ID: Hi everyone, in my script I'm trying to connect to a remote database using sqlalchemy. Since I'm pretty new to this library I'm not really sure of what I am doing :-). Up to now what I'm doing to connect to the database is this: engine = create_engine("mysql:// my_username:my_password at phpmyadmin.myhost.com/my_db_name") metadata = MetaData(engine, reflect=True) If I run this script I get the following error: Traceback (most recent call last): File "C:\Documents and Settings\pc2\Desktop\prova.py", line 9, in metadata = MetaData(engine, reflect=True) File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg \sqlalchemy\schema.py", line 1770, in __init__ self.reflect() File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg \sqlalchemy\schema.py", line 1879, in reflect connection=conn)) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\base.py", line 1604, in table_names conn = self.contextual_connect() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\base.py", line 1592, in contextual_connect return self.Connection(self, self.pool.connect(), close_with_result=close_with_result, **kwargs) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 154, in connect return _ConnectionFairy(self).checkout() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 318, in __init__ rec = self._connection_record = pool.get() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 173, in get return self.do_get() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 665, in do_get con = self.create_connection() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 134, in create_connection return _ConnectionRecord(self) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 209, in __init__ self.connection = self.__connect() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\pool.py", line 271, in __connect connection = self.__pool._creator() File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\strategies.py", line 76, in connect return dialect.connect(*cargs, **cparams) File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg \sqlalchemy\engine\default.py", line 227, in connect return self.dbapi.connect(*cargs, **cparams) File "C:\Python25\lib\site-packages\MySQLdb\__init__.py", line 74, in Connect return Connection(*args, **kwargs) File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line 170, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (OperationalError) (2003, "Can't connect to MySQL server on 'phpmyadmin.myhost.com' (10060)") None None Is there something I am missing? thanks in advance for the help! From jdixon at omniti.com Fri Jul 9 11:08:19 2010 From: jdixon at omniti.com (Jason Dixon) Date: Fri, 9 Jul 2010 11:08:19 -0400 Subject: Last day to submit your Surge 2010 CFP! Message-ID: <20100709150818.GE4133@omniti.com> Today is your last chance to submit a CFP abstract for the 2010 Surge Scalability Conference. The event is taking place on Sept 30 and Oct 1, 2010 in Baltimore, MD. Surge focuses on case studies that address production failures and the re-engineering efforts that led to victory in Web Applications or Internet Architectures. You can find more information, including suggested topics and our current list of speakers, online: http://omniti.com/surge/2010 The final lineup should be available on the conference website next week. If you have questions about the CFP, attending Surge, or having your business sponsor/exhibit at Surge 2010, please contact us at surge at omniti.com. Thanks! -- Jason Dixon OmniTI Computer Consulting, Inc. jdixon at omniti.com 443.325.1357 x.241 From rtomek at ceti.com.pl Fri Jul 9 11:21:15 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 17:21:15 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Fri, 9 Jul 2010, Tomasz Rola wrote: > On Fri, 9 Jul 2010, Steven D'Aprano wrote: > > > This is a style question rather than a programming question. > > > > How large (how many KB, lines, classes, whatever unit of code you like to > > measure in) should a module grow before I should break it up into a > > package? I see that, for example, decimal.py is > 3000 lines of code, so > > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > > Where do you draw the line? > > > > For the purposes of the discussion, you should consider that the code in > > the module really does belong together, and that splitting it into sub- > > modules would mean arbitrarily separating code into separate files. > > Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with > comments) - if something takes a lot of place to comment, then maybe it > should go to a separate unit. I meant 2-5 KLOC&C. Oups... Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From robin1 at cnsp.com Fri Jul 9 11:30:31 2010 From: robin1 at cnsp.com (Robin) Date: Fri, 9 Jul 2010 08:30:31 -0700 (PDT) Subject: do Message-ID: please, please post a link to my site, http://offlame.thevoid1.net/ also, post free for all links at www.thevoid1.net/ffa -Robin From aahz at pythoncraft.com Fri Jul 9 11:41:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 08:41:57 -0700 Subject: Python -- floating point arithmetic References: <4C346DA0.1070708@tu-clausthal.de> <86vd8qq8cy.fsf@aiuole.stru.polimi.it> Message-ID: In article , Chris Rebert wrote: >On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi wrote: >> "Zooko O'Whielacronx" writes: >>> >>> I'm starting to think that one should use Decimals by default and >>> reserve floats for special cases. >> >> would you kindly lend me your Decimals ruler? i need to measure the >> sides of the triangle whose area i have to compute > >If your ruler doesn't have a [second] set of marks for centimeters and >millimeters, that's really one cheap/cruddy ruler you're using. Unless I'm badly mistaken, Giacomo was making a funny about Greek geometers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From aahz at pythoncraft.com Fri Jul 9 11:47:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 08:47:51 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: In article , Frederic Rentsch wrote: > >Module M says 'from service import *'. >Next I correct a mistake in function 'service.f'. >Now 'service.f' works fine. > >I do 'reload (service); reload (M)'. >The function 'M.f' still misbehaves. Absolutely! >'print inspect.getsource (service.f)' and >'print inspect.getsource (M.f)' shows the same >corrected code. > >'print service.f' and 'print M.f' show different ids. > >So I do 'del M; reload (M)'. Nothing changes. > >I delete M again and run gc.collect () to really clean house. I reload >M again and still nothing changes. The id of the reloaded function >'M.f' is still the same as it was before the purge and so M.f still >isn't fixed. > >I know I have more radical options, such as starting a new IDLE >window. That would save me time, but I'd like to take the opportunity >to understand what is happening. Surely someone out there knows. Take a look at sys.modules to get a better idea of what's happening. (Maybe someone else will have time to write a longer answer.) But really, relying on reload() is foolish in the general case because it's nearly impossible to track down every single reference. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From alf.p.steinbach+usenet at gmail.com Fri Jul 9 11:52:14 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 17:52:14 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? Message-ID: [Cross-posted comp.lang.python and comp.lang.c++] I lack experience with shared libraries in *nix and so I need to ask... This is about "cppy", some support for writing Python extensions in C++ that I just started on (some days ago almost known as "pynis" (not funny after all)). For an extension module it seems that Python requires each routine to be defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern "C"' and C++ linkage, using a routine declared as 'static' in a class as a C callback, formally they're two different kinds, and I seem to recall that /some/ C++ compiler balks at that kind of mixing unless specially instructed to allow it. Perhaps it was the Sun compiler? Anyway, to be formally correct I cannot generate the required C routines via templating, and I ended up using macros that the user must explicitly invoke, like, here the Py doc's first extension module example recoded using cppy, ------------------------------------------------------------------ #include #include using namespace progrock; class Spam: public cppy::Module { public: Spam(): cppy::Module( "spam" ) { setDocString( L"bl?b?rsyltet?y er bl?tt" ); } PyObject* system( PyObject* args ) { const char *command; int sts; if( !PyArg_ParseTuple( args, "s", &command ) ) { return NULL; } sts = ::system( command ); return Py_BuildValue( "i", sts ); } }; CPPY_MODULE_CROUTINE( Spam, system, "Execute a shell command" ) PyMODINIT_FUNC PyInit_spam() { return cppy::init< Spam >(); } ------------------------------------------------------------------ It works in Windows. But here CPPY_MODULE_CROUTINE does three things: A Defining the 'extern "C"' routine. I cannot think of any problem here. B Defining installation data for that routine. Possible problem: initializing a static with address of routine? C -> Adding that install data record into a linked list! Possible problem: are dynamic initialization actions guaranteed to be performed in *nix shared library? Problem (C) is outside the realm of the C++ standard, since the C++ standard doesn't support shared libraries, and I've never actually used *nix shared libraries so I don't /know/... Is such dynamic initialization guaranteed? For completeness, the macro definition (the 0 in there is a list next-pointer): #define CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ extern "C" \ static PyObject* cppClassName##_##name( PyObject*, PyObject* args ) \ { \ return ::progrock::cppy::module().name( args ); \ } #define CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) \ static ::progrock::cppy::detail::ModuleRoutineDescriptor \ cppClassName##_##name##_descriptor = { \ 0, \ #name, \ docString, \ &cppClassName##_##name \ }; \ \ static bool cppClassName##_##name##_descriptor_installed = \ ::progrock::cppy::detail::addToList< cppClassName >( \ cppClassName##_##name##_descriptor \ ); #define CPPY_MODULE_CROUTINE( cppClassName, name, docString ) \ CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) TIA., - Alf -- blog at From wentlv at gmail.com Fri Jul 9 11:58:35 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 08:58:35 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? Message-ID: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Hi, everyone I'm a new hand at python. I tried to set system default encoding by using "import sys; sys.setdefaultencoding('utf-f')", but I got error message: >>> sys.setdefaultencoding('utf-8') Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'setdefaultencoding' Then I checked dir(sys), seems there was no function named "setdefaultencoding" in "sys" module. But in python's document, it said I should use sys.setdefaultencoding. So, my questions: why there is no setdefaultencoding in sys module? if I want to change system's default encoding, what should I do? Thanks in advance From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 11:58:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 15:58:38 GMT Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: <4c37472e$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 15:02:25 +0200, Frederic Rentsch wrote: > I develop in an IDLE window. > > Module M says 'from service import *'. Next I correct a mistake in > function 'service.f'. Now 'service.f' works fine. from service import * should be considered advanced functionality that is discouraged unless you really know what you are doing, precisely for the problems you are experiencing. You should try to avoid it. But putting that aside, if you have done "from service import *" in module m, where are you getting "service.f" from? The only way that is possible is if you ALSO say "import service". > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. > > 'print inspect.getsource (service.f)' and 'print inspect.getsource > (M.f)' shows the same corrected code. inspect.getsource always looks at the source code on disk, no matter what the byte code in memory actually says. > 'print service.f' and 'print M.f' show different ids. > > So I do 'del M; reload (M)'. Nothing changes. > > I delete M again and run gc.collect () to really clean house. I reload M > again and still nothing changes. The id of the reloaded function 'M.f' > is still the same as it was before the purge and so M.f still isn't > fixed. > > I know I have more radical options, such as starting a new IDLE window. > That would save me time, but I'd like to take the opportunity to > understand what is happening. Surely someone out there knows. Yes. You have to understand importing. Let's start with the simple: import m In *very* simplified pseudo-code, this does: look for module m in the global cache if not there, then: search for m.py compile it to a Module object put the Module object in the cache create a new name "m" in the local namespace set the name "m" to the Module object in the cache Now let's compare it to: from m import f look for module m in the global cache if not there, then: search for m.py compile it to a Module object put the Module object in the cache look for object named "f" in the Module object create a new name "f" in the local namespace set the name "f" to cached object The important thing to notice is the the name "f" is a local variable. It doesn't, and can't, remember that it comes from module m. Reloading m can't do anything to f, because the connection is lost. Now consider that the object "f" that came from m was itself imported from another module, "service". Reloading service doesn't help, because m.f doesn't know it came from service. Reloading m doesn't help, because all that does is run "from service import f" again, and that just fetches f from the global cache. The simplest, easiest way of dealing with this is not to have to deal with it: don't use "from service import f", and ESPECIALLY don't use "from service import *". Always use fully-qualified importing: import service service.f Now "reload(service)" should do what you expect. The other way is not to bother with reload. It's not very powerful, only good for the simplest use in the interactive interpreter. Just exit the interpreter and restart it. -- Steven From martin.hellwig at dcuktec.org Fri Jul 9 12:03:21 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 09 Jul 2010 17:03:21 +0100 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 07/09/10 05:37, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. > Personally I like to split up my module quite early and the main criteria is whether this improves (IMO) maintainability. So if I can refactor stuff that with some adaption can be used multiple times I put it in its own module. I rarely exceed 1KLOC per module and on average are on half of that. -- mph From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 12:04:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jul 2010 16:04:02 GMT Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Message-ID: <4c374872$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > So, my questions: why there is no setdefaultencoding in sys module? if I > want to change system's default encoding, what should I do? I think the answer is: Don't. If you do, you will break built-ins. http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/ Googling will find many discussions about this. -- Steven From wentlv at gmail.com Fri Jul 9 12:06:41 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 09:06:41 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> Message-ID: <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> On Jul 10, 12:04?am, Steven D'Aprano wrote: > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > So, my questions: why there is no setdefaultencoding in sys module? if I > > want to change system's default encoding, what should I do? > > I think the answer is: > > Don't. > > If you do, you will break built-ins. > > http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > Googling will find many discussions about this. > > -- > Steven Interesting, so it has been removed from python? then why it's still in document... It's really misleading. Thanks for your quick answer From wentlv at gmail.com Fri Jul 9 12:16:42 2010 From: wentlv at gmail.com (crow) Date: Fri, 9 Jul 2010 09:16:42 -0700 (PDT) Subject: Why there is no "setdefaultencoding" in sys module? References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> Message-ID: <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> On Jul 10, 12:06?am, crow wrote: > On Jul 10, 12:04?am, Steven D'Aprano > > > > > cybersource.com.au> wrote: > > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > > So, my questions: why there is no setdefaultencoding in sys module? if I > > > want to change system's default encoding, what should I do? > > > I think the answer is: > > > Don't. > > > If you do, you will break built-ins. > > >http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > > Googling will find many discussions about this. > > > -- > > Steven > > Interesting, so it has been removed from python? then why it's still > in document... It's really misleading. > > Thanks for your quick answer oh, I take back my words, it's still there, just I need to reload(sys). From puntabluda at gmail.com Fri Jul 9 12:20:53 2010 From: puntabluda at gmail.com (Rebelo) Date: Fri, 9 Jul 2010 09:20:53 -0700 (PDT) Subject: SqlAlchemy: remote connection on problem on mysql database References: Message-ID: <8f2b52af-fe20-4219-b54c-7992f3177982@k39g2000yqb.googlegroups.com> from SQLAlchemy docs (http://www.sqlalchemy.org/docs/ dbengine.html#database-engine-options): " create_engine() URL Arguments SQLAlchemy indicates the source of an Engine strictly via RFC-1738 style URLs, combined with optional keyword arguments to specify options for the Engine. The form of the URL is: dialect+driver://username:password at host:port/database Dialect names include the identifying name of the SQLAlchemy dialect which include sqlite, mysql, postgresql, oracle, mssql, and firebird. The drivername is the name of the DBAPI to be used to connect to the database using all lowercase letters. If not specified, a ?default? DBAPI will be imported if available - this default is typically the most widely known driver available for that backend (i.e. cx_oracle, pysqlite/sqlite3, psycopg2, mysqldb). " are you sure that phpmyadmin.myhost.com is your mysql server? or are you missing port? usually its 3306. AFAIK From nitinpawar432 at gmail.com Fri Jul 9 12:27:14 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 9 Jul 2010 21:57:14 +0530 Subject: Netbeans plugin and Python 3 Message-ID: Hi, I never tried python3.0 with netbeans but I use python 2.6.5 with netbean 6.7.1 Here is how I managed to change from python 2.5 (netbeans default) to 2.6.5 1) From the tools-> plugins section install python plugin 2) Once plugin is installed just restart netbeans so that plugin is activated 3) After plugin is activated, you can edit default python version by tools-> python platform 4) It will open a configure window, where you can point python to newly installed 3.0 version. I hope that helps. Thanks, nitin On Fri, Jul 9, 2010 at 9:30 PM, wrote: > 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. python instructor (Greg) > 2. Re: ipython problem in opening a file (Youngung Jeong) > 3. Netbeans plugin and Python 3 (Chrix) > 4. Re: python instructor (Ed Keith) > 5. Last day to submit your Surge 2010 CFP! (Jason Dixon) > 6. SqlAlchemy: remote connection on problem on mysql database (Massi) > 7. do (Robin) > 8. Re: Opinions please -- how big should a single module grow? > (Tomasz Rola) > 9. Re: Python -- floating point arithmetic (Aahz) > 10. Re: 'reload M' doesn't update 'from M inport *' (Aahz) > 11. Cpp + Python: static data dynamic initialization in *nix > shared lib? (Alf P. Steinbach /Usenet) > 12. Why there is no "setdefaultencoding" in sys module? (crow) > > > ---------- Forwarded message ---------- > From: Greg > To: python-list at python.org > Date: Fri, 9 Jul 2010 07:09:13 -0700 (PDT) > Subject: python instructor > We're looking for a first-rate python trainer to come to our > organization for a day or two. We are a small group of geospatial/ > remote sensing scientists whose research spans the gap between > environmental accounting/monitoring and policy and human interaction. > We have about 5-10 (or so) python users (and potential python users) > who could potentially apply new skills to several in-house projects. > The difficulty for the teacher would be covering breadth of experience > we have currently. > > Any thoughts or advice would be greatly appreciated. Thanks very > much, > > Greg > > > > ---------- Forwarded message ---------- > From: Youngung Jeong > To: Eli Bendersky > Date: Fri, 9 Jul 2010 23:27:08 +0900 > Subject: Re: ipython problem in opening a file > Thanks a lot! > > Youngung > > > On Fri, Jul 9, 2010 at 10:17 PM, Eli Bendersky wrote: > >> On Fri, Jul 9, 2010 at 16:07, Youngung Jeong >> wrote: >> > Thank you for your kindness. >> > I found you're right. It's running in that folder. >> > What should I do for making this work? >> > Could you please tell me a bit more... >> > >> > Youngung >> >> You can change the "current directory" ipython executes in, by either >> executing it directly (from the command line) in the directory of your >> choice, or calling the os.chdir function with the path of your choice. >> >> Eli >> > > > > ---------- Forwarded message ---------- > From: Chrix > To: python-list at python.org > Date: Fri, 9 Jul 2010 07:26:24 -0700 (PDT) > Subject: Netbeans plugin and Python 3 > Hi, > > Someone knows if Netbeans will support Python 3 language features? > Nowadays, I tried Netbeans 6.9 but it only supports Python 2.5 :( > And I'd like really to develop with Python 3. > > Thanks. > > > > ---------- Forwarded message ---------- > From: Ed Keith > To: python-list at python.org, Greg > Date: Fri, 9 Jul 2010 07:49:05 -0700 (PDT) > Subject: Re: python instructor > Where are you located? > > -EdK > > Ed Keith > e_d_k at yahoo.com > > Blog: edkeith.blogspot.com > > > --- On Fri, 7/9/10, Greg wrote: > > > From: Greg > > Subject: python instructor > > To: python-list at python.org > > Date: Friday, July 9, 2010, 10:09 AM > > We're looking for a first-rate python > > trainer to come to our > > organization for a day or two. We are a small group > > of geospatial/ > > remote sensing scientists whose research spans the gap > > between > > environmental accounting/monitoring and policy and human > > interaction. > > We have about 5-10 (or so) python users (and potential > > python users) > > who could potentially apply new skills to several in-house > > projects. > > The difficulty for the teacher would be covering breadth of > > experience > > we have currently. > > > > Any thoughts or advice would be greatly appreciated. > > Thanks very > > much, > > > > Greg > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > ---------- Forwarded message ---------- > From: Jason Dixon > To: python-list at python.org > Date: Fri, 9 Jul 2010 11:08:19 -0400 > Subject: Last day to submit your Surge 2010 CFP! > Today is your last chance to submit a CFP abstract for the 2010 Surge > Scalability Conference. The event is taking place on Sept 30 and Oct 1, > 2010 in Baltimore, MD. Surge focuses on case studies that address > production failures and the re-engineering efforts that led to victory > in Web Applications or Internet Architectures. > > You can find more information, including suggested topics and our > current list of speakers, online: > > http://omniti.com/surge/2010 > > The final lineup should be available on the conference website next > week. If you have questions about the CFP, attending Surge, or having > your business sponsor/exhibit at Surge 2010, please contact us at > surge at omniti.com. > > Thanks! > > -- > Jason Dixon > OmniTI Computer Consulting, Inc. > jdixon at omniti.com > 443.325.1357 x.241 > > > > ---------- Forwarded message ---------- > From: Massi > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:07:23 -0700 (PDT) > Subject: SqlAlchemy: remote connection on problem on mysql database > Hi everyone, > > in my script I'm trying to connect to a remote database using > sqlalchemy. Since I'm pretty new to this library I'm not really sure > of what I am doing :-). Up to now what I'm doing to connect to the > database is this: > > engine = create_engine("mysql:// > my_username:my_password at phpmyadmin.myhost.com/my_db_name") > metadata = MetaData(engine, reflect=True) > > If I run this script I get the following error: > > Traceback (most recent call last): > File "C:\Documents and Settings\pc2\Desktop\prova.py", line 9, in > > metadata = MetaData(engine, reflect=True) > File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg > \sqlalchemy\schema.py", line 1770, in __init__ > self.reflect() > File "C:\Python25\lib\site-packages\sqlalchemy-0.6.0-py2.5.egg > \sqlalchemy\schema.py", line 1879, in reflect > connection=conn)) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\base.py", line 1604, in table_names > conn = self.contextual_connect() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\base.py", line 1592, in contextual_connect > return self.Connection(self, self.pool.connect(), > close_with_result=close_with_result, **kwargs) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 154, in connect > return _ConnectionFairy(self).checkout() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 318, in __init__ > rec = self._connection_record = pool.get() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 173, in get > return self.do_get() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 665, in do_get > con = self.create_connection() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 134, in create_connection > return _ConnectionRecord(self) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 209, in __init__ > self.connection = self.__connect() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\pool.py", line 271, in __connect > connection = self.__pool._creator() > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\strategies.py", line 76, in connect > return dialect.connect(*cargs, **cparams) > File "c:\python25\lib\site-packages\SQLAlchemy-0.6.0-py2.5.egg > \sqlalchemy\engine\default.py", line 227, in connect > return self.dbapi.connect(*cargs, **cparams) > File "C:\Python25\lib\site-packages\MySQLdb\__init__.py", line 74, > in Connect > return Connection(*args, **kwargs) > File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line > 170, in __init__ > super(Connection, self).__init__(*args, **kwargs2) > OperationalError: (OperationalError) (2003, "Can't connect to MySQL > server on 'phpmyadmin.myhost.com' (10060)") None None > > Is there something I am missing? thanks in advance for the help! > > > > ---------- Forwarded message ---------- > From: Robin > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:30:31 -0700 (PDT) > Subject: do > please, please post a link to my site, http://offlame.thevoid1.net/ > > also, post free for all links at www.thevoid1.net/ffa > > -Robin > > > > ---------- Forwarded message ---------- > From: Tomasz Rola > To: python-list at python.org > Date: Fri, 9 Jul 2010 17:21:15 +0200 > Subject: Re: Opinions please -- how big should a single module grow? > On Fri, 9 Jul 2010, Tomasz Rola wrote: > > > On Fri, 9 Jul 2010, Steven D'Aprano wrote: > > > > > This is a style question rather than a programming question. > > > > > > How large (how many KB, lines, classes, whatever unit of code you like > to > > > measure in) should a module grow before I should break it up into a > > > package? I see that, for example, decimal.py is > 3000 lines of code, > so > > > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > > > Where do you draw the line? > > > > > > For the purposes of the discussion, you should consider that the code > in > > > the module really does belong together, and that splitting it into sub- > > > modules would mean arbitrarily separating code into separate files. > > > > Myself, I would draw "the line" somewhere between 20-50 KLOC&C (code with > > comments) - if something takes a lot of place to comment, then maybe it > > should go to a separate unit. > > I meant 2-5 KLOC&C. Oups... > > Regards, > Tomasz Rola > > -- > ** A C programmer asked whether computer had Buddha's nature. ** > ** As the answer, master did "rm -rif" on the programmer's home ** > ** directory. And then the C programmer became enlightened... ** > ** ** > ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 9 Jul 2010 08:41:57 -0700 > Subject: Re: Python -- floating point arithmetic > In article , > Chris Rebert wrote: > >On Thu, Jul 8, 2010 at 8:52 AM, Giacomo Boffi > wrote: > >> "Zooko O'Whielacronx" writes: > >>> > >>> I'm starting to think that one should use Decimals by default and > >>> reserve floats for special cases. > >> > >> would you kindly lend me your Decimals ruler? i need to measure the > >> sides of the triangle whose area i have to compute > > > >If your ruler doesn't have a [second] set of marks for centimeters and > >millimeters, that's really one cheap/cruddy ruler you're using. > > Unless I'm badly mistaken, Giacomo was making a funny about Greek > geometers. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > > > > ---------- Forwarded message ---------- > From: aahz at pythoncraft.com (Aahz) > To: python-list at python.org > Date: 9 Jul 2010 08:47:51 -0700 > Subject: Re: 'reload M' doesn't update 'from M inport *' > In article , > Frederic Rentsch wrote: > > > >Module M says 'from service import *'. > >Next I correct a mistake in function 'service.f'. > >Now 'service.f' works fine. > > > >I do 'reload (service); reload (M)'. > >The function 'M.f' still misbehaves. > > Absolutely! > > >'print inspect.getsource (service.f)' and > >'print inspect.getsource (M.f)' shows the same > >corrected code. > > > >'print service.f' and 'print M.f' show different ids. > > > >So I do 'del M; reload (M)'. Nothing changes. > > > >I delete M again and run gc.collect () to really clean house. I reload > >M again and still nothing changes. The id of the reloaded function > >'M.f' is still the same as it was before the purge and so M.f still > >isn't fixed. > > > >I know I have more radical options, such as starting a new IDLE > >window. That would save me time, but I'd like to take the opportunity > >to understand what is happening. Surely someone out there knows. > > Take a look at sys.modules to get a better idea of what's happening. > (Maybe someone else will have time to write a longer answer.) > > But really, relying on reload() is foolish in the general case because > it's nearly impossible to track down every single reference. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > > > > ---------- Forwarded message ---------- > From: "Alf P. Steinbach /Usenet" > > > To: python-list at python.org > Date: Fri, 09 Jul 2010 17:52:14 +0200 > Subject: Cpp + Python: static data dynamic initialization in *nix shared > lib? > [Cross-posted comp.lang.python and comp.lang.c++] > > I lack experience with shared libraries in *nix and so I need to ask... > > This is about "cppy", some support for writing Python extensions in C++ > that I just started on (some days ago almost known as "pynis" (not funny > after all)). > > For an extension module it seems that Python requires each routine to be > defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern "C"' > and C++ linkage, using a routine declared as 'static' in a class as a C > callback, formally they're two different kinds, and I seem to recall that > /some/ C++ compiler balks at that kind of mixing unless specially instructed > to allow it. Perhaps it was the Sun compiler? > > Anyway, to be formally correct I cannot generate the required C routines > via templating, and I ended up using macros that the user must explicitly > invoke, like, here the Py doc's first extension module example recoded using > cppy, > > > ------------------------------------------------------------------ > > #include > #include > using namespace progrock; > > class Spam: public cppy::Module > { > public: > Spam(): cppy::Module( "spam" ) > { > setDocString( L"bl?b?rsyltet?y er bl?tt" ); > } > > PyObject* system( PyObject* args ) > { > const char *command; > int sts; > > if( !PyArg_ParseTuple( args, "s", &command ) ) > { > return NULL; > } > sts = ::system( command ); > return Py_BuildValue( "i", sts ); > } > }; > > CPPY_MODULE_CROUTINE( Spam, system, "Execute a shell command" ) > > PyMODINIT_FUNC PyInit_spam() > { > return cppy::init< Spam >(); > } > > ------------------------------------------------------------------ > > > It works in Windows. > > But here CPPY_MODULE_CROUTINE does three things: > > A Defining the 'extern "C"' routine. > I cannot think of any problem here. > > B Defining installation data for that routine. > Possible problem: initializing a static with address of routine? > > C -> Adding that install data record into a linked list! > Possible problem: are dynamic initialization actions guaranteed > to be performed in *nix shared library? > > Problem (C) is outside the realm of the C++ standard, since the C++ > standard doesn't support shared libraries, and I've never actually used *nix > shared libraries so I don't /know/... > > Is such dynamic initialization guaranteed? > > For completeness, the macro definition (the 0 in there is a list > next-pointer): > > > > #define CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) \ > extern "C" \ > static PyObject* cppClassName##_##name( PyObject*, PyObject* args ) \ > { \ > return ::progrock::cppy::module().name( args ); \ > } > > #define CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) > \ > static ::progrock::cppy::detail::ModuleRoutineDescriptor > \ > cppClassName##_##name##_descriptor = { > \ > 0, > \ > #name, > \ > docString, > \ > &cppClassName##_##name > \ > }; > \ > > \ > static bool cppClassName##_##name##_descriptor_installed = > \ > ::progrock::cppy::detail::addToList< cppClassName >( > \ > cppClassName##_##name##_descriptor > \ > ); > > #define CPPY_MODULE_CROUTINE( cppClassName, name, docString ) > \ > CPPY_MODULE_CROUTINE_DEF( cppClassName, name ) > \ > CPPY_MODULE_CROUTINE_INSTALLDATA( cppClassName, name, docString ) > > > > TIA., > > - Alf > > -- > blog at > > > > ---------- Forwarded message ---------- > From: crow > To: python-list at python.org > Date: Fri, 9 Jul 2010 08:58:35 -0700 (PDT) > Subject: Why there is no "setdefaultencoding" in sys module? > Hi, everyone > > I'm a new hand at python. > > I tried to set system default encoding by using > > "import sys; sys.setdefaultencoding('utf-f')", > > but I got error message: > > >>> sys.setdefaultencoding('utf-8') > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'setdefaultencoding' > > Then I checked dir(sys), seems there was no function named > "setdefaultencoding" in "sys" module. But in python's document, it > said I should use sys.setdefaultencoding. > > So, my questions: why there is no setdefaultencoding in sys module? if > I want to change system's default encoding, what should I do? > > Thanks in advance > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dani.valverde at gmail.com Fri Jul 9 12:31:36 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Fri, 09 Jul 2010 18:31:36 +0200 Subject: Hello Message-ID: <4C374EE8.4060404@gmail.com> Hello! I am new to python and pretty new to programming (I have some expertise wit R statistical programming language). I am just starting, so my questions may be a little bit stupid. Can anyone suggest a good editor for python? Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From thomas at jollans.com Fri Jul 9 12:35:34 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 18:35:34 +0200 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> Message-ID: <4C374FD6.8070300@jollans.com> On 07/09/2010 06:06 PM, crow wrote: > On Jul 10, 12:04 am, Steven D'Aprano cybersource.com.au> wrote: >> On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: >>> So, my questions: why there is no setdefaultencoding in sys module? if I >>> want to change system's default encoding, what should I do? >> >> I think the answer is: >> >> Don't. >> >> If you do, you will break built-ins. >> >> http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... >> >> Googling will find many discussions about this. >> >> -- >> Steven > > Interesting, so it has been removed from python? then why it's still > in document... It's really misleading. Actually, it's still there. Lurking in the corners of sys. But site.py knows it's evil: % python Python 2.6.5+ (release26-maint, Jul 6 2010, 12:58:20) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.setdefaultencoding Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'setdefaultencoding' >>> reload(sys) >>> sys.setdefaultencoding >>> From animator333 at gmail.com Fri Jul 9 12:36:11 2010 From: animator333 at gmail.com (King) Date: Fri, 9 Jul 2010 09:36:11 -0700 (PDT) Subject: zipimport (.pyd & .so) files. Message-ID: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Hi, The 'zipimport' modules can only import (.py & .pyc) files from a zip file and doesn't support importing .pyd & .so files. Recently I was examining the code of Py2Exe (python package deployment tool) and I have found that it is using a module 'zipextimporter' that can import dlls(.pyd) modules from a zip file. It is based on the concept of loading library form memory. You can find out more about here: http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ It's strictly for windows platform. I would like to know from expert python users and linux programmers, how we can achieve similar functionality on linux platform? I do have limited c/c++ skill sets but I would love to give a try. Cheers Prashant From alf.p.steinbach+usenet at gmail.com Fri Jul 9 12:37:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 18:37:59 +0200 Subject: Hello In-Reply-To: References: Message-ID: * Dani Valverde, on 09.07.2010 18:31: > Hello! > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? > Cheers! If you're working in Windows the Notepad++ and PSPad and old Crimson Editor (all free) all work nicely and are reasonably light-weight. Cheers & hth., - Alf -- blog at From airscorp at otenet.gr Fri Jul 9 12:41:43 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Fri, 09 Jul 2010 19:41:43 +0300 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C375147.9030708@otenet.gr> > I know I have more radical options, such as starting > a new IDLE window. That would save me time, but > I'd like to take the opportunity to understand what > is happening. Surely someone out there knows. > > Frederic > > Or you can restart the IDLE shell with CTRL+F6. If you can't restart it, you're probably not using an IDLE subprocess: On linux, make sure the menu item doesn't use "-n" in the command On Windows, first open IDLE, then open the file, or change the Open command to not use the "-n" flag. Sorry to not chip in to your question, frankly, Steven nailed it! Just thought to share an IDLE tip :) Nick From invalid at invalid.invalid Fri Jul 9 12:49:20 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Subject: Hello References: Message-ID: On 2010-07-09, Dani Valverde wrote: > I am new to python and pretty new to programming (I have some > expertise wit R statistical programming language). I am just > starting, so my questions may be a little bit stupid. Can anyone > suggest a good editor for python? Emacs, Scite (has nice folding), Vim, Eclipse. -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From rhodri at wildebst.demon.co.uk Fri Jul 9 12:59:59 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 09 Jul 2010 17:59:59 +0100 Subject: Hello References: Message-ID: On Fri, 09 Jul 2010 17:31:36 +0100, Dani Valverde wrote: > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? Whatever you feel most comfortable with. Idle comes packaged with Python, but can be a bit limited. If you can stand the learning curve (and a lot of people can't, it seems), Emacs and Vim are highly configurable and offer a lot of language-specific convenience functions. Basically, try a few different editors out and see what style you like. -- Rhodri James *-* Wildebeeste Herder to the Masses From airscorp at otenet.gr Fri Jul 9 13:02:00 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Fri, 09 Jul 2010 20:02:00 +0300 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: <4C375608.2000905@otenet.gr> Hello Dani! IDLE is very friendly for new users and has got me a long way when I was starting. You also can't beat that it comes bundled with Python. I'd also like to suggest the Python-Tutor list http://mail.python.org/mailman/listinfo/tutor for your "new-user" questions. Lots of helpful folk there, myself included. Nick On 07/09/2010 07:31 PM, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some > expertise wit R statistical programming language). I am just starting, > so my questions may be a little bit stupid. Can anyone suggest a good > editor for python? > Cheers! > > Dani > From sturlamolden at yahoo.no Fri Jul 9 13:03:42 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Fri, 9 Jul 2010 10:03:42 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <25863592-e417-4157-bbfb-1743e6889fb1@z10g2000yqb.googlegroups.com> Message-ID: On 9 Jul, 15:25, Felix wrote: > PS: No need to convince me that MATLAB is not the solution. What I mean is that Matlab and Mathematica are inherently "single threaded" interpreters. Yet they are still used for serious parallel computing. While Python has multiple threads but a GIL, only allowing one thread in the interpreter is even more restrictive. From bradley.h at aggiemail.usu.edu Fri Jul 9 13:03:43 2010 From: bradley.h at aggiemail.usu.edu (Bradley Hintze) Date: Fri, 9 Jul 2010 13:03:43 -0400 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: There are lots of great editors out there. It really depends on personal preference. It also depends on your OS. I us Mac OSX and like jEdit (my lab mate likes bbEdit). When I was on windows I liked notepad2. On linux i really like gEdit. Any of these will work great for a beginner! Bradley On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise wit > R statistical programming language). I am just starting, so my questions may > be a little bit stupid. Can anyone suggest a good editor for python? > Cheers! > > Dani > > -- > Daniel Valverde Saub? > c/Joan Maragall 37 4 2 > 17002 Girona > Spain > Tel?fon m?bil: +34651987662 > e-mail: dani.valverde at gmail.com > http://www.acrocephalus.net > http://natupics.blogspot.com > > Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas > utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera > ajudar?s a estalviar aigua, energia i recursos forestals. ?GR?CIES! > > Do not print this message unless it is absolutely necessary. If you must > print it, please use 100% recycled paper whitened without chlorine. By doing > so, you will save water, energy and forest resources. THANK YOU! > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From dani.valverde at gmail.com Fri Jul 9 13:08:19 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Fri, 09 Jul 2010 19:08:19 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> Message-ID: <4C375783.7090700@gmail.com> Sorry, I forgot to mention that I am using Linux. In fact, my first test have been with gedit. Is there any way to directly run the Python code into the console? Cheers! Dani Bradley Hintze wrote: > There are lots of great editors out there. It really depends on > personal preference. It also depends on your OS. I us Mac OSX and like > jEdit (my lab mate likes bbEdit). When I was on windows I liked > notepad2. On linux i really like gEdit. Any of these will work great > for a beginner! > > Bradley > > > On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde wrote: > >> Hello! >> I am new to python and pretty new to programming (I have some expertise wit >> R statistical programming language). I am just starting, so my questions may >> be a little bit stupid. Can anyone suggest a good editor for python? >> Cheers! >> >> Dani >> >> -- >> Daniel Valverde Saub? >> c/Joan Maragall 37 4 2 >> 17002 Girona >> Spain >> Tel?fon m?bil: +34651987662 >> e-mail: dani.valverde at gmail.com >> http://www.acrocephalus.net >> http://natupics.blogspot.com >> >> Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas >> utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera >> ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! >> >> Do not print this message unless it is absolutely necessary. If you must >> print it, please use 100% recycled paper whitened without chlorine. By doing >> so, you will save water, energy and forest resources. THANK YOU! >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > > -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From lists at cheimes.de Fri Jul 9 13:25:31 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 19:25:31 +0200 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> <4c374872$0$28647$c3e8da3@news.astraweb.com> <3c3e00f1-1d01-4483-af47-583849536a2f@w15g2000pro.googlegroups.com> <8bd0bd45-6adc-4a94-b266-511b6c86f064@w15g2000pro.googlegroups.com> Message-ID: > oh, I take back my words, it's still there, just I need to > reload(sys). Just don't. If you change the default encoding you are going to break important data structures like dicts in a subtle and hard to detect way. If your application needs to change the default encoding, it's broken. The function is removed for a very good reaso. From jeanmichel at sequans.com Fri Jul 9 13:38:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 09 Jul 2010 19:38:18 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C375E8A.6080506@sequans.com> Frederic Rentsch wrote: > I develop in an IDLE window. > > Module M says 'from service import *'. > Next I correct a mistake in function 'service.f'. > Now 'service.f' works fine. > > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. > > 'print inspect.getsource (service.f)' and > 'print inspect.getsource (M.f)' shows the same > corrected code. > > 'print service.f' and 'print M.f' show different ids. > > So I do 'del M; reload (M)'. Nothing changes. > > I delete M again and run gc.collect () to really > clean house. I reload M again and still nothing changes. > The id of the reloaded function 'M.f' is still the > same as it was before the purge and so M.f still isn't > fixed. > > I know I have more radical options, such as starting > a new IDLE window. That would save me time, but > I'd like to take the opportunity to understand what > is happening. Surely someone out there knows. > > Frederic > > > > > > Hi, Don't use reload, this is nothing but a trap, espacially if your using it to update your objects with the code you are writting. JM PS : You're misusing the del statement. It does not remove any object from mmory, however, it removes the reference to it, the object is still in memory. They are very few cases where del is usefull in python, so try to avoid using it as well. From thomas at jollans.com Fri Jul 9 13:48:53 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 19:48:53 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <4C376105.20008@jollans.com> On 07/09/2010 06:36 PM, King wrote: > Hi, > > The 'zipimport' modules can only import (.py & .pyc) files from a zip > file and doesn't support importing .pyd & .so files. Recently I was > examining the code of Py2Exe (python package deployment tool) and I > have found that it is using a module 'zipextimporter' that can import > dlls(.pyd) modules from a zip file. > It is based on the concept of loading library form memory. You can > find out more about here: > http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ > > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. I don't think it's possible as such: On UNIX systems, dynamic module loading is done with the dl* functions in libdl. From the manual installed on my machine: void *dlopen(const char *filename, int flag); char *dlerror(void); void *dlsym(void *handle, const char *symbol); int dlclose(void *handle); Link with -ldl. dlopen() takes a file name. It is, as far as I know, the only, or at least the only portable way to load a shared object. There might be some way to load so's from memory on certain Unices, but these would only work on one system (and I doubt they exist anyway) So you'd have to extract the file, and make it available through the file system. This would typically mean creating a file under /tmp (or possibly under $HOME/.cache/...) Cheers Thomas > > Cheers > > Prashant > From thomas at jollans.com Fri Jul 9 13:58:10 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 09 Jul 2010 19:58:10 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <4C376332.2040308@jollans.com> On 07/09/2010 06:36 PM, King wrote: > Hi, > > The 'zipimport' modules can only import (.py & .pyc) files from a zip > file and doesn't support importing .pyd & .so files. Recently I was > examining the code of Py2Exe (python package deployment tool) and I > have found that it is using a module 'zipextimporter' that can import > dlls(.pyd) modules from a zip file. > It is based on the concept of loading library form memory. You can > find out more about here: > http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ I just had a quick look at that article (I hadn't before). It's probably possible to do something similar on other systems: In principle, you can know the layout of an .so, and then manually load it. But, basically, don't. While supporting Linux itself might not be too difficult (you can use the libdl (or kernel?) sources as a reference, I expect), but supporting multiple UNIX variants is almost certainly very, very difficult. Maybe there are some actual experts around with a different view, but I'd recommend, to load object code not directly accessible via the file system, put it in the file system! > > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. > > Cheers > > Prashant > From lists at cheimes.de Fri Jul 9 13:58:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 19:58:54 +0200 Subject: zipimport (.pyd & .so) files. In-Reply-To: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: > It's strictly for windows platform. I would like to know from expert > python users and linux programmers, how we can achieve similar > functionality on linux platform? I do have limited c/c++ skill sets > but I would love to give a try. I don't know any way to load a shared library from something other than a file on the file system. Unless you find a variant of dlopen() that supports memory segments, you are out of luck. From jeanmichel at sequans.com Fri Jul 9 13:59:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 09 Jul 2010 19:59:00 +0200 Subject: Hello In-Reply-To: <4C375783.7090700@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: <4C376364.9020405@sequans.com> Dani Valverde wrote: > Sorry, I forgot to mention that I am using Linux. In fact, my first > test have been with gedit. Is there any way to directly run the Python > code into the console? > > Cheers! > > Dani > > Bradley Hintze wrote: >> There are lots of great editors out there. It really depends on >> personal preference. It also depends on your OS. I us Mac OSX and like >> jEdit (my lab mate likes bbEdit). When I was on windows I liked >> notepad2. On linux i really like gEdit. Any of these will work great >> for a beginner! >> >> Bradley >> >> >> On Fri, Jul 9, 2010 at 12:31 PM, Dani Valverde >> wrote: >> >>> Hello! >>> I am new to python and pretty new to programming (I have some >>> expertise wit >>> R statistical programming language). I am just starting, so my >>> questions may >>> be a little bit stupid. Can anyone suggest a good editor for python? >>> Cheers! >>> >>> Dani > Welcome Dani, Please do not top post. vim & emacs are the most featured text editors, they are suitable for any language. If you want something more oriented towards python, have a try with "eric", that's the IDE name. The name's sucks a lot but I discovered it recently from an annoucement in this list, and I found it pretty impressive. Integrated shell, debugger, linter, refactoring plugin, UI designers etc... JM From rtomek at ceti.com.pl Fri Jul 9 14:03:59 2010 From: rtomek at ceti.com.pl (Tomasz Rola) Date: Fri, 9 Jul 2010 20:03:59 +0200 Subject: Opinions please -- how big should a single module grow? In-Reply-To: References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: And just in case... A real life example (my computer, more or less typical Linux setup): find / -type f -name '*.py' -exec wc {} \; | gawk '{ l+=$1; } END {print l / FNR; } BEGIN { l=0; }' (the two lines should be concatenated) This gives a mean: 269.069 So, if I did not screw something, a typical Python code size is far below 1KLOC (wc counts all lines, so my result includes all comments and blanks too). Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From no.email at nospam.invalid Fri Jul 9 14:21:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 09 Jul 2010 11:21:32 -0700 Subject: Opinions please -- how big should a single module grow? References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: <7x4og8v7mb.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is > 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? I'd tend to say 2-4 KLOC, basically the max size in which it's reasonable to scroll through the file and read what it's doing, navigate around it with an editor, etc. Some exceptions are possible. From anthra.norell at bluewin.ch Fri Jul 9 14:38:43 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 20:38:43 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <4c37472e$0$28647$c3e8da3@news.astraweb.com> References: <4c37472e$0$28647$c3e8da3@news.astraweb.com> Message-ID: <1278700723.2362.45.camel@hatchbox-one> On Fri, 2010-07-09 at 15:58 +0000, Steven D'Aprano wrote: > On Fri, 09 Jul 2010 15:02:25 +0200, Frederic Rentsch wrote: > > > I develop in an IDLE window. > > > > Module M says 'from service import *'. Next I correct a mistake in > > function 'service.f'. Now 'service.f' works fine. > > from service import * > > should be considered advanced functionality that is discouraged unless > you really know what you are doing, precisely for the problems you are > experiencing. You should try to avoid it. > > But putting that aside, if you have done "from service import *" in > module m, where are you getting "service.f" from? The only way that is > possible is if you ALSO say "import service". > > > > I do 'reload (service); reload (M)'. > > The function 'M.f' still misbehaves. > > > > 'print inspect.getsource (service.f)' and 'print inspect.getsource > > (M.f)' shows the same corrected code. > > inspect.getsource always looks at the source code on disk, no matter what > the byte code in memory actually says. > > > 'print service.f' and 'print M.f' show different ids. > > > > So I do 'del M; reload (M)'. Nothing changes. > > > > I delete M again and run gc.collect () to really clean house. I reload M > > again and still nothing changes. The id of the reloaded function 'M.f' > > is still the same as it was before the purge and so M.f still isn't > > fixed. > > > > I know I have more radical options, such as starting a new IDLE window. > > That would save me time, but I'd like to take the opportunity to > > understand what is happening. Surely someone out there knows. > > Yes. You have to understand importing. Let's start with the simple: > > import m > > In *very* simplified pseudo-code, this does: > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > create a new name "m" in the local namespace > set the name "m" to the Module object in the cache > > Now let's compare it to: > > from m import f > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > look for object named "f" in the Module object > create a new name "f" in the local namespace > set the name "f" to cached object > > The important thing to notice is the the name "f" is a local variable. It > doesn't, and can't, remember that it comes from module m. Reloading m > can't do anything to f, because the connection is lost. > > Now consider that the object "f" that came from m was itself imported > from another module, "service". Reloading service doesn't help, because > m.f doesn't know it came from service. Reloading m doesn't help, because > all that does is run "from service import f" again, and that just fetches > f from the global cache. > > The simplest, easiest way of dealing with this is not to have to deal > with it: don't use "from service import f", and ESPECIALLY don't use > "from service import *". Always use fully-qualified importing: > > import service > service.f > > Now "reload(service)" should do what you expect. > > The other way is not to bother with reload. It's not very powerful, only > good for the simplest use in the interactive interpreter. Just exit the > interpreter and restart it. > > > -- > Steven Thank you very much for your excellent explanation! I must say that I haven't been using the "from soandso import ..." formula at all. I thought it might expose names to collision, and why should I assume the responsibility if I can avoid the problem altogether using explicit names. If I used the, shall we say, "direct import" this time it was in an effort to develop a more extensive program. I thought if a module grows beyond a size that's comfortable to edit, I could just move select segments to separate files and replace the vacancy with "from the_respective_segment_module import *", analogous to "#include" in C. The remedy seems to have side-effects that can kill the patient. So I'll go back to the explicit imports, then. No problem at all. Thanking you and the other helpers too Frederic From debatem1 at gmail.com Fri Jul 9 14:43:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 14:43:24 -0400 Subject: Hello In-Reply-To: <4C375783.7090700@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > Sorry, I forgot to mention that I am using Linux. In fact, my first test > have been with gedit. Is there any way to directly run the Python code into > the console? Gedit has a plugin that brings up a python intepreter. Edit->Preferences->Plugins->python console I think. Geremy Condra From stefaan.himpe at gmail.com Fri Jul 9 15:10:52 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Fri, 09 Jul 2010 21:10:52 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <1vKZn.103886$We4.70738@hurricane> > Is Pocoo really the only solution available out there? No. See e.g. http://www.pyforum.org/ From schaffer at optonline.net Fri Jul 9 15:13:30 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 09 Jul 2010 15:13:30 -0400 Subject: any issues with long running python apps? Message-ID: <4c3774df$0$31278$607ed4bc@cv.net> i have been asked to guarantee that a proposed Python application will run continuously under MS Windows for two months time. And i am looking to know what i don't know. The app would read instrument data from a serial port, store the data in file, and display in matplotlib. typical sampling times are about once per hour. our design would be to read the serial port once a second (long story, but it worked for ten days straight so far) and just store and display the values once an hour. so basically we'd have a long running for-loop. maybe running in a separate thread. i have thought through the issues on our end: we have to properly handle the serial port and make sure our GUI doesn't hang easily. we'd have to be sure we don't have any memory leaks in numpy or matplotlib and we're not storing data in memory stupidly. i've never looked into Windows serial port driver reliability over the long term. But we think if the serial port hangs, we can detect that and react accordingly. but none of this has anything to do with Python itself. i am sure python servers have been running reliably for long periods of time, but i've never had to deal with a two-month guarantee before. is there something else i am missing here that i should be concerned about on the pure-Python side of things? something under the hood of the python interpreter that could be problematic when run for a long time? or need we only concern ourselves with the nuts behind the wheel:that is, we the developers? thanks Les From tjreedy at udel.edu Fri Jul 9 15:55:58 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 15:55:58 -0400 Subject: 500 tracker orphans; we need more reviewers In-Reply-To: References: Message-ID: On 7/8/2010 5:58 PM, Mark Lawrence wrote: > On 19-6-2010 23:45, Shashwat Anand wrote: >> Terry: Thanks for bringing this to notice. >> Mark: Kudos for your effort in cleaning up bugs.python.org >> > > Like I've said elsewhere, flattery will get you everywhere. :) > > FYI there are now 480 orphans and I've managed to get 8 issues closed. > After one week I even got promoted to the triage team, although I found > the pay increase rather disappointing. :) Great news. Imitation is the sincerest form of flattery. [Charles Caleb Colton,(1780 - 1832): Lacon, volume I, no. 183] -- Terry Jan Reedy From torriem at gmail.com Fri Jul 9 15:56:12 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 09 Jul 2010 13:56:12 -0600 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4C377EDC.2030809@gmail.com> On 07/09/2010 01:13 PM, Les Schaffer wrote: > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? It never hurts to separate the data collection and visualization/analysis parts into separate programs. That way you can keep the critical, long-running data collection program running, and if you get an exception in the GUI because of some divide by zero programming error or some other problem, you can restart that part without impacting the overall system. From lists at cheimes.de Fri Jul 9 15:58:35 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 09 Jul 2010 21:58:35 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? At our company we have long running Python processes with an uptime of 60, 90 days or more. Python is up to the challenge. ;) But it's a challenge to keep any process written in any programming language running for two months or more. If I were in your case I would split up the work across multiple python process. One guardian process that keeps the other processes alive and checks if they are still reacting on events, another process that reads data from the serial port and writes it to a database or file and a third process to process the data. Small processes reduce the chance of an error. I assume that the "read from serial port" part is the mission critical element of your app. Christian From kosh at aesaeion.com Fri Jul 9 16:03:15 2010 From: kosh at aesaeion.com (William Heymann) Date: Fri, 9 Jul 2010 14:03:15 -0600 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <201007091403.16095.kosh@aesaeion.com> On Friday 09 July 2010, Les Schaffer wrote: > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? > > thanks > > Les I have been running zope apps for about 10 years now and they normally run for many months between being restarted so python has no inherent problems with running that long. Your specific python program might though. You have to make sure you don't have any reference leaks so your program keeps growing in memory but you also have to deal with windows. The program can not be any more reliable then the os it is running on. Personally I would never make a guarantee like that on a windows box. I would have to hand choose every piece of hardware and run some kind of unix on it with a guarantee like that. Last I ran a program for a long time on windows it ran into some kind of address space fragmentation and eventually it would die on windows. There is some kind of problem with the windows VM system. 64bit windows will solve that mostly by having an address space so large you can't fragment it enough to kill the program in any reasonable time frame. If your program is not allocating and destroying large data structures all the time you probably don't have to worry about that but you do have to test it. From davea at ieee.org Fri Jul 9 16:15:27 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 09 Jul 2010 16:15:27 -0400 Subject: [Tutor] the ball needs a kick... In-Reply-To: References: <4C336BB7.8030209@ieee.org> <4C374A4E.60402@ieee.org> Message-ID: <4C37835F.2080505@ieee.org> yes But further messages had better be posted to the forum. And not top-posted. DaveA From tjreedy at udel.edu Fri Jul 9 16:16:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 16:16:52 -0400 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 7/9/2010 3:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. typical sampling times are about once > per hour. our design would be to read the serial port once a second > (long story, but it worked for ten days straight so far) and just store > and display the values once an hour. so basically we'd have a long > running for-loop. maybe running in a separate thread. Is this a dedicated machine, so you do not have anything else going that can delay for more than a second? > > i have thought through the issues on our end: we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to > be sure we don't have any memory leaks in numpy or matplotlib and we're > not storing data in memory stupidly. i've never looked into Windows > serial port driver reliability over the long term. But we think if the > serial port hangs, we can detect that and react accordingly. I read the ibmpc serial port bios code in the early 80s. It was pretty simple then. I would be very surprised if it has been messed up since and not fixed. > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? Python has been used for long-running background processes, at least on *nix, so the Python devs are sensitive to memory leak issues and respond to leak reports. That still leaves memory fragmentation. To try to avoid that, I would allocate all the needed data arrays immediately on startup (with dummy None pointers) and reuse them instead of deleting and regrowing them. Keeping explicit pointers is, of course more tedious and slightly error prone. I hope someone with actual experience also answers. -- Terry Jan Reedy From aahz at pythoncraft.com Fri Jul 9 16:34:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 13:34:54 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: In article , Jean-Michel Pichavant wrote: > >PS : You're misusing the del statement. It does not remove any object >from mmory, however, it removes the reference to it, the object is still >in memory. They are very few cases where del is usefull in python, so >try to avoid using it as well. The first two sentences are true; the last sentence is completely wrong. I've got lots of code using del, and it's a critically useful element of dictionary manipulation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From debatem1 at gmail.com Fri Jul 9 16:42:43 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 16:42:43 -0400 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On Fri, Jul 9, 2010 at 3:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will run > continuously under MS Windows for two months time. And i am looking to know > what i don't know. I normally use Linux for this sort of thing, so YMMV on the following advice. > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. ?typical sampling times are about once per > hour. our design would be to read the serial port once a second (long story, > but it worked for ten days straight so far) and just store and display the > values once an hour. so basically we'd have a long running for-loop. maybe > running in a separate thread. I'd keep the two timers, the process that actually checks and logs the data, and any postprocessing code completely separate. I'd also use something like the logging module to double up on where your data is stored- one on the local machine, another physically separated in case you lose a hard drive. It will also give you more information about where a failure might have occurred if/when it does. I'd also handle output/display on a separate machine. > i have thought through the issues on our end: ?we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to be > sure we don't have any memory leaks in numpy or matplotlib and we're not > storing data in memory stupidly. i've never looked into Windows serial port > driver reliability over the long term. But we think if the serial port > hangs, we can detect that and react accordingly. I would launch this as a subprocess and log so that even if you miss a measurement you still get what you need further on in the process. Just make sure that you can detect it at the time and that you also log an error when it occurs. This also minimizes the amount of memory your application directly handles and the susceptibility of your code to non-fatal problems with the serial port. > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've never > had to deal with a two-month guarantee before. ?is there something else i am > missing here that i should be concerned about on the pure-Python side of > things? something under the hood of the python interpreter that could be > problematic when run for a long time? Just ask all the what-ifs and you'll probably be ok. Geremy Condra From angani at gmail.com Fri Jul 9 16:47:48 2010 From: angani at gmail.com (Raju Angani) Date: Fri, 9 Jul 2010 13:47:48 -0700 (PDT) Subject: Hello References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Jul 9, 11:43?am, geremy condra wrote: > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > > Sorry, I forgot to mention that I am using Linux. In fact, my first test > > have been with gedit. Is there any way to directly run the Python code into > > the console? > > Gedit has a plugin that brings up a python intepreter. > Edit->Preferences->Plugins->python console I think. > > Geremy Condra Hi Dani, I started liking wingware ide, I used free version before my company finally bought a licensed version. Give it a try www.wingware.com Raju Angani From martin.hellwig at dcuktec.org Fri Jul 9 17:03:15 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 09 Jul 2010 22:03:15 +0100 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 07/09/10 20:13, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. Get a good lawyer and put into the contract, the last thing you want is a windows update that restarts the host and you are responsible because you guaranteed that it would run continuously. On the technical side; as Christian Heimes already pointed out, split the programs. Specifically I would have 1 service for data gathering, two separate watchdog services (that checks whether the other watchdog is still running and the 'core' service). The GUI should be an user side app and the services could be too, however consider running the services under the appropriate system account as in the past I have seen some strange things happening with services under user account, especially if there are password policies. I don't see from the interpreter point of view no reason why it couldn't work, it is much more likely your host system will mess things up (even if it wouldn't be windows). -- mph From tjreedy at udel.edu Fri Jul 9 17:10:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:10:05 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> Message-ID: On 7/9/2010 1:25 AM, sturlamolden wrote: > With OpenCL, Python is better than C for heavy computing. The Python > or C/C++ program has to supply OpenCL code (structured text) to the > OpenCL driver, which does the real work on GPU or CPU. Python is much > better than C or C++ at processing text. There will soon be OpenCL > drivers for most processors on the market. For those as ignorant as me, OpenCL = Open Computing Language (for parallel computing). Apple proposed, Khronos Group maintains spec (along with OpenGL), AMD, NVidea, Intel support. Send C-like text to device, as with OpenGL; device compiles and runs; mainly for number crunching with all resources a machine has. OpenCL and OpenGL can work together. There is already a Python binding: http://sourceforge.net/projects/pyopencl/ > But OpenCL drivers will not be pre-installed on Windows, as Microsoft > has a competing COM-based technology (DirectX Compute, with an > atrocious API and syntax). > -- Terry Jan Reedy From anthra.norell at bluewin.ch Fri Jul 9 17:14:23 2010 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Fri, 09 Jul 2010 23:14:23 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <4C375E8A.6080506@sequans.com> References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> Message-ID: <1278710063.2362.75.camel@hatchbox-one> On Fri, 2010-07-09 at 19:38 +0200, Jean-Michel Pichavant wrote: > Frederic Rentsch wrote: > > I develop in an IDLE window. > > > > Module M says 'from service import *'. > > Next I correct a mistake in function 'service.f'. > > Now 'service.f' works fine. > > > > I do 'reload (service); reload (M)'. > > The function 'M.f' still misbehaves. > > > > 'print inspect.getsource (service.f)' and > > 'print inspect.getsource (M.f)' shows the same > > corrected code. > > > > 'print service.f' and 'print M.f' show different ids. > > > > So I do 'del M; reload (M)'. Nothing changes. > > > > I delete M again and run gc.collect () to really > > clean house. I reload M again and still nothing changes. > > The id of the reloaded function 'M.f' is still the > > same as it was before the purge and so M.f still isn't > > fixed. > > > > I know I have more radical options, such as starting > > a new IDLE window. That would save me time, but > > I'd like to take the opportunity to understand what > > is happening. Surely someone out there knows. > > > > Frederic > > > > > > > > > > > > > Hi, > > Don't use reload, this is nothing but a trap, espacially if your using > it to update your objects with the code you are writting. > > JM I've found "reload" very usable for development in IDLE. IDLE memorizes my input, and the variables I assign output to. If restart IDLE I lose it all and start over. That is an awfully awkward alternative to "reload", an alternative I wouldn't consider. I found "reload" tricky with several modules, because all dependencies need to be updated and which way they go isn't always obvious. Reloading all modules in the right order works for me. The reload commands come up with Alt-P as long, precisely, as I don't restart IDLE. S : You're misusing the del statement. It does not remove any object > from mmory, however, it removes the reference to it, the object is still > in memory. They are very few cases where del is usefull in python, so > try to avoid using it as well. I understand that things going out of scope delete themselves. I have used del on occasion, for instance, to get rid of invalid members of a list or a dictionary. It has to be done in two passes, though, because neither can be altered during an iteration. The first pass makes a delete list of indices or keys, so that the actual deletion iterates through the delete list, not the object deleted from. Would you call that a misuse? Frederic From nagle at animats.com Fri Jul 9 17:19:44 2010 From: nagle at animats.com (John Nagle) Date: Fri, 09 Jul 2010 14:19:44 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c379276$0$1661$742ec2ed@news.sonic.net> On 7/9/2010 12:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. What if Master Control in Redmond decides to reboot your machine to install an update? They've been known to do that even when you thought you had remote update turned off. If you have to run Windows in a data acquistion application, you should be running Windows Embedded. See http://www.microsoft.com/windowsembedded This is a version of Windows 7 which comes with a tool for building customized boot images. Basically, you take out everything except what your application needs. Do you get Embedded Systems Journal? You should. John Nagle From ian-news at hotmail.com Fri Jul 9 17:22:43 2010 From: ian-news at hotmail.com (Ian Collins) Date: Sat, 10 Jul 2010 09:22:43 +1200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: Message-ID: <89pi93F819U4@mid.individual.net> On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: > [Cross-posted comp.lang.python and comp.lang.c++] > > I lack experience with shared libraries in *nix and so I need to ask... > > This is about "cppy", some support for writing Python extensions in C++ > that I just started on (some days ago almost known as "pynis" (not funny > after all)). > > For an extension module it seems that Python requires each routine to be > defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern > "C"' and C++ linkage, using a routine declared as 'static' in a class as > a C callback, formally they're two different kinds, and I seem to recall > that /some/ C++ compiler balks at that kind of mixing unless specially > instructed to allow it. Perhaps it was the Sun compiler? Yes, it will (correctly) issue a warning. As the is a bit OT, contact me directly and we can work through it. I have had similar fun and games adding PHP modules! -- Ian Collins From tjreedy at udel.edu Fri Jul 9 17:38:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:38:35 -0400 Subject: Opinions please -- how big should a single module grow? In-Reply-To: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> References: <4c36a7a0$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 7/9/2010 12:37 AM, Steven D'Aprano wrote: > This is a style question rather than a programming question. > > How large (how many KB, lines, classes, whatever unit of code you like to > measure in) should a module grow before I should break it up into a > package? I see that, for example, decimal.py is> 3000 lines of code, so > I can assume that 3 KLOC is acceptable. Presumably 3000 KLOC is not. > Where do you draw the line? > > For the purposes of the discussion, you should consider that the code in > the module really does belong together, and that splitting it into sub- > modules would mean arbitrarily separating code into separate files. 3000 lines is more that I would prefer. I pulled decimal.py into an IDLE edit window; loading was sluggish; the scroll bar is tiny; and any movement moves the text faster and farther than I would like. -- Terry Jan Reedy From debatem1 at gmail.com Fri Jul 9 17:43:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 17:43:51 -0400 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <89pi93F819U4@mid.individual.net> References: <89pi93F819U4@mid.individual.net> Message-ID: On Fri, Jul 9, 2010 at 5:22 PM, Ian Collins wrote: > On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >> >> [Cross-posted comp.lang.python and comp.lang.c++] >> >> I lack experience with shared libraries in *nix and so I need to ask... >> >> This is about "cppy", some support for writing Python extensions in C++ >> that I just started on (some days ago almost known as "pynis" (not funny >> after all)). >> >> For an extension module it seems that Python requires each routine to be >> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >> "C"' and C++ linkage, using a routine declared as 'static' in a class as >> a C callback, formally they're two different kinds, and I seem to recall >> that /some/ C++ compiler balks at that kind of mixing unless specially >> instructed to allow it. Perhaps it was the Sun compiler? > > Yes, it will (correctly) issue a warning. > > As the is a bit OT, contact me directly and we can work through it. ?I have > had similar fun and games adding PHP modules! I'd appreciate it if you'd either leave this on-list or cc me in on this, as I'm working through a similar issue. Geremy Condra From tjreedy at udel.edu Fri Jul 9 17:46:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:46:26 -0400 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278680545.2376.30.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: On 7/9/2010 9:02 AM, Frederic Rentsch wrote: > I do 'reload (service); reload (M)'. > The function 'M.f' still misbehaves. Guido removed reload from 3.0 because it gave people false hopes and he gave up on fixing it. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jul 9 17:48:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Jul 2010 17:48:30 -0400 Subject: Why there is no "setdefaultencoding" in sys module? In-Reply-To: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> References: <576f217a-d4f2-4f56-b631-a393e31e0151@q21g2000prm.googlegroups.com> Message-ID: On 7/9/2010 11:58 AM, crow wrote: > But in python's document, it > said I should use sys.setdefaultencoding. Where? That may need to be changed. -- Terry Jan Reedy From alf.p.steinbach+usenet at gmail.com Fri Jul 9 17:57:55 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 09 Jul 2010 23:57:55 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <89pi93F819U4@mid.individual.net> References: <89pi93F819U4@mid.individual.net> Message-ID: * Ian Collins, on 09.07.2010 23:22: > On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >> [Cross-posted comp.lang.python and comp.lang.c++] >> >> I lack experience with shared libraries in *nix and so I need to ask... >> >> This is about "cppy", some support for writing Python extensions in C++ >> that I just started on (some days ago almost known as "pynis" (not funny >> after all)). >> >> For an extension module it seems that Python requires each routine to be >> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >> "C"' and C++ linkage, using a routine declared as 'static' in a class as >> a C callback, formally they're two different kinds, and I seem to recall >> that /some/ C++ compiler balks at that kind of mixing unless specially >> instructed to allow it. Perhaps it was the Sun compiler? > > Yes, it will (correctly) issue a warning. > > As the is a bit OT, contact me directly and we can work through it. I > have had similar fun and games adding PHP modules! Thanks. I'm mailing you a zip with the code... The question, of course, whether it works in *nix. Cheers, - Alf -- blog at From debatem1 at gmail.com Fri Jul 9 18:17:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 9 Jul 2010 18:17:24 -0400 Subject: Lua is faster than Fortran??? In-Reply-To: References: <4c300afc$0$28647$c3e8da3@news.astraweb.com> <20100704102348.6e25c22e.darcy@druid.net> <20100704110047.d7d77cae.darcy@druid.net> <821dd785-aeac-4cd1-81ab-270d8c50f2e1@z8g2000yqz.googlegroups.com> Message-ID: On Fri, Jul 9, 2010 at 5:10 PM, Terry Reedy wrote: > On 7/9/2010 1:25 AM, sturlamolden wrote: > >> With OpenCL, Python is better than C for heavy computing. The Python >> or C/C++ program has to supply OpenCL code (structured text) to the >> OpenCL driver, which does the real work on GPU or CPU. Python is much >> better than C or C++ at processing text. There will soon be OpenCL >> drivers for most processors on the market. > > For those as ignorant as me, OpenCL = Open Computing Language (for parallel > computing). Apple proposed, Khronos Group maintains spec (along with > OpenGL), AMD, NVidea, Intel support. ?Send C-like text to device, as with > OpenGL; device compiles and runs; mainly for number crunching with all > resources a machine has. OpenCL and OpenGL can work together. There is > already a Python binding: > http://sourceforge.net/projects/pyopencl/ Its worth pointing out that right now you're generally better off with CUDA than OpenCL, and that pycuda bindings are usable, if not what I would call easy-to-use. Geremy Condra From ankit at callfire.com Fri Jul 9 18:27:28 2010 From: ankit at callfire.com (Ankit Jhalaria) Date: Fri, 9 Jul 2010 15:27:28 -0700 Subject: PIL Query Message-ID: Hi I was using the PIL. I found it pretty useful. I was wondering if you could please let me know, whether I could change the image size. What I mean is if suppose I have 100 points having the same latitude and longitude, the point on the map appears (for instance as a red circle). My question to you is, can I change the radius of this circle? I was also trying to figure out where in the code I can change the location where the url is served from. So instead of serving the images form http://localhost/classic/4/4,5.png how do I change it to http://localhost/username/classic/4/4,5.png where username is taken from the database. & my last question is, is it possible that I just give the PIL the latitude,longitude and the no. of points having the same latitude and longitude[i.e. intensity], instead of repeating the lat & long coordinates. Your help will be greatly appreciated Thanks Ankit -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Jul 9 18:39:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 10 Jul 2010 08:39:45 +1000 Subject: python instructor References: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> Message-ID: <871vbcb7pq.fsf@benfinney.id.au> Greg writes: > Any thoughts or advice would be greatly appreciated. Rather than here, you should post job advertisements at the Python Job Board . -- \ ?Love is the triumph of imagination over intelligence.? ?Henry | `\ L. Mencken | _o__) | Ben Finney From abhijeet.thatte at gmail.com Fri Jul 9 18:46:14 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 9 Jul 2010 15:46:14 -0700 Subject: Pretty printing with ElementTree Message-ID: Hi, Does any one know how to use pretty printing with ElementTree while generating xml files. We can use that with lxml. But I want to stick with it ElementTree. Thanks, Abhijeet -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkrukoff at ltgc.com Fri Jul 9 19:03:48 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Fri, 09 Jul 2010 17:03:48 -0600 Subject: Pretty printing with ElementTree In-Reply-To: References: Message-ID: <1278716628.7825.15.camel@localhost.localdomain> On Fri, 2010-07-09 at 15:46 -0700, abhijeet thatte wrote: > Hi, > > > Does any one know how to use pretty printing with ElementTree while > generating xml files. > We can use that with lxml. But I want to stick with it ElementTree. > > > Thanks, > Abhijeet It's pretty simple minded, but this recipe from the element tree documentation may do what you want: http://effbot.org/zone/element-lib.htm#prettyprint -- John Krukoff Land Title Guarantee Company From abhijeet.thatte at gmail.com Fri Jul 9 19:14:14 2010 From: abhijeet.thatte at gmail.com (abhijeet thatte) Date: Fri, 9 Jul 2010 16:14:14 -0700 Subject: Pretty printing with ElementTree In-Reply-To: <1278716628.7825.15.camel@localhost.localdomain> References: <1278716628.7825.15.camel@localhost.localdomain> Message-ID: It worked. Thanks, Abhijeet On Fri, Jul 9, 2010 at 4:03 PM, John Krukoff wrote: > On Fri, 2010-07-09 at 15:46 -0700, abhijeet thatte wrote: > > Hi, > > > > > > Does any one know how to use pretty printing with ElementTree while > > generating xml files. > > We can use that with lxml. But I want to stick with it ElementTree. > > > > > > Thanks, > > Abhijeet > > > It's pretty simple minded, but this recipe from the element tree > documentation may do what you want: > http://effbot.org/zone/element-lib.htm#prettyprint > > -- > John Krukoff > Land Title Guarantee Company > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Fri Jul 9 19:30:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 09 Jul 2010 16:30:56 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 7/9/2010 12:13 PM Les Schaffer said... > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. Keep users off the machine, turn off automated updates, and point dns to 127.0.0.1. Oh, put it on a UPS. I've got a handful or two of these automated systems in place and rarely have trouble. Add a watchdog scheduled task process to restart the job and check disk space or memory usage and push out a heartbeat. I found Chris Liechti's serial module years ago and have used it successfully since. The only times that come to mind when I've problems on the python side were related to memory usage and the system started thrashing. Adding memory fixed it. HTH, Emile > And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, store the data in > file, and display in matplotlib. typical sampling times are about once > per hour. our design would be to read the serial port once a second > (long story, but it worked for ten days straight so far) and just store > and display the values once an hour. so basically we'd have a long > running for-loop. maybe running in a separate thread. > > i have thought through the issues on our end: we have to properly handle > the serial port and make sure our GUI doesn't hang easily. we'd have to > be sure we don't have any memory leaks in numpy or matplotlib and we're > not storing data in memory stupidly. i've never looked into Windows > serial port driver reliability over the long term. But we think if the > serial port hangs, we can detect that and react accordingly. > > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? > > or need we only concern ourselves with the nuts behind the wheel:that > is, we the developers? > > thanks > > Les From roy at panix.com Fri Jul 9 19:32:57 2010 From: roy at panix.com (Roy Smith) Date: Fri, 09 Jul 2010 19:32:57 -0400 Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: In article <4c3774df$0$31278$607ed4bc at cv.net>, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. Heh. The OS won't stay up that long. From aahz at pythoncraft.com Fri Jul 9 19:52:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Jul 2010 16:52:03 -0700 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel References: Message-ID: In article , Steve Holden wrote: >Vicky Twomey-Lee wrote: >> >> When: Wed 14th July, from 7pm >> Where: Trinity Capital Hotel > >Hope you all had a good piss-up! See you a week on Saturday. Did Guido get pissed and give you the keys to the time machine? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From breamoreboy at yahoo.co.uk Fri Jul 9 20:14:30 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 10 Jul 2010 01:14:30 +0100 Subject: Python Ireland's pre-PyCon drinks - Wed, 14th July @ Trinity Capital Hotel In-Reply-To: References: Message-ID: On 10-7-2010 0:52, Aahz wrote: > In article, > Steve Holden wrote: >> Vicky Twomey-Lee wrote: >>> >>> When: Wed 14th July, from 7pm >>> Where: Trinity Capital Hotel >> >> Hope you all had a good piss-up! See you a week on Saturday. > > Did Guido get pissed and give you the keys to the time machine? No, he simply had a bad day and forgot to run the unit tests. Kindest regards. Mark Lawrence p.s. Best of luck to the Dutch and Spanish Sunday evening in the World Series Soccer!!! From python.list at tim.thechases.com Fri Jul 9 20:23:37 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 09 Jul 2010 19:23:37 -0500 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4C37BD89.1030006@tim.thechases.com> On 07/09/2010 06:32 PM, Roy Smith wrote: >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking >> to know what i don't know. > > Heh. The OS won't stay up that long. While I'm not sure how much of Roy's comment was "hah, hah, just serious", this has been my biggest issue with long-running Python processes on Win32 -- either power outages the UPS can't handle, or (more frequently) the updates (whether Microsoft-initiated or by other vendors' update tools) require a reboot for every ${EXPLETIVE}ing thing. The similar long-running Python processes I have on my Linux boxes have about 0.1% of the reboots/restarts for non-electrical reasons (just kernel and Python updates). As long as you're not storing an ever-increasing quantity of data in memory (write it out to disk storage and you should be fine), I've not had problems with Python-processes running for months. If you want belt+suspenders with that, you can take others' recommendations for monitoring processes and process separation of data-gathering vs. front-end GUI/web interface. -tkc From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 21:09:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 01:09:44 GMT Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4c37c857$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 17:46:26 -0400, Terry Reedy wrote: > On 7/9/2010 9:02 AM, Frederic Rentsch wrote: > >> I do 'reload (service); reload (M)'. >> The function 'M.f' still misbehaves. > > Guido removed reload from 3.0 because it gave people false hopes and he > gave up on fixing it. It's not quite *removed*. It's just no longer a built-in: import imp imp.reload(spam) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 9 21:13:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 01:13:28 GMT Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> Message-ID: <4c37c938$0$28647$c3e8da3@news.astraweb.com> On Fri, 09 Jul 2010 23:14:23 +0200, Frederic Rentsch wrote: > I understand that things going out of scope delete themselves. I have > used del on occasion, for instance, to get rid of invalid members of a > list or a dictionary. It has to be done in two passes, though, because > neither can be altered during an iteration. The first pass makes a > delete list of indices or keys, so that the actual deletion iterates > through the delete list, not the object deleted from. > Would you call that a misuse? No, that is perfectly fine. Pay no attention to anyone who says that del should be avoided. Like all tools, it can be used badly or inefficiently, or by somebody who doesn't understand it, but that's no reason to avoid using del correctly. Another strategy is to make a copy of the dict/list and iterate over that. Copies are fast, since you're only copying the top-level list or dict and not the underlying objects within it. A third is to forget about deleting and create a new list containing only the objects you don't want to delete. All three strategies (two using del, one without) have different use-cases and are perfectly acceptable. -- Steven From no.email at nospam.invalid Fri Jul 9 21:18:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 09 Jul 2010 18:18:42 -0700 Subject: python instructor References: <927dfd7f-ddec-44c9-a922-617347cab2bf@y4g2000yqy.googlegroups.com> <871vbcb7pq.fsf@benfinney.id.au> Message-ID: <7x630ob0ct.fsf@ruckus.brouhaha.com> Ben Finney writes: >> Any thoughts or advice would be greatly appreciated. > Rather than here, you should post job advertisements at the Python Job > Board . Since you are looking for an instructor to come to your site, it would also help if you stated your geographical location. From greg.ewing at canterbury.ac.nz Fri Jul 9 22:02:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 10 Jul 2010 14:02:00 +1200 Subject: delegation pattern via descriptor In-Reply-To: References: <36afce9e-7b1c-474b-a732-cc24c066165a@m40g2000prc.googlegroups.com> <4c2e072e$0$28647$c3e8da3@news.astraweb.com> <4c2f1b2f$0$17371$426a74cc@news.free.fr> <89aamgF7vdU1@mid.individual.net> <1fff02fe-ee2c-4d14-9afa-a50e2abf0407@z15g2000prn.googlegroups.com> <89cnv0FjnuU1@mid.individual.net> <89llvrFflvU1@mid.individual.net> Message-ID: <89q23iF1ufU1@mid.individual.net> kedra marbun wrote: > this 'passing class' thing comes from, > IIRC, learning python 4ed by Mark Lutz, it's stated there that the 3rd > arg to __get__ is the class to which the descriptor instance is > attached That's there so that the __get__ method of function objects can return an unbound method when looked up on a class rather than an instance of the class. There is no corresponding use case for a class argument to __set__ or __delete__, so they don't have one. -- Greg From f2h2d2 at gmail.com Fri Jul 9 22:29:01 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Fri, 9 Jul 2010 19:29:01 -0700 (PDT) Subject: Excuse me!! Message-ID: <653c44d7-9b08-48ec-a284-e52a262fa60c@41g2000yqn.googlegroups.com> Would you stop for a moment?! O...man...Haven't you thought-one day- about yourself ? Who has made it? Have you seen a design which hasn't a designer ?! Have you seen a wonderful,delicate work without a worker ?! It's you and the whole universe!.. Who has made them all ?!! You know who ?.. It's "ALLAH",prise be to him. Just think for a moment. How are you going to be after death ?! Can you believe that this exact system of the universe and all of these great creation will end in in nothing...just after death! Have you thought, for a second, How to save your soul from Allah's punishment?! Haven't you thought about what is the right religion?! Read ... and think deeply before you answer.. It is religion of Islam. It is the religion that Mohammad-peace upon him- the last prophet, had been sent by. It is the religion that the right Bible- which is not distorted-has preached. Just have a look at The Bible of (Bernaba). Don't be emstional. Be rational and judge.. Just look..listen...compare..and then judge and say your word. We advise you visiting : http://www.islamreligion.com http://www.islam-guide.com http://www.islamhouse.com/s/9661 ---------------------------------------------------- From falhodeb at gmail.com Fri Jul 9 23:18:59 2010 From: falhodeb at gmail.com (=?windows-1256?B?KCgoKOPM4+baySDH4c/a5skgx+HsIMfh4eUgx+HI0Q==?= =?windows-1256?B?7c/tySkpKSkgLQ==?=) Date: Fri, 9 Jul 2010 20:18:59 -0700 (PDT) Subject: (((((( hi Friend)))))) Message-ID: <610add37-b11e-400c-806f-350e527f778b@a30g2000yqn.googlegroups.com> (((((( hi Friend)))))) I bet that your happiness here Site a priest after being found happiness www.islamalways.com www.shareislam.com Other Sites: For more information about Islam http://islamtomorrow.com/ http://www.55a.net/firas/english/ http://english.islamway.com/ http://www.islamonline.net/english/inde x.shtml http://www.thelastingmiracle.com/eng/ ... http://alislam.6te.net/ http://www.quran.net/ http://www.thelastingmiracle.com/eng/ .. http://www.islamcode.com/ http://islamnewsroom.com/ Book calls to get to know the religion of Islam in English ... Author:. Saviour bin Mahmoud Alsagar Link: http://saaid.net/book/open.php?cat=&book=3850 Message presentations to non-Muslims about Islam http://www.imanway.com/vb/showthread.php?t=14862 Message ready, entitled Islam and the goal of life: ISLAM and the AIM of LIFE http://www.saaid.net/islam/2.htm Islam is a religion ease Islam, the Religion of Ease http://www.saaid.net/islam/3.htm You must know this man In The Name Of Allaah, Most Gracious, Most MercifulYOU MUST KNOW THIS MAN MUHAMMAD http://www.saaid.net/islam/9.htm Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=11984 Prophet Muhammad (peace and a message of thanks and appreciation from a non-Muslim person of the Prophet peace be upon him) http://www.imanway.com/vb/showthread...2092 # post92092 "Even the light laments his brother (piece of literature a simplified world, before and after the Prophet peace be upon him)" http://www.imanway.com/vb/showthread.php?t=15438 Prophet Muhammad (peace be upon him) in the eyes of western fair http://www.imanway.com/vb/showthread.php?t=15225 Certificate of non-Muslims to the Messenger of Allah (peace be upon him) http://www.imanway.com/vb/showthread.php?t=11985 You must know this man http://www.imanway.com/vb/showthread.php?t=11503 Life of the Prophet (peace be upon him) before the mission http://www.imanway.com/vb/showthread.php?t=11186 Signs of Prophethood http://www.imanway.com/vb/showthread.php?t=10815 Guide 12 on the health of the prophethood of the Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=15462 Hadith and Modern Science (genetic map) http://www.imanway.com/vb/showthread...0383 # post80383 A love letter to the whole world about the Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=2996 Success principles http://www.imanway.com/vb/showthread.php?t=2905 Sincerity of the Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=2658 Prophecy of the Prophet Moses peace be upon Prophet Muhammad peace be upon him http://www.imanway.com/vb/showthread.php?t=2657 Gospel of Prophet Jesus Prophet Muhammad (peace be upon him) http://www.imanway.com/vb/showthread.php?t=2649 Prophet Muhammad, peace be upon him in the Bible http://www.imanway.com/vb/showthread...8364 # post78364 Those who reject Sunnah of the Prophet peace be upon him and only the Qur'an http://www.imanway.com/vb/showthread...4545 # post84545 Jews waiting for the prophets (two, in fact, Jesus and Muhammad peace be upon them) http://www.imanway.com/vb/showthread.php?t=2648 Reply to slander the Gospel "deuteronomy" (God that will kill the prophet who speaks on behalf of the gods Error) http://www.imanway.com/vb/showthread.php?t=2647 Reply to suspicion (Muslims worship Muhammad peace be upon him) http://www.imanway.com/vb/showthread.php?t=16146 Muhammad is the Messenger of God: http://www.imanway.com/vb/showthread.php?t=11984 http://islamic-council.org/lib/FACTS-E-PDF/p5-123.pdf A quick message showing that Islam is a religion does not call for violence http://www.imanway.com/vb/showthread.php?t=15312 Cursing Islam Terrorism http://www.imanway.com/vb/showthread.php?t=15208 Response to a question: Why do most Muslims terrorists? http://www.imanway.com/vb/showthread.php?t=10198 Duties of the Muslim to non-Muslim http://www.imanway.com/vb/showthread.php?t=10828 Stories of Omar bin Khattab show the tolerance of Islam http://www.imanway.com/vb/showthread.php?t=18729 Prophet Muhammad peace be upon him in his last (farewell sermon) http://www.imanway.com/vb/showthread.php?t=18730 LIBRARY BOOKS Islamic library: You can copy the messages from and send Almtbp http://www.musalla.org/Articles/articles.htm Islamic library with more than 106 video clip in English: http://www.hyahya.org/en.m_video_index.php On this link to find Quran with Translation of the meaning in English ((direct link just copy it and then send it)) http://islamtomorrow.com/downloads/Quran_Khan.pdf This Rrabott for an explanation of each province: http://allahsquran.com/read/index.php A link to a collection of books and the Koran in several languages http://islamtomorrow.com/downloads/index.asp From drsalists at gmail.com Fri Jul 9 23:42:46 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 9 Jul 2010 20:42:46 -0700 Subject: any issues with long running python apps? In-Reply-To: <4C37BD89.1030006@tim.thechases.com> References: <4c3774df$0$31278$607ed4bc@cv.net> <4C37BD89.1030006@tim.thechases.com> Message-ID: On Fri, Jul 9, 2010 at 5:23 PM, Tim Chase wrote: > On 07/09/2010 06:32 PM, Roy Smith wrote: > >> i have been asked to guarantee that a proposed Python application will >>> run continuously under MS Windows for two months time. And i am looking >>> to know what i don't know. >>> >> >> Heh. The OS won't stay up that long. >> > > While I'm not sure how much of Roy's comment was "hah, hah, just serious", > this has been my biggest issue with long-running Python processes on Win32 > -- either power outages the UPS can't handle, or (more frequently) the > updates (whether Microsoft-initiated or by other vendors' update tools) > require a reboot for every ${EXPLETIVE}ing thing. The similar long-running > Python processes I have on my Linux boxes have about 0.1% of the > reboots/restarts for non-electrical reasons (just kernel and Python > updates). > > As long as you're not storing an ever-increasing quantity of data in memory > (write it out to disk storage and you should be fine), I've not had problems > with Python-processes running for months. If you want belt+suspenders with > that, you can take others' recommendations for monitoring processes and > process separation of data-gathering vs. front-end GUI/web interface. > > -tkc 1) Separate the crucial parts from the "need it someday" parts, as previously suggested. Perhaps run the crucial parts as a system service or daemon. 2) Use pylint, or at least PyChecker. pylint spills over into stylistic stuff in places, but it's very valuable in writing bullet proof Python, and its various warnings can all be turned off if necessary. I've not tried PyChecker. 3) Test, test, test. Unit test, Component test, System test. Consider hiring a Q/A person, even if only temporarily - if someone other than the main developer performs/writes the tests, they'll probably be more merciless to the code, and hence find more bugs before they become an issue. 4) Seriously: Think about whether you're on the right operating system. 5) Write a list of things that're beyond your control (Power Outages, OS crashes if they won't let you switch, crucial/unintended system patch, earthquake, fire, etc) and get your management to sign off on them as not your fault, with mitigations and contingencies where practical. You might want to include "...including but not limited to..." at the top of your list if you can. 6) Put the machine in a controlled machine room, and only access it over RDP or ssh. Don't put it near the KVM :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rene7705 at gmail.com Sat Jul 10 00:56:13 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Sat, 10 Jul 2010 06:56:13 +0200 Subject: how do you do a count of a result set? Message-ID: hi. i'm using this function; def dbCacheGet(self, appParams): results = db.GqlQuery( "SELECT * " "FROM DBcache " "WHERE url='"+appParams['urlCalled']+"'" ).fetch(1) if results.count('*')==0: return None else: return results i dont think this will work correctly. i need a function that returns the complete count in the results variable. i searched the docs, but couldn't find it. hope you can help me out here. -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From clp2 at rebertia.com Sat Jul 10 01:46:17 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 9 Jul 2010 22:46:17 -0700 Subject: how do you do a count of a result set? In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 9:56 PM, Rene Veerman wrote: > hi. > > i'm using this function; > > > ? ? ? ?def dbCacheGet(self, appParams): > ? ? ? ? ? ? ? ?results = db.GqlQuery( > ? ? ? ? ? ? ? ? ? ? ? ?"SELECT * " > ? ? ? ? ? ?"FROM DBcache " > ? ? ? ? ? ?"WHERE url='"+appParams['urlCalled']+"'" > ? ? ? ? ? ? ? ?).fetch(1) > ? ? ? ? ? ? ? ?if results.count('*')==0: > ? ? ? ? ? ? ? ? ? ? ? ?return None > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ? ? ?return results > > > i dont think this will work correctly. > i need a function that returns the complete count in the results variable. But you're returning either None or `results`, neither of which is a number ("count")... Also, .count() appears to take an integer, yet you're passing it the string "*". I thus have little idea what your code is intended to do. > i searched the docs, but couldn't find it. hope you can help me out here. (A) **Include the context** for your question next time, i.e. which library/framework/platform(s) you're using! You're fortunate I just so happened to recognize the mention of GQL and was able to guess that you're using Google App Engine. (B) Define "complete count". Its meaning in this situation is not obviously clear. I will *guess* that "complete count" means the total number of query results, and answer based on that assumption. I'm not that familiar with GAE, but it /appears/ from the docs that your only option is to try .count(), and if you hit the max of 1000+ results, either: * Call .fetch() with higher and higher limits until the results list stops growing, then return its len(); or * Iterate over the query object and count the number of results manually. Here's an attempt at implementing the latter approach: COUNT_MAX = 1000 def dbCacheGet(self, appParams): query_str = "SELECT * FROM DBcache WHERE url='"+appParams['urlCalled']+"'" query = db.GqlQuery(query_str) count = query.count() if count < COUNT_MAX: return count else: return sum(1 for result in query) Overall, I would guess it's probably more advisable and efficient to (if possible) just track these counts manually, ahead of time in your database as you add/remove records; GQL != SQL, so some things must be done differently. Hence probably why the "count the number of query results" approach isn't elegant. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Sat Jul 10 02:21:50 2010 From: nagle at animats.com (John Nagle) Date: Fri, 09 Jul 2010 23:21:50 -0700 Subject: how do you do a count of a result set? In-Reply-To: References: Message-ID: <4c381183$0$1636$742ec2ed@news.sonic.net> On 7/9/2010 11:08 PM, Dennis Lee Bieber wrote: > On Sat, 10 Jul 2010 06:56:13 +0200, Rene Veerman > declaimed the following in gmane.comp.python.general: > >> hi. >> >> i'm using this function; >> >> >> def dbCacheGet(self, appParams): >> results = db.GqlQuery( >> "SELECT * " >> "FROM DBcache " >> "WHERE url='"+appParams['urlCalled']+"'" >> ).fetch(1) >> if results.count('*')==0: >> return None >> else: >> return results >> >> >> i dont think this will work correctly. >> i need a function that returns the complete count in the results variable. This is really a Google AppEngine question. Ask in their support forums. It's worth noting that for many database queries, asking how many hits there are can cost almost as much as actually retrieving them. John Nagle From brian at sweetapp.com Sat Jul 10 02:53:27 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 10 Jul 2010 16:53:27 +1000 Subject: how do you do a count of a result set? In-Reply-To: <4c381183$0$1636$742ec2ed@news.sonic.net> References: <4c381183$0$1636$742ec2ed@news.sonic.net> Message-ID: <4D5A4AD5-C347-42D2-BBB5-5C758F792DB1@sweetapp.com> On 10 Jul 2010, at 16:21, John Nagle wrote: > On 7/9/2010 11:08 PM, Dennis Lee Bieber wrote: >> On Sat, 10 Jul 2010 06:56:13 +0200, Rene Veerman >> declaimed the following in gmane.comp.python.general: >> >>> hi. >>> >>> i'm using this function; >>> >>> >>> def dbCacheGet(self, appParams): >>> results = db.GqlQuery( >>> "SELECT * " >>> "FROM DBcache " >>> "WHERE url='"+appParams['urlCalled']+"'" >>> ).fetch(1) >>> if results.count('*')==0: >>> return None >>> else: >>> return results >>> >>> >>> i dont think this will work correctly. >>> i need a function that returns the complete count in the results >>> variable. > > This is really a Google AppEngine question. Ask in their support > forums. http://groups.google.com/group/google-appengine-python would be a good place to start. > It's worth noting that for many database queries, asking how many > hits there are can cost almost as much as actually retrieving them. That is the case with the App Engine datastore. If your counts contain more than a few hundred results then you would be better so store them somewhere. Cheers, Brian From bnrj.rudra at gmail.com Sat Jul 10 03:29:50 2010 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 10 Jul 2010 00:29:50 -0700 (PDT) Subject: load and plot from multiple file Message-ID: Dear friends, I have several 2 column file which i need to plot in one figure. I generally do it using gnuplot, but when there is several files, its hard to do manually. can you tell me how i can load a file in python and plot several file in one figure(as it is done via replot in gnuplot)? I am novice in python, but tried the matplotlib...with no luck. will u plz help? From usernet at ilthio.net Sat Jul 10 04:13:10 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 10 Jul 2010 08:13:10 +0000 (UTC) Subject: load and plot from multiple file References: Message-ID: On 2010-07-10, rudra wrote: > Dear friends, > I have several 2 column file which i need to plot in one figure. > I generally do it using gnuplot, but when there is several files, its > hard to do manually. > can you tell me how i can load a file in python and plot several file > in one figure(as it is done via replot in gnuplot)? > I am novice in python, but tried the matplotlib...with no luck. > will u plz help? It would really help to see a representative sample of the data that you are working with and what you want the plot to look like. Other then that, you likely just want to load the data from the file into lists (ordered together, lists with sublists, or potentially into a list ofrepresentative objects). You can then simply open a pipe to gnuplot and send it the commands it needs to create your plot. You could also just create a single comined file with all of the information to plot and then use it to create you plots. From animator333 at gmail.com Sat Jul 10 05:42:16 2010 From: animator333 at gmail.com (King) Date: Sat, 10 Jul 2010 02:42:16 -0700 (PDT) Subject: zipimport (.pyd & .so) files. References: <6fe67903-1944-4f4c-a158-1315c8278f44@h8g2000prn.googlegroups.com> Message-ID: <970bd811-f03b-4c20-9505-56c0942e5d06@b4g2000pra.googlegroups.com> I think I am trying to open a can of worms. It's better to leave the idea for now. Prashant From usenot at geekmail.INVALID Sat Jul 10 06:00:48 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 10 Jul 2010 12:00:48 +0200 Subject: Hello References: Message-ID: <20100710120048.39c9a613@geekmail.INVALID> On Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Grant Edwards wrote: > On 2010-07-09, Dani Valverde wrote: > > > I am new to python and pretty new to programming (I have some > > expertise wit R statistical programming language). I am just > > starting, so my questions may be a little bit stupid. Can anyone > > suggest a good editor for python? > > Emacs, Scite (has nice folding), Vim, Eclipse. > Great tips for a newbie. Not. Well, they might be, but chances are, they are overkill for people new to programming and will only alienate them (Scite may be an exception). Text editors are an acquired taste. /W -- INVALID? DE! From xcr4cx at googlemail.com Sat Jul 10 06:11:24 2010 From: xcr4cx at googlemail.com (christian schulze) Date: Sat, 10 Jul 2010 03:11:24 -0700 (PDT) Subject: Hello References: Message-ID: <003f9cf0-93d3-43d4-ac1c-832f9a51b5eb@b35g2000yqi.googlegroups.com> On 9 Jul., 18:31, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise > wit R statistical programming language). I am just starting, so my > questions may be a little bit stupid. Can anyone suggest a good editor > for python? > Cheers! > > Dani > Editors: Scribes, vim, gVim, Emacs, Gedit, Joe, Kate, Leafpad, Mousepad, Nano IDE's: Eric, Geany, ActiveState, Anjuta, Bluefish, Code::Blocks, CodeDragon/ wxStudio, WingIDE I suggest you to try around and find the editor/IDE that fits your needs. I use: Eric, Geany, Scribes, Emacs, Vim, gVim, Bluefish, (Gedit) (You should give Eric a try, its a rather good Python IDE) cheers From bnrj.rudra at gmail.com Sat Jul 10 06:31:07 2010 From: bnrj.rudra at gmail.com (rudra) Date: Sat, 10 Jul 2010 03:31:07 -0700 (PDT) Subject: load and plot from multiple file References: Message-ID: <37a13f23-0743-4305-b720-aacfbeff786e@a4g2000prm.googlegroups.com> On Jul 10, 1:13?pm, Tim Harig wrote: > It would really help to see a representative sample of the data that you > are working with and what you want the plot to look like. The data looks something like that: 0.70711 -2.57266 1.00000 0.16694 1.22474 -0.15287 1.41421 0.28025 1.58114 -0.03806 1.73205 0.05049 1.87083 -0.01686 2.00000 -0.02918 2.12132 0.00246 2.12132 0.13460 2.23607 -0.01552 2.34521 -0.00033 2.44949 0.00550 2.54951 -0.00827 2.54951 -0.01189 2.73861 0.00397 2.82843 0.04685 2.91548 -0.00115 2.91548 -0.00951 3.00000 0.00069 3.00000 0.00214 and there are several such file. I need two types of plotting: 1) multiple plot in same figure 2) grid of plots with different data in different grid From dani.valverde at gmail.com Sat Jul 10 06:49:35 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Sat, 10 Jul 2010 12:49:35 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: <4C38503F.6050309@gmail.com> geremy condra wrote: > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > >> Sorry, I forgot to mention that I am using Linux. In fact, my first test >> have been with gedit. Is there any way to directly run the Python code into >> the console? >> > > Gedit has a plugin that brings up a python intepreter. > Edit->Preferences->Plugins->python console I think. > > Geremy Condra > > I have this plugin enabled, but I don't know how to send the code to the console... Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From debatem1 at gmail.com Sat Jul 10 07:01:30 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 10 Jul 2010 07:01:30 -0400 Subject: Hello In-Reply-To: <4C38503F.6050309@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> Message-ID: On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde wrote: > geremy condra wrote: >> >> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >> wrote: >> >>> >>> Sorry, I forgot to mention that I am using Linux. In fact, my first test >>> have been with gedit. Is there any way to directly run the Python code >>> into >>> the console? >>> >> >> Gedit has a plugin that brings up a python intepreter. >> Edit->Preferences->Plugins->python console I think. >> >> Geremy Condra >> >> > > I have this plugin enabled, but I don't know how to send the code to the > console... type it in? Geremy Condra From dani.valverde at gmail.com Sat Jul 10 07:05:17 2010 From: dani.valverde at gmail.com (Dani Valverde) Date: Sat, 10 Jul 2010 13:05:17 +0200 Subject: Hello In-Reply-To: References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> Message-ID: <4C3853ED.9000806@gmail.com> geremy condra wrote: > On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde wrote: > >> geremy condra wrote: >> >>> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >>> wrote: >>> >>> >>>> Sorry, I forgot to mention that I am using Linux. In fact, my first test >>>> have been with gedit. Is there any way to directly run the Python code >>>> into >>>> the console? >>>> >>>> >>> Gedit has a plugin that brings up a python intepreter. >>> Edit->Preferences->Plugins->python console I think. >>> >>> Geremy Condra >>> >>> >>> >> I have this plugin enabled, but I don't know how to send the code to the >> console... >> > > type it in? > > Geremy Condra > > It could be a solution. But I am used to work with gEdit using the R statistical programming language plugin, and I am able to send the code to console instead of typing it in. Cheers! Dani -- Daniel Valverde Saub? c/Joan Maragall 37 4 2 17002 Girona Spain Tel?fon m?bil: +34651987662 e-mail: dani.valverde at gmail.com http://www.acrocephalus.net http://natupics.blogspot.com Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. GR?CIES! Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! -------------- next part -------------- A non-text attachment was scrubbed... Name: dani_valverde.vcf Type: text/x-vcard Size: 296 bytes Desc: not available URL: From donn.ingle at gmail.com Sat Jul 10 07:39:29 2010 From: donn.ingle at gmail.com (donn) Date: Sat, 10 Jul 2010 13:39:29 +0200 Subject: Hello [How to run your code] In-Reply-To: <4C3853ED.9000806@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> <4C3853ED.9000806@gmail.com> Message-ID: <4C385BF1.4010708@gmail.com> On 10/07/2010 13:05, Dani Valverde wrote: > It could be a solution. But I am used to work with gEdit using the R > statistical programming language plugin, and I am able to send the code > to console instead of typing it in. To run your code, save it to a file 'mycode.py' (or whatever), then open a console and cd into that directory, then: python mycode.py That will get you started. Keep the console open and alt-tab to it whenever you want to run your code. \d From flebber.crue at gmail.com Sat Jul 10 07:55:00 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 10 Jul 2010 04:55:00 -0700 (PDT) Subject: Hello References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> Message-ID: On Jul 10, 8:49?pm, Dani Valverde wrote: > geremy condra wrote: > > On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde wrote: > > >> Sorry, I forgot to mention that I am using Linux. In fact, my first test > >> have been with gedit. Is there any way to directly run the Python code into > >> the console? > > > Gedit has a plugin that brings up a python intepreter. > > Edit->Preferences->Plugins->python console I think. > > > Geremy Condra > > I have this plugin enabled, but I don't know how to send the code to the > console... > > Dani > > -- > Daniel Valverde Saub? > c/Joan Maragall 37 4 2 > 17002 Girona > Spain > Tel?fon m?bil: +34651987662 > e-mail: dani.valve... at gmail.comhttp://www.acrocephalus.nethttp://natupics.blogspot.com > > Si no ?s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar?s a estalviar aigua, energia i recursos forestals. ?GR?CIES! > > Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU! > > ?dani_valverde.vcf > < 1KViewDownload A few good options. Editor: Notepad++ IDE: Pyscripter - Clean clear design easy to use. Eclipse/Pydev Cheers Sayth From debatem1 at gmail.com Sat Jul 10 08:13:18 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 10 Jul 2010 08:13:18 -0400 Subject: Hello In-Reply-To: <4C3853ED.9000806@gmail.com> References: <4C374EE8.4060404@gmail.com> <4C375783.7090700@gmail.com> <4C38503F.6050309@gmail.com> <4C3853ED.9000806@gmail.com> Message-ID: On Sat, Jul 10, 2010 at 7:05 AM, Dani Valverde wrote: > geremy condra wrote: >> >> On Sat, Jul 10, 2010 at 6:49 AM, Dani Valverde >> wrote: >> >>> >>> geremy condra wrote: >>> >>>> >>>> On Fri, Jul 9, 2010 at 1:08 PM, Dani Valverde >>>> wrote: >>>> >>>> >>>>> >>>>> Sorry, I forgot to mention that I am using Linux. In fact, my first >>>>> test >>>>> have been with gedit. Is there any way to directly run the Python code >>>>> into >>>>> the console? >>>>> >>>>> >>>> >>>> Gedit has a plugin that brings up a python intepreter. >>>> Edit->Preferences->Plugins->python console I think. >>>> >>>> Geremy Condra >>>> >>>> >>>> >>> >>> I have this plugin enabled, but I don't know how to send the code to the >>> console... >>> >> >> type it in? >> >> Geremy Condra >> >> > > It could be a solution. But I am used to work with gEdit using the R > statistical programming language plugin, and I am able to send the code to > console instead of typing it in. Not sure how that works, but everything in gedit is accessible through python, so it should be a snap to put together a plugin to do what you want. Geremy Condra From prouleau001 at gmail.com Sat Jul 10 09:30:11 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 06:30:11 -0700 (PDT) Subject: Any reason www.python.org is slow? Message-ID: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> All, I have been finding python.org site very slow for the last year and probably before. Is there any known reason why the site is slow? I tried accessing it from several locations and I always get to wait several seconds for a page to load (in any browser/OS). Thanks -- Pierre From solipsis at pitrou.net Sat Jul 10 09:48:43 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 15:48:43 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <20100710154843.1a8919b1@pitrou.net> On Sat, 10 Jul 2010 06:30:11 -0700 (PDT) Pierre Rouleau wrote: > All, > > I have been finding python.org site very slow for the last year and > probably before. Is there any known reason why the site is slow? For the last year?? It's been mostly zippy here. Is IPv6 enabled on your computer? If so, I'd try to disable it. python.org domains resolve to both IPv4 and IPv6 addresses and, if your computer has IPv6 enabled but you don't have any IPv6 connectivity, this can result in slowdowns. Regards Antoine. From prouleau001 at gmail.com Sat Jul 10 09:59:59 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 06:59:59 -0700 (PDT) Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: On Jul 10, 9:48?am, Antoine Pitrou wrote: > On Sat, 10 Jul 2010 06:30:11 -0700 (PDT) > > > I have been finding python.org site very slow for the last year and > > probably before. Is there any known reason why the site is slow? > > For the last year?? > It's been mostly zippy here. > Is IPv6 enabled on your computer? If so, I'd try to disable it. > python.org domains resolve to both IPv4 and IPv6 addresses and, if your > computer has IPv6 enabled but you don't have any IPv6 connectivity, > this can result in slowdowns. > > Regards > > Antoine. Merci Antoine! I did disable IPv6 on my computer at home and it did speed it up. I'll check the other computers where I experienced the same slowness. Thanks again! -- Pierre From martin at v.loewis.de Sat Jul 10 10:03:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:03:24 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <4C387DAC.7020805@v.loewis.de> > For the last year?? > It's been mostly zippy here. > Is IPv6 enabled on your computer? If so, I'd try to disable it. > python.org domains resolve to both IPv4 and IPv6 addresses and, if your > computer has IPv6 enabled but you don't have any IPv6 connectivity, > this can result in slowdowns. That is a common myth. If your computer doesn't have any IPv6 connectivity, all is fine. The web browser will fallback to IPv4 immediately (*), without sending out any IPv6 datagrams first. If your computer does have IPv6 connectivity, but it's broken (i.e. you have a gateway, but eventually packets are discarded), you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in itself then would be fast. If your computer has IPv6 connectivity, but through low-bandwidth tunnels (which may happen with 6to4 tunnels, for example), then you'll get slow responses all the time. Regards, Martin (*) unless it's some older Opera version, in which case you would get no connection to python.org at all. From martin at v.loewis.de Sat Jul 10 10:04:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:04:50 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> Message-ID: <4C387E02.2030803@v.loewis.de> > I did disable IPv6 on my computer at home and it did speed it up. I'll > check the other computers where I experienced the same slowness. Of course, it would be interesting to find out what precisely went wrong. If you are curious to find out, let me know, and I'll help investigating. Regards, Martin From luke0104 at gmail.com Sat Jul 10 10:06:47 2010 From: luke0104 at gmail.com (pcchen) Date: Sat, 10 Jul 2010 07:06:47 -0700 (PDT) Subject: About new urllib.request in python 3.1.2 Message-ID: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> Sorry I have searched related topic but none could point out this problem. I am currently using python 3.1.2: >>>Python 3.1.2 (r312:79147, Jun 30 2010, 11:58:11) >>>[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 And for the following three simple lines of code, borrowed from official python-doc 3.1.2: >>>from urllib.request import urlopen >>>response = urlopen('http://python.org/') >>>html = response.read() They could cause this error: File "./http.py", line 3, in from urllib.request import urlopen File "/usr/local/lib/python3.1/urllib/request.py", line 88, in import http.client File "/home/pcchen/Python/http.py", line 3, in from urllib.request import urlopen ImportError: cannot import name urlopen All the related discussions point to urlopen has been moved from urllib to urllib.request, but none can discribe the above error. Any information is appreciated, thank you so much. From solipsis at pitrou.net Sat Jul 10 10:17:57 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 16:17:57 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> Message-ID: <20100710161757.78eaa6f1@pitrou.net> On Sat, 10 Jul 2010 16:03:24 +0200 "Martin v. Loewis" wrote: > > That is a common myth. If your computer doesn't have any IPv6 > connectivity, all is fine. The web browser will fallback to IPv4 > immediately (*), without sending out any IPv6 datagrams first. Ok, I suppose the explanation wasn't factually exact. > If your computer does have IPv6 connectivity, but it's broken > (i.e. you have a gateway, but eventually packets are discarded), > you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in > itself then would be fast. I think it's what most users experience when they are talking about this problem. It manifests itself on many Linux setups. Regards Antoine. From martin at v.loewis.de Sat Jul 10 10:28:19 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 10 Jul 2010 16:28:19 +0200 Subject: Any reason www.python.org is slow? In-Reply-To: References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> Message-ID: <4C388383.1050904@v.loewis.de> >> If your computer does have IPv6 connectivity, but it's broken >> (i.e. you have a gateway, but eventually packets are discarded), >> you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in >> itself then would be fast. > > I think it's what most users experience when they are talking about > this problem. It manifests itself on many Linux setups. This (*) is something I really cannot believe. What specifically happened on these Linux setups? What specific network use these people, and why do they get bad IPv6 connectivity? Regards, Martin (*) that there are many From solipsis at pitrou.net Sat Jul 10 10:47:09 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 10 Jul 2010 16:47:09 +0200 Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> <4C388383.1050904@v.loewis.de> Message-ID: <20100710164709.1d217c2a@pitrou.net> On Sat, 10 Jul 2010 16:28:19 +0200 "Martin v. Loewis" wrote: > >> If your computer does have IPv6 connectivity, but it's broken > >> (i.e. you have a gateway, but eventually packets are discarded), > >> you see the IPv4 fallback after the IPv6 timeout. The IPv4 connection in > >> itself then would be fast. > > > > I think it's what most users experience when they are talking about > > this problem. It manifests itself on many Linux setups. > > This (*) is something I really cannot believe. > (*) that there are many Well, just take a look at the number of recipes for disabling IPv6 specifically in order to solve slowdown problems: http://www.google.com/search?hl=fr&safe=off&q=linux+ipv6+disable+slowdowns&aq=f&aqi=&aql=&oq=&gs_rfai= It is at least the third time that someone asks why python.org is "slow", and that their problem is "solved" by disabling IPv6. I disabled IPv6 myself, which solved similar slowdown issues. The issues happened on *.python.org, *.google.com and a couple of other domains; hence they weren't python.org-specific. The issues happened with a Web browser but also with ssh; hence they were neither application- nor protocol-specific. The issues happened on two different machines, one hooked to a DSL router, another with wireless connection to various outside networks. Hence the issue is probably not tied to a particular hardware gateway. I was quite surprised myself when I discovered that "solution". But it really suppressed the frequent lag I had in some connection attempts (including ssh connection to a rather close, mostly idle box). It is possible that the way Linux (or some Linux setups: many of the recipes above are for Ubuntu, I use Mandriva myself) handles IPv6 "connectivity" is suboptimal in some cases, and that connection attempts don't fail immediately when they should. I don't have enough knowledge to diagnose further. Regards Antoine. From eliben at gmail.com Sat Jul 10 11:02:45 2010 From: eliben at gmail.com (Eli Bendersky) Date: Sat, 10 Jul 2010 18:02:45 +0300 Subject: Hello In-Reply-To: <4C374EE8.4060404@gmail.com> References: <4C374EE8.4060404@gmail.com> Message-ID: On Fri, Jul 9, 2010 at 19:31, Dani Valverde wrote: > Hello! > I am new to python and pretty new to programming (I have some expertise wit > R statistical programming language). I am just starting, so my questions may > be a little bit stupid. Can anyone suggest a good editor for python? > Cheers! > Hi Dani, Don't be shy to ask beginner questions. However, you will do well to first read a few FAQs. Start here: http://www.python.org/doc/faq/ Part of it is also available in spanish, for your convenience: http://www.python.org/doc/faq/es/general/ The Python wiki (http://wiki.python.org/moin/FrontPage) is also useful. For example, it has a rather comprehensive page about editors: http://wiki.python.org/moin/PythonEditors Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Jul 10 11:35:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Jul 2010 15:35:06 GMT Subject: About new urllib.request in python 3.1.2 References: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> Message-ID: <4c389329$0$28647$c3e8da3@news.astraweb.com> On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote: > And for the following three simple lines of code, borrowed from official > python-doc 3.1.2: > >>>>from urllib.request import urlopen >>>>response = urlopen('http://python.org/') html = response.read() > > They could cause this error: > > File "./http.py", line 3, in > from urllib.request import urlopen > File "/usr/local/lib/python3.1/urllib/request.py", line 88, in > > import http.client > File "/home/pcchen/Python/http.py", line 3, in > from urllib.request import urlopen > ImportError: cannot import name urlopen Look at the traceback: your code executes "from urllib.request import urlopen". That line in turn executes "import http.client". And *that* fails, which causes the first import to fail. It fails because you have shadowed the built-in package http with your own module http.py. Rename your file to something else ("myhttp.py") and it should just work. -- Steven From pavan_maddali at yahoo.com Sat Jul 10 12:11:14 2010 From: pavan_maddali at yahoo.com (pavan kumar maddali) Date: Sat, 10 Jul 2010 09:11:14 -0700 (PDT) Subject: About new urllib.request in python 3.1.2 In-Reply-To: <4c389329$0$28647$c3e8da3@news.astraweb.com> References: <96a39ca9-40ad-4005-b2a9-14d1bff173de@x2g2000prk.googlegroups.com> <4c389329$0$28647$c3e8da3@news.astraweb.com> Message-ID: <810244.99491.qm@web39701.mail.mud.yahoo.com> Thank You Steve, I am not using the urllib. I am using the xmlrpc and http modules from the python library. Please see the header code for the modules I am including.. from xmlrpc import client import pprint class ClientCertTransport(client.Transport): ?def make_connection(self,host): ??import http ??host, extra_headers,x509 = self.get_host_info(host) ?? ??try: ???HTTPS = http.HTTPS ??except AttributeError: ???raise NotImplementedError("your version of http does not support HTTPS") ??else: ???return HTTPS(host,None,'privkey.pem','resellercert.pem') the rest of the code is just to get the result from the api.... regards Pavan ________________________________ From: Steven D'Aprano To: python-list at python.org Sent: Sat, July 10, 2010 11:35:06 AM Subject: Re: About new urllib.request in python 3.1.2 On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote: > And for the following three simple lines of code, borrowed from official > python-doc 3.1.2: > >>>>from urllib.request import urlopen >>>>response = urlopen('http://python.org/') html = response.read() > > They could cause this error: > >? File "./http.py", line 3, in >? ? from urllib.request import urlopen >? File "/usr/local/lib/python3.1/urllib/request.py", line 88, in > >? ? import http.client >? File "/home/pcchen/Python/http.py", line 3, in >? ? from urllib.request import urlopen > ImportError: cannot import name urlopen Look at the traceback: your code executes "from urllib.request import urlopen". That line in turn executes "import http.client". And *that* fails, which causes the first import to fail. It fails because you have shadowed the built-in package http with your own module http://http.py. Rename your file to something else ("myhttp.py") and it should just work. -- Steven -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdesth.quelquechose at free.quelquepart.fr Sat Jul 10 12:23:22 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 10 Jul 2010 18:23:22 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c38b9fe$0$12484$426a74cc@news.free.fr> Les Schaffer a ?crit : > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. (snip) > but none of this has anything to do with Python itself. i am sure python > servers have been running reliably for long periods of time, but i've > never had to deal with a two-month guarantee before. is there something > else i am missing here that i should be concerned about on the > pure-Python side of things? something under the hood of the python > interpreter that could be problematic when run for a long time? Zope is (rightly) considered as a memory/resources hog, and I have a Zope instance hosting two apps on a cheap dedicated server that has not been restarted for the past 2 or 3 years. So as long as your code is clean you should not have much problem with the Python runtime itself, at least on a a linux box. Can't tell how it would work on Windows. From gervaz at gmail.com Sat Jul 10 12:24:23 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 16:24:23 GMT Subject: Web page special characters encoding Message-ID: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Hi all, I'm using py3k and the urllib package to download web pages. Can you suggest me a package that can translate reserved characters in html like "è", "ò", "é" in the corresponding correct encoding? Thanks, Mattia From bdesth.quelquechose at free.quelquepart.fr Sat Jul 10 12:37:00 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 10 Jul 2010 18:37:00 +0200 Subject: Only one forum app in Python? In-Reply-To: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> Message-ID: <4c38bd30$0$2776$426a74cc@news.free.fr> Gilles Ganault a ?crit : > Hello > > I'd like to write a small web app in Python which must include a > forum. > > So I checked the relevant article in Wikipedia, which says that only > one forum app is available for Python: > > http://en.wikipedia.org/wiki/Comparison_of_internet_forum_software_(other) > > Is Pocoo really the only solution available out there? There are almost a dozen of Python "forum apps" for Django alone, and Python is known as "the language with more web frameworks than keywords". From asim.ssat at gmail.com Sat Jul 10 12:51:28 2010 From: asim.ssat at gmail.com (asim malik) Date: Sat, 10 Jul 2010 09:51:28 -0700 (PDT) Subject: Indian photographer denies affair with Lindsay Lohan! Message-ID: Speaking on the issue for the first time, Chaudhuri, over the phone from New York, says, "They were completely distorted reports. We are really good friends for more details www.bollywood789.blogspot.com From rami.chowdhury at gmail.com Sat Jul 10 13:07:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 10 Jul 2010 10:07:33 -0700 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <01EF6E9B-AFB9-477C-BF01-871E1FA83280@gmail.com> On Jul 10, 2010, at 09:24 , mattia wrote: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? It won't do the whole job for you but you may find the 'name2codepoint' mapping in the 'html.entities' module useful. HTH, Rami From python at mrabarnett.plus.com Sat Jul 10 13:09:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jul 2010 18:09:12 +0100 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4C38A938.7070207@mrabarnett.plus.com> mattia wrote: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? > import re from html.entities import entitydefs # The downloaded web page will be bytes, so decode it to a string. webpage = downloaded_page.decode("iso-8859-1") # Then decode the HTML entities. webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) From alf.p.steinbach+usenet at gmail.com Sat Jul 10 13:38:03 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 10 Jul 2010 19:38:03 +0200 Subject: Not-quite-the-module-name qualified names in extension modules? What? Message-ID: Hi. I built the [xxmodule.c] from the source distribution, as suggested by the Python 3.1.1 docs. I named this [xx.pyd], as I believed the module name was just "xx". Indeed importing xx works fine, but when I do help(xx) I get ... >>> help( xx ) Help on module xx: NAME xx - This is a template module just for instruction. FILE c:\projects\progrock\lib\progrock\cppy_dev\examples\02_xx_apilevel\xx.pyd CLASSES builtins.Exception(builtins.BaseException) error builtins.object xxmodule.Null builtins.str(builtins.object) xxmodule.Str class Null(builtins.object) | Methods defined here: | ... with the name "xxmodule" somehow in there as qualification. Checking the standard "csv" module I similarly get ... CLASSES builtins.Exception(builtins.BaseException) _csv.Error builtins.object Dialect excel excel_tab DictReader DictWriter Sniffer ... with the name "_csv" in there. And I'm pretty sure that these not-quite-the-module-name names stem from the literal specification of names in the C code in the extension module, assuming that the csv module is indeed a C extension module. Is it really necessary to qualify names in the C code? And can it do harm when such name qualification is not using the final module name but instead something like "xxmodule" or "_csv"? More to the point, what's the point? Cheers, - Alf -- blog at From news1234 at free.fr Sat Jul 10 14:22:21 2010 From: news1234 at free.fr (News123) Date: Sat, 10 Jul 2010 20:22:21 +0200 Subject: MySqlDb any way to see the query string Message-ID: <4c38ba5d$0$10393$426a74cc@news.free.fr> Hi, I'm using MYSQLdb and have following code db = MySQLdb.connect(**cfg) c = db.cursor() qrystr = "insert mytable set id = %s , other_field = %s" c.execute(qrystr, (id_val,other_field_val) ) What I wondered is whether there is any way to print the 'filled in' query string for debuggin. The reason I'm askng is, that I'd like to copy paste the 'filled in' query string and try it from the command line. I know I could create it myself, but I had to do all the esaping myself. Thanks for suggestions N From gelonida at gmail.com Sat Jul 10 14:42:40 2010 From: gelonida at gmail.com (Gelonida) Date: Sat, 10 Jul 2010 20:42:40 +0200 Subject: simples setup for an wsgi https server in python Message-ID: Hi, I'd like to debug a small wsgi module. I run it either on an apache web server or locally via wsgiref.simple_server.make_server and following code snippet: from wsgiref.simple_server import make_server httpd = make_server('localhost',8012,application) while True: httpd.handle_request() print_some_debug_info() It seems, that wsgiref.simple_server.make_server can only create an http server. What I wondered would be how to easiest create an https server, that supports wsgi modules TIA From nagle at animats.com Sat Jul 10 14:54:46 2010 From: nagle at animats.com (John Nagle) Date: Sat, 10 Jul 2010 11:54:46 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3774df$0$31278$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c38c1fa$0$1616$742ec2ed@news.sonic.net> On 7/9/2010 12:13 PM, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking > to know what i don't know. > > The app would read instrument data from a serial port, If the device you're listening to is read-only, and you're just listening, make a cable to feed the serial data into two machines, and have them both log it. Put them on separate UPSs and in a place where nobody can knock them over or mess with them. John Nagle From alf.p.steinbach+usenet at gmail.com Sat Jul 10 15:07:12 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 10 Jul 2010 21:07:12 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c38c1fa$0$1616$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c38c1fa$0$1616$742ec2ed@news.sonic.net> Message-ID: * John Nagle, on 10.07.2010 20:54: > On 7/9/2010 12:13 PM, Les Schaffer wrote: >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking >> to know what i don't know. >> >> The app would read instrument data from a serial port, > > If the device you're listening to is read-only, and you're just > listening, make a cable to feed the serial data into two machines, > and have them both log it. Put them on separate UPSs and in > a place where nobody can knock them over or mess with them. "The Ramans do everything in triplicate" - Old jungle proverb Cheers, - Alf -- blog at From exarkun at twistedmatrix.com Sat Jul 10 15:21:43 2010 From: exarkun at twistedmatrix.com (Jean-Paul Calderone) Date: Sat, 10 Jul 2010 12:21:43 -0700 (PDT) Subject: simples setup for an wsgi https server in python References: Message-ID: On Jul 10, 2:42?pm, Gelonida wrote: > Hi, > > I'd like to debug a small wsgi module. > > I run it either on an apache web server > > or locally via wsgiref.simple_server.make_server > and following code snippet: > > from wsgiref.simple_server import make_server > httpd = make_server('localhost',8012,application) > while True: > ? ?httpd.handle_request() > ? ?print_some_debug_info() > > It seems, that wsgiref.simple_server.make_server can only create an http > server. > > What I wondered would be how to easiest create an https server, that > supports wsgi modules > > TIA You could do this with Twisted: twistd -n web --https 443 --certificate server.pem --privkey server.key --wsgi your.application Jean-Paul From timr at probo.com Sat Jul 10 15:41:02 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 12:41:02 -0700 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> <1v9d36d3s1mr9a91vvgo0jfdboabc1uflr@4ax.com> Message-ID: <04jh36hf5s66pepkf8a711qd7n5c55j5ob@4ax.com> Dave Angel wrote: >Tim Roberts wrote: >> >> No. The multi-thread-aware CRT in Visual C++ (which is the only option >> since VS2008) puts errno in thread-local storage, so it's shared by all >> CRTs. >> >I didn't know specifically that errno is in TLS, but I will disagree >with the conclusion that a TLS entry is implicitly shared by all CRT's. >Unless the CRT for each DLL explicitly does some extra work to allow >sharing, each will have its own set of TLS variables. Yes, I should have thought about this before posting. I checked the CRT source code, and you are correct. Every DLL that calls the C run-time startup code will do its own TlsAlloc. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sat Jul 10 16:03:15 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 10 Jul 2010 21:03:15 +0100 Subject: MySqlDb any way to see the query string In-Reply-To: References: <4c38ba5d$0$10393$426a74cc@news.free.fr> Message-ID: <4C38D203.8030507@mrabarnett.plus.com> Dennis Lee Bieber wrote: > On Sat, 10 Jul 2010 20:22:21 +0200, News123 declaimed > the following in gmane.comp.python.general: > >> Hi, >> >> I'm using MYSQLdb > >> What I wondered is whether there is any way to print the 'filled in' >> query string for debuggin. >> > Just edit the MySQLdb cursors module -- it's plain Python unless > something has changed in the last year... Find the .execute() method, > and stuff in a debug print statement where it does the escaping and > "fill in" (reason MySQLdb uses %s placeholder is that it uses Python to > do the fill in; things may change if the module is ever updated to use > ver 5 prepared queries). > > Come to think of it, one could probably duplicate the .execute() > method, creating a "d_execute" with the print statement, while not > affecting operational code... That way one wouldn't have to edit the > module just for testing. > Why duplicate the method? Why not add a keyword argument to turn on printing or a provide a file-type instance to which it should log the query? From ndbecker2 at gmail.com Sat Jul 10 16:08:26 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 10 Jul 2010 16:08:26 -0400 Subject: Sumatra m/l? Message-ID: Sumatra looks like an interesting project http://pypi.python.org/pypi/Sumatra/0.2 But I have some questions. Is there any mail list or forum? I can't find anything on the website. From aahz at pythoncraft.com Sat Jul 10 16:48:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Jul 2010 13:48:09 -0700 Subject: Sumatra m/l? References: Message-ID: In article , Neal Becker wrote: > >Sumatra looks like an interesting project >http://pypi.python.org/pypi/Sumatra/0.2 And how are we supposed to know that it's interesting? You should provide a summary. Also, it's pretty rude to set followups to gmane.comp.python.general -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From gervaz at gmail.com Sat Jul 10 17:03:41 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 21:03:41 GMT Subject: Web page special characters encoding References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> Il Sat, 10 Jul 2010 18:09:12 +0100, MRAB ha scritto: > mattia wrote: >> Hi all, I'm using py3k and the urllib package to download web pages. >> Can you suggest me a package that can translate reserved characters in >> html like "è", "ò", "é" in the corresponding >> correct encoding? >> > import re > from html.entities import entitydefs > > # The downloaded web page will be bytes, so decode it to a string. > webpage = downloaded_page.decode("iso-8859-1") > > # Then decode the HTML entities. > webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) Thanks, very useful, didn't know about the entitydefs dictionary. From lists at cheimes.de Sat Jul 10 17:15:25 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Jul 2010 23:15:25 +0200 Subject: Web page special characters encoding In-Reply-To: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? I think the html parser of LXML can convert the entities, too. Christian From nagle at animats.com Sat Jul 10 17:48:49 2010 From: nagle at animats.com (John Nagle) Date: Sat, 10 Jul 2010 14:48:49 -0700 Subject: Web page special characters encoding In-Reply-To: <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> <4c38e02d$0$40279$4fafbaef@reader2.news.tin.it> Message-ID: <4c38eac5$0$1631$742ec2ed@news.sonic.net> On 7/10/2010 2:03 PM, mattia wrote: > Il Sat, 10 Jul 2010 18:09:12 +0100, MRAB ha scritto: > >> mattia wrote: >>> Hi all, I'm using py3k and the urllib package to download web pages. >>> Can you suggest me a package that can translate reserved characters in >>> html like "è", "ò", "é" in the corresponding >>> correct encoding? >>> >> import re >> from html.entities import entitydefs >> >> # The downloaded web page will be bytes, so decode it to a string. >> webpage = downloaded_page.decode("iso-8859-1") >> >> # Then decode the HTML entities. >> webpage = re.sub(r"&(\w+);", lambda m: entitydefs[m.group(1)], webpage) > > Thanks, very useful, didn't know about the entitydefs dictionary. You also need to decode the HTML numerical escapes. Expect that in real-world HTML, out of range values will occasionally appear. John Nagle From solipsis at pitrou.net Sat Jul 10 18:25:35 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 11 Jul 2010 00:25:35 +0200 Subject: Sumatra m/l? References: Message-ID: <20100711002535.223aee77@pitrou.net> On 10 Jul 2010 13:48:09 -0700 aahz at pythoncraft.com (Aahz) wrote: > > Also, it's pretty rude to set followups to gmane.comp.python.general Can you expand? From cs at zip.com.au Sat Jul 10 18:33:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 11 Jul 2010 08:33:43 +1000 Subject: About new urllib.request in python 3.1.2 In-Reply-To: <810244.99491.qm@web39701.mail.mud.yahoo.com> References: <810244.99491.qm@web39701.mail.mud.yahoo.com> Message-ID: <20100710223343.GA1616@cskk.homeip.net> On 10Jul2010 09:11, pavan kumar maddali wrote: | Thank You Steve, | I am not using the urllib. Your example did: from urllib.request import urlopen response = urlopen('http://python.org/') html = response.read() | I am using the xmlrpc and http modules from the | python library. [...] That's not what he meant. Your file is called "http.py". Python searches the current directory first. That means that when any library module (internally) tried to use the "http" module it will find your file, not the library module. So you don't get to use the http library module. Rename your http.py file to "my-http-test.py" and retry. Then its name won't get in the way of the library name. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Success in software development depends on making a carefully planned series of small mistakes in order to avoid making unplanned large mistakes. - Steve McConnell, _Software Project Survival Guide_ From prouleau001 at gmail.com Sat Jul 10 18:39:25 2010 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Sat, 10 Jul 2010 15:39:25 -0700 (PDT) Subject: Any reason www.python.org is slow? References: <6ca4bf2d-03cc-43d0-83de-c16c5e7389e8@d37g2000yqm.googlegroups.com> <4C387DAC.7020805@v.loewis.de> <4C388383.1050904@v.loewis.de> Message-ID: <2b7da6c9-2f8f-4576-91e9-ee9232e57a13@y4g2000yqy.googlegroups.com> > > It is possible that the way Linux (or some Linux setups: many of the > recipes above are for Ubuntu, I use Mandriva myself) handles IPv6 > "connectivity" is suboptimal in some cases, and that connection > attempts don't fail immediately when they should. I don't have enough > knowledge to diagnose further. > > Note that I am not using Linux. I had the problem on OS/X 10.4. I did another experiment. I have VMWare Fusion on that computer and have Linux Ubuntu 9.04 in one VMWare appliance. I activated IPv6 on the OS/X Preference for the interface I am using. Access to www.python.org went slow for Firefox and Safari running directly under OS/X. However, access for Firefox running inside VMWare-based Linux Ubuntu 9.04 was fine! I tried pages from Ubuntu first, got them right away, then tried the same page under OS/X and was waiting for over 10 seconds. Regards - Pierre From gervaz at gmail.com Sat Jul 10 19:17:03 2010 From: gervaz at gmail.com (mattia) Date: 10 Jul 2010 23:17:03 GMT Subject: Web page special characters encoding References: <4c389eb7$0$40288$4fafbaef@reader2.news.tin.it> Message-ID: <4c38ff6e$0$18657$4fafbaef@reader3.news.tin.it> Il Sat, 10 Jul 2010 16:24:23 +0000, mattia ha scritto: > Hi all, I'm using py3k and the urllib package to download web pages. Can > you suggest me a package that can translate reserved characters in html > like "è", "ò", "é" in the corresponding correct > encoding? > > Thanks, > Mattia Basically I'm trying to get an html page and stripping out all the tags to obtain just plain text. John Nagle and Christian Heimes somehow figured out what I'm trying to do ;-) So far what I've done, thanks to you suggestions: import lxml.html import lxml.html.clean import urllib.request import urllib.parse from html.entities import entitydefs import re import sys HEADERS = {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"} def replace(m): if m.group(1) in entitydefs: return entitydefs[m.group(1)] else: return m.group(1) def test(page): req = urllib.request.Request(page, None, HEADERS) page = urllib.request.urlopen(req) charset = page.info().get_content_charset() if charset is not None: html = page.read().decode(charset) else: html = page.read().decode("iso-8859-1") html = re.sub(r"&(\w+);", replace, html) cleaner = lxml.html.clean.Cleaner(safe_attrs_only = True, style = True) html = cleaner.clean_html(html) # create the element tree tree = lxml.html.document_fromstring(html) txt = tree.text_content() for x in txt.split(): # DOS shell is not able to print characters like u'\u20ac' - why??? try: print(x) except: continue if __name__ == "__main__": if len(sys.argv) < 2: print("Usage:", sys.argv[0], "") print("Example:", sys.argv[0], "http://www.bing.com") sys.exit() test(sys.argv[1]) Every new tips will be appreciated. Ciao, Mattia From timr at probo.com Sat Jul 10 19:24:59 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 16:24:59 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: Message-ID: <570i36ltptk14js0prc79he2342rgt6ffv@4ax.com> Frederic Rentsch wrote: > >I develop in an IDLE window. > >Module M says 'from service import *'. >Next I correct a mistake in function 'service.f'. >Now 'service.f' works fine. > >I do 'reload (service); reload (M)'. >The function 'M.f' still misbehaves. > >'print inspect.getsource (service.f)' and >'print inspect.getsource (M.f)' shows the same >corrected code. > >'print service.f' and 'print M.f' show different ids. Yes. This: from service import xxx is essentially the same as: import service xxx = service.xxx At that point, xxx contains a reference to the "service.xxx" object as it is right now. When you do a reload, that imports a new version of "service.xxx", but your global "xxx" object is still bound to the old one. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Jul 10 19:29:07 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 10 Jul 2010 16:29:07 -0700 Subject: MySqlDb any way to see the query string References: <4c38ba5d$0$10393$426a74cc@news.free.fr> Message-ID: <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> News123 wrote: > >I'm using MYSQLdb > >and have following code > >db = MySQLdb.connect(**cfg) >c = db.cursor() >qrystr = "insert mytable set id = %s , other_field = %s" >c.execute(qrystr, (id_val,other_field_val) ) > >What I wondered is whether there is any way to print the 'filled in' >query string for debuggin. > >The reason I'm askng is, that I'd like to copy paste the 'filled in' >query string and try it from the command line. You have the source code in front of you. After you do the execute, the actual query string that was transmitted is available in "c._executed". If you need to know the result before you submit it, you can scan the source for the "execute" method and see how they do the quoting. It's not that complicated. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From news1234 at free.fr Sat Jul 10 20:07:42 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 02:07:42 +0200 Subject: MySqlDb any way to see the query string In-Reply-To: <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> References: <4c38ba5d$0$10393$426a74cc@news.free.fr> <8d0i369qc3584832nmvb7q398r5a0917bl@4ax.com> Message-ID: <4C390B4E.80003@free.fr> Hi everybody, im Roberts wrote: > News123 wrote: >> I'm using MYSQLdb >> >> and have following code >> >> db = MySQLdb.connect(**cfg) >> c = db.cursor() >> qrystr = "insert mytable set id = %s , other_field = %s" >> c.execute(qrystr, (id_val,other_field_val) ) >> >> What I wondered is whether there is any way to print the 'filled in' >> query string for debuggin. >> >> The reason I'm askng is, that I'd like to copy paste the 'filled in' >> query string and try it from the command line. > > You have the source code in front of you. After you do the execute, the > actual query string that was transmitted is available in "c._executed". > > If you need to know the result before you submit it, you can scan the > source for the "execute" method and see how they do the quoting. It's not > that complicated. Thanks for all of your answers. In my case c._executed is absolutely sufficient. From ritchy_gato at hotmail.com Sat Jul 10 20:12:23 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Sat, 10 Jul 2010 17:12:23 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> Message-ID: <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> On 7 jul, 08:38, Johan Gr?nqvist wrote: > 2010-07-06 19:18, Ritchy lelis skrev: > > > On 6 jul, 17:29, Alan G Isaac ?wrote: > >> Unfortunately I cannot make sense of the code you posted. > >> Provide a detailed description in words (or psuedocode) > >> of what you are trying to accomplish. ?Be very careful > >> and detailed is you want a useful response. > > >> Alan Isaac > > > hummm... > > > ok, i will try to make that detailed description. > > I can tell you why I do not understand from your posted code what you > are trying to do. > > Firstly, I do not understand if you are trying to plot a surface, a set > of curves, or a curve, or just a set of points? In your posted code, the > plot command is part of the else clause, and my guess is that you never > intend the else-clause to be executed at all. > > In your code snippet you loop over two arrays (Vi and Vref), compute a > scalar value V0, and all plot-commands you issue are of the form > plot(V0). This will probably draw a line of one point (for each value in > Vi and Vref), which may not be what you want, and if it draws anything > at all, then all points will be drawn at the same x-value, which is also > probably not what you want. > > Secondly, how are the Vi and Vref related to your axes? I assume you > want to plot all values you compute for V0, but as a function of what? > When I use the plot command, I usually give it (at least) two arguments, > where the first is the x-axis, and the second is the y-axis. > > After I have understood those things, the next question would be about > the maths relating the Vi and Vref values to the V0 values, but I do not > think I will understand those until after the above points are explained > clearer. > > I definitely think your english is not a problem here. > > Johan hi Johan Thanks for the interest in my problem... really appreciate. About the plot draw it's a curve that it's a set of points wich it's the result of the comput of the Vref and Vi together. I don't know if i had to make a break instruction (like in other's languages) after the "If" instructions if i want the else-condition to be executed? ... (do you have some sujestions?) Anyway i have a picture of a tuturial that i found but in this forum i can't post it. That pic would show what a really want... Relatively to the axis, the Vi takes the x-axis and the Vref takes the y-axis. As i said, i have a good 2 pic of a doc that has the information about this ADC that i'm developing. I would appreciate more of your help, if you permit me i could send you those 2 pic and i guarantee that you would got the certain vision of the problem. I'll be waiting for your answer, i thing that you can help me. Cheers. Ritchy Lelis From sturlamolden at yahoo.no Sat Jul 10 20:48:57 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 10 Jul 2010 17:48:57 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <9da45f74-d042-4405-a8c5-1cbac5baada4@r27g2000yqb.googlegroups.com> On 10 Jul, 02:23, Tim Chase wrote: > While I'm not sure how much of Roy's comment was "hah, hah, just > serious", this has been my biggest issue with long-running Python > processes on Win32 -- either power outages the UPS can't handle, > or (more frequently) the updates Win32 is also the only OS in common use known to fragment memory enough to make long-running processes crash or hang (including system services), and require reboots on regular basis. Algorithms haven't changed, but it takes a bit "longer" for the heap to go fubar with Win64. (That is, "longer" as in "you're dead long before it happens".) For processes that needs to run that long, I would really recommend using Win64 and Python compiled for amd64. From sturlamolden at yahoo.no Sat Jul 10 20:55:53 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 10 Jul 2010 17:55:53 -0700 (PDT) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <4C33580C.9030609@jollans.com> <5ad412ec-21d0-428a-9315-a8311223c05c@y11g2000yqm.googlegroups.com> Message-ID: <65382aab-9d99-4687-a607-5bdb282a06ff@i28g2000yqa.googlegroups.com> On 9 Jul, 02:02, Neil Hodgson wrote: > ? ?If you break the rules by using malloc rather than IMalloc for memory > that is deallocated by a different component to that which allocated it > or try to pass around FILE* objects then you will see failures. Yes, the CRT issue applies to COM as well. COM developers are even less aware of this than Python developers. > So, > always follow the COM rules. Or just avoid COM... From aahz at pythoncraft.com Sat Jul 10 21:54:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 10 Jul 2010 18:54:01 -0700 Subject: Sumatra m/l? References: Message-ID: In article , Antoine Pitrou wrote: >On 10 Jul 2010 13:48:09 -0700 >aahz at pythoncraft.com (Aahz) wrote: >> >> Also, it's pretty rude to set followups to gmane.comp.python.general > >Can you expand? If you look at the original post's headers, you'll see Followup-To: gmane.comp.python.general which does not exist on my news server. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From drsalists at gmail.com Sat Jul 10 22:02:25 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 10 Jul 2010 19:02:25 -0700 Subject: Issues compiling 2.6.5 on AIX 6.1 In-Reply-To: <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> References: <40FB2AE5907F9743A593A85015F157BF02F935AE@ARG-EXVS03.corp.argushealth.com> <4C3711B1.1070006@jollans.com> <40FB2AE5907F9743A593A85015F157BF02F935BA@ARG-EXVS03.corp.argushealth.com> Message-ID: On Fri, Jul 9, 2010 at 5:54 AM, Stopp, Bryan wrote: > I checked, none of the files are symlinks. The install process never got > to the point where it created sym-links for libraries (if it even does, > I haven't gotten to that point in the install process.) > > -B > > -----Original Message----- > From: python-list-bounces+cbds=argushealth.com at python.org > [mailto:python-list-bounces+cbds = > argushealth.com at python.org] On Behalf > Of Thomas Jollans > Sent: Friday, July 09, 2010 7:10 AM > To: python-list at python.org > Subject: Re: Issues compiling 2.6.5 on AIX 6.1 > > On 07/08/2010 04:36 PM, Stopp, Bryan wrote: > > building '_struct' extension > > > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > > -I/build/tools/src/Python-2.6.5/Include > -I/build/tools/src/Python-2.6.5 > > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > > build/lib.aix-6.1-2.6/_struct.so > > > > collect2: library libpython2.6 not found > > What really stumps me (and you too, I expect) about this is the two > different error messages. Above, it looks like collect2 simply doesn't > find a -lpython2.6 anywhere. Adding . to LIBPATH does make sense. > > > building '_struct' extension > > > > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall > > -Wstrict-prototypes -I. -I/build/tools/src/Python-2.6.5/./Include > > -I/build/tools/include -I. -IInclude -I./Include -I/usr/local/include > > -I/build/tools/src/Python-2.6.5/Include > -I/build/tools/src/Python-2.6.5 > > -c /build/tools/src/Python-2.6.5/Modules/_struct.c -o > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > > > ./Modules/ld_so_aix gcc -pthread -bI:Modules/python.exp > > build/temp.aix-6.1-2.6/build/tools/src/Python-2.6.5/Modules/_struct.o > > -L/build/tools/lib -L/usr/local/lib -lpython2.6 -o > > build/lib.aix-6.1-2.6/_struct.so > > > > ld: 0706-006 Cannot find or open library file: -l python2.6 > > > > ld:open(): No such file or directory > > > > collect2: ld returned 255 exit status > > But what on earth is this? It looks like collect2 found the library, and > told it's mate ld, which can't open it. collect2 thinks it find a file, > ld hits "No such file or directory" on the same file. > > Maybe it's a dead symlink? Looking for a file with the right name and > location would find it, while opening it would hit a dead end, and > probably return "No such file " > > It's been a while since I've used AIX, but is it possible you're mixing 32 bit and 64 bit operations? AIX shared libraries: 1) Are closer to windows dll's than *ix .so's - unsurprising given that Windows shares a heritage with OS/2, and both OS/2 and AIX are from IBM. 2) A .a can hold both 32 bit and 64 bit objects. 3) If you have a .a with 32 objects in it, and try to link against it in 64 bit mode, the file is sort of there and sort of not - ls will see it, but the linker will not. 4) 32 bit libraries suffer from a "loader domain" issue - the first part of $LIBPATH optionally specifies a loader domain, which is a namespace into which shared libraries are loaded 5) 64 bit libraries are supposed to be cleaner than 32 bit 6) Make sure that if you're building for 64 bit (for example) that ld is doing the same when it's called from collect2 or whatever. 7) You can test what kind of shared library you're looking at (and sometimes .a's are _shared_ on AIX - yes, it's weird, yes, it's true) with ar -X - see the man page for more. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dg.gmane at thesamovar.net Sat Jul 10 23:36:26 2010 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Sun, 11 Jul 2010 05:36:26 +0200 Subject: Sumatra m/l? In-Reply-To: References: Message-ID: On 10/07/2010 22:08, Neal Becker wrote: > Sumatra looks like an interesting project > http://pypi.python.org/pypi/Sumatra/0.2 > > But I have some questions. Is there any mail list or forum? I can't find > anything on the website. It's part of Neural Ensemble which has a google group (not specifically devoted to Sumatra, but all their projects): http://groups.google.com/group/neuralensemble Dan From luke.leighton at gmail.com Sat Jul 10 23:59:50 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Sun, 11 Jul 2010 03:59:50 +0000 Subject: grailbrowser now running under python 2.5 (probably above too) Message-ID: source at: http://github.com/lkcl/grailbrowser $ python grail.py (note the lack of "python1.5" or "python2.4") conversion of the 80 or so regex's to re has been carried out. entirely successfully or not is a matter yet to be determined. always a hoot to try browsing http://www.bbc.co.uk or http://www.youtube.com with a browser from 11+ years ago, it still cannot be resisted as grail is the only working graphical web browser in the world written in pure python [pybrowser is still in development, stalled]. l. From rantingrick at gmail.com Sun Jul 11 01:38:10 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 22:38:10 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! Message-ID: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Let me tell you folks about a recent case of culo rojo i experianced whilst creating a customized bin packer with Python. First i want to say that i actually like the fact that i can do this.. py> a = [] py> if a: ... do something Instead of this py> if len(a) > 0: ... do something Ok but the buck stops with integers. Why? you ask in amazing befuddlement...Well I happened upon this atrocity when creating variables that hold indexes into a python list. the variables where named "choice1 and choice2 and both where initialized to None. Fine no problem there. So the algorithm will search for the two best choices. The first choice "choice1" will always be array[0]. The second choice "choice2" will need to be found using a completely different algorithm. ...Well i could tell you about it but i would rather just show you with some simple code.. array = [c1,c2,c3,c4,c5,c6,...] while looping: choiceIdx1 = None choiceIdx2 = None if array[0] meets condition this condition: choiceIdx1 = 0 for i in range(len(array)): if array[i] meets this condition: choiceIdx2 = i break if choiceIdx1 and not choiceIdx2: best = array.pop(choiceIdx1) elif choiceIdx2 and not choiceIdx1: best = array.pop(choiceIdx2) elif choiceIdx1 and choiceIdx2: # figure out which choice is better. best = choiceIdx1 if choiceIdx1.better() else choiceIdx2 elif not choiceIdx1 and not choiceIdx2: break else: # assume the worst raise do_somthing_with(best) BUT THAT WONT WORK BECAUSE OF CRAPPY INTEGER BOOLEAN DEFAULTS! So i had to do this crap...! array = [c1,c2,c3,c4,c5,c6,...] while looping: choiceIdx1 = () choiceIdx2 = () if array[0] meets condition this condition: choiceIdx1 = (0,) for i in range(len(array)): if array[i] meets this condition: choiceIdx2 = (i,) break if choiceIdx1 and not choiceIdx2: best = array.pop(choiceIdx1[0]) elif choiceIdx2 and not choiceIdx1: best = array.pop(choiceIdx2[0]) elif choiceIdx1 and choiceIdx2: # figure out which choice is better. best = choiceIdx1[0] if choiceIdx1.better() else choiceIdx2[0] elif not choiceIdx1 and not choiceIdx2: break else: # assume the worst raise do_somthing_with(best) Seems kinda dumb to build a tuple just so a conditional wont blow chunks! This integer bool-ing need to be fixed right away! From rantingrick at gmail.com Sun Jul 11 01:44:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 22:44:33 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 10, 10:59?pm, Luke Kenneth Casson Leighton wrote: > source at:http://github.com/lkcl/grailbrowser > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > conversion of the 80 or so regex's to re has been carried out. > entirely successfully or not is a matter yet to be determined. ?always > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > with a browser from 11+ years ago, it still cannot be resisted as > grail is the only working graphical web browser in the world written > in pure python [pybrowser is still in development, stalled]. > > l. Congratulations on this effort Luke. However you know what project i would really like to see the community get around? ...dramatic pause here... a cross platform Python file browser! Yes i know there are tons of them out there already and Python is a bit slow, but i think it would be useful to many peoples. From me+list/python at ixokai.io Sun Jul 11 01:51:49 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 10 Jul 2010 22:51:49 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4C395BF5.4000305@ixokai.io> On 7/10/10 10:38 PM, rantingrick wrote: > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! Yes, let us penalize the thousands of use cases where 0 being false is useful and good, for the benefit of the one use-case (indexing) where it is not. You don't need to build a tuple. Just change the tests, to "if choiceIdx1 is not None". Its a little more work, sure. But its not enough that its even vaguely worth breaking the otherwise very useful behavior of bool(0) == False. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 02:03:40 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 23:03:40 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Jul 11, 12:51?am, Stephen Hansen wrote: > You don't need to build a tuple. Just change the tests, to "if > choiceIdx1 is not None". Its a little more work, sure. But its not > enough that its even vaguely worth breaking the otherwise very useful > behavior of bool(0) == False. Hmm, i beg to differ. The if choice1 is not None and choice2 is not None is going to run off my screen and into my neighbors backyard swimming pool! If you *can* Stefen, show the class a "very useful" case for integer bool-ing? Please do so, although i doubt you can offer one. Maybe you'll offer this kinda kludgy stuff... function(option=1) #instead of True function(option=0) #instead of False This is another example of the damage integer booling does to your code and your mind. What happened to explicit is better than implicit? What happened to tim toady is a SOB! It is easy to get drawn into this way of coding and very hard to pull out. And it's wrong, wrong, wrong. NEVER substitute 1 for True and/or 0 for False! NEVER! This is anti Pythonic! py> import this From me+list/python at ixokai.io Sun Jul 11 02:22:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 10 Jul 2010 23:22:27 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4C396323.2010908@ixokai.io> On 7/10/10 11:03 PM, rantingrick wrote: > On Jul 11, 12:51 am, Stephen Hansen wrote: > >> You don't need to build a tuple. Just change the tests, to "if >> choiceIdx1 is not None". Its a little more work, sure. But its not >> enough that its even vaguely worth breaking the otherwise very useful >> behavior of bool(0) == False. > > > Hmm, i beg to differ. The if choice1 is not None and choice2 is not > None is going to run off my screen and into my neighbors backyard > swimming pool! "if choiceIdx1 is not None and choiceIdx2 is not None:" is 54 characters. Your straw man argument fails. Even if this is in a method of a class, that's only 64; even with another two levels of indentation it still isn't longer then the 80 which is where some people consider things "long" (I do not: I don't mind code > 100). If you are so desperately concerned with space, then simply do: if (choiceIdx1, choiceIdx2) != (None, None): Its only eleven characters longer. Or, you can do: if None not in (choiceIdx1, choiceIdx2): Its only two characters. You really can't honestly be making an argument about two characters. > If you *can* Stefen, My name is Stephen. This is the second time you've done this: if you can't show even the vaguest respect and actually use my name and not a mockery of it, then I'll just killfile you. > show the class a "very useful" case for integer > bool-ing? Please do so, although i doubt you can offer one. Maybe > you'll offer this kinda kludgy stuff... > > function(option=1) #instead of True > function(option=0) #instead of False Of course I won't offer that. If I wish a boolean flag, something which can have only one of two states (although sometimes a three-state 'maybe' is useful, with None being the 'neither true nor false'), I'd use the boolean. There's numerous cases where "if x" where x is an integer is useful. A counter is the simplest example. Say you're counting how many watermelons are in your inventory there is, and you want to test if there's any or not. "if watermelons" is the concise, readable, understandable way to express this. Readability counts. A boolean test in Python tests "something" verses "nothing", it doesn't test Truth verses False It is entirely consistent in this regard (except in the case of custom classes which may decide to do strange things). Zero is, clearly, nothing. > This is another example of the damage integer booling does to your > code and your mind. Utter nonsense. No one does that unless they are coming from C or some other language without a True/False and don't know about it, or if they are using a codebase which is supporting a very old version of Python before True or False were introduced. But you're just going to argue endlessly, no doubt. Have you ever actually considered the fact that your gut reaction might, I don't know, be wrong or misguided? I've admitted when I'm wrong on more then one occasion. I really don't know why I bother. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 02:50:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 10 Jul 2010 23:50:05 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> On Jul 11, 1:22?am, Stephen Hansen wrote: > If you are so desperately concerned with space, then simply do: > > ? ? if (choiceIdx1, choiceIdx2) != (None, None): > > Its only eleven characters longer. > > Or, you can do: > > ? ? if None not in (choiceIdx1, choiceIdx2): Only the first example was worse than the second. You do realize that Python must build a tuple for ever conditional that uses this semantic? This is more bad, bad, bad than integer bool-ing! My bin packer could potentially compute millions of parts. I do not want to waste valuable processor cycles building numerous tuples just for the sake of a conditional "condition"! This is bad coding style Stephen. > Its only two characters. You really can't honestly be making an argument > about two characters. > > > If you *can* Stefen, > > My name is Stephen. It was a typo not an on purpose misspelling > Of course I won't offer that. If I wish a boolean flag, something which > can have only one of two states (although sometimes a three-state > 'maybe' is useful, with None being the 'neither true nor false'), I'd > use the boolean. I agree... True, False, None. The trinity of bool-inity. > There's numerous cases where "if x" where x is an integer is useful. A > counter is the simplest example. Say you're counting how many > watermelons are in your inventory there is, and you want to test if > there's any or not. "if watermelons" is the concise, readable, > understandable way to express this. Readability counts. I agree but when in a conditional bool(integer) should be forced. Look, don't try to shoove this under the mattress like nobody initializes a variable to None and then maybe or maybe not stores an array index in the variable and then later needs to test for true false in a conditional. It's very common to initialize a counter or index variable to None or 0. And later you don't want 0 and None bool- ing to False and range(1:infinity)+range(-infinity:-1) bool-ing to True! > A boolean test in Python tests "something" verses "nothing", it doesn't > test Truth verses False > > It is entirely consistent in this regard (except in the case of custom > classes which may decide to do strange things). > > Zero is, clearly, nothing. No shit! i am talking about CONDITIONALS HERE. Specifically CONDITIONALS and BOOL-ING! > Utter nonsense. No one does that unless they are coming from C or some > other language without a True/False and don't know about it, or if they > are using a codebase which is supporting a very old version of Python > before True or False were introduced. Ah yes, when nothing else seems to work fall back to you default programming... FUD and ad hominem attacks > But you're just going to argue endlessly, no doubt. Have you ever > actually considered the fact that your gut reaction might, I don't know, > be wrong or misguided? I've admitted when I'm wrong on more then one > occasion. I have no problem admitting when i wrong. In this case however i am completely right. Use True/False for bool-ing, None for emptyness, and integers for inetgers. From ian.g.kelly at gmail.com Sun Jul 11 02:57:55 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Jul 2010 00:57:55 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 12:03 AM, rantingrick wrote: > This is another example of the damage integer booling does to your > code and your mind. What happened to explicit is better than implicit? Explicit is better than implicit. Hence, if you're specifically testing for the property of not being None rather than for the more general truth value, it's better to write "if choiceIdx1 is not None" rather than just "if choiceIdx". This holds true for empty collections as well. On Sun, Jul 11, 2010 at 12:22 AM, Stephen Hansen wrote: > There's numerous cases where "if x" where x is an integer is useful. A > counter is the simplest example. Say you're counting how many > watermelons are in your inventory there is, and you want to test if > there's any or not. "if watermelons" is the concise, readable, > understandable way to express this. Readability counts. I would also point out that the current semantics mean that "bool(container)", "bool(len(container))", and "len(container) > 0" are all equivalent. I view this as a positive thing. It also means that "if integer" in Python and "if (the_same_integer)" in a C module have the same semantics. It would be a nasty surprise for writers of C modules if they didn't. And I think that partly this is simply historical. Before a proper boolean type was added to Python, 1 and 0 were the norm for storing truth values. Changing the truth value of 0 when bools were introduced would have broken tons of existing code. This is also the reason why bool is a subclass of int. From ian.g.kelly at gmail.com Sun Jul 11 03:11:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Jul 2010 01:11:31 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 12:57 AM, Ian Kelly wrote: > And I think that partly this is simply historical. ?Before a proper > boolean type was added to Python, 1 and 0 were the norm for storing > truth values. ?Changing the truth value of 0 when bools were > introduced would have broken tons of existing code. ?This is also the > reason why bool is a subclass of int. Another thought related to that list bit: if bool(0) were True, then bool(int(False)) would also be True. That seems messed up. Then again, bool(str(False)) is already True. Does that bother anybody other than me? From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:13:29 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:13:29 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: * rantingrick, on 11.07.2010 08:50: > On Jul 11, 1:22 am, Stephen Hansen wrote: > >> Utter nonsense. No one does that unless they are coming from C or some >> other language without a True/False and don't know about it, or if they >> are using a codebase which is supporting a very old version of Python >> before True or False were introduced. > > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem > attacks I agree with Stephen, but for a different reason: that given desirability of implicit conversion to bool for some elementary types, then for uniformity there should be such conversion for all of them (and AFAIK there is), and given that, the rule should be the same, namely that default value of each type bool's to False, and other values to True, and so it is. The OP should simply represent "not found" as e.g. integer -1 instead of as a value of a different type. And write e.g. not_found = -1 ... if choiceIdx1 == choiceIdx2 == not_found: bah, none of them elif choice2Idx == not_found: use choice 1 elif choice1Idx == not_found: use choice 2 else: determine bestest choice Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Sun Jul 11 03:19:14 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 00:19:14 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C397072.90409@ixokai.io> On 7/10/10 11:50 PM, rantingrick wrote: > On Jul 11, 1:22 am, Stephen Hansen wrote: > >> If you are so desperately concerned with space, then simply do: >> >> if (choiceIdx1, choiceIdx2) != (None, None): >> >> Its only eleven characters longer. >> >> Or, you can do: >> >> if None not in (choiceIdx1, choiceIdx2): > > > Only the first example was worse than the second. You do realize that > Python must build a tuple for ever conditional that uses this > semantic? This is more bad, bad, bad than integer bool-ing! My bin > packer could potentially compute millions of parts. I do not want to > waste valuable processor cycles building numerous tuples just for the > sake of a conditional "condition"! This is bad coding style Stephen. Nonsense. Prove it. Show actual benchmarks and actual problems to that style. Tests that do, in essence, "if whatever in (constant1, constant2)" are exceedingly common. The burden is on you to prove they are bad. With real data. > >> Its only two characters. You really can't honestly be making an argument >> about two characters. >> >>> If you *can* Stefen, >> >> My name is Stephen. > > It was a typo not an on purpose misspelling If this had been the first time, perhaps. If you had not in *numerous* previous times spelled my name correctly, perhaps. If it were at all possible for "f" to be a typo of "ph", perhaps. As none of those are true, I must assume you are simply trying to be insulting. And yes, I do consider mangling my name to be an insult. >> There's numerous cases where "if x" where x is an integer is useful. A >> counter is the simplest example. Say you're counting how many >> watermelons are in your inventory there is, and you want to test if >> there's any or not. "if watermelons" is the concise, readable, >> understandable way to express this. Readability counts. > > I agree but when in a conditional bool(integer) should be forced. Uh, what? I left off the rest of this paragraph because it is incomprehensible. If bool(anything_at_all) returns True, then "if anything_at_all" must succeed. If bool(anything_at_all) returns False, then "if anything_at_all" must fail. To do otherwise would create two entirely different and strange definitions for what is Truth and what is False. Python defines them very clearly. Something. Verses. Nothing. 1 is something. 0 is nothing. >> A boolean test in Python tests "something" verses "nothing", it doesn't >> test Truth verses False >> >> It is entirely consistent in this regard (except in the case of custom >> classes which may decide to do strange things). >> >> Zero is, clearly, nothing. > > No shit! i am talking about CONDITIONALS HERE. Specifically > CONDITIONALS and BOOL-ING! I, too, am speaking of conditionals here. No shit back at you. The "if" statement works on the test, "Is this something?" If so, it executes its body. If not, it executes the 'else' body if present. >> Utter nonsense. No one does that unless they are coming from C or some >> other language without a True/False and don't know about it, or if they >> are using a codebase which is supporting a very old version of Python >> before True or False were introduced. > > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem > attacks Red herring. Do you know what FUD is? FUD is Fear, Uncertainty, and Doubt. I didn't try to scare you about anything. I didn't try to make you uncertain if something would work. And so on, and so forth. I dismissed your utterly unfounded claim and example which you held up as proof of your central point as nonsense. Do you know what an ad hominem attack is? I didn't say, "Your argument is invalid because you, a jackass, said it" -- that would be an ad hominem attack. My statement is neither FUD, nor even an ad hominem attack. If you dispute my dismissal, show evidence. Any will do. Oh, I do admit that in the end, I did venture into the ad hominem area where I called into question your attitude and general behavior of utter Infallible Rightness and trolling tendencies, but that is not a logical fallacy. You can call into question the motives and character of a person -- provided you are not using this as the sole means of denying their claim. You can't simply sweep my argument aside by claiming its an ad hominem attack because besides my pointing out you're trollish behavior, I'm actually taking the time to refute your actual arguments with arguments of my own. >> But you're just going to argue endlessly, no doubt. Have you ever >> actually considered the fact that your gut reaction might, I don't know, >> be wrong or misguided? I've admitted when I'm wrong on more then one >> occasion. > > I have no problem admitting when i wrong. Please, show an example. > In this case however i am > completely right. Use True/False for bool-ing, None for emptyness, and > integers for inetgers. Nonsense. None is not "for emptiness". None is a discrete entity, which exists for a very specific purpose. It evaluates as false, certainly. But it is neither the definition nor the poster child of emptiness. It is something else entirely. It is None. It is "no value" -- not the absence of a value, nor the absence of any thing, but the discrete state of "I explicitly have no value". That is *very* different, and very powerful, from the simple state of "empty". Many things can be empty. Many things can be nothing. Emptiness is far, far more then None. "" is emptiness, too. {} is emptiness, too. () is emptiness, too. [] is emptiness, too. And, 0 is emptiness, too. As is 0.0, though this is less useful (Since floating point math gets weird). Do you see the pattern? Every fundamental data type has a "nothing" state: and they ALL evaluate as false in conditionals. Why should integers be any different? Because, uh, you say so. Okay. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Sun Jul 11 03:26:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 00:26:36 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? Message-ID: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Another source of asininity seems to be the naming conventions of the Python language proper! True/False start with an upper case and i applaud this. However str, list, tuple, int, float --need i go on...?-- start with lowercase. Q: Well what the hell is your problem Rick. Who cares right? WRONG, I tell you what my problem is. Now i cannot "wisely" use variables like... str="this is a string" list = [1,2,3] def make_random_objs(range=10) def show_message(str) int = 12 If we would have adopted proper naming conventions from dios numero uno all this nonsense would be rectified! Str, Float, List, Range, etc, etc. You think Python 3000 was a hump to climb over just wait for Python 4000. Just thoughts. From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:30:23 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:30:23 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: * Stephen Hansen, on 11.07.2010 09:19: > On 7/10/10 11:50 PM, rantingrick wrote: >> >> It was a typo not an on purpose misspelling > > If this had been the first time, perhaps. If you had not in *numerous* > previous times spelled my name correctly, perhaps. If it were at all > possible for "f" to be a typo of "ph", perhaps. It is a natural mistake to make in some languages. E.g. in Norwegian the Devil can be spelled Faen or Fanden (modern) or Phanden (old-fashioned, no longer in dictionaries but still used to sort of tone down the expression). It's even there in English, like "file" and "philosophy". So it's an error committed not by the limbic system but by a slightly higher level sound-to-text translator brain circuit. The text is generated from how the word sounds in one's head. Cheers & hth., - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Sun Jul 11 03:34:29 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 09:34:29 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: * rantingrick, on 11.07.2010 09:26: > > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 > > If we would have adopted proper naming conventions from dios numero > uno all this nonsense would be rectified! Str, Float, List, Range, > etc, etc. You think Python 3000 was a hump to climb over just wait for > Python 4000. > > Just thoughts. Just do Str = str List = list Float = float and so on in module "myBasicTypes", and import that. :-) Cheers & hth., - Alf -- blog at From no.email at nospam.invalid Sun Jul 11 03:39:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 11 Jul 2010 00:39:22 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <7xmxtywjpx.fsf@ruckus.brouhaha.com> rantingrick writes: > unspeakably ugly code. I'd write the code differently to not do all those branches. I like to use 1-elemnt lists as an option type, instead of using None, so you can just concatenate them together to get the first non-empty one. Untested code: array = [c1,c2,c3,c4,c5,c6,...] # return first element of iterable that matches condition, wrapped # as a 1-element list. If no match, return empty list. def xfind(condition, iterable): for x in iterable: if condition(x): return [x] return [] while looping: cs = xfind(this_condition, array) + xfind(other_condition, array) # cs is now a list of either zero, one, or two matching elements if len(cs) == 1: r = cs[0] elif len(cs) = 2: r = else: break best = array.pop(r) do_somthing_with(best) Obviously you can golf the above in various ways. From me+list/python at ixokai.io Sun Jul 11 03:53:26 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 00:53:26 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C397876.7040809@ixokai.io> On 7/11/10 12:30 AM, Alf P. Steinbach /Usenet wrote: > * Stephen Hansen, on 11.07.2010 09:19: >> On 7/10/10 11:50 PM, rantingrick wrote: >>> >>> It was a typo not an on purpose misspelling >> >> If this had been the first time, perhaps. If you had not in *numerous* >> previous times spelled my name correctly, perhaps. If it were at all >> possible for "f" to be a typo of "ph", perhaps. > > It is a natural mistake to make in some languages. E.g. in Norwegian the > Devil can be spelled Faen or Fanden (modern) or Phanden (old-fashioned, > no longer in dictionaries but still used to sort of tone down the > expression). It's even there in English, like "file" and "philosophy". > So it's an error committed not by the limbic system but by a slightly > higher level sound-to-text translator brain circuit. The text is > generated from how the word sounds in one's head. I'm aware of the "f" vs "v" vs "ph" thing, and the complexity of it between languages and between the spoken verses written nature of language. And for most instances, I'd just idly note, hey-- "My name is Stephen" and leave it at that -- but this is not the first time with I've run into it with this person, and neither is it the first time I've responded to him and politely corrected him. That, and I have seen absolutely no reason to think this person speaks anything but standard American English. He has, for example, gone so far as to create a rant which declared quite vocally that everyone should adopt English, destroy Unicode and the usage of any other language, and that anyone who didn't follow through with this was ultimately hurting humanity. That any programmer which cow-towed towards this evil empire of Unicodeness was just embracing separatism and decisiveness. When this guy on more then one occasion chooses to articulate my name improperly, I take it as an underhanded act with no purpose but to belittle my point of view. So yes. The first time, its a natural mistake, and I hold no hard feelings. I regularly deal with people who misspell my name and mispronounce my name. A polite correction invariably solves the problem, and we are all happy. But if one then makes the mistake again-- and in an entirely different way (Stefan vs Steven) then they were politely corrected before-- its no longer an issue of linguistic confusion at that point. At that point, I have to assume he's doing it on purpose, and for the sole purpose of being disrespectful and disparaging. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From gd.usenet at spamfence.net Sun Jul 11 04:03:27 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 11 Jul 2010 10:03:27 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: rantingrick wrote: >Another source of asininity seems to be the naming conventions of the >Python language proper! True/False start with an upper case and i >applaud this. However str, list, tuple, int, float --need i go >on...?-- start with lowercase. > >Q: Well what the hell is your problem Rick. Who cares right? > >WRONG, I tell you what my problem is. Now i cannot "wisely" use >variables like... > >str="this is a string" >list = [1,2,3] >def make_random_objs(range=10) >def show_message(str) >int = 12 Someone who wants to write readable and maintainable code would (practically) never want to use variables named in this way. Why? Because these names don't tell anything about the purpose of the variables. So, it is not a disadvantage that the functions you listed above are named in this way. In the contrary, it is an advantage, as it keeps newcomers from using stupid variable names. >If we would have adopted proper naming conventions from dios numero >uno all this nonsense would be rectified! Str, Float, List, Range, >etc, etc. You think Python 3000 was a hump to climb over just wait for >Python 4000. Additionally to what I mention above, there is PEP 0008. Read it, you can learn from it. What you listed above, are functions, and their names comply completely with PEP 0008. Regards, G?nther PS: Even though I suspect that you are simply an agitator rsp. troll (based on what you posted in this group so far), and normally I refuse to feed trolls, I make an exception in this case, so newcomers ar not mislead by your half-baked ideas. From rantingrick at gmail.com Sun Jul 11 04:15:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:15:51 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <26122d68-3c13-430e-ada1-e10cb7126f26@u26g2000yqu.googlegroups.com> On Jul 11, 2:19?am, Stephen Hansen wrote: > Nonsense. > > Prove it. Show actual benchmarks and actual problems to that style. I can't believe i actually have to prove to you that creating a tuple and then testing for bool-inity takes more time than just the bool test, but here goes *another* Sunday school lesson... >>> s1 = "if (a, b) != (None, None):\n pass" >>> t1 = timeit.Timer(s1, 'a=1;b=1') >>> min(t1.repeat()) 0.23950232000015603 >>> s2 = "if a is not None and b is not None:\n pass" >>> t2 = timeit.Timer(s2, 'a=1;b=1') >>> min(t2.repeat()) 0.14334155999995346 > Tests that do, in essence, "if whatever in (constant1, constant2)" are > exceedingly common. The burden is on you to prove they are bad. With > real data. yea, been there done that. > And yes, I do consider mangling my name to be an insult. obviously i sounded out your name in my head. It is getting pretty late here after all so give me break for crying out loud. > 1 is something. Yes, but not necessarily a "True" something! > 0 is nothing. Yes, but not necessarily a "False" nothing! What is a True "something" and what is a False "nothing" Stephen? Put that one up where it belongs with the chicken and the egg where it belongs -- next to the toilet with Hustler and Time. > My statement is neither FUD, nor even an ad hominem attack. If you > dispute my dismissal, show evidence. Any will do. > > Oh, I do admit that in the end, I did venture into the ad hominem area > where I called into question your attitude and general behavior haha, i love how you denied the fact that you used ad hominem attacks and then directly after that tried to makes excuses for the very behavior you denied. Clinton made a career out this very same story telling. Nice work Bill Jr. *wink* > Do you see the pattern? Every fundamental data type has a "nothing" > state: and they ALL evaluate as false in conditionals. > > Why should integers be any different? Because, uh, you say so. No because i provide a very good reason --specifically in the case of a conditional bool-ing-- that integers bool-ing to True/False can be disastrous. And not only did i provide one reason, i provided two. The second being that 1/0 as compared to True/False is misleading in it's intention. Which renders code less readable, and supports bad programming styles. From rantingrick at gmail.com Sun Jul 11 04:26:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:26:38 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <7xmxtywjpx.fsf@ruckus.brouhaha.com> Message-ID: <884ba255-ca02-437c-bc98-2f2d7eb103e0@i31g2000yqm.googlegroups.com> On Jul 11, 2:39?am, Paul Rubin wrote: > rantingrick writes: > > unspeakably ugly code. > > I'd write the code differently to not do all those branches. > I like to use 1-elemnt lists as an option type, instead of using None, > so you can just concatenate them together to get the first non-empty > one. ?Untested code: Hmm, thanks for offering a solution but since functions call's induce so much overhead and you use the len function in each condition i believe the code would run much slower. How much slower, i don't know? Maybe i'll run the test later. I need to come up with some good test cases. Of course i'll want to maximize my side of the argument by producing the most efficient code that really makes your look slow. ;-) From rantingrick at gmail.com Sun Jul 11 04:30:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 01:30:36 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> On Jul 11, 3:03?am, "G?nther Dietrich" wrote: > So, it is not a disadvantage that the functions you listed above are > named in this way. In the contrary, it is an advantage, as it keeps > newcomers from using stupid variable names. "int" for an Integer is stupid? "list" for a List is stupid? "str" for a String is stupid? What am i missing? From kedra.marbun at gmail.com Sun Jul 11 04:31:07 2010 From: kedra.marbun at gmail.com (kedra marbun) Date: Sun, 11 Jul 2010 01:31:07 -0700 (PDT) Subject: 'reload M' doesn't update 'from M inport *' References: <4c37472e$0$28647$c3e8da3@news.astraweb.com> Message-ID: > from m import f > > look for module m in the global cache > if not there, then: > search for m.py > compile it to a Module object > put the Module object in the cache > look for object named "f" in the Module object agree > create a new name "f" in the local namespace > set the name "f" to cached object strongly agree > The important thing to notice is the the name "f" is a local variable. It > doesn't, and can't, remember that it comes from module m. Reloading m > can't do anything to f, because the connection is lost. disagree with 2nd stmt. local 'f' does *remember* (if that's the right word) where it comes from, because it points to the original obj, as you said: 'set the name "f" to cached object' py0.py ====== def f(): ... >>> from py0 import * >>> assert f.__module__ == sys.modules['py0'].__name__ >>> assert f.__globals__ is sys.modules['py0'].__dict__ > Now consider that the object "f" that came from m was itself imported > from another module, "service". Reloading service doesn't help, because > m.f doesn't know it came from service. Reloading m doesn't help, because > all that does is run "from service import f" again, and that just fetches > f from the global cache. disagree with 2nd stmt, partially disagree with 3rd stmt reloading 'service' partially helps, since it updates the mod obj pointed by 'service' in global cache. it needs to be followed by reloading m, then we have m.f points to the new obj. the important part is the order of reloading mods l.py ==== def f(): ... m.py ==== from l import * >>> from m import * at this point, the func obj is referenced by 3 distinct variables with name 'm'(one in each mod) >>> assert sys.getrefcount(f) == 4 >>> referrers = gc.get_referrers(f) >>> mod_dicts = [sys.modules[k].__dict__ for k in sys.modules if k == 'l' or k == 'm' or k == __name__] >>> for d in mod_dicts: ... referrers.remove(d) >>> assert len(referrers) == 0 >>> imp.reload(sys.modules['l']) now the original func obj is ref'ed by 2 vars, the new func obj is ref'ed by 1 var >>> imp.reload(sys.modules['m']) >>> f = sys.modules['m'].f now the original func obj is ready to be recollected, the new func obj is ref'ed by 3 vars > The simplest, easiest way of dealing with this is not to have to deal > with it: don't use "from service import f", and ESPECIALLY don't use > "from service import *". Always use fully-qualified importing: > > import service > service.f strongly agree > The other way is not to bother with reload. It's not very powerful, only > good for the simplest use in the interactive interpreter. Just exit the > interpreter and restart it. set, del, reload are useful when it comes to structure manipulation at runtime, most langs differentiate it, labeling as metaprogramming, py smashes the diff in an elegant way (oh flattery, i love it) ;) as their names say, set & del only bind & unbind obj to var, the obj to bind must be in its bytecode form, in theory one could do it, maybe thru modules that are categorized as "Python Language Services" in the lib manual, but it's not practical (e.g. see the last stmt of types.CodeType.__doc__). this is where 'reload' steps in, and so the story goes ... From post at andre-bell.de Sun Jul 11 04:49:20 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Sun, 11 Jul 2010 10:49:20 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4C398590.9080602@andre-bell.de> On 07/11/2010 10:30 AM, rantingrick wrote: > On Jul 11, 3:03 am, "G?nther Dietrich" > wrote: > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? You are missing (from PEP 8): --- 8< --- 8< --- Class Names Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition. --- 8< --- 8< --- You may want to think of list, int, str, object, ... as classes that don't follow this advice with their class name. But besides that, shouldn't a variable name reflect it's purpose instead of it's type? E.g. name = 'rantingrick' counter = 1 ... as compared to str = 'rantingrick' int = 1? Regards Andre From kaklis at gmail.com Sun Jul 11 05:22:38 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Sun, 11 Jul 2010 02:22:38 -0700 (PDT) Subject: Load/Performance Testing of a Web Server References: <7a2fed45-a80b-4945-bcf2-64bcc9db83c8@m17g2000prl.googlegroups.com> Message-ID: <1668dc8d-ab50-4b58-a1c9-bae19db95202@r27g2000yqb.googlegroups.com> On Jul 9, 4:44?pm, Simon Brunning wrote: > On 9 July 2010 14:17, kak... at gmail.com wrote: > > > Hi to all, i want to stress test ? a tomcat web server, so that i > > could find out its limits. e.g how many users can be connected and > > request a resource concurrently. > > I used JMeter which is an excellent tool, but i would like to use a > > more pythonic approach. > > The Grinder? > > -- > Cheers, > Simon B. Thank you Simon! I'll give it a try. It looks very promising. Antonis K. From bartc at freeuk.com Sun Jul 11 05:57:27 2010 From: bartc at freeuk.com (bart.c) Date: Sun, 11 Jul 2010 10:57:27 +0100 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <4Bg_n.204567$k15.45006@hurricane> "rantingrick" wrote in message news:1b285203-33f6-41fb-8321-381c154bc8ed at w12g2000yqj.googlegroups.com... > Let me tell you folks about a recent case of culo rojo i experianced > whilst creating a customized bin packer with Python. First i want to > say that i actually like the fact that i can do this.. > > py> a = [] > py> if a: > ... do something > > Instead of this > > py> if len(a) > 0: > ... do something Or perhaps: if len(a): ... > Ok but the buck stops with integers. Why? you ask in amazing > befuddlement...Well I happened upon this atrocity when creating > variables that hold indexes into a python list. > choiceIdx1 = None > choiceIdx2 = None > if array[0] meets condition this condition: > choiceIdx1 = 0 > for i in range(len(array)): > if array[i] meets this condition: > choiceIdx2 = i > break > if choiceIdx1 and not choiceIdx2: > BUT THAT WONT WORK BECAUSE OF CRAPPY INTEGER BOOLEAN DEFAULTS! So i > had to do this crap...! You can also blame the 0-based indexing in Python. I'm not sure what would be the more fundamental change: changing over to 1-based indexing, or for 0 to be True (probably the opposite meaning to every other language). > array = [c1,c2,c3,c4,c5,c6,...] > while looping: > choiceIdx1 = () > choiceIdx2 = () > if array[0] meets condition this condition: > choiceIdx1 = (0,) > for i in range(len(array)): > if array[i] meets this condition: > choiceIdx2 = (i,) > break > if choiceIdx1 and not choiceIdx2: > > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! So, you're simply trying to signal whether a value is in the range 0 or more, or not? That doesn't sound difficult: start with -1, then test whether it's >=0. But you're trying a boolean test where you expect None=False, and 0,1,2, etc = True. While this would save typing in the condition, you're introducing extraneous stuff elsewhere which makes it harder to read, such as (i,) just to store an index. -- Bartc From marek at xivilization.net Sun Jul 11 07:51:50 2010 From: marek at xivilization.net (Marek Kubica) Date: Sun, 11 Jul 2010 13:51:50 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <20100711135150.5ecf4a61@halmanfloyd.lan.local> On Sun, 11 Jul 2010 00:26:36 -0700 (PDT) rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. Achtually, these are type names with their own constructor. The name of the type of True and False is bool and, bool() returns a bool-object. regards, Marek From johan.gronqvist at gmail.com Sun Jul 11 08:28:54 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Sun, 11 Jul 2010 14:28:54 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: 2010-07-11 02:12, Ritchy lelis skrev: > On 7 jul, 08:38, Johan Gr?nqvist wrote: > > About the plot draw it's a curve that it's a set of points wich it's > the result of the comput of the Vref and Vi together. I don't know if > i had to make a break instruction (like in other's languages) after > the "If" instructions if i want the else-condition to be executed? ... > (do you have some sujestions?) I would have expected a code structure similar to this: (NOTE: This is a very inefficient solution, and not the one suggested earlier, but it is closer to the code snippet you posted originally, and it does produce a plot.) ---------------------- import numpy as np import matplotlib.pyplot as plt Vref = np.linspace(1,20, 100) Vi = np.linspace(1,10,100) for ref in Vref: # Loop over Vref and Vi for i in Vi: if i > ref/4: # Compute V0 V0 = 2*i-ref elif (-ref/4) <= ref and ref <= ref/4: V0 = 2*i elif i < -ref/4: V0 = 2*i+ref plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 plt.show() # Display the plot in a window ---------------------- > Anyway i have a picture of a tuturial that i found but in this forum i > can't post it. That pic would show what a really want... Can you give a link? > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > y-axis. To me this sound like you want to make a 3D-plot, as there is the x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > As i said, i have a good 2 pic of a doc that has the information about > this ADC that i'm developing. > I looked on wikipedia , and saw some figures. Is any of those similar to what you look for? I see that they have (Vi - Vref) on the x-axis, and the computed value on the y-axis. Regards Johan From rene7705 at gmail.com Sun Jul 11 09:23:30 2010 From: rene7705 at gmail.com (Rene Veerman) Date: Sun, 11 Jul 2010 15:23:30 +0200 Subject: getting the variable type Message-ID: hi. i need to know the type of variable i'm dealing with. take this list: files = [ "lib/jquery/jquery-1.4.2.source.js", "lib/jquery-ui-1.8.1/development-bundle/ui/jquery-ui-1.8.1.custom.js", "lib/jquery-ui-1.8.1/development-bundle/ui/jquery.ui.tabs.js", "lib/jquery/jquery.scrollTo-min.js", "lib/jquery/jquery.corner.js", "lib/jquery/jquery.mousewheel.js", "lib/jquery/jquery.em.js", "lib/jquery/jScrollPane.js", "lib_rv/logAndHandler-1.1.0/lah.source.js", "lib_rv/visCanvasLoaderIcon-1.1.0/visCanvasLoaderIcon.source.js", self.getJavascript_getbootJSPHP, "js/mbCore_boot.js", "content/mediaBeez_custom.js" ] # output a list of the files. html = ''; for i in range(len(files)): file = files[i] f = open (file, 'r') html += f.read() page = { 'html' : html } the third-last item in the list is not a string, it's a function. how do i test for that? -- --------------------------------- Greetings from Rene7705, My free open source webcomponents: ? http://code.google.com/u/rene7705/ ? http://mediabeez.ws/downloads (and demos) My music (i'm DJ firesnake) ? http://mediabeez.ws/music http://www.facebook.com/rene7705 --------------------------------- From gelonida at gmail.com Sun Jul 11 09:37:28 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 11 Jul 2010 15:37:28 +0200 Subject: how to determine whether pathname1 is below bathname2 Message-ID: Hi, I wanted to figure out whether a given path name is below another path name. Surprisingly this turned out to be more difficult than initially anticipated: Let's assume I want to find out, whether path1 is below path2 First I thought about checking whether path1 starts with path2 For this I had to - convert path1 / path2 to absolute paths - I had to normalize the path name Further this would still fail for path1='/tmp/dir11' and path2='/tmp/dir1' next option would be to split both absolute and normalized paths by os.sep and check whether the path2's split list starts with path1's split list. That should work but is also not really nice. finally I came up with: ################################################# import os def is_below_dir(fname,topdir): relpath = os.path.relpath(fname,topdir) return not relpath.startswith('..'+os.sep) print is_below_dir(path1,path2) ################################################# The basic idea is, if the path name of path1 relative to path2 does NOT start with '..', then it must be below path2 Does anybody see pitfalls with that solution? Is there by any chance a function, that I overlooked, which does already what I'd like to do? From news1234 at free.fr Sun Jul 11 09:46:40 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 15:46:40 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4c39cb40$0$5856$426a74cc@news.free.fr> Andre Alexander Bell wrote: > On 07/11/2010 10:30 AM, rantingrick wrote: >>> So, it is not a disadvantage that the functions you listed above are >>> named in this way. In the contrary, it is an advantage, as it keeps >>> newcomers from using stupid variable names. >> "int" for an Integer is stupid? >> "list" for a List is stupid? >> "str" for a String is stupid? >> >> What am i missing? > > You are missing (from PEP 8): > > --- 8< --- 8< --- > Class Names > > Almost without exception, class names use the CapWords convention. > Classes for internal use have a leading underscore in addition. > > --- 8< --- 8< --- > > You may want to think of list, int, str, object, ... as classes that > don't follow this advice with their class name. > > But besides that, shouldn't a variable name reflect it's purpose instead > of it's type? E.g. hm, well sometimes I do write generic functions, that do something with a list or a string or an int. However a simple way around this is to use following naming style. to replace def process_list(list): dostuff_with(list) with def process_list(alist): dostuff_with(alist) or with def process_list(a_list): dostuff_with(a_list) I must admit, that I have still problems to not use the variables range or id From breamoreboy at yahoo.co.uk Sun Jul 11 09:46:51 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 11 Jul 2010 14:46:51 +0100 Subject: getting the variable type In-Reply-To: References: Message-ID: On 11-7-2010 14:23, Rene Veerman wrote: > hi. > > i need to know the type of variable i'm dealing with. > > take this list: > > files = [ > "lib/jquery/jquery-1.4.2.source.js", > "lib/jquery-ui-1.8.1/development-bundle/ui/jquery-ui-1.8.1.custom.js", > "lib/jquery-ui-1.8.1/development-bundle/ui/jquery.ui.tabs.js", > "lib/jquery/jquery.scrollTo-min.js", > "lib/jquery/jquery.corner.js", > "lib/jquery/jquery.mousewheel.js", > "lib/jquery/jquery.em.js", > "lib/jquery/jScrollPane.js", > "lib_rv/logAndHandler-1.1.0/lah.source.js", > "lib_rv/visCanvasLoaderIcon-1.1.0/visCanvasLoaderIcon.source.js", > self.getJavascript_getbootJSPHP, > "js/mbCore_boot.js", > "content/mediaBeez_custom.js" > ] > # output a list of the files. > html = ''; > for i in range(len(files)): > file = files[i] You could write for file in files: *BUT* using file will override the builtin name, better (say) for fn in files: > > f = open (file, 'r') hence:- f = open (fn, 'r') > html += f.read() > > page = { > 'html' : html > } > the third-last item in the list is not a string, it's a function. > how do i test for that? > Check out the isinstance function here. http://docs.python.org/library/functions.html HTH. Mark Lawrence From thomas at jollans.com Sun Jul 11 09:52:09 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 15:52:09 +0200 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: References: Message-ID: <4C39CC89.8070500@jollans.com> On 07/11/2010 03:37 PM, Gelonida wrote: > ################################################# > import os > def is_below_dir(fname,topdir): > relpath = os.path.relpath(fname,topdir) > return not relpath.startswith('..'+os.sep) > > print is_below_dir(path1,path2) > ################################################# > The basic idea is, if the path name of path1 > relative to path2 does NOT start with '..', then > it must be below path2 > > > Does anybody see pitfalls with that solution? > Is there by any chance a function, that I overlooked, > which does already what I'd like to do? It probably won't work on Windows because it isolates volumes (drive letters). What does, for example, os.path.relpath do when you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two reasonably correct options: either raise an exception (there is no relative path) or return the absolute path, which doesn't start with .. On UNIX, the only potential problem I see is that it may or may not do what you expect when symlinks are involved somewhere. From aahz at pythoncraft.com Sun Jul 11 10:00:24 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Jul 2010 07:00:24 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: In article , Luke Kenneth Casson Leighton wrote: > >$ python grail.py (note the lack of "python1.5" or "python2.4") Congrats! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From aahz at pythoncraft.com Sun Jul 11 10:01:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Jul 2010 07:01:06 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: In article , rantingrick wrote: > >Congratulations on this effort Luke. However you know what project i >would really like to see the community get around? ...dramatic pause >here... a cross platform Python file browser! Yes i know there are >tons of them out there already and Python is a bit slow, but i think >it would be useful to many peoples. As usual, you would rather tell other people what to do instead of doing any work yourself. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From usenot at geekmail.INVALID Sun Jul 11 10:24:23 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 11 Jul 2010 16:24:23 +0200 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c39cb40$0$5856$426a74cc@news.free.fr> Message-ID: <20100711162423.1b8f1d36@geekmail.INVALID> On Sun, 11 Jul 2010 15:46:40 +0200 News123 wrote: > Andre Alexander Bell wrote: > > On 07/11/2010 10:30 AM, rantingrick wrote: > > >>> So, it is not a disadvantage that the functions you listed above > >>> are named in this way. In the contrary, it is an advantage, as it > >>> keeps newcomers from using stupid variable names. > >> "int" for an Integer is stupid? > >> "list" for a List is stupid? > >> "str" for a String is stupid? > >> > >> What am i missing? > > > > [snip] > > hm, well sometimes I do write generic functions, that do something > with a list or a string or an int. > > [snip] > > I must admit, that I have still problems > to not use the variables range or id > There are several approaches: - Use range_, id_, and so on. I think this is the proposed convention. Slightly ugly, though. - Use abbreviations, or misspellings like lst, Set, klass, ... Less ugly, but can get weird. - Prepend 'a' to a type name: alist, aset, astr. Similar weirdness potential as above, but more consistent in terms of style. I sometimes take this to the extreme and prepend 'some_'. So really, this is a non issue, at least for me. Having capitalized boolean values ... that is a bit odd, but as long as children are starving in Africa, this isn't very high on my gripe-list. /W -- INVALID? DE! From gelonida at gmail.com Sun Jul 11 10:34:14 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 11 Jul 2010 16:34:14 +0200 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: <4C39CC89.8070500@jollans.com> References: <4C39CC89.8070500@jollans.com> Message-ID: Hi Thomas, Thomas Jollans wrote: > On 07/11/2010 03:37 PM, Gelonida wrote: >> ################################################# >> import os >> def is_below_dir(fname,topdir): >> relpath = os.path.relpath(fname,topdir) >> return not relpath.startswith('..'+os.sep) >> >> print is_below_dir(path1,path2) >> ################################################# >> The basic idea is, if the path name of path1 >> relative to path2 does NOT start with '..', then >> it must be below path2 >> >> >> Does anybody see pitfalls with that solution? >> Is there by any chance a function, that I overlooked, >> which does already what I'd like to do? > > It probably won't work on Windows because it isolates volumes (drive > letters). What does, for example, os.path.relpath do when > you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two > reasonably correct options: Thanks, Indeed. different drives raise an ecception. I could catch the ValueError and let it just return False > > either raise an exception (there is no relative path) or return the > absolute path, which doesn't start with .. > > On UNIX, the only potential problem I see is that it may or may not do > what you expect when symlinks are involved somewhere. Also true. In my case I'd prefer it would not follow, but it doesn't really matter. So my function in order to be portable had now to look like: ################################################# import os def is_below_dir(fname,topdir): try: relpath = os.path.relpath(fname,topdir) except ValueError: return False return not relpath.startswith('..'+os.sep) print is_below_dir(path1,path2) ################################################# if I wanted to folow symlinks, then had to apply os.path.realpath() on fname AND on topdir From news1234 at free.fr Sun Jul 11 10:36:46 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 16:36:46 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <20100711162423.1b8f1d36@geekmail.INVALID> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c39cb40$0$5856$426a74cc@news.free.fr> <20100711162423.1b8f1d36@geekmail.INVALID> Message-ID: <4c39d6fe$0$2485$426a74cc@news.free.fr> Andreas Waldenburger wrote: > > Having capitalized boolean values ... that is a bit odd, but as long as > children are starving in Africa, this isn't very high on my gripe-list. > +1 From zooko at zooko.com Sun Jul 11 10:45:39 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Sun, 11 Jul 2010 08:45:39 -0600 Subject: I wish for a tool named "2to6". Message-ID: Folks: I have been (I admit it) a Python 3 skeptic. I even speculated that the Python 3 backward-incompatibility would lead to the obsolescence of Python: http://pubgrid.tahoe-lafs.org/uri/URI:DIR2-RO:ixqhc4kdbjxc7o65xjnveoewym:5x6lwoxghrd5rxhwunzavft2qygfkt27oj3fbxlq4c6p45z5uneq/blog.html However, things are really looking up now because it turns out that it is eminently practical to support both Python 2 and Python 3 with a single codebase. There have been some recent discussions about that on this list. A few references: http://mail.python.org/pipermail/python-list/2010-July/1249312.html http://www.voidspace.org.uk/python/weblog/arch_d7_2010_03_20.shtml#e1167 http://nedbatchelder.com/blog/200910/running_the_same_code_on_python_2x_and_3x.html http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html Benjamin Peterson has even written a library intended to help programmers who want to do that: http://packages.python.org/six/ This note to the list is to express my wish for an automated tool named "2to6" which converts my Python 2.6 codebase to being both py2- and py2- compatible using Benjamin Peterson's six library. Regards, Zooko From dhruvbird at gmail.com Sun Jul 11 11:59:06 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Sun, 11 Jul 2010 08:59:06 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? Message-ID: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which suggests that this is done to make sure that the programmer understands that the list is being modified in place, but that rules out constructs like: ([1,2,3,4].reverse()+[[]]).reverse() I want to prepend an empty list to [1,2,3,4]. This is just a toy example, since I can always do that with [[]]+[1,2,3,4]. Regards, -Dhruv. From torriem at gmail.com Sun Jul 11 12:03:12 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jul 2010 10:03:12 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4C39EB40.80800@gmail.com> On 07/11/2010 12:50 AM, rantingrick wrote: > Ah yes, when nothing else seems to work fall back to you default > programming... FUD and ad hominem attacks Please stop calling things what they are not. Stephen's post was not an ad hominem attack, nor was it FUD. Someone who is countering your premise and position (IE disagrees with you) is not automatically attacking your character or some characteristic of your person. http://en.wikipedia.org/wiki/Ad_hominem#Common_misconceptions_about_ad_hominem Kudos to Stephen for replying in such a reasonable and even logical fashion to your post. Would that you would reply to his posts in a similar fashion, rather than leveling silly false accusations of "FUD and ad hominem attacks." From rantingrick at gmail.com Sun Jul 11 12:16:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 09:16:46 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> On Jul 11, 9:01?am, a... at pythoncraft.com (Aahz) wrote: > As usual, you would rather tell other people what to do instead of doing > any work yourself. Dear God! My statement was intended to fetch responses like... "Hey, that sounds like a great idea" or \ "Hey, lets get hacking on this". I am so sick of you people constantly accusing me of being lazy. You don't even know me. Also i think you're really a bit jealous because i have the brass cohones to initiate a coding project without your express written permission. I will not allow myself to be brow beaten by anyone! From thomas at jollans.com Sun Jul 11 12:19:35 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:19:35 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: <4C39EF17.7040206@jollans.com> On 07/11/2010 05:59 PM, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggests that this is done to make sure that > the programmer understands that the list is being modified in place, Yes! > but that rules out constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() No! you can either approach this by imperatively modifying a list in-place: L = [1,2,3,4] L.reverse() L.append([]) L.reverse() Or you can use a more functional style: L2 = reversed(reversed([1,2,3,4]) + [[]]) (or ([1,2,3,4][::-1]+[[]])[::-1], if you like that kind of thing) Imagine list.reverse and list.append *did* return self: L1 = [1,2,3,4] L2 = L1.reverse().append([]).reverse() would you expect, after this code, that (L1 == L2) and (L1 is L2)? I think it would surprise a lot of people. Better clearly separate modifying an object and functionally processing an object. Cheers Thomas From nathan.alexander.rice at gmail.com Sun Jul 11 12:28:05 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sun, 11 Jul 2010 12:28:05 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) Though TBH sometimes get annoyed at this behavior myself. There are a lot of people who are very vocal in support of returning none, and it makes sense in some ways. Since reversed returns an iterator though, it makes this code horrible and unreadable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Sun Jul 11 12:31:39 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:31:39 +0200 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: <4C39F1EB.10006@jollans.com> On 07/11/2010 07:44 AM, rantingrick wrote: > On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton > wrote: >> source at:http://github.com/lkcl/grailbrowser >> >> $ python grail.py (note the lack of "python1.5" or "python2.4") >> >> conversion of the 80 or so regex's to re has been carried out. >> entirely successfully or not is a matter yet to be determined. always >> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >> with a browser from 11+ years ago, it still cannot be resisted as >> grail is the only working graphical web browser in the world written >> in pure python [pybrowser is still in development, stalled]. >> >> l. > > Congratulations on this effort Luke. However you know what project i > would really like to see the community get around? ...dramatic pause > here... a cross platform Python file browser! Yes i know there are > tons of them out there already and Python is a bit slow, but i think > it would be useful to many peoples. Cross platform file manager. Hmm. Does "cross platform" involve UNIX and something that isn't UNIX, say, Windows? Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't be any good. The UNIX and Windows concepts of "file system" are similar enough for most programs not to care too much, but for something like a file manager, that works intimately with the file system, trying to support both UNIX and Windows is NOT a good idea. If you stick to common functionality, the program will be rather useless on both systems. Yes, you could *browse* the file system alright, but that's about it. If you attempt to be full-featured, keeping it in one code base, let alone in one user interface, is destined to be a nightmare and induce suicides. The above might have been very slightly exaggerated. Cheers! Thomas From ritchy_gato at hotmail.com Sun Jul 11 12:39:07 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Sun, 11 Jul 2010 09:39:07 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> On 11 jul, 13:28, Johan Gr?nqvist wrote: > 2010-07-11 02:12, Ritchy lelis skrev: > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > About the plot draw it's a curve that it's a set of points wich it's > > the result of the comput of the Vref and Vi together. I don't know if > > i had to make a break instruction (like in other's languages) after > > the "If" instructions if i want the else-condition to be executed? ... > > (do you have some sujestions?) > > I would have expected a code structure similar to this: > > (NOTE: This is a very inefficient solution, and not the one suggested > earlier, but it is closer to the code snippet you posted originally, and > it does produce a plot.) > > ---------------------- > import numpy as np > import matplotlib.pyplot as plt > Vref = np.linspace(1,20, 100) > Vi = np.linspace(1,10,100) > > for ref in Vref: # Loop over Vref and Vi > ? ? ?for i in Vi: > ? ? ? ? ?if ?i > ref/4: # Compute V0 > ? ? ? ? ? ? ?V0 = 2*i-ref > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > ? ? ? ? ? ? ?V0 = 2*i > ? ? ? ? ?elif i < -ref/4: > ? ? ? ? ? ? ?V0 = 2*i+ref > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > plt.show() # Display the plot in a window > ---------------------- > > > Anyway i have a picture of a tuturial that i found but in this forum i > > can't post it. That pic would show what a really want... > > Can you give a link? > > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > y-axis. > > To me this sound like you want to make a 3D-plot, as there is the > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > > As i said, i have a good 2 pic of a doc that has the information about > > this ADC that i'm developing. > > I looked on wikipedia > , and saw some > figures. Is any of those similar to what you look for? > > I see that they have (Vi - Vref) on the x-axis, and the computed value > on the y-axis. > > Regards > > Johan Hi Yes those fig look's familiar to me but for now the objective its to get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). I found in http://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF there are some fig and explanations on page's 9-13. Can you take a look there please? Also you can take a look in http://www.maxim-ic.com/app-notes/index.mvp/id/1023 (I think there it?s more information than the first link i gave you). I'll be waiting for sujestions. Thank's From thomas at jollans.com Sun Jul 11 12:39:41 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 18:39:41 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: Message-ID: <4C39F3CD.1020408@jollans.com> On 07/11/2010 06:28 PM, Nathan Rice wrote: > Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) > > Though TBH sometimes get annoyed at this behavior myself. There are a > lot of people who are very vocal in support of returning none, and it > makes sense in some ways. Since reversed returns an iterator though, it > makes this code horrible and unreadable. > ah yes, forgot about that nuance. casting reversed to list. Still, there is slicing. From python at bdurham.com Sun Jul 11 12:51:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 11 Jul 2010 12:51:28 -0400 Subject: Possible to create a read-only complex object? Message-ID: <1278867088.27525.1384321763@webmail.messagingengine.com> I have a complex object with attributes that contain lists, sets, dictionaries, and other objects. The lists and dictionaries may themselves contain complex objects. I would like to provide a read-only version of this type of object for other developers to query for reporting. Is there a way to prevent other developers from changing the attributes of my complex and nested object? In researching this question, I have identified __setattr__ and __delattr__ as possible ways to prevent changes to simple attributes, but I don't believe these magic methods will prevent others from fiddling with attributes containing lists and dictionaries or the contents of these lists and dictionaries. Another idea I had was to create a wrapper object to proxy all access to the original object. Is there a generic reciepe for this type of wrapper? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Sun Jul 11 12:57:02 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 09:57:02 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <4C39F1EB.10006@jollans.com> References: <4C39F1EB.10006@jollans.com> Message-ID: <4C39F7DE.50409@ixokai.io> On 7/11/10 9:31 AM, Thomas Jollans wrote: > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't > be any good. The UNIX and Windows concepts of "file system" are similar > enough for most programs not to care too much, but for something like a > file manager, that works intimately with the file system, trying to > support both UNIX and Windows is NOT a good idea. Indeed so. And you can't lump the Mac in with "UNIX" here, even though it really is UNIX at the foundation, because there's some very fundamental differences between HFS+ (and some other details that are higher level) and more traditional unix FS's. Not to mention that the Mac FS situation is slightly schitzo since it has two very different ways at looking and treating the files, the posix way and the Foundation way... and users think more in terms of the latter, usually. At least less sophisticated users. You can't do a cross-platform file manager without either doing a huge amount of work exposing each platform separately-- essentially getting separate codebases for each-- or doing a least common denominator situation, at which point I boggle: why the hell did you bother to begin with? Even Finder is better then that, let alone windows' Explorer. Even if you did the former... what the hell is the point, still? What real problem needs solving here that people should drop something and rally behind*? -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ (*): I do not argue that a non-default file manager on an OS might be a great thing. I use Path Finder on the mac and have been very pleased with it for years, and consider its purchase money very well spent. Its hands-down the absolute best file management tool ever done, in my opinion. But really. When I'm using windows (or ubuntu), the only thing I miss is the drop stack(**). I'd *almost* consider a bare-bones LCD file manager which brought only a drop stack to windows and linux to be worth the effort-- except then I'd keep having to switch over to an entirely different program whenever I wanted to do permissions, since Windows and Linux have /completely/ different permission models. (**): The drop stack is a little corner of the window that you can drag files onto. Then drag more files onto. Then drag more files onto. Then you can navigate to another part of the system, and drag files off of said stack, in a LIFO manner, moving them as a result of this action. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From solipsis at pitrou.net Sun Jul 11 13:21:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 11 Jul 2010 19:21:25 +0200 Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <20100711192125.02c4f3b0@pitrou.net> On Sun, 11 Jul 2010 08:59:06 -0700 (PDT) dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggests that this is done to make sure that > the programmer understands that the list is being modified in place, > but that rules out constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() > I want to prepend an empty list to [1,2,3,4]. This is just a toy > example, since I can always do that with [[]]+[1,2,3,4]. >>> x = [1,2,3,4] >>> y = [5,6] >>> x[:0] = y >>> x [5, 6, 1, 2, 3, 4] From python at mrabarnett.plus.com Sun Jul 11 13:23:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 18:23:21 +0100 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <4C39FE09.5030609@mrabarnett.plus.com> rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 > > If we would have adopted proper naming conventions from dios numero > uno all this nonsense would be rectified! Str, Float, List, Range, > etc, etc. You think Python 3000 was a hump to climb over just wait for > Python 4000. > > Just thoughts. If you're so unhappy with Python, why don't you create your own language. I suggest the name "Rantthon". From python at mrabarnett.plus.com Sun Jul 11 13:38:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 18:38:53 +0100 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4C39EF17.7040206@jollans.com> References: <4C39EF17.7040206@jollans.com> Message-ID: <4C3A01AD.4030209@mrabarnett.plus.com> Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: >> Why doesn't python's list append() method return the list itself? For >> that matter, even the reverse() and sort() methods? >> I found this link (http://code.google.com/edu/languages/google-python- >> class/lists.html) which suggests that this is done to make sure that >> the programmer understands that the list is being modified in place, > > Yes! > >> but that rules out constructs like: >> ([1,2,3,4].reverse()+[[]]).reverse() > > No! > > you can either approach this by imperatively modifying a list in-place: > > L = [1,2,3,4] > L.reverse() > L.append([]) > L.reverse() > [snip] If you want to prepend an empty list in-place, use the .insert method: L = [1,2,3,4] L.insert(0, []) From wherespythonmonks at gmail.com Sun Jul 11 13:48:05 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sun, 11 Jul 2010 13:48:05 -0400 Subject: Easy questions from a python beginner Message-ID: I'm an old Perl-hacker, and am trying to Dive in Python. I have some easy issues (Python 2.6) which probably can be answered in two seconds: 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>> True and print "It is true!" I found a nice work-around using eval(compile(.....,"","exec"))... Seems ugly to this Perl Programmer -- certainly Python has something better? 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y = 7; swap(x,y);" given x=7,y=3?? (I want to use Perl's Ref "\" operator, or C's &). (And if I cannot do this [other than creating an Int class], is this behavior limited to strings, ?tuples, and numbers) 3. ?Why might one want to store "strings" as "objects" in numpy arrays? ?(Maybe they wouldn't)? 4. ?Is there a way for me to make some function-definitions explicitly module-local? (Actually related to Q3 below: Is there a way to create an anonymous scope?) 5. Is there a way for me to introduce a indention-scoped variables in python? See for example: http://evanjones.ca/python-pitfall-scope.html 6. ?Is there a Python Checker that enforces?Strunk and White and is bad English grammar anti-python? ?(Only half joking) http://www.python.org/dev/peps/pep-0008/ Thanks, W From dhruvbird at gmail.com Sun Jul 11 14:07:46 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Sun, 11 Jul 2010 11:07:46 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> On Jul 11, 9:19?pm, Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: > > > Why doesn't python's list append() method return the list itself? For > > that matter, even the reverse() and sort() methods? > > I found this link (http://code.google.com/edu/languages/google-python- > > class/lists.html) which suggests that this is done to make sure that > > the programmer understands that the list is being modified in place, > > Yes! > > > but that rules out constructs like: > > ([1,2,3,4].reverse()+[[]]).reverse() > > No! > > you can either approach this by imperatively modifying a list in-place: > > L = [1,2,3,4] > L.reverse() > L.append([]) > L.reverse() > > Or you can use a more functional style: > > L2 = reversed(reversed([1,2,3,4]) + [[]]) Okay, but this assumes that I have reversed/sorted/etc... type of functions for all member functions that mutate the container. Also, as Nathan mentioned, reversed returns an iterator, whereas sorted returns a list. This asymmertic behaviour is a bit unnerving. > > (or ([1,2,3,4][::-1]+[[]])[::-1], if you like that kind of thing) > > Imagine list.reverse and list.append *did* return self: > > L1 = [1,2,3,4] > L2 = L1.reverse().append([]).reverse() > > would you expect, after this code, that (L1 == L2) and (L1 is L2)? I > think it would surprise a lot of people. Better clearly separate > modifying an object and functionally processing an object. I think this is a fair call. Honestly, I wouldn't expect them to be the same. However, there are cases when I want to be able to write down my intent in one line. Much like f(g(h(x))). On a side note, is there any other way to append to a list using slices (apart from the one below): x[len(x):len(x)] = [item to append] And while we are talking about python here, why does this statement: y = x[:0] = [100] behave the way it does? I mean everything except for the last value is assigned to the last value rather than the assignments following the chain and every item getting its succeeding item's reference? Regards, -Dhruv. From thomas at jollans.com Sun Jul 11 14:08:26 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 20:08:26 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A089A.8040900@jollans.com> On 07/11/2010 07:48 PM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" prior to Python 3.0, print is a statement, not an expression, which means that it's rather unflexible. In Python 3.x, print is a function, and you can use it as one: Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> True and print('It is true!') It is true! >>> > > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? Either use good old if: if True: print 'It is true!' or use a function instead of the print statement: def print_(s): print s True and print_("It is true!") > > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) You can't. A function cannot modify the caller's namespace. "x" and "y" are just names, not pointers you can edit directly. But look at this: >>> x = 1 >>> y = 2 >>> x,y = y,x >>> x 2 >>> y 1 >>> > 4. Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous scope?) Do you mean have the function visible inside the module, but not to the importer? Well, you could "del thefunc" at the end of the module, but then you won't be able to access it from within other functions. You could in principle create a function, pass it as a default argument to every function that uses it, and then delete it. But that's just silly. > > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html No. exception: nested functions. if you really want, you can always del variables after use. > > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ Huh? - Thomas From duncan.booth at invalid.invalid Sun Jul 11 14:17:49 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Jul 2010 18:17:49 GMT Subject: Easy questions from a python beginner References: Message-ID: wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>> True and print "It is true!" > > I found a nice work-around using > eval(compile(.....,"","exec"))... Seems ugly to this Perl > Programmer -- certainly Python has something better? In Python 2.x print is a statement. If you really wanted you could do: True and sys.write("It is true!\n") In Python 3 you can do this: True and print("It is true!") though I can't think of any situations where this would be better that just writing: if somecondition: print "whatever" > > 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >= 7; swap(x,y);" given x=7,y=3?? Why use a function? x, y = y, x > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > ?tuples, and numbers) If you want to use perl's operators I suggest you use perl. > > 3. ?Why might one want to store "strings" as "objects" in numpy > arrays? ?(Maybe they wouldn't)? Why would one want to write incomprehensible questions? > > 4. ?Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous > scope?) Not really. > > 5. Is there a way for me to introduce a indention-scoped variables in > python? See for example: http://evanjones.ca/python-pitfall-scope.html No. The page you reference effectively says 'my brain is used to the way Java works'. *My* brain is used to the way Python works. Who is to say which is better? > > 6. ?Is there a Python Checker that enforces?Strunk and White and is > bad English grammar anti-python? ?(Only half joking) > http://www.python.org/dev/peps/pep-0008/ > pylint will do quite a good job of picking over your code. Most people don't bother. From torriem at gmail.com Sun Jul 11 14:18:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Sun, 11 Jul 2010 12:18:54 -0600 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A0B0E.3030406@gmail.com> On 07/11/2010 11:48 AM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" This works in Python 3, or 2.6 and later with the print function: >>> True and print("It's true!") That said, this is one particular perl-ism that most python programmers don't really like. I think most python programmers prefer: if True: print "It's true!" Other perlisms like "something or die" are also to be avoided in python generally. Just state what you want: if not something: sys.exit(1) > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? Seems ugly even to Python programmers! And potentially dangerous. Just use an if statement. It's cleaner, more readable, and explicitly declares what you want. > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) I'm not sure you can. Python "variables" are names that are bound to objects. When you pass an object to a function, that object is bound to the names declared in the function. Python passes things by object, not by reference. Names are merely for convenience when accessing an object. If you want a function to be able to modify an object you have to make sure that object is mutable, or if it's not, pass it in a list (which is mutable). You probably could do something like this: (x,y) = (y,x) Seems pretty clean to me, cleaner than using a function to swap things. > 3. Why might one want to store "strings" as "objects" in numpy > arrays? (Maybe they wouldn't)? > > 4. Is there a way for me to make some function-definitions explicitly > module-local? The standard way is to declare them with a name beginning with a leading _ (underscore) to indicate that they are private and should not be accessed by others. Someone could access them if they want, though; python obviously lets programmers shoot themselves in the foot if they want. > (Actually related to Q3 below: Is there a way to create an anonymous scope?) Not that I know of. A nested function usually does enough for me. > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html Perhaps nest a function and call it? > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ From dickinsm at gmail.com Sun Jul 11 14:19:28 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 11 Jul 2010 11:19:28 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> Message-ID: <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> On Jul 11, 6:38?am, rantingrick wrote: > Seems kinda dumb to build a tuple just so a conditional wont blow > chunks! This integer bool-ing need to be fixed right away! Okay. What fix do you propose? Would your fix maintain the identity "0 == False"? For bonus points, explain how you'd deal with any backwards compatibility problems that your fix introduces. Have you considered forking Python? That may be the way forward here. -- Mark From me+list/python at ixokai.io Sun Jul 11 14:37:45 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 11:37:45 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A0F79.8070502@ixokai.io> On 7/11/10 10:48 AM, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. Why is it that I cannot use print in booleans?? e.g.: >>>> True and print "It is true!" Because print is a statement. Statements have to start lines. If you want to do this, use a function-- in Python 2.6 either via "from __future__ import print_function" or writing your own, even if its just a very thing wrapper around the print statement. > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) You can't do that*. Its not limited to any certain type of objects. You can't manipulate calling scopes: if you really want to do that sort of explicit namespace mangling, use dictionaries (or objects, really) as the namespace to mangle and pass them around. > 3. Why might one want to store "strings" as "objects" in numpy > arrays? (Maybe they wouldn't)? I don't use numpy. No idea. > 4. Is there a way for me to make some function-definitions explicitly > module-local? In what sense? If you prepend them with an underscore, the function won't be imported with "from x import *". You can also explicitly control what is imported in that way with a module-level __all__ attribute. Now that won't stop someone from doing "import x" and "x._your_private_function" but Python doesn't believe in enforicng restrictions. > (Actually related to Q3 below: Is there a way to create an anonymous scope?) No. You can create a limited anonymous function with lambda, but note it takes only an expression-- no statements in it. > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example: http://evanjones.ca/python-pitfall-scope.html No. Python only has three scopes historically; local, global, and builtin. Then post-2.2(ish, I forget) limited nested scoping -- but only with nested functions, and you can't (until Python 3) re-bind variables in outer scopes (though you can modify them if they are mutable objects). Python's scoping is very basic (we generally think this is a good thing; others are never happy with it) and is not fully lexical scoped. > 6. Is there a Python Checker that enforces Strunk and White and is > bad English grammar anti-python? (Only half joking) > http://www.python.org/dev/peps/pep-0008/ Check out pylint and/or pychecker, which do various style-based checking. If you're asking for something else, I can't pierce your sarcasm to figure out what. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * Yes, I know its actually possible, to manipulate outer/calling scopes with frame hacking. This is dangerous / bad / an implementation detail that one should not rely on or use, generally speaking. If you need to do this you're writing Java or Perl or C in Python, instead of writing Python in Python, so are probably doing all kinds of things that are slow / bad / dangerous / just not taking advantage of Python's strengths. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From wherespythonmonks at gmail.com Sun Jul 11 14:45:46 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sun, 11 Jul 2010 14:45:46 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: Thanks for your answers -- it is much appreciated. On #1: I had very often used chained logic with both logging and functional purposes in Perl, and wanted to duplicate this in Python. "It reads like english" Using the print_ print wrapper works for me. Follow-up: Is there a way to define compile-time constants in python and have the bytecode compiler optimize away expressions like: if is_my_extra_debugging_on: print ... when "is_my_extra_debugging" is set to false? I'd like to pay no run-time penalty for such code when extra_debugging is disabled. On #2: My point regarding the impossibility of writing the swap function for ints is to explicitly understand that this isn't possible, so as not to look for solutions along those lines when trying to write python code. On #3: Sorry this is confusing, but I was browsing some struct array code from numpy, in which one of the columns contained strings, but the type information, supplied in numpy.array's dtype argument, specified the type as a an "object" not a string. Just wondering why one would do that. On #4: So there are some hacks, but not something as easy as "import unimportable" or an @noexport decorator. The underscore works, so does "del". On #5: Nesting the function was actually what I was thinking of doing, but alas, I cannot modify outer-scope variables within a function, and of course, I don't want to use globals. On #6: Always trying to improve my writing -- and I thought it was cute that Guido tries to encourage this as well. I am programmer who likes to scope off variables as much as possible (I believe in minimal state). The following is an example of what I am trying to protect against: http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters Will try to avoid namespace mangling until next week. Thanks again, W On Sun, Jul 11, 2010 at 2:17 PM, Duncan Booth wrote: > wheres pythonmonks wrote: > >> I'm an old Perl-hacker, and am trying to Dive in Python. ?I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>>> True and print "It is true!" >> >> I found a nice work-around using >> eval(compile(.....,"","exec"))... Seems ugly to this Perl >> Programmer -- certainly Python has something better? > > In Python 2.x print is a statement. If you really wanted you could do: > > ? True and sys.write("It is true!\n") > > In Python 3 you can do this: > > ? True and print("It is true!") > > though I can't think of any situations where this would be better that just > writing: > > ? if somecondition: print "whatever" > >> >> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >>= 7; swap(x,y);" given x=7,y=3?? > > Why use a function? > > ? x, y = y, x > >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> ?tuples, and numbers) > > If you want to use perl's operators I suggest you use perl. > >> >> 3. ?Why might one want to store "strings" as "objects" in numpy >> arrays? ?(Maybe they wouldn't)? > > Why would one want to write incomprehensible questions? > >> >> 4. ?Is there a way for me to make some function-definitions explicitly >> module-local? >> (Actually related to Q3 below: Is there a way to create an anonymous >> scope?) > > Not really. > >> >> 5. Is there a way for me to introduce a indention-scoped variables in >> python? See for example: http://evanjones.ca/python-pitfall-scope.html > > No. The page you reference effectively says 'my brain is used to the way > Java works'. *My* brain is used to the way Python works. Who is to say > which is better? > >> >> 6. ?Is there a Python Checker that enforces?Strunk and White and is >> bad English grammar anti-python? ?(Only half joking) >> http://www.python.org/dev/peps/pep-0008/ >> > pylint will do quite a good job of picking over your code. Most people > don't bother. > -- > http://mail.python.org/mailman/listinfo/python-list > From me+list/python at ixokai.io Sun Jul 11 15:00:52 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 12:00:52 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A14E4.4040902@ixokai.io> On 7/11/10 11:45 AM, wheres pythonmonks wrote: > Follow-up: > Is there a way to define compile-time constants in python and have the > bytecode compiler optimize away expressions like: > > if is_my_extra_debugging_on: print ... > > when "is_my_extra_debugging" is set to false? I'd like to pay no > run-time penalty for such code when extra_debugging is disabled. Any code wrapped in a __debug__ guard is utterly ommitted if you run Python with the -O option. That, and asserts go away. > On #2: My point regarding the impossibility of writing the swap > function for ints is to explicitly understand that this isn't > possible, so as not to look for solutions along those lines when > trying to write python code. Its impossible because Python's calling and namespace semantics simply don't work like that. There's no references in the traditional sense, because there's no variables-- boxes that you put values in. There's just concrete objects. Objects are passed into the function and given new names; that those objects have names in the enclosing scope is something you don't know, can't access, and can't manipulate.. even the objects don't know what names they happen to be called. Check out http://effbot.org/zone/call-by-object.htm > On #3: Sorry this is confusing, but I was browsing some struct array > code from numpy, in which one of the columns contained strings, but > the type information, supplied in numpy.array's dtype argument, > specified the type as a an "object" not a string. Just wondering why > one would do that. Strings are objects. I don't use numpy, btu I'd assume "object" would basically mean, "anything can go here", as everything is an object. > On #5: Nesting the function was actually what I was thinking of doing, > but alas, I cannot modify outer-scope variables within a function, and > of course, I don't want to use globals. You can modify outer-scope objects: if they are mutable. I.e., a dictionary. What you can't do is modify outer *scopes*, the namespaces. You can't re-bind a new/different object to a certain name in an outer scope. > I am programmer who likes to scope off variables as much as possible > (I believe in minimal state). That's a fine and nice goal. In Python your only real tool for this is to break things up into more logical functions. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Sun Jul 11 15:09:57 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 11 Jul 2010 21:09:57 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A1705.6050603@jollans.com> On 07/11/2010 08:45 PM, wheres pythonmonks wrote: > Thanks for your answers -- it is much appreciated. > > On #1: I had very often used chained logic with both logging and > functional purposes in Perl, and wanted to duplicate this in Python. > "It reads like english" Using the print_ print wrapper works for me. > > Follow-up: > Is there a way to define compile-time constants in python and have the > bytecode compiler optimize away expressions like: > > if is_my_extra_debugging_on: print ... > > when "is_my_extra_debugging" is set to false? I'd like to pay no > run-time penalty for such code when extra_debugging is disabled. no. > On #3: Sorry this is confusing, but I was browsing some struct array > code from numpy, in which one of the columns contained strings, but > the type information, supplied in numpy.array's dtype argument, > specified the type as a an "object" not a string. Just wondering why > one would do that. No expert on numpy, but maybe storing object references is cheaper than storing strings here ? > > On #5: Nesting the function was actually what I was thinking of doing, > but alas, I cannot modify outer-scope variables within a function, and > of course, I don't want to use globals. yes you can. Well, at least since whenever the "nonlocal" keyword was introduced (recent, might be 3.x only) Or you can wrap what you want to change in a dict or list. > I am programmer who likes to scope off variables as much as possible > (I believe in minimal state). > > The following is an example of what I am trying to protect against: > http://stackoverflow.com/questions/938429/scope-of-python-lambda-functions-and-their-parameters On the other hand, python scoping and namespace rules, while they may be different to those in other languages, are nice and simple. > Will try to avoid namespace mangling until next week. Cheers - Thomas From alf.p.steinbach+usenet at gmail.com Sun Jul 11 15:37:28 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 11 Jul 2010 21:37:28 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * Stephen Hansen, on 11.07.2010 21:00: > On 7/11/10 11:45 AM, wheres pythonmonks wrote: >> Follow-up: >> Is there a way to define compile-time constants in python and have the >> bytecode compiler optimize away expressions like: >> >> if is_my_extra_debugging_on: print ... >> >> when "is_my_extra_debugging" is set to false? I'd like to pay no >> run-time penalty for such code when extra_debugging is disabled. > > Any code wrapped in a __debug__ guard is utterly ommitted if you run > Python with the -O option. That, and asserts go away. > >> On #2: My point regarding the impossibility of writing the swap >> function for ints is to explicitly understand that this isn't >> possible, so as not to look for solutions along those lines when >> trying to write python code. > > Its impossible because Python's calling and namespace semantics simply > don't work like that. There's no references in the traditional sense, > because there's no variables-- boxes that you put values in. There's > just concrete objects. Objects are passed into the function and given > new names; that those objects have names in the enclosing scope is > something you don't know, can't access, and can't manipulate.. even the > objects don't know what names they happen to be called. > > Check out http://effbot.org/zone/call-by-object.htm Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like Java in this respect, that's all; neither Java nor Python support 'swap'. Of course there are variables, that's why the docs call them variables. We've had this discussion before and I know from that that it is a religious issue with a small subset of the Python community, where reason, facts, logic does not apply and is not even recognized as such. So be it. So I'm not out to convince you or other of that sub-community, or trying to reason with you folks on this issue (futile, and generates flames pretty fast), but I do not want newbies brainwashed into that non-reasoning nonsense pure faith religion. For what it's worth, I'm sure that the effbot.org author, whose pages are otherwise quite technically meaningful & useful, in this case, after the flame war with some Java folks, decided that technical accuracy just wasn't worth it. So, I believe, he punted, which is an eminently rational choice when one's goals require acceptance in a society dominated by a religious clique. And just as I'm not out to engage you in any debate on this issue (futile), neither am I calling you irrational. Perhaps your choice is the same as that author's. Cheers, - Alf -- blog at From dkelley21 at gmail.com Sun Jul 11 16:18:39 2010 From: dkelley21 at gmail.com (dk) Date: Sun, 11 Jul 2010 13:18:39 -0700 (PDT) Subject: Getting started with python on macintosh snow leopard with mysql - need help Message-ID: I have been going round and round trying to configure python 2.6 running on osx 10.6.x to work with mySQL 5.1.44. Python seems to work ... i have an installation of mysql 5.1.44 running and have used it in conjunction for other php/apache projects. I want to learn python and think i need a better database then mysql lite that installs with the web2py frame work, so my quest to connect to mysql or postgres began. I seem to be stuck stuck getting mySQLdb drivers installed. I down loaded python 2.6.5 from the python site and MySQL-python-1.2.3 from the my sql site. I have worked past numerous errors by i now get the errors below when i try to compile. -- some background that might help anyone kind enough to have read this far and who might be inclined to take pitty -- I have (tried) to use macports to install setuptools (which MySQL- python-1.2.3 says it needs). MacPorts has put tons of stuff in /opt/local ... so i am not sure i am using this tool the way its intended. this could all be as simple as adding some path declarations in the right place but where? lots of the post i have seen on the subject talk about 32/64 installation ... it makes sense that you might need to be consistent in getting your components to work together, but i am not sure how i tell of the various parts i have install which and how they were compiled. whereis python display /usr/bin/python python -v spits out lots ... but here is a sample: # /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ encodings/utf_8.pyc matches /Library/Frameworks/Python.framework/ Versions/2.6/lib/python2.6/encodings/utf_8.py import encodings.utf_8 # precompiled from /Library/Frameworks/ Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.pyc Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin when i try to compile mysql-python-1.2.3 i get the following error returned from python setup.py build ----- building '_mysql' extension gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL In file included from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/unicodeobject.h:4, from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/Python.h:85, from pymemcompat.h:10, from _mysql.c:29: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory In file included from _mysql.c:36: /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" redefined In file included from /Library/Frameworks/Python.framework/Versions/ 2.6/include/python2.6/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ pyconfig.h:808:1: warning: this is the location of the previous definition error: command 'gcc-4.0' failed with exit status 1 From john at castleamber.com Sun Jul 11 16:50:50 2010 From: john at castleamber.com (John Bokma) Date: Sun, 11 Jul 2010 15:50:50 -0500 Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <87aapxyc7p.fsf@castleamber.com> Thomas Jollans writes: > On 07/11/2010 07:44 AM, rantingrick wrote: >> On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton >> wrote: >>> source at:http://github.com/lkcl/grailbrowser >>> >>> $ python grail.py (note the lack of "python1.5" or "python2.4") >>> >>> conversion of the 80 or so regex's to re has been carried out. >>> entirely successfully or not is a matter yet to be determined. always >>> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >>> with a browser from 11+ years ago, it still cannot be resisted as >>> grail is the only working graphical web browser in the world written >>> in pure python [pybrowser is still in development, stalled]. >>> >>> l. >> >> Congratulations on this effort Luke. However you know what project i >> would really like to see the community get around? ...dramatic pause >> here... a cross platform Python file browser! Yes i know there are >> tons of them out there already and Python is a bit slow, but i think >> it would be useful to many peoples. > > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't > be any good. The UNIX and Windows concepts of "file system" are similar > enough for most programs not to care too much, but for something like a > file manager, that works intimately with the file system, trying to > support both UNIX and Windows is NOT a good idea. Can't think of why not. Of course not all operations are shared by each OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean that on Windows I can't make a file only readable by me. Just give me the Windows security options on Windows, and chmod on *nix and I would be very happy. Especially if all can be done via a context menu a la RISC OS. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From pavlovevidence at gmail.com Sun Jul 11 16:52:34 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jul 2010 13:52:34 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: On Jul 11, 10:48?am, wheres pythonmonks wrote: > I'm an old Perl-hacker, and am trying to Dive in Python. Welcome to the light. >?I have some > easy issues (Python 2.6) > which probably can be answered in two seconds: > > 1. ?Why is it that I cannot use print in booleans?? ?e.g.: > > >>> True and print "It is true!" > > I found a nice work-around using eval(compile(.....,"","exec"))... > Seems ugly to this Perl Programmer -- certainly Python has something better? I'll repeat other people's sentiments: if you drop nothing else from your perl habits, drop this one. > 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's &). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > ?tuples, and numbers) Can't do it, but you can get reference-like behavior if you don't mind a level of indirection. For example: def swap(x,y): t = y[0] y[0] = x[0] x[0] = t a = [1] b = [2] swap(a,b) There's no reason to do this for a swap() function, as you've already seen. But it is sometimes handy for other things. (This includes certain idioms involving regualar expression that are common in Perl. Perl uses some special semantics when performing regexp searches that allow automatic binding of match results. Python doesn't, so in some cases it's helpful to define an object you can mutate to store that information.) In the more general sense, Python functions and methods that mutate the object they operate on are pretty common. > 3. ?Why might one want to store "strings" as "objects" in numpy > arrays? ?(Maybe they wouldn't)? numpy is a library designed mainly to store numerical data, with some advanced slicing operations and other cool stuff like multdimensionality. Some people, however, want to use the cool slicing operations on arrays of Python objects, so numpy has a storage mode for arbitrary Python objects. (If you're wondering why they use object instead of a character type, it's because rows of such an array are fixed-length strings. Main reason to use those is to interface with Fortran string arrays, or maybe to simulate crossword puzzles or something.) > 4. ?Is there a way for me to make some function-definitions explicitly > module-local? > (Actually related to Q3 below: Is there a way to create an anonymous scope?) No. The (loose) convention is to define local or private functions with a leading underscore to label them as "intended for internal use only". > 5. Is there a way for me to introduce a indention-scoped variables in python? > See for example:http://evanjones.ca/python-pitfall-scope.html Yes, define a nested function. In Python 2 it's limited since you cannot rebind variables in the surrounding scope; that's possible in Python 3, though. > 6. ?Is there a Python Checker that enforces?Strunk and White and is > bad English grammar anti-python? ?(Only half joking)http://www.python.org/dev/peps/pep-0008/ There's a few, PyChecker and PyLint get mentioned a lot. I used to use them until I noticed that it never actually caught anything (except stuff I didn't care about like using "id" as a variable name). Carl Banks From pavlovevidence at gmail.com Sun Jul 11 17:03:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 11 Jul 2010 14:03:52 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <98f2d8c8-09f5-4d72-9ecb-94c186f45f7c@z15g2000prn.googlegroups.com> On Jul 11, 11:45?am, wheres pythonmonks wrote: > On #4: ?So there are some hacks, but not something as easy as "import > unimportable" or an @noexport decorator. ?The underscore works, so > does "del". Careful. If you have a module that looks like this: def foo(): bar() def bar(): print "hello" del bar # bar is an internal function It won't work; foo will raise NameError on bar if you try that. However, del is useful to clean up code you run at module import time, for example: squares = [] for i in xrange(101): squares.append(i*i) del i Carl Banks From news1234 at free.fr Sun Jul 11 17:08:31 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 23:08:31 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4c3a32cf$0$14947$426a34cc@news.free.fr> Carl Banks wrote: > On Jul 11, 10:48 am, wheres pythonmonks > wrote: >> I'm an old Perl-hacker, and am trying to Dive in Python. > > Welcome to the light. > > >> I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. Why is it that I cannot use print in booleans?? e.g.: >> >>>>> True and print "It is true!" >> I found a nice work-around using eval(compile(.....,"","exec"))... >> Seems ugly to this Perl Programmer -- certainly Python has something better? > > I'll repeat other people's sentiments: if you drop nothing else from > your perl habits, drop this one. > > >> 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y >> = 7; swap(x,y);" given x=7,y=3?? >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> tuples, and numbers) > > Can't do it, but you can get reference-like behavior if you don't mind > a level of indirection. For example: > > def swap(x,y): > t = y[0] > y[0] = x[0] > x[0] = t > > a = [1] > b = [2] > swap(a,b) or def swap[x,y]: x[0],y[0] = y[0],x[0] From clp2 at rebertia.com Sun Jul 11 17:16:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 14:16:01 -0700 Subject: Easy questions from a python beginner In-Reply-To: <4c3a32cf$0$14947$426a34cc@news.free.fr> References: <4c3a32cf$0$14947$426a34cc@news.free.fr> Message-ID: On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote: > Carl Banks wrote: >> On Jul 11, 10:48 am, wheres pythonmonks >> wrote: >>> I'm an old Perl-hacker, and am trying to Dive in Python. >> >> Welcome to the light. >> >> >>> ?I have some >>> easy issues (Python 2.6) >>> which probably can be answered in two seconds: >>> >>> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>> >>>>>> True and print "It is true!" >>> I found a nice work-around using eval(compile(.....,"","exec"))... >>> Seems ugly to this Perl Programmer -- certainly Python has something better? >> >> I'll repeat other people's sentiments: if you drop nothing else from >> your perl habits, drop this one. >> >> >>> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >>> = 7; swap(x,y);" given x=7,y=3?? >>> (I want to use Perl's Ref "\" operator, or C's &). >>> (And if I cannot do this [other than creating an Int class], is this >>> behavior limited to strings, >>> ?tuples, and numbers) >> >> Can't do it, but you can get reference-like behavior if you don't mind >> a level of indirection. ?For example: >> >> def swap(x,y): >> ? ? t = y[0] >> ? ? y[0] = x[0] >> ? ? x[0] = t >> >> a = [1] >> b = [2] >> swap(a,b) > > or > def swap[x,y]: > ? ?x[0],y[0] = y[0],x[0] >>> def swap[x,y]: File "", line 1 def swap[x,y]: ^ SyntaxError: invalid syntax Cheers, Chris From news1234 at free.fr Sun Jul 11 17:18:16 2010 From: news1234 at free.fr (News123) Date: Sun, 11 Jul 2010 23:18:16 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3a32cf$0$14947$426a34cc@news.free.fr> Message-ID: <4c3a3518$0$9132$426a74cc@news.free.fr> Chris Rebert wrote: > On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote: >> Carl Banks wrote: >>> On Jul 11, 10:48 am, wheres pythonmonks >>> wrote: >>>> I'm an old Perl-hacker, and am trying to Dive in Python. >>> Welcome to the light. >>> >>> >>>> I have some >>>> easy issues (Python 2.6) >>>> which probably can be answered in two seconds: >>>> >>>> 1. Why is it that I cannot use print in booleans?? e.g.: >>>> >>>>>>> True and print "It is true!" >>>> I found a nice work-around using eval(compile(.....,"","exec"))... >>>> Seems ugly to this Perl Programmer -- certainly Python has something better? >>> I'll repeat other people's sentiments: if you drop nothing else from >>> your perl habits, drop this one. >>> >>> >>>> 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y >>>> = 7; swap(x,y);" given x=7,y=3?? >>>> (I want to use Perl's Ref "\" operator, or C's &). >>>> (And if I cannot do this [other than creating an Int class], is this >>>> behavior limited to strings, >>>> tuples, and numbers) >>> Can't do it, but you can get reference-like behavior if you don't mind >>> a level of indirection. For example: >>> >>> def swap(x,y): >>> t = y[0] >>> y[0] = x[0] >>> x[0] = t >>> >>> a = [1] >>> b = [2] >>> swap(a,b) >> or >> def swap[x,y]: >> x[0],y[0] = y[0],x[0] > >>>> def swap[x,y]: > File "", line 1 > def swap[x,y]: apologies: I meant def swap(x,y): x[0],y[0] = y[0],x[0] a = [1] b = [2] swap(a,b) From clp2 at rebertia.com Sun Jul 11 17:22:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 14:22:11 -0700 Subject: Possible to create a read-only complex object? In-Reply-To: <1278867088.27525.1384321763@webmail.messagingengine.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: On Sun, Jul 11, 2010 at 9:51 AM, wrote: > I have a complex object with attributes that contain lists, sets, > dictionaries, and other objects. The lists and dictionaries may themselves > contain complex objects. > > I would like to provide a read-only version of this type of object for other > developers to query for reporting. > > Is there a way to prevent other developers from changing the attributes of > my complex and nested object? Have you considered just making a deep copy of your object instead? That way, others could inspect the copy and mess with it all they want, without affecting the original. http://docs.python.org/library/copy.html#copy.deepcopy Cheers, Chris -- http://blog.rebertia.com From drsalists at gmail.com Sun Jul 11 18:13:54 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 11 Jul 2010 15:13:54 -0700 Subject: how to determine whether pathname1 is below bathname2 In-Reply-To: References: <4C39CC89.8070500@jollans.com> Message-ID: You could probably: cd to dir1 getcwd cd to dir2 getcwd repeat cd .. getcwd if getcwd == dir1's cwd, then under until at / cd to dir1 repeat cd .. getcwd if getcwd == dir2's cwd, then under until at / This should deal with symlinks and junctions, as long as you aren't worried about permissions issues on directories. On Sun, Jul 11, 2010 at 7:34 AM, Gelonida wrote: > Hi Thomas, > > Thomas Jollans wrote: > > On 07/11/2010 03:37 PM, Gelonida wrote: > >> ################################################# > >> import os > >> def is_below_dir(fname,topdir): > >> relpath = os.path.relpath(fname,topdir) > >> return not relpath.startswith('..'+os.sep) > >> > >> print is_below_dir(path1,path2) > >> ################################################# > >> The basic idea is, if the path name of path1 > >> relative to path2 does NOT start with '..', then > >> it must be below path2 > >> > >> > >> Does anybody see pitfalls with that solution? > >> Is there by any chance a function, that I overlooked, > >> which does already what I'd like to do? > > > > It probably won't work on Windows because it isolates volumes (drive > > letters). What does, for example, os.path.relpath do when > > you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two > > reasonably correct options: > Thanks, Indeed. different drives raise an ecception. > I could catch the ValueError and let it just return False > > > > > either raise an exception (there is no relative path) or return the > > absolute path, which doesn't start with .. > > > > On UNIX, the only potential problem I see is that it may or may not do > > what you expect when symlinks are involved somewhere. > > Also true. In my case I'd prefer it would not follow, but > it doesn't really matter. > > > So my function in order to be portable > had now to look like: > ################################################# > import os > def is_below_dir(fname,topdir): > try: > relpath = os.path.relpath(fname,topdir) > except ValueError: > return False > return not relpath.startswith('..'+os.sep) > > print is_below_dir(path1,path2) > ################################################# > > if I wanted to folow symlinks, then had to apply > os.path.realpath() on > fname AND on topdir > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at gmail.com Sun Jul 11 18:28:34 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Sun, 11 Jul 2010 15:28:34 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: On Jul 11, 5:16?pm, rantingrick wrote: > On Jul 11, 9:01?am, a... at pythoncraft.com (Aahz) wrote: > > > As usual, you would rather tell other people what to do instead of doing > > any work yourself. > > Dear God! My statement was intended to fetch responses like... > > ? "Hey, that sounds like a great idea" or \ > ? "Hey, lets get hacking on this". > > I am so sick of you people constantly accusing me of being lazy. You > don't even know me. Also i think you're really a bit jealous because i > have the brass cohones to initiate a coding project without your > express written permission. I will not allow myself to be brow beaten > by anyone! But why hijack someone else's announcement to do that? Congratulations alone would have been great. However good your intentions your message came across as "but it would really have been better if you had been doing something else instead...". All the best, Michael Foord -- http://www.voidspace.org.uk/ From rantingrick at gmail.com Sun Jul 11 18:36:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 15:36:52 -0700 (PDT) Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <569e34f0-4da0-49a9-a8d2-c23c4424daf0@j8g2000yqd.googlegroups.com> On Jul 11, 12:23?pm, MRAB wrote: > If you're so unhappy with Python, why don't you create your own > language. I suggest the name "Rantthon". Ah yes, then i can finally assume my worthy title of the "Ranting Dictator For Life"! ;-) From python at mrabarnett.plus.com Sun Jul 11 18:37:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 23:37:39 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A47B3.3060502@mrabarnett.plus.com> Alf P. Steinbach /Usenet wrote: > * Stephen Hansen, on 11.07.2010 21:00: >> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>> Follow-up: >>> Is there a way to define compile-time constants in python and have the >>> bytecode compiler optimize away expressions like: >>> >>> if is_my_extra_debugging_on: print ... >>> >>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>> run-time penalty for such code when extra_debugging is disabled. >> >> Any code wrapped in a __debug__ guard is utterly ommitted if you run >> Python with the -O option. That, and asserts go away. >> >>> On #2: My point regarding the impossibility of writing the swap >>> function for ints is to explicitly understand that this isn't >>> possible, so as not to look for solutions along those lines when >>> trying to write python code. >> >> Its impossible because Python's calling and namespace semantics simply >> don't work like that. There's no references in the traditional sense, >> because there's no variables-- boxes that you put values in. There's >> just concrete objects. Objects are passed into the function and given >> new names; that those objects have names in the enclosing scope is >> something you don't know, can't access, and can't manipulate.. even the >> objects don't know what names they happen to be called. >> >> Check out http://effbot.org/zone/call-by-object.htm > > Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python > works like Java in this respect, that's all; neither Java nor Python > support 'swap'. > > Of course there are variables, that's why the docs call them variables. > In Java a variable is declared and exists even before the first assignment to it. In Python a 'variable' isn't declared and won't exist until the first 'assignment' to it. From martin.hellwig at dcuktec.org Sun Jul 11 18:39:32 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 11 Jul 2010 23:39:32 +0100 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: On 07/11/10 04:59, Luke Kenneth Casson Leighton wrote: > source at: > http://github.com/lkcl/grailbrowser > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > conversion of the 80 or so regex's to re has been carried out. > entirely successfully or not is a matter yet to be determined. always > a hoot to try browsing http://www.bbc.co.uk or http://www.youtube.com > with a browser from 11+ years ago, it still cannot be resisted as > grail is the only working graphical web browser in the world written > in pure python [pybrowser is still in development, stalled]. > > l. Congrats! Are you planning to take over the world with grail and pyjs? :-) -- mph From python at mrabarnett.plus.com Sun Jul 11 18:55:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 11 Jul 2010 23:55:04 +0100 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <87aapxyc7p.fsf@castleamber.com> References: <87aapxyc7p.fsf@castleamber.com> Message-ID: <4C3A4BC8.1090106@mrabarnett.plus.com> John Bokma wrote: > Thomas Jollans writes: > >> On 07/11/2010 07:44 AM, rantingrick wrote: >>> On Jul 10, 10:59 pm, Luke Kenneth Casson Leighton >>> wrote: >>>> source at:http://github.com/lkcl/grailbrowser >>>> >>>> $ python grail.py (note the lack of "python1.5" or "python2.4") >>>> >>>> conversion of the 80 or so regex's to re has been carried out. >>>> entirely successfully or not is a matter yet to be determined. always >>>> a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com >>>> with a browser from 11+ years ago, it still cannot be resisted as >>>> grail is the only working graphical web browser in the world written >>>> in pure python [pybrowser is still in development, stalled]. >>>> >>>> l. >>> Congratulations on this effort Luke. However you know what project i >>> would really like to see the community get around? ...dramatic pause >>> here... a cross platform Python file browser! Yes i know there are >>> tons of them out there already and Python is a bit slow, but i think >>> it would be useful to many peoples. >> Cross platform file manager. Hmm. Does "cross platform" involve UNIX and >> something that isn't UNIX, say, Windows? >> Erm, no. No, no, no. It won't work. Well, it would work, but it wouldn't >> be any good. The UNIX and Windows concepts of "file system" are similar >> enough for most programs not to care too much, but for something like a >> file manager, that works intimately with the file system, trying to >> support both UNIX and Windows is NOT a good idea. > > Can't think of why not. Of course not all operations are shared by each > OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean > that on Windows I can't make a file only readable by me. Just give me > the Windows security options on Windows, and chmod on *nix and I would > be very happy. > On Windows the root folders of the different drives could be treated as subfolders of a 'root' folder. > Especially if all can be done via a context menu a la RISC OS. > Ah, RISC OS! I'd heard how user-friendly the Mac was, but when I was first introduced to the Mac (circa MacOS 8) I was very surprised that even it still used old-fashioned Open and Save dialog boxes with their own little file browsers like on a Windows PC instead of drag-and-drop like I'd become used to on RISC OS. And that menu bar not even at the top of the window but at the top of the _screen_! And the way that bringing one Finder window to the front brought _all_ the Finder windows in front of the other windows! I was distinctly underwhelmed... :-( From rantingrick at gmail.com Sun Jul 11 19:22:41 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 16:22:41 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> Message-ID: <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> On Jul 11, 1:19?pm, Mark Dickinson wrote: > Okay. ?What fix do you propose? ?Would your fix maintain the identity > "0 == False"? No because all integers should bool True. An integer is a value that IS NOT empty and IS NOT None. Therefore the only logical way to handle integer bool-ing is to say they are all True. > For bonus points, explain how you'd deal with any > backwards compatibility problems that your fix introduces. We would't deal with backwards compatibility as this notion of bool(1) == True and bool(0) == False if backwards way of thinking. Sure it saves a few keystrokes but in the end only serves to obfuscate the code and promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF True AND 0 IN PLACE OF False! > Have you considered forking Python? ?That may be the way forward here. I have considered this many times in the past and continue to consider it even today. I believe the Python language to be the best high level language ever created up to this point. I also believe GvR to be a true genius who has forged the path of all 21st century high level languages. However, like all new inventions eventually the bright shiny paint job starts to oxidize and expose the rotten and rusting core that has been slowly disintegrating behind the scenes all along. GvR stood on the shoulders of giants to reach the plateau of elegant bliss that we know today as Python programming. As we all know perfection will never be achieved, only lusted after forever and ever. A perpetual game of cat and mouse. So maybe it is now time for the next genius (Rick?) to stand on Guido's shoulders and reach the next "cookie-jar-of-programming-enlightenment" one shelf higher than Guido's cookies where found. Maybe it was fate that CPython 3000 would disturb so many folks as to create a question in their minds... A splinter lodged deep within the mind constantly tickling new never before thoughts to form... "Is Python all it can be?". A lustful yearning to fix the warts that have been ignored for far too long and were scarified at the alter of the simplistic development cycle. But i think we are now at a crossroads people. We must forge the new path and resist the temptation to circle around the familiar roads endlessly. Heck *maybe* Guido himself is the architect of this change? Maybe he *purposely* sowed discontent in an effort to ignite (or reignite?) a passion for change within this community...? The black monolith is before us. We have reached a crossroads. In the balance hangs the future of high level programming languages. Will we understand what the portal is and take the leap of faith forward, or just bang some bones around like toddlers for another 10,000 years? Only time will tell...? Only time will tell...? From rantingrick at gmail.com Sun Jul 11 19:44:10 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 16:44:10 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 11:31?am, Thomas Jollans wrote: > On 07/11/2010 07:44 AM, rantingrick wrote: > > Congratulations on this effort Luke. However you know what project i > > would really like to see the community get around? ...dramatic pause > > here... a cross platform Python file browser! > > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? > Erm, no. No, no, no. It won't work....... trying to > support both UNIX and Windows is NOT a good idea. Why is that a bad idea, Python does it all the time? Many software so it all the time. This sounds like more fear than anything. If you attempt to be full-featured, keeping it in one > code base, let alone in one user interface, is destined to be a > nightmare and induce suicides. Thats False! > The above might have been very slightly exaggerated. Thats True! From debatem1 at gmail.com Sun Jul 11 20:00:02 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 11 Jul 2010 20:00:02 -0400 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 7:22 PM, rantingrick wrote: > On Jul 11, 1:19?pm, Mark Dickinson wrote: > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity >> "0 == False"? > > No because all integers should bool True. An integer is a value that > IS NOT empty and IS NOT None. Therefore the only logical way to handle > integer bool-ing is to say they are all True. > >> For bonus points, explain how you'd deal with any >> backwards compatibility problems that your fix introduces. > > We would't deal with backwards compatibility as this notion of bool(1) > == True and bool(0) == False if backwards way of thinking. Sure it > saves a few keystrokes but in the end only serves to obfuscate the > code and promote bad programming styles. WE SHOULD NEVER BE USING 1 IN > PLACE OF True AND 0 IN PLACE OF False! > >> Have you considered forking Python? ?That may be the way forward here. > > ?I have considered this many times in the past and continue to > consider it even today. I believe the Python language to be the best > high level language ever created up to this point. I also believe GvR > to be a true genius who has forged the path of all 21st century high > level languages. However, like all new inventions eventually the > bright shiny paint job starts to oxidize and expose the rotten and > rusting core that has been slowly disintegrating behind the scenes all > along. > > ?GvR stood on the shoulders of giants to reach the plateau of elegant > bliss that we know today as Python programming. As we all know > perfection will never be achieved, only lusted after forever and ever. > A perpetual game of cat and mouse. So maybe it is now time for the > next genius (Rick?) to stand on Guido's shoulders and reach the next > "cookie-jar-of-programming-enlightenment" one shelf higher than > Guido's cookies where found. > > ?Maybe it was fate that CPython 3000 would disturb so many folks as to > create a question in their minds... A splinter lodged deep within the > mind constantly tickling new never before thoughts to form... "Is > Python all it can be?". A lustful yearning to fix the warts that have > been ignored for far too long and were scarified at the alter of the > simplistic development cycle. > > ?But i think we are now at a crossroads people. We must forge the new > path and resist the temptation to circle around the familiar roads > endlessly. Heck *maybe* Guido himself is the architect of this change? > Maybe he *purposely* sowed discontent in an effort to ignite (or > reignite?) a passion for change within this community...? > > The black monolith is before us. We have reached a crossroads. In the > balance hangs the future of high level programming languages. Will we > understand what the portal is and take the leap of faith forward, or > just bang some bones around like toddlers for another 10,000 years? > Only time will tell...? Only time will tell...? I literally laughed out loud as I read this. Go write some code, might help connect you back to reality. Geremy Condra From rantingrick at gmail.com Sun Jul 11 20:01:03 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:01:03 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <4C39F1EB.10006@jollans.com> Message-ID: <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> On Jul 11, 11:57?am, Stephen Hansen wrote: > On 7/11/10 9:31 AM, Thomas Jollans wrote: > > trying to > > support both UNIX and Windows is NOT a good idea. > > And you can't lump the Mac in with "UNIX" here, even though it really is > UNIX at the foundation, because there's some very fundamental > differences between HFS+ (and some other details that are higher level) > and more traditional unix FS's. Not to mention that the Mac FS situation > is slightly schitzo since it has two very different ways at looking and > treating the files, the posix way and the Foundation way... and users > think more in terms of the latter, usually. At least less sophisticated > users. Sure you can! Have you ever heard of a *rare* module by the name of "os"? Yes i know *nobody* uses it but it works nonetheless! > You can't do a cross-platform file manager without either doing a huge > amount of work exposing each platform separately-- essentially getting > separate codebases for each-- or doing a least common denominator > situation, at which point I boggle: why the hell did you bother to begin > with? Even Finder is better then that, let alone windows' Explorer. Nothing is worse than InternetExploder\Exploder, nothing! And whats wrong with seperate code bases, it's three modules and a startup script... if sys.platform == 'win32': import fm32 elif sys.platform == 'darwin': import fmdarwin elif sys.platform == 'nix': import fmnix We just recently had a discussion about CONDITIONALS Stephen have you forgotten already? > (*): I do not argue that a non-default file manager on an OS might be a > great thing. Now you're talking! > (**): The drop stack is a little corner of the window that you can drag > files onto. Then drag more files onto. Then drag more files onto. Then > you can navigate to another part of the system, and drag files off of > said stack, in a LIFO manner, moving them as a result of this action. This drop stack sound interesting. I've always hated the cut paste as you could not add to the cut buffer. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:02:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:02:20 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> Message-ID: <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> On Sat, 10 Jul 2010 23:50:05 -0700, rantingrick wrote: > You do realize that > Python must build a tuple for ever conditional that uses this semantic? > This is more bad, bad, bad than integer bool-ing! My bin packer could > potentially compute millions of parts. I do not want to waste valuable > processor cycles building numerous tuples just for the sake of a > conditional "condition"! This is bad coding style Stephen. No, premature optimization is bad coding. Building a tuple is extremely fast: $ python -m timeit "x = ()" 1000000 loops, best of 3: 0.316 usec per loop $ python -m timeit "x = False" 1000000 loops, best of 3: 0.36 usec per loop Testing is fast too: $ python -m timeit "x = (); 1 if x else 2" 1000000 loops, best of 3: 0.663 usec per loop $ python -m timeit "x = False; 1 if x else 2" 1000000 loops, best of 3: 0.969 usec per loop You've been around here long enough that you should know better. Stop wasting your time, and ours, ranting over the enormous cost of things that aren't costly at all. Come back when you have profiled your code and can prove that the cost of building empty tuples is an actual bottleneck. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:06:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:06:15 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4c3a5c77$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote: > On Jul 11, 3:03?am, "G?nther Dietrich" wrote: > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? If you're going to use generic names, why type three or four letters when one will do? i, j, k, m, n, p, q for ints. L, a, b, x for lists s, t, a, b for strings. If you don't want to use generic names, then int, list, str are useless because they don't mean anything. You need something like: count_of_widgets list_of_widgets description -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:06:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:06:23 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote: > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go on...?-- > start with lowercase. > > Q: Well what the hell is your problem Rick. Who cares right? > > WRONG, I tell you what my problem is. Now i cannot "wisely" use > variables like... > > str="this is a string" > list = [1,2,3] > def make_random_objs(range=10) > def show_message(str) > int = 12 Yes. So what? You can't wisely use variables like: True = "rantingrick is an obnoxious loudmouth" None = "the problem he is describing" Nor can you wisely use variables like: len = len("something") chr = chr(48) [...] > Just thoughts. But not deep thoughts. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:15:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:15:15 GMT Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: <4c3a5e93$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 18:31:39 +0200, Thomas Jollans wrote: > Cross platform file manager. Hmm. Does "cross platform" involve UNIX and > something that isn't UNIX, say, Windows? Erm, no. No, no, no. It won't > work. Well, it would work, but it wouldn't be any good. The UNIX and > Windows concepts of "file system" are similar enough for most programs > not to care too much, but for something like a file manager, that works > intimately with the file system, trying to support both UNIX and Windows > is NOT a good idea. Try telling that to the KDE people. -- Steven From breamoreboy at yahoo.co.uk Sun Jul 11 20:18:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 Jul 2010 01:18:52 +0100 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 12/07/2010 01:02, Steven D'Aprano wrote: > On Sat, 10 Jul 2010 23:50:05 -0700, rantingrick wrote: > >> You do realize that >> Python must build a tuple for ever conditional that uses this semantic? >> This is more bad, bad, bad than integer bool-ing! My bin packer could >> potentially compute millions of parts. I do not want to waste valuable >> processor cycles building numerous tuples just for the sake of a >> conditional "condition"! This is bad coding style Stephen. > > No, premature optimization is bad coding. > > Building a tuple is extremely fast: > > $ python -m timeit "x = ()" > 1000000 loops, best of 3: 0.316 usec per loop > $ python -m timeit "x = False" > 1000000 loops, best of 3: 0.36 usec per loop > > > Testing is fast too: > > $ python -m timeit "x = (); 1 if x else 2" > 1000000 loops, best of 3: 0.663 usec per loop > $ python -m timeit "x = False; 1 if x else 2" > 1000000 loops, best of 3: 0.969 usec per loop > > > You've been around here long enough that you should know better. Stop > wasting your time, and ours, ranting over the enormous cost of things > that aren't costly at all. Come back when you have profiled your code and > can prove that the cost of building empty tuples is an actual bottleneck. > +1 Kindest regards. Mark Lawrence From rantingrick at gmail.com Sun Jul 11 20:21:08 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:21:08 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: On Jul 11, 5:28?pm, Fuzzyman wrote: > But why hijack someone else's announcement to do that? Congratulations > alone would have been great. However good your intentions your message > came across as "but it would really have been better if you had been > doing something else instead...". Micheal i think you're just simply projecting some inner feelings on to my post resulting in a complete mis-understanding. And i *did not* say the project was useless, on the contrary i am very happy the OP resurrected this lost script. I only suggested a similar project that the OP *may* find to be interesting. Maybe not, but lets leave the decision for the OP, Ok. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:23:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:23:40 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> Message-ID: <4c3a608b$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: > On Jul 11, 1:19?pm, Mark Dickinson wrote: > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity >> "0 == False"? > > No because all integers should bool True. An integer is a value that IS > NOT empty Integers aren't containers, the concept of "empty" or "full" doesn't apply to them. > and IS NOT None. By this definition, the string "rantingrick hasn't thought this through" is an integer. It's not empty, and not None, so therefore an integer by your definition. Possibly the integer two-thirds of the way between 3 and 4. > Therefore the only logical way to handle > integer bool-ing is to say they are all True. For some definition of "logical". >> For bonus points, explain how you'd deal with any backwards >> compatibility problems that your fix introduces. > > We would't deal with backwards compatibility as this notion of bool(1) > == True and bool(0) == False if backwards way of thinking. Sure it saves > a few keystrokes but in the end only serves to obfuscate the code and > promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF > True AND 0 IN PLACE OF False! Nevertheless, what is done is done, and now you have to deal with it. Just wishing that it was never done is not dealing with backwards compatibility, and breaking existing code is not an acceptable option. So if your plan is to refuse to deal with existing code, I am very glad indeed that your plan will go absolutely nowhere. >> Have you considered forking Python? ?That may be the way forward here. > > I have considered this many times in the past and continue to > consider it even today. Please do. I think that this will be the best thing for the Python community. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jul 11 20:24:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 00:24:09 GMT Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? I found this link > (http://code.google.com/edu/languages/google-python- class/lists.html) > which suggests that this is done to make sure that the programmer > understands that the list is being modified in place, but that rules out > constructs like: > ([1,2,3,4].reverse()+[[]]).reverse() Yes. So what? Where's the problem? List methods work in place. If you're annoyed now, that's *nothing* to the annoyance you'll feel if they returned the list and you did this: alist = [1,2,3] blist = alist.append(4) # Make a new list with 4 appended. assert alist == [1,2,3] > I want to prepend an empty list to [1,2,3,4]. This is just a toy > example, since I can always do that with [[]]+[1,2,3,4]. Or: L = [[]] L.extend([1,2,3,4]) Or: L = [1,2,3,4] L.insert(0, []) Not everything needs to be a one-liner. -- Steven From news1234 at free.fr Sun Jul 11 20:30:39 2010 From: news1234 at free.fr (News123) Date: Mon, 12 Jul 2010 02:30:39 +0200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> Message-ID: <4c3a622f$0$700$426a74cc@news.free.fr> dhruvbird wrote: > > On a side note, is there any other way to append to a list using > slices (apart from the one below): > x[len(x):len(x)] = [item to append] dy you mean x.extend([1,2,3]) ? From me+list/python at ixokai.io Sun Jul 11 20:31:09 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 17:31:09 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> Message-ID: <4C3A624D.2090903@ixokai.io> On 7/11/10 5:01 PM, rantingrick wrote: > On Jul 11, 11:57 am, Stephen Hansen wrote: >> On 7/11/10 9:31 AM, Thomas Jollans wrote: >>> trying to >>> support both UNIX and Windows is NOT a good idea. >> >> And you can't lump the Mac in with "UNIX" here, even though it really is >> UNIX at the foundation, because there's some very fundamental >> differences between HFS+ (and some other details that are higher level) >> and more traditional unix FS's. Not to mention that the Mac FS situation >> is slightly schitzo since it has two very different ways at looking and >> treating the files, the posix way and the Foundation way... and users >> think more in terms of the latter, usually. At least less sophisticated >> users. > > > Sure you can! Have you ever heard of a *rare* module by the name of > "os"? Yes i know *nobody* uses it but it works nonetheless! Uh, "os" is beyond inadequate. Even shutil is severely lacking. For the most basic operations, Python's provided tools basically work only in very simple cases -- but only those simple cases -- and a file manager would be an utter failure if it had those limitations. See the big red box on top of the docs: http://docs.python.org/library/shutil.html Copying a file without the resource fork on a mac, *can* result in essential data being lost (This is less common then it used to be). As simple a task as chown/chmod for posix systems to take ownership of a file and make it only readable by you is actually a *deeply* complex task with the win32api. Check out http://mail.python.org/pipermail/python-win32/2004-July/002111.html for just an example of what it /looks/ like. That's not even getting into the nitty-gritty details, like how Mac's are *usually* case-insensitive, windows is always, linux is almost always not, and yet some power users go out of their way to enable case-sensitivity on mac filesystems (which has a tendency to break all kinds of things). Oh, and a LOT of the filesystem-details and how you could go around handling them on a mac is *very* dependant on just what version of OSX you have. It changes a lot. >> You can't do a cross-platform file manager without either doing a huge >> amount of work exposing each platform separately-- essentially getting >> separate codebases for each-- or doing a least common denominator >> situation, at which point I boggle: why the hell did you bother to begin >> with? Even Finder is better then that, let alone windows' Explorer. > > Nothing is worse than InternetExploder\Exploder, nothing! And whats > wrong with seperate code bases, it's three modules and a startup > script... > > if sys.platform == 'win32': > import fm32 > elif sys.platform == 'darwin': > import fmdarwin > elif sys.platform == 'nix': > import fmnix > > We just recently had a discussion about CONDITIONALS Stephen have you > forgotten already? You underestimate the significance of the differences and how that would impact the resulting user interface; have you actually implemented anything which targeted the big three OS's and did non-trivial file operations? I have: just dealing with permissions and network shares and other details is actually a pain in the ass. And in the end, there's plenty of Explorer/Finder replacements out there which do their job splendidly. And I assume not everyone on linux loves nautilus and uses it :P >> (*): I do not argue that a non-default file manager on an OS might be a >> great thing. > > Now you're talking! Selective quoting to make it sound like I'm agreeing in some way with you = jerkoff move. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From breamoreboy at yahoo.co.uk Sun Jul 11 20:31:14 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 12 Jul 2010 01:31:14 +0100 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> Message-ID: On 12/07/2010 01:06, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote: > >> Another source of asininity seems to be the naming conventions of the >> Python language proper! True/False start with an upper case and i >> applaud this. However str, list, tuple, int, float --need i go on...?-- >> start with lowercase. >> >> Q: Well what the hell is your problem Rick. Who cares right? >> >> WRONG, I tell you what my problem is. Now i cannot "wisely" use >> variables like... >> >> str="this is a string" >> list = [1,2,3] >> def make_random_objs(range=10) >> def show_message(str) >> int = 12 > > > Yes. So what? You can't wisely use variables like: > > True = "rantingrick is an obnoxious loudmouth" +1 QOTW > None = "the problem he is describing" > > Nor can you wisely use variables like: > > len = len("something") > chr = chr(48) > > > [...] >> Just thoughts. > > But not deep thoughts. > Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? Kindest regards. Mark Lawrence. From rantingrick at gmail.com Sun Jul 11 20:35:18 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:35:18 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:02?pm, Steven D'Aprano wrote: > Come back when you have profiled your code and > can prove that the cost of building empty tuples is an actual bottleneck. Did you even read this thread, i mean from head to tail. I NEVER said building EMPTY tuples was the cause of my rant. My complaint (an oddly enough the title of this thread!) concerns the fact that Python treats 0 as False and every integer above and below 0 as True. Which is another example of how *some* aspects of Python support bad coding styles. The only reason i used the tuple was so that my conditional logic worked as expected. *Stephen* offered a solution in the form of using tuples within the conditional expression. I countered his solution by showing that creating tuples in a conditional expression is slower that testing for bool-inity. *Steven*, Please read the thread completely before making off hand comments else you could make a complete fool of yourself! From rantingrick at gmail.com Sun Jul 11 20:38:06 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:38:06 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:18?pm, Mark Lawrence wrote: > +1 Oh mark grow a spine already, really. I can't help but thinking of the spineless Robert Ford every time you open your mouth. From johannes.black at gmail.com Sun Jul 11 20:48:40 2010 From: johannes.black at gmail.com (joblack) Date: Sun, 11 Jul 2010 17:48:40 -0700 (PDT) Subject: Errno 9] Bad file descriptor Message-ID: I get sometimes a Errno 9 Bad file descriptor the code is too long to show it here but what are the circumstances this could happen? A web search showed nothing. I have especially the feeling Python 2.6 has some problems with Unicode ... and might not find the file. Is that possible? From rantingrick at gmail.com Sun Jul 11 20:51:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 17:51:04 -0700 (PDT) Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Jul 11, 7:23?pm, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: > > On Jul 11, 1:19?pm, Mark Dickinson wrote: > > >> Okay. ?What fix do you propose? ?Would your fix maintain the identity > >> "0 == False"? > > > No because all integers should bool True. An integer is a value that IS > > NOT empty > > Integers aren't containers, the concept of "empty" or "full" doesn't > apply to them. And again you failed to follow along with the thread so you have no idea where my statements is projected from. Of course integers are NOT containers in the way a list or dict is a container! My remark was a rebuff of comments made by Stephen earlier. > > and IS NOT None. > > By this definition, the string "rantingrick hasn't thought this through" > is an integer. It's not empty, and not None, so therefore an integer by > your definition. Again you show lack of reading and comprehension skills. The fact that an integer IS NOT None does not mean this is the only definition of an integer. And any blabbing otherwise is just complete nonsensical crap. If you think you're going to fly in here and dis-credit me that easily you'd better pack a lunch next time! I gots my think'in cap on today fella! > > We would't deal with backwards compatibility as this notion of bool(1) > > == True and bool(0) == False if backwards way of thinking. Sure it saves > > a few keystrokes but in the end only serves to obfuscate the code and > > promote bad programming styles. WE SHOULD NEVER BE USING 1 IN PLACE OF > > True AND 0 IN PLACE OF False! > > Nevertheless, what is done is done, and now you have to deal with it. > Just wishing that it was never done is not dealing with backwards > compatibility, and breaking existing code is not an acceptable option. Yea and if Guido would have taking your defeatist attitude we'd all be using braces for scope! You know D'Aprano, i had once considered you one of the foremost intelligent minds within this group. However, after your display within this thread i am beginning to doubt my original beliefs of you. Hopefully you're just having an "off" day? From ash.connor at gmail.com Sun Jul 11 20:55:45 2010 From: ash.connor at gmail.com (ashconnor) Date: Sun, 11 Jul 2010 17:55:45 -0700 (PDT) Subject: Problems running VirtualEnv under Windows. Message-ID: <7fc04b13-8006-45f6-a099-94bd9353761f@c33g2000yqm.googlegroups.com> Hello, After reading 'Practical Django Projects' I decided that I want to implement the VirtualEnv tip suggested in order to properly segregate code/modules in different projects. I am however having problems with my django installations not using site-packages within the virtualenv but rather attempting to use site-packages in the default python installation directory. Recreating the problem: 1) Install Python 2.7 via the Windows installer. Add C:/Python27;C:/ Python27/Scripts to Windows PATH. 2) Install setuptools-0.6c11-py2.7.egg via the Windows installer. 3) Install VirtualEnv through `pip install virtualenv` 4) Create an VirtualEnv via `virtualenv --no-site-packages MyEnvName` 5) Activate VirtualEnv via `../MyEnvName/Scripts/activate.bat` 6) Install django via `pip install django` 7) Run django-admin.py startproject ProjectName 8) Error results stating django.core module does not exist. NB: This error will not occur if django is installed in your root directory. NB2: Running the Python interpreter in active VirtualEnv to print the sys.path shows the correct paths. Which has just futher added to my confusion. I'd appreciate any insight or troubleshooting assistance. Thanks Ash From python at rcn.com Sun Jul 11 20:55:53 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 11 Jul 2010 17:55:53 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: Message-ID: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> On Jul 11, 8:59?am, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? Because Guido thinks that having those methods return None is the best way to communicate that the underlying object has been mutated in- place. Some other languages do it differently, but this is Guido's language, so we do it his way. Raymond From rantingrick at gmail.com Sun Jul 11 21:10:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 11 Jul 2010 18:10:19 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> Message-ID: <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> On Jul 11, 7:31?pm, Stephen Hansen wrote: You said about macs... > Copying a file without the resource fork on a mac, *can* result in > essential data being lost (This is less common then it used to be). As > simple a task as chown/chmod for posix systems to take ownership of a > file and make it only readable by you is actually a *deeply* complex > task with the win32api. And again... > That's not even getting into the nitty-gritty details, like how Mac's > are *usually* case-insensitive, windows is always, linux is almost > always not, and yet some power users go out of their way to enable > case-sensitivity on mac filesystems (which has a tendency to break all > kinds of things). And again... > Oh, and a LOT of the filesystem-details and how you could go around > handling them on a mac is *very* dependant on just what version of OSX > you have. It changes a lot. Well i've never used a mac and now i won't even bother for sure! But if you want to maintain the macfman code base feel free. > Selective quoting to make it sound like I'm agreeing in some way with > you = jerkoff move. *fakes throwing stick* *dog runs to get stick but stick not there* Who's smarter ;-) From alf.p.steinbach+usenet at gmail.com Sun Jul 11 21:12:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 03:12:10 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * MRAB, on 12.07.2010 00:37: > Alf P. Steinbach /Usenet wrote: >> * Stephen Hansen, on 11.07.2010 21:00: >>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>> Follow-up: >>>> Is there a way to define compile-time constants in python and have the >>>> bytecode compiler optimize away expressions like: >>>> >>>> if is_my_extra_debugging_on: print ... >>>> >>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>> run-time penalty for such code when extra_debugging is disabled. >>> >>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>> Python with the -O option. That, and asserts go away. >>> >>>> On #2: My point regarding the impossibility of writing the swap >>>> function for ints is to explicitly understand that this isn't >>>> possible, so as not to look for solutions along those lines when >>>> trying to write python code. >>> >>> Its impossible because Python's calling and namespace semantics simply >>> don't work like that. There's no references in the traditional sense, >>> because there's no variables-- boxes that you put values in. There's >>> just concrete objects. Objects are passed into the function and given >>> new names; that those objects have names in the enclosing scope is >>> something you don't know, can't access, and can't manipulate.. even the >>> objects don't know what names they happen to be called. >>> >>> Check out http://effbot.org/zone/call-by-object.htm >> >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >> works like Java in this respect, that's all; neither Java nor Python >> support 'swap'. >> >> Of course there are variables, that's why the docs call them variables. >> > In Java a variable is declared and exists even before the first > assignment to it. In Python a 'variable' isn't declared and won't exist > until the first 'assignment' to it. That is a misconception. In Python a variable is declared by having an assignment to it, which for a local variable may be anywhere within a routine. If such a variable is used before it's been assigned to, then you get an uninitialized variable exception. Clearly the variable must exist in order for the exception to refer to it (not to mention the exception occurring at all). def foo(): print( blah ) blah = "this is both an assignment and a declaration causing it to exist" foo() Clearly when the exception is raised, referring to the variable, the variable exists. Contrary to your statement that is before the assignment. However, as stated up-thread, I do not expect facts, logic or general reasoning to have any effect whatsoever on such hard-core religious beliefs. And I do not care whether I convince you or not. But I *do not* want the religious subset of the community to succeed too much in propagating nonsense idiot beliefs to newbies -- hence the concrete example that any newbie can try. Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Sun Jul 11 21:33:33 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 18:33:33 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4C3A70ED.6070106@ixokai.io> On 7/11/10 5:51 PM, rantingrick wrote: > On Jul 11, 7:23 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 11 Jul 2010 16:22:41 -0700, rantingrick wrote: >>> On Jul 11, 1:19 pm, Mark Dickinson wrote: >> >>>> Okay. What fix do you propose? Would your fix maintain the identity >>>> "0 == False"? >> >>> No because all integers should bool True. An integer is a value that IS >>> NOT empty >> >> Integers aren't containers, the concept of "empty" or "full" doesn't >> apply to them. > > And again you failed to follow along with the thread so you have no > idea where my statements is projected from. Of course integers are NOT > containers in the way a list or dict is a container! My remark was a > rebuff of comments made by Stephen earlier. I forgot to reply to that; an integer is certainly not empty. But 0 is nothing. Its not empty vs full. Its nothing vs something that determines if something is considered true-ish or not. >> Nevertheless, what is done is done, and now you have to deal with it. >> Just wishing that it was never done is not dealing with backwards >> compatibility, and breaking existing code is not an acceptable option. > > Yea and if Guido would have taking your defeatist attitude we'd all be > using braces for scope! Guido made a new language. You should go do that. Feel free to define it however you want. In Python, the meaning of "truth" goes back a very, very, very long way. It isn't going to change. Every once in awhile people hate it. For awhile after True/False were introduced, some people wanted to go modify things to a boolean strictness. But in the end, its all pointless. This is just how it works. Its not going to change. It would break thousands and thousands of lines of code. There's not going to be another major breakage for, oh, maybe ten years. Or twenty. If ever. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From brendon.wickham at gmail.com Sun Jul 11 21:41:47 2010 From: brendon.wickham at gmail.com (Brendon Wickham) Date: Mon, 12 Jul 2010 11:41:47 +1000 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <8b0a74a9-88c6-4100-87d4-4d8d5128a573@r27g2000yqb.googlegroups.com> <439fcdbd-bb36-4dfe-b0fb-b560b6828f4c@k39g2000yqb.googlegroups.com> <4c3a608b$0$28647$c3e8da3@news.astraweb.com> Message-ID: "i had once considered you one of the foremost intelligent minds within this group. However, after your display within this thread i am beginning to doubt my original beliefs of you." "Oh ... grow a spine already, really. I can't help but thinking of the spineless Robert Ford every time you open your mouth" @rantingrick : these comments among others fail to meet the standard of engagement expected of, and traditional to, this list. Take a breath, get some sleep and come back with a level head and a civil tongue. If you have any valid point to make at all, your attitude so far has failed to make it credible, and nor will it enable you to enlist supporters. From me+list/python at ixokai.io Sun Jul 11 21:54:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 18:54:15 -0700 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> References: <4C39F1EB.10006@jollans.com> <5f0b3927-edf8-40cb-aed2-0742d821d1e1@i31g2000yqm.googlegroups.com> <6e21ef7a-e5a1-4d9c-9978-b4a101280207@i28g2000yqa.googlegroups.com> Message-ID: <4C3A75C7.2020405@ixokai.io> On 7/11/10 6:10 PM, rantingrick wrote: > On Jul 11, 7:31 pm, Stephen Hansen wrote: > > You said about macs... >> Copying a file without the resource fork on a mac, *can* result in >> essential data being lost (This is less common then it used to be). As >> simple a task as chown/chmod for posix systems to take ownership of a >> file and make it only readable by you is actually a *deeply* complex >> task with the win32api. > > And again... >> That's not even getting into the nitty-gritty details, like how Mac's >> are *usually* case-insensitive, windows is always, linux is almost >> always not, and yet some power users go out of their way to enable >> case-sensitivity on mac filesystems (which has a tendency to break all >> kinds of things). > > And again... >> Oh, and a LOT of the filesystem-details and how you could go around >> handling them on a mac is *very* dependant on just what version of OSX >> you have. It changes a lot. > > Well i've never used a mac and now i won't even bother for sure! But > if you want to maintain the macfman code base feel free. I like how you tried to cut out my commentary on Windows and its difficulties and peculiarities, but you accidentally included it anyways -- hint: read more then the first line of a paragraph. My point stands. And I take your non actually responding to my actual point as a concession to it. With that, I'm signing off of this conversation. Tah. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Sun Jul 11 22:02:28 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 19:02:28 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A77B4.6080701@ixokai.io> On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote: > However, as stated up-thread, I do not expect facts, logic or general > reasoning to have any effect whatsoever on such hard-core religious > beliefs. Grow up, and/or get a grip, and/or get over yourself. Everyone who disagreed with you, disagreed with you with arguments, logic, facts, and reasoning. You disputed those facts, disagreed with the conclusions, but for you to then just dismiss people who don't agree with you as merely "religious", is childish. Exactly why I think you're wrong -- you're free to go re-read, I stand by my statements in this thread, and the others. The same arguments apply. Its not a religion, dear; my conclusions are not a matter of faith. That's all I have to say on this subject; the conversation has been had, at length (repeatedly). I swear, I'm just going to filter you and Rick out to /dev/null today and leave it at that at this rate. I'm getting worn out of these kinds of responses. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:09:02 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:09:02 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3a793e$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 17:35:18 -0700, rantingrick wrote: > On Jul 11, 7:02?pm, Steven D'Aprano cybersource.com.au> wrote: > >> Come back when you have profiled your code and can prove that the cost >> of building empty tuples is an actual bottleneck. > > Did you even read this thread, i mean from head to tail. Yes I did. > I NEVER said > building EMPTY tuples was the cause of my rant. The cause of your rant appears to be that you have nothing better to do with your time. But the *excuse* for your rant was that you had to replace: choiceIdx1 = None with: choiceIdx1 = () and followed with: Seems kinda dumb to build a tuple just so a conditional wont blow chunks! and My bin packer could potentially compute millions of parts. I do not want to waste valuable processor cycles building numerous TUPLES just for the sake of a conditional "condition"! [emphasis added] > My complaint (an oddly > enough the title of this thread!) concerns the fact that Python treats 0 > as False and every integer above and below 0 as True. Which is another > example of how *some* aspects of Python support bad coding styles. Yes, Python does support bad coding styles. The treatment of 0 as a false value is not one of them though. -- Steven From python at mrabarnett.plus.com Sun Jul 11 22:09:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jul 2010 03:09:12 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3A7948.20706@mrabarnett.plus.com> Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: >> Alf P. Steinbach /Usenet wrote: >>> * Stephen Hansen, on 11.07.2010 21:00: >>>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>>> Follow-up: >>>>> Is there a way to define compile-time constants in python and have the >>>>> bytecode compiler optimize away expressions like: >>>>> >>>>> if is_my_extra_debugging_on: print ... >>>>> >>>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>>> run-time penalty for such code when extra_debugging is disabled. >>>> >>>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>>> Python with the -O option. That, and asserts go away. >>>> >>>>> On #2: My point regarding the impossibility of writing the swap >>>>> function for ints is to explicitly understand that this isn't >>>>> possible, so as not to look for solutions along those lines when >>>>> trying to write python code. >>>> >>>> Its impossible because Python's calling and namespace semantics simply >>>> don't work like that. There's no references in the traditional sense, >>>> because there's no variables-- boxes that you put values in. There's >>>> just concrete objects. Objects are passed into the function and given >>>> new names; that those objects have names in the enclosing scope is >>>> something you don't know, can't access, and can't manipulate.. even the >>>> objects don't know what names they happen to be called. >>>> >>>> Check out http://effbot.org/zone/call-by-object.htm >>> >>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >>> works like Java in this respect, that's all; neither Java nor Python >>> support 'swap'. >>> >>> Of course there are variables, that's why the docs call them variables. >>> >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. > > If such a variable is used before it's been assigned to, then you get an > uninitialized variable exception. Clearly the variable must exist in > order for the exception to refer to it (not to mention the exception > occurring at all). > > def foo(): > print( blah ) > blah = "this is both an assignment and a declaration causing it to > exist" > > foo() > > Clearly when the exception is raised, referring to the variable, the > variable exists. > > Contrary to your statement that is before the assignment. > > However, as stated up-thread, I do not expect facts, logic or general > reasoning to have any effect whatsoever on such hard-core religious > beliefs. And I do not care whether I convince you or not. But I *do not* > want the religious subset of the community to succeed too much in > propagating nonsense idiot beliefs to newbies -- hence the concrete > example that any newbie can try. > How about this: >>> def foo(): print("Before:", locals()) x = 0 print("After:", locals()) >>> foo() Before: {} After: {'x': 0} From dannybos at gmail.com Sun Jul 11 22:15:39 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 19:15:39 -0700 (PDT) Subject: IOError and Try Again to loop the loop. Message-ID: Heya, I'm running a py script that simply grabs an image, creates a thumbnail and uploads it to s3. I'm simply logging into ssh and running the script through Terminal. It works fine, but gives me an IOError every now and then. I was wondering if I can catch this error and just get the script to start again? I mean, in Terminal it dies anyway, so I have to start it again by hand, which is a pain as it dies so sporadically. Can I automate this error, catch it and just get it to restart the loop? Thanks for your time and energy, Danny From alf.p.steinbach+usenet at gmail.com Sun Jul 11 22:25:14 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 04:25:14 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * Stephen Hansen, on 12.07.2010 04:02: > On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote: >> However, as stated up-thread, I do not expect facts, logic or general >> reasoning to have any effect whatsoever on such hard-core religious >> beliefs. > > Grow up, and/or get a grip, and/or get over yourself. > > Everyone who disagreed with you, disagreed with you with arguments, > logic, facts, and reasoning. You disputed those facts, disagreed with > the conclusions, but for you to then just dismiss people who don't agree > with you as merely "religious", is childish. > > Exactly why I think you're wrong -- you're free to go re-read, I stand > by my statements in this thread, and the others. The same arguments > apply. Its not a religion, dear; my conclusions are not a matter of faith. > > That's all I have to say on this subject; the conversation has been had, > at length (repeatedly). > > I swear, I'm just going to filter you and Rick out to /dev/null today > and leave it at that at this rate. I'm getting worn out of these kinds > of responses. Well, the above is flaming, which I predicted. The alleged facts etc. you're referring are just that, alleged, by you. In contrast, in debates among non-religious folks facts are /presented/, like I've done in this thread, e.g. concrete code, instead of like you alleging that facts have been presented, hinting about things, and so on -- it's pathetic. Cheers & hth., - Alf -- blog at From clp2 at rebertia.com Sun Jul 11 22:31:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 19:31:00 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 7:15 PM, The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? Of course. Use try-except; http://docs.python.org/tutorial/errors.html#handling-exceptions Here's one way to do it: for image in images:#or whatever the actual loop is # whatever while True: try: part_that_may_raise_IOError() except IOError: print("IOError; Retrying...") else: break # whatever other stuff Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sun Jul 11 22:33:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Jul 2010 03:33:45 +0100 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: <4C3A7F09.4030508@mrabarnett.plus.com> The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? > > Thanks for your time and energy, > Exceptions can be caught. You could do something like this: while True: try: do_something() break except IOError: pass From mehgcap at gmail.com Sun Jul 11 22:35:07 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 11 Jul 2010 22:35:07 -0400 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: It seems like seeing the code, or at least the bit in question, would be easier, but what about: for img in range(0, len(imagesToUpload:)) try: #do the thumbnail / upload thing on images[i] exceptIOError: i=0 This will duplicate a lot of the images already processed, but you said you are just restarting the script anyway. If you are in a while loop, just move the processing to the for loop and use the while to add all images to be processed to a list. On 7/11/10, The Danny Bos wrote: > Heya, > > I'm running a py script that simply grabs an image, creates a > thumbnail and uploads it to s3. I'm simply logging into ssh and > running the script through Terminal. It works fine, but gives me an > IOError every now and then. > > I was wondering if I can catch this error and just get the script to > start again? > I mean, in Terminal it dies anyway, so I have to start it again by > hand, which is a pain as it dies so sporadically. Can I automate this > error, catch it and just get it to restart the loop? > > Thanks for your time and energy, > > Danny > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:39:39 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:39:39 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: [...] >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. Oh, I'm going to regret being sucked into this... In *CPython*, but not necessarily other implementations, variables which are local to a function are not kept in a dictionary-based namespace, but in slots in the code object (not to be confused with __slots__ used for classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing locals. This is intended as a speed, and possibly memory, optimization. I don't believe this is a requirement though, so implementations may not do this. It is true that the slot is created at compile time, and in *that sense*, local variables exist before they are bound. I'm not entirely convinced that this is the only sense that matters, but never mind. The error message given exposes this to the user: >>> def f(): ... print x ... x = 1 ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced before assignment If you try this with a global, you get this: >>> def f(): ... global x ... print x ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'x' is not defined In this case, there's no doubt that global variable "x" doesn't exist at all -- there is no key "x" in the global namespace. It seems to me that "a slot to hold the variable is created for local variables" is an implementation detail, not a language feature. CPython could easily hide the difference by changing the exception from UnboundLocalError to: NameError: local name 'x' does not exist and nobody would be any wiser. (Well, perhaps people who catch UnboundLocalError, but why would you do that?) I also note that UnboundLocalError is a subclass of NameError, so "variable exists but is not bound" is considered to be a special case of "variable doesn't exist" rather than a completely independent case. In that sense, I think I'm on solid ground to say that in Python variables don't exist until they are bound to a value, and leave it to pedants like you and I to mention that for CPython local variables have space reserved for them by the compiler before they are bound. -- Steven From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:40:07 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:40:07 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3a8087$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: > Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? For some reason, when I answer the phone and say "Hello, Steven speaking?" I often get called Peter. -- Steven From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 22:43:29 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 02:43:29 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> <4c3a8087$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: > >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? > > For some reason, when I answer the phone and say "Hello, Steven > speaking?" I often get called Peter. Er, without the question mark. -- Steven From alf.p.steinbach+usenet at gmail.com Sun Jul 11 23:04:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 05:04:13 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: * MRAB, on 12.07.2010 04:09: > Alf P. Steinbach /Usenet wrote: >> * MRAB, on 12.07.2010 00:37: >>> Alf P. Steinbach /Usenet wrote: >>>> * Stephen Hansen, on 11.07.2010 21:00: >>>>> On 7/11/10 11:45 AM, wheres pythonmonks wrote: >>>>>> Follow-up: >>>>>> Is there a way to define compile-time constants in python and have >>>>>> the >>>>>> bytecode compiler optimize away expressions like: >>>>>> >>>>>> if is_my_extra_debugging_on: print ... >>>>>> >>>>>> when "is_my_extra_debugging" is set to false? I'd like to pay no >>>>>> run-time penalty for such code when extra_debugging is disabled. >>>>> >>>>> Any code wrapped in a __debug__ guard is utterly ommitted if you run >>>>> Python with the -O option. That, and asserts go away. >>>>> >>>>>> On #2: My point regarding the impossibility of writing the swap >>>>>> function for ints is to explicitly understand that this isn't >>>>>> possible, so as not to look for solutions along those lines when >>>>>> trying to write python code. >>>>> >>>>> Its impossible because Python's calling and namespace semantics simply >>>>> don't work like that. There's no references in the traditional sense, >>>>> because there's no variables-- boxes that you put values in. There's >>>>> just concrete objects. Objects are passed into the function and given >>>>> new names; that those objects have names in the enclosing scope is >>>>> something you don't know, can't access, and can't manipulate.. even >>>>> the >>>>> objects don't know what names they happen to be called. >>>>> >>>>> Check out http://effbot.org/zone/call-by-object.htm >>>> >>>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >>>> works like Java in this respect, that's all; neither Java nor Python >>>> support 'swap'. >>>> >>>> Of course there are variables, that's why the docs call them variables. >>>> >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. >> >> If such a variable is used before it's been assigned to, then you get >> an uninitialized variable exception. Clearly the variable must exist >> in order for the exception to refer to it (not to mention the >> exception occurring at all). >> >> def foo(): >> print( blah ) >> blah = "this is both an assignment and a declaration causing it to exist" >> >> foo() >> >> Clearly when the exception is raised, referring to the variable, the >> variable exists. >> >> Contrary to your statement that is before the assignment. >> >> However, as stated up-thread, I do not expect facts, logic or general >> reasoning to have any effect whatsoever on such hard-core religious >> beliefs. And I do not care whether I convince you or not. But I *do >> not* want the religious subset of the community to succeed too much in >> propagating nonsense idiot beliefs to newbies -- hence the concrete >> example that any newbie can try. >> > How about this: > > >>> def foo(): > print("Before:", locals()) > x = 0 > print("After:", locals()) > > > >>> foo() > Before: {} > After: {'x': 0} How about it? Note that you get the same result if you do x = "blah" def foo(): # print( x ) # Causes uninitialized variable exception here print( "Before:", locals() ) x = 0 print( "After:", locals() ) However, if you remove the local assignment to x, then the out-commented print statement will no longer cause an exception, it will then refer to the global. The reason that it does throw an exception when you do have the local assignment, is that the local x exists at that point. If it didn't exist it could not have any effect. Things that don't exist generally have no effect, except in the minds of the religious, like angels and so on. On the basis of what locals() reports it should be OK to refer to the global x as above. Judging by locals(), there's no local x that could get in the way. But since it is not OK to refer to the global x, the result of locals() has nothing to do with that: it doesn't tell you about the local x -- and no, the Python interpreter does not look forward in time to see that it will appear. In passing, I should perhaps have told you up front, your argument has nothing substantial to do with the article you originally responded to, about the semantics of variables. Your argument is the assertion that different languages can't have similar or identical semantics for some feature. That's nonsense in itself, plus, as you've seen, the difference that you focused on is not there, and, third, what you do maintain is not there, doesn't exist, has a real effect. Cheers & hth., - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Sun Jul 11 23:11:48 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 03:11:48 GMT Subject: Errno 9] Bad file descriptor References: Message-ID: <4c3a87f4$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 17:48:40 -0700, joblack wrote: > I get sometimes a > > Errno 9 Bad file descriptor > > the code is too long to show it here You can at least show the actual line that fails. Are you trying to open a file, a named socket, a pipe or a device? > but what are the circumstances this > could happen? A web search showed nothing. The first two google hits for "bad file descriptor" seem pretty relevant to me: http://linux.sys-con.com/node/1053821 http://lists.freebsd.org/pipermail/freebsd-questions/2003-June/009583.html > I have especially the feeling Python 2.6 has some problems with Unicode > ... and might not find the file. Is that possible? Possible, but you should get Errno 2 No such file or directory not bad file descriptor. If you're trying to open a file, you have a broken file system and need to run fsck or equivalent. If it's a pipe or socket or something, you need to tell us what it is. -- Steven From dannybos at gmail.com Sun Jul 11 23:13:57 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 20:13:57 -0700 (PDT) Subject: IOError and Try Again to loop the loop. References: Message-ID: Thanks gang, I'm gonna paste what I've put together, doesn't seem right. Am I way off? Here's my code. - It goes through a table Item - Matches that Item ID to an API call - Grabs the data, saves it and creates the thumbnail - It dies due to Timeouts and Other baloney, all silly, nothing code based. items = Item.objects.all().filter(cover='').order_by('-reference_id') for item in items: url = "http://someaddress.org/books/?issue=%s" % item.reference_id url_array = [] url_open = urllib.urlopen(url) url_read = url_open.read().decode('utf-8') try: url_data = simplejson.loads(url_read) url_array.append(url_data) for detail in url_array: if detail['artworkUrl']: cover_url = detail['artworkUrl'].replace(' ','%20') cover_open = urllib.urlretrieve(cover_url) cover_name = os.path.split(cover_url)[1] item.cover.save(cover_name, File(open(cover_open[0])), save=True) ## Create and save Thumbnail print "Cover - %s: %s" % (item.number, url) else: print "Missing - %s: %s" % (item.number, url) except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) pass except IOError: print "IOError; Retrying..." pass print "Done" On Jul 12, 12:33?pm, MRAB wrote: > The Danny Bos wrote: > > Heya, > > > I'm running a py script that simply grabs an image, creates a > > thumbnail and uploads it to s3. I'm simply logging into ssh and > > running the script through Terminal. It works fine, but gives me an > > IOError every now and then. > > > I was wondering if I can catch this error and just get the script to > > start again? > > I mean, in Terminal it dies anyway, so I have to start it again by > > hand, which is a pain as it dies so sporadically. Can I automate this > > error, catch it and just get it to restart the loop? > > > Thanks for your time and energy, > > Exceptions can be caught. You could do something like this: > > ? ? ?while True: > ? ? ? ? ?try: > ? ? ? ? ? ? ?do_something() > ? ? ? ? ? ? ?break > ? ? ? ? ?except IOError: > ? ? ? ? ? ? ?pass From benjamin.kaplan at case.edu Sun Jul 11 23:28:30 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 11 Jul 2010 20:28:30 -0700 Subject: Getting started with python on macintosh snow leopard with mysql - need help In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 1:18 PM, dk wrote: > I have been going round and round trying to configure python 2.6 > running on osx 10.6.x to work with mySQL 5.1.44. > Python seems to work ... i have an installation of mysql 5.1.44 > running and have used it in conjunction for other php/apache projects. > > I want to learn python and think i need a better database then mysql > lite that installs with the web2py frame work, so my quest to connect > to mysql or postgres began. > > I seem to be stuck stuck getting mySQLdb drivers installed. ?I down > loaded python 2.6.5 from the python site and MySQL-python-1.2.3 from > the my sql site. > I have worked past numerous errors by i now get the errors below when > i try to compile. > > -- some background that might help anyone kind enough to have read > this far and who might be inclined to take pitty -- > I have (tried) to use macports to install setuptools (which MySQL- > python-1.2.3 says it needs). > MacPorts has put tons of stuff in /opt/local ... so i am not sure i am > using this tool the way its intended. > this could all be as simple as adding some path declarations in the > right place but where? > That could be part of your problem. Macports basically ignores the rest of the system. Setuptools depends on python, so Macports compiles and installs its own version of Python in /opt/local. So you now have 3 different versions of Python 2.6 on your computer: /usr/bin/python (the System python), /usr/local/bin/python (the Python.org python) and /opt/local/Library/Frameworks/Python.Framework/Versions/2.6/bin/python. You can use Macport's python-select package to choose which one is the default (it symlinks one of them to /opt/local/bin/python which should be first on your path). Anyway, as long as you're using Macports : sudo port install py26-mysql that should solve most of your problems :) > lots of the post i have seen on the subject talk about 32/64 > installation ... it makes sense that you might need to be consistent > in getting your components to work together, but i am not sure how i > tell of the various parts i have install which and how they were > compiled. > > whereis python ?display ?/usr/bin/python > python -v spits out lots ... but here is a sample: > > # /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ > encodings/utf_8.pyc matches /Library/Frameworks/Python.framework/ > Versions/2.6/lib/python2.6/encodings/utf_8.py > import encodings.utf_8 # precompiled from /Library/Frameworks/ > Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.pyc > Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > > > > > > when i try to compile mysql-python-1.2.3 i get the following error > returned from python setup.py build ----- > > building '_mysql' extension > gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing > -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - > D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ > Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ > temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - > D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - > DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/unicodeobject.h:4, > ? ? ? ? ? ? ? ? from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/Python.h:85, > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > ? ? ? ? ? ? ? ? from _mysql.c:29: > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > stdarg.h: No such file or directory > In file included from _mysql.c:36: > /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" > redefined > In file included from /Library/Frameworks/Python.framework/Versions/ > 2.6/include/python2.6/Python.h:8, > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > ? ? ? ? ? ? ? ? from _mysql.c:29: > /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ > pyconfig.h:808:1: warning: this is the location of the previous > definition > error: command 'gcc-4.0' failed with exit status 1 > -- Strange. Seems that the package is trying to use gcc-4.0 and the MacOSX10.4 SDK. The default version of gcc on Snow Leopard is 4.2, and XCode only comes with the SDKs for the previous two versions of OS X. From debatem1 at gmail.com Mon Jul 12 00:10:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 00:10:09 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Sun, Jul 11, 2010 at 10:39 PM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > >> * MRAB, on 12.07.2010 00:37: > [...] >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. > > Oh, I'm going to regret being sucked into this... > > In *CPython*, but not necessarily other implementations, variables which > are local to a function are not kept in a dictionary-based namespace, but > in slots in the code object (not to be confused with __slots__ used for > classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing > locals. > > This is intended as a speed, and possibly memory, optimization. I don't > believe this is a requirement though, so implementations may not do this. > > It is true that the slot is created at compile time, and in *that sense*, > local variables exist before they are bound. I'm not entirely convinced > that this is the only sense that matters, but never mind. The error > message given exposes this to the user: > >>>> def f(): > ... ? ? print x > ... ? ? x = 1 > ... >>>> f() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 2, in f > UnboundLocalError: local variable 'x' referenced before assignment > > > If you try this with a global, you get this: > >>>> def f(): > ... ? ? global x > ... ? ? print x > ... >>>> f() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in f > NameError: global name 'x' is not defined > > In this case, there's no doubt that global variable "x" doesn't exist at > all -- there is no key "x" in the global namespace. > > > It seems to me that "a slot to hold the variable is created for local > variables" is an implementation detail, not a language feature. CPython > could easily hide the difference by changing the exception from > UnboundLocalError to: > > NameError: local name 'x' does not exist > > and nobody would be any wiser. (Well, perhaps people who catch > UnboundLocalError, but why would you do that?) > > I also note that UnboundLocalError is a subclass of NameError, so > "variable exists but is not bound" is considered to be a special case of > "variable doesn't exist" rather than a completely independent case. In > that sense, I think I'm on solid ground to say that in Python variables > don't exist until they are bound to a value, and leave it to pedants like > you and I to mention that for CPython local variables have space reserved > for them by the compiler before they are bound. Very interesting, and a pleasant change of tone to boot. Thanks. Geremy Condra From clp2 at rebertia.com Mon Jul 12 00:14:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 21:14:44 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: > Thanks gang, > I'm gonna paste what I've put together, doesn't seem right. Am I way > off? > > Here's my code. > ?- It goes through a table Item > ?- Matches that Item ID to an API call > ?- Grabs the data, saves it and creates the thumbnail > ?- It dies due to Timeouts and Other baloney, all silly, nothing code > based. > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > for item in items: > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id > > ? ? ? ?url_array = [] > ? ? ? ?url_open = urllib.urlopen(url) > ? ? ? ?url_read = url_open.read().decode('utf-8') > > ? ? ? ?try: > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) > ? ? ? ? ? ? ? ?url_array.append(url_data) > > ? ? ? ? ? ? ? ?for detail in url_array: Unless I'm missing something, there's no need for url_array to exist at all. It starts out empty, you append url_data to it, then you iterate over it as `detail`; and you don't touch it anywhere else in the loop. Just s/detail/url_data/ and excise url_array altogether. As a bonus, there'll be one less level of indentation. Also, the reason your code doesn't work (currently, it just skips to the next item upon error) is because you're missing a surrounding `while True` loop (and associated embedded `break`) to do the retrying (see my or MRAB's examples). Additionally, stylistically I'd prefer the try-excepts to cover smaller and more targeted areas of the code, rather than having one giant blanket one for the entire loop body; perhaps that's just me though. Cheers, Chris -- How exactly does one acquire a prenominal "The"? http://blog.rebertia.com From debatem1 at gmail.com Mon Jul 12 00:18:36 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 00:18:36 -0400 Subject: [Python-ideas] explicitation lines in python ? In-Reply-To: References: <4C24FEAF.4030304@gmail.com> <4C26F710.4030902@gmail.com> Message-ID: On Sun, Jul 11, 2010 at 11:39 PM, Carl M. Johnson wrote: > On Sun, Jun 27, 2010 at 8:25 PM, Nick Coghlan wrote: > >> The availability of "nonlocal" binding semantics also makes the >> semantics much easier to define than they were in those previous >> discussions (the lack of clear semantics for name binding statements >> with an attached local namespace was the major factor blocking >> creation of a reference implementation for this proposal back then). >> >> For example: >> >> ?c = sqrt(a*a + b*b) where: >> ? ?a = retrieve_a() >> ? ?b = retrieve_b() >> >> could translate to something like: >> >> ?def _anon(): # *(see below) >> ? ?nonlocal c >> ? ?a = retrieve_a() >> ? ?b = retrieve_b() >> ? ?c = sqrt(a*a + b*b) >> ?_anon() >> >> *(unlike Python code, the compiler can make truly anonymous functions >> by storing them solely on the VM stack. It already does this when >> executing class definitions): > > I like this idea, but I would tweak it slightly. Maybe we should say > > EXPRESSION where: > ? ?BLOCK > > is equivalent to > > def _(): > ? ?BLOCK > ? ?return EXPRESSION > _() > > That way, c = a where: a = 7 would be equivalent to > > def _(): > ? a = 7 > ? return a > c = _() > > One advantage of this equivalence is it would make it easier to work > around a longstanding scoping gotcha. A na?ve coder might expect this > code to print out numbers 0 to 4: > > ? ?>>> fs = [] > ? ?>>> for n in range(5): > ? ?... ? ? def f(): > ? ?... ? ? ? ? print(item) > ? ?... ? ? fs.append(f) > ? ?... > ? ?>>> [f() for f in fs] > ? ?4 > ? ?4 > ? ?4 > ? ?4 > ? ?4 > ? ?[None, None, None, None, None] > > I think we all have enough experience to know this isn?t a totally > unrealistic scenario. I personally stumbled into when I was trying to > create a class by looping through a set of method names. > > To get around it, one could use a where clause like so: > > fs = [] > for n in range(5): > ? ?fs.append(f) where: > ? ? ? ?shadow = n > ? ? ? ?def f(): > ? ? ? ? ? ?print(shadow) > > This would print out 0 to 4 as expected and be equivalent to > > ? ?>>> fs = [] > ? ?>>> for n in range(5): > ? ?... ? ? def _(): > ? ?... ? ? ? ? shadow = n > ? ?... ? ? ? ? def f(): > ? ?... ? ? ? ? ? ? print(shadow) > ? ?... ? ? ? ? fs.append(f) > ? ?... ? ? _() > ? ?... > ? ?>>> [f() for f in fs] > ? ?0 > ? ?1 > ? ?2 > ? ?3 > ? ?4 > ? ?[None, None, None, None, None] > > I think a where-clause with def-like namespace semantics would be a > positive addition to Python, once the moratorium is up. > > -- Carl Johnson +1 from me, FWIW Geremy Condra From dannybos at gmail.com Mon Jul 12 00:20:19 2010 From: dannybos at gmail.com (The Danny Bos) Date: Sun, 11 Jul 2010 21:20:19 -0700 (PDT) Subject: IOError and Try Again to loop the loop. References: Message-ID: Thanks Chris, Agreed some of the code is a lot useless, I need to go through that stuff. So something like this (apologies for asking for some details, I'm not good at catching): items = Item.objects.all().filter(cover='').order_by('-reference_id') for item in items: url = "http://someaddress.org/books/?issue=%s" % item.reference_id url_array = [] url_open = urllib.urlopen(url) url_read = url_open.read().decode('utf-8') while True: try: url_data = simplejson.loads(url_read) url_array.append(url_data) for detail in url_array: if detail['artworkUrl']: cover_url = detail['artworkUrl'].replace(' ','%20') cover_open = urllib.urlretrieve(cover_url) cover_name = os.path.split(cover_url) [1] item.cover.save(cover_name, File(open(cover_open[0])), save=True) print "Cover - %s: %s" % (item.number, url) else: print "Missing - %s: %s" % (item.number, url) break except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) pass except IOError: print "IOError; Retrying..." pass print "Done" On Jul 12, 2:14?pm, Chris Rebert wrote: > On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: > > > > > > > Thanks gang, > > I'm gonna paste what I've put together, doesn't seem right. Am I way > > off? > > > Here's my code. > > ?- It goes through a table Item > > ?- Matches that Item ID to an API call > > ?- Grabs the data, saves it and creates the thumbnail > > ?- It dies due to Timeouts and Other baloney, all silly, nothing code > > based. > > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > > for item in items: > > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id > > > ? ? ? ?url_array = [] > > ? ? ? ?url_open = urllib.urlopen(url) > > ? ? ? ?url_read = url_open.read().decode('utf-8') > > > ? ? ? ?try: > > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) > > ? ? ? ? ? ? ? ?url_array.append(url_data) > > > ? ? ? ? ? ? ? ?for detail in url_array: > > Unless I'm missing something, there's no need for url_array to exist > at all. It starts out empty, you append url_data to it, then you > iterate over it as `detail`; and you don't touch it anywhere else in > the loop. Just s/detail/url_data/ and excise url_array altogether. As > a bonus, there'll be one less level of indentation. > > Also, the reason your code doesn't work (currently, it just skips to > the next item upon error) is because you're missing a surrounding > `while True` loop (and associated embedded `break`) to do the retrying > (see my or MRAB's examples). > > Additionally, stylistically I'd prefer the try-excepts to cover > smaller and more targeted areas of the code, rather than having one > giant blanket one for the entire loop body; perhaps that's just me > though. > > Cheers, > Chris > -- > How exactly does one acquire a prenominal "The"?http://blog.rebertia.com From clp2 at rebertia.com Mon Jul 12 00:34:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 21:34:35 -0700 Subject: IOError and Try Again to loop the loop. In-Reply-To: References: Message-ID: > On Jul 12, 2:14?pm, Chris Rebert wrote: >> On Sun, Jul 11, 2010 at 8:13 PM, The Danny Bos wrote: >> > Thanks gang, >> > I'm gonna paste what I've put together, doesn't seem right. Am I way >> > off? >> >> > Here's my code. >> > ?- It goes through a table Item >> > ?- Matches that Item ID to an API call >> > ?- Grabs the data, saves it and creates the thumbnail >> > ?- It dies due to Timeouts and Other baloney, all silly, nothing code >> > based. >> >> > items = Item.objects.all().filter(cover='').order_by('-reference_id') >> > for item in items: >> > ? ? ? ?url = "http://someaddress.org/books/?issue=%s" % item.reference_id >> >> > ? ? ? ?url_array = [] >> > ? ? ? ?url_open = urllib.urlopen(url) >> > ? ? ? ?url_read = url_open.read().decode('utf-8') >> >> > ? ? ? ?try: >> > ? ? ? ? ? ? ? ?url_data = simplejson.loads(url_read) >> > ? ? ? ? ? ? ? ?url_array.append(url_data) >> >> > ? ? ? ? ? ? ? ?for detail in url_array: >> >> Unless I'm missing something, there's no need for url_array to exist >> at all. It starts out empty, you append url_data to it, then you >> iterate over it as `detail`; and you don't touch it anywhere else in >> the loop. Just s/detail/url_data/ and excise url_array altogether. As >> a bonus, there'll be one less level of indentation. >> >> Also, the reason your code doesn't work (currently, it just skips to >> the next item upon error) is because you're missing a surrounding >> `while True` loop (and associated embedded `break`) to do the retrying >> (see my or MRAB's examples). >> >> Additionally, stylistically I'd prefer the try-excepts to cover >> smaller and more targeted areas of the code, rather than having one >> giant blanket one for the entire loop body; perhaps that's just me >> though. On Sun, Jul 11, 2010 at 9:20 PM, The Danny Bos wrote: > Thanks Chris, > > Agreed some of the code is a lot useless, I need to go through that > stuff. > So something like this (apologies for asking for some details, I'm not > good at catching): > > items = Item.objects.all().filter(cover='').order_by('-reference_id') > for item in items: > ? ?url = "http://someaddress.org/books/?issue=%s" % > item.reference_id > ? ?url_array = [] > ? ?url_open = urllib.urlopen(url) > ? ?url_read = url_open.read().decode('utf-8') > > ? ?while True: > ? ? ? ?try: > ? ? ? ? ? ? ? ?break > ? ? ? ?except ValueError: > ? ? ? ? ? ? ? ?print "Error Processing record: %s: %s" % > (item.reference_id, url) > ? ? ? ? ? ? ? ?pass > ? ? ? ?except IOError: > ? ? ? ? ? ? ? ?print "IOError; Retrying..." > ? ? ? ? ? ? ? ?pass > > print "Done" Yes, correct, that's essentially it, although the `pass` statements are superfluous, and I would personally put the `break` in a separate+new else-clause of the try-except for clarity; so the try-except part of the code would look like: try: # lots of code here except ValueError: print "Error Processing record: %s: %s" % (item.reference_id, url) except IOError: print "IOError; Retrying..." else: break Also, please avoid top-posting in the future; http://en.wikipedia.org/wiki/Top-posting#Top-posting Cheers, Chris -- http://blog.rebertia.com From sturlamolden at yahoo.no Mon Jul 12 00:52:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 11 Jul 2010 21:52:17 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" wrote: > Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like > Java in this respect, that's all; neither Java nor Python support 'swap'. x,y = y,x From nathan.alexander.rice at gmail.com Mon Jul 12 01:03:45 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Mon, 12 Jul 2010 01:03:45 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: Yeah, I long ago filed the in place place in the same folder as strings-as-sequences, all() returning True for an empty iterable and any returning True rather than the thing which triggered it. Almost always annoying and worked around, but that's the price you pay for the other nice stuff :) It just takes writing a few hundred lines of Java code for me to shrug and forget about it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Mon Jul 12 01:03:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 11 Jul 2010 22:03:50 -0700 Subject: Learn Python the Hard Way (online tutorial) References: Message-ID: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> I just came across this, a python tutorial purportedly intended for beginning programmers. I only read the first few pages and I'm not crazy about the approach, but I haven't seen it mentioned here, and some folks might like it: http://learnpythonthehardway.org/home From me+list/python at ixokai.io Mon Jul 12 01:10:19 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 22:10:19 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: <4C3AA3BB.4050404@ixokai.io> On 7/11/10 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > strings-as-sequences, all() returning True for an empty iterable and any > returning True rather than the thing which triggered it. You know, the latter two I can see an argument for, and could see the usefulness therein -- though I've never used either like that, but I consider that chance. I could see the use (and could readily write my own all/any in such a case, then keep it in my toolbox). But the first: what?! for ch in data: is exceptionally useful. Strings-as-sequences I've used hundreds, thousands of times. I use it constantly. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From clp2 at rebertia.com Mon Jul 12 01:50:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 22:50:46 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: On Sun, Jul 11, 2010 at 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > all() returning True for an empty iterable If you weren't taught about vacuous truth (or even identity elements) in Discrete Mathematics, someone fscked up. Said behavior is the absolute correct behavior from a formal logic standpoint. Cheers, Chris -- http://blog.rebertia.com From alf.p.steinbach+usenet at gmail.com Mon Jul 12 01:51:16 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 07:51:16 +0200 Subject: Easy questions from a python beginner In-Reply-To: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 12.07.2010 06:52: > On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like >> Java in this respect, that's all; neither Java nor Python support 'swap'. > > x,y = y,x > We're talking about defining a 'swap' routine that works on variables. Since Java/Python doesn't support pass by reference of variables it's not possible in these languages, i.e., you missed the point, or made a joke. :-) However, C# is very similar to Java, nearly all the way, except that in C# you can pass by reference. Remove that from C# and you have Java. Add that to Java and you have C#, roughly. No change in other aspects is needed. E.g. (ignore this if you've never heard about it, but it's a subtle point that you might be wondering about now) both Java and C# implement the definite assignment rule. I.e., there's nothing in the core semantics that prevents accessing/passing the variables by reference, although for Python and Java it could be a terminological nightmare, and for Python compounded to the n'th degree by the general confusion of a subset of the Python community about basic concepts. I don't know how C#'ers resolve the terminology... Cheers & hth., - Alf -- blog at From me+list/python at ixokai.io Mon Jul 12 01:52:38 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 22:52:38 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3AADA6.1090208@ixokai.io> On 7/11/10 7:25 PM, Alf P. Steinbach /Usenet wrote: > The alleged facts etc. you're referring are just that, alleged, by you. Two people come together and have a debate. Both present arguments. Both present cases. In the end, they are still in disagreement. You declare us, "religious", and therefore our opinions, arguments, facts, and conclusion are based solely on faith and unworthy of consideration on their merits. That, my friend, is an ad hominem attack. Hypocrite. And you are plonked. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From clp2 at rebertia.com Mon Jul 12 01:59:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Jul 2010 22:59:31 -0700 Subject: Learn Python the Hard Way (online tutorial) In-Reply-To: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> References: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> Message-ID: On Sun, Jul 11, 2010 at 10:03 PM, Paul Rubin wrote: > I just came across this, a python tutorial purportedly intended for > beginning programmers. ?I only read the first few pages and I'm not > crazy about the approach, but I haven't seen it mentioned here, and some > folks might like it: > > ?http://learnpythonthehardway.org/home "By Zed A. Shaw" Hm... - Chris From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 02:09:49 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 06:09:49 GMT Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: <4c3ab1ac$0$28662$c3e8da3@news.astraweb.com> On Sun, 11 Jul 2010 21:52:17 -0700, sturlamolden wrote: > On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python >> works like Java in this respect, that's all; neither Java nor Python >> support 'swap'. > > x,y = y,x Of course that's a good alternative, but that's not what Alf, or the original poster, are talking about. They're specifically talking about writing a function which swaps two variables in the enclosing scope. This is a good test of languages that support call-by-reference, e.g. Pascal: procedure swap(var x:integer, var y: integer): VAR tmp: integer; BEGIN tmp := x; x := y; y := x; END; If you pass two integer variables to swap(), Pascal will exchange their values. You can't do this in Python. You can get close if you assume the enclosing scope is global, or if you pass the name of the variables rather than the variables themselves, but even then you can't make it work reliably. Or at all. Naturally the swap() function itself is not terribly useful in a language like Python that makes exchanging variables so easy, but there are other uses for call-by-reference that aren't quite so trivial. However, I can't think of anything off the top of my head, so here's another trivial example that can't work in Python: s = "hello" call_something_magic(s) assert s == "goodbye" -- Steven From tjreedy at udel.edu Mon Jul 12 02:13:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:13:05 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: On 7/11/2010 1:48 PM, wheres pythonmonks wrote: > 2. How can I write a function, "def swap(x,y):..." so that "x = 3; y > = 7; swap(x,y);" given x=7,y=3?? > (I want to use Perl's Ref "\" operator, or C's&). > (And if I cannot do this [other than creating an Int class], is this > behavior limited to strings, > tuples, and numbers) Since you are just exploring, addendum to other answers: >>> x,y = 1,2 >>> def swapxy(): global x,y x,y=y,x >>> swapxy() >>> x,y (2, 1) Not too useful >>> s = [1,2] >>> def swap01(lis): lis[:2] = reversed(lis[:2]) # other versions possible >>> swap01(s) >>> s [2, 1] A function can *modify* an input object. When is does, the usual convention is that it should *not* return the object. -- Terry Jan Reedy From me+list/python at ixokai.io Mon Jul 12 02:30:47 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sun, 11 Jul 2010 23:30:47 -0700 Subject: Learn Python the Hard Way (online tutorial) In-Reply-To: References: <7x39vpcmvd.fsf_-_@ruckus.brouhaha.com> Message-ID: <4C3AB697.9050906@ixokai.io> On 7/11/10 10:59 PM, Chris Rebert wrote: > On Sun, Jul 11, 2010 at 10:03 PM, Paul Rubin wrote: >> I just came across this, a python tutorial purportedly intended for >> beginning programmers. I only read the first few pages and I'm not >> crazy about the approach, but I haven't seen it mentioned here, and some >> folks might like it: >> >> http://learnpythonthehardway.org/home > > "By Zed A. Shaw" > > Hm... Is there some significance to this name that I am unaware? Google points me to a wikipedia article on a guy who appears involved in both Python and Ruby. Is there something about him that colors or holds meaning for his approach? Just curious. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From tjreedy at udel.edu Mon Jul 12 02:51:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:51:59 -0400 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> Message-ID: On 7/11/2010 3:26 AM, rantingrick wrote: > > Another source of asininity seems to be the naming conventions of the > Python language proper! True/False start with an upper case and i > applaud this. However str, list, tuple, int, float --need i go > on...?-- start with lowercase. This is an anomaly, known to all long-time Pythoneers, due the the history of Python. Before 2.2 and unification of types and classes as new-style classes, those were all type constructor *functions*, not class names. The idea of breaking most every serious Python program on the planet by upper-casing them has been considered and so far rejected. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jul 12 02:56:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 02:56:34 -0400 Subject: Possible to create a read-only complex object? In-Reply-To: <1278867088.27525.1384321763@webmail.messagingengine.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: On 7/11/2010 12:51 PM, python at bdurham.com wrote: > I have a complex object with attributes that contain lists, sets, > dictionaries, and other objects. The lists and dictionaries may > themselves contain complex objects. > I would like to provide a read-only version of this type of object for > other developers to query for reporting. > Is there a way to prevent other developers from changing the attributes > of my complex and nested object? > In researching this question, I have identified __setattr__ and > __delattr__ as possible ways to prevent changes to simple attributes, > but I don't believe these magic methods will prevent others from > fiddling with attributes containing lists and dictionaries or the > contents of these lists and dictionaries. Python was not really not developed for multi-developer projects whose members are willing to stomp on each others objects. > Another idea I had was to create a wrapper object to proxy all access to > the original object. Is there a generic reciepe for this type of wrapper? -- Terry Jan Reedy From cs at zip.com.au Mon Jul 12 03:08:50 2010 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Jul 2010 17:08:50 +1000 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> References: <4c3a8151$0$28662$c3e8da3@news.astraweb.com> Message-ID: <20100712070850.GA14063@cskk.homeip.net> On 12Jul2010 02:43, Steven D'Aprano wrote: | On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote: | > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote: | >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what? | > | > For some reason, when I answer the phone and say "Hello, Steven | > speaking?" I often get called Peter. | | Er, without the question mark. Ah, so you get differing results when you use the question mark? Phonetic punctuation; Victor Borge would be proud. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A lot of people don't know the difference between a violin and a viola, so I'll tell you. A viola burns longer. - Victor Borge From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 03:45:31 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 07:45:31 GMT Subject: Possible to create a read-only complex object? References: <1278867088.27525.1384321763@webmail.messagingengine.com> Message-ID: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: > On 7/11/2010 12:51 PM, python at bdurham.com wrote: >> I have a complex object with attributes that contain lists, sets, >> dictionaries, and other objects. The lists and dictionaries may >> themselves contain complex objects. >> I would like to provide a read-only version of this type of object for >> other developers to query for reporting. Is there a way to prevent >> other developers from changing the attributes of my complex and nested >> object? >> In researching this question, I have identified __setattr__ and >> __delattr__ as possible ways to prevent changes to simple attributes, >> but I don't believe these magic methods will prevent others from >> fiddling with attributes containing lists and dictionaries or the >> contents of these lists and dictionaries. > > Python was not really not developed for multi-developer projects whose > members are willing to stomp on each others objects. I like the idea of competition-driven development, where the code that survives best in the face of hostile developers gets used. -- Steven From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 04:05:16 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 08:05:16 GMT Subject: Numpy now supports Python3, Scipy to follow soon Message-ID: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Pardon me if this has already been mentioned, but I didn't see it, and this is big big news. The latest release of numpy now supports Python 2.x and 3.x out of a single code base, and Scipy is predicted to follow soon. http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html If I can take the liberty of quoting Pauli Virtanen: An important point is that supporting Python 3 and Python 2 in the same code base can be done, and it is not very difficult either. It is also much preferable from the maintenance POV to creating separate branches for Python 2 and 3. Well done to all those who contributed to the effort! -- Steven From alf.p.steinbach+usenet at gmail.com Mon Jul 12 04:06:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 10:06:59 +0200 Subject: Design questions for C++ support for Python extensions (cppy) Message-ID: Hi. With the current cppy code the Python 3.1.1 doc's spam example extension module looks like this (actual working code): #include #include using namespace progrock; namespace { class Spam: public cppy::Module { public: Spam(): cppy::Module( L"spam", L"bl?b?rsyltet?y er bl?tt" ) {} PyObject* system( PyObject* args ) { const char *command; if( !PyArg_ParseTuple( args, "s", &command ) ) { return NULL; } int const sts = ::system( command ); return Py_BuildValue( "i", sts ); } }; } // namespace CPPY_MODULE_CROUTINE( Spam, system, L"Execute a shell command" ) PyMODINIT_FUNC PyInit_spam() { return cppy::safeInit< Spam >(); } Issues: 1. Wide string literals OK? The basic Python API often requires UTF-8 encoded byte strings. With C++ source code encoded using e.g. Windows ANSI Western, string literals with national characters such as Norwegian ??? then become gobbledegook or cause outright failure. I balanced the hypothetical need for string literals with national characters, versus perceived unnaturalness of wide string literals for *nix developers, in favor of the former, i.e. L"wide string literals". Related issue here: in Windows MinGW g++ can not compile utf-8 encoded source with BOM, while MSVC requires a BOM in order to detect the encoding. Is L"this" an acceptable decision if you were to use something like cppy? 2. Exception translation OK? The code within the 'system' member routine could conceivably be reduced to a single short line by adding some C++ support, but that would require use of exceptions to report errors. Translating C++ exceptions to Python exceptions does however add some overhead to every Python -> C++ call. Currently I do this only for the module initialization code, but should it be done for every exported method? Or perhaps as user choice? Benefit of translation e.g. reducing 'system' above to sweet single line. Cost is setup of try-block (negligible) and exception translation (inefficient). 3. Some unsafety OK? In 'PyInit_spam' there may be a window of opportunity for client code to Mess Things Up. Within the cppy::safeInit the C++ module object is created and creates a Python module object, and if anything fails then the C++ side frees the Python object. And after PyInit_spam has returned to Python the cleanup responsibility resides with the Python interpreter: freeing the Python module object causes the C++ object to be destroyed. But if say the client code's equivalent of 'PyInit_spam' calls cppy::safeInit and just discards the result and returns 0 (say) to Python, then it seems to not be documented whether Python will free the Python module, i.e. possible leak. 4. Threading? Is it necessary to make singletons/statics thread safe? Or does Python ensure that no other threads execute while PyInit_spam is called? Can it be called simultaneously by two or more threads? 5. Reload of interpreter? My impression from the documentation is that finalization and reinit of the interpreter is something that an application shouldn't really do, and that an extension developer need not worry about that happening. Is it so? Cheers, - Alf -- blog at From clp2 at rebertia.com Mon Jul 12 04:11:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 01:11:53 -0700 Subject: Possible to create a read-only complex object? In-Reply-To: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: >> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>> I have a complex object with attributes that contain lists, sets, >>> dictionaries, and other objects. The lists and dictionaries may >>> themselves contain complex objects. >>> I would like to provide a read-only version of this type of object for >>> other developers to query for reporting. Is there a way to prevent >>> other developers from changing the attributes of my complex and nested >>> object? >>> In researching this question, I have identified __setattr__ and >>> __delattr__ as possible ways to prevent changes to simple attributes, >>> but I don't believe these magic methods will prevent others from >>> fiddling with attributes containing lists and dictionaries or the >>> contents of these lists and dictionaries. >> >> Python was not really not developed for multi-developer projects whose >> members are willing to stomp on each others objects. > > I like the idea of competition-driven development, where the code that > survives best in the face of hostile developers gets used. http://en.wikipedia.org/wiki/Defensive_programming Cheers, Chris From clp2 at rebertia.com Mon Jul 12 04:14:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 01:14:49 -0700 Subject: Netbeans plugin and Python 3 In-Reply-To: References: Message-ID: On Fri, Jul 9, 2010 at 9:27 AM, Nitin Pawar wrote: > Hi, > I never tried python3.0 with netbeans but I use python 2.6.5 with netbean > 6.7.1 > Here is how I managed to change from python 2.5 (netbeans default) to 2.6.5 > 1) From the tools-> plugins section install python plugin > 2) Once plugin is installed just restart netbeans so that plugin is > activated > 3) After plugin is activated, you can edit default python version by tools-> > python platform > 4) It will open a configure window, where you can point python to newly > installed 3.0 version. > I hope that helps. > Thanks, > nitin > > On Fri, Jul 9, 2010 at 9:30 PM, wrote: >> >> 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. python instructor (Greg) >> ? 2. Re: ipython problem in opening a file (Youngung Jeong) >> ? 3. Netbeans plugin and Python 3 (Chrix) >> ? 4. Re: python instructor (Ed Keith) >> ? 5. Last day to submit your Surge 2010 CFP! (Jason Dixon) >> ? 6. SqlAlchemy: remote connection on problem on mysql database (Massi) >> ? 7. do (Robin) >> ? 8. Re: Opinions please -- how big should a single module grow? >> ? ? ?(Tomasz Rola) >> ? 9. Re: Python -- floating point arithmetic (Aahz) >> ?10. Re: 'reload M' doesn't update 'from M inport *' (Aahz) >> ?11. Cpp + Python: static data dynamic initialization in *nix >> ? ? ?shared lib? (Alf P. Steinbach /Usenet) >> ?12. Why there is no "setdefaultencoding" in sys module? (crow) Netiquette note: Please don't include the entire digest in future posts to the mailinglist. Cheers, Chris From almar.klein at gmail.com Mon Jul 12 04:29:50 2010 From: almar.klein at gmail.com (Almar Klein) Date: Mon, 12 Jul 2010 10:29:50 +0200 Subject: Numpy now supports Python3, Scipy to follow soon In-Reply-To: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> References: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Message-ID: On 12 July 2010 10:05, Steven D'Aprano wrote: > Pardon me if this has already been mentioned, but I didn't see it, and > this is big big news. > I haven't heard it yet, this is great news! Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 04:42:05 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 08:42:05 GMT Subject: Possible to create a read-only complex object? References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3ad55d$0$28664$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 01:11:53 -0700, Chris Rebert wrote: > On Mon, Jul 12, 2010 at 12:45 AM, Steven D'Aprano > wrote: >> On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: >>> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>>> I have a complex object with attributes that contain lists, sets, >>>> dictionaries, and other objects. The lists and dictionaries may >>>> themselves contain complex objects. >>>> I would like to provide a read-only version of this type of object >>>> for other developers to query for reporting. Is there a way to >>>> prevent other developers from changing the attributes of my complex >>>> and nested object? >>>> In researching this question, I have identified __setattr__ and >>>> __delattr__ as possible ways to prevent changes to simple attributes, >>>> but I don't believe these magic methods will prevent others from >>>> fiddling with attributes containing lists and dictionaries or the >>>> contents of these lists and dictionaries. >>> >>> Python was not really not developed for multi-developer projects whose >>> members are willing to stomp on each others objects. >> >> I like the idea of competition-driven development, where the code that >> survives best in the face of hostile developers gets used. > > http://en.wikipedia.org/wiki/Defensive_programming Meh, defensive programming is designed to deal with bugs and hostile outsiders. I mean writing your functions and classes to deal with actively hostile coding *partners* who are trying to destroy your class so their class will survive to fight another day... There's probably a Dilbert cartoon about it. I'm not serious of course, if the members of your project are trying to screw your code, you're in trouble. I just like the idea of competition- driven development being the next buzzword, for when agile, test-driven, or pair-programming development is no longer enough. -- Steven From bartc at freeuk.com Mon Jul 12 04:48:04 2010 From: bartc at freeuk.com (bart.c) Date: Mon, 12 Jul 2010 09:48:04 +0100 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: "MRAB" wrote in message news:mailman.591.1278900548.1673.python-list at python.org... > Alf P. Steinbach /Usenet wrote: >> def foo(): >> print( blah ) >> blah = "this is both an assignment and a declaration causing it to >> exist" >> >> foo() >> >> Clearly when the exception is raised, referring to the variable, the >> variable exists. > How about this: > > >>> def foo(): > print("Before:", locals()) > x = 0 > print("After:", locals()) > > > >>> foo() > Before: {} > After: {'x': 0} That's interesting. So in Python, you can't tell what local variables a function has just by looking at it's code: def foo(day): if day=="Tuesday": x=0 print ("Locals:",locals()) #foo("Monday") Does foo() have 1 or 2 locals? That might explain some of the difficulties of getting Python implementations up to speed. -- Bartc From debatem1 at gmail.com Mon Jul 12 05:01:30 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 05:01:30 -0400 Subject: Possible to create a read-only complex object? In-Reply-To: <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> References: <1278867088.27525.1384321763@webmail.messagingengine.com> <4c3ac81b$0$28662$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 3:45 AM, Steven D'Aprano wrote: > On Mon, 12 Jul 2010 02:56:34 -0400, Terry Reedy wrote: > >> On 7/11/2010 12:51 PM, python at bdurham.com wrote: >>> I have a complex object with attributes that contain lists, sets, >>> dictionaries, and other objects. The lists and dictionaries may >>> themselves contain complex objects. >>> I would like to provide a read-only version of this type of object for >>> other developers to query for reporting. Is there a way to prevent >>> other developers from changing the attributes of my complex and nested >>> object? >>> In researching this question, I have identified __setattr__ and >>> __delattr__ as possible ways to prevent changes to simple attributes, >>> but I don't believe these magic methods will prevent others from >>> fiddling with attributes containing lists and dictionaries or the >>> contents of these lists and dictionaries. >> >> Python was not really not developed for multi-developer projects whose >> members are willing to stomp on each others objects. > > I like the idea of competition-driven development, where the code that > survives best in the face of hostile developers gets used. You jest, but I've actually done this. The goal was to test security awareness among developers- we formed two tiger teams, one to develop code and one to exploit it, and had one member of the developer group as a saboteur. His goal was to put in the largest possible vulnerability without getting caught, while the others wanted to produce the most secure code they could that met spec. Geremy Condra From jeanmichel at sequans.com Mon Jul 12 05:42:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 11:42:22 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: <4C3AE37E.2040405@sequans.com> Aahz wrote: > In article , > Jean-Michel Pichavant wrote: > >> PS : You're misusing the del statement. It does not remove any object >> > >from mmory, however, it removes the reference to it, the object is still > >> in memory. They are very few cases where del is usefull in python, so >> try to avoid using it as well. >> > > The first two sentences are true; the last sentence is completely wrong. > I've got lots of code using del, and it's a critically useful element of > dictionary manipulation. > Can you please give a short example ? I'm not challenging though, just curious. JM From jeanmichel at sequans.com Mon Jul 12 05:47:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 11:47:00 +0200 Subject: 'reload M' doesn't update 'from M inport *' In-Reply-To: <1278710063.2362.75.camel@hatchbox-one> References: <1278680545.2376.30.camel@hatchbox-one> <4C375E8A.6080506@sequans.com> <1278710063.2362.75.camel@hatchbox-one> Message-ID: <4C3AE494.3090700@sequans.com> >> Hi, >> >> Don't use reload, this is nothing but a trap, espacially if your using >> it to update your objects with the code you are writting. >> >> JM >> > > I've found "reload" very usable for development in IDLE. IDLE memorizes > my input, and the variables I assign output to. If restart IDLE I lose > it all and start over. That is an awfully awkward alternative to > "reload", an alternative I wouldn't consider. > I found "reload" tricky with several modules, because all > dependencies need to be updated and which way they go isn't always > obvious. Reloading all modules in the right order works for me. The > reload commands come up with Alt-P as long, precisely, as I don't > restart IDLE. > Instead of writing your test code in the IDLE shell, write it into a file, an run this file in IDLE (from the IDLE file edit window hit F5). That way restarting from the begining is costless. If you insist on using reload, then you've already been given helpful answers, understanding the import model is always a good thing anyway :) JM From robin at reportlab.com Mon Jul 12 05:52:00 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 12 Jul 2010 10:52:00 +0100 Subject: round issue Message-ID: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> A client wants to know why his db number -9.85 gets displayed by some simple code as -9.8 I looked at the number and see that >>> -9.85 -9.8499999999999996 ie I expect simple rounding to produce the observed result and indeed >>> '%.1f' % -9.85 '-9.8' however, when I use round I get an unexpected result ie >>> round(-9.85,1) -9.9000000000000004 according to its definition > round(x[, n])? > Return the floating point value x rounded to n digits after the decimal point. > If n is omitted, it defaults to zero. The result is a floating point number. > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 (so. for example, > round(0.5) is 1.0 and round(-0.5) is -1.0). so looking at the absolute differences I see >>> abs(-9.9 - -9.85) 0.050000000000000711 >>> abs(-9.8 - -9.85) 0.049999999999998934 ie the -9.8 value appears closer and at least to a primitive test >>> abs(-9.9 - -9.85) > abs(-9.8 - -9.85) True the distance from the -9.9 result is larger, however, that may be because the model numbers for -9.8 & -9.9 differ in distance from the true 10**-n values eg >>> -9.9 -9.9000000000000004 >>> -9.8 -9.8000000000000007 What value should round(-9.85,1) return? Is the result explainable in python (ie without resort to the internal FP representations etc etc)? -- Robin Becker From mal at egenix.com Mon Jul 12 06:04:16 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 12 Jul 2010 12:04:16 +0200 Subject: Python conference and user group statistics Message-ID: <4C3AE8A0.5070901@egenix.com> Hello, I am currently working on a Python Software Foundation (PSF) project to create marketing material for Python with the aim of providing this to Python conferences and user groups. In order to come up with reasonable figures for the number of brochures and flyers to print, I'd like to get a rough idea about the number of attendees of the various Python conferences and user group meetings. It would be great, if you could report the approx. number of attendees coming to the events and the frequency with which you hold the conferences/meetings. I'm also interested in whether English as language of the marketing material would suffice or whether having the material in other languages would result in better acceptance among your attendees. These are the list of conferences and user groups I'm currently using as basis for the survey: http://www.python.org/community/workshops/ http://wiki.python.org/moin/LocalUserGroups Please reply either in private email or CC to my email address. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 12 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2010-07-19: EuroPython 2010, Birmingham, UK 6 days to go ::: 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 duncan.booth at invalid.invalid Mon Jul 12 06:09:30 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Jul 2010 10:09:30 GMT Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: "Alf P. Steinbach /Usenet" wrote: > * sturlamolden, on 12.07.2010 06:52: >> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet"> +use... at gmail.com> wrote: >> >>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. >>> Python works like Java in this respect, that's all; neither Java nor >>> Python support 'swap'. >> >> x,y = y,x >> > > We're talking about defining a 'swap' routine that works on variables. > > Since Java/Python doesn't support pass by reference of variables it's > not possible in these languages, i.e., you missed the point, or made a > joke. :-) > I think talking about a swap function is confusing the issue somewhat: you don't need to define a swap function in Python because the language supports the functionality directly, but that is just hiding the wider question of what you do in Python instead of using reference or in/out arguments. The simple answer is that Python makes it easy to return more than result from a function, so for every 'out' parameter just return one more result, and for a 'ref' parameter just bind that result back to the same name as you passed in. Note that this gives you more flexibility than languages with 'out' or 'ref' parameters as the caller of the function can decide whether to overwrite the original name or create a new one. A literal implementation of 'swap' in Python is possible but pretty pointless: def swap(a, b): return b, a ... x, y = swap(x, y) but it makes a lot of sense when you move to functions that actually do something useful: scheme, netloc, path, parms, query, fragment = urlparse(url) and there's even a convention for ignoring results we don't care about: head, _, tail = line.partition(':') -- Duncan Booth http://kupuguy.blogspot.com From dhruvbird at gmail.com Mon Jul 12 06:10:34 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 12 Jul 2010 03:10:34 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> Message-ID: On Jul 12, 5:30?am, News123 wrote: > dhruvbird wrote: > > > On a side note, is there any other way to append to a list using > > slices (apart from the one below): > > x[len(x):len(x)] = [item to append] > > dy you mean > x.extend([1,2,3]) No, I meant x.append(4) Except that I want to accomplish it using slices. (I can do it as x[lex(x):] = [item_to_append] but is there any other way?) Regards, -Dhruv. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 06:26:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 10:26:29 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: > That's interesting. So in Python, you can't tell what local variables a > function has just by looking at it's code: In the presence of "exec", you can't really tell *anything*. >>> def f(s): ... exec s ... print locals() ... >>> f("x = 2;y = None") {'y': None, 'x': 2, 's': 'x = 2;y = None'} > def foo(day): > if day=="Tuesday": > x=0 > print ("Locals:",locals()) > > #foo("Monday") > > Does foo() have 1 or 2 locals? That's easy for CPython: it prepares two slots for variables, but only creates one: >>> foo("Monday") ('Locals:', {'day': 'Monday'}) >>> foo.func_code.co_varnames ('day', 'x') >>> foo.func_code.co_nlocals 2 So, the question is, is x a local variable or not? It's not in locals, but the function clearly knows that it could be. > That might explain some of the > difficulties of getting Python implementations up to speed. I'm not quite sure why you say that. -- Steven From jeanmichel at sequans.com Mon Jul 12 06:34:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 12:34:46 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3a793e$0$28662$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4C3AEFC6.3000102@sequans.com> Steven D'Aprano wrote: >> My complaint (an oddly >> enough the title of this thread!) concerns the fact that Python treats 0 >> as False and every integer above and below 0 as True. Which is another >> example of how *some* aspects of Python support bad coding styles. >> > > Yes, Python does support bad coding styles. The treatment of 0 as a false > value is not one of them though. > > Well, actually some people might think otherwise. While I disagree with the OP flaming style, one could argue that muting an integer into a boolean makes no sense (I'm one of them). You can still do it, but there is no "right" way to do it. You can decide that everything else than 0 is True, but you could also pickup the integer 3 as false value, it would work as well since it makes no sense. This is just an arbitrary definition. Where the OP is fooling himself, is that you can't state that bool-ing an integer makes no sense and state the line after that 0 *should* | *has to* return True. I personally can live with 0 == False (with all due respect to our C-coding ancestors :) ), however as one of my personal coding rule I avoid using it. I prefere to explicitly write what I want to test: if myInt <> 0: or if myInt is not None: etc... That way I do not rely on a arbitrary int-to-bool mutation. JM From jeanmichel at sequans.com Mon Jul 12 06:42:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Jul 2010 12:42:51 +0200 Subject: Naming Conventions, Where's the Convention Waldo? In-Reply-To: <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> Message-ID: <4C3AF1AB.1090203@sequans.com> rantingrick wrote: > On Jul 11, 3:03 am, "G?nther Dietrich" > wrote: > > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. >> > > "int" for an Integer is stupid? > "list" for a List is stupid? > "str" for a String is stupid? > > What am i missing? > def func154(): int32 = 24 list18 = [int32, 14] str14 = "" for int89 in list18: if int89 == int32 or int89 == 88: str14 = "I am missing everything" if str14: print str14 >>> func154() >>> "I am missing everything" JM From dickinsm at gmail.com Mon Jul 12 06:44:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 03:44:23 -0700 (PDT) Subject: round issue References: Message-ID: <2876a1b4-2f1e-4355-866f-d4b271cf3e99@e5g2000yqn.googlegroups.com> On Jul 12, 10:52?am, Robin Becker wrote: > What value should round(-9.85,1) return? Is the result explainable in python (ie > without resort to the internal FP representations etc etc)? As you observe, the closest float to -9.85 is actually just a little smaller (i.e., closer to 0) than -9.85: Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> decimal.Decimal(-9.85) Decimal('-9.8499999999999996447286321199499070644378662109375') So you're right: round(-9.85, 1) *should* return -9.8. The 2.x (for x <= 6) version of round is a bit deficient in that respect. Internally, it's doing the obvious thing: namely, multiplying by 10.0, rounding to the nearest integer, then dividing by 10.0. The problem is that this not-quite-9.85 value, when multiplied by 10, becomes (as a result of rounding error) *exactly* 98.5, which then gets rounded *up* to 99 instead of down to 98. This is fixed in Python 2.7, and in Python 3.x. (The code that was introduced for the new short float repr made it easy to fix.) That said, if your client really *means* -9.85 (rather than some binary approximation to it), and wants it to round in a predictable manner, the right way to fix this would be to use Decimal instead of float to represent the number. That way, you can also specify what rounding mode you want (instead of relying on the default round-half- away-from-zero in 2.x or round-half-to-even in 3.x.) >>> decimal.Decimal('-9.85').quantize(decimal.Decimal('0.1'), rounding=decimal.ROUND_HALF_UP) Decimal('-9.9') >>> decimal.Decimal('-9.85').quantize(decimal.Decimal('0.1'), rounding=decimal.ROUND_HALF_EVEN) Decimal('-9.8') -- Mark From nospam at nospam.com Mon Jul 12 06:49:05 2010 From: nospam at nospam.com (Gilles Ganault) Date: Mon, 12 Jul 2010 12:49:05 +0200 Subject: Only one forum app in Python? References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Sat, 10 Jul 2010 18:37:00 +0200, Bruno Desthuilliers wrote: >There are almost a dozen of Python "forum apps" for Django alone, and >Python is known as "the language with more web frameworks than keywords". Thanks for the tip. I'll head that way. From hniksic at xemacs.org Mon Jul 12 07:20:45 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 12 Jul 2010 13:20:45 +0200 Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> Message-ID: <87630lrlo2.fsf@busola.homelinux.net> dhruvbird writes: > No, I meant x.append(4) > Except that I want to accomplish it using slices. > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > way?) It seems that you've found a way to do so, so why do you need another way? Are you after elegance? Efficiency? Brevity? Here are some other ways to express the same, and all use slices in some way: x[slice(len(x), None)] = [item_to_append] x.__setitem__(slice(len(x), None), [item_to_append]) x.__setslice__(len(x), len(x), [item_to_append]) ...but I have no idea why any of them would make any more sense than x[len(x):] = [item_to_append]. From fuzzyman at gmail.com Mon Jul 12 07:51:24 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Mon, 12 Jul 2010 04:51:24 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: <6395ee27-81be-4531-9d5d-e39dcf8fa5b5@w31g2000yqb.googlegroups.com> Message-ID: <11e013ef-2ac9-4991-b151-eb7258bd7437@41g2000yqn.googlegroups.com> On Jul 12, 1:21?am, rantingrick wrote: > On Jul 11, 5:28?pm,Fuzzyman wrote: > > > But why hijack someone else's announcement to do that? Congratulations > > alone would have been great. However good your intentions your message > > came across as "but it would really have been better if you had been > > doing something else instead...". > > Micheal i think you're just simply projecting some inner feelings on > to my post resulting in a complete mis-understanding. And i *did not* > say the project was useless, on the contrary i am very happy the OP > resurrected this lost script. I only suggested a similar project that > the OP *may* find to be interesting. Maybe not, but lets leave the > decision for the OP, Ok. Plenty of people have told you in multiple threads how you come across. Eventually you have to realise that they aren't *all* projecting... :-) Michael -- http://www.voidspace.org.uk/ From prologic at shortcircuit.net.au Mon Jul 12 08:01:51 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 12 Jul 2010 22:01:51 +1000 Subject: Only one forum app in Python? In-Reply-To: References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Mon, Jul 12, 2010 at 8:49 PM, Gilles Ganault wrote: >>There are almost a dozen of Python "forum apps" for Django alone, and >>Python is known as "the language with more web frameworks than keywords". Speaking of frameworks and python forums, sahriswiki 91) is not a forum, but it's goals are to have a best-of-mix of features from blogging, wiki and cms engines. cheers James 1. http://sahriswiki.org/ -- -- James Mills -- -- "Problems are solved by method" From bartc at freeuk.com Mon Jul 12 08:56:38 2010 From: bartc at freeuk.com (bart.c) Date: Mon, 12 Jul 2010 13:56:38 +0100 Subject: Easy questions from a python beginner In-Reply-To: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... > On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: > >> That's interesting. So in Python, you can't tell what local variables a >> function has just by looking at it's code: >> def foo(day): >> if day=="Tuesday": >> x=0 >> print ("Locals:",locals()) >> >> #foo("Monday") >> >> Does foo() have 1 or 2 locals? > > That's easy for CPython: it prepares two slots for variables, but only > creates one: > >>>> foo("Monday") > ('Locals:', {'day': 'Monday'}) >>>> foo.func_code.co_varnames > ('day', 'x') >>>> foo.func_code.co_nlocals > 2 > > So, the question is, is x a local variable or not? It's not in locals, > but the function clearly knows that it could be. So Alf P.S. could be right; x exists, but Python pretends it doesn't until it's assigned to. >> That might explain some of the >> difficulties of getting Python implementations up to speed. > > I'm not quite sure why you say that. Only that an implementation might be obliged to keep these various tables updated during function execution, instead of just at entry and exit. -- Bartc From nathan.alexander.rice at gmail.com Mon Jul 12 09:20:39 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Mon, 12 Jul 2010 09:20:39 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: Stephen: I'm not adverse to being able to do that, but the number of times that I've wanted to do that is greatly outweighed by the number of times I've had to pass a function "(somestring,)" or call "if isinstance(foo, basestring): ..." to avoid producing a bug. The more abstract and adaptive the code you are writing, the more annoying it gets - you end up with a rats nest of string instance checks and strings wrapped in tuples. Looking at my code, I don't have a lot of use cases for string slicing or iterating character by character. Most of the time I use the string methods, they're faster and (IMO) clearer - lower, index/rindex, find, etc. One use case that I avoid is extracting substrings, by slicing out the results of rfind. There's a good case for this but I feel it's brittle so I usually just jump to regular expressions (and it could be performed equally well with a substring method). That doesn't mean I don't think it's useful, just that as it stands the default language behavior is bug producing, and in my opinion people would be equally well served with an as_list method on strings that makes the behavior explicit. Chris: Let's not run around questioning people's math skills, that's actually my area of expertise, and it's impolite besides :) While having all([]) return True from a formal standpoint "makes sense" it typically reduces people to writing "if all(something) and something:", because feeding an iterable that has been filtered in some way (and thus has a range between 0 and n, where n is the length of the original iterable) is an incredibly common use case. In fact, I'm going to go out on a limb here and say there are a lot of bugs floating around that haven't been caught because the code author used all() under the assumption that it would be passed a non-empty list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcl.office at googlemail.com Mon Jul 12 10:04:08 2010 From: mcl.office at googlemail.com (mcl) Date: Mon, 12 Jul 2010 07:04:08 -0700 (PDT) Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing Message-ID: My Code `import os from PIL import Image from iptcinfo import IPTCInfo info = IPTCInfo('test.jpg') print info.keywords, info.supplementalCategories, info.contacts caption = info.data['caption/abstract'] print caption` running Win XP SP3 I get the message No module: iptcinfo I have downloaded iptcinfo and placed it in python27\Lib\site-packages \iptcinfo I guessed that was the right place, because that is where PIL ended up, but that had a fancy installer with it. As you will appreciate, I am very much an amateur in all this. I can code a bit of python, but where everything goes and links is a complete mystery. All I want is to write a quick script which extracts the Caption field from a directory of JPEGS. I get the filenames and the dimensions with PIL, but I need IPTCinfo to get at the Caption field. If anyone can throw any light on what I need to do or which stupid mistake I have made, I would be most grateful. Richard From invalid at invalid.invalid Mon Jul 12 10:19:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:19:32 +0000 (UTC) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: On 2010-07-09, Les Schaffer wrote: > i have been asked to guarantee that a proposed Python application will > run continuously under MS Windows for two months time. And i am looking ^^^^^^^^^^ IMO, that's going to be your main problem. -- Grant Edwards grant.b.edwards Yow! PIZZA!! at gmail.com From invalid at invalid.invalid Mon Jul 12 10:40:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:40:47 +0000 (UTC) Subject: Easy questions from a python beginner References: Message-ID: On 2010-07-11, Thomas Jollans wrote: > On 07/11/2010 08:45 PM, wheres pythonmonks wrote: >> On #3: Sorry this is confusing, but I was browsing some struct array >> code from numpy, in which one of the columns contained strings, but >> the type information, supplied in numpy.array's dtype argument, >> specified the type as a an "object" not a string. A string is an object. >> Just wondering why one would do that. > > No expert on numpy, but maybe storing object references is cheaper than > storing strings here ? Strings are objects. IIRC, numpy has special homogeneous array types to hold certain scalar values: byte, int, float, complex. Those special array types allow for very efficient storage and operations. If you want an array of any other type, or a heterogeneous array, then you use an array of objects and then you can put anything into the array (including strings). -- Grant Edwards grant.b.edwards Yow! The PINK SOCKS were at ORIGINALLY from 1952!! gmail.com But they went to MARS around 1953!! From newsuser at stacom-software.de Mon Jul 12 10:43:21 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Mon, 12 Jul 2010 16:43:21 +0200 Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) Message-ID: Hello together, python: 2.5.1 palttform: winXP I'm using pickle.dump and pickle.load with data that is created in a wrapped (boost.python) piece of C++ code. pickle.dump works fine. pickle.load creates the following exception: [...] data = pickle.load(input) File "C:\Python25\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python25\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python25\lib\pickle.py", line 954, in load_float self.append(float(self.readline()[:-1])) ValueError: invalid literal for float(): -1.#IND - I'm not sure what -1.#IND means. Can somebody assist? - As pickle write the data I'm a bit confused, that is can't be unpickled it. Is that a bug or a feature? BTW: I'm tied to version 2.5 of python Thank and regards Alexander From invalid at invalid.invalid Mon Jul 12 10:51:53 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:51:53 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: On 2010-07-12, Alexander Eisenhuth wrote: > python: 2.5.1 > palttform: winXP > > I'm using pickle.dump and pickle.load with data that is created in a > wrapped (boost.python) piece of C++ code. pickle.dump works fine. > pickle.load creates the following exception: > > [...] > data = pickle.load(input) > File "C:\Python25\lib\pickle.py", line 1370, in load > return Unpickler(file).load() > File "C:\Python25\lib\pickle.py", line 858, in load > dispatch[key](self) > File "C:\Python25\lib\pickle.py", line 954, in load_float > self.append(float(self.readline()[:-1])) > ValueError: invalid literal for float(): -1.#IND > > - I'm not sure what -1.#IND means. That's an infinity. > Can somebody assist? In Python 2.x, pickle doesn't handle infinities and NaNs. > - As pickle write the data I'm a bit confused, that is can't be > unpickled it. Is that a bug or a feature? IMO, it's a bug. It's been fixed in 3.x. > BTW: I'm tied to version 2.5 of python If you want to pickle floating point data that includes infinities and NaNs, you need to write your own handler for floating point values. When pickling you need to check for infinities and NaNs and output some defined strings. When unpickling, you need to check for those strings and generate infinities and NaNs as appropriate. The CPython 2.x version of pickle just uses the underlying C library routines to print and parse floating point values. If those libraries are broken in the way that they represent infinity and NaN, then pickle is broken in the same manner. Windows standard libraries are broken. When formatting floating point values, it produces strings that it can't parse as input. IIRC, Linux works better -- but if you want something that you know is going to work (and work cross-platform), then you need to write your own floating point pickle/unpickle methods, and hook them into the pickle module. -- Grant Edwards grant.b.edwards Yow! Uh-oh!! I'm having at TOO MUCH FUN!! gmail.com From invalid at invalid.invalid Mon Jul 12 10:54:25 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 12 Jul 2010 14:54:25 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: On 2010-07-12, Grant Edwards wrote: > On 2010-07-12, Alexander Eisenhuth wrote: > >> python: 2.5.1 >> palttform: winXP >> >> I'm using pickle.dump and pickle.load with data that is created in a >> wrapped (boost.python) piece of C++ code. pickle.dump works fine. >> pickle.load creates the following exception: >> >> [...] >> data = pickle.load(input) >> File "C:\Python25\lib\pickle.py", line 1370, in load >> return Unpickler(file).load() >> File "C:\Python25\lib\pickle.py", line 858, in load >> dispatch[key](self) >> File "C:\Python25\lib\pickle.py", line 954, in load_float >> self.append(float(self.readline()[:-1])) >> ValueError: invalid literal for float(): -1.#IND >> >> - I'm not sure what -1.#IND means. > > That's an infinity. Oops, I just noticed that I misread that. 1.#INF is an infinity, 1.#IND is an "indefinite", or what everybody outside of Microsoft calls a NaN (Not-a-Number). -- Grant Edwards grant.b.edwards Yow! ONE LIFE TO LIVE for at ALL MY CHILDREN in ANOTHER gmail.com WORLD all THE DAYS OF OUR LIVES. From sturlamolden at yahoo.no Mon Jul 12 10:59:12 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 12 Jul 2010 07:59:12 -0700 (PDT) Subject: Easy questions from a python beginner References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" wrote: > We're talking about defining a 'swap' routine that works on variables. I did not miss the point. One cannot make a swap function that rebinds its arguments in the calling stack frame. But a swap function can swap values, given that the type is not immutable: def swap(a,b): a[0],b[0] = b[0],a[0] >>> a,b = [1],[2] >>> swap(a,b) >>> print a,b [2] [1] From dickinsm at gmail.com Mon Jul 12 11:03:07 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 15:03:07 +0000 (UTC) Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) References: Message-ID: Alexander Eisenhuth stacom-software.de> writes: > File "C:\Python25\lib\pickle.py", line 954, in load_float > self.append(float(self.readline()[:-1])) > ValueError: invalid literal for float(): -1.#IND > > - I'm not sure what -1.#IND means. Can somebody assist? It's the Windows way of representing a NaN (not a number). A NaN is typically what you get when you try to perform an invalid floating-point operation, like taking the square root of a negative number, or dividing 0.0 by 0.0. Some people also use NaNs to represent uninitialized values, or as placeholders for missing data. > - As pickle write the data I'm a bit confused, that is can't > be unpickled it. Is that a bug or a feature? Well, it's certainly not ideal. It shouldn't be a problem in Python 2.6 or 2.7, though; unfortunately, Python 2.5 is no longer receiving bugfixes, so it's not going to change there. > BTW: I'm tied to version 2.5 of python Have you tried using pickle protocol 1 or 2, instead of pickle protocol 0? That may well solve your problem. (Those protocols write out the binary form of a float directly, instead of reading and writing a string representation.) -- Mark From airscorp at otenet.gr Mon Jul 12 11:11:11 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Mon, 12 Jul 2010 18:11:11 +0300 Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing In-Reply-To: References: Message-ID: <4C3B308F.3000300@otenet.gr> Hi Richard! > I have downloaded iptcinfo and placed it in python27\Lib\site-packages > \iptcinfo > > I guessed that was the right place, because that is where PIL ended > up, but that had a fancy installer with it. > > You did place it in the right path, but the "fancy installer" does one more thing, it registers the package into the python-path, so python can get to it. I've long switched from windows unfortunately and can't remember the way it does this though, so you can do it manually. Have some good news though: I looked in the IPTCinfo package and it does indeed include a setup.py, which is a standard way of installing python packages. All you need to do is unpack the package to any folder and run setup.py install from that folder, which should take care of everything for you. Some documentation on installing packages for you to read: http://docs.python.org/install/ Nick From gherron at islandtraining.com Mon Jul 12 12:42:25 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 12 Jul 2010 09:42:25 -0700 Subject: round issue In-Reply-To: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3B45F1.2020109@islandtraining.com> On 07/12/2010 02:52 AM, Robin Becker wrote: > A client wants to know why his db number -9.85 gets displayed by some > simple code as -9.8 > > I looked at the number and see that > > >>> -9.85 > -9.8499999999999996 > > ie I expect simple rounding to produce the observed result and indeed > > >>> '%.1f' % -9.85 > '-9.8' > > however, when I use round I get an unexpected result ie > >>> round(-9.85,1) > -9.9000000000000004 > > according to its definition > >> round(x[, n])? >> Return the floating point value x rounded to n digits after the >> decimal point. >> If n is omitted, it defaults to zero. The result is a floating >> point number. >> Values are rounded to the closest multiple of 10 to the power >> minus n; >> if two multiples are equally close, rounding is done away from 0 >> (so. for example, >> round(0.5) is 1.0 and round(-0.5) is -1.0). > > so looking at the absolute differences I see > > >>> abs(-9.9 - -9.85) > 0.050000000000000711 > >>> abs(-9.8 - -9.85) > 0.049999999999998934 Do you *seriously* need to ask a computer if -9.85 is half-way between -9.9 and -9.8. Just look at the numbers man! Of course it's equally close to both, so rounding to -9.9 is correct according to the definition. Do you actually *believe* that -9.9 - -9.85 = 0.050000000000000711. Of course you know it's really 0.05. All you've done here is demonstrate the fallible nature of (the last several digits of) floating point arithmetic on a computer. Don't let that distract you from using your common sense. Gary Herron > ie the -9.8 value appears closer and at least to a primitive test > > >>> abs(-9.9 - -9.85) > abs(-9.8 - -9.85) > True > > the distance from the -9.9 result is larger, however, that may be > because the model numbers for -9.8 & -9.9 differ in distance from the > true 10**-n values eg > > >>> -9.9 > -9.9000000000000004 > >>> -9.8 > -9.8000000000000007 > > What value should round(-9.85,1) return? Is the result explainable in > python (ie without resort to the internal FP representations etc etc)? From thomas at jollans.com Mon Jul 12 13:16:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 12 Jul 2010 19:16:03 +0200 Subject: grailbrowser now running under python 2.5 (probably above too) In-Reply-To: References: Message-ID: <4C3B4DD3.5080304@jollans.com> On 07/12/2010 01:44 AM, rantingrick wrote: > On Jul 11, 11:31 am, Thomas Jollans wrote: >> On 07/11/2010 07:44 AM, rantingrick wrote: > >>> Congratulations on this effort Luke. However you know what project i >>> would really like to see the community get around? ...dramatic pause >>> here... a cross platform Python file browser! >> >> Cross platform file manager. Hmm. Does "cross platform" involve UNIX and >> something that isn't UNIX, say, Windows? >> Erm, no. No, no, no. It won't work....... trying to >> support both UNIX and Windows is NOT a good idea. > > Why is that a bad idea, Python does it all the time? Many software so > it all the time. This sounds like more fear than anything. Python is not a file manager. > > If you attempt to be full-featured, keeping it in one >> code base, let alone in one user interface, is destined to be a >> nightmare and induce suicides. > > Thats False! > >> The above might have been very slightly exaggerated. > > Thats True! > From nagle at animats.com Mon Jul 12 13:16:07 2010 From: nagle at animats.com (John Nagle) Date: Mon, 12 Jul 2010 10:16:07 -0700 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> On 7/12/2010 7:19 AM, Grant Edwards wrote: > On 2010-07-09, Les Schaffer wrote: > >> i have been asked to guarantee that a proposed Python application will >> run continuously under MS Windows for two months time. And i am looking > ^^^^^^^^^^ > > IMO, that's going to be your main problem. If you're doing a real-time job, run a real-time OS. QNX, a real-time variant of Linux, Windows CE, Windows Embedded, LynxOS, etc. There's too much background junk going on in a consumer OS today. Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP. This is a machine that moves around a plasma torch that cuts thick steel plate. A "New Java update is available" window popped up while I was working. Not good. John Nagle From animator333 at gmail.com Mon Jul 12 14:08:50 2010 From: animator333 at gmail.com (King) Date: Mon, 12 Jul 2010 11:08:50 -0700 (PDT) Subject: Node based architecture Message-ID: <5a1a0178-771c-4aa8-9c15-bc1ad2f60fa9@p11g2000prf.googlegroups.com> Hi, I am planning to build a generic node based framework using python. I would start with a simple image editing application. I hope that experienced users understands what am I trying to say here. In simple words: LoaderNode : Load Image from disk OperatorNode : Performs a specific task on data and spit output(data) OutputNode : Get the data from OperatorNode(output) and writes image to disk. Graph : A collection Nodes that are inter connected. The question is how to process graph? Here is a simple representation: class Integer(object): """ A simple integer node. """ def __init__(self, value=0): self.value = value def output(self): return self.value class OperatorAdd(object): """ A simple operator node """ def __init__(self, integerInst1=None, integerInst2=None): self.a = integerInst1.output() self.b = integerInst2.output() def compute(self): return Integer(self.a + self.b) def output(self): return self.compute() "Integer" is data node and "OperatorAdd" is a compute node. Imagine I have created two integer nodes and their output is going to "OperatorNode". One way to solve is to represent every node using a string and then you can write these series of string which actually is a python code that you can execute and get the result. Example: compute = """ i1 = Integer(2) i2 = Integer(3) i3 = OperatorAdd(i1, i2).output() """ Now you can execute "compute" variable using exec(compute) or something like that. This would do the job but I would like to know the opinion of more experienced users. One advantage of above mentioned string method is that it can be saved to disk and later you can load/compute it again. Cheers Prashant From alf.p.steinbach+usenet at gmail.com Mon Jul 12 14:11:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 20:11:36 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <01176cc1-a3e5-41a1-a872-e39f8fa8bb78@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 12.07.2010 16:59: > On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> We're talking about defining a 'swap' routine that works on variables. > > I did not miss the point. One cannot make a swap function that rebinds > its arguments in the calling stack frame. But a swap function can swap > values, given that the type is not immutable: > > def swap(a,b): > a[0],b[0] = b[0],a[0] > >>>> a,b = [1],[2] >>>> swap(a,b) >>>> print a,b > [2] [1] OK, that's missing the point. I thought you were joking. Cheers & hth., - Alf -- blog at From ash.connor at gmail.com Mon Jul 12 14:13:50 2010 From: ash.connor at gmail.com (ashconnor) Date: Mon, 12 Jul 2010 11:13:50 -0700 (PDT) Subject: Problems running VirtualEnv under Windows. References: <7fc04b13-8006-45f6-a099-94bd9353761f@c33g2000yqm.googlegroups.com> Message-ID: I've resolved this issue by deleting the *.py file association in Windows. You can do this either by associating *.py with something like textpad, using a utility such as http://defaultprogramseditor.com/ or doing so in the registry. Note that when using the command like you need to issue commands with a preceding `python` keyword. For example in a normal installation enviroment the following is possible `django-admin.py startproject MyProject`, however in a VirtualEnv with *.py associations removed one must do `python django- admin.py startproject MyProject` otherwise Windows will attempt to open the file in the default application even if there isn't one. Thanks, Ash On Jul 12, 1:55?am, ashconnor wrote: > Hello, > > After reading 'Practical Django Projects' I decided that I want to > implement the VirtualEnv tip suggested in order to properly segregate > code/modules in different projects. I am however having problems with > my django installations not using site-packages within the virtualenv > but rather attempting to use site-packages in the default python > installation directory. > > Recreating the problem: > > 1) Install Python 2.7 via the Windows installer. Add C:/Python27;C:/ > Python27/Scripts to Windows PATH. > 2) Install setuptools-0.6c11-py2.7.egg via the Windows installer. > 3) Install VirtualEnv through `pip install virtualenv` > 4) Create an VirtualEnv via `virtualenv --no-site-packages MyEnvName` > 5) Activate VirtualEnv via `../MyEnvName/Scripts/activate.bat` > 6) Install django via `pip install django` > 7) Run django-admin.py startproject ProjectName > 8) Error results stating django.core module does not exist. > > NB: This error will not occur if django is installed in your root > directory. > NB2: Running the Python interpreter in active VirtualEnv to print the > sys.path shows the correct paths. Which has just futher added to my > confusion. > > I'd appreciate any insight or troubleshooting assistance. > > Thanks > > Ash From emile at fenx.com Mon Jul 12 14:15:28 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 12 Jul 2010 11:15:28 -0700 Subject: round issue In-Reply-To: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: On 7/12/2010 2:52 AM Robin Becker said... > What value should round(-9.85,1) return? Per round's definition, -9.9. String interpolation for %n.mf doesn't appear to define it's rounding behavior, so a peek at the source would answer what's being done. It does look inconsistent however, and it seems to me rounding and interpolation should behave similarly. So I'd call it a bug. Emile >>> def display(val): ... print "%.1f" % val ... print round(val,1) ... >>> display(1.45) 1.5 1.5 >>> display(-1.45) -1.5 -1.5 >>> display(-1.85) -1.9 -1.9 >>> display(1.85) 1.9 1.9 >>> display(-7.85) -7.8 -7.9 >>> display(-9.85) -9.8 -9.9 >>> From john at castleamber.com Mon Jul 12 14:26:29 2010 From: john at castleamber.com (John Bokma) Date: Mon, 12 Jul 2010 13:26:29 -0500 Subject: GUIs (was: grailbrowser now running under python 2.5 (probably above too)) References: <87aapxyc7p.fsf@castleamber.com> Message-ID: <8739voeeui.fsf_-_@castleamber.com> MRAB writes: > John Bokma wrote: [..] >> Can't think of why not. Of course not all operations are shared by each >> OS, but /I/ know that I can't do chmod on Windows. But it doesn't mean >> that on Windows I can't make a file only readable by me. Just give me >> the Windows security options on Windows, and chmod on *nix and I would >> be very happy. >> > On Windows the root folders of the different drives could be treated as > subfolders of a 'root' folder. Yup, instead of a single tree there is a forrest. Wouldn't confuse me, and I doubt anyone else. >> Especially if all can be done via a context menu a la RISC OS. >> > Ah, RISC OS! :-D. > > I'd heard how user-friendly the Mac was, but when I was first introduced > to the Mac (circa MacOS 8) I was very surprised that even it still used > old-fashioned Open and Save dialog boxes with their own little file > browsers like on a Windows PC instead of drag-and-drop like I'd become > used to on RISC OS. And that menu bar not even at the top of the window > but at the top of the _screen_! And the way that bringing one Finder > window to the front brought _all_ the Finder windows in front of the > other windows! I was distinctly underwhelmed... :-( > It's on top of the screen because of Fitts's law: it's easier to move accurately to the top of the screen than to the top of the window (unless it's located in the top or bottom of the screen). However, personally I think that a context menu even scores better: it's easier to click a mouse button than to roll up and then move to the correct menu entry. Yes, RISC OS has some very good ideas: 1) context menus instead of menus at the top of the Windows/screen 2) clearly defined operations of each of the three mouse buttons: left = select, middle = context menu, right = adjust 3) the ability to select items in a menu and keep the menu open 4) drag & drop saving/loading (including between applications) 5) direction of scrollbars depends on mouse button: left = expected direction, right = reverse. Based on this I would say that the designers of RISC OS understood Fitts's Law way better. I am aware of ROX but haven't checked it out yet. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alf.p.steinbach+usenet at gmail.com Mon Jul 12 14:28:49 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 20:28:49 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 12.07.2010 04:39: > On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote: > >> * MRAB, on 12.07.2010 00:37: > [...] >>> In Java a variable is declared and exists even before the first >>> assignment to it. In Python a 'variable' isn't declared and won't exist >>> until the first 'assignment' to it. >> >> That is a misconception. >> >> In Python a variable is declared by having an assignment to it, which >> for a local variable may be anywhere within a routine. > > Oh, I'm going to regret being sucked into this... > > In *CPython*, but not necessarily other implementations, variables which > are local to a function are not kept in a dictionary-based namespace, but > in slots in the code object (not to be confused with __slots__ used for > classes). Python has STORE_FAST and LOAD_FAST byte-codes for accessing > locals. > > This is intended as a speed, and possibly memory, optimization. I don't > believe this is a requirement though, so implementations may not do this. > > It is true that the slot is created at compile time, and in *that sense*, > local variables exist before they are bound. I'm not entirely convinced > that this is the only sense that matters, but never mind. The error > message given exposes this to the user: > >>>> def f(): > ... print x > ... x = 1 > ... >>>> f() > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in f > UnboundLocalError: local variable 'x' referenced before assignment > > > If you try this with a global, you get this: > >>>> def f(): > ... global x > ... print x > ... >>>> f() > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in f > NameError: global name 'x' is not defined > > In this case, there's no doubt that global variable "x" doesn't exist at > all -- there is no key "x" in the global namespace. Yes. What I disproved was the statement that every Python variable is created by the execution of an assignment. Some (the global ones) are. :-) > It seems to me that "a slot to hold the variable is created for local > variables" is an implementation detail, not a language feature. Yes. However, any Python implementation has to implement the same user level semantics in some way (note: use level semantics do not include "space reserved" for an unassigned variable, or even for all assigned variables since with single assignment a sufficiently smart compiler can optimize away the space, but user level semantics do include existence and resultant effect). As I see it it doesn't matter whether the implementation is CPython call frame slots or that mechanism called something else or a different mechanism called the same or a different mechanism called something different; what IMO matters is same semantics, that any assignment to a variable within a routine serves as a compile time declaration, creating that local variable in advance, unless, with Python 3.x., that name has been declared as a 'global' or 'nonlocal'. So, this is a possible point of disagreement. I say the semantics of local variable creation are part of the language definition, but I get the /impression/ that maybe you think it's CPython-specific, that e.g. def foo(): x x = 0 might not raise an unassigned variable exception with some conforming Python implementation, i.e. different effect for same code with different implementations, that this is at least /unspecified behavior/ in Python? > CPython > could easily hide the difference by changing the exception from > UnboundLocalError to: > > NameError: local name 'x' does not exist > > and nobody would be any wiser. (Well, perhaps people who catch > UnboundLocalError, but why would you do that?) > > I also note that UnboundLocalError is a subclass of NameError, so > "variable exists but is not bound" is considered to be a special case of > "variable doesn't exist" rather than a completely independent case. In > that sense, I think I'm on solid ground to say that in Python variables > don't exist until they are bound to a value, and leave it to pedants like > you and I to mention that for CPython local variables have space reserved > for them by the compiler before they are bound. He he. I wouldn't say "space reserved". That is an implementation detail. Cheers, - Alf -- blog at From cmpython at gmail.com Mon Jul 12 14:54:15 2010 From: cmpython at gmail.com (CM) Date: Mon, 12 Jul 2010 11:54:15 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: On Jul 12, 1:16?pm, John Nagle wrote: > On 7/12/2010 7:19 AM, Grant Edwards wrote: > > > On 2010-07-09, Les Schaffer ?wrote: > > >> i have been asked to guarantee that a proposed Python application will > >> run continuously under MS Windows for two months time. And i am looking > > ? ? ? ? ? ? ? ? ? ? ? ? ? ^^^^^^^^^^ > > > IMO, that's going to be your main problem. > > ? ? If you're doing a real-time job, run a real-time OS. ?QNX, > a real-time variant of Linux, Windows CE, Windows Embedded, LynxOS, > etc. ?There's too much background junk going on in a consumer OS > today. > > ? ? Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. ?This is a machine that moves around a plasma torch that > cuts thick steel plate. ?A "New Java update is available" window > popped up while I was working. ?Not good. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle I'm not sure I can like that example any better. From dickinsm at gmail.com Mon Jul 12 14:59:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 12 Jul 2010 18:59:35 +0000 (UTC) Subject: round issue References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: Emile van Sebille fenx.com> writes: > > On 7/12/2010 2:52 AM Robin Becker said... > > > What value should round(-9.85,1) return? > > Per round's definition, -9.9. No. The float that's represented by the literal '-9.85' *isn't* exactly -9.85, for all the usual binary floating-point reasons. The value that gets stored is a tiny amount smaller (i.e., closer to zero) than -9.85, so according to the definition it should round *down*, to -9.8. (Or rather, to a float that's very close to, but not exactly equal to, -9.8.) > String interpolation for %n.mf doesn't > appear to define it's rounding behavior, so a peek at the source would > answer what's being done. In Python 2.6, the string interpolation delegates to the system, so it does whatever C string formatting does. Usually that's rounding to nearest, with exact halfway cases rounded to even. In Python 2.7 and 3.x, Python has its own code for string formatting, and again it rounds to nearest, rounding ties to even. > It does look inconsistent however, and it seems to me rounding and > interpolation should behave similarly. Agreed. In this case it's a minor bug that round(-9.85, 1) produces -9.9 instead of -9.8; both string formatting and round should give -9.8. This bug is fixed in Python 2.7 and in Python 3.x. Note that in 2.7 there's still a legitimate difference: round rounds halfway cases away from 0, while string formatting rounds them to even. So the following results are correct: Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> round(1.25, 1) 1.3 >>> '%.1f' % 1.25 '1.2' (1.25 *is* an exact halfway case, since it's exactly representable as a binary float.) In Python 3.x, round always does round-half-to-even, so string formatting and round should agree (and if they don't, it's definitely a bug: please report it!) With all this said, asking for *decimal* rounding of *binary* approximations to *decimal* halfway cases to give the results you expect is ... optimistic, to say the least. Use the decimal module if you care about which way your (almost) halfway cases get rounded. [I already replied to this earlier through Google groups, but I'm not sure whether it went through properly. Apologies for the duplication, if so.] -- Mark From dhruvbird at gmail.com Mon Jul 12 15:24:29 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 12 Jul 2010 12:24:29 -0700 (PDT) Subject: Why doesn't python's list append() method return the list itself? References: <838143ba-edae-47b8-b101-3473a573c7db@q21g2000prm.googlegroups.com> <4c3a622f$0$700$426a74cc@news.free.fr> <87630lrlo2.fsf@busola.homelinux.net> Message-ID: <906a8735-4f2b-45b5-bc14-5ac570098819@z30g2000prg.googlegroups.com> On Jul 12, 4:20?pm, Hrvoje Niksic wrote: > dhruvbird writes: > > No, I meant x.append(4) > > Except that I want to accomplish it using slices. > > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > > way?) > > It seems that you've found a way to do so, so why do you need another > way? ?Are you after elegance? ?Efficiency? ?Brevity? Actually, the reason I ask is because I think a lot of things can be done using slices and its support for negative indexes. Basically putting constants in the slices (as opposed to variables like len(x), etc... which depend upon the variable name). So, was just trying to cogitate on whether append can be implemented that way or not. Regards, -Dhruv. From nagle at animats.com Mon Jul 12 15:46:08 2010 From: nagle at animats.com (John Nagle) Date: Mon, 12 Jul 2010 12:46:08 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3b7102$0$1587$742ec2ed@news.sonic.net> On 7/11/2010 5:24 PM, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > >> Why doesn't python's list append() method return the list itself? For >> that matter, even the reverse() and sort() methods? I found this link >> (http://code.google.com/edu/languages/google-python- class/lists.html) >> which suggests that this is done to make sure that the programmer >> understands that the list is being modified in place, but that rules out >> constructs like: >> ([1,2,3,4].reverse()+[[]]).reverse() > > Yes. So what? Where's the problem? > > List methods work in place. ... > Not everything needs to be a one-liner. It's interesting that all Python functions are considered to return a value. Arguably, if a function just does a "return", it should be an error to try to use its return value. Some languages have a very functional orientation, and everything is considered to return some value, even control structures. LISP is like that. But Python isn't one of those languages. John Nagle From mcl.office at googlemail.com Mon Jul 12 15:56:50 2010 From: mcl.office at googlemail.com (mcl) Date: Mon, 12 Jul 2010 12:56:50 -0700 (PDT) Subject: iptcinfo: Can not import: Newbie not really knowing what he is doing References: Message-ID: <008715c6-4bb3-4d55-a82f-bbecbdfda069@k39g2000yqd.googlegroups.com> On Jul 12, 4:11?pm, Nick Raptis wrote: > Hi Richard!> I have downloaded iptcinfo and placed it in python27\Lib\site-packages > > \iptcinfo > > > I guessed that was the right place, because that is where PIL ended > > up, but that had a fancy installer with it. > > You did place it in the right path, but the "fancy installer" does one > more thing, it registers the package into the python-path, so python can > get to it. > I've long switched from windows unfortunately and can't remember the way > it does this though, so you can do it manually. > > Have some good news though: I looked in the IPTCinfo package and it does > indeed include a setup.py, which is a standard way of installing python > packages. > All you need to do is unpack the package to any folder and run > setup.py install > from that folder, which should take care of everything for you. > > Some documentation on installing packages for you to read:http://docs.python.org/install/ > > Nick What a star. It is all now working. I will try to look at the reference you mentioned, but at the moment I can not even figure out why 'python' on its own does not work. I would have thought the installation would have set the appropriate environment variables, but it does not seem to have. I have to give the full path name to python.exe. Just remembered SET at DOS prompt, but no mention of PYTHON anywhere. Thank you very much again - I now have a list of all my JPEGS and their CAPTIONS. Richard From rhodri at wildebst.demon.co.uk Mon Jul 12 16:19:56 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 12 Jul 2010 21:19:56 +0100 Subject: Easy questions from a python beginner References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote: > "Steven D'Aprano" wrote in > message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... >> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: >> >>> That's interesting. So in Python, you can't tell what local variables a >>> function has just by looking at it's code: > >>> def foo(day): >>> if day=="Tuesday": >>> x=0 >>> print ("Locals:",locals()) >>> >>> #foo("Monday") >>> >>> Does foo() have 1 or 2 locals? >> >> That's easy for CPython: it prepares two slots for variables, but only >> creates one: >> >>>>> foo("Monday") >> ('Locals:', {'day': 'Monday'}) >>>>> foo.func_code.co_varnames >> ('day', 'x') >>>>> foo.func_code.co_nlocals >> 2 >> >> So, the question is, is x a local variable or not? It's not in locals, >> but the function clearly knows that it could be. > > So Alf P.S. could be right; x exists, but Python pretends it doesn't > until it's assigned to. CPython, not Python. And as Steven said, x *doesn't* exist. Allowance is made by that specific implementation of the interpreter because x *might* exist, but in this particular case it doesn't and a more dynamic implementation might choose not to reserve a slot just in case. x is created until it's actually used. -- Rhodri James *-* Wildebeeste Herder to the Masses From john at castleamber.com Mon Jul 12 16:27:07 2010 From: john at castleamber.com (John Bokma) Date: Mon, 12 Jul 2010 15:27:07 -0500 Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <87sk3ofntw.fsf@castleamber.com> John Nagle writes: > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. You can blame that one on Sun (or Oracle nowadays). Good example though. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From hujia06 at gmail.com Mon Jul 12 16:27:19 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 16:27:19 -0400 Subject: how to delete "\n" Message-ID: Hi, I just want to delete "\n" at each line. My operating system is ubuntu 9.1. The code is as follows #!/usr/bin/python import string fileName=open('Direct_Irr.txt', 'r') # read file directIrr = fileName.readlines() fileName.close() for line in directIrr: line.rstrip('\n') print directIrr But I found there is still "\n" . Could someone help me why it is not correct? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Mon Jul 12 16:34:23 2010 From: landimatte at gmail.com (Matteo Landi) Date: Mon, 12 Jul 2010 22:34:23 +0200 Subject: how to delete "\n" In-Reply-To: References: Message-ID: I hope this could help: >>> f = open('powersave.sh') >>> map(lambda s: s.strip(), f.readlines()) ['echo 1 > /sys/module/snd_hda_intel/parameters/power_save', 'echo min_power > /sys/class/scsi_host/host0/link_power_management_policy', 'echo 1 > /sys/module/snd_hda_intel/parameters/power_save'] I know for sure someone else will address you to other better solutions :) On Mon, Jul 12, 2010 at 10:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? > > Thank you > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From alister.ware at ntlworld.com Mon Jul 12 16:36:36 2010 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 12 Jul 2010 20:36:36 GMT Subject: Easy questions from a python beginner References: Message-ID: On Sun, 11 Jul 2010 18:17:49 +0000, Duncan Booth wrote: > wheres pythonmonks wrote: > >> I'm an old Perl-hacker, and am trying to Dive in Python. I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: without going into details on how to do these things in python(many suggestions have already been made) i think you need to take a step back Why do you want to do these particular things in this way? is it because this is what is needed to get the job done or is it because this is what's needed to get the job done in perl? if the later then step back and think what is the real goal & program accordingly. Each language does things differently ( if they didn't we wouldn't have different languages!) what is Best for perl (or c , java, pascal or malbolge) may not necessarily be the best for Python & vice Versa. -- backups: always in season, never out of style. From ian.g.kelly at gmail.com Mon Jul 12 16:38:49 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 14:38:49 -0600 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 2:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? The print statement automatically adds a newline to each line. If you want the lines written verbatim, use sys.stdout.write(line) From tjreedy at udel.edu Mon Jul 12 16:44:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 16:44:40 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: On 7/12/2010 4:48 AM, bart.c wrote: >> >>> def foo(): >> print("Before:", locals()) >> x = 0 >> print("After:", locals()) >> >> >> >>> foo() >> Before: {} >> After: {'x': 0} > > That's interesting. So in Python, you can't tell what local variables a > function has just by looking at it's code: You are being fooled by the multiple meanings of the overloaded term 'variable'. Thing are clearer with the two terms 'name' and 'namespace' (a set of name-object bindings). Before compiling function code, an interpreter must read it and make a classified list of *names*. The interpreter has to know the fixed set of local names in order to know what to do with assignment statements. If the interpreter can tell how many local names there are, so can you. Before a function begins execution, all parameter names must be bound, with no arguments left over. At that point, the local namespace consists of those parameter-object bindings. During the execution of the function, bindings may be added and deleted. The size of the local namespace varies. > def foo(day): > if day=="Tuesday": > x=0 > print ("Locals:",locals()) > > #foo("Monday") > > Does foo() have 1 or 2 locals? foo has 2 local names. Its local namespace starts with 1 binding and may get another, depending of the value of the first. If the size of the local namespace at some point of execution depends on unknown information, then of course the size at that point is also unknown. Here is another example: >>> def f(a): print(locals()) del a print(locals()) a = None print(locals()) >>> f(2) {'a': 2} {} {'a': None} -- Terry Jan Reedy From clp2 at rebertia.com Mon Jul 12 16:45:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 13:45:27 -0700 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: > Hi, I just want to delete "\n" at each line. My?operating system?is ubuntu > 9.1. The code is as follows > > #!/usr/bin/python > import string > fileName=open('Direct_Irr.txt', 'r') # read file > directIrr = fileName.readlines() > fileName.close() > for line in directIrr: > ?????? line.rstrip('\n') > print directIrr > > But I found there is still "\n" . Could someone help me why it is not > correct? .rstrip() returns a *new* string without trailing whitespace (which you are currently then throwing away); it does *not* modify string objects in-place. Python strings objects are entirely immutable and unmodifiable; all operations on them merely produce /new/ strings. Assuming you still want to use .readlines(), you'd do: directIrr = fileName.readlines() fileName.close() directIrr = [line.rstrip('\n') for line in directIrr] print directIrr For how third line works, google "python list comprehensions". Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Mon Jul 12 16:51:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Jul 2010 16:51:48 -0400 Subject: Numpy now supports Python3, Scipy to follow soon In-Reply-To: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> References: <4c3accbc$0$28664$c3e8da3@news.astraweb.com> Message-ID: On 7/12/2010 4:05 AM, Steven D'Aprano wrote: > Pardon me if this has already been mentioned, but I didn't see it, and > this is big big news. > > The latest release of numpy now supports Python 2.x and 3.x out of a > single code base, and Scipy is predicted to follow soon. > > http://www.mail-archive.com/numpy-discussion at scipy.org/msg26524.html > > If I can take the liberty of quoting Pauli Virtanen: > > An important point is that supporting Python 3 and Python 2 > in the same code base can be done, and it is not very difficult > either. It is also much preferable from the maintenance POV to > creating separate branches for Python 2 and 3. > > > Well done to all those who contributed to the effort! There are extensive notes on the transition at http://projects.scipy.org/numpy/browser/trunk/doc/Py3K.txt I am sure that some of this should be added to the current HowTo on porting CAPI to Py3. -- Terry Jan Reedy From alf.p.steinbach+usenet at gmail.com Mon Jul 12 16:57:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 22:57:10 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Rhodri James, on 12.07.2010 22:19: > On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote: > >> "Steven D'Aprano" wrote in >> message news:4c3aedd5$0$28647$c3e8da3 at news.astraweb.com... >>> On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote: >>> >>>> That's interesting. So in Python, you can't tell what local variables a >>>> function has just by looking at it's code: >> >>>> def foo(day): >>>> if day=="Tuesday": >>>> x=0 >>>> print ("Locals:",locals()) >>>> >>>> #foo("Monday") >>>> >>>> Does foo() have 1 or 2 locals? >>> >>> That's easy for CPython: it prepares two slots for variables, but only >>> creates one: >>> >>>>>> foo("Monday") >>> ('Locals:', {'day': 'Monday'}) >>>>>> foo.func_code.co_varnames >>> ('day', 'x') >>>>>> foo.func_code.co_nlocals >>> 2 >>> >>> So, the question is, is x a local variable or not? It's not in locals, >>> but the function clearly knows that it could be. >> >> So Alf P.S. could be right; x exists, but Python pretends it doesn't >> until it's assigned to. > > CPython, not Python. And as Steven said, x *doesn't* exist. Allowance is > made by that specific implementation of the interpreter because x > *might* exist, but in this particular case it doesn't and a more dynamic > implementation might choose not to reserve a slot just in case. x is > created until it's actually used. You are conflating existence with space allocation. It's up to the implementation whether to allocate memory for the variable's reference in any particular case where that memory isn't strictly required. This is known as "optimization". Optimization depends on the implementation. Existence of a variable means, among other things, that * You can use the value, with guaranteed effect (either unassigned exception or you get a proper value): in particular, you won't be accessing a global if you're using the name of a local declared by a later assignment. * You can assign to it. How the Python implementation implements that is an implementation detail. In short, how CPython does things is completely irrelevant to the language's semantics, so you're conflating things here. Cheers & hth., - Alf -- blog at From luke.leighton at gmail.com Mon Jul 12 16:59:09 2010 From: luke.leighton at gmail.com (lkcl) Date: Mon, 12 Jul 2010 13:59:09 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) Message-ID: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> for several reasons, i'm doing a cooperative multi-tasking HTTP server: git clone git://pyjs.org/git/multitaskhttpd.git there probably exist perfectly good web frameworks that are capable of doing this sort of thing: i feel certain that twisted is one of them. however, the original author of rtmplite decided to rip twisted out and to use multitask.py and i'm one of those strange people that also likes the idea of using 900 lines of awesome elegant code rather than tens of thousands of constantly-moving-target. one of the things that's slightly unfortunate is that i'm going to have to copy SimpleHTTPServer.py and slightly modify it; CGIHTTPServer.py as well. this is Generally Bad Practice. can anyone think of a way of monkey-patching or otherwise using SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the base class from which those two are derived? i have had to pull bits out of BaseHTTPRequestHandler to make them use the "yield" logic of multitask.py already, which was painful enough. ideas, anyone? l. From alf.p.steinbach+usenet at gmail.com Mon Jul 12 16:59:44 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 12 Jul 2010 22:59:44 +0200 Subject: Standard distutils package problems with MSVC / lacking functionality? Message-ID: I let the setup.py script talk: # 03_1__noddy from distutils.core import setup, Extension import distutils.ccompiler compilerName = distutils.ccompiler.get_default_compiler() options = [] if compilerName == "msvc": # * distutils sets warning level 3: # Overriding with warning level 4 generates command line warning D9025... # There's no good away around that, it needs fix/extension of distutils # or the config file(s) that distutil uses (perhaps that's a makefile?). options.append( "/W4" ) # Must be done in this script. # * distutils forgets to enable exception handling: options.append( "/EHsc" ) # Could be done via CL env. var. # * distutils forgets to enable RTTI: options.append( "/GR" ) # Could be done via CL env. var. # * distutils forgets to enable standard 'for' loop and 'wchar_t' type: options.append( "/Zc:forScope,wchar_t" ) # Could be done via CL env. var. module1 = Extension( name = "noddy", sources = [ "noddy.cpp" ], extra_compile_args = options ) setup( name = "noddy", version = '1.0', description = 'This is a demo package', ext_modules = [module1] ) Cheers, - Alf -- blog at From gdamjan at gmail.com Mon Jul 12 17:15:59 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 12 Jul 2010 23:15:59 +0200 Subject: Lua is faster than Fortran??? References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: On the positive side, Lua supports tail call optimization and coroutines are built in by default. -- ?????? ((( http://damjan.softver.org.mk/ ))) Education is one of the "prices" of freedom that some are unwilling to pay. From python at bdurham.com Mon Jul 12 17:29:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 12 Jul 2010 17:29:11 -0400 Subject: how to delete "\n" In-Reply-To: References: Message-ID: <1278970151.7048.1384527261@webmail.messagingengine.com> Jia, print ''.join( open( 'Direct_Irr.txt' ).read().split() ) Broken out: - open(): open file - read(): read its entire contents as one string - split(): split the contents into a list of lines (splits lines at \n; does not include \n in split values) - ''.join(): join list of lines with an empty char Malcolm From hujia06 at gmail.com Mon Jul 12 17:33:02 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 17:33:02 -0400 Subject: how to delete "\n" In-Reply-To: References: Message-ID: Thank you. It works now. if I use 'print' to print the whole list, 'print' will add newline at the end of the list but not each item in the list. right? For the code: for line in fileName: line = line.rstrip('\n') I think this will affect 'fileName' because it assign the value to 'line' ? But when I print fileName, "\n" still exists at each item in the list. Because each line in my txt file are numeric values. is there any other better way to get each numerical value at each line? for example using numpy or changing string list to numerical list? Thank you for help. On Mon, Jul 12, 2010 at 4:45 PM, Chris Rebert wrote: > On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: > > Hi, I just want to delete "\n" at each line. My operating system is > ubuntu > > 9.1. The code is as follows > > > > #!/usr/bin/python > > import string > > fileName=open('Direct_Irr.txt', 'r') # read file > > directIrr = fileName.readlines() > > fileName.close() > > for line in directIrr: > > line.rstrip('\n') > > print directIrr > > > > But I found there is still "\n" . Could someone help me why it is not > > correct? > > .rstrip() returns a *new* string without trailing whitespace (which > you are currently then throwing away); it does *not* modify string > objects in-place. Python strings objects are entirely immutable and > unmodifiable; all operations on them merely produce /new/ strings. > > Assuming you still want to use .readlines(), you'd do: > directIrr = fileName.readlines() > fileName.close() > directIrr = [line.rstrip('\n') for line in directIrr] > print directIrr > > For how third line works, google "python list comprehensions". > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 12 17:36:11 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 12 Jul 2010 23:36:11 +0200 Subject: how to delete "\n" In-Reply-To: <1278970151.7048.1384527261@webmail.messagingengine.com> References: <1278970151.7048.1384527261@webmail.messagingengine.com> Message-ID: <4C3B8ACB.8030907@jollans.com> On 07/12/2010 11:29 PM, python at bdurham.com wrote: > Jia, > > print ''.join( open( 'Direct_Irr.txt' ).read().split() ) > > Broken out: > > - open(): open file > - read(): read its entire contents as one string > - split(): split the contents into a list of lines > (splits lines at \n; does not include \n in split values) also splits at other whitespace. > - ''.join(): join list of lines with an empty char > > Malcolm From gelonida at gmail.com Mon Jul 12 17:52:15 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 12 Jul 2010 23:52:15 +0200 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: Hi lkcl, Do you have any documentation or overview for your project? Questions I would be interested in: - List of features already working - list of features under development - list of features being in in the near future lkcl wrote: > for several reasons, i'm doing a cooperative multi-tasking HTTP > server: > git clone git://pyjs.org/git/multitaskhttpd.git > > there probably exist perfectly good web frameworks that are capable of > doing this sort of thing: i feel certain that twisted is one of them. > however, the original author of rtmplite decided to rip twisted out > and to use multitask.py and i'm one of those strange people that also > likes the idea of using 900 lines of awesome elegant code rather than > tens of thousands of constantly-moving-target. > > one of the things that's slightly unfortunate is that i'm going to > have to copy SimpleHTTPServer.py and slightly modify it; > CGIHTTPServer.py as well. this is Generally Bad Practice. > > can anyone think of a way of monkey-patching or otherwise using > SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the > base class from which those two are derived? > > i have had to pull bits out of BaseHTTPRequestHandler to make them use > the "yield" logic of multitask.py already, which was painful enough. > > ideas, anyone? > > l. From python at bdurham.com Mon Jul 12 17:53:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 12 Jul 2010 17:53:01 -0400 Subject: how to delete "\n" In-Reply-To: <4C3B8ACB.8030907@jollans.com> References: <1278970151.7048.1384527261@webmail.messagingengine.com> <4C3B8ACB.8030907@jollans.com> Message-ID: <1278971581.13157.1384530935@webmail.messagingengine.com> Thomas, > split() also splits at other whitespace. Doh! Corrected version follows: print ''.join( open( 'Direct_Irr.txt' ).read().splitlines() ) Broken out: - open(): open file - read(): read its entire contents as one string - splitlines(): split the contents into a list of lines (splits lines at \n; does not include \n in split values) - ''.join(): join list of lines with an empty char Malcolm From f2h2d2 at gmail.com Mon Jul 12 17:54:00 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Mon, 12 Jul 2010 14:54:00 -0700 (PDT) Subject: Why did I Embrace Islam? Message-ID: <03506da7-7ea6-46af-b02d-fa4dec101f59@j13g2000yqj.googlegroups.com> Why did I Embrace Islam? This is an extract from Dr. Gronier, a French MP, who embraced Islam. Revealing the reason of embracing Islam he said, I read all of the Ayat (Quranic verses), which have a relation to medical, health, and natural sciences that I studied before and have a wide knowledge of. I found that these verses are totally compatible with and give a picture of our modern sciences. Thus, I embraced Islam as it was obvious that Muhammad revealed the Absolute Truth more than a thousand years ago. Had every specialist, artist or scientist compared those Quranic verses to his own specialization, beyond the shadow of doubt he would embrace Islam, especially if he has a sound mentality and goodwill to search for the truth and not a mentally defective person with the intentions of malevolent aims>> Islam is the last religion to be sent to the world , every religion had proofs that authenticated its Divine source . God foreordained that Islam would be the last message to the world , so it must comprise many miracles that could be categorized under six categories , among them in this age , being the age of science , what is termed as the scientific miracles which science has recently proved them amazingly . let alone the scientific miracle , as we are going to talk about the unseen matters news . Prophet Mohummed had depicted and given prophecies concerning our generation and the many generation to come . In fact , these prophecies which can't be easily enumerated , have come true . As to the miracle of the unseen news , prophet Mohummed gave a large number of them ; some of them happened during his life , others directly after his death . Every age witnessed the fulfilment some of these . The large portion of these prophecies go to our age . Insha Allah , we will tackle these in the coming studies. Some of these prophecies , as prophet Mohummed determined , are portents of the of the doomsday . we ,now , are approaching that day according to the Devine calculation . The miracle of the unseen tackled that the different phases of life , these tackled the social life , economic life , techmological life , political strifes and wars . Though ther are fearful , they prove the true phrophethood of prophet Mohummed . What we are giving here are just two portents that reflect the social and economic life .The Bedouins , in the life of prophet Mohummed , used to lead a very simple life . They used to live in very simple houses out of mud and palm leaves . The discovery of oil made a revolution in every thing in the life of the bedouin . Contraray to the life they used to lead , they ,now , live in very tall structures but even they compete in building very high structures a picture of a tall building in the arabia Here are two Hadith ( traditional sayings of prophet mohummed ) that talk about two prophecies that have come true . It is narrated in Sahih Muslim that Allah's Apostle (peace be upon him) said to his companions ( through a long conversation about the signs of the last hour) ask me but the companions of the prophet embarrassed to ask him. Then there appeared before us a man and sat with the Apostle (peace be upon him) He knelt before him placed his palms on his thighs and said: Muhammad, inform me about al-Islam. The Messenger of Allah (peace be upon him) said: Al-Islam implies that you testify that there is no god but Allah and that Muhammad is the messenger of Allah, and you establish prayer, pay Zakat, observe the fast of Ramadan. He (the inquirer) said: You have told the truth. He (the inquirer) said: Inform me about Iman (faith). He (the Holy Prophet) replied: That you affirm your faith in Allah, in His angels, in His Books, in His Apostles, in the Day of Judgment, and you affirm your faith in the Divine Decree about good and evil. He (the inquirer) said: You have told the truth. He (the inquirer) again said: Inform me about al-Ihsan (performance of good deeds). He (the Holy Prophet) said: That you worship Allah as if you are seeing Him, for though you don't see Him, He, verily, sees you. He (the enquirer) again said: Inform me about the hour (of the Doom). He (the Holy Prophet) remarked: One who is asked knows no more than the one who is inquiring (about it). He (the inquirer) said: Tell me some of its indications. He (the Holy Prophet) said: That the slave-girl will give birth to her mistress and master, that you will find barefooted, destitute goat- herds vying with one another in the construction of magnificent buildings . Man installed hundreds of marine stations to study the characteristics of various seas. Scientists have found out that the differences in these characteristics distinguished one sea from another. But why do these seas not mix and become homogeneous in spite of the effect of tide and ebb that moves sea water twice a day, and causes seas to move forward and backward turbulently, besides other factors that cause sea water to be in continuous movement and turbulence, such as surface and internal waves and sea currents? The answer appeared for the first time in scientific books in 1361 AH/ 1942 AD. Extensive studies of marine characteristics revealed that there are water barriers separating neighboring seas and maintaining the distinctive properties of each sea with respect to density, salinity, marine life, temperature and solubility of oxygen in water. There are large waves, strong currents, and tides in the Mediterranean Sea and the Atlantic Ocean. Mediterranean Sea water enters the Atlantic by Gibraltar. But their temperature, salinity, and densities do not change, because of the barrier that separates them. After 1962 AD there was known the role of sea barriers in modifying the properties of the water masses that pass from one sea to another, to prevent one sea from overwhelming the other. So salty seas retain their own properties and boundaries by virtue of these barriers. A field study comparing the waters of Oman Gulf and those of the Arabian Gulf has shown the difference between them regarding their chemical properties, the prevalent vegetation and the barrier separating them. About a hundred years of research and study has been required to discover the fact of the existence of barriers between sea water masses and their role in making each sea retain its own properties. Hundred of researchers took part and numerous precise scientific instruments and equipment were used to achieve that. Fourteen centuries ago the Holy Qur?an revealed this fact. We can conclude the following from the discussion above: The Holy Qur?an, which was revealed more than 14 centuries ago, includes very precise pieces of information and knowledge about marine phenomena that have been discovered only recently by means of very sophisticated equipment. An instance in this respect is the existence of water barriers between seas. The historical development of Oceanography shows that no precise information had been available on seas before Challenger Expedition (in 1873 AD), let alone at the time when the Holy Qur?an was being revealed 14 centuries ago to an illiterate Prophet that lived in a desert environment and never traveled by sea. Oceanography has witnessed no advances except in the last two centuries, particularly in the latter half of the twentieth century. Prior to that a sea was considered as something fearful and mysterious. Myths and superstitions were fabricated about it. Sea voyagers were only interested in their own safety and how to find the correct routes during their long journeys. Man discovered that salt seas are different only in the thirties of the twentieth century, after thousands of marine stations had been established by researchers to analyze samples of sea water to measure the differences between the degrees of temperature, salinity, density and oxygen dissolubility in the sea water recorded at all those stations, and then realize that salt seas are different. Man did not know anything about the barrier that separates between salt seas till the establishment of the aforesaid stations, and after spending a long time tracing these wavy moving barriers that change their geographical locations with the change of seasons. Man did not know that the water masses of the two seas are separated by a water barrier and are mixed at the same time till he started studying with his ships and equipment the water movement in the meeting region of the seas and analyzing the water masses in those regions. Man did not apply this rule to all seas that meet together except after vast scientific surveying, investigation and verification of this phenomenon, which occurs between each pair of adjacent seas in the world. Now then, did Allah?s Messenger (Peace be upon him) own stations and equipment for analyzing water and the ability to trace the movement of various water masses? Did he carry out a comprehensive surveying process, although he never sailed the sea and lived at a time when superstitions were prevalent, particularly in the field of seas? Were, at the time of Allah?s Messenger (Peace be upon him) such researches, instruments and studies as are available for the oceanographers of today who have discovered all these secrets by means of research and study? This knowledge, which the Qur?an came with, included a precise de******ion of the subtlest secrets at a time when humanity could never have known them, which indicates that its source is Divine **Regarding praying to Makkah at whose middle the Kaaba and the Inviolable Mosque lie, Allah orders us in the Qur?an to do so: ?So turn your face towards the Inviolable Mosque; and wherever you are, then turn your faces towards it.? (The Cow 144[a5]) Various studies, among which one was done by Dr. Hussein Kamal Ad Din, Head of the Department of Survey Engineering at RiyadhUniversity, proved that Makkah is the center of earth. Dr. Robert G. Coleman (3[a6]), StanfordUniversity in USA, did a study on the center of earth gravity and the point in which gravity cosmological radiations meet (the meeting point magnetic gravitational radiations) on earth; he found that this center is Makkah. Makkah, then, is the center of the seven continents as well as the meeting point of magnetic gravitational radiations.. As for going around the Kaaba anticlockwise, it is consistent with the movement of the whole universe: from the atom to the galaxy. Going around is a cosmological phenomenon that includes everything. The electron goes around the nucleus, the moons go around their planets, the planets go around their suns, the suns and the stars go around the centers of their galaxies, and even energy goes around in its paths; all these movements are anticlockwise. It is the same direction of the Hajji going around the Kaaba. salma Bouafair ( Soufi Bouafair )- M.D in teaching French and mathematics The story of this woman is an extraordinary example of the long tiring intellectual journey through which those who converted to Islam always undergo . She embodies the real challenging will and introduces a good courageous intellectual mind which is to be considered the finest kind of courage at all. She proudly narrated her story as follows: ? I was born in 1971 in Montreal, Canada. I was grown up within a religious Catholic family , so I used to go to church until I was 14 years old when I started to have my personal questions about our Creator and the different religions...I have always believed in God and in His power and in His greatness, so I have studied different religions seeking for any convincing answers for my endless questions but again I could not find what I was looking for? I was so confused and distracted until I started my university. There I came to know a Muslim young man , who introduced Islam to me. I was so overwhelmed as it was an easy way to track the answers for my doubts and questions. It took me a whole year just to study such a religion, and the result was that I was obsessed by Islam to the bones. I was further overwhelmed when I saw how the Moslems -in their prayers- adoringly prostrate themselves to God, it is some thing I could not find in any other religion. I was obsessed by such touching movements which the worshipper performs... they convey nothing but peace of mind , politeness and a perfect act of worship, it seems as if he really feels that he is at the hands of God. I started attending the mosque where I could find many other Canadian Muslim sisters, who encouraged me to follow my track to Islam. I wore the veil in an attempt to test my will, and two weeks later came the true moment when I testified that there are no other gods but Allah, the One, and that Muhammad (PBUH) is His prophet and messenger. [Watch videos of world's top scientists commenting on the "Miracle of Science in Quran"] http://islamyesterday.com/videos/science/ Discover the fastest growing religionin the world; http;//www.sultan.org www.55a.net From ninmonkeys at gmail.com Mon Jul 12 18:00:22 2010 From: ninmonkeys at gmail.com (Jake b) Date: Mon, 12 Jul 2010 17:00:22 -0500 Subject: Help choosing license for new projects Message-ID: I'm starting a new python code project. What license do you suggest? I am searching, but I'm not finding a simple comparison of licenses. So I don't know which to use. Maybe MIT or Apache or LGPL or BSD? Are there certain licenses to avoid using because of interaction problems between libraries using GPL2 / GPL3 / MIT / LGPL. / BSD with my own? I want: 1] Pretty much let anyone use it. Users do not have to include source code, as long as I get credit. (which I think normallly is a textfile with project url + name?) 2] (if it matters) I will be using different combinations of pyglet, pygame, wxPython, etc. 3] I want the option to use my own code in something commercial at a later date. Does #3 complicate things, or is fine when including author info? The choices for google code projects are: Apache License 2.0 Eclipse license 1.0 GPLv2 GPLv3 GNU lesser GPL MIT license Mozilla Public license 1.1 New BSD License thanks for advice, -- ninmonkey From python.list at tim.thechases.com Mon Jul 12 18:01:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 12 Jul 2010 17:01:33 -0500 Subject: any issues with long running python apps? In-Reply-To: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <4C3B90BD.6000508@tim.thechases.com> On 07/12/2010 12:16 PM, John Nagle wrote: > On 7/12/2010 7:19 AM, Grant Edwards wrote: >> On 2010-07-09, Les Schaffer wrote: >> >>> i have been asked to guarantee that a proposed Python application will >>> run continuously under MS Windows for two months time. And i am looking >> ^^^^^^^^^^ >> >> IMO, that's going to be your main problem. > > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. Hi, it looks like you're attempting to cut something with a plasma torch. Would you like help? (_) inserting a steel plate to cut (_) severing the tip of your finger [ ] Don't show me this tip again. -tkc From alister.ware at ntlworld.com Mon Jul 12 18:05:35 2010 From: alister.ware at ntlworld.com (Alister Ware) Date: Mon, 12 Jul 2010 22:05:35 GMT Subject: Why did I Embrace Islam? References: <03506da7-7ea6-46af-b02d-fa4dec101f59@j13g2000yqj.googlegroups.com> Message-ID: On Mon, 12 Jul 2010 14:54:00 -0700, nais-saudi wrote: > Why did I Embrace Islam? Very interesting & good fro you but I cannot find any thing related to python here. -- This place just isn't big enough for all of us. We've got to find a way off this planet. From debatem1 at gmail.com Mon Jul 12 18:13:08 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 18:13:08 -0400 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: > for several reasons, i'm doing a cooperative multi-tasking HTTP > server: > ?git clone git://pyjs.org/git/multitaskhttpd.git > > there probably exist perfectly good web frameworks that are capable of > doing this sort of thing: i feel certain that twisted is one of them. > however, the original author of rtmplite decided to rip twisted out > and to use multitask.py and i'm one of those strange people that also > likes the idea of using 900 lines of awesome elegant code rather than > tens of thousands of constantly-moving-target. > > one of the things that's slightly unfortunate is that i'm going to > have to copy SimpleHTTPServer.py and slightly modify it; > CGIHTTPServer.py as well. ?this is Generally Bad Practice. > > can anyone think of a way of monkey-patching or otherwise using > SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the > base class from which those two are derived? > > i have had to pull bits out of BaseHTTPRequestHandler to make them use > the "yield" logic of multitask.py already, which was painful enough. > > ideas, anyone? > > l. I may not be fully understanding what you're doing, but is there a reason that one of the mixins can't be used? Geremy Condra From rami.chowdhury at gmail.com Mon Jul 12 18:14:52 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 12 Jul 2010 15:14:52 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <74B5583A-A65A-49EE-8876-8ADAEA74F138@gmail.com> Perhaps I'm misunderstanding, but ... On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: > > Existence of a variable means, among other things, that > > * You can use the value, with guaranteed effect (either unassigned exception > or you get a proper value) Surely by that definition any variable in any Python program "exists" -- you are guaranteed to get one of NameError, UnboundLocalError, or a value. That seems to argue away the meaning of the word entirely, and renders it not particularly useful. > > How the Python implementation implements that is an implementation detail. > > In short, how CPython does things is completely irrelevant to the language's semantics, so you're conflating things here. > As I'd understood the previous discussion, it is the CPython implementation that reserves local names and produces UnboundLocalErrors. The language semantics don't call for it, and another implementation might choose to handle function locals the same way as globals, through a namespace dictionary -- in which case the variable *wouldn't* exist in any way, shape, or form until it was assigned to. What am I getting wrong here? ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From j at junkwallah.org Mon Jul 12 18:32:27 2010 From: j at junkwallah.org (Junkman) Date: Mon, 12 Jul 2010 15:32:27 -0700 Subject: Python 3 grammar, function parameters Message-ID: <4C3B97FB.5010409@junkwallah.org> Greetings to Python users, I'm trying to parse Python code using the grammar supplied with the documentation set, and have a question on the grammar for function parameters: funcdef: 'def' NAME parameters ['->' test] ':' suite parameters: '(' [typedargslist] ')' typedargslist: ((tfpdef ['=' test] ',')* ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef) | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) tfpdef: NAME [':' test] >From what I understand, a naked asterisk - i.e. it is not a prefix to an identifier - is not a valid parameter, but the grammar explicitly allows it by making the identifier that immediately follows the asterisk optional. Are there cases where naked asterisk is allowed as a function parameter? If not, would it be correct for the grammar to specify the identifier trailing asterisk as mandatory? Thanks for any insight. Jay From alf.p.steinbach+usenet at gmail.com Mon Jul 12 18:55:59 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 00:55:59 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: * Rami Chowdhury, on 13.07.2010 00:14: > Perhaps I'm misunderstanding, but ... > > On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: >> >> Existence of a variable means, among other things, that >> >> * You can use the value, with guaranteed effect (either unassigned exception >> or you get a proper value) > > Surely by that definition any variable in any Python program "exists" -- you > are guaranteed to get one of NameError, UnboundLocalError, or a value. That > seems to argue away the meaning of the word entirely, and renders it not > particularly useful. No, you're conflating non-existence (NameError) with accessing the value of an existing but unassigned variable (UnboundLocalError). It is like arguing that vacuum is the same as cement because sticking your head into it for ten minutes or so yields an effect -- you're dead -- that in many ways is just about the same. However, the tangible existence of cement means that one can pour it over your head, /adding/ the cement, while it's difficult to pour vacuum over your head; rather, for the latter effect one would need to /remove/ the air around your head. OK, the analogy halts a little. But I think you'll get it. Similarly, you can add a variable and thereby cause am UnboundLocalError, and you can remove a variable and thereby cause a NameError. >> How the Python implementation implements that is an implementation detail. >> >> In short, how CPython does things is completely irrelevant to the language's > semantics, so you're conflating things here. >> > > As I'd understood the previous discussion, it is the CPython implementation > that reserves local names and produces UnboundLocalErrors. The language > semantics don't call for it, and another implementation might choose to handle > function locals the same way as globals, through a namespace dictionary -- in > which case the variable *wouldn't* exist in any way, shape, or form until it > was assigned to. > > What am I getting wrong here? The bit about the language semantics not specifying the effect. From the 3.1.1 language reference ?4.1: "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." And it goes on to elaborate on that, a little later: "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." In short, Stephen D'Aprano's remarks were technically on the spot, while Rhodri James's follow up, that it seems influenced your response, was meaningless mumbo-jumbo with strong emphasis added repeatedly to denials of reality. This is the usual reaction of the religious when exposed to reality. Cheers & hth., - Alf -- blog at From debatem1 at gmail.com Mon Jul 12 19:03:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 12 Jul 2010 19:03:09 -0400 Subject: Help choosing license for new projects In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 6:00 PM, Jake b wrote: > I'm starting a new python code project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of licenses. So > I don't know which to use. Maybe MIT or Apache or LGPL or BSD? Fair warning: I like and use the GPL a lot, so I'm biased. Take my advice with a grain of salt and recognize that while everybody has some semi-rational basis for the license they choose, in the end the decision is likely to be made on dogmatic grounds. > Are there certain licenses to avoid using because of interaction > problems between libraries using GPL2 / GPL3 / MIT / LGPL. / BSD with > my own? Generally, GPL'd code likes GPL'd code and BSD/MIT etc are more free-form. Depending on what you leverage this may or may not be a problem for you. > I want: > 1] Pretty much let anyone use it. Users do not have to include source > code, as long as I get credit. (which I think normallly is a textfile > with project url + name?) GPL is pretty much out then. CC-BY-* may be the way to go. > 2] (if it matters) I will be using different combinations of pyglet, > pygame, wxPython, etc. Not going to dig through those to find the licenses for you. Be aware that their choices impact yours. > 3] I want the option to use my own code in something commercial at a later date. Not generally an issue. Even GPL lets you sell your stuff. > Does #3 complicate things, or is fine when including author info? If you have many contributors it can. > The choices for google code projects are: > ?Apache License 2.0 Good choice, not my flavor but it does preserve attribution. > ?Eclipse license 1.0 Small license, doesn't give you the same degree of legal muscle that some others will if it gets violated. > ?GPLv2 > ?GPLv3 Both out on the source-not-required part. Personally, I like them (and the Artistic License) for exactly that reason. > ?GNU lesser GPL Fewer restrictions on linking, etc, but probably not what I would recommend here. > ?MIT license Good choice, well understood and widely used. Note that attribution is not preserved, although copyright is. That may or may not be enough for you. > ?Mozilla Public license 1.1 I'd avoid it, same caveats for the eclipse license and few obvious advantages. > ?New BSD License Also a good choice, same caveat as the X11 license. Geremy Condra From ben+python at benfinney.id.au Mon Jul 12 19:28:24 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 13 Jul 2010 09:28:24 +1000 Subject: Help choosing license for new projects References: Message-ID: <87pqys9t5z.fsf@benfinney.id.au> Jake b writes: > I want: > 1] Pretty much let anyone use it. Users do not have to include source > code, as long as I get credit. (which I think normallly is a textfile > with project url + name?) The simplest effective license that requires nothing more that attribution is ?under the terms of the Expat license? . The terms are effectively the same as some of the MIT/X11 licenses, but: * It's even shorter and simpler, while still being widely regarded as effective. * The name ?Expat license? is far less ambiguous, because MIT have released X11 under several different licenses, not all of them free. > 2] (if it matters) I will be using different combinations of pyglet, > pygame, wxPython, etc. You'll need to check the license terms on anything that you combine your work with, to see what the effective combination of terms will be. > 3] I want the option to use my own code in something commercial at a > later date. All free software licenses are commercial licenses, by definition. Preventing selling the work, or other commercial use, would make the license terms non-free. So if you choose any free software license this isn't a problem. > Does #3 complicate things, or is fine when including author info? You may be wanting to talk about making the work non-free (proprietary), in which case you're on your own :-) -- \ ?My mind is incapable of conceiving such a thing as a soul. I | `\ may be in error, and man may have a soul; but I simply do not | _o__) believe it.? ?Thomas Edison | Ben Finney From luke.leighton at gmail.com Mon Jul 12 19:28:29 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Mon, 12 Jul 2010 23:28:29 +0000 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: >> for several reasons, i'm doing a cooperative multi-tasking HTTP >> server: >> ?git clone git://pyjs.org/git/multitaskhttpd.git >> >> there probably exist perfectly good web frameworks that are capable of >> doing this sort of thing: i feel certain that twisted is one of them. >> however, the original author of rtmplite decided to rip twisted out >> and to use multitask.py and i'm one of those strange people that also >> likes the idea of using 900 lines of awesome elegant code rather than >> tens of thousands of constantly-moving-target. > I may not be fully understanding what you're doing, but is there a > reason that one of the mixins can't be used? yes: they're threaded. or forking. this is *single-process* cooperative multitasking. but that's not quite an answer, i know. perhaps i should explain the three use-cases: 1) pyjamas-web. pyjamas-web was an experiment i did, last year, to port pyjamas http://pyjs.org to run the *exact* same app which normally is either compiled to javascript (to run in the web browser), or is run as a desktop app.... that *exact* same app i wanted to run it *server-side*. the reason for doing this is so that javascript would not be needed. remember that the apps _really_ look like GTK apps: RootPanel().add(HTML("Hello World") so there's a python application, and i re-implemented all of the widgets to add to an XML document (actually an eltree instance) and i tidied things up with BeautifulSoup, voila, splat, spew forth some HTML, output it from the web framework. i'd picked mod_python. did it work? why yes it did! right up until i had pressed refresh a few times, or pressed a few application "buttons". at that point, it all fell over, because, why? ****ing threads, that's why. HTTP is totally stateless. each mod_python thread is arbitrarily picked to run an incoming request. i had totally forgotten this, and had "associated" the pyjamas application instance with the python thread's local storage memory. oh... shit :) so, one person could be viewing an app, then next minute, someone else connects to the server, and they get the other person's app!! the only sane way round this, especially because if you want to serialise the data structures of the pyjamas app you might have to dump... what... 100k into a database or so (!!) and retrieve it, is to have a SINGLE PROCESS multitasking web server, where all the apps are stored in the SAME PROCESS. then, you can store the apps in a dictionary, and look them up by a session cookie identifier. problem is solved. 2) rtmplite itself rtmplite currently does RTMP only (port 1935). for the exact same reasons as 1) the real-time audio/video streams need to be passed across from client to client, and it needs to be done QUICKLY. passing A/V data across unix domain sockets or shared memory in a _portable_ fashion... does anyone _know_ how to do data sharing portably using python? i don't! i'd love to know! :) so to avoid the problem, easy: just design the app to be single-process, handling multiple RTMP clients simultaneously. now i would like to see rtmplite extended to support HTTP (RTMP can be proxied over HTTP and HTTPS). 3) persistent database connections with per-user credentials this is the _real_ reason why i'm doing this. the GNUmed team are looking to create a web version of GNUmed. however, their current system relies on postgresql "roles" for security. as a python-wxWidgets app, that's of course absolutely fine. but, for a _web_ app, it's not in the slightest bit fine, because _all_ web frameworks assume "global" database credentials. also, they're counting on the database connections being persistent. how in hell's name, when using a stateless protocol like HTTP, do you cross-associate *persistent* and multiple per-user database connections with a user's browser, when all the web frameworks out there only really do "global" single-username, single-password database logins?? and the answer is: by using a cooperative multitasking httpd, which adds a session cookie to each incoming connection, and uses that to create an in-memory "application instance" which will STAY in memory (of the single-process http server). in that in-memory application instance, you can do whatever you like: have a login form which takes user/pass as input, then uses that on the POST to create a database connection, and stores the resultant authenticated psycopg2 "pool" connection into the app instance. the app instance is always always looked up in the dictionary of app instances, using the cookie session id as a key, and thus, each browser will _always_ be directed at the correct app instance. i hate to think how this would be done using any of the standard MixIns. even if you wrote a special MixIn which did single-instance socket handling, you couldn't use it because the BaseHTTPHandler doesn't "cooperate", it has a while True loop on serving connections until they're closed. so, you could serve one HTTP 0.9 request and then another person, orrr you could serve one HTTP 1.0 or 1.1 request that WAS NOT SET TO "Connection: keep-alive" and then do another person... ... but if ever there was a keep-alive set, you would be FORCED to serve that one HTTP connection, blocking absolutely everyone else until they buggered off. ... but with multitaskhttpd, even the persistent HTTP connections are still cooperatively multi-tasking. so, yah, whilst you're reading a big file, or serving a big database query, you're hosed (and i think i have a way to deal with the big database query thing, but it's an optimisation so am leaving it for now [*]), but other than that, you're fine. so - yah. definitely something that i've not been able to find (and don't like twisted, even if it could do this). l. [*] the solution involves creating some threads, accessible using a global lock, which run the database queries. the threads could even be done using a Threaded TCPSocketServer, and in each thread, the handler instance has a persistent database connection. the sockets are there merely to notify the main process (the multitask app) of the fact that a particular database query operation has completed, by sending the unique ID of the thread down the socket. the main process (multitask app) can then hook a global lock, get at the list of threads, grab the one with the right ID, grab the SQL query results and then unhook the global lock. the reason for using sockets is because multitask can do cooperative multitasking on socket filehandles. by having a special task which yields on the Threaded TCPSocketServer connection, the main process can delay answering a particular HTTP request until the database response has been completed. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:34:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:34:18 GMT Subject: Easy questions from a python beginner References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3ba679$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote: > As I see it it doesn't matter whether the implementation is CPython call > frame slots or that mechanism called something else or a different > mechanism called the same or a different mechanism called something > different; what IMO matters is same semantics, that any assignment to a > variable within a routine serves as a compile time declaration, creating > that local variable in advance, unless, with Python 3.x., that name has > been declared as a 'global' or 'nonlocal'. > > So, this is a possible point of disagreement. > > I say the semantics of local variable creation are part of the language > definition, but I get the /impression/ that maybe you think it's > CPython-specific, that e.g. > > def foo(): > x > x = 0 > > might not raise an unassigned variable exception with some conforming > Python implementation, i.e. different effect for same code with > different implementations, that this is at least /unspecified behavior/ > in Python? Almost. I believe that "any assignment to a variable within a routine serves as a compile time declaration" is a promise of the language, but what an implementation does in response to that declaration is unspecified. So long as foo() raises NameError, or a subclass of it, it will be a conforming Python implementation. That's what Python 1.5 does, and I think if some competing implementation targeted 1.5 we'd still be happy to call it Python. (Although we might wonder about the author's sanity...) Implementations are free to subclass NameError, as CPython does with UnboundLocalError, but mustn't raise a completely unrelated error, or no error at all. E.g. I don't think it would be acceptable to implicitly create new names and bind them to some arbitrary default value. E.g. an implementation might do something like this: * when parsing the function, prior to compiling the byte-code, tag every name with a sigil representing whether it is local or non-local; * compile a single byte-code for name lookup; * when executing that instruction, if the name is tagged as a local, search only the local namespace, otherwise search the nonlocal, global and builtin namespaces; * when displaying names to the user (say, in tracebacks) suppress the sigil. Under this implementation, no variable actually exists until it is assigned to. This is equivalent to shifting the decision to use LOAD_FAST or LOAD_GLOBAL to runtime rather than compile time, so it would probably hurt performance rather than increase it, but it would still be a conforming implementation. But of course I'm not Guido, and he has the final word on what counts as acceptable behaviour. -- Steven From luke.leighton at gmail.com Mon Jul 12 19:48:03 2010 From: luke.leighton at gmail.com (lkcl) Date: Mon, 12 Jul 2010 16:48:03 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: <1fea3f6a-f504-4298-b052-d3dcc6a651e1@i31g2000yqm.googlegroups.com> On Jul 12, 9:52?pm, Gelonida wrote: > Hi lkcl, > > Do you have any documentation or overview for your project? git clone git://pyjs.org/git/multitaskhttpd.git i only started it today, but yes, there's a README. the primary reason it's being developed is because GNUmed are looking to create a web service but they want to use the same psycopg2-based middleware that's taken them pretty much forever to develop. see my reply to geremy condra for more details. if this turns out to be something that _really_ hasn't been done before, then i'm happy for other people to pitch in and help out. > Questions ?I would be interested in: > - List of features already working * simple HTTP GET of files and subdirs (because i blatantly copied SimpleHTTPServer.py) * JSONRPC services (i blatantly copied SimpleJSONRPCServer.py, it's something i found, it's based on SimpleXMLRPCService.py) > - list of features under development the time between "under development" and "in future" is so short it's hardly worthwhile stating. i added JSONRPC in about 90 minutes for example. tomorrow i'll add HTTP POST multi-part forms and it will take me about... 50 mins i should imagine, by looking at something like turbogears or django. i'm not going to "waste time reinventing" stuff when i can pretty much cut/paste it. web servers have been _done_ already - it's just that cooperative multitasking seems most definitely _not_ to have been done before. > - list of features being in in the near future * HTTP POST with multi-part forms (just like standard web frameworks) * a better API once i have a clearer idea of what's needed * use of regex matching on apps, just like django urls.py l. From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:49:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:49:41 GMT Subject: Help choosing license for new projects References: Message-ID: <4c3baa15$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 17:00:22 -0500, Jake b wrote: > I'm starting a new python code project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of licenses. So I > don't know which to use. Maybe MIT or Apache or LGPL or BSD? http://www.dwheeler.com/essays/gpl-compatible.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 19:50:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Jul 2010 23:50:12 GMT Subject: Easy questions from a python beginner References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <4c3baa34$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote: > Existence of a variable means, among other things, that > > * You can use the value, with guaranteed effect (either unassigned > exception > or you get a proper value): in particular, you won't be accessing a > global if you're using the name of a local declared by a later > assignment. That is too strong. Given the global code: x (where x doesn't exist in the global namespace, and therefore does not exist, as you agreed earlier) Python promises to raise NameError. By the above definition, this counts as "variable x exists". But surely that is undesirable -- that implies that *all* variables exist. Even $%@*@( is a variable that exists, as that is guaranteed to raise SyntaxError. -- Steven From alf.p.steinbach+usenet at gmail.com Mon Jul 12 20:06:39 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 02:06:39 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3baa34$0$28644$c3e8da3@news.astraweb.com> References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> <4c3baa34$0$28644$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 13.07.2010 01:50: > On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote: > >> Existence of a variable means, among other things, that >> >> * You can use the value, with guaranteed effect (either unassigned >> exception >> or you get a proper value): in particular, you won't be accessing a >> global if you're using the name of a local declared by a later >> assignment. > > That is too strong. Given the global code: > > x > > (where x doesn't exist in the global namespace, and therefore does not > exist, as you agreed earlier) Python promises to raise NameError. By the > above definition, this counts as "variable x exists". > > But surely that is undesirable -- that implies that *all* variables > exist. Even $%@*@( is a variable that exists, as that is guaranteed to > raise SyntaxError. Hm, I already answered someone else here committing that logic error. In one case an exception is generated by removing a variable. In the other case an exception is generated by adding a variable. Cheers & hth., - Alf -- blog at From alf.p.steinbach+usenet at gmail.com Mon Jul 12 20:18:06 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 02:18:06 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4c3ba679$0$28644$c3e8da3@news.astraweb.com> References: <4c3a806b$0$28662$c3e8da3@news.astraweb.com> <4c3ba679$0$28644$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 13.07.2010 01:34: > On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote: > >> As I see it it doesn't matter whether the implementation is CPython call >> frame slots or that mechanism called something else or a different >> mechanism called the same or a different mechanism called something >> different; what IMO matters is same semantics, that any assignment to a >> variable within a routine serves as a compile time declaration, creating >> that local variable in advance, unless, with Python 3.x., that name has >> been declared as a 'global' or 'nonlocal'. >> >> So, this is a possible point of disagreement. >> >> I say the semantics of local variable creation are part of the language >> definition, but I get the /impression/ that maybe you think it's >> CPython-specific, that e.g. >> >> def foo(): >> x >> x = 0 >> >> might not raise an unassigned variable exception with some conforming >> Python implementation, i.e. different effect for same code with >> different implementations, that this is at least /unspecified behavior/ >> in Python? > > Almost. > > I believe that "any assignment to a variable within a routine serves as a > compile time declaration" is a promise of the language, but what an > implementation does in response to that declaration is unspecified. So > long as foo() raises NameError, or a subclass of it, it will be a > conforming Python implementation. > > That's what Python 1.5 does, and I think if some competing implementation > targeted 1.5 we'd still be happy to call it Python. (Although we might > wonder about the author's sanity...) Implementations are free to subclass > NameError, as CPython does with UnboundLocalError, but mustn't raise a > completely unrelated error, or no error at all. E.g. I don't think it > would be acceptable to implicitly create new names and bind them to some > arbitrary default value. > > E.g. an implementation might do something like this: > > * when parsing the function, prior to compiling the byte-code, tag > every name with a sigil representing whether it is local or non-local; > * compile a single byte-code for name lookup; > * when executing that instruction, if the name is tagged as a local, > search only the local namespace, otherwise search the nonlocal, > global and builtin namespaces; > * when displaying names to the user (say, in tracebacks) suppress > the sigil. > > Under this implementation, no variable actually exists until it is > assigned to. > > This is equivalent to shifting the decision to use LOAD_FAST or > LOAD_GLOBAL to runtime rather than compile time, so it would probably > hurt performance rather than increase it, but it would still be a > conforming implementation. > > But of course I'm not Guido, and he has the final word on what counts as > acceptable behaviour. The 3.1.1 docs explicitly require UnboundLocalError (I just checked). So, at least for 3.x it is not an implementation detail. Anyway, your phrase "actually exist" presumably refers to storage allocation. That is an implementation detail. As a similar implementation scheme, a compiler can in certain cases detect that a variable is only assigned once, and substitute the value whereever that variable is used, not allocating any storage for it. This is the case in Python, in C++ and in almost any language. We don't start doubting the existence of variables in general (as some in the Python community do) on such grounds. More to the point of this sub-thread, it would be impossible to reason about things if one had to take into account the particular implementation's details at all times. Doing that renders most terms, including "exist", pretty meaningless and useless, since you would have to check whether each particular variable was optimized away or not: for the purpose of discussing existence in Python, what matters is portable effect. Summing up, how CPython implements the required semantics, is irrelevant. :-) Cheers from Norway, - Alf -- blog at From steve at REMOVE-THIS-cybersource.com.au Mon Jul 12 20:18:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 00:18:20 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> Message-ID: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 12:34:46 +0200, Jean-Michel Pichavant wrote: > Well, actually some people might think otherwise. While I disagree with > the OP flaming style, one could argue that muting an integer into a > boolean makes no sense (I'm one of them). You can still do it, but there > is no "right" way to do it. > You can decide that everything else than 0 is True, but you could also > pickup the integer 3 as false value, it would work as well since it > makes no sense. This is just an arbitrary definition. Choosing 3 as a false value would be arbitrary, but the choice of 0 is anything but arbitrary. The distinction that Python makes is between values which are Something (true values) and those which are Nothing (false values). Python has an infinite number of ways of spelling Something: True, 1, 2, 3.1415, "abc", (2, 4), [None, 1, "A"], ... and a smaller number of ways of spelling Nothing: False, None, 0, 0.0, "", (), [], ... The fact that False == 0 (as opposed to, say, [] != 0) is due to the need for backwards compatibility. That bools are implemented as a subclass of int is a historical accident. The fundamental distinction in Python is between objects which are Something and those that are Nothing, and that's not an arbitrary distinction, it's a very deep distinction. This is why virtually all low-level languages treat 0 as a false flag and 1 (or sometimes -1) as a true flag. I say "virtually all", not because I know of any exceptions, but because in the history of computer languages you can probably find every design mistake, arbitrary choice, and perverse decision imaginable made by *somebody*. Consider branch statements. Forth jumps to the "true" branch on any integer flag, and to the "false" branch on 0, but the canonical true value is either 1 (0000 00001 in binary) or -1 (1111 1111). Early versions of BASIC used -1 as true and 0 as false. With Pascal's strong type-checking, you were forced to use the boolean type in branches, but (if I recall correctly) the language guaranteed that false was 0 and true was 1: a packed array of bools would use a 0 bit for false and 1 for true, and an unpacked array would use eight zero bits versus seven zeroes and an one. So there's historical precedent from other languages, backwards compatibility with early Python versions, and a fundamental philosophical distinction all in favour of using 0 for false. Not arbitrary at all. > I prefere to explicitly write what I want to test: > > if myInt <> 0: I would argue against that. Why do you, the coder, care about the specific details of treating ints in a boolean context? The int type itself knows, leave the decision to it. Sure, in the specific case of ints, the distinction is so fundamental, so basic, and so unlikely to change, that there's no real harm in the explicit test. But consider some other type: if myValue.count <= 0 and myValue.next is None and myValue.blob == "": # myValue is considered false versus: if not myValue: Which would you prefer? I think the choice is obvious: the type knows whether it is equivalent to true or false, leave it up to the object to decide. Why bother making an exception for ints, or strings? -- Steven From rami.chowdhury at gmail.com Mon Jul 12 20:29:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 12 Jul 2010 17:29:33 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4c3aedd5$0$28647$c3e8da3@news.astraweb.com> Message-ID: <2377A6A6-29B3-4395-8995-E17747A23AAE@gmail.com> On Jul 12, 2010, at 15:55 , Alf P. Steinbach /Usenet wrote: > * Rami Chowdhury, on 13.07.2010 00:14: >> Perhaps I'm misunderstanding, but ... >> >> On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote: >>> >>> Existence of a variable means, among other things, that >>> >>> * You can use the value, with guaranteed effect (either unassigned exception >>> or you get a proper value) >> >> Surely by that definition any variable in any Python program "exists" -- you >> are guaranteed to get one of NameError, UnboundLocalError, or a value. That >> seems to argue away the meaning of the word entirely, and renders it not >> particularly useful. > > No, you're conflating non-existence (NameError) with accessing the value of an existing but unassigned variable (UnboundLocalError). It is like arguing that vacuum is the same as cement because sticking your head into it for ten minutes or so yields an effect -- you're dead -- that in many ways is just about the same. Right -- but you're playing with the definition of "existence" there, and since you're not using it quite consistently, I wasn't sure what you meant. Your discussion of the language reference below helps clear it up. > >>> How the Python implementation implements that is an implementation detail. >>> >>> In short, how CPython does things is completely irrelevant to the language's >> semantics, so you're conflating things here. >>> >> >> As I'd understood the previous discussion, it is the CPython implementation >> that reserves local names and produces UnboundLocalErrors. The language >> semantics don't call for it, and another implementation might choose to handle >> function locals the same way as globals, through a namespace dictionary -- in >> which case the variable *wouldn't* exist in any way, shape, or form until it >> was assigned to. >> >> What am I getting wrong here? > > The bit about the language semantics not specifying the effect. > > From the 3.1.1 language reference ?4.1: > > "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." > > And it goes on to elaborate on that, a little later: > > "If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." Ah, interesting. Thank you for pointing that out -- I didn't know that. I notice the same paragraph is in the 2.7 reference, so it presumably holds for 2.x implementations as well. > This is the usual reaction of the religious when exposed to reality. > > Cheers & hth. It does, thank you. Although the repeated references to the "religious" and their "refusal to accept reality" are less than helpful. > > -- > blog at > -- > http://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Mon Jul 12 20:36:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 17:36:38 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <7xeif8fca1.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > This is why virtually all low-level languages treat 0 as a false ... OK, but is Python a low-level language, and if not, why are low-level languages appropriate examples to follow? >> if myInt <> 0: > > I would argue against that. Why do you, the coder, care about the > specific details of treating ints in a boolean context? The int type > itself knows, leave the decision to it. There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, which is automatically convert strings to numbers, so "12"+3 = 15. Python has the good sense to throw a type error if you attempt such an addition, but it goes and converts various types to bool automatically, which is more Perl-like than I really enjoy. In fact Python 3 added yet another automatic conversion, of int to float on division, so 1/2 = 0.5. Obviously it's a point in the design space where various decisions are possible, but I can get behind the "explicit is better than implicit" idea and say that none of those conversions should be automatic, and if 1/2 = 0 was confusing people in Python 2 enough to justify changing divison semantics in Python 3, the preferable change would be for int division to raise TypeError rather than quietly converting to float. The same thing goes for bool conversion, though we are all used to it by now, and it would be way too disruptive a change. > if myValue.count <= 0 and myValue.next is None and myValue.blob == "": > # myValue is considered false > versus: > if not myValue: > Which would you prefer? I'd personally prefer if not bool(myValue): which would call the myValue's __bool__ method if it chose to implement one. Explicit is better than implicit. From benjamin.kaplan at case.edu Mon Jul 12 20:45:22 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 12 Jul 2010 17:45:22 -0700 Subject: how to delete "\n" In-Reply-To: References: Message-ID: On Mon, Jul 12, 2010 at 2:33 PM, Jia Hu wrote: > Thank you. It works now. > > ?if I use?'print' to print?the whole list, 'print'?will add newline > at the end of the list?but not each item in the list.? right? > > For the?code: > for line in fileName: > ??? line = line.rstrip('\n') > I think?this will affect 'fileName' because it assign the value to 'line' ? No it does not. Python assignments never modify anything other than the enclosing namespace. "for line in fileName" reads a line from the file and creates a string. That string resides in memory somewhere, who knows where. It does not reside inside fileName- it is a separate object. That string is then bound to the name "line" in the current namespace (the module's namespace in this case). Variables in Python are just entries in a dictionary. In fact, you can do globals()["line"] and it will return the string associated with that name. line.rstrip("\n") gets the object associated with the name "line" and accesses the object with the name "rstrip" that's associated with the object named "line". It then calls that object (in this case a builtin_function_or_method object) with the string "\n" as a parameter. rstrip then generates a new string. The line = (that new string that was just generated) associates the new string with the name "line". The old string hasn't changed at all (in fact, the object will get deleted almost immediately since it's reference count just dropped to 0). And the file hasn't changed either. > But when I print fileName, "\n" still exists at each item in the list. > > Because each line in?my?txt file are numeric values. is there any other > better way to get each > numerical value at each line? for example using numpy or changing?string > list to numerical list? > > Thank you for?help. > > On Mon, Jul 12, 2010 at 4:45 PM, Chris Rebert wrote: >> >> On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote: >> > Hi, I just want to delete "\n" at each line. My?operating system?is >> > ubuntu >> > 9.1. The code is as follows >> > >> > #!/usr/bin/python >> > import string >> > fileName=open('Direct_Irr.txt', 'r') # read file >> > directIrr = fileName.readlines() >> > fileName.close() >> > for line in directIrr: >> > ?????? line.rstrip('\n') >> > print directIrr >> > >> > But I found there is still "\n" . Could someone help me why it is not >> > correct? >> >> .rstrip() returns a *new* string without trailing whitespace (which >> you are currently then throwing away); it does *not* modify string >> objects in-place. Python strings objects are entirely immutable and >> unmodifiable; all operations on them merely produce /new/ strings. >> >> Assuming you still want to use .readlines(), you'd do: >> directIrr = fileName.readlines() >> fileName.close() >> directIrr = [line.rstrip('\n') for line in directIrr] >> print directIrr >> >> For how third line works, google "python list comprehensions". >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From chantikotyada1 at gmail.com Mon Jul 12 20:56:41 2010 From: chantikotyada1 at gmail.com (Chantodu) Date: Mon, 12 Jul 2010 17:56:41 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <0aac4eda-71a7-4de0-8008-a3ef097112cc@n8g2000prh.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account. At http://ukcollegegirls.co.cc Due to high security risks, i have hidden the PayPal Form link in an image. in that website On search box Top Side, click on image and enter your PayPal id And Your name. please don,t tell to any One. From hujia06 at gmail.com Mon Jul 12 21:28:06 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 12 Jul 2010 21:28:06 -0400 Subject: write a .txt file Message-ID: Hello: I have a problem about how to generate a specific.txt file. I use the following code: #!/usr/bin/python # OS: Ubuntu import subprocess fileName = open ('final.txt', 'a') fileName.write ('%s %s %s \n' % (12,25,9)) desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) fileName.seek(0,2) fileName.write ('%s %s %s \n' % (85,25,12)) fileName.close() The above code generates the following result: 12 25 9 85 25 12 hello What I want is: 12 25 9 hello 85 25 12 Could someone provies some suggestions about this problem? Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Jul 12 21:28:28 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 19:28:28 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano wrote: >> I prefere to explicitly write what I want to test: >> >> if myInt <> 0: > > I would argue against that. Why do you, the coder, care about the > specific details of treating ints in a boolean context? The int type > itself knows, leave the decision to it. I think you're missing the point. He's not using ints in a boolean context. If it were a boolean context, he would be using bools in the first place. What he is objecting to is the practice of testing for special cases of ints (i.e. 0) by treating them as bools. The specific details of converting ints to bools are very much relevant here; as long as 0 is false, it works. If -1 is false (a semantic I have actually seen used), then it does not. Cheers, Ian From knny.myer at gmail.com Mon Jul 12 21:29:00 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Mon, 12 Jul 2010 18:29:00 -0700 (PDT) Subject: Check if a command is valid Message-ID: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Hello, I have to figure out if a string is callable on a Linux system. I'm actually doing this: def is_valid_command(command): retcode = 100 # initialize if command: retcode = subprocess.call(command, shell=True) if retcode is 0: print "Valid command." else: print "Looks not so good..." is_valid_command("ls") Never mind the code, because this is not the original. The side effect of subprocess.call() is that it *actually* executes it, but I just need the return code. What are better ways of doing this? From tim.wintle at teamrubber.com Mon Jul 12 21:30:38 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 13 Jul 2010 02:30:38 +0100 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> Message-ID: <1278984638.9880.46.camel@tim-laptop> On Mon, 2010-07-12 at 23:28 +0000, Luke Kenneth Casson Leighton wrote: > On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: > > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: > >> there probably exist perfectly good web frameworks that are capable of > >> doing this sort of thing: i feel certain that twisted is one of them. > >> however, the original author of rtmplite decided to rip twisted out > >> and to use multitask.py and i'm one of those strange people that also > >> likes the idea of using 900 lines of awesome elegant code rather than > >> tens of thousands of constantly-moving-target. have you seen nagare: http://www.nagare.org/ I've not used it - but from my understanding it might be what you're looking for (for the http part at least). > i hate to think how this would be done using any of the standard > MixIns. even if you wrote a special MixIn which did single-instance > socket handling, you couldn't use it because the BaseHTTPHandler > doesn't "cooperate", it has a while True loop on serving connections > until they're closed. I started working on something like this once (but I still had threads) - afraid I can't find the code with it in right now. I think it was similar to what you're doing: at least 2 threads - one accepts requests, the other deals with them. * overload BaseHTTPServer.process_request so it just adds connections to a queue. * worker threads fetch connections from the queue and starts working on them. when they want to give up control they raise an exception to bubble back up, and the connection is re-added to the queue along with any persistent data. I seem to remember the annoying bit being having to override SocketServer.finish_request to use an existing handler. - you can fairly easily limit that to process a single session at a time with a shared dictionary or similar. The reason I was doing it was for work that was cached for a short time, but took a while on cache misses - If I noticed that another thread was currently updating the cached version then I raised an exception. (I had code that unlocked the gil, so multi-threaded made sense) Tim From me+list/python at ixokai.io Mon Jul 12 21:36:32 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 12 Jul 2010 18:36:32 -0700 Subject: any issues with long running python apps? In-Reply-To: <4c3b4dda$0$1620$742ec2ed@news.sonic.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <4C3BC320.5010200@ixokai.io> On 7/12/10 10:16 AM, John Nagle wrote: > Yesterday, I was running a CNC plasma cutter that's controlled > by Windows XP. This is a machine that moves around a plasma torch that > cuts thick steel plate. A "New Java update is available" window > popped up while I was working. Not good. That's downright frightening. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Mon Jul 12 21:41:06 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 19:41:06 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Jul 12, 2010 at 6:36 PM, Paul Rubin wrote: > There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, > which is automatically convert strings to numbers, so "12"+3 = 15. > Python has the good sense to throw a type error if you attempt such an > addition, but it goes and converts various types to bool automatically, > which is more Perl-like than I really enjoy. ?In fact Python 3 added yet > another automatic conversion, of int to float on division, so 1/2 = 0.5. > > Obviously it's a point in the design space where various decisions are > possible, but I can get behind the "explicit is better than implicit" > idea and say that none of those conversions should be automatic, and if > 1/2 = 0 was confusing people in Python 2 enough to justify changing > divison semantics in Python 3, the preferable change would be for int > division to raise TypeError rather than quietly converting to float. I don't think it's any more egregious than automatic conversions of mixed-type expressions, such as 3 + 4.5. If you don't want your ints automatically converted to floats on division, then use the integer division operator. 1 // 2 is still 0 in Python 3. Cheers, Ian From python at mrabarnett.plus.com Mon Jul 12 21:58:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jul 2010 02:58:31 +0100 Subject: write a .txt file In-Reply-To: References: Message-ID: <4C3BC847.4040606@mrabarnett.plus.com> Jia Hu wrote: > Hello: > > I have a problem about how to generate a specific.txt file. I use the > following code: > > #!/usr/bin/python > # OS: Ubuntu > import subprocess > fileName = open ('final.txt', 'a') > fileName.write ('%s %s %s \n' % (12,25,9)) > desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) > > fileName.seek(0,2) > fileName.write ('%s %s %s \n' % (85,25,12)) > fileName.close() > > The above code generates the following result: > 12 25 9 > 85 25 12 > hello > > What I want is: > 12 25 9 > hello > 85 25 12 > > Could someone provies some suggestions about this problem? > > Thank you. > When "echo" is called the file is still open, so the might not be able to write to it. Try closing the file before starting the subprocess and then reopen it afterwards. By the way, it slightly confusing that you call the variable "fileName", but it doesn't contain the name of a file! :-) From no.email at nospam.invalid Mon Jul 12 22:14:38 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 19:14:38 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <7xy6dg1629.fsf@ruckus.brouhaha.com> Ian Kelly writes: > I don't think it's any more egregious than automatic conversions of > mixed-type expressions, such as 3 + 4.5. That could also be explicit: float(3) + 4.5, or 3 + int(4.5). > If you don't want your ints automatically converted to floats on > division, then use the integer division operator. 1 // 2 is still 0 > in Python 3. Sure, I do that, but the issue was that 1/2 was confusing newbies who don't understand the different characteristics of int and floating types. If the idea is to change Python to fix this problem in a newbie-friendly way, the right fix is to create enlightment by raising an exception that points out the problem, not sweep it under the rug with an automatic conversion. From cs at zip.com.au Mon Jul 12 22:30:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 12:30:43 +1000 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <20100713023043.GA16776@cskk.homeip.net> On 12Jul2010 17:36, Paul Rubin wrote: | Steven D'Aprano writes: | > This is why virtually all low-level languages treat 0 as a false ... | | OK, but is Python a low-level language, Not particularly, but true/false and Boolean login are low level ideas. If it works well in a low level language (where all you might have are ints of various flavours and thus some equivalence notion is required), why would you _change_ the conventions in a high level language without a compelling reason? The more commonality in concepts there are, for all that they are just conventions, the easier it is remember how to do things. | and if not, why are low-level | languages appropriate examples to follow? They may not be in any inherent sense, but they are examples and if the usage doesn't cause pain are they inappropriate? Steven: | >> if myInt <> 0: | > | > I would argue against that. Why do you, the coder, care about the | > specific details of treating ints in a boolean context? The int type | > itself knows, leave the decision to it. [...snip...] This I'm only halfway with. I, the coder, _must_ know. The "if" statement has an intent, and I need to know that "if myInt:" matches my intent. Of course, using the right idioms it will match a lot of the time. But I've certainly been bitten by writing: if myDict: intending: if myDict is not None: but also getting: if myDict != {}: Clearly the fault was mine, but I, the coder, _must_ care about the details of using non-Booleans in a Boolean context. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is Texas law that when two trains meet each other at a railroad crossing, each shall come to a full stop, and neither shall proceed until the other has gone. From f2h2d2 at gmail.com Mon Jul 12 23:16:01 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Mon, 12 Jul 2010 20:16:01 -0700 (PDT) Subject: Must We Worship Message-ID: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> Must We Worship Whom Must We Worship The submission of man to His Creator is the essence of Islam. The name ?Islam? is chosen by God (Allah) and not by man. It is the same unifying Message revealed to all the Prophets and Messengers by Allah and which they spread amongst their respective nations. In its Final form it was revealed to Muhammad (Peace & Mercy of Allah be upon him) as a complete Message to whole mankind. The Lord, Allah, is the True and Only Creator that deserves to be worshipped. No worship is worthy of being given to a stone, statue, a cross, a triangle, Khomeini, Farakhan, Eliajahs, Malcom?s X or Y, Ghandi, Krishna, Guru, Buddha, Mahatma, Emperor, Joseph Smith, Sun, Moon (not to that from Korea too!), Light, Fire, rivers, cows, Rama, Temples, Prophets, Messengers (Yes! Muslims do not worship Muhammad-peace be upon him), Saints, Priests, Monks, Movie Stars, Sheiks, etc.!!! All are created beings or things. ALLAH, is the Name of the One True God. His Name is not chosen by man and does not have a number or gender. It is known that Allah is the Name of God in Aramaic, the language of our beloved Prophet Jesus and a sister language of Arabic. The Name ?Allah? has been used by all previous Prophets starting with Adam and by the last and final Prophet, Muhammad (Peace be upon them all). The Innate Nature in man recognizes what is good and bad, what is true and false. It recognizes that the Attributes of Allah must be True, Unique, and All-Perfect. It does not feel comfortable towards any kind of degradation of His Attributes not does it qualities to the Creator. Many who became ?discontent with God? did so because of the practices of the Church in medieval Europe and because of the claims of ?god dwelling in a son? and the concept of the ?original sin?. However, they ?escaped? into worshipping a new theory called ?mother nature? as well as the ?material? World. With the advancement of materialistic technology others from different religions adopted the concept of ?forgetting about God? and ?let us live this life and enjoy it!?, not realizing that they have chosen the worship of the ?original god? of Rome: Desire! .As a result the ?enjoyment? is turning to ?suffering? from AIDS. NOW we can see that all of this materialistic and secular progress produced a spiritual vacuum that led to complex social, economical, political, and psychological problems. Many of those who ?fled? their ?religions? are in search again. Some try to ?escape? the complexity of their daily lives via various means. Those who had the chance to examine the Qur?an and Islam, proceed with a complete way of life that relates man to establish a purpose for his presence on earth. This is well recognized in the Attributes of Allah and what does He require from man. He does not want man to be enslaved to any false deity: nature, drugs, lust, money, other man, desire, or sex. He provides man with the proofs that He is the One who can redeem so that man can free himself from the slavery to any form of creation and to turn to his Creator Alone. THIS Creator Has Perfect Attributes. He is the First, nothing is before Him, the Ever Living. To Him is the Final Return where everyone will be dealt with in the Most Perfect and Just way. He does not begot nor He is begotten. Those who attribute Divinity to Jesus forget or ignore the fact that Jesus was in a mother?s womb. He needed nutrition; he was born and grew up to be a man. He was trusted with the Gospel as a Message to the Children of Israel: ?For there is One God, and one mediator (i.e. a messenger) between God and men (the Children of Israel), the man Christ Jesus) (I Timothy 2:5). A man- messenger calling his nation not to worship him: ?But in vain they do worship me!? (Mathew 15:9). A man who needs to eat, walk, sleed, rest, etc.. cannot have Divine Attributes because he is in need and God (Allah) is Self-Sufficient. AS far as Buddhism, Hinduism, Zoroastrianism, Marxism, and Capitalism, there is the devotion of worshipping created being/things in one form or another. Jews had attributed a ?Nationalistic? belonging to Allah. They labeled Him ?The Tribal God? for the Children of Israel. Men and women following these ?religions? were born with the natural inclination of submission to their Creator, Allah. It is their parents who had driven them into their respective traditions. However, once people are exposed to the Signs of Allah around them, or in the Qur?an or to someone who triggers their Fitra (natural inclination to worship Allah Alone), the reverting process begins and that is why we see a universal spreading of Islam. In the West and despite tha many distortions of Islam in the Media, many admit that Islam may be the fastest growing Faith. No sense of fairness can be achieved without a genuine attempt to know the Word of Allah in the Qur?an and not on the 30-min-Evening News. This is the real challenge for those who seek the Truth. Man is created for a purpose: to live a life in accordance with Allah?s way. Why Not? Do we posses the air we breath? Did we create ourselves or others? Or were we ourselves the Creators? We are limited and weak. So is our right to ignore our Creator where we all need Him? ISLAM is the submission in worship to Allah Alone and it is the essence of all the Messages sent to all nations before us. Allah is All-Just and All-Wise. He does not intend confusion for His Creation. The religion accepted to Him is the one chosen by Him. Its essence must be One, because He is One. It is free from geographical, racist, and status oriented concepts. It is Perfect and it is the complete way of life. All these qualities are chosen by Allah in His Only Religion: Islam. Its details are in in the Qur?an, read it and come with an open heart because none can expose better than the World of Allah. The Qur?an was revealed to Prophet Muhammad. He did not author it. He was unlettered. Its translation is available in many languages in bookstores or in an Islamic Center close to you. Take the time to read it and come/call the Islamic Center, or speak to someone who re-verted and submitted to Allah Alone. The Decision is yours! From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:16:31 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:16:31 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote: > On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano > wrote: >>> I prefere to explicitly write what I want to test: >>> >>> if myInt <> 0: >> >> I would argue against that. Why do you, the coder, care about the >> specific details of treating ints in a boolean context? The int type >> itself knows, leave the decision to it. > > I think you're missing the point. He's not using ints in a boolean > context. If it were a boolean context, he would be using bools in the > first place. Of course he is -- he's branching on an int (a boolean context), and explicitly writing out the test as myInt <> 0. In fact, that test could just as easily be written as bool(myInt), which has the benefit of being even more explicit that you want a bool. It's also silly. Explicitness is not always a virtue. Beginners sometimes write things like: s = "hello " t = "world" print str(s + t) and we rightly shake our heads at the sheer n00b-ness of it. Writing the explicit tests: if bool(myInt): or even: if myInt <> 0: are firmly in the same category. The only difference is that it is more familiar and therefore comfortable to those who are used to languages that don't have Python's truth-testing rules. > What he is objecting to is the practice of testing for > special cases of ints (i.e. 0) by treating them as bools. The specific > details of converting ints to bools are very much relevant here; as long > as 0 is false, it works. If -1 is false (a semantic I have actually > seen used), then it does not. You've seen -1 being used as false? Where? Are you still talking about Python builtins or language semantics? If you're about to say string.find(substring), no, absolutely not. find does not return a true/false flag, it returns an index, with -1 the sentinel for Not Found. This is not a flag! In fact, one of the motivations for adding bools to Python was to avoid people mistakenly thinking that cmp(a, b) returned a flag 0, 1 when it actually returns a three-state -1, 0, 1. This was a common source of errors before Python got bools. -- Steven From ckaynor at zindagigames.com Mon Jul 12 23:16:47 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Mon, 12 Jul 2010 20:16:47 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xy6dg1629.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <7xy6dg1629.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Jul 12, 2010 at 7:14 PM, Paul Rubin wrote: > Ian Kelly writes: > > I don't think it's any more egregious than automatic conversions of > > mixed-type expressions, such as 3 + 4.5. > > That could also be explicit: float(3) + 4.5, or 3 + int(4.5). > > > If you don't want your ints automatically converted to floats on > > division, then use the integer division operator. 1 // 2 is still 0 > > in Python 3. > > Sure, I do that, but the issue was that 1/2 was confusing newbies who > don't understand the different characteristics of int and floating > types. If the idea is to change Python to fix this problem in a > newbie-friendly way, the right fix is to create enlightment by raising > an exception that points out the problem, not sweep it under the rug > with an automatic conversion. > Behind this automatic conversion is the concept that there is really one type: Number. The fact that the language has both int and float is merely as there is no good, solid way of storing the Number type, and thus we have float, Decimal, Rational, and probably other less common types. Calculating 1/2 does not give you 0, 1/10 won't give you 0.100000001 (or whatever the number stored in float is). The fact that integers and real numbers are separate in the language is an optimization and intended to improve functionality while providing a simple default (you can choose to use Decimal instead of float if you know you will be dealing with decimal numbers). Chris > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Mon Jul 12 23:22:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 20:22:39 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <7xy6dg83r4.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Writing the explicit tests: > if bool(myInt): > or even: > if myInt <> 0: > > are firmly in the same category. The only difference is that it is more > familiar and therefore comfortable to those who are used to languages > that don't have Python's truth-testing rules. It's like list.append returning None. It helps catch errors. From clp2 at rebertia.com Mon Jul 12 23:50:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 20:50:10 -0700 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On Mon, Jul 12, 2010 at 6:29 PM, Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm "callable" seems vague. Is a command string with invalid arguments but a valid executable "callable"? If no, then there's no general way to test "callability" without actually running the command. > actually doing this: > > ? ?def is_valid_command(command): > ? ? ? ?retcode = 100 # initialize > ? ? ? ?if command: > ? ? ? ? ? ?retcode = subprocess.call(command, shell=True) > ? ? ? ?if retcode is 0: That should be `== 0`, not `is 0`. The fact that `is 0` just so happens to work is an implementation detail. > ? ? ? ? ? ?print "Valid command." > ? ? ? ?else: > ? ? ? ? ? ?print "Looks not so good..." > > ? ?is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. Well, you're not gonna be able to get the command's return code without actually running it (unless perhaps you're referring to a return code from the shell itself?). > What are better ways of doing this? One idea: from shlex import split as shell_tokenize from subprocess import check_output def is_valid_command(command): try: executable = shell_tokenize(command)[0] except (ValueError, IndexError):# invalid shell syntax return False return bool(check_output(['which', executable]))# on the PATH? Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:51:06 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:51:06 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 17:36:38 -0700, Paul Rubin wrote: >> I would argue against that. Why do you, the coder, care about the >> specific details of treating ints in a boolean context? The int type >> itself knows, leave the decision to it. > > There is a horrible (IMO) thing that Perl, Lua, and Javascript all do, > which is automatically convert strings to numbers, so "12"+3 = 15. > Python has the good sense to throw a type error if you attempt such an > addition, but it goes and converts various types to bool automatically, No, what Python does is more subtle than that. An example using strings will (I hope!) make it clear. Or possibly muddy the waters even more. Compare converting strings to ints: the string "1" maps to the int 1, "2" to 2, and so forth. There's a one-to-one map of string to int (modulo unicode and whitespace issues), and since this is more or less a universal standard, it's enshrined in the language. Now consider converting strings to bools. Should "true" map to True? Or "yes", "ja", "vrai", "waar", or something else? That's an application- specific question, not a universal standard (not even a de facto standard), and Python rightly avoids it. What about "maybe" or "strawberry jam"? You can't convert "strawberry jam" into True or False any more than you can convert it into an int. What Python does instead is to accept *any* object in a context where other languages (such as Pascal) would insist on a boolean. In practice, that means branches (if) as well as the short-cut operators and, or, not. The semantics of this is well-defined, and I trust I don't need to go over it again. In an expression like: x and y unlike Pascal, there is no requirement that x and y be booleans. This is why I talk about x and y being used "in a boolean context", rather than converting it to a bool. [3,4,5] is not, by any stretch of the imagination, True converted into a list, and likewise [2,3,4] is a list and can't be converted to a flag any more than it can be converted to an int. But what I do say is that, according to Python's semantics, the list [3,4,5] is equivalent to True in a boolean context. Where Python muddies the water is to provide a bool() built-in which *does* convert any object to canonical boolean form. bool([2,3,4]) returns True, which contradicts what I said above about not converting the list into a flag. I accept this -- it's a triumph of practicality over purity. It would be silly to force people to write: # get the canonical form if any_old_object: flag = True else: flag = False when we can say flag = bool(any_old_object). One last thing -- we can see that Python does *not* convert objects to bools "in a boolean context". The Python virtual machine really does accept any object as an argument to and/or/not operators, as well as if: >>> import dis >>> dis.dis(compile('a or b', '', 'single')) 1 0 LOAD_NAME 0 (a) 3 JUMP_IF_TRUE 4 (to 10) 6 POP_TOP 7 LOAD_NAME 1 (b) >> 10 PRINT_EXPR 11 LOAD_CONST 0 (None) 14 RETURN_VALUE The JUMP_IF_TRUE opcode accepts any object, not just True or False. -- Steven From ian.g.kelly at gmail.com Mon Jul 12 23:54:14 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 12 Jul 2010 21:54:14 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 12, 2010 at 9:16 PM, Steven D'Aprano wrote: > You've seen -1 being used as false? Where? Are you still talking about > Python builtins or language semantics? Some of our database tables at work use 1 for true, -1 for false, and 0 for neither. Don't look at me, I didn't design it. Why they didn't just make the column nullable is beyond me, but that's the way it is. From steve-REMOVE-THIS at cybersource.com.au Mon Jul 12 23:55:43 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 03:55:43 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> <7xy6dg83r4.fsf@ruckus.brouhaha.com> Message-ID: <4c3be3bf$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:22:39 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Writing the explicit tests: >> if bool(myInt): >> or even: >> if myInt <> 0: >> >> are firmly in the same category. The only difference is that it is more >> familiar and therefore comfortable to those who are used to languages >> that don't have Python's truth-testing rules. > > It's like list.append returning None. It helps catch errors. How? >>> myInt = 'x' >>> if myInt <> 0: ... print "myInt is not zero, safe to divide" ... print 42/myInt ... myInt is not zero, safe to divide Traceback (most recent call last): File "", line 3, in TypeError: unsupported operand type(s) for /: 'int' and 'str' What error did this catch? -- Steven From no.email at nospam.invalid Mon Jul 12 23:58:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Jul 2010 20:58:39 -0700 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> Message-ID: <7x39voc9sg.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > What Python does instead is to accept *any* object in a context where > other languages (such as Pascal) would insist on a boolean. I'm aware of what Python does, just saying I can sympathize with the sentiment that explicit conversions would make more sense. I wouldn't change it in Python since it's what we're all used to, but if I were designing a language from scratch I'd probably make it explicit. From clp2 at rebertia.com Tue Jul 13 00:04:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 12 Jul 2010 21:04:42 -0700 Subject: Python 3 grammar, function parameters In-Reply-To: <4C3B97FB.5010409@junkwallah.org> References: <4C3B97FB.5010409@junkwallah.org> Message-ID: On Mon, Jul 12, 2010 at 3:32 PM, Junkman wrote: > Greetings to Python users, > > I'm trying to parse Python code using the grammar supplied with the > documentation set, and have a question on the grammar for function > parameters: > > funcdef: 'def' NAME parameters ['->' test] ':' suite > parameters: '(' [typedargslist] ')' > typedargslist: ((tfpdef ['=' test] ',')* > ? ? ? ? ? ? ? ?('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] > | '**' tfpdef) > ? ? ? ? ? ? ? ?| tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) > tfpdef: NAME [':' test] > > >From what I understand, a naked asterisk - i.e. it is not a prefix to an > identifier - is not a valid parameter, but the grammar ?explicitly > allows it by making the ?identifier that immediately follows the > asterisk optional. > > Are there cases where naked asterisk is allowed as a function > parameter? Yes, for keyword-only arguments, a new feature in Python 3.x. See PEP 3102 (http://www.python.org/dev/peps/pep-3102/ ). A lone asterisk signals that the function does not take extra positional arguments. All keyword-only arguments must be declared after a lone or normal *-argument. Example: def compare(a, b, *, key=None): compare() does not accept extra positional arguments and has 1 keyword-only argument (namely, `key`). Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Tue Jul 13 00:47:16 2010 From: cmpython at gmail.com (CM) Date: Mon, 12 Jul 2010 21:47:16 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> <4c3b4dda$0$1620$742ec2ed@news.sonic.net> Message-ID: <67f1310d-493a-49b4-9d97-76bf58e223c3@e5g2000yqn.googlegroups.com> > > ? ? ?Yesterday, I was running a CNC plasma cutter that's controlled > > by Windows XP. ?This is a machine that moves around a plasma torch that > > cuts thick steel plate. ?A "New Java update is available" window > > popped up while I was working. ?Not good. > > Hi, it looks like you're attempting to cut something > with a plasma torch. ?Would you like help? > > (_) inserting a steel plate to cut > > (_) severing the tip of your finger > > [ ] Don't show me this tip again. > > -tkc Brilliant. (I almost think you should have gone with far more than severing the tip of the finger, but then you'd lose that killer play on words at the end). From mahyd2011 at gmail.com Tue Jul 13 00:51:34 2010 From: mahyd2011 at gmail.com (mbbabu) Date: Mon, 12 Jul 2010 21:51:34 -0700 (PDT) Subject: See Hot Sexy Star Angelina Jolie Nude Bathing Videos In All Angles. Message-ID: See Hot Sexy Star Angelina Jolie Nude Bathing Videos In All Angles. At http://easypaypalmoney.tk Due to high sex content, i have hidden the videos in an image. I Link in that website On search box Top Side, click on image and watch videos in all angles. please don,t tell to anyone. From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 00:52:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 13 Jul 2010 04:52:58 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> <4c3be2a9$0$11092$c3e8da3@news.astraweb.com> <7x39voc9sg.fsf@ruckus.brouhaha.com> Message-ID: <4c3bf12a$0$11092$c3e8da3@news.astraweb.com> On Mon, 12 Jul 2010 20:58:39 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> What Python does instead is to accept *any* object in a context where >> other languages (such as Pascal) would insist on a boolean. > > I'm aware of what Python does, just saying I can sympathize with the > sentiment that explicit conversions would make more sense. I wouldn't > change it in Python since it's what we're all used to, but if I were > designing a language from scratch I'd probably make it explicit. Fair enough, and that's a reasonable design choice too. Ruby, for example, only has two false values: False and Null. -- Steven From torriem at gmail.com Tue Jul 13 01:28:26 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Jul 2010 23:28:26 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> Message-ID: <4C3BF97A.3080207@gmail.com> On 07/12/2010 06:18 PM, Steven D'Aprano wrote: > Early versions of BASIC used -1 as true and 0 as false. They did this for good reason. BASIC had no logical operators. AND, OR, and NOT were all actually bitwise operators. By making the True value -1, the bitwise operations yielded the result one would expect from logical operations. From kkaruppuraja at gmail.com Tue Jul 13 01:29:36 2010 From: kkaruppuraja at gmail.com (sivaji) Date: Mon, 12 Jul 2010 22:29:36 -0700 (PDT) Subject: if you choose this bag you will ged a loptop Message-ID: <5d440858-0bf5-4884-b9d0-65bb83db65a4@s17g2000prh.googlegroups.com> http;//www.123maza.com/elaxa/domain-hosting From torriem at gmail.com Tue Jul 13 01:31:45 2010 From: torriem at gmail.com (Michael Torrie) Date: Mon, 12 Jul 2010 23:31:45 -0600 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <7xeif8fca1.fsf@ruckus.brouhaha.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <7xeif8fca1.fsf@ruckus.brouhaha.com> Message-ID: <4C3BFA41.5060109@gmail.com> On 07/12/2010 06:36 PM, Paul Rubin wrote: > I'd personally prefer > > if not bool(myValue): > > which would call the myValue's __bool__ method if it chose to implement > one. Explicit is better than implicit. That's just ugly. Probably a more explicit way would be to have an is_true() and is_false() function/method. if is_false(my_value). But that's ugly too, especially when the idea of emptiness or falseness is so consistently defined across python types. I have yet to encounter any situation where I got tripped up on such a small thing as the OP. From DierkErdmann at mail.com Tue Jul 13 01:50:43 2010 From: DierkErdmann at mail.com (DierkErdmann at mail.com) Date: Mon, 12 Jul 2010 22:50:43 -0700 (PDT) Subject: Debugging a segmentation fault References: <7e13ce17-77ae-4a59-b0fd-7e5b227f06aa@u26g2000yqu.googlegroups.com> Message-ID: <8aeab75c-19c3-4721-a2f1-a5304d85c23f@j4g2000yqh.googlegroups.com> On 8 Jul., 19:32, Christian Heimes wrote: > Which third party products with C extensions do you use? Have you > updated your database adapter and NumPy yet? I'm using sqlalchemy, scipy and numpy. I will try to update these and see if that helps. Dierk From hujia06 at gmail.com Tue Jul 13 01:51:49 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 01:51:49 -0400 Subject: write a .txt file In-Reply-To: References: <4C3BC847.4040606@mrabarnett.plus.com> Message-ID: If I change "'echo "hello">> final.txt" to "ls -a >> final.txt" and add fileName.close() before subprocess. The result is still like: 12 25 9 85 25 12 .... # list of files ..... How can I put the list before the number list 85 25 12? Thank you. On Tue, Jul 13, 2010 at 12:47 AM, Jia Hu wrote: > Thank you. I will try that. > > The code was simplified to show my problem. I do not use fileName as > a variable in my code. Thanks for your reminding. > > On Mon, Jul 12, 2010 at 9:58 PM, MRAB wrote: > >> Jia Hu wrote: >> >>> Hello: >>> I have a problem about how to generate a specific.txt file. I use the >>> following code: >>> #!/usr/bin/python >>> # OS: Ubuntu >>> import subprocess >>> fileName = open ('final.txt', 'a') >>> fileName.write ('%s %s %s \n' % (12,25,9)) >>> desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) >>> >>> fileName.seek(0,2) >>> fileName.write ('%s %s %s \n' % (85,25,12)) >>> fileName.close() >>> The above code generates the following result: >>> 12 25 9 >>> 85 25 12 >>> hello >>> What I want is: >>> 12 25 9 >>> hello >>> 85 25 12 >>> Could someone provies some suggestions about this problem? >>> Thank you. >>> >>> When "echo" is called the file is still open, so the might not be able >> to write to it. Try closing the file before starting the subprocess and >> then reopen it afterwards. >> >> By the way, it slightly confusing that you call the variable "fileName", >> but it doesn't contain the name of a file! :-) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Jul 13 02:15:27 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 12 Jul 2010 23:15:27 -0700 Subject: Errno 9] Bad file descriptor References: Message-ID: <3v0o369u3toutqpt1e3j0klq2jvs3kfna1@4ax.com> joblack wrote: > >I get sometimes a > >Errno 9 Bad file descriptor > >the code is too long to show it here but what are the circumstances >this could happen? A web search showed nothing. > >I have especially the feeling Python 2.6 has some problems with >Unicode ... and might not find the file. Is that possible? You seem to be under the mistaken impression that we all have crystal balls and are able to read your mind. There is SO MUCH you haven't told us here. Which platform? Surely you can post SOME of the code around where the error occurs. For example, there is a bug in the Windows shell that will cause this error if you try to read stdin when a Python script is called implicitly from a command line: C:\tmp>type y.py import sys print sys.stdin.readlines() C:\tmp>y.py < y.py Traceback (most recent call last): File "C:\tmp\y.py", line 3, in print sys.stdin.readlines() IOError: [Errno 9] Bad file descriptor C:\tmp>python y.py < y.py ['import sys\n', '\n', 'print sys.stdin.readlines()\n'] C:\tmp> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cs at zip.com.au Tue Jul 13 02:16:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 16:16:29 +1000 Subject: write a .txt file In-Reply-To: References: Message-ID: <20100713061629.GA14142@cskk.homeip.net> On 12Jul2010 21:28, Jia Hu wrote: | I have a problem about how to generate a specific.txt file. I use the | following code: | | #!/usr/bin/python | # OS: Ubuntu | import subprocess | fileName = open ('final.txt', 'a') | fileName.write ('%s %s %s \n' % (12,25,9)) String still in Python's buffer, not yet in the file. Add: fileName.flush() to ensure data in file before running echo. | desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) Command dispatched, but not yet waited for. So your Python program proceeds and writes to the file _before_ the echo command gets to run. Wait for desLrr to complete before proceeding. | fileName.seek(0,2) | fileName.write ('%s %s %s \n' % (85,25,12)) | fileName.close() And the rest is ok. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ We tend to overestimate the short-term impact of technological change and underestimate its long-term impact. - Amara's Law From timr at probo.com Tue Jul 13 02:18:48 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 12 Jul 2010 23:18:48 -0700 Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: Kenny Meyer wrote: > >I have to figure out if a string is callable on a Linux system. I'm >actually doing this: >... >Never mind the code, because this is not the original. >The side effect of subprocess.call() is that it *actually* executes >it, but I just need the return code. What are better ways of doing >this? You can do what the "which" command does: split the PATH environment variable into individual components, and see if the string maps to a file in any directory in your PATH with the "execute" bit set. That won't catch shell macros, however. You might be able to use "type" to do that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From chenlily84 at hotmail.com Tue Jul 13 02:30:42 2010 From: chenlily84 at hotmail.com (cntrade08) Date: Mon, 12 Jul 2010 23:30:42 -0700 (PDT) Subject: Discount Wholesale Kanji Jeans, ED Hardy Jeans (http://www.cntrade09.com/) Message-ID: <59f06967-a15a-400c-983e-3f52052ef9e4@z34g2000pro.googlegroups.com> Discount Wholesale Affliction Jeans Discount Wholesale AK Jeans (http://www.cntrade09.com/) Discount Wholesale Armani Jeans Discount Wholesale Artful Dodger Jeans Discount Wholesale BAPE Jeans Discount Wholesale BBC Jeans (http://www.cntrade09.com/) Discount Wholesale Black Label Jeans Discount Wholesale Cavalli Jeans Discount Wholesale Christian Audigier Jeans Discount Wholesale Coogi Jeans Discount Wholesale Crown Holder Jeans (http://www.cntrade09.com/) Discount Wholesale D&G Jeans Discount Wholesale Diesel Jeans Discount Wholesale ECKO Jeans (http://www.cntrade09.com/) Discount Wholesale ED Hardy Jeans Discount Wholesale Evisu Jeans Discount Wholesale G-STAR Jeans Discount Wholesale GUCCI Jeans Discount Wholesale Iceberg Jeans Discount Wholesale Kanji Jeans (http://www.cntrade09.com/) Discount Wholesale Laguna Beach Jeans Discount Wholesale Levi s Jeans Discount Wholesale LRG Jeans Discount Wholesale LV Jeans Discount Wholesale Prada Jeans (http://www.cntrade09.com/) Discount Wholesale RMC Jeans Discount Wholesale Roca Wear Jeans Discount Wholesale Rock&Republic Jeans Discount Wholesale True Religion Jeans Discount Wholesale Versace Jeans Discount Wholesale ZEN Jeans (http://www.cntrade09.com/) From stefan_ml at behnel.de Tue Jul 13 02:37:12 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 13 Jul 2010 08:37:12 +0200 Subject: Lua is faster than Fortran??? In-Reply-To: References: Message-ID: sturlamolden, 04.07.2010 05:30: > I was just looking at Debian's benchmarks. It seems LuaJIT is now (on > median) beating Intel Fortran! > > C (gcc) is running the benchmarks faster by less than a factor of two. > Consider that Lua is a dynamically typed scripting language very > similar to Python. > > LuaJIT also runs the benchmarks faster than Java 6 server, OCaml, and > SBCL. > > I know it's "just a benchmark" but this has to count as insanely > impressive. Beating Intel Fortran with a dynamic scripting language, > how is that even possible? And what about all those arguments that > dynamic languages "have to be slow"? > > If this keeps up we'll need a Python to Lua bytecode compiler very > soon. And LuaJIT 2 is rumoured to be much faster than the current... In case anyone's interested, I uploaded a wrapper for LuaJIT2 to PyPI: http://pypi.python.org/pypi/lupa It's written in Cython and heavily borrows from the existing Lua wrapper LunaticPython, with a couple of enhancements and a couple of yet missing features. Stefan From hujia06 at gmail.com Tue Jul 13 02:46:14 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 02:46:14 -0400 Subject: write a .txt file In-Reply-To: References: <20100713061629.GA14142@cskk.homeip.net> Message-ID: Hi: Do you mean the following code? #!/usr/bin/python # OS: Ubuntu import subprocess fileName = open ('final.txt', 'a') fileName.write ('%s %s %s \n' % (12,25,9)) fileName.flush() # add fileName.close() # add desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to "ls -a" fileName=open ('final.txt', 'a') fileName.seek(0,2) fileName.write ('%s %s %s \n' % (85,25,12)) fileName.close() I run that, the result showed the list of file is located after the number list 85 25 12 Is that possible that I put the fileName.flush() in a wrong position ? I am new to Python and do not quite understand the "flush" concept. Thank you. Jia > On Tue, Jul 13, 2010 at 2:16 AM, Cameron Simpson wrote: > >> On 12Jul2010 21:28, Jia Hu wrote: >> | I have a problem about how to generate a specific.txt file. I use the >> | following code: >> | >> | #!/usr/bin/python >> | # OS: Ubuntu >> | import subprocess >> | fileName = open ('final.txt', 'a') >> | fileName.write ('%s %s %s \n' % (12,25,9)) >> >> String still in Python's buffer, not yet in the file. Add: >> >> fileName.flush() >> >> to ensure data in file before running echo. >> >> | desLrr = subprocess.Popen('echo "hello" >> final.txt ', shell=True) >> >> Command dispatched, but not yet waited for. So your Python program >> proceeds >> and writes to the file _before_ the echo command gets to run. >> >> Wait for desLrr to complete before proceeding. >> >> | fileName.seek(0,2) >> | fileName.write ('%s %s %s \n' % (85,25,12)) >> | fileName.close() >> >> And the rest is ok. >> >> Cheers, >> -- >> Cameron Simpson DoD#743 >> http://www.cskk.ezoshosting.com/cs/ >> >> We tend to overestimate the short-term impact of technological change and >> underestimate its long-term impact. - Amara's Law >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Jul 13 02:59:41 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 16:59:41 +1000 Subject: Errno 9] Bad file descriptor In-Reply-To: References: Message-ID: <20100713065941.GA20959@cskk.homeip.net> On 11Jul2010 17:48, joblack wrote: | I get sometimes a | | Errno 9 Bad file descriptor | | the code is too long to show it here but what are the circumstances | this could happen? A web search showed nothing. | | I have especially the feeling Python 2.6 has some problems with | Unicode ... and might not find the file. Is that possible? You get a UNIX "bad file descriptor" error when you try to use an invalid file descriptor number. The typical occasion is when you open a file, use it, close it, and then try to continue to use it. I would suspect you have performed that sequence in some way. But you should really try to produce a small sequence of code that shows the error. That way you can post it here, and for extra value you may reduce it to the point where you realise what you have done wrong, since the failing code is then small enough for you to examine easily. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There is a chasm of carbon and silicon the software can't bridge - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html From cs at zip.com.au Tue Jul 13 03:17:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 13 Jul 2010 17:17:06 +1000 Subject: write a .txt file In-Reply-To: References: Message-ID: <20100713071705.GA22054@cskk.homeip.net> On 13Jul2010 02:46, Jia Hu wrote: | Hi: | | Do you mean the following code? | | #!/usr/bin/python | # OS: Ubuntu | import subprocess | fileName = open ('final.txt', 'a') | fileName.write ('%s %s %s \n' % (12,25,9)) | | fileName.flush() # add | fileName.close() # add You should not need the .close(). | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to "ls | -a" You're still not waiting for the Popen subprocess to finish before continuing. | fileName=open ('final.txt', 'a') You shouldn't need the open() if you skip the .close() | fileName.seek(0,2) If you _do_ do an open(..., "a") then you don't need the seek - append mode will write at the end for you. | fileName.write ('%s %s %s \n' % (85,25,12)) | fileName.close() | | I run that, the result showed the list of file is located after the number | list 85 25 12 | Is that possible that I put the fileName.flush() in a wrong position ? | I am new to Python and do not quite understand the "flush" concept. First: please don't top post. Post below the relevant points as I do above, like a conversation. That way it is clear exactly what each remark is for. Second: "flush" is a general idea used with buffers. When you .write() to a file the data does not normally go directly to disc. This is because a real write to the disc is expensive in time (the CPU is much much faster than a hard drive). Also, a OS-level "write", which transfers the data from your program into the OS's buffers (where it queues, for eventual writing to the disc) is _also_ a comparitively expensive operation. So when you .write() in python (or C using stdio, and in many other languages) the data is normally kept in a memory buffer inside your program. Only when that buffer is filled is an OS-level "write" done. In this way, OS calls are few. This is a performance gain. So, in your program, when you .write() your first line of numbers the data has not been handed to the OS at all, and therefore the "final.txt" file has not seen it. A .flush() call is an explicit request to empty the buffer, making an OS-level "write" immediately. In your program, this is necessary to get the data to "final.txt" before the "echo" or "ls" commands are run. If you .close() a file, that also empties the buffer. But it also closes the file! SO you need to re-open it. For your purposes, a .flush() is enough and leaves the file open for you to continue using it later. Regarding the .seek(): after the "echo" or "ls" command has run the file has grown. Python's "file" object does not know the file has grown because it was not involved. So a .seek(0 is needed to position Python's .write() location to the end of the file instead of where it though things were. Um. Because you have opened the file in 'a' mode you should not need the .seek() - an "append" mode file will always write to the end of the file. So: your first problem only requires a .flush(), to empty the buffer before "echo" or "ls" runs. However, you still have not waited for the "echo" or "ls" to finish - Popen kicks the command off, but it will run at the same time as your program! Call: desLrr.wait() to wait for the "echo" or "ls" to finish before continuing! Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Quick Guide to Resources to break crypto systems of given strength: Difficulty Resources required 2**0 Pencil and paper 2**8 Pencil and paper and a lot of patience 2**16 Warez d00d with a Commodore 64 2**32 Amateur with an average PC 2**40 Smart amateur with a good PC 2**56 Network of workstations, custom-built hardware 2**64 Thousands of PCs working together for several years 2**80 NSA, Microsoft, the Illuminati 2**128 Cubic kilometers of sci-fi nanotech 2**160 Dyson spheres Eddy L O Jansson and Matthew Skala, from: http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html From j.kleese at arcor.de Tue Jul 13 03:28:01 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Tue, 13 Jul 2010 09:28:01 +0200 Subject: Worship We Must In-Reply-To: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> Message-ID: <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> On 13.07.2010 05:16, nais-saudi wrote: > The submission of man to His Creator is the essence of Islam. The submission of topic-related Bla to His Newsgroup is the essence of Posting. Learn it. Know it. Live it. From alf.p.steinbach+usenet at gmail.com Tue Jul 13 03:34:08 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 09:34:08 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: * geremy condra, on 09.07.2010 23:43: > On Fri, Jul 9, 2010 at 5:22 PM, Ian Collins wrote: >> On 07/10/10 03:52 AM, Alf P. Steinbach /Usenet wrote: >>> >>> [Cross-posted comp.lang.python and comp.lang.c++] >>> >>> I lack experience with shared libraries in *nix and so I need to ask... >>> >>> This is about "cppy", some support for writing Python extensions in C++ >>> that I just started on (some days ago almost known as "pynis" (not funny >>> after all)). >>> >>> For an extension module it seems that Python requires each routine to be >>> defined as 'extern "C"'. And although e.g. MSVC is happy to mix 'extern >>> "C"' and C++ linkage, using a routine declared as 'static' in a class as >>> a C callback, formally they're two different kinds, and I seem to recall >>> that /some/ C++ compiler balks at that kind of mixing unless specially >>> instructed to allow it. Perhaps it was the Sun compiler? >> >> Yes, it will (correctly) issue a warning. >> >> As the is a bit OT, contact me directly and we can work through it. I have >> had similar fun and games adding PHP modules! > > I'd appreciate it if you'd either leave this on-list or cc me in on this, as > I'm working through a similar issue. Well, we got no further, but I know of three solutions: A) Punting: just say that the compiler has to support C++/C function type mingling. -> Perhaps the practical solution, but formally unsafe. B) On the script side of things, delegate all calls to single Mother Of All C func downcaller that supplies as extra arg an id of the C++ function. -> Micro-level inefficient but easy to use and formally correct. C) Let the user define the C linkage function wrappers via macros. -> Efficient and formally correct but exposes ugly macro names. I chose (C). I believe Boost's Python binding uses (A), or perhaps (B). Cheers, - Alf PS: You (the reader) may be wondering, why why why Yet Another Python/C++ binding? Well, because I had this great name for it, "pyni", unfortunately already in use. But cppy is very different from Boost: Boost is large, cppy is tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating argument conversion etc., while with cppy your Python design is exposed to C++ with no enforced arg conversions and such; Boost relies on canned magic, difficult to subvert when it doesn't do what you want, while with cppy you are (or, so far, I am) in control; and I suspect that the Boost Python binding, relying on dynamic registries and stuff, is not all that efficient, while cppy is as efficient as using the Python C API to create an extension. And besides, cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) -- blog at From debatem1 at gmail.com Tue Jul 13 04:00:38 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 01:00:38 -0700 Subject: Worship We Must In-Reply-To: <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: > On 13.07.2010 05:16, nais-saudi wrote: >> The submission of man to His Creator is the essence of Islam. > > The submission of topic-related Bla to His Newsgroup is the essence of > Posting. > > Learn it. Know it. Live it. The submission of replies to trolls and spammers is the essence of the internet. Live long. And Prosper. Geremy Condra From pdwjfndjbdgfyg at gmail.com Tue Jul 13 04:08:29 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Tue, 13 Jul 2010 01:08:29 -0700 (PDT) Subject: SEXY VIDEOS Message-ID: HOT SEXY VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-sexy-videos.html HOT KISS VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-kiss-videos.html HOT ROMANTIC VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-romantic-videos.html HOT LIP KISS BEST VIDEOS http://hotvideosonlyforyouth.blogspot.com/2010/07/hot-lip-kiss-best-videos.html jobs java jobs http://allfreshersjobsseehere.blogspot.com/2009/02/java-jobs.html oracle jobs http://allfreshersjobsseehere.blogspot.com/2009/02/oracle-jobs.html work from home http://allfreshersjobsseehere.blogspot.com/2009/02/work-from-home.html make money from online http://allfreshersjobsseehere.blogspot.com/2009/02/make-money-from-online.html online work http://allfreshersjobsseehere.blogspot.com/2009/02/online-work.html From j.kleese at arcor.de Tue Jul 13 04:17:26 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Tue, 13 Jul 2010 10:17:26 +0200 Subject: Worship We Must In-Reply-To: References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> On 13.07.2010 10:00, geremy condra wrote: > On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: >> On 13.07.2010 05:16, nais-saudi wrote: >>> The submission of man to His Creator is the essence of Islam. >> >> The submission of topic-related Bla to His Newsgroup is the essence of >> Posting. >> >> Learn it. Know it. Live it. > > The submission of replies to trolls and spammers is the essence of the internet. > > Live long. And Prosper. The submission of troll feed to the Internet is the essence of Bla. Now do the truffle shuffle! From debatem1 at gmail.com Tue Jul 13 04:32:42 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 01:32:42 -0700 Subject: Worship We Must In-Reply-To: <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, Jul 13, 2010 at 1:17 AM, Johannes Kleese wrote: > On 13.07.2010 10:00, geremy condra wrote: >> On Tue, Jul 13, 2010 at 12:28 AM, Johannes Kleese wrote: >>> On 13.07.2010 05:16, nais-saudi wrote: >>>> The submission of man to His Creator is the essence of Islam. >>> >>> The submission of topic-related Bla to His Newsgroup is the essence of >>> Posting. >>> >>> Learn it. Know it. Live it. >> >> The submission of replies to trolls and spammers is the essence of the internet. >> >> Live long. And Prosper. > > The submission of troll feed to the Internet is the essence of Bla. > > Now do the truffle shuffle! I'm sure you're aware that the shuffle of so-called 'conflict truffles' is highly illegal, not to mention unethical. I'm shocked you would advocate it publicly. Geremy Condra From gdamjan at gmail.com Tue Jul 13 05:21:06 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Tue, 13 Jul 2010 11:21:06 +0200 Subject: simples setup for an wsgi https server in python References: Message-ID: <2pntg7-ve7.ln1@archaeopteryx.softver.org.mk> > It seems, that wsgiref.simple_server.make_server can only create an > http server. > > What I wondered would be how to easiest create an https server, that > supports wsgi modules PythonPaste has a WSGI server that supports https http://pythonpaste.org/modules/httpserver.html#module-paste.httpserver Werkzeug too http://werkzeug.pocoo.org/documentation/0.6.2/serving.html#ssl I'd strongly suggest you to have both of those libraries installed, they have a lot of WSGI goodies :) -- ?????? ((( http://damjan.softver.org.mk/ ))) Scarlett Johansson: You always see the glass half-empty. Woody Allen: No. I see the glass half-full... but of poison. From greg.ewing at canterbury.ac.nz Tue Jul 13 07:22:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 13 Jul 2010 23:22:42 +1200 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <4c3b7102$0$1587$742ec2ed@news.sonic.net> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> <4c3b7102$0$1587$742ec2ed@news.sonic.net> Message-ID: <8a302tF2qdU1@mid.individual.net> John Nagle wrote: > Arguably, if a function just does a "return", > it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exception if you try to do anything with it except throw it away. Unfortunately, the existence of such a value would cause headaches for things like debuggers that need to be able to deal with anything at all without blowing up. -- Greg From jeanmichel at sequans.com Tue Jul 13 07:24:11 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Jul 2010 13:24:11 +0200 Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! In-Reply-To: <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <4C3C4CDB.40904@sequans.com> Steven D'Aprano wrote: > On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote: > > >> On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano >> wrote: >> >>>> I prefere to explicitly write what I want to test: >>>> >>>> if myInt <> 0: >>>> >>> I would argue against that. Why do you, the coder, care about the >>> specific details of treating ints in a boolean context? The int type >>> itself knows, leave the decision to it. >>> >> I think you're missing the point. He's not using ints in a boolean >> context. If it were a boolean context, he would be using bools in the >> first place. >> > > Of course he is -- he's branching on an int (a boolean context), and > explicitly writing out the test as myInt <> 0. In fact, that test could > just as easily be written as bool(myInt), which has the benefit of being > even more explicit that you want a bool. I never use integers as boolean value. There is no need to in python, since True and False are available. I use integers only as integers (hope you see what i mean, i.e to count a number of...). Knowing that, the only meaning possible would be if myInt: equals to if myInt is not None: in other words, if myInt is a meaningful integer. But this is wrong in python, as "if myInt" means "if myInt <>None and myInt <>0" (I experienced bug because of my wrong understanding). Fine I can live with that. It forces me to write explicitly the condition I require, which is a good thing (explicit >> implicit). JM PS : you made a typo, myInt <> 0 does not equal to bool(myInt) (when myInt is None) From sathish at solitontech.com Tue Jul 13 07:25:33 2010 From: sathish at solitontech.com (Sathish S) Date: Tue, 13 Jul 2010 16:55:33 +0530 Subject: Calling LabVIEW VI from Python Message-ID: Hi ppl, I'm trying to call the LabVIEW VI's from python. I'm trying to use the Call method exposed in the LabVIEW activex. this method expects the input values to be passed as an array of reference. I'm passing a list to it, and I find that the list is unchanged. Here is my code: import win32com.client from win32com.client import gencache gencache.EnsureModule('{8C8AAA4D-51FE-41DE-85CF-8E6929409012}', 0, 5, 5) Application = win32com.client.Dispatch("LabVIEW.Application") InputNames = ("Cluster","Array","Numeric","Output") Cluster=("abcd","1") Array=("1","2.97") Output=() Inputs= (Cluster,Array,"5",Output) Application._FlagAsMethod("GetVIReference") VirtualInstrument = Application.GetVIReference('C:\Test.vi'); VirtualInstrument._FlagAsMethod("OpenFrontPanel") VirtualInstrument.OpenFrontPanel(True,3) VirtualInstrument._FlagAsMethod("Call") VirtualInstrument.Call(InputNames,Inputs) print(Output) print("Output") VirtualInstrument._FlagAsMethod("GetControlValue") print(VirtualInstrument.GetControlValue("Output")) Application._FlagAsMethod("Quit") Application.Quit(); Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 13 07:33:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Jul 2010 13:33:05 +0200 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <4C3C4EF1.3080609@sequans.com> Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? > I'm not sure I get exactly what you're searching for but here's something that may help. If you just whant to know if a command (without parameter) is a Linux command (either a builtin, alias of file exe) you can use the "where" command and inspect its return code, the command is not executed though. >where ls ls is an alias for ls --color=auto -F ls is /bin/ls >where apt-get apt-get is /usr/bin/apt-get >where doesnotexists doesnotexists not found zsh: exit 1 retcode = subprocess.call(command, shell=True) becomes retcode = subprocess.call("where " + command) JM NB : this does not work with parameters appened to the command. From luke.leighton at gmail.com Tue Jul 13 08:00:57 2010 From: luke.leighton at gmail.com (Luke Kenneth Casson Leighton) Date: Tue, 13 Jul 2010 12:00:57 +0000 Subject: multitask http server (single-process multi-connection HTTP server) In-Reply-To: <1278984638.9880.46.camel@tim-laptop> References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> <1278984638.9880.46.camel@tim-laptop> Message-ID: On Tue, Jul 13, 2010 at 1:30 AM, Tim Wintle wrote: > On Mon, 2010-07-12 at 23:28 +0000, Luke Kenneth Casson Leighton wrote: >> On Mon, Jul 12, 2010 at 10:13 PM, geremy condra wrote: >> > On Mon, Jul 12, 2010 at 4:59 PM, lkcl wrote: >> >> there probably exist perfectly good web frameworks that are capable of >> >> doing this sort of thing: i feel certain that twisted is one of them. >> >> however, the original author of rtmplite decided to rip twisted out >> >> and to use multitask.py and i'm one of those strange people that also >> >> likes the idea of using 900 lines of awesome elegant code rather than >> >> tens of thousands of constantly-moving-target. > > have you seen nagare: > http://www.nagare.org/ i have now! :) it uses stackless python, which is proobbably where the nonblocking aspects come from. going from there... http://stacklessexamples.googlecode.com/svn/trunk/examples/networking/basicWebserver.py ah ha! on the face of it, that does actually look like it achieves the same sort of thing. > I've not used it - but from my understanding it might be what you're > looking for (for the http part at least). yes, for the http part: the rest - mmm no. >> i hate to think how this would be done using any of the standard >> MixIns. ?even if you wrote a special MixIn which did single-instance >> socket handling, you couldn't use it because the BaseHTTPHandler >> doesn't "cooperate", it has a while True loop on serving connections >> until they're closed. > > I started working on something like this once (but I still had threads) > - afraid I can't find the code with it in right now. I think it was > similar to what you're doing: > > at least 2 threads - one accepts requests, the other deals with them. ok, that sounds like the problem has moved: requests could still be received rather than blocked at the TCP level, but they'd still not actually get processed if the 2nd "dealing with it" thread was in "serve_forever()" mode. and because of HTTP Keep-Alives, when close_connection=1 in the HTTPRequestHandler base class, that would still be an issue. looking at that stackless basic web server example, i believe that that's actually it: the concept of "tasklets", and that cooperative scheduling loop: while time.time() < t + delay: stackless.schedule() multitask.py effectively does the same thing, but using "yield", which is just amazing. but... not being funny or anything, but basically i'm done already :) multitaskhttpd works, it doesn't need stackless, i completed a JSONRPC service last night, i'll add POST of multi-part forms today, and i have everything that [GNUmed] will need. i think convincing the gnumed team to get all their users to install and use stackless python would be a bit of a hard sell. l. From __peter__ at web.de Tue Jul 13 08:02:38 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Jul 2010 14:02:38 +0200 Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: Joe Hughes wrote: > I'm doing some work with logging.config and I'm running into an > interesting situation. I've run this by python-help, but that didn't help > so I thought I would send to the list. Here is the config file > > [loggers] > keys=root,log,syslog > > [handlers] > keys=console,log,syslog > > [formatters] > keys=rootFormat,logFormat,syslogFormat > > [logger_root] > level=DEBUG > handlers=console > > [logger_log] > level=DEBUG > handlers=log > qualname=log > > [logger_syslog] > level=DEBUG > handlers=syslog > qualname=syslog > > [handler_console] > class=StreamHandler > level=DEBUG > formatter=rootFormat > args=(sys.stdout,) > > [handler_log] > class=handlers.RotatingFileHandler > level=DEBUG > formatter=logFormat > args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) > propagate=0 > > [handler_syslog] > class=handlers.SysLogHandler > level=DEBUG > formatter=syslogFormat > host=141.232.41.205 > port=handlers.SYSLOG_UDP_PORT > facility=LOG_LOCAL0 > args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) > > [formatter_rootFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > [formatter_logFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > [formatter_syslogFormat] > format=%(asctime)s - %(name)s - %(levelname)s - %(message)s > > and the python code > > ######################################################################## > # Imports > ######################################################################## > import logging > import logging.config > import os > import re > from threading import Thread > > ######################################################################## > # Constants > ######################################################################## > CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' > MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' > > ######################################################################## > # Classes > ######################################################################## > > ######## > # PingIt > ######## > class PingIt(Thread): > def __init__(self, mcuIP): > Thread.__init__(self) > self.ip = mcuIP > self.status = -1 > > def run(self): > pinging = os.popen("ping -n 2 " + self.ip, 'r') > > while 1: > line = pinging.readline() > > if not line: > break > > gotResponse = re.findall(PingIt.lifeline, line) > > if gotResponse: > self.status = int(gotResponse[0]) > > ######################################################################## > # Main Routine > ######################################################################## > # > # Get the logger configuration information > # > logging.config.fileConfig(CONFIG_FILENAME) > > # > # Check if running from command line and create logger > # > if os.environ.get('PROMPT'): > # > # create logger for output to stdout > # > logger = logging.getLogger('root') > else: > # > # create logger for output to logfile > # > logger = logging.getLogger('log') > > # > # Create logger for syslog output > # > syslog = logging.getLogger('syslog') > > # > # Declare variables > # > PingIt.lifeline = re.compile(r"Received = (\d)") > mcu_dict = {} > ping_list = [] > status = ("Not responding", "Responded to only 1 ping of 2", "Alive") > > # > # Open the MCU file > # > mcu_file = open(MCU_LIST_FILENAME, 'r') > > # > # Loop through the contents of the MCU file and ping the IPs > # > for mcu in mcu_file: > # > # mcu file contents example > # 192.168.97.227 MCU_HMSTD > # > # mcu_info[0] = MCU IP Address > # mcu_info[1] = MCU Name > # > mcu_info = mcu.split() > mcu_dict[mcu_info[0]] = mcu_info[1] > current = PingIt(mcu_info[0]) > logger.info("Pinging " + mcu_info[1]) > ping_list.append(current) > current.start() > > # > # Loop through ping list and print the response > # > for pinged in ping_list: > pinged.join() > logger.info("Status - " + mcu_dict[pinged.ip] + " is " + > status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + > " is " + status[pinged.status]) > > This is the output from the code > > 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding > msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is > Not responding > address = ('141.232.41.205', 514) > Traceback (most recent call last): > File "C:\Python31\lib\logging\handlers.py", line 786, in emit > self.socket.sendto(msg, self.address) > TypeError: sendto() takes exactly 3 arguments (2 given) > 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not > responding > > This is the handlers.py code from the library. I added the print > statement to figure out why it is asking for three args but only getting > two. > > Line 777 of handlers.py > > try: > if self.unixsocket: > try: > self.socket.send(msg) > except socket.error: > self._connect_unixsocket(self.address) > self.socket.send(msg) > else: > print('msg = ', msg, '\naddress = ', self.address) > self.socket.sendto(msg, self.address) > except (KeyboardInterrupt, SystemExit): > raise > except: > self.handleError(record) > > line 790 of handlers.py > > This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea > about why this happening I would appreciate knowing what the issue is. The error can be reproduced with Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> from logging.handlers import SysLogHandler >>> handler = SysLogHandler() >>> logger = logging.getLogger() >>> logger.addHandler(handler) >>> logger.critical("yadda") Traceback (most recent call last): File "/usr/lib/python3.1/logging/handlers.py", line 785, in emit self.socket.sendto(msg, self.address) TypeError: sendto() takes exactly 3 arguments (2 given) This is is a known bug, see http://bugs.python.org/issue7077 Peter From e_d_k at yahoo.com Tue Jul 13 08:03:00 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Tue, 13 Jul 2010 05:03:00 -0700 (PDT) Subject: Help choosing license for new projects In-Reply-To: Message-ID: <410241.60269.qm@web120511.mail.ne1.yahoo.com> --- On Mon, 7/12/10, Jake b wrote: > I'm starting a new python code > project. What license do you suggest? I > am searching, but I'm not finding a simple comparison of > licenses. So > I don't know which to use. Maybe MIT or Apache or LGPL or > BSD? > > Are there certain licenses to avoid using because of > interaction > problems between libraries using GPL2 / GPL3 / MIT / LGPL. > / BSD with > my own? I generally avoid GPL, one of the reasons in interaction with other licenses. > > I want: > 1] Pretty much let anyone use it. Users do not have to > include source > code, as long as I get credit. (which I think normallly is > a textfile > with project url + name?) This rules out GPL. > > 2] (if it matters) I will be using different combinations > of pyglet, > pygame, wxPython, etc. You will need to look at the individual licenses to see is they have iterations with other licenses. > > 3] I want the option to use my own code in something > commercial at a later date. > > Does #3 complicate things, or is fine when including author > info? You can always re-license i, as long as you have the copyright to all the code. If other people have made contributions you will need to get their permission before you can re-license. > > The choices for google code projects are: > ? Apache License 2.0 I do not use it, but it is good. > ? Eclipse license 1.0 I have not read this one, so I can not comment. > ? GPLv2 > ? GPLv3 Incomparable with point one. > ? GNU lesser GPL You would need to decide whether this is comparable with your first requirement. LGPL requires that users be able to relink with new versions of the library. This has always bothered me because relinking without recompiling (even when dynamic linking) in C/C++ is a good way to crash a program. But this should not be a problem with Python. > ? MIT license This one is good. > ? Mozilla Public license 1.1 I avoid this one. > ? New BSD License This one is good. I personalty like the Boost License, it has very few restrictions. I hope this helps, -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From johannes.black at gmail.com Tue Jul 13 08:56:51 2010 From: johannes.black at gmail.com (joblack) Date: Tue, 13 Jul 2010 05:56:51 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: Thanks for the answers so far. It's not my code I'm just curious how that could happen: Starting point: ... self.status['text'] = 'Processing ...' try: cli_main(argv) except Exception, e: self.status['text'] = 'Error: ' + str(e) return ... cli_main: keypath, inpath, outpath = argv[1:] ... with open(inpath, 'rb') as inf: serializer = PDFSerializer(inf, keypath) with open(outpath, 'wb') as outf: filenr = outf.fileno() serializer.dump(outf) return 0 PDFSerializer.dump: def dump(self, outf): self.outf = outf ... From clp2 at rebertia.com Tue Jul 13 10:12:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jul 2010 07:12:41 -0700 Subject: Check if a command is valid In-Reply-To: <4C3C4EF1.3080609@sequans.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> Message-ID: On Tue, Jul 13, 2010 at 4:33 AM, Jean-Michel Pichavant wrote: > Kenny Meyer wrote: >> I have to figure out if a string is callable on a Linux system. I'm >> actually doing this: >> >> ? ?def is_valid_command(command): >> ? ? ? ?retcode = 100 # initialize >> ? ? ? ?if command: >> ? ? ? ? ? ?retcode = subprocess.call(command, shell=True) >> ? ? ? ?if retcode is 0: >> ? ? ? ? ? ?print "Valid command." >> ? ? ? ?else: >> ? ? ? ? ? ?print "Looks not so good..." >> >> ? ?is_valid_command("ls") >> >> Never mind the code, because this is not the original. >> The side effect of subprocess.call() is that it *actually* executes >> it, but I just need the return code. What are better ways of doing >> this? >> > > I'm not sure I get exactly what you're searching for but here's something > that may help. > > If you just whant to know if a command (without parameter) is a Linux > command (either a builtin, alias of file exe) you can use the "where" > command and inspect its return code, the command is not executed though. > >>where ls > ls is an alias for ls --color=auto -F > ls is /bin/ls >>where apt-get > apt-get is /usr/bin/apt-get >>where doesnotexists > doesnotexists not found > zsh: exit 1 `where` seems to be a zsh built-in: $ # I'm in UR bash $ nonexistent -bash: nonexistent: command not found $ where bash -bash: where: command not found And not everyone has zsh installed, so... I don't see why one shouldn't use the standard `which` *nix command instead. Also, in retrospect, my suggestion should probably have checked the return code rather than the output; more efficient and simple that way. Cheers, Chris -- http://blog.rebertia.com From jonathan.lee.975 at gmail.com Tue Jul 13 10:41:51 2010 From: jonathan.lee.975 at gmail.com (Jonathan Lee) Date: Tue, 13 Jul 2010 07:41:51 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: Message-ID: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> > Problem (C) is outside the realm of the C++ standard, since the C++ standard > doesn't support shared libraries, and I've never actually used *nix shared > libraries so I don't /know/... > > Is such dynamic initialization guaranteed? > Not guaranteed, though I think there's a combination of dlopen options and gcc command line parameters that invoke this behavior. See the second page of http://www.linuxjournal.com/article/3687 about auto-registration. Personally, though, it never worked for me :/ --Jonathan From astan.chee at al.com.au Tue Jul 13 11:15:04 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 14 Jul 2010 01:15:04 +1000 Subject: executing python scripts within wx frames Message-ID: <4C3C82F8.5060402@al.com.au> Hi, I'm trying to make one of those frames thats similar to the wx python demo where a folder is filled with demo wx python scripts and there is one main script that opens the other ones in as different items in a tree/notebook. I've gotten most of it figured out except the part where the scripts are executed in a wx frame. The difference between what I'm trying to do and the wx python demo one is that mine are generic scripts that output the results to std out/error (or whatever gets displayed in IDLE). Does anyone know how I can do this? Simulate a IDLE or python shell in one of the frames thats basically the output of whatever script has been selected to run? It would be better if the solution was platform independent too. Thanks for any suggestions From robert.kern at gmail.com Tue Jul 13 11:16:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Jul 2010 10:16:07 -0500 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote: > PS: You (the reader) may be wondering, why why why Yet Another Python/C++ > binding? Well, because I had this great name for it, "pyni", unfortunately > already in use. But cppy is very different from Boost: Boost is large, cppy is > tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating > argument conversion etc., while with cppy your Python design is exposed to C++ > with no enforced arg conversions and such; Boost relies on canned magic, > difficult to subvert when it doesn't do what you want, while with cppy you are > (or, so far, I am) in control; and I suspect that the Boost Python binding, > relying on dynamic registries and stuff, is not all that efficient, while cppy > is as efficient as using the Python C API to create an extension. And besides, > cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) Note that Boost is not the only C++ binding out there. You may want to take a look at the old SCXX library, which appears to be similar in intent: http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html matplotlib uses it heavily, and their included copy may include some more recent bugfixes and enhancements: http://matplotlib.sourceforge.net/ -- 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 Tue Jul 13 11:18:13 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Jul 2010 15:18:13 GMT Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <757363be-5f66-4f92-9dfc-c5d453ae07c1@t10g2000yqg.googlegroups.com> <4c3a5c77$0$28647$c3e8da3@news.astraweb.com> Message-ID: <8a3edlFlrjU4@mid.individual.net> On 2010-07-12, Steven D'Aprano wrote: > On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote: > >> On Jul 11, 3:03??am, "G??nther Dietrich" wrote: >> >>> So, it is not a disadvantage that the functions you listed above are >>> named in this way. In the contrary, it is an advantage, as it keeps >>> newcomers from using stupid variable names. >> >> "int" for an Integer is stupid? >> "list" for a List is stupid? >> "str" for a String is stupid? >> >> What am i missing? > > If you're going to use generic names, why type three or four letters when > one will do? > > i, j, k, m, n, p, q for ints. > L, a, b, x for lists > s, t, a, b for strings. > > If you don't want to use generic names, then int, list, str are useless > because they don't mean anything. You need something like: > > count_of_widgets > list_of_widgets > description def map(function, list): # etc. It's a slight annoyance, nothing more. In the data I deal with, I get annoyed at needing to write student_id instead of id, but it's not a huge issue. The big consolation is that Python really doesn't care if I happen to shadow a builtin name that I've never heard of. I forget, and use id as a variable all the time, and nothing bad happens to me, because I don't need the builtin function. To see a really odd example of a similar name clash, create a tab separated values file with a header line starting with ID (I get lots of them in my work), and then open it with Excel (I don't know which version has the most bizarre error message). -- Neil Cerutti From luismgz at gmail.com Tue Jul 13 11:38:59 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 13 Jul 2010 08:38:59 -0700 (PDT) Subject: Lua is faster than Fortran??? References: <95832221-5aef-4330-ae51-dbf1d8c936dd@i31g2000yqm.googlegroups.com> Message-ID: On Jul 4, 6:09?pm, Stephen Hansen wrote: > On 7/4/10 9:21 AM, sturlamolden wrote: > > > On 4 Jul, 14:29, David Cournapeau wrote: > > >> Actually, I think the main reason why Lua is much faster than other > >> dynamic languages is its size. The language is small. You don't list, > >> dict, tuples, etc... > > > They have managed to combine list and dict into one type (table) that > > does the job of both. > > You say "managed" as if it were some technical accomplishment, or that > the result is able to actually do the job of both: neither of these > assertions are true. > > Have you actually *used* Lua? I quite like the language in certain > contexts where its appropriate, but if you've actually used it in real > code and found tables to be at all a substitute for *either* > dictionaries *or* lists, then I think somehow you've managed to actually > miss using either data structure in Python to any real extent, somehow. > > Lua's tables are at very weak "dictionary-like" and "list-like" objects, > which indeed have been folded into one. To the detriment of both, at > least as far as they are an actual useful data structure. > > You can't even get the equivalent of len(dict) in it: you have to > actually brute-force iterate the table and count manually. Even for a > purely array-like table with onlyn umbered indexes, #table can be > unreliable: its quite possible through normal list-like operations that > you perform on it, it can end up with holes where #table will fail. > Since it is *not* an list internally at *all*, but simply an associative > array with numbered indexes. > > I could go on, and on, and on: but the fundamental *weakness* of Lua' > data types as data-structures is irrefutable, from its tables to strings > to numbers: they are incredibly weak on capabilities. You end up writing > all kinds of "library" functions to just do the normal things that > should be really easy to do. > > Now, of course, there's really good reason why Lua is so simple in these > ways. Its entirely suitable for Lua as an embedded scripting language to > keep things very light, so it can be simple and fast. Good for Lua to > fill this niche superbly. But you can't start saying its simple > alternatives are at all comparable to Python's extremely rich and > capable data types. > > > And yes there are tuples. > > No, there isn't. There's ways to create a tuple-like-thing which kind of > behaves like a braindead tuple, and functions have a positively bizarre > capability of returning more then one value (and accepting variable > values), so there's these points in the language where you have this > sort of Immutable Sequence, but its opaque until you unwrap it -- and > then it ceases to be. > > That's not the same thing as having an immutable sequence that you can > store data in at your discretion, with a rich series of capabilities > that you can leverage. > > > There are no classes, but there are closures and other building blocks > > that can be used to create any object-oriented type system > > Not really. > > Above, I spoke of tables as data structures, things just storing data. > But you're right, they are capable of more then that-- but you're > over-selling just how far that capability goes, by a long shot (and > underselling just how much work it takes to get it there). > > Yes, tables have a limited series of 'hooks' that you can tie into to > alter their behavior, and through this you can simulate certain higher > order type systems as defined in other languages. In fact, lots of > people have done this: there's multiple "classy" libraries out there to > bring some kind of Class-or-Object-Oriented-Programming to Lua. > > They work to varying degrees: but the hooks that Lua provides to tables > is still significantly lacking to really replace Python's > comprehensively dynamic object model, without a LOT of wasted cycles. > > For example, while you can use __newindex to 'catch' someone setting a > new 'key' on a table, and and __index to replace or forward the actual > lookup, you can't actually capture someone trying to set a value to a > key which already exists. So, you end up having to do a full proxy > approach, where your table never actually stores anything directly > (except a reference to another hidden table), and so when someone goes > to set something you have to set it on the proxied object instead. > Because you can't let there ever be any real keys on the proxying / > external table. > > So you're able to work around its lack a bit, to simulate something > /like/ what it means to have __setattr__. > > But then you run into problems. There's no way now to iterate over the > table now, because pairs() will only return your internal hidden keys > that you're using to point to the proxied table (Although you can get > around this with some more complexity by hiding said key into a > closure-- but even then, you still can't iterate over the proxied > table's keys instead). > > So what do you do? Well you go replace the global "pairs" function, > that's what you do! So it learns your particular style of Classness, and > interacts well. Hope you never use any third-party code which has even a > vaguely different kind of Classness. Alternately, you can just decide to > never use the standard idiom of iteration for your classes, and instead > one must always "for x in my_table:iter()" -- so now you have one kind > of code operating on 'real' tables, and a totally different kind > operating on your 'classy tables'. > > And on and on. The point is, sure. Lua can sort of simulate different > OOP approaches, and Lua-folk are very adept at tweaking, twisting, > turning and ripping tables into all kinds of pseudo-data types that > match other paradigms, but its all hacks on top of hacks on top of > hacks. You end up with some *really* weird and/or messy code if you try. > > Better to do Lua in Lua, instead of Python in Lua, or Java in Lua. > > (just like > > > CLOS is defined by Lisp, not a part of the basic Lisp syntax). So I > > imagine it would be possible to define an equivalent to the Python > > type system in Lua, and compile Python to Lua. Lua can be compiled to > > Lua byte code. Factoring Lua, out that means we should be able to > > compile Python to Lua byte code. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload This is a very good explanation of what Lua is and how it differs from python. It all comes down to what you are looking for in a language. Simplicity of use or simplicity of implementation? Python gives you all the tools to code your algorithm right now with the least delay an with minimal effort, at the expense of some performance penalty. Lua is lean and fast, but if you need to use classes, or list comprehensions or some other cool features easily found in python, you have to code them yourself before using them. Perhaps you don't need them and you prefer a more spartan language in favor of speed and performance, and that's ok. Actually, this is what Lua is for. You may find that coding your own helper functions in Lua are not that difficult, but you have to do it. Basically, both languages are very similar, and their grammar is almost identical in their simplest aspects. But as soon as you start working with Lua, you wish you had all the missing python features. I see Lua as a some sort of minimal Python. It looks like a simplified subset of python. Being simpler, it's also easier to implement efficiently. Note that Lua was created a simple language to be embedded into larger applications written in c or c++. So it doesn't need a standard library, since you would be using libraries built for the main aplication, written in c or c++. However it worth noting that, according to Mike Pall (the creator of Luajit), there's no reason to believe Python could not be as fast a Luajit. It has no show stoppers. It would simply require much more work around its corner cases, being the main difficulties in python's own environment, not in the core language. This is all explained in the above mentioned thread on tracing jits... Luis From python at bdurham.com Tue Jul 13 11:56:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 13 Jul 2010 11:56:46 -0400 Subject: Cross-platform module that creates directory object with all file attributes Message-ID: <1279036606.15881.1384667215@webmail.messagingengine.com> Any recommendations for a cross-platform module that creates a directory object with not only file names, but file attributes as well? Use cases: - Sort files by file size or date last modified - Filter files by read-only status I know I can use various standard library functions [1] to construct such a class, but I'd rather avoid re-inventing the wheel if at all possible. (I fear that this may be one of those seemingly easy tasks that starts off simple and ends up taking a lot more time to implement after real world refactoring). Malcolm [1] os.path.getmtime, os.path.getsize, os.W_OK, etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Tue Jul 13 12:06:36 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 13 Jul 2010 17:06:36 +0100 Subject: round issue In-Reply-To: References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> On 12/07/2010 19:59, Mark Dickinson wrote: ............ >> It does look inconsistent however, and it seems to me rounding and >> interpolation should behave similarly. > > Agreed. In this case it's a minor bug that round(-9.85, 1) > produces -9.9 instead of -9.8; both string formatting > and round should give -9.8. This bug is fixed in Python > 2.7 and in Python 3.x. > > Note that in 2.7 there's still a legitimate difference: round > rounds halfway cases away from 0, while string formatting > rounds them to even. So the following results are correct: > > Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> round(1.25, 1) > 1.3 >>>> '%.1f' % 1.25 > '1.2' > > (1.25 *is* an exact halfway case, since it's exactly > representable as a binary float.) > > In Python 3.x, round always does round-half-to-even, so > string formatting and round should agree (and if they don't, > it's definitely a bug: please report it!) > > With all this said, asking for *decimal* rounding of > *binary* approximations to *decimal* halfway cases to give > the results you expect is ... optimistic, to say the least. > Use the decimal module if you care about which way > your (almost) halfway cases get rounded. > > [I already replied to this earlier through Google groups, but > I'm not sure whether it went through properly. Apologies > for the duplication, if so.] > yes thanks I saw that, but no problem about the dup. I suspect we might end up using some kind of fixed point. Anyhow does anyone have a good algorithm for ensuring rounded percentages do add up to 100%? :) How about grouped percentages ie ensure the group sums and the groups display correctly in rounded form. -- Robin Becker From robin at reportlab.com Tue Jul 13 12:06:36 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 13 Jul 2010 17:06:36 +0100 Subject: round issue In-Reply-To: References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> Message-ID: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> On 12/07/2010 19:59, Mark Dickinson wrote: ............ >> It does look inconsistent however, and it seems to me rounding and >> interpolation should behave similarly. > > Agreed. In this case it's a minor bug that round(-9.85, 1) > produces -9.9 instead of -9.8; both string formatting > and round should give -9.8. This bug is fixed in Python > 2.7 and in Python 3.x. > > Note that in 2.7 there's still a legitimate difference: round > rounds halfway cases away from 0, while string formatting > rounds them to even. So the following results are correct: > > Python 2.7 (r27:82500, Jul 11 2010, 22:38:53) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> round(1.25, 1) > 1.3 >>>> '%.1f' % 1.25 > '1.2' > > (1.25 *is* an exact halfway case, since it's exactly > representable as a binary float.) > > In Python 3.x, round always does round-half-to-even, so > string formatting and round should agree (and if they don't, > it's definitely a bug: please report it!) > > With all this said, asking for *decimal* rounding of > *binary* approximations to *decimal* halfway cases to give > the results you expect is ... optimistic, to say the least. > Use the decimal module if you care about which way > your (almost) halfway cases get rounded. > > [I already replied to this earlier through Google groups, but > I'm not sure whether it went through properly. Apologies > for the duplication, if so.] > yes thanks I saw that, but no problem about the dup. I suspect we might end up using some kind of fixed point. Anyhow does anyone have a good algorithm for ensuring rounded percentages do add up to 100%? :) How about grouped percentages ie ensure the group sums and the groups display correctly in rounded form. -- Robin Becker From ritchy_gato at hotmail.com Tue Jul 13 12:13:18 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:13:18 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> Message-ID: <28b460f2-e6ae-4edc-90e2-4f79f880d646@r27g2000yqb.googlegroups.com> On 11 Jul, 17:39, Ritchy lelis wrote: > On 11 jul, 13:28, Johan Gr?nqvist wrote: > > > > > > > 2010-07-11 02:12, Ritchy lelis skrev: > > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > > About the plot draw it's a curve that it's a set of points wich it's > > > the result of the comput of the Vref and Vi together. I don't know if > > > i had to make a break instruction (like in other's languages) after > > > the "If" instructions if i want the else-condition to be executed? ... > > > (do you have some sujestions?) > > > I would have expected a code structure similar to this: > > > (NOTE: This is a very inefficient solution, and not the one suggested > > earlier, but it is closer to the code snippet you posted originally, and > > it does produce a plot.) > > > ---------------------- > > import numpy as np > > import matplotlib.pyplot as plt > > Vref = np.linspace(1,20, 100) > > Vi = np.linspace(1,10,100) > > > for ref in Vref: # Loop over Vref and Vi > > ? ? ?for i in Vi: > > ? ? ? ? ?if ?i > ref/4: # Compute V0 > > ? ? ? ? ? ? ?V0 = 2*i-ref > > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > > ? ? ? ? ? ? ?V0 = 2*i > > ? ? ? ? ?elif i < -ref/4: > > ? ? ? ? ? ? ?V0 = 2*i+ref > > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > > plt.show() # Display the plot in a window > > ---------------------- > > > > Anyway i have a picture of a tuturial that i found but in this forum i > > > can't post it. That pic would show what a really want... > > > Can you give a link? > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > > y-axis. > > > To me this sound like you want to make a 3D-plot, as there is the > > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > As i said, i have a good 2 pic of a doc that has the information about > > > this ADC that i'm developing. > > > I looked on wikipedia > > , and saw some > > figures. Is any of those similar to what you look for? > > > I see that they have (Vi - Vref) on the x-axis, and the computed value > > on the y-axis. > > > Regards > > > Johan > > Hi > > Yes those fig look's familiar to me but for now the objective its to > get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). > > I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF > there are some fig and explanations on page's 9-13. Can you take a > look there please? > > Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023 > (I think there it?s more information than the first link i gave you). > > I'll be waiting for sujestions. > > Thank's- Ocultar texto citado - > > - Mostrar texto citado - hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From rushikesh.busetty at gmail.com Tue Jul 13 12:15:00 2010 From: rushikesh.busetty at gmail.com (RUSHIKESH BUSETTY) Date: Tue, 13 Jul 2010 09:15:00 -0700 (PDT) Subject: HOTTEST ENTERTAINMENT Message-ID: HOT HEROINES PHOTOS http://hotheroinesphoto.blogspot.com/ SEXY SNEHA http://hotheroinesphoto.blogspot.com/2010/06/sneha-hot.html KOUSHA HOT EXPOSING http://hotheroinesphoto.blogspot.com/2010/06/sexy-kousha.html PRIYAMANI IN HOT BIKINI http://hotheroinesphoto.blogspot.com/2010/06/priyamani-hot.html MADHUSHALINI IN HOT DRESS http://hotheroinesphoto.blogspot.com/2010/06/blog-post_2972.html HOTTEST LIPKISS http://hotheroinesphoto.blogspot.com/2010/06/lipkiss-2.html NAMITHA IN BATH http://hotheroinesphoto.blogspot.com/2010/06/nayagarala-namitha.html http://hotheroinesphoto.blogspot.com/2010/06/nayagarala-namitha.html From ritchy_gato at hotmail.com Tue Jul 13 12:17:02 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:17:02 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <2ecfbff1-114c-4033-ba67-30c8aac6deeb@y4g2000yqy.googlegroups.com> Message-ID: <902aea8e-854a-42c5-9801-bca459eeb209@i31g2000yqm.googlegroups.com> On 11 Jul, 17:39, Ritchy lelis wrote: > On 11 jul, 13:28, Johan Gr?nqvist wrote: > > > > > > > 2010-07-11 02:12, Ritchy lelis skrev: > > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > > About the plot draw it's a curve that it's a set of points wich it's > > > the result of the comput of the Vref and Vi together. I don't know if > > > i had to make a break instruction (like in other's languages) after > > > the "If" instructions if i want the else-condition to be executed? ... > > > (do you have some sujestions?) > > > I would have expected a code structure similar to this: > > > (NOTE: This is a very inefficient solution, and not the one suggested > > earlier, but it is closer to the code snippet you posted originally, and > > it does produce a plot.) > > > ---------------------- > > import numpy as np > > import matplotlib.pyplot as plt > > Vref = np.linspace(1,20, 100) > > Vi = np.linspace(1,10,100) > > > for ref in Vref: # Loop over Vref and Vi > > ? ? ?for i in Vi: > > ? ? ? ? ?if ?i > ref/4: # Compute V0 > > ? ? ? ? ? ? ?V0 = 2*i-ref > > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > > ? ? ? ? ? ? ?V0 = 2*i > > ? ? ? ? ?elif i < -ref/4: > > ? ? ? ? ? ? ?V0 = 2*i+ref > > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > > plt.show() # Display the plot in a window > > ---------------------- > > > > Anyway i have a picture of a tuturial that i found but in this forum i > > > can't post it. That pic would show what a really want... > > > Can you give a link? > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > > y-axis. > > > To me this sound like you want to make a 3D-plot, as there is the > > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > As i said, i have a good 2 pic of a doc that has the information about > > > this ADC that i'm developing. > > > I looked on wikipedia > > , and saw some > > figures. Is any of those similar to what you look for? > > > I see that they have (Vi - Vref) on the x-axis, and the computed value > > on the y-axis. > > > Regards > > > Johan > > Hi > > Yes those fig look's familiar to me but for now the objective its to > get that residue transfer function (1.5-Bit-Per-Stage Pipelined ADC). > > I found inhttp://amesp02.tamu.edu/~sanchez/ADC-pipeline_lecture.PDF > there are some fig and explanations on page's 9-13. Can you take a > look there please? > > Also you can take a look inhttp://www.maxim-ic.com/app-notes/index.mvp/id/1023 > (I think there it?s more information than the first link i gave you). > > I'll be waiting for sujestions. > > Thank's- Ocultar texto citado - > > - Mostrar texto citado - hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From ritchy_gato at hotmail.com Tue Jul 13 12:17:20 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Tue, 13 Jul 2010 09:17:20 -0700 (PDT) Subject: Plot problem.. ?? No sign at all References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> Message-ID: <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> On 11 Jul, 13:28, Johan Gr?nqvist wrote: > 2010-07-11 02:12, Ritchy lelis skrev: > > > On 7 jul, 08:38, Johan Gr?nqvist ?wrote: > > > About the plot draw it's a curve that it's a set of points wich it's > > the result of the comput of the Vref and Vi together. I don't know if > > i had to make a break instruction (like in other's languages) after > > the "If" instructions if i want the else-condition to be executed? ... > > (do you have some sujestions?) > > I would have expected a code structure similar to this: > > (NOTE: This is a very inefficient solution, and not the one suggested > earlier, but it is closer to the code snippet you posted originally, and > it does produce a plot.) > > ---------------------- > import numpy as np > import matplotlib.pyplot as plt > Vref = np.linspace(1,20, 100) > Vi = np.linspace(1,10,100) > > for ref in Vref: # Loop over Vref and Vi > ? ? ?for i in Vi: > ? ? ? ? ?if ?i > ref/4: # Compute V0 > ? ? ? ? ? ? ?V0 = 2*i-ref > ? ? ? ? ?elif (-ref/4) <= ref and ref <= ref/4: > ? ? ? ? ? ? ?V0 = 2*i > ? ? ? ? ?elif i < -ref/4: > ? ? ? ? ? ? ?V0 = 2*i+ref > ? ? ? ? ?plt.plot(i, V0, ".") # Plot one single point at x = i, y = V0 > plt.show() # Display the plot in a window > ---------------------- > > > Anyway i have a picture of a tuturial that i found but in this forum i > > can't post it. That pic would show what a really want... > > Can you give a link? > > > > > Relatively to the axis, the Vi takes the x-axis and the Vref takes the > > y-axis. > > To me this sound like you want to make a 3D-plot, as there is the > x-axis, the y-axis, and V0. Is this correct? Is V0 on a z-axis? > > > > > As i said, i have a good 2 pic of a doc that has the information about > > this ADC that i'm developing. > > I looked on wikipedia > , and saw some > figures. Is any of those similar to what you look for? > > I see that they have (Vi - Vref) on the x-axis, and the computed value > on the y-axis. > > Regards > > Johan hi This is how looks like the flash residue transference function that i was talking about... http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif I'm suposed to obtain a figure like that in my plot. Somebody help me please. Cheers From python.list at tim.thechases.com Tue Jul 13 12:29:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 13 Jul 2010 11:29:44 -0500 Subject: Cross-platform module that creates directory object with all file attributes In-Reply-To: <1279036606.15881.1384667215@webmail.messagingengine.com> References: <1279036606.15881.1384667215@webmail.messagingengine.com> Message-ID: <4C3C9478.5070205@tim.thechases.com> On 07/13/2010 10:56 AM, python at bdurham.com wrote: > Any recommendations for a cross-platform module that creates a > directory object with not only file names, but file attributes as > well? > > Use cases: > - Sort files by file size or date last modified > - Filter files by read-only status > > I know I can use various standard library functions [1] to > construct such a class, but I'd rather avoid re-inventing the > wheel if at all possible. (I fear that this may be one of those > seemingly easy tasks that starts off simple and ends up taking a > lot more time to implement after real world refactoring). I think it's sufficiently easy to create a custom solution that there's not much value in trying to map file-metadata into a wrapper object. For your examples: f = os.path.getmtime #f = os.path.getsize sorted_by_mtime = sorted(os.listdir('.'), key=f) or if you need a different location sorted_by_mtime = sorted( os.listdir(loc), key=lambda fname: f(os.path.join(loc, fname)) ) And for your read-only status: files = [fname for fname in os.listdir(loc) if os.access(os.path.join(loc, fname), os.W_OK) ] That doesn't mean somebody hasn't done it before, but given how easy it is without a wrapper object, it's not something I'd go out of my way to find. -tkc From emile at fenx.com Tue Jul 13 12:39:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 13 Jul 2010 09:39:18 -0700 Subject: round issue In-Reply-To: <4C3C8F0C.3020606@chamonix.reportlab.co.uk> References: <4C3AE5C0.4090806@chamonix.reportlab.co.uk> <4C3C8F0C.3020606@chamonix.reportlab.co.uk> Message-ID: On 7/13/2010 9:06 AM Robin Becker said... > > Anyhow does anyone have a good algorithm for ensuring rounded > percentages do add up to 100%? :) How about grouped percentages ie > ensure the group sums and the groups display correctly in rounded form. I generally do the calculations in memory then set the largest to 100 - sum(rounded(others)). (Same as for double entry bookkeeping to ensure debits == credits) Emile From rubendario_778 at hotmail.com Tue Jul 13 13:25:52 2010 From: rubendario_778 at hotmail.com (Ruben ruben) Date: Tue, 13 Jul 2010 14:25:52 -0300 Subject: guia de python 2.6.4 en castellano Message-ID: buenos dias mi nombre es ruben queria ver si me podian mandar la guia de python 2.6.4 en castellano yo baje el programa python pero en ingles y mi ingles es muy regular desde ya muchas gracias muy bueno el programa python _________________________________________________________________ En Hotmail estamos reinventando un nuevo correo. Preparate para lo que se viene. Ver m?s http://www.nuevohotmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From downaold at gmail.com Tue Jul 13 13:26:34 2010 From: downaold at gmail.com (Roald de Vries) Date: Tue, 13 Jul 2010 19:26:34 +0200 Subject: floatref Message-ID: Hi all, I have two objects that should both be able to alter a shared float. So i need something like a mutable float object, or a float reference object. Does anybody know if something like that exists? I know it's not hard to build, but I have a feeling that there should be a standard solution to it. Roald From j at junkwallah.org Tue Jul 13 13:48:50 2010 From: j at junkwallah.org (Junkman) Date: Tue, 13 Jul 2010 10:48:50 -0700 Subject: Python 3 grammar, function parameters In-Reply-To: References: <4C3B97FB.5010409@junkwallah.org> Message-ID: <4C3CA702.3070603@junkwallah.org> A-ha! Thank you very much, Chris. Much appreciated. :-) Jay Chris Rebert wrote: > On Mon, Jul 12, 2010 at 3:32 PM, Junkman wrote: >> Greetings to Python users, >> >> I'm trying to parse Python code using the grammar supplied with the >> documentation set, and have a question on the grammar for function >> parameters: >> >> funcdef: 'def' NAME parameters ['->' test] ':' suite >> parameters: '(' [typedargslist] ')' >> typedargslist: ((tfpdef ['=' test] ',')* >> ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] >> | '**' tfpdef) >> | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) >> tfpdef: NAME [':' test] >> >> >From what I understand, a naked asterisk - i.e. it is not a prefix to an >> identifier - is not a valid parameter, but the grammar explicitly >> allows it by making the identifier that immediately follows the >> asterisk optional. >> >> Are there cases where naked asterisk is allowed as a function >> parameter? > > Yes, for keyword-only arguments, a new feature in Python 3.x. See PEP > 3102 (http://www.python.org/dev/peps/pep-3102/ ). > A lone asterisk signals that the function does not take extra > positional arguments. All keyword-only arguments must be declared > after a lone or normal *-argument. > > Example: > def compare(a, b, *, key=None): > > compare() does not accept extra positional arguments and has 1 > keyword-only argument (namely, `key`). > > Cheers, > Chris > -- > http://blog.rebertia.com > From ppearson at nowhere.invalid Tue Jul 13 14:33:57 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 13 Jul 2010 18:33:57 GMT Subject: integer >= 1 == True and integer.0 == False is bad, bad, bad!!! References: <1b285203-33f6-41fb-8321-381c154bc8ed@w12g2000yqj.googlegroups.com> <059dee86-1f11-4e18-9647-de209186e6e5@t10g2000yqg.googlegroups.com> <4c3a5b8b$0$28647$c3e8da3@news.astraweb.com> <4c3a793e$0$28662$c3e8da3@news.astraweb.com> <4c3bb0cb$0$28644$c3e8da3@news.astraweb.com> <4c3bda8f$0$11092$c3e8da3@news.astraweb.com> Message-ID: <8a3pslFebiU1@mid.individual.net> On 13 Jul 2010 03:16:31 GMT, Steven D'Aprano wrote: [snip] > . . . and we rightly shake our heads at the sheer > n00b-ness of it. Writing the explicit tests: > > if bool(myInt): > > or even: > > if myInt <> 0: > > are firmly in the same category. The only difference is that it is more > familiar and therefore comfortable to those who are used to languages > that don't have Python's truth-testing rules. I have been a Python newbie for over 10 years, and would like to mention that what's clear to Python experts is much less clear to me. I think this might matter more than you think, since clarity-to-the-semicompetent is an important component of the "activation barrier" that heavily influences market share. Names are seldom so felicitous as myInt. In practice, when trying to read foreign code, I encounter "if x:", and poor commenting leaves me ignorant of x's type and thus of the exact meaning of "if x:". When I see "if x <> 0:", I get the feeling that x is some kind of number, and the meaning of the test is pretty clear. And then when writing code, I usually can't confidently retrieve the recipe for the boolean interpretation of x from readily accessible memory, so I will write explicitly what I mean, and thereby do a favor for the next guy to look at the code, who is almost always a 10-year Python newbie who needs all the clues he can get. -- To email me, substitute nowhere->spamcop, invalid->net. From xahlee at gmail.com Tue Jul 13 14:43:16 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 13 Jul 2010 11:43:16 -0700 (PDT) Subject: death of newsgroups (Microsoft closing their newsgroups) Message-ID: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> ? Death of Newsgroups http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html plain text version follows. -------------------------------------------------- Death of Newsgroups Xah Lee, 2010-07-13 Microsoft is closing down their newsgroups. See: microsoft.public.windows.powershell. I use comp.lang.lisp, comp.emacs since about 1999. Have been using them pretty much on a weekly basis in the past 10 years. Starting about 2007, the traffic has been increasingly filled with spam, and the posters are always just the 20 or 30 known faces. I think perhaps maybe no more than 100 different posters a year. Since this year or last year, they are some 95% spam. comp.emacs is pretty much just me. gnu.emacs.help is not much better. It's pretty much the same developers and the same few elisp coders, with perhaps 1 new face with once-per-lifetime post every few days. gnu.emacs.help is doing a bit better because it is connected to fsf's mailing list. comp.lang.perl.misc is dead few years ago. It's filled with just snippet of FAQs that's posted by machine. There's perl.beginners since 2002, and it's a moderated group. The one newsgroup that i use that's still healthy is comp.lang.python. Part of the reason it's healthy because it's connected to a mailing list, and python has become a mainstream lang. Though, it is also infected by a lot spam in late years. I did a study of language popularity by graphing newsgroup traffic thru the years. See: Computer Language Popularity Trend. I thought about updating it now and then, but it's useless if the majority of posts are machine generated spam. For vast majority of people who is not a regular user of newsgroups in the 1990s or earlier, i suppose newsgroup has been dead since perhaps 2002. It's somewhat sad. Because newsgroup once was the vibrant hotbed for uncensored information and freespeech, with incidences that spawned main stream public debate on policies, or change of nations. (scientology being one famous example, then there's Cindy's Torment censorship, then i remember also several cases of political dirty secrets being released in newsgroups ) These days, much of this happens in the blogs and there's Wikileaks. Xah ? http://xahlee.org/ ? From gherron at digipen.edu Tue Jul 13 14:54:35 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 13 Jul 2010 11:54:35 -0700 Subject: floatref In-Reply-To: References: Message-ID: <4C3CB66B.9030107@digipen.edu> On 07/13/2010 10:26 AM, Roald de Vries wrote: > Hi all, > > I have two objects that should both be able to alter a shared float. > So i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's > not hard to build, but I have a feeling that there should be a > standard solution to it. > > Roald Huh? I must be missing something here. Isn't this what you use a variable for: sharedFloat = 123 and later sharedFloat = 99 The variable sharedFloat could exit as a global (in some module) or as a instance variable in some shared object or anywhere else you want to store it. As a module attribute: import Shared Shared.sharedFloat = 123 Or as a class attribute: class Shared: sharedFloat = 0 Shared.sharedFloat = 123 or as an instance attribute: class Shared: def __init__(self): self.sharedFloat = 0 sharedObject = Shared() sharedObject.sharedFloat = 123 Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From hujia06 at gmail.com Tue Jul 13 15:16:54 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 13 Jul 2010 15:16:54 -0400 Subject: write a .txt file In-Reply-To: <20100713071705.GA22054@cskk.homeip.net> References: <20100713071705.GA22054@cskk.homeip.net> Message-ID: On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson wrote: > On 13Jul2010 02:46, Jia Hu wrote: > | Hi: > | > | Do you mean the following code? > | > | #!/usr/bin/python > | # OS: Ubuntu > | import subprocess > | fileName = open ('final.txt', 'a') > | fileName.write ('%s %s %s \n' % (12,25,9)) > | > | fileName.flush() # add > | fileName.close() # add > > You should not need the .close(). > > Thank you. > | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # change to > "ls > | -a" > > You're still not waiting for the Popen subprocess to finish before > continuing. > > | fileName=open ('final.txt', 'a') > > You shouldn't need the open() if you skip the .close() > > | fileName.seek(0,2) > > If you _do_ do an open(..., "a") then you don't need the seek - append > mode will write at the end for you. > > | fileName.write ('%s %s %s \n' % (85,25,12)) > | fileName.close() > | > | I run that, the result showed the list of file is located after the > number > | list 85 25 12 > | Is that possible that I put the fileName.flush() in a wrong position ? > | I am new to Python and do not quite understand the "flush" concept. > > First: please don't top post. Post below the relevant points as I do > above, like a conversation. That way it is clear exactly what each > remark is for. > OK, it is a good suggestion. By the way, do you add the pipe "|" or they are automatically generated ? > > Second: "flush" is a general idea used with buffers. > > When you .write() to a file the data does not normally go directly to > disc. This is because a real write to the disc is expensive in time > (the CPU is much much faster than a hard drive). > > Also, a OS-level "write", which transfers the data from your program into > the OS's buffers (where it queues, for eventual writing to the disc) > is _also_ a comparitively expensive operation. So when you .write() > in python (or C using stdio, and in many other languages) the data is > normally kept in a memory buffer inside your program. Only when that > buffer is filled is an OS-level "write" done. In this way, OS calls are > few. This is a performance gain. > > So, in your program, when you .write() your first line of numbers > the data has not been handed to the OS at all, and therefore the > "final.txt" file has not seen it. A .flush() call is an explicit request > to empty the buffer, making an OS-level "write" immediately. In your > program, this is necessary to get the data to "final.txt" before the > "echo" or "ls" commands are run. > > If you .close() a file, that also empties the buffer. But it also closes > the file! SO you need to re-open it. For your purposes, a .flush() is > enough and leaves the file open for you to continue using it later. > > Regarding the .seek(): after the "echo" or "ls" command has run > the file has grown. Python's "file" object does not know the file has > grown because it was not involved. So a .seek(0 is needed to position > Python's .write() location to the end of the file instead of where it > though things were. > > Um. Because you have opened the file in 'a' mode you should not need the > .seek() - an "append" mode file will always write to the end of the > file. > > So: your first problem only requires a .flush(), to empty the buffer > before "echo" or "ls" runs. However, you still have not waited for the > "echo" or "ls" to finish - Popen kicks the command off, but it will run > at the same time as your program! Call: > > desLrr.wait() I initially thought only desLrr.wait() is needed even if without fileName.flush() , that is because the first line of number will transfer to the memory buffer and then "echo, ls" is also kept in the memory buffer and then wait() to make them finish. But when I actually did this, I find this method is not very correct. The first few words generated by "ls" are missing. When I add "fileName.flush()" again and got a correct output. Should I always write to the file at one time and then run "flush" or "close()" before the next write to the file (e.g. "echo" or the second line of number) ? Thank you. > to wait for the "echo" or "ls" to finish before continuing! > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > Quick Guide to Resources to break crypto systems of given strength: > Difficulty Resources required > 2**0 Pencil and paper > 2**8 Pencil and paper and a lot of patience > 2**16 Warez d00d with a Commodore 64 > 2**32 Amateur with an average PC > 2**40 Smart amateur with a good PC > 2**56 Network of workstations, custom-built hardware > 2**64 Thousands of PCs working together for several years > 2**80 NSA, Microsoft, the Illuminati > 2**128 Cubic kilometers of sci-fi nanotech > 2**160 Dyson spheres > Eddy L O Jansson and Matthew Skala, from: > http://hem.passagen.se/eddy1/reveng/cp4/cp4break.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alf.p.steinbach+usenet at gmail.com Tue Jul 13 15:39:50 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 21:39:50 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: References: <89pi93F819U4@mid.individual.net> Message-ID: * Robert Kern, on 13.07.2010 17:16: > On 7/13/10 2:34 AM, Alf P. Steinbach /Usenet wrote: > >> PS: You (the reader) may be wondering, why why why Yet Another Python/C++ >> binding? Well, because I had this great name for it, "pyni", unfortunately >> already in use. But cppy is very different from Boost: Boost is large, cppy is >> tiny; Boost has as main goal to expose arbitrary C++ code to Python, automating >> argument conversion etc., while with cppy your Python design is exposed to C++ >> with no enforced arg conversions and such; Boost relies on canned magic, >> difficult to subvert when it doesn't do what you want, while with cppy you are >> (or, so far, I am) in control; and I suspect that the Boost Python binding, >> relying on dynamic registries and stuff, is not all that efficient, while cppy >> is as efficient as using the Python C API to create an extension. And besides, >> cppy supports national characters in doc strings etc. And I'm Norwegian. So. :-) > > Note that Boost is not the only C++ binding out there. You may want to > take a look at the old SCXX library, which appears to be similar in intent: > > http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html > > matplotlib uses it heavily, and their included copy may include some > more recent bugfixes and enhancements: > > http://matplotlib.sourceforge.net/ Thanks! It seems that SCXX does those things that I've been planning to do but haven't got around to (wrapping standard Python types), while what it doesn't do (abstracting away all those tables etc. and mapping Python calls to C++ calls) is what I've been working on. Which could be a Very Nice combination except that I'm assuming Py3, while SCXX seems to be Py2 only. :-( Cheers, - Alf -- blog at From python at mrabarnett.plus.com Tue Jul 13 15:40:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 13 Jul 2010 20:40:16 +0100 Subject: write a .txt file In-Reply-To: References: <20100713071705.GA22054@cskk.homeip.net> Message-ID: <4C3CC120.4060201@mrabarnett.plus.com> Jia Hu wrote: > > > On Tue, Jul 13, 2010 at 3:17 AM, Cameron Simpson > wrote: > > On 13Jul2010 02:46, Jia Hu > wrote: > | Hi: > | > | Do you mean the following code? > | > | #!/usr/bin/python > | # OS: Ubuntu > | import subprocess > | fileName = open ('final.txt', 'a') > | fileName.write ('%s %s %s \n' % (12,25,9)) > | > | fileName.flush() # add > | fileName.close() # add > > You should not need the .close(). > > > Thank you. > > > | desLrr = subprocess.Popen('ls -a >> final.txt', shell=True) # > change to "ls > | -a" > > You're still not waiting for the Popen subprocess to finish before > continuing. > > | fileName=open ('final.txt', 'a') > > You shouldn't need the open() if you skip the .close() > > | fileName.seek(0,2) > > If you _do_ do an open(..., "a") then you don't need the seek - append > mode will write at the end for you. > > | fileName.write ('%s %s %s \n' % (85,25,12)) > | fileName.close() > | > | I run that, the result showed the list of file is located after > the number > | list 85 25 12 > | Is that possible that I put the fileName.flush() in a wrong position ? > | I am new to Python and do not quite understand the "flush" concept. > > First: please don't top post. Post below the relevant points as I do > above, like a conversation. That way it is clear exactly what each > remark is for. > > > > OK, it is a good suggestion. By the way, do you add the pipe "|" or > > they are automatically generated ? > > > Second: "flush" is a general idea used with buffers. > > When you .write() to a file the data does not normally go directly to > disc. This is because a real write to the disc is expensive in time > (the CPU is much much faster than a hard drive). > > Also, a OS-level "write", which transfers the data from your program > into > the OS's buffers (where it queues, for eventual writing to the disc) > is _also_ a comparitively expensive operation. So when you .write() > in python (or C using stdio, and in many other languages) the data is > normally kept in a memory buffer inside your program. Only when that > buffer is filled is an OS-level "write" done. In this way, OS calls are > few. This is a performance gain. > > So, in your program, when you .write() your first line of numbers > the data has not been handed to the OS at all, and therefore the > "final.txt" file has not seen it. A .flush() call is an explicit request > to empty the buffer, making an OS-level "write" immediately. In your > program, this is necessary to get the data to "final.txt" before the > "echo" or "ls" commands are run. > > If you .close() a file, that also empties the buffer. But it also closes > the file! SO you need to re-open it. For your purposes, a .flush() is > enough and leaves the file open for you to continue using it later. > > Regarding the .seek(): after the "echo" or "ls" command has run > the file has grown. Python's "file" object does not know the file has > grown because it was not involved. So a .seek(0 is needed to position > Python's .write() location to the end of the file instead of where it > though things were. > > Um. Because you have opened the file in 'a' mode you should not need the > .seek() - an "append" mode file will always write to the end of the > file. > > So: your first problem only requires a .flush(), to empty the buffer > before "echo" or "ls" runs. However, you still have not waited for the > "echo" or "ls" to finish - Popen kicks the command off, but it will run > at the same time as your program! Call: > > desLrr.wait() > > I initially thought only desLrr.wait() is needed even if without > fileName.flush() , that is > because the first line of number will transfer to the memory buffer and > then "echo, ls" is > also kept in the memory buffer and then wait() to make them finish. But > when I actually did this, > I find this method is not very correct. The first few words generated > by "ls" are missing. > When I add "fileName.flush()" again and got a correct output. > > Should I always write to the file at one time and then run "flush" or > "close()" before the next > write to the file (e.g. "echo" or the second line of number) ? > Each process will have its own buffers, so the output from "echo" won't be going into the same buffer as that of your Python script. Whether you need to close the file depends on whether the open file can be shared. When I tried it on Windows XP without closing the file I got an error message saying that it ("echo") couldn't write to the file because it was open in another process (the Python script). If the open file can be shared then you just need to ensure that the script's output is flushed to disk; if the open file can't be shared then you need to close the file (any output that's still in the buffer will be flushed automatically when the file is closed). From alf.p.steinbach+usenet at gmail.com Tue Jul 13 15:53:09 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 21:53:09 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> References: <3d18dfba-8dab-4709-92c6-aee9f7341e55@c10g2000yqi.googlegroups.com> Message-ID: * Jonathan Lee, on 13.07.2010 16:41: >> Problem (C) is outside the realm of the C++ standard, since the C++ standard >> doesn't support shared libraries, and I've never actually used *nix shared >> libraries so I don't /know/... >> >> Is such dynamic initialization guaranteed? >> > > Not guaranteed, though I think there's a combination of dlopen options > and gcc command line parameters that invoke this behavior. See the > second page of > > http://www.linuxjournal.com/article/3687 > > about auto-registration. > > Personally, though, it never worked for me :/ Ah, well. :-( Thanks for the info! OK, I'll just have to replace the auto-registration with some C++ magic. For which I think I'll simply /require/ that the compiler supports mixing of C and C++ linkage, that is, that ... #include extern "C" { typedef int (*Callback)( int ); } void foo( Callback f ) { std::cout << "foo!" << f( 42 ) << std::endl; } int a( int ) { return 1; } extern "C" int b( int ) { return 2; } int main() { foo( a ); // Unholy Mix of C++ and C linkage, formally not OK. foo( b ); // Should be OK with any compiler. } ... compiles, and works. Cheers, & thanks, - Alf -- blog at From micayael at gmail.com Tue Jul 13 15:55:35 2010 From: micayael at gmail.com (micayael) Date: Tue, 13 Jul 2010 12:55:35 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None Message-ID: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Hi. I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 the adodb and psycopg2 module (sudo apt-get install python-adodb python-psycopg2) but when I put this import adodb print adodb.NewADOConnection('postgres') --> None but with print adodb.NewADOConnection('mysql') --> From sturlamolden at yahoo.no Tue Jul 13 16:03:11 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 13:03:11 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: Message-ID: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> On 9 Jul, 17:52, "Alf P. Steinbach /Usenet" wrote: > For an extension module it seems that Python requires each routine to be defined > as 'extern "C"'. That is strange. PyMethodDef is just a jump table. So why should 'extern "C"' matter? Good luck on re-inventing the wheel (you've probably heared about Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...) From sturlamolden at yahoo.no Tue Jul 13 16:06:32 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 13:06:32 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> Message-ID: <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> On 13 Jul, 21:39, "Alf P. Steinbach /Usenet" wrote: > Thanks! It seems that SCXX does those things that I've been planning to do but > haven't got around to (wrapping standard Python types), while what it doesn't do > (abstracting away all those tables etc. and mapping Python calls to C++ calls) > is what I've been working on. Which could be a Very Nice combination except that > I'm assuming Py3, while SCXX seems to be Py2 only. :-( I'd suggest PyCXX instead. http://cxx.sourceforge.net SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in Python. From hansmu at xs4all.nl Tue Jul 13 16:14:27 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 13 Jul 2010 22:14:27 +0200 Subject: Check if a command is valid In-Reply-To: References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> Message-ID: <4c3cc937$0$22938$e4fe514c@news.xs4all.nl> Chris Rebert wrote: > `where` seems to be a zsh built-in: > $ # I'm in UR bash > $ nonexistent > -bash: nonexistent: command not found > $ where bash > -bash: where: command not found > > And not everyone has zsh installed, so... > I don't see why one shouldn't use the standard `which` *nix command instead. Because `which` ia a C shell script. It reads your .cshrc, to see which aliases would be defined if you were to use the C shell, but it doesn't look at your .bashrc. You're probably better off using `type`: it knows about built-ins and shell functions and that sort of stuff: $ which type /usr/bin/type $ type type type is a shell builtin $ Guess which answer is more relevant to you ..... HTH, -- HansM From alf.p.steinbach+usenet at gmail.com Tue Jul 13 16:35:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 22:35:10 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: * sturlamolden, on 13.07.2010 22:03: > On 9 Jul, 17:52, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> For an extension module it seems that Python requires each routine to be defined >> as 'extern "C"'. > > That is strange. PyMethodDef is just a jump table. So why should > 'extern "C"' matter? Formally because they're incompatible function pointer types. C++98 standard ?7.5/1: "Two function types with different language linkages are distinct types even if they are otherwise identical". Add to that ?7.5/4 "A linkage-specification shall occur only in namespace scope". And add to that ?14-4 "A template, a template explicit specialization, or a class-template partial specialization shall not have C linkage." This means that formally correct code that generates callbacks by templating, is ruled out. In practice, 'extern "C"' matters for the jump tables because for those few compilers if any where it really matters (not just the compiler emitting a warning like reportedly Sun CC does), different linkage can imply different machine code level calling convention. For example, who's responsible for cleaning up the stack, the order in which arguments are pushed or which registers they're passed in, and so forth. Ignoring such matters your code gets into la-la land pretty fast, but, it's a different matter when one /understands/ this and places a requirement on the compiler. > Good luck on re-inventing the wheel (you've probably heared about > Swig, SIP, Boost.Python, PyCXX, scipy.weave and Cython...) Yes, I know Boost.Python in more detail and I've heard of all the rest except SIP, but then regarding SIP I really don't like QT (QT makes eminent sense in the context of Python, they're both essentially dynamically typed, but that means QT is not very nice as C++, plus there is the ugly preprocessor). And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not reinventing the wheel. Cheers & hth., - Alf -- blog at From tim at johnsons-web.com Tue Jul 13 16:47:31 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Tue, 13 Jul 2010 15:47:31 -0500 Subject: Hello References: <20100710120048.39c9a613@geekmail.INVALID> Message-ID: On 2010-07-10, Andreas Waldenburger wrote: > On Fri, 9 Jul 2010 16:49:20 +0000 (UTC) Grant Edwards > wrote: > >> On 2010-07-09, Dani Valverde wrote: >> >> > I am new to python and pretty new to programming (I have some >> > expertise wit R statistical programming language). I am just >> > starting, so my questions may be a little bit stupid. Can anyone >> > suggest a good editor for python? >> >> Emacs, Scite (has nice folding), Vim, Eclipse. >> > Great tips for a newbie. > > Not. > > Well, they might be, but chances are, they are overkill for people new > to programming and will only alienate them (Scite may be an exception). > Text editors are an acquired taste. Emacs and Vim are very difficult to learn. Emacs more so than vim (even with vim's modal style of editing IMHO). However, to suggest that either might alienate someone new to programming presupposes some metric on their ability to learn. Since I am not privy to that metric, read on: As linux programmer, I use vim for python, javascript, rebol and adhoc system management and emacs for lispish programmer languages. 1)Most releases of vim (such as those available from ubuntu repositories) are compiled with the python binary embedded. Thus one could customize vim using python itself. 2)Emacs is itself a design environment based on the elisp programming language and both of these. The time spent on learning either of these could pay off in the long run, *but it would be a long run*. Vim and emacs are available for Windows. When I programmed in Windows I used two different editors: Pythowin, obviously coming with the python for windows distribution. Pythonwin is great and very 'helpful'. Boxer - a freeware programmer's editor, that has the best balance of configurability and ease of use of any editor that I have used. But it has been years since I used either. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com From rdilipk at lycos.com Tue Jul 13 16:47:48 2010 From: rdilipk at lycos.com (Dilip) Date: Tue, 13 Jul 2010 13:47:48 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> Message-ID: <133f8384-9944-4d61-b159-9af216c178ec@z8g2000yqz.googlegroups.com> On Jul 13, 2:34?am, "Alf P. Steinbach /Usenet" wrote: > Well, we got no further, but I know of three solutions: > > ? ?A) Punting: just say that the compiler has to support C++/C function type > ? ? ? mingling. > ? ? ? -> Perhaps the practical solution, but formally unsafe. > > ? ?B) On the script side of things, delegate all calls to single Mother Of All > ? ? ? C func downcaller that supplies as extra arg an id of the C++ function. > ? ? ? -> Micro-level inefficient but easy to use and formally correct. > > ? ?C) Let the user define the C linkage function wrappers via macros. > ? ? ? -> Efficient and formally correct but exposes ugly macro names. > > I chose (C). Alf This may or may not be what you are looking for but the middleware Ice provides language mapping to enable Python to call into the Ice libraries which are basically written in C++. You can take a look at this: http://www.zeroc.com/icepy.html However that page may not be very descriptive. The codebase, though, is freely downloadable. You can take a look at it if that will help although you need to wade around a little bit to figure out what is where. From sturlamolden at yahoo.no Tue Jul 13 17:17:14 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 14:17:14 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: On 13 Jul, 22:35, "Alf P. Steinbach /Usenet" wrote: > In practice, 'extern "C"' matters for the jump tables because for those few > compilers if any where it really matters (not just the compiler emitting a > warning like reportedly Sun CC does), different linkage can imply different > machine code level calling convention. I see. Just stick to MSVC and GNU and that never happens, just do a C style cast. > Yes, I know Boost.Python in more detail and I've heard of all the rest except > SIP, but then regarding SIP I really don't like QT You don't have to use Qt to use SIP. It's just a tool to automatically wrap C++ for Python (like Swig, except designed for C++). > And as you'd guess if you were not in silly ignoramus assertion-mode, I'm not > reinventing the wheel. It seems you are re-inventing PyCXX (or to a lesser extent Boost.Python). From ramercer at gmail.com Tue Jul 13 17:18:00 2010 From: ramercer at gmail.com (Adam Mercer) Date: Tue, 13 Jul 2010 16:18:00 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem Message-ID: Hi I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a and it is failing with the following: 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c 106 :info:build swig -python -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a pointer/reference variable may leak memory. 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a pointer/reference variable may leak memory. 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a pointer/reference variable may leak memory. 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a pointer/reference variable may leak memory. 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a pointer/reference variable may leak memory. 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a pointer/reference variable may leak memory. 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a pointer/reference variable may leak memory. 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a pointer/reference variable may leak memory. 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a pointer/reference variable may leak memory. 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a pointer/reference variable may leak memory. 117 :info:build SWIG/_util.i:9: Warning 454: Setting a pointer/reference variable may leak memory. 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a pointer/reference variable may leak memory. 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a pointer/reference variable may leak memory. 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -I/opt/local/include -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG -c SWIG/_m2crypto_wrap.c -o build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 138 :info:build SWIG/_m2crypto_wrap.c: At top level: 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in signedness 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in signedness 151 :info:build SWIG/_m2crypto_wrap.c: At top level: 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token 156 :info:build SWIG/_m2crypto_wrap.c:6081: error: expected declaration specifiers or '...' before 'STACK' 157 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': 158 :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared (first use in this function) 159 :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared identifier is reported only once 160 :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function it appears in.) 161 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_entry_create_by_txt': 162 :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in signedness 163 :info:build SWIG/_m2crypto_wrap.c: At top level: 164 :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 165 :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token 166 :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token 167 :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 168 :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token 169 :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token 170 :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token 171 :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token 172 :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token 173 :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 174 :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token 175 :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token 176 :info:build SWIG/_m2crypto_wrap.c:6385: error: expected declaration specifiers or '...' before 'STACK' 177 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': 178 :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared (first use in this function) 179 :info:build SWIG/_m2crypto_wrap.c: At top level: 180 :info:build SWIG/_m2crypto_wrap.c:6390: error: expected declaration specifiers or '...' before 'STACK' 181 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': 182 :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared (first use in this function) 183 :info:build SWIG/_m2crypto_wrap.c: At top level: 184 :info:build SWIG/_m2crypto_wrap.c:6418: error: expected declaration specifiers or '...' before 'STACK' 185 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': 186 :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared (first use in this function) 187 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument 3 of 'pkcs7_verify1' from incompatible pointer type 188 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument 4 of 'pkcs7_verify1' makes integer from pointer without a cast 189 :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments to function 'pkcs7_verify1' 190 :info:build SWIG/_m2crypto_wrap.c: At top level: 191 :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 192 :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': 193 :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets in passing argument 1 of 'PyString_FromStringAndSize' differ in signedness 194 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': 195 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared (first use in this function) 196 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' undeclared (first use in this function) 197 :info:build SWIG/_m2crypto_wrap.c:16913: error: expected expression before ')' token 198 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': 199 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared (first use in this function) 200 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared (first use in this function) 201 :info:build SWIG/_m2crypto_wrap.c:16923: error: expected expression before ')' token 202 :info:build SWIG/_m2crypto_wrap.c:16934: error: expected expression before ')' token 203 :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit declaration of function 'sk_ssl_cipher_num' 204 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': 205 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared (first use in this function) 206 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared (first use in this function) 207 :info:build SWIG/_m2crypto_wrap.c:16953: error: expected expression before ')' token 208 :info:build SWIG/_m2crypto_wrap.c:16968: error: expected expression before ')' token 209 :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit declaration of function 'sk_ssl_cipher_value' 210 :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer from integer of different size 211 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_peer_cert_chain': 212 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared (first use in this function) 213 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' undeclared (first use in this function) 214 :info:build SWIG/_m2crypto_wrap.c:17006: error: expected expression before ')' token 215 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': 216 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared (first use in this function) 217 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared (first use in this function) 218 :info:build SWIG/_m2crypto_wrap.c:17016: error: expected expression before ')' token 219 :info:build SWIG/_m2crypto_wrap.c:17027: error: expected expression before ')' token 220 :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit declaration of function 'sk_x509_num' 221 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': 222 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared (first use in this function) 223 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared (first use in this function) 224 :info:build SWIG/_m2crypto_wrap.c:17046: error: expected expression before ')' token 225 :info:build SWIG/_m2crypto_wrap.c:17061: error: expected expression before ')' token 226 :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit declaration of function 'sk_x509_value' 227 :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer from integer of different size 228 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_name_entry_set_data': 229 :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets in assignment differ in signedness 230 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_store_ctx_get1_chain': 231 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared (first use in this function) 232 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' undeclared (first use in this function) 233 :info:build SWIG/_m2crypto_wrap.c:19741: error: expected expression before ')' token 234 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': 235 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared (first use in this function) 236 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' undeclared (first use in this function) 237 :info:build SWIG/_m2crypto_wrap.c:20573: error: expected expression before ')' token 238 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': 239 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared (first use in this function) 240 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared (first use in this function) 241 :info:build SWIG/_m2crypto_wrap.c:20583: error: expected expression before ')' token 242 :info:build SWIG/_m2crypto_wrap.c:20593: error: expected expression before ')' token 243 :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit declaration of function 'sk_x509_free' 244 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': 245 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared (first use in this function) 246 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared (first use in this function) 247 :info:build SWIG/_m2crypto_wrap.c:20609: error: expected expression before ')' token 248 :info:build SWIG/_m2crypto_wrap.c:20624: error: expected expression before ')' token 249 :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit declaration of function 'sk_x509_push' 250 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': 251 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared (first use in this function) 252 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared (first use in this function) 253 :info:build SWIG/_m2crypto_wrap.c:20653: error: expected expression before ')' token 254 :info:build SWIG/_m2crypto_wrap.c:20664: error: expected expression before ')' token 255 :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit declaration of function 'sk_x509_pop' 256 :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer from integer of different size 257 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509_req_add_extensions': 258 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared (first use in this function) 259 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared (first use in this function) 260 :info:build SWIG/_m2crypto_wrap.c:20871: error: expected expression before ')' token 261 :info:build SWIG/_m2crypto_wrap.c:20890: error: expected expression before ')' token 262 :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments to function 'x509_req_add_extensions' 263 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': 264 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared (first use in this function) 265 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' undeclared (first use in this function) 266 :info:build SWIG/_m2crypto_wrap.c:20981: error: expected expression before ')' token 267 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_set_conf_lhash': 268 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared (first use in this function) 269 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared (first use in this function) 270 :info:build SWIG/_m2crypto_wrap.c:20991: error: expected expression before ')' token 271 :info:build SWIG/_m2crypto_wrap.c:21002: error: expected expression before ')' token 272 :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit declaration of function 'x509v3_set_conf_lhash' 273 :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer from integer of different size 274 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': 275 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared (first use in this function) 276 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared (first use in this function) 277 :info:build SWIG/_m2crypto_wrap.c:21013: error: expected expression before ')' token 278 :info:build SWIG/_m2crypto_wrap.c:21038: error: expected expression before ')' token 279 :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit declaration of function 'x509v3_ext_conf' 280 :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer from integer of different size 281 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_new_null': 282 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared (first use in this function) 283 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' undeclared (first use in this function) 284 :info:build SWIG/_m2crypto_wrap.c:21116: error: expected expression before ')' token 285 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_free': 286 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared (first use in this function) 287 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared (first use in this function) 288 :info:build SWIG/_m2crypto_wrap.c:21126: error: expected expression before ')' token 289 :info:build SWIG/_m2crypto_wrap.c:21136: error: expected expression before ')' token 290 :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit declaration of function 'sk_x509_extension_free' 291 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_push': 292 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared (first use in this function) 293 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared (first use in this function) 294 :info:build SWIG/_m2crypto_wrap.c:21152: error: expected expression before ')' token 295 :info:build SWIG/_m2crypto_wrap.c:21167: error: expected expression before ')' token 296 :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit declaration of function 'sk_x509_extension_push' 297 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_pop': 298 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared (first use in this function) 299 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared (first use in this function) 300 :info:build SWIG/_m2crypto_wrap.c:21191: error: expected expression before ')' token 301 :info:build SWIG/_m2crypto_wrap.c:21202: error: expected expression before ')' token 302 :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit declaration of function 'sk_x509_extension_pop' 303 :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer from integer of different size 304 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_num': 305 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared (first use in this function) 306 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared (first use in this function) 307 :info:build SWIG/_m2crypto_wrap.c:21218: error: expected expression before ')' token 308 :info:build SWIG/_m2crypto_wrap.c:21229: error: expected expression before ')' token 309 :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit declaration of function 'sk_x509_extension_num' 310 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_extension_value': 311 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared (first use in this function) 312 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared (first use in this function) 313 :info:build SWIG/_m2crypto_wrap.c:21248: error: expected expression before ')' token 314 :info:build SWIG/_m2crypto_wrap.c:21263: error: expected expression before ')' token 315 :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit declaration of function 'sk_x509_extension_value' 316 :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer from integer of different size 317 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_make_stack_from_der_sequence': 318 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared (first use in this function) 319 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' undeclared (first use in this function) 320 :info:build SWIG/_m2crypto_wrap.c:21314: error: expected expression before ')' token 321 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_get_der_encoding_stack': 322 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared (first use in this function) 323 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared (first use in this function) 324 :info:build SWIG/_m2crypto_wrap.c:21324: error: expected expression before ')' token 325 :info:build SWIG/_m2crypto_wrap.c:21335: error: expected expression before ')' token 326 :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit declaration of function 'get_der_encoding_stack' 327 :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer from integer of different size 328 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': 329 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared (first use in this function) 330 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared (first use in this function) 331 :info:build SWIG/_m2crypto_wrap.c:22343: error: expected expression before ')' token 332 :info:build SWIG/_m2crypto_wrap.c:22366: error: expected expression before ')' token 333 :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit declaration of function 'pkcs7_encrypt' 334 :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer from integer of different size 335 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': 336 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared (first use in this function) 337 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared (first use in this function) 338 :info:build SWIG/_m2crypto_wrap.c:22547: error: expected expression before ')' token 339 :info:build SWIG/_m2crypto_wrap.c:22582: error: expected expression before ')' token 340 :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument 4 of 'pkcs7_sign1' makes integer from pointer without a cast 341 :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments to function 'pkcs7_sign1' 342 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': 343 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared (first use in this function) 344 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared (first use in this function) 345 :info:build SWIG/_m2crypto_wrap.c:22628: error: expected expression before ')' token 346 :info:build SWIG/_m2crypto_wrap.c:22659: error: expected expression before ')' token 347 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument 3 of 'pkcs7_verify1' from incompatible pointer type 348 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument 4 of 'pkcs7_verify1' makes integer from pointer without a cast 349 :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments to function 'pkcs7_verify1' 350 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': 351 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared (first use in this function) 352 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared (first use in this function) 353 :info:build SWIG/_m2crypto_wrap.c:22707: error: expected expression before ')' token 354 :info:build SWIG/_m2crypto_wrap.c:22734: error: expected expression before ')' token 355 :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument 3 of 'pkcs7_verify0' makes integer from pointer without a cast 356 :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments to function 'pkcs7_verify0' 357 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': 358 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared (first use in this function) 359 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared (first use in this function) 360 :info:build SWIG/_m2crypto_wrap.c:23188: error: expected expression before ')' token 361 :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' undeclared (first use in this function) 362 :info:build SWIG/_m2crypto_wrap.c:23211: error: expected expression before ')' token 363 :info:build SWIG/_m2crypto_wrap.c:23227: error: expected expression before ')' token 364 :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 Anyone know a way to resolve this? Cheers Adam From alf.p.steinbach+usenet at gmail.com Tue Jul 13 17:22:24 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Tue, 13 Jul 2010 23:22:24 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> Message-ID: * sturlamolden, on 13.07.2010 22:06: > On 13 Jul, 21:39, "Alf P. Steinbach /Usenet" +use... at gmail.com> wrote: > >> Thanks! It seems that SCXX does those things that I've been planning to do but >> haven't got around to (wrapping standard Python types), while what it doesn't do >> (abstracting away all those tables etc. and mapping Python calls to C++ calls) >> is what I've been working on. Which could be a Very Nice combination except that >> I'm assuming Py3, while SCXX seems to be Py2 only. :-( > > I'd suggest PyCXX instead. http://cxx.sourceforge.net > > SCXX is a tiny wrapper mostly used in scipy.weave to inline C++ in > Python. Thanks. I looked up your URL, and PyCXX design goals seem to be much like what I'm doing, but different in some crucial ways. It's probably great, but it's not to my taste. E.g. the PyCXX String class interface: explicit String( PyObject *pyob, bool owned = false ) String( const Object &ob ) String() String( const char *latin1 ) String( const char *latin1, Py_ssize_t size ) String( const std::string &latin1 ) String( const std::string &v, const char *encoding, const char *error=NULL ) String( const char *s, const char *encoding, const char *error=NULL ) String( const char *s, Py_ssize_t len, const char *encoding, const char *error=NULL ) String & operator=( const Object &o ) String & operator=( PyObject *p ) String & operator=( const unicodestring &v ) size_type size() const size_type capacity() const unicodestring as_unicodestring() const std::string operator std::string() const String encode( const char *encoding, const char *error="strict" ) std::string as_std_string( const char *encoding=NULL, const char *error="strict" ) const In C++ the only way to portably specify a string literal with national characters, is as a wide string literal. Otherwise the result depends on the source code encoding. Yet PyCXX's String does not support wchar_t. Also, things like the 'owned' option is just asking for trouble. I chose this example because a Python string wrapper is the only object wrapper (apart from a general PyPtr) that I've implemented so far. The PyCXX string wrapper fails the design criterions of general usability (including in particular lack of wide char support) and safety (in particular the 'owned' option). And it's underdocumented, like, what encoding does the operator std::string() produce? The details don't matter though. I'm sure that PyCXX is Very Nice for its purpose, as is e.g. Boost.Python (which is Very Very Nice for its purpose). :-) Cheers, & thanks for the link, - Alf -- blog at From sturlamolden at yahoo.no Tue Jul 13 17:28:09 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 13 Jul 2010 14:28:09 -0700 (PDT) Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <8654fa32-1f26-4205-bde8-be5c393040ea@z10g2000yqb.googlegroups.com> Message-ID: <67a0404a-6273-4461-912a-9c960e22d8cb@t10g2000yqg.googlegroups.com> On 13 Jul, 22:35, "Alf P. Steinbach /Usenet" wrote: > Yes, I know Boost.Python in more detail and I've heard of all the rest except > SIP, In my opinion, SIP is the easiest way of integrating C++ and Python. Just ignore the PyQt stuff. http://www.riverbankcomputing.co.uk/static/Docs/sip4/using.html#a-simple-c-example http://www.riverbankcomputing.co.uk/software/sip/intro (SIP 4 can also expose C libraries to Python, not just C++.) From thomas at jollans.com Tue Jul 13 17:35:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 13 Jul 2010 23:35:01 +0200 Subject: adodb.NewADOConnection('postgres') returns None In-Reply-To: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: <4C3CDC05.9010809@jollans.com> On 07/13/2010 09:55 PM, micayael wrote: > Hi. > > I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 > the adodb and psycopg2 module (sudo apt-get install python-adodb > python-psycopg2) but when I put this > > import adodb > print adodb.NewADOConnection('postgres') --> None > > but with > > print adodb.NewADOConnection('mysql') --> > http://packages.ubuntu.com/lucid/python-adodb Recommends: python-psycopg (Package not available) If it says it wants psycopg, I wouldn't expect it to work with psycopg2, which is probably quite different in some way - otherwise it would be called the same. - Thomas From philip at semanchuk.com Tue Jul 13 17:54:43 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 13 Jul 2010 17:54:43 -0400 Subject: executing python scripts within wx frames In-Reply-To: <4C3C82F8.5060402@al.com.au> References: <4C3C82F8.5060402@al.com.au> Message-ID: <4A875FB1-4257-4517-858C-DC7BC8CBCEA2@semanchuk.com> On Jul 13, 2010, at 11:15 AM, Astan Chee wrote: > Hi, > I'm trying to make one of those frames thats similar to the wx > python demo where a folder is filled with demo wx python scripts and > there is one main script that opens the other ones in as different > items in a tree/notebook. > I've gotten most of it figured out except the part where the scripts > are executed in a wx frame. The difference between what I'm trying > to do and the wx python demo one is that mine are generic scripts > that output the results to std out/error (or whatever gets displayed > in IDLE). Does anyone know how I can do this? Simulate a IDLE or > python shell in one of the frames thats basically the output of > whatever script has been selected to run? > It would be better if the solution was platform independent too. Hi Astan, The subprocess module allows you to capture the stdin/stdout/stderr of a process that you launch. This sounds like what you're looking for. bye Philip From knny.myer at gmail.com Tue Jul 13 18:00:44 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Tue, 13 Jul 2010 18:00:44 -0400 Subject: Check if a command is valid In-Reply-To: References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <20100713220044.GD5162@5732Z> Chris Rebert (clp2 at rebertia.com) wrote: > On Mon, Jul 12, 2010 at 6:29 PM, Kenny Meyer wrote: > > Hello, > > > > I have to figure out if a string is callable on a Linux system. I'm > > "callable" seems vague. Is a command string with invalid arguments but > a valid executable "callable"? If no, then there's no general way to > test "callability" without actually running the command. I'm glad you pointed that out, because you're right. I subconciously meant a file that is in the $PATH. [snip] > > Well, you're not gonna be able to get the command's return code > without actually running it (unless perhaps you're referring to a > return code from the shell itself?). > > > What are better ways of doing this? > > One idea: > > from shlex import split as shell_tokenize > from subprocess import check_output > > def is_valid_command(command): > try: > executable = shell_tokenize(command)[0] > except (ValueError, IndexError):# invalid shell syntax > return False > return bool(check_output(['which', executable]))# on the PATH? > I have tried this and found some unexpected issues with Python 2.6 which I though I should point out: Firstly, the function `check_output` in the `subprocess` module only comes with Python 2.7, but I have found a similar function called `check_call` [1] which seems is similar, but not the same. [1] http://docs.python.org/library/subprocess.html#subprocess.check_call The code now looks like this: from shlex import split as shell_tokenize from subprocess import check_call, CalledProcessError def is_valid_command(command): try: executable = shell_tokenize(command)[0] check_call(['which', executable]) # Raises CalledProcessError if # something went wrong return True except (ValueError, IndexError, CalledProcessError): # Catch exception if there # was an error calling the process return False The idea with `which` is really great one. Thanks a lot, for your time and your input. -- Onward and upwards, Kenny Meyer -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From python at bdurham.com Tue Jul 13 18:19:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 13 Jul 2010 18:19:07 -0400 Subject: Cross-platform module that creates directory object with all file attributes In-Reply-To: <4C3CC796.9010704@timgolden.me.uk> References: <1279036606.15881.1384667215@webmail.messagingengine.com> <4C3CC796.9010704@timgolden.me.uk> Message-ID: <1279059547.25615.1384729753@webmail.messagingengine.com> Hi Tim, > Can't help you with x-platform; but for Windows I can offer my winsys package. > if f.readonly: > print f.created_at, f I like your logical model - that's exactly what I was looking for. Thank you for sharing your code. Cheers, Malcolm From johannes.black at gmail.com Tue Jul 13 19:24:22 2010 From: johannes.black at gmail.com (joblack) Date: Tue, 13 Jul 2010 16:24:22 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: All right I found the web link. It's an improvement to the pdf miner project (adds pdf dump methods). http://pastebin.com/P8SWj5YK From gherron at digipen.edu Tue Jul 13 19:26:53 2010 From: gherron at digipen.edu (Gary Herron) Date: Tue, 13 Jul 2010 16:26:53 -0700 Subject: floatref In-Reply-To: <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: <4C3CF63D.20008@digipen.edu> On 07/13/2010 03:02 PM, Roald de Vries wrote: > Hi Gary, > > On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>> Hi all, >>> >>> I have two objects that should both be able to alter a shared float. >>> So i need something like a mutable float object, or a float reference >>> object. Does anybody know if something like that exists? I know it's >>> not hard to build, but I have a feeling that there should be a >>> standard solution to it. >>> >>> Roald >> >> Huh? I must be missing something here. Isn't this what you use a >> variable for: > > Maybe I didn't explain well: > > >>> shared_var = 1.0 > >>> x.var = shared_var > >>> y.var = shared_var > >>> x.var = 2.0 > >>> y.var > 1.0 > > I wanted y.var and x.var to point to the same value, so that always > x.var == y.var. So that the last line becomes: > > >>> y.var > 2.0 > > Cheers, Roald Please keep responses and further discussions on list.python-list at python.org instead of using private emails. Python does not have pointers, so if I take your wording"y.var and x.var to point to the same value" literally, then the answer is NO Python does not do that. However, Python does have references all over the place, so you can achieve something similar in many ways. If x and y in your example code are instances of a class, than look into using a property for x.var and y.var. A property is a thing that looks like an attribute, (that would be var in x.var and y.var), but which really executes getter/setter code when accessed. That getter/setter code would then access/set the value in shared_var: shared_var = 123 class Thing(object): def get_var(self): return shared_var def set_var(self, v): global shared_var shared_var = v var = property(get_var, set_var) x = Thing() y = Thing() print x.var, y.var # prints: 123 123 x.var = 99 print x.var, y.var # prints: 99 99 -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From news1234 at free.fr Tue Jul 13 19:49:10 2010 From: news1234 at free.fr (News123) Date: Wed, 14 Jul 2010 01:49:10 +0200 Subject: nicer way to remove prefix of a string if it exists Message-ID: <4c3cfb76$0$20964$426a74cc@news.free.fr> I wondered about a potentially nicer way of removing a prefix of a string if it exists. Here what I tried so far: def rm1(prefix,txt): if txt.startswith(prefix): return txt[len(prefix):] return txt for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: # method 1 inline prefix = "file://" if f.startswith(prefix): rslt = f[len(prefix):] else rsl = f # method 2 as function rslt = rm1('file://',f) Is there any nicer function than above rm1()? Is there any nicer inline statement rhan my method 1' ? From juanknebel at gmail.com Tue Jul 13 19:51:24 2010 From: juanknebel at gmail.com (Juan Andres Knebel) Date: Tue, 13 Jul 2010 20:51:24 -0300 Subject: guia de python 2.6.4 en castellano In-Reply-To: References: Message-ID: Hola, esto tal vez te pueda ayudar, no es para 2.6.4 pero sirve igual. http://www.espaciolinux.com/2009/01/tutorial-%E2%80%9Cpython-para-todos%E2%80%9D-en-espanol/ Igualmente esto es una lista en ingles, por lo que si necesitas ayuda en espanol te recomiendo la lista python en dicho idioma Saludos 2010/7/13 Ruben ruben > buenos dias mi nombre es ruben queria ver si me podian mandar la guia de > python 2.6.4 en castellano yo baje el programa python pero en ingles y mi > ingles es muy regular desde ya muchas gracias muy bueno el programa python > ------------------------------ > Descubr? un nuevo Hotmail: con m?s herramientas para una vida m?s pr?ctica. > Muy pronto. Ver m?s > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Juan Andres Knebel -------------- next part -------------- An HTML attachment was scrubbed... URL: From juanknebel at gmail.com Tue Jul 13 20:08:21 2010 From: juanknebel at gmail.com (Juan Andres Knebel) Date: Tue, 13 Jul 2010 21:08:21 -0300 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4c3cfb76$0$20964$426a74cc@news.free.fr> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: Hi, for rm1 I think something like this could work: def rm1(prefix,txt): regular_expresion = re.compile(r''+prefix+'(.*)') return re.match(regular_expresion,txt).group(1) On Tue, Jul 13, 2010 at 8:49 PM, News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > > > Here what I tried so far: > > > def rm1(prefix,txt): > if txt.startswith(prefix): > return txt[len(prefix):] > return txt > > > for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: > # method 1 inline > prefix = "file://" > if f.startswith(prefix): > rslt = f[len(prefix):] > else > rsl = f > # method 2 as function > rslt = rm1('file://',f) > > > Is there any nicer function than above rm1()? > Is there any nicer inline statement rhan my method 1' ? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Juan Andres Knebel -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Jul 13 20:12:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jul 2010 01:12:27 +0100 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4c3cfb76$0$20964$426a74cc@news.free.fr> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: <4C3D00EB.1010203@mrabarnett.plus.com> News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > > > Here what I tried so far: > > > def rm1(prefix,txt): > if txt.startswith(prefix): > return txt[len(prefix):] > return txt > > > for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: > # method 1 inline > prefix = "file://" > if f.startswith(prefix): > rslt = f[len(prefix):] > else > rsl = f > # method 2 as function > rslt = rm1('file://',f) > > > Is there any nicer function than above rm1()? No. > Is there any nicer inline statement rhan my method 1' ? > You could write: rsl = f[len(prefix):] if f.startswith(prefix) else f in recent versions of Python, but the function is neater. From drsalists at gmail.com Tue Jul 13 20:30:14 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 13 Jul 2010 17:30:14 -0700 Subject: How is Unladen Swallow coming along? In-Reply-To: <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> References: <4c360004$0$1607$742ec2ed@news.sonic.net> <83789a67-8273-498e-abf6-92adb1413e5d@e5g2000yqn.googlegroups.com> Message-ID: 2010/7/8 Luis M. Gonz?lez > On Jul 8, 1:42 pm, John Nagle wrote: > > How is Unladen Swallow coming along? Looking at the site, code is > > being checked in and issues are being reported, but the last quarterly > > release was 2009 Q3. They missed their January 2010 release date > > for "2009 Q4", so they're now about 6 months behind their project > > plan. > > > > ("http://code.google.com/p/unladen-swallow/wiki/ProjectPlan") > > > > John Nagle > > Don't be shy. > Ask this question in Unladen Swallow's google group. They don't bite! I'm not the O.P., but I was curious too, so I asked on an Unladen Swallow mailing list. The response was that progress on Unladen Swallow is still occurring, and is focused on merging things into the py3k-jit branch of the official python repo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Jul 13 20:32:48 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 14 Jul 2010 10:32:48 +1000 Subject: Errno 9] Bad file descriptor In-Reply-To: References: Message-ID: <20100714003248.GA23169@cskk.homeip.net> On 13Jul2010 05:56, joblack wrote: | Thanks for the answers so far. It's not my code I'm just curious how | that could happen: | | Starting point: | ... | self.status['text'] = 'Processing ...' | try: | cli_main(argv) | except Exception, e: | self.status['text'] = 'Error: ' + str(e) | return | ... | cli_main: | | keypath, inpath, outpath = argv[1:] | ... | with open(inpath, 'rb') as inf: | serializer = PDFSerializer(inf, keypath) | with open(outpath, 'wb') as outf: | filenr = outf.fileno() | serializer.dump(outf) | return 0 | | PDFSerializer.dump: | | def dump(self, outf): | self.outf = outf | ... See that you set serializer.outf to the outf you open in cli_main? Any attempt to use serializer _after_ exiting the "with open(outpath, 'wb') as outf" will use serializer.outf, but the outf is now closed. And thus its file descriptor is invalid. BTW, by catching Exception in the starting point code you prevent yourself seeing exactly which line throws the error. It is usualy a bad idea to catch broad things like "Exception". It is normally better to place try/except around very small pieces of code and to catch very specific things. That way you know exactly what's going wrong and don't quietly catch all sorts of unplanned stuff. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ When buying and selling are controlled by legislation, the first things bought and sold are the legislators. - P.J. O'Rourke From aahz at pythoncraft.com Tue Jul 13 20:48:43 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Jul 2010 17:48:43 -0700 Subject: Why doesn't python's list append() method return the list itself? References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: [Original not available on my swerver, responding here] >On 7/11/10 10:03 PM, Nathan Rice wrote: >> >> Yeah, I long ago filed the in place place in the same folder as >> strings-as-sequences, all() returning True for an empty iterable and any >> returning True rather than the thing which triggered it. Because I love to repeat myself: "...string iteration isn't about treating strings as sequences of strings, it's about treating strings as sequences of characters. The fact that characters are also strings is the reason we have problems, but characters are strings for other good reasons." --Aahz http://mail.python.org/pipermail/python-3000/2006-April/000897.html Do you really want to give up Python's lovely string-slicing capabilities? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From tekion at gmail.com Tue Jul 13 21:15:58 2010 From: tekion at gmail.com (tekion) Date: Tue, 13 Jul 2010 18:15:58 -0700 (PDT) Subject: python ldap recursive Message-ID: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Hi, I know perl Net::LDAP could do a recursive search call to LDAP. What I am running into with Python LDAP on the search call is that I would l have to wait for the search to complete to get the result. Where as with Perl recursive search call, I would get the result (not the completed result) back while the search is still running. Does any know if we have something like this in Python LDAP module? Thanks. From alf.p.steinbach+usenet at gmail.com Tue Jul 13 21:19:36 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 03:19:36 +0200 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: * Gary Herron, on 14.07.2010 01:26: > On 07/13/2010 03:02 PM, Roald de Vries wrote: >> Hi Gary, >> >> On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >>> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>>> Hi all, >>>> >>>> I have two objects that should both be able to alter a shared float. >>>> So i need something like a mutable float object, or a float reference >>>> object. Does anybody know if something like that exists? I know it's >>>> not hard to build, but I have a feeling that there should be a >>>> standard solution to it. >>>> >>>> Roald >>> >>> Huh? I must be missing something here. Isn't this what you use a >>> variable for: >> >> Maybe I didn't explain well: >> >> >>> shared_var = 1.0 >> >>> x.var = shared_var >> >>> y.var = shared_var >> >>> x.var = 2.0 >> >>> y.var >> 1.0 >> >> I wanted y.var and x.var to point to the same value, so that always >> x.var == y.var. So that the last line becomes: >> >> >>> y.var >> 2.0 >> >> Cheers, Roald > > Please keep responses and further discussions on > list.python-list at python.org > instead of using private emails. Seconded. I didn't see that posting. > Python does not have pointers, so if I take your wording"y.var and x.var > to point to the same value" literally, then the answer is NO Python does > not do that. This is just a terminological issue. Saying "Python does not have pointers" is highly misleading in response to the OP's statement. It's easy enough to understand what he means. E.g., in the Java language specification "pointer" has a suitable meaning. And in general, the term "pointer" encompasses far more than the concept of a C or Pascal pointer, e.g., in C++ it includes offset-like things called member pointers. You can't represent or usefully think of a C++ member pointer as a C or Pascal pointer. It isn't useful on its own. So, considering C++ and Java, the general pointer notion is something that refers, however obliquely. You chose a specific meaning of "pointer" where the OP's statement does not make sense, but presumably the OP is explaining his needs in terms of a more general meaning of "pointer"; assuming anything else is silly. > However, Python does have references all over the place, so you can > achieve something similar in many ways. > > If x and y in your example code are instances of a class, than look into > using a property for x.var and y.var. A property is a thing that looks > like an attribute, (that would be var in x.var and y.var), but which > really executes getter/setter code when accessed. That getter/setter > code would then access/set the value in shared_var: > > > shared_var = 123 > > class Thing(object): > def get_var(self): > return shared_var > def set_var(self, v): > global shared_var > shared_var = v > > var = property(get_var, set_var) > > > x = Thing() > y = Thing() > > print x.var, y.var # prints: 123 123 > x.var = 99 > print x.var, y.var # prints: 99 99 This code goes through hoops to /hide/ the fact of the sharing. Rather, I'd make that as explicit as possible. Like, x = {"sharedVar": 123} y = x The one won't be surprised when changing x["sharedVar"] also changes y["sharedVar"]. Cheers & hth., - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 21:53:14 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 01:53:14 GMT Subject: floatref References: Message-ID: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > Hi all, > > I have two objects that should both be able to alter a shared float. So > i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's not > hard to build, but I have a feeling that there should be a standard > solution to it. One standard solution would be to wrap the float in a class as an attribute. Another is to put it in a list: myvalue = [3.1415] pi = myvalue myvalue[0] = 3.0 assert pi[0] == 3.0 A third standard solution is to create a mutable float using delegation. See the MutableStr class in the standard library for hints. An even better solution is to avoid the idiom of shared state in the first place. Whenever people say "I need shared data", the chances are very good that they don't *need* it at all, but merely *want* it because that's the idiom they're used to. But if you really need it, you can make it. -- Steven From anand.shashwat at gmail.com Tue Jul 13 22:22:15 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 07:52:15 +0530 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: <4C3D00EB.1010203@mrabarnett.plus.com> References: <4c3cfb76$0$20964$426a74cc@news.free.fr> <4C3D00EB.1010203@mrabarnett.plus.com> Message-ID: On Wed, Jul 14, 2010 at 5:42 AM, MRAB wrote: > News123 wrote: > >> I wondered about a potentially nicer way of removing a prefix of a >> string if it exists. >> >> >> Here what I tried so far: >> >> >> def rm1(prefix,txt): >> if txt.startswith(prefix): >> return txt[len(prefix):] >> return txt >> >> >> for f in [ 'file:///home/me/data.txt' , '/home/me/data.txt' ]: >> # method 1 inline >> prefix = "file://" >> if f.startswith(prefix): >> rslt = f[len(prefix):] >> else >> rsl = f >> # method 2 as function >> rslt = rm1('file://',f) >> >> >> Is there any nicer function than above rm1()? >> > > No. > > > Is there any nicer inline statement rhan my method 1' ? >> >> You could write: > > rsl = f[len(prefix):] if f.startswith(prefix) else f > Or you can just do split and join, "".join(f.split(prefix, 1)) will do. >>> prefix = 'file://' >>> f = 'file:///home/me/data.txt' >>> "".join(f.split(prefix, 1)) '/home/me/data.txt' >>> f = 'file:///home/me/data.txtfile://' >>> "".join(f.split(prefix, 1)) '/home/me/data.txtfile://' >>> f = '/home/me/data.txt' >>> "".join(f.split(prefix, 1)) '/home/me/data.txt' -------------- next part -------------- An HTML attachment was scrubbed... URL: From barzhomi at gmail.com Tue Jul 13 22:37:08 2010 From: barzhomi at gmail.com (=?KOI8-R?B?4sHWxc4g8tbF1dTTy8nK?=) Date: Wed, 14 Jul 2010 09:37:08 +0700 Subject: Problem with executing python interpretetor on special build of win server 2003 In-Reply-To: References: Message-ID: Hello. Actual problem in the next, when i trying to execute portable python on my build then nothing happens, and the error code is 128. What does mean this code 128? -------------- next part -------------- An HTML attachment was scrubbed... URL: From superjuicylady4 at gmail.com Tue Jul 13 22:40:01 2010 From: superjuicylady4 at gmail.com (superjuicylady) Date: Tue, 13 Jul 2010 19:40:01 -0700 (PDT) Subject: FREE HOT SEX DATES FOR YOU RIGHT NOW Message-ID: <2c93ea89-f0e7-4d39-9f79-6a9cc4205d0b@n8g2000prh.googlegroups.com> if you are feeling bored but hot right now? well just click this safe and secured link for your privacy and enjoy. copy and paste it in your browser if it isnt linked please wait for 1 minute for the site to load free stuff -----> http://u-gfi5eq0m0h.urlcash.net free porn -----> http://u-xfhkxxpjz0.urlcash.net latest movies-----> http://254d9bd5.zxxo.net free games -----> http://5efb70b9.uberpicz.com Enjoy and read instructions very well From cdalten at gmail.com Tue Jul 13 23:03:14 2010 From: cdalten at gmail.com (chad) Date: Tue, 13 Jul 2010 20:03:14 -0700 (PDT) Subject: python namespace question Message-ID: Given the following code... #!/usr/bin/python class cgraph: def printme(self): print "hello\n" x = cgraph() x.printme() Does the function print() exist in the cgraph namespace or the printme() one? From anand.shashwat at gmail.com Tue Jul 13 23:19:20 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 08:49:20 +0530 Subject: python namespace question In-Reply-To: References: Message-ID: On Wed, Jul 14, 2010 at 8:33 AM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > def printme(self): > print "hello\n" > No need to do print "hello\n", python is not C, print "hello" prints hello with a newline. Try it on interpretor. > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the > printme() one? > Where exactly is the print() function here. BTW printme() is in cgraph namespace. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From kentilton at gmail.com Tue Jul 13 23:24:12 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Tue, 13 Jul 2010 23:24:12 -0400 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: <4c3d2dcd$0$31270$607ed4bc@cv.net> Xah Lee wrote: > ? Death of Newsgroups > http://xahlee.org/UnixResource_dir/writ2/death_of_newsgroups.html > > plain text version follows. > > -------------------------------------------------- > Death of Newsgroups > > Xah Lee, 2010-07-13 > > Microsoft is closing down their newsgroups. See: > microsoft.public.windows.powershell. > > I use comp.lang.lisp, comp.emacs since about 1999. Have been using > them pretty much on a weekly basis in the past 10 years. Starting > about 2007, the traffic has been increasingly filled with spam, and > the posters are always just the 20 or 30 known faces. I think perhaps > maybe no more than 100 different posters a year. Since this year or > last year, they are some 95% spam. Forest. Trees. Please note order. Case in point: twelve weeks ago His Timness mentioned this on comp.lang.lisp; http://www.math.union.edu/~dpvc/jsMath/ Now we have this, a port of a desktop app to the web: http://teamalgebra.com/ It happened fast because http://qooxdoo.org/lets me program the Web without bothering with HTML and CSS and browser variation as if I were using a framework like GTk. I learned about qooxdoo... on comp.lang.lisp. The moral? If you look for the spam, you'll find it. kt -- http://www.teamalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:37:03 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:37:03 GMT Subject: python namespace question References: Message-ID: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > def printme(self): > print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the printme() > one? What function print()? You're calling the print STATEMENT. It doesn't exist in any namespace, it's a Python keyword like "if", "for", "return", and similar. Note: this changes in Python 3, where print becomes a function like len(), chr(), max(), and similar. In Python 3, you would write: print("hello\n") and the function lives in the built-in namespace. BTW, print (both versions) automatically prints a newline at the end of the output, so printing "hello\n" will end up with an extra blank line. Is that what you wanted? -- Steven From anand.shashwat at gmail.com Tue Jul 13 23:38:58 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 14 Jul 2010 09:08:58 +0530 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On Tue, Jul 13, 2010 at 6:59 AM, Kenny Meyer wrote: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? > Check your $PATH. All your system commands lies there. Make a list and save it. Now just check whether your 'command' lies in the list. However better is to run the command, but some commands like 'shutdown' won't be good for this I think. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:40:50 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:40:50 GMT Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> Message-ID: <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: > The moral? If you look for the spam, you'll find it. And if you *don't* look for spam, you can be sure that some goose will reply to it and get it past your filters. Thanks for that Kenneth, if that is your name and you're not a Xah Lee sock-puppet. Followups set to a black hole. -- Steven From steve-REMOVE-THIS at cybersource.com.au Tue Jul 13 23:43:41 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 03:43:41 GMT Subject: python ldap recursive References: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Message-ID: <4c3d326c$0$11091$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 18:15:58 -0700, tekion wrote: > Hi, > I know perl Net::LDAP could do a recursive search call to LDAP. What I > am running into with Python LDAP on the search call is that I would l > have to wait for the search to complete to get the result. Where as > with Perl recursive search call, I would get the result (not the > completed result) back while the search is still running. Does any know > if we have something like this in Python LDAP module? Thanks. What Python LDAP module are you using? -- Steven From cdalten at gmail.com Tue Jul 13 23:48:29 2010 From: cdalten at gmail.com (chad) Date: Tue, 13 Jul 2010 20:48:29 -0700 (PDT) Subject: python namespace question References: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Jul 13, 8:37?pm, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 20:03:14 -0700, chad wrote: > > Given the following code... > > > #!/usr/bin/python > > > class cgraph: > > ? ? def printme(self): > > ? ? ? ? print "hello\n" > > > x = cgraph() > > x.printme() > > > Does the function print() exist in the cgraph namespace or the printme() > > one? > > What function print()? You're calling the print STATEMENT. It doesn't > exist in any namespace, it's a Python keyword like "if", "for", "return", > and similar. > > Note: this changes in Python 3, where print becomes a function like > len(), chr(), max(), and similar. In Python 3, you would write: > > print("hello\n") > > and the function lives in the built-in namespace. > > BTW, print (both versions) automatically prints a newline at the end of > the output, so printing "hello\n" will end up with an extra blank line. > Is that what you wanted? > I could care less about the extra blank line. I guess I was just more concerned about the namespace question. From clp2 at rebertia.com Tue Jul 13 23:52:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Jul 2010 20:52:31 -0700 Subject: python namespace question In-Reply-To: References: Message-ID: On Tue, Jul 13, 2010 at 8:03 PM, chad wrote: > Given the following code... > > #!/usr/bin/python > > class cgraph: > ? ?def printme(self): > ? ? ? ?print "hello\n" > > x = cgraph() > x.printme() > > > Does the function print() exist in the cgraph namespace or the > printme() one? Neither. It exists in the built-ins namespace along with the rest of the built-in functions like len(), zip(), hex(), etc. The built-ins is the namespace of last resort; it's the last one to be consulted when trying to resolve a name in Python. You can inspect it via __builtins__ Also, in your example, print is being used as a statement (i.e. part of the language syntax), not a function; note the odd lack of parentheses when "calling" it. print was changed to a regular function in Python 3.x. Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 00:29:00 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 04:29:00 GMT Subject: python namespace question References: Message-ID: <4c3d3d0c$0$28657$c3e8da3@news.astraweb.com> On Tue, 13 Jul 2010 20:52:31 -0700, Chris Rebert wrote: > The built-ins is the > namespace of last resort; it's the last one to be consulted when trying > to resolve a name in Python. You can inspect it via __builtins__ Avoid __builtins__ as it is an implementation detail. The difference between __builtins__ and __builtin__ is one of the more confusing corners of Python, but the correct one to use is __builtin__. http://docs.python.org/library/__builtin__.html -- Steven From kse.listed.co1 at gmail.com Wed Jul 14 00:31:06 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Tue, 13 Jul 2010 21:31:06 -0700 (PDT) Subject: "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ Message-ID: <7cf3c527-90f4-43ec-9ff5-c2e805aa6077@a4g2000prm.googlegroups.com> "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ "SEXY HOLLYWOOD GIRLS" "SEXY BIKINI GIRLS" "SEXY CHINESE GIRLS" "SEXY PAKISTANI GIRLS" "SEXY INDIAN GIRLS" "SEXY EURO GIRLS" "WORLD OF SEX" "PRETTY SEXY GIRLS" "SEXY LONG LEGS GIRLS" ON http://hollywood-bollywood-sexy.blogspot.com/ V From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 00:31:54 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 04:31:54 GMT Subject: floatref References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> Message-ID: <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 03:19:36 +0200, Alf P. Steinbach /Usenet wrote: > Gary Herron wrote: >> Python does not have pointers, so if I take your wording"y.var and >> x.var to point to the same value" literally, then the answer is NO >> Python does not do that. > > This is just a terminological issue. "Just"? If people can't agree on terminology, they can't even understand each other, let alone communicate effectively. If I call you a fine fellow with a detailed grasp of programming and a helpful manner, but what I mean by "fine", "detailed" and "helpful" are different from what you mean by them, how can you tell if I've just complimented you or insulted you? Gary did the right thing by pointing out that the simple-sounding term "points to" is anything but simple, it depends on what you mean by pointing and pointers. > Saying "Python does not have > pointers" is highly misleading in response to the OP's statement. It's > easy enough to understand what he means. E.g., in the Java language > specification "pointer" has a suitable meaning. And in a Java language forum, that would arguably be the right meaning to assume. Possibly even in a Jython forum. But this is neither, it's a Python forum, where "Python" is typically understood to be CPython, not Jython and certainly not Java, and "pointer" is typically understood to mean C or Pascal pointers. In an English language forum, the correct meaning to use for "cafeteria" is a "dining hall", and not "fringe benefit" as it would be in a Hungarian forum. Likewise, the correct meaning to use for the word "gift" in an English forum is a present or object which is given, and not "poison" as a German might assume. [...] > You can't represent or usefully think of a C++ member pointer > as a C or Pascal pointer. It isn't useful on its own. So, considering > C++ and Java, the general pointer notion is something that refers, > however obliquely. So an integer like 3 counts as a pointer, as you can use it as an index into a list, array or other sequence. In that sense, yes, Python has pointers, and makes frequent use of them. You can even do pointer arithmetic! I don't think this position is terribly useful. It's possible to be *too* generic. > You chose a specific meaning of "pointer" where the > OP's statement does not make sense, but presumably the OP is explaining > his needs in terms of a more general meaning of "pointer"; assuming > anything else is silly. The Zen of Python includes: In the face of ambiguity, refuse the temptation to guess. Wise words, not just for programming. -- Steven From alf.p.steinbach+usenet at gmail.com Wed Jul 14 00:50:58 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 06:50:58 +0200 Subject: floatref In-Reply-To: <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano, on 14.07.2010 06:31: > > Gary did the right thing by pointing out that the simple-sounding term > "points to" is anything but simple, it depends on what you mean by > pointing and pointers. Possibly you have a point here. Cheers, - Alf -- blog at From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 01:05:15 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 05:05:15 GMT Subject: floatref References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4c3d3db9$0$28657$c3e8da3@news.astraweb.com> Message-ID: <4c3d458b$0$28657$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 06:50:58 +0200, Alf P. Steinbach /Usenet wrote: > Possibly you have a point here. Oh yeah? Don't think you can escape a flame war by agreeing with me! *wink* -- Steven From wuwei23 at gmail.com Wed Jul 14 01:46:32 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 13 Jul 2010 22:46:32 -0700 (PDT) Subject: python namespace question References: <4c3d30de$0$11091$c3e8da3@news.astraweb.com> Message-ID: <1606d351-6bd4-43bf-8723-159ecc351ebd@z30g2000prg.googlegroups.com> chad wrote: > I could care less about the extra blank line. I guess I was just more > concerned about the namespace question. Which is why Steven spent far more time answering that question than commenting on newline handling. Now say 'thank you'. From gnuist006 at gmail.com Wed Jul 14 02:01:39 2010 From: gnuist006 at gmail.com (bolega) Date: Tue, 13 Jul 2010 23:01:39 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: Message-ID: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> On Jun 20, 9:31?pm, Richard Fateman wrote: > Define Macro wrote: > > On Jun 13, 7:07 pm, bolega wrote: > >> I am trying to compare LISP/Scheme/Python for their expressiveness. > > >> For this, I propose a vanilla C interpreter. I have seen a book which > >> writes C interpreter in C. > > >> The criteria would be the small size and high readability of the code. > > >> Are there already answers anywhere ? > > Sure. ?Lots of texts on compilers provide exercises which, in one way or > another suggest how to write an interpreter and perhaps a compiler too > for some language. ?Anyone taking a course on compilers is likely to > have followed such exercises in order to pass the course. ?Some > instructors are enlightened enough to allow students to pick the > implementation language. > > Ask any such instructor. Beware, he does not tell the readers the financial details. This is what he wrote to me by email. I would be willing to meet with you here in Berkeley to educate you on these matters at a consulting rate of $850 per hour, with a minimum of 8 hours. RJF > I think you will find that many people use a packaged parser-generator > which eliminates much of the choice-of-language difference. Do you like > Bison, Yacc, Antlr, or one of the many parser generators in Lisp, > python, etc. > > My own experience is that in comparing Lisp to C, students end up with > smaller and better interpreters and compilers, faster. ?I don't know > about python vs C for sure, but I suspect python wins. ?As for > python vs Lisp, I don't know. > > RJF From debatem1 at gmail.com Wed Jul 14 02:18:10 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 13 Jul 2010 23:18:10 -0700 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> Message-ID: On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: > On Jun 20, 9:31?pm, Richard Fateman wrote: >> Define Macro wrote: >> > On Jun 13, 7:07 pm, bolega wrote: >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. >> >> >> For this, I propose a vanilla C interpreter. I have seen a book which >> >> writes C interpreter in C. >> >> >> The criteria would be the small size and high readability of the code. >> >> >> Are there already answers anywhere ? >> >> Sure. ?Lots of texts on compilers provide exercises which, in one way or >> another suggest how to write an interpreter and perhaps a compiler too >> for some language. ?Anyone taking a course on compilers is likely to >> have followed such exercises in order to pass the course. ?Some >> instructors are enlightened enough to allow students to pick the >> implementation language. >> >> Ask any such instructor. > > > > Beware, he does not tell the readers the financial details. This is > what he wrote to me by email. > > > I would be willing to meet with you here in Berkeley to educate you on > these matters at a consulting rate of ?$850 per hour, with a minimum > of 8 hours. > > RJF > He's Berkeley's former CS chair and was implementing lisp before common lisp was a twinkle in anybody's eye. His time is valuable. Geremy Condra From martin at v.loewis.de Wed Jul 14 02:30:46 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 14 Jul 2010 08:30:46 +0200 Subject: Python track at German Zope conference Message-ID: [Das ist im Wesentlichen eine Kopie einer Nachricht, die Dinu an die Python-DE-Liste geschickt hat.] >From September 15 to September 17, 2010, the German Zope conference (organized by DZUG) takes place in Dresden. It has tracks for Python, Zope, and Plone. Dinu Gherman and me are organizing the Python Track, and we are still looking for people interested in presenting Python related projects or topics. If so, please let us know, or submit your talk proposal to the conference site. Also, if you would like to come to the conference if a certain topic was presented, please let us know. You'll find more information on the conference at http://www.zope.de/tagung/Dresden_2010/call-for-papers Notice that there will be tutorials before the regular tracks, and sprints afterwards. Regards, Martin From no.email at nospam.invalid Wed Jul 14 02:35:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 13 Jul 2010 23:35:14 -0700 Subject: C interpreter in Lisp/scheme/python References: Message-ID: <7xoceao9jx.fsf@ruckus.brouhaha.com> bolega writes: > I am trying to compare LISP/Scheme/Python for their expressiveness... > Are there already answers anywhere ? > How would a gury approach such a project ? These two articles http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf http://www.haskell.org/papers/NSWC/jfp.ps about language comparisons (Python is in the first but not the second) might be of interest. If you want to know how to implement C, there is a pretty good book by Hanson and Fraser about LCC, called "A Retargetable C Compiler". Basically a code walkthrough of a small C compiler written in C. From maaindia0 at gmail.com Wed Jul 14 02:41:05 2010 From: maaindia0 at gmail.com (easy money) Date: Tue, 13 Jul 2010 23:41:05 -0700 (PDT) Subject: Simple hack to get $500 to your home. Message-ID: <5b42511e-4382-4567-896a-31228f560d5d@m35g2000prn.googlegroups.com> Simple hack to get $500 to your home at http://cashbygetpaypal.tk Due to high security risks,i have hidden the cheque link in an image. in that website on top side above search box, click on image and enter your name and address where you want to receive your cheque. please don,t tell to anyone. From downaold at gmail.com Wed Jul 14 03:56:08 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 09:56:08 +0200 Subject: floatref In-Reply-To: <4C3CF63D.20008@digipen.edu> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: On Jul 14, 2010, at 1:26 AM, Gary Herron wrote: > On 07/13/2010 03:02 PM, Roald de Vries wrote: >> Hi Gary, >> >> On Jul 13, 2010, at 8:54 PM, Gary Herron wrote: >>> On 07/13/2010 10:26 AM, Roald de Vries wrote: >>>> Hi all, >>>> >>>> I have two objects that should both be able to alter a shared >>>> float. >>>> So i need something like a mutable float object, or a float >>>> reference >>>> object. Does anybody know if something like that exists? I know >>>> it's >>>> not hard to build, but I have a feeling that there should be a >>>> standard solution to it. >>>> >>>> Roald >>> >>> Huh? I must be missing something here. Isn't this what you use a >>> variable for: >> >> Maybe I didn't explain well: >> >> >>> shared_var = 1.0 >> >>> x.var = shared_var >> >>> y.var = shared_var >> >>> x.var = 2.0 >> >>> y.var >> 1.0 >> >> I wanted y.var and x.var to point to the same value, so that always >> x.var == y.var. So that the last line becomes: >> >> >>> y.var >> 2.0 >> >> Cheers, Roald > > Please keep responses and further discussions on > list.python-list at python.org > instead of using private emails. Sorry. > Python does not have pointers, so if I take your wording"y.var and > x.var to point to the same value" literally, then the answer is NO > Python does not do that. Maybe I should have put it between quotes, but I used the words 'mutable float' and 'float reference' in the original post, and this was only an attempt to clarify better. > However, Python does have references all over the place, so you can > achieve something similar in many ways. I know, I just wondered if there is a *standard* solution. Cheers, Roald From downaold at gmail.com Wed Jul 14 04:11:54 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 10:11:54 +0200 Subject: floatref In-Reply-To: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> References: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> Message-ID: <7B2036EE-B050-4520-A5A3-6B3B1A53E702@gmail.com> On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > >> Hi all, >> >> I have two objects that should both be able to alter a shared >> float. So >> i need something like a mutable float object, or a float reference >> object. Does anybody know if something like that exists? I know >> it's not >> hard to build, but I have a feeling that there should be a standard >> solution to it. > > > One standard solution would be to wrap the float in a class as an > attribute. E.g.: a class FloatWrapper with a get and set method. Advantages: transparent, easy to implement Disadvantages: for 'f = FloatWrapper' you have to use 'f.set(1.0)' instead of 'f = 1.0', which reads less easily (I think), and a mistake like assigning with 'f = 1.0' is easily made. > Another is to put it in a list: > > myvalue = [3.1415] > pi = myvalue > myvalue[0] = 3.0 > assert pi[0] == 3.0 I thought about something like that, but it's a bit misleading, because the value is actually a list. > An even better solution is to avoid the idiom of shared state in the > first place. Whenever people say "I need shared data", the chances are > very good that they don't *need* it at all, but merely *want* it > because > that's the idiom they're used to. I want to simulate a distributed algorithm, in which components can only communicate through shared state. Cheers, Roald From lars at gustaebel.de Wed Jul 14 04:16:45 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Wed, 14 Jul 2010 10:16:45 +0200 Subject: tarfile and progress information In-Reply-To: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> References: <20100707112322.3c83870f@SamZwo.tch.harvard.edu> Message-ID: <20100714081645.GA28817@axis.g33x.de> On Wed, Jul 07, 2010 at 11:23:22AM -0400, Nathan Huesken wrote: > I am packing large files with tarfile. Is there any way I can get > progress information while packing? There is no builtin way in tarfile, but there are several possible solutions: 1. Replace the tarfile.copyfileobj() function that is used to copy the files' contents to the archive with your own. 2. Subclass the TarFile class, replace the addfile() method, and wrap every file object argument into an object that triggers a callback function for each block of data being read: """ import sys import os import tarfile class FileProxy(object): def __init__(self, fobj, callback): self.fobj = fobj self.callback = callback self.size = os.fstat(self.fobj.fileno()).st_size def read(self, size): self.callback(self.fobj.tell(), self.size) return self.fobj.read(size) def close(self): self.callback(self.size, self.size) self.fobj.close() class MyTarFile(tarfile.TarFile): def __init__(self, *args, **kwargs): self.callback = kwargs.pop("callback") super(MyTarFile, self).__init__(*args, **kwargs) def addfile(self, tarinfo, fileobj=None): if self.callback is not None and fileobj is not None: fileobj = FileProxy(fileobj, self.callback) super(MyTarFile, self).addfile(tarinfo, fileobj) def callback(processed, total): sys.stderr.write("%.1f%% \r" % (processed / float(total) * 100)) tar = MyTarFile.open("test.tar.gz", "w:gz", callback=callback) tar.add("...") tar.close() """ 3. If you have a defined set of files to add you can do something like this: tar = tarfile.open("test.tar.gz", "w:gz") for filename in filenames: tarinfo = tar.gettarinfo(filename) fobj = FileProxy(open(filename, "rb"), callback) tar.addfile(tarinfo, fobj) fobj.close() I hope this helps. Regards, -- Lars Gust?bel lars at gustaebel.de The power of accurate observation is called cynicism by those who have not got it. (George Bernard Shaw) From hniksic at xemacs.org Wed Jul 14 04:17:58 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 14 Jul 2010 10:17:58 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> Message-ID: <8739vma349.fsf@busola.homelinux.net> "Alf P. Steinbach /Usenet" writes: > Also, things like the 'owned' option is just asking for trouble. Isn't owned=true (or equivalent) a necessity when initializing from a PyObject* returned by a function declared to return a "new reference"? How does your API deal with the distinction between new and borrowed references? From downaold at gmail.com Wed Jul 14 04:32:37 2010 From: downaold at gmail.com (Roald de Vries) Date: Wed, 14 Jul 2010 10:32:37 +0200 Subject: floatref In-Reply-To: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> References: <4c3d1889$0$11125$c3e8da3@news.astraweb.com> Message-ID: <7102D8D5-CC41-4C7E-A480-D7827FBD525D@gmail.com> On Jul 14, 2010, at 3:53 AM, Steven D'Aprano wrote: > On Tue, 13 Jul 2010 19:26:34 +0200, Roald de Vries wrote: > >> Hi all, >> >> I have two objects that should both be able to alter a shared >> float. So >> i need something like a mutable float object, or a float reference >> object. Does anybody know if something like that exists? I know >> it's not >> hard to build, but I have a feeling that there should be a standard >> solution to it. > > One standard solution would be to wrap the float in a class as an > attribute. I think the nicest solution is to do this with a wrapping descriptor class. Thanks for your input! Cheers, Roald From info at egenix.com Wed Jul 14 05:36:09 2010 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 14 Jul 2010 11:36:09 +0200 Subject: eGenix at EuroPython 2010 Message-ID: <4C3D8509.10907@egenix.com> ________________________________________________________________________ eGenix at EuroPython 2010 ________________________________________________________________________ Meet up with eGenix at this year's EuroPython Conference in Birmingham, UK. The EuroPython Conference is the one of the premier conferences for Python users and developers. This year it is being held from the 19th to 22th July in Birmingham, UK. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/EuroPython-Conference-2010.html ________________________________________________________________________ MEET UP WITH EGENIX AT EUROPYTHON eGenix was one of the founding members of the EuroPython conference team and played a major role in organizing the first EuroPython conference in the year 2002. Since then we have attended every EuroPython conference to meet up face-to-face with the many people we know from the Python & Zope communities and the many people that we don't yet know from these communities -- if you are interested in meeting with us, please drop us a note so that we can arrange a meeting: info at egenix.com. ________________________________________________________________________ EGENIX TALKS AT EUROPYTHON 2010 At this year's EuroPython, eGenix will be giving a talk about an interesting custom project we successfully finished recently: Running Ghana VAT on Python --------------------------- At the EuroPython 2009 conference, we gave a lightning talk showcasing an eGenix Custom Python Project that we have been working on for our client Aya Technologies, Switzerland: EuroPython 2009 - Making 50 Mio. EUR per year using Python http://www.egenix.com/go23/ This year, we will present the fantastic results of that project, go into more depth, analyze the problems we faced and how we solved them. Marc-Andr?, CEO of eGenix, will be giving this presentation on Monday, July 19th in the Library Theatre: http://www.europython.eu/talks/timetable/ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 14 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2010-07-19: EuroPython 2010, Birmingham, UK 4 days to go ::: 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 lists at cheimes.de Wed Jul 14 05:37:29 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jul 2010 11:37:29 +0200 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: > I know, I just wondered if there is a *standard* solution. Yeah, you have to reset your brain and switch to Python mode. *scnr* Seriously, your inquiry sounds like you are trying to code C in Python. I'm using Python for more than seven years and I've never felt the need for a mutable float ref or something similar. Well, except for the first year when my brain was still in C pointer mode. :) From newsuser at stacom-software.de Wed Jul 14 05:48:52 2010 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Wed, 14 Jul 2010 11:48:52 +0200 Subject: ValueError: invalid literal for float(): -1.#IND (pickle.py) In-Reply-To: References: Message-ID: Mark Dickinson schrieb: > >> BTW: I'm tied to version 2.5 of python > > Have you tried using pickle protocol 1 or 2, instead of pickle > protocol 0? That may well solve your problem. (Those > protocols write out the binary form of a float directly, instead > of reading and writing a string representation.) > Thanks a lot, it looks like it solves the problem using another version of the protocol Regards From Maria.Reinhammar at accalon.com Wed Jul 14 06:23:24 2010 From: Maria.Reinhammar at accalon.com (Maria R) Date: Wed, 14 Jul 2010 03:23:24 -0700 (PDT) Subject: any issues with long running python apps? References: <4c3774df$0$31278$607ed4bc@cv.net> Message-ID: <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> I can second the stated opinion that Python per se is stable enough. We deliver production systems running 24/7 with uptimes counted in several months and from what I can see, compared to the OP's app, ours is vastly more complex. The only Python-related issue we have encountered so far, wrt to stability, is how timers are working. Extensive creation of timer threads have locked up after some indeterminable time. We found that the issue was probably related to some update in Windows at the time. We do not know whether this issue is resolved (we encountered it back in Python 1.4) and we rewrote our code to use timers differently. I also second that partitioning the solution in working (server) parts and GUI (client) parts is important. I do not second the generally outspoken distrust in Windows. Indeed, I would prefer *nix/*nux but in our case, stability concerns is not one of the issues behind that. We use threading to a certain extent (in addition to partioning into processes). One approach we have, and have shown very useful to gain stability, is to use Exception handling carefully and extensively. We catch *every* exception, report and counteract but do not allow the process/thread to die. This is not a trival approach, by no means, but when one know the app sufficiently, it can be applied with good results. Just my 2 c //Maria From alf.p.steinbach+usenet at gmail.com Wed Jul 14 06:39:17 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Wed, 14 Jul 2010 12:39:17 +0200 Subject: Cpp + Python: static data dynamic initialization in *nix shared lib? In-Reply-To: <8739vma349.fsf@busola.homelinux.net> References: <89pi93F819U4@mid.individual.net> <08c3679e-f844-4f70-b827-baf6d283cfe6@j13g2000yqj.googlegroups.com> <8739vma349.fsf@busola.homelinux.net> Message-ID: * Hrvoje Niksic, on 14.07.2010 10:17: > "Alf P. Steinbach /Usenet" writes: > >> Also, things like the 'owned' option is just asking for trouble. > > Isn't owned=true (or equivalent) a necessity when initializing from a > PyObject* returned by a function declared to return a "new reference"? No, not quite. Consider this signature (PyCXX): String( PyObject* pyob, bool owned = false ) versus this (cppy): PyString( PyPtr object ) With the first signature, every time you construct a String you have to remember to (explicitly or implicitly) set the bool flag correctly depending on where the actual argument value comes from. With the second signature the /type/ of the actual argument decides, automatically, so there's much less room for messing things up. With the second signature, if the actual argument is a raw PyObject* pointer then it's not owned, and the PyPtr formal argument doesn't increment the reference count but just takes ownership. If the actual argument, on the other hand, is a PyPtr, then the object is owned by the collection of PyPtr instances that refer to the object, and the new formal argument PyPtr instance then increments the reference count. In passing, if it should happen that the Python community uses the word 'owned' in the opposite sense of what's conventional in C++, then I guess & hope you'll figure out what I mean from this description. PyPtr currently looks like this (complete code): // progrock.cppy -- "C++ plus Python" // A simple C++ framework for writing Python 3.x extensions. // // Copyright (c) Alf P. Steinbach, 2010. #ifndef CPPY_PYPTR_H #define CPPY_PYPTR_H #include //----------------------------------------- Dependencies: #include #include #include //----------------------------------------- Interface: namespace progrock{ namespace cppy { using namespace cppx; enum DoAddRef {}; class PyPtr { private: PyObject* p_; public: typedef cppy::DoAddRef DoAddRef; PyPtr( PyObject* p = 0 ): p_( p ) {} PyPtr( PyObject* p, DoAddRef ): p_( p ) { assert( p != 0 ); Py_INCREF( p_ ); } PyPtr( PyPtr const& other ): p_( other.p_ ) { Py_XINCREF( p_ ); } ~PyPtr() { Py_XDECREF( p_ ); } void swapWith( PyPtr& other ) { std::swap( p_, other.p_ ); } PyPtr& operator=( PyPtr other ) { swapWith( other ); return *this; } PyObject* get() const { return p_; } PyObject* release() { PyObject* const result = p_; p_ = 0; return result; } }; inline PyObject* withAddedRef( PyObject* p ) { Py_INCREF( p ); return p; } inline PyObject* pyNoneRef() { return withAddedRef( Py_None ); } } } // namespace progrock::cppy #endif As you can see at the end there, there is 'withAddedRef' and 'pyNoneRef', and for that matter the 'DoAddRef' and the 'release()' method, for the cases where PyPtr default handling doesn't quite cut it... :-) > How does your API deal with the distinction between new and borrowed > references? See above. There are some cases where it must be dealt with, but the main idea is to encode that into /types/, instead of as context-dependent figure-it-out. That's also the main idea of C++ as compared to C, to encode much more into types, which helps both for compile time error detection and for automating things (like above), which is Very Nice, but which also can make for enormous waste of time trying to make the darned language do what you want it to do! :-) Cheers & hth., - Alf Disclaimer: it's late in the day/night for me, so the above explanation may have big logic holes, mispelings and so on, but I hope it gives the idea. -- blog at From johannes.black at gmail.com Wed Jul 14 07:21:54 2010 From: johannes.black at gmail.com (joblack) Date: Wed, 14 Jul 2010 04:21:54 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: Message-ID: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> > | > | Starting point: > | ... > | ? ? ? ? self.status['text'] = 'Processing ...' > | ? ? ? ? try: > | ? ? ? ? ? ? cli_main(argv) > | ? ? ? ? except Exception, e: > | ? ? ? ? ? ? self.status['text'] = 'Error: ' + str(e) > | ? ? ? ? ? ? return > | ... > | cli_main: > | > | ? ? keypath, inpath, outpath = argv[1:] > | ... > | ? ? with open(inpath, 'rb') as inf: > | ? ? ? ? serializer = PDFSerializer(inf, keypath) > | ? ? ? ? with open(outpath, 'wb') as outf: > | ? ? ? ? ? ? filenr = outf.fileno() > | ? ? ? ? ? ? serializer.dump(outf) > | ? ? return 0 > | > | PDFSerializer.dump: > | > | ? ? def dump(self, outf): > | ? ? ? ? self.outf = outf > | ... > > See that you set serializer.outf to the outf you open in cli_main? > Any attempt to use serializer _after_ exiting the "with open(outpath, > 'wb') as outf" will use serializer.outf, but the outf is now closed. > And thus itsfiledescriptoris invalid. Okay, I changed it to a try: ... finally: block where I open the file and in finally I close it. Nothing has changed. The error still occures. Doesn't the with open(outpath, 'wb') as outf: clause has to wait until the pdfserialiser.dump method has finished anyway? IMHO it can't just call it and immediately close it. At least the try: finally: construct should work? Or does it the same (call the method and immediately jump to the finally close)? Would it work if I would write: with closing(outpath, 'wb') as outf: ? I'm a little bit confused about Python's strange processing ... From python.list at tim.thechases.com Wed Jul 14 07:27:05 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 14 Jul 2010 06:27:05 -0500 Subject: nicer way to remove prefix of a string if it exists In-Reply-To: References: <4c3cfb76$0$20964$426a74cc@news.free.fr> <4C3D00EB.1010203@mrabarnett.plus.com> Message-ID: <4C3D9F09.1050207@tim.thechases.com> On 07/13/2010 09:22 PM, Shashwat Anand wrote: >> You could write: >> >> rsl = f[len(prefix):] if f.startswith(prefix) else f > > Or you can just do split and join, "".join(f.split(prefix, 1)) will do. This suggestion breaks if the prefix occurs within the string rather than at the beginning: f = "this has file:// inside it" prefix = "file://" So your suggestion really just operates like f.replace(prefix, '', 1) -tkc From antonyjeevaraj at rediffmail.com Wed Jul 14 07:48:48 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Wed, 14 Jul 2010 04:48:48 -0700 (PDT) Subject: MAKE UPTO $5000 MONTHLY! $2000 INYOUR FIRST 30 DAYS! Message-ID: <3b66596d-fbef-4185-b363-3af1a2c0d739@p11g2000prf.googlegroups.com> MAKE UPTO $5000 MONTHLY! $2000 INYOUR FIRST 30 DAYS! Generate $50 to $100 whenever you have a couple of hours free time to spare. You could make $50 or more in the next 2 hours. Starting right Now!Today! Earn from your free website Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://www.freesitesignup.com/a/coupon.php?id=3448 Get paid for your real work and earn awesome $$$$ From micayael at gmail.com Wed Jul 14 08:14:08 2010 From: micayael at gmail.com (micayael) Date: Wed, 14 Jul 2010 05:14:08 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Jul 13, 5:35?pm, Thomas Jollans wrote: > On 07/13/2010 09:55 PM, micayael wrote: > > > Hi. > > > I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 > > the adodb and psycopg2 module (sudo apt-get install python-adodb > > python-psycopg2) but when I put this > > > import adodb > > print adodb.NewADOConnection('postgres') --> None > > > but with > > > print adodb.NewADOConnection('mysql') --> > > > > http://packages.ubuntu.com/lucid/python-adodb > > Recommends: python-psycopg (Package not available) > > If it says it wants psycopg, I wouldn't expect it to work with psycopg2, > which is probably quite different in some way - otherwise it would be > called the same. > > ?- Thomas Thanks Thomas. :-( then adodb today dosn't work with postgres (at least on ubuntu) right? From fetchinson at googlemail.com Wed Jul 14 08:27:40 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 14 Jul 2010 14:27:40 +0200 Subject: eGenix at EuroPython 2010 In-Reply-To: <4C3D8509.10907@egenix.com> References: <4C3D8509.10907@egenix.com> Message-ID: > EuroPython 2009 - Making 50 Mio. EUR per year using Python > http://www.egenix.com/go23/ This link returns a 404. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From mohana2004 at gmail.com Wed Jul 14 08:37:43 2010 From: mohana2004 at gmail.com (Monyl) Date: Wed, 14 Jul 2010 05:37:43 -0700 (PDT) Subject: Identify the Color of an Image Message-ID: Hi, 1. How can I find the color of an image present the webpage? 2. How to identify the font type of the selected text present in the content of the web page It would be much helpfull, if anyone responds to it ASAP Thanks Mohmyda From knny.myer at gmail.com Wed Jul 14 08:58:16 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Wed, 14 Jul 2010 05:58:16 -0700 (PDT) Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> <4C3C4EF1.3080609@sequans.com> <4c3cc937$0$22938$e4fe514c@news.xs4all.nl> Message-ID: <26baa0df-7ac7-4502-94a8-7faaf9b77316@q22g2000yqm.googlegroups.com> On Jul 13, 4:14?pm, Hans Mulder wrote: > Chris Rebert wrote: > > `where` seems to be a zsh built-in: > > $ # I'm in UR bash > > $ nonexistent > > -bash: nonexistent: command not found > > $ where bash > > -bash: where: command not found > > > And not everyone has zsh installed, so... > > I don't see why one shouldn't use the standard `which` *nix command instead. > > Because `which` ia a C shell script. ?It reads your .cshrc, to see which > aliases would be defined if you were to use the C shell, but it doesn't > look at your .bashrc. > > You're probably better off using `type`: it knows about built-ins and > shell functions and that sort of stuff: > > $ which type > /usr/bin/type > $ type type > type is a shell builtin > $ > > Guess which answer is more relevant to you ..... > > HTH, > > -- HansM Oh thanks, Hans! `type` seems to a good alternative. Surely it can also get the job (better) done. From nathan.alexander.rice at gmail.com Wed Jul 14 09:21:17 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 14 Jul 2010 09:21:17 -0400 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: References: <6c66e536-cc8d-4a2d-835e-96eb9d025cef@z15g2000prn.googlegroups.com> Message-ID: The better question is, do I ever use them? Thinking back over the code I've written in the last couple of years, I would say probably two or three times (mostly in unit tests). I've had to code around string's sequence behavior DOZENS of times. Is it nifty that strings can be sliced like that? Sure. In general my experience has been that the string methods (and some misc functions in other modules) do a better job in simple cases, and regular expressions do a better job in complex cases. I just don't see string slicing having utility that is irreplaceable, and it is bug-inducing in many cases, or at the very least it can propagate programming errors way down stream. Ultimately, I highly doubt it's going anywhere, so it's a moot point. I definitely feel that python is trading real usability for "flash" with string slicing though. On Tue, Jul 13, 2010 at 8:48 PM, Aahz wrote: > [Original not available on my swerver, responding here] > > >On 7/11/10 10:03 PM, Nathan Rice wrote: > >> > >> Yeah, I long ago filed the in place place in the same folder as > >> strings-as-sequences, all() returning True for an empty iterable and any > >> returning True rather than the thing which triggered it. > > Because I love to repeat myself: > > "...string iteration isn't about treating strings as sequences of strings, > it's about treating strings as sequences of characters. The fact that > characters are also strings is the reason we have problems, but characters > are strings for other good reasons." --Aahz > http://mail.python.org/pipermail/python-3000/2006-April/000897.html > > Do you really want to give up Python's lovely string-slicing > capabilities? > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "....Normal is what cuts off your sixth finger and your tail..." --Siobhan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Jul 14 09:24:31 2010 From: no.email at please.post (kj) Date: Wed, 14 Jul 2010 13:24:31 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) Message-ID: I have a C library function hg that returns a long double, so when I import it using C types I specify this return type like this: MYLIB.hg.restype = ctypes.c_longdouble But certain non-zero values returned by hg appear as zero Python-side. If I modify hg so that it prints out its value right before returning it, I get stuff like the following: >>> 0 == MYLIB.hg(100, 200, 100, 6000) from hg: 2.96517e-161 False >>> 0 == MYLIB.hg(200, 200, 200, 6000) from hg: 5.28791e-380 True So, although the value returned by hg in the second invocation above is 5.28791e-380, Python sees it as 0. What am I doing wrong? TIA! ~K From ptmcg at austin.rr.com Wed Jul 14 09:40:58 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 14 Jul 2010 06:40:58 -0700 (PDT) Subject: nicer way to remove prefix of a string if it exists References: <4c3cfb76$0$20964$426a74cc@news.free.fr> Message-ID: <10092676-6c13-4b78-87d3-de0a19e47a07@g19g2000yqc.googlegroups.com> On Jul 13, 6:49?pm, News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > Here is an iterator solution: from itertools import izip def trim_prefix(prefix, s): i1,i2 = iter(prefix),iter(s) if all(c1==c2 for c1,c2 in izip(i1,i2)): return ''.join(i2) return s print trim_prefix("ABC","ABCDEFGHI") print trim_prefix("ABC","SLFJSLKFSLJFLSDF") Prints: DEFGHI SLFJSLKFSLJFLSDF -- Paul From jwhughes at hughesconcepts.com Wed Jul 14 10:21:32 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 10:21:32 -0400 Subject: Issue with logging.config In-Reply-To: References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: Peter, Thanks for the information. I sent an email to the maintainer and got some information that helped me continue with this. My solution was to change line 785 of handlers.py to self.socket.sendto(bytes(msg, 'ascii'), self.address) After I made the change, I got exactly what I was looking for. Joe On Jul 13, 2010, at 8:02 AM, Peter Otten wrote: > Joe Hughes wrote: > >> I'm doing some work with logging.config and I'm running into an >> interesting situation. I've run this by python-help, but that didn't help >> so I thought I would send to the list. Here is the config file >> >> [loggers] >> keys=root,log,syslog >> >> [handlers] >> keys=console,log,syslog >> >> [formatters] >> keys=rootFormat,logFormat,syslogFormat >> >> [logger_root] >> level=DEBUG >> handlers=console >> >> [logger_log] >> level=DEBUG >> handlers=log >> qualname=log >> >> [logger_syslog] >> level=DEBUG >> handlers=syslog >> qualname=syslog >> >> [handler_console] >> class=StreamHandler >> level=DEBUG >> formatter=rootFormat >> args=(sys.stdout,) >> >> [handler_log] >> class=handlers.RotatingFileHandler >> level=DEBUG >> formatter=logFormat >> args=('E:\local\Logs\syslog_interface.txt', 'a', 10000000, 10) >> propagate=0 >> >> [handler_syslog] >> class=handlers.SysLogHandler >> level=DEBUG >> formatter=syslogFormat >> host=141.232.41.205 >> port=handlers.SYSLOG_UDP_PORT >> facility=LOG_LOCAL0 >> > args=(('141.232.41.205',handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_LOCAL0) >> >> [formatter_rootFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> [formatter_logFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> [formatter_syslogFormat] >> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s >> >> and the python code >> >> ######################################################################## >> # Imports >> ######################################################################## >> import logging >> import logging.config >> import os >> import re >> from threading import Thread >> >> ######################################################################## >> # Constants >> ######################################################################## >> CONFIG_FILENAME = 'E:\local\Config\syslog_interface.conf' >> MCU_LIST_FILENAME = 'E:\local\Scada_Devices\mcu.txt' >> >> ######################################################################## >> # Classes >> ######################################################################## >> >> ######## >> # PingIt >> ######## >> class PingIt(Thread): >> def __init__(self, mcuIP): >> Thread.__init__(self) >> self.ip = mcuIP >> self.status = -1 >> >> def run(self): >> pinging = os.popen("ping -n 2 " + self.ip, 'r') >> >> while 1: >> line = pinging.readline() >> >> if not line: >> break >> >> gotResponse = re.findall(PingIt.lifeline, line) >> >> if gotResponse: >> self.status = int(gotResponse[0]) >> >> ######################################################################## >> # Main Routine >> ######################################################################## >> # >> # Get the logger configuration information >> # >> logging.config.fileConfig(CONFIG_FILENAME) >> >> # >> # Check if running from command line and create logger >> # >> if os.environ.get('PROMPT'): >> # >> # create logger for output to stdout >> # >> logger = logging.getLogger('root') >> else: >> # >> # create logger for output to logfile >> # >> logger = logging.getLogger('log') >> >> # >> # Create logger for syslog output >> # >> syslog = logging.getLogger('syslog') >> >> # >> # Declare variables >> # >> PingIt.lifeline = re.compile(r"Received = (\d)") >> mcu_dict = {} >> ping_list = [] >> status = ("Not responding", "Responded to only 1 ping of 2", "Alive") >> >> # >> # Open the MCU file >> # >> mcu_file = open(MCU_LIST_FILENAME, 'r') >> >> # >> # Loop through the contents of the MCU file and ping the IPs >> # >> for mcu in mcu_file: >> # >> # mcu file contents example >> # 192.168.97.227 MCU_HMSTD >> # >> # mcu_info[0] = MCU IP Address >> # mcu_info[1] = MCU Name >> # >> mcu_info = mcu.split() >> mcu_dict[mcu_info[0]] = mcu_info[1] >> current = PingIt(mcu_info[0]) >> logger.info("Pinging " + mcu_info[1]) >> ping_list.append(current) >> current.start() >> >> # >> # Loop through ping list and print the response >> # >> for pinged in ping_list: >> pinged.join() >> logger.info("Status - " + mcu_dict[pinged.ip] + " is " + >> status[pinged.status]) syslog.info("Status - " + mcu_dict[pinged.ip] + >> " is " + status[pinged.status]) >> >> This is the output from the code >> >> 2010-07-06 14:43:58,280 - log - INFO - Status - netboss2 is Not responding >> msg = <134>2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is >> Not responding >> address = ('141.232.41.205', 514) >> Traceback (most recent call last): >> File "C:\Python31\lib\logging\handlers.py", line 786, in emit >> self.socket.sendto(msg, self.address) >> TypeError: sendto() takes exactly 3 arguments (2 given) >> 2010-07-06 14:43:58,312 - syslog - INFO - Status - netboss2 is Not >> responding >> >> This is the handlers.py code from the library. I added the print >> statement to figure out why it is asking for three args but only getting >> two. >> >> Line 777 of handlers.py >> >> try: >> if self.unixsocket: >> try: >> self.socket.send(msg) >> except socket.error: >> self._connect_unixsocket(self.address) >> self.socket.send(msg) >> else: >> print('msg = ', msg, '\naddress = ', self.address) >> self.socket.sendto(msg, self.address) >> except (KeyboardInterrupt, SystemExit): >> raise >> except: >> self.handleError(record) >> >> line 790 of handlers.py >> >> This is Python/Idle 3.1.2 on Windows 2003 Server. If anyone has an idea >> about why this happening I would appreciate knowing what the issue is. > > The error can be reproduced with > > Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import logging >>>> from logging.handlers import SysLogHandler >>>> handler = SysLogHandler() >>>> logger = logging.getLogger() >>>> logger.addHandler(handler) >>>> logger.critical("yadda") > Traceback (most recent call last): > File "/usr/lib/python3.1/logging/handlers.py", line 785, in emit > self.socket.sendto(msg, self.address) > TypeError: sendto() takes exactly 3 arguments (2 given) > > This is is a known bug, see http://bugs.python.org/issue7077 > > Peter > > > -- > http://mail.python.org/mailman/listinfo/python-list From kaklis at gmail.com Wed Jul 14 10:52:30 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 14 Jul 2010 07:52:30 -0700 (PDT) Subject: stdiodemo (twisted-python) and enable command history Message-ID: <2ff970a1-ddf9-465d-a1c3-d9c774f84d08@k39g2000yqb.googlegroups.com> Hello again to all, While playing and extending stdiodemo.py, a came up with a thought of adding command line history. Is this possible? Any hints? Thanks Antonis K. From ericjvandervelden at gmail.com Wed Jul 14 10:54:58 2010 From: ericjvandervelden at gmail.com (Eric J. Van der Velden) Date: Wed, 14 Jul 2010 07:54:58 -0700 (PDT) Subject: list.insert Message-ID: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Hi, I understand this: >>> l=[1,2,3] >>> l[1:2]=[8,9] >>> l [1,8,9,3] But how do you do this with list.insert? Thanks, Eric J. From kentilton at gmail.com Wed Jul 14 11:19:32 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Wed, 14 Jul 2010 11:19:32 -0400 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c3dd58a$0$4989$607ed4bc@cv.net> Steven D'Aprano wrote: > On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: > >> The moral? If you look for the spam, you'll find it. > > And if you *don't* look for spam, you can be sure that some goose will > reply to it and get it past your filters. Thanks for that Kenneth, if > that is your name and you're not a Xah Lee sock-puppet. Let me see if I have this right. Your technique for reducing unwanted traffic is to openly insult one of the participants? That is how you clean things up? Because most people on Usenet respond well to personal insults and hush up? I have so much to learn! Or was it this? > > Followups set to a black hole. > > That works? Amazing. Here, I'll show you what spam looks like: my steadily-improving revolution in learning Algebra: http://teamalgebra.com/ kt -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From cnnshoe006 at gmail.com Wed Jul 14 11:25:12 2010 From: cnnshoe006 at gmail.com (cnnshoe) Date: Wed, 14 Jul 2010 08:25:12 -0700 (PDT) Subject: Wholesale Sports Shoes Clear Air Force One AAA++quality(www.cnnshoe.com) Message-ID: <74294e2e-5b43-4731-8a40-8b33b87d6980@w15g2000pro.googlegroups.com> supply sports shoes. The brand Sports shoes basketball shoes, Boot, walling shoes, Athletic shoes, Jogging shoes, running shoes, leather shoes, football, shoe sports shoe Footwear Sneaker, Shox Max Rift T- shirts, womens t-shirts, Clothing womens clothing, wear hats Caps Jersey jeans Sock Jacks, Watches, wallet, handbags, and Jeans Lady Clothing and so on. Please contact us by email to get more information. please kindly visite our website: http://www.cnnshoe.com msn: cnnshoe2010 at hotmail.com email: cnnshoe at gmail.com From alanwilter at gmail.com Wed Jul 14 11:38:08 2010 From: alanwilter at gmail.com (Alan) Date: Wed, 14 Jul 2010 16:38:08 +0100 Subject: python3: help with subprocess Message-ID: Hi there, Module commands is gone in python3, so I am trying subprocess. So please I would appreciate if someone can tell me how to do this better: before I had: cmd = 'uname -a' out = commands.getoutput(cmd) 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' now: out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE).communicate()[0][:-1] b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with getoutputs I didn't have. But what's giving headache is this "b'..." in the beginning. Can someone explain, point me to where I can now about it and how to make this better? I wanted a plain string in out. Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Jul 14 11:40:20 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 14 Jul 2010 08:40:20 -0700 (PDT) Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> Message-ID: <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> On Jul 14, 3:21?pm, Joe Hughes wrote: > ? ? ? ? Thanks for the information. ?I sent an email to the maintainer and got some information that helped me continue with this. ?My solution was to change line 785 of handlers.py to > > self.socket.sendto(bytes(msg, 'ascii'), self.address) > > After I made the change, I got exactly what I was looking for. > What I suggested was this: http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal-with.html Of course your change may work for you, but it's not a change we can have in the stdlib - since not everyone will be using ASCII for everything. Regards, Vinay Sajip From emile at fenx.com Wed Jul 14 11:41:11 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 14 Jul 2010 08:41:11 -0700 Subject: list.insert In-Reply-To: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> References: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Message-ID: On 7/14/2010 7:54 AM Eric J. Van der Velden said... > Hi, > > I understand this: > >>>> l=[1,2,3] >>>> l[1:2]=[8,9] >>>> l > [1,8,9,3] > > But how do you do this with list.insert? > >>> l = [1,2,3,4] >>> l[1:2]="" >>> dummy = [l.insert(1,x) for x in reversed([8,9])] Emile From urban.yoga.journeys at gmail.com Wed Jul 14 11:42:03 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Wed, 14 Jul 2010 08:42:03 -0700 (PDT) Subject: python app development References: <758bace3-dbec-42de-ba43-d3a745f1a12a@5g2000yqz.googlegroups.com> Message-ID: On Jul 3, 9:59?pm, Terry Reedy wrote: > On 7/3/2010 1:48 PM,mo reinawrote: > > > an anyone recommend a resource (book,tutorial,etc.) that focuses on > > application development in python? something similar to Practical > > Django Projects, but for stand alone applications instead of web apps > > (for now). > > > i'm in a bit of a funny place, i have a decent/good grasp of python > > syntax and my logic isn't bad, but i have no clue on how to assemble > > an application, i seem to be stuck on writing scripts. > > > i've looked at the source of a few projects but the flow is way over > > my head, i understand the syntax but not the logic, which is why i'm > > looking for a project-cenetered learning resource, instead of a > > reference or language-feature resource. also, it seems that a lot of > > app programming is 90% gui bindings, with very little actual code, or > > am i totally way off mark? > > If the app is a gui app and if logic is overly intermixed with gui > stuff, I am sure it can seem like that. Many recommend the MVC > model-view-controller model for app design. Even that can be confusing; > to me it should be model-controller-view, even though that is harder to > say. What are the data (values and objects) and how are they stored? > What are the rules for manipulating the data and objects? And then, and > only then, how to communicate with the user? > > > > > i recently picked up the django practical projects book, and in a few > > days i re-wrote a website i did with django. i feel it was the book's > > project-centric approach that made this possible. > > Another issue is who controls the flow of interactions, the user or the > code. For instance, a gui form used for input tends to direct the user > along a linear path. The same form, used for edit, presents existing > data and allows the user to pick and choose the fields to edit. This > distinction, along with MVC ideas, is important for reading source code. > > I have mostly seen this issue discussed in game reviews and game design > writing. In computer games, there is the same general difference between > a linear obstacle course game and a world to be explored in whatever > order one wants. (And there are some with both an explorable world *and* > a (somewhat optional) linear main quest line.) > > I am not familiar with any general app design books, but I have seen > game design articles and books that are on a par with writing about web > design. There are other books on business apps. > > -- > Terry Jan Reedy so you're suggesting: -write core algorithm(model) -link algorithm(s) with each other and a central menu, if applicable(controller) -write views for gui or cli(view) this is actually the path that i follow when writing django apps, and is the sequence that is being used in "Practical Django Projects", where first the different classes/data structures are written, then linked together through the url file, and finally html is written for each "view". From gherron at islandtraining.com Wed Jul 14 11:51:23 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 14 Jul 2010 08:51:23 -0700 Subject: Identify the Color of an Image In-Reply-To: References: Message-ID: <4C3DDCFB.4020505@islandtraining.com> On 07/14/2010 05:37 AM, Monyl wrote: > Hi, > > 1. How can I find the color of an image present the webpage? > > 2. How to identify the font type of the selected text present in the > content of the web page > > It would be much helpfull, if anyone responds to it ASAP > > Thanks > Mohmyda > Please be clearer about what you want. 1. An image does not "have" a color, although each pixel in an image does have a color. 2. Text in a web page does not (necessarily) have a font, although the display engine will use a font of its choice to render text. And my browser will probably use a different font than yours. From nagle at animats.com Wed Jul 14 12:01:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 14 Jul 2010 09:01:36 -0700 Subject: Identify the Color of an Image In-Reply-To: References: Message-ID: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> On 7/14/2010 5:37 AM, Monyl wrote: > Hi, > > 1. How can I find the color of an image present the webpage? > > 2. How to identify the font type of the selected text present in the > content of the web page > > It would be much helpfull, if anyone responds to it ASAP > > Thanks > Mohmyda "Selected text"? Selected how? "Selected" implies some form of user interface, like a browser. If you're doing something in a browser, look into Firefox and Greasemonkey. John Nagle From bsk16 at case.edu Wed Jul 14 12:03:51 2010 From: bsk16 at case.edu (Ben Kaplan) Date: Wed, 14 Jul 2010 09:03:51 -0700 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: On Jul 14, 2010, at 8:38 AM, Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So please I would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with getoutputs I didn't have. But what's giving headache is this "b'..." in the beginning. > > Can someone explain, point me to where I can now about it and how to make this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan There are 2 string types in Python: byte strings and unicode strings. In Python 2.x, they were called str and unicode, the default was str, and unicode was signaled by prefixing the string with a u. In python 3.x, they are called bytes and str. str (which is what used to be unicode) is the default, and a byte string (what used to be str) is signaled by putting a b in front of the string. Unicode is an abstract concept. Python can move it around internally, but the only thing you can send to other computers and programs is a sequence of bytes. If you want to convert the byte string to a unicode string, you have to decode it afterwards. out = out.decode("utf-8") From gherron at islandtraining.com Wed Jul 14 12:04:58 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 14 Jul 2010 09:04:58 -0700 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: <4C3DE02A.7060802@islandtraining.com> On 07/14/2010 08:38 AM, Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So > please I would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 > MacBookPro5,2 Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = > sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 > MacBookPro5,2 Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which > with getoutputs I didn't have. But what's giving headache is this > "b'..." in the beginning. > > Can someone explain, point me to where I can now about it and how to > make this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan > -- > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate > Department of Biochemistry, University of Cambridge. > 80 Tennis Court Road, Cambridge CB2 1GA, UK. > >>http://www.bio.cam.ac.uk/~awd28 << The 'b' is not part of the returned value. If you look at the *type* of the returned value, you will find that it is not a string, but rather a byte array. Printing of byte arrays displays the b'...' to indicate the type of thing begin printed. If you want a string, then you must convert the byte array to a string. For instance: str_out = out.decode('ascii') (And remember: in Python3, strings are always unicode.) Also, using out.strip() or str_out.strip() may be a better way to remove the white space. Gary Herron From michele.simionato at gmail.com Wed Jul 14 12:05:05 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 14 Jul 2010 09:05:05 -0700 (PDT) Subject: multiline input and readline Message-ID: Googling for ways to use the readline library with multiline input I found out the following stackoverflow answer: http://stackoverflow.com/questions/161495/is-there-a-nice-way-of-handling-multi-line-input-with-gnu-readline The solution is to use the rl_bind_key function, but it does not look like such function is wrapped in Python: what are my options? Notice that compatibility with pyreadline (which work on Windows) would be a plus. TIA, Michele Simionato From ethan at stoneleaf.us Wed Jul 14 12:06:34 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 14 Jul 2010 09:06:34 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3DE08A.1030808@stoneleaf.us> Alf P. Steinbach /Usenet wrote: > * MRAB, on 12.07.2010 00:37: >> Alf P. Steinbach /Usenet wrote: >>> >>> Of course there are variables, that's why the docs call them variables. >>> >> In Java a variable is declared and exists even before the first >> assignment to it. In Python a 'variable' isn't declared and won't exist >> until the first 'assignment' to it. > > That is a misconception. > > In Python a variable is declared by having an assignment to it, which > for a local variable may be anywhere within a routine. > > If such a variable is used before it's been assigned to, then you get an > uninitialized variable exception. Clearly the variable must exist in > order for the exception to refer to it (not to mention the exception > occurring at all). Really? So it's impossible for the interpreter, upon seeing the name 'blah', to scan forward to see if 'blah' is somewhere in the function in order to give a more meaningful error message? Of course not. > def foo(): > print( blah ) > blah = "this is both an assignment and a declaration causing it to > exist" > > foo() > > Clearly when the exception is raised, referring to the variable, the > variable exists. You are the only one spouting nonsense. Have you tried this? --> def foo(): ... print locals() ... blah = 'interesting' ... print locals() ... --> foo() {} {'blah': 'interesting'} As can be clearly seen, blah does not exist before the assignment -- the *name* blah has not been *bound* to an object yet, which is also what the error message says when you try to use it before it exists: UnboundLocalError: local variable 'blah' referenced before assignment Nothing religious about it -- just the facts. ~Ethan~ From john at castleamber.com Wed Jul 14 12:20:31 2010 From: john at castleamber.com (John Bokma) Date: Wed, 14 Jul 2010 11:20:31 -0500 Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> <4c3dd58a$0$4989$607ed4bc@cv.net> Message-ID: <87hbk2592o.fsf@castleamber.com> Kenneth Tilton writes: fup2 poster > Let me see if I have this right. Your technique for reducing unwanted > traffic is to openly insult one of the participants? Heh, or just ploinking them (done). Or making them cry like a little baby: http://xahlee.org/Periodic_dosage_dir/t2/harassment.html (it had an effect for a while :-D ) -- The John Bokma guy j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From davea at ieee.org Wed Jul 14 12:24:47 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 14 Jul 2010 12:24:47 -0400 Subject: python3: help with subprocess In-Reply-To: References: Message-ID: <4C3DE4CF.7020100@ieee.org> Alan wrote: > Hi there, > > Module commands is gone in python3, so I am trying subprocess. So please I > would appreciate if someone can tell me how to do this better: > > before I had: > > cmd = 'uname -a' > out = commands.getoutput(cmd) > > 'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 > Darwin' > > now: > > out = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = > sub.PIPE).communicate()[0][:-1] > > b'Darwin amadeus.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 > 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386 i386 MacBookPro5,2 > Darwin' > > Yes, it's ugly. the [:-1] above is to get read of the last '\n' which with > getoutputs I didn't have. But what's giving headache is this "b'..." in the > beginning. > > Can someone explain, point me to where I can now about it and how to make > this better? I wanted a plain string in out. > > Many thanks in advance, > > Alan > In Python3, 'plain string' would be unicode. But communicate returns bytes. So convert them to a string, for example, by using str(). By default that'll assume the bytes are ASCII encoded, so if you have any characters above 7f, you'd need something more. DaveA From thomas at jollans.com Wed Jul 14 12:28:42 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 18:28:42 +0200 Subject: ctypes' c_longdouble: underflow error (bug?) In-Reply-To: References: Message-ID: <4C3DE5BA.6070701@jollans.com> On 07/14/2010 03:24 PM, kj wrote: > > > > I have a C library function hg that returns a long double, so when > I import it using C types I specify this return type like this: > > MYLIB.hg.restype = ctypes.c_longdouble > > But certain non-zero values returned by hg appear as zero Python-side. > If I modify hg so that it prints out its value right before returning > it, I get stuff like the following: > >>>> 0 == MYLIB.hg(100, 200, 100, 6000) > from hg: 2.96517e-161 > False >>>> 0 == MYLIB.hg(200, 200, 200, 6000) > from hg: 5.28791e-380 > True > > So, although the value returned by hg in the second invocation > above is 5.28791e-380, Python sees it as 0. > > What am I doing wrong? Nothing. http://docs.python.org/library/ctypes.html#fundamental-data-types c_longdouble maps to float http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex "floating point numbers are implemented using double in C" ergo, the extra precision a long double gives you versus a normal double is lost if you use Python (or, at least, ctypes) If you really want to keep the precision, you need a new/different type. ctypes won't help you. Cython and NumPy may or may not be useful here. - Thomas From __peter__ at web.de Wed Jul 14 12:35:21 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Jul 2010 18:35:21 +0200 Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: Vinay Sajip wrote: > On Jul 14, 3:21 pm, Joe Hughes wrote: >> Thanks for the information. I sent an email to the maintainer and got >> some information that helped me continue with this. My solution was to >> change line 785 of handlers.py to >> >> self.socket.sendto(bytes(msg, 'ascii'), self.address) >> >> After I made the change, I got exactly what I was looking for. >> > > What I suggested was this: > > http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal- with.html > > Of course your change may work for you, but it's not a change we can > have in the stdlib - since not everyone will be using ASCII for > everything. It's not obvious to me how you'd adapt that code to work with python3.1 and the SysLogHandler. Can you give some details? Peter From ritchy_gato at hotmail.com Wed Jul 14 12:37:37 2010 From: ritchy_gato at hotmail.com (Ritchy lelis) Date: Wed, 14 Jul 2010 09:37:37 -0700 (PDT) Subject: Some success with the "Plot" problem :D Message-ID: <1e0fcfa4-cf05-43ac-8cc6-07d8a5117bdf@5g2000yqz.googlegroups.com> Hello guys On Following the development of my ADC (Analog-to-Digital converter Residue function transference) i already got some progress with the plot problem and (much thanks to colleagues who help me in this forum and not only) i would like to show you all the progress that has already got and take the opportunity to leave some doubt: ------------------------------------------------------------------------------------- import numpy import matplotlib.pylab as plt Vref = numpy.arange(-20, 20, 0.2) Vi = numpy.arange(-10, 10, 0.1) V0 = numpy.arange(Vi.shape[0]) i = 0 while i < Vi.shape[0]: if Vi[i] > Vref[i]/4: V0[i] = 2*Vi[i]-Vref[i] elif (-Vref[i]/4)<= Vi[i] and Vi[i] <= Vref[i]/4: V0[i] = 2*Vi[i] elif Vi[i] < -Vref[i]/4: V0[i] = 2*Vi[i] + Vref[i] i = i + 1 plt.plot(V0) # this plot will make that seems stairs rising plt.show() ----------------------------------------------------------------------------------------- For now i have a draw that seems cool to initialize the second part of my objectives but anyway i would like to request some help because I'm not getting on the waveform to start at origin of the coordinate axes. I'm looking for a better way to create those initial vectors (Vi, Vref, V0), any sujestions? Forword i want them to be implemented as a function that in the start of the program, i ask the user the dimention of the arrays that they want to use. Also if you have any sujestions to improve the script you can drope it here, is always welcome. For who want's to help but don?t have much information about what i'm doing here it's a link that is pretty cool: http://www.eit.lth.se/fileadmin/eit/courses/eti220/files/lectures/2009/lec4.pdf I'll be waiting. Cheers. Ritchy. From steve at REMOVE-THIS-cybersource.com.au Wed Jul 14 12:59:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Jul 2010 16:59:27 GMT Subject: Easy questions from a python beginner References: Message-ID: <4c3decee$0$11101$c3e8da3@news.astraweb.com> On Wed, 14 Jul 2010 09:06:34 -0700, Ethan Furman wrote: > Alf P. Steinbach /Usenet wrote: [...] >> Clearly when the exception is raised, referring to the variable, the >> variable exists. > > You are the only one spouting nonsense. Have you tried this? > > --> def foo(): > ... print locals() > ... blah = 'interesting' > ... print locals() > ... > --> foo() > {} > {'blah': 'interesting'} > > As can be clearly seen, blah does not exist before the assignment -- the > *name* blah has not been *bound* to an object yet, which is also what > the error message says when you try to use it before it exists: While I agree with your basic position that, in a meaningful sense, "blah" does not exist before it is assigned to, your explanation is invalid. In CPython, local variables in functions are optimised into pre-allocated slots. locals() is a *copy* of the actual locals, and any locals which are allocated but not defined are suppressed from the dict. >>> def f(): ... x = 5 ... if y: ... z = 1 ... return x+z ... >>> f.func_code.co_nlocals 2 >>> f.func_code.co_freevars () >>> f.func_code.co_varnames ('x', 'z') More here: http://tech.blog.aknin.name/2010/07/03/pythons-innards-code-objects/ You'll notice that in the sense of having space allocated for them in the code object, the variables already exist before the function has even been executed. But of course that's not the only sense, or even the most important one. I would argue that, in a very real sense, if you call f() with the global y set to False, that *semantically* the local z doesn't exist, even if the error message says different: > UnboundLocalError: local variable 'z' referenced before assignment -- Steven From ricaraoz at gmail.com Wed Jul 14 13:15:51 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Wed, 14 Jul 2010 14:15:51 -0300 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <4c3dd58a$0$4989$607ed4bc@cv.net> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> <4c3d2dcd$0$31270$607ed4bc@cv.net> <4c3d31c2$0$11091$c3e8da3@news.astraweb.com> <4c3dd58a$0$4989$607ed4bc@cv.net> Message-ID: <4C3DF0C7.2050203@gmail.com> On 14/07/2010 12:19 p.m., Kenneth Tilton wrote: > Steven D'Aprano wrote: >> On Tue, 13 Jul 2010 23:24:12 -0400, Kenneth Tilton wrote: >> >>> The moral? If you look for the spam, you'll find it. >> >> And if you *don't* look for spam, you can be sure that some goose >> will reply to it and get it past your filters. Thanks for that >> Kenneth, if that is your name and you're not a Xah Lee sock-puppet. > > Let me see if I have this right. Your technique for reducing unwanted > traffic is to openly insult one of the participants? That is how you > clean things up? Because most people on Usenet respond well to > personal insults and hush up? I have so much to learn! PLONK!!! From jjposner at optimum.net Wed Jul 14 13:33:52 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 14 Jul 2010 13:33:52 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: Message-ID: <4C3DF500.9050707@optimum.net> On 7/14/2010 12:06 PM, Ethan Furman wrote: > ... Have you tried this? > > --> def foo(): > ... print locals() > ... blah = 'interesting' > ... print locals() > ... > --> foo() > {} > {'blah': 'interesting'} > > As can be clearly seen, blah does not exist before the assignment -- the > *name* blah has not been *bound* to an object yet, which is also what > the error message says when you try to use it before it exists: As already cited, according to Section 4.1 "Naming and binding" in the Language Reference, the name "blah" *does* exist before the assignment. That's the implication of this phrase: If the name refers to a local variable that has not been bound, (BTW, "has not been bound" should really be "is not currently bound", to allow for use of *del* earlier in the block.) Try this: #-------------- def foo(): print "1. varnames:", globals()['foo'].__code__.co_varnames print "2. locals:", locals() blah = 'interesting' print "3. locals:", locals() foo() #-------------- The output (Python 2.6.5) is: 1. varnames: ('blah',) 2. locals: {} 3. locals: {'blah': 'interesting'} -John From shishaozhong at gmail.com Wed Jul 14 13:49:08 2010 From: shishaozhong at gmail.com (David) Date: Wed, 14 Jul 2010 10:49:08 -0700 (PDT) Subject: High Performance solutions are needed to do things like urlretrieve Message-ID: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> urlretrieve works fine. However, when file size get very large. It goes on forever, and even fails. For instance, one of download .zip file is of 363,096KB. Particularly, when trying to get, with urlretrieve, a zipped folder of a very large size, it could take up to 20 to 30 minutes. Often it fails, never any problem with smaller folders. Any solution for this? Regards. David From thomas at jollans.com Wed Jul 14 14:04:04 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:04:04 +0200 Subject: High Performance solutions are needed to do things like urlretrieve In-Reply-To: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> References: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> Message-ID: <4C3DFC14.8000501@jollans.com> On 07/14/2010 07:49 PM, David wrote: > > urlretrieve works fine. However, when file size get very large. It > goes on forever, and even fails. > > For instance, one of download .zip file is of 363,096KB. > > Particularly, when trying to get, with urlretrieve, a zipped folder of > a very large size, it could take up to 20 to 30 minutes. Often it > fails, never any problem with smaller folders. Any solution for this? Does this only occur with urllib, or is this the case for other software, like a web browser, or a downloader like wget? The more you try to copy, the longer it takes. The longer it takes, the more probable a problem affecting a file becomes. 20 to 30 minutes might well, depending on the network speed, be a readonable timeframe for 360M. And what does "often" mean here? In other words: Are you sure urlretrieve is to blame for your problems, why are you sure, and have you tried using urllib2 or the other urllib functions? From thomas at jollans.com Wed Jul 14 14:04:59 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:04:59 +0200 Subject: adodb.NewADOConnection('postgres') returns None In-Reply-To: References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: <4C3DFC4B.7010102@jollans.com> On 07/14/2010 02:14 PM, micayael wrote: > On Jul 13, 5:35 pm, Thomas Jollans wrote: >> On 07/13/2010 09:55 PM, micayael wrote: >> >>> Hi. >> >>> I'm trying to use adodb for postgres. I had instaled in ubuntu 9.10 >>> the adodb and psycopg2 module (sudo apt-get install python-adodb >>> python-psycopg2) but when I put this >> >>> import adodb >>> print adodb.NewADOConnection('postgres') --> None >> >>> but with >> >>> print adodb.NewADOConnection('mysql') --> >>> >> >> http://packages.ubuntu.com/lucid/python-adodb >> >> Recommends: python-psycopg (Package not available) >> >> If it says it wants psycopg, I wouldn't expect it to work with psycopg2, >> which is probably quite different in some way - otherwise it would be >> called the same. >> >> - Thomas > > Thanks Thomas. > :-( then adodb today dosn't work with postgres (at least on ubuntu) > right? It certainly looks that way. It may be possible to install an old psycopg module by hand - I'd expect that to work as well. From jwhughes at hughesconcepts.com Wed Jul 14 14:08:13 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 14:08:13 -0400 Subject: Issue with logging.config In-Reply-To: References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: <6B0AAE8C-3C20-4F42-BCB4-3607C75C6D25@hughesconcepts.com> This is why I did what I did, because I couldn't figure it out either. I did find issue 5421 at python.org which is where I got the idea for the code change. Joe On Jul 14, 2010, at 12:35 PM, Peter Otten wrote: > Vinay Sajip wrote: > >> On Jul 14, 3:21 pm, Joe Hughes wrote: >>> Thanks for the information. I sent an email to the maintainer and got >>> some information that helped me continue with this. My solution was to >>> change line 785 of handlers.py to >>> >>> self.socket.sendto(bytes(msg, 'ascii'), self.address) >>> >>> After I made the change, I got exactly what I was looking for. >>> >> >> What I suggested was this: >> >> http://plumberjack.blogspot.com/2010/07/using-custom-formatter-to-deal- > with.html >> >> Of course your change may work for you, but it's not a change we can >> have in the stdlib - since not everyone will be using ASCII for >> everything. > > It's not obvious to me how you'd adapt that code to work with python3.1 and > the SysLogHandler. Can you give some details? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Wed Jul 14 14:10:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Jul 2010 19:10:04 +0100 Subject: High Performance solutions are needed to do things like urlretrieve In-Reply-To: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> References: <94c3162a-9c53-4573-9646-783f9d040747@q22g2000yqm.googlegroups.com> Message-ID: <4C3DFD7C.50806@mrabarnett.plus.com> David wrote: > urlretrieve works fine. However, when file size get very large. It > goes on forever, and even fails. > > For instance, one of download .zip file is of 363,096KB. > > Particularly, when trying to get, with urlretrieve, a zipped folder of > a very large size, it could take up to 20 to 30 minutes. Often it > fails, never any problem with smaller folders. Any solution for this? > Do you have any control over the other end? If yes, then you could try transferring it in multiple chunks. From clp2 at rebertia.com Wed Jul 14 14:10:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Jul 2010 11:10:08 -0700 Subject: list.insert In-Reply-To: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> References: <8cd8d4a7-a028-4504-a929-28e2811b5107@j4g2000yqh.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 7:54 AM, Eric J. Van der Velden wrote: > Hi, > > I understand this: > >>>> l=[1,2,3] >>>> l[1:2]=[8,9] >>>> l > [1,8,9,3] > > But how do you do this with list.insert? You can't clobber existing items in the list using just .insert(), so the closest you could get is something like: del l[1] l.insert(1,9) l.insert(1,8) Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Wed Jul 14 14:24:20 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Jul 2010 18:24:20 +0000 (UTC) Subject: Easy questions from a python beginner References: Message-ID: On 2010-07-11, wheres pythonmonks wrote: > I have some easy issues (Python 2.6) As of a few minutes ago, this thread had 48 postings on my news server. To paraphrase somebody famous: There are no such things as easy questions. There are, however, easy answers. And they're wrong. -- Grant Edwards grant.b.edwards Yow! Did I say I was at a sardine? Or a bus??? gmail.com From thomas at jollans.com Wed Jul 14 14:35:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 14 Jul 2010 20:35:40 +0200 Subject: Errno 9] Bad file descriptor In-Reply-To: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: <4C3E037C.7090908@jollans.com> On 07/14/2010 01:21 PM, joblack wrote: >> | >> | Starting point: >> | ... >> | self.status['text'] = 'Processing ...' >> | try: >> | cli_main(argv) >> | except Exception, e: >> | self.status['text'] = 'Error: ' + str(e) >> | return >> | ... >> | cli_main: >> | >> | keypath, inpath, outpath = argv[1:] >> | ... >> | with open(inpath, 'rb') as inf: >> | serializer = PDFSerializer(inf, keypath) >> | with open(outpath, 'wb') as outf: >> | filenr = outf.fileno() >> | serializer.dump(outf) >> | return 0 >> | >> | PDFSerializer.dump: >> | >> | def dump(self, outf): >> | self.outf = outf >> | ... >> >> See that you set serializer.outf to the outf you open in cli_main? >> Any attempt to use serializer _after_ exiting the "with open(outpath, >> 'wb') as outf" will use serializer.outf, but the outf is now closed. >> And thus itsfiledescriptoris invalid. > > Okay, I changed it to a try: ... finally: block where I open the file > and in finally I close it. Nothing has changed. The error still > occures. Where does the error occur? If Cameron is right, it occurs somewhere completely different, when serializer.dump() is already long done, when some unsuspecting fool tries to do something with serializer.outf (such as closing it) > > Doesn't the > > with open(outpath, 'wb') as outf: > > clause has to wait until the pdfserialiser.dump method has finished > anyway? IMHO it can't just call it and immediately close it. > > At least the try: finally: construct should work? Or does it the same > (call the method and immediately jump to the finally close)? > > Would it work if I would write: > > with closing(outpath, 'wb') as outf: ? > > I'm a little bit confused about Python's strange processing ... From no at email.here.invalid Wed Jul 14 14:35:49 2010 From: no at email.here.invalid (Mladen Gogala) Date: Wed, 14 Jul 2010 18:35:49 +0000 (UTC) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Wed, 14 Jul 2010 20:04:59 +0200, Thomas Jollans wrote: > It certainly looks that way. It may be possible to install an old > psycopg module by hand - I'd expect that to work as well. Not on Ubuntu 9.10: checking PostgreSQL type catalog... /usr/include/postgresql/catalog/ pg_type.h checking for mxDateTime.h... configure: error: can't build without mx headers mgogala at nycwxp2622:/tmp/psycopg-1.1.21$ ADOdb package for PostgreSQL is broken and needs fixing. -- http://mgogala.byethost5.com From pandyan.senthil at gmail.com Wed Jul 14 14:50:22 2010 From: pandyan.senthil at gmail.com (senthi) Date: Wed, 14 Jul 2010 11:50:22 -0700 (PDT) Subject: CHANCE YOUR LIFE CLICK THEAR Message-ID: <921095ba-038d-4547-9f23-3bfbdb1d6e1d@v6g2000prd.googlegroups.com> http://www.123maza.com/dora/vvvv From no at email.here.invalid Wed Jul 14 14:51:55 2010 From: no at email.here.invalid (Mladen Gogala) Date: Wed, 14 Jul 2010 18:51:55 +0000 (UTC) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On Wed, 14 Jul 2010 05:14:08 -0700, micayael wrote: > Thanks Thomas. > :-( then adodb today dosn't work with postgres (at least on ubuntu) > right? No, ADOdb doesn't work with the newer versions of Postgres. ADOdb doesn't work with Psycopg2 and the guy who maintains it did not reply to my email. That is unfortunate because ADOdb is my favorite PHP class library. It seems, though, that the Python version is not nearly as well maintained as the PHP one. -- http://mgogala.byethost5.com From tommybear at hotmail.com Wed Jul 14 15:28:58 2010 From: tommybear at hotmail.com (Thomas Tundor) Date: 14 Jul 2010 19:28:58 GMT Subject: Is Python portable/Can I install it on an USB Stick? Message-ID: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Is Python portable? Can I install it on an USB Stick? Or is Python installing (at least on WinXP) services or register some DLLs or write something into Registry? Thomas From philip at semanchuk.com Wed Jul 14 15:36:23 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 14 Jul 2010 15:36:23 -0400 Subject: Is Python portable/Can I install it on an USB Stick? In-Reply-To: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <79F74E57-287B-4723-83E5-113A17007D6C@semanchuk.com> On Jul 14, 2010, at 3:28 PM, Thomas Tundor wrote: > Is Python portable? > > Can I install it on an USB Stick? > > Or is Python installing (at least on WinXP) services or register > some DLLs or > write something into Registry? http://www.portablepython.com/ From lists at cheimes.de Wed Jul 14 15:44:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 14 Jul 2010 21:44:07 +0200 Subject: Is Python portable/Can I install it on an USB Stick? In-Reply-To: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: > Is Python portable? > > Can I install it on an USB Stick? > > Or is Python installing (at least on WinXP) services or register some DLLs or > write something into Registry? Yes, a single user installation of Python is portable. An installation for every user is not portable since it installs some DLLs in system32. Some features and extensions are not portable, e.g. COM with pywin32 because they require registered DLLs. Christian From tino at wildenhain.de Wed Jul 14 16:22:59 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 14 Jul 2010 22:22:59 +0200 Subject: floatref In-Reply-To: References: Message-ID: <4C3E1CA3.7020503@wildenhain.de> Am 13.07.2010 19:26, schrieb Roald de Vries: > Hi all, > > I have two objects that should both be able to alter a shared float. > So i need something like a mutable float object, or a float reference > object. Does anybody know if something like that exists? I know it's > not hard to build, but I have a feeling that there should be a > standard solution to it. Nice question to reflect our understanding of the basics of this language. From what I know, we have the terms: - reference - name (pointer is not really used beside from indices into lists or such) I see it this way: you have named and unnamed references to objects. This means you can bind any number of names to an object as well as reference the object in a list, tupe or set: >>> (1,2,3) # unnamed references to int objects 1,2 and 3 >>> a=(1,2,3)[1] # binds a to tuple element #1 (int 2 object) >>> b=a # now a and b are bound to the same int 2 object So back to your question: >>> a=b=1.0 # binds the names a and b to the same float object 1.0 >>> a,b (1.0, 1.0) now, there is no way to alter the float object since it is immutable (as there are str, unicode, int, long, tuple...) >>> a+=0.5 >>> a,b (1.5, 1.0) now you see even the "in place" addition creates a new object and binds the name to it. What you'd need to do would probably wrapping the float value into a class where you can simulate a mutable float by providing a constant name or reference for it within the class. For example: >>> a=b=[1.0] >>> a[0]+=0.5 >>> a,b ([1.5], [1.5]) HTH Tino From steveo at syslang.net Wed Jul 14 16:42:04 2010 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 14 Jul 2010 16:42:04 -0400 Subject: Check if a command is valid In-Reply-To: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: <4C3E211C.4000207@syslang.net> On 07/12/10 21:29, quoth Kenny Meyer: > Hello, > > I have to figure out if a string is callable on a Linux system. I'm > actually doing this: > > def is_valid_command(command): > retcode = 100 # initialize > if command: > retcode = subprocess.call(command, shell=True) > if retcode is 0: > print "Valid command." > else: > print "Looks not so good..." > > is_valid_command("ls") > > Never mind the code, because this is not the original. > The side effect of subprocess.call() is that it *actually* executes > it, but I just need the return code. What are better ways of doing > this? Luke! Use the force! #! /usr/bin/python import os def is_valid_command(command): looking_good = False for ii in os.environ['PATH'].split(':'): if os.access(ii + '/' + command, os.X_OK): looking_good = True break print ["Looks not so good...", "Valid command."][looking_good] is_valid_command('python') is_valid_command('pythoon') This way you don't start up any subprocesses and you are actually doing what the shell would do for you. THE ONLY DIFFERENCE is that a persistent bash would hash all of the contents of what lives in PATH and so might have a slight shot of being faster under somewhat obscure conditions. I would strongly encourage you to not execute an arbitrary string to see if it returns a pretty return code. is_valid_command('{cd /; rm -rf /}') Warning: * It only checks if the command exists in PATH and is executable TO YOU: * Do not make fun of is_valid_command. It will get angry. * You might also want to beef it up a la pp = ii + '/' + command if os.access(pp, (os.X_OK) and not os.stat.isdir(p)): so you are checking executable files and not directories etc... * More warnings can be amplified upon over pitchers of beer. -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From luke.leighton at gmail.com Wed Jul 14 16:42:20 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 14 Jul 2010 13:42:20 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 5:44?am, rantingrick wrote: > On Jul 10, 10:59?pm, Luke Kenneth Casson Leighton > > wrote: > > source at:http://github.com/lkcl/grailbrowser > > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > > conversion of the 80 or so regex's to re has been carried out. > > entirely successfully or not is a matter yet to be determined. ?always > > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > > with a browser from 11+ years ago, it still cannot be resisted as > > grail is the only working graphical web browser in the world written > > in pure python [pybrowser is still in development, stalled]. > > > l. > > Congratulations on this effort Luke. However you know what project i > would really like to see the community get around? ...dramatic pause > here... a cross platform Python file browser! weeelll... you _could_ always just use grailbrowser :) it does still support file:// so it lists directories, shows text files and downloads anything it doesn't understand. l. From luke.leighton at gmail.com Wed Jul 14 16:47:49 2010 From: luke.leighton at gmail.com (lkcl) Date: Wed, 14 Jul 2010 13:47:49 -0700 (PDT) Subject: grailbrowser now running under python 2.5 (probably above too) References: Message-ID: On Jul 11, 10:39?pm, "Martin P. Hellwig" wrote: > On 07/11/10 04:59, Luke Kenneth Casson Leighton wrote:> source at: > >http://github.com/lkcl/grailbrowser > > > $ python grail.py (note the lack of "python1.5" or "python2.4") > > > conversion of the 80 or so regex's to re has been carried out. > > entirely successfully or not is a matter yet to be determined. ?always > > a hoot to try browsinghttp://www.bbc.co.ukorhttp://www.youtube.com > > with a browser from 11+ years ago, it still cannot be resisted as > > grail is the only working graphical web browser in the world written > > in pure python [pybrowser is still in development, stalled]. > > > l. > > Congrats! > Are you planning to take over the world with grail and pyjs? :-) mwahaahhah basically, yes. i'm fed up with the mozilla foundation, who have trashed python-xpcom _just_ at the point where i demonstrated its usefulness: the only reason things still work across linux distributions is due to inertia as the distros are still offering xulrunner-1.9.1, and i'm definitely fed up with the webkit developers, one in particular, whose treatment of and attitude to the work that i did to get python bindings to the DOM of webkit was beyond atrocious. so, python-based web browser it is, implement the W3C DOM API with it. hack it about, combine paul bonser's pybrowser back-end (which was where paul did most of the work, and stalled on the front-end), job done, one compliant python browser supporting W3C TR1,2 and 3 and if we're reaaallly lucky i maybe add some HTML5 features too. just don't expect it to be quick! l. From hayathms at gmail.com Wed Jul 14 16:51:01 2010 From: hayathms at gmail.com (Hayathms) Date: Thu, 15 Jul 2010 02:21:01 +0530 Subject: Please Help Message-ID: PLease anyone help me ,, program not running ------------------------------------------------------------------------------------ from tkinter import ttk from tkinter import * class Hami(ttk.Frame): def __init__(self,master=None): ttk.Frame.__init__(self,master,borderwidth=5) self.grid(column=0,row=0,sticky=('W,E,N,S'),padx=5,pady=5) class Honey(ttk.Label): def __init__(self,master=None,te='Honey'): ttk.Label.__init__(master,text=te) self.grid(column=0,row=0) root=Tk() root.title('Employee') root.option_add('*tearOff',FALSE) sam=Hami(root) harmain=Honey(master=sam) root.mainloop() ------------------------------------------------------------------------------------ Error is ----> Traceback (most recent call last): File "C:/Python31/hayathhh.py", line 20, in harmain=Honey(master=sam) File "C:/Python31/hayathhh.py", line 13, in __init__ self.grid(column=0,row=0) File "C:\Python31\lib\tkinter\__init__.py", line 1843, in grid_configure self.tk.call( AttributeError: 'Honey' object has no attribute 'tk' >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Wed Jul 14 16:54:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Jul 2010 20:54:22 +0000 (UTC) Subject: Check if a command is valid References: <4d2ab9ef-0988-47d1-95d9-0734131e41d2@i31g2000yqm.googlegroups.com> Message-ID: On 2010-07-14, Steven W. Orr wrote: > On 07/12/10 21:29, quoth Kenny Meyer: > >> I have to figure out if a string is callable on a Linux system. I'm >> actually doing this: >> >> def is_valid_command(command): >> retcode = 100 # initialize >> if command: >> retcode = subprocess.call(command, shell=True) >> if retcode is 0: >> print "Valid command." >> else: >> print "Looks not so good..." >> >> is_valid_command("ls") >> >> Never mind the code, because this is not the original. The side >> effect of subprocess.call() is that it *actually* executes it, but I >> just need the return code. What are better ways of doing this? > > Luke! Use the force! > > #! /usr/bin/python > > import os > def is_valid_command(command): > looking_good = False > for ii in os.environ['PATH'].split(':'): > if os.access(ii + '/' + command, os.X_OK): > looking_good = True > break > print ["Looks not so good...", "Valid command."][looking_good] > > is_valid_command('python') > is_valid_command('pythoon') Just to be clear, that's not the same as the OP's code in two respects: 1) It doesn't handle shell builtins or aliases. 2) It determines not whether a command is valid (returns 0), but whether a command exists as an executable. "Valid" is a rather small subset of "exists". Of course the OP didn't explain what he meant by "callable", so all we have to go on is his posted code. > This way you don't start up any subprocesses and you are actually > doing what the shell would do for you. > > THE ONLY DIFFERENCE is that a persistent bash would hash all of the > contents of what lives in PATH and so might have a slight shot of > being faster under somewhat obscure conditions. No, there are other differences. See above. > I would strongly encourage you to not execute an arbitrary string to > see if it returns a pretty return code. > > is_valid_command('{cd /; rm -rf /}') > > Warning: > * It only checks if the command exists in PATH and is executable TO > YOU: Which is different than determining whether a command (including arguments) is valid (callable and returns 0). However, running a command to determine if it's valid is going to cause problems sooner or later due to side-effects of that command. For example, the first time you the command "rm /path/to/a/file" it may be valid, but the second time it won't be. > * Do not make fun of is_valid_command. It will get angry. And don't taunt happy fun ball! > * You might also want to beef it up a la > pp = ii + '/' + command > if os.access(pp, (os.X_OK) and not os.stat.isdir(p)): > so you are checking executable files and not directories etc... > * More warnings can be amplified upon over pitchers of beer. -- Grant Edwards grant.b.edwards Yow! My mind is making at ashtrays in Dayton ... gmail.com From nad at acm.org Wed Jul 14 16:57:30 2010 From: nad at acm.org (Ned Deily) Date: Wed, 14 Jul 2010 13:57:30 -0700 Subject: Getting started with python on macintosh snow leopard with mysql - need help References: Message-ID: In article , Benjamin Kaplan wrote: > On Sun, Jul 11, 2010 at 1:18 PM, dk wrote: [...] > > when i try to compile mysql-python-1.2.3 i get the following error > > returned from python setup.py build ----- > > > > building '_mysql' extension > > gcc-4.0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing > > -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) - > > D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/ > > Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/ > > temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch x86_64 -fno-common - > > D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - > > DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL > > In file included from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/unicodeobject.h:4, > > ? ? ? ? ? ? ? ? from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/Python.h:85, > > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > > ? ? ? ? ? ? ? ? from _mysql.c:29: > > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > > stdarg.h: No such file or directory > > In file included from _mysql.c:36: > > /usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" > > redefined > > In file included from /Library/Frameworks/Python.framework/Versions/ > > 2.6/include/python2.6/Python.h:8, > > ? ? ? ? ? ? ? ? from pymemcompat.h:10, > > ? ? ? ? ? ? ? ? from _mysql.c:29: > > /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ > > pyconfig.h:808:1: warning: this is the location of the previous > > definition > > error: command 'gcc-4.0' failed with exit status 1 > > -- > > Strange. Seems that the package is trying to use gcc-4.0 and the > MacOSX10.4 SDK. The default version of gcc on Snow Leopard is 4.2, and > XCode only comes with the SDKs for the previous two versions of OS X. Not strange at all. The python.org Python 2.6 (which is installed to /Library/Frameworks/Python.framework) is deliberately built to be compatible with OS X 10.3.9 through 10.6 and, as such, requires gcc-4.0 and the 10.4u SDK. The latter is included in the 10.6 Xcode distribution as a separate package but is not installed by default; to build a Python C extension module for that Python, you need to go back to the Xcode installer for Snow Leopard (or download a new one from Apple) and do a custom installation of that SDK. -- Ned Deily, nad at acm.org From gherron at digipen.edu Wed Jul 14 17:14:37 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 14 Jul 2010 14:14:37 -0700 Subject: Please Help In-Reply-To: References: Message-ID: <4C3E28BD.7040309@digipen.edu> On 07/14/2010 01:51 PM, Hayathms wrote: > PLease anyone help me ,, > > program not running > ------------------------------------------------------------------------------------ > > from tkinter import ttk > from tkinter import * > > class Hami(ttk.Frame): > def __init__(self,master=None): > ttk.Frame.__init__(self,master,borderwidth=5) > self.grid(column=0,row=0,sticky=('W,E,N,S'),padx=5,pady=5) > > > class Honey(ttk.Label): > def __init__(self,master=None,te='Honey'): > ttk.Label.__init__(master,text=te) > self.grid(column=0,row=0) > > > root=Tk() > root.title('Employee') > root.option_add('*tearOff',FALSE) > sam=Hami(root) > harmain=Honey(master=sam) > root.mainloop() > ------------------------------------------------------------------------------------ > > Error is ----> > > > Traceback (most recent call last): > File "C:/Python31/hayathhh.py", line 20, in > harmain=Honey(master=sam) > File "C:/Python31/hayathhh.py", line 13, in __init__ > self.grid(column=0,row=0) > File "C:\Python31\lib\tkinter\__init__.py", line 1843, in grid_configure > self.tk.call( > AttributeError: 'Honey' object has no attribute 'tk' > >>> Here is *one* clear problem. Others may exist. Since Honey is derived from ttk.Label, Honey's constructor must call Label's constructor, (which you do), *however* when called as ttk.Label.__init__, you must provide it with the 'self' parameter. class Honey(ttk.Label): def __init__(self,master=None,te='Honey'): ttk.Label.__init__(*self*,master,text=te) # self parameter added here self.grid(column=0,row=0) -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From vinay_sajip at yahoo.co.uk Wed Jul 14 20:20:48 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 14 Jul 2010 17:20:48 -0700 (PDT) Subject: Issue with logging.config References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> Message-ID: <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> On Jul 14, 7:08?pm, Joe Hughes wrote: > This is why I did what I did, because I couldn't figure it out either. ?I did find issue 5421 at python.org which is where I got the idea for the code change. Perhaps you should read the messages for issue 7077, linked to by Peter above. You'll see that according to RFC 5424, syslog UDP messages should be encoded in UTF-8 with a BOM, not ASCII. Revisions r75586 and later of the Python repository implement the correct fix for the problem. My suggestion (in the blog post I linked to) would apply to socket applications other than syslog. Regards, Vinay Sajip From candide at free.invalid Wed Jul 14 21:30:24 2010 From: candide at free.invalid (candide) Date: Thu, 15 Jul 2010 03:30:24 +0200 Subject: Splitting numeric litterals Message-ID: <4c3e64ba$0$31001$426a74cc@news.free.fr> The escape sequence \ENTER allows to split a string over 2 consecutive lines. On the other hand, it seems impossible to split a numeric litteral across multiple lines, compare : >>> "1000\ ... 000\ ... 000" '1000000000' >>> 1000\ ... 000\ File "", line 2 000\ ^ SyntaxError: invalid syntax >>> Is this the general behaviour ? So, how do you edit code containing a very very long numeric constant ? From steve-REMOVE-THIS at cybersource.com.au Wed Jul 14 21:57:25 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 01:57:25 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c3e6b05$0$28672$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 03:30:24 +0200, candide wrote: > The escape sequence \ENTER allows to split a string over 2 consecutive > lines. On the other hand, it seems impossible to split a numeric > litteral across multiple lines [...] > Is this the general behaviour ? Yes. You can't put any whitespace in the middle of a numeric literal: >>> n = 4 2 File "", line 1 n = 4 2 ^ SyntaxError: invalid syntax > So, how do you edit code containing a very very long numeric constant ? s = ( "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" ) assert len(s) == 200 n = int(s) -- Steven From python at mrabarnett.plus.com Wed Jul 14 22:02:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jul 2010 03:02:06 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c3e64ba$0$31001$426a74cc@news.free.fr> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4C3E6C1E.1010402@mrabarnett.plus.com> candide wrote: > The escape sequence \ENTER allows to split a string over 2 consecutive > lines. On the other hand, it seems impossible to split a numeric > litteral across multiple lines, compare : > > >>> "1000\ > ... 000\ > ... 000" > '1000000000' > >>> 1000\ > ... 000\ > File "", line 2 > 000\ > ^ > SyntaxError: invalid syntax > >>> > > > Is this the general behaviour ? So, how do you edit code containing a > very very long numeric constant ? Normally it's only string literals that could be so long that you might want to split them over several lines. It is somewhat unusual to have a _numeric_ literal that's very very long! For an integer literal you could use a string literal and convert it to an integer: >>> int("1000\ 000\ 000") 1000000000 >>> From candide at free.invalid Wed Jul 14 22:37:57 2010 From: candide at free.invalid (candide) Date: Thu, 15 Jul 2010 04:37:57 +0200 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c3e7491$0$10849$426a74cc@news.free.fr> MRAB a ?crit : > want to split them over several lines. It is somewhat unusual to have a > _numeric_ literal that's very very long! > I agree. But consider RSA-155 for instance ... ;) > For an integer literal you could use a string literal and convert it to > an integer: > > >>> int("1000\ > 000\ > 000") > 1000000000 > >>> OK. In C, the following code is allowed : int x=1000\ 000\ 000; but not very usefull for sure ! From rt8396 at gmail.com Wed Jul 14 22:45:01 2010 From: rt8396 at gmail.com (r) Date: Wed, 14 Jul 2010 19:45:01 -0700 (PDT) Subject: Easy questions from a python beginner References: Message-ID: <0ab2ecae-f7d2-4025-8308-a12e07200950@t10g2000yqg.googlegroups.com> On Jul 14, 1:24?pm, Grant Edwards wrote: > As of a few minutes ago, this thread had 48 postings on my news > server. > > To paraphrase somebody famous: > > ? ? There are no such things as easy questions. ?There are, however, > ? ? easy answers. ?And they're wrong. ? ? ? ? Ha! This is the very reason i always steer clear of any post with the words "easy", "simple", or "BUSTARDS" in the title. ;-) From jwhughes at hughesconcepts.com Wed Jul 14 22:48:36 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 14 Jul 2010 22:48:36 -0400 Subject: Issue with logging.config In-Reply-To: <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> References: <175DD54A-A19C-4031-A321-1507A9B705E4@hughesconcepts.com> <788f50f8-298c-4ee4-9cc1-bb3ecd9e1945@y11g2000yqm.googlegroups.com> <17269304-5890-489c-b604-cd8ff288c880@x21g2000yqa.googlegroups.com> Message-ID: <1F81AB9F-52FD-4527-9515-F1CF2C628265@hughesconcepts.com> Hi Vinay, I think I figured out what you are talking about after reading RFC 5424. I think this means that this code syslog.info("Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status]) needs to become something like this BOM = 0xEFBBBF msg = str(BOM) + "Status - " + mcu_dict[pinged.ip] + " is " + status[pinged.status] syslog.info(msg) This would add the BOM to the message that RFC 5424 requires. Or did I totally misread it? Thanks, Joe On Jul 14, 2010, at 8:20 PM, Vinay Sajip wrote: > On Jul 14, 7:08 pm, Joe Hughes wrote: >> This is why I did what I did, because I couldn't figure it out either. I did find issue 5421 at python.org which is where I got the idea for the code change. > > Perhaps you should read the messages for issue 7077, linked to by > Peter above. You'll see that according to RFC 5424, syslog UDP > messages should be encoded in UTF-8 with a BOM, not ASCII. Revisions > r75586 and later of the Python repository implement the correct fix > for the problem. > > My suggestion (in the blog post I linked to) would apply to socket > applications other than syslog. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramercer at gmail.com Thu Jul 15 01:05:26 2010 From: ramercer at gmail.com (Adam Mercer) Date: Thu, 15 Jul 2010 00:05:26 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: Anyone have any ideas about this? Cheers Adam On Tue, Jul 13, 2010 at 16:18, Adam Mercer wrote: > Hi > > I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: > > 105 ? ? :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c > 106 ? ? :info:build swig -python > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c > SWIG/_m2crypto.i > 107 ? ? :info:build SWIG/_bio.i:64: Warning 454: Setting a > pointer/reference variable may leak memory. > 108 ? ? :info:build SWIG/_rand.i:19: Warning 454: Setting a > pointer/reference variable may leak memory. > 109 ? ? :info:build SWIG/_evp.i:156: Warning 454: Setting a > pointer/reference variable may leak memory. > 110 ? ? :info:build SWIG/_dh.i:36: Warning 454: Setting a > pointer/reference variable may leak memory. > 111 ? ? :info:build SWIG/_rsa.i:43: Warning 454: Setting a > pointer/reference variable may leak memory. > 112 ? ? :info:build SWIG/_dsa.i:31: Warning 454: Setting a > pointer/reference variable may leak memory. > 113 ? ? :info:build SWIG/_ssl.i:207: Warning 454: Setting a > pointer/reference variable may leak memory. > 114 ? ? :info:build SWIG/_x509.i:313: Warning 454: Setting a > pointer/reference variable may leak memory. > 115 ? ? :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 116 ? ? :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 117 ? ? :info:build SWIG/_util.i:9: Warning 454: Setting a > pointer/reference variable may leak memory. > 118 ? ? :info:build SWIG/_ec.i:111: Warning 454: Setting a > pointer/reference variable may leak memory. > 119 ? ? :info:build SWIG/_engine.i:162: Warning 454: Setting a > pointer/reference variable may leak memory. > 120 ? ? :info:build creating build/temp.macosx-10.6-x86_64-2.5 > 121 ? ? :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG > 122 ? ? :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd > -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include > -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG > -c SWIG/_m2crypto_wrap.c -o > build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING > 123 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': > 124 ? ? :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 125 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': > 126 ? ? :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 127 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': > 128 ? ? :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 129 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': > 130 ? ? :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 131 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': > 132 ? ? :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 133 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': > 134 ? ? :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used > 135 ? ? :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used > 136 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': > 137 ? ? :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 138 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 139 ? ? :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 140 ? ? :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token > 141 ? ? :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token > 142 ? ? :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 143 ? ? :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token > 144 ? ? :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token > 145 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': > 146 ? ? :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 147 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': > 148 ? ? :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in > signedness > 149 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': > 150 ? ? :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in > signedness > 151 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 152 ? ? :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 153 ? ? :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token > 154 ? ? :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token > 155 ? ? :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token > 156 ? ? :info:build SWIG/_m2crypto_wrap.c:6081: error: expected > declaration specifiers or '...' before 'STACK' > 157 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': > 158 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared > (first use in this function) > 159 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared > identifier is reported only once > 160 ? ? :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function > it appears in.) > 161 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > 'x509_name_entry_create_by_txt': > 162 ? ? :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets > in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in > signedness > 163 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 164 ? ? :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 165 ? ? :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token > 166 ? ? :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token > 167 ? ? :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 168 ? ? :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token > 169 ? ? :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token > 170 ? ? :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token > 171 ? ? :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token > 172 ? ? :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token > 173 ? ? :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 174 ? ? :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token > 175 ? ? :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token > 176 ? ? :info:build SWIG/_m2crypto_wrap.c:6385: error: expected > declaration specifiers or '...' before 'STACK' > 177 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': > 178 ? ? :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared > (first use in this function) > 179 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 180 ? ? :info:build SWIG/_m2crypto_wrap.c:6390: error: expected > declaration specifiers or '...' before 'STACK' > 181 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': > 182 ? ? :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared > (first use in this function) > 183 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 184 ? ? :info:build SWIG/_m2crypto_wrap.c:6418: error: expected > declaration specifiers or '...' before 'STACK' > 185 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': > 186 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared > (first use in this function) > 187 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument > 3 of 'pkcs7_verify1' from incompatible pointer type > 188 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument > 4 of 'pkcs7_verify1' makes integer from pointer without a cast > 189 ? ? :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments > to function 'pkcs7_verify1' > 190 ? ? :info:build SWIG/_m2crypto_wrap.c: At top level: > 191 ? ? :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 192 ? ? :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': > 193 ? ? :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 194 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': > 195 ? ? :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared > (first use in this function) > 196 ? ? :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' > undeclared (first use in this function) > 197 ? ? :info:build SWIG/_m2crypto_wrap.c:16913: error: expected > expression before ')' token > 198 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': > 199 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared > (first use in this function) > 200 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared > (first use in this function) > 201 ? ? :info:build SWIG/_m2crypto_wrap.c:16923: error: expected > expression before ')' token > 202 ? ? :info:build SWIG/_m2crypto_wrap.c:16934: error: expected > expression before ')' token > 203 ? ? :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit > declaration of function 'sk_ssl_cipher_num' > 204 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': > 205 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared > (first use in this function) > 206 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared > (first use in this function) > 207 ? ? :info:build SWIG/_m2crypto_wrap.c:16953: error: expected > expression before ')' token > 208 ? ? :info:build SWIG/_m2crypto_wrap.c:16968: error: expected > expression before ')' token > 209 ? ? :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit > declaration of function 'sk_ssl_cipher_value' > 210 ? ? :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer > from integer of different size > 211 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_ssl_get_peer_cert_chain': > 212 ? ? :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared > (first use in this function) > 213 ? ? :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' > undeclared (first use in this function) > 214 ? ? :info:build SWIG/_m2crypto_wrap.c:17006: error: expected > expression before ')' token > 215 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': > 216 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared > (first use in this function) > 217 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared > (first use in this function) > 218 ? ? :info:build SWIG/_m2crypto_wrap.c:17016: error: expected > expression before ')' token > 219 ? ? :info:build SWIG/_m2crypto_wrap.c:17027: error: expected > expression before ')' token > 220 ? ? :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit > declaration of function 'sk_x509_num' > 221 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': > 222 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared > (first use in this function) > 223 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared > (first use in this function) > 224 ? ? :info:build SWIG/_m2crypto_wrap.c:17046: error: expected > expression before ')' token > 225 ? ? :info:build SWIG/_m2crypto_wrap.c:17061: error: expected > expression before ')' token > 226 ? ? :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit > declaration of function 'sk_x509_value' > 227 ? ? :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer > from integer of different size > 228 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_name_entry_set_data': > 229 ? ? :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets > in assignment differ in signedness > 230 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_store_ctx_get1_chain': > 231 ? ? :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared > (first use in this function) > 232 ? ? :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' > undeclared (first use in this function) > 233 ? ? :info:build SWIG/_m2crypto_wrap.c:19741: error: expected > expression before ')' token > 234 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': > 235 ? ? :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared > (first use in this function) > 236 ? ? :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' > undeclared (first use in this function) > 237 ? ? :info:build SWIG/_m2crypto_wrap.c:20573: error: expected > expression before ')' token > 238 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': > 239 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared > (first use in this function) > 240 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared > (first use in this function) > 241 ? ? :info:build SWIG/_m2crypto_wrap.c:20583: error: expected > expression before ')' token > 242 ? ? :info:build SWIG/_m2crypto_wrap.c:20593: error: expected > expression before ')' token > 243 ? ? :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit > declaration of function 'sk_x509_free' > 244 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': > 245 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared > (first use in this function) > 246 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared > (first use in this function) > 247 ? ? :info:build SWIG/_m2crypto_wrap.c:20609: error: expected > expression before ')' token > 248 ? ? :info:build SWIG/_m2crypto_wrap.c:20624: error: expected > expression before ')' token > 249 ? ? :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit > declaration of function 'sk_x509_push' > 250 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': > 251 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared > (first use in this function) > 252 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared > (first use in this function) > 253 ? ? :info:build SWIG/_m2crypto_wrap.c:20653: error: expected > expression before ')' token > 254 ? ? :info:build SWIG/_m2crypto_wrap.c:20664: error: expected > expression before ')' token > 255 ? ? :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit > declaration of function 'sk_x509_pop' > 256 ? ? :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer > from integer of different size > 257 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509_req_add_extensions': > 258 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared > (first use in this function) > 259 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared > (first use in this function) > 260 ? ? :info:build SWIG/_m2crypto_wrap.c:20871: error: expected > expression before ')' token > 261 ? ? :info:build SWIG/_m2crypto_wrap.c:20890: error: expected > expression before ')' token > 262 ? ? :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments > to function 'x509_req_add_extensions' > 263 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': > 264 ? ? :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared > (first use in this function) > 265 ? ? :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' > undeclared (first use in this function) > 266 ? ? :info:build SWIG/_m2crypto_wrap.c:20981: error: expected > expression before ')' token > 267 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_x509v3_set_conf_lhash': > 268 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared > (first use in this function) > 269 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared > (first use in this function) > 270 ? ? :info:build SWIG/_m2crypto_wrap.c:20991: error: expected > expression before ')' token > 271 ? ? :info:build SWIG/_m2crypto_wrap.c:21002: error: expected > expression before ')' token > 272 ? ? :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit > declaration of function 'x509v3_set_conf_lhash' > 273 ? ? :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer > from integer of different size > 274 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': > 275 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared > (first use in this function) > 276 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared > (first use in this function) > 277 ? ? :info:build SWIG/_m2crypto_wrap.c:21013: error: expected > expression before ')' token > 278 ? ? :info:build SWIG/_m2crypto_wrap.c:21038: error: expected > expression before ')' token > 279 ? ? :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit > declaration of function 'x509v3_ext_conf' > 280 ? ? :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer > from integer of different size > 281 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_new_null': > 282 ? ? :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared > (first use in this function) > 283 ? ? :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' > undeclared (first use in this function) > 284 ? ? :info:build SWIG/_m2crypto_wrap.c:21116: error: expected > expression before ')' token > 285 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_free': > 286 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared > (first use in this function) > 287 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared > (first use in this function) > 288 ? ? :info:build SWIG/_m2crypto_wrap.c:21126: error: expected > expression before ')' token > 289 ? ? :info:build SWIG/_m2crypto_wrap.c:21136: error: expected > expression before ')' token > 290 ? ? :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit > declaration of function 'sk_x509_extension_free' > 291 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_push': > 292 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared > (first use in this function) > 293 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared > (first use in this function) > 294 ? ? :info:build SWIG/_m2crypto_wrap.c:21152: error: expected > expression before ')' token > 295 ? ? :info:build SWIG/_m2crypto_wrap.c:21167: error: expected > expression before ')' token > 296 ? ? :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit > declaration of function 'sk_x509_extension_push' > 297 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_pop': > 298 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared > (first use in this function) > 299 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared > (first use in this function) > 300 ? ? :info:build SWIG/_m2crypto_wrap.c:21191: error: expected > expression before ')' token > 301 ? ? :info:build SWIG/_m2crypto_wrap.c:21202: error: expected > expression before ')' token > 302 ? ? :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit > declaration of function 'sk_x509_extension_pop' > 303 ? ? :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer > from integer of different size > 304 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_num': > 305 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared > (first use in this function) > 306 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared > (first use in this function) > 307 ? ? :info:build SWIG/_m2crypto_wrap.c:21218: error: expected > expression before ')' token > 308 ? ? :info:build SWIG/_m2crypto_wrap.c:21229: error: expected > expression before ')' token > 309 ? ? :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit > declaration of function 'sk_x509_extension_num' > 310 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_sk_x509_extension_value': > 311 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared > (first use in this function) > 312 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared > (first use in this function) > 313 ? ? :info:build SWIG/_m2crypto_wrap.c:21248: error: expected > expression before ')' token > 314 ? ? :info:build SWIG/_m2crypto_wrap.c:21263: error: expected > expression before ')' token > 315 ? ? :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit > declaration of function 'sk_x509_extension_value' > 316 ? ? :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer > from integer of different size > 317 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_make_stack_from_der_sequence': > 318 ? ? :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared > (first use in this function) > 319 ? ? :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' > undeclared (first use in this function) > 320 ? ? :info:build SWIG/_m2crypto_wrap.c:21314: error: expected > expression before ')' token > 321 ? ? :info:build SWIG/_m2crypto_wrap.c: In function > '_wrap_get_der_encoding_stack': > 322 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared > (first use in this function) > 323 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared > (first use in this function) > 324 ? ? :info:build SWIG/_m2crypto_wrap.c:21324: error: expected > expression before ')' token > 325 ? ? :info:build SWIG/_m2crypto_wrap.c:21335: error: expected > expression before ')' token > 326 ? ? :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit > declaration of function 'get_der_encoding_stack' > 327 ? ? :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer > from integer of different size > 328 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': > 329 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared > (first use in this function) > 330 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared > (first use in this function) > 331 ? ? :info:build SWIG/_m2crypto_wrap.c:22343: error: expected > expression before ')' token > 332 ? ? :info:build SWIG/_m2crypto_wrap.c:22366: error: expected > expression before ')' token > 333 ? ? :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit > declaration of function 'pkcs7_encrypt' > 334 ? ? :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer > from integer of different size > 335 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': > 336 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared > (first use in this function) > 337 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared > (first use in this function) > 338 ? ? :info:build SWIG/_m2crypto_wrap.c:22547: error: expected > expression before ')' token > 339 ? ? :info:build SWIG/_m2crypto_wrap.c:22582: error: expected > expression before ')' token > 340 ? ? :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument > 4 of 'pkcs7_sign1' makes integer from pointer without a cast > 341 ? ? :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments > to function 'pkcs7_sign1' > 342 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': > 343 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared > (first use in this function) > 344 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared > (first use in this function) > 345 ? ? :info:build SWIG/_m2crypto_wrap.c:22628: error: expected > expression before ')' token > 346 ? ? :info:build SWIG/_m2crypto_wrap.c:22659: error: expected > expression before ')' token > 347 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument > 3 of 'pkcs7_verify1' from incompatible pointer type > 348 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument > 4 of 'pkcs7_verify1' makes integer from pointer without a cast > 349 ? ? :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments > to function 'pkcs7_verify1' > 350 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': > 351 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared > (first use in this function) > 352 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared > (first use in this function) > 353 ? ? :info:build SWIG/_m2crypto_wrap.c:22707: error: expected > expression before ')' token > 354 ? ? :info:build SWIG/_m2crypto_wrap.c:22734: error: expected > expression before ')' token > 355 ? ? :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument > 3 of 'pkcs7_verify0' makes integer from pointer without a cast > 356 ? ? :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments > to function 'pkcs7_verify0' > 357 ? ? :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': > 358 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared > (first use in this function) > 359 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared > (first use in this function) > 360 ? ? :info:build SWIG/_m2crypto_wrap.c:23188: error: expected > expression before ')' token > 361 ? ? :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' > undeclared (first use in this function) > 362 ? ? :info:build SWIG/_m2crypto_wrap.c:23211: error: expected > expression before ')' token > 363 ? ? :info:build SWIG/_m2crypto_wrap.c:23227: error: expected > expression before ')' token > 364 ? ? :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 > > Anyone know a way to resolve this? > > Cheers > > Adam > From gnuist006 at gmail.com Thu Jul 15 01:17:05 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 14 Jul 2010 22:17:05 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> Message-ID: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> On Jul 13, 11:18 pm, geremy condra wrote: > On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: > > On Jun 20, 9:31 pm, Richard Fateman wrote: > >> Define Macro wrote: > >> > On Jun 13, 7:07 pm, bolega wrote: > >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. > > >> >> For this, I propose a vanilla C interpreter. I have seen a book which > >> >> writes C interpreter in C. > > >> >> The criteria would be the small size and high readability of the code. > > >> >> Are there already answers anywhere ? > > >> Sure. Lots of texts on compilers provide exercises which, in one way or > >> another suggest how to write an interpreter and perhaps a compiler too > >> for some language. Anyone taking a course on compilers is likely to > >> have followed such exercises in order to pass the course. Some > >> instructors are enlightened enough to allow students to pick the > >> implementation language. > > >> Ask any such instructor. > > > Beware, he does not tell the readers the financial details. This is > > what he wrote to me by email. > > > > > I would be willing to meet with you here in Berkeley to educate you on > > these matters at a consulting rate of $850 per hour, with a minimum > > of 8 hours. > > > RJF > > > > He's Berkeley's former CS chair and was implementing lisp before > common lisp was a twinkle in anybody's eye. His time is valuable. > > Geremy Condra This makes some sense. He replied on the newsgroup in a lengthy post that there are sufficient resources out there giving hint that no one need help me out. Then I was called "lazy" in one email and tersely given JUST the last name of an author who has many books each many 100s pages, when I asked for a relevant book, as if i am a scholar in the field, although he did spend lots of words on irrelevant and unbeneficial things which diminished my enthusiasm. Now, I find out from you that he has/had a business concern or interest in a company that is writing/wrote lisp interpreter in C. Correct me if I am making an error. I dont want to think deprecatingly of any good soul but this is what i experienced. From gnuist006 at gmail.com Thu Jul 15 01:26:26 2010 From: gnuist006 at gmail.com (bolega) Date: Wed, 14 Jul 2010 22:26:26 -0700 (PDT) Subject: C interpreter in Lisp/scheme/python References: <7xoceao9jx.fsf@ruckus.brouhaha.com> Message-ID: On Jul 13, 11:35?pm, Paul Rubin wrote: > bolega writes: > > I am trying to compare LISP/Scheme/Python for their expressiveness... > > Are there already answers anywhere ? > > How would a gury approach such a project ? > > These two articles > > ? ?http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprt_computer2000.pdf > ? ?http://www.haskell.org/papers/NSWC/jfp.ps > > about language comparisons (Python is in the first but not the second) > might be of interest. > > If you want to know how to implement C, there is a pretty good book by > Hanson and Fraser about LCC, called "A Retargetable C Compiler". > Basically a code walkthrough of a small C compiler written in C. I have decided to limit my goal to tyni LISP interpreter in C because its a smaller and simpler language. From debatem1 at gmail.com Thu Jul 15 01:52:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 14 Jul 2010 22:52:51 -0700 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 10:17 PM, bolega wrote: > On Jul 13, 11:18 pm, geremy condra wrote: >> On Tue, Jul 13, 2010 at 11:01 PM, bolega wrote: >> > On Jun 20, 9:31 pm, Richard Fateman wrote: >> >> Define Macro wrote: >> >> > On Jun 13, 7:07 pm, bolega wrote: >> >> >> I am trying to compare LISP/Scheme/Python for their expressiveness. >> >> >> >> For this, I propose a vanilla C interpreter. I have seen a book which >> >> >> writes C interpreter in C. >> >> >> >> The criteria would be the small size and high readability of the code. >> >> >> >> Are there already answers anywhere ? >> >> >> Sure. ?Lots of texts on compilers provide exercises which, in one way or >> >> another suggest how to write an interpreter and perhaps a compiler too >> >> for some language. ?Anyone taking a course on compilers is likely to >> >> have followed such exercises in order to pass the course. ?Some >> >> instructors are enlightened enough to allow students to pick the >> >> implementation language. >> >> >> Ask any such instructor. >> >> > Beware, he does not tell the readers the financial details. This is >> > what he wrote to me by email. >> >> > >> > I would be willing to meet with you here in Berkeley to educate you on >> > these matters at a consulting rate of ?$850 per hour, with a minimum >> > of 8 hours. >> >> > RJF >> > >> >> He's Berkeley's former CS chair and was implementing lisp before >> common lisp was a twinkle in anybody's eye. His time is valuable. >> >> Geremy Condra > > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. No one does. Your problem is yours to solve. > Then I was called "lazy" in one email and tersely > given JUST the last name of an author who has many books each many > 100s pages, when I asked for a relevant book, as if i am a scholar in > the field, although he did spend lots of words on irrelevant and > unbeneficial things which diminished my enthusiasm. Yes, you've failed to take advantage of the resources which have been made available to you, preferring to have other people solve your problem. Sounds like a pretty good working definition of laziness. > Now, I find out > from you that he has/had a business concern or interest in a company > that is writing/wrote lisp interpreter in C. Correct me if I am making > an error. You're making an error. Given that there are probably only a handful of people on earth more qualified to teach you anything you'd want to know about this I'd say he's made you an exceptional offer. Expect no better help elsewhere. Geremy Condra From ian.g.kelly at gmail.com Thu Jul 15 02:30:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Jul 2010 00:30:31 -0600 Subject: C interpreter in Lisp/scheme/python In-Reply-To: <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Wed, Jul 14, 2010 at 11:17 PM, bolega wrote: > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. I have no record of such a post. From mohana2004 at gmail.com Thu Jul 15 02:56:27 2010 From: mohana2004 at gmail.com (Monyl) Date: Wed, 14 Jul 2010 23:56:27 -0700 (PDT) Subject: Identify the Color of an Image References: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> Message-ID: <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> On Jul 14, 9:01?pm, John Nagle wrote: > On 7/14/2010 5:37 AM, Monyl wrote: > > > Hi, > > > 1. How can I find thecolorof ?animagepresent the webpage? > > > 2. How to identify the font type of the selected text present in the > > content of the web page > > > It would be much helpfull, if anyone responds to it ASAP > > > Thanks > > Mohmyda > > ? ? ?"Selected text"? ?Selected how? ?"Selected" implies some form > of user interface, like a browser. ?If you're doing something in > a browser, look into Firefox and Greasemonkey. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle I will be using a automation tool called Sikuli and select the text or an Image. My Requirement --------------- I will capture the image manually and scriptify using Sikuli. To find the captured image in the web page. Once it finds the image I need to collect the information of the image like, Co-ordinates of the image, height and width, color and pixel rate of the image. If I want to search a particular text in a webpage. I need to find the font name, type, color and size of the text. Note :- We can open the web page in any browser. but I should be able to capture the attributes of the image/Text displayed. From mohana2004 at gmail.com Thu Jul 15 03:13:28 2010 From: mohana2004 at gmail.com (Monyl) Date: Thu, 15 Jul 2010 00:13:28 -0700 (PDT) Subject: Identify the Color of an Image References: Message-ID: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> On Jul 14, 8:51?pm, Gary Herron wrote: > On 07/14/2010 05:37 AM, Monyl wrote: > > > Hi, > > > 1. How can I find thecolorof ?animagepresent the webpage? > > > 2. How to identify the font type of the selected text present in the > > content of the web page > > > It would be much helpfull, if anyone responds to it ASAP > > > Thanks > > Mohmyda > > Please be clearer about what you want. > > 1. Animagedoes not "have" acolor, although each pixel in animage > does have acolor. > > 2. ?Text in a web page does not (necessarily) ?have a font, although the > display engine will use a font of its choice to render text. ?And my > browser will probably use a different font than yours. Hi Gary Herron, 1.If I am going to click on a particular image. I will have click using the co-ordinates of an Image. Can we find the color of the pixel which lies in that particular co-ordinate where I click. 2.I just want to retrive the attributes of the text as it appears on the browser. Can I get the font value depending on the browsers. Hope you understand my problem. From nagle at animats.com Thu Jul 15 03:14:24 2010 From: nagle at animats.com (John Nagle) Date: Thu, 15 Jul 2010 00:14:24 -0700 Subject: floatref In-Reply-To: References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> Message-ID: <4c3eb550$0$1665$742ec2ed@news.sonic.net> On 7/14/2010 12:56 AM, Roald de Vries wrote: > I know, I just wondered if there is a *standard* solution. Yes, there is. class floatref(object) : def __init__(self, initialval) : self.__dict__["_val"] = initialval def __getattr__(self, attrname) : if attrname == 'val' : return(self._val) else : raise AttributeError(attrname) def __setattr__(self, attrname, val) : if attrname == 'val' : self.__dict__["_val"] = val else : raise AttributeError(attrname) x = floatref(1.0) y = x print(x.val) x.val = 10.0 print(x.val) print(y.val) Are you happy now? John Nagle From sst.misc at gmail.com Thu Jul 15 03:36:25 2010 From: sst.misc at gmail.com (Simon SSt) Date: Thu, 15 Jul 2010 09:36:25 +0200 Subject: Is python suitable for my needs? Message-ID: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Hi, Never too late to discover a new language :-) I hope anybody could help me answering my questions. I'm a technical consultant for a software editor. Our software is running on the UNIX (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x and 10.x. I'd like to know if Python is suitable for helping me: Monitoring the UNIX box? Get some metrics from Sybase and Oracle? Get JMX metrics from Weblogic Server (Weblogic Server is provided with a scripting tool based on Jython) Thanks for your hints. Simon From epost2 at gmail.com Thu Jul 15 03:45:10 2010 From: epost2 at gmail.com (Bruce) Date: Thu, 15 Jul 2010 00:45:10 -0700 (PDT) Subject: whitespace in a word doc Message-ID: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> I'm trying to create a word doc using win32com. I don't get the same whitespace as when printing the same stuff in the dos window. At the terminal I manage to line up the second column like apples 5 pears 7 I do this by adding whitespace characters to the strings in the first column so that their length is equal to that of the longest string in the first column. I print the excact same string to word. but in the word doc somehting happens that messes things up like this : apples 5 pears 7 Needless to say, this is extremely frustrating. But why does it happen, and how can I align the column in word? From youngung.jeong at gmail.com Thu Jul 15 03:54:19 2010 From: youngung.jeong at gmail.com (youngung) Date: Thu, 15 Jul 2010 00:54:19 -0700 (PDT) Subject: insufficient memory problem in running .exe file in ipython Message-ID: <0b71e44b-10e1-4faf-a473-e8f1ed19875e@q16g2000prf.googlegroups.com> Hello! I came across a problem in running a .exe file through ipython. """ os.system(' ~.exe') """ was used. The error message popped up says Memory error: insufficient physical memory available What should I try further? From mail at timgolden.me.uk Thu Jul 15 03:59:30 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 08:59:30 +0100 Subject: whitespace in a word doc In-Reply-To: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: <4C3EBFE2.1090808@timgolden.me.uk> On 15/07/2010 08:45, Bruce wrote: > I'm trying to create a word doc using win32com. I don't get the same > whitespace as when printing the same stuff in the dos window. At the > terminal I manage to line up the second column like > > apples 5 > pears 7 > > I do this by adding whitespace characters to the strings in the first > column so that their length is equal to that of the longest string in > the first column. > > I print the excact same string to word. but in the word doc somehting > happens that messes things up like this : > > apples 5 > pears 7 > > Needless to say, this is extremely frustrating. But why does it > happen, and how can I align the column in word? Couple of things which will help us to help you: 1) Consider what's going on *without* Python: if you take the exact same text and spaces and type it into a Word document, does the same thing happen? If so, then there is something of a gap in your understanding of how Word arranges spaces, especially with proportional fonts. 2) If the text looks fine when you type it in but dodgy when programmed in from Python, post the code here. If there's an issue with the way your code is doing what its' doing, we need to see the code to work that out. (Usually). If you want things to line up in columns in Word, you probably want to do one of two things (possibly both): use a fixed-width font, eg Courier New; use Word tables. If you go the latter route, it can sometimes be easier to generate the equivalent HTML and then ask Word to open it directly. Depends. TJG From nitinpawar432 at gmail.com Thu Jul 15 04:01:06 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 15 Jul 2010 13:31:06 +0530 Subject: Is python suitable for my needs? In-Reply-To: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Message-ID: Python will absolutely will suit for monitoring. I use it on tomcat, mysql , apache and linux as well as freebsd Thanks, Nitin On Thu, Jul 15, 2010 at 1:06 PM, Simon SSt wrote: > Hi, > > Never too late to discover a new language :-) > > I hope anybody could help me answering my questions. I'm a technical > consultant for a software editor. Our software is running on the UNIX > (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x and > 10.x. > > I'd like to know if Python is suitable for helping me: > Monitoring the UNIX box? > Get some metrics from Sybase and Oracle? > Get JMX metrics from Weblogic Server (Weblogic Server is provided with a > scripting tool based on Jython) > > Thanks for your hints. > > Simon > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From epost2 at gmail.com Thu Jul 15 04:06:17 2010 From: epost2 at gmail.com (Bruce) Date: Thu, 15 Jul 2010 01:06:17 -0700 (PDT) Subject: whitespace in a word doc References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: <57cc4790-aaba-4f36-92b6-9246c3f6c649@y4g2000yqy.googlegroups.com> On Jul 15, 9:59?am, Tim Golden wrote: > On 15/07/2010 08:45, Bruce wrote: > > > > > > > I'm trying to create a word doc using win32com. I don't get the same > > whitespace as when printing the same stuff in the dos window. At the > > terminal I manage to line up the second column like > > > apples ? ? ? ? ?5 > > pears ? ? ? ? ? ?7 > > > I do this by adding whitespace characters to the strings in the first > > column so that their length is equal to that of the longest string in > > the first column. > > > I print the excact same string to word. but in the word doc somehting > > happens that messes things up like this : > > > apples ? ? ? ? ? ? ? ? ? ? ? ?5 > > pears ? ? ? ? ? ? ? 7 > > > Needless to say, this is extremely frustrating. But why does it > > happen, and how can I align the column in word? > > Couple of things which will help us to help you: > > 1) Consider what's going on *without* Python: if you take the exact > same text and spaces and type it into a Word document, does the same > thing happen? Yes. Now using courier new. Thanks. From lee8321 at gmail.com Thu Jul 15 04:25:06 2010 From: lee8321 at gmail.com (swiss luxury watches) Date: Thu, 15 Jul 2010 01:25:06 -0700 (PDT) Subject: Balenciaga Envelop Clutch 084357L_CF Message-ID: Balenciaga Envelop Clutch 084357L_CF http://www.bagstag.com/Balenciaga-Envelop-Clutch-084357L_CF.html Balenciaga Envelop Clutch Information : Brand : Balenciaga ( http://www.bagstag.com/Balenciaga.html ) Code : 084357L_CF Balenciaga Envelop Clutch Pure chevre (goatskin) with matching leather trimmings A central zip pocket on flap Leather coated studs on front and corners. Two compartments Attached mirror Llower buckle accent Black cloth interior Each Balenciaga Envelop Clutch replica comes with a Balenciaga dust bag, Balenciaga authenticity card and a Balenciaga care booklet. Size: 12" x 7" General Attributes Style: Clutches & Pouches Color: Tan Gender: Women From engmohamedeid83 at gmail.com Thu Jul 15 05:16:32 2010 From: engmohamedeid83 at gmail.com (M Eid) Date: Thu, 15 Jul 2010 02:16:32 -0700 (PDT) Subject: VoIP Message-ID: <66e754db-5a55-42a7-b73c-8174ea87cb8b@d37g2000yqm.googlegroups.com> Dears, My blog about Voice over Internet protocol networks......Let's improve our general knowledg http://voib-net.blogspot.com/ Thanks&BR From michael at stroeder.com Thu Jul 15 05:23:12 2010 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 15 Jul 2010 11:23:12 +0200 Subject: python ldap recursive In-Reply-To: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> References: <8587b63d-7339-41c4-86a5-3aa61da3956e@s9g2000yqd.googlegroups.com> Message-ID: tekion wrote: > I know perl Net::LDAP could do a recursive search call to LDAP. I don't know perl's Net::LDAP and therefore I'm not sure what you mean with "recursive search call". Personally I'd associate that with recursively processing LDAP tree structure. > What I am running into with Python LDAP on the search call is that I would > l have to wait for the search to complete to get the result. Where as with > Perl recursive search call, I would get the result (not the completed > result) back while the search is still running. In case you're using http://www.python-ldap.org you're probably looking for the asynchronous search methods: http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.search See general note: http://www.python-ldap.org/doc/html/ldap.html#sending-ldap-requests Ciao, Michael. From marek at xivilization.net Thu Jul 15 05:25:18 2010 From: marek at xivilization.net (Marek Kubica) Date: Thu, 15 Jul 2010 11:25:18 +0200 Subject: Is Python portable/Can I install it on an USB Stick? References: <4c3e0ff9$0$6979$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <20100715112518.20138a67@halmanfloyd.lan.local> On 14 Jul 2010 19:28:58 GMT tommybear at hotmail.com (Thomas Tundor) wrote: > Is Python portable? Yes. > Can I install it on an USB Stick? Yes. > Or is Python installing (at least on WinXP) services or register some > DLLs or write something into Registry? Well, the installer is writing something into the registry, although it is not neccessary to run Python. regards, Marek From aimeixu at amazon.com Thu Jul 15 05:38:11 2010 From: aimeixu at amazon.com (aimeixu) Date: Thu, 15 Jul 2010 17:38:11 +0800 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python Message-ID: <4C3ED703.2010703@amazon.com> Hi guys, I really need help to figure out a way to get someone's calendar from mail exchange server with python. I have no idea about how to make it .Or could some nice guys give me some hint?Thank a lot . From tino at wildenhain.de Thu Jul 15 05:48:24 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Thu, 15 Jul 2010 11:48:24 +0200 Subject: floatref In-Reply-To: <4c3eb550$0$1665$742ec2ed@news.sonic.net> References: <4C3CB66B.9030107@digipen.edu> <175F00CB-DF48-4043-B442-84DBA21B6176@gmail.com> <4C3CF63D.20008@digipen.edu> <4c3eb550$0$1665$742ec2ed@news.sonic.net> Message-ID: <4C3ED968.4060406@wildenhain.de> Hi John, Am 15.07.2010 09:14, schrieb John Nagle: > On 7/14/2010 12:56 AM, Roald de Vries wrote: >> I know, I just wondered if there is a *standard* solution. > > Yes, there is. > > class floatref(object) : > def __init__(self, initialval) : > self.__dict__["_val"] = initialval > def __getattr__(self, attrname) : > if attrname == 'val' : > return(self._val) > else : > raise AttributeError(attrname) > def __setattr__(self, attrname, val) : > if attrname == 'val' : > self.__dict__["_val"] = val > else : > raise AttributeError(attrname) Uhm. How would that be different to: class floatref(object): def __init__(self,val): self.val=val ? > > x = floatref(1.0) > y = x > > print(x.val) > x.val = 10.0 > print(x.val) > print(y.val) Regards Tino From manoj.nehame.neha at gmail.com Thu Jul 15 06:01:02 2010 From: manoj.nehame.neha at gmail.com (neha manoj) Date: Thu, 15 Jul 2010 03:01:02 -0700 (PDT) Subject: WATCH KATRINA KAIF SEX VIDEOS Message-ID: <64a2a143-ea34-4868-85d0-05044a63c4a1@s17g2000prh.googlegroups.com> WATCH KATRINA KAIF SEX VIDEOS AT http://katrinakaif-sex.weebly.com/ From mail at timgolden.me.uk Thu Jul 15 06:03:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 11:03:55 +0100 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python In-Reply-To: <4C3ED703.2010703@amazon.com> References: <4C3ED703.2010703@amazon.com> Message-ID: <4C3EDD0B.4030008@timgolden.me.uk> On 15/07/2010 10:38, aimeixu wrote: > Hi guys, > I really need help to figure out a way to get someone's calendar from > mail exchange server with python. I have no idea about how to make it > .Or could some nice guys give me some hint?Thank a lot . There's an IMAP-based recipe here: http://sites.google.com/site/mattpoepping/gcalpython and an IronPython one here: http://exchange2ical.codeplex.com/ and an ADO one here: http://www.codeproject.com/KB/dotnet/Dot_Net_2005.aspx and a CDO one here (search for "Open another users calendar folder"): http://www.cdolive.com/cdo5p2.htm The last two aren't directly Python examples but are easily translated via win32com.client. TJG From eckhardt at satorlaser.com Thu Jul 15 06:24:52 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 15 Jul 2010 12:24:52 +0200 Subject: need help: Is there is a way to get someone's calendar from mail exchange server with python References: Message-ID: aimeixu wrote: > I really need help to figure out a way to get someone's calendar from > mail exchange server with python. You can implement any network protocol with Python, see e.g. the struct library. However, it would be easier to use an existing protocol implementation. When you say "mail exchange server", what exactly does that mean? I guess you actually mean an Exchange mail which is a product of Microsoft. For that, there is a free implementation of the server-side protocol (openexchange, IIRC). OTOH, you may be able to use the win32 MAPI (message API), but I'm not sure what this can do and if there are Python bindings for it. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From alanwilter at gmail.com Thu Jul 15 06:34:00 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 15 Jul 2010 11:34:00 +0100 Subject: python3: help with pickle Message-ID: Hi there, This is more an exercise to myself to understand python3. I took a code I wrote (acpype) and I am trying to make it compatible with either python 3 or 2. I am trying to make a pickle file compatible with either python 3 and 2 as I believe it should be possible. I've looked at http://docs.python.org/py3k/library/pickle.html but still, when I create a pickle file for an object with python 2.7 and then I try to load it in python3, I got this: Python 3.1.2 (r312:79147, Jul 7 2010, 10:55:24) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from acpype import * # this acpype package contains needed class ACTopol >>> import pickle >>> o = pickle.load(open('AAA.acpype/AAA.pkl','rb')) Traceback (most recent call last): File "", line 1, in File "/sw/lib/python3.1/pickle.py", line 1365, in load encoding=encoding, errors=errors).load() TypeError: ('__init__() takes at least 2 positional arguments (1 given)', , ()) >>> Now trying the contrary, pickle file is created with python3, I got this when trying to load it with python 2.7: Python 2.7 (r27:82500, Jul 7 2010, 10:48:15) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from acpype import * >>> import pickle >>> o = pickle.load(open('AAA.pkl','rb')) Traceback (most recent call last): File "", line 1, in File "/sw/lib/python2.7/pickle.py", line 1378, in load return Unpickler(file).load() File "/sw/lib/python2.7/pickle.py", line 858, in load dispatch[key](self) File "/sw/lib/python2.7/pickle.py", line 1083, in load_newobj obj = cls.__new__(cls, *args) AttributeError: class ACTopol has no attribute '__new__' Apart that, everything else seems to work. Just one note more: when loading the pickle file 2.7 in python 2.7, type(o) is , while pickle 3 in python 3, type(o) is Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From pwdyson at yahoo.com Thu Jul 15 07:00:53 2010 From: pwdyson at yahoo.com (Paul) Date: Thu, 15 Jul 2010 04:00:53 -0700 (PDT) Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... Message-ID: <299733.71288.qm@web53601.mail.re2.yahoo.com> I'm pleased to announce the release of inflect.py v0.1.8, a module that correctly generates: * the plural of singular nouns and verbs * the singular of plural nouns * ordinals * indefinite articles * present participles * and converts numbers to words Examples: >>> import inflect >>> p = inflect.engine() >>> p.pl('cat') 'cats' >>> p.pl('sheep') 'sheep' >>> p.pl('bacterium') 'bacteria' plural of singular verbs: it walks -> they walk >>> p.pl('walks') 'walk' singular of plural nouns: >>> p.sinoun('bacteria') 'bacterium' >>> p.sinoun('knives') 'knife' ordinals: >>> p.ordinal(31) '31st' >>> p.ordinal('twenty-five') 'twenty-fifth' indefinite articles: >>> p.a('horse') 'a horse' >>> p.a('ant') 'an ant' >>> p.a('hour') 'an hour' present participles: >>> p.prespart('drinks') 'drinking' >>> p.prespart('runs') 'running' >>> p.prespart('flies') 'flying' numbers to words: >>> p.numwords(1234567) 'one million, two hundred and thirty-four thousand, five hundred and sixty-seven' Installation: "pip install inflect" or "easy_install inflect" PyPi: http://pypi.python.org/pypi/inflect Bug Tracker: http://github.com/pwdyson/inflect.py/issues Source Code: http://github.com/pwdyson/inflect.py Cheers, Paul Dyson -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jul 15 07:12:16 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 04:12:16 -0700 Subject: python3: help with pickle In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 3:34 AM, Alan wrote: > Hi there, > This is more an exercise to myself to understand python3. I took a code I > wrote (acpype) and I am trying to make it compatible with either python 3 or > 2. > I am trying to make a pickle file compatible with either python 3 and 2 as I > believe it should be possible. > I've looked at?http://docs.python.org/py3k/library/pickle.html but still, > when I create a pickle file for an object with python 2.7 and then I try to > load it in python3, I got this: > Python 3.1.2 (r312:79147, Jul ?7 2010, 10:55:24) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from acpype import * # this acpype package contains needed class?ACTopol >>>> import pickle >>>> o = pickle.load(open('AAA.acpype/AAA.pkl','rb')) > Traceback (most recent call last): > ??File "", line 1, in > ??File "/sw/lib/python3.1/pickle.py", line 1365, in load > ?? ?encoding=encoding, errors=errors).load() > TypeError: ('__init__() takes at least 2 positional arguments (1 given)', > , ()) >>>> > Now trying the contrary, pickle file is created with python3, I got this > when trying to load it with python 2.7: > Python 2.7 (r27:82500, Jul ?7 2010, 10:48:15) > [GCC 4.2.1 (Apple Inc. build 5659)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from acpype import * >>>> import pickle >>>> o = pickle.load(open('AAA.pkl','rb')) > Traceback (most recent call last): > ??File "", line 1, in > ??File "/sw/lib/python2.7/pickle.py", line 1378, in load > ?? ?return Unpickler(file).load() > ??File "/sw/lib/python2.7/pickle.py", line 858, in load > ?? ?dispatch[key](self) > ??File "/sw/lib/python2.7/pickle.py", line 1083, in load_newobj > ?? ?obj = cls.__new__(cls, *args) > AttributeError: class ACTopol has no attribute '__new__' > Apart that, everything else seems to work. Just one note more: when loading > the pickle file 2.7 in python 2.7, type(o) is?, while > pickle 3 in python 3, type(o) is? Your AbstractTopol class needs to inherit from class `object` so that it (and its descendant ACTopol) become new-style classes. Old-style classes don't exist in Python 3, and I think this is at least partly the cause of your problem. Cheers, Chris -- http://blog.rebertia.com From kwutzke at web.de Thu Jul 15 07:35:06 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 04:35:06 -0700 (PDT) Subject: Extending objects by a method? Message-ID: Hello, I'm new to Python so beware. I have a hierarchical object structure which I iterate over (the elements/classes of interest). I would like to apply the Visitor pattern onto this object structure, so I must add an "accept" method to every object (I'm interesting in) for the Visitor pattern to work. Is there any Python-inbuilt way to dynamically add a method or do I have to wrap each iterated object into a Decorator supplying the accept method? The latter would mean having to rebuild the (part) hierarchy with the Decorator objects before running the Visitor, which I'd like to avoid. Karsten From kwutzke at web.de Thu Jul 15 07:45:08 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 04:45:08 -0700 (PDT) Subject: Extending objects by a method? References: Message-ID: Small correction: I probably have to add a method to a class, so that every object instantiated not by me has the desired functionality. Karsten From maaindia0 at gmail.com Thu Jul 15 08:07:10 2010 From: maaindia0 at gmail.com (easy money) Date: Thu, 15 Jul 2010 05:07:10 -0700 (PDT) Subject: See Hot College Girls Latest Sex Videos. Message-ID: See Hot College Girls Latest Sex Videos. At http://beatifulcollegegirls.tk Due to high sex content, i have hidden the videos in an image. in that website on Top Side search box Above click on image and watch videos in all angles. please don,t tell to anyone. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 15 08:11:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 12:11:51 GMT Subject: insufficient memory problem in running .exe file in ipython References: <0b71e44b-10e1-4faf-a473-e8f1ed19875e@q16g2000prf.googlegroups.com> Message-ID: <4c3efb07$0$11101$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 00:54:19 -0700, youngung wrote: > Hello! > > I came across a problem in running a .exe file through ipython. """ > os.system(' ~.exe') """ was used. The error message popped up says > > Memory error: insufficient physical memory available > > What should I try further? More memory? What's your operating system, how much memory do you have, how much memory does ' ~.exe' (that's a weird name) need? Is your operating system set to limit the amount of memory each process is given? What happens if you don't use ipython but call os.system(' ~.exe') from the normal Python prompt? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Jul 15 08:26:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Jul 2010 12:26:08 GMT Subject: Is python suitable for my needs? References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> Message-ID: <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> On Thu, 15 Jul 2010 09:36:25 +0200, Simon SSt wrote: > Hi, > > Never too late to discover a new language :-) > > I hope anybody could help me answering my questions. I'm a technical > consultant for a software editor. Our software is running on the UNIX > (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x > and 10.x. > > I'd like to know if Python is suitable for helping me: Monitoring the > UNIX box? You're probably better off using existing tools like Nagios and Munin rather than trying to reinvent the wheel. But yes, Python is a fine language for tasks like that. Server monitoring is an awfully big wheel to reinvent though; you should have a good reason for not using an existing, well-tested and supported product. > Get some metrics from Sybase and Oracle? Google blocked where you are? http://www.oracle.com/technology/pub/articles/prez-python-queries.html http://wiki.oracle.com/page/Python If you've got specific questions that you couldn't answer by googling, you should say so. > Get JMX metrics from Weblogic > Server (Weblogic Server is provided with a scripting tool based on > Jython) That's a pretty good hint. Are you aware that Jython is Python implemented in Java instead of C? In other words, Jython *is* Python. -- Steven From lanyjie at yahoo.com Thu Jul 15 08:30:53 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Thu, 15 Jul 2010 05:30:53 -0700 (PDT) Subject: empty set and empty dict for Python 3 Message-ID: <9760.58719.qm@web54201.mail.re2.yahoo.com> Hi there, Maybe somebody already suggested this: How about "{:}" for the empty dict, so that "{}" can denote the empty set? Yingjie From mail at timgolden.me.uk Thu Jul 15 08:44:18 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Jul 2010 13:44:18 +0100 Subject: empty set and empty dict for Python 3 In-Reply-To: <9760.58719.qm@web54201.mail.re2.yahoo.com> References: <9760.58719.qm@web54201.mail.re2.yahoo.com> Message-ID: <4C3F02A2.2000807@timgolden.me.uk> On 15/07/2010 13:30, Yingjie Lan wrote: > Hi there, > > Maybe somebody already suggested this: > > How about "{:}" for the empty dict, > so that "{}" can denote the empty set? Well one thing is that {} has denoted the empty dict for many many releases of Python so a *lot* of code would break if you suddenly switched... TJG From __peter__ at web.de Thu Jul 15 08:49:16 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Jul 2010 14:49:16 +0200 Subject: empty set and empty dict for Python 3 References: Message-ID: Yingjie Lan wrote: > Maybe somebody already suggested this: > > How about "{:}" for the empty dict, > so that "{}" can denote the empty set? http://mail.python.org/pipermail/python-3000/2007-April/006620.html From ranjithtenz at gmail.com Thu Jul 15 09:04:32 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Thu, 15 Jul 2010 18:34:32 +0530 Subject: how to install all python plugins Message-ID: Hi! I`m using ubuntu 10.04 I want to install all the python plugins at once or the python plugins list. thank you in advance -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From maaindia19 at gmail.com Thu Jul 15 09:07:43 2010 From: maaindia19 at gmail.com (free money) Date: Thu, 15 Jul 2010 06:07:43 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <741067d6-4608-4f32-85e8-002b61d42378@n19g2000prf.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account At http://easyhappydays.tk Due to high security risks, i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. please don,t tell to any One. From maaindia19 at gmail.com Thu Jul 15 09:08:34 2010 From: maaindia19 at gmail.com (free money) Date: Thu, 15 Jul 2010 06:08:34 -0700 (PDT) Subject: Simple Hack To Get $2000 To Your PayPal Account Message-ID: <1ea5528d-885f-40e7-849a-883a3840da97@t13g2000prf.googlegroups.com> Simple Hack To Get $2000 To Your PayPal Account At http://easyhappydays.tk Due to high security risks, i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. please don,t tell to any One. From alanwilter at gmail.com Thu Jul 15 09:13:37 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 15 Jul 2010 14:13:37 +0100 Subject: python3: signal.signal/singal.alarm Message-ID: Hi there, I have this, say timeTol = 5 (5 seconds) and 'cmd' takes minutes to execute : import subprocess as sub ... p = sub.Popen(cmd, shell=True, stderr = sub.STDOUT, stdout = sub.PIPE) pid = p.pid signal.signal(signal.SIGALRM, signal_handler) signal.alarm(timeTol) And it works on python 2.x. However, on python 3.x, the signal_handler is only called when 'p = sub.Popen...' has finished (after minutes) and signal.alarm appears to not be called at 5 sec. Can someone please explain me this behaviour and how to solve this? Many thanks in advance, Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Thu Jul 15 09:58:53 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 15 Jul 2010 08:58:53 -0500 Subject: Extending objects by a method? In-Reply-To: References: Message-ID: <4C3F141D.6030305@tim.thechases.com> On 07/15/2010 06:45 AM, Karsten Wutzke wrote: > Small correction: I probably have to add a method to a class, so that > every object instantiated not by me has the desired functionality. You mean like: >>> class Foo: ... def __init__(self, greeting): ... self.greeting = greeting ... >>> f = Foo("Hello") >>> def greet(self, other): ... print "%s, %s" % (self.greeting, other) ... >>> Foo.greet = greet >>> f.greet("world") Hello, world -tkc From invalid at invalid.invalid Thu Jul 15 10:10:40 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 15 Jul 2010 14:10:40 +0000 (UTC) Subject: whitespace in a word doc References: <0c7d220e-2753-4716-95ad-4f81fbb986aa@y11g2000yqm.googlegroups.com> Message-ID: On 2010-07-15, Bruce wrote: > I'm trying to create a word doc using win32com. Unfortunately the phrase "word doc" is meaningless. Exactly what format file are you trying to generate? For example: Word97 "doc" or the new "docx" format? > I don't get the same whitespace as when printing the same stuff in > the dos window. At the terminal I manage to line up the second column > like > > apples 5 > pears 7 > > I do this by adding whitespace characters to the strings in the first > column so that their length is equal to that of the longest string in > the first column. Are you just generating an ASCII text file and then opening it in word? > I print the excact same string to word. but in the word doc somehting > happens that messes things up like this : > > apples 5 > pears 7 > > Needless to say, this is extremely frustrating. But why does it > happen, and how can I align the column in word? Why? Because word is using a viable-spaced font and the "dos window" uses a fixed-width font. If you want any control over the appearance of the document, you'll have to either force word to open the file in a fixed-width font, or you'll have to generate a file that contains formatting information. What you appear to want is a table. Generating RTF has worked well for me in the past: http://code.google.com/p/pyrtf-ng/ http://pyrtf.sourceforge.net/ An enahanced version of pyRTF that supports EMF graphics and scaling of graphics is available here: http://www.panix.com/~grante/files/python/PyRTF-0.46.tar.gz If you want to generate graphics, this might be worth a look http://pyemf.sourceforge.net/ You might also be able to generate HTML and then open that file using Word. -- Grant Edwards grant.b.edwards Yow! The Osmonds! You are at all Osmonds!! Throwing up gmail.com on a freeway at dawn!!! From sst.misc at gmail.com Thu Jul 15 10:27:27 2010 From: sst.misc at gmail.com (Simon SSt) Date: Thu, 15 Jul 2010 16:27:27 +0200 Subject: Is python suitable for my needs? In-Reply-To: <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> References: <4c3eba7a$0$4547$4d5ecec7@news.xlned.com> <4c3efe5f$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c3f1acf$0$29537$4c5ecfc7@news.xlned.com> Le 15/07/2010 14:26, Steven D'Aprano a ?crit : > On Thu, 15 Jul 2010 09:36:25 +0200, Simon SSt wrote: > >> Hi, >> >> Never too late to discover a new language :-) >> >> I hope anybody could help me answering my questions. I'm a technical >> consultant for a software editor. Our software is running on the UNIX >> (solaris 10 / AIX 5L), Sybase 15.x / Oracle 10G , Weblogic Server 9.x >> and 10.x. >> >> I'd like to know if Python is suitable for helping me: Monitoring the >> UNIX box? > > You're probably better off using existing tools like Nagios and Munin > rather than trying to reinvent the wheel. But yes, Python is a fine > language for tasks like that. Server monitoring is an awfully big wheel > to reinvent though; you should have a good reason for not using an > existing, well-tested and supported product. > > >> Get some metrics from Sybase and Oracle? > > Google blocked where you are? > > http://www.oracle.com/technology/pub/articles/prez-python-queries.html > http://wiki.oracle.com/page/Python > > If you've got specific questions that you couldn't answer by googling, > you should say so. > > > >> Get JMX metrics from Weblogic >> Server (Weblogic Server is provided with a scripting tool based on >> Jython) > > That's a pretty good hint. Are you aware that Jython is Python > implemented in Java instead of C? In other words, Jython *is* Python. > > Regarding the System monitoring, I agree there are plenty of excellent solution and I shouldn't reinventing the wheel. I just want a script that will give me some info regarding the system state that I can use at any client site...but this monitoring part isn't my priority. Regarding the DB, thanks for your link I'll look at them thoroughly. And finally for JMX, yes I know about Jython so I'll investigate it. Thanks ----- Simon From andrewcrlucas at sympatico.ca Thu Jul 15 11:23:31 2010 From: andrewcrlucas at sympatico.ca (Andrew Lucas) Date: Thu, 15 Jul 2010 08:23:31 -0700 (PDT) Subject: Python source checkout problem Message-ID: I am trying to check-out the python source using subversion. The documentation says that "svn co http://svn.python.org/projects/python/trunk" should do the trick. When I do this I get the following response: "svn: REPORT of '/projects/!svn/vcc/default': 200 OK (http:// svn.python.org)" There is now a hidden .svn folder in my directory, but I can't find any source anywhere, all subdirectories are empty. When I try to update via "svn update" I get the following response. "svn: Server sent unexpected return value (307 Proxy Redirect) in response to OPTIONS request for 'http://svn.python.org/projects/python/ trunk' " Any ideas what I am doing wrong? Thanks, Andrew From guandalino at gmail.com Thu Jul 15 11:54:23 2010 From: guandalino at gmail.com (guandalino) Date: Thu, 15 Jul 2010 08:54:23 -0700 (PDT) Subject: Question about Python upgrade on linux Message-ID: <4c51f0a6-a8a4-43a0-b76c-181eeea847a5@i28g2000yqa.googlegroups.com> Hi, suppose I have python 2.6.4 installed from source and I want to upgrade to 2.6.5. Python standard library is automatically upgraded at 2.6.5 as well, while 3rd party pure Python and extension modules in site-packages don't. Is it safe to keep the old site-packages or is it suggested to reinstall modules and/or recompile extensions using the new Python? And to upgrade from 2.6 to 2.7? Thanks, best regards. From tjreedy at udel.edu Thu Jul 15 12:04:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 15 Jul 2010 12:04:35 -0400 Subject: Python source checkout problem In-Reply-To: References: Message-ID: On 7/15/2010 11:23 AM, Andrew Lucas wrote: > I am trying to check-out the python source using subversion. The > documentation says that Which doc? It probably needs to be changed. > "svn co http://svn.python.org/projects/python/trunk" I believe 'trunk' is frozen as of the 2.7 release. I suspect you want the releasexy-maint branch for some value of x and y or py3k for what is now the main developmemt branch. (3.2a) As to the errors: I am currently browsing the svn view ok. I would try again to make sure it was not a temporary glitch. -- Terry Jan Reedy From mike at nerone.org Thu Jul 15 12:10:02 2010 From: mike at nerone.org (Mike Nerone) Date: Thu, 15 Jul 2010 11:10:02 -0500 Subject: Python source checkout problem In-Reply-To: References: Message-ID: <4C3F32DA.6000608@nerone.org> On 07/15/2010 10:23 AM, Andrew Lucas wrote: > "svn co http://svn.python.org/projects/python/trunk" > > ... > > "svn: Server sent unexpected return value (307 Proxy Redirect) in > response to OPTIONS request for 'http://svn.python.org/projects/python/ > trunk' " > Assuming trunk is what you actually want, I would guess that your environment has a proxy server that's not compatible with subversion getting in your way. Ask your network admins if you're at a business location. Mike Nerone From fetchinson at googlemail.com Thu Jul 15 12:18:49 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 15 Jul 2010 18:18:49 +0200 Subject: how to install all python plugins In-Reply-To: References: Message-ID: > I`m using ubuntu 10.04 I want to install all the python plugins at once > or the python plugins list. > thank you in advance What is a python plugin? If you mean all published packages on the python website, then you probably don't really want to install all of them, only those that you need. If you mean all python packages that are available through the package manager of ubuntu, then you'll need to search the entire list of available packages using ubuntu's package manager, pick out the ones that have 'python' in their names (presumably, this is how it works on fedora) and install them using the above mentioned package manager software. If you don't know how to use it, please see https://help.ubuntu.com/community/SynapticHowto https://help.ubuntu.com/community/InstallingSoftware HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Thu Jul 15 12:24:24 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 15 Jul 2010 18:24:24 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <299733.71288.qm@web53601.mail.re2.yahoo.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> Message-ID: > I'm pleased to announce the release of inflect.py v0.1.8, a module that > correctly generates: > > * the plural of singular nouns and verbs > * the singular of plural nouns > * ordinals > * indefinite articles > * present participles > * and converts numbers to words Wow! Tons of kudos, this must have been hell of a work to put together with all the irregular nouns/verbs/etc, and I really needed something like this for a long time. Thanks a lot, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From thomas at jollans.com Thu Jul 15 12:41:00 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 18:41:00 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <299733.71288.qm@web53601.mail.re2.yahoo.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> Message-ID: <4C3F3A1C.5040208@jollans.com> On 07/15/2010 01:00 PM, Paul wrote: > > > I'm pleased to announce the release of inflect.py v0.1.8, a module that > correctly generates: > > * the plural of singular nouns and verbs > * the singular of plural nouns > * ordinals > * indefinite articles > * present participles > * and converts numbers to words Which languages does it support? If the answer is what I expect it is, did you design the module with multilingualism in mind? From no.email at please.post Thu Jul 15 12:41:07 2010 From: no.email at please.post (kj) Date: Thu, 15 Jul 2010 16:41:07 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: In Thomas Jollans writes: >http://docs.python.org/library/ctypes.html#fundamental-data-types >c_longdouble maps to float Thanks for pointing this out! ~K (Does it make *any difference at all* to use c_longdouble instead of c_double? If not, I wonder what's the point of having c_longdouble at all.) From no.email at please.post Thu Jul 15 12:45:22 2010 From: no.email at please.post (kj) Date: Thu, 15 Jul 2010 16:45:22 +0000 (UTC) Subject: Q for Emacs users: code-folding (hideshow) Message-ID: This is a question _for Emacs users_ (the rest of you, go away :) ). How do you do Python code-folding in Emacs? Thanks! ~K From gscotfleming at yahoo.com Thu Jul 15 12:50:57 2010 From: gscotfleming at yahoo.com (G F) Date: Thu, 15 Jul 2010 09:50:57 -0700 (PDT) Subject: Cannot send email Message-ID: <594998.379.qm@web53205.mail.re2.yahoo.com> A while back I was working for a company and set up a little python script to send out maintenance emails for some equipment we had set up in the field. The script collected information about the equipment composed an email and sent it out to interested persons. Then I left the company and they changed their ISP and got a new IP address. Now the emails are not getting through. The email server is the same as before but it is not working. Below is the error messaage that is reported by the script. Does anyone have any ideas where the trouble is and what can be done about it? The little bit about: "reply: retcode (557); Msg: This mail server does not accept mail addressed to anInterestedPerson at yahoo.com" seems to be telling but I do not know why the server would respond this way. Thank you. >>> s = smtplib.SMTP(emailHost) >>> s.set_debuglevel(1) >>> s.sendmail(emailAddress, sendTo, testTxt) send: 'ehlo [127.0.1.1]\r\n' reply: '250-AUTH LOGIN PLAIN\r\n' reply: '250-AUTH LOGIN\r\n' reply: '250-AUTH=LOGIN\r\n' reply: '250-8BITMIME\r\n' reply: '250-SIZE 40960000\r\n' reply: '250 HELP\r\n' reply: retcode (250); Msg: AUTH LOGIN PLAIN AUTH LOGIN AUTH=LOGIN 8BITMIME SIZE 40960000 HELP send: 'mail FROM: size=10\r\n' reply: '250? Address Okay\r\n' reply: retcode (250); Msg: Address Okay send: 'rcpt TO:\r\n' reply: '557 This mail server does not accept mail addressed to gscotfleming at yahoo.com\r\n' reply: retcode (557); Msg: This mail server does not accept mail addressed to anInterestedPerson at yahoo.com send: 'rset\r\n' Traceback (most recent call last): ? File "", line 1, in ? File "/usr/lib/python2.6/smtplib.py", line 708, in sendmail ??? self.rset() ? File "/usr/lib/python2.6/smtplib.py", line 438, in rset ??? return self.docmd("rset") ? File "/usr/lib/python2.6/smtplib.py", line 363, in docmd ??? return self.getreply() ? File "/usr/lib/python2.6/smtplib.py", line 340, in getreply ??? raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Thu Jul 15 12:58:06 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 18:58:06 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <4C3F3A1C.5040208@jollans.com> References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: Thomas Jollans, 15.07.2010 18:41: > On 07/15/2010 01:00 PM, Paul wrote: >> I'm pleased to announce the release of inflect.py v0.1.8, a module that >> correctly generates: >> >> * the plural of singular nouns and verbs >> * the singular of plural nouns >> * ordinals >> * indefinite articles >> * present participles >> * and converts numbers to words > > Which languages does it support? If the answer is what I expect it is, It is. Most of the time, when people forget to say what they are talking about, assuming that they are either US-Americans or Windows users will hit the nail on the head. Still, a pretty nice tool, I'd say. > did you design the module with multilingualism in mind? Just look at the code, it consists almost exclusively of long lists of words. Multilingualism clearly wasn't a design goal. Stefan From thomas at jollans.com Thu Jul 15 13:04:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 19:04:19 +0200 Subject: ctypes' c_longdouble: underflow error (bug?) In-Reply-To: References: Message-ID: <4C3F3F93.2000803@jollans.com> On 07/15/2010 06:41 PM, kj wrote: > In Thomas Jollans writes: > >> http://docs.python.org/library/ctypes.html#fundamental-data-types > >> c_longdouble maps to float > > Thanks for pointing this out! > ~K > (Does it make *any difference at all* to use c_longdouble instead > of c_double? If not, I wonder what's the point of having c_longdouble > at all.) they're still different types (in C). on my machine, a double is 64 bits wide, while a long double is 128 bits wide. This means that a function that expects a long double argument will expect 16 bytes, but ctypes will only pass 8 bytes if you tell it to pass double. The same applies to return values. From darcy at druid.net Thu Jul 15 13:07:11 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 15 Jul 2010 13:07:11 -0400 Subject: Cannot send email In-Reply-To: <594998.379.qm@web53205.mail.re2.yahoo.com> References: <594998.379.qm@web53205.mail.re2.yahoo.com> Message-ID: <20100715130711.85592265.darcy@druid.net> On Thu, 15 Jul 2010 09:50:57 -0700 (PDT) G F wrote: > Does anyone have any ideas where the trouble is and what can be done > about it? The little bit about: > "reply: retcode (557); Msg: This mail server does not accept mail > addressed to anInterestedPerson at yahoo.com" > seems to be telling but I do not know why the server would respond this way. This is really not a Python question but I think that you will find that the issue is that the server needs to know about the new IP address. The error looks like an anti-relay thing. Contact the mail server admin or ask on a list dedicated to administrating email. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From kwutzke at web.de Thu Jul 15 13:58:34 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 10:58:34 -0700 (PDT) Subject: Code generator and visitor pattern Message-ID: Hello, this is obviously a Python OO question: Since Python isn't stringly typed, single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, which is usually used in OO systems to implement code generators. So, what is the de facto method in Python to handle source code generation? Karsten From jeff at jmcneil.net Thu Jul 15 14:19:31 2010 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 15 Jul 2010 11:19:31 -0700 (PDT) Subject: Question about Python upgrade on linux References: <4c51f0a6-a8a4-43a0-b76c-181eeea847a5@i28g2000yqa.googlegroups.com> Message-ID: On Jul 15, 11:54?am, guandalino wrote: > Hi, suppose I have python 2.6.4 installed from source and I want to > upgrade to 2.6.5. Python standard library is automatically upgraded at > 2.6.5 as well, while 3rd party pure Python and extension modules in > site-packages don't. Is it safe to keep the old site-packages or is it > suggested to reinstall modules and/or recompile extensions using the > new Python? > > And to upgrade from 2.6 to 2.7? > > Thanks, > best regards. Going from 2.6.4 to 2.6.5 ought to be fine (consider the /usr/lib/ python2.x/ naming, and not /usr/lib/python2.x.y naming).When Going from 2.6 to 2.7, you're better off reinstalling your extensions. Thanks, Jeff http://www.jmcneil.net From thomas at jollans.com Thu Jul 15 14:28:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 20:28:47 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F535F.6020002@jollans.com> On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, I expect this is an innocent typo, and you mean strictly. > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, Wait, what? First of all, python is strictly typed in that every object has exactly one type, which is different from other types. So you can't do "1"+2, as you can in some other languages. Anyway, this is interesting: Tell me more about how Python's dynamic nature makes it impossible to do whatever you're trying to do. I'm baffled. What are you trying to do, anyway? > which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from your train of thought, apparently: Now, the thing that code generators probably share is that they write code to files. It depends on what I'm trying to do of course, but I expect there's a good chance that if I wrote a code generator in Python, it wouldn't be particularly object-oriented at all. From kwutzke at web.de Thu Jul 15 14:45:17 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 11:45:17 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: On 15 Jul., 20:28, Thomas Jollans wrote: > On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > > > Hello, > > > this is obviously a Python OO question: > > > Since Python isn't stringly typed, > > I expect this is an innocent typo, and you mean strictly. > > > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, > Yes, typo, I meant strictly. > Wait, what? > First of all, python is strictly typed in that every object has exactly > one type, which is different from other types. So you can't do "1"+2, as > you can in some other languages. > > Anyway, this is interesting: Tell me more about how Python's dynamic > nature makes it impossible to do whatever you're trying to do. I'm > baffled. What are you trying to do, anyway? > > > which is usually used > > in OO systems to implement code generators. So, what is the de facto > > method in Python to handle source code generation? > > WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from > your train of thought, apparently: Now, the thing that code generators > probably share is that they write code to files. It depends on what I'm > trying to do of course, but I expect there's a good chance that if I > wrote a code generator in Python, it wouldn't be particularly > object-oriented at all. Well, I'm most experienced in OO, so writing OO in Python seems like the way to start with Python. The visitor pattern uses single- dispatch, that is, it determines which method to call be the type of object passed in. I did some reading and it turned out that Python can't do it without some tricks (function decorators and 3rd party code). For what I'm doing, I can't, or rather don't want to rely on 3rd party code (that has reasons). Thus, the visitor OO pattern must be replaced by some other way. As I expected, you already hinted a non-OO solution. Which is now that *I* am wondering what that would look like... Note, that I have an hierarchical object structure which I want to iterate over, so using OO looked natural to me. If there's a better approach, I'm all ears. Karsten From lists at cheimes.de Thu Jul 15 14:46:13 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 15 Jul 2010 20:46:13 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? Do you mean strongly typed langauge? You are wrong, Python is a strongly typed language. Perhaps you are confusing strong/weak with dynamic/static? These attributes are orthogonal to each other. Python is a strongly and dynamicly typed language. The visitor pattern is required for double dispatching in *some* OO language like C++, to work around issues with inheritance and function overloading. Python's OO works differently. Christian From johan.gronqvist at gmail.com Thu Jul 15 14:57:35 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Thu, 15 Jul 2010 20:57:35 +0200 Subject: how to install all python plugins In-Reply-To: References: Message-ID: 2010-07-15 18:18, Daniel Fetchinson skrev: > > If you mean all python packages that are available through the package > manager of ubuntu, then you'll need to search the entire list of > available packages using ubuntu's package manager, pick out the ones > that have 'python' in their names (presumably, this is how it works on > fedora) and install them using the above mentioned package manager > software. To install all packages whose names start with "python-" in ubuntu: "apt-get install python-*" (as root, or prepended with sudo) / johan From kwutzke at web.de Thu Jul 15 15:00:00 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 15 Jul 2010 12:00:00 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> > > Yes, typo, I meant strictly. > Damn, I mean strongly. At least not for identifying which methods to call depending on the type/s. Karsten From thomas at jollans.com Thu Jul 15 15:07:10 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 21:07:10 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F5C5E.4010908@jollans.com> On 07/15/2010 08:45 PM, Karsten Wutzke wrote: > On 15 Jul., 20:28, Thomas Jollans wrote: >> On 07/15/2010 07:58 PM, Karsten Wutzke wrote: >> >>> Hello, >> >>> this is obviously a Python OO question: >> >>> Since Python isn't stringly typed, >> >> I expect this is an innocent typo, and you mean strictly. >> >>> single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, >> > > Yes, typo, I meant strictly. > >> Wait, what? >> First of all, python is strictly typed in that every object has exactly >> one type, which is different from other types. So you can't do "1"+2, as >> you can in some other languages. >> >> Anyway, this is interesting: Tell me more about how Python's dynamic >> nature makes it impossible to do whatever you're trying to do. I'm >> baffled. What are you trying to do, anyway? >> >>> which is usually used >>> in OO systems to implement code generators. So, what is the de facto >>> method in Python to handle source code generation? >> >> WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from >> your train of thought, apparently: Now, the thing that code generators >> probably share is that they write code to files. It depends on what I'm >> trying to do of course, but I expect there's a good chance that if I >> wrote a code generator in Python, it wouldn't be particularly >> object-oriented at all. > > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. I did some reading and it turned out that Python > can't do it without some tricks (function decorators and 3rd party > code). Well, yes: the name of a function or method refers to a single callable object and piece of code. if you care about the type of the argument, you must say so explicitly: class A: def dothing(self, obj): if isinstance(obj, str): self.dostringthing(obj) elif isinstance(obj, (int,float)): self.donumberthing(obj) else: self.dogenericthing(obj) # ... while python doesn't have C++-style function overloading, its alternative also doesn't have the limitations that come with it. From nagle at animats.com Thu Jul 15 15:10:49 2010 From: nagle at animats.com (John Nagle) Date: Thu, 15 Jul 2010 12:10:49 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> I had a similar problem back in 2007. See http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems Also see http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs There have been problems with SWIG. There have been problems with how OpenSSL was built (with or without elliptic curve crypto support). And there were some issues with building on 64-bit hardware running 32-bit operating systems, because the build script was checking the wrong system configuration parameter. Not sure what problem you're having with Mac OS X. From the errors, though, I suspect that not all the components involved are consistent with 32/64 bit width. John Nagle On 7/14/2010 10:05 PM, Adam Mercer wrote: > Anyone have any ideas about this? > > Cheers > > Adam > > On Tue, Jul 13, 2010 at 16:18, Adam Mercer wrote: >> Hi >> >> I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 >> (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a >> and it is failing with the following: >> >> 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c >> 106 :info:build swig -python >> -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 >> -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c >> SWIG/_m2crypto.i >> 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 117 :info:build SWIG/_util.i:9: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a >> pointer/reference variable may leak memory. >> 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 >> 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG >> 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd >> -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes >> -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 >> -I/opt/local/include >> -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG >> -c SWIG/_m2crypto_wrap.c -o >> build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING >> 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': >> 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': >> 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': >> 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': >> 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': >> 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': >> 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used >> 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used >> 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': >> 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 138 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token >> 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token >> 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token >> 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token >> 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': >> 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': >> 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets >> in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in >> signedness >> 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': >> 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets >> in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in >> signedness >> 151 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token >> 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token >> 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token >> 156 :info:build SWIG/_m2crypto_wrap.c:6081: error: expected >> declaration specifiers or '...' before 'STACK' >> 157 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_req_add_extensions': >> 158 :info:build SWIG/_m2crypto_wrap.c:6082: error: 'exts' undeclared >> (first use in this function) >> 159 :info:build SWIG/_m2crypto_wrap.c:6082: error: (Each undeclared >> identifier is reported only once >> 160 :info:build SWIG/_m2crypto_wrap.c:6082: error: for each function >> it appears in.) >> 161 :info:build SWIG/_m2crypto_wrap.c: In function >> 'x509_name_entry_create_by_txt': >> 162 :info:build SWIG/_m2crypto_wrap.c:6086: warning: pointer targets >> in passing argument 4 of 'X509_NAME_ENTRY_create_by_txt' differ in >> signedness >> 163 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 164 :info:build SWIG/_m2crypto_wrap.c:6089: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 165 :info:build SWIG/_m2crypto_wrap.c:6095: error: expected ')' before '*' token >> 166 :info:build SWIG/_m2crypto_wrap.c:6105: error: expected ')' before '*' token >> 167 :info:build SWIG/_m2crypto_wrap.c:6131: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 168 :info:build SWIG/_m2crypto_wrap.c:6136: error: expected ')' before '*' token >> 169 :info:build SWIG/_m2crypto_wrap.c:6141: error: expected ')' before '*' token >> 170 :info:build SWIG/_m2crypto_wrap.c:6146: error: expected ')' before '*' token >> 171 :info:build SWIG/_m2crypto_wrap.c:6151: error: expected ')' before '*' token >> 172 :info:build SWIG/_m2crypto_wrap.c:6156: error: expected ')' before '*' token >> 173 :info:build SWIG/_m2crypto_wrap.c:6178: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 174 :info:build SWIG/_m2crypto_wrap.c:6204: error: expected ')' before '*' token >> 175 :info:build SWIG/_m2crypto_wrap.c:6347: error: expected ')' before '*' token >> 176 :info:build SWIG/_m2crypto_wrap.c:6385: error: expected >> declaration specifiers or '...' before 'STACK' >> 177 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_sign1': >> 178 :info:build SWIG/_m2crypto_wrap.c:6386: error: 'stack' undeclared >> (first use in this function) >> 179 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 180 :info:build SWIG/_m2crypto_wrap.c:6390: error: expected >> declaration specifiers or '...' before 'STACK' >> 181 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify1': >> 182 :info:build SWIG/_m2crypto_wrap.c:6400: error: 'stack' undeclared >> (first use in this function) >> 183 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 184 :info:build SWIG/_m2crypto_wrap.c:6418: error: expected >> declaration specifiers or '...' before 'STACK' >> 185 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs7_verify0': >> 186 :info:build SWIG/_m2crypto_wrap.c:6419: error: 'stack' undeclared >> (first use in this function) >> 187 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument >> 3 of 'pkcs7_verify1' from incompatible pointer type >> 188 :info:build SWIG/_m2crypto_wrap.c:6419: warning: passing argument >> 4 of 'pkcs7_verify1' makes integer from pointer without a cast >> 189 :info:build SWIG/_m2crypto_wrap.c:6419: error: too many arguments >> to function 'pkcs7_verify1' >> 190 :info:build SWIG/_m2crypto_wrap.c: At top level: >> 191 :info:build SWIG/_m2crypto_wrap.c:6502: error: expected '=', ',', >> ';', 'asm' or '__attribute__' before '*' token >> 192 :info:build SWIG/_m2crypto_wrap.c: In function 'util_string_to_hex': >> 193 :info:build SWIG/_m2crypto_wrap.c:6553: warning: pointer targets >> in passing argument 1 of 'PyString_FromStringAndSize' differ in >> signedness >> 194 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_ssl_get_ciphers': >> 195 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'STACK' undeclared >> (first use in this function) >> 196 :info:build SWIG/_m2crypto_wrap.c:16900: error: 'result' >> undeclared (first use in this function) >> 197 :info:build SWIG/_m2crypto_wrap.c:16913: error: expected >> expression before ')' token >> 198 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_num': >> 199 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'STACK' undeclared >> (first use in this function) >> 200 :info:build SWIG/_m2crypto_wrap.c:16923: error: 'arg1' undeclared >> (first use in this function) >> 201 :info:build SWIG/_m2crypto_wrap.c:16923: error: expected >> expression before ')' token >> 202 :info:build SWIG/_m2crypto_wrap.c:16934: error: expected >> expression before ')' token >> 203 :info:build SWIG/_m2crypto_wrap.c:16940: warning: implicit >> declaration of function 'sk_ssl_cipher_num' >> 204 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_ssl_cipher_value': >> 205 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'STACK' undeclared >> (first use in this function) >> 206 :info:build SWIG/_m2crypto_wrap.c:16953: error: 'arg1' undeclared >> (first use in this function) >> 207 :info:build SWIG/_m2crypto_wrap.c:16953: error: expected >> expression before ')' token >> 208 :info:build SWIG/_m2crypto_wrap.c:16968: error: expected >> expression before ')' token >> 209 :info:build SWIG/_m2crypto_wrap.c:16979: warning: implicit >> declaration of function 'sk_ssl_cipher_value' >> 210 :info:build SWIG/_m2crypto_wrap.c:16979: warning: cast to pointer >> from integer of different size >> 211 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_ssl_get_peer_cert_chain': >> 212 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'STACK' undeclared >> (first use in this function) >> 213 :info:build SWIG/_m2crypto_wrap.c:16993: error: 'result' >> undeclared (first use in this function) >> 214 :info:build SWIG/_m2crypto_wrap.c:17006: error: expected >> expression before ')' token >> 215 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_num': >> 216 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'STACK' undeclared >> (first use in this function) >> 217 :info:build SWIG/_m2crypto_wrap.c:17016: error: 'arg1' undeclared >> (first use in this function) >> 218 :info:build SWIG/_m2crypto_wrap.c:17016: error: expected >> expression before ')' token >> 219 :info:build SWIG/_m2crypto_wrap.c:17027: error: expected >> expression before ')' token >> 220 :info:build SWIG/_m2crypto_wrap.c:17033: warning: implicit >> declaration of function 'sk_x509_num' >> 221 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_value': >> 222 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'STACK' undeclared >> (first use in this function) >> 223 :info:build SWIG/_m2crypto_wrap.c:17046: error: 'arg1' undeclared >> (first use in this function) >> 224 :info:build SWIG/_m2crypto_wrap.c:17046: error: expected >> expression before ')' token >> 225 :info:build SWIG/_m2crypto_wrap.c:17061: error: expected >> expression before ')' token >> 226 :info:build SWIG/_m2crypto_wrap.c:17072: warning: implicit >> declaration of function 'sk_x509_value' >> 227 :info:build SWIG/_m2crypto_wrap.c:17072: warning: cast to pointer >> from integer of different size >> 228 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_name_entry_set_data': >> 229 :info:build SWIG/_m2crypto_wrap.c:19133: warning: pointer targets >> in assignment differ in signedness >> 230 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_store_ctx_get1_chain': >> 231 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'STACK' undeclared >> (first use in this function) >> 232 :info:build SWIG/_m2crypto_wrap.c:19733: error: 'result' >> undeclared (first use in this function) >> 233 :info:build SWIG/_m2crypto_wrap.c:19741: error: expected >> expression before ')' token >> 234 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_new_null': >> 235 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'STACK' undeclared >> (first use in this function) >> 236 :info:build SWIG/_m2crypto_wrap.c:20570: error: 'result' >> undeclared (first use in this function) >> 237 :info:build SWIG/_m2crypto_wrap.c:20573: error: expected >> expression before ')' token >> 238 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_free': >> 239 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'STACK' undeclared >> (first use in this function) >> 240 :info:build SWIG/_m2crypto_wrap.c:20583: error: 'arg1' undeclared >> (first use in this function) >> 241 :info:build SWIG/_m2crypto_wrap.c:20583: error: expected >> expression before ')' token >> 242 :info:build SWIG/_m2crypto_wrap.c:20593: error: expected >> expression before ')' token >> 243 :info:build SWIG/_m2crypto_wrap.c:20599: warning: implicit >> declaration of function 'sk_x509_free' >> 244 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_push': >> 245 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'STACK' undeclared >> (first use in this function) >> 246 :info:build SWIG/_m2crypto_wrap.c:20609: error: 'arg1' undeclared >> (first use in this function) >> 247 :info:build SWIG/_m2crypto_wrap.c:20609: error: expected >> expression before ')' token >> 248 :info:build SWIG/_m2crypto_wrap.c:20624: error: expected >> expression before ')' token >> 249 :info:build SWIG/_m2crypto_wrap.c:20640: warning: implicit >> declaration of function 'sk_x509_push' >> 250 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_sk_x509_pop': >> 251 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'STACK' undeclared >> (first use in this function) >> 252 :info:build SWIG/_m2crypto_wrap.c:20653: error: 'arg1' undeclared >> (first use in this function) >> 253 :info:build SWIG/_m2crypto_wrap.c:20653: error: expected >> expression before ')' token >> 254 :info:build SWIG/_m2crypto_wrap.c:20664: error: expected >> expression before ')' token >> 255 :info:build SWIG/_m2crypto_wrap.c:20670: warning: implicit >> declaration of function 'sk_x509_pop' >> 256 :info:build SWIG/_m2crypto_wrap.c:20670: warning: cast to pointer >> from integer of different size >> 257 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509_req_add_extensions': >> 258 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'STACK' undeclared >> (first use in this function) >> 259 :info:build SWIG/_m2crypto_wrap.c:20871: error: 'arg2' undeclared >> (first use in this function) >> 260 :info:build SWIG/_m2crypto_wrap.c:20871: error: expected >> expression before ')' token >> 261 :info:build SWIG/_m2crypto_wrap.c:20890: error: expected >> expression before ')' token >> 262 :info:build SWIG/_m2crypto_wrap.c:20901: error: too many arguments >> to function 'x509_req_add_extensions' >> 263 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_lhash': >> 264 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'LHASH' undeclared >> (first use in this function) >> 265 :info:build SWIG/_m2crypto_wrap.c:20978: error: 'result' >> undeclared (first use in this function) >> 266 :info:build SWIG/_m2crypto_wrap.c:20981: error: expected >> expression before ')' token >> 267 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_x509v3_set_conf_lhash': >> 268 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'LHASH' undeclared >> (first use in this function) >> 269 :info:build SWIG/_m2crypto_wrap.c:20991: error: 'arg1' undeclared >> (first use in this function) >> 270 :info:build SWIG/_m2crypto_wrap.c:20991: error: expected >> expression before ')' token >> 271 :info:build SWIG/_m2crypto_wrap.c:21002: error: expected >> expression before ')' token >> 272 :info:build SWIG/_m2crypto_wrap.c:21003: warning: implicit >> declaration of function 'x509v3_set_conf_lhash' >> 273 :info:build SWIG/_m2crypto_wrap.c:21003: warning: cast to pointer >> from integer of different size >> 274 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_x509v3_ext_conf': >> 275 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'LHASH' undeclared >> (first use in this function) >> 276 :info:build SWIG/_m2crypto_wrap.c:21013: error: 'arg1' undeclared >> (first use in this function) >> 277 :info:build SWIG/_m2crypto_wrap.c:21013: error: expected >> expression before ')' token >> 278 :info:build SWIG/_m2crypto_wrap.c:21038: error: expected >> expression before ')' token >> 279 :info:build SWIG/_m2crypto_wrap.c:21054: warning: implicit >> declaration of function 'x509v3_ext_conf' >> 280 :info:build SWIG/_m2crypto_wrap.c:21054: warning: cast to pointer >> from integer of different size >> 281 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_new_null': >> 282 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'STACK' undeclared >> (first use in this function) >> 283 :info:build SWIG/_m2crypto_wrap.c:21113: error: 'result' >> undeclared (first use in this function) >> 284 :info:build SWIG/_m2crypto_wrap.c:21116: error: expected >> expression before ')' token >> 285 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_free': >> 286 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'STACK' undeclared >> (first use in this function) >> 287 :info:build SWIG/_m2crypto_wrap.c:21126: error: 'arg1' undeclared >> (first use in this function) >> 288 :info:build SWIG/_m2crypto_wrap.c:21126: error: expected >> expression before ')' token >> 289 :info:build SWIG/_m2crypto_wrap.c:21136: error: expected >> expression before ')' token >> 290 :info:build SWIG/_m2crypto_wrap.c:21142: warning: implicit >> declaration of function 'sk_x509_extension_free' >> 291 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_push': >> 292 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'STACK' undeclared >> (first use in this function) >> 293 :info:build SWIG/_m2crypto_wrap.c:21152: error: 'arg1' undeclared >> (first use in this function) >> 294 :info:build SWIG/_m2crypto_wrap.c:21152: error: expected >> expression before ')' token >> 295 :info:build SWIG/_m2crypto_wrap.c:21167: error: expected >> expression before ')' token >> 296 :info:build SWIG/_m2crypto_wrap.c:21178: warning: implicit >> declaration of function 'sk_x509_extension_push' >> 297 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_pop': >> 298 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'STACK' undeclared >> (first use in this function) >> 299 :info:build SWIG/_m2crypto_wrap.c:21191: error: 'arg1' undeclared >> (first use in this function) >> 300 :info:build SWIG/_m2crypto_wrap.c:21191: error: expected >> expression before ')' token >> 301 :info:build SWIG/_m2crypto_wrap.c:21202: error: expected >> expression before ')' token >> 302 :info:build SWIG/_m2crypto_wrap.c:21208: warning: implicit >> declaration of function 'sk_x509_extension_pop' >> 303 :info:build SWIG/_m2crypto_wrap.c:21208: warning: cast to pointer >> from integer of different size >> 304 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_num': >> 305 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'STACK' undeclared >> (first use in this function) >> 306 :info:build SWIG/_m2crypto_wrap.c:21218: error: 'arg1' undeclared >> (first use in this function) >> 307 :info:build SWIG/_m2crypto_wrap.c:21218: error: expected >> expression before ')' token >> 308 :info:build SWIG/_m2crypto_wrap.c:21229: error: expected >> expression before ')' token >> 309 :info:build SWIG/_m2crypto_wrap.c:21235: warning: implicit >> declaration of function 'sk_x509_extension_num' >> 310 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_sk_x509_extension_value': >> 311 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'STACK' undeclared >> (first use in this function) >> 312 :info:build SWIG/_m2crypto_wrap.c:21248: error: 'arg1' undeclared >> (first use in this function) >> 313 :info:build SWIG/_m2crypto_wrap.c:21248: error: expected >> expression before ')' token >> 314 :info:build SWIG/_m2crypto_wrap.c:21263: error: expected >> expression before ')' token >> 315 :info:build SWIG/_m2crypto_wrap.c:21274: warning: implicit >> declaration of function 'sk_x509_extension_value' >> 316 :info:build SWIG/_m2crypto_wrap.c:21274: warning: cast to pointer >> from integer of different size >> 317 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_make_stack_from_der_sequence': >> 318 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'STACK' undeclared >> (first use in this function) >> 319 :info:build SWIG/_m2crypto_wrap.c:21308: error: 'result' >> undeclared (first use in this function) >> 320 :info:build SWIG/_m2crypto_wrap.c:21314: error: expected >> expression before ')' token >> 321 :info:build SWIG/_m2crypto_wrap.c: In function >> '_wrap_get_der_encoding_stack': >> 322 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'STACK' undeclared >> (first use in this function) >> 323 :info:build SWIG/_m2crypto_wrap.c:21324: error: 'arg1' undeclared >> (first use in this function) >> 324 :info:build SWIG/_m2crypto_wrap.c:21324: error: expected >> expression before ')' token >> 325 :info:build SWIG/_m2crypto_wrap.c:21335: error: expected >> expression before ')' token >> 326 :info:build SWIG/_m2crypto_wrap.c:21341: warning: implicit >> declaration of function 'get_der_encoding_stack' >> 327 :info:build SWIG/_m2crypto_wrap.c:21341: warning: cast to pointer >> from integer of different size >> 328 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_encrypt': >> 329 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'STACK' undeclared >> (first use in this function) >> 330 :info:build SWIG/_m2crypto_wrap.c:22343: error: 'arg1' undeclared >> (first use in this function) >> 331 :info:build SWIG/_m2crypto_wrap.c:22343: error: expected >> expression before ')' token >> 332 :info:build SWIG/_m2crypto_wrap.c:22366: error: expected >> expression before ')' token >> 333 :info:build SWIG/_m2crypto_wrap.c:22399: warning: implicit >> declaration of function 'pkcs7_encrypt' >> 334 :info:build SWIG/_m2crypto_wrap.c:22399: warning: cast to pointer >> from integer of different size >> 335 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_sign1': >> 336 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'STACK' undeclared >> (first use in this function) >> 337 :info:build SWIG/_m2crypto_wrap.c:22547: error: 'arg3' undeclared >> (first use in this function) >> 338 :info:build SWIG/_m2crypto_wrap.c:22547: error: expected >> expression before ')' token >> 339 :info:build SWIG/_m2crypto_wrap.c:22582: error: expected >> expression before ')' token >> 340 :info:build SWIG/_m2crypto_wrap.c:22615: warning: passing argument >> 4 of 'pkcs7_sign1' makes integer from pointer without a cast >> 341 :info:build SWIG/_m2crypto_wrap.c:22615: error: too many arguments >> to function 'pkcs7_sign1' >> 342 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify1': >> 343 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'STACK' undeclared >> (first use in this function) >> 344 :info:build SWIG/_m2crypto_wrap.c:22628: error: 'arg2' undeclared >> (first use in this function) >> 345 :info:build SWIG/_m2crypto_wrap.c:22628: error: expected >> expression before ')' token >> 346 :info:build SWIG/_m2crypto_wrap.c:22659: error: expected >> expression before ')' token >> 347 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument >> 3 of 'pkcs7_verify1' from incompatible pointer type >> 348 :info:build SWIG/_m2crypto_wrap.c:22692: warning: passing argument >> 4 of 'pkcs7_verify1' makes integer from pointer without a cast >> 349 :info:build SWIG/_m2crypto_wrap.c:22692: error: too many arguments >> to function 'pkcs7_verify1' >> 350 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_verify0': >> 351 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'STACK' undeclared >> (first use in this function) >> 352 :info:build SWIG/_m2crypto_wrap.c:22707: error: 'arg2' undeclared >> (first use in this function) >> 353 :info:build SWIG/_m2crypto_wrap.c:22707: error: expected >> expression before ')' token >> 354 :info:build SWIG/_m2crypto_wrap.c:22734: error: expected >> expression before ')' token >> 355 :info:build SWIG/_m2crypto_wrap.c:22755: warning: passing argument >> 3 of 'pkcs7_verify0' makes integer from pointer without a cast >> 356 :info:build SWIG/_m2crypto_wrap.c:22755: error: too many arguments >> to function 'pkcs7_verify0' >> 357 :info:build SWIG/_m2crypto_wrap.c: In function '_wrap_pkcs7_get0_signers': >> 358 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'STACK' undeclared >> (first use in this function) >> 359 :info:build SWIG/_m2crypto_wrap.c:23188: error: 'arg2' undeclared >> (first use in this function) >> 360 :info:build SWIG/_m2crypto_wrap.c:23188: error: expected >> expression before ')' token >> 361 :info:build SWIG/_m2crypto_wrap.c:23199: error: 'result' >> undeclared (first use in this function) >> 362 :info:build SWIG/_m2crypto_wrap.c:23211: error: expected >> expression before ')' token >> 363 :info:build SWIG/_m2crypto_wrap.c:23227: error: expected >> expression before ')' token >> 364 :info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1 >> >> Anyone know a way to resolve this? >> >> Cheers >> >> Adam >> From stefan_ml at behnel.de Thu Jul 15 15:10:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:10:58 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Karsten Wutzke, 15.07.2010 20:45: > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. Well, then do that. Put the types into a dict and map them to the functions to call, then call the function through the dict. That's a pretty common way to do dispatching. > Note, that I have an hierarchical object structure which I want to > iterate over, so using OO looked natural to me. If there's a better > approach, I'm all ears. You speak in riddles, but my guess is that your problem is that you don't want to dispatch mechanism to match only exact types but also subtypes. No problem, just build your dict incrementally and add new types as they come in. See this file for an example: http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py Stefan From stefan_ml at behnel.de Thu Jul 15 15:14:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:14:56 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> Message-ID: Karsten Wutzke, 15.07.2010 21:00: >> Yes, typo, I meant strictly. > > Damn, I mean strongly. At least not for identifying which methods to > call depending on the type/s. I think you meant "statically typed". http://c2.com/cgi-bin/wiki?StronglyTyped http://www.c2.com/cgi/wiki?StaticTyping Stefan From python at mrabarnett.plus.com Thu Jul 15 15:33:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Jul 2010 20:33:47 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F629B.9000208@mrabarnett.plus.com> Stefan Behnel wrote: > Karsten Wutzke, 15.07.2010 20:45: >> Well, I'm most experienced in OO, so writing OO in Python seems like >> the way to start with Python. The visitor pattern uses single- >> dispatch, that is, it determines which method to call be the type of >> object passed in. > > Well, then do that. Put the types into a dict and map them to the > functions to call, then call the function through the dict. That's a > pretty common way to do dispatching. > > >> Note, that I have an hierarchical object structure which I want to >> iterate over, so using OO looked natural to me. If there's a better >> approach, I'm all ears. > > You speak in riddles, but my guess is that your problem is that you > don't want to dispatch mechanism to match only exact types but also > subtypes. No problem, just build your dict incrementally and add new > types as they come in. See this file for an example: > > http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py > Another variation: the dispatch table starts with entries for certain types then it adds subtypes on demand: def visit(self, obj): try: handler = self.dispatch_table[type(obj)] except KeyError: for disp_type, disp_func in self.dispatch_table.items(): if isinstance(obj, disp_type): self.dispatch_table[type(obj)] = disp_func handler = disp_func else: raise RuntimeError("Visitor does not accept object: %s" % obj) return handler(obj) From samnsparky at gmail.com Thu Jul 15 15:37:26 2010 From: samnsparky at gmail.com (Sparky) Date: Thu, 15 Jul 2010 12:37:26 -0700 (PDT) Subject: Best Pythonic Approach to Annotation/Metadata? Message-ID: Hello Python community! I am building a JSON-RPC web application that uses quite a few models. I would like to return JSON encoded object information and I need a system to indicate which properties should be returned when the object is translated to a JSON encoded string. Unfortunately, this application runs on top of Google's App Engine and, thus, private attributes are not an option. Also, a preliminary search leads me to believe that there are no real established ways to annotate variables. Ideally I want to do something like: def to_JSON(self): returnDict = {} for member in filter(someMethod, inspect.getmembers(self)): returnDict[member[0]] = member[1] return json.dumps(returnDict) I recognize that two solutions would be to 1) include a prefix like "public_" before variable names or 2) have a list/tuple of attributes that should be transmitted, simply using the "in" operator. However, both these options seem like a pretty ungraceful way to do it. Does anyone else have an idea? Are there any established methods to apply metadata / annotations to variables in Python or do you believe one of the above is a good "pythonic" way to solve this problem? I am using 2.6. Thanks, Sam From mccredie at gmail.com Thu Jul 15 15:43:06 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 15 Jul 2010 19:43:06 +0000 (UTC) Subject: Code generator and visitor pattern References: Message-ID: Karsten Wutzke web.de> writes: > So, what is the de facto method in Python to handle source code generation? Take a look at the NodeVisitor class in the ast module in python 2.6+. The visitor pattern is implemented in the python standard library. Matt From stefan_ml at behnel.de Thu Jul 15 15:48:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Jul 2010 21:48:54 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4C3F629B.9000208@mrabarnett.plus.com> References: <4C3F629B.9000208@mrabarnett.plus.com> Message-ID: MRAB, 15.07.2010 21:33: > Stefan Behnel wrote: >> Karsten Wutzke, 15.07.2010 20:45: >>> Well, I'm most experienced in OO, so writing OO in Python seems like >>> the way to start with Python. The visitor pattern uses single- >>> dispatch, that is, it determines which method to call be the type of >>> object passed in. >> >> Well, then do that. Put the types into a dict and map them to the >> functions to call, then call the function through the dict. That's a >> pretty common way to do dispatching. >> >> >>> Note, that I have an hierarchical object structure which I want to >>> iterate over, so using OO looked natural to me. If there's a better >>> approach, I'm all ears. >> >> You speak in riddles, but my guess is that your problem is that you >> don't want to dispatch mechanism to match only exact types but also >> subtypes. No problem, just build your dict incrementally and add new >> types as they come in. See this file for an example: >> >> http://hg.cython.org/cython-devel/file/tip/Cython/Compiler/Visitor.py >> > Another variation: the dispatch table starts with entries for certain > types then it adds subtypes on demand: > > def visit(self, obj): > try: > handler = self.dispatch_table[type(obj)] > except KeyError: > for disp_type, disp_func in self.dispatch_table.items(): > if isinstance(obj, disp_type): > self.dispatch_table[type(obj)] = disp_func > handler = disp_func > else: > raise RuntimeError("Visitor does not accept object: %s" % obj) > return handler(obj) Well, yes, that's basically what the code behind the above link does, except that it follows the type hierarchy correctly to find the closest match. Stefan From ranjithtenz at gmail.com Thu Jul 15 16:02:50 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Fri, 16 Jul 2010 01:32:50 +0530 Subject: Python script to start, restart and stop the apache server Message-ID: Hi, I planned to write a python script to starts the apache server and when the HTTPD goes down/drop it should auto restart and when user chooses stop it should stop the apache server. Here the start and stop should be user set but the restart when the server goes down. Similar to this program, This is shell script, #!/bin/bash # Apache Process Monitor # Restart Apache Web Server When It Goes Down # ------------------------------------------------------------------------- # Copyright (c) 2003 nixCraft project # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- # RHEL / CentOS / Fedora Linux restart command RESTART="/sbin/service httpd restart" # uncomment if you are using Debian / Ubuntu Linux #RESTART="/etc/init.d/apache2 restart" #path to pgrep command PGREP="/usr/bin/pgrep" # Httpd daemon name, # Under RHEL/CentOS/Fedora it is httpd # Under Debian 4.x it is apache2 HTTPD="httpd" # find httpd pid $PGREP ${HTTPD} if [ $? -ne 0 ] # if apache not running then # restart apache $RESTART fi Johan Gr?nqvist and Daniel Fetchinson thanks for your reply. -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkrukoff at ltgc.com Thu Jul 15 16:26:05 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Thu, 15 Jul 2010 14:26:05 -0600 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: <1279225565.4395.9.camel@localhost.localdomain> On Thu, 2010-07-15 at 12:37 -0700, Sparky wrote: > the above is a good "pythonic" way to solve this problem? I am using > 2.6. Hopefully a helpful correction, but if you're running on google app engine, you're using python 2.5 on the google side irrespective of what you're running for development. -- John Krukoff Land Title Guarantee Company From peter.milliken at gmail.com Thu Jul 15 16:34:22 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 15 Jul 2010 13:34:22 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: On Jul 16, 2:45?am, kj wrote: > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > How do you do Python code-folding in Emacs? > > Thanks! > > ~K I don't - when I first looked at folding-mode (I assume this is what you are referring too?) I couldn't be bothered putting the {{{ }}} strings into the code comments - maybe somebody else has had better success with it? But I just couldn't be bothered. Although if you use a template generating system such as ELSE, you could probably work it into the code templates and have them generated automatically. I must admit that I started to modify my code templates once upon a time to provide this but lost interest part way through and just put up with splitting the window and "hiding" the intervening code that way. Personally I think something like "folding" would be better worked into the major mode and performed on a syntactic scan basis i.e. the elisp must understand where the code blocks begin and end and make folding decisions based on where point is located in relation to surround code blocks. Actually, it might be possible now that pymacs is available (well, I say "now" - even though pymacs has been available for quite some time, I looked at folding mode even earlier!) i.e. call a Python helper program that would provide the syntactic scanning of the buffer contents and return appropriate markers into the buffer for the folding mode code to work with. One day when I have run out of other (programming) things to do I might investigate this :-) Anybody else now of any better ideas or whatever? Now that I think about it, I wouldn't mind using folding mode if I could make it "easier" to use myself! :-) Peter From hwpi31 at gmail.com Thu Jul 15 16:40:49 2010 From: hwpi31 at gmail.com (Nonpython) Date: Thu, 15 Jul 2010 13:40:49 -0700 (PDT) Subject: [OFF TOPIC] How to Learn Lambda Calculus: A Guide Message-ID: 1: Try to learn lambda calculus 2: Fail to learn lambda calculus 3: Sit in corner rocking 4: Consider suicide. From peter.milliken at gmail.com Thu Jul 15 16:53:51 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 15 Jul 2010 13:53:51 -0700 (PDT) Subject: How to Learn Lambda Calculus: A Guide References: Message-ID: <33833e4a-e2c0-445a-81f3-d70ffc021900@p22g2000pre.googlegroups.com> On Jul 16, 6:40?am, Nonpython wrote: > 1: Try to learn lambda calculus > 2: Fail to learn lambda calculus > 3: Sit in corner rocking > 4: Consider suicide. You forgot: 5: (quietly) drooling But then that might be part of the advanced course? I really can't remember, my PHD in 'lambda calculus' was done so long ago now... From ian.hobson at ntlworld.com Thu Jul 15 16:54:30 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:54:30 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F7586.2070202@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From ian.hobson at ntlworld.com Thu Jul 15 16:55:35 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:55:35 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F75C7.2020707@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From ian.hobson at ntlworld.com Thu Jul 15 16:55:35 2010 From: ian.hobson at ntlworld.com (Ian Hobson) Date: Thu, 15 Jul 2010 21:55:35 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: <4C3F75C7.2020707@ntlworld.com> On 15/07/2010 18:58, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten > I'm baffled. Not by what you mean by stringly, but.... What feature of Python stops you writing the three parts of the visitor pattern: IIRC you need: A tree walker that creates the visitor and walks the tree calling node.visitFrom(visitor) on each one in the required order. The visitfrom(aVisitor) routines in each node type that calls aVisitor.visitedMyNodeType(self) where MyNodeType is, naturally different for each node type! All the def visitedNodeType(aNode): routines in visitor to generate the code. Simples! No? :) Ian From python at bdurham.com Thu Jul 15 17:14:22 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 15 Jul 2010 17:14:22 -0400 Subject: Possible to include \n chars in doctest code samples or output? Message-ID: <1279228462.13146.1385097561@webmail.messagingengine.com> I'm working with some Python 2.6 code that is using the doctest module for unittests. I tried adding tests whose code and results required newlines (\n). Apparently newlines in string constants breaks the doctest code. Any workarounds other than using another char for newlines and wrapping all my strings with .replace( someChar, chr(10) )? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Thu Jul 15 17:26:59 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 15 Jul 2010 23:26:59 +0200 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279228462.13146.1385097561@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> Message-ID: <4C3F7D23.2060204@jollans.com> On 07/15/2010 11:14 PM, python at bdurham.com wrote: > I'm working with some Python 2.6 code that is using the doctest module > for unittests. > > I tried adding tests whose code and results required newlines (\n). > Apparently newlines in string constants breaks the doctest code. > > Any workarounds other than using another char for newlines and wrapping > all my strings with .replace( someChar, chr(10) )? Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. Remember that the two following strings are identical: """a b""" """a\nb""" As are these two: r"\n" "\\n" Anyway, you need to escape the backslash if you want backslash-n to be in your docstring. Otherwise you'll get a newline like any other newline, not a character sequence doctest can eval() to a newline while processing. From ramercer at gmail.com Thu Jul 15 18:03:13 2010 From: ramercer at gmail.com (Adam Mercer) Date: Thu, 15 Jul 2010 17:03:13 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> References: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 15, 2010 at 14:10, John Nagle wrote: > ? I had a similar problem back in 2007. ?See > > http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems > > Also see > > http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs > > ? There have been problems with SWIG. There have been problems with > how OpenSSL was built (with or without elliptic curve crypto support). > And there were some issues with building on 64-bit hardware running > 32-bit operating systems, because the build script was checking > the wrong system configuration parameter. > > ? Not sure what problem you're having with Mac OS X. ?From the > errors, though, I suspect that not all the components involved > are consistent with 32/64 bit width. Thanks, I'm sure everything is consistent with the architecture, i.e. everything is 64 bit. The last time I build M2Crypto on this box was against SWIG-1.3.x and OpenSSL-0.9.8? So one of these (or both) has broken something... Looks like I'll have to revert each one at a time... Cheers Adam From a.j.romanista at gmail.com Thu Jul 15 18:04:37 2010 From: a.j.romanista at gmail.com (ata.jaf) Date: Thu, 15 Jul 2010 15:04:37 -0700 (PDT) Subject: About problems that I have with learning wxPython in Macintosh Message-ID: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Hi, I'm newbie to wxPython and need it to develop my little app. But from start I have problems with tutorials. Because all of them are compatible with Windows but not so much with Mac. For example in this code: import wx class MainWindow(wx.Frame) : def __init__(self, parent, title) : wx.Frame.__init__(self, parent, title=title, size=(200, 100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.CreateStatusBar() filemenu = wx.Menu() filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this program.') filemenu.AppendSeparator() filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') menuBar = wx.MenuBar() menuBar.Append(filemenu, '&File') self.SetMenuBar(menuBar) self.Show(True) app = wx.App(False) frame = MainWindow(None, 'Sample editor') app.MainLoop() The menus doesn't appear in the product. Can anyone help me to find a tutorial that is for using wxPython on a Mac? Thanks Ata From debatem1 at gmail.com Thu Jul 15 18:14:53 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 15 Jul 2010 15:14:53 -0700 Subject: How to Learn Lambda Calculus: A Guide In-Reply-To: References: <33833e4a-e2c0-445a-81f3-d70ffc021900@p22g2000pre.googlegroups.com> Message-ID: On Thu, Jul 15, 2010 at 1:53 PM, Peter wrote: > On Jul 16, 6:40?am, Nonpython wrote: >> 1: Try to learn lambda calculus >> 2: Fail to learn lambda calculus >> 3: Sit in corner rocking >> 4: Consider suicide. > > You forgot: > > 5: (quietly) drooling > > But then that might be part of the advanced course? I really can't > remember, my PHD in 'lambda calculus' was done so long ago now... No PhD required (if one ever is, besides for jobification purposes). Simple (somewhat shallow) introduction: http://eflorenzano.com/blog/post/lambda-calculus/ A construction of the Church numerals: http://www.stephendiehl.com/?p=66 Not so hard, really. Geremy Condra From debatem1 at gmail.com Thu Jul 15 18:17:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 15 Jul 2010 15:17:48 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: <4c3f5d47$0$1630$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 15, 2010 at 3:03 PM, Adam Mercer wrote: > On Thu, Jul 15, 2010 at 14:10, John Nagle wrote: >> ? I had a similar problem back in 2007. ?See >> >> http://bytes.com/topic/python/answers/613336-more-m2crypto-build-problems >> >> Also see >> >> http://bytes.com/topic/python/answers/711381-m2crypto-0-18-new-version-same-old-build-bugs >> >> ? There have been problems with SWIG. There have been problems with >> how OpenSSL was built (with or without elliptic curve crypto support). >> And there were some issues with building on 64-bit hardware running >> 32-bit operating systems, because the build script was checking >> the wrong system configuration parameter. >> >> ? Not sure what problem you're having with Mac OS X. ?From the >> errors, though, I suspect that not all the components involved >> are consistent with 32/64 bit width. > > Thanks, I'm sure everything is consistent with the architecture, i.e. > everything is 64 bit. The last time I build M2Crypto on this box was > against SWIG-1.3.x and OpenSSL-0.9.8? So one of these (or both) has > broken something... Looks like I'll have to revert each one at a > time... > > Cheers > > Adam The move to 1.0 was a PITA for me, although I appreciate the improved EVP_PKEY support it will probably break a chunk of code. Geremy Condra From mukeshtiwari.iiitm at gmail.com Thu Jul 15 18:22:39 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Thu, 15 Jul 2010 15:22:39 -0700 (PDT) Subject: File transfer on network Message-ID: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Hello all Currently i am trying to develop a client and server in python. Client takes screenshot in every 20 seconds and send it to server. Server store the received file in folder. Here is code for Client import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/tmp_1/screenshot.png',"png") f=open('/home//tmp_1/screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() Server Code import sys import socket import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) host,port="",50007 s.bind((host,port)) s.listen(1) conn,add=s.accept() i=0 while 1: f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') while 1: data=conn.recv(2048) if not data:break f.write(data) f.close() print 'file received' time.sleep(20) i+=1; #print ' file received ' conn.close() My problem is that server is copying only first image copyscreenshot_0.png while my client continuously taking screen shot. Kindly tell me what is wrong with my server code. Thank you Mukesh Tiwari import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False, 8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(), 0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/user/Programs/Mukesh_Tiwari/ python/tmp_1/screenshot.png',"png") f=open('/home/user/Programs/Mukesh_Tiwari/python/tmp_1/ screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "client.py" 25L, 715C 7,2-9 All From samnsparky at gmail.com Thu Jul 15 18:30:11 2010 From: samnsparky at gmail.com (Sparky) Date: Thu, 15 Jul 2010 15:30:11 -0700 (PDT) Subject: Best Pythonic Approach to Annotation/Metadata? References: Message-ID: <4944e4eb-7a04-43f6-a21b-ba122286cc1a@d37g2000yqm.googlegroups.com> On Jul 15, 2:26?pm, John Krukoff wrote: > On Thu, 2010-07-15 at 12:37 -0700, Sparky wrote: > > > > > the above is a good "pythonic" way to solve this problem? I am using > > 2.6. > > Hopefully a helpful correction, but if you're running on google app > engine, you're using python 2.5 on the google side irrespective of what > you're running for development. > > -- > John Krukoff > Land Title Guarantee Company Sorry about that and thanks for pointing out my mistake there. Sam From mukeshtiwari.iiitm at gmail.com Thu Jul 15 18:35:51 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Thu, 15 Jul 2010 15:35:51 -0700 (PDT) Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <3728a08c-f994-4d2e-9d23-cccc91a59990@i18g2000pro.googlegroups.com> Kindly see this post as above post contains some garbage code in end. Sorry for that. Hello all Currently i am trying to develop a client and server in python. Client takes screenshot in every 20 seconds and send it to server. Server store the received file in folder. Here is code for Client import sys import socket import gtk.gdk import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); host,port="localhost",50007 s.connect((host,port)) while 1: w = gtk.gdk.get_default_root_window() sz = w.get_size() pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False, 8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(), 0,0,0,0,sz[0],sz[1]) if (pb != None): pb.save('/home/tmp_1/screenshot.png',"png") f=open('/home//tmp_1/screenshot.png','rb') while 1: blk=f.read(2048) if not blk:break s.send(blk) f.close() print 'file transfer done'; time.sleep(20) s.close() Server Code import sys import socket import time if __name__ == "__main__": s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) host,port="",50007 s.bind((host,port)) s.listen(1) conn,add=s.accept() i=0 while 1: f=open('/home/tmp_2/copyscreenshot_'+str(i) +'.png','wb') while 1: data=conn.recv(2048) if not data:break f.write(data) f.close() print 'file received' time.sleep(20) i+=1; #print ' file received ' conn.close() My problem is that server is copying only first image copyscreenshot_0.png while my client continuously taking screen shot. Kindly tell me what is wrong with my server code. Thank you Mukesh Tiwari From luke.leighton at gmail.com Thu Jul 15 18:39:29 2010 From: luke.leighton at gmail.com (lkcl) Date: Thu, 15 Jul 2010 15:39:29 -0700 (PDT) Subject: multitask http server (single-process multi-connection HTTP server) References: <440a2280-901f-4c9e-ae68-ab908c9f97a7@d16g2000yqb.googlegroups.com> <1278984638.9880.46.camel@tim-laptop> Message-ID: On Jul 13, 12:00?pm, Luke Kenneth Casson Leighton wrote: > but... not being funny or anything, but basically i'm done already :)multitaskhttpdworks, it doesn't need stackless, i completed a JSONRPC > service last night, i'll add POST of multi-part forms today, and i > have everything that [GNUmed] will need. ok instead of adding this to httpd.py i created an HTTP proxy out of multitaskhttpd. i also cobbled together an example JSONRPC Server which is highly likely to be used in gnumed, now. this modified version of SimpleJSONRPCServer.py i had to rip bits of BaseHTTPServer.py and add in Connection Keep-Alives on every response. so, send_error needed modding/replacing, as did send_head, list_directory and so on, all with a view to making sure that the HTTP proxy is "happy". the reason why the proxy works is because the incoming HTTP connection results in an HTTP/1.1 proxy connection with Connection: Keep-Alive set. so, even if the user's browser drops the connection, the proxy permanently keeps open the connection to the upstream HTTP server. in the case of the standard SimpleHTTPServer.py and so on that results in the handle_request() loop basically serving that same user _forever_. well... it would, if it wasn't for the fact that the standard version of send_error() in BaseHTTPServer.py does "Connection: Close", hence the reason why i had to replace it. so, yeah - now you can do truly dreadful things like... create a massive in-memory data structure and never have to serialise it because the back-end process will _still_ be around pretty much forever... and you can keep doing that until the server runs out of memory. hurrah! l. From python at mrabarnett.plus.com Thu Jul 15 19:08:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 00:08:09 +0100 Subject: File transfer on network In-Reply-To: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <4C3F94D9.8020501@mrabarnett.plus.com> mukesh tiwari wrote: > Hello all > Currently i am trying to develop a client and server in python. Client > takes screenshot in every 20 seconds and send it to server. Server > store the received file in folder. Here is code for Client > > import sys > import socket > import gtk.gdk > import time > if __name__ == "__main__": > s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); > host,port="localhost",50007 > s.connect((host,port)) > while 1: > w = gtk.gdk.get_default_root_window() > sz = w.get_size() > pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) > pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) > if (pb != None): > pb.save('/home/tmp_1/screenshot.png',"png") > f=open('/home//tmp_1/screenshot.png','rb') > while 1: > blk=f.read(2048) > if not blk:break > s.send(blk) > f.close() > print 'file transfer done'; > time.sleep(20) > > s.close() > > > Server Code > import sys > import socket > import time > if __name__ == "__main__": > > s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) > host,port="",50007 > s.bind((host,port)) > s.listen(1) > conn,add=s.accept() > i=0 > while 1: > f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') > while 1: > data=conn.recv(2048) > if not data:break > f.write(data) > > f.close() > print 'file received' > time.sleep(20) > i+=1; > #print ' file received ' > > conn.close() > > > My problem is that server is copying only first image > copyscreenshot_0.png while my client continuously taking screen shot. > Kindly tell me what is wrong with my server code. > The .recv will return an empty string only when the connection is closed by the client, but the client keeps the connection open. You could either open and close a connection for each image, or have the client tell the server how many bytes it's going to send, followed by the bytes (my preference would be to send the size as a string ending with, say, a newline). Another point: the .send method doesn't guarantee that it'll send all the bytes (it'll return the number of bytes that it has actually sent); use the .sendall method instead. From pavlovevidence at gmail.com Thu Jul 15 19:14:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jul 2010 16:14:01 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> On Jul 15, 11:45?am, Karsten Wutzke wrote: > On 15 Jul., 20:28, Thomas Jollans wrote: > > > On 07/15/2010 07:58 PM, Karsten Wutzke wrote: > > > > Hello, > > > > this is obviously a Python OO question: > > > > Since Python isn't stringly typed, > > > I expect this is an innocent typo, and you mean strictly. > > > > single-dispatch isn't available per se. So is the "double-dispatch" Visitor pattern, > > Yes, typo, I meant strictly. > > > > > > > Wait, what? > > First of all, python is strictly typed in that every object has exactly > > one type, which is different from other types. So you can't do "1"+2, as > > you can in some other languages. > > > Anyway, this is interesting: Tell me more about how Python's dynamic > > nature makes it impossible to do whatever you're trying to do. I'm > > baffled. What are you trying to do, anyway? > > > > which is usually used > > > in OO systems to implement code generators. So, what is the de facto > > > method in Python to handle source code generation? > > > WHOA! Now if that isn't a Gedankensprung. Also, I'm still very far from > > your train of thought, apparently: Now, the thing that code generators > > probably share is that they write code to files. It depends on what I'm > > trying to do of course, but I expect there's a good chance that if I > > wrote a code generator in Python, it wouldn't be particularly > > object-oriented at all. > > Well, I'm most experienced in OO, so writing OO in Python seems like > the way to start with Python. The visitor pattern uses single- > dispatch, that is, it determines which method to call be the type of > object passed in. I did some reading and it turned out that Python > can't do it without some tricks (function decorators and 3rd party > code). For what I'm doing, I can't, or rather don't want to rely on > 3rd party code (that has reasons). Thus, the visitor OO pattern must > be replaced by some other way. Oh brother. Around these parts, we consider the main use of most Design Patterns to be to work around limitations of other languages. Visitor Pattern is probably the worst example of it. In Python it's completely unnecessary (at least in its boilerplate- heavy incarnation as used in C++), and the fact that Python isn't strongly typed, as you put it, is exactly the reason why. Say you have a bunch of unrelated types that define a calculate method, you have a variable x that could be any of these types. Here's how you would do that in Python: x.calculate() Bam, that's it. Visitor Pattern in Python. You don't have to create a bunch of homemade dispatching boilerplate like you do in C++. Carl Banks From missive at hotmail.com Thu Jul 15 19:20:42 2010 From: missive at hotmail.com (Lee Harr) Date: Fri, 16 Jul 2010 03:50:42 +0430 Subject: [ANNC] pynguin-0.9 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release has focused on improvements to usabilty and ??? user-friendliness, with much input and many reports ??? from actual users. Thanks Alec! There is a huge list ??? of bug fixes and new features. Pynguin is tested with Python 2.6.5 and PyQt 4.7.2 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.9: ??? Pynguin API ??????? - added pythonic accessors for .x .y and .heading ??????? - added methods for getting heading: xyh() and h() ??????? - added promote() method to change which pynguin is primary ??????? - added remove() to get rid of unneeded pynguins ??????????? - also enables removing pynguin, but keeping its drawing ??????????? - added reap() method to remove all other pynguins and ??????????????? take charge of all their drawings at once ??????? - made turnto() instant, like goto() ??????? - plain reset() now only affects single pynguin ??????????? - restores as much as possible to initial state ??????????? - use reset(True) or reset(full=True) for complete reset ??????? - square() is now built in ??????? - added avatar() to access setImageid() more reliably ??????? - changed onclick() API slightly ??????????? - updated onclick examples and added new examples ??? Canvas ??????? - added ability to zoom and pan the canvas ??????? - added ability to track pynguin if it draws off the screen ??????? - pynguins can now be dragged in to position ??????? - now passes mouse clicks to all pynguins ??? Integrated Editor ??????? - fixed problem with editor undo entries being lost ??????? - better recognition of when document has actually been modified ??????? - automatically strips prompts when pasting to code editor ??????? - allow changing font size and word wrapping in editor ??????? - fixed tabifying/untabifying selection in editor ??? Integrated Console ??????? - fixed copying from console area (shortcut and context menu) ??????? - KeyboardInterrupt is now quiet by default ??????? - fixed tab/backtab in console area ??????? - added keyboard shortcuts for scrolling in console ??????? - added ctrl-d shortcut for exiting when typing in console ??? General ??????? - added periodic automatic saving ??????? - better control-c handling ??????????? - code that never uses Pynguin methods can now be stopped ??????????? - limits print rate to keep console responsive ??????????? - fixed prompt alignment after ctrl-c on non-function code ??????? - made .png default export and improved error message on failure ??????? - now allows unicode in code area and console ??????? - added command line switch to enable debugging ??????? - added Save As, New, and Open shortcuts _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 From benjamin.kaplan at case.edu Thu Jul 15 19:28:31 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 15 Jul 2010 16:28:31 -0700 Subject: About problems that I have with learning wxPython in Macintosh In-Reply-To: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> References: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Message-ID: On Thu, Jul 15, 2010 at 3:04 PM, ata.jaf wrote: > Hi, > I'm newbie to wxPython and need it to develop my little app. > But from start I have problems with tutorials. Because all of them are > compatible with Windows but not so much with Mac. > For example in this code: > > > import wx > > class MainWindow(wx.Frame) : > def __init__(self, parent, title) : > wx.Frame.__init__(self, parent, title=title, size=(200, 100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.CreateStatusBar() > > filemenu = wx.Menu() > > filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this > program.') > filemenu.AppendSeparator() > filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') > > menuBar = wx.MenuBar() > menuBar.Append(filemenu, '&File') > self.SetMenuBar(menuBar) > self.Show(True) > > app = wx.App(False) > frame = MainWindow(None, 'Sample editor') > app.MainLoop() > > > > The menus doesn't appear in the product. > Can anyone help me to find a tutorial that is for using wxPython on a > Mac? > Thanks > Ata > -- > Did you look on the menubar? wxPython uses native components (Cocoa in the case of OS X) so the menu should appear in the menu bar and not in the application window. wx will automatically move some of the items in the menu to the appropriate location (About, Preferences, and Quit are all in the Application menu for instance and not the file menu) The wxPython Wiki has a page about Mac-specific issues : http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X Also, you'll get better answer for questions like this (which are wx-specific and not Python-specific) on the wxPython list: http://groups.google.com/group/wxpython-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes.black at gmail.com Thu Jul 15 19:46:35 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 15 Jul 2010 16:46:35 -0700 (PDT) Subject: Errno 9] Bad file descriptor References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: > Where does the error occur? If Cameron is right, it occurs somewhere > completely different, when serializer.dump() is already long done, when > some unsuspecting fool tries to do something with serializer.outf (such > as closing it) I have found it but still I don't get it. Dump looks like this: ... File "C: ... ineptpdf8.4.20.pyw", line 1266, in initialize return self.initialize_fopn(docid, param) File "C: ... ineptpdf8.4.20.pyw", line 1411, in initialize_fopn print buildurl IOError: [Errno 9] Bad file descriptor Two strange things: 1st: in the buildurl is only the url (as a string) to open (something like http://www.serverblaba.com/asdfasdf?wdfasdf=4&awfwf=34 ...) 2nd: it works if I start in in IDLE, it doesn't work if I double klick on the .pyw file. How can printing out a string throw a IOError exception? I'm quite puzzled. From f2h2d2 at gmail.com Thu Jul 15 19:46:40 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Thu, 15 Jul 2010 16:46:40 -0700 (PDT) Subject: Fairy scenes Message-ID: <9837d665-a093-41f0-aba4-4261b40271ea@j4g2000yqh.googlegroups.com> Fairy scenes The sections that cried and asked YouTube viewers translation: http://www.youtube.com/v/IFq9cjtrWlQ&rel=0 http://www.youtube.com/v/y2BN73Q-AJw&rel=0 http://www.youtube.com/v/nNFMvznJ-4c&rel=0 http://www.youtube.com/v/qVB9HNQ-w2I&rel=0 http://www.youtube.com/v/RWfR9z91j8I&rel=0 http://www.todayislam.com/yusuf.htm http://islamtomorrow.com From python at mrabarnett.plus.com Thu Jul 15 20:07:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 01:07:33 +0100 Subject: Errno 9] Bad file descriptor In-Reply-To: References: <11d55a84-011a-4cfd-9e98-fd4d450e1434@w30g2000yqw.googlegroups.com> Message-ID: <4C3FA2C5.5050404@mrabarnett.plus.com> joblack wrote: >> Where does the error occur? If Cameron is right, it occurs somewhere >> completely different, when serializer.dump() is already long done, when >> some unsuspecting fool tries to do something with serializer.outf (such >> as closing it) > I have found it but still I don't get it. > > Dump looks like this: > > ... > > File "C: ... ineptpdf8.4.20.pyw", line 1266, in initialize return > self.initialize_fopn(docid, param) > File "C: ... ineptpdf8.4.20.pyw", line 1411, in initialize_fopn print > buildurl > > IOError: [Errno 9] Bad file descriptor > > Two strange things: > > 1st: in the buildurl is only the url (as a string) to open (something > like http://www.serverblaba.com/asdfasdf?wdfasdf=4&awfwf=34 ...) > 2nd: it works if I start in in IDLE, it doesn't work if I double klick > on the .pyw file. > > How can printing out a string throw a IOError exception? I'm quite > puzzled. The extension .pyw says to run the script without opening a console window. If there's no console, the script can't print to it. Result? IOError exception. From nfdisco at gmail.com Thu Jul 15 20:42:01 2010 From: nfdisco at gmail.com (ernest) Date: Thu, 15 Jul 2010 17:42:01 -0700 (PDT) Subject: __getattribute__ hook and len() problem Message-ID: Hi! I have this class that overrides the __getattribute__ method, so that it returns the attributes of str(self) instead of the attributes of self. class Part(object): def __init__(self): self.content = [] def __str__(self): return str.join('\n', self.content) def __getattribute__(self, name): if name in ['content', 'write', '__str__']: return object.__getattribute__(self, name) else: return str(self).__getattribute__(name) def write(self, data): self.content.append(data) Then I do: In [50]: p = Part() In [51]: p.write('foo') In [52]: p.upper() Out[56]: 'FOO' This is okay, works as expected. However, len(p) fails: TypeError: object of type 'Part' has no len() And yet, p.__len__() returns 3. I though len(object) simply called object.__len__. Can somebody shed some light on this?? Many thanks in advance. Ernest From cbc at unc.edu Thu Jul 15 20:50:17 2010 From: cbc at unc.edu (Chris Calloway) Date: Thu, 15 Jul 2010 20:50:17 -0400 Subject: Toronto PyCamp 2010 Message-ID: <4C3FACC9.6030208@unc.edu> The University of Toronto Department of Physics brings PyCamp to Toronto on Monday, August 30 through Friday, September 3, 2010. Register today at http://trizpug.org/boot-camp/torpy10/ For beginners, this ultra-low-cost Python Boot Camp makes you productive so you can get your work done quickly. PyCamp emphasizes the features which make Python a simpler and more efficient language. Following along with example Python PushUps? speeds your learning process in a modern high-tech classroom. Become a self-sufficient Python developer in just five days at PyCamp! Conducted on the campus of the University of Toronto, PyCamp comes with your own single OS/single developer copy of Wing Professional Python IDE. -- Sincerely, Chris Calloway office: 332 Chapman Hall phone: (919) 599-3530 mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599 From clp2 at rebertia.com Thu Jul 15 20:51:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 17:51:56 -0700 Subject: __getattribute__ hook and len() problem In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 5:42 PM, ernest wrote: > Hi! > > I have this class that overrides the __getattribute__ method, > so that it returns the attributes of str(self) instead of the > attributes of self. > > class Part(object): > ? ?def __init__(self): > ? ? ? ?self.content = [] > ? ?def __str__(self): > ? ? ? ?return str.join('\n', self.content) > ? ?def __getattribute__(self, name): > ? ? ? ?if name in ['content', 'write', '__str__']: > ? ? ? ? ? ?return object.__getattribute__(self, name) > ? ? ? ?else: > ? ? ? ? ? ?return str(self).__getattribute__(name) > ? ?def write(self, data): > ? ? ? ?self.content.append(data) > > Then I do: > > In [50]: p = Part() > > In [51]: p.write('foo') > > However, len(p) fails: > > TypeError: object of type 'Part' has no len() > > And yet, p.__len__() returns 3. I though len(object) simply > called object.__len__. > > Can somebody shed some light on this?? Quoth http://docs.python.org/reference/datamodel.html#more-attribute-access-for-new-style-classes : """ 3.4.2.1. More attribute access for new-style classes object.__getattribute__(self, name) ***Note: This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions. See Special method lookup for new-style classes (http://docs.python.org/reference/datamodel.html#new-style-special-lookup ).*** """ (emphasis mine) Cheers, Chris -- http://blog.rebertia.com From lists at cheimes.de Thu Jul 15 20:56:12 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jul 2010 02:56:12 +0200 Subject: __getattribute__ hook and len() problem In-Reply-To: References: Message-ID: > And yet, p.__len__() returns 3. I though len(object) simply > called object.__len__. Not exactly, all __magic__ methods of new style classes are called like getattr(type(obj), "__len__")(obj). As a result magic methods are never looked up on the object, including hooks like __getattr_() and __getattribute__(). Christian From aahz at pythoncraft.com Thu Jul 15 20:59:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Jul 2010 17:59:31 -0700 Subject: Naming Conventions, Where's the Convention Waldo? References: <3e96f640-4aaa-45e6-aa15-a9ab43dbddc8@c10g2000yqi.googlegroups.com> <4c3a5c7f$0$28647$c3e8da3@news.astraweb.com> <4c3a8087$0$28662$c3e8da3@news.astraweb.com> Message-ID: In article <4c3a8087$0$28662$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >For some reason, when I answer the phone and say "Hello, Steven >speaking?" I often get called Peter. That's the Peter Principle in action. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From nfdisco at gmail.com Thu Jul 15 21:21:13 2010 From: nfdisco at gmail.com (ernest) Date: Thu, 15 Jul 2010 18:21:13 -0700 (PDT) Subject: __getattribute__ hook and len() problem References: Message-ID: <2acf330e-5156-499f-8675-dc493c128a07@w30g2000yqw.googlegroups.com> Thanks Chris & Christian. Mistery solved :) Ernest From usenet-nospam at seebs.net Thu Jul 15 22:43:02 2010 From: usenet-nospam at seebs.net (Seebs) Date: 16 Jul 2010 02:43:02 GMT Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On 2010-07-15, bolega wrote: > This makes some sense. He replied on the newsgroup in a lengthy post > that there are sufficient resources out there giving hint that no one > need help me out. Then I was called "lazy" in one email and tersely > given JUST the last name of an author who has many books each many > 100s pages, when I asked for a relevant book, as if i am a scholar in > the field, although he did spend lots of words on irrelevant and > unbeneficial things which diminished my enthusiasm. If you found those "irrelevant and unbeneficial", then while I agree that he may have been wasting his time, he would have been wasting it even worse trying to walk you through the technical material when you're clearly not currently at a stage where you are ready to learn anyway. > Now, I find out > from you that he has/had a business concern or interest in a company > that is writing/wrote lisp interpreter in C. Correct me if I am making > an error. I dont want to think deprecatingly of any good soul but this > is what i experienced. If you are trying to imply that he was acting in some unethical way, you have further cemented the notion that trying to talk to you is a waste of anyone's time. *plonk* -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! From fuglyducky at gmail.com Thu Jul 15 22:53:23 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Thu, 15 Jul 2010 19:53:23 -0700 (PDT) Subject: Newbie: Python 3 and MySQL??? Message-ID: I am brand new Python and need to connect to a MySQL DB. The books I have been using are all Python 3 so I'd like to stick with what I know. Does anyone know if there is a library out there for connecting to MySQL with Python 3? If not, does anyone have any info on when MySQLdb may be ported? Thanks!!! From gavcomedy at gmail.com Thu Jul 15 23:11:12 2010 From: gavcomedy at gmail.com (gavino) Date: Thu, 15 Jul 2010 20:11:12 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: Message-ID: <1a63a61c-a9f2-4e02-9c7e-00637c06b3a7@k8g2000prh.googlegroups.com> On Jul 7, 1:56?pm, bolega wrote: > "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > Enjoy ..... AWESOME From ldo at geek-central.gen.new_zealand Thu Jul 15 23:22:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 16 Jul 2010 15:22:47 +1200 Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: In message , MRAB wrote: > Normally it's only string literals that could be so long that you might > want to split them over several lines. It is somewhat unusual to have a > _numeric_ literal that's very very long! Seems a peculiar assumption to make in a language that allows integers of arbitrary length, does it not? From stefan_ml at behnel.de Thu Jul 15 23:33:17 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 05:33:17 +0200 Subject: Code generator and visitor pattern In-Reply-To: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: Carl Banks, 16.07.2010 01:14: > Around these parts, we consider the main use of most Design Patterns > to be to work around limitations of other languages. Visitor Pattern > is probably the worst example of it. > > In Python it's completely unnecessary (at least in its boilerplate- > heavy incarnation as used in C++), and the fact that Python isn't > strongly typed, as you put it, is exactly the reason why. > > Say you have a bunch of unrelated types that define a calculate > method, you have a variable x that could be any of these types. > Here's how you would do that in Python: > > x.calculate() > > Bam, that's it. Visitor Pattern in Python. You don't have to create > a bunch of homemade dispatching boilerplate like you do in C++. Well, you can do that in every OO language. It's not what the visitor pattern is there for, though. The code I referenced is from the Cython compiler, and we use it to "do stuff" with the AST. The visitor pattern is actually a pretty common way to bind code in a single place that does a certain thing to different parts of a data structure. Without it, if you kept that code *inside* of the data structure, you'd have to spill the type specific parts all over your code. Stefan From no.email at nospam.invalid Thu Jul 15 23:51:05 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 15 Jul 2010 20:51:05 -0700 Subject: Code generator and visitor pattern References: Message-ID: <7x1vb4dqza.fsf@ruckus.brouhaha.com> Karsten Wutzke writes: > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? A minute of web surfing found this: http://chris-lamb.co.uk/2006/12/08/visitor-pattern-in-python/ From rami.chowdhury at gmail.com Fri Jul 16 00:48:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 15 Jul 2010 21:48:44 -0700 Subject: Newbie: Python 3 and MySQL??? In-Reply-To: References: Message-ID: <210D964F-D736-441F-9E4D-2F6F49E90D6E@gmail.com> On Jul 15, 2010, at 19:53 , fuglyducky wrote: > I am brand new Python and need to connect to a MySQL DB. The books I > have been using are all Python 3 so I'd like to stick with what I > know. Does anyone know if there is a library out there for connecting > to MySQL with Python 3? I believe OurSQL supports Python 3.x -- http://packages.python.org/oursql/ HTH, Rami ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From crazy808s at yahoo.com Fri Jul 16 00:49:27 2010 From: crazy808s at yahoo.com (Dylan Gleason) Date: Thu, 15 Jul 2010 21:49:27 -0700 (PDT) Subject: IDLE won't start on Mac OSX Message-ID: <550552.57286.qm@web56208.mail.re3.yahoo.com> Hello, My name is Dylan. I am new to this list and am just getting started with Python and programming in general (although I have some experience with general UNIX wankery). I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX 10.6.3), but it will not start, citing the following error message: >>> IDLE's subprocess didn't make connection. Either IDLE can't start subprocess or >>>personal firewall software is blocking the connection. I tried disabling my firewall and restarting but unfortunately I still get the same message. I executed Python via the command line and it seemed to work just fine. Can someone help me?? Thanks, Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jul 16 01:00:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 22:00:02 -0700 Subject: IDLE won't start on Mac OSX In-Reply-To: <550552.57286.qm@web56208.mail.re3.yahoo.com> References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: On Thu, Jul 15, 2010 at 9:49 PM, Dylan Gleason wrote: > Hello, > My name is Dylan. I am new to this list and am just getting started with > Python and programming in general (although I have some experience with > general UNIX wankery). > I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX > 10.6.3), but it will not start, citing the following error message: >>>> IDLE's subprocess didn't make connection. Either IDLE can't start >>>> subprocess or personal firewall software is blocking the connection. > I tried disabling my firewall and restarting but unfortunately I still get > the same message. > I executed Python via the command line and it seemed to work just fine. Can > someone help me?? How are you starting IDLE (i.e. what icon are you clicking or what command are you running)? How did you install Python (e.g. Fink, MacPorts, Python.org installer, etc.)? Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Fri Jul 16 01:19:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Jul 2010 22:19:47 -0700 Subject: IDLE won't start on Mac OSX In-Reply-To: References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: On Thu, Jul 15, 2010 at 10:00 PM, Chris Rebert wrote: > On Thu, Jul 15, 2010 at 9:49 PM, Dylan Gleason wrote: >> Hello, >> My name is Dylan. I am new to this list and am just getting started with >> Python and programming in general (although I have some experience with >> general UNIX wankery). >> I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX >> 10.6.3), but it will not start, citing the following error message: >>>>> IDLE's subprocess didn't make connection. Either IDLE can't start >>>>> subprocess or personal firewall software is blocking the connection. >> I tried disabling my firewall and restarting but unfortunately I still get >> the same message. >> I executed Python via the command line and it seemed to work just fine. Can >> someone help me?? > > How are you starting IDLE (i.e. what icon are you clicking or what > command are you running)? > How did you install Python (e.g. Fink, MacPorts, Python.org installer, etc.)? ---------- Forwarded message ---------- From: Dylan Gleason Date: Thu, Jul 15, 2010 at 10:07 PM Subject: Re: IDLE won't start on Mac OSX To: Chris Rebert I am clicking the IDLE.app icon located in the Applications folder. I installed Python with the Python.mpkg file from the disk image file for version 2.7 (universal binary), which I in turn downloaded from the Python website. Thanks, Dylan ---------- In the future, please use Reply-All (so everyone can see your reply) and don't top-post (it makes conversations harder to follow; http://en.wikipedia.org/wiki/Top-post ). Hopefully your answers will help others in solving your problem; I personally don't have an answer for ya (my setup is different). Cheers, Chris -- http://blog.rebertia.com From nad at acm.org Fri Jul 16 01:24:20 2010 From: nad at acm.org (Ned Deily) Date: Thu, 15 Jul 2010 22:24:20 -0700 Subject: IDLE won't start on Mac OSX References: <550552.57286.qm@web56208.mail.re3.yahoo.com> Message-ID: In article <550552.57286.qm at web56208.mail.re3.yahoo.com>, Dylan Gleason wrote: > I am trying to fire up Python ver. 2.7 with IDLE (I am using Mac OSX 10.6.3), > but it will not start, citing the following error message: > > >>> IDLE's subprocess didn't make connection. Either IDLE can't start > >>> subprocess or > >>>personal firewall software is blocking the connection. > > I tried disabling my firewall and restarting but unfortunately I still get > the > same message. > > I executed Python via the command line and it seemed to work just fine. Can > someone help me?? If you downloaded the python.org 2.7 installer for OS X 10.5 or later, you are probably running into the problems documented here: http://bugs.python.org/issue9227 As a workaround, try downloading and installing the 32-bit Mac Installer for 2.7. The IDLE that it installs *should* work OK on 10.6. http://python.org/download/releases/2.7/ -- Ned Deily, nad at acm.org From python at bdurham.com Fri Jul 16 01:26:40 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 01:26:40 -0400 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <4C3F7D23.2060204@jollans.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> Message-ID: <1279258000.23856.1385149339@webmail.messagingengine.com> Thomas, > Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. I understand what you're saying, but I'm struggling with how to represent the following strings in doctest code and doctest results. No matter what combination of backslashes or raw strings I use, I am unable to find a way to code the following. >>> encode( '", \, \t, \n' ) '\", \\, \\t, \\n' Thank you, Malcolm From johan.gronqvist at gmail.com Fri Jul 16 01:41:58 2010 From: johan.gronqvist at gmail.com (=?ISO-8859-1?Q?Johan_Gr=F6nqvist?=) Date: Fri, 16 Jul 2010 07:41:58 +0200 Subject: Plot problem.. ?? No sign at all In-Reply-To: <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> References: <2ab1e0e5-6380-48e2-b1c1-2ce66784c440@x21g2000yqa.googlegroups.com> <4C334928.4020105@gmail.com> <3b2b50b9-7341-4828-862e-bac50d5648c5@5g2000yqz.googlegroups.com> <64d145a5-6a12-4d3b-b342-e1d5bd672bb0@u7g2000yqm.googlegroups.com> <1071a7e9-6027-408b-996c-8e81c68a2403@d16g2000yqb.googlegroups.com> <738d72d6-88a8-4f56-b9e6-4f2b702ec029@k39g2000yqd.googlegroups.com> Message-ID: Hi Ritchy, This is the first time I am doing this, but it's a standard response given on lists like this. 2010-07-13 18:17, Ritchy lelis skrev: > This is how looks like the flash residue transference function that i > was talking about... > > http://www.iadc.ca/Imran_ADC_tutorial_files/image048.gif > > I'm suposed to obtain a figure like that in my plot. > From the hints you have been given, and your answers to those hints, my conclusion is that the issue is not with the programming, but with your understanding of the problem. I get the feeling you do not understand what you are trying to do, and therefore our programming hints do not help you. Based on the "we will not do your homework"-principle, I will therefore not read up on your theory, and therefore not produce your plot for you. That will not change until you show better understanding for the plot you are trying to generate. Regards Johan From pavlovevidence at gmail.com Fri Jul 16 01:50:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 15 Jul 2010 22:50:20 -0700 (PDT) Subject: Code generator and visitor pattern References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: On Jul 15, 8:33?pm, Stefan Behnel wrote: > Carl Banks, 16.07.2010 01:14: > > > > > > > Around these parts, we consider the main use of most Design Patterns > > to be to work around limitations of other languages. ?Visitor Pattern > > is probably the worst example of it. > > > In Python it's completely unnecessary (at least in its boilerplate- > > heavy incarnation as used in C++), and the fact that Python isn't > > strongly typed, as you put it, is exactly the reason why. > > > Say you have a bunch of unrelated types that define a calculate > > method, you have a variable x that could be any of these types. > > Here's how you would do that in Python: > > > ? ? ?x.calculate() > > > Bam, that's it. ?Visitor Pattern in Python. ?You don't have to create > > a bunch of homemade dispatching boilerplate like you do in C++. > > Well, you can do that in every OO language. It's not what the visitor > pattern is there for, though. > > The code I referenced is from the Cython compiler, and we use it to "do > stuff" with the AST. The visitor pattern is actually a pretty common way to > bind code in a single place that does a certain thing to different parts of > a data structure. Without it, if you kept that code *inside* of the data > structure, you'd have to spill the type specific parts all over your code. Ahh, so this aspect oriented programming is it. I see your point, Visitor Pattern isn't necessary to work around the "can't easily polymorph unrelated types" limitation, but could still be necessary to work around "can't easily dispatch on methods not part of the class" limitation. So, ok, Visitor Pattern maybe isn't the worst one. My bad Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 02:06:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 06:06:47 GMT Subject: Possible to include \n chars in doctest code samples or output? References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> Message-ID: <4c3ff6f7$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 01:26:40 -0400, python wrote: > Thomas, > >> Recall that doctest doesn't parse the code, it extracts the docstrings. >> And docstrings are just strings, and are parsed like strings. > > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. No > matter what combination of backslashes or raw strings I use, I am unable > to find a way to code the following. > >>>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' I don't believe that this is a valid example. The interactive interpreter prints the repr() of objects unless you explicitly call print, which you have not done. I don't believe that there is any string whose repr() is what you have given. Consequently, there's no way to get that output in the interpreter (without using print), and the doctest MUST fail. But even if I'm wrong... when you run up against the limitations of doctests, don't use doctests. Is there any reason why you need to show that specific example out of the infinite number of possible examples? Remember that doctests aren't intended for a comprehensive test suite. Use unit tests for that. Or put the tests in a plain text file, not a docstring, and point doctest at that. That will reduce the amount of awkward escaping needed. If you insist on using that example, including it in the docstring should be simple. Call up the interactive interpreter, and run this: >>> from mymodule import encode # whatever your module happens to be >>> encode( '", \, \t, \n' ) something prints here Now copy the last two lines (the encode line, and the output). Paste it into your docstring, adjusting the indentation if needed. Then edit the two lines, doubling EVERY backslash. That should do it. If it doesn't, please show us the code of the encode function, the doctest failure, and the two lines copied from the interactive interpreter. -- Steven From mithrandiragainwiki at mailinator.com Fri Jul 16 02:23:39 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Fri, 16 Jul 2010 06:23:39 +0000 (UTC) Subject: Worship We Must References: <4c440c73-717c-455a-89b5-fb59ff600d39@w31g2000yqb.googlegroups.com> <4c3c1581$0$6774$9b4e6d93@newsspool3.arcor-online.net> <4c3c2115$0$6892$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Tue, 13 Jul 2010 01:32:42 -0700, geremy condra wrote: > > I'm sure you're aware that the shuffle of so-called 'conflict truffles' > is highly illegal, not to mention unethical. I'm shocked you would > advocate it publicly. > > Geremy Condra Ignore them. It's just Google Groups spam. :( -- /home/mithrandir/Documents/sig.txt From nanothermite911fbibustards at gmail.com Fri Jul 16 02:50:01 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Thu, 15 Jul 2010 23:50:01 -0700 (PDT) Subject: >>> Assembler Book - Read or Download Individual Chapters - Volume 5 Chapter One: Thunks <<< Message-ID: <405e0ca4-5873-427f-af6d-ff8ab8ebcfab@i31g2000yqm.googlegroups.com> Assembler Book - Read or Download Individual Chapters Table of Contents and Index Short Table of Contents (44KB) PDF File Full Table of Contents (408KB) PDF File Index (724KB) PDF File Volume One - Data Representation (40K) Chapter One: Foreward (60K) PDF File Chapter Two: Hello, World of Assembly (316 K) PDF File Chapter Three: Data Representation (304K) PDF File Chapter Four: More Data Representation (284) PDF File Chapter Five: Questions, Projects, and Lab Exercises (136K) PDF File Volume Two - Introduction to Machine Architecture (28K) Chapter One: System Organization (164K) PDF File Chapter Two: Memory Access and Organization (340K) PDF File Chapter Three: Introduction to Digital Design (336K) PDF File Chapter Four: CPU Architecture (244K) PDF File Chapter Five: Instruction Set Architecture (212K) PDF File Chapter Six: Memory Architecture (164K) PDF File Chapter Seven: The I/O Subsystem (188K) PDF File Chapter Eight: Questions, Projects, and Lab Exercises (264K) PDF File Volume Three - Basic Assembly Language Programming (28K) Chapter One: Constants, Variables, and Data Types (216K) PDF File Chapter Two: Character Strings (176K) PDF File Chapter Three: Characters and Character Sets (204K) PDF File Chapter Four: Arrays (172K) PDF File Chapter Five: Records, Unions, and Namespaces (156K) PDF File Chapter Six: Dates and Times (144K) PDF File Chapter Seven: File I/O (188K) PDF File Chapter Eight: Introduction to Procedures (224K) PDF File Chapter Nine: Managing Large Programs (144K) PDF File Chapter Ten: Integer Arithmetic (216K) PDF File Chapter Eleven: Real Arithmetic (412K) PDF File Chapter Twelve: Calculation Via Table Lookup (152K) PDF File Chapter Thirteen: Questions, Projects, and Lab Exercises (480 K) PDF File Volume Four - Intermediate Assembly Language Programming (28K) Chapter One: Advanced High Level Control Structures (180 KB) PDF File Chapter Two: Low Level Control Structures (428 KB) PDF File Chapter Three: Intermediate Procedures (348 KB) PDF File Chapter Four: Advanced Arithmetic (436K) PDF File Chapter Five: Bit Manipulation (220 KB) PDF File Chapter Six: String Instructions (120 KB) PDF File Chapter Seven: The HLA Compile-Time Language (164 KB) PDF File Chapter Eight: Macros(272 KB) PDF File Chapter Nine: Domain Specific Languages (436 KB) PDF File Chapter Ten: Classes and Objects (408 KB) PDF File Chapter Eleven: The MMX Instruction Set (280 KB) PDF File Chapter Twelve: Mixed Language Programming (328 KB) PDF File Chapter Thirteen: Questions, Projects, and Lab Exercises (612 KB) PDF File Volume Five - Advanced Procedures (28K) Chapter One: Thunks (208 KB) PDF File Chapter Two: Iterators (200 KB) PDF File Chapter Three: Coroutines (100 KB) PDF File Chapter Four: Low Level Parameter Implementation (240 KB) PDF File Chapter Five: Lexical Nesting (184 KB) PDF File Chapter Six: Questions, Projects, and Lab Exercises (56KB) PDF File Appendices Appendix A: Solutions to Selected Exercises (20KB) N/A Appendix B: Console Graphic Characters (24KB) PDF File Appendix C: HLA Programming Style Guidelines (264KB) PDF File Appendix D: The 80x86 Instruction Set (224KB) PDF File Appendix E: HLA Language Reference (16KB) N/A Appendix F: HLA Standard Library Reference (16KB) N/A Appendix G: HLA Exceptions (52KB) PDF File Appendix H: HLA Compile-Time Functions (224KB) PDF File Appendix I: Installing HLA on Your System (192KB) PDF File Appendix J: Debugging HLA Programs (60KB) PDF File Appendix K: Comparison of HLA and MASM (16KB) N/A Appendix L: Code Generation for HLA High Level Statements 104KB) PDF File line Last updated: January 19, 2005 2:02 PM , Please send comments to Dr. Bradley K. Jensen jensenb at unt.edu ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From hjtoi-better-remove-before-reply at comcast.net Fri Jul 16 03:09:31 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Fri, 16 Jul 2010 00:09:31 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem References: Message-ID: On 07/13/2010 02:18 PM, Adam Mercer wrote: > I'm trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at this time, you should check out M2Crypto from the Subversion repository. See http://chandlerproject.org/Projects/MeTooCrypto for details on how to get the sources. -- Heikki Toivonen - http://heikkitoivonen.net From nanothermite911fbibustards at gmail.com Fri Jul 16 03:15:17 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:15:17 -0700 (PDT) Subject: Rapidly navigating buffers using search References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> Message-ID: On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST On Jul 11, 10:27 am, Xah Lee wrote: > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > M Stallman, and much of the unix people (although we should remember > that Richard Stallman hated unix, if not more thanMicrosoft, and > thehatredof unix was a major reason he started GNU's Not Unix, by ORACLE by Larry Ellison is a more dangerous monopoly with boundless GREED Bill Gates is a decent family man and a genuine PHILANTHROPIST From nanothermite911fbibustards at gmail.com Fri Jul 16 03:26:37 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:26:37 -0700 (PDT) Subject: Microsoft Hatred, Richard Matthew Stallman, Bill Gates, Larry Ellison, ORACLE References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> Message-ID: <19c60c5f-4d0f-4984-bb97-acf85cf071ee@i28g2000yqa.googlegroups.com> On Jul 16, 12:15?am, nanothermite911fbibustards wrote: > On Jul 11, 10:27 am, Xah Lee wrote: > > > > > you are a victum of the Microsoft hatred. A hatred spread by, Richard > > M Stallman, and much of the unix people (although we should remember > > that Richard Stallman hated unix, if not more thanMicrosoft, and > > thehatredof unix was a major reason he started GNU's Not Unix, by > > ORACLE by Larry Ellison is a more dangerous monopoly with boundless > GREED > > Bill Gates is a decent family man and a genuine PHILANTHROPIST > They are all from Bronx http://www.nndb.com/people/439/000022373/ Larry Ellison Larry EllisonAKA Lawrence Joseph Ellison Born: 17-Aug-1944 Birthplace: Bronx, NY Gender: Male Religion: Jewish Race or Ethnicity: White Sexual orientation: Straight Occupation: Business Nationality: United States Executive summary: CEO of Oracle Larry Ellison was born out of wedlock to a 19-year-old mother, and raised by her aunt. As a boy he showed an aptitude for math and science, and as a young man he was a computer programmer for Ampex Corporation. His primary project for Ampex was crafting a large-scale database for the Central Intelligence Agency (CIA). The database was code-named "Oracle". Ellison put up $2,000 of his own money to start Software Development Laboratories in 1977, in partnership with Robert Miner, his boss from Ampex. The new company was renamed Relational Software Inc. in 1979, as it prepared to release Oracle Version 2, a commercial database system -- but the company had never released a "Version 1" of Oracle. Calling it "Version 2" was a marketing tactic, intended to convey the notion that any initial bugs had been worked out. Oracle sold briskly, and in 1983 the company renamed itself after its principal product. Oracle Corporation went public in 1986, and was on the verge of bankruptcy by 1990, when it was revealed that its revenues had been overstated for several years. The company has since rebounded, and been extremely profitable. In 1996, Ellison took a month-long sabbatical, and spent most of his waking time on-line. When he returned he'd decided that the 'net was the next big thing, bigger than personal computers. Oracle started reconfiguring its software for on-line data sharing, and for adaptability to not-quite-computer products like TVs with internet access and pocket internet devices. This strategy has made Oracle still more profitable. Oracle's main competitors are Microsoft and IBM, and one of Ellison's passions is needling Microsoft. He's been a prominent proponent of efforts to break Microsoft up for antitrust violations. "I think when somebody breaks the law, they should be punished", says Ellison. He's admitted hiring private detectives to gather information on Microsoft's tactics, and charged that Microsoft funded pro-Microsoft "grassroots" political action groups that were pressuring the Justice Department to drop its antitrust prosecution. Microsoft responded that Oracle might be funding anti-Microsoft political groups. Neener- neener. David Theroux, president of the Independent Institute -- alleged by Ellison to be a Microsoft front -- said of Ellison, "anybody who stoops to whatever was done here, cannot be trusted. Oracle has apparently felt the need to employ back-alley tactics, subterfuge, and disinformation in order to achieve its aims". Ellison's net worth dropped about $3.5 billion after September 11, as stocks plummeted and Oracle stock lost almost 50% of its value. It was at this time that Ellison became a loud supporter of a U.S. identity card, which -- he insisted -- would help prevent terrorism. Ellison has offered to provide data-tracking software for the national ID card free of charge (but with fees for maintenance and upgrades, of course). As envisioned by Ellison, the national ID card would be "optional" for native-born Americans, but mandatory for immigrants. Ellison had a dispute with the city of San Jose, CA, and its airport, when his personal jet violated the city's jet curfew law at least six times. Noise control legislation makes it illegal for planes weighing 75,000 pounds or more to take off or land at San Jose International Airport during overnight hours, but after Ellison sued, the city granted him a special exemption to the law in 2001. In 2000, Forbes listed Ellison as the world's second richest man, worth $47 billion to Bill Gates's $60 billion. By 2007, Forbes had Ellison slipping to fourth place, worth only $26 billion. Close friend of Steve Jobs. Mother: Florence Spellman (unwed mother, at age 19) Father: Louis Ellison (adoptive father) Mother: Lillian Ellison (adoptive mother) Wife: Adda Quinn (m. 1967, div. 1974) Wife: Nancy Wheeler (m. 1977, div. 1978) Wife: Barbara Boothe (m. 1983, div. 1986) Daughter: Megan Ellison Son: David Ellison Girlfriend: Adelyn Lee (later fired by an Oracle VP, she sued Ellison, settled for $100k) Wife: Melanie Craft (romance novelist, m. 18-Dec-2003) High School: South Shore High School, Chicago, IL University: University of Illinois Urbana-Champaign (two years, dropped out) University: University of Chicago (one quarter, dropped out) Oracle CEO (1977-) Oracle President (1978-96) nCUBE CEO (1996-2002) nCUBE Majority Shareholder (1988-) Ampex Amdahl (1973-) Member of the Board of Apple (-2002) Member of the Board of Oracle (1977-, as Chairman, 1990-92 and 1995-2004) Academy of Achievement (1997) Dreier for Congress Committee John McCain 2008 Monday Morning PAC Obama for Illinois US Big Brother Award Greatest Corporate Invader Rhinoplasty FILMOGRAPHY AS ACTOR Iron Man 2 (26-Apr-2010) Himself The Triumph of the Nerds: The Rise of Accidental Empires (12- Jun-1996) Himself Appears in articles: Time, 23-Jun-2003, DETAILS: Eat... or Be Eaten -- Software mogul Larry Ellison makes a hostile bid for a rival firm -- and predicts that other tech giants will follow his lead (p.47, three pages), BYLINE: Chris Taylor New! NNDB MAPPER Create a map starting with Larry Ellison Requires Flash 7+ and Javascript. Do you know something we don't? Submit a correction or make a comment about this profile Copyright ?2010 Soylent Communications From nanothermite911fbibustards at gmail.com Fri Jul 16 03:45:22 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Fri, 16 Jul 2010 00:45:22 -0700 (PDT) Subject: CONVICTED RAPIST of 13y old girl Semantha Geimer, ROMAN POLANSKY is RELEASED by a KANGAROO court in Switzerland, Re: Microsoft Hatred, Richard Matthew Stallman, Bill Gates, Larry Ellison, ORACLE References: <20100707064305.GF31621@groll.co.za> <20100707080139.GA18906@groll.co.za> <9dc07ed9-f6f1-4ac5-949a-5b97368cc32a@n19g2000prf.googlegroups.com> <87mxu22rbc.fsf@lola.goethe.zz> <873cd6b9-8a85-478f-9943-c3ce09eb62c6@n8g2000prh.googlegroups.com> <19c60c5f-4d0f-4984-bb97-acf85cf071ee@i28g2000yqa.googlegroups.com> Message-ID: <62a07fd7-fb45-4368-af79-0615b36df10a@r27g2000yqb.googlegroups.com> CONVICTED RAPIST, ROMAN POLANSKY is RELEASED by a KANGAROO court in Switzerland We all know that Germans are paying a big tribute to the polanskys and the swiss paid for the gold in the teeth. Israeli Professor: 'We Could Destroy All European Capitals' By Nadim Ladki 2-6-3 (IAP News) -- An Israeli professor and military historian hinted that Israel could avenge the holocaust by annihilating millions of Germans and other Europeans. Speaking during an interview which was published in Jerusalem Friday, Professor Martin Van Crevel said Israel had the capability of hitting most European capitals with nuclear weapons. "We possess several hundred atomic warheads and rockets and can launch them at targets in all directions, perhaps even at Rome. Most European capitals are targets of our air force." Creveld, a professor of military history at the Hebrew University in Jerusalem, pointed out that "collective deportation" was Israel's only meaningful strategy towards the Palestinian people. "The Palestinians should all be deported. The people who strive for this (the Israeli government) are waiting only for the right man and the right time. Two years ago, only 7 or 8 per cent of Israelis were of the opinion that this would be the best solution, two months ago it was 33 per cent, and now, according to a Gallup poll, the figure is 44 percent." Creveld said he was sure that Israeli Prime Minister Ariel Sharon wanted to deport the Palestinians. "I think it's quite possible that he wants to do that. He wants to escalate the conflict. He knows that nothing else we do will succeed." Asked if he was worried about Israel becoming a rogue state if it carried out a genocidal deportation against Palestinians, Creveld quoted former Israeli Defense Minister Moshe Dayan who said "Israel must be like a mad dog, too dangerous to bother." Creveld argued that Israel wouldn't care much about becoming a rogue state. "Our armed forces are not the thirtieth strongest in the world, but rather the second or third. We have the capability to take the world down with us. And I can assure you that this will happen before Israel goes under." Islamic Association for Palestine (IAP) http://www.iap.org A CHRISTIAN VIEW OF THE HOLOCAUST Ladies and gentlemen, you are about to hear a very frightening speech. This speech is an explanation of the plans now being laid to throw the United States into a third world war. It was made a short time ago before a large group in the Congressional `Room of the Willard Hotel in Washington, D.C. Both the speech and the question and answer period later so electrified the audience that a group of patriots has transferred it to two long-playing records which you may buy to play for friends, clubs, and your church group in your community. The speaker is Mr. Benjamin Freedman, noted authority on Zionism and all of its schemes. Mr. Freedman is a former Jew, and I mean a FORMER Jew. He has fought the Communist world conspiracy tooth and nail, and stands today as a leading American patriot. We now take you to the speaker's platform to present Benjamin Freedman. (applause) [Freedman's speech] What I intend to tell you tonight is something that you have never been able to learn from any other source, and what I tell you now concerns not only you, but your children and the survival of this country and Christianity. I'm not here just to dish up a few facts to send up your blood pressure, but I'm here to tell you things that will help you preserve what you consider the most sacred things in the world: the liberty, and the freedom, and the right to live as Christians, where you have a little dignity, and a little right to pursue the things that your conscience tells you are the right things, as Christians. I'm not so poor that I can't live without working and that's what worries the Anti-Defamation League. I can just get by without going and asking for a job or getting on the bread line. But Mr. McGinley is working. He's sick and he's going at this stronger than ever. And all I want to say is that they want to close up "Common Sense" more than any other single thing in the whole world, as a death-blow to the fight Christians are making to survive. So I just want to tell you this. All they do is circulate rumors: "Mr. Benjamin H. Freedman is the wealthy backer of 'Common Sense'." The reason they do that is to discourage the people in the United States: don't send any money to Common Sense. They don't need it. The've got the wealthy Mr. Freedman as a backer. That all has strategy. They don't want to advertise me so that people that have real estate or securities to sell will come and call on me. They just want people to lay off "Common Sense". And all I'm telling you is, I do try to help him, but I haven't been able to. And I will be very honest. One thing I won't do is lie. In the last year I've had so much sickness in my family that I could not give him one dollar. How he's managed to survive, I don't know. God alone knows. And he must be in God's care because how he's pulled through his sickness and with his financial troubles, I don't know. But that press is working. . . and every two weeks about a hundred or a hundred-fifty- thousand of "Common Sense" go out with a new message. And if that information could be multiplied. . . if people that now get it could buy ten or twenty five, or fifty, give them around. Plow that field. Sow those seeds, you don't know which will take root, but for God's sake, this is our last chance. From mukeshtiwari.iiitm at gmail.com Fri Jul 16 03:52:23 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 16 Jul 2010 00:52:23 -0700 (PDT) Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: On Jul 16, 4:08?am, MRAB wrote: > mukesh tiwari wrote: > > Hello all > > Currently i am trying to develop a client and server in python. Client > > takes screenshot in every 20 seconds and send it to server. Server > > store the received file in folder. Here is code for Client > > > import sys > > import socket > > import gtk.gdk > > import time > > if __name__ == "__main__": > > ? ?s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); > > ? ?host,port="localhost",50007 > > ? ?s.connect((host,port)) > > ? ?while 1: > > ? ? ? ? ? ?w = gtk.gdk.get_default_root_window() > > ? ? ? ? ? ?sz = w.get_size() > > ? ? ? ? ? ?pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) > > ? ? ? ? ? ?pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) > > ? ? ? ? ? ?if (pb != None): > > ? ? ? ? ? ? ? ? ? ? ? ?pb.save('/home/tmp_1/screenshot.png',"png") > > ? ? ? ? ? ?f=open('/home//tmp_1/screenshot.png','rb') > > ? ? ? ? ? ?while 1: > > ? ? ? ? ? ? ? ? ? ?blk=f.read(2048) > > ? ? ? ? ? ? ? ? ? ?if not blk:break > > ? ? ? ? ? ? ? ? ? ?s.send(blk) > > ? ? ? ? ? ?f.close() > > ? ? ? ? ? ?print 'file transfer done'; > > ? ? ? ? ? ?time.sleep(20) > > > ? ?s.close() > > > Server Code > > import sys > > import socket > > import time > > if __name__ == "__main__": > > > ? ?s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) > > ? ?host,port="",50007 > > ? ?s.bind((host,port)) > > ? ?s.listen(1) > > ? ? ? conn,add=s.accept() > > ? ?i=0 > > ? ?while 1: > > ? ? ? ? ? ?f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') > > ? ? ? ? ? ?while 1: > > ? ? ? ? ? ? ? ? ? ?data=conn.recv(2048) > > ? ? ? ? ? ? ? ? ? ?if not data:break > > ? ? ? ? ? ? ? ? ? ?f.write(data) > > > ? ? ? ? ? ?f.close() > > ? ? ? ? ? ?print 'file received' > > ? ? ? ? ? ?time.sleep(20) > > ? ? ? ? ? ?i+=1; > > ? ?#print ' file received ' > > > ? ?conn.close() > > > My problem is that server is copying only first image > > copyscreenshot_0.png while my client continuously taking screen shot. > > Kindly tell me what is wrong with my server code. > > The .recv will return an empty string only when the connection is closed > by the client, but the client keeps the connection open. > > You could either open and close a connection for each image, or have the > client tell the server how many bytes it's going to send, followed by > the bytes (my preference would be to send the size as a string ending > with, say, a newline). > > Another point: the .send method doesn't guarantee that it'll send all > the bytes (it'll return the number of bytes that it has actually sent); > use the .sendall method instead. Thank you MARB. I used your first idea and opening and closing connection for each image. Just wanted to know if i have to take pictures at small intervals , this method is efficient or not? It would be great if you can provide a bit code for second method. Keeping the connection open but how to know that this is end a particular image and save it. From michele.simionato at gmail.com Fri Jul 16 03:52:25 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 16 Jul 2010 00:52:25 -0700 (PDT) Subject: Code generator and visitor pattern References: Message-ID: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> On Jul 15, 7:58?pm, Karsten Wutzke wrote: > Hello, > > this is obviously a Python OO question: > > Since Python isn't stringly typed, single-dispatch isn't available per > se. So is the "double-dispatch" Visitor pattern, which is usually used > in OO systems to implement code generators. So, what is the de facto > method in Python to handle source code generation? > > Karsten You ask about code generation and you already had answers in that area, but let me talk a bit about a simpler topic, traversing a hierarchical file system. I think this is relevant (even if not answering your question) if you want to get familiar with the Python way. In the old days, the way to traverse a file system was through the os.path.walk function. Here is what the docs say (from http://docs.python.org/library/os.path.html): """ os.path.walk(path, visit, arg) Calls the function visit with arguments (arg, dirname, names) for each directory in the directory tree rooted at path (including path itself, if it is a directory). The argument dirname specifies the visited directory, the argument names lists the files in the directory (gotten from os.listdir(dirname)). The visit function may modify names to influence the set of directories visited below dirname, e.g. to avoid visiting certain parts of the tree. (The object referred to by names must be modified in place, using del or slice assignment.) """ As you see the documentation make explicit reference to the visitor pattern. However a note below says: """ This function is deprecated and has been removed in 3.0 in favor of os.walk(). """ In other word, the visitor pattern is *not* the Pythonic way to solve this problem. The Pythonic way is to use os.walk, which converts the nested structure in a flat structure. From the docs (http://docs.python.org/library/os.html): """ This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn?t look under any CVS subdirectory: import os from os.path import join, getsize for root, dirs, files in os.walk('python/Lib/email'): print root, "consumes", print sum(getsize(join(root, name)) for name in files), print "bytes in", len(files), "non-directory files" if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories """ There is a big conceptual difference between os.path.walk and os.walk. The first works like a framework: you pass a function to it and os.path.walk is in charging of calling it when needed. The second works like a library: os.walk flattens the hierarchical structure and then you are in charge of doing everything you wish with it. os.walk is the Pythonic way, and you suggested to follow that approach; for instance elementTree and lxml (libraries for parsing XML data) work exactly that way. Actually one of the motivating examples for the introduction of generators in Python was their use in flattening data structure, i.e. exactly the pattern used by os.walk. The message is stop thinking like in Java and start using idiomatic Python. We are here to help. Michele Simionato From smallpox911 at gmail.com Fri Jul 16 04:07:39 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:07:39 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** Message-ID: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Self-Study Course : The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS First, we will present the TRANSFORMATION, using HIGHLY AUTHENTIC source . Lying and Deception is the second nature of zionists , so we cant contaminate ourselves with an iota of it. We present evidence from the mouth of TORAH true jews which you will also see with your own eyes in a unique style. Rabbi Israel Domb - The Author of THE TRANSFORMATION http://www.youtube.com/watch?v=1QfgvDXsDds Rabbi Israel Domb ushers me into the dining room of his terraced house in Stamford Hill. With a lace-covered table that fills the room and glass-panelled sideboard, we could almost be in Eastern Europe in the 50s. Now 86, Domb shuffles slightly in the slippers that, with his long, black satin coat, make up his housewear. But he exudes the twin qualities of self-containedness and benevolence that mark those who believe they've arrived at a place of existential and spiritual certainty. Bizarrely, the entire proceedings are filmed by a young man neither of us was expecting. Wanting to capture the discourse of one of their elders, and aware of the increasing need for publicity material, Neturei Karta in New York have commissioned videos of most of my interviews. Domb's long life testifies to the experience of 20th-century Jewry. He came to England from Poland in 1939, and lost his mother and sisters in the Holocaust. But it has also been a life lived countercurrent: he visited the newly founded state of Israel in the 50s and started speaking and writing against Zionism, which made him unpopular with the Orthodox community. The publication of The Transformation , the definitive exposition of the Neturei Karta worldview, confirmed his status as one of the movement's main spiritual leaders. Bound in dark red leather, and the length of a short novel, its register is hard to place, with its blend of theological assertion and historical- political commentary written in a style dating from decades ago. He insists that the politicised turn of his life grew out of his upbringing in a deeply religious family. He tells me how, when the Nazis came, a Polish teacher offered to hide his two blonde sisters. 'My mother said, "I appreciate your kindness. But I would rather they should die as Jews than be brought up as non-Jews." I come from a family of very strong convictions. Neturei Karta is nothing new.' Domb claims that while most modern Jews have departed from true Judaism, the Neturei Karta - which means 'guardians of the holy city' in Aramaic - are the minority charged with keeping the faith. The movement was established in Jerusalem in the 30s. Its supporters, living in the Holy Land since the 18th century, had always opposed a Jewish state and were concerned about the growing pressure to establish a Jewish homeland. Domb insists that its tenets go back to the origins of Jewish identity. 'Neturei Karta is not an idea, it's not a new trend, it's not a party with a programme,' he tells me. 'It is the authentic Jewishness of the Jewish people.' At its theological heart lies the belief that the Jews have been exiled for their sins and are destined to suffer, a fate which will be redeemed only when divine intervention, with the coming of the Messiah, changes the world order. In the meantime, Jews must remain stateless, living under the rule of whichever country hosts them. Zionism, as the desire for a sovereign state, represents a blasphemous rejection of God's will. 'An earthly solution for the Jewish people is not possible, because we are not destined for any earthly happiness. The Jewish people should come to their senses and see that the Zionist state is one big misfortune,' says Domb. In conversation, Domb frequently distinguishes the religious level - the messianism that forbids the Jews political intervention - from what he calls the 'mundane' or worldly perspective. When he talks on this second level, his observations are sharpened with a campaigning edge. 'When the Zionists speak about peace, they want peace, but what it means is a peaceful occupation,' he says. But he also has a Middle- European, black sense of humour, chuckling grimly to himself as he invokes the worst excesses of human behaviour: 'Were they invited to the West Bank? Were they invited to Ramallah and Jenin? Were they invited to throw out from their homes around 600,000 Arabs?' The political solution Domb advocates is, ironically, more radical than the PLO's, which recognised Israel's right to exist in 1988. He has no hope that this will happen, but he thinks the Israelis should renounce their claims to land within the 1948 borders and make reparations to the Palestinians. With the state of Israel dismantled, Jews could remain in the Holy Land, but live under Palestinian rule. But ultimately, he stresses, Neturei Karta's objection to Israel rests on theological rather than political grounds. 'The very existence of the Jewish state is diametrically opposed to Judaism,' he says. 'But as it happens, the Arabs have suffered, and it is our duty to say to them: "It is morally wrong, it is illegal from the worldly point of view, and we are not part of it. So don't blame all the Jewish people for the sufferings which you have had."' The acknowledgement of this injustice, he says, imposes an obligation on the Neturei Karta to actively seek out Palestinians to make clear their position. Speaking slowly and with emphasis, he declares: 'It's an encouraging matter that young people come out, speak against Zionism. But they also have to guard against speaking nonsense and overdoing it.' Unsurprisingly, Neturei Karta's brand of overt protest finds them little favour with the leaders of Britain's Jewry. The Chief Rabbi Jonathan Sacks, speaking at the Zionist Federation's Israel Independence Day rally at Wembley, where one of the Neturei Karta set alight an Israeli flag, condemned their stance as 'unforgivable'. Neville Nagler, director general of the Board of the Deputies of British Jews, dismisses them as 'a fringe organisation, off the wall'. He claims that their 'vicious hostility to Israel, their willingness to desecrate the Sabbath to show up at demonstrations' isolates them even from the Orthodox community among whom they live. Rabbi Tony Bayfield, head of Britain's Reform Synagogues, says that Neturei's religiously grounded anti-Zionism is untenable nowadays: 'The intellectual and theological battle was lost the best part of a century ago. It's no longer relevant or meaningful. For the vast majority of Jews, the existence of the state of Israel is not negotiable.' It's a paradoxical attitude - dismissing the group as irrelevant while evincing palpable hostility - which is perhaps a measure of how far the Neturei Karta touches on the central, raw nerve of the Middle East conflict: Israel's right to exist. The Neturei Karta in New York have long experience in handling public protest and controversy. Based in the city's Monsey area, the bigger, more established group has been organising anti-Zionist protests since 1948, some of which, they say, have attracted up to 30,000 Orthodox Jews. Their leader, Rabbi Moshe Beck, visiting his sons in London and speaking through a Yiddish interpreter, tells me that the heightened tension of the past year has caused some supporters to fall off and provoked threats against him and other activists. But many remain steadfast. 'Those that do it are prepared for whatever consequences,' he insists, adding: 'All our actions are no more or less than proclaiming the truth - it's not a political idea.' Beck, a frail-looking man of 68 who does not once make eye contact during our hour-long meeting, seems an unlikely character to be at the frontline of so much conflict. Born in Hungary, he emigrated to Israel soon after its establishment. What he saw there - the emergence of a modern, secular society, combined with the government's harsh treatment of the Palestinians - horrified him, clashing as it did with the inner religious life he was pur suing through study and reflection. Then he met Neturei Karta's most respected leader, Amram Blau, and became active in the Jerusalem-based movement. But in 1973, feeling it was no longer right to live in Israel, he and his family moved to New York. In Israel, Neturei Karta's position is very different. Part of the ultra-Orthodox community in the Mea Shearim quarter of Jerusalem, the group denies the legitimacy of the government, refusing to pay taxes and avoiding military conscription into the Israeli Defence Forces. In the 60s and 70s they fought an often violent campaign for observing the Sabbath, finally persuading the authorities to close some of Jerusalem's streets on the holy day. Its leader and self-styled foreign minister, Rabbi Moshe Hirsh, who considers himself a Palestinian Jew, ran a high-profile campaign in the 80s to be appointed as Neturei Karta's representative in the PLO. In 1994, Arafat endorsed his position as the Palestinian National Authority's Minister for Jewish Affairs but, as a non-Arabic speaker and unable to deal directly with Israeli representatives because of Neturei Karta's refusal to recognise the Israeli government, Hirsh has had a more advisory than ministerial role in the Palestinian adminis tration. He has used his position as a platform for campaigning, in 2000 urging Arafat to unilaterally declare an independent Palestinian state. But for the most part, Neturei Karta's activities are fairly low key. Hirsh, who claims 10,000 supporters in Jerusalem, says that the group is so well established that taking to the streets is felt to be unnecessary. 'We don't recognise the government; everyone knows that. We don't see the need,' he says. From smallpox911 at gmail.com Fri Jul 16 04:19:54 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:19:54 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** References: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Message-ID: <8c1e7781-fab5-4635-998b-d503b3f929d9@d37g2000yqm.googlegroups.com> The Kitab al Khazari, an Arabic phrase meaning Book of the Khazars, is one of most famous works of the medieval Spanish Jewish philosopher and poet Rabbi Yehuda Halevi, completed around 1140.[1] Divided into five essays ("ma'amarim," Articles), it takes the form of a dialogue between the pagan king of the Khazars and a Jew who was invited to instruct him in the tenets of the Jewish religion. Originally written in Arabic, the book was translated by numerous scholars (including Judah ibn Tibbon) into Hebrew and other languages. Though the book is not considered a historical account of the Khazar conversion to Judaism, scholars such as D.M. Dunlop have postulated that Yehuda had access to Khazar documents upon which he loosely based his work. His contemporary, Avraham ibn Daud, reported meeting Khazar rabbinical students in Toledo, Spain in the mid-12th century. Introduction After a short account of the incidents preceding the conversion of the king, and of the conversations of the latter with a philosopher, a Christian, and a Muslim concerning their respective beliefs, a Jew appears on the stage, and by his first statement startles the king; for, instead of giving him proofs of the existence of God, he asserts and explains the miracles performed by Him in favor of the Israelites. The king expresses his astonishment at this exordium, which seems to him incoherent; but the Jew replies that the existence of God, the creation of the world, etc., being taught by religion, do not need any speculative demonstrations. Further, he propounds the principle upon which his religious system is founded; namely, that revealed religion is far superior to natural religion. For the aim of ethical training, which is the object of religion, is not to create in man good intentions, but to cause him to perform good deeds. This aim can not be attained by philosophy, which is undecided as to the nature of good, but can be secured by religious training, which teaches what is good. As science is the sum of all truth found by successive generations, so religious training is based upon a set of traditions; in other words, history is an important factor in the development of human culture and science. [edit] "Creatio ex Nihilo" Halevi writes that as the Jews are the only depositaries of a written history of the development of the human race from the beginning of the world, the superiority of their traditions can not be denied. Halevi asserts that no comparison is possible between Jewish culture, which in his view is based upon religious truth, and Greek culture, which is based upon science only. He holds that the wisdom of Greek philosophers lacked that divine support with which the Israelite prophets were endowed. Had a trustworthy tradition that the world was created out of nothing been known to Aristotle, he would have supported it by at least as strong arguments as those advanced by him to prove the eternity of matter. Belief in the eternity of matter, however, is not absolutely contrary to Jewish religious ideas; for the Biblical narrative of the Creation refers only to the beginning of the human race, and does not preclude the possibility of preexistent matter. Still, relying upon tradition, the Jews believe in "creatio ex nihilo," which theory can be sustained by as powerful arguments as those advanced in favor of the belief in the eternity of matter. The objection that the Absolutely Infinite and Perfect could not have produced imperfect and finite beings, made by the Neoplatonists to the theory of "creatio ex nihilo," is not removed by attributing the existence of all mundane things to the action of nature; for the latter is only a link in the chain of causes having its origin in the First Cause, which is God. [edit] Superiority of his faith Halevi now attempts to demonstrate the superiority of his religion, Judaism. From smallpox911 at gmail.com Fri Jul 16 04:20:03 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 16 Jul 2010 01:20:03 -0700 (PDT) Subject: *** StudyCourse :: The Conversion of KHAZARS to Jews and thence TRANSFORMATION to ZIONIST ATHEISTS *** References: <3e53070f-5af4-4335-ae8b-3959f24488c4@t10g2000yqg.googlegroups.com> Message-ID: <58d8b6b7-e7eb-45af-9b97-d896a9b8fe7d@d16g2000yqb.googlegroups.com> The Kitab al Khazari, an Arabic phrase meaning Book of the Khazars, is one of most famous works of the medieval Spanish Jewish philosopher and poet Rabbi Yehuda Halevi, completed around 1140.[1] Divided into five essays ("ma'amarim," Articles), it takes the form of a dialogue between the pagan king of the Khazars and a Jew who was invited to instruct him in the tenets of the Jewish religion. Originally written in Arabic, the book was translated by numerous scholars (including Judah ibn Tibbon) into Hebrew and other languages. Though the book is not considered a historical account of the Khazar conversion to Judaism, scholars such as D.M. Dunlop have postulated that Yehuda had access to Khazar documents upon which he loosely based his work. His contemporary, Avraham ibn Daud, reported meeting Khazar rabbinical students in Toledo, Spain in the mid-12th century. Introduction After a short account of the incidents preceding the conversion of the king, and of the conversations of the latter with a philosopher, a Christian, and a Muslim concerning their respective beliefs, a Jew appears on the stage, and by his first statement startles the king; for, instead of giving him proofs of the existence of God, he asserts and explains the miracles performed by Him in favor of the Israelites. The king expresses his astonishment at this exordium, which seems to him incoherent; but the Jew replies that the existence of God, the creation of the world, etc., being taught by religion, do not need any speculative demonstrations. Further, he propounds the principle upon which his religious system is founded; namely, that revealed religion is far superior to natural religion. For the aim of ethical training, which is the object of religion, is not to create in man good intentions, but to cause him to perform good deeds. This aim can not be attained by philosophy, which is undecided as to the nature of good, but can be secured by religious training, which teaches what is good. As science is the sum of all truth found by successive generations, so religious training is based upon a set of traditions; in other words, history is an important factor in the development of human culture and science. [edit] "Creatio ex Nihilo" Halevi writes that as the Jews are the only depositaries of a written history of the development of the human race from the beginning of the world, the superiority of their traditions can not be denied. Halevi asserts that no comparison is possible between Jewish culture, which in his view is based upon religious truth, and Greek culture, which is based upon science only. He holds that the wisdom of Greek philosophers lacked that divine support with which the Israelite prophets were endowed. Had a trustworthy tradition that the world was created out of nothing been known to Aristotle, he would have supported it by at least as strong arguments as those advanced by him to prove the eternity of matter. Belief in the eternity of matter, however, is not absolutely contrary to Jewish religious ideas; for the Biblical narrative of the Creation refers only to the beginning of the human race, and does not preclude the possibility of preexistent matter. Still, relying upon tradition, the Jews believe in "creatio ex nihilo," which theory can be sustained by as powerful arguments as those advanced in favor of the belief in the eternity of matter. The objection that the Absolutely Infinite and Perfect could not have produced imperfect and finite beings, made by the Neoplatonists to the theory of "creatio ex nihilo," is not removed by attributing the existence of all mundane things to the action of nature; for the latter is only a link in the chain of causes having its origin in the First Cause, which is God. [edit] Superiority of his faith Halevi now attempts to demonstrate the superiority of his religion, Judaism. From uDOTsDOTreddy at cs.bham.ac.uk Fri Jul 16 04:22:48 2010 From: uDOTsDOTreddy at cs.bham.ac.uk (Uday S Reddy) Date: Fri, 16 Jul 2010 09:22:48 +0100 Subject: death of newsgroups (Microsoft closing their newsgroups) In-Reply-To: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: On 7/13/2010 7:43 PM, Xah Lee wrote: > > I use comp.lang.lisp, comp.emacs since about 1999. Have been using > them pretty much on a weekly basis in the past 10 years. Starting > about 2007, the traffic has been increasingly filled with spam, and > the posters are always just the 20 or 30 known faces. I think perhaps > maybe no more than 100 different posters a year. Since this year or > last year, they are some 95% spam. > > comp.emacs is pretty much just me. > > gnu.emacs.help is not much better. It's pretty much the same > developers and the same few elisp coders, with perhaps 1 new face with > once-per-lifetime post every few days. gnu.emacs.help is doing a bit > better because it is connected to fsf's mailing list. Doing "better" means having more posts? I don't believe that having a lot of posts is necessarily a measure of goodness. In my opinion, discussion forums do well when they encourage people to think carefully and communicate clearly. In this respect, I think mailing lists do worse, newsgroups better, and web-based forums the best. Mailing lists seem to turn into talking shops where people get to know each other over time and their "public" nature gets lost. Those who write a lot end up dominating them, independent of whether they write any sense or not. The other people get tired and stop reading. So, you can generate a lot of traffic, but its value is dubious. Newsgroups are much better because they are public and, visibly so. If somebody says something stupid, a lot of people will jump on them. And, so, over time, they develop some quality. (There is no guarantee, of course. I have also seen a lot of newsgroups, especially in politics, really degenerate with opposing factions fighting and dominating everything else.) Web-based forums, especially those where people have to register, work the best in my experience. They are very visibly public, discouraging people to write nonsense. The difficulty of writing on the web instead of your favorite editor hopefully provides some resistance to write. So, people tend to think more than they write. I used a forum called silentpcforum last year to help me build myself a new computer. There was a lot of high quality information dating back to years, which was easy to find and easy to use. So, if newsgroups die and get replaced by web forums, that would be a move for the better. If they get replaced by mailing lists, that would be a move for the worse. Cheers, Uday From dr.mtarver at ukonline.co.uk Fri Jul 16 04:24:51 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Fri, 16 Jul 2010 01:24:51 -0700 (PDT) Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> Message-ID: <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> On 15 July, 23:21, bolega wrote: > http://www.gnu.org/philosophy/stallman-kth.html > > RMS lecture at KTH (Sweden), 30 October 1986 > > (Kungliga Tekniska H?gskolan (Royal Institute of Technology)) > Stockholm, Sweden > > Arranged by the student society > ?Datorf?reningen Stacken? > 30 October 1986 > > [Note: This is a slightly edited transcript of the talk. As such it > contains false starts, as well as locutions that are natural in spoken > English but look strange in print. It is not clear how to correct them > to written English style without ?doing violence to the original > speech?.] > > It seems that there are three things that people would like me to talk > about. On the one hand I thought that the best thing to talk about > here for a club of hackers, was what it was like at the MIT in the old > days. What made the Artificial Intelligence Lab such a special place. > But people tell me also that since these are totally different people > from the ones who were at the conference Monday and Tuesday that I > ought to talk about what's going on in the GNU project and that I > should talk about why software and information can not be owned, which > means three talks in all, and since two of those subjects each took an > hour it means we're in for a rather long time. So I had the idea that > perhaps I could split it in to three parts, and people could go > outside for the parts they are not interested in, and that then when I > come to the end of a part I can say it's the end and people can go out > and I can send Jan Rynning out to bring in the other people. (Someone > else says: ?Janne, han trenger ingen mike? (translation: ?Janne, he > doesn't need a mike?)). Jan, are you prepared to go running out to > fetch the other people? Jmr: I am looking for a microphone, and > someone tells me it is inside this locked box. Rms: Now in the old > days at the AI lab we would have taken a sledgehammer and cracked it > open, and the broken door would be a lesson to whoever had dared to > lock up something that people needed to use. Luckily however I used to > study Bulgarian singing, so I have no trouble managing without a > microphone. > > Anyway, should I set up this system to notify you about the parts of > the talk, or do you just like to sit through all of it? (Answer: > Yeaaah) > > When I started programming, it was 1969, and I did it in an IBM > laboratory in New York. After that I went to a school with a computer > science department that was probably like most of them. There were > some professors that were in charge of what was supposed to be done, > and there were people who decided who could use what. There was a > shortage of terminals for most people, but a lot of the professors had > terminals of their own in their offices, which was wasteful, but > typical of their attitude. When I visited the Artificial Intelligence > lab at MIT I found a spirit that was refreshingly different from that. > For example: there, the terminals was thought of as belonging to > everyone, and professors locked them up in their offices on pain of > finding their doors broken down. I was actually shown a cart with a > big block of iron on it, that had been used to break down the door of > one professors office, when he had the gall to lock up a terminal. > There were very few terminals in those days, there was probably > something like five display terminals for the system, so if one of > them was locked up, it was a considerable disaster. > > In the years that followed I was inspired by that ideas, and many > times I would climb over ceilings or underneath floors to unlock rooms > that had machines in them that people needed to use, and I would > usually leave behind a note explaining to the people that they > shouldn't be so selfish as to lock the door. The people who locked the > door were basically considering only themselves. They had a reason of > course, there was something they thought might get stolen and they > wanted to lock it up, but they didn't care about the other people they > were affecting by locking up other things in the same room. Almost > every time this happened, once I brought it to their attention, that > it was not up to them alone whether that room should be locked, they > were able to find a compromise solution: some other place to put the > things they were worried about, a desk they could lock, another little > room. But the point is that people usually don't bother to think about > that. They have the idea: ?This room is Mine, I can lock it, to hell > with everyone else?, and that is exactly the spirit that we must teach > them not to have. > > But this spirit of unlocking doors wasn't an isolated thing, it was > part of an entire way of life. The hackers at the AI lab were really > enthusiastic about writing good programs, and interesting programs. > And it was because they were so eager to get more work done, that they > wouldn't put up with having the terminals locked up, or lots of other > things that people could do to obstruct useful work. The differences > between people with high morale who really care about what they're > trying to do, and people who think of it as just a job. If it's just a > job, who cares if the people who hired you are so stupid they make you > sit and wait, it's their time, their money but not much gets done in a > place like that, and it's no fun to be in a place like that. > > Another thing that we didn't have at the AI lab was file protection. > There was no security at all on the computer. And we very consciously > wanted it that way. The hackers who wrote the Incompatible Timesharing > System decided that file protection was usually used by a self-styled > system manager to get power over everyone else. They didn't want > anyone to be able to get power over them that way, so they didn't > implement that kind of a feature. The result was, that whenever > something in the system was broken, you could always fix it. You never > had to sit there in frustration because there was NO WAY, because you > knew exactly what's wrong, and somebody had decided they didn't trust > you to do it. You don't have to give up and go home, waiting for > someone to come in in the morning and fix the system when you know ten > times as well as he does what needs to be done. > > And we didn't let any professors or bosses decide what work was going > to be done either, because our job was to improve the system! We > talked to the users of course; if you don't do that you can't tell > what's needed. But after doing that, we were the ones best able to see > what kind of improvements were feasible, and we were always talking to > each other about how we'd like to see the system changed, and what > sort of neat ideas we'd seen in other systems and might be able to > use. So the result is that we had a smoothly functioning anarchy, and > after my experience there, I'm convinced that that is the best way for > people to live. > > Unfortunately the AI lab in that form was destroyed. For many years we > were afraid the AI lab would be destroyed by another lab at MIT, the > Lab for Computer Science, whose director was a sort of empire builder > type, doing everything he could to get himself promoted within MIT, > and make his organization bigger, and he kept trying to cause the AI > lab to be made a part of his lab, and nobody wanted to do things his > way because he believed that people should obey orders and things like > that. > > But that danger we managed to defend against, only to be destroyed by > something we had never anticipated, and that was commercialism. Around > the early 80's the hackers suddenly found that there was now > commercial interest in what they were doing. It was possible to get > rich by working at a private company. All that was necessary was to > stop sharing their work with the rest of the world and destroy the MIT- > AI lab, and this is what they did despite all the efforts I could make > to prevent them. > > Essentially all the competent programmers except for me, at the AI lab > were hired away, and this caused more than a momentary change, it > caused a permanent transformation because it broke the continuity of > the culture of hackers. New hackers were always attracted by the old > hackers; there were the most fun computers and the people doing the > most interesting things, and also a spirit which was a great deal of > fun to be part of. Once these things were gone, there is nothing to > recommend the place to anyone new, so new people stopped arriving. > There was no-one they could be inspired by, no-one that they could > learn those traditions from. In addition no-one to learn how to do > good programming from. With just a bunch of professors and graduate > students, who really don't know how to make a program work, you can't > learn to make good programs work. So the MIT AI lab that I loved is > gone and after a couple of years of fighting against the people who > did it to try to punish them for it I decided that I should dedicate > my self to try to create a new community with that spirit. > > But one of the problems I had to face was the problem of proprietary > software. For example one thing that happened at the lab, after the > hackers left, was that the machines and the software that we had > developed could no longer be maintained. The software of course > worked, and it continued to work if nobody changed it, but the > machines did not. The machines would break and there would be no-one > who could fix them and eventually they would be thrown out. In the old > days, yes we had service contracts for the machines, but it was > essentially a joke. That was a way of getting parts after the expert > hackers from the AI lab fixed the problem. Because if you let the > field-service person fix it it would take them days, and you didn't > want to do that, you wanted it to work. So, the people who knew how to > do those things would just go and fix it quickly, and since they were > ten times as competent as any field service person, they could do a > much better job. And then they would have the ruined boards, they > would just leave them there and tell the field service person ?take > these back and bring us some new ones?. > > In the real old days our hackers used to modify the > > read more ?... Perhaps as an antidote http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi Mark From stefan_ml at behnel.de Fri Jul 16 04:25:19 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 10:25:19 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: <37a6f5de-1c73-4e53-afc6-ad588caec2c5@e5g2000yqn.googlegroups.com> Message-ID: Carl Banks, 16.07.2010 07:50: > On Jul 15, 8:33 pm, Stefan Behnel wrote: >> The code I referenced is from the Cython compiler, and we use it to "do >> stuff" with the AST. The visitor pattern is actually a pretty common way to >> bind code in a single place that does a certain thing to different parts of >> a data structure. Without it, if you kept that code *inside* of the data >> structure, you'd have to spill the type specific parts all over your code. > > Ahh, so this aspect oriented programming is it. Never thought about it that way, but you have a point there. It's pretty much the same idea as AOP, but without any of those huge and feature drooling code injection frameworks. Stefan From jeanmichel at sequans.com Fri Jul 16 05:00:55 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 16 Jul 2010 11:00:55 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> Message-ID: <4C401FC7.3010203@sequans.com> Karsten Wutzke wrote: >> Yes, typo, I meant strictly. >> >> > > Damn, I mean strongly. At least not for identifying which methods to > call depending on the type/s. > > Karsten > Stringly is the perfect combination of strictly and strongly. Nice one :) JM From clp2 at rebertia.com Fri Jul 16 05:22:56 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jul 2010 02:22:56 -0700 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: On Thu, Jul 15, 2010 at 12:37 PM, Sparky wrote: > Hello Python community! > > I am building a JSON-RPC web application that uses quite a few models. > I would like to return JSON encoded object information and I need a > system to indicate which properties should be returned when the object > is translated to a JSON encoded string. Unfortunately, this > application runs on top of Google's App Engine and, thus, private > attributes are not an option. Also, a preliminary search leads me to > believe that there are no real established ways to annotate variables. > Ideally I want to do something like: > > def to_JSON(self): > ? ? ? ?returnDict = {} > ? ? ? ?for member in filter(someMethod, inspect.getmembers(self)): > ? ? ? ? ? ? ? ?returnDict[member[0]] = member[1] > ? ? ? ?return json.dumps(returnDict) > > I recognize that two solutions would be to 1) include a prefix like > "public_" before variable names or 2) have a list/tuple of attributes > that should be transmitted, simply using the "in" operator. However, > both these options seem like a pretty ungraceful way to do it. Does > anyone else have an idea? Are there any established methods to apply > metadata / annotations to variables in Python or do you believe one of > the above is a good "pythonic" way to solve this problem? Those are about as Pythonic as you're going to get; I for one find the prefix (or similar) solution rather neat (Good luck pulling it off in a less dynamic language!), but option (2) is probably better in your particular case. Remember that at class-definition-time, Python has no idea what instance variables an object will have, so nothing exists for you to annotate; hence we're left with solutions of the forms you've given. You /could/ do something involving decorators and property()s, but that would be more verbose, more unnecessarily complicated, and less Pythonic. Cheers, Chris -- http://blog.rebertia.com From lists at cheimes.de Fri Jul 16 05:57:53 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 16 Jul 2010 11:57:53 +0200 Subject: Best Pythonic Approach to Annotation/Metadata? In-Reply-To: References: Message-ID: > def to_JSON(self): > returnDict = {} > for member in filter(someMethod, inspect.getmembers(self)): > returnDict[member[0]] = member[1] > return json.dumps(returnDict) By the way you don't need filter here. The getmembers() function has a filter functions. It's called 'predicate'. Try inspect.getmembers(self, someMethod). http://docs.python.org/library/inspect.html#inspect.getmembers From marduk at letterboxes.org Fri Jul 16 06:48:21 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 16 Jul 2010 06:48:21 -0400 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279258000.23856.1385149339@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <1279258000.23856.1385149339@webmail.messagingengine.com> Message-ID: <1279277301.487364.5.camel@paska> On Fri, 2010-07-16 at 01:26 -0400, python at bdurham.com wrote: > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. > No > matter what combination of backslashes or raw strings I use, I am > unable > to find a way to code the following. > > >>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' >>> encode(', '.join([chr(i) for i in (34, 92, 9, 10)])) But, as another poster already said, if the limitations of doctests are causing you to struggle, then don't use doctests and instead use "real" tests. From micayael at gmail.com Fri Jul 16 07:09:16 2010 From: micayael at gmail.com (micayael) Date: Fri, 16 Jul 2010 04:09:16 -0700 (PDT) Subject: adodb.NewADOConnection('postgres') returns None References: <31a4448e-1721-4dd4-aeb9-abc9ae22e5ec@w30g2000yqw.googlegroups.com> Message-ID: On 14 jul, 14:51, Mladen Gogala wrote: > On Wed, 14 Jul 2010 05:14:08 -0700, micayael wrote: > > Thanks Thomas. > > :-( then adodb today dosn't work with postgres (at least on ubuntu) > > right? > > No, ADOdb doesn't work with the newer versions of Postgres. ADOdb doesn't > work with Psycopg2 and the guy who maintains it did not reply to my > email. That is unfortunate because ADOdb is my favorite PHP class > library. It seems, though, that the Python version is not nearly as well > maintained as the PHP one. > > --http://mgogala.byethost5.com Thanks all of you for reply. Well bad news then, we have to use Psycopg2 directly. From bjornsteinarfjeldpettersen at gmail.com Fri Jul 16 08:02:11 2010 From: bjornsteinarfjeldpettersen at gmail.com (thebjorn) Date: Fri, 16 Jul 2010 05:02:11 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: On Jul 15, 10:34?pm, Peter wrote: > On Jul 16, 2:45?am, kj wrote: > > > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > > How do you do Python code-folding in Emacs? > > > Thanks! > > > ~K > [...] > Anybody else now of any better ideas or whatever? Now that I think > about it, I wouldn't mind using folding mode if I could make it > "easier" to use myself! :-) > > Peter I gave up too :-( Komodo from ActiveState has Emacs bindings and folding, and is generally a good editor and environment for when you want such a thing. It also has an out-of-process debugger that has helped me solve some nasty bugs. Still, I keep going back to Emacs, it's just snappier(*) and easier(**) to work with... Instead of folding I either split the window or create a new Frame (Ctrl 5 2) for the content I wish to refer to. -- bjorn (*) ha! (**) ...I know... From bjornsteinarfjeldpettersen at gmail.com Fri Jul 16 08:05:55 2010 From: bjornsteinarfjeldpettersen at gmail.com (thebjorn) Date: Fri, 16 Jul 2010 05:05:55 -0700 (PDT) Subject: Cannot send email References: <594998.379.qm@web53205.mail.re2.yahoo.com> Message-ID: On Jul 15, 7:07?pm, "D'Arcy J.M. Cain" wrote: > On Thu, 15 Jul 2010 09:50:57 -0700 (PDT) > > G F wrote: > > Does anyone have any ideas where the trouble is and what can be done > > about it? The little bit about: > > "reply: retcode (557); Msg: This mail server does not accept mail > > addressed to anInterestedPer... at yahoo.com" > > seems to be telling but I do not know why the server would respond this way. > > This is really not a Python question but I think that you will find > that the issue is that the server needs to know about the new IP > address. ?The error looks like an anti-relay thing. > > Contact the mail server admin or ask on a list dedicated to > administrating email. > Jeff Atwood had a column about it recently http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html well worth a read. -- bjorn From inquisitive.scientist at gmail.com Fri Jul 16 08:45:50 2010 From: inquisitive.scientist at gmail.com (Inquisitive Scientist) Date: Fri, 16 Jul 2010 05:45:50 -0700 (PDT) Subject: improvement for copy.deepcopy : no memo for immutable types Message-ID: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> I am having problems with running copy.deepcopy on very large data structures containing lots of numeric data: 1. copy.deepcopy can be very slow 2. copy.deepcopy can cause memory errors even when I have plenty of memory I think the problem is that the current implementation keeps a memo for everything it copies even immutable types. In addition to being slow, this makes the memo dict grow very large when there is lots of simple numeric data to be copied. For long running programs, large memo dicts seem to cause memory fragmentation and result in memory errors. It seems like this could be easily fixed by adding the following lines at the very start of the deepcopy function: if isinstance(x, (type(None), int, long, float, bool, str)): return x This seems perfectly safe, should speed things up, keep the memo dict smaller, and be easy to add. Can someone add this to copy.py or point me to the proper procedure for requesting this change in copy.py? Thanks, -I.S. From nick_keighley_nospam at hotmail.com Fri Jul 16 09:00:57 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Fri, 16 Jul 2010 06:00:57 -0700 (PDT) Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: On 16 July, 09:24, Mark Tarver wrote: > On 15 July, 23:21, bolega wrote: > > >http://www.gnu.org/philosophy/stallman-kth.html > > > RMS lecture at KTH (Sweden), 30 October 1986 did you really have to post all of this... > > read more ?... ...oh sorry only about a third of it... > Perhaps as an antidote > > http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-form... ...to add two lines? From stefan_ml at behnel.de Fri Jul 16 09:02:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 15:02:50 +0200 Subject: improvement for copy.deepcopy : no memo for immutable types In-Reply-To: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> Message-ID: Inquisitive Scientist, 16.07.2010 14:45: > I am having problems with running copy.deepcopy on very large data > structures containing lots of numeric data: > > 1. copy.deepcopy can be very slow > 2. copy.deepcopy can cause memory errors even when I have plenty of > memory > > I think the problem is that the current implementation keeps a memo > for everything it copies even immutable types. In addition to being > slow, this makes the memo dict grow very large when there is lots of > simple numeric data to be copied. For long running programs, large > memo dicts seem to cause memory fragmentation and result in memory > errors. > > It seems like this could be easily fixed by adding the following lines > at the very start of the deepcopy function: > > if isinstance(x, (type(None), int, long, float, bool, str)): > return x > > This seems perfectly safe, should speed things up, keep the memo dict > smaller, and be easy to add. and - have you tried it? Stefan From schaffer at optonline.net Fri Jul 16 09:07:42 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 16 Jul 2010 09:07:42 -0400 Subject: any issues with long running python apps? In-Reply-To: <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> Message-ID: <4c40599f$0$21783$607ed4bc@cv.net> thanks to all for the replies. the Windows memory fragmentation was one of the "i didn't know that" items. we will use 64-bit Windows OS if the job happens. agree with all the other suggestions: multiple threads for data and GUI, etc. Also, might push for Linux even though the company is Windows-only presently. but thinking about the issue some more as well as everyone's comments, have decided to proceed cautiously and let the client decide first that they really need this app regardless of guaranteed Windows-based uptime. Les From victorsubervi at gmail.com Fri Jul 16 09:22:31 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 16 Jul 2010 08:52:31 -0430 Subject: MySQL One More Again Message-ID: Hi; I have the following code: cursor.execute('select MyTable from optionsDetails where Store=%s', (store,)) options_tables = [item[0] for item in cursor] for table in options_tables: cursor.execute('select * from %' % table) You can already see what my question is. One of y'all said it's possible under certain conditions to use the % without risking attack. Now is when I need to know how to do that. Please advise. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Jul 16 09:29:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 15:29:35 +0200 Subject: any issues with long running python apps? In-Reply-To: <4c40599f$0$21783$607ed4bc@cv.net> References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> <4c40599f$0$21783$607ed4bc@cv.net> Message-ID: Les Schaffer, 16.07.2010 15:07: > agree with all the other suggestions: multiple threads for data and GUI, The way I read it, the suggestion was to use separate processes, not multiple threads. That's a pretty important difference. Stefan From nfdisco at gmail.com Fri Jul 16 09:29:46 2010 From: nfdisco at gmail.com (ernest) Date: Fri, 16 Jul 2010 06:29:46 -0700 (PDT) Subject: Q for Emacs users: code-folding (hideshow) References: Message-ID: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> On 15 Jul, 18:45, kj wrote: > This is a question _for Emacs users_ (the rest of you, go away :) ?). > > How do you do Python code-folding in Emacs? > > Thanks! > > ~K I tried the outline-mode and it seemed to work. It can collapse different blocks of code, such as functions, classes, etc. However, I never got used to it because of the bizarre key bindings. Bye. Ernest From usenot at geekmail.INVALID Fri Jul 16 09:38:31 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 16 Jul 2010 15:38:31 +0200 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: <20100716153831.5d399451@geekmail.INVALID> On Fri, 16 Jul 2010 06:29:46 -0700 (PDT) ernest wrote: > On 15 Jul, 18:45, kj wrote: > > This is a question _for Emacs users_ (the rest of you, go away :) > > ?). > > > > How do you do Python code-folding in Emacs? > > > > Thanks! > > > > ~K > > I tried the outline-mode and it seemed to work. It can > collapse different blocks of code, such as functions, > classes, etc. > > However, I never got used to it because of the bizarre > key bindings. > Yeah, that's Emacs for ya ... Like, BURRRN! ... OK, I'll move along. /W -- INVALID? DE! From python at mrabarnett.plus.com Fri Jul 16 09:49:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 14:49:21 +0100 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4C406361.8050607@mrabarnett.plus.com> Lawrence D'Oliveiro wrote: > In message , MRAB wrote: > >> Normally it's only string literals that could be so long that you might >> want to split them over several lines. It is somewhat unusual to have a >> _numeric_ literal that's very very long! > > Seems a peculiar assumption to make in a language that allows integers of > arbitrary length, does it not? What's the recommended maximum line length in Python? 80 characters? If you take into account indentation, etc, that's still a long integer. And it's still only the _recommended_ maximum. From no.email at please.post Fri Jul 16 09:53:02 2010 From: no.email at please.post (kj) Date: Fri, 16 Jul 2010 13:53:02 +0000 (UTC) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: In Thomas Jollans writes: >On 07/15/2010 06:41 PM, kj wrote: >> In Thomas Jollans writes: >> >>> http://docs.python.org/library/ctypes.html#fundamental-data-types >> >>> c_longdouble maps to float >> >> Thanks for pointing this out! >> ~K >> (Does it make *any difference at all* to use c_longdouble instead >> of c_double? If not, I wonder what's the point of having c_longdouble >> at all.) >they're still different types (in C). i understand that doubles and long doubles are different in C. >on my machine, a double is 64 bits wide, while a long double is 129 bits >wide. This means that a function that expects a long double argument >will expect 16 bytes, but ctypes will only pass 8 bytes if you tell it >to pass double. The same applies to return values. This is extremely confusing. From my naive reading of the documentation, I would have expected that the following two blocks would produce identical results (expl is one of the standard C math library exponential functions, with signature "long double expl(long double)"): MATH.expl.argtypes = [c_longdouble] MATH.expl.restype = c_longdouble print MATH.expl(0) MATH.expl.argtypes = [c_double] MATH.expl.restype = c_double print MATH.expl(0) ...but no, they don't: the first one prints out the correct result, 1.0, while the second one prints out 0.0, of all things. (In fact, with the second (mis)configuration, the value returned by MATH.expl is always equal to its argument, go figure.) I find these results perplexing because, based on the docs, I expected that they *both* would be analogous to doing the following in C: printf("%f\n", (double) expl((double) 0.0)); /* prints out 1.000000 */ i.e., in *both* cases, expl would get passed a double (which gets automatically cast into a long double), and in both cases its returned value would be cast into a double. Clearly, this is not what's happening, but I can't figure out the correct interpreation of what's going on based on the documentation... From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 09:59:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 13:59:31 GMT Subject: improvement for copy.deepcopy : no memo for immutable types References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> Message-ID: <4c4065c2$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 05:45:50 -0700, Inquisitive Scientist wrote: > I am having problems with running copy.deepcopy on very large data > structures containing lots of numeric data: [...] > This seems perfectly safe, should speed things up, keep the memo dict > smaller, and be easy to add. Can someone add this to copy.py or point me > to the proper procedure for requesting this change in copy.py? These are the minimum steps you can take: (1) Go to the Python bug tracker: http://bugs.python.org/ (2) If you don't already have one, create an account. (3) Create a new bug report, explaining why you think deepcopy is buggy, the nature of the bug, and your suggested fix. If you do so, it might be a good idea to post a link to the bug here, for interested people to follow up. However doing the minimum isn't likely to be very useful. Python is maintained by volunteers, and there are more bugs than person-hours available to fix them. Consequently, unless a bug is serious, high- profile, or affects a developer personally, it is likely to be ignored. Sometimes for years. Sad but true. You can improve the odds of having the bug (assuming you are right that it is a bug) fixed by doing more than the minimum. The more of these you can do, the better the chances: (4) Create a test that fails with the current code, following the examples in the standard library tests. Confirm that it fails with the existing module. (5) Patch the copy module to fix the bug. Confirm that the new test passes with your patch, and that you don't cause any regressions (failed tests). (6) Create a patch file that adds the new test and the patch. Upload it to the bug tracker. There's no point in writing the patch for Python 2.5 or 3.0, don't waste your time. Version 2.6 *might* be accepted. 2.7 and/or 3.1 should be, provided people agree that it is a bug. If you do all these things -- demonstrate successfully that this is a genuine bug, create a test for it, and fix the bug without breaking anything else, then you have a good chance of having the fix accepted. Good luck! Your first patch is always the hardest. -- Steven From schaffer at optonline.net Fri Jul 16 10:13:17 2010 From: schaffer at optonline.net (Les Schaffer) Date: Fri, 16 Jul 2010 10:13:17 -0400 Subject: any issues with long running python apps? In-Reply-To: References: <4c3774df$0$31278$607ed4bc@cv.net> <8679d700-be68-4dbc-8784-3b0d93d6a77c@r27g2000yqb.googlegroups.com> <4c40599f$0$21783$607ed4bc@cv.net> Message-ID: <4c4068f5$0$31269$607ed4bc@cv.net> Stefan Behnel wrote: > Les Schaffer, 16.07.2010 15:07: >> agree with all the other suggestions: multiple threads for data and GUI, > > The way I read it, the suggestion was to use separate processes, not > multiple threads. That's a pretty important difference. check. processes, not threads. Les From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 10:17:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Jul 2010 14:17:02 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> Message-ID: <4c4069de$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > Lawrence D'Oliveiro wrote: >> In message , MRAB >> wrote: >> >>> Normally it's only string literals that could be so long that you >>> might want to split them over several lines. It is somewhat unusual to >>> have a _numeric_ literal that's very very long! >> >> Seems a peculiar assumption to make in a language that allows integers >> of arbitrary length, does it not? > > What's the recommended maximum line length in Python? 80 characters? If > you take into account indentation, etc, that's still a long integer. And > it's still only the _recommended_ maximum. Not only that, but it only takes 73 digits to write out the total number of particles in the entire universe: 1000000000000000000000000000000000000000000000000000000000000000000000000 or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all the way up to 1e87.) So for anything related to counting or labelling actual, physical objects, you will be dealing with smaller numbers than that. E.g. the number of grains of sand on the earth has been estimated (very roughly) as a mere 1000000000000000000000000, or 25 digits. It always makes me laugh when I receive an invoice from some company, and the account number or invoice number is (e.g.) 1000000023456789. Who do they think they're fooling? -- Steven From python at mrabarnett.plus.com Fri Jul 16 10:32:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:32:40 +0100 Subject: File transfer on network In-Reply-To: References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: <4C406D88.40707@mrabarnett.plus.com> mukesh tiwari wrote: > On Jul 16, 4:08 am, MRAB wrote: >> mukesh tiwari wrote: >>> Hello all >>> Currently i am trying to develop a client and server in python. Client >>> takes screenshot in every 20 seconds and send it to server. Server >>> store the received file in folder. Here is code for Client >>> import sys >>> import socket >>> import gtk.gdk >>> import time >>> if __name__ == "__main__": >>> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); >>> host,port="localhost",50007 >>> s.connect((host,port)) >>> while 1: >>> w = gtk.gdk.get_default_root_window() >>> sz = w.get_size() >>> pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1]) >>> pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) >>> if (pb != None): >>> pb.save('/home/tmp_1/screenshot.png',"png") >>> f=open('/home//tmp_1/screenshot.png','rb') >>> while 1: >>> blk=f.read(2048) >>> if not blk:break >>> s.send(blk) >>> f.close() >>> print 'file transfer done'; >>> time.sleep(20) >>> s.close() >>> Server Code >>> import sys >>> import socket >>> import time >>> if __name__ == "__main__": >>> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) >>> host,port="",50007 >>> s.bind((host,port)) >>> s.listen(1) >>> conn,add=s.accept() >>> i=0 >>> while 1: >>> f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb') >>> while 1: >>> data=conn.recv(2048) >>> if not data:break >>> f.write(data) >>> f.close() >>> print 'file received' >>> time.sleep(20) >>> i+=1; >>> #print ' file received ' >>> conn.close() >>> My problem is that server is copying only first image >>> copyscreenshot_0.png while my client continuously taking screen shot. >>> Kindly tell me what is wrong with my server code. >> The .recv will return an empty string only when the connection is closed >> by the client, but the client keeps the connection open. >> >> You could either open and close a connection for each image, or have the >> client tell the server how many bytes it's going to send, followed by >> the bytes (my preference would be to send the size as a string ending >> with, say, a newline). >> >> Another point: the .send method doesn't guarantee that it'll send all >> the bytes (it'll return the number of bytes that it has actually sent); >> use the .sendall method instead. > > Thank you MARB. I used your first idea and opening and closing > connection for each image. Just wanted to know if i have to take > pictures at small intervals , this method is efficient or not? Creating a new connection every 20 seconds should be OK. For much smaller intervals you would need to test it yourself. The minimum interval depends on how often you're sending data and you're sending each time, and keeping the connection open would let you avoid the extra overhead and get a little bit more capacity. > It would be great if you can provide a bit code for second method. > Keeping the connection open but how to know that this is end a > particular image and save it. The client is told how many bytes of image data it should expect, so it can count how many it has written to the image file and close the file when all of them. You'll learn more if you try it yourself first! :-) From johann.spies at gmail.com Fri Jul 16 10:34:19 2010 From: johann.spies at gmail.com (Johann Spies) Date: Fri, 16 Jul 2010 16:34:19 +0200 Subject: Nested loop not working Message-ID: I am overlooking something stupid. I have two files: one with keywords and another with data (one record per line). I want to determine for each keyword which lines in the second file contains that keyword. The following code is not working. It loops through the second file but only uses the first keyword in the first file. #!/usr/bin/env python # -*- coding: utf-8 -*- import re keywords = open("sleutelwoorde",'r') data = open("sarua_marine_sleutelwoorde.csv",'r') remove_quotes = re.compile('"') for sw in keywords: for r in data: swc = remove_quotes('',sw)[:-1] if swc in r.lower(): print swc + ' ---> ' + r print swc What am I missing? Regards Johann -- "Finally, brethren, whatsoever things are true, whatsoever things are honest, whatsoever things are just, whatsoever things are pure, whatsoever things are lovely, whatsoever things are of good report; if there be any virtue, and if there be any praise, think on these things." Philippians 4:8 From python at mrabarnett.plus.com Fri Jul 16 10:39:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:39:21 +0100 Subject: MySQL One More Again In-Reply-To: References: Message-ID: <4C406F19.5080909@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have the following code: > > cursor.execute('select MyTable from optionsDetails where Store=%s', > (store,)) > options_tables = [item[0] for item in cursor] > for table in options_tables: > cursor.execute('select * from %' % table) > Should be: 'select * from %s' % table Details! :-) > You can already see what my question is. One of y'all said it's possible > under certain conditions to use the % without risking attack. Now is > when I need to know how to do that. Please advise. > It's safe when there's no way that the value you're putting in can come from the user. Here you're taking it from the 'optionsDetails' table. Can the user add, alter or delete that entry in any way? From python at mrabarnett.plus.com Fri Jul 16 10:41:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:41:45 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c4069de$0$11101$c3e8da3@news.astraweb.com> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C406FA9.9030504@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > >> Lawrence D'Oliveiro wrote: >>> In message , MRAB >>> wrote: >>> >>>> Normally it's only string literals that could be so long that you >>>> might want to split them over several lines. It is somewhat unusual to >>>> have a _numeric_ literal that's very very long! >>> Seems a peculiar assumption to make in a language that allows integers >>> of arbitrary length, does it not? >> What's the recommended maximum line length in Python? 80 characters? If >> you take into account indentation, etc, that's still a long integer. And >> it's still only the _recommended_ maximum. > > Not only that, but it only takes 73 digits to write out the total number > of particles in the entire universe: > > 1000000000000000000000000000000000000000000000000000000000000000000000000 > > or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all > the way up to 1e87.) So for anything related to counting or labelling > actual, physical objects, you will be dealing with smaller numbers than > that. E.g. the number of grains of sand on the earth has been estimated > (very roughly) as a mere 1000000000000000000000000, or 25 digits. > > It always makes me laugh when I receive an invoice from some company, and > the account number or invoice number is (e.g.) 1000000023456789. Who do > they think they're fooling? > It's possible that they're splitting it into fields. From victorsubervi at gmail.com Fri Jul 16 10:55:10 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 16 Jul 2010 10:25:10 -0430 Subject: MySQL One More Again In-Reply-To: <4C406F19.5080909@mrabarnett.plus.com> References: <4C406F19.5080909@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 10:09 AM, MRAB wrote: > Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> cursor.execute('select MyTable from optionsDetails where Store=%s', >> (store,)) >> options_tables = [item[0] for item in cursor] >> for table in options_tables: >> cursor.execute('select * from %' % table) >> >> Should be: > > 'select * from %s' % table > > Details! :-) LOL. Whoops. Thanks. > > > You can already see what my question is. One of y'all said it's possible >> under certain conditions to use the % without risking attack. Now is when I >> need to know how to do that. Please advise. >> >> It's safe when there's no way that the value you're putting in can come > from the user. > > Here you're taking it from the 'optionsDetails' table. Can the user add, > alter or delete that entry in any way? > No, and that's kind of what I figured. Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Fri Jul 16 10:56:25 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 16 Jul 2010 07:56:25 -0700 (PDT) Subject: ctypes' c_longdouble: underflow error (bug?) References: Message-ID: <8a635803-56c4-4593-954a-510561567e17@d8g2000yqf.googlegroups.com> On Jul 16, 2:53?pm, kj wrote: > This is extremely confusing. ?From my naive reading of the > documentation, I would have expected that the following two blocks > would produce identical results (expl is one of the standard C math > library exponential functions, with signature "long double expl(long > double)"): > > MATH.expl.argtypes = [c_longdouble] > MATH.expl.restype = c_longdouble > print MATH.expl(0) > > MATH.expl.argtypes = [c_double] > MATH.expl.restype = c_double > print MATH.expl(0) > > ...but no, they don't: the first one prints out the correct result, > 1.0, while the second one prints out 0.0, of all things. ?(In fact, > with the second (mis)configuration, the value returned by MATH.expl > is always equal to its argument, go figure.) This is just a case of garbage in, garbage out. In the second case you're telling ctypes that the signature of expl is double expl(double) which just isn't true. ctypes has no way of telling that in fact expl takes a long double rather than a double. > I find these results perplexing because, based on the docs, I > expected that they *both* would be analogous to doing the following > in C: > > printf("%f\n", (double) expl((double) 0.0)); /* prints out 1.000000 */ No, not really. Assuming that expl has been declared somewhere (e.g. you've included math.h), the C compiler knows that expl takes a long double, so it'll convert the "(double) 0.0" argument to a long double before passing it to expl. Your second Python+ctypes example would be equivalent to doing something like this in C: #include double expl(double x); /* deliberate misdeclaration of expl */ int main(void) { printf("%f\n", expl(0.0)); return 0; } which indeed produces 0.0 on my machine (gcc 4.2 / OS X 10.6). And the compiler helpfully issues a warning: test.c:1: warning: conflicting types for built-in function ?expl? Actually, the warning is a bit surprising, because there's only one (wrong) declaration for expl, so what is there for it to conflict with? The answer is that there are some commonly used library functions that gcc has builtin versions for, so already knows the signature of; expl is one of these. This is backed up by the fact that when compiling with -fno-builtin-expl, no warning is issued. > i.e., in *both* cases, expl would get passed a double (which gets > automatically cast into a long double), But how on earth would ctypes *know* it's supposed to convert (nitpick: not cast) to a long double? The function signature isn't available to ctypes; it's only through you setting .argtypes and .restype that ctypes knows anything about it. -- Mark From ian.g.kelly at gmail.com Fri Jul 16 10:56:46 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Jul 2010 08:56:46 -0600 Subject: Nested loop not working In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 8:34 AM, Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. ?It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > ? ?for r in data: > ? ? ? ?swc = remove_quotes('',sw)[:-1] > ? ? ? ?if swc in r.lower(): > ? ? ? ? ? ? ? ?print swc + ' ---> ' + r > ? ? ? ? ? ? ? ?print swc > > What am I missing? Not sure about the loop, but this line looks incorrect: swc = remove_quotes('',sw)[:-1] I don't think a compiled regular expression object is callable; you have to call one of its methods. HTH, Ian From python at mrabarnett.plus.com Fri Jul 16 10:59:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 15:59:28 +0100 Subject: Nested loop not working In-Reply-To: References: Message-ID: <4C4073D0.7050601@mrabarnett.plus.com> Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? > The line: for r in data reads through the file until it the end. The next time around the outer loop it's already at the end of the file. You need to reset it to the start of the file with: data.seek(0) Incidentally, it would be faster if you read the keywords into a list first (assuming that there isn't a huge number of keywords) and then scanned through the file once. From pwdyson at yahoo.com Fri Jul 16 11:15:54 2010 From: pwdyson at yahoo.com (Paul) Date: Fri, 16 Jul 2010 08:15:54 -0700 (PDT) Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... Message-ID: <717828.19237.qm@web53602.mail.re2.yahoo.com> > Thomas Jollans, 15.07.2010 18:41: > > On 07/15/2010 01:00 PM, Paul wrote: > >> I'm pleased to announce the release of inflect.py v0.1.8, a module that > >> correctly generates: > >> * the plural of singular nouns and verbs > >> * the singular of plural nouns > >> * ordinals > >> * indefinite articles > >> * present participles > >> * and converts numbers to words > > Which languages does it support? If the answer is what I expect it is, > It is. Most of the time, when people forget to say what they are talking > about, assuming that they are either US-Americans or Windows users will hit > the nail on the head. > Still, a pretty nice tool, I'd say. > > did you design the module with multilingualism in mind? > Just look at the code, it consists almost exclusively of long lists of > words. Multilingualism clearly wasn't a design goal. > Stefan The module is based upon a Perl module that has been around for about ten years. I did a line by line translation of the Perl code into Python, got that working and am now slowly redesigning the code. I am currently removing many of the regular expressions, which makes the code many times faster (and clearer, I think). The code alternates between applying rules and using lists of words. The author of the original Perl code, Damian Conway, wrote an academic paper on the approach taken. http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html A future goal is to have this work in a way that is far more pluggable and so be applicable to other languages. But at the moment I'm happy to have got it working. I'm pretty sure that if Damian was writing this from scratch today he would design it differently. However, I had existing Perl code that worked, so I would rather start with that, get it working in Python and covered by tests. Then I can improve the design with the safety of test coverage. The Perl version is called Lingua::EN::Inflect, so was more explicit about being for English in its naming and there are other Perl Lingua::XX::Inflects for other languages. But my lack of mentioning English in the announcement was an oversight. Both the Perl author and I are Australian, and so the modules support British English over American English where necessary, with the Oxford English Dictionary as our guide. Cheers, Paul From ramercer at gmail.com Fri Jul 16 11:18:41 2010 From: ramercer at gmail.com (Adam Mercer) Date: Fri, 16 Jul 2010 10:18:41 -0500 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 02:09, Heikki Toivonen wrote: > That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL > changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at > this time, you should check out M2Crypto from the Subversion repository. See > http://chandlerproject.org/Projects/MeTooCrypto for details on how to get > the sources. Thanks any ETA on a new release supporting OpenSSL 1.0.x? Cheers Adam From fetchinson at googlemail.com Fri Jul 16 11:26:05 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 16 Jul 2010 17:26:05 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: >>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>> correctly generates: >>> >>> * the plural of singular nouns and verbs >>> * the singular of plural nouns >>> * ordinals >>> * indefinite articles >>> * present participles >>> * and converts numbers to words >> >> Which languages does it support? If the answer is what I expect it is, > > It is. Most of the time, when people forget to say what they are talking > about, assuming that they are either US-Americans or Windows users will hit > the nail on the head. And most of the time, when people are bitching about US-Americans, assuming that they are Europeans will hit the nail on the head :) Duck-and-run-ly yours, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Fri Jul 16 11:29:23 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 16 Jul 2010 11:29:23 -0400 Subject: Nested loop not working In-Reply-To: References: Message-ID: <4C407AD3.204@ieee.org> Johann Spies wrote: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? > > Regards > Johann > > Once you've read all the data from 'data' in the first inner loop, there's no more for the second keyword. Easiest answer is to do something like: data.seek(0) just before the inner loop. That will (re)position to begin of hte 'data' file. DaveA From fetchinson at googlemail.com Fri Jul 16 11:29:44 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 16 Jul 2010 17:29:44 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>>> correctly generates: >>>> >>>> * the plural of singular nouns and verbs >>>> * the singular of plural nouns >>>> * ordinals >>>> * indefinite articles >>>> * present participles >>>> * and converts numbers to words >>> >>> Which languages does it support? If the answer is what I expect it is, >> >> It is. Most of the time, when people forget to say what they are talking >> about, assuming that they are either US-Americans or Windows users will >> hit >> the nail on the head. > > And most of the time, when people are bitching about US-Americans, > assuming that they are Europeans will hit the nail on the head :) In this case, I actually should modify the above to: when people are bitching about an English speaker they don't like for some reason and they automatically think that said person must be US-American when in fact he/she is Australian (or British or South African or something else), assuming that they are Europeans will hit the nail on the head :) Duck-and-run-even-faster-ly yours, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From drobinow at gmail.com Fri Jul 16 11:42:46 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 16 Jul 2010 11:42:46 -0400 Subject: Q for Emacs users: code-folding (hideshow) In-Reply-To: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: On Fri, Jul 16, 2010 at 9:29 AM, ernest wrote: > On 15 Jul, 18:45, kj wrote: >> This is a question _for Emacs users_ (the rest of you, go away :) ?). >> >> How do you do Python code-folding in Emacs? >> >> Thanks! >> >> ~K > > I tried the outline-mode and it seemed to work. It can > collapse different blocks of code, such as functions, > classes, etc. > > However, I never got used to it because of the bizarre > key bindings. Really, if you can't be bothered to set your key bindings to something you prefer, then I don't think Emacs is the right tool for you. From rui.vapps at gmail.com Fri Jul 16 12:01:01 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 16 Jul 2010 09:01:01 -0700 (PDT) Subject: create dynamic instance Message-ID: class Test: def __init__(self): self.value=0 def change(self, val): self.value=val if __name__=='__main__': for x in range(10): x=Test() """ the question is how do i call x.value outside of that for loop? something like print x.value ? """ thanks for any help. From fuglyducky at gmail.com Fri Jul 16 12:10:09 2010 From: fuglyducky at gmail.com (fuglyducky) Date: Fri, 16 Jul 2010 09:10:09 -0700 (PDT) Subject: Python 3 and setuptools Message-ID: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> I am trying to install a library that requires setuptools. Unfortunately, setuptools isn't available for Python 3 yet. Is this correct? Any idea when it may be available OR if there is a different tool/method of getting setuptools installed for Python 3? Thanks!!! From nagle at animats.com Fri Jul 16 12:10:57 2010 From: nagle at animats.com (John Nagle) Date: Fri, 16 Jul 2010 09:10:57 -0700 Subject: MySQL One More Again In-Reply-To: References: Message-ID: <4c40849f$0$1583$742ec2ed@news.sonic.net> On 7/16/2010 7:39 AM, MRAB wrote: > Victor Subervi wrote: >> Hi; >> I have the following code: >> >> cursor.execute('select MyTable from optionsDetails where Store=%s', >> (store,)) >> options_tables = [item[0] for item in cursor] >> for table in options_tables: >> cursor.execute('select * from %' % table) As has been explained to you repeatedly, you're doing it wrong. You don't use a relational database to get a field which leads to another table. Put the options in one table keyed by Store. Go buy a copy of "Databases for Dummies": http://www.amazon.com/Intranet-Databases-Dummies-Paul-Litwin/dp/0764502212 John Nagle From python at mrabarnett.plus.com Fri Jul 16 12:15:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 17:15:19 +0100 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: <717828.19237.qm@web53602.mail.re2.yahoo.com> References: <717828.19237.qm@web53602.mail.re2.yahoo.com> Message-ID: <4C408597.9000705@mrabarnett.plus.com> Paul wrote: >> Thomas Jollans, 15.07.2010 18:41: > >>> On 07/15/2010 01:00 PM, Paul wrote: >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module >>>> that correctly generates: > >>>> * the plural of singular nouns and verbs >>>> * the singular of plural nouns >>>> * ordinals >>>> * indefinite articles >>>> * present participles >>>> * and converts numbers to words > >>> Which languages does it support? If the answer is what I expect it >>> is, > >> It is. Most of the time, when people forget to say what they are >> talking about, assuming that they are either US-Americans or Windows >> users will hit the nail on the head. > >> Still, a pretty nice tool, I'd say. > >>> did you design the module with multilingualism in mind? > >> Just look at the code, it consists almost exclusively of long lists >> of words. Multilingualism clearly wasn't a design goal. > >> Stefan > > The module is based upon a Perl module that has been around for about > ten years. I did a line by line translation of the Perl code into > Python, got that working and am now slowly redesigning the code. I am > currently removing many of the regular expressions, which makes the > code many times faster (and clearer, I think). > > The code alternates between applying rules and using lists of words. > The author of the original Perl code, Damian Conway, wrote an academic > paper on the approach taken. > http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html > > A future goal is to have this work in a way that is far more pluggable > and so be applicable to other languages. But at the moment I'm happy > to have got it working. > > I'm pretty sure that if Damian was writing this from scratch today he > would design it differently. However, I had existing Perl code that > worked, so I would rather start with that, get it working in Python > and covered by tests. Then I can improve the design with the safety of > test coverage. > > The Perl version is called Lingua::EN::Inflect, so was more explicit > about being for English in its naming and there are other Perl > Lingua::XX::Inflects for other languages. But my lack of mentioning > English in the announcement was an oversight. Both the Perl author and > I are Australian, and so the modules support British English over > American English where necessary, with the Oxford English Dictionary > as our guide. > Could I suggest that you also change the method names to something clearer? From python at mrabarnett.plus.com Fri Jul 16 12:17:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 17:17:54 +0100 Subject: create dynamic instance In-Reply-To: References: Message-ID: <4C408632.5060205@mrabarnett.plus.com> Ray wrote: > class Test: > def __init__(self): > self.value=0 > def change(self, val): > self.value=val > > if __name__=='__main__': > for x in range(10): > x=Test() > """ > the question is how do i call x.value outside of that for loop? > something like > print x.value ? > """ > > thanks for any help. Have you tried it? Why are you using the same name for the loop variable and the instance you're creating? From stefan_ml at behnel.de Fri Jul 16 12:20:37 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Jul 2010 18:20:37 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... In-Reply-To: References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: Daniel Fetchinson, 16.07.2010 17:29: >>>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that >>>>> correctly generates: >>>>> >>>>> * the plural of singular nouns and verbs >>>>> * the singular of plural nouns >>>>> * ordinals >>>>> * indefinite articles >>>>> * present participles >>>>> * and converts numbers to words >>>> >>>> Which languages does it support? If the answer is what I expect it is, >>> >>> It is. Most of the time, when people forget to say what they are talking >>> about, assuming that they are either US-Americans or Windows users will >>> hit the nail on the head. >> >> And most of the time, when people are bitching about US-Americans, >> assuming that they are Europeans will hit the nail on the head :) > > In this case, I actually should modify the above to: when people are > bitching about an English speaker they don't like for some reason and > they automatically think that said person must be US-American when in > fact he/she is Australian (or British or South African or something > else), assuming that they are Europeans will hit the nail on the head > :) :) I'm happy to see that the good old clich?s still work in all directions. Makes the world so easy. Stefan From rui.vapps at gmail.com Fri Jul 16 12:22:16 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 16 Jul 2010 09:22:16 -0700 (PDT) Subject: create dynamic instance References: Message-ID: <5fe7c1ea-4a1b-46d8-a2f0-5267ac4847cc@n19g2000prf.googlegroups.com> On Jul 16, 12:17?pm, MRAB wrote: > Ray wrote: > > class Test: > > ? def __init__(self): > > ? ? self.value=0 > > ? def change(self, val): > > ? ? self.value=val > > > if __name__=='__main__': > > ? for x in range(10): > > ? ? x=Test() > > ? """ > > ? the question is how do i call x.value outside of that for loop? > > ? something like > > ? print x.value ? > > ? """ > > > thanks for any help. > > Have you tried it? > > Why are you using the same name for the loop variable and the instance > you're creating? yes. I need to create instance. the code above is just a example. on real code, it read a dict, and create the instance from dict.keys() name. that dict is build dynamic from database. From breamoreboy at yahoo.co.uk Fri Jul 16 12:23:34 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 16 Jul 2010 17:23:34 +0100 Subject: improvement for copy.deepcopy : no memo for immutable types In-Reply-To: <4c4065c2$0$11101$c3e8da3@news.astraweb.com> References: <8ebecf3e-4d2b-4a17-92ca-0dc78b62e7cd@q12g2000yqj.googlegroups.com> <4c4065c2$0$11101$c3e8da3@news.astraweb.com> Message-ID: On 16/07/2010 14:59, Steven D'Aprano wrote: [snip] > However doing the minimum isn't likely to be very useful. Python is > maintained by volunteers, and there are more bugs than person-hours > available to fix them. Consequently, unless a bug is serious, high- > profile, or affects a developer personally, it is likely to be ignored. > Sometimes for years. Sad but true. > To give people an idea, here's the weekly Summary of Python tracker Issues on python-dev and timed at 17:07 today. " 2807 open (+44) / 18285 closed (+18) / 21092 total (+62) Open issues with patches: 1144 Average duration of open issues: 703 days. Median duration of open issues: 497 days. Open Issues Breakdown open 2765 (+42) languishing 14 ( +0) pending 27 ( +2) Issues Created Or Reopened (64) " I've spent a lot of time helping out in the last few weeks on the issue tracker. The oldest open issue I've come across was dated 2001, and there could be older. Unless more volunteers come forward, particularly to do patch reviews or similar, the situation as I see it can only get worse. Kindest regards. Mark Lawrence. From post at andre-bell.de Fri Jul 16 12:37:00 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Fri, 16 Jul 2010 18:37:00 +0200 Subject: create dynamic instance In-Reply-To: References: Message-ID: <4C408AAC.7090009@andre-bell.de> On 07/16/2010 06:01 PM, Ray wrote: > if __name__=='__main__': > for x in range(10): > x=Test() > """ > the question is how do i call x.value outside of that for loop? > something like > print x.value ? > """ You would have to keep references to your Test objects (untested code): if __name__ == '__main__': test_objects = [] for x in range(10): test_objects[x] = Test() print test_objects[0].value ... You may want to rewrite this as a list comprehension if __name__ == '__main__': test_objects = [Test() for i in range(10)] print test_objects[0].value Andre From solipsis at pitrou.net Fri Jul 16 12:40:28 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 16 Jul 2010 18:40:28 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: <20100716184028.79874a61@pitrou.net> On Fri, 16 Jul 2010 17:29:44 +0200 Daniel Fetchinson wrote: > >>>> I'm pleased to announce the release of inflect.py v0.1.8, a module that > >>>> correctly generates: > >>>> > >>>> * the plural of singular nouns and verbs > >>>> * the singular of plural nouns > >>>> * ordinals > >>>> * indefinite articles > >>>> * present participles > >>>> * and converts numbers to words > >>> > >>> Which languages does it support? If the answer is what I expect it is, > >> > >> It is. Most of the time, when people forget to say what they are talking > >> about, assuming that they are either US-Americans or Windows users will > >> hit > >> the nail on the head. > > > > And most of the time, when people are bitching about US-Americans, > > assuming that they are Europeans will hit the nail on the head :) > > In this case, I actually should modify the above to: when people are > bitching about an English speaker they don't like for some reason and > they automatically think that said person must be US-American when in > fact he/she is Australian (or British or South African or something > else), assuming that they are Europeans will hit the nail on the head > :) That's why we'd rather bitch about Anglo-Saxons instead. Regards Antoine. From thomas at jollans.com Fri Jul 16 12:45:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 18:45:03 +0200 Subject: Possible to include \n chars in doctest code samples or output? In-Reply-To: <1279258000.23856.1385149339@webmail.messagingengine.com> References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <1279258000.23856.1385149339@webmail.messagingengine.com> Message-ID: <4C408C8F.5010505@jollans.com> On 07/16/2010 07:26 AM, python at bdurham.com wrote: > Thomas, > >> Recall that doctest doesn't parse the code, it extracts the docstrings. And docstrings are just strings, and are parsed like strings. > > I understand what you're saying, but I'm struggling with how to > represent the following strings in doctest code and doctest results. No > matter what combination of backslashes or raw strings I use, I am unable > to find a way to code the following. > >>>> encode( '", \, \t, \n' ) > '\", \\, \\t, \\n' Does either of these docstrings work: def encode(s): """description >>> encode( '", \\, \\t, \\n' ) '\\", \\\\, \\\\t, \\\\n' """ ... def encode(s): r"""description >>> encode( '", \, \t, \n' ) '\", \\, \\t, \\n' """ ... From thomas at jollans.com Fri Jul 16 12:51:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 18:51:05 +0200 Subject: Python 3 and setuptools In-Reply-To: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> References: <53680cf7-aec8-41ae-8f67-ac634f28dd67@k1g2000prl.googlegroups.com> Message-ID: <4C408DF9.9060900@jollans.com> On 07/16/2010 06:10 PM, fuglyducky wrote: > I am trying to install a library that requires setuptools. > Unfortunately, setuptools isn't available for Python 3 yet. Is this > correct? Any idea when it may be available OR if there is a different > tool/method of getting setuptools installed for Python 3? It is available. It is, in fact, in the Debian archives, which is where I got it from, thought this probably doesn't help you directly. http://packages.debian.org/sid/python3-setuptools Closer inspection reveals that it's actually a fork. There you go: http://pypi.python.org/pypi/distribute Cheers - Thomas From jason at powerpull.net Fri Jul 16 12:58:08 2010 From: jason at powerpull.net (Jason Friedman) Date: Fri, 16 Jul 2010 16:58:08 +0000 Subject: rstrip() Message-ID: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "x.vsd-dir".rstrip("-dir") 'x.vs' I expected 'x.vsd' as a return value. From usenot at geekmail.INVALID Fri Jul 16 12:59:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 16 Jul 2010 18:59:40 +0200 Subject: [ANN] inflect.py: generate plurals, ordinals, numbers to words... References: <299733.71288.qm@web53601.mail.re2.yahoo.com> <4C3F3A1C.5040208@jollans.com> Message-ID: <20100716185940.23994a28@geekmail.INVALID> On Fri, 16 Jul 2010 17:26:05 +0200 Daniel Fetchinson wrote: > >>> I'm pleased to announce the release of inflect.py v0.1.8, a > >>> module that correctly generates: > >>> > >>> * the plural of singular nouns and verbs > >>> * the singular of plural nouns > >>> * ordinals > >>> * indefinite articles > >>> * present participles > >>> * and converts numbers to words > >> > >> Which languages does it support? If the answer is what I expect it > >> is, > > > > It is. Most of the time, when people forget to say what they are > > talking about, assuming that they are either US-Americans or > > Windows users will hit the nail on the head. > > And most of the time, when people are bitching about US-Americans, > assuming that they are Europeans will hit the nail on the head :) > I think Arabs may have shaken up that guess a bit, huh? OK, less snark, more Python. Sorry. ;) /W -- INVALID? DE! From pengyu.ut at gmail.com Fri Jul 16 13:01:11 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 12:01:11 -0500 Subject: Is '[' a function or an operator or an language feature? Message-ID: I mean to get the man page for '[' like in the following code. x=[1,2,3] But help('[') doesn't seem to give the above usage. ########### Mutable Sequence Types ********************** List objects support additional operations that allow in-place modification of the object. Other mutable sequence types (when added to the language) should also support these operations. Strings and tuples are immutable sequence types: such objects cannot be modified once created. The following operations are defined on mutable sequence types (where *x* is an arbitrary object): ... ########## I then checked help('LISTLITERALS'), which gives some description that is available from the language reference. So '[' in "x=[1,2,3]" is considered as a language feature rather than a function or an operator? ############ List displays ************* A list display is a possibly empty series of expressions enclosed in square brackets: list_display ::= "[" [expression_list | list_comprehension] "]" list_comprehension ::= expression list_for list_for ::= "for" target_list "in" old_expression_list [list_iter] old_expression_list ::= old_expression [("," old_expression)+ [","]] list_iter ::= list_for | list_if list_if ::= "if" old_expression [list_iter] ..... ########### -- Regards, Peng From john.hammink at gmail.com Fri Jul 16 13:06:23 2010 From: john.hammink at gmail.com (John Hammink) Date: Fri, 16 Jul 2010 10:06:23 -0700 (PDT) Subject: Python Imaging Library available for Python 3.1 ? Fractals References: Message-ID: <29ac0e3e-6a06-4f41-bdf7-15cb01d34444@r27g2000yqb.googlegroups.com> On Jun 6, 12:40?am, pdlemper@earthlink.net wrote: > On the site > ? ?http://code.activestate.com/recipes/langs/python/ > there are several scripts for fractals. ?See page five. > These begin > ? ? ? ? ? ? ? ? ? ? ? ? from PIL import Image > > This fails in my python 3.1.2 > > Google reveals PIL is Python Imaging Library from > pythonware.com > According to their website PIL is not available beyond 2.6 ?: ( > > Do I need a full GUI like tkinter to image a fractal ( on my > python 3.1.2 ) ?? ? ?Is there any simpler option ? > Thanks, ? ? ? ? ? ? ? Dave WB3DWE I'm a beginner pretty much, but I've just got Shai Vaingast's Newton- Raphson fractal working. I'm using python 2.6.5. from PIL import Image from cmath import * ... I don't need any windowing kit or anything. Maybe you can downgrade your python? or set up an older environment for it. From anand.shashwat at gmail.com Fri Jul 16 13:12:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 16 Jul 2010 22:42:46 +0530 Subject: rstrip() In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 10:28 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. > rstrip([chars]) The chars are stripped from right. Here it's ['-', 'd','i','r'] , hence these 4 characters will be stripped from right, so you are left with 'x.vs' -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Fri Jul 16 13:14:19 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 19:14:19 +0200 Subject: rstrip() In-Reply-To: References: Message-ID: <4C40936B.4000701@jollans.com> On 07/16/2010 06:58 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. >>> "x-vsd-dir".rstrip("-dir") 'x-vs' >>> "x-vsd-dir".rstrip("123id-r456") 'x-vs' >>> "x-vsd-dir".rstrip("-di") 'x-vsd-dir' >>> "fooabc".rstrip("bca") 'foo' >>> http://docs.python.org/py3k/library/stdtypes.html#str.rstrip :: """ The chars argument is not a suffix; rather, all combinations of its values are stripped: """ From soren.skou.nielsen at gmail.com Fri Jul 16 13:17:01 2010 From: soren.skou.nielsen at gmail.com (Soren) Date: Fri, 16 Jul 2010 10:17:01 -0700 (PDT) Subject: py2app with weave fails Message-ID: <4f6430e5-31ea-450d-a2b9-56442a7141fa@k19g2000yqc.googlegroups.com> Hi, I'm trying to create a standalone app using py2app, but it seems no matter what I do I get this error: Traceback (most recent call last): File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/__boot__.py", line 158, in _run('RAW.py') File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/__boot__.py", line 134, in _run execfile(path, globals(), globals()) File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/RAW.py", line 42, in from masking import CircleMask, RectangleMask, PolygonMask File "masking.pyc", line 34, in File "fileIO.pyc", line 29, in File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/__init__.py", line 13, in from inline_tools import inline File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/inline_tools.py", line 5, in import ext_tools File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/ext_tools.py", line 6, in import build_tools File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/build_tools.py", line 28, in import platform_info File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/scipy/weave/platform_info.py", line 15, in from numpy.distutils.core import setup File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/numpy/distutils/core.py", line 25, in from numpy.distutils.command import config, config_compiler, \ File "/Users/soren/Documents/workspace/bioxtasraw/dist/RAW.app/ Contents/Resources/lib/python2.6/numpy/distutils/command/ build_ext.py", line 9, in from distutils.command.build_ext import build_ext as old_build_ext File "distutils/command/build_ext.pyc", line 13, in ImportError: cannot import name USER_BASE 2010-07-16 13:10:07.542 RAW[24832] RAW Error 2010-07-16 13:10:07.544 RAW[24832] RAW Error An unexpected error has occurred during execution of the main script Does anyone have an idea on how to fix this?? Thanks, Soren From kwatford+python at gmail.com Fri Jul 16 13:20:01 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Fri, 16 Jul 2010 13:20:01 -0400 Subject: rstrip() In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 12:58 PM, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. > -- > http://mail.python.org/mailman/listinfo/python-list > rstrip strips a given set of characters, not a specific string. '-dir' contains d, so the trailing d is also stripped. From thomas at jollans.com Fri Jul 16 13:20:13 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 19:20:13 +0200 Subject: Code generator and visitor pattern In-Reply-To: <4C401FC7.3010203@sequans.com> References: <4b6c0975-b3ce-4398-88b7-e6e05355c741@x21g2000yqa.googlegroups.com> <4C401FC7.3010203@sequans.com> Message-ID: <4C4094CD.6040905@jollans.com> On 07/16/2010 11:00 AM, Jean-Michel Pichavant wrote: > Karsten Wutzke wrote: >>> Yes, typo, I meant strictly. >>> >>> >> >> Damn, I mean strongly. At least not for identifying which methods to >> call depending on the type/s. >> >> Karsten >> > Stringly is the perfect combination of strictly and strongly. Nice one :) stringly typed sounds like "everything is a string" - doesn't Tcl do that ? ^^ From python at mrabarnett.plus.com Fri Jul 16 13:27:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 18:27:28 +0100 Subject: rstrip() In-Reply-To: References: Message-ID: <4C409680.8000503@mrabarnett.plus.com> Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. .strip, .lstrip and .rstrip treat their argument like a set of characters and remove any of those characters from the end(s) of the string. In your example it's removing any "-", "d", "i" or "r" from the right-hand end of "x.vsd-dir", leaving "x.vs", like this: result = "x.vsd-dir" characters = "-dir" while result and result[-1] in characters: result = result[ : -1] From bartc at freeuk.com Fri Jul 16 13:30:38 2010 From: bartc at freeuk.com (bart.c) Date: Fri, 16 Jul 2010 18:30:38 +0100 Subject: Splitting numeric litterals In-Reply-To: <4c4069de$0$11101$c3e8da3@news.astraweb.com> References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4c4069de$0$11101$c3e8da3 at news.astraweb.com... > On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > Not only that, but it only takes 73 digits to write out the total number > of particles in the entire universe: > > 1000000000000000000000000000000000000000000000000000000000000000000000000 > > or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all > the way up to 1e87.) > So for anything related to counting or labelling > actual, physical objects, you will be dealing with smaller numbers than > that. E.g. the number of grains of sand on the earth has been estimated > (very roughly) as a mere 1000000000000000000000000, or 25 digits. Big integers tend to be used for playing around with mathematical ideas, and they have to be exact. So if you wanted to hardcode 1000! for some reason, you'd need some 2568 digits which is a little awkward on one line. > It always makes me laugh when I receive an invoice from some company, and > the account number or invoice number is (e.g.) 1000000023456789. Who do > they think they're fooling? I used to do that. Giving someone an invoice number, or product serial number, 000001 doesn't exactly give the impression of a thriving business. -- Bartc From nagle at animats.com Fri Jul 16 13:40:27 2010 From: nagle at animats.com (John Nagle) Date: Fri, 16 Jul 2010 10:40:27 -0700 Subject: Why doesn't python's list append() method return the list itself? In-Reply-To: <8a302tF2qdU1@mid.individual.net> References: <4c3a60a8$0$28647$c3e8da3@news.astraweb.com> <4c3b7102$0$1587$742ec2ed@news.sonic.net> <8a302tF2qdU1@mid.individual.net> Message-ID: <4c409999$0$1633$742ec2ed@news.sonic.net> On 7/13/2010 4:22 AM, Gregory Ewing wrote: > John Nagle wrote: >> Arguably, if a function just does a "return", >> it should be an error to try to use its return value. > > It's been suggested at least once before that the > default return value for a function should be some > special value that raises an exception if you try > to do anything with it except throw it away. Treating that case as an error would be consistent with the way attribute access works in Python. In Python, attempting to access a nonexistent attribute raises an exception. In Javascript, that returns a null. Javascript makes no distinction between "null" and "nonexistent", but Python does. It's un-Pythonic and inconsistent that functions which return nothing are considered to return a None object. John Nagle From robert.kern at gmail.com Fri Jul 16 13:41:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Jul 2010 12:41:48 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/10 12:01 PM, Peng Yu wrote: > I then checked help('LISTLITERALS'), which gives some description that > is available from the language reference. So '[' in "x=[1,2,3]" is > considered as a language feature rather than a function or an > operator? Yes. It is part of the list literal syntax of the Python language. -- 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 gregory.j.baker at gmail.com Fri Jul 16 13:55:14 2010 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Fri, 16 Jul 2010 10:55:14 -0700 (PDT) Subject: rstrip() References: Message-ID: <50ce9040-aecd-4030-b69e-5aab682c02af@x20g2000pro.googlegroups.com> On Jul 16, 10:58?am, Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>> "x.vsd-dir".rstrip("-dir") > > 'x.vs' > > I expected 'x.vsd' as a return value. One way to achieve the desired result: 'x.vsd-dir'.split('-')[0] From robert.kern at gmail.com Fri Jul 16 14:28:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Jul 2010 13:28:49 -0500 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: On 7/16/10 12:30 PM, bart.c wrote: > > "Steven D'Aprano" wrote in message > news:4c4069de$0$11101$c3e8da3 at news.astraweb.com... >> On Fri, 16 Jul 2010 14:49:21 +0100, MRAB wrote: > >> Not only that, but it only takes 73 digits to write out the total number >> of particles in the entire universe: >> >> 1000000000000000000000000000000000000000000000000000000000000000000000000 >> >> or 1e72. (Of course that's the lower-bound, estimates range from 1e72 all >> the way up to 1e87.) >> So for anything related to counting or labelling >> actual, physical objects, you will be dealing with smaller numbers than >> that. E.g. the number of grains of sand on the earth has been estimated >> (very roughly) as a mere 1000000000000000000000000, or 25 digits. > > Big integers tend to be used for playing around with mathematical ideas, and > they have to be exact. So if you wanted to hardcode 1000! for some reason, you'd > need some 2568 digits which is a little awkward on one line. This happens too rarely to justify adding line-spanning integer literals to the language's syntax. -- 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 msandeep167 at gmail.com Fri Jul 16 14:59:56 2010 From: msandeep167 at gmail.com (ssssssssssssss) Date: Fri, 16 Jul 2010 11:59:56 -0700 (PDT) Subject: ( . ) ( . ) ( . ) ( . ) ( . ) Nude desi videos and pictures ( . ) ( . ) ( . ) ( . ) ( . ) ( . ) Message-ID: <883048a2-51d1-4965-b5b3-d9088f6a13fa@y12g2000prb.googlegroups.com> Click here for nude desi videos >>>>>>>>>>>>>>>>>>>>>>> http://ukpinkgirls.co.cc/ http://uk-worldwebhosting.co.cc/ From pengyu.ut at gmail.com Fri Jul 16 15:13:21 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 14:13:21 -0500 Subject: How to list all the python help topics that are capitalized? Message-ID: Hi, I see that there are help topics that are capitalized, which I think in general are related with languages syntax. I want to see the complete list of such help topics. Would you please let me know if there is a command to do so? >>> help('SUBSCRIPTS') Related help topics: SEQUENCEMETHODS1 >>> help('[') Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> help('LISTLITERALS') Related help topics: LISTS, LITERALS -- Regards, Peng From spheba at gmail.com Fri Jul 16 15:17:42 2010 From: spheba at gmail.com (hena) Date: Fri, 16 Jul 2010 12:17:42 -0700 (PDT) Subject: +++++++++ 18 + teen girls sex clips and pics +++++++++++ Message-ID: Click here to watch nude desi actress videos, Wallpapers, and more >>>>>>>>>>>>> http://ukpinkgirls.co.cc/ http://uk-worldwebhosting.co.cc/ From sunckell at gmail.com Fri Jul 16 15:20:16 2010 From: sunckell at gmail.com (Chad Kellerman) Date: Fri, 16 Jul 2010 15:20:16 -0400 Subject: pattern matching with multiple lists Message-ID: Greetings, ???? I have some code that I wrote and know there is a better way to write it.? I wonder if anyone could point me in the right direction on making this 'cleaner'. ???? I have two lists:?? liveHostList = [ app11, app12, web11, web12, host11 ] ??????????????????????????????????? stageHostList????? = [? web21, web22, host21, app21, app22 ] ???? I need to pair the elements in the list such that: ??? app11? pairs with app21 ??? app12 pairs with app22 ??? web11 pairs with web21 ??? web12 pairs with web22 ??? host11pairs with host21 ??? each time I get the list I don't know the order, and the lists will grow over time.? (hosts will be added in pairs.? app13 to liveHostList and app23 to stageHostList, etc) Anyways this is what I have.? I think it can be written better with map, but not sure.? Any help would be appreciated. import re for liveHost in liveHostlist: ??? nameList = list(liveHost) ??? clone??? = nameList[-1] ??? di?????? = nameList[-2] ??? generic? = liveHost[:-2] ??? for stageHost in stageHostList: ??? ??? if re.match( generic + '.' + clone, stageHost ): ??? ??? ??? print "Got a pair: " + stageHost + liveHost Thanks again for any suggestions, Chad -- A grasshopper walks into a bar and the bartender says "Hey, we have a drink named after you." And the grasshopper says "Really, You have a drink named Murray?" From thomas at jollans.com Fri Jul 16 15:44:04 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 21:44:04 +0200 Subject: Identify the Color of an Image In-Reply-To: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> References: <9ef8052b-47e8-4422-8476-019e3a5e0e6c@t13g2000prf.googlegroups.com> Message-ID: <4C40B684.9020600@jollans.com> On 07/15/2010 09:13 AM, Monyl wrote: >> Please be clearer about what you want. >> >> 1. Animagedoes not "have" acolor, although each pixel in animage >> does have acolor. >> >> 2. Text in a web page does not (necessarily) have a font, although the >> display engine will use a font of its choice to render text. And my >> browser will probably use a different font than yours. > > Hi Gary Herron, > > 1.If I am going to click on a particular image. I will have click > using the co-ordinates of an Image. Can we find the color of the pixel > which lies in that particular co-ordinate where I click. You haven't even told us which platform you're talking about. This is a highly platform specific problem. > > 2.I just want to retrive the attributes of the text as it appears on > the browser. Can I get the font value depending on the browsers. If you want to know which font a browser is using to render something, you'll have to, essentially, ask the browser! I doubt this is something any browser would support, as it's hard to imagine *any* practical use case. Should be possible by extending firefox. (or any open source browser) > > Hope you understand my problem. Not really. From python at mrabarnett.plus.com Fri Jul 16 16:10:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:10:03 +0100 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: Message-ID: <4C40BC9B.2010500@mrabarnett.plus.com> Peng Yu wrote: > Hi, > > I see that there are help topics that are capitalized, which I think > in general are related with languages syntax. I want to see the > complete list of such help topics. Would you please let me know if > there is a command to do so? > >>>> help('SUBSCRIPTS') > > Related help topics: SEQUENCEMETHODS1 > >>>> help('[') > > Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS > >>>> help('LISTLITERALS') > > Related help topics: LISTS, LITERALS > Try: >>> help("topics") From pengyu.ut at gmail.com Fri Jul 16 16:21:53 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 15:21:53 -0500 Subject: How to list all the python help topics that are capitalized? In-Reply-To: <4C40BC9B.2010500@mrabarnett.plus.com> References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: > Peng Yu wrote: >> >> Hi, >> >> I see that there are help topics that are capitalized, which I think >> in general are related with languages syntax. I want to see the >> complete list of such help topics. Would you please let me know if >> there is a command to do so? >> >>>>> help('SUBSCRIPTS') >> >> Related help topics: SEQUENCEMETHODS1 >> >>>>> help('[') >> >> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >> >>>>> help('LISTLITERALS') >> >> Related help topics: LISTS, LITERALS >> > Try: > >>>> help("topics") Would you please let me know where this is documented? -- Regards, Peng From thomas at jollans.com Fri Jul 16 16:25:14 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 16 Jul 2010 22:25:14 +0200 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: <4C40C02A.1080203@jollans.com> On 07/16/2010 10:21 PM, Peng Yu wrote: > On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: >> Peng Yu wrote: >>> >>> Hi, >>> >>> I see that there are help topics that are capitalized, which I think >>> in general are related with languages syntax. I want to see the >>> complete list of such help topics. Would you please let me know if >>> there is a command to do so? >>> >>>>>> help('SUBSCRIPTS') >>> >>> Related help topics: SEQUENCEMETHODS1 >>> >>>>>> help('[') >>> >>> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> >>>>>> help('LISTLITERALS') >>> >>> Related help topics: LISTS, LITERALS >>> >> Try: >> >>>>> help("topics") > > Would you please let me know where this is documented? > help('help') From rami.chowdhury at gmail.com Fri Jul 16 16:25:21 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 16 Jul 2010 13:25:21 -0700 Subject: Identify the Color of an Image In-Reply-To: <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> References: <4c3ddf61$0$1613$742ec2ed@news.sonic.net> <671e718e-6602-4fc8-93c6-4aca18390c51@i18g2000pro.googlegroups.com> Message-ID: <201007161325.21534.rami.chowdhury@gmail.com> On Wednesday 14 July 2010 23:56:27 Monyl wrote: > > I will be using a automation tool called Sikuli and select the text or > an Image. It sounds to me like this is a question not about Python, but about Sikuli. I suggest you ask the question at https://answers.launchpad.net/sikuli or on their mailing list at https://lists.csail.mit.edu/mailman/listinfo/sikuli-users . > > My Requirement > --------------- > > I will capture the image manually and scriptify using Sikuli. To find > the captured image in the web page. Once it finds the image I need to > collect the information of the image like, > > Co-ordinates of the image, height and width, color and pixel rate of > the image. > > If I want to search a particular text in a webpage. I need to find the > font name, type, color and size of the text. > > Note :- We can open the web page in any browser. but I should be able > to capture the attributes of the image/Text displayed. ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law +1-408-597-7068 / +44-7875-841-046 / +88-01819-245544 From python at mrabarnett.plus.com Fri Jul 16 16:29:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:29:16 +0100 Subject: pattern matching with multiple lists In-Reply-To: References: Message-ID: <4C40C11C.4080802@mrabarnett.plus.com> Chad Kellerman wrote: > Greetings, > I have some code that I wrote and know there is a better way to > write it. I wonder if anyone could point me in the right direction > on making this 'cleaner'. > > I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ] > stageHostList = [ web21, > web22, host21, app21, app22 ] > > I need to pair the elements in the list such that: > app11 pairs with app21 > app12 pairs with app22 > web11 pairs with web21 > web12 pairs with web22 > host11pairs with host21 > > each time I get the list I don't know the order, and the lists > will grow over time. (hosts will be added in pairs. app13 to > liveHostList and app23 to stageHostList, etc) > > > Anyways this is what I have. I think it can be written better with > map, but not sure. Any help would be appreciated. > > import re > for liveHost in liveHostlist: > > nameList = list(liveHost) > clone = nameList[-1] > di = nameList[-2] > generic = liveHost[:-2] > > for stageHost in stageHostList: > if re.match( generic + '.' + clone, stageHost ): > print "Got a pair: " + stageHost + liveHost > > Thanks again for any suggestions, > Chad > So you recognise a pair by them having the same 'key', which is: name[ : -2] + name[-1 : ] Therefore you can put one of the lists into a dict and look up the name by its key: liveHostDict = dict((liveHost[ : -2] + liveHost[-1 : ], liveHost) for liveHost in liveHostList) for stageHost in stageHostList: key = stageHost[ : -2] + stageHost[-1 : ] liveHost = liveHostDict[key] print "Got a pair: %s %s" % (stageHost, liveHost) From python at mrabarnett.plus.com Fri Jul 16 16:33:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Jul 2010 21:33:30 +0100 Subject: How to list all the python help topics that are capitalized? In-Reply-To: References: <4C40BC9B.2010500@mrabarnett.plus.com> Message-ID: <4C40C21A.30507@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Jul 16, 2010 at 3:10 PM, MRAB wrote: >> Peng Yu wrote: >>> Hi, >>> >>> I see that there are help topics that are capitalized, which I think >>> in general are related with languages syntax. I want to see the >>> complete list of such help topics. Would you please let me know if >>> there is a command to do so? >>> >>>>>> help('SUBSCRIPTS') >>> Related help topics: SEQUENCEMETHODS1 >>> >>>>>> help('[') >>> Related help topics: LISTLITERALS, SUBSCRIPTS, SLICINGS >>> >>>>>> help('LISTLITERALS') >>> Related help topics: LISTS, LITERALS >>> >> Try: >> >>>>> help("topics") > > Would you please let me know where this is documented? > >>> help() From alf.p.steinbach+usenet at gmail.com Fri Jul 16 17:14:41 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Fri, 16 Jul 2010 23:14:41 +0200 Subject: Nested loop not working In-Reply-To: References: Message-ID: * Johann Spies, on 16.07.2010 16:34: > I am overlooking something stupid. > > I have two files: one with keywords and another with data (one record per line). > > I want to determine for each keyword which lines in the second file > contains that keyword. > > The following code is not working. It loops through the second file > but only uses the first keyword in the first file. > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > import re > > keywords = open("sleutelwoorde",'r') > data = open("sarua_marine_sleutelwoorde.csv",'r') > > remove_quotes = re.compile('"') > > > for sw in keywords: > for r in data: > swc = remove_quotes('',sw)[:-1] > if swc in r.lower(): > print swc + ' ---> ' + r > print swc > > What am I missing? For the inner loop, 'data' is an object that represents a file and keeps track of a current read position of the file. The first execution of the loop moves that read position all the way to the End Of the File, EOF. The second time this loop is attempted, which would be for the second keyword, the 'data' object's read position is already at end of file, and thus nothing's done. One way to just make it work is to open and close the data file within the outer loop. Actually with CPython it's automatically closed, as far as I can recall, so you only need to reopen it, but this (if true) is less than completely documented. This way is inefficient for small data set, but works. In order to get a better handle on the general problem -- not the Python technicalitities -- google up "KWIC", KeyWord In Context. It's a common exercise problem given to first or second-year students. So I think there should be an abundance of answers and discussion, although I haven't googled. Cheers & hth., - Alf -- blog at From python.list at tim.thechases.com Fri Jul 16 17:58:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 16 Jul 2010 16:58:18 -0500 Subject: pattern matching with multiple lists In-Reply-To: References: Message-ID: <4C40D5FA.1010403@tim.thechases.com> On 07/16/2010 02:20 PM, Chad Kellerman wrote: > Greetings, > I have some code that I wrote and know there is a better way to > write it. I wonder if anyone could point me in the right direction > on making this 'cleaner'. > > I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ] > stageHostList = [ web21, > web22, host21, app21, app22 ] > > I need to pair the elements in the list such that: > app11 pairs with app21 > app12 pairs with app22 > web11 pairs with web21 > web12 pairs with web22 > host11pairs with host21 While I like MRAB's solution even better than mine[1], you can also use: liveHostList = ["app11", "app12", "web11", "web12", "host11"] stageHostList = ["web21", "web22", "host21", "app21", "app22"] def bits(s): return (s[:-2],s[-1]) for live, stage in zip( sorted(liveHostList, key=bits), sorted(stageHostList, key=bits), ): print "Match: ", live, stage -tkc [1] His solution is O(N), making one pass through each list, with O(1) lookups into the created dict during the 2nd loop, while mine is likely overwhelmed by the cost of the sorts...usually O(N log N) for most reasonable sorts. However, this doesn't likely matter much until your list-sizes are fairly large. From tjreedy at udel.edu Fri Jul 16 18:42:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 18:42:31 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/2010 1:01 PM, Peng Yu wrote: > I mean to get the man page for '[' like in the following code. > > x=[1,2,3] You might find my Python symbol glossary useful. https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html From db3l.net at gmail.com Fri Jul 16 18:47:11 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 16 Jul 2010 18:47:11 -0400 Subject: About problems that I have with learning wxPython in Macintosh References: <2e03c884-2d53-4529-a099-a4b4b48cfe49@d37g2000yqm.googlegroups.com> Message-ID: "ata.jaf" writes: > import wx > > class MainWindow(wx.Frame) : > def __init__(self, parent, title) : > wx.Frame.__init__(self, parent, title=title, size=(200, 100)) > self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) > self.CreateStatusBar() > > filemenu = wx.Menu() > > filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this > program.') > filemenu.AppendSeparator() > filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program') > > menuBar = wx.MenuBar() > menuBar.Append(filemenu, '&File') > self.SetMenuBar(menuBar) > self.Show(True) > > app = wx.App(False) > frame = MainWindow(None, 'Sample editor') > app.MainLoop() > > The menus doesn't appear in the product. > Can anyone help me to find a tutorial that is for using wxPython on a > Mac? I think the menus are actually working as designed, and they are present, but just not perhaps what or where you expected. That's because some of the standard IDs (e.g., wx.ID_ABOUT) and some names (e.g., "E&xit") are adjusted under OSX to conform to that platform's menu standard. This is actually to your benefit, as you can use the same wxPython code to get menus on each platform to which users on that platform will be familiar. So for example, ID_ABOUT and ID_EXIT are always under the Application menu (and E&xit becomes &Quit) which is where Mac users expect them to be. Mac users would be quite confused if your application exited with Command-x rather than Command-Q. See http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X for a little more information. There are also a series of methods on wxApp if you want finer control over this (such as SetMacAboutMenuItemId, SetMacExitMenuItemId, SetMacPreferencesMenuItemId) but using the standard ID_* names does it automatically. If you're looking for your own specific menus, I'd just switch away from the standard ids and names. For example, if you switched the wx.ID_* in the above to -1, you'd see them show up under the File menu rather than relocated to the Application menu. Although "E&xit" would still get replaced with "&Quit". But if you are in fact setting up a menu for an application exit, I'd let wxPython do what it's doing, as your application will appear "normal" to users on the Mac. I'd also suggest moving over to the wxPython mailing list for followup questions as there are more folks there familiar with wxPython. -- David From python at bdurham.com Fri Jul 16 18:47:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 18:47:48 -0400 Subject: os.times values under Windows Message-ID: <1279320468.5600.1385279675@webmail.messagingengine.com> Python 2.6 under Windows: are the two non-zero values returned by this function of any practical use? The documentation [1] is vague and points to the Windows Platform API which I'm not sure maps 1:1 to the help description. In looking at the values returned on my system (Windows 7, 64-bit), I wonder if the documentation is correct because it looks like the values for user and system time might be reversed? >>> import os >>> os.times() (2465.0030011999997, 132.4292489, 0.0, 0.0, 0.0) >>> help(os.times) Help on built-in function times in module nt: times(...) times() -> (utime, stime, cutime, cstime, elapsed_time) Return a tuple of floating point numbers indicating process times. Thanks, Malcolm [1] http://docs.python.org/library/os.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jul 16 18:51:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 18:51:54 -0400 Subject: Splitting numeric litterals In-Reply-To: References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: > On 7/16/10 12:30 PM, bart.c wrote: >> they have to be exact. So if you wanted to hardcode 1000! for some >> reason, you'd >> need some 2568 digits which is a little awkward on one line. No, only 20 digits >>> math.factorial(1000) 402387260077093773543702433923003985719374 ... Most big ints people want to work with can be encoded similarly. -- Terry Jan Reedy From candide at free.invalid Fri Jul 16 19:34:48 2010 From: candide at free.invalid (candide) Date: Sat, 17 Jul 2010 01:34:48 +0200 Subject: Subsets of Python implemented in Python Message-ID: <4c40ec99$0$8103$426a34cc@news.free.fr> I don't understand why some parts of the Python language (or the Python standard library too) are implemented in C while some other parts are implemented in the Python language itself. For instance, lists and dictionnaries are implemented in C but sets are not. Wouldn't be better to implement all in C (for efficiency reasons for example) ? From chardster at gmail.com Fri Jul 16 19:54:05 2010 From: chardster at gmail.com (Richard Thomas) Date: Fri, 16 Jul 2010 16:54:05 -0700 (PDT) Subject: Subsets of Python implemented in Python References: <4c40ec99$0$8103$426a34cc@news.free.fr> Message-ID: On Jul 17, 12:34?am, candide wrote: > I don't understand why some parts of the Python language (or the Python > standard library too) are implemented in C while some other parts are > implemented in the Python language itself. For instance, lists and > dictionnaries are implemented in C but sets are not. > > Wouldn't be better to implement all in C (for efficiency reasons for > example) ? CPython's sets are implemented in C. Old versions of Python implemented sets in the 'set' module which was written in Python but that has been deprecated and removed. A lot of the standard library is implemented in Python because it makes it more easily portable to non- CPython implementations. Chard. From hujia06 at gmail.com Fri Jul 16 20:52:23 2010 From: hujia06 at gmail.com (Jia Hu) Date: Fri, 16 Jul 2010 20:52:23 -0400 Subject: timing Message-ID: Hello: If I want to calculate the runtime of a section of a program. How can I do it? Thank you, Jia -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 20:57:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 00:57:54 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c410011$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 18:30:38 +0100, bart.c wrote: >> It always makes me laugh when I receive an invoice from some company, >> and the account number or invoice number is (e.g.) 1000000023456789. >> Who do they think they're fooling? > > I used to do that. Giving someone an invoice number, or product serial > number, 000001 doesn't exactly give the impression of a thriving > business. Sure, and there's nothing wrong with (say) 1000234 as your starting figure. I know people who put the year as the starting four digits: 201012345, say. But when you're a one-man company, is anyone going to think that you've genuinely put out 1000000000023456789 invoices to date? Even if you're a giant multinational corporation, such a number is just ridiculous, and it is user-hostile, especially when dealing with the robot interface to their help-desk or paying bills by phone. "Enter your invoice number followed by the hash-key." 1 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 0 *beep* 2 *beep* 3 *beep* 4 *beep* 5 *beep* 6 *beep* ... 7 *beep* 8 * beep* 9 *beep* # *beep* "Sorry, that invoice number is incorrect. Please try again." -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 21:02:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 01:02:51 GMT Subject: Splitting numeric litterals References: <4c3e64ba$0$31001$426a74cc@news.free.fr> <4c4069de$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4c41013b$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 15:41:45 +0100, MRAB wrote: >> It always makes me laugh when I receive an invoice from some company, >> and the account number or invoice number is (e.g.) 1000000023456789. >> Who do they think they're fooling? >> > It's possible that they're splitting it into fields. Anything is possible. It's possible that they're encoding secret instructions to their army of sleeper agents in the invoice numbers too, but how likely is it? Good accounting practice is to treat invoice numbers as a simple unique numeric key. Every accounting software I've used has started the invoices at some value N, and returned N+1, N+2, N+3, ... with the starting value N user-configurable. But even if some software flies in the face of all accounting principles, good database design, and common sense, by overloading invoice numbers to include "fields" (of what?), what is the likelihood that my fields just happen to be virtually all zero? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 16 21:06:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 01:06:27 GMT Subject: Subsets of Python implemented in Python References: <4c40ec99$0$8103$426a34cc@news.free.fr> Message-ID: <4c410212$0$11101$c3e8da3@news.astraweb.com> On Sat, 17 Jul 2010 01:34:48 +0200, candide wrote: > I don't understand why some parts of the Python language (or the Python > standard library too) are implemented in C while some other parts are > implemented in the Python language itself. For instance, lists and > dictionnaries are implemented in C but sets are not. > > Wouldn't be better to implement all in C (for efficiency reasons for > example) ? Efficiency for who? The person writing the code? The CPU? There's currently a thread about the difficulty of finding volunteers willing *and able* to fix bugs in Python. If all of the Python code base was written in C, this would be a thousand times worse. There are many Python developers who can patch Python code, but not even read C code, let alone write it effectively. Most of the Python standard library is written in Python because (1) it's easier (2) it's fast enough (3) it allows experimentation and rapid prototyping E.g. the sets module was written in Python to start with, then replaced with a C built-in once it had proven itself. In other words, the Python standard library is written in Python for the exact same reasons that *any* software project might be written in Python. -- Steven From pengyu.ut at gmail.com Fri Jul 16 21:42:48 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 20:42:48 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: > On 7/16/2010 1:01 PM, Peng Yu wrote: >> >> I mean to get the man page for '[' like in the following code. >> >> x=[1,2,3] > > You might find my Python symbol glossary useful. > https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html This is for Python 3. Is there one for Python 2.x? -- Regards, Peng From clp2 at rebertia.com Fri Jul 16 21:58:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Jul 2010 18:58:13 -0700 Subject: timing In-Reply-To: References: Message-ID: On Fri, Jul 16, 2010 at 5:52 PM, Jia Hu wrote: > Hello: > > If I want to calculate the runtime of a section of a program. How can I do > it? Taking you extremely literally: from time import time start = time() run_section_here() end = time() runtime = end-start Assuming you're doing this in order to optimize: http://docs.python.org/library/profile.html Or in particularly simple cases: http://docs.python.org/library/timeit.html Cheers, Chris -- http://blog.rebertia.com From hujia06 at gmail.com Fri Jul 16 22:05:14 2010 From: hujia06 at gmail.com (Jia Hu) Date: Fri, 16 Jul 2010 22:05:14 -0400 Subject: timing In-Reply-To: References: Message-ID: Thank you, it is so straightforward. On Fri, Jul 16, 2010 at 9:58 PM, Chris Rebert wrote: > On Fri, Jul 16, 2010 at 5:52 PM, Jia Hu wrote: > > Hello: > > > > If I want to calculate the runtime of a section of a program. How can I > do > > it? > > Taking you extremely literally: > from time import time > start = time() > run_section_here() > end = time() > runtime = end-start > > Assuming you're doing this in order to optimize: > http://docs.python.org/library/profile.html > Or in particularly simple cases: > http://docs.python.org/library/timeit.html > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Jul 16 22:08:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jul 2010 03:08:40 +0100 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: <4C4110A8.8040406@mrabarnett.plus.com> Peng Yu wrote: > On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >> On 7/16/2010 1:01 PM, Peng Yu wrote: >>> I mean to get the man page for '[' like in the following code. >>> >>> x=[1,2,3] >> You might find my Python symbol glossary useful. >> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html > > This is for Python 3. Is there one for Python 2.x? > Is anyone /still/ using Python 2.x? ;-) From python.list at tim.thechases.com Fri Jul 16 22:23:09 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 16 Jul 2010 21:23:09 -0500 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C4110A8.8040406@mrabarnett.plus.com> References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: <4C41140D.4010001@tim.thechases.com> On 07/16/2010 09:08 PM, MRAB wrote: > Peng Yu wrote: >>> You might find my Python symbol glossary useful. >>> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html >> >> This is for Python 3. Is there one for Python 2.x? >> > Is anyone /still/ using Python 2.x? ;-) 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, week-in week-out, for sixpence a week, and when we got home our Dad would thrash us to sleep wi' his belt... -tkc From pengyu.ut at gmail.com Fri Jul 16 22:36:25 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Fri, 16 Jul 2010 21:36:25 -0500 Subject: Where is a module usually installed? Message-ID: My Python is installed in the following location. ~/utility/linux/opt/Python-2.6.5/ I then installed SCons (http://www.scons.org/) using the command "python setup.py install", which install it at ~/utility/linux/opt/Python-2.6.5/lib/scons-2.0.0.final.0 sys.path doesn't have the above directory. I have to add it to my PYTHONPATH. Would a python module usually be installed at the following location? ~/utility/linux/opt/Python-2.6.5/lib/python2.6 -- Regards, Peng From python at bdurham.com Fri Jul 16 22:59:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 16 Jul 2010 22:59:11 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41140D.4010001@tim.thechases.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> Message-ID: <1279335551.5281.1385300137@webmail.messagingengine.com> Tim, > 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, week-in week-out, for sixpence a week, and when we got home our Dad would thrash us to sleep wi' his belt... Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter our code, in the dark, using loose binary toggle switches with poor connections. We used to have to get out of the lake at three o'clock in the morning, clean the lake, eat a handful of hot gravel, go to work at the mill every day for tuppence a month, come home, and Dad would beat us around the head and neck with a broken bottle, if we were LUCKY! Cheers, Malcolm [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm From tjreedy at udel.edu Fri Jul 16 23:12:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Jul 2010 23:12:20 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: Message-ID: On 7/16/2010 9:42 PM, Peng Yu wrote: > On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >> On 7/16/2010 1:01 PM, Peng Yu wrote: >>> >>> I mean to get the man page for '[' like in the following code. >>> >>> x=[1,2,3] >> >> You might find my Python symbol glossary useful. >> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html > > This is for Python 3. Is there one for Python 2.x? They are close to 100% the same. I intentionally worded the entries so one could look in the manuals for details. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Sat Jul 17 01:29:35 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 17 Jul 2010 01:29:35 -0400 Subject: [ANN] Struqtural: High level database interface library Message-ID: Struqtural makes it easy to get data into a database, and easy to work with it once it's there. Some of the big features include: * Automatically generate all tables and relations needed to represent XML in a database, including one to one, one to many, many to one and many to many relationships (JSON and YAML support is planned for a future release), returning mapped objects. * Automatically generate python objects for a specified table in a database, with support for discovery of all types of relationships (sort of like SQL Soup on 4 different kinds of steroids). * Automatically create persisted representations of python objects in a database, along with a persistent version of the object class. * Automatically infer SQL data types and create table representations for delimited text files (i.e. CSV/TSV), returning mapped objects. * Easily generate and query EAV/vertical attribute tables. * Easily generate and query graphs/trees/directed acyclic graphs. * Easily manage session configuration and creation for multiple databases. * Easily override almost all behavior with custom code or configuration variables * And much more... Once you're up and running, it's SQL Alchemy under the hood, with a few tune-ups that you are free to bypass if you don't like them. Home page:?http://www.turnkey-analytics.com/struqtural/ PyPI:?http://pypi.python.org/pypi/Struqtural Source:?https://code.launchpad.net/pydatastep Bugs:?https://bugs.launchpad.net/pydatastep To see Struqtural in action, take a look at the tutorial... ================================================= Struqtural has been designed to be as smart as possible. Because of that, most common use cases are retardedly simple. Let?s take a look, shall we? First, let?s just examine the most basic use case: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> data = [{"A":True, "B":1, "C":1.5, "D":"a"}, ... {"A":False, "B":2, "C":2.5, "D":"b"}, ... {"A":True, "B":3, "C":3.5, "D":"c"}, ... {"A":False, "B":4, "C":4.5, "D":"d"}] >>> example_structure = Structure(loader.CollectionLoader, data, "B", "SimpleInstance") >>> print "primary keys:", example_structure.primary_keys primary keys: ['B'] # Note that you could have also specified the primary key using an iterable >>> print "table name:", example_structure.table table name: SimpleInstances >>> print "table columns:", example_structure.columns table columns: ['SimpleInstances.A', 'SimpleInstances.C', 'SimpleInstances.B', 'SimpleInstances.D'] >>> for true_instance in example_structure.filter("B>2"): ... print true_instance SimpleInstance(A=True, C=3.5, B=3, D="c") SimpleInstance(A=False, C=4.5, B=4, D="d") >>> for small_true_instance in example_structure.query().filter("A", "C<3"): ... print small_true_instance SimpleInstance(A=True, C=1.5, B=1, D="a") Another nice feature is that Struqtural is pretty flexible about how you pass it data: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> more_data = [["T", "1", "1.0"], ... ["FALSE", "2", "2.0"], ... ["true", "3", "3.0"], ... ["False", "4", "4.0"]] # Note that more_data is strings, which isn't uncommon in the real world >>> data_headers = ["A", "B", "E"] >>> categories = Structure(loader.CollectionLoader, (data_headers, more_data), ["B", "E"], "Category") # Just a quick aside to demonstrate that Struqtural gets your table names right >>> print "table name:", categories.table table name: Categories >>> for category in categories: ... print category ... Category(A=True, B=1, E=1.0) Category(A=False, B=2, E=2.0) Category(A=True, B=3, E=3.0) Category(A=False, B=4, E=4.0) As you can see the strings have been handled elegantly. Type conversion is completely controllable and extensible. A small collection of useful type inference and conversion functions have been included. How about if we want to create a new structure out of multiple previously existing ones: >>> example_structure = Structure(loader.CollectionLoader, data, "B", "SimpleInstance") >>> connector = example_structure.connector >>> categories = Structure(loader.CollectionLoader, (data_headers, more_data), ["B", "E"], "Category", connector) >>> joint_structure = Structure(loader.JoinLoader, categories, example_structure) >>> for instance in joint_structure: ... print instance Category(A=True, B=1, E=1.0, C=1.5, D="a") Category(A=False, B=2, E=2.0, C=2.5, D="b") Category(A=True, B=3, E=3.0, C=3.5, D="c") Category(A=False, B=4, E=4.0, C=4.5, D="d") Note that we took advantage of some intelligence on the join we did there, since we have identically named, identically typed columns in the two tables. If you needed to be explicit about it you could just as easily have called structure like so (where the dictionary key is the column on the left table, in this case categories, and the value is the column on the joined table): >>> joined_with = (example_structure, {'A':'A', 'B':'B'}) >>> joint_structure = Structure(loader.JoinLoader, categories, joined_with) Next, let?s create persisted versions of pre-existing objects: >>> from struqtural.structures.structure import Structure >>> from struqtural.loaders import loader >>> class Mock(object): ... def __init__(self, a, b, c): ... self.a = a ... self.b = b ... self.c = c >>> mocks = [Mock(1, 2, 3), Mock(4, 5, 6), Mock(7, 8, 9)] >>> another_example_structure = Structure(loader.ObjectLoader, mocks, "a") >>> for mock in another_example_structure.query(): ... print mock Mock(a=1, c=3, b=2) Mock(a=4, c=6, b=5) Mock(a=7, c=9, b=8) Pretty easy, right? Notice that you got a nice __repr__ for free there, too. Any type which can be converted to a known SQL primitive will be mapped automatically by default, though this is easily configurable. If a variable cannot be directly mapped, or more than one type occurs on for a given variable name, by default it will be pickled so that what comes off the database is identical to what went in, though this can also be easily disabled. Note This does not directly instrument pre-existing objects. It populates the database with the data of the objects. Any changes made to the original Mock objects in the above example will not be persisted. I suggest replacing the original objects with the new objects from the session immediately. Also, rather than modify the original class, a modified subclass is created, so it is advisable to save the modified class as well. This was a design decision, however it would be trivial to switch, so the behavior may change depending on user feedback. Now on to something a little bit more complicated... Struqtural can automatically generate a schema from XML. As a basic example, let?s use the following document: 123 10/29/00 007 Bond, Inc. 1 3 ABC 12.95 What happens when you give this document to Struqtural? Let?s take a look: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_1) >>> order_structure = multi.properties["Order"] >>> for order in order_structure.query(): ... print "Order number:", order.number ... print "Order date:", order.date ... print "Order customer count:", len(order.customers) ... for customer in order.customers: ... print "Order customer:", customer ... print "Order line count:", len(order.lines) ... for line in order.lines: ... print "Order line:", line ... print "Order line part count:", len(line.parts) ... for part in line.parts: ... print "Order line part:", part ... Order number: 123 Order date: 2000-10-29 Order customer count: 1 Order customer: Customer(order_id=1, custnum=7, name="Bond, Inc.", id=1) Order line count: 1 Order line: Line(order_id=1, linenum=1, id=1, quantity=3) Order line part count: 1 Order line part: Part(line_id=1, price=12.95, id=1, partnum="ABC") Ok, Struqtural automatically figured out all the relations and properties from the XML file, that?s pretty neat. Because we didn?t set any tag primary keys or provide a SchemaFormatter object with a primary key identification engine, an id key is automatically added. Since this behavior is typically not desirable, it is very easy to override. Note You will probably notice that our customer has an order_id... In this case, that customer appears only on the one Order, so that is not too odd. Had the customer appeared on multiple orders, the order would have had a customer_id. Even better, if multiple customers appeared on any order, a secondary table would be automatically created to handle the relationship, as we?ll demonstrate in a minute. So Struqtural can get data into a database easily, you say. What if my data is already in the database? What can you do for me? No problem, check it out: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_1) >>> order_structure = multi.properties["Order"] >>> connector = order_structure.connector # This isn't strictly needed, but gives us nice, informative names. # The key in names is the table name, the value is the name you would like to give # the instance you are creating to represent that table. >>> names = {"Customers":"Customer", "Lines":"Line", "Parts":"Part"} >>> multi = MultiStructure(loader.DatabaseMultiLoader, "Orders", connector, names) >>> order_structure = multi.properties["Orders"] >>> for order in order_structure.query(): ... print "Order number:", order.number ... print "Order date:", order.date ... print "Order customer count:", len(order.customers) ... for customer in order.customers: ... print "Order customer:", customer ... print "Order line count:", len(order.lines) ... for line in order.lines: ... print "Order line:", line ... print "Order line part count:", len(line.parts) ... for part in line.parts: ... print "Order line part:", part Order number: 123 Order date: 2000-10-29 Order customer count: 1 Order customer: Customer(order_id=1, custnum=7, name="Bond, Inc.", id=1) Order line count: 1 Order line: Line(order_id=1, linenum=1, id=1, quantity=3) Order line part count: 1 Order line part: Part(line_id=1, price=12.95, partnum="ABC", id=1) You just got the ?Orders? table and everything connected with it (including stuff that points to it as well as stuff it points to) loaded and mapped, and it took almost no work! You?re free to do interesting stuff! Pretty awesome, huh? Let?s push things to the edge now with a quick demo of many to many relationship support. For this example we?re going to be using the following XML: 123 Sales 143 Raul Lopez 687 John Smith 947 Ming Chu 456 Marketing 157 Jim Jones 687 John Smith 947 Ming Chu Note that we?re also going to be passing tag primary keys here, so that things work properly: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> primary_keys = {"Department":"DeptNum", "Employee":"Number"} >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_2, ... primary_keys=primary_keys) >>> department_structure = multi.properties["Department"] >>> for department in department_structure.query(): ... print "Department number:", department.deptnum ... print "Employee count:", len(department.employees) ... for employee in department.employees: ... print "Employee name:", employee.name ... print "Employee number:", employee.number ... Department number: 123 Employee count: 3 Employee name: Raul Lopez Employee number: 143 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 Department number: 456 Employee count: 3 Employee name: Jim Jones Employee number: 157 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 If you already have a database with many to many relationships, that is no problem. As long as the secondary tables for the relationship don?t contain any non-foreign key columns or foreign keys for more than two tables, you?re in good shape. For example: >>> from struqtural.structures.structure import MultiStructure >>> from struqtural.loaders import loader, file as file_ >>> primary_keys = {"Department":"DeptNum", "Employee":"Number"} >>> multi = MultiStructure(file_.XmlMultiLoader, fake_file_2, ... primary_keys=primary_keys) >>> department_structure = multi.properties["Department"] >>> connector = department_structure.connector >>> names = {"Departments":"Department", "Employees":"Employee"} >>> multi = MultiStructure(loader.DatabaseMultiLoader, "Departments", connector, ... names, backref_by_default=True) >>> departments = multi.properties["Departments"] >>> for department in department_structure.query(): ... print "Department number:", department.deptnum ... print "Employee count:", len(department.employees) ... for employee in department.employees: ... print "Employee name:", employee.name ... print "Employee number:", employee.number ... Department number: 123 Employee count: 3 Employee name: Raul Lopez Employee number: 143 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 Department number: 456 Employee count: 3 Employee name: Jim Jones Employee number: 157 Employee name: John Smith Employee number: 687 Employee name: Ming Chu Employee number: 947 You will note that in all these examples we used a memory resident SQLite database. If you want to use a real database, you will need to pass a connector to your structure. You create one like so: >>> from struqtural.database import DatabaseConnector >>> connector = DatabaseConnector("my_database_config.cfg") That?s it! In fact, Struqtural will even automatically look in a few logical places for your configuration information, so you can set it up once and you?ll never have to pass it the location of a configuration file again. Just to give you an example of the format for the configuration file (this is included in the resources subdirectory): [current engine] engine= [parameter values] user= pass= host= db= [parameter lists] mysql=mysql://{user}:{pass}@{host}/{db} postgresql=postgresql://{user}:{pass}@{host}/{db} Note The configuration file shown here does not include driver, port or other information that you would probably want to be able to specify in a real case. Those parameters are supported, so if you modify the configuration to include them, the struqtural.database.connector.Databaseconnector will work as expected. From breamoreboy at yahoo.co.uk Sat Jul 17 04:01:40 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 Jul 2010 09:01:40 +0100 Subject: Where is a module usually installed? In-Reply-To: References: Message-ID: On 17/07/2010 03:36, Peng Yu wrote: > My Python is installed in the following location. > ~/utility/linux/opt/Python-2.6.5/ > > I then installed SCons (http://www.scons.org/) using the command > "python setup.py install", which install it at > ~/utility/linux/opt/Python-2.6.5/lib/scons-2.0.0.final.0 > > sys.path doesn't have the above directory. I have to add it to my PYTHONPATH. > > Would a python module usually be installed at the following location? > ~/utility/linux/opt/Python-2.6.5/lib/python2.6 > See the following for an explanation. http://docs.python.org/release/2.6.5/library/site.html#module-site HTH. Mark Lawrence From steve at REMOVE-THIS-cybersource.com.au Sat Jul 17 04:03:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 17 Jul 2010 08:03:27 GMT Subject: Is '[' a function or an operator or an language feature? References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: >> Is anyone /still/ using Python 2.x? ;-) > > 2.x?! You were lucky. We lived for three months with Python 1.x in a > septic tank. We used to have to get up at six in the morning, write our > 1.x code using ed, You got to use ed? Oh, we *dreamed* of using an editor! We had to edit the sectors on disk directly with a magnetised needle. A rusty, blunt needle. -- Steven From debatem1 at gmail.com Sat Jul 17 04:17:58 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 01:17:58 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 17, 2010 at 1:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > >>> Is anyone /still/ using Python 2.x? ;-) >> >> 2.x?! ?You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, > > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. Real programmers use butterflies. http://xkcd.com/378/ Geremy Condra From breamoreboy at yahoo.co.uk Sat Jul 17 04:57:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 17 Jul 2010 09:57:15 +0100 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <1279335551.5281.1385300137@webmail.messagingengine.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> <1279335551.5281.1385300137@webmail.messagingengine.com> Message-ID: On 17/07/2010 03:59, python at bdurham.com wrote: > Tim, > >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > Cheers, > Malcolm > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm I'm just envisaging a "Paper Tape Repairman" sketch. Kindest regards. Mark Lawrence. From alf.p.steinbach+usenet at gmail.com Sat Jul 17 05:50:48 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 17 Jul 2010 11:50:48 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) Message-ID: [Cross-posted comp.lang.c++ and comp.lang.python] Consider the following code, from an example usage of some C++ support for Python I'm working on, "cppy": struct Noddy { PyPtr first; PyPtr last; int number; Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) : number( 0 ) { // ... some initialization here } PyPtr name() { return (PyString( first ) + L" " + PyString( last )).pyPtr(); } }; struct NoddyPyClass: PyClass< Noddy > { typedef PyClass< Noddy > Base; NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) : Base( m, name, doc, Exposition() .method( L"name", CPPY_METHOD_FORWARDER( name ), L"Return the name, combining the first and last name" ) .attribute( L"first", CPPY_GETSET_FORWARDERS( first ), L"first name" ) .attribute( L"last", CPPY_GETSET_FORWARDERS( last ), L"last name" ) .attribute( L"number", CPPY_GETSET_FORWARDERS( number ), L"noddy number" ) ) {} }; Originally e.g. CPPY_GETSET_FORWARDERS( number ), had to be written as CPPY_GETSET_FORWARDERS( int, number ), because in order to use a compile time member pointer as template actual argument, one needs to supply the member type as a separate template argument. E.g. the template might look like template< class Class, class MemberType, MemberType Class::*pMember > struct ForwardersForGetAndSet { // Some definitions here, hardwiring that compile time member pointer! }; Apparently there was no way around the user repeating explicitly the member type that the compiler already knew about... It seemed akin to deducing the return type of a function. Difficult in C++98 (although Boost does a fair job). But then it seemed that I'm not totally senile yet, for this occurred to me: #define CPPY_GETSET_FORWARDERS( name ) \ ::progrock::cppy::forwardersGetSet( \ &CppClass::name \ ).themForwarders< &CppClass::name >() Here forwardersGetSet is a templated function that via argument type deduction produces an instance of a templated struct, thereby "knowing" the member type, which struct in turn has a member function templated on the member pointer, which the macro supplies *twice*, once as run-time arg and once as compile-time. He he. Perhaps this trick is well-known already, but it was new to me, so! :-) Cheers, - Alf -- blog at From nospam at nospam.com Sat Jul 17 05:56:18 2010 From: nospam at nospam.com (Gilles Ganault) Date: Sat, 17 Jul 2010 11:56:18 +0200 Subject: Only one forum app in Python? References: <7mmd361p47nbc8c4rhjbkufdchnh811jmt@4ax.com> <4c38bd30$0$2776$426a74cc@news.free.fr> Message-ID: On Sat, 10 Jul 2010 18:37:00 +0200, Bruno Desthuilliers wrote: >There are almost a dozen of Python "forum apps" for Django alone, and >Python is known as "the language with more web frameworks than keywords". So this list at Wikipedia is out-of-date/wrong, and there are more options through web frameworks. Thanks guys. From thomas at jollans.com Sat Jul 17 06:39:05 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 12:39:05 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C418849.7060409@jollans.com> On 07/17/2010 10:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > >>> Is anyone /still/ using Python 2.x? ;-) >> >> 2.x?! You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, > > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. > You try and tell the young people of today that, and they won't believe you. From as at sci.fi Sat Jul 17 08:27:40 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 17 Jul 2010 15:27:40 +0300 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: David Robinow writes: > Really, if you can't be bothered to set your key bindings to something > you prefer, then I don't think Emacs is the right tool for you. Uh, I absolutely think Emacs is the right tool for me, but I don't think I've never changed any key bindings in the 20 years I've used it. Considering the number of functions and existing key bindings, the whole idea makes me think it would be like a game of musical chairs, always some function would be left without a key binding? From tlikonen at iki.fi Sat Jul 17 08:57:01 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Sat, 17 Jul 2010 15:57:01 +0300 Subject: Q for Emacs users: code-folding (hideshow) References: <29bdf451-381e-4de9-a1ba-23e311148040@k39g2000yqb.googlegroups.com> Message-ID: <87oce66zc2.fsf@mithlond.arda> * 2010-07-16 06:29 (-0700), ernest wrote: > I tried the outline-mode and it seemed to work. It can collapse > different blocks of code, such as functions, classes, etc. > > However, I never got used to it because of the bizarre key bindings. I use outline-minor-mode and the code below to make key bindings fast and easy. Alt + up/down arrow will go to previous/next heading or code block. Alt + left/right will close or open one sublevel. And that's about it. My code is slightly modified version of the code from http://www.emacswiki.org/emacs/OutlineMinorMode Note that on that page there is also a tip to use Vim-like manual fold markers (like the Vim's default "{{{"). ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; outline-mode-easy-bindings.el ;; ;; Installation: Store this file as outline-mode-easy-bindings.el ;; somewhere in your load-path and create hooks for outline modes to ;; load this automatically, for example: ;; (add-hook 'outline-mode-hook 'my-outline-easy-bindings) ;; (add-hook 'outline-minor-mode-hook 'my-outline-easy-bindings) ;; ;; (defun my-outline-easy-bindings () ;; (require 'outline-mode-easy-bindings nil t)) (defun outline-body-p () (save-excursion (outline-back-to-heading) (outline-end-of-heading) (and (not (eobp)) (progn (forward-char 1) (not (outline-on-heading-p)))))) (defun outline-body-visible-p () (save-excursion (outline-back-to-heading) (outline-end-of-heading) (not (outline-invisible-p)))) (defun outline-subheadings-p () (save-excursion (outline-back-to-heading) (let ((level (funcall outline-level))) (outline-next-heading) (and (not (eobp)) (< level (funcall outline-level)))))) (defun outline-subheadings-visible-p () (interactive) (save-excursion (outline-next-heading) (not (outline-invisible-p)))) (defun outline-hide-more () (interactive) (when (outline-on-heading-p) (cond ((and (outline-body-p) (outline-body-visible-p)) (hide-entry) (hide-leaves)) (t (hide-subtree))))) (defun outline-show-more () (interactive) (when (outline-on-heading-p) (cond ((and (outline-subheadings-p) (not (outline-subheadings-visible-p))) (show-children)) ((and (not (outline-subheadings-p)) (not (outline-body-visible-p))) (show-subtree)) ((and (outline-body-p) (not (outline-body-visible-p))) (show-entry)) (t (show-subtree))))) (let ((major outline-mode-map) (minor outline-minor-mode-map)) (define-key major (kbd "M-") 'outline-hide-more) (define-key major (kbd "M-") 'outline-show-more) (define-key major (kbd "M-") 'outline-previous-visible-heading) (define-key major (kbd "M-") 'outline-next-visible-heading) (define-key major (kbd "C-c J") 'outline-hide-more) (define-key major (kbd "C-c L") 'outline-show-more) (define-key major (kbd "C-c I") 'outline-previous-visible-heading) (define-key major (kbd "C-c K") 'outline-next-visible-heading) (define-key minor (kbd "M-") 'outline-hide-more) (define-key minor (kbd "M-") 'outline-show-more) (define-key minor (kbd "M-") 'outline-previous-visible-heading) (define-key minor (kbd "M-") 'outline-next-visible-heading) (define-key minor (kbd "C-c J") 'outline-hide-more) (define-key minor (kbd "C-c L") 'outline-show-more) (define-key minor (kbd "C-c I") 'outline-previous-visible-heading) (define-key minor (kbd "C-c K") 'outline-next-visible-heading)) (provide 'outline-mode-easy-bindings) From alf.p.steinbach+usenet at gmail.com Sat Jul 17 09:02:58 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sat, 17 Jul 2010 15:02:58 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: * Alf P. Steinbach /Usenet, on 17.07.2010 11:50: > [Cross-posted comp.lang.c++ and comp.lang.python] > > [snip] > this occurred to me: > > #define CPPY_GETSET_FORWARDERS( name ) \ > ::progrock::cppy::forwardersGetSet( \ > &CppClass::name \ > ).themForwarders< &CppClass::name >() > > Here forwardersGetSet is a templated function that via argument type > deduction produces an instance of a templated struct, thereby "knowing" > the member type, which struct in turn has a member function templated on > the member pointer, which the macro supplies *twice*, once as run-time > arg and once as compile-time. That trick allowed uniform treatment of data and function member pointers. :-) So, with cppy the complete noddy2 example from the docs (I'm sort of working my way through the Python doc examples) now looks as shown below. The "typelessness" of the 'first' and 'last' members is in order to recreate as close as possible the noddy2 functionality, or, lack of it. Also, I haven't got around to sort of backporting the 'Exposition' scheme to modules. So, exposure of module functionality looks a little different from same for types, for now. // The Python 3.1.1 docs' Noddy 2 example rewritten using cppy. // Docs: "Extending and Embedding the Python Interpreter" ?2.1.1 #include // PyWeakPtr, PyPtr, PyModule, PyClass using namespace progrock; namespace { using namespace cppy; struct Noddy { PyPtr first; PyPtr last; int number; Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) : number( 0 ) { devsupport::suppressUnusedWarning( pySelf ); PyWeakPtr pFirstName = 0; PyWeakPtr pLastName = 0; static char* kwlist[] = { "first", "last", "number", 0 }; ::PyArg_ParseTupleAndKeywords( args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, pointerTo( pFirstName ), pointerTo( pLastName ), &number ) >> Accept< IsNonZero >() || throwX( "Invalid args" ); if( pFirstName != 0 ) { first = pFirstName; } if( pLastName != 0 ) { last = pLastName; } } PyPtr name() { (first != 0) || throwX( ::PyExc_AttributeError, "first" ); (last != 0) || throwX( ::PyExc_AttributeError, "last" ); return (PyString( first ) + L" " + PyString( last )).pyPtr(); } }; struct NoddyPyClass: PyClass< Noddy > { NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) : PyClass< Noddy >( m, name, doc, Exposition() .method( L"name", CPPY_GLUE( name ), L"Return the name, combining the first and last name" ) .attribute( L"first", CPPY_GLUE( first ), L"first name" ) .attribute( L"last", CPPY_GLUE( last ), L"last name" ) .attribute( L"number", CPPY_GLUE( number ), L"noddy number" ) ) {} }; class NoddyModule: public PyModule { private: NoddyPyClass noddyPyClass_; public: NoddyModule() : PyModule( L"noddy2", L"Example module that creates an extension type." ) , noddyPyClass_( *this, L"Noddy", L"A Noddy object has a name and a noddy number" ) {} }; } // namespace PyMODINIT_FUNC PyInit_noddy2() { return cppy::safeInit< NoddyModule >(); } I wonder if this is readable / self-documenting, or not? Cheers, - Alf -- blog at From sturlamolden at yahoo.no Sat Jul 17 09:25:12 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 17 Jul 2010 06:25:12 -0700 (PDT) Subject: Struqtural: High level database interface library References: Message-ID: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> On 17 Jul, 07:29, Nathan Rice wrote: > Let?s push things to the edge now with a quick demo of many to many > relationship support. For this example we?re going to be using the > following XML: > > > ? ? > ? ? ? ? 123 > ? ? ? ? Sales > ? ? ? ? > ? ? ? ? ? ? 143 > ? ? ? ? ? ? Raul Lopez > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 687 > ? ? ? ? ? ? John Smith > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 947 > ? ? ? ? ? ? Ming Chu > ? ? ? ? > ? ? > ? ? > ? ? ? ? 456 > ? ? ? ? Marketing > ? ? ? ? > ? ? ? ? ? ? 157 > ? ? ? ? ? ? Jim Jones > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 687 > ? ? ? ? ? ? John Smith > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? 947 > ? ? ? ? ? ? Ming Chu > ? ? ? ? > ? ? > Oh yes, I'd rather write pages of that rather than some SQL in a Python string. From ptmcg at austin.rr.com Sat Jul 17 09:57:06 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sat, 17 Jul 2010 06:57:06 -0700 (PDT) Subject: Is '[' a function or an operator or an language feature? References: Message-ID: <42f45ff6-db51-474d-aa0b-0860a3333907@y4g2000yqy.googlegroups.com> On Jul 16, 12:01?pm, Peng Yu wrote: > I mean to get the man page for '[' like in the following code. > > x=[1,2,3] > > But help('[') doesn't seem to give the above usage. > > ########### > Mutable Sequence Types > ********************** > > List objects support additional operations that allow in-place > modification of the object. Other mutable sequence types (when added > to the language) should also support these operations. Strings and > tuples are immutable sequence types: such objects cannot be modified > once created. The following operations are defined on mutable sequence > types (where *x* is an arbitrary object): > ... > ########## > > I then checked help('LISTLITERALS'), which gives some description that > is available from the language reference. So '[' in "x=[1,2,3]" is > considered as a language feature rather than a function or an > operator? > > ############ > List displays > ************* > > A list display is a possibly empty series of expressions enclosed in > square brackets: > > ? ?list_display ? ? ? ?::= "[" [expression_list | list_comprehension] "]" > ? ?list_comprehension ?::= expression list_for > ? ?list_for ? ? ? ? ? ?::= "for" target_list "in" old_expression_list > [list_iter] > ? ?old_expression_list ::= old_expression [("," old_expression)+ [","]] > ? ?list_iter ? ? ? ? ? ::= list_for | list_if > ? ?list_if ? ? ? ? ? ? ::= "if" old_expression [list_iter] > ..... > ########### > -- > Regards, > Peng Also look for __getitem__ and __setitem__, these methods defined on your own container classes will allow you to write "myobject['x']" and have your own custom lookup code get run. -- Paul From sturlamolden at yahoo.no Sat Jul 17 10:19:46 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sat, 17 Jul 2010 07:19:46 -0700 (PDT) Subject: Sharing: member type deduction for member pointers (Alf's device?) References: Message-ID: On 17 Jul, 15:02, "Alf P. Steinbach /Usenet" wrote: > #include ? ? ?// PyWeakPtr, PyPtr, PyModule, PyClass > using namespace progrock; > > namespace { > ? ? ?using namespace cppy; > > ? ? ?struct Noddy > ? ? ?{ > ? ? ? ? ?PyPtr ? ? ? first; > ? ? ? ? ?PyPtr ? ? ? last; > ? ? ? ? ?int ? ? ? ? number; > > ? ? ? ? ?Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) > ? ? ? ? ? ? ?: number( 0 ) > ? ? ? ? ?{ > ? ? ? ? ? ? ?devsupport::suppressUnusedWarning( pySelf ); > > ? ? ? ? ? ? ?PyWeakPtr ? pFirstName ?= 0; > ? ? ? ? ? ? ?PyWeakPtr ? pLastName ? = 0; > > ? ? ? ? ? ? ?static char* ? ?kwlist[] = { "first", "last", "number", 0 }; > > ? ? ? ? ? ? ?::PyArg_ParseTupleAndKeywords( > ? ? ? ? ? ? ? ? ?args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, > ? ? ? ? ? ? ? ? ?pointerTo( pFirstName ), pointerTo( pLastName ), &number > ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?>> Accept< IsNonZero >() > ? ? ? ? ? ? ? ? ?|| throwX( "Invalid args" ); > > ? ? ? ? ? ? ?if( pFirstName != 0 ) ? { first = pFirstName; } > ? ? ? ? ? ? ?if( pLastName != 0 ) ? ?{ last = pLastName; } > ? ? ? ? ?} > > ? ? ? ? ?PyPtr name() > ? ? ? ? ?{ > ? ? ? ? ? ? ?(first != 0) > ? ? ? ? ? ? ? ? ?|| throwX( ::PyExc_AttributeError, "first" ); > ? ? ? ? ? ? ?(last != 0) > ? ? ? ? ? ? ? ? ?|| throwX( ::PyExc_AttributeError, "last" ); > ? ? ? ? ? ? ?return (PyString( first ) + L" " + PyString( last )).pyPtr(); > ? ? ? ? ?} > ? ? ?}; > > ? ? ?struct NoddyPyClass: PyClass< Noddy > > ? ? ?{ > ? ? ? ? ?NoddyPyClass( PyModule& m, PyString const& name, PyString const& doc ) > ? ? ? ? ? ? ?: PyClass< Noddy >( m, name, doc, Exposition() > ? ? ? ? ? ? ? ? ?.method( > ? ? ? ? ? ? ? ? ? ? ?L"name", ? ?CPPY_GLUE( name ), > ? ? ? ? ? ? ? ? ? ? ?L"Return the name, combining the first and last name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"first", ? CPPY_GLUE( first ), ? ? L"first name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"last", ? ?CPPY_GLUE( last ), ? ? ?L"last name" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?.attribute( > ? ? ? ? ? ? ? ? ? ? ?L"number", ?CPPY_GLUE( number ), ? ?L"noddy number" > ? ? ? ? ? ? ? ? ? ? ?) > ? ? ? ? ? ? ? ? ?) > ? ? ? ? ?{} > ? ? ?}; > > ? ? ?class NoddyModule: public PyModule > ? ? ?{ > ? ? ?private: > ? ? ? ? ?NoddyPyClass ? ?noddyPyClass_; > > ? ? ?public: > ? ? ? ? ?NoddyModule() > ? ? ? ? ? ? ?: PyModule( > ? ? ? ? ? ? ? ? ?L"noddy2", L"Example module that creates an extension type." ) > ? ? ? ? ? ? ?, noddyPyClass_( *this, > ? ? ? ? ? ? ? ? ?L"Noddy", L"A Noddy object has a name and a noddy number" ) > ? ? ? ? ?{} > ? ? ?}; > > } ? ?// namespace > > PyMODINIT_FUNC > PyInit_noddy2() > { > ? ? ?return cppy::safeInit< NoddyModule >();} > I wonder if this is readable / self-documenting, or not? Are you serious? It's C++, Heaven forbid, and you wonder if it's readable or not? From rajgopal.srinivasan at gmail.com Sat Jul 17 12:21:00 2010 From: rajgopal.srinivasan at gmail.com (raj) Date: Sat, 17 Jul 2010 09:21:00 -0700 (PDT) Subject: Python 3.1.2 and marshal Message-ID: Hi, I am using 64 bit Python on an x86_64 platform (Fedora 13). I have some code that uses the python marshal module to serialize some objects to files. However, in moving the code to python 3 I have come across a situation where, if more than one object has been serialized to a file, then while trying to de-serialize only the first object is de-serialized. Trying to de-serialize the second object raises an EOFError. De-serialization of multiple objects works fine in Python 2.x. I tried going through the Python 3 documentation to see if marshal functionality has been changed, but haven't found anything to that effect. Does anyone else see this problem? Here is some example code: bash-4.1$ cat marshaltest.py import marshal numlines = 1 numwords = 25 stream = open('fails.mar','wb') marshal.dump(numlines, stream) marshal.dump(numwords, stream) stream.close() tmpstream = open('fails.mar', 'rb') value1 = marshal.load(tmpstream) value2 = marshal.load(tmpstream) print(value1 == numlines) print(value2 == numwords) Here are the results of running this code bash-4.1$ python2.7 marshaltest.py True True bash-4.1$ python3.1 marshaltest.py Traceback (most recent call last): File "marshaltest.py", line 13, in value2 = marshal.load(tmpstream) EOFError: EOF read where object expected Interestingly the file created by using Python 3.1 is readable by both Python 2.7 as well as Python 2.6 and both objects are successfully read. Cheers, raj From news1234 at free.fr Sat Jul 17 12:27:15 2010 From: news1234 at free.fr (News123) Date: Sat, 17 Jul 2010 18:27:15 +0200 Subject: rstrip() In-Reply-To: References: Message-ID: <4c41d9e3$0$25709$426a74cc@news.free.fr> Jason Friedman wrote: > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "x.vsd-dir".rstrip("-dir") > 'x.vs' > > I expected 'x.vsd' as a return value. This is kind of similiar to the question, that I posted recently. "nicer way to remove prefix of a string if it exists" if you want to remove '-dir' at the end of the string if it exists and leave the string as it is if it is not followed by '-dir', then you could do: def rmv_suffix(suffix,txt): if txt.endswith(suffix): return txt[:-len(suffix)] return txt >>> rmv_suffix('-dir','abcd') 'abcd' >>> rmv_suffix('-dir','abcd-dir') 'abcd' >>> rmv_suffix('-dir','abcd-dir-and then more') 'abcd-dir-and then more' >>> the other solution would involve regular expressions: import re >>> re.sub('-dir$','','abcd') 'abcd' >>> re.sub('-dir$','','abcd-dir') 'abcd' >>> re.sub('-dir$','','abcd-dirand more') 'abcd-dirand more' >>> From gherron at islandtraining.com Sat Jul 17 12:38:49 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 17 Jul 2010 09:38:49 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4c4163cf$0$11101$c3e8da3@news.astraweb.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> Message-ID: <4C41DC99.90406@islandtraining.com> On 07/17/2010 01:03 AM, Steven D'Aprano wrote: > On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: > > >>> Is anyone /still/ using Python 2.x? ;-) >>> >> 2.x?! You were lucky. We lived for three months with Python 1.x in a >> septic tank. We used to have to get up at six in the morning, write our >> 1.x code using ed, >> > You got to use ed? Oh, we *dreamed* of using an editor! We had to edit > the sectors on disk directly with a magnetised needle. A rusty, blunt > needle. > Along those lines, there's this -- one of my favorite comics: http://xkcd.com/378/ and unrelated to the thread but still about python: http://xkcd.com/353/ Gary Herron From thomas at jollans.com Sat Jul 17 13:11:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 19:11:33 +0200 Subject: Python 3.1.2 and marshal In-Reply-To: References: Message-ID: <4C41E445.5070002@jollans.com> On 07/17/2010 06:21 PM, raj wrote: > Hi, > > I am using 64 bit Python on an x86_64 platform (Fedora 13). I have > some code that uses the python marshal module to serialize some > objects to files. However, in moving the code to python 3 I have come > across a situation where, if more than one object has been serialized > to a file, then while trying to de-serialize only the first object is > de-serialized. Trying to de-serialize the second object raises an > EOFError. De-serialization of multiple objects works fine in Python > 2.x. I tried going through the Python 3 documentation to see if > marshal functionality has been changed, but haven't found anything to > that effect. Does anyone else see this problem? Here is some > example code: Interesting. I modified your script a bit: 0:pts/2:/tmp% cat marshtest.py from __future__ import print_function import marshal import sys if sys.version_info[0] == 3: bytehex = lambda i: '%02X ' % i else: bytehex = lambda c: '%02X ' % ord(c) numlines = 1 numwords = 25 stream = open('fails.mar','wb') marshal.dump(numlines, stream) marshal.dump(numwords, stream) stream.close() tmpstream = open('fails.mar', 'rb') for byte in tmpstream.read(): sys.stdout.write(bytehex(byte)) sys.stdout.write('\n') tmpstream.seek(0) print('pos:', tmpstream.tell()) value1 = marshal.load(tmpstream) print('val:', value1) print('pos:', tmpstream.tell()) value2 = marshal.load(tmpstream) print('val:', value2) print('pos:', tmpstream.tell()) print(value1 == numlines) print(value2 == numwords) 0:pts/2:/tmp% python2.6 marshtest.py 69 01 00 00 00 69 19 00 00 00 pos: 0 val: 1 pos: 5 val: 25 pos: 10 True True 0:pts/2:/tmp% python3.1 marshtest.py 69 01 00 00 00 69 19 00 00 00 pos: 0 val: 1 pos: 10 Traceback (most recent call last): File "marshtest.py", line 29, in value2 = marshal.load(tmpstream) EOFError: EOF read where object expected 1:pts/2:/tmp% So, the contents of the file is identical, but Python 3 reads the whole file, Python 2 reads only the data it uses. This looks like a simple optimisation: read the whole file at once, instead of byte-by-byte, to improve performance when reading large objects. (such as Python modules...) The question is: was storing multiple objects in sequence an intended use of the marshal module? I doubt it. You can always wrap your data in tuples or use pickle. > > bash-4.1$ cat marshaltest.py > import marshal > > numlines = 1 > numwords = 25 > > stream = open('fails.mar','wb') > marshal.dump(numlines, stream) > marshal.dump(numwords, stream) > stream.close() > > tmpstream = open('fails.mar', 'rb') > value1 = marshal.load(tmpstream) > value2 = marshal.load(tmpstream) > > print(value1 == numlines) > print(value2 == numwords) > > > Here are the results of running this code > > bash-4.1$ python2.7 marshaltest.py > True > True > > bash-4.1$ python3.1 marshaltest.py > Traceback (most recent call last): > File "marshaltest.py", line 13, in > value2 = marshal.load(tmpstream) > EOFError: EOF read where object expected > > Interestingly the file created by using Python 3.1 is readable by both > Python 2.7 as well as Python 2.6 and both objects are successfully > read. > > Cheers, > raj From thomas at jollans.com Sat Jul 17 13:16:12 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 17 Jul 2010 19:16:12 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41DC99.90406@islandtraining.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: <4C41E55C.4060201@jollans.com> On 07/17/2010 06:38 PM, Gary Herron wrote: > On 07/17/2010 01:03 AM, Steven D'Aprano wrote: >> On Fri, 16 Jul 2010 21:23:09 -0500, Tim Chase wrote: >> >> >>>> Is anyone /still/ using Python 2.x? ;-) > http://xkcd.com/353/ There we have the most important difference between Python 2 and 3: in the latter, "import antigravity" actually works. From emile at fenx.com Sat Jul 17 13:27:09 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:27:09 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C41DC99.90406@islandtraining.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On 7/17/2010 9:38 AM Gary Herron said... > and unrelated to the thread but still about python: > > http://xkcd.com/353/ ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import antigravity Nothing happens. >>> Emile From emile at fenx.com Sat Jul 17 13:28:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:28:01 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C4110A8.8040406@mrabarnett.plus.com> References: <4C4110A8.8040406@mrabarnett.plus.com> Message-ID: On 7/16/2010 7:08 PM MRAB said... > Peng Yu wrote: >> On Fri, Jul 16, 2010 at 5:42 PM, Terry Reedy wrote: >>> On 7/16/2010 1:01 PM, Peng Yu wrote: >>>> I mean to get the man page for '[' like in the following code. >>>> >>>> x=[1,2,3] >>> You might find my Python symbol glossary useful. >>> https://code.google.com/p/xploro/downloads/detail?name=PySymbols.html >> >> This is for Python 3. Is there one for Python 2.x? >> > Is anyone /still/ using Python 2.x? ;-) Is anyone /actually/ using Python 3.x ;-) Emile From emmynoether3 at gmail.com Sat Jul 17 13:31:47 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 10:31:47 -0700 (PDT) Subject: death of newsgroups (Microsoft closing their newsgroups) References: <04b78dd8-5411-44a1-9435-dadec59b51ea@n8g2000prh.googlegroups.com> Message-ID: <1e9dc79f-f483-4b46-827e-20ef278c3a94@d16g2000yqb.googlegroups.com> > So, if newsgroups die and get replaced by web forums, that would be a move for > the better. If they get replaced by mailing lists, that would be a move for > the worse. Uday has gotten the valuation of the three communications media - a little wrong. 1/ Newsgroups are international, free and without censorship in the true spirit of democracy. 2/ The forums are privately owned, serve private interests and the most autocratic medium, you can be denied reading permissions if you go against official line which is never described. 3/ The mailing lists are archived, so read permission is often available and write permission can be denied. They are the second best. Moderated lists are no good. The quality of discussion in any of these media only depends on the generosity of the members in sharing information. Take a look at past archives of the newsgroups, and marvel at the quality of information. They stand as a counterexample to anyone bickering about newsgroups. Today, after monetary interests have attached to the software and the internet, the whole game is about controlling discourse, about marketing and creating hype towards sales and prominence without giving anything of substance. The forums are an excellent tool for this corporate control. The newsgroups are the ONLY NEUTRAL medium. Its obvious about the spam going on here today that the OCCASIONAL political messages are disliked by some groups and they start MASSIVELY spamming with sex-viagra-xanax etc. to drown OCCASIONAL political messages and hide them in a burst of spam. Alternatively, some companies dont like discussion and they produce the spam. The best method is to put some of these VIAGRA-XANAX words in the kill file or spam filter or search filters. On Jul 16, 1:22?am, Uday S Reddy wrote: > > Doing "better" means having more posts? ?I don't believe that having a lot of > posts is necessarily a measure of goodness. > > In my opinion, discussion forums do well when they encourage people to think > carefully and communicate clearly. ?In this respect, I think mailing lists do > worse, newsgroups better, and web-based forums the best. Uday presents a FACTOID on the order of "goodness". Forums are generally against freedom. They appeared around 2001 to control discourse and kill newsgroups, democracy and freedom of speech. Its the same forces who wanted to institute the Patriot Law and who mailed the ANTHRAX for that are the ones destroying the newsgroups by spamming. They operate on the principle of "provocation/reaction" cycle as explained Lucidly by Alex Jones which you can learn in first 2 minutes of this video http://video.google.com/videoplay?docid=5792753647750188322 > Mailing lists seem to turn into talking shops where people get to know each > other over time and their "public" nature gets lost. ?Those who write a lot end > up dominating them, independent of whether they write any sense or not. ?The > other people get tired and stop reading. ?So, you can generate a lot of > traffic, but its value is dubious. > > Newsgroups are much better because they are public and, visibly so. ?If > somebody says something stupid, a lot of people will jump on them. ?And, so, > over time, they develop some quality. ?(There is no guarantee, of course. ?I > have also seen a lot of newsgroups, especially in politics, really degenerate > with opposing factions fighting and dominating everything else.) > > Web-based forums, especially those where people have to register, work the best > in my experience. ?They are very visibly public, discouraging people to write > nonsense. ?The difficulty of writing on the web instead of your favorite editor > hopefully provides some resistance to write. ?So, people tend to think more > than they write. > > I used a forum called silentpcforum last year to help me build myself a new > computer. ?There was a lot of high quality information dating back to years, > which was easy to find and easy to use. > From emile at fenx.com Sat Jul 17 13:36:43 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 10:36:43 -0700 Subject: Struqtural: High level database interface library In-Reply-To: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> References: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> Message-ID: On 7/17/2010 6:25 AM sturlamolden said... > On 17 Jul, 07:29, Nathan Rice wrote: > >> Let?s push things to the edge now with a quick demo of many to many >> relationship support. For this example we?re going to be using the >> following XML: >> >> >> >> 123 >> Sales >> >> 143 >> Raul Lopez >> >> >> 687 >> John Smith >> >> >> 947 >> Ming Chu >> >> >> >> 456 >> Marketing >> >> 157 >> Jim Jones >> >> >> 687 >> John Smith >> >> >> 947 >> Ming Chu >> >> >> > > > Oh yes, I'd rather write pages of that rather than some SQL in a > Python string. > That's not the point. I've got examples of XML content that I don't create that could be tamed quite easily (if I understand from a quick once over). This looks really interesting. I've got to go read more now... Emile From benjamin.kaplan at case.edu Sat Jul 17 13:57:01 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 17 Jul 2010 10:57:01 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On Sat, Jul 17, 2010 at 10:27 AM, Emile van Sebille wrote: > On 7/17/2010 9:38 AM Gary Herron said... > > and unrelated to the thread but still about python: >> >> http://xkcd.com/353/ >> > > ActivePython 2.6.1.1 (ActiveState Software Inc.) based on > Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import antigravity > Nothing happens. > >>> > > Emile > > Try it in Python 3. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emmynoether3 at gmail.com Sat Jul 17 14:11:10 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:11:10 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: Message-ID: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> On Jul 16, 1:41?am, Uday S Reddy wrote: > On 7/16/2010 12:23 AM, Xah Lee wrote: > > > > > It got closed right away i suppose partly has to do with my > > unforgiving nature of criticizing and run-in with some GNU emacs > > developers in gnu.emacs.help and comp.emacs in the past 5 or so years. > > I think "criticizing" is an understatement for what you do. ?Insulting and > abusing might be closer to the truth. ?You do write a lot of sense, but you > also go off on rants occasionally writing stuff that has no place in civil > conversation. ?I am sure that the emacs developers try to be as professional as > they can, but they would only be human if they undervalue your input because of > your writing style. Well, there is a lot of resistance from the emacs community in sharing information. Richard Stallman is a true STALLER of progress. He has held the whole process hostage by not sharing information. He has RENEGED on his promise to make it truly open by suppressing documentation of his softwares. > > Re-writing the whole doc in a modern perspective might take me one > > month full time. (e.g. 160 hours) But if it were to be done in a > > public way, or submit to him, the time it takes to communicate, email, > > write justifications, create diffs, etc, can easily take half a year > > full time (960 hours). In the end, i'm not even sure half of the text > > in the new doc would be accepted. > > If you can rewrite it in a month's time, then what are you waiting for? ?You > can write it and publish it on your own, calling it a "Modernized Emacs > Manual". ?If people find it valuable and it is accurate, then I am sure Gnu > will distribute it. The one who has the key can open the lock in a jiffy. The one who does not have the key will take lots of labor to do it esp if he has never opened the lock before. All Richard Stallman has to do is to hand draw the data-structures and architecture of the various programs. Give references to the places where he got the ideas. He does not even have to type. He can write with pencil and scan and thats all. This way he can make marvelously elaborate diagrams. He can even make audios or videos. He has plenty of time to make POLITICAL videos. He has plenty of time to to write that elaborate manual on LISP MACHINE PROPOSAL on the internet. Its less about bugs and more about releasing the details and tricks of the softwares he has written. Yes, he can do in one month because he has the key. Will he do it only after he is anointed as a king in the temple of Solomon ? > > The GNU Emacs's bug database sucks majorly. I have problem finding all > > bugs posted by me. (it's using Debbugs.) Hard to find any bug by its > > search feature. They did not have a bug database, only in around 2008. > > Most commercial software have a bug database system in 1990s, and most > > large open source projects have one by early 2000s. (I wrote a bug > > tracker in 1998, 4k lines of Perl (with CGI, MySQL), in about 2 weeks, > > for a startup brainpower.com.) > > I go to gmane.emacs.bugs and view it in Thunderbird. ?I have no problem finding > my bug reports or any one else's. The FSF people have intentionally erected lots of barriers for others. FSF plays a crooked game and this will be discussed in detail. In this video, Stall man makes 4 promises to public but stalls on 2nd of them. http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr 1/ Freedom to Run to the Program 2/ Freedom to study the source code, you control it <------ Software is a puzzle and it must be explained to be able to do that, its like a lock 3/ Freedom to help your neightbors, share with them 4/ Freedom to contribute to your community Software is a puzzle and it must be explained to be able to do that, its like a lock "to MAKE SURE you get the four freedoms" He is WRONG !!! He has not made sure. He has not taken the first steps. Software architecture must be documented. A model minimal release must be given. If it takes too long to document the program by writing in Latex, then he can write by hand or make an video with camera on the paper and he can talk. From nathan.alexander.rice at gmail.com Sat Jul 17 14:20:41 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 17 Jul 2010 14:20:41 -0400 Subject: Struqtural: High level database interface library In-Reply-To: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> References: <54f24179-408a-42d7-b7f0-53548e3a46e9@g19g2000yqc.googlegroups.com> Message-ID: > Oh yes, I'd rather write lines of that rather than pages of SQL in a Python string. (not to mention, avoid some easy to fall into security flaws, not have to worry about porting dialect specific SQL code, etc, etc). Fixed that for you. I can't take the credit for that part though, that magic comes from SQL Alchemy. All Struqtural does is let you move data into a database easily, move data from a database to Python easily, and simplify the creation of some common complex schemas. From emmynoether3 at gmail.com Sat Jul 17 14:34:59 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:34:59 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: <030bc145-6931-49ac-a953-b33e62d3fb90@w35g2000prd.googlegroups.com> Message-ID: On Jul 16, 2:59?pm, Xah Lee wrote: > In comp.emacs Xah Lee wrote: > > > GNU Emacs Developement Inefficiency > > It [a bug report] got closed right away i suppose partly has to do with > > my unforgiving nature of criticizing and run-in with some GNU emacs > > developers in gnu.emacs.help and comp.emacs in the past 5 or so years. > > On Jul 16, 9:25?am, Alan Mackenzie wrote: > > > It has to be said that that criticism has sometimes involved the use of > > curse words. > > i admit that's true. Didnt you say that you wrote several polite emails and it did not work ??? Have some spine and say the truth !!! > > So if your bug reports are getting things moved, what's so frustrating? > > couldn've been better. You meant "could've" > > > Re-writing the whole doc in a modern perspective might take me one > > > month full time. (e.g. 160 hours) > > > I think it would take you a great deal longer than that. ?But it would be > > easy enough to experiment on. ?Chose some chapter from the Emacs or Elisp > > manual, fire away and see how long it takes you. > > btw, i don't think elisp manual needs to be re-worked, or at least not > critical... but i think it's much critical that the emacs manual be. What he needs is to give a clear and concise explanation of the data- structures and algorithms of the software. If he used ideas from others, he need to give reference to them so others can find it and get into depth. There is no need to make professional diagrams using xfig etc if it takes too much time. He only needs a scanner, pencil , eraser and a ruler. Others who worked for him and learnt the hard way can also do it , but I suspect he extracted such a price that they wont be able to give freely. The XEMACs people deserve some commendation . > > I think your changes would not be accepted as such. ?Quite bluntly, your > > English isn't good enough, so somebody would have to go through your > > version eliminating solecisms. ?There's a vast gap between being able to > > use English adequately to transmit your meaning and being able to write > > stylish and correct English. ?Your English belongs to the former > > category. ?As a matter of interest, what is your native language? > > Haha, that's a good one. This is why they brought indians to checkmate the chinese. They can put this accusation of english as they used to do on the asians and japanese throughout the 90s by Japanese Bashing. I remember very well that George Bush senior vomited on the face of Toshiki Kaifu to insult him intentionally in Japan. This is just a false excuse to give proper space to you. I think you write excellently. > i disconcur. See: > > ? The Writing Style on XahLee.org > ?http://xahlee.org/Periodic_dosage_dir/bangu/xah_style.html > > > > (the GNU emacs dev's revision control system was CVS up to ~2008. CVS > > > has been phased out by 2000 in vast majority of software orgs or > > > projects. I think GNU emacs now using SVN, while most bleeding edge > > > orgs have switched to git, mercurial, distributed systems. (e.g. > > > FireFox, Google)) > > > What's your source for "the vast majority" of projects no longer using > > CVS, again as a matter of interest? > > sloppy exaggeration. Though, i would say ?majority?, from experience. > e.g. look at google and other large orgs commercial or open source, > and look at the revision system supported by large project hosters > such as google code, SourceForge, github... Mackenzie, bring a properly written documentation by FSF for example on emacs of gcc. I want to see where RMS got his ideas ? Did he invent all of them himself ? Is he giving proper references to the sources of the ideas ? Is that plagiarism ? I am sick of such jews/zionists like RMS, Roman Polansky, Bernard Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism by their flagrant unethical behaviour. If you use someone else's ideas, give reference. Dont try to portray yourself falsely as a genius by hiding sources and weaving rosy false pictures of being a victim or born out of wedlock. you went to school and got good education. you got insights from your community and good mentorship from other jews in aggressive networking in the jews like other communities dont have. These are facts. Thats why these people dont stand to scrutiny and questioning. > > Emacs uses BZR, not SVN, and has > > done since the beginning of 2010. > > Thanks for your correction. Updated my site. Write a good documentation using pencil and scan that helps newbies enter the field. If it is not there, you will be subject of perpetual criticism and no thanks. > (also thanks to Uday S Reddy & David Kastrup for comment.) > > ? Xah > ?http://xahlee.org/ > > ? From emile at fenx.com Sat Jul 17 14:37:55 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 17 Jul 2010 11:37:55 -0700 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: References: <4C4110A8.8040406@mrabarnett.plus.com> <4c4163cf$0$11101$c3e8da3@news.astraweb.com> <4C41DC99.90406@islandtraining.com> Message-ID: On 7/17/2010 10:57 AM Benjamin Kaplan said... > Try it in Python 3. > Cool. :) Although I wouldn't have been surprised had my monitor levitated. :) Emile From emmynoether3 at gmail.com Sat Jul 17 14:43:09 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 11:43:09 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: Message-ID: <0d3e8a52-a7a3-4f9b-9fb5-b4b1e3fddf7c@c10g2000yqi.googlegroups.com> On Jul 15, 4:23?pm, Xah Lee wrote: > ? GNU Emacs Developement Inefficiency > ?http://xahlee.org/emacs/GNU_Emacs_dev_inefficiency.html > > essay; commentary. Plain text version follows. > > -------------------------------------------------- > GNU Emacs Developement Inefficiency > > Xah Lee, 2010-07-15 > > I've also written to Richard Stallman a few times in private in about > 2008 or 2009, about documentation improvements. With extreme > politeness and respect on my part. You took good precaution to deny him any excuse to fend you off ... so that we can all know the true reality of the situation. Its long said by others that this idea of freedom is a bait. Still, I want to give him / FSF a chance to prove their sincerity in enabling others in reading the code and learning from it ... > Without going into detail, i'm just > disenchanted by his reaction. In short, it appears to me he did not > pay much attention, and basically in the end asked me to submit > changes to him. Yeah right. The whole shebang seems to be very well > described by Ben Wing. (See: GNU Emacs and Xemacs Schism, by Ben > Wing.) (Richard Stallman's emails are pretty short, just a couple > terse sentences; but he does, however, whenever he got a chance, tell > his correspondents to use the term GNU/Linux, and ask them to > contribute.) > > Re-writing the whole doc in a modern perspective might take me one > month full time. (e.g. 160 hours) But if it were to be done in a > public way, or submit to him, the time it takes to communicate, email, > write justifications, create diffs, etc, can easily take half a year > full time (960 hours). In the end, i'm not even sure half of the text > in the new doc would be accepted. > > The GNU Emacs's bug database sucks majorly. I have problem finding all > bugs posted by me. (it's using Debbugs.) Hard to find any bug by its > search feature. They did not have a bug database, only in around 2008. > Most commercial software have a bug database system in 1990s, and most > large open source projects have one by early 2000s. (I wrote a bug > tracker in 1998, 4k lines of Perl (with CGI, MySQL), in about 2 weeks, > for a startup brainpower.com.) > > Am pretty sure there are several good ?FSF Free? bug databases. (see: > Comparison of issue-tracking systems) Few years ago, some may have > problem to be politically qualified to be ?Free? for FSF to adopt. > However, these days there are many that FSF officially sactions as > ?Free?. However, when you look at FSF, you see that even when a > software became free, they usually are still picky with lots qualms, > and typically always ends up using their OWN ones (i.e. from GNU > project), even though it is clear that it is inferior. (the GNU emacs > dev's revision control system was CVS up to ~2008. CVS has been phased > out by 2000 in vast majority of software orgs or projects. I think GNU > emacs now using SVN, while most bleeding edge orgs have switched to > git, mercurial, distributed systems. (e.g. FireFox, Google)) > > These are consequence of old and large orgs, with its old policies and > beaucracies. See: ?Free? Software Morality, Richard Stallman, and > Paperwork Bureaucracy. > > Who are the main developers of FSF software these days? Mostly, they > are either paid as FSF employee, or students still trying to break out > their craft in programing, or 40/50 years old semi-retired programers > who otherwise isn't doing anything. Those willing and able, spend time > and get decent salary in commercial corps, or went to start their own > projects or business that'd be far more rewarding financially or not > than being another name in FSF's list of contributors. > > These days, FSF and Richard Stallman more serves as a figure-head and > political leader in open source movement. FSF's software, largely are > old and outdated (e.g. unix command line utils), with the exception of > perhaps GCC and GPG. If we go by actual impact of open source software > in society, i think Google's role, and other commercial orgs (such as > Apache, Perl, Python, PHP, various langs on JVM, and other project > hosters hosting any odd-end single-man projects), exceeded FSF by > ~2000. > > ? Xah > ?http://xahlee.org/ > > ? From emmynoether3 at gmail.com Sat Jul 17 15:09:05 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 12:09:05 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> Message-ID: <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> On Jul 7, 1:57?pm, bolega wrote: > "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > Enjoy ..... In this video, Stall man makes 4 promises to public but stalls on 2nd of them. http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr 1/ Freedom to Run to the Program 2/ Freedom to study the source code, you control it <------ Software is a puzzle and it must be explained to be able to do that, its like a lock 3/ Freedom to help your neightbors, share with them 4/ Freedom to contribute to your community Software is a puzzle and it must be explained to be able to do that, its like a lock "to MAKE SURE you get the four freedoms" He is WRONG !!! He has not made sure. He has not taken the first steps. Software architecture must be documented. A model minimal release must be given. If it takes too long to document the program by writing in Latex, then he can write by hand or make an video with camera on the paper and he can talk. Mackenzie, bring a properly written documentation by FSF for example on emacs of gcc. I want to see where RMS got his ideas ? Did he invent all of them himself ? Is he giving proper references to the sources of the ideas ? Is that plagiarism ? I am sick of such jews/zionists like RMS, Roman Polansky, Bernard Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism by their flagrant unethical behaviour. If you use someone else's ideas, give reference. Dont try to portray yourself falsely as a genius by hiding sources and weaving rosy false pictures of being a victim or born out of wedlock. you went to school and got good education. you got insights from your community and good mentorship from other jews in aggressive networking in the jews like other communities dont have. These are facts. Thats why these people dont stand to scrutiny and questioning. > > Emacs uses BZR, not SVN, and has > > done since the beginning of 2010. > Thanks for your correction. Updated my site. Write a good documentation using pencil and scan that helps newbies enter the field. If it is not there, you will be subject of perpetual criticism and no thanks. From hjtoi-better-remove-before-reply at comcast.net Sat Jul 17 15:20:23 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Sat, 17 Jul 2010 12:20:23 -0700 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem References: Message-ID: On 07/16/2010 08:18 AM, Adam Mercer wrote: >> That version of M2Crypto does not work with OpenSSL 1.0.x because OpenSSL >> changed APIs. M2Crypto trunk works, as will the next M2Crypto release. So at >> this time, you should check out M2Crypto from the Subversion repository. See >> http://chandlerproject.org/Projects/MeTooCrypto for details on how to get >> the sources. > > Thanks any ETA on a new release supporting OpenSSL 1.0.x? I was actually planning on doing a release by the end of June, but life happened. Maybe by the end of August... -- Heikki Toivonen - http://heikkitoivonen.net From mad.mick at gmx.de Sat Jul 17 15:38:01 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sat, 17 Jul 2010 21:38:01 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Karsten Wutzke wrote: > The visitor pattern uses single-dispatch, that is, it determines > which method to call be the type of object passed in. Say, in Python, I have an object o and want to call one of it's methods, say m. Then which of possibly many methods m to call is determined by the type of o, and nothing else (at least without further magic) - hence, it is single dispatch. The VP uses two single dispatch calls (one being a callback) to accomplish double dispatching. Java has a form of multiple dispatch through function overloading. In fact, it's still single dispatch, because which of the targets overloaded methods gets called is determined at compile time by the staticly known types of the methods parameters, AKA the formal parameter types. Anyway. Although VP *uses* double dispatch, it does not necessarily rely on function overloading. In Java the VP is most often implemented like this: interface IASTNode { void accept(IASTVisitor); } class IfNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visit(this); } } class ElseNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visit(this); } } interface IASTVisitor { void visit(IfNode node); void visit(ElseNode node); ... } class PrettyPrinter implements IASTVisitor { public void visit(IfNode n) { ... } public void visit(ElseNode n) { ... } } but it could as well be implemented like this: interface IASTNode { void accept(IASTVisitor); } class IfNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visitIfNode(this); } } class ElseNode implements IASTNode { void accept(IASTVisitor visitor) { visitor.visitElseNode(this); } } interface IASTVisitor { void visitIfNode(IfNode node); void visitElseNode(ElseNode node); ... } class PrettyPrinter implements IASTVisitor { public void visitIfNode(IfNode n) { ... } public void visitElseNode(ElseNode n) { ... } } If Java were *really* a multiple dispatch language, it wouldn't be necessary to repeat the accept-code for every subclass. Instead a single accept method in the base class would suffice. In fact, with true multiple dispatch VP wouldn't even be needed. Regards, Mick. From mad.mick at gmx.de Sat Jul 17 15:55:09 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sat, 17 Jul 2010 21:55:09 +0200 Subject: Code generator and visitor pattern In-Reply-To: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> References: <3ff2a36c-8f6b-4d20-aa02-7165e3686d9f@s9g2000yqd.googlegroups.com> Message-ID: Hello, Am 16.07.2010 09:52, Michele Simionato wrote: > [os.path.walk vs os.walk] > There is a big conceptual difference between os.path.walk and os.walk. > The first works like a framework: you pass a function to it and > os.path.walk is in charging of calling it when needed. The second works > like a library: os.walk flattens the hierarchical structure and then > you are in charge of doing everything you wish with it. > > os.walk is the Pythonic way, and you suggested to follow that > approach; for instance elementTree and lxml (libraries for parsing XML > data) work exactly that way. Actually one of the motivating examples for > the introduction of generators in Python was their use in flattening > data structure, i.e. exactly the pattern used by os.walk. The Visitor Pattern isn't about traversing, so they could as well have had an os.walk() that took a visitor object. Instead, it's about the untangling of unrelated stuff. Not the traversing vs. everything else - that's what iterators are for, like you said. But if you want to be able to add new types of operations without ever touching the code of the objects on which to apply those operations, then the VP is an easy way to accomplish things: class IfNode: def apply(self, operation): operation.handleIfNode(self) ... class ElseNode: def apply(self, operation): operation.handleElseNode(self) ... class PrettyPrinter: def handleIfNode(self, if_node): # print if_node pretty def handleElseNode(self, else_node): # print else_node pretty ... class Interpreter: def handleIfNode(self, if_node): # interpret if_node def handleElseNode(self, else_node): # interpret else_node ... class AST: def apply(self, operation): # apply operation to all nodes ... some_ast = ... some_ast.apply(PrettyPrinter()) some_ast.apply(Interpreter()) The traversing in AST.apply() is not really part of the pattern, it could also be done in the client code. The VP lives in the relation between the ...Node and the operation classes. It Encapsulates What Varies and helps to uphold the Open/Closed Principle, because to add new operations one does not need to touch the ...Node classes. It implements double dispatching in a single dispatch language. Regards, Mick. From dak at gnu.org Sat Jul 17 15:56:51 2010 From: dak at gnu.org (David Kastrup) Date: Sat, 17 Jul 2010 21:56:51 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <87d3ulj30c.fsf@lola.goethe.zz> Emmy Noether writes: > On Jul 7, 1:57?pm, bolega wrote: >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> Enjoy ..... > > In this video, Stall man makes 4 promises to public but stalls on 2nd > of them. > > > http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > > 1/ Freedom to Run to the Program > 2/ Freedom to study the source code, you control it <------ Software > is a puzzle and it must be explained to be able to do that, its like > a > lock > 3/ Freedom to help your neightbors, share with them > 4/ Freedom to contribute to your community > > > Software is a puzzle and it must be explained to be able to do that, > its like a lock There is no unfreedom involved here. Freedom does not hand you a free ride. Only a free road. -- David Kastrup From kst-u at mib.org Sat Jul 17 16:56:04 2010 From: kst-u at mib.org (Keith Thompson) Date: Sat, 17 Jul 2010 13:56:04 -0700 Subject: GNU Emacs Developement Inefficiency (commentary) References: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> Message-ID: Emmy Noether writes: [98 lines deleted] The parent article was posted to comp.emacs and comp.lang.lisp. Why did you cross-post your followup to comp.lang.c, comp.lang.python, and comp.lang.scheme? -- Keith Thompson (The_Other_Keith) kst-u at mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" From clp2 at rebertia.com Sat Jul 17 18:11:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jul 2010 15:11:18 -0700 Subject: rstrip() In-Reply-To: <4C409680.8000503@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> Message-ID: On Fri, Jul 16, 2010 at 10:27 AM, MRAB wrote: > Jason Friedman wrote: >> >> $ python >> Python 2.6.4 (r264:75706, Dec ?7 2009, 18:43:55) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> "x.vsd-dir".rstrip("-dir") >> >> 'x.vs' >> >> I expected 'x.vsd' as a return value. > > .strip, .lstrip and .rstrip treat their argument like a set of > characters and remove any of those characters from the end(s) of the > string. It's a pity that str.strip() doesn't actually take a set() of length-1 strings, which would make its behavior more obvious and cut down on this perennial question. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sat Jul 17 18:17:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 17 Jul 2010 23:17:08 +0100 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> Message-ID: <4C422BE4.8070304@mrabarnett.plus.com> Chris Rebert wrote: > On Fri, Jul 16, 2010 at 10:27 AM, MRAB wrote: >> Jason Friedman wrote: >>> $ python >>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) >>> [GCC 4.4.1] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> "x.vsd-dir".rstrip("-dir") >>> 'x.vs' >>> >>> I expected 'x.vsd' as a return value. >> .strip, .lstrip and .rstrip treat their argument like a set of >> characters and remove any of those characters from the end(s) of the >> string. > > It's a pity that str.strip() doesn't actually take a set() of length-1 > strings, which would make its behavior more obvious and cut down on > this perennial question. > Even better, a set (or tuple) of strings. It's the kind of thing that could've been done in Python 3, with Python 2's .strip(string) becoming .strip(set(string)), but it didn't occur to me until too late. :-( From breamoreboy at yahoo.co.uk Sat Jul 17 19:08:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 18 Jul 2010 00:08:22 +0100 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: On 17/07/2010 20:38, Mick Krippendorf wrote: > Karsten Wutzke wrote: >> The visitor pattern uses single-dispatch, that is, it determines >> which method to call be the type of object passed in. > > Say, in Python, I have an object o and want to call one of it's methods, > say m. Then which of possibly many methods m to call is determined by > the type of o, and nothing else (at least without further magic) - > hence, it is single dispatch. The VP uses two single dispatch calls (one > being a callback) to accomplish double dispatching. > > Java has a form of multiple dispatch through function overloading. In > fact, it's still single dispatch, because which of the targets > overloaded methods gets called is determined at compile time by the > staticly known types of the methods parameters, AKA the formal parameter > types. > > Anyway. Although VP *uses* double dispatch, it does not necessarily rely > on function overloading. In Java the VP is most often implemented like this: > > > > interface IASTNode { > void accept(IASTVisitor); > } > > class IfNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visit(this); > } > } > > class ElseNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visit(this); > } > } > > interface IASTVisitor { > void visit(IfNode node); > void visit(ElseNode node); > ... > } > class PrettyPrinter implements IASTVisitor { > public void visit(IfNode n) { > ... > } > public void visit(ElseNode n) { > ... > } > } > > > > but it could as well be implemented like this: > > > > interface IASTNode { > void accept(IASTVisitor); > } > > class IfNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visitIfNode(this); > } > } > > class ElseNode implements IASTNode { > void accept(IASTVisitor visitor) { > visitor.visitElseNode(this); > } > } > > interface IASTVisitor { > void visitIfNode(IfNode node); > void visitElseNode(ElseNode node); > ... > } > class PrettyPrinter implements IASTVisitor { > public void visitIfNode(IfNode n) { > ... > } > public void visitElseNode(ElseNode n) { > ... > } > } > > > > If Java were *really* a multiple dispatch language, it wouldn't be > necessary to repeat the accept-code for every subclass. Instead a single > accept method in the base class would suffice. In fact, with true > multiple dispatch VP wouldn't even be needed. > > > Regards, > Mick. Boilerplate, boilerplate everywhere, but not a beer to drink. Hope everyone at EuroPython is having a good time. Kindest regards. Mark Lawrence. From breamoreboy at yahoo.co.uk Sat Jul 17 19:13:41 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 18 Jul 2010 00:13:41 +0100 Subject: rstrip() In-Reply-To: <4C422BE4.8070304@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> Message-ID: On 17/07/2010 23:17, MRAB wrote: > Chris Rebert wrote: >> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >> wrote: >>> Jason Friedman wrote: >>>> $ python >>>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) >>>> [GCC 4.4.1] on linux2 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>>>>> "x.vsd-dir".rstrip("-dir") >>>> 'x.vs' >>>> >>>> I expected 'x.vsd' as a return value. >>> .strip, .lstrip and .rstrip treat their argument like a set of >>> characters and remove any of those characters from the end(s) of the >>> string. >> >> It's a pity that str.strip() doesn't actually take a set() of length-1 >> strings, which would make its behavior more obvious and cut down on >> this perennial question. >> > Even better, a set (or tuple) of strings. It's the kind of thing that > could've been done in Python 3, with Python 2's .strip(string) becoming > .strip(set(string)), but it didn't occur to me until too late. :-( Maybe 3.2 which is still in alpha, if not 3.3? Kindest regards. Mark Lawrence. From ldo at geek-central.gen.new_zealand Sat Jul 17 19:29:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 18 Jul 2010 11:29:55 +1200 Subject: File transfer on network References: <0f3321a0-f2a9-4443-ba41-21e2a70bc6ce@q16g2000prf.googlegroups.com> Message-ID: In message , MRAB wrote: > You could either open and close a connection for each image, or have the > client tell the server how many bytes it's going to send, followed by > the bytes (my preference would be to send the size as a string ending > with, say, a newline). I have used variations on this in several projects. From emmynoether3 at gmail.com Sat Jul 17 19:44:20 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 16:44:20 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> Message-ID: <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> On Jul 17, 2:49?pm, Cor Gest wrote: > Some entity, AKA David Kastrup , > wrote this mindboggling stuff: > (selectively-snipped-or-not-p) >>> Software is a puzzle and it must be explained to be able to do that, >>> its like a lock >> There is no unfreedom involved here. ?Freedom does not hand you a free >> ride. ?Only a free road. No one asks for a free ride. A free road is good enough. If RMS used other people's free roads (gnu is not the first free thing. the first free thing is what he got at AI labs at TAX Payer money. I read his interview where he said that the hackers would break into professor's offices. Perhaps we do the same to him and break into his FSF office and leave a "friend" note we came to get the docs he has not released.) which has proper signs, proper references, and he could ask profs proper questions, and get straight answers, he must do the same in return. The concise answer: We want a free road but not a free puzzle. Perhaps, next time when he is sick he take his DNA code and parse it using bison. Now, dont run away from this argument and bring each and every of the boys from his mailing list to tackle this question. He is a manager and he can put the volunteers to the task of documenting, illuminating and revealing the operation of his softwares and its evolution. He owes it to others [just like he got for free , I bet ya he could never afford any of his machines on his own money at that time when they were so rare so it must be public money. Even a company like IBM gets public funding. Its all issue of ethics, not of free software. Its issue of two way road. Or else our society would die. People all away in Africa are beginning to agitate from the theft of their resources and evolutionary time by europeans led by jews and so you gotta give them back by fully disclosing technologies. I know you can bribe say a big player like india. We dont want anti-semitism to spread and want the same ethical requirements for everyone.] to describe the algorithms used, references, or else, describe them if he dont want to give references. He need to give priorty to the past undocumented tools. Automatically, more volunteers will come. Right now, the mistrust of Richard Stall man and FSF is growing everywhere. Strength of my arguments stand on their validity. I repeat, no one wants a free ride. We want a free road that you seemed to offer. But we dont want a free puzzle. Or else, ask him to decode his own DNA alone in reasonable time. Its nothing but a code. > You know, nowdadys many 'people' are used to get everything on a platter > any mental incovieniences are circumvented as much as possible, so is > any try for independent thinking about anything strongly dissuaded. > > The last 25 years, since click-tah-icon-software emerged > "the dumbing down of programming" [1] has been on a rampage. > > [1]http://www.salon.com/21st/feature/1998/05/cov_12feature.html From aahz at pythoncraft.com Sat Jul 17 20:09:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 17 Jul 2010 17:09:42 -0700 Subject: 'reload M' doesn't update 'from M inport *' References: <1278680545.2376.30.camel@hatchbox-one> Message-ID: In article , Jean-Michel Pichavant wrote: >Aahz wrote: >> In article , >> Jean-Michel Pichavant wrote: >>> >>> PS : You're misusing the del statement. It does not remove any object >>> from mmory, however, it removes the reference to it, the object is still >>> in memory. They are very few cases where del is usefull in python, so >>> try to avoid using it as well. >> >> The first two sentences are true; the last sentence is completely wrong. >> I've got lots of code using del, and it's a critically useful element of >> dictionary manipulation. > >Can you please give a short example ? I'm not challenging though, just >curious. Let's suppose you want to remove duplicate keys from a second dict: for k in d1: if k in d2: del d2[k] You could do d2.pop() instead, but I'll bet you'll find that it's slightly slower, which makes a difference in a tight loop. (Mainly, though, I learned this idiom long before pop() was available.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From ramercer at gmail.com Sat Jul 17 20:15:56 2010 From: ramercer at gmail.com (Adam Mercer) Date: Sat, 17 Jul 2010 20:15:56 -0400 Subject: M2Crypto-0.20.2, SWIG-2.0.0, and OpenSSL-1.0.0a build problem In-Reply-To: References: Message-ID: On Sat, Jul 17, 2010 at 15:20, Heikki Toivonen wrote: > I was actually planning on doing a release by the end of June, but life > happened. Maybe by the end of August... Know what whats like :-) I've backported the OpenSSL patches for the MacPorts port so for the time being this particular fire has been put out. Cheers Adam From emmynoether3 at gmail.com Sat Jul 17 20:16:35 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 17 Jul 2010 17:16:35 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> Message-ID: <252adaf3-df99-4d27-8fcf-a3e339e7a0ac@w12g2000yqj.googlegroups.com> The XEMACS programmers have documented in writing that Richard Matthews Stallman asked them to explain every single line of code. They got exasperated and would explain him blocks. I suspect that they were playing the same game as him - perhaps giving him the same medicine. If he was NEEDY of an explanation of every single line, isn't it UTTERLY SHAMELESS of him to deny others similar information and give them such a puzzle ? We have the right to tell the people what it really is all about. By writing the GNU license, he eliminated the competition only from those one-in-a-million who were persistent enough to read his code and figure it out. This is because by not documenting and describing his softwares, he ensured that there is little chance that the multitude would be able to take the code and do anything with it. But by writing the GNU license, he made sure that those few who can understand it cant take it away and build on it. An new type of license is needed that requires concurrent documentation with each release, even if hand-written. Scans can be put together in a pdf and diagrams drawn with hand. From rui.maciel at gmail.com Sat Jul 17 20:34:36 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Sun, 18 Jul 2010 01:34:36 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <4c424c1b$0$1334$a729d347@news.telepac.pt> Emmy Noether wrote: > Mackenzie, bring a properly written documentation by FSF for example > on emacs of gcc. I want to see where RMS got his ideas ? Did he > invent > all of them himself ? Is he giving proper references to the sources > of > the ideas ? Is that plagiarism ? > > I am sick of such jews/zionists like RMS, Roman Polansky, Bernard > Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl > he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism > by their flagrant unethical behaviour. You are a lousy troll. Rui Maciel From debatem1 at gmail.com Sat Jul 17 21:10:01 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 18:10:01 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <4c424c1b$0$1334$a729d347@news.telepac.pt> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <4c424c1b$0$1334$a729d347@news.telepac.pt> Message-ID: On Sat, Jul 17, 2010 at 5:34 PM, Rui Maciel wrote: > Emmy Noether wrote: > > >> Mackenzie, bring a properly written documentation by FSF for example >> on emacs of gcc. I want to see where RMS got his ideas ? Did he >> invent >> all of them himself ? Is he giving proper references to the sources >> of >> the ideas ? Is that plagiarism ? >> >> I am sick of such jews/zionists like RMS, Roman Polansky, Bernard >> Madoff, Larry Ellison (he had to pay 100K in court to a chinese girl >> he screwed), Stephen Wolfram, Albert Einstein spreading anti-semitism >> by their flagrant unethical behaviour. > > > You are a lousy troll. I'm seriously considering blocking everyone who uses the word 'zionist' in an email. The amount of anti-semitic crap that comes through on this list is staggering. Geremy Condra From me+list/python at ixokai.io Sat Jul 17 23:01:13 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 17 Jul 2010 20:01:13 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <4C426E79.5030607@ixokai.io> On 7/17/10 12:09 PM, Emmy Noether wrote: > I am sick of such jews/zionists [...] This racist rant may be on-topic for some of the other newsgroups/lists you are cross-posting to, but it is most assuredly not on topic for Python. Also, its just daft. But that's another thing entirely. Reported. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rajgopal.srinivasan at gmail.com Sun Jul 18 00:46:10 2010 From: rajgopal.srinivasan at gmail.com (raj) Date: Sat, 17 Jul 2010 21:46:10 -0700 (PDT) Subject: Python 3.1.2 and marshal References: Message-ID: <43f8638f-adb7-4c3c-a12a-932e469eb144@w37g2000prc.googlegroups.com> On Jul 17, 10:11?pm, Thomas Jollans wrote: [Snip] > So, the contents of the file is identical, but Python 3 reads the whole > file, Python 2 reads only the data it uses. > > This looks like a simple optimisation: read the whole file at once, > instead of byte-by-byte, to improve performance when reading large > objects. (such as Python modules...) > Good analysis and a nice catch. Thanks. It is likely that the intent is to optimize performance. > The question is: was storing multiple objects in sequence an intended > use of the marshal module? The documentation (http://docs.python.org/py3k/library/marshal.html) for marshal itself states (emphasis added by me), marshal.load(file)? Read *one value* from the open file and return it. If no valid value is read (e.g. because the data has a different Python version?s incompatible marshal format), raise EOFError, ValueError or TypeError. The file must be an open file object opened in binary mode ('rb' or 'r +b'). This suggests that support for reading multiple values is intended. > I doubt it. You can always wrap your data in > tuples or use pickle. > The code that I am moving to 3.x dates back to the python 1.5 days, when marshal was significantly faster than pickle and Zope was evolutionarily at the Bobo stage :-). I have switched the current code to pickle - makes more sense. The pickle files are a bit larger and loading it is a tad bit slower, but nothing that makes even a noticeable difference for my use case. Thanks. raj From be.krul at gmail.com Sun Jul 18 01:01:26 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 17 Jul 2010 22:01:26 -0700 (PDT) Subject: why is this group being spammed? Message-ID: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> why is this group being spammed? From clp2 at rebertia.com Sun Jul 18 01:09:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 17 Jul 2010 22:09:19 -0700 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > why is this group being spammed? Because that's what happens in unmoderated USENET newsgroups. Cheers, Chris From ben+python at benfinney.id.au Sun Jul 18 01:24:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 18 Jul 2010 15:24:18 +1000 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <874ofx9xbx.fsf@benfinney.id.au> "be.krul" writes: > why is this group being spammed? What kind of answer are you looking for? Are you asking about the motives of spammers, or the technical explanation for how the spam arrives, or something else? -- \ ?The best ad-libs are rehearsed.? ?Graham Kennedy | `\ | _o__) | Ben Finney From me+list/python at ixokai.io Sun Jul 18 01:40:15 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 17 Jul 2010 22:40:15 -0700 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <4C4293BF.5070701@ixokai.io> On 7/17/10 10:01 PM, be.krul wrote: > why is this group being spammed? Because while God created the Internet, the Devil twisted it by creating spammers. What do you expect? Adam just didn't pay enough attention when Eve made him a waldorf salad; we descendants of Seth have gone and tried to devour not only the knowledge of good and evil but all knowledge of all things, most notably breasts. Of course there'd be a dire consequence for our hubris. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From alf.p.steinbach+usenet at gmail.com Sun Jul 18 01:57:42 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Sun, 18 Jul 2010 07:57:42 +0200 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: * be.krul, on 18.07.2010 07:01: > why is this group being spammed? It depends a little on what you're asking, e.g. technical versus motivation. But I'll answer about something you probably didn't mean to ask, namely what human trait enables and almost forces that kind of behavior. And I believe it is the same trait that let hypnotists do funny TV-shows with quite normal folks behaving in ridiculous ways, the same trait that causes wars, the same trait that causes religion, the same trait that holds back science so that "paradigm shifts" only occur when new generations take over, a trait that /makes/ your feet start moving to the rhythm when you hear the right kind of music, and so on. Namely the instinctual drive to fit in in a social group by sharing that group's behavior and values. This instinct is possibly stronger than the sex drive, e.g., wars are seldom fought over sex ("surrender, and give us sex!", no, that's not it, it's "surrender, and become part of us!"). Consider, there would be almost no spam if spamming didn't pay. And the only way that spam can pay is if there are at least some suckers with good money. And the only way that there can be a reasonable number of suckers of such monumental stupidity, who also have good money, is, as I see it, if intelligence and good sense is not a requirement for succeeding in society. But what is required, then, for succeeding in society? Some of it is no doubt blind chance, but I believe that the main requirement is simply one of fitting in, conformance. Thus, if my hypothesis is right, almost any idiot can rise to any level of responsibility and social standing simply by fitting in, conforming. This idiot then has good money and might be one of the suckers responding to spam. Cheers, - Alf -- blog at From debatem1 at gmail.com Sun Jul 18 02:09:54 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 17 Jul 2010 23:09:54 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet wrote: > * be.krul, on 18.07.2010 07:01: >> >> why is this group being spammed? > > It depends a little on what you're asking, e.g. technical versus motivation. > > But I'll answer about something you probably didn't mean to ask, namely what > human trait enables and almost forces that kind of behavior. > > And I believe it is the same trait that let hypnotists do funny TV-shows > with quite normal folks behaving in ridiculous ways, the same trait that > causes wars, the same trait that causes religion, the same trait that holds > back science so that "paradigm shifts" only occur when new generations take > over, a trait that /makes/ your feet start moving to the rhythm when you > hear the right kind of music, and so on. Namely the instinctual drive to fit > in in a social group by sharing that group's behavior and values. This > instinct is possibly stronger than the sex drive, e.g., wars are seldom > fought over sex ("surrender, and give us sex!", no, that's not it, it's > "surrender, and become part of us!"). Helen of Troy begs to differ. Geremy Condra From ldo at geek-central.gen.new_zealand Sun Jul 18 02:49:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 18 Jul 2010 18:49:33 +1200 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: In message , Nick Keighley wrote: > On 16 July, 09:24, Mark Tarver wrote: >> On 15 July, 23:21, bolega wrote: >> >> >http://www.gnu.org/philosophy/stallman-kth.html >> >> > RMS lecture at KTH (Sweden), 30 October 1986 > > did you really have to post all of this... > > > >> > read more ?... > > ...oh sorry only about a third of it... Still totally unnecessary, though. >> Perhaps as an antidote >> >> http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi In other words, software that was developed at Symbolics was not given way for free to LMI. Is that so surprising? Which is conceding Stallman?s point. Anyway, that wasn?t Symbolics?s ?plan?; it was part of the MIT licensing agreement, the very same one that LMI signed. LMI?s changes were all proprietary to LMI, too. I don?t understand this bit. The only ?MIT licensing agreement? I?m aware off _allows_ you to redistribute your copies without the source, but doesn?t _require_ it. From dak at gnu.org Sun Jul 18 03:27:40 2010 From: dak at gnu.org (David Kastrup) Date: Sun, 18 Jul 2010 09:27:40 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> Message-ID: <87wrstgsgj.fsf@lola.goethe.zz> Emmy Noether writes: >> Some entity, AKA David Kastrup , >> wrote this mindboggling stuff: >> (selectively-snipped-or-not-p) > >>>> Software is a puzzle and it must be explained to be able to do that, >>>> its like a lock > >>> There is no unfreedom involved here. ?Freedom does not hand you a free >>> ride. ?Only a free road. > > No one asks for a free ride. A free road is good enough. Obviously you don't understand what you are talking about. > Perhaps we do the same to him and break into his FSF office and leave > a "friend" note we came to get the docs he has not released. You can't "get" anything that has not been written. > The concise answer: We want a free road but not a free puzzle. You have the freedom to walk the forest you perceive. You have the freedom to build the road that you want, in that forest. If it is a puzzle to you, that is your own problem. It is not a puzzle because somebody would have cut a whole into pieces and scattered them around. It is a puzzle because nobody put it together yet. Feel free to do so, doing others the service you want done. > Now, dont run away from this argument and bring each and every of the > boys from his mailing list to tackle this question. He is a manager > and he can put the volunteers to the task of documenting, illuminating > and revealing the operation of his softwares and its evolution. You want a free ride, very obviously. > He owes it to others And you think your whining entitles you to it. What did you ever do to _deserve_ others working for you? -- David Kastrup From j.kleese at arcor.de Sun Jul 18 03:49:24 2010 From: j.kleese at arcor.de (Johannes Kleese) Date: Sun, 18 Jul 2010 09:49:24 +0200 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> On 18.07.2010 08:09, geremy condra wrote: > On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet > wrote: >> in in a social group by sharing that group's behavior and values. This >> instinct is possibly stronger than the sex drive, e.g., wars are seldom >> fought over sex ("surrender, and give us sex!", no, that's not it, it's >> "surrender, and become part of us!"). > > Helen of Troy begs to differ. Britney Spears, too. From mad.mick at gmx.de Sun Jul 18 04:09:17 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Sun, 18 Jul 2010 10:09:17 +0200 Subject: Code generator and visitor pattern In-Reply-To: References: Message-ID: Mark Lawrence wrote: > On 17/07/2010 20:38, Mick Krippendorf wrote: >> >> If Java were *really* a multiple dispatch language, it wouldn't be >> necessary to repeat the accept-code for every subclass. Instead a single >> accept method in the base class would suffice. In fact, with true >> multiple dispatch VP wouldn't even be needed. > > Boilerplate, boilerplate everywhere, but not a beer to drink. That's Java for ya. class ASTNode: def accept(self, visitor): getattr(visitor, self.__class__.__name__)(self) class IfNode(ASTNode): ... # inherits generic accept method class ElseNode(ASTNode): ... # inherits generic accept method class PrettyPrinter: def IfNode(self, node): ... def ElseNode(self, node): ... Regards, Mick. From 3-nospam at temporary-address.org.uk Sun Jul 18 04:09:34 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Sun, 18 Jul 2010 09:09:34 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> Message-ID: <87iq4dmcsh.fsf@temporary-address.org.uk> Emmy Noether writes: > On Jul 7, 1:57?pm, bolega wrote: >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> Enjoy ..... > > In this video, Stall man makes 4 promises to public but stalls on 2nd > of them. I have no idea of the rights or wrongs of this case. But I've found through experience that when someone uses a "witty" misspelling of someone's name, they are almost always the one in the wrong. 5 lines in and here we are - so if your case has merit, think about whether you want to do this. BTW - Did you see what I did there? I snipped all the rest of the post as it wasn't relevant. I know several people have asked you to do it, but you seem to be having difficulty with the concept, so I thought I'd give you a practical example. -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From emmynoether3 at gmail.com Sun Jul 18 04:23:47 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sun, 18 Jul 2010 01:23:47 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> Message-ID: <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> On Jul 18, 12:27?am, David Kastrup wrote: > Emmy Noether writes: > >> Some entity, AKA David Kastrup , > >> wrote this mindboggling stuff: > >> (selectively-snipped-or-not-p) > > >>>> Software is a puzzle and it must be explained to be able to do that, > >>>> its like a lock > > >>> There is no unfreedom involved here. ?Freedom does not hand you a free > >>> ride. ?Only a free road. > > > No one asks for a free ride. A free road is good enough. > > Obviously you don't understand what you are talking about. > > > Perhaps we do the same to him and break into his FSF office and leave > > a "friend" note we came to get the docs he has not released. > > You can't "get" anything that has not been written. > > > The concise answer: We want a free road but not a free puzzle. > > You have the freedom to walk the forest you perceive. ?You have the > freedom to build the road that you want, in that forest. > > If it is a puzzle to you, that is your own problem. ?It is not a puzzle > because somebody would have cut a whole into pieces and scattered them > around. ?It is a puzzle because nobody put it together yet. > > Feel free to do so, doing others the service you want done. > > > Now, dont run away from this argument and bring each and every of the > > boys from his mailing list to tackle this question. He is a manager > > and he can put the volunteers to the task of documenting, illuminating > > and revealing the operation of his softwares and its evolution. > > You want a free ride, very obviously. > > > He owes it to others > > And you think your whining entitles you to it. By his own admission he broke into professor's offices to help others, ie unlock the monitors. He has tried to project an image of a saint for freedom. Its a DECEPTION. A scoundrel has a right to be scoundrel. But if he projects himself as a saint, then people have a right to clear the facts. > What did you ever do to _deserve_ others working for you? What did we do to deserve him to write that elisp manual of 800+ pages ? NOTHING. He gave it to us in the hope that his software will spread like a VIRUS. He had hopes for money from big companies probably, which he must be making to pay the astronomical rent in tbe boston/cambridge area. I can assure you that he can document all the essentials of his program in a thin book of a few hundred pages with a trivial amount of man-hours compared to being spent on things which brings fewer volunteers. It is said : A picture is worth a thousand words. Make some transition diagrams, structures, and UML type diagrams of the operation of the software. > What did you ever do to _deserve_ others working for you? Draw a diagram, A state transition diagram to understand how illogical you are. A person arrives in the state of a newbie and wants to exit in a state of having made a contribution to FSF. How can one do it without adequate documentation ? Xah Lee has been complaining for a year. First you deprive people of ESSENTIAL documentation to contribute. Stall man has written user manuals to effect viral spread. But he has not written operational details to get the same viral contribution by others. He must not want it. Yet you want to use it as a taunt as in pot calling the kettle black ???!!! OK, why dont you explain a few basic things, if it not a puzzle ????!!!! DEFUN ("or", For, Sor, 0, UNEVALLED, 0, "Eval args until one of them yields non-NIL, then return that value. \n\ The remaining args are not evalled at all.\n\ If all args return NIL, return NIL.") (args) Lisp_Object args; { register Lisp_Object val; Lisp_Object args_left; struct gcpro gcpro1; if (NULL(args)) return Qnil; args_left = args; GCPRO1 (args_left); do { val = Feval (Fcar (args_left)); if (!NULL (val)) break; args_left = Fcdr (args_left); } while (!NULL(args_left)); UNGCPRO; return val; } I saw that on comp.lang.c and found no one capable of explaining it. And where does the manual explain the C struct or ADT of the basic cons cell ? which file has the definition ? where is his eval_quote function definition ? Basically, Richard Mathew Stall man is a STALLER of PROGRESS. He expected the XEMACS people to EXPLAIN HIM EVERY SINGLE line of code. What did he do to expect all this ? He was even paid money , as claimed by the XEMACS people. What did he do to deserve and EXPECT a line by line explanation from them ?????!!!!!! ANSWER this question and dont run away !!!!!! He is prone to forgetting like all mortals and if he is prolific to write that 900 page manual, I am sure he has hidden notes that he has not released. Where was he recording the line by line explanation he was receiving from the XEMACS people ? If not in his own very personal version ??? Answer these very strong arguments ??? What did he deserve to get the XEMACS people's explanations ? AND why is he INCAPABLE of building upon the XEMACS work ??? This is all about documentation, professional jealousies of these mean spirited people with double standards. Send him a CC of this thread. I expect him to explain some of these issues of documentation. > -- > David Kastrup From emmynoether3 at gmail.com Sun Jul 18 04:38:15 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sun, 18 Jul 2010 01:38:15 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: > Emmy Noether writes: > > On Jul 7, 1:57?pm, bolega wrote: > >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr > > >> Enjoy ..... > > > In this video, Stall man makes 4 promises to public but stalls on 2nd > > of them. > > I have no idea of the rights or wrongs of this case. ?But I've found > through experience that when someone uses a "witty" misspelling of > someone's name, they are almost always the one in the wrong. ? Huh, you forgot that the whole of GNU = Gnu Not Unix You have double standard and you know very well whats right and whats wrong. > 5 lines in > and here we are - so if your case has merit, think about whether you > want to do this. > > BTW - Did you see what I did there? ?I snipped all the rest of the post > as it wasn't relevant. ?I know several people have asked you to do it, > but you seem to be having difficulty with the concept, so I thought I'd > give you a practical example. > -- > Online waterways route planner ? ? ? ? ? ?|http://canalplan.eu > Plan trips, see photos, check facilities ?|http://canalplan.org.uk From jcb at inf.ed.ac.uk Sun Jul 18 04:50:32 2010 From: jcb at inf.ed.ac.uk (Julian Bradfield) Date: Sun, 18 Jul 2010 08:50:32 +0000 (UTC) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> Message-ID: On 2010-07-18, Emmy Noether wrote: > DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > "Eval args until one of them yields non-NIL, then return that value. > \n\ > The remaining args are not evalled at all.\n\ > If all args return NIL, return NIL.") > (args) > Lisp_Object args; > { > register Lisp_Object val; > Lisp_Object args_left; > struct gcpro gcpro1; > > if (NULL(args)) > return Qnil; > > args_left = args; > GCPRO1 (args_left); > > do > { > val = Feval (Fcar (args_left)); > if (!NULL (val)) > break; > args_left = Fcdr (args_left); > } > while (!NULL(args_left)); > > UNGCPRO; > return val; > } > > I saw that on comp.lang.c and found no one capable of explaining it. What do you need explained? Other than what's already in the manual (Gnu Emacs Internals section of the Elisp manual.) > And where does the manual explain the C struct or ADT of the basic > cons cell ? which file has the definition ? where is his eval_quote > function definition ? Try lisp.h RMS doesn't really believe in ADTs - that's one of the main complaints from XEmacs. As for finding functions, I believe Emacs has commands to help with that, but personally I just go grep eval_quote *.c From 3-nospam at temporary-address.org.uk Sun Jul 18 05:30:29 2010 From: 3-nospam at temporary-address.org.uk (Nick) Date: Sun, 18 Jul 2010 10:30:29 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <87aappm91m.fsf@temporary-address.org.uk> Emmy Noether writes: > On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: >> Emmy Noether writes: >> > On Jul 7, 1:57?pm, bolega wrote: >> >> "Democracy is sick in the US, government monitors your Internet"http://www.youtube.com/watch?v=2BfCJq_zIdk&feature=fvsr >> >> >> Enjoy ..... >> >> > In this video, Stall man makes 4 promises to public but stalls on 2nd >> > of them. >> >> I have no idea of the rights or wrongs of this case. ?But I've found >> through experience that when someone uses a "witty" misspelling of >> someone's name, they are almost always the one in the wrong. ? > > Huh, you forgot that the whole of GNU = Gnu Not Unix > > You have double standard and you know very well whats right and whats > wrong. Ah. I see. You know my thoughts better than I do. That means you're another nutter. What I wrote was entirely true - I haven't read these great long posts in any detail. I've just deleted your email unread and plonked you. -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk From thomas at jollans.com Sun Jul 18 06:55:17 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 12:55:17 +0200 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <1279335551.5281.1385300137@webmail.messagingengine.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com> <1279335551.5281.1385300137@webmail.messagingengine.com> Message-ID: <4C42DD95.8050802@jollans.com> On 07/17/2010 04:59 AM, python at bdurham.com wrote: > Tim, > >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm In slightly related news, I just stumbled upon this: http://catb.org/esr/jargon/html/story-of-mel.html Now of course, he had it tough. From news1234 at free.fr Sun Jul 18 07:18:10 2010 From: news1234 at free.fr (News123) Date: Sun, 18 Jul 2010 13:18:10 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> Message-ID: <4c42e2f2$0$20937$426a74cc@news.free.fr> Mark Lawrence wrote: > On 17/07/2010 23:17, MRAB wrote: >> Chris Rebert wrote: >>> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >>> wrote: >>>> Jason Friedman wrote: >>> >>> It's a pity that str.strip() doesn't actually take a set() of length-1 >>> strings, which would make its behavior more obvious and cut down on >>> this perennial question. >>> >> Even better, a set (or tuple) of strings. It's the kind of thing that >> could've been done in Python 3, with Python 2's .strip(string) becoming >> .strip(set(string)), but it didn't occur to me until too late. :-( > > Maybe 3.2 which is still in alpha, if not 3.3? > > Kindest regards. > > Mark Lawrence. > It could even be introduced without breaking compatibility. if being defined as str.rstrip([iterable]) so you could either call string.rstrip( [ '-dir' ] ) or as string.rstrip( '-dir' ) However I wouldn't be sure, that it really reduces the amount of questions being asked. In order to reduce the ambiguities one had to have two distinct functions. If one wouldn't want to break backwards-compatibility, then the new names would be for stripping off prefixes / suffixes and could be str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) I'd love to have this functionality, though I can live with importing my self written function. From rui.vapps at gmail.com Sun Jul 18 07:36:24 2010 From: rui.vapps at gmail.com (Ray) Date: Sun, 18 Jul 2010 04:36:24 -0700 (PDT) Subject: create dynamic instance References: Message-ID: <3ce37b9c-4e0c-42da-9b82-e07986658bcf@c36g2000prf.googlegroups.com> thanks a lot. I was really stupid. of course I should keep a references to use it later. From thomas at jollans.com Sun Jul 18 07:42:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 13:42:15 +0200 Subject: rstrip() In-Reply-To: <4c42e2f2$0$20937$426a74cc@news.free.fr> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> Message-ID: <4C42E897.5090103@jollans.com> On 07/18/2010 01:18 PM, News123 wrote: > Mark Lawrence wrote: >> On 17/07/2010 23:17, MRAB wrote: >>> Chris Rebert wrote: >>>> On Fri, Jul 16, 2010 at 10:27 AM, MRAB >>>> wrote: >>>>> Jason Friedman wrote: >>>> >>>> It's a pity that str.strip() doesn't actually take a set() of length-1 >>>> strings, which would make its behavior more obvious and cut down on >>>> this perennial question. >>>> >>> Even better, a set (or tuple) of strings. It's the kind of thing that >>> could've been done in Python 3, with Python 2's .strip(string) becoming >>> .strip(set(string)), but it didn't occur to me until too late. :-( >> >> Maybe 3.2 which is still in alpha, if not 3.3? >> >> Kindest regards. >> >> Mark Lawrence. >> > > It could even be introduced without breaking compatibility. > > if being defined as > str.rstrip([iterable]) > so you could either call > string.rstrip( [ '-dir' ] ) > or as > string.rstrip( '-dir' ) The former should certainly raise an exception. '-dir' is not a single character ! Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but that's just silly. > > > However I wouldn't be sure, that it really reduces the amount of > questions being asked. > > In order to reduce the ambiguities one had to have two distinct functions. > If one wouldn't want to break backwards-compatibility, then the new > names would be for stripping off prefixes / suffixes and could be > str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) > > > I'd love to have this functionality, though I can live with importing my > self written function. From rjh at see.sig.invalid Sun Jul 18 07:48:30 2010 From: rjh at see.sig.invalid (Richard Heathfield) Date: Sun, 18 Jul 2010 12:48:30 +0100 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <6MOdnZERJ9-Zd9_RnZ2dnUVZ7rSdnZ2d@bt.com> Emmy Noether wrote: > On Jul 18, 1:09 am, Nick <3-nos... at temporary-address.org.uk> wrote: >> Emmy Noether writes: >>> On Jul 7, 1:57 pm, bolega wrote: >>> In this video, Stall man makes 4 promises to public but stalls on 2nd >>> of them. >> I have no idea of the rights or wrongs of this case. But I've found >> through experience that when someone uses a "witty" misspelling of >> someone's name, they are almost always the one in the wrong. > > Huh, you forgot that the whole of GNU = Gnu Not Unix > > You have double standard and you know very well whats right and whats > wrong. If you must be an idiot, that's entirely up to you, but I would take it as a personal favour if you could be an idiot *somewhere else*. If you don't like GNU software, fine - don't use it. End of problem. -- Richard Heathfield Email: -http://www. +rjh@ "Usenet is a strange place" - dmr 29 July 1999 Sig line vacant - apply within From news1234 at free.fr Sun Jul 18 10:17:45 2010 From: news1234 at free.fr (News123) Date: Sun, 18 Jul 2010 16:17:45 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> Message-ID: <4c430d0a$0$20945$426a74cc@news.free.fr> Thomas Jollans wrote: > > >> string.rstrip( [ '-dir' ] ) >> or as >> string.rstrip( '-dir' ) > > The former should certainly raise an exception. '-dir' is not a single > character ! > Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but > that's just silly. > It's silly with the example of '-dir' it's much less silly with a string like ' \t'. The doc is rather clear about it: str.rstrip([chars]) It is marked 'chars' and not 'suffix' The textual description is even clearer: "The chars argument is not a suffix; rather, all combinations of its values are stripped:" When I asked in this grpup about a way of how to strip off a prefix I never even considered strip as a solution having read the doc before. I also think, that the functionality of strip / rstrip is useful as is. It would just be great to have functions to strip prefixes/suffixes. If these new commands were alphabetically next to the classic commands, ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for string functions would probably use the function, which is appropriate for his purpose. Breaking backwardscompatibility within python 3 might not be the best choice. >> However I wouldn't be sure, that it really reduces the amount of >> questions being asked. >> >> In order to reduce the ambiguities one had to have two distinct functions. >> If one wouldn't want to break backwards-compatibility, then the new >> names would be for stripping off prefixes / suffixes and could be >> str.strip_prefix(prefixes) / str.rstrip_suffix(suffixes) >> >> >> I'd love to have this functionality, though I can live with importing my >> self written function. > From dak at gnu.org Sun Jul 18 10:53:53 2010 From: dak at gnu.org (David Kastrup) Date: Sun, 18 Jul 2010 16:53:53 +0200 Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> Message-ID: <87oce4hmda.fsf@lola.goethe.zz> Emmy Noether writes: > On Jul 18, 12:27?am, David Kastrup wrote: > >> What did you ever do to _deserve_ others working for you? > > What did we do to deserve him to write that elisp manual of 800+ > pages ? NOTHING. So once one gives you something, you demand everything? > He gave it to us in the hope that his software will spread like a > VIRUS. Yup. It is called "culture". It is _supposed_ to spread exponentially. That's what the peculiar brain structure of humans is good for. Communicating knowledge instead of inheriting it. That's the fundamental advantage we have over other animals. Not something lightly given up. > A person arrives in the state of a newbie and wants to exit in a state > of having made a contribution to FSF. That's the problem of the person. It has not been a goal of the GNU project to turn every person into somebody useful. They have the freedom to try, getting everything for their start that anybody else has available. > How can one do it without adequate documentation ? Emacs development is active, so there are people considering the documentation adequate for starting to work on Emacs. > Xah Lee has been complaining for a year. First you deprive people of > ESSENTIAL documentation to contribute. You can't "deprive" anybody of anything that is not there to start with. > DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > "Eval args until one of them yields non-NIL, then return that value. > \n\ > The remaining args are not evalled at all.\n\ > If all args return NIL, return NIL.") > (args) > Lisp_Object args; > { > register Lisp_Object val; > Lisp_Object args_left; > struct gcpro gcpro1; > > if (NULL(args)) > return Qnil; > > args_left = args; > GCPRO1 (args_left); > > do > { > val = Feval (Fcar (args_left)); > if (!NULL (val)) > break; > args_left = Fcdr (args_left); > } > while (!NULL(args_left)); > > UNGCPRO; > return val; > } > > I saw that on comp.lang.c and found no one capable of explaining it. If you see other context-free stuff on comp.lang.c, the situation will not be different. The above code is rather trivial. But you'll find the respective parts explained in the Emacs Lisp manual. In fact, the above is likely extracted from exactly there, from (info "(elisp) Writing Emacs Primitives") I append the whole at the bottom to not interrupt the flow of non-thought. > And where does the manual explain the C struct or ADT of the basic > cons cell ? which file has the definition ? where is his eval_quote > function definition ? eval_quote? What's that? > Basically, Richard Mathew Stall man is a STALLER of PROGRESS. He > expected the XEMACS people to EXPLAIN HIM EVERY SINGLE line of code. > What did he do to expect all this ? He was the maintainer of upstream Emacs, and it was his decision what code was going there. And he had to keep maintainability in mind. Something which was less of a priority with XEmacs developers, and likely part of the reason that they are running out of fresh blood much worse than Emacs these days. > He was even paid money , as claimed by the XEMACS people. > > What did he do to deserve and EXPECT a line by line explanation from > them ?????!!!!!! ANSWER this question and dont run away !!!!!! There was nothing to "deserve". It was his job to keep Emacs going forward, and his opinion and decision that throwing the Lucid Emacs code in would not have been good in the long run. It has not been good for XEmacs in the long run. Whether it would have been better or worse for a grand unified Emacs, noone will ever know. He decided to play it safe given the information he had at that time, and Emacs is still there and going forward. In spite of trolls like you spouting abuse by the hundreds. More than can be said for many other projects. File: elisp, Node: Writing Emacs Primitives, Next: Object Internals, Prev: Memory Usage, Up: GNU Emacs Internals E.5 Writing Emacs Primitives ============================ Lisp primitives are Lisp functions implemented in C. The details of interfacing the C function so that Lisp can call it are handled by a few C macros. The only way to really understand how to write new C code is to read the source, but we can explain some things here. An example of a special form is the definition of `or', from `eval.c'. (An ordinary function would have the same general appearance.) DEFUN ("or", For, Sor, 0, UNEVALLED, 0, doc: /* Eval args until one of them yields non-nil, then return that value. The remaining args are not evalled at all. If all args return nil, return nil. usage: (or CONDITIONS ...) */) (Lisp_Object args) { register Lisp_Object val = Qnil; struct gcpro gcpro1; GCPRO1 (args); while (CONSP (args)) { val = Feval (XCAR (args)); if (!NILP (val)) break; args = XCDR (args); } UNGCPRO; return val; } Let's start with a precise explanation of the arguments to the `DEFUN' macro. Here is a template for them: DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC) LNAME This is the name of the Lisp symbol to define as the function name; in the example above, it is `or'. FNAME This is the C function name for this function. This is the name that is used in C code for calling the function. The name is, by convention, `F' prepended to the Lisp name, with all dashes (`-') in the Lisp name changed to underscores. Thus, to call this function from C code, call `For'. Remember that the arguments must be of type `Lisp_Object'; various macros and functions for creating values of type `Lisp_Object' are declared in the file `lisp.h'. SNAME This is a C variable name to use for a structure that holds the data for the subr object that represents the function in Lisp. This structure conveys the Lisp symbol name to the initialization routine that will create the symbol and store the subr object as its definition. By convention, this name is always FNAME with `F' replaced with `S'. MIN This is the minimum number of arguments that the function requires. The function `or' allows a minimum of zero arguments. MAX This is the maximum number of arguments that the function accepts, if there is a fixed maximum. Alternatively, it can be `UNEVALLED', indicating a special form that receives unevaluated arguments, or `MANY', indicating an unlimited number of evaluated arguments (the equivalent of `&rest'). Both `UNEVALLED' and `MANY' are macros. If MAX is a number, it may not be less than MIN and it may not be greater than eight. INTERACTIVE This is an interactive specification, a string such as might be used as the argument of `interactive' in a Lisp function. In the case of `or', it is 0 (a null pointer), indicating that `or' cannot be called interactively. A value of `""' indicates a function that should receive no arguments when called interactively. If the value begins with a `(', the string is evaluated as a Lisp form. DOC This is the documentation string. It uses C comment syntax rather than C string syntax because comment syntax requires nothing special to include multiple lines. The `doc:' identifies the comment that follows as the documentation string. The `/*' and `*/' delimiters that begin and end the comment are not part of the documentation string. If the last line of the documentation string begins with the keyword `usage:', the rest of the line is treated as the argument list for documentation purposes. This way, you can use different argument names in the documentation string from the ones used in the C code. `usage:' is required if the function has an unlimited number of arguments. All the usual rules for documentation strings in Lisp code (*note Documentation Tips::) apply to C code documentation strings too. After the call to the `DEFUN' macro, you must write the argument list that every C function must have, including the types for the arguments. For a function with a fixed maximum number of arguments, declare a C argument for each Lisp argument, and give them all type `Lisp_Object'. When a Lisp function has no upper limit on the number of arguments, its implementation in C actually receives exactly two arguments: the first is the number of Lisp arguments, and the second is the address of a block containing their values. They have types `int' and `Lisp_Object *'. Within the function `For' itself, note the use of the macros `GCPRO1' and `UNGCPRO'. `GCPRO1' is used to "protect" a variable from garbage collection--to inform the garbage collector that it must look in that variable and regard its contents as an accessible object. GC protection is necessary whenever you call `Feval' or anything that can directly or indirectly call `Feval'. At such a time, any Lisp object that this function may refer to again must be protected somehow. It suffices to ensure that at least one pointer to each object is GC-protected; that way, the object cannot be recycled, so all pointers to it remain valid. Thus, a particular local variable can do without protection if it is certain that the object it points to will be preserved by some other pointer (such as another local variable which has a `GCPRO')(1). Otherwise, the local variable needs a `GCPRO'. The macro `GCPRO1' protects just one local variable. If you want to protect two variables, use `GCPRO2' instead; repeating `GCPRO1' will not work. Macros `GCPRO3', `GCPRO4', `GCPRO5', and `GCPRO6' also exist. All these macros implicitly use local variables such as `gcpro1'; you must declare these explicitly, with type `struct gcpro'. Thus, if you use `GCPRO2', you must declare `gcpro1' and `gcpro2'. Alas, we can't explain all the tricky details here. `UNGCPRO' cancels the protection of the variables that are protected in the current function. It is necessary to do this explicitly. Built-in functions that take a variable number of arguments actually accept two arguments at the C level: the number of Lisp arguments, and a `Lisp_Object *' pointer to a C vector containing those Lisp arguments. This C vector may be part of a Lisp vector, but it need not be. The responsibility for using `GCPRO' to protect the Lisp arguments from GC if necessary rests with the caller in this case, since the caller allocated or found the storage for them. You must not use C initializers for static or global variables unless the variables are never written once Emacs is dumped. These variables with initializers are allocated in an area of memory that becomes read-only (on certain operating systems) as a result of dumping Emacs. *Note Pure Storage::. Do not use static variables within functions--place all static variables at top level in the file. This is necessary because Emacs on some operating systems defines the keyword `static' as a null macro. (This definition is used because those systems put all variables declared static in a place that becomes read-only after dumping, whether they have initializers or not.) Defining the C function is not enough to make a Lisp primitive available; you must also create the Lisp symbol for the primitive and store a suitable subr object in its function cell. The code looks like this: defsubr (&SUBR-STRUCTURE-NAME); Here SUBR-STRUCTURE-NAME is the name you used as the third argument to `DEFUN'. If you add a new primitive to a file that already has Lisp primitives defined in it, find the function (near the end of the file) named `syms_of_SOMETHING', and add the call to `defsubr' there. If the file doesn't have this function, or if you create a new file, add to it a `syms_of_FILENAME' (e.g., `syms_of_myfile'). Then find the spot in `emacs.c' where all of these functions are called, and add a call to `syms_of_FILENAME' there. The function `syms_of_FILENAME' is also the place to define any C variables that are to be visible as Lisp variables. `DEFVAR_LISP' makes a C variable of type `Lisp_Object' visible in Lisp. `DEFVAR_INT' makes a C variable of type `int' visible in Lisp with a value that is always an integer. `DEFVAR_BOOL' makes a C variable of type `int' visible in Lisp with a value that is either `t' or `nil'. Note that variables defined with `DEFVAR_BOOL' are automatically added to the list `byte-boolean-vars' used by the byte compiler. If you define a file-scope C variable of type `Lisp_Object', you must protect it from garbage-collection by calling `staticpro' in `syms_of_FILENAME', like this: staticpro (&VARIABLE); Here is another example function, with more complicated arguments. This comes from the code in `window.c', and it demonstrates the use of macros and functions to manipulate Lisp objects. DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, Scoordinates_in_window_p, 2, 2, "xSpecify coordinate pair: \nXExpression which evals to window: ", "Return non-nil if COORDINATES is in WINDOW.\n\ COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ ... If they are on the border between WINDOW and its right sibling,\n\ `vertical-line' is returned.") (coordinates, window) register Lisp_Object coordinates, window; { int x, y; CHECK_LIVE_WINDOW (window, 0); CHECK_CONS (coordinates, 1); x = XINT (Fcar (coordinates)); y = XINT (Fcdr (coordinates)); switch (coordinates_in_window (XWINDOW (window), &x, &y)) { case 0: /* NOT in window at all. */ return Qnil; case 1: /* In text part of window. */ return Fcons (make_number (x), make_number (y)); case 2: /* In mode line of window. */ return Qmode_line; case 3: /* On right border of window. */ return Qvertical_line; default: abort (); } } Note that C code cannot call functions by name unless they are defined in C. The way to call a function written in Lisp is to use `Ffuncall', which embodies the Lisp function `funcall'. Since the Lisp function `funcall' accepts an unlimited number of arguments, in C it takes two: the number of Lisp-level arguments, and a one-dimensional array containing their values. The first Lisp-level argument is the Lisp function to call, and the rest are the arguments to pass to it. Since `Ffuncall' can call the evaluator, you must protect pointers from garbage collection around the call to `Ffuncall'. The C functions `call0', `call1', `call2', and so on, provide handy ways to call a Lisp function conveniently with a fixed number of arguments. They work by calling `Ffuncall'. `eval.c' is a very good file to look through for examples; `lisp.h' contains the definitions for some important macros and functions. If you define a function which is side-effect free, update the code in `byte-opt.el' which binds `side-effect-free-fns' and `side-effect-and-error-free-fns' so that the compiler optimizer knows about it. ---------- Footnotes ---------- (1) Formerly, strings were a special exception; in older Emacs versions, every local variable that might point to a string needed a `GCPRO'. > He is prone to forgetting like all mortals and if he is prolific to > write that 900 page manual, I am sure he has hidden notes that he has > not released. Where was he recording the line by line explanation he > was receiving from the XEMACS people ? If not in his own very personal > version ??? What makes you think he received any such explanation? Why would not the XEmacs people, after writing such explanations, put them in their own code and manuals? Your conspiracy theories just stink. > Answer these very strong arguments ??? Ok, so they stink strongly. > What did he deserve to get the XEMACS people's explanations ? AND why > is he INCAPABLE of building upon the XEMACS work ??? This is all about > documentation, professional jealousies of these mean spirited people > with double standards. Send him a CC of this thread. I expect him to > explain some of these issues of documentation. I quoted the above part from the documentation. I do not consider this sort of shit worth his attention and certainly won't forward it, lending it credibility. It is not like he has a secret Email address or something. I should hope he would have the prudence to just throw crap like the above away should he receive it from some anonymous idiot not willing to sign his name under his brain farts. -- David Kastrup From clp2 at rebertia.com Sun Jul 18 11:35:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Jul 2010 08:35:41 -0700 Subject: why is this group being spammed? In-Reply-To: <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <4c42b200$0$6986$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On Sun, Jul 18, 2010 at 12:49 AM, Johannes Kleese wrote: > On 18.07.2010 08:09, geremy condra wrote: >> On Sat, Jul 17, 2010 at 10:57 PM, Alf P. Steinbach /Usenet >> wrote: > >>> in in a social group by sharing that group's behavior and values. This >>> instinct is possibly stronger than the sex drive, e.g., wars are seldom >>> fought over sex ("surrender, and give us sex!", no, that's not it, it's >>> "surrender, and become part of us!"). >> >> Helen of Troy begs to differ. > > Britney Spears, too. Sorry, which war was that again? Cheers, Chris From python at bdurham.com Sun Jul 18 12:45:00 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 12:45:00 -0400 Subject: Is '[' a function or an operator or an language feature? In-Reply-To: <4C42DD95.8050802@jollans.com> References: <4C4110A8.8040406@mrabarnett.plus.com> <4C41140D.4010001@tim.thechases.com><1279335551.5281.1385300137@webmail.messagingengine.com> <4C42DD95.8050802@jollans.com> Message-ID: <1279471500.17203.1385458203@webmail.messagingengine.com> Thomas, > In slightly related news, I just stumbled upon this: > http://catb.org/esr/jargon/html/story-of-mel.html > > Now of course, he had it tough. Tough??? Well we had it tough. Our computers[1][2] had 0 bytes of RAM and 0 bytes of ROM. We had to hand wire our logic and physically push data through logic gates without the benefit of transistors. We used to have to get up out of the shoebox at twelve o'clock at night, and LICK the road clean with our tongues. We had half a handful of freezing cold gravel, worked twenty-four hours a day at the mill for fourpence every six years, and when we got home, our Dad would slice us in two with a bread knife. Malcolm [1] http://totallytrygve.com/computer.php?item=188&picture=0 [2] I learned about computers through one of these kits. When I first stumbled across assembly language (6502), my first thought was, "wow, this is so much easier than what I've been doing"! >> 2.x?! You were lucky. We lived for three months with Python 1.x in a septic tank. We used to have to get up at six in the morning, write our 1.x code using ed, eat a crust of stale bread, go to work down in machine language, fourteen hours a day, > week-in week-out, for sixpence a week, and when we got home our Dad > would thrash us to sleep wi' his belt... > > Luxury. Our computers only had 256 bytes[1] of RAM and We had to enter > our code, in the dark, using loose binary toggle switches with poor > connections. We used to have to get out of the lake at three o'clock in > the morning, clean the lake, eat a handful of hot gravel, go to work at > the mill every day for tuppence a month, come home, and Dad would beat > us around the head and neck with a broken bottle, if we were LUCKY! > > [1] http://incolor.inebraska.com/bill_r/elf/html/elf-1-33.htm In slightly related news, I just stumbled upon this: http://catb.org/esr/jargon/html/story-of-mel.html Now of course, he had it tough. From python at mrabarnett.plus.com Sun Jul 18 12:49:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 18 Jul 2010 17:49:11 +0100 Subject: rstrip() In-Reply-To: <4c430d0a$0$20945$426a74cc@news.free.fr> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> Message-ID: <4C433087.8090403@mrabarnett.plus.com> News123 wrote: > Thomas Jollans wrote: > >> >>> string.rstrip( [ '-dir' ] ) >>> or as >>> string.rstrip( '-dir' ) >> The former should certainly raise an exception. '-dir' is not a single >> character ! >> Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but >> that's just silly. >> > It's silly with the example of '-dir' it's much less silly with > a string like ' \t'. > > The doc is rather clear about it: > str.rstrip([chars]) > > It is marked 'chars' and not 'suffix' > > The textual description is even clearer: > "The chars argument is not a suffix; rather, all combinations of its > values are stripped:" > > > When I asked in this grpup about a way of how to strip off a prefix I > never even considered strip as a solution having read the doc before. > > I also think, that the functionality of strip / rstrip is useful as is. > > > It would just be great to have functions to strip prefixes/suffixes. > If these new commands were alphabetically next to the classic commands, > ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for > string functions would probably use the function, which is appropriate > for his purpose. > > Breaking backwardscompatibility within python 3 might not be the best > choice. > [snip] How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something similar? From lord at emf.net Sun Jul 18 13:26:50 2010 From: lord at emf.net (Tom Lord) Date: Sun, 18 Jul 2010 10:26:50 -0700 (PDT) Subject: GNU Emacs Developement Inefficiency (commentary) References: <9f509ba3-b39a-46a4-b8ea-9fccdbaa2cd2@t10g2000yqg.googlegroups.com> Message-ID: <26b77eee-6a92-468d-989f-14d443ef45c9@t5g2000prd.googlegroups.com> On Jul 17, 11:11?am, Emmy Noether wrote: > Well, there is a lot of resistance from the emacs community in sharing > information. Richard Stallman is a true STALLER of progress. He has > held the whole process hostage by not sharing information. He has > RENEGED on his promise to make it truly open by suppressing > documentation of his softwares. I used to think similarly but differently. In my case I thought of him as a "STALLER" for not more aggressively changing Emacs to keep up with GUIs, with better languages than elisp, with better ways to implement text buffers, and so forth. One day I woke up and realized: hey, I've been using this same damn program for 15 years (and now, today, more than 20). I use it every day. I'm annoyed on systems that lack it. It satisfies me, as a user, in ways that almost no other program I've used for a long time does. Aha - I realized. He must be doing something right. And it became way more interesting to try to understand what he's doing right than to focus exclusively on what he's doing wrong. On the documentation thing ... well: Stallman's code (and code descended from Stallman's code) tends to annoy me with its sparcity of good commenting, its long, convoluted functions, its sometimes wacky choices of how to structure module dependencies, its horrific approach to portability..... Problem is, though, than when I've had to actually work on any of that code? Yeah, it takes some hours or days of study to puzzle it out - weeks even - but then once you've "got it" you've got it. It's actually fairly lucid in spite of the style. One of the things he does right is not overly documenting the code. First, it's a lot of work. Second, the folks that wind up contributing the most to it learn a lot and learn it well by puzzling it out a bit first on their own. Yes, really. I'm not suggesting weak internals documentation and all the other aspects as a general style that everyone should adapt. I do think it slows some things down. Yet in some cases, like Emacs, .... well, it's hard to argue with success, ain't it? > All Richard Stallman has to do is to hand draw the data-structures and > architecture of the various programs. Give references to the places > where he got the ideas. Isn't that (the drawing) something you could do? As for where he got the ideas: a lot of Emacs architecture is based on common knowledge ideas, some on the order of 40 years old. There's not a lot that isn't original in the core architecture that one would normally want cites about. From thomas at jollans.com Sun Jul 18 13:43:44 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 18 Jul 2010 19:43:44 +0200 Subject: [Python-Dev] Function Operators In-Reply-To: References: Message-ID: <4C433D50.70004@jollans.com> On 07/18/2010 05:52 PM, Reid Kleckner wrote: > Usual disclaimer: python-dev is for the development *of* python, not > *with*. See python-list, etc. Moving to python-list. Please keep discussion there. > > That said, def declares new functions or methods, so you can't put > arbitrary expressions in there like type(f).__mul__ . > > You can usually assign to things like that though, but in this case > you run into trouble, as shown below: > >>>> def func(): pass > ... >>>> type(func) > >>>> def compose(f, g): > ... return lambda x: f(g(x)) > ... >>>> type(func).__mul__ = compose > Traceback (most recent call last): > File "", line 1, in > TypeError: can't set attributes of built-in/extension type 'function' > > As the interpreter says, it doesn't like people mucking with operator > slots on built in types. > > Finally, if you like coding in that very functional style, I'd > recommend Haskell or other ML derived languages. Python doesn't > support that programming style very well by choice. > > Reid > > On Sun, Jul 18, 2010 at 8:34 AM, Christopher Olah > wrote: >> Dear python-dev, >> >> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >> times). I often run into situations in python where such operators >> could result in cleaner code. Eventually, I decided to implement it >> myself and see how it worked in practice. >> >> However, my intuitive implementation [1] doesn't seem to work. In >> particular, despite what it says in function's documentation, function >> does not seem to be in __builtin__. Furthermore, when I try to >> implement this through type(f) (where f is a function) I get invalid >> syntax errors. >> >> I hope I haven't made some trivial error; I'm rather inexperienced as >> a pythonist. >> >> Christopher Olah >> >> >> [1] Sketch: >> >> def __builtin__.function.__mul__(self, f): >> return lambda x: self(f(x)) >> >> def __builtin__.function.__pow__(self, n): >> return lambda x: reduce(lambda a,b: [f for i in range(n)]+[x]) As Reid explained, you can't just muck around with built-in types like that. However, you can "use a different type". If you're not familiar with Python decorators, look them up, and then have a look at this simple implementation of what you were looking for: >>> class mfunc: ... def __init__(self, func): ... self.func = func ... self.__doc__ = func.__doc__ ... self.__name__ = func.__name__ ... def __call__(self, *args, **kwargs): ... return self.func(*args, **kwargs) ... def __mul__(self, f2): ... @mfunc ... def composite(*a, **kwa): ... return self.func(f2(*a, **kwa)) ... return composite ... def __pow__(self, n): ... if n < 1: ... raise ValueError(n) ... elif n == 1: ... return self.func ... else: ... return self * (self ** (n-1)) ... >>> @mfunc ... def square(x): return x*x ... >>> @mfunc ... def twice(x): return 2*x ... >>> (square*twice)(1.5) 9.0 >>> addthree = mfunc(lambda x: x+3) >>> addfifteen = (addthree ** 5) >>> addfifteen(0) 15 >>> From python at bdurham.com Sun Jul 18 13:46:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 13:46:48 -0400 Subject: Print file via file association using os.system or subprocess? (Windows) Message-ID: <1279475208.25344.1385464451@webmail.messagingengine.com> Under Windows: Is there a way to print a file using the file's file extension association using either the os.system or subprocess modules (vs. win32 extensions)? Use case: print PDF or Office documents to default printer without having to distribute win32 extensions. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From christopherolah.co at gmail.com Sun Jul 18 14:48:04 2010 From: christopherolah.co at gmail.com (Christopher Olah) Date: Sun, 18 Jul 2010 14:48:04 -0400 Subject: [Python-Dev] Function Operators In-Reply-To: <4C433D50.70004@jollans.com> References: <4C433D50.70004@jollans.com> Message-ID: Firstly, apologies for posting to the wrong list. Since I was fiddling around with a modification to the language, if the implementation details of something I'd never expect to get accepted, I'd thought python-dev might be appropriate... In retrospect, it is fairly clear that it was the wrong choice. Secondly, the problem with using decorators is that it doesn't make it so that all functions do this by default. If one is going to decorate every function they use/declare, lambdas look preferable. In any case, thank you for your help. Christopher On Sun, Jul 18, 2010 at 1:43 PM, Thomas Jollans wrote: > On 07/18/2010 05:52 PM, Reid Kleckner wrote: >> Usual disclaimer: python-dev is for the development *of* python, not >> *with*. ?See python-list, etc. > > Moving to python-list. Please keep discussion there. > >> >> That said, def declares new functions or methods, so you can't put >> arbitrary expressions in there like type(f).__mul__ . >> >> You can usually assign to things like that though, but in this case >> you run into trouble, as shown below: >> >>>>> def func(): pass >> ... >>>>> type(func) >> >>>>> def compose(f, g): >> ... ? ? return lambda x: f(g(x)) >> ... >>>>> type(func).__mul__ = compose >> Traceback (most recent call last): >> ? File "", line 1, in >> TypeError: can't set attributes of built-in/extension type 'function' >> >> As the interpreter says, it doesn't like people mucking with operator >> slots on built in types. >> >> Finally, if you like coding in that very functional style, I'd >> recommend Haskell or other ML derived languages. ?Python doesn't >> support that programming style very well by choice. >> >> Reid >> >> On Sun, Jul 18, 2010 at 8:34 AM, Christopher Olah >> wrote: >>> Dear python-dev, >>> >>> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >>> times). I often run into situations in python where such operators >>> could result in cleaner code. Eventually, I decided to implement it >>> myself and see how it worked in practice. >>> >>> However, my intuitive implementation [1] doesn't seem to work. In >>> particular, despite what it says in function's documentation, function >>> does not seem to be in __builtin__. Furthermore, when I try to >>> implement this through type(f) (where f is a function) I get invalid >>> syntax errors. >>> >>> I hope I haven't made some trivial error; I'm rather inexperienced as >>> a pythonist. >>> >>> Christopher Olah >>> >>> >>> [1] Sketch: >>> >>> def __builtin__.function.__mul__(self, f): >>> ? ?return lambda x: self(f(x)) >>> >>> def __builtin__.function.__pow__(self, n): >>> ? ?return lambda x: reduce(lambda a,b: [f for i in range(n)]+[x]) > > > As Reid explained, you can't just muck around with built-in types like > that. However, you can "use a different type". > > If you're not familiar with Python decorators, look them up, and then > have a look at this simple implementation of what you were looking for: > >>>> class mfunc: > ... ? ? def __init__(self, func): > ... ? ? ? ? self.func = func > ... ? ? ? ? self.__doc__ = func.__doc__ > ... ? ? ? ? self.__name__ = func.__name__ > ... ? ? def __call__(self, *args, **kwargs): > ... ? ? ? ? return self.func(*args, **kwargs) > ... ? ? def __mul__(self, f2): > ... ? ? ? ? @mfunc > ... ? ? ? ? def composite(*a, **kwa): > ... ? ? ? ? ? ? return self.func(f2(*a, **kwa)) > ... ? ? ? ? return composite > ... ? ? def __pow__(self, n): > ... ? ? ? ? if n < 1: > ... ? ? ? ? ? ? raise ValueError(n) > ... ? ? ? ? elif n == 1: > ... ? ? ? ? ? ? return self.func > ... ? ? ? ? else: > ... ? ? ? ? ? ? return self * (self ** (n-1)) > ... >>>> @mfunc > ... def square(x): return x*x > ... >>>> @mfunc > ... def twice(x): return 2*x > ... >>>> (square*twice)(1.5) > 9.0 >>>> addthree = mfunc(lambda x: x+3) >>>> addfifteen = (addthree ** 5) >>>> addfifteen(0) > 15 >>>> > > > From tjreedy at udel.edu Sun Jul 18 15:10:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Jul 2010 15:10:34 -0400 Subject: [Python-Dev] Function Operators In-Reply-To: <4C433D50.70004@jollans.com> References: <4C433D50.70004@jollans.com> Message-ID: >> Christopher Olah >>> In mathematical notation, f*g = z->f(g(z)) and f^n = f*f*f... (n >>> times). I often run into situations in python where such operators >>> could result in cleaner code. Python has a general mechanism for composing functions to make new functions: the def statement. "z = f*g" is a special case operation combining two compatible one-parameter parameter functions. In Python, it is spelled def z(x): return f(g(x)) The advantage of the latter is that it gives the resulting function object a definition name attached to the function as an attribute, which is important for error tracebacks. This gets to a difference between math and computing. In math, 'z=f*f', if it is not an equality claim ('z==f*g' in Python terms), defines 'z' to mean the *pre-existing*, abstract, attribute-less function that can also be denoted by 'f*g'. In Python (in particular), it would mean "create a *new*, anonymous function object and associate it non-exclusively with 'z'". If f and g are not primitive functions but are compositions themselves, then substituting the composition for g in the composition for f may allow for simplification and greater efficiency. This consideration is irrelevant in math, where computation happens instantaneously, or where f*g is simply a set of ordered pairs, just like f and g (all with instataneous lookup). As for f^n, it is very rare in practice for n to be a fixed value more than 2 or 3. For n==2, f^2 is simply f*f, see above. For n==3, def f3(x): return f(f(f(x))) has the advantage of creating one new function instead of two. I believe larger values of n mostly arise in iteration to a fixed point or until some other stopping point in reached. Terry Jan Reedy From news1234 at free.fr Sun Jul 18 18:10:45 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 00:10:45 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> Message-ID: <4c437be5$0$5702$426a74cc@news.free.fr> MRAB wrote: > News123 wrote: >> Thomas Jollans wrote: >> >>> >>>> string.rstrip( [ '-dir' ] ) >>>> or as >>>> string.rstrip( '-dir' ) >>> The former should certainly raise an exception. '-dir' is not a single >>> character ! >>> Or it should actually strip '-dir', or '-dir-dir', but not 'r--i'... but >>> that's just silly. >>> >> It's silly with the example of '-dir' it's much less silly with >> a string like ' \t'. >> >> The doc is rather clear about it: >> str.rstrip([chars]) >> >> It is marked 'chars' and not 'suffix' >> >> The textual description is even clearer: >> "The chars argument is not a suffix; rather, all combinations of its >> values are stripped:" >> >> >> When I asked in this grpup about a way of how to strip off a prefix I >> never even considered strip as a solution having read the doc before. >> >> I also think, that the functionality of strip / rstrip is useful as is. >> >> >> It would just be great to have functions to strip prefixes/suffixes. >> If these new commands were alphabetically next to the classic commands, >> ( e.g. strip_prefix / rstrip_suffix) then almost everybody looking for >> string functions would probably use the function, which is appropriate >> for his purpose. >> >> Breaking backwardscompatibility within python 3 might not be the best >> choice. >> > [snip] > How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > similar? sounds reasonable to me From sturlamolden at yahoo.no Sun Jul 18 18:18:59 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 18 Jul 2010 15:18:59 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> On 18 Jul, 07:01, "be.krul" wrote: > why is this group being spammed? There used to be bots that issued cancel messages against spam, but I don't think they are actively maintained anymore. From kentilton at gmail.com Sun Jul 18 18:27:26 2010 From: kentilton at gmail.com (Kenneth Tilton) Date: Sun, 18 Jul 2010 18:27:26 -0400 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals In-Reply-To: References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> Message-ID: <4c437fcb$0$31260$607ed4bc@cv.net> Lawrence D'Oliveiro wrote: > In message > , Nick Keighley wrote: > >> On 16 July, 09:24, Mark Tarver wrote: >>> On 15 July, 23:21, bolega wrote: >>> >>>> http://www.gnu.org/philosophy/stallman-kth.html >>>> RMS lecture at KTH (Sweden), 30 October 1986 >> did you really have to post all of this... >> >> >> >>>> read more ?... >> ...oh sorry only about a third of it... > > Still totally unnecessary, though. > >>> Perhaps as an antidote >>> >>> http://danweinreb.org/blog/rebuttal-to-stallmans-story-about-the-formation-of-symbolics-and-lmi > > In other words, software that was developed at Symbolics was not given > way for free to LMI. Is that so surprising? > > Which is conceding Stallman?s point. > > Anyway, that wasn?t Symbolics?s ?plan?; it was part of the MIT licensing > agreement, the very same one that LMI signed. LMI?s changes were all > proprietary to LMI, too. > > I don?t understand this bit. The only ?MIT licensing agreement? I?m aware > off _allows_ you to redistribute your copies without the source, but doesn?t > _require_ it. > > Right, and this "fascinating" and "amazing" and "awesome" post needs only one rejoinder: twenty-four years later all we have is "free as in beer" software being milked by proprietary enterprises. Sadly, they would be more effective and more profitable if RMS had never existed, because then they would be paying fair market price for significantly better proprietary tools driven by the demands of a price/value competitive market. What we do not have is any interesting amount of "free as in speech" software, because no one uses the GPL. The LGPL is Stallman's way of saying, OK, I was wrong. kt -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld From falk at green.rahul.net Sun Jul 18 18:58:45 2010 From: falk at green.rahul.net (Edward A. Falk) Date: Sun, 18 Jul 2010 22:58:45 +0000 (UTC) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: In article <334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, be.krul wrote: >why is this group being spammed? They're *all* being spammed. Why? Because they can, and because Google doesn't care. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From falk at green.rahul.net Sun Jul 18 18:59:54 2010 From: falk at green.rahul.net (Edward A. Falk) Date: Sun, 18 Jul 2010 22:59:54 +0000 (UTC) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: In article , Alf P. Steinbach /Usenet wrote: > >Consider, there would be almost no spam if spamming didn't pay. Or if ISPs refused to tolerate it from their customers. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From breamoreboy at yahoo.co.uk Sun Jul 18 19:08:54 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 19 Jul 2010 00:08:54 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On 18/07/2010 23:58, Edward A. Falk wrote: > In article<334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, > be.krul wrote: >> why is this group being spammed? > > They're *all* being spammed. Why? Because they can, and because Google > doesn't care. > I see little or nothing because I read through gmane.comp.python.general. Kindest regards. Mark Lawrence. From skippy.hammond at gmail.com Sun Jul 18 20:09:42 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 19 Jul 2010 10:09:42 +1000 Subject: Print file via file association using os.system or subprocess? (Windows) In-Reply-To: <1279475208.25344.1385464451@webmail.messagingengine.com> References: <1279475208.25344.1385464451@webmail.messagingengine.com> Message-ID: <4C4397C6.30605@gmail.com> On 19/07/2010 3:46 AM, python at bdurham.com wrote: > Under Windows: Is there a way to print a file using the file's file > extension association using either the os.system or subprocess modules > (vs. win32 extensions)? > Use case: print PDF or Office documents to default printer without > having to distribute win32 extensions. > Thanks, > Malcolm You probably want to use the windows ShellExec function with a 'print' verb. Mark From ethan at stoneleaf.us Sun Jul 18 20:31:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 18 Jul 2010 17:31:58 -0700 Subject: rstrip() In-Reply-To: <4C433087.8090403@mrabarnett.plus.com> References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> <4C433087.8090403@mrabarnett.plus.com> Message-ID: <4C439CFE.6050406@stoneleaf.us> MRAB wrote: > [snip] > How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > similar? +1 on the names ~Ethan~ From python at bdurham.com Sun Jul 18 21:49:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 21:49:27 -0400 Subject: Print file via file association using os.system or subprocess? (Windows) In-Reply-To: <4C4397C6.30605@gmail.com> References: <1279475208.25344.1385464451@webmail.messagingengine.com> <4C4397C6.30605@gmail.com> Message-ID: <1279504167.26700.1385507775@webmail.messagingengine.com> Hi Mark, > You probably want to use the windows ShellExec function with a 'print' verb. Thanks Mark! And cheers for the great win32api library!! I've included a link[1] on how to do this for anyone searching the archives. Malcolm [1] Print via ShellExecute (prints to the user's default printer) http://timgolden.me.uk/python/win32_how_do_i/print.html#shellexecute Example: win32api.ShellExecute( 0, 'print', fileName, None, '.', 0 ) Under Windows: Is there a way to print a file using the file's file extension association using either the os.system or subprocess modules (vs. win32 extensions)? Use case: print PDF or Office documents to default printer without having to distribute win32 extensions. From python at bdurham.com Sun Jul 18 21:51:17 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 18 Jul 2010 21:51:17 -0400 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr><4C433087.8090403@mrabarnett.plus.com> Message-ID: <1279504277.27617.1385508209@webmail.messagingengine.com> And don't forget the oft requested strip_tease(). Malcolm From f2h2d2 at gmail.com Sun Jul 18 23:12:37 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Sun, 18 Jul 2010 20:12:37 -0700 (PDT) Subject: Human Rights In An Islamic State Message-ID: <0b3b2bb8-ad0b-438c-9a78-c8e8339035bd@y11g2000yqm.googlegroups.com> Human Rights In An Islamic State Human Rights In An Islamic State 1. The Security Of Life And Property: In the address which the Prophet delivered on the occasion of the Farewell Hajj, he said: "Your lives and properties are forbidden to one another till you meet your Lord on the Day of Resurrection." The Prophet has also said about the dhimmis (the non-Muslim citizens of the Muslim state): "One who kills a man under covenant (i.e., dhimmi) will not even smell the fragrance of Paradise." 2. The Protection Of Honor: The Holy Quran lays down: "You who believe, do not let one (set of) people make fun of another set." "Do not defame one another." "Do not insult by using nicknames." "Do not backbite or speak ill of one another." (49:11-12) 3. Sanctity And Security Of Private Life: The Quran has laid down the injunction: "Do not spy on one another." (49:12) "Do not enter any houses unless you are sure of their occupant's consent." (24:27) 4. The Security Of Personal Freedom: Islam has laid down the principle that no citizen can be imprisoned unless his guilt has been proven in an open court. To arrest a man only on the basis of suspicion and to throw him into a prison without proper court proceedings and without providing him a reasonable opportunity to produce his defense is not permissible in Islam. 5. The Right To Protest Against Tyranny: Among the rights that Islam has conferred on human beings is the right to protest against government's tyranny. Referring to it the Quran says: "God does not love evil talk in public unless it is by someone who has been injured thereby." (4:148) In Islam, as has been argued earlier, all power and authority belong to God, and with man there is only delegated power which becomes a trust; everyone who becomes a recipient of such a power has to stand in awful reverence before his people toward whom and for whose sake he will be called upon to use these powers. This was acknowledged by Hazrat Abu Bakr who said in his very first address: "Cooperate with me when I am right but correct me when I commit error; obey me so long as I follow the commandments of Allah and His Prophet; but turn away from me when I deviate." 6. Freedom Of Expression: Islam gives the right of freedom of thought and expression to all citizens of the Islamic state on the condition that it should be used for the propagation of virtue and truth and not for spreading evil and wickedness. The Islamic concept of freedom of expression is much superior to the concept prevalent in the West. Under no circumstances would Islam allow evil and wickedness to be propagated. It also does not give anybody the right to use abusive or offensive language in the name of criticism. It was the practice of the Muslims to enquire from the Holy Prophet whether on a certain matter a divine injunction had been revealed to him. If he said that he had received no divine injunction, the Muslims freely expressed their opinion on the matter. 7. Freedom Of Association: Islam has also given people the right to freedom of association and formation of parties or organizations. This right is also subject to certain general rules. 8. Freedom Of Conscience And Conviction: Islam has laid down the injunction: "There should be no coercion in the matter of faith." (2:256) On the contrary, totalitarian societies totally deprive the individuals of their freedom. Indeed, this undue exaltation of the state authority curiously enough postulates a sort of servitude, of slavishness on the part of man. At one time slavery meant total control of man over man - now that type of slavery has been legally abolished but in its place totalitarian societies impose a similar sort of control over individuals. 9. Protection Of Religious Sentiments: Along with the freedom of conviction and freedom of conscience, Islam has given the right to the individual that his religious sentiments will be given due respect and nothing will be said or done which may encroach upon his right. 10. Protection From Arbitrary Imprisonment: Islam also recognizes the right of the individual not to be arrested or imprisoned for the offenses of others. The Holy Quran has laid down this principle clearly: "No bearer of burdens shall be made to bear the burden of another." (35:18) 11. The Right To Basic Necessities of Life: Islam has recognized the right of the needy people for help and assistance to be provided to them: "And in their wealth there is acknowledged right for the needy and the destitute." (51:19) 12. Equality Before Law: Islam gives its citizens the right to absolute and complete equality in the eyes of the law. 13. Rulers Not Above The Law: A woman belonging to a high and noble family was arrested in connection with theft. The case was brought to the Prophet, and it was recommended that she might be spared the punishment of theft. The Prophet replied: "The nations that lived before you were destroyed by God because they punished the common man for their offenses and let their dignitaries go unpunished for their crimes; I swear by Him Who holds my life in His hand that even if Fatima, the daughter of Muhammad, had committed this crime, I would have amputated her hand." 14. The Right To Participate In The Affairs Of State: "And their business is (conducted) through consultation among themselves." (42:38) The "Shura" or the legislative assembly has no other meaning except that the executive head of the government and the members of the assembly should be elected by free and independent choice of the people. Lastly, it is to be made clear that Islam tries to achieve the above mentioned human rights and many others not only by providing certain legal safeguards but mainly by inviting mankind to transcend the lower level of animal life to be able to go beyond the mere ties fostered by the kinship of blood, racial superiority, linguistic arrogance, and economic privileges. It invites mankind to move on to a plane of existence where, by reason of his inner excellence, man can realize the ideal of the Brotherhood of man. From eldiener at tropicsoft.invalid Mon Jul 19 00:53:56 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 00:53:56 -0400 Subject: Difference between import in script and from interpreter Message-ID: In a python script a: from xxx.yyy.zzz import aaa fails with the message: "ImportError: No module named xxx.yyy.zzz" but from within the python interpreter the same line succeeds. What would be the causes of that ? From within the python interpreter I have looked at sys.path and xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am not sure why this is failing within the python script. From steve-REMOVE-THIS at cybersource.com.au Mon Jul 19 01:15:25 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 19 Jul 2010 05:15:25 GMT Subject: Difference between import in script and from interpreter References: Message-ID: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote: > In a python script a: > > from xxx.yyy.zzz import aaa > > fails with the message: > > "ImportError: No module named xxx.yyy.zzz" > > but from within the python interpreter the same line succeeds. What > would be the causes of that ? > > From within the python interpreter I have looked at sys.path and > xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am > not sure why this is failing within the python script. And how is sys.path different when you run it as a script? -- Steven From news1234 at free.fr Mon Jul 19 03:06:09 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 09:06:09 +0200 Subject: rstrip() In-Reply-To: References: <4C409680.8000503@mrabarnett.plus.com> <4C422BE4.8070304@mrabarnett.plus.com> <4c42e2f2$0$20937$426a74cc@news.free.fr> <4c430d0a$0$20945$426a74cc@news.free.fr> <4C433087.8090403@mrabarnett.plus.com> Message-ID: <4c43f962$0$3717$426a74cc@news.free.fr> Dennis Lee Bieber wrote: > On Sun, 18 Jul 2010 17:49:11 +0100, MRAB > declaimed the following in gmane.comp.python.general: > >> How about 'strip_str', 'lstrip_str' and 'rstrip_str', or something > > Not sure what the first would do... unless one is envisioning > > "abracadabra".strip_str("abra")... > > For the others... trim_suffix, trim_prefix are more explicit in > meaning -- after all, someone might ask if there is an *strip_unicode > too! (or _bytes). That still leaves the question of what the desired > behavior of > > "Shanana".trim_suffix("na") > > is to produce? "Sha" or "Shana"? > > What I'd imagine would be stripping of a suffix or the first match in a list of suffixes exactly once. TO me this seems the most common use case, though one is surprised how functions can be used. Example: def strip_suffix(str,*suffixes): for suffix in suffixes: if str.endswith(suffix): return str[-len(suffix):] return str From news1234 at free.fr Mon Jul 19 03:10:24 2010 From: news1234 at free.fr (News123) Date: Mon, 19 Jul 2010 09:10:24 +0200 Subject: Difference between import in script and from interpreter In-Reply-To: References: Message-ID: <4c43fa60$0$3717$426a74cc@news.free.fr> Edward Diener wrote: > In a python script a: > > from xxx.yyy.zzz import aaa > > fails with the message: > > "ImportError: No module named xxx.yyy.zzz" > > but from within the python interpreter the same line succeeds. What > would be the causes of that ? > > From within the python interpreter I have looked at sys.path and > xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am > not sure why this is failing within the python script. Probably your problem is, that you call a python script, which is NOT located in the current working directlory. if you type python then imports will be relative to your current working directory if you execute a script imports will be relative to the scripts location. no idea in which directory you are when starting python from a windows menu. you can set PYTHONPATH to point to the base directory of your project if you want to be sure to always find your modules From gnuist006 at gmail.com Mon Jul 19 03:11:37 2010 From: gnuist006 at gmail.com (bolega) Date: Mon, 19 Jul 2010 00:11:37 -0700 (PDT) Subject: Emacs Time Line, Graphical Chart by Jamie Zawinski - Valuable Resource for Newbies - written: 8-Mar-1999, updated: 29-Oct-2007 Message-ID: <411df585-3bf4-4640-ab8f-50282c3b47a8@k39g2000yqb.googlegroups.com> Many newbies would find this one by Jamie Zawinski, of immense help http://www.jwz.org/doc/emacs-timeline.html written: 8-Mar-1999, updated: 29-Oct-2007 For more detail about the early days, please see Bernie Greenberg's paper, Multics Emacs: The History, Design and Implementation. I've drawn lines only where code is shared, not merely ideas. 1976 TECMAC and TMACS a pair of "TECO-macro realtime editors." by Guy Steele, Dave Moon, Richard Greenblatt, Charles Frankston, et al. | | 1976 EMACS by Richard Stallman, Guy Steele, EINE (EINE Is Not EMACS) and Dave Moon. by Dan Weinreb. Merger of TECMAC and TMACS, plus for MIT Lisp Machine. a dynamic loader and Meta-key cmds. First Emacs written in Lisp. Ran on ITS and TWENEX (Tops-20) | written in TECO and PDP 10 assembly. | | | 1978 Multics Emacs ZWEI (ZWEI Was EINE Initially) by Bernie Greenberg. by Dan Weinreb and Mike McMahon. written in MacLisp; | also used Lisp as its | extension language. | 1980 ZMACS (direct descendant of ZWEI) on Symbolics LM-2, LMI LispM, and later, TI Explorer (1983-1989) 1981 Gosling Emacs : by James Gosling : written in C; with "Mocklisp" as its extension language. / | 1983 / | / Unipress Emacs (6-may-83) / $395 commercial product. 1984 / Hemlock / by Bill Chiles, / Rob MacLachlan, et al. 1985 GNU Emacs 13.0? (20-mar-85) written in Spice Lisp by Richard Stallman. (CMU Common Lisp) initial public release? : | : GNU Emacs 15.10 (11-apr-85) : | GNU Emacs 15.34 (07-may-85) | GNU Emacs 16.56 (15-jul-85) (Gosling code expunged for copyright reasons) | | GNU Emacs 16.60 (19-sep-85) (contained first patches from the net, including preliminary SYSV support) | | GNU Emacs 17.36 (20-dec-85) (included TeX manual; first version that worked on SYSV out of the box) | | 1986 GNU Emacs 18.24 beta (02-oct-86) | 1987 GNU Emacs 18.41 (22-mar-87) | GNU Emacs 18.45 (02-jun-87) | GNU Emacs 18.49 (18-sep-87) | \ | \________________________________________________ | \ | \ | Early work on Epoch begins (1987) | by Alan M. Carroll 1988 GNU Emacs 18.50 (13-feb-88) | | | GNU Emacs 18.51 (07-may-88) | | | GNU Emacs 18.52 (01-sep-88) | | Epoch 1.0 (14-dec-88) | by Alan M. Carroll with Simon Kaplan 1989 GNU Emacs 18.53 (24-feb-89) | | \ | | \________________________________________________ | _____ | | \ GNU Emacs 18.54 (26-apr-89) | \ | | \ GNU Emacs 18.55 (23-aug-89) | \ | | | \ | | | NEmacs 3.2.1 (15-dec-89) | | | "Nihongo Emacs": a fork | | | with multi-byte Japanese | | | language support. | | | | | | Epoch 2.0 (23-dec-89) | | | | | | | | | 1990 | | Epoch 3.1 (06-feb-90) | | | | | | \ | NEmacs 3.3.1 (3-mar-90) | \ | | | \ Epoch 3.2 (11-dec-90) | | \ last Carroll release. | | \____ (sporadic work on | | | GNU Emacs 19 begins) | | | | | | | | | | | | Epoch 4.0 (27-aug-90) | | | Now maintained by NCSA. | | | | | 1991 GNU Emacs 18.57 (??-jan-91) | | | | | | | GNU Emacs 18.58 (??-???-91) | | | | | | | 1992 | |___ | MULE 0.9.0b (4-mar-92) | | \ | "Multilingual | | \ | Enhancements to Emacs": | | \ | support for input methods | | \ | and various languages | | Lucid Emacs 19.0 (??-apr-92) | including Japanese, | | by Jamie Zawinski et al. | Chinese, Korean, Greek, | | | | Hebrew, and Cyrillic. | | Lucid Emacs 19.1 (04-jun-92) | | | | | | | | | Lucid Emacs 19.2 (19-jun-92) | | | | | | | | | Lucid Emacs 19.3 (09-sep-92) | | GNU Emacs 18.59 (31-oct-92) | | | | | | | | | 1993 | / Lucid Emacs 19.4 (21-jan-93) | | | / | | | | / Lucid Emacs 19.5 (05-feb-93) | | | / (trade-show giveaway CD only) | | | / | | | | ____________/ Lucid Emacs 19.6 (09-apr-93) | | | / | | | | / | | | GNU Emacs 19.7 beta (22-may-93) | /| | first public v19 beta | / | | | | / | ...___ | GNU Emacs 19.8 beta (27-may-93) | / | \ | | \ | / | \ | | \________________ | ___________________/ | MULE 1.0 (1-aug-93) | \ | / | (based on GNU Emacs 18.59) | Lucid Emacs 19.8 (06-sep-93) | | | (Epoch merger, preliminary | | | I18N support) | | | | | | GNU Emacs 19.22 beta (28-nov-93) | | | | | | | 1994 | Lucid Emacs 19.9 (12- may-94) / | | (scrollbars, Athena) / | | | / | GNU Emacs 19.23 beta (17-may-94) | / | | \ | / | | \____________ | ___________________/ | | \ | / | | Lucid Emacs 19.10 (27- may-94) | | last JWZ release. | | | | GNU Emacs 19.24 beta (16-may-94) | | | | ...___ | | | \ | | | \ | | | MULE 2.0 (6-aug-94) | | (based on GNU Emacs 19.25) | | | | XEmacs 19.11 (13- sep-94) | | Lucid Emacs -> XEmacs renaming. | | now maintained by Chuck Thompson | | and Ben Wing. | | | | GNU Emacs 19.27 beta (14-sep-94) | | | | | GNU Emacs 19.28 (01-nov-94) | | first official v19 release. | ...___ | | | \ | | | \ | | | MULE 2.2 (28-dec-94) | | (based on GNU Emacs 19.28) | | | | | | 1995 | | MULE 2.3 (24-jul-95) | | . | XEmacs 19.12 (23- jun-95) . | (tty support) \ . GNU Emacs 19.29 (21-jun-95) | \ . | | (work on 20.x begins) . GNU Emacs 19.30 (24-nov-95) | : . | \ | : . | \_____________ | . | \ | . | XEmacs 19.13 (01- sep-95) . 1996 GNU Emacs 19.31 (25-may-96) | . | XEmacs 19.14 (23- jun-96) . GNU Emacs 19.34 (21-aug-96) | \ . 1997 | XEmacs 20.0 (09-feb-97) \ . | now maintained by \ . | Steve Baur. | . | | XEmacs 19.15 (26- mar-97) . | | | . | XEmacs 20.1 (15-apr-97) | . | | | . | XEmacs 20.2 (16-may-97) | . GNU Emacs 20.1 (17-sep-97) | | . | | | . GNU Emacs 20.2 (20-sep-97) | | . | | XEmacs 19.16 (31- oct-97) . | | . | XEmacs 20.3 (21- nov-97) . | | / | | ________________________________/ | | / | | / 1998 | XEmacs 20.4 (28-feb-98) | first reasonably stable | release with MULE support. | XEmacs "core" and "packages" | now packaged separately. | | | | | XEmacs 21.0-pre5 (18-jul-98) | Numbering scheme goes wonky due to | switch to stable + unstable branches. GNU Emacs 20.3 (19-aug-98) | | | | XEmacs 21.0.60 (10-dec-98) | / \___________________ | / \ 1999 | / XEmacs 21.2.9 (03- feb-99) | / (trunk / unstable branch) | / | | XEmacs 21.1.3 (26-jun-99) | | (stable / maintenance branch) | | maintained by Vin Shelton. | | | | GNU Emacs 20.4 (12-jul-99) | | | | | 2000 | | XEmacs 21.2.27 (18-jan-00) | | | | XEmacs 21.1.9 (13-feb-00) | | | | GNU Emacs 21.1 (20-oct-01) | XEmacs 21.2.36 (04-oct-00) | | | 2001 | XEmacs 21.1.14 (27-jan-01) | | (branch retired) | | XEmacs 21.2.40 (08-jan-01) | ____________________/ | | / | | / XEmacs 21.5.0 (18-apr-01) | / (trunk / unstable branch) | / | | XEmacs 21.4.0 (16-apr-01) | | (stable / maintenance branch) | | Maintained by Stephen Turnbull. | | Shipped by Red Hat, Debian, | | Mandrake, etc. | | | | 2002 GNU Emacs 21.2 (16-mar-02) | XEmacs 21.5.6 (05-apr-02) | | | | XEmacs 21.4.7 (04-may-02) | | | | 2003 | XEmacs 21.4.12 (15-jan-03) | | first "stable" 21.4 | | | | GNU Emacs 21.3 (19-mar-03) | | | | | | XEmacs 21.4.13 (25-may-03) | | maintained by Vin Shelton. | | | | | | XEmacs 21.5.14 (01-jun-03) | | | | XEmacs 21.4.14 (05-sep-03) | | | | | | XEmacs 21.5.16 (26-sep-03) 2004 | | | | XEmacs 21.4.15 (03-feb-04) | | | | | | XEmacs 21.5.18 (22-oct-04) | | | | XEmacs 21.4.17 (06-feb-05) | 2005 | | | GNU Emacs 21.4a (17-feb-05) | XEmacs 21.5.19 (18-feb-05) | | | | | XEmacs 21.5.23 (26-oct-05) | | | | XEmacs 21.4.18 (03-dec-05) | | | | | | XEmacs 21.5.24 (19-dec-05) | | | 2006 | XEmacs 21.4.19 (28-jan-06) | | | | | | XEmacs 21.5.28 (21-may-06) | | | XEmacs 21.4.20 (09-dec-06) | | GNU Emacs 22.1 (02-jun-07) | | 2007 XEmacs 21.4.21 (14-oct-07) From nick_keighley_nospam at hotmail.com Mon Jul 19 03:27:33 2010 From: nick_keighley_nospam at hotmail.com (Nick Keighley) Date: Mon, 19 Jul 2010 00:27:33 -0700 (PDT) Subject: Fascinating interview by Richard Stallman on Russia TV References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87iq4dmcsh.fsf@temporary-address.org.uk> Message-ID: <12697207-f70c-4f6d-8be3-e326e4dbaddf@k19g2000yqc.googlegroups.com> On 18 July, 09:38, Emmy Noether wrote: > On Jul 18, 1:09?am, Nick <3-nos... at temporary-address.org.uk> wrote: > > Emmy Noether writes: > > > In this video, Stall man makes 4 promises to public but stalls on 2nd > > > of them. > > > I have no idea of the rights or wrongs of this case. ?But I've found > > through experience that when someone uses a "witty" misspelling of > > someone's name, they are almost always the one in the wrong. ? > > Huh, you forgot that the whole of GNU = Gnu Not Unix you know someone named GNU? They must have had strange parents... From vladaspams at gmail.com Mon Jul 19 03:41:17 2010 From: vladaspams at gmail.com (Vladimir Jovic) Date: Mon, 19 Jul 2010 09:41:17 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: Alf P. Steinbach /Usenet wrote: > #include // PyWeakPtr, PyPtr, PyModule, > PyClass > using namespace progrock; > > namespace { > using namespace cppy; > > struct Noddy > { > PyPtr first; > PyPtr last; > int number; > > Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) > : number( 0 ) > { > devsupport::suppressUnusedWarning( pySelf ); > > PyWeakPtr pFirstName = 0; > PyWeakPtr pLastName = 0; > > static char* kwlist[] = { "first", "last", "number", 0 }; > > ::PyArg_ParseTupleAndKeywords( > args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, > pointerTo( pFirstName ), pointerTo( pLastName ), &number > ) > >> Accept< IsNonZero >() > || throwX( "Invalid args" ); > > if( pFirstName != 0 ) { first = pFirstName; } > if( pLastName != 0 ) { last = pLastName; } Why not initiallize all member variables in the initializer list? > } > > PyPtr name() > { > (first != 0) > || throwX( ::PyExc_AttributeError, "first" ); > (last != 0) > || throwX( ::PyExc_AttributeError, "last" ); Nice trick. I would still find this more readable : if ( first != 0 ) { throwX( ::PyExc_AttributeError, "first" ); } > return (PyString( first ) + L" " + PyString( last )).pyPtr(); > } > }; > > struct NoddyPyClass: PyClass< Noddy > > { > NoddyPyClass( PyModule& m, PyString const& name, PyString const& > doc ) > : PyClass< Noddy >( m, name, doc, Exposition() > .method( > L"name", CPPY_GLUE( name ), > L"Return the name, combining the first and last name" > ) > .attribute( > L"first", CPPY_GLUE( first ), L"first name" > ) > .attribute( > L"last", CPPY_GLUE( last ), L"last name" > ) > .attribute( > L"number", CPPY_GLUE( number ), L"noddy number" > ) > ) > {} > }; > > class NoddyModule: public PyModule > { > private: > NoddyPyClass noddyPyClass_; > > public: > NoddyModule() > : PyModule( > L"noddy2", L"Example module that creates an extension > type." ) > , noddyPyClass_( *this, > L"Noddy", L"A Noddy object has a name and a noddy number" ) hmmm what is L ? From alf.p.steinbach+usenet at gmail.com Mon Jul 19 04:21:52 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 10:21:52 +0200 Subject: Sharing: member type deduction for member pointers (Alf's device?) In-Reply-To: References: Message-ID: * Vladimir Jovic, on 19.07.2010 09:41: > Alf P. Steinbach /Usenet wrote: > >> #include // PyWeakPtr, PyPtr, PyModule, >> PyClass >> using namespace progrock; >> >> namespace { >> using namespace cppy; >> >> struct Noddy >> { >> PyPtr first; >> PyPtr last; >> int number; >> >> Noddy( PyWeakPtr pySelf, PyPtr args, PyPtr kwArgs ) >> : number( 0 ) >> { >> devsupport::suppressUnusedWarning( pySelf ); >> >> PyWeakPtr pFirstName = 0; >> PyWeakPtr pLastName = 0; >> >> static char* kwlist[] = { "first", "last", "number", 0 }; >> >> ::PyArg_ParseTupleAndKeywords( >> args.rawPtr(), kwArgs.rawPtr(), "|OOi", kwlist, >> pointerTo( pFirstName ), pointerTo( pLastName ), &number >> ) >> >> Accept< IsNonZero >() >> || throwX( "Invalid args" ); >> >> if( pFirstName != 0 ) { first = pFirstName; } >> if( pLastName != 0 ) { last = pLastName; } > > Why not initiallize all member variables in the initializer list? 'PyPtr' is a smart pointer with default constructor, so 'first' and 'last' are initialized to zero implicitly. My goal was to emulate the Python 3.1.1 docs' Noddy2 example as closely as possible. And that code's assignment of zero to 'first' and 'last' here corresponds to default initialization to zero. :-) Anyway, parsing the Python arguments in the constructor initializer list is possible, but would be inefficient to do directly since it would then involve parsing the Python arguments three times (once for each data member). There is at least one way around that problem, namely outfitting a derived class with knowledge of the Noddy class' Python-side __init__ arguments. But I haven't implemented such support, and I don't know if it would do any good. As it is Noddy above is self-contained, except for exporting names to the Python side. With a derived class doing the argument parsing it would be less self-contained, and the machinery for that would add complexity, I think. So, I strive to make things simple and explicit (KISS: Keep It Simple, Stupid!). And I strive to not go into orgies of smart templates doing things implicitly... >> } >> >> PyPtr name() >> { >> (first != 0) >> || throwX( ::PyExc_AttributeError, "first" ); >> (last != 0) >> || throwX( ::PyExc_AttributeError, "last" ); > > Nice trick. I would still find this more readable : > > if ( first != 0 ) > { > throwX( ::PyExc_AttributeError, "first" ); > } Ah, well. :-) You can read about the rationale here: -- posted yesterday. Of course the only reason that those member variables /can/ be 0 is because I'm following the doc's progression of examples. The next version in the docs avoid the 0 possibility, as I recall. And the simple way of achieving that in cppy would be to declare 'first' and 'last' as PyString instead of generic PyPtr... >> return (PyString( first ) + L" " + PyString( last )).pyPtr(); >> } >> }; >> >> struct NoddyPyClass: PyClass< Noddy > >> { >> NoddyPyClass( PyModule& m, PyString const& name, PyString >> const& doc ) >> : PyClass< Noddy >( m, name, doc, Exposition() >> .method( >> L"name", CPPY_GLUE( name ), >> L"Return the name, combining the first and last name" >> ) >> .attribute( >> L"first", CPPY_GLUE( first ), L"first name" >> ) >> .attribute( >> L"last", CPPY_GLUE( last ), L"last name" >> ) >> .attribute( >> L"number", CPPY_GLUE( number ), L"noddy number" >> ) >> ) >> {} >> }; >> >> class NoddyModule: public PyModule >> { >> private: >> NoddyPyClass noddyPyClass_; >> >> public: >> NoddyModule() >> : PyModule( >> L"noddy2", L"Example module that creates an extension >> type." ) >> , noddyPyClass_( *this, >> L"Noddy", L"A Noddy object has a name and a noddy >> number" ) > > > hmmm what is L ? It's standard C and C++ notation for a wide character literal, where each character is of type 'wchar_t' instead of plain 'char'. Essentially the intent is to hold Unicode UTF16 or UTF32 code points, which is how it is in practice, although for political correctness the C and C++ standards allow for other wide character encodings (not necessarily Unicode). It is the only way to /portably/ use national character literals in C++, because otherwise the result depends on the source code encoding. E.g. sizeof( "?" ) yields 2 (the character '?' plus a zero byte at the end) with source code in Windows ANSI Western, and 3 with source code in UTF8, while sizeof( L"?" )/sizeof( wchar_t ) should in practice -- with Unicode wide chars -- always yield 2, namely the wide character encoding of '?' plus a zero wchar_t. The Python C API generally assumes that all 'char' strings are encoded in UTF8, while in Windows they're generally in Windows ANSI Western, so, I avoid that. Cheers, & thanks, - Alf -- blog at From debatem1 at gmail.com Mon Jul 19 04:22:19 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 19 Jul 2010 01:22:19 -0700 Subject: Fascinating interview by Richard Stallman on Russia TV In-Reply-To: <87oce4hmda.fsf@lola.goethe.zz> References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <1f6bd9bb-f7c6-4d0c-9936-d51b881da156@s24g2000pri.googlegroups.com> <87d3ulj30c.fsf@lola.goethe.zz> <87iq4d6any.fsf@atthis.clsnet.nl> <1f12874a-8683-40b2-9d7c-af5b801963a5@k39g2000yqd.googlegroups.com> <87wrstgsgj.fsf@lola.goethe.zz> <6e469332-eb46-4b81-aee3-10e5aa4e92cb@i31g2000yqm.googlegroups.com> <87oce4hmda.fsf@lola.goethe.zz> Message-ID: On Sun, Jul 18, 2010 at 7:53 AM, David Kastrup wrote: > ? ?File: elisp, ?Node: Writing Emacs Primitives, ?Next: Object Internals, ?Prev: Memory Usage, ?Up: GNU Emacs Internals > > ? ?E.5 Writing Emacs Primitives > ? ?============================ > > ? ?Lisp primitives are Lisp functions implemented in C. ?The details of > ? ?interfacing the C function so that Lisp can call it are handled by a few > ? ?C macros. ?The only way to really understand how to write new C code is > ? ?to read the source, but we can explain some things here. > > ? ? ? An example of a special form is the definition of `or', from > ? ?`eval.c'. ?(An ordinary function would have the same general > ? ?appearance.) > > ? ? ? ? DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > ? ? ? ? ? doc: /* Eval args until one of them yields non-nil, then return that > ? ? ? ? value. The remaining args are not evalled at all. > ? ? ? ? If all args return nil, return nil. > ? ? ? ? usage: (or CONDITIONS ...) ?*/) > ? ? ? ? ? (Lisp_Object args) > ? ? ? ? { > ? ? ? ? ? register Lisp_Object val = Qnil; > ? ? ? ? ? struct gcpro gcpro1; > > ? ? ? ? ? GCPRO1 (args); > > ? ? ? ? ? while (CONSP (args)) > ? ? ? ? ? ? { > ? ? ? ? ? ? ? val = Feval (XCAR (args)); > ? ? ? ? ? ? ? if (!NILP (val)) > ? ? ? ? ? ? ? ? break; > ? ? ? ? ? ? ? args = XCDR (args); > ? ? ? ? ? ? } > > ? ? ? ? ? UNGCPRO; > ? ? ? ? ? return val; > ? ? ? ? } > > ? ? ? Let's start with a precise explanation of the arguments to the > ? ?`DEFUN' macro. ?Here is a template for them: > > ? ? ? ? DEFUN (LNAME, FNAME, SNAME, MIN, MAX, INTERACTIVE, DOC) > > ? ?LNAME > ? ? ? ? This is the name of the Lisp symbol to define as the function > ? ? ? ? name; in the example above, it is `or'. > > ? ?FNAME > ? ? ? ? This is the C function name for this function. ?This is the name > ? ? ? ? that is used in C code for calling the function. ?The name is, by > ? ? ? ? convention, `F' prepended to the Lisp name, with all dashes (`-') > ? ? ? ? in the Lisp name changed to underscores. ?Thus, to call this > ? ? ? ? function from C code, call `For'. ?Remember that the arguments must > ? ? ? ? be of type `Lisp_Object'; various macros and functions for creating > ? ? ? ? values of type `Lisp_Object' are declared in the file `lisp.h'. > > ? ?SNAME > ? ? ? ? This is a C variable name to use for a structure that holds the > ? ? ? ? data for the subr object that represents the function in Lisp. > ? ? ? ? This structure conveys the Lisp symbol name to the initialization > ? ? ? ? routine that will create the symbol and store the subr object as > ? ? ? ? its definition. ?By convention, this name is always FNAME with `F' > ? ? ? ? replaced with `S'. > > ? ?MIN > ? ? ? ? This is the minimum number of arguments that the function > ? ? ? ? requires. ?The function `or' allows a minimum of zero arguments. > > ? ?MAX > ? ? ? ? This is the maximum number of arguments that the function accepts, > ? ? ? ? if there is a fixed maximum. ?Alternatively, it can be `UNEVALLED', > ? ? ? ? indicating a special form that receives unevaluated arguments, or > ? ? ? ? `MANY', indicating an unlimited number of evaluated arguments (the > ? ? ? ? equivalent of `&rest'). ?Both `UNEVALLED' and `MANY' are macros. > ? ? ? ? If MAX is a number, it may not be less than MIN and it may not be > ? ? ? ? greater than eight. > > ? ?INTERACTIVE > ? ? ? ? This is an interactive specification, a string such as might be > ? ? ? ? used as the argument of `interactive' in a Lisp function. ?In the > ? ? ? ? case of `or', it is 0 (a null pointer), indicating that `or' > ? ? ? ? cannot be called interactively. ?A value of `""' indicates a > ? ? ? ? function that should receive no arguments when called > ? ? ? ? interactively. ?If the value begins with a `(', the string is > ? ? ? ? evaluated as a Lisp form. > > ? ?DOC > ? ? ? ? This is the documentation string. ?It uses C comment syntax rather > ? ? ? ? than C string syntax because comment syntax requires nothing > ? ? ? ? special to include multiple lines. ?The `doc:' identifies the > ? ? ? ? comment that follows as the documentation string. ?The `/*' and > ? ? ? ? `*/' delimiters that begin and end the comment are not part of the > ? ? ? ? documentation string. > > ? ? ? ? If the last line of the documentation string begins with the > ? ? ? ? keyword `usage:', the rest of the line is treated as the argument > ? ? ? ? list for documentation purposes. ?This way, you can use different > ? ? ? ? argument names in the documentation string from the ones used in > ? ? ? ? the C code. ?`usage:' is required if the function has an unlimited > ? ? ? ? number of arguments. > > ? ? ? ? All the usual rules for documentation strings in Lisp code (*note > ? ? ? ? Documentation Tips::) apply to C code documentation strings too. > > ? ? ? After the call to the `DEFUN' macro, you must write the argument > ? ?list that every C function must have, including the types for the > ? ?arguments. ?For a function with a fixed maximum number of arguments, > ? ?declare a C argument for each Lisp argument, and give them all type > ? ?`Lisp_Object'. ?When a Lisp function has no upper limit on the number > ? ?of arguments, its implementation in C actually receives exactly two > ? ?arguments: the first is the number of Lisp arguments, and the second is > ? ?the address of a block containing their values. ?They have types `int' > ? ?and `Lisp_Object *'. > > ? ? ? Within the function `For' itself, note the use of the macros > ? ?`GCPRO1' and `UNGCPRO'. ?`GCPRO1' is used to "protect" a variable from > ? ?garbage collection--to inform the garbage collector that it must look > ? ?in that variable and regard its contents as an accessible object. ?GC > ? ?protection is necessary whenever you call `Feval' or anything that can > ? ?directly or indirectly call `Feval'. ?At such a time, any Lisp object > ? ?that this function may refer to again must be protected somehow. > > ? ? ? It suffices to ensure that at least one pointer to each object is > ? ?GC-protected; that way, the object cannot be recycled, so all pointers > ? ?to it remain valid. ?Thus, a particular local variable can do without > ? ?protection if it is certain that the object it points to will be > ? ?preserved by some other pointer (such as another local variable which > ? ?has a `GCPRO')(1). ?Otherwise, the local variable needs a `GCPRO'. > > ? ? ? The macro `GCPRO1' protects just one local variable. ?If you want to > ? ?protect two variables, use `GCPRO2' instead; repeating `GCPRO1' will > ? ?not work. ?Macros `GCPRO3', `GCPRO4', `GCPRO5', and `GCPRO6' also > ? ?exist. ?All these macros implicitly use local variables such as > ? ?`gcpro1'; you must declare these explicitly, with type `struct gcpro'. > ? ?Thus, if you use `GCPRO2', you must declare `gcpro1' and `gcpro2'. > ? ?Alas, we can't explain all the tricky details here. > > ? ? ? `UNGCPRO' cancels the protection of the variables that are protected > ? ?in the current function. ?It is necessary to do this explicitly. > > ? ? ? Built-in functions that take a variable number of arguments actually > ? ?accept two arguments at the C level: the number of Lisp arguments, and > ? ?a `Lisp_Object *' pointer to a C vector containing those Lisp > ? ?arguments. ?This C vector may be part of a Lisp vector, but it need not > ? ?be. ?The responsibility for using `GCPRO' to protect the Lisp arguments > ? ?from GC if necessary rests with the caller in this case, since the > ? ?caller allocated or found the storage for them. > > ? ? ? You must not use C initializers for static or global variables unless > ? ?the variables are never written once Emacs is dumped. ?These variables > ? ?with initializers are allocated in an area of memory that becomes > ? ?read-only (on certain operating systems) as a result of dumping Emacs. > ? ?*Note Pure Storage::. > > ? ? ? Do not use static variables within functions--place all static > ? ?variables at top level in the file. ?This is necessary because Emacs on > ? ?some operating systems defines the keyword `static' as a null macro. > ? ?(This definition is used because those systems put all variables > ? ?declared static in a place that becomes read-only after dumping, whether > ? ?they have initializers or not.) > > ? ? ? Defining the C function is not enough to make a Lisp primitive > ? ?available; you must also create the Lisp symbol for the primitive and > ? ?store a suitable subr object in its function cell. ?The code looks like > ? ?this: > > ? ? ? ? defsubr (&SUBR-STRUCTURE-NAME); > > ? ?Here SUBR-STRUCTURE-NAME is the name you used as the third argument to > ? ?`DEFUN'. > > ? ? ? If you add a new primitive to a file that already has Lisp primitives > ? ?defined in it, find the function (near the end of the file) named > ? ?`syms_of_SOMETHING', and add the call to `defsubr' there. ?If the file > ? ?doesn't have this function, or if you create a new file, add to it a > ? ?`syms_of_FILENAME' (e.g., `syms_of_myfile'). ?Then find the spot in > ? ?`emacs.c' where all of these functions are called, and add a call to > ? ?`syms_of_FILENAME' there. > > ? ? ? The function `syms_of_FILENAME' is also the place to define any C > ? ?variables that are to be visible as Lisp variables. ?`DEFVAR_LISP' > ? ?makes a C variable of type `Lisp_Object' visible in Lisp. ?`DEFVAR_INT' > ? ?makes a C variable of type `int' visible in Lisp with a value that is > ? ?always an integer. ?`DEFVAR_BOOL' makes a C variable of type `int' > ? ?visible in Lisp with a value that is either `t' or `nil'. ?Note that > ? ?variables defined with `DEFVAR_BOOL' are automatically added to the list > ? ?`byte-boolean-vars' used by the byte compiler. > > ? ? ? If you define a file-scope C variable of type `Lisp_Object', you > ? ?must protect it from garbage-collection by calling `staticpro' in > ? ?`syms_of_FILENAME', like this: > > ? ? ? ? staticpro (&VARIABLE); > > ? ? ? Here is another example function, with more complicated arguments. > ? ?This comes from the code in `window.c', and it demonstrates the use of > ? ?macros and functions to manipulate Lisp objects. > > ? ? ? ? DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, > ? ? ? ? ? Scoordinates_in_window_p, 2, 2, > ? ? ? ? ? "xSpecify coordinate pair: \nXExpression which evals to window: ", > ? ? ? ? ? "Return non-nil if COORDINATES is in WINDOW.\n\ > ? ? ? ? COORDINATES is a cons of the form (X . Y), X and Y being distances\n\ > ? ? ? ? ... > ? ? ? ? If they are on the border between WINDOW and its right sibling,\n\ > ? ? ? ? ? ?`vertical-line' is returned.") > ? ? ? ? ? (coordinates, window) > ? ? ? ? ? ? ?register Lisp_Object coordinates, window; > ? ? ? ? { > ? ? ? ? ? int x, y; > > ? ? ? ? ? CHECK_LIVE_WINDOW (window, 0); > ? ? ? ? ? CHECK_CONS (coordinates, 1); > ? ? ? ? ? x = XINT (Fcar (coordinates)); > ? ? ? ? ? y = XINT (Fcdr (coordinates)); > > ? ? ? ? ? switch (coordinates_in_window (XWINDOW (window), &x, &y)) > ? ? ? ? ? ? { > ? ? ? ? ? ? case 0: ? ? ? ? ? ? ? ? ? ? /* NOT in window at all. */ > ? ? ? ? ? ? ? return Qnil; > > ? ? ? ? ? ? case 1: ? ? ? ? ? ? ? ? ? ? /* In text part of window. */ > ? ? ? ? ? ? ? return Fcons (make_number (x), make_number (y)); > > ? ? ? ? ? ? case 2: ? ? ? ? ? ? ? ? ? ? /* In mode line of window. */ > ? ? ? ? ? ? ? return Qmode_line; > > ? ? ? ? ? ? case 3: ? ? ? ? ? ? ? ? ? ? /* On right border of window. ?*/ > ? ? ? ? ? ? ? return Qvertical_line; > > ? ? ? ? ? ? default: > ? ? ? ? ? ? ? abort (); > ? ? ? ? ? ? } > ? ? ? ? } > > ? ? ? Note that C code cannot call functions by name unless they are > ? ?defined in C. ?The way to call a function written in Lisp is to use > ? ?`Ffuncall', which embodies the Lisp function `funcall'. ?Since the Lisp > ? ?function `funcall' accepts an unlimited number of arguments, in C it > ? ?takes two: the number of Lisp-level arguments, and a one-dimensional > ? ?array containing their values. ?The first Lisp-level argument is the > ? ?Lisp function to call, and the rest are the arguments to pass to it. > ? ?Since `Ffuncall' can call the evaluator, you must protect pointers from > ? ?garbage collection around the call to `Ffuncall'. > > ? ? ? The C functions `call0', `call1', `call2', and so on, provide handy > ? ?ways to call a Lisp function conveniently with a fixed number of > ? ?arguments. ?They work by calling `Ffuncall'. > > ? ? ? `eval.c' is a very good file to look through for examples; `lisp.h' > ? ?contains the definitions for some important macros and functions. > > ? ? ? If you define a function which is side-effect free, update the code > ? ?in `byte-opt.el' which binds `side-effect-free-fns' and > ? ?`side-effect-and-error-free-fns' so that the compiler optimizer knows > ? ?about it. > > ? ? ? ---------- Footnotes ---------- > > ? ? ? (1) Formerly, strings were a special exception; in older Emacs > ? ?versions, every local variable that might point to a string needed a > ? ?`GCPRO'. > To me, this is amazing documentation. I would love it if there were something this explicit for the C API. Geremy Condra From jeanmichel at sequans.com Mon Jul 19 05:57:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 19 Jul 2010 11:57:32 +0200 Subject: Difference between import in script and from interpreter In-Reply-To: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> References: <4c43df6c$0$28664$c3e8da3@news.astraweb.com> Message-ID: <4C44218C.6070802@sequans.com> Steven D'Aprano wrote: > On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote: > > >> In a python script a: >> >> from xxx.yyy.zzz import aaa >> >> fails with the message: >> >> "ImportError: No module named xxx.yyy.zzz" >> >> but from within the python interpreter the same line succeeds. What >> would be the causes of that ? >> >> From within the python interpreter I have looked at sys.path and >> xxx.yyy.zzz is definitely in the path ( off of site-packages ). So I am >> not sure why this is failing within the python script. >> > > And how is sys.path different when you run it as a script? > > > '' is not in sys.path when running a script. '' is in sys.path by default within a interpreter. JM From lepto.python at gmail.com Mon Jul 19 06:54:39 2010 From: lepto.python at gmail.com (oyster) Date: Mon, 19 Jul 2010 18:54:39 +0800 Subject: how to copy and move file with its attribute? Message-ID: I mean writeonly, hidden, system and so on attributes I use windows, but if possible, is there any method to do so in a crossplatfrom way? thanks From __peter__ at web.de Mon Jul 19 07:17:40 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jul 2010 13:17:40 +0200 Subject: how to copy and move file with its attribute? References: Message-ID: oyster wrote: > I mean writeonly, hidden, system and so on attributes > > I use windows, but if possible, is there any method to do so in a > crossplatfrom way? I can't check, but shutil.copy2() may do what you want. Peter From dhruvbird at gmail.com Mon Jul 19 07:18:48 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 04:18:48 -0700 (PDT) Subject: Accumulate function in python Message-ID: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Hello, I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] And would like to compute the cumulative sum of all the integers from index zero into another array. So for the array above, I should get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] What is the best way (or pythonic way) to get this. Regards, -Dhruv. From vlastimil.brom at gmail.com Mon Jul 19 07:21:08 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 19 Jul 2010 13:21:08 +0200 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: 2010/7/19 oyster : > I mean writeonly, hidden, system and so on attributes > > I use windows, but if possible, is there any method to do so in a > crossplatfrom way? > > thanks > -- > http://mail.python.org/mailman/listinfo/python-list > You may check to see several possibilities http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html Probably the shutil module might be appropriate for simple usecases. hth, vbr From nitinpawar432 at gmail.com Mon Jul 19 07:25:47 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Mon, 19 Jul 2010 16:55:47 +0530 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: Hi, you may want to do like this array=[0,1,2] sumArray = [] for element in range(0,len(array)): if element == 0 : sumArray.append(array[element]) else: sumArray.append((array[element] + sumArray[element-1])) and then you can recheck it Thanks, nitin On Mon, Jul 19, 2010 at 4:48 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Jul 19 07:28:35 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Jul 2010 13:28:35 +0200 Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: dhruvbird wrote: > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. Homework? >>> def cumulative_sum(values, start=0): ... for v in values: ... start += v ... yield start ... >>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) [0, 1, 3, 4, 5, 5, 5, 7, 10] Peter From vlastimil.brom at gmail.com Mon Jul 19 07:40:29 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 19 Jul 2010 13:40:29 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: 2010/7/19 dhruvbird : > Hello, > ?I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > ?And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > ?What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. > -- Hi, just a straightworward, naive approach...: lst_int = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] acc_int = 0 output_lst = [] for i in lst_int: acc_int += i output_lst.append(acc_int) print output_lst vbr From mad.mick at gmx.de Mon Jul 19 08:14:15 2010 From: mad.mick at gmx.de (Mick Krippendorf) Date: Mon, 19 Jul 2010 14:14:15 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: Am 19.07.2010 13:18, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. import copy import itertools def acc(items, copy=copy.deepcopy): items = iter(items) result = next(items) yield copy(result) for item in items: result += item yield copy(result) print list(acc([0, 1, 2, 1, 1, 0, 0, 2, 3])) print list(itertools.islice(acc(itertools.count()), 10)) print list(acc(['a', 'b', 'c'])) print list(acc([[a], [b], [c]])) Output: [0, 1, 3, 4, 5, 5, 5, 7, 10] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] ['a', 'ab', 'abc'] [[a], [a, b], [a, b, c]] Without copy.deepcopy() the last line would be: [[a, b, c], [a, b, c], [a, b, c]] The copy=copy.deepcopy parameter allows for things like this: >>> print list(acc([[a], [b], [c]], tuple)) [(a,), (a, b), (a, b, c)] or: >>> print list(acc([['a'], ['b'], ['f'], ['s'], ['c'], ['g']], max)) ['a', 'b', 'f', 's', 's', 's'] or: >>> data = [[0], [1], [2], [1], [1], [2], [3]] >>> print list(acc(data, lambda x: float(sum(x)) / float(len(x)))) [0.0, 0.5, 1.0, 1.0, 1.0, 1.1666666666666667, 1.4285714285714286] Endless possibilities in an endless universe. Regards, Mick. From python at lists.fastmail.net Mon Jul 19 08:32:06 2010 From: python at lists.fastmail.net (python at lists.fastmail.net) Date: Mon, 19 Jul 2010 14:32:06 +0200 Subject: decimal.Decimal formatting Message-ID: <1279542726.26482.1385575193@webmail.messagingengine.com> I have various decimals which eventually are written to an XML file. Requirements indicate a precision of 11. I am currently having some 'issues' with Decimal("0"). When using quantize(decimal.Decimal("1e-11")) the result is not 0.00000000000, but 1e-11. Personally I agree 1e-11 is a better notation than 0.00000000000, but I currently need the long one. Is there a way to overwrite the switch to the scientific notation? Apparently there is a switch in notation 'between' 1e-6 and 1e-7. Thijs From alf.p.steinbach+usenet at gmail.com Mon Jul 19 08:41:13 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 14:41:13 +0200 Subject: CPython 3.1.1 docs error in noddy3 example? Message-ID: "Extending and Embedding the Python Interpreter" ?2.1.2, the noddy3 extension module example, uses "S" as format character for string arguments in its call to PyArg_ParseTupleAndKeywords. This causes Noddy to only accept bytes as arguments, instead of strings (format "U"). I suspect this is a leftover from Python 2.x, where strings were bytes, and that this is a bug? Cheers, - Alf -- blog at From xr.lists at gmail.com Mon Jul 19 08:48:16 2010 From: xr.lists at gmail.com (Alex A.) Date: Mon, 19 Jul 2010 15:48:16 +0300 Subject: timing In-Reply-To: References: Message-ID: You could use pycallgraph module Regards, Alex Abushkevich -------------- next part -------------- An HTML attachment was scrubbed... URL: From eldiener at tropicsoft.invalid Mon Jul 19 08:53:53 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 08:53:53 -0400 Subject: Different python versions confusion under Windows Vista x64 Message-ID: In Windows Vista x64 I have installed python 2.6 64-bit version and python 3.1 64-bit version to separate folders. Within the command interpreter I add python 2.6 to the PATH. In the command interpreter, When I type python somescript.py with an import sys print (sys.version) in the script, it shows: 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] In the command interpreter if I type 'python' I see: Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32 Does anybody have any ideas why this is happening ? From alf.p.steinbach+usenet at gmail.com Mon Jul 19 09:15:10 2010 From: alf.p.steinbach+usenet at gmail.com (Alf P. Steinbach /Usenet) Date: Mon, 19 Jul 2010 15:15:10 +0200 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: * Edward Diener, on 19.07.2010 14:53: > In Windows Vista x64 I have installed python 2.6 64-bit version and > python 3.1 64-bit version to separate folders. Within the command > interpreter I add python 2.6 to the PATH. > > In the command interpreter, When I type python somescript.py with an > > import sys > print (sys.version) > > in the script, it shows: > > 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] > > In the command interpreter if I type 'python' I see: > > Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit > (AMD64)] on win32 > > Does anybody have any ideas why this is happening ? At a guess your description of what's happening is not entirely accurate. Although it could be, since Windows moves in mysterious ways. Please try the following commands in sequence, with no other commands: python -V echo %path% ftype python.file python somescript.py Then right-click the command interpreter's title bar to get edit menu. /Mark/ the text of your commands and results. Then /copy/ it to the clipboard (note: you can't use [Ctrl C] here, use the edit menu or just press Enter). Then post the commands and results here, /paste/ them into your message (e.g. [Ctrl V]). And then, if you haven't already figured it out, somebody probably will. :-) Cheers & hth., - Alf -- blog at From mistobaan at gmail.com Mon Jul 19 09:41:10 2010 From: mistobaan at gmail.com (Fabrizio Milo aka misto) Date: Mon, 19 Jul 2010 15:41:10 +0200 Subject: [ANN] Lupa 0.6 - Lua in Python In-Reply-To: <4C433F2B.8050706@behnel.de> References: <4C433F2B.8050706@behnel.de> Message-ID: This is very very interesting. Do you have any direct application of it ? I know games like World of Warcraft uses Lua as scripting language. Thanks. Fabrizio -------------------------- Luck favors the prepared mind. (Pasteur) From post at andre-bell.de Mon Jul 19 10:24:41 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Mon, 19 Jul 2010 16:24:41 +0200 Subject: Accumulate function in python In-Reply-To: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4C446029.2000501@andre-bell.de> On 07/19/2010 01:18 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. > > Regards, > -Dhruv. Maybe not pythonic, but straight-forward: >>> import numpy >>> numpy.cumsum(x) array([ 0, 1, 3, 4, 5, 5, 5, 7, 10]) An example with a class class CumulativeSum(object): def __init__(self, start=0): self._current = start def __call__(self, value): self._current += value return self._current >>> cummulative_sum = CumulativeSum(0) >>> map(cummulative_sum, x) [0, 1, 3, 4, 5, 5, 5, 7, 10] Dirty: current = 0 def cummulative_sum(value): global current current += value return current >>> map(cummulative_sum, x) [0, 1, 3, 4, 5, 5, 5, 7, 10] Weird: def cummulative_sum_reducer(x, y): x.append(x[-1] + y) return x >>> reduce(cummulative_sum_reducer, x, [0]) [0, 0, 1, 3, 4, 5, 5, 5, 7, 10] Cheers Andre From kwa at kuwata-lab.com Mon Jul 19 10:48:55 2010 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 19 Jul 2010 23:48:55 +0900 Subject: ANN: pyTenjin 0.9.0 - very fast and full-featured template engine Message-ID: I released pyTenjin 0.9.0 http://www.kuwata-lab.com/tenjin/ http://pypi.python.org/pypi/Tenjin/ This release contains a lot of enhancements and changes. Also you should read planned changes in the next release (1.0.0). See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes for details. Overview -------- pyTenjin is very fast and full-featured template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (nestable layout template, partial template, preprocessing, ...) * Google App Engine supported Documents --------- * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * Examples http://www.kuwata-lab.com/tenjin/pytenjin-examples.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Enhancements from 0.8.1 ----------------------- * Performance improved (about 5%). * (IMPORTANT!!) Fragment cache supported. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#fragment-cache for details. * (IMPORTANT!!) include() now takes keyword arguments as local variables. ex. * Add new module 'tenjin.gae'. * Add 'input' argument to tenjin.Template() to create template object without file. ex. input = "

Hello ${name}

" t = tenjin.Template(None, input=input) html = t.render({'name': 'World'}) * Add tenjin.Engine.add_template() to add template object explicitly. * User's guide (doc/users-guide.html) is rewrited entirely. * Add benchmark for Jinja2. Changes from 0.8.1 ------------------ * (IMPORTANT!!) It is strongly recommended to close 'if', 'for', 'while', ... by corresponding '#endif', '#endfor', '#endwhile', and so on. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#planned-changes for details. * (IMPORTANT!!) Google App Engine support is changed. All you have to do is to call tenjin.gae.init() at first. See http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html#google-appengine for details. * (IMPORTANT!!) tenjin.Engine is changed to share a cache storage between engines by default. This improves performance of Tenjin but your test scripts may get errors. If you get errors in your test scripts, clear cache storage for each test. def setUp(self): tenjin.Engine.cache.clear() If you prefer previous behaviour, set tenjin.Engine.cache to None. ## create new MarshalCacheStorage object for each engine tenjin.Engine.cache = None * Now you can set default template class to tenjin.Engine.templateclass. ex. tenjin.Engine.templateclass = MyTemplate * 'cache' argument of tenjin.Engine() is changed. [old behaviour] if 'cache' is None, cache template object into memory. [new behaviour] if 'cache' is None, use default cache storage. * Default preamble is changed from "print ''.join(_buf)" to "print(''.join(_buf))". * 'doc/faq.html' is integrated into 'doc/users-guide.html'. * All test scripts are changed to import oktest instead of unittest. Bug fixes --------- * Fixed to set correct file path of template object which is loaded from cache. * Fixed a bug that 'pytenjin -sbN' didn't trim line number on the last line Have fun! -- regards, makoto kuwata From steve at REMOVE-THIS-cybersource.com.au Mon Jul 19 10:49:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Jul 2010 14:49:31 GMT Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4c4465fb$0$11101$c3e8da3@news.astraweb.com> On Mon, 19 Jul 2010 04:18:48 -0700, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] And would > like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] [pedant] The above are *lists*, not arrays. Python has arrays, but you have to call "import array" to get them. [/pedant] > What is the best way (or pythonic way) to get this. Others have given you a plethora of advanced, complicated and obscure ways to solve this question, but I haven't seen anyone give the simplest method (simple as in no tricks or advanced features): data = [0, 1, 2, 1, 1, 0, 0, 2, 3] csums = [] for x in data: if csums: y = x + csums[-1] else: y = x csums.append(y) We can save some code with the ternary operator: data = [0, 1, 2, 1, 1, 0, 0, 2, 3] csums = [] for x in data: csums.append((x + csums[-1]) if csums else x) Here's a version that writes the cumulative sum in place: data = [0, 1, 2, 1, 1, 0, 0, 2, 3] for i in range(1, len(data)): data[i] += data[i-1] -- Steven From stefan-usenet at bytereef.org Mon Jul 19 11:23:39 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Mon, 19 Jul 2010 17:23:39 +0200 Subject: decimal.Decimal formatting In-Reply-To: <1279542726.26482.1385575193@webmail.messagingengine.com> References: <1279542726.26482.1385575193@webmail.messagingengine.com> Message-ID: <20100719152339.GA4422@yoda.bytereef.org> python at lists.fastmail.net wrote: > I have various decimals which eventually are written to an XML file. > Requirements indicate a precision of 11. I am currently having some > 'issues' with Decimal("0"). When using > quantize(decimal.Decimal("1e-11")) the result is not 0.00000000000, but > 1e-11. > > Personally I agree 1e-11 is a better notation than 0.00000000000, but I > currently need the long one. Is there a way to overwrite the switch to > the scientific notation? Apparently there is a switch in notation > 'between' 1e-6 and 1e-7. Try: >>> format(Decimal("0"), ".11f") '0.00000000000' Stefan Krah From pjb at informatimago.com Mon Jul 19 11:42:33 2010 From: pjb at informatimago.com (Pascal J. Bourguignon) Date: Mon, 19 Jul 2010 17:42:33 +0200 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> <4c437fcb$0$31260$607ed4bc@cv.net> Message-ID: <87mxtnjx5i.fsf@kuiper.lan.informatimago.com> Kenneth Tilton writes: > What we do not have is any interesting amount of "free as in speech" > software, because no one uses the GPL. I do. So far, I resist to calls to put my software in a less freedom-promoting license. Hey everybody! Switch from MIT or BSD to GPL! Now! -- __Pascal Bourguignon__ http://www.informatimago.com/ From WolfgangMeiners01 at web.de Mon Jul 19 11:52:56 2010 From: WolfgangMeiners01 at web.de (Wolfgang Meiners) Date: Mon, 19 Jul 2010 17:52:56 +0200 Subject: Email =?ISO-8859-15?Q?f=FCr_Dich?= Message-ID: <4c4474d8$0$6777$9b4e6d93@newsspool3.arcor-online.net> Liebe Kirsten, ich liebe dich und freue mich, dass du bald auch Ferien hast. Wolfgang From dirk at plfn.invalid Mon Jul 19 12:10:23 2010 From: dirk at plfn.invalid (Deadly Dirk) Date: Mon, 19 Jul 2010 16:10:23 +0000 (UTC) Subject: Email =?iso-8859-1?b?Zvxy?= Dich References: <4c4474d8$0$6777$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Mon, 19 Jul 2010 17:52:56 +0200, Wolfgang Meiners wrote: > Liebe Kirsten, > > ich liebe dich und freue mich, dass du bald auch Ferien hast. > > Wolfgang Und die ganze Python gruppe liebt dich auch. -- The missionaries go forth to Christianize the savages - as if the savages weren't dangerous enough already. From homeusenet4 at brianhv.org Mon Jul 19 12:12:04 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Mon, 19 Jul 2010 16:12:04 +0000 (UTC) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > What is the best way (or pythonic way) to get this. Now that Steven's given you the simple, pythonic way, I'll just mention the advanced, complicated and obscure way that might be vaguely familiar if you're coming from a functional programming background: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] def running_sum(result, current_value): return result + [result[-1]+current_value if result else current_value] reduce(running_sum, x, []) Having offered this, I don't recall ever seeing reduce used in real python code, and explicit iteration is almost always preferred. -- Brian From bayesianroom at googlemail.com Mon Jul 19 12:12:20 2010 From: bayesianroom at googlemail.com (li wang) Date: Mon, 19 Jul 2010 09:12:20 -0700 (PDT) Subject: mod_python load cx_Oracle error Message-ID: <73e34de4-a508-4d78-9d79-937c31c3d3ba@x2g2000prk.googlegroups.com> It's quite weird when I import cx_Oracle in python interactive shell, it works perfectly. but when I import cx_Oracle in a *,py script, handled by mod_python.publisher, it keep reportint : ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory Can I anyone have a clue what's the matter, any help would be appreciated! From zooko at zooko.com Mon Jul 19 12:31:24 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 19 Jul 2010 10:31:24 -0600 Subject: ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1 Message-ID: Folks: This innovative distributed filesystem is written entirely in Python. Well, actually we rely on some C/C++ extension code in Python packages like "zfec" and "pycryptopp" for some mathematical heavy lifting, but all of the code in the tahoe-lafs package is actually pure Python. Regards, Zooko ANNOUNCING Tahoe, the Least-Authority File System, v1.7.1 The Tahoe-LAFS team is pleased to announce the immediate availability of version 1.7.1 of Tahoe-LAFS, an extremely reliable distributed storage system. Tahoe-LAFS is the first distributed storage system which offers "provider-independent security"?meaning that not even the operators of your storage servers can read or alter your data without your consent. Here is the one-page explanation of its unique security and fault-tolerance properties: http://tahoe-lafs.org/source/tahoe/trunk/docs/about.html Tahoe-LAFS v1.7.1 is the successor to v1.7.0, which was released June 18, 2010 [1]. v1.7.1 is a stable minor release which adds several bugfixes and improvements in security, forward-compatibility, packaging, usability, and portability. See the NEWS file [2] for details. WHAT IS IT GOOD FOR? With Tahoe-LAFS, you distribute your filesystem across multiple servers, and even if some of the servers are compromised by by an attacker, the entire filesystem continues to work correctly, and continues to preserve your privacy and security. You can easily share specific files and directories with other people. In addition to the core storage system itself, volunteers have built other projects on top of Tahoe-LAFS and have integrated Tahoe-LAFS with existing systems. These include frontends for Windows, Macintosh, JavaScript, iPhone, and Android, and plugins for Hadoop, bzr, mercurial, duplicity, TiddlyWiki, and more. See the Related Projects page on the wiki [3]. We believe that strong cryptography, Free and Open Source Software, erasure coding, and principled engineering practices make Tahoe-LAFS safer than RAID, removable drive, tape, on-line backup or "cloud storage" systems. This software is developed under test-driven development, and there are no known bugs or security flaws which would compromise confidentiality or data integrity under recommended use. (For all currently known issues please see the known_issues.txt file [4].) COMPATIBILITY This release is fully compatible with the version 1 series of Tahoe-LAFS. Clients from this release can write files and directories in the format used by clients of all versions back to v1.0 (which was released March 25, 2008). Clients from this release can read files and directories produced by clients of all versions since v1.0. Servers from this release can serve clients of all versions back to v1.0 and clients from this release can use servers of all versions back to v1.0. This is the tenth release in the version 1 series. This series of Tahoe-LAFS will be actively supported and maintained for the forseeable future, and future versions of Tahoe-LAFS will retain the ability to read and write files compatible with this series. LICENCE You may use this package under the GNU General Public License, version 2 or, at your option, any later version. See the file "COPYING.GPL" [5] for the terms of the GNU General Public License, version 2. You may use this package under the Transitive Grace Period Public Licence, version 1 or, at your option, any later version. (The Transitive Grace Period Public Licence has requirements similar to the GPL except that it allows you to delay for up to twelve months after you redistribute a derived work before releasing the source code of your derived work.) See the file "COPYING.TGPPL.html" [6] for the terms of the Transitive Grace Period Public Licence, version 1. (You may choose to use this package under the terms of either licence, at your option.) INSTALLATION Tahoe-LAFS works on Linux, Mac OS X, Windows, Cygwin, Solaris, *BSD, and probably most other systems. Start with "docs/quickstart.html" [7]. HACKING AND COMMUNITY Please join us on the mailing list [8]. Patches are gratefully accepted -- the RoadMap page [9] shows the next improvements that we plan to make and CREDITS [10] lists the names of people who've contributed to the project. The Dev page [11] contains resources for hackers. SPONSORSHIP Tahoe-LAFS was originally developed by Allmydata, Inc., a provider of commercial backup services. After discontinuing funding of Tahoe-LAFS R&D in early 2009, they have continued to provide servers, bandwidth, small personal gifts as tokens of appreciation, and bug reports. Thank you to Allmydata, Inc. for their generous and public-spirited support. Google, Inc. is sponsoring Tahoe-LAFS development as part of the Google Summer of Code 2010. Google suggested that we should apply for the Summer of Code program, and when we did they generously awarded four sponsorships to students from around the world to hack on Tahoe-LAFS this summer. Thank you to Google, Inc. for their generous and public-spirited support. HACK TAHOE-LAFS! If you can find a security flaw in Tahoe-LAFS which is serious enough that feel compelled to warn our users and issue a fix, then we will award you with a customized t-shirts with your exploit printed on it and add you to the "Hack Tahoe-LAFS Hall Of Fame" [12]. ACKNOWLEDGEMENTS This is the fifth release of Tahoe-LAFS to be created solely as a labor of love by volunteers. Thank you very much to the team of "hackers in the public interest" who make Tahoe-LAFS possible. David-Sarah Hopwood and Zooko Wilcox-O'Hearn on behalf of the Tahoe-LAFS team July 18, 2010 Rainhill, Merseyside, UK and Boulder, Colorado, USA [1] http://tahoe-lafs.org/trac/tahoe/browser/relnotes.txt?rev=4514 [2] http://tahoe-lafs.org/trac/tahoe/browser/NEWS?rev=4577 [3] http://tahoe-lafs.org/trac/tahoe/wiki/RelatedProjects [4] http://tahoe-lafs.org/trac/tahoe/browser/docs/known_issues.txt [5] http://tahoe-lafs.org/trac/tahoe/browser/COPYING.GPL [6] http://tahoe-lafs.org/source/tahoe/trunk/COPYING.TGPPL.html [7] http://tahoe-lafs.org/source/tahoe/trunk/docs/quickstart.html [8] http://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev [9] http://tahoe-lafs.org/trac/tahoe/roadmap [10] http://tahoe-lafs.org/trac/tahoe/browser/CREDITS?rev=4567 [11] http://tahoe-lafs.org/trac/tahoe/wiki/Dev [12] http://tahoe-lafs.org/hacktahoelafs/ From python.koda at gmail.com Mon Jul 19 12:38:47 2010 From: python.koda at gmail.com (Alban Nona) Date: Mon, 19 Jul 2010 12:38:47 -0400 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: Hello, About this one. I tried the os.system copy. But it seems I cant find the right syntax. *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* This one seems to not working. Is there anyway I can do this way: localpath= c:\ networkpath=g:\ os.system("copy localpath networkpath) I tried many variations, but still not working. Any help will apreciated :/ Thanks ! 2010/7/19 Vlastimil Brom > 2010/7/19 oyster : > > I mean writeonly, hidden, system and so on attributes > > > > I use windows, but if possible, is there any method to do so in a > > crossplatfrom way? > > > > thanks > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > You may check to see several possibilities > http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html > Probably the shutil module might be appropriate for simple usecases. > > hth, > vbr > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dhruvbird at gmail.com Mon Jul 19 12:56:03 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 09:56:03 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> On Jul 19, 9:12?pm, Brian Victor wrote: > dhruvbird wrote: > > Hello, > > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > > ? And would like to compute the cumulative sum of all the integers > > from index zero into another array. So for the array above, I should > > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > > ? What is the best way (or pythonic way) to get this. > > Now that Steven's given you the simple, pythonic way, I'll just mention > the advanced, complicated and obscure way that might be vaguely familiar > if you're coming from a functional programming background: > > x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > def running_sum(result, current_value): > ? ? return result + [result[-1]+current_value if result else current_value] > > reduce(running_sum, x, []) > > Having offered this, I don't recall ever seeing reduce used in real > python code, and explicit iteration is almost always preferred. Yes, even I have noticed that reduce is a tad under-used function. So, I guess no function like "accumulate" below exists in the standard lib. def accumulate(proc, seed, seq): ret = [] for i in seq: ret.append(proc(seed, i)) return ret x = [0, 1, 3, 4, 5, 5, 5, 7, 10] print accumulate(lambda x,y: x+y, 0, x) My guess is that accumulate can be used in many more scenarios. Regards, -Dhruv. From python at mrabarnett.plus.com Mon Jul 19 12:57:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jul 2010 17:57:31 +0100 Subject: how to copy and move file with its attribute? In-Reply-To: References: Message-ID: <4C4483FB.2030009@mrabarnett.plus.com> Alban Nona wrote: > Hello, > > About this one. I tried the os.system copy. But it seems I cant find the > right syntax. > > *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* > > This one seems to not working. > In what way doesn't it work? If the names contain spaces then you need to quote them: os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) (It's easier to always quote them.) If the destination doesn't exist then you need to add the "/i" flag: os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2)) > Is there anyway I can do this way: > > localpath= c:\ > networkpath=g:\ > > os.system("copy localpath networkpath) > > I tried many variations, but still not working. Any help will apreciated :/ > From dhruvbird at gmail.com Mon Jul 19 13:01:59 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 19 Jul 2010 10:01:59 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <1994a39d-eb84-42f1-a434-6123a100ef81@a4g2000prm.googlegroups.com> On Jul 19, 4:28?pm, Peter Otten <__pete... at web.de> wrote: > dhruvbird wrote: > > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > > ? And would like to compute the cumulative sum of all the integers > > from index zero into another array. So for the array above, I should > > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > > ? What is the best way (or pythonic way) to get this. > > Homework? not really :) It's just that I was wondering if a built-in function for doing such things (which I find myself doing increasingly with an explicit loop) exists. Regards, -Dhruv. > > >>> def cumulative_sum(values, start=0): > > ... ? ? for v in values: > ... ? ? ? ? ? ? start += v > ... ? ? ? ? ? ? yield start > ...>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) > > [0, 1, 3, 4, 5, 5, 5, 7, 10] > > Peter From john at castleamber.com Mon Jul 19 13:20:48 2010 From: john at castleamber.com (John Bokma) Date: Mon, 19 Jul 2010 12:20:48 -0500 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <87fwzf2xsf.fsf@castleamber.com> "be.krul" writes: > why is this group being spammed? Do you report those spammers? While Google is extremely lazy with dealing with spammers, if sufficient people report them action might be taken. Also make sure to report those spammers with their ISP; posts via GG contain the posting IP address. Even trolls can be hurt, if enough people report them: http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From scott.mccarty at gmail.com Mon Jul 19 13:28:47 2010 From: scott.mccarty at gmail.com (Scott McCarty) Date: Mon, 19 Jul 2010 13:28:47 -0400 Subject: CPython Signal Handler Check for SIGKILL Message-ID: All, I just want to understand the C/Python piece better because I am writing a tutorial on signals and I am using python to demonstrate. I thought it would be fun to show that the SIGKILL is never processed, but instead python errors out. There is something in Python checking the SIGKILL signal handler, while not checking SIGTERM and I can't find the Python C code that handles it. When I am writing something like this, I like to point out the C code, not just cite the documentation (I did find this change in behaviour noted in the Python change log). I have searched everywhere (mostly the code and a little google) and I cannot understand where the SIGKILL signal gets checked when it is set as a handler. I have scoured the Modules/signalmodule.c only to find two instances of the RuntimeError exception, but I cannot understand how python knows when a handler is set for SIGKILL. I understand that this changed in 2.4 and I am not trying to change it, I just really want to understand where this happens. I used grep to find SIGKILL and SIGTERM to see if I could determine where the critical difference is, but I cannot figure it out. I have about 2 hours of searching around and I can't figure it out, I assume it has to rely on some default behaviour in Unix, but I have no idea. I don't see a difference between SIGKILL and SIGTERM in the python code, but obviously there is some difference. I understand what the difference is in Unix/Linux, I just want to see it in the python code. Since python is checking at run time to see what signals handlers are added, I know there must be a difference. I am not asking about the signals, I understand them, I am asking about the registration of the SIGNAL handler and how it knows that you are trying to register SIGKILL, you get an error like this. ./signal-catcher.py Traceback (most recent call last): File "./signal-catcher.py", line 22, in signal.signal(signal.SIGKILL, signal_handler_kill) RuntimeError: (22, 'Invalid argument') And the code is very simple, this attempts to register a handler for SIGKILL, but python knows and won't let you. signal.signal(signal.SIGKILL, signal_handler_kill) Please can someone just point me in the right direction. Thank You Scott M -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Mon Jul 19 13:51:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Jul 2010 17:51:34 GMT Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <1994a39d-eb84-42f1-a434-6123a100ef81@a4g2000prm.googlegroups.com> Message-ID: dhruvbird wrote: > On Jul 19, 4:28?pm, Peter Otten <__pete... at web.de> wrote: >> dhruvbird wrote: >> > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] >> > ? And would like to compute the cumulative sum of all the integers >> > from index zero into another array. So for the array above, I should >> > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] >> > ? What is the best way (or pythonic way) to get this. >> >> Homework? > > not really :) > > It's just that I was wondering if a built-in function for doing such > things (which I find myself doing increasingly with an explicit loop) > exists. > Why would you find yourself doing it more than once? Write it once in a function and then just re-use the code. From python.koda at gmail.com Mon Jul 19 13:55:16 2010 From: python.koda at gmail.com (Alban Nona) Date: Mon, 19 Jul 2010 13:55:16 -0400 Subject: how to copy and move file with its attribute? In-Reply-To: <4C4483FB.2030009@mrabarnett.plus.com> References: <4C4483FB.2030009@mrabarnett.plus.com> Message-ID: Hello Mrab, Thank you very much for this informations. Homever, Im still stuck with a problem: import os import sys import threading import shutil source= "C://Production//" dest= "D://Production//" os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) It seems that it wont copy the files File not found - //Production// 0 File(s) copied any idea of why its doing this please ? 2010/7/19 MRAB > Alban Nona wrote: > >> Hello, >> >> About this one. I tried the os.system copy. But it seems I cant find the >> right syntax. >> >> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* >> >> This one seems to not working. >> >> In what way doesn't it work? > > If the names contain spaces then you need to quote them: > > > os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) > > (It's easier to always quote them.) > > If the destination doesn't exist then you need to add the "/i" flag: > > os.system('xcopy /s /i "%s" "%s"' % (dirname1, dirname2)) > > > Is there anyway I can do this way: >> >> localpath= c:\ >> networkpath=g:\ >> >> os.system("copy localpath networkpath) >> >> I tried many variations, but still not working. Any help will apreciated >> :/ >> >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at jollans.com Mon Jul 19 13:56:07 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 19 Jul 2010 19:56:07 +0200 Subject: CPython Signal Handler Check for SIGKILL In-Reply-To: References: Message-ID: <4C4491B7.5030404@jollans.com> On 07/19/2010 07:28 PM, Scott McCarty wrote: > All, I just want to understand the C/Python piece better because I am > writing a tutorial on signals and I am using python to demonstrate. I > thought it would be fun to show that the SIGKILL is never processed, but > instead python errors out. There is something in Python checking the > SIGKILL signal handler, while not checking SIGTERM and I can't find the > Python C code that handles it. When I am writing something like this, I > like to point out the C code, not just cite the documentation (I did > find this change in behaviour noted in the Python change log). You cannot handle SIGKILL. Nothing to do with Python. Let me demonstrate: 0:pts/8:/tmp% cat sig.c #include #include void handle_sig(int sig) { printf("SIGNAL: %d\n", sig); } int main(int argc, char **argv) { if (signal(SIGUSR1, handle_sig) == SIG_ERR) printf("failed to set for USR1\n"); if (signal(SIGTERM, handle_sig) == SIG_ERR) printf("failed to set for TERM\n"); if (signal(SIGKILL, handle_sig) == SIG_ERR) printf("failed to set for KILL\n"); for(;;); } 0:pts/8:/tmp% cc -osig sig.c 0:pts/8:/tmp% ./sig failed to set for KILL ^C 130:pts/8:/tmp% > > I have searched everywhere (mostly the code and a little google) and I > cannot understand where the SIGKILL signal gets checked when it is set > as a handler. I have scoured the Modules/signalmodule.c only to find two > instances of the RuntimeError exception, but I cannot understand how > python knows when a handler is set for SIGKILL. I understand that this > changed in 2.4 and I am not trying to change it, I just really want to > understand where this happens. I used grep to find SIGKILL and SIGTERM > to see if I could determine where the critical difference is, but I > cannot figure it out. > > I have about 2 hours of searching around and I can't figure it out, I > assume it has to rely on some default behaviour in Unix, but I have no > idea. I don't see a difference between SIGKILL and SIGTERM in the python > code, but obviously there is some difference. I understand what the > difference is in Unix/Linux, I just want to see it in the python code. > Since python is checking at run time to see what signals handlers are > added, I know there must be a difference. I am not asking about the > signals, I understand them, I am asking about the registration of the > SIGNAL handler and how it knows that you are trying to register SIGKILL, > you get an error like this. > > ./signal-catcher.py > Traceback (most recent call last): > File "./signal-catcher.py", line 22, in > signal.signal(signal.SIGKILL, signal_handler_kill) > RuntimeError: (22, 'Invalid argument') > > And the code is very simple, this attempts to register a handler for > SIGKILL, but python knows and won't let you. > > signal.signal(signal.SIGKILL, signal_handler_kill) > > Please can someone just point me in the right direction. > > Thank You > Scott M > From rui.maciel at gmail.com Mon Jul 19 13:56:33 2010 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 19 Jul 2010 18:56:33 +0100 Subject: Fascinating interview by Richard Stallman at KTH on emacs history and internals References: <4db5e9a2-1d00-4b02-b988-17829a537aab@x27g2000yqb.googlegroups.com> <75be3e9a-d145-499b-8f5f-ceb734aaa4eb@j8g2000yqd.googlegroups.com> <4c437fcb$0$31260$607ed4bc@cv.net> Message-ID: <4c4491d4$0$17017$a729d347@news.telepac.pt> Kenneth Tilton wrote: > What we do not have is any interesting amount of "free as in speech" > software, because no one uses the GPL. You appear to be either confused or out of touch with reality. If that wasn't enough, your comment becomes a bit more amusing once we check your post's user agent. Rui Maciel From solipsis at pitrou.net Mon Jul 19 14:06:16 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 19 Jul 2010 20:06:16 +0200 Subject: CPython Signal Handler Check for SIGKILL References: Message-ID: <20100719200616.19a344e0@pitrou.net> Hello, > I am not asking about the signals, I understand them, > I am asking about the registration of the SIGNAL handler and how it knows > that you are trying to register SIGKILL, you get an error like this. > > ./signal-catcher.py > Traceback (most recent call last): > File "./signal-catcher.py", line 22, in > signal.signal(signal.SIGKILL, signal_handler_kill) > RuntimeError: (22, 'Invalid argument') >>> import errno >>> errno.errorcode[22] 'EINVAL' EINVAL is the error returned by the standard POSIX signal() function when trying to register a handler for SIGKILL. As the signal() man page says: [...] The signals SIGKILL and SIGSTOP cannot be caught or ignored. [...] ERRORS EINVAL signum is invalid. So, in short, Python doesn't check SIGKILL by itself. It's just forbidden by the underlying C standard library, and Python propagates the error as a RuntimeError. Regards Antoine. From no at email.here.invalid Mon Jul 19 14:08:00 2010 From: no at email.here.invalid (Mladen Gogala) Date: Mon, 19 Jul 2010 18:08:00 +0000 (UTC) Subject: mod_python load cx_Oracle error References: <73e34de4-a508-4d78-9d79-937c31c3d3ba@x2g2000prk.googlegroups.com> Message-ID: On Mon, 19 Jul 2010 09:12:20 -0700, li wang wrote: > It's quite weird when I import cx_Oracle in python interactive shell, it > works perfectly. > but when I import cx_Oracle in a *,py script, handled by > mod_python.publisher, it keep reportint : > > ImportError: libclntsh.so.10.1: cannot open shared object file: No such > file or directory > > Can I anyone have a clue what's the matter, any help would be > appreciated! That's an Oracle error, it means that you didn't set and export LD_LIBRARY_PATH like this: export LD_LIBRARY_PATH=$ORACLE_HOME/lib This is how it normally works: mgogala at nycwxp2622:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>> And this is what happens when I unset the shell variable: mgogala at nycwxp2622:~$ unset LD_LIBRARY_PATH mgogala at nycwxp2622:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory >>> My cx_Oracle is linked against Oracle instant client 11.2 on Ubuntu. -- http://mgogala.byethost5.com From python at mrabarnett.plus.com Mon Jul 19 14:09:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Jul 2010 19:09:55 +0100 Subject: how to copy and move file with its attribute? In-Reply-To: References: <4C4483FB.2030009@mrabarnett.plus.com> Message-ID: <4C4494F3.5080408@mrabarnett.plus.com> Alban Nona wrote: > Hello Mrab, > > Thank you very much for this informations. > Homever, Im still stuck with a problem: > > import os > import sys > import threading > import shutil > > source= "C://Production//" > dest= "D://Production//" > > os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) > > > It seems that it wont copy the files > > File not found - //Production// > 0 File(s) copied > > any idea of why its doing this please ? > [snip] If you're using slashes then there's no need to double them. Also, you don't need to end the folder names with slashes or backslashes (except for root folders). That's what it doesn't like, apparently. source = "C:/Production" dest = "D:/Production" os.system('xcopy /E /I /Q "%s" "%s"' % (source, dest)) From hujia06 at gmail.com Mon Jul 19 14:19:00 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 19 Jul 2010 14:19:00 -0400 Subject: why is this group being spammed? In-Reply-To: <87fwzf2xsf.fsf@castleamber.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <87fwzf2xsf.fsf@castleamber.com> Message-ID: I use Gmail. When I receive spams, I will click "Report Spam". In addition, I will not empty the spam box of my email immediately. When I receive about 25 spams, I will click "Filter messages like these" to filter all the spams and let gmail automatically delete them. On Mon, Jul 19, 2010 at 1:20 PM, John Bokma wrote: > "be.krul" writes: > > > why is this group being spammed? > > Do you report those spammers? > > While Google is extremely lazy with dealing with spammers, if sufficient > people report them action might be taken. Also make sure to report those > spammers with their ISP; posts via GG contain the posting IP address. > > Even trolls can be hurt, if enough people report them: > http://www.xahlee.org/Periodic_dosage_dir/t2/harassment.html > > -- > John Bokma > j3b > > Hacking & Hiking in Mexico - http://johnbokma.com/ > http://castleamber.com/ - Perl & Python Development > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.mccarty at gmail.com Mon Jul 19 14:34:33 2010 From: scott.mccarty at gmail.com (Scott McCarty) Date: Mon, 19 Jul 2010 14:34:33 -0400 Subject: CPython Signal Handler Check for SIGKILL In-Reply-To: <20100719200616.19a344e0@pitrou.net> References: <20100719200616.19a344e0@pitrou.net> Message-ID: Yes, yes, thank you both. That is exactly what I didn't understand, I knew it was some how linked to the C library and wasn't exactly being handled or decided at the Python layer, I just didn't understand the C part good enough. I have found the CPython source code that checks. I see what you are saying, it is basically checking for SIG_ERR like the C code and just setting the RuntimeError which forces an exit, thereby making the python module respond in a way very similar to the C library. Here is the CPython code in Modules/signalmodule.c if (PyOS_setsig(sig_num, func) == SIG_ERR) { PyErr_SetFromErrno(PyExc_RuntimeError); return NULL; } Second, I would like to apologize, this list is amazing, and I made a stupid comment on the core developers mailing list this morning because I didn't understand that this was the right place to post this question. Thank You Scott M On Mon, Jul 19, 2010 at 2:06 PM, Antoine Pitrou wrote: > > Hello, > > > I am not asking about the signals, I understand them, > > I am asking about the registration of the SIGNAL handler and how it knows > > that you are trying to register SIGKILL, you get an error like this. > > > > ./signal-catcher.py > > Traceback (most recent call last): > > File "./signal-catcher.py", line 22, in > > signal.signal(signal.SIGKILL, signal_handler_kill) > > RuntimeError: (22, 'Invalid argument') > > >>> import errno > >>> errno.errorcode[22] > 'EINVAL' > > EINVAL is the error returned by the standard POSIX signal() function > when trying to register a handler for SIGKILL. As the signal() man page > says: > > [...] > The signals SIGKILL and SIGSTOP cannot be caught or ignored. > [...] > ERRORS > EINVAL signum is invalid. > > > So, in short, Python doesn't check SIGKILL by itself. It's just > forbidden by the underlying C standard library, and Python propagates > the error as a RuntimeError. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Jul 19 14:42:46 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:42:46 +0100 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> Message-ID: On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote: >> why is this group being spammed? > > There used to be bots that issued cancel messages against spam, but I > don't think they are actively maintained anymore. Mostly because cancel messages are invariably ignored nowadays. From no.email at nospam.invalid Mon Jul 19 14:45:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 19 Jul 2010 11:45:33 -0700 Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <7xpqyjgvjm.fsf@ruckus.brouhaha.com> Brian Victor writes: > def running_sum(result, current_value): > return result + [result[-1]+current_value if result else current_value] > > reduce(running_sum, x, []) That is not really any good because Python lists are actually vectors, so result+[...] actually copies the whole old list, making your function take quadratic time. It would be ok in a FP language where lists were chains of cons nodes and result+[...] just allocated a single cons. I think Peter Otten's solution involving a generator is the one most in the current Python spirit. It's cleaner (for my tastes) than the ones that use things like list.append. From nobody at nowhere.com Mon Jul 19 14:46:55 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:46:55 +0100 Subject: how to copy and move file with its attribute? References: Message-ID: On Mon, 19 Jul 2010 17:57:31 +0100, MRAB wrote: >> About this one. I tried the os.system copy. But it seems I cant find the >> right syntax. >> >> *os.system ("xcopy /s %s %s" % (dirname1, dirname2))* >> >> This one seems to not working. >> > In what way doesn't it work? > > If the names contain spaces then you need to quote them: > > os.system('xcopy /s "%s" "%s"' % (dirname1, dirname2)) No, you need to use subprocess.call() instead of os.system(). If you absolutely must use os.system() for some reason, at least quote the arguments correctly. If you want to know how to do this, look at the subprocess.py source code (hint: it's not as simple as the above suggests). From nobody at nowhere.com Mon Jul 19 14:49:15 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 19 Jul 2010 19:49:15 +0100 Subject: CPython Signal Handler Check for SIGKILL References: Message-ID: On Mon, 19 Jul 2010 20:06:16 +0200, Antoine Pitrou wrote: > So, in short, Python doesn't check SIGKILL by itself. It's just > forbidden by the underlying C standard library, Actually, it's forbidden by the kernel. The C library just passes along the error to Python, which just passes it to the application. From joshua.landau.ws at gmail.com Mon Jul 19 14:49:55 2010 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 19 Jul 2010 19:49:55 +0100 Subject: Pyglet being extremely slow Message-ID: I've just tried Pyglet on my computer, a lower-end laptop at that, and going though the Pyglet tutorials I've tried this: import pyglet > window = pyglet.window.Window() > @window.event def on_key_press(symbol, modifiers): print 'A key was pressed' > @window.event def on_draw(): window.clear() > pyglet.app.run() And from a button-press to the print-statement activating takes ~3 seconds. I mean, yeah so I'm on a slow-ish-medium laptop but... three bloody seconds? On another one that shows the FPS of the program I'm getting 0 (fps). I would give you more detail but this has me stumped. Pygame was a decent performer -- and I'm not even drawing anything. Yeah, any help? *sigh* PS: Note that I'm on Ubuntu with a tiling window manager (Awesome). -------------- next part -------------- An HTML attachment was scrubbed... URL: From hujia06 at gmail.com Mon Jul 19 15:06:41 2010 From: hujia06 at gmail.com (Jia Hu) Date: Mon, 19 Jul 2010 15:06:41 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <5728a92c-9ad0-458a-8b5d-4af4c22fea44@k39g2000yqd.googlegroups.com> Message-ID: Hi noboby: How can you make the current email and name hidden? On Mon, Jul 19, 2010 at 2:42 PM, Nobody wrote: > On Sun, 18 Jul 2010 15:18:59 -0700, sturlamolden wrote: > > >> why is this group being spammed? > > > > There used to be bots that issued cancel messages against spam, but I > > don't think they are actively maintained anymore. > > Mostly because cancel messages are invariably ignored nowadays. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at picloud.com Mon Jul 19 15:49:40 2010 From: ken at picloud.com (Ken Elkabany) Date: Mon, 19 Jul 2010 12:49:40 -0700 Subject: ANN: PiCloud's Python Platform is now open to the Public! Message-ID: After 5 months in private beta, PiCloud, a cloud computing platform for the Python Programming Language, is now open to the general public. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as two lines of code! No server management necessary. All new users receive 5 free compute hours of computation. You can find out more here: http://www.picloud.com Full service description: PiCloud is a cloud computing platform that integrates into the Python Programming Language. It enables you to leverage the compute power of Amazon Web Services without having to manage, maintain, or configure virtual servers. PiCloud integrates seamlessly into your existing code base through a custom Python library, cloud. To offload the execution of a function to the cloud, all you must do is pass your desired function into the cloud library. PiCloud will then run the function on its high-performance and automatically-scaling cluster. We quickly scale our server capacity to meet your computational needs, and only charge you for the resources you actually consume. Getting on the cloud has never been this easy! PiCloud improves the full cycle of software development and deployment. Functions that are run on PiCloud have their resource usage monitored, performance analyzed, and errors traced; we further aggregate all your functions to give you a bird's eye view of your service. Through these introspective capabilities, PiCloud enables you to develop faster, easier, and smarter. Common use cases for our platform: * Scientific computing * Simulations * Video and image encoding * Statistical analysis of data sets * Real-time data processing * Charts and graphs generation Cheers, Ken Elkabany PiCloud, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.trojan at noaa.gov Mon Jul 19 16:06:59 2010 From: george.trojan at noaa.gov (George Trojan) Date: Mon, 19 Jul 2010 20:06:59 +0000 Subject: parmiko problem Message-ID: I have a problem with connecting to a host without specifying password (but with ssh keys configured correctly. That is [tina src]$ sftp alice Connecting to alice... sftp> works, but the code import paramiko paramiko.util.log_to_file('/tmp/paramiko') t = paramiko.Transport(('alice', 22)) t.connect(username='gtrojan') # , password='a-passwd']) sftp = paramiko.SFTPClient.from_transport(t) sftp.close() t.close() results in the following output in /tmp/paramiko: DEB [20100719-19:58:22.497] thr=1 paramiko.transport: starting thread (client mode): 0xb81e1150L INF [20100719-19:58:22.501] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_4.3) DEB [20100719-19:58:22.502] thr=1 paramiko.transport: kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib at openssh.com'] server compress:['none', 'zlib at openssh.com'] client lang:[''] server lang:[''] kex follows?False DEB [20100719-19:58:22.502] thr=1 paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr DEB [20100719-19:58:22.502] thr=1 paramiko.transport: using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none DEB [20100719-19:58:22.571] thr=1 paramiko.transport: Switch to new keys ... DEB [20100719-19:58:22.578] thr=2 paramiko.transport: [chan 1] Max packet in: 34816 bytes WAR [20100719-19:58:22.611] thr=1 paramiko.transport: Oops, unhandled type 3 DEB [20100719-20:00:22.502] thr=1 paramiko.transport: EOF in transport thread and a traceback in the terminal: Traceback (most recent call last): File "./try.py", line 18, in sftp = paramiko.SFTPClient.from_transport(t) File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 102, in from_transport File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, in open_session File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, in open_channel EOFError When the remove the comment on the connect() line and specify password the code works fine. Is this a bug, or I am missing something? I am running Python 2.6.3 on Centos 5.4. George From george.trojan at noaa.gov Mon Jul 19 17:02:53 2010 From: george.trojan at noaa.gov (George Trojan) Date: Mon, 19 Jul 2010 21:02:53 +0000 Subject: parmiko problem In-Reply-To: References: Message-ID: George Trojan wrote: > I have a problem with connecting to a host without specifying password > (but with ssh keys configured correctly. That is > > [tina src]$ sftp alice > Connecting to alice... > sftp> > > works, but the code > > import paramiko > paramiko.util.log_to_file('/tmp/paramiko') > t = paramiko.Transport(('alice', 22)) > t.connect(username='gtrojan') # , password='a-passwd']) > sftp = paramiko.SFTPClient.from_transport(t) > sftp.close() > t.close() > > results in the following output in /tmp/paramiko: > > DEB [20100719-19:58:22.497] thr=1 paramiko.transport: starting thread > (client mode): 0xb81e1150L > INF [20100719-19:58:22.501] thr=1 paramiko.transport: Connected > (version 2.0, client OpenSSH_4.3) > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: kex > algos:['diffie-hellman-group-exchange-sha1', > 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server > key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', > 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', > 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', > 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', > 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', > 'aes192-cbc', 'aes256-cbc', 'rijndael-cbc at lysator.liu.se', 'aes128-ctr', > 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', > 'hmac-ripemd160', 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', > 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'hmac-ripemd160', > 'hmac-ripemd160 at openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client > compress:['none', 'zlib at openssh.com'] server compress:['none', > 'zlib at openssh.com'] client lang:[''] server lang:[''] kex follows?False > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: Ciphers agreed: > local=aes128-ctr, remote=aes128-ctr > DEB [20100719-19:58:22.502] thr=1 paramiko.transport: using kex > diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local > aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; > compression: local none, remote none > DEB [20100719-19:58:22.571] thr=1 paramiko.transport: Switch to new > keys ... > DEB [20100719-19:58:22.578] thr=2 paramiko.transport: [chan 1] Max > packet in: 34816 bytes > WAR [20100719-19:58:22.611] thr=1 paramiko.transport: Oops, unhandled > type 3 > DEB [20100719-20:00:22.502] thr=1 paramiko.transport: EOF in transport > thread > > and a traceback in the terminal: > > Traceback (most recent call last): > File "./try.py", line 18, in > sftp = paramiko.SFTPClient.from_transport(t) > File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 102, > in from_transport > File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 655, > in open_session > File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 745, > in open_channel > EOFError > > When the remove the comment on the connect() line and specify password > the code works fine. Is this a bug, or I am missing something? I am > running Python 2.6.3 on Centos 5.4. > > George Thanks for listening;-) Found my problem - has to pass private key to connect(): paramiko.util.log_to_file('/tmp/paramiko') t = paramiko.Transport(('alice', 22)) path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa') key = paramiko.DSSKey.from_private_key_file(path) t.connect(username='gtrojan', pkey=key) sftp = paramiko.SFTPClient.from_transport(t) print sftp.listdir() sftp.close() t.close() From eldiener at tropicsoft.invalid Mon Jul 19 17:45:23 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 17:45:23 -0400 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote: > * Edward Diener, on 19.07.2010 14:53: >> In Windows Vista x64 I have installed python 2.6 64-bit version and >> python 3.1 64-bit version to separate folders. Within the command >> interpreter I add python 2.6 to the PATH. >> >> In the command interpreter, When I type python somescript.py with an >> >> import sys >> print (sys.version) >> >> in the script, it shows: >> >> 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] >> >> In the command interpreter if I type 'python' I see: >> >> Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit >> (AMD64)] on win32 >> >> Does anybody have any ideas why this is happening ? > > At a guess your description of what's happening is not entirely accurate. > > Although it could be, since Windows moves in mysterious ways. > > Please try the following commands in sequence, with no other commands: > > python -V > echo %path% > ftype python.file > python somescript.py > > Then right-click the command interpreter's title bar to get edit menu. > /Mark/ the text of your commands and results. Then /copy/ it to the > clipboard (note: you can't use [Ctrl C] here, use the edit menu or just > press Enter). Then post the commands and results here, /paste/ them into > your message (e.g. [Ctrl V]). > > And then, if you haven't already figured it out, somebody probably will. > :-) I figured out the cause. One of the Python scripts started with: #!Path/to/Python31Executable which evidently caused python 3.1 to be called to run that script. I am not sure that script was run via an 'import' statement, as opposed to a 'python someScript.py' within another script, but I suspect the latter. From joel.goldstick at columbuswebmakers.com Mon Jul 19 18:08:25 2010 From: joel.goldstick at columbuswebmakers.com (Joel Goldstick) Date: Mon, 19 Jul 2010 18:08:25 -0400 Subject: Accumulate function in python In-Reply-To: References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: <4C44CCD9.3000508@columbuswebmakers.com> Peter Otten wrote: > dhruvbird wrote: > >> I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] >> And would like to compute the cumulative sum of all the integers >> from index zero into another array. So for the array above, I should >> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] >> What is the best way (or pythonic way) to get this. > > Homework? > >>>> def cumulative_sum(values, start=0): > ... for v in values: > ... start += v > ... yield start > ... >>>> list(cumulative_sum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])) > [0, 1, 3, 4, 5, 5, 5, 7, 10] > > Peter nice! Peter From ranavishal at gmail.com Mon Jul 19 21:30:20 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Mon, 19 Jul 2010 18:30:20 -0700 Subject: How is memory managed in python? Message-ID: Hi, In my web application (Django) I call a function for some request which loads like 500 MB data from the database uses it to do some calculation and stores the output in disk. I just wonder even after this request is served the apache / python process is still shows using that 500 MB, why is it so? Can't I release that memory? Thanks Vishal Rana -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranjithtenz at gmail.com Mon Jul 19 21:41:56 2010 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Tue, 20 Jul 2010 07:11:56 +0530 Subject: How to pass the shell in Python Message-ID: Hi Folks, Can anyone tell me how to run shell commands using python script. -- Cheers Ranjith, http://ranjith10z.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Jul 19 21:48:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 20 Jul 2010 02:48:43 +0100 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: <4C45007B.8000602@mrabarnett.plus.com> Ranjith Kumar wrote: > Hi Folks, > Can anyone tell me how to run shell commands using python script. > Use the 'subprocess' module. From eldiener at tropicsoft.invalid Mon Jul 19 21:50:28 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 19 Jul 2010 21:50:28 -0400 Subject: Different python versions confusion under Windows Vista x64 In-Reply-To: References: Message-ID: On 7/19/2010 5:45 PM, Edward Diener wrote: > On 7/19/2010 9:15 AM, Alf P. Steinbach /Usenet wrote: >> * Edward Diener, on 19.07.2010 14:53: >>> In Windows Vista x64 I have installed python 2.6 64-bit version and >>> python 3.1 64-bit version to separate folders. Within the command >>> interpreter I add python 2.6 to the PATH. >>> >>> In the command interpreter, When I type python somescript.py with an >>> >>> import sys >>> print (sys.version) >>> >>> in the script, it shows: >>> >>> 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] >>> >>> In the command interpreter if I type 'python' I see: >>> >>> Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit >>> (AMD64)] on win32 >>> >>> Does anybody have any ideas why this is happening ? >> >> At a guess your description of what's happening is not entirely accurate. >> >> Although it could be, since Windows moves in mysterious ways. >> >> Please try the following commands in sequence, with no other commands: >> >> python -V >> echo %path% >> ftype python.file >> python somescript.py >> >> Then right-click the command interpreter's title bar to get edit menu. >> /Mark/ the text of your commands and results. Then /copy/ it to the >> clipboard (note: you can't use [Ctrl C] here, use the edit menu or just >> press Enter). Then post the commands and results here, /paste/ them into >> your message (e.g. [Ctrl V]). >> >> And then, if you haven't already figured it out, somebody probably will. >> :-) > > I figured out the cause. One of the Python scripts started with: > > #!Path/to/Python31Executable > > which evidently caused python 3.1 to be called to run that script. I am > not sure that script was run via an 'import' statement, as opposed to a > 'python someScript.py' within another script, but I suspect the latter. No, this is incorrect. The cause had nothing to do with the above. It was because .py files were associated with the 3.1 version of Python, no Python folder was in the PATH, and a Pyhton script invoked python passing it a .py file. So even though the initial command specified the 2.6 version of Python on a script, subsequent scripts were run using Python 3.1. I since changed the association of .py files to the 2.6 version of Python and everything works correctly. From clp2 at rebertia.com Tue Jul 20 02:43:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 19 Jul 2010 23:43:38 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana wrote: > Hi, > In my web application (Django) I call a function for some request which > loads like 500 MB data from the database uses it to do some calculation and > stores the output in disk. I just wonder even after this request is served > the apache / python process is still shows using that 500 MB, why is it so? > Can't I release that memory? http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm There are multiple layers of memory allocation involved. To avoid thrashing+fragmentation and to improve efficiency, free memory is not always immediately returned to the operating system. Example: If your problem involved calling your 500MB function twice, free-ing after the first call and then immediately re-allocating another 500MB of memory for the second call would waste time. Cheers, Chris -- http://blog.rebertia.com From stefan_ml at behnel.de Tue Jul 20 04:15:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Jul 2010 10:15:34 +0200 Subject: [ANN] Lupa 0.6 - Lua in Python In-Reply-To: References: <4C433F2B.8050706@behnel.de> Message-ID: Fabrizio Milo aka misto, 19.07.2010 15:41: > This is very very interesting. > > Do you have any direct application of it ? > I know games like World of Warcraft uses Lua as scripting language. Lua is widely used in the gaming industry, mainly for its size but also for its speed. Personally, I don't have any direct use for it, so this is mainly a fun project to see how well I can get it integrated and how fast I can get it. Stefan From dmitrey.kroshko at scipy.org Tue Jul 20 06:10:25 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 03:10:25 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug Message-ID: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. So, when I invoke in other code part "hasattr(myObject, 'size')", instead o returning True/False it goes to __getattr__ and starts constructor for another one oofun, that wasn't intended behaviour. Thus "hasattr(myObject, 'size')" always returns True. It prevents me of some bonuses and new features to be done in FuncDesigner. >>> 'size' in dir(b) False >>> hasattr(b,'size') True >>> 'size' in dir(b) True Could you fix it? From clp2 at rebertia.com Tue Jul 20 06:37:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 03:37:46 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > >>>> 'size' in dir(b) > False >>>> hasattr(b,'size') > True >>>> 'size' in dir(b) > True > > Could you fix it? There's probably some hackery you could do to check whether hasattr() is in the call stack, and then not dynamically create the attribute in __getattr__ if that's the case, but that's obviously quite kludgey. /Slightly/ less hackish: Replace hasattr() in the __builtin__ module with your own implementation that treats instances of FuncDesigner specially. Least ugly suggestion: Just don't use hasattr(); use your `x in dir(y)` trick instead. > Subject: [...] I think this is Python bug Nope, that's just how hasattr() works. See http://docs.python.org/library/functions.html#hasattr (emphasis mine): """ hasattr(object, name) The arguments are an object and a string. The result is True if the string is the name of one of the object?s attributes, False if not. (***This is implemented by calling getattr(object, name)*** and seeing whether it raises an exception or not.) """ I suppose you could argue for the addition of a __hasattr__ special method, but this seems like a really rare use case to justify adding such a method (not to mention the language change moratorium is still currently in effect). Cheers, Chris -- http://blog.rebertia.com From dmitrey.kroshko at scipy.org Tue Jul 20 06:59:30 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 03:59:30 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> On Jul 20, 1:37?pm, Chris Rebert wrote: > On Tue, Jul 20, 2010 at 3:10 AM, dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and connected to > > myObject as attribute. > > > So, when I invoke in other code part "hasattr(myObject, 'size')", > > instead o returning True/False it goes to __getattr__ and starts > > constructor for another one oofun, that wasn't intended behaviour. > > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) > > False > >>>> hasattr(b,'size') > > True > >>>> 'size' in dir(b) > > True > > > Could you fix it? > > There's probably some hackery you could do to check whether hasattr() > is in the call stack, and then not dynamically create the attribute in > __getattr__ if that's the case, but that's obviously quite kludgey. It's too unreliable solution, hasattr may or may not appear in stack wrt different cases > /Slightly/ less hackish: Replace hasattr() in the __builtin__ module > with your own implementation that treats instances of FuncDesigner > specially. It's too unreliable as well > Least ugly suggestion: Just don't use hasattr(); use your `x in > dir(y)` trick instead. something in dir() consumes O(n) operations for lookup, while hasattr or getattr() require O(log(n)). It matters for me, because it's inside deeply nested mathematical computations FuncDesigner is made for. > > > Subject: [...] I think this is Python bug > > Nope, that's just how hasattr() works. Seehttp://docs.python.org/library/functions.html#hasattr(emphasis mine): > """ > hasattr(object, name) > ? ? The arguments are an object and a string. The result is True if > the string is the name of one of the object?s attributes, False if > not. (***This is implemented by calling getattr(object, name)*** and > seeing whether it raises an exception or not.) > """ Thus I believe this is very ugly implementation. Some code implemented via "__getattr__" can start to execute arbitrary Python code, that is certainly not desired behaviour "hasattr" was designed for (to perform a check only), and it's too hard to reveal the situations, that makes a potential holes for viruses etc. Moreover, the implementation via "try getattr(object, name)" slowers code evaluation, I wonder why it is implemented so. > > I suppose you could argue for the addition of a __hasattr__ special > method, but this seems like a really rare use case to justify adding > such a method (not to mention the language change moratorium is still > currently in effect). I think much more easier solution would be to implement an additional argument to hasattr, e.g. hasattr(obj, field, onlyLookupInExistingFields = {True/False}). I think by default it's better set to True, now it behaves like False. D. From duncan.booth at invalid.invalid Tue Jul 20 07:14:55 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jul 2010 11:14:55 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > >>>> 'size' in dir(b) > False >>>> hasattr(b,'size') > True >>>> 'size' in dir(b) > True > > Could you fix it? This isn't a bug, it is by design: try reading the documentation for 'hasattr' as that explains that it is implemented by calling getattr and seeing whether or not it throws an exception. If you want different behaviour you just need to define your own helper function that has the behaviour you desire. e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. -- Duncan Booth http://kupuguy.blogspot.com From guandalino at gmail.com Tue Jul 20 07:42:58 2010 From: guandalino at gmail.com (guandalino) Date: Tue, 20 Jul 2010 04:42:58 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) Message-ID: Hi, running Python 2.7 test suite for urllib2 there is a test that doesn't pass. Do you have an idea about where the problem could be and how to solve it? Thanks, best regards. $ # ubuntu 8.04 $ pwd ~/sandbox/2.7/lib/python2.7/test $ python test_urllib2.py ====================================================================== ERROR: test_file (__main__.HandlerTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_urllib2.py", line 711, in test_file h.file_open, Request(url)) File "/home/redt/sandbox/2.7/lib/python2.7/unittest/case.py", line 456, in assertRaises callableObj(*args, **kwargs) File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, in file_open return self.open_local_file(req) File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, in open_local_file (not port and socket.gethostbyname(host) in self.get_names()): gaierror: [Errno -5] No address associated with hostname Notes: $ hostname speedy $ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain speedy ::1 localhost speedy ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts Finally, I don't know if this matters but the tests have been executed offline (without an internet connection). From s.selvamsiva at gmail.com Tue Jul 20 07:57:45 2010 From: s.selvamsiva at gmail.com (S.Selvam) Date: Tue, 20 Jul 2010 17:27:45 +0530 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 7:11 AM, Ranjith Kumar wrote: > Hi Folks, > Can anyone tell me how to run shell commands using python script. > > For simple work, i generally use os.system call. -- Regards, S.Selvam " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 20 08:00:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 20 Jul 2010 14:00:39 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4C458FE7.3020004@sequans.com> dmitrey wrote: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > > So, when I invoke in other code part "hasattr(myObject, 'size')", > instead o returning True/False it goes to __getattr__ and starts > constructor for another one oofun, that wasn't intended behaviour. > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) >>>> > False > >>>> hasattr(b,'size') >>>> > True > >>>> 'size' in dir(b) >>>> > True > > Could you fix it? > Quite simple, when calling b.size, return the computed value but do not set it as attribute, the value will be computed on each b.size call, and hasattr w. If you don't want to compute it each time, cause there no reason for it to change, use a private dummy attribute to record the value instead of size (__size for instance) and return the value of __size when getting the value of size. class Foo(object): def __init__(self): self.__size = None def __getattr__(self, name): if name == "size": if self.__size is None: self.__size = 5 # compute the value return self.__size raise AttributeError(name) b = Foo() print 'size' in dir(b) print hasattr(b, 'size') print 'size' in dir(b) False True False JM From lists at cheimes.de Tue Jul 20 08:31:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 14:31:38 +0200 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: > In my web application (Django) I call a function for some request which > loads like 500 MB data from the database uses it to do some calculation and > stores the output in disk. I just wonder even after this request is served > the apache / python process is still shows using that 500 MB, why is it so? > Can't I release that memory? Are you talking about resident or virtual memory here? From lists at cheimes.de Tue Jul 20 08:40:18 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 14:40:18 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: Am 20.07.2010 12:10, schrieb dmitrey: > hi all, > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. From nikos.the.gr33k at gmail.com Tue Jul 20 10:43:20 2010 From: nikos.the.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/I=?=) Date: Tue, 20 Jul 2010 07:43:20 -0700 (PDT) Subject: Trying to redirect every urel request to test.py script with the visitors page request as url parameter. Message-ID: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> Hello guys! This is my first post in this group! I'am trying to create a python script to take a visitors page request as url parameter, and the insert or update the counters database table and the render the template(my tempalets are actually html files) that has int hem special strign identifies format charactes so to replace them with actual data form within my python script. While the mod_rewwrite redirects okey when i try to http://webville.gr apache by default tries to open idnex.html file right? but due to Code: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.+) /cgi-bin/test.py?page=$1 [L,PT] redirectes the url to test.py script and i expect it to give to my pythoin script the initial url before the mod_rewrite as a URL parameter. while i tested and my script works ok(its a simple test cghi script afgter all) when i enable out mod_rewriute code within the htaccess file i get an Internal Server Error You can see if you try to http://webville.gr/index.html whiel if i disbale mod_rewrite code my test.py script work proiducing results. That leads me to beleive that the intiial requests never passes as url parameter. my python script is this simple script: Code: #!/usr/bin/python # -*- coding: utf-8 -*- import cgitb import os, sys, socket, datetime cgitb.enable() print ( "Content-type: text/html\n" ) # get some enviromental values if os.environ.has_key('HTTP_REFERER'): page = os.environ['HTTP_REFERER'] else: page = "tipota" host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] date = datetime.datetime.now().strftime( '%y-%m-%d %H:%M:%S' ) print page, host, date Can you help please? Also i want the code to redirect to test.py only if the initial request is a .html page not with every page. Thanks again! From dmitrey.kroshko at scipy.org Tue Jul 20 11:32:39 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:32:39 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: On 20 ???, 15:00, Jean-Michel Pichavant wrote: > dmitrey wrote: > > hi all, > > I have a class (FuncDesigner oofun) that has no attribute "size", but > > it is overloaded in __getattr__, so if someone invokes > > "myObject.size", it is generated (as another oofun) and connected to > > myObject as attribute. > > > So, when I invoke in other code part "hasattr(myObject, 'size')", > > instead o returning True/False it goes to __getattr__ and starts > > constructor for another one oofun, that wasn't intended behaviour. > > Thus "hasattr(myObject, 'size')" always returns True. It prevents me > > of some bonuses and new features to be done in FuncDesigner. > > >>>> 'size' in dir(b) > > > False > > >>>> hasattr(b,'size') > > > True > > >>>> 'size' in dir(b) > > > True > > > Could you fix it? > > Quite simple, when calling b.size, return the computed value but do not > set it as attribute, the value will be computed on each b.size call, and > hasattr w. If you don't want to compute it each time, cause there no > reason for it to change, use a private dummy attribute to record the > value instead of size (__size for instance) and return the value of > __size when getting the value of size. > > class Foo(object): > ? ? def __init__(self): > ? ? ? ? self.__size = None > > ? ? def __getattr__(self, name): > ? ? ? ? if name == "size": > ? ? ? ? ? ? if self.__size is None: > ? ? ? ? ? ? ? ? self.__size = 5 # compute the value > ? ? ? ? ? ? return self.__size > ? ? ? ? raise AttributeError(name) > > b = Foo() > print 'size' in dir(b) > print hasattr(b, 'size') > print 'size' in dir(b) > > False > True > False > > JM This doesn't stack with the following issue: sometimes user can write in code "myObject.size = (some integer value)" and then it will be involved in future calculations as ordinary fixed value; if user doesn't supply it, but myObject.size is involved in calculations, then the oofun is created to behave like similar numpy.array attribute. From jldunn2000 at gmail.com Tue Jul 20 11:33:57 2010 From: jldunn2000 at gmail.com (loial) Date: Tue, 20 Jul 2010 08:33:57 -0700 (PDT) Subject: Kick off a delete command from python and not wait Message-ID: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> I have a requirement to kick off a shell script from a python script without waiting for it to complete. I am not bothered about any return code from the script. What is the easiest way to do this. I have looked at popen but cannot see how to do it. From dmitrey.kroshko at scipy.org Tue Jul 20 11:39:41 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:39:41 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> > e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. So can anyone explain me how to look into object's dict? As I have wrote, "something in dir(...)" requires O(numOfFields) while I would like to use o(log(n)) >How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. Could anyone provide an example of it to be implemented, taking into account that a user can manually set "myObject.size" to an integer value? From neilc at norwich.edu Tue Jul 20 11:39:42 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 20 Jul 2010 15:39:42 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <8alu9uFosjU2@mid.individual.net> On 2010-07-20, dmitrey wrote: > This doesn't stack with the following issue: sometimes user can > write in code "myObject.size = (some integer value)" and then > it will be involved in future calculations as ordinary fixed > value; if user doesn't supply it, but myObject.size is involved > in calculations, then the oofun is created to behave like > similar numpy.array attribute. Telling them, "Don't do that," is a good solution in Python. -- Neil Cerutti From dmitrey.kroshko at scipy.org Tue Jul 20 11:47:00 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Tue, 20 Jul 2010 08:47:00 -0700 (PDT) Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <8alu9uFosjU2@mid.individual.net> Message-ID: <6ed6b050-ca1d-48db-81bf-d894d0ffb0c1@f6g2000yqa.googlegroups.com> On 20 ???, 18:39, Neil Cerutti wrote: > On 2010-07-20, dmitrey wrote: > > > This doesn't stack with the following issue: sometimes user can > > write in code "myObject.size = (some integer value)" and then > > it will be involved in future calculations as ordinary fixed > > value; if user doesn't supply it, but myObject.size is involved > > in calculations, then the oofun is created to behave like > > similar numpy.array attribute. > > Telling them, "Don't do that," is a good solution in Python. > > -- > Neil Cerutti But this is already documented feature, and it works as intended, so moving it into something like "myObject._size" will bring backward incompatibility and break all FuncDesigner user API and style, where no underlines are present, it will seem like a hack that it really is. Sometimes apriory knowing size value as fixed integer brings some code speedup, also, if a user supplies the value, a check for computed value wrt the provided size is performed each time. From ranavishal at gmail.com Tue Jul 20 11:49:44 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:49:44 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Chris, Thanks for the link. On Mon, Jul 19, 2010 at 11:43 PM, Chris Rebert wrote: > On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana wrote: > > Hi, > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > > http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm > > There are multiple layers of memory allocation involved. To avoid > thrashing+fragmentation and to improve efficiency, free memory is not > always immediately returned to the operating system. Example: If your > problem involved calling your 500MB function twice, free-ing after the > first call and then immediately re-allocating another 500MB of memory > for the second call would waste time. > > Cheers, > Chris > -- > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranavishal at gmail.com Tue Jul 20 11:50:57 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:50:57 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Hi Christian, I am not sure which one is used in this case, I use htop to see the memory used by apache / python. Thanks Vishal Rana On Tue, Jul 20, 2010 at 5:31 AM, Christian Heimes wrote: > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > Are you talking about resident or virtual memory here? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ranavishal at gmail.com Tue Jul 20 11:51:51 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 08:51:51 -0700 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: Thanks for your input. On Mon, Jul 19, 2010 at 7:23 PM, Scott McCarty wrote: > I had this exactly same problem with Peel and as far as I could find there > is no way reclaiming this memory unless you set max requests, which will > kill the Apache children processes after that number of requests. It's > normally something used for debugging, but can be used to reclaim ram. > > On the flip side, you could find your machine servers down and your child > processes will reuse that memory when they receive another request that uses > a huge amount of ram. It really depends on how often you are doing that > kind of processing, how you want to tune apache. > > Scott M > > On Jul 19, 2010 9:31 PM, "Vishal Rana" wrote: > > Hi, > > > > In my web application (Django) I call a function for some request which > > loads like 500 MB data from the database uses it to do some calculation > and > > stores the output in disk. I just wonder even after this request is > served > > the apache / python process is still shows using that 500 MB, why is it > so? > > Can't I release that memory? > > > > Thanks > > Vishal Rana > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Jul 20 11:52:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 20 Jul 2010 17:52:25 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4C45C639.6050207@sequans.com> dmitrey wrote: > On 20 ???, 15:00, Jean-Michel Pichavant > wrote: > >> dmitrey wrote: >> >>> hi all, >>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>> it is overloaded in __getattr__, so if someone invokes >>> "myObject.size", it is generated (as another oofun) and connected to >>> myObject as attribute. >>> >>> So, when I invoke in other code part "hasattr(myObject, 'size')", >>> instead o returning True/False it goes to __getattr__ and starts >>> constructor for another one oofun, that wasn't intended behaviour. >>> Thus "hasattr(myObject, 'size')" always returns True. It prevents me >>> of some bonuses and new features to be done in FuncDesigner. >>> >>>>>> 'size' in dir(b) >>>>>> >>> False >>> >>>>>> hasattr(b,'size') >>>>>> >>> True >>> >>>>>> 'size' in dir(b) >>>>>> >>> True >>> >>> Could you fix it? >>> >> Quite simple, when calling b.size, return the computed value but do not >> set it as attribute, the value will be computed on each b.size call, and >> hasattr w. If you don't want to compute it each time, cause there no >> reason for it to change, use a private dummy attribute to record the >> value instead of size (__size for instance) and return the value of >> __size when getting the value of size. >> >> class Foo(object): >> def __init__(self): >> self.__size = None >> >> def __getattr__(self, name): >> if name == "size": >> if self.__size is None: >> self.__size = 5 # compute the value >> return self.__size >> raise AttributeError(name) >> >> b = Foo() >> print 'size' in dir(b) >> print hasattr(b, 'size') >> print 'size' in dir(b) >> >> False >> True >> False >> >> JM >> > > This doesn't stack with the following issue: sometimes user can write > in code "myObject.size = (some integer value)" and then it will be > involved in future calculations as ordinary fixed value; if user > doesn't supply it, but myObject.size is involved in calculations, then > the oofun is created to behave like similar numpy.array attribute. > Here are some solutions in my humble order of preference: 1/ ask the user to always fill the size field 2/ ask the user to never fill the size filed (you can override __setattr__ to make sure...) 3/ override __setattr__ to set __size instead of size JM From duncan.booth at invalid.invalid Tue Jul 20 11:52:52 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Jul 2010 15:52:52 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: dmitrey wrote: >> e.g. one that just looks in the object's dictionary so as to avoid >> returning true for properties or other such fancy attributes. > > So can anyone explain me how to look into object's dict? As I have > wrote, "something in dir(...)" requires O(numOfFields) while I would > like to use o(log(n)) O(1) might be even better. Try this: def dmitry_hasattr(obj, name): """Checks for existence of an attribute directly in an object's dictionary. Doesn't see all attributes but doesn't have side effects.""" d = getattr(obj, '__dict__') if d is not None: return name in d return False -- Duncan Booth http://kupuguy.blogspot.com From lists at cheimes.de Tue Jul 20 11:53:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 20 Jul 2010 17:53:54 +0200 Subject: How is memory managed in python? In-Reply-To: References: Message-ID: <4C45C692.8030804@cheimes.de> Am 20.07.2010 17:50, schrieb Vishal Rana: > Hi Christian, > > I am not sure which one is used in this case, I use htop to see the memory > used by apache / python. In its default configuration htop reports three different types of memory usage: virt, res and shr (virtual, resident and shared memory). Which of them stays at 500 MB? Christian From robert.kern at gmail.com Tue Jul 20 12:05:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 12:05:19 -0400 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4a3773a7-c63f-4a91-a661-7eb4bd2bd0f3@f6g2000yqa.googlegroups.com> Message-ID: On 7/20/10 6:59 AM, dmitrey wrote: > On Jul 20, 1:37 pm, Chris Rebert wrote: >> Least ugly suggestion: Just don't use hasattr(); use your `x in >> dir(y)` trick instead. > > something in dir() consumes O(n) operations for lookup, while hasattr > or getattr() require O(log(n)). It matters for me, because it's inside > deeply nested mathematical computations FuncDesigner is made for. I'm not sure where you are getting log(n) from, but regardless, if you have so many attributes that the O() matters more than the constant, you have more problems than this. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Tue Jul 20 12:06:58 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 12:06:58 -0400 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: On 7/20/10 11:39 AM, dmitrey wrote: >> e.g. one that just looks in the object's dictionary so as to avoid returning true for properties or other such fancy attributes. > > So can anyone explain me how to look into object's dict? As I have > wrote, "something in dir(...)" requires O(numOfFields) while I would > like to use o(log(n)) ('size' in obj.__dict__) is O(1) with a pretty low constant. -- 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 ian.g.kelly at gmail.com Tue Jul 20 12:19:17 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Jul 2010 10:19:17 -0600 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <6d9acfcd-900f-4f5e-bd72-3f3e6ae2e3ef@s9g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 9:39 AM, dmitrey wrote: >>How about using a property instead of the __getattr__() hook? A property is a computed attribute that (among other things) plays much nicer with hasattr. > > Could anyone provide an example of it to be implemented, taking into > account that a user can manually set "myObject.size" to an integer > value? The following will work in Python 2.6+: class MyClass(object): @property def size(self): if not hasattr(self, '_size'): self._size = self._compute_size() return self._size @size.setter def size(self, value): self._size = value To support earlier versions of Python, you would write it like so: class MyClass(object): def _get_size(self): if not hasattr(self, '_size'): self._size = self._compute_size() return self._size def _set_size(self, value): self._size = value size = property(_get_size, _set_size) From animator333 at gmail.com Tue Jul 20 12:45:25 2010 From: animator333 at gmail.com (King) Date: Tue, 20 Jul 2010 09:45:25 -0700 (PDT) Subject: Compile python executable only for package deployment on Linux Message-ID: Hi, I have created a simple tool(python script) that creates a self sufficient package ready for deployment. Current implementation is based on shell scripting to set environment for the app and finally execute "python main.py". I am planning to convert "main.py" into an executable. The plan is to rip the unnecessary code from source code that produce python executable such as command line arguments etc, use "main.py" as python string (hardcoded inside executable source) and execute it using "exec" or similar methods and finally creates executable. Am I right here? Is this is the correct approach? For example a simple script: import os import math print math.sin(23.0) print os.getenv("PATH") Once I'll convert above script as i have mentioned above in an executable say: "myapp", executing "myapp" will print messages on console. Cheers Prashant From ranavishal at gmail.com Tue Jul 20 13:04:02 2010 From: ranavishal at gmail.com (Vishal Rana) Date: Tue, 20 Jul 2010 10:04:02 -0700 Subject: How is memory managed in python? In-Reply-To: <4C45C692.8030804@cheimes.de> References: <4C45C692.8030804@cheimes.de> Message-ID: Christian, It stays in RES and VIRT as well. Thanks Vishal Rana On Tue, Jul 20, 2010 at 8:53 AM, Christian Heimes wrote: > Am 20.07.2010 17:50, schrieb Vishal Rana: > > Hi Christian, > > > > I am not sure which one is used in this case, I use htop to see the > memory > > used by apache / python. > > In its default configuration htop reports three different types of > memory usage: virt, res and shr (virtual, resident and shared memory). > Which of them stays at 500 MB? > > Christian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Tue Jul 20 13:25:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Jul 2010 19:25:23 +0200 Subject: Compile python executable only for package deployment on Linux In-Reply-To: References: Message-ID: King, 20.07.2010 18:45: > I have created a simple tool(python script) that creates a self > sufficient package ready for deployment. Current implementation is > based on shell scripting to set environment for the app and finally > execute "python main.py". > > I am planning to convert "main.py" into an executable. The plan is to > rip the unnecessary code from source code that produce python > executable such as command line arguments etc, use "main.py" as python > string (hardcoded inside executable source) and execute it using > "exec" or similar methods and finally creates executable. > > Am I right here? Is this is the correct approach? From what you write here, I'm not exactly sure what you want to achieve, but... > For example a simple script: > > import os > import math > print math.sin(23.0) > print os.getenv("PATH") > > Once I'll convert above script as i have mentioned above in an > executable say: "myapp", executing "myapp" will print messages on > console. Assuming that Python is installed on the machine and readily runnable from the PATH, this will make the script executable: #!/usr/bin/env python import os import math ... Note that the file must have the executable bit set. Search for "shebang", which is the spelled-out name for the "#!" special file prefix. Stefan From hujia06 at gmail.com Tue Jul 20 13:28:41 2010 From: hujia06 at gmail.com (Jia Hu) Date: Tue, 20 Jul 2010 13:28:41 -0400 Subject: How to pass the shell in Python In-Reply-To: References: Message-ID: sub = subprocess.Popen("shell command", shell=True) If you have to wait the shell finishes its commands and then continue the next Python code. You can add another line: sub.wait() On Tue, Jul 20, 2010 at 7:57 AM, S.Selvam wrote: > > > On Tue, Jul 20, 2010 at 7:11 AM, Ranjith Kumar wrote: > >> Hi Folks, >> Can anyone tell me how to run shell commands using python script. >> > >> > > For simple work, i generally use os.system call. > > -- > Regards, > S.Selvam > > " I am because we are " > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jul 20 13:32:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 10:32:12 -0700 Subject: Kick off a delete command from python and not wait In-Reply-To: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> References: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 8:33 AM, loial wrote: > I have a requirement to kick off a shell script from a python script > without waiting for it to complete. I am not bothered about any return > code from the script. > > What is the easiest way to do this. I have looked at popen but cannot > see how to do it. Use the `subprocess` module. import subprocess proc = subprocess.Popen(["shell_script.sh", "arg1", "arg2"], stdout=subprocess.PIPE, stderr=subprcoess.PIPE) # lots of code here doing other stuff proc.wait() I believe you need to /eventually/ call .wait() as shown to avoid the child becoming a zombie process. Cheers, Chris -- http://blog.rebertia.com From animator333 at gmail.com Tue Jul 20 13:42:16 2010 From: animator333 at gmail.com (King) Date: Tue, 20 Jul 2010 10:42:16 -0700 (PDT) Subject: Compile python executable only for package deployment on Linux References: Message-ID: <39ac3ceb-d396-4464-8107-4f5d798e9a4a@y32g2000prc.googlegroups.com> Hi Stefan, Well, the idea is similar to package tools like pyinstaller or cx_freeze. There approach is slightly different then what I intend to do here. You have to pass the name of the script to python executable("python main.py") in order to execute it. What I mean here is to create python executable using python executable source code only(not compilation of entire python using source code) and insert "main.py" contents in source code(hardcoded) and produce a new executable. When you run that executable, it should run the "main.py", which was hard coded while building using fixed string or any other method. The executable is actually a modified version of python executable. It won't take any argument because we'll rip that piece of code out. Hope this will clear out. Cheers prashant From tjreedy at udel.edu Tue Jul 20 15:24:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jul 2010 15:24:42 -0400 Subject: urllib2 test fails (2.7, linux) In-Reply-To: References: Message-ID: On 7/20/2010 7:42 AM, guandalino wrote: > Hi, running Python 2.7 test suite for urllib2 there is a test that > doesn't pass. > Do you have an idea about where the problem could be and how to solve > it? > > Thanks, > best regards. > > $ # ubuntu 8.04 > $ pwd > ~/sandbox/2.7/lib/python2.7/test > $ python test_urllib2.py > ====================================================================== > ERROR: test_file (__main__.HandlerTests) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "test_urllib2.py", line 711, in test_file > h.file_open, Request(url)) Look there to find the complete statement. For 3.1, it would be self.assertRaises(urllib.error.URLError, h.file_open, Request(url)) (urllib2 is now urllib.request) You could insert a print to find what url caused a problem. > File "/home/redt/sandbox/2.7/lib/python2.7/unittest/case.py", line This puzzles me. In 3.1, unittest is a module, unittest.py, not a package containing modules like 'case.py'. I though it was the same for 2.7 > 456, in assertRaises > callableObj(*args, **kwargs) This is in unittest.py. It says that this test case *should* fail, but with a different error (urllib.error.URLError) than the one you got (gaierror). > File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, > in file_open > return self.open_local_file(req) > File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, > in open_local_file > (not port and socket.gethostbyname(host) in self.get_names()): > gaierror: [Errno -5] No address associated with hostname gaierror comes from socket.gethostbyname > Finally, I don't know if this matters but the tests have been executed > offline (without an internet connection). Since error is in open_local_file, I would think not. -- Terry Jan Reedy From b3nder at yandex.ru Tue Jul 20 15:26:52 2010 From: b3nder at yandex.ru (Alexander) Date: Tue, 20 Jul 2010 23:26:52 +0400 Subject: convert time to UTC seconds since epoch Message-ID: <4C45F87C.1040607@yandex.ru> Hi, list How with python standard library to convert string like 'YYYY-MM-DD mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time zone or given in explicit way like +0100. From rami.chowdhury at gmail.com Tue Jul 20 16:46:44 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 20 Jul 2010 13:46:44 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: <4C45F87C.1040607@yandex.ru> References: <4C45F87C.1040607@yandex.ru> Message-ID: <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> On Jul 20, 2010, at 12:26 , Alexander wrote: > Hi, list > > How with python standard library to convert string like 'YYYY-MM-DD > mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time > zone or given in explicit way like +0100. If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? HTH, Rami ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) From kaklis at gmail.com Tue Jul 20 17:38:35 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 20 Jul 2010 14:38:35 -0700 (PDT) Subject: linux console command line history Message-ID: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Hi to all, I 'm writing a linux console app with sockets. It's basically a client app that fires commands in a server. For example: $log user 55 $sessions list $server list etc. What i want is, after entering some commands, to press the up arrow key and see the previous commands that i have executed. Any hints? Any examples? Antonis From nobody at nowhere.com Tue Jul 20 17:44:11 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 20 Jul 2010 22:44:11 +0100 Subject: Kick off a delete command from python and not wait References: <587a2ffd-419e-49e3-922d-e6a50d5ffbb1@g35g2000yqa.googlegroups.com> Message-ID: On Tue, 20 Jul 2010 10:32:12 -0700, Chris Rebert wrote: > I believe you need to /eventually/ call .wait() as shown to avoid the > child becoming a zombie process. Alternatively, you can call .poll() periodically. This is similar to .wait() insofar as it will "reap" the process if it has terminated, but unlike .wait(), .poll() won't block if the process is still running. On Unix, you can use os.fork(), have the child execute the command in the background, and have the parent wait for the child with os.wait(). The child will terminate as soon as it has spawned the grandchild, and the grandchild will be reaped automatically upon termination (so you can forget about it). From benjamin.kaplan at case.edu Tue Jul 20 17:47:00 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 20 Jul 2010 14:47:00 -0700 Subject: linux console command line history In-Reply-To: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 2:38 PM, kaklis at gmail.com wrote: > Hi to all, > I 'm writing a linux console app with sockets. It's basically a client > app that fires commands in a server. > For example: > $log user 55 > $sessions list > $server list etc. > What i want is, after entering some commands, to press the up arrow > key and see the previous commands that i have executed. > Any hints? Any examples? > > Antonis > -- Look at the readline module. http://docs.python.org/library/readline.html From tjreedy at udel.edu Tue Jul 20 17:58:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Jul 2010 17:58:33 -0400 Subject: How to treat the first or last item differently Message-ID: A Python newcomer asked this question on python-ideas list. I am answering here for the benefit of others. Example: building a string res with commas separating substrings s from some sequence. Either the first item added must be s versus ', '+s or the last must be s versus s+', '. For building strings, of course, the join method solves the problem, adding n-1 separators between n items. items = ['first', 'second', 'last'] print(', '.join(items)) #first, second, last DISCLAIMER: All of the following code chunks produce the same result, for the purpose of illustration, but they are NOT the way to build a string result with dependable efficiency. To treat the first item differently, either peel it off first ... it = iter(items) try: # protect against empty it, simplify if know not res = next(it) for s in it: res += ', ' + s except StopIteration: res = '' print(res) # first, second, last or use a flag. res = '' First = True for s in items: if First: res=s First=False else: res += ', ' + s print(res) # first, second, last There is no way, in general, to know whether next(it) will yield another item after the current one. That suggests that the way to know whether an item is the last or not is try to get another first, before processing the current item. One approach is to look ahead ... it = iter(items) res = '' try: cur = next(it) for nxt in it: # cur is not last res += cur + ', ' cur = nxt else: # cur is last item res += cur except StopIteration: pass print(res) # first, second, last Another is to add a unique sentinel to the sequence. Last = object() items.append(Last) # so not empty, so no protection against that needed it = iter(items) res = '' cur = next(it) for nxt in it: if nxt is not Last: res += cur + ', ' cur = nxt else: res += cur print(res) # first, second, last It makes sense to separate last detection from item processing so last detection can be put in a library module and reused. def o_last(iterable): " Yield item,islast pairs" it = iter(iterable) cur = next(it) for nxt in it: yield cur,False cur = nxt else: yield cur,True def comma_join(strings): res = '' for s,last in o_last(strings): res += s if not last: res += ', ' return res print(comma_join(['first', 'second', 'last'])) print(comma_join(['first', 'last'])) print(comma_join(['last'])) print(comma_join([])) # first, second, last # first, last # last # -- Terry Jan Reedy From peter.milliken at gmail.com Tue Jul 20 18:01:03 2010 From: peter.milliken at gmail.com (Peter) Date: Tue, 20 Jul 2010 15:01:03 -0700 (PDT) Subject: Pickle MemoryError - any ideas? Message-ID: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> I have created a class that contains a list of files (contents, binary) - so it uses a LOT of memory. When I first pickle.dump the list it creates a 1.9GByte file on the disk. I can load the contents back again, but when I attempt to dump it again (with or without additions), I get the following: Traceback (most recent call last): File "", line 1, in File "c:\Python26\Lib\pickle.py", line 1362, in dump Pickler(file, protocol).dump(obj) File "c:\Python26\Lib\pickle.py", line 224, in dump self.save(obj) File "c:\Python26\Lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\Python26\Lib\pickle.py", line 600, in save_list self._batch_appends(iter(obj)) File "c:\Python26\Lib\pickle.py", line 615, in _batch_appends save(x) File "c:\Python26\Lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\Python26\Lib\pickle.py", line 488, in save_string self.write(STRING + repr(obj) + '\n') MemoryError I get this error either attempting to dump the entire list or dumping it in "segments" i.e. the list is 2229 elements long, so from the command line I attempted using pickle to dump individual parts of the list into into files i.e. every 500 elements were saved to their own file - but I still get the same error. I used the following sequence when attempting to dump the list in segments - X and Y were 500 element indexes apart, the sequence fails on [1000:1500]: f = open('archive-1', 'wb', 2) pickle.dump(mylist[X:Y], f) f.close() I am assuming that available memory has been exhausted, so I tried "waiting" between dumps in the hopes that garbage collection might free some memory - but that doesn't help at all. In summary: 1. The list gets originally created from various sources 2. the list can be dumped successfully 3. the program restarts and successfully loads the list 4. the list can not be (re) dumped without getting a MemoryError This seems like a bug in pickle? Any ideas (other than the obvious - don't save all of these files contents into a list! Although that is the only "answer" I can see at the moment :-)). Thanks Peter From kwatford+python at gmail.com Tue Jul 20 18:09:22 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 18:09:22 -0400 Subject: Exposing buffer interface for non-extension types? Message-ID: Is there any way to expose the PEP 3118 buffer interface for objects that aren't extension types? Currently, I can expose the NumPy array interface (using either __array_interface__ or __array_struct__) for any class, extension or otherwise. But I can't find any reference to python-side interfacing for PEP 3118. SWIG makes an extension module for your wrapped code, but not extension *types*, so the classes it produces are pure-python with methods added in from the extension module. The NumPy array interface works fine for now (especially since NumPy is the only thing I need to consume these objects), but the documentation claims that it's being deprecated in favor of PEP 3118, so I thought it might be relevant to bring this up. From b3nder at yandex.ru Tue Jul 20 18:51:24 2010 From: b3nder at yandex.ru (Alexander) Date: Wed, 21 Jul 2010 02:51:24 +0400 Subject: convert time to UTC seconds since epoch In-Reply-To: <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> References: <4C45F87C.1040607@yandex.ru> <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> Message-ID: <4C46286C.6010708@yandex.ru> On 21.07.2010 00:46, Rami Chowdhury wrote: > On Jul 20, 2010, at 12:26 , Alexander wrote: > >> Hi, list >> >> How with python standard library to convert string like 'YYYY-MM-DD >> mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time >> zone or given in explicit way like +0100. > If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? > Yes. May be I don't undertand something. but it seems strptime doesn't work with timezones at all. Only understands localzone and dates w/o zones. From stefan_ml at behnel.de Tue Jul 20 18:58:15 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 00:58:15 +0200 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: Ken Watford, 21.07.2010 00:09: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? Given that it's a pure C-level interface, I don't think there would be much use for that. > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. SWIG makes an extension module for your wrapped code, > but not extension *types*, so the classes it produces are pure-python > with methods added in from the extension module. Try using Cython instead, it has native support for the buffer protocol. Stefan From emile at fenx.com Tue Jul 20 19:10:07 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 20 Jul 2010 16:10:07 -0700 Subject: Pickle MemoryError - any ideas? In-Reply-To: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: On 7/20/2010 3:01 PM Peter said... > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > Any ideas? Switch to 64 bit Windows & Python? Emile From kaklis at gmail.com Tue Jul 20 19:12:32 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 20 Jul 2010 16:12:32 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: <7f51c705-e53c-44e4-891f-0f731598f102@d37g2000yqm.googlegroups.com> On Jul 21, 12:47?am, Benjamin Kaplan wrote: > On Tue, Jul 20, 2010 at 2:38 PM, kak... at gmail.com wrote: > > Hi to all, > > I 'm writing a linux console app with sockets. It's basically a client > > app that fires commands in a server. > > For example: > > $log user 55 > > $sessions list > > $server list etc. > > What i want is, after entering some commands, to press the up arrow > > key and see the previous commands that i have executed. > > Any hints? Any examples? > > > Antonis > > -- > > Look at the readline module.http://docs.python.org/library/readline.html ok that's fine, thanks. I have also find a very helpful example in PyMoTW http://www.doughellmann.com/PyMOTW/readline/index.html(Thanks Doug!!!). But if i want to run this in it's own separate thread, how could i do that? there is an # Prompt the user for text input_loop() which is blocking? Antonis K. From pavlovevidence at gmail.com Tue Jul 20 20:06:50 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 17:06:50 -0700 (PDT) Subject: Pickle MemoryError - any ideas? References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: On Jul 20, 3:01?pm, Peter wrote: > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > > When I first pickle.dump the list it creates a 1.9GByte file on the > disk. I can load the contents back again, but when I attempt to dump > it again (with or without additions), I get the following: > > Traceback (most recent call last): > ? File "", line 1, in > ? File "c:\Python26\Lib\pickle.py", line 1362, in dump > ? ? Pickler(file, protocol).dump(obj) > ? File "c:\Python26\Lib\pickle.py", line 224, in dump > ? ? self.save(obj) > ? File "c:\Python26\Lib\pickle.py", line 286, in save > ? ? f(self, obj) # Call unbound method with explicit self > ? File "c:\Python26\Lib\pickle.py", line 600, in save_list > ? ? self._batch_appends(iter(obj)) > ? File "c:\Python26\Lib\pickle.py", line 615, in _batch_appends > ? ? save(x) > ? File "c:\Python26\Lib\pickle.py", line 286, in save > ? ? f(self, obj) # Call unbound method with explicit self > ? File "c:\Python26\Lib\pickle.py", line 488, in save_string > ? ? self.write(STRING + repr(obj) + '\n') > MemoryError (Aside) Wow, pickle concatenates strings like this? > I get this error either attempting to dump the entire list or dumping > it in "segments" i.e. the list is 2229 elements long, so from the > command line I attempted using pickle to dump individual parts of the > list into into files i.e. every 500 elements were saved to their own > file - but I still get the same error. > > I used the following sequence when attempting to dump the list in > segments - X and Y were 500 element indexes apart, the sequence fails > on [1000:1500]: > > f = open('archive-1', 'wb', 2) > pickle.dump(mylist[X:Y], f) > f.close() First thing to do is try cPickle module instead of pickle. > I am assuming that available memory has been exhausted, so I tried > "waiting" between dumps in the hopes that garbage collection might > free some memory - but that doesn't help at all. Waiting won't trigger a garbage collection. Well first of all, it's not garbage collection but cycle collection (objects not part of refernce cycles are collected immediately after they're destroyed, at least they are in CPyhton), and given that your items are all binary data, I doubt there are many reference cycles in your data. Anyway, cycle collection is triggered when object creation/deletion counts meet certain criteria (which won't happen if you are waiting), but you could call gc.collect() to force a cycle collection. > In summary: > > 1. The list gets originally created from various sources > 2. the list can be dumped successfully > 3. the program restarts and successfully loads the list > 4. the list can not be (re) dumped without getting a MemoryError > > This seems like a bug in pickle? No > Any ideas (other than the obvious - don't save all of these files > contents into a list! Although that is the only "answer" I can see at > the moment :-)). You should at least consider if one of the dbm-style databases (dbm, gdbm, or dbhash) meets your needs. Carl Banks From neoethical at gmail.com Tue Jul 20 20:27:26 2010 From: neoethical at gmail.com (neoethical) Date: Tue, 20 Jul 2010 20:27:26 -0400 Subject: Set Python Path for Idle Mac 10.5 Message-ID: Hi, New to programming and after doing some research I've chosed to work with Python. One thing that's bothering me is that I would like to set up a specific folder in my Documents folder to hold my modules. How do I go about doing this? I've found the way to change it for each IDLE session but I'd like to make it check the folder automatically. I've done a bunch of searches and have come up with nothing helpful. Thanks. -Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Jul 20 20:28:12 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 17:28:12 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: Message-ID: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> On Jul 20, 3:09?pm, Ken Watford wrote: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? > > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. SWIG makes an extension module for your wrapped code, > but not extension *types*, so the classes it produces are pure-python > with methods added in from the extension module. > > The NumPy array interface works fine for now (especially since NumPy > is the only thing I need to consume these objects), but the > documentation claims that it's being deprecated in favor of PEP 3118, > so I thought it might be relevant to bring this up. Can you tell let us know what you want to use it for? We could offer better help. Numpy is generally how I get at buffers in Python 2.x. For instance if I have an object m that supports buffer protocol (m could a string, mmap object, Python array, etc.), then the following will create an array view of the same buffer: numpy.ndarray((10,10),type=numpy.float32,buffer=m) As far as I know this procedure won't be too different under PEP 3118; if anything it's simplified in Python 3 since it can discover type and shape information itself. (You'll have to check with the numpy people on that.) Carl Banks From kwatford+python at gmail.com Tue Jul 20 20:38:27 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 20:38:27 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel wrote: > Ken Watford, 21.07.2010 00:09: >> >> Is there any way to expose the PEP 3118 buffer interface for objects >> that aren't extension types? > > Given that it's a pure C-level interface, I don't think there would be much > use for that. Perhaps, but *why* is it only a pure C-level interface? It's based on/inspired by the array interface, which was not a pure C-level interface. Did they simply neglect to provide the functionality due to lack of obvious use cases, or did they consciously decide to drop that functionality? >> Currently, I can expose the NumPy array interface (using either >> __array_interface__ or __array_struct__) for any class, extension or >> otherwise. But I can't find any reference to python-side interfacing >> for PEP 3118. SWIG makes an extension module for your wrapped code, >> but not extension *types*, so the classes it produces are pure-python >> with methods added in from the extension module. > > Try using Cython instead, it has native support for the buffer protocol. I've used Cython before, and I generally like it. But its purpose is slightly different than SWIG's, and does not particularly meet my current project's needs. From nagle at animats.com Tue Jul 20 20:58:03 2010 From: nagle at animats.com (John Nagle) Date: Tue, 20 Jul 2010 17:58:03 -0700 Subject: Pickle MemoryError - any ideas? In-Reply-To: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> References: <749b9b23-e55f-4bb6-a5f9-5b90793fc451@x18g2000pro.googlegroups.com> Message-ID: <4c46462f$0$1608$742ec2ed@news.sonic.net> On 7/20/2010 3:01 PM, Peter wrote: > I have created a class that contains a list of files (contents, > binary) - so it uses a LOT of memory. > > When I first pickle.dump the list it creates a 1.9GByte file on the > disk. I can load the contents back again, but when I attempt to dump > it again (with or without additions), I get the following: Be sure to destroy the pickle object when you're done with it. Don't reuse it. Pickle has a cache - it saves every object pickled, and if the same object shows up more than once, the later instances are represented as a cache ID. This can fill memory unnecessarily. See "http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f8b999c25af263a" John Nagle From ian.g.kelly at gmail.com Tue Jul 20 21:01:48 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Jul 2010 19:01:48 -0600 Subject: convert time to UTC seconds since epoch In-Reply-To: <4C46286C.6010708@yandex.ru> References: <4C45F87C.1040607@yandex.ru> <3435651B-2B22-4873-9DC9-453C842845C3@gmail.com> <4C46286C.6010708@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 4:51 PM, Alexander wrote: > ?On 21.07.2010 00:46, Rami Chowdhury wrote: >> On Jul 20, 2010, at 12:26 , Alexander wrote: >> >>> Hi, list >>> >>> How with python standard library to convert string like 'YYYY-MM-DD >>> mm:HH:SS ZONE' to seconds since epoch in UTC? ZONE may be literal time >>> zone or given in explicit way like +0100. >> If you have a sufficiently recent version of Python, have you considered time.strptime: http://docs.python.org/library/time.html#time.strptime ? >> > Yes. May be I don't undertand something. but it seems strptime doesn't > work with timezones at all. Only understands localzone and dates w/o zones. Have you looked at the dateutil.parser module? It's not part of the standard library but probably does what you need. http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2 Cheers, Ian From kwatford+python at gmail.com Tue Jul 20 21:04:01 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 21:04:01 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote: > On Jul 20, 3:09?pm, Ken Watford wrote: >> Is there any way to expose the PEP 3118 buffer interface for objects >> that aren't extension types? >> >> Currently, I can expose the NumPy array interface (using either >> __array_interface__ or __array_struct__) for any class, extension or >> otherwise. But I can't find any reference to python-side interfacing >> for PEP 3118. SWIG makes an extension module for your wrapped code, >> but not extension *types*, so the classes it produces are pure-python >> with methods added in from the extension module. >> >> The NumPy array interface works fine for now (especially since NumPy >> is the only thing I need to consume these objects), but the >> documentation claims that it's being deprecated in favor of PEP 3118, >> so I thought it might be relevant to bring this up. > > Can you tell let us know what you want to use it for? ?We could offer > better help. > > Numpy is generally how I get at buffers in Python 2.x. ?For instance > if I have an object m that supports buffer protocol (m could a string, > mmap object, Python array, etc.), then the following will create an > array view of the same buffer: > > numpy.ndarray((10,10),type=numpy.float32,buffer=m) > > As far as I know this procedure won't be too different under PEP 3118; > if anything it's simplified in Python 3 since it can discover type and > shape information itself. ?(You'll have to check with the numpy people > on that.) I'm not having trouble using buffers, I'm having trouble providing them. As a part of SWIG-wrapping a larger C++ project, I'm producing some wrappings for Blitz++ arrays. I can extract the shape and stride information from the array object to fill either NumPy's or PEP 3118's appropriate structure. In the case of NumPy, I can easily arrange for the necessary interface on the proxy object to be fulfilled, because NumPy doesn't care what kind of object it's attached to. But the PEP 3118 interface can only be provided by C extension types. One possibility I've considered is injecting a small extension type into the wrapper that provides PEP 3118 by reading the NumPy array interface info off of the object, and then inject it into all appropriate SWIG-generated proxy classes as an additional base class. This isn't a big deal for me - the array interface works just fine, and probably will for longer than I'll be working on this project - but it just struck me as strange that some of my existing array-interface-enabled classes can't be trivially ported to PEP 3118 because they're defined in pure Python modules rather than extension modules. From fabiofz at gmail.com Tue Jul 20 21:09:51 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 20 Jul 2010 22:09:51 -0300 Subject: Pydev 1.6.0 Released Message-ID: Hi All, Pydev 1.6.0 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Debugger o Code-completion added to the debug console o Entries in the debug console are evaluated on a line-by-line basis (previously an empty line was needed) o Threads started with thread.start_new_thread are now properly traced in the debugger o Added method -- pydevd.set_pm_excepthook() -- which clients may use to debug uncaught exceptions o Printing exception when unable to connect in the debugger * General o Interactive console may be created using the eclipse vm (which may be used for experimenting with Eclipse) o Apply patch working (Fixed NPE when opening compare editor in a dialog) o Added compatibility to Aptana Studio 3 (Beta) -- release from July 12th What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From sturlamolden at yahoo.no Tue Jul 20 21:17:17 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 20 Jul 2010 18:17:17 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: Message-ID: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> On 21 Jul, 02:38, Ken Watford wrote: > Perhaps, but *why* is it only a pure C-level interface? It is exposed to Python as memoryview. If memoryview is not sufficient, we can use ctypes.pythonapi to read the C struct. From robert.kern at gmail.com Tue Jul 20 21:26:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 21:26:03 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On 7/20/10 8:38 PM, Ken Watford wrote: > On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel wrote: >> Ken Watford, 21.07.2010 00:09: >>> >>> Is there any way to expose the PEP 3118 buffer interface for objects >>> that aren't extension types? >> >> Given that it's a pure C-level interface, I don't think there would be much >> use for that. > > Perhaps, but *why* is it only a pure C-level interface? It's based > on/inspired by the array interface, which was not a pure C-level > interface. Did they simply neglect to provide the functionality due to > lack of obvious use cases, or did they consciously decide to drop that > functionality? Lack of obvious use cases. The primary use case is for C extensions to communicate with each other. SWIG is the odd man out in that it does not create true extension types. While the functionality of the PEP derives from numpy's interface, it's inclusion in Python was largely seen as the extension of the older buffer interface which is also a pure C interface. The Python-level __array_interface__ numpy API is not and will not be deprecated despite some outdated language in the documentation. Please continue to use 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 greg.hennessy at cox.net Tue Jul 20 21:31:28 2010 From: greg.hennessy at cox.net (Greg Hennessy) Date: Wed, 21 Jul 2010 01:31:28 +0000 (UTC) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: On 2010-07-20, Rami Chowdhury wrote: > If you have a sufficiently recent version of Python, have you >considered time.strptime: >http://docs.python.org/library/time.html#time.strptime ? Given the documentation talks about "double leap seconds" which don't exist, why should this code be trusted? From kwatford+python at gmail.com Tue Jul 20 21:39:23 2010 From: kwatford+python at gmail.com (Ken Watford) Date: Tue, 20 Jul 2010 21:39:23 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On Tue, Jul 20, 2010 at 9:26 PM, Robert Kern wrote: > On 7/20/10 8:38 PM, Ken Watford wrote: >> >> On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel >> ?wrote: >>> >>> Ken Watford, 21.07.2010 00:09: >>>> >>>> Is there any way to expose the PEP 3118 buffer interface for objects >>>> that aren't extension types? >>> >>> Given that it's a pure C-level interface, I don't think there would be >>> much >>> use for that. >> >> Perhaps, but *why* is it only a pure C-level interface? It's based >> on/inspired by the array interface, which was not a pure C-level >> interface. Did they simply neglect to provide the functionality due to >> lack of obvious use cases, or did they consciously decide to drop thaThat >> functionality? > > Lack of obvious use cases. The primary use case is for C extensions to > communicate with each other. SWIG is the odd man out in that it does not > create true extension types. While the functionality of the PEP derives from > numpy's interface, it's inclusion in Python was largely seen as the > extension of the older buffer interface which is also a pure C interface. > > The Python-level __array_interface__ numpy API is not and will not be > deprecated despite some outdated language in the documentation. Please > continue to use it. Thanks, that's good to know. (Someone should probably do something about the big red box that says the opposite in the current docs). I assume the same is true about __array_struct__? Since it *is* an extension despite the non-extension types, filling in a structure is a little more convenient than building the dictionary. From clp2 at rebertia.com Tue Jul 20 21:44:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 18:44:40 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: References: <4C45F87C.1040607@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: > On 2010-07-20, Rami Chowdhury wrote: >> If you have a sufficiently recent version of Python, have you >>considered time.strptime: >>http://docs.python.org/library/time.html#time.strptime ? > > Given the documentation talks about "double leap seconds" which don't > exist, why should this code be trusted? Because they exist(ed) in POSIX. See http://www.ucolick.org/~sla/leapsecs/onlinebib.html : """ The standards committees decided that POSIX time should be UTC, but the early POSIX standards inexplicably incorporated a concept which never existed in UTC -- the ``double leap second''. This mistake reportedly existed in the POSIX standard from 1989, and it persisted in POSIX until at least 1997. """ Cheers, Chris -- http://blog.rebertia.com From greg.hennessy at cox.net Tue Jul 20 21:48:58 2010 From: greg.hennessy at cox.net (Greg Hennessy) Date: Wed, 21 Jul 2010 01:48:58 +0000 (UTC) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: On 2010-07-21, Chris Rebert wrote: > On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: >> Given the documentation talks about "double leap seconds" which don't >> exist, why should this code be trusted? > > Because they exist(ed) in POSIX. Why should POSIX time calculations involving leap seconds be trusted? This is a pet peeve of mine, when will someone actually implement leap seconds correctly? And as a professional astronomer myself, I'm well aware of Steve Allen's website. :) From clp2 at rebertia.com Tue Jul 20 21:57:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 20 Jul 2010 18:57:44 -0700 Subject: convert time to UTC seconds since epoch In-Reply-To: References: <4C45F87C.1040607@yandex.ru> Message-ID: On Tue, Jul 20, 2010 at 6:48 PM, Greg Hennessy wrote: > On 2010-07-21, Chris Rebert wrote: >> On Tue, Jul 20, 2010 at 6:31 PM, Greg Hennessy wrote: >>> Given the documentation talks about "double leap seconds" which don't >>> exist, why should this code be trusted? >> >> Because they exist(ed) in POSIX. > > Why should POSIX time calculations involving leap seconds be trusted? I'm not saying they necessarily should, but they're standardized and the `time` module is based on POSIX/Unix-ish assumptions; not following POSIX would be inconsistent and problematic. Breaking standards is bad, M'Kay? > This is a pet peeve of mine, when will someone actually implement leap > seconds correctly? Well, at least there's the possibility they will be eliminated in the future anyway, which would make their implementation a non-issue. :-) Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Tue Jul 20 21:58:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 21:58:15 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: Message-ID: On 7/20/10 9:39 PM, Ken Watford wrote: > On Tue, Jul 20, 2010 at 9:26 PM, Robert Kern wrote: >> On 7/20/10 8:38 PM, Ken Watford wrote: >>> >>> On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel >>> wrote: >>>> >>>> Ken Watford, 21.07.2010 00:09: >>>>> >>>>> Is there any way to expose the PEP 3118 buffer interface for objects >>>>> that aren't extension types? >>>> >>>> Given that it's a pure C-level interface, I don't think there would be >>>> much >>>> use for that. >>> >>> Perhaps, but *why* is it only a pure C-level interface? It's based >>> on/inspired by the array interface, which was not a pure C-level >>> interface. Did they simply neglect to provide the functionality due to >>> lack of obvious use cases, or did they consciously decide to drop thaThat >>> functionality? >> >> Lack of obvious use cases. The primary use case is for C extensions to >> communicate with each other. SWIG is the odd man out in that it does not >> create true extension types. While the functionality of the PEP derives from >> numpy's interface, it's inclusion in Python was largely seen as the >> extension of the older buffer interface which is also a pure C interface. >> >> The Python-level __array_interface__ numpy API is not and will not be >> deprecated despite some outdated language in the documentation. Please >> continue to use it. > > Thanks, that's good to know. (Someone should probably do something > about the big red box that says the opposite in the current docs). I just did. I'm sorry; we had a discussion about that some time ago, and I thought we had removed it then. > I assume the same is true about __array_struct__? Since it *is* an > extension despite the non-extension types, filling in a structure is a > little more convenient than building the dictionary. Yes, __array_struct__ is also not deprecated. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Tue Jul 20 22:02:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 22:02:17 -0400 Subject: Exposing buffer interface for non-extension types? In-Reply-To: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> References: <1b3b12fe-240a-4f5c-a756-499818f1598a@5g2000yqz.googlegroups.com> Message-ID: On 7/20/10 9:17 PM, sturlamolden wrote: > On 21 Jul, 02:38, Ken Watford wrote: > >> Perhaps, but *why* is it only a pure C-level interface? > > It is exposed to Python as memoryview. That's not really his question. His question is why there is no way for a pure Python class (like SWIG wrappers) have no way to expose the buffer interface. memoryview allows pure Python code to *consume* the buffer interface but not for pure Python classes to *provide* 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 j.m.girven at warwick.ac.uk Tue Jul 20 22:13:29 2010 From: j.m.girven at warwick.ac.uk (D2Hitman) Date: Tue, 20 Jul 2010 19:13:29 -0700 (PDT) Subject: Multidimensional Fitting Message-ID: <29221343.post@talk.nabble.com> I want to fit an n-dimensional distribution with an n-dimensional gaussian. So far i have managed to do this in 2d (see below). I am not sure how to convert this to work in n-dimensions. Using "ravel" on the arrays is not ideal, but optimize does not appear to work on multidimensional arrays. It seems "meshgrid" also does not translate to nd. import numpy as np from scipy import optimize #2D #random points N = 1000 nd = 2 a = np.random.normal(loc=[1.,2.], scale=[1.,2.], size=[N,nd]) #histogram points bins = [10, 20] H, e = np.histogramdd(a, bins=bins) #find center rather than left edge edges = [] for i in range(len(e)): edges.append( e[i][:-1] + np.diff(e[i])/2. ) #not n-dimensional x, y = np.meshgrid(edges[0], edges[1]) x, y = np.ravel(x), np.ravel(y) H = np.ravel(H) #2D gaussian gauss2d = lambda p, x, y: p[0] * np.exp( (-0.5*(x-p[1])**2/p[2]**2) - (0.5*(y-p[3])**2/p[4]**2) ) + p[5] residuals = lambda p, x, y, H: H - gauss2d(p, x, y) #Fitting p0 = [1., 0., 1., 0., 1., 0] plsq, cov_x, infodict, mesg, ier = optimize.leastsq(residuals, p0, args=(x, y, H), full_output=True) #Reading off _x, _y = 0.091, 1.293 print '%.3f %.3f %.4f' % (_x, _y, gauss2d(plsq, _x,_y) / plsq[0]) -- View this message in context: http://old.nabble.com/Multidimensional-Fitting-tp29221343p29221343.html Sent from the Python - python-list mailing list archive at Nabble.com. From pavlovevidence at gmail.com Tue Jul 20 22:14:22 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 20 Jul 2010 19:14:22 -0700 (PDT) Subject: Exposing buffer interface for non-extension types? References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: On Jul 20, 6:04?pm, Ken Watford wrote: > On Tue, Jul 20, 2010 at 8:28 PM, Carl Banks wrote: > > On Jul 20, 3:09?pm, Ken Watford wrote: > >> Is there any way to expose the PEP 3118 buffer interface for objects > >> that aren't extension types? > > >> Currently, I can expose the NumPy array interface (using either > >> __array_interface__ or __array_struct__) for any class, extension or > >> otherwise. But I can't find any reference to python-side interfacing > >> for PEP 3118. SWIG makes an extension module for your wrapped code, > >> but not extension *types*, so the classes it produces are pure-python > >> with methods added in from the extension module. > > >> The NumPy array interface works fine for now (especially since NumPy > >> is the only thing I need to consume these objects), but the > >> documentation claims that it's being deprecated in favor of PEP 3118, > >> so I thought it might be relevant to bring this up. > > > Can you tell let us know what you want to use it for? ?We could offer > > better help. > > > Numpy is generally how I get at buffers in Python 2.x. ?For instance > > if I have an object m that supports buffer protocol (m could a string, > > mmap object, Python array, etc.), then the following will create an > > array view of the same buffer: > > > numpy.ndarray((10,10),type=numpy.float32,buffer=m) > > > As far as I know this procedure won't be too different under PEP 3118; > > if anything it's simplified in Python 3 since it can discover type and > > shape information itself. ?(You'll have to check with the numpy people > > on that.) > > I'm not having trouble using buffers, I'm having trouble providing them. I see. > As a part of SWIG-wrapping a larger C++ project, I'm producing some > wrappings for Blitz++ arrays. I can extract the shape and stride > information from the array object to fill either NumPy's or PEP 3118's > appropriate structure. In the case of NumPy, I can easily arrange for > the necessary interface on the proxy object to be fulfilled, because > NumPy doesn't care what kind of object it's attached to. But the PEP > 3118 interface can only be provided by C extension types. Well, let's get the facts straight before proceeding. The buffer protocol has always been for C only. PEP 3118 is an extension to this buffer protocol, so it's also C only. Numpy's array interface is not the buffer protocol, and is specific to numpy (though I guess other types are free to use it among themselves, if they wish). So what you've been doing was *not* to provide buffers; it was to provide some numpy-specific methods that allowed numpy to discover your buffers. That said, your complaint is reasonable. And since the numpy docs say "use PEP 3118 instead of array interface" your misunderstanding is understandable. I assume it's not practical to address your real problem (i.e., SWIG), so we'll instead take it for granted that you have a block of memory in some custom C code that you can't expose as a real buffer. In the past, you've used numpy's special Python methods to let numpy know where your memory block was, but what do you do now? Your suggestion to write a small base class is probably the best you can do as things stand now. Another thing you can do is write a small extension to create a surrogate buffer object (that implements buffer protocol), so if you want to create an ndarray from a buffer you can do it like this: b = create_surrogate_buffer(pointer=_proxy.get_buffer_pointer()) numpy.ndarray(shape=_proxy.get_shape(),type=_proxy.get_type(),buffer=b) Not as convenient to use, but might be simpler to code up than the base-class solution. The numpy developers might be sympathetic to your concerns since you have a reasonable use case (they might also tell you you need to get a real wrapper generator). Just be sure to keep the distinction clear between "buffer protocol" (which is what PEP 3118 is, is C only, and the buffer must be owned by a Python object) and "array interface" (which is what you were using for 2.x, is C or Python, and the buffer can be anywhere). HTH Carl Banks From robert.kern at gmail.com Tue Jul 20 22:22:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Jul 2010 22:22:27 -0400 Subject: Multidimensional Fitting In-Reply-To: <29221343.post@talk.nabble.com> References: <29221343.post@talk.nabble.com> Message-ID: On 7/20/10 10:13 PM, D2Hitman wrote: > > I want to fit an n-dimensional distribution with an n-dimensional gaussian. > So far i have managed to do this in 2d (see below). I am not sure how to > convert this to work in n-dimensions. Using "ravel" on the arrays is not > ideal, but optimize does not appear to work on multidimensional arrays. It > seems "meshgrid" also does not translate to nd. You will want to ask scipy questions on the scipy mailing list: http://www.scipy.org/Mailing_Lists Don't try to fit a Gaussian to a histogram using least-squares. It's an awful way to estimate the parameters. Just use np.mean() and np.cov() to estimate the mean and covariance matrix directly. -- 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 nad at acm.org Tue Jul 20 22:48:19 2010 From: nad at acm.org (Ned Deily) Date: Tue, 20 Jul 2010 19:48:19 -0700 Subject: Set Python Path for Idle Mac 10.5 References: Message-ID: In article , neoethical wrote: > New to programming and after doing some research I've chosed to work with > Python. One thing that's bothering me is that I would like to set up a > specific folder in my Documents folder to hold my modules. How do I go about > doing this? I've found the way to change it for each IDLE session but I'd > like to make it check the folder automatically. I've done a bunch of > searches and have come up with nothing helpful. On OS X, depending on which version of Python you are using, there are usually two ways to start IDLE: either by launching IDLE.app (often found in /Applications/Python x.y or /Applications/MacPython x.y) or by invoking IDLE from the command line (generally something like /usr/local/bin/idlex.y). When started from a terminal command line, IDLE uses the current working directory ("folder") as the default for opening and saving files from the shell window. When you "launch" IDLE.app (by double-clicking on its icon, for example), it always uses Documents as the default working directory. Unfortunately, AFAIK, there is no built-in way to specify a different default for the shell window, which is a bit annoying. The simplest way to work around it, I think, would be to always start IDLE from the command line after changing to the desired default directory. So, from a terminal session (in Terminal.app or equivalent), something like this for, say, python3.1 installed from python.org: cd /path/to/default/directory /usr/local/bin/idle3.1 The equivalent could be turned into a shell function or alias or an AppleScript app or Automator action. >From the command line, you can also give IDLE a list of one or more files to open, each in its own file window. When the focus is on a file window, file command such as open and save default to the directory of the opened file (this is also true in IDLE.app). So you could have something like this: cd /path/to/project/directory /usr/local/bin/idle3.1 my_mod_1.py my_mod_2.py ... or, if you want to edit all of the python modules in a directory: cd /path/to/project/directory /usr/local/bin/idle3.1 *.py You can achieve a similar effect (except for the shell window) in the Finder by dragging the files to the IDLE.app icon (in a Finder window or on the dock). Double-clicking on the .py files themselves can be made to work but it's a bit of a crap shoot which version of IDLE or other app might actually be launched; it's best to avoid depending on that mechanism. -- Ned Deily, nad at acm.org From jason at powerpull.net Tue Jul 20 23:04:37 2010 From: jason at powerpull.net (Jason Friedman) Date: Wed, 21 Jul 2010 03:04:37 +0000 Subject: Trying to redirect every urel request to test.py script with the visitors page request as url parameter. In-Reply-To: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> References: <62cddc8c-45b7-47b9-88a1-f1724ffc96df@f6g2000yqa.googlegroups.com> Message-ID: 2010/7/20 ????? : > Hello guys! This is my first post in this group! I do not have an answer to your question, other than to suggest you look at (and/or post) relevant lines from Apache's access.log and error.log. I write mostly to say that, in my experience, folks on this list are very helpful, but your post has many, many spelling errors, making it difficult to read. It looks like you are using Gmail, which has a "Check Spelling" drop-down on the compose window. If you re-post with better spelling you might get more responses. From j.m.girven at warwick.ac.uk Tue Jul 20 23:56:40 2010 From: j.m.girven at warwick.ac.uk (D2Hitman) Date: Tue, 20 Jul 2010 20:56:40 -0700 (PDT) Subject: Multidimensional Fitting In-Reply-To: References: <29221343.post@talk.nabble.com> Message-ID: <29221776.post@talk.nabble.com> Robert Kern-2 wrote: > > Don't try to fit a Gaussian to a histogram using least-squares. It's an > awful > way to estimate the parameters. Just use np.mean() and np.cov() to > estimate the > mean and covariance matrix directly. > Ok, what about distributions other than gaussian? Would you use leastsq in that case? If yes, i will post that to the scipy mailing list. -- View this message in context: http://old.nabble.com/Multidimensional-Fitting-tp29221343p29221776.html Sent from the Python - python-list mailing list archive at Nabble.com. From robert.kern at gmail.com Wed Jul 21 00:31:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 Jul 2010 00:31:29 -0400 Subject: Multidimensional Fitting In-Reply-To: <29221776.post@talk.nabble.com> References: <29221343.post@talk.nabble.com> <29221776.post@talk.nabble.com> Message-ID: On 7/20/10 11:56 PM, D2Hitman wrote: > > > Robert Kern-2 wrote: >> >> Don't try to fit a Gaussian to a histogram using least-squares. It's an >> awful >> way to estimate the parameters. Just use np.mean() and np.cov() to >> estimate the >> mean and covariance matrix directly. >> > > Ok, what about distributions other than gaussian? Would you use leastsq in > that case? If yes, i will post that to the scipy mailing list. No, you would use a maximum likelihood method. -- 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 michele.simionato at gmail.com Wed Jul 21 02:03:41 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 20 Jul 2010 23:03:41 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: On Jul 20, 11:38?pm, "kak... at gmail.com" wrote: > Hi to all, > I 'm writing a linux console app with sockets. It's basically a client > app that fires commands in a server. > For example: > $log user 55 > $sessions list > $server list etc. > What i want is, after entering some commands, to press the up arrow > key and see the previous commands that i have executed. > Any hints? Any examples? > > Antonis You may find interesting to look at the source code for plac (http:// micheles.googlecode.com/hg/plac/doc/plac_adv.html). The readline support (including command history and autocompletion) is implemented in the ReadlineInput class (see http://code.google.com/p/micheles/source/browse/plac/plac_ext.py). If you just want command history you can use rlwrap (http:// freshmeat.net/projects/rlwrap). From kaklis at gmail.com Wed Jul 21 04:03:27 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 01:03:27 -0700 (PDT) Subject: linux console command line history References: <672238b7-2096-4d2e-a610-1c7328cecf3e@j8g2000yqd.googlegroups.com> Message-ID: <63733ddf-9068-4e60-a031-141e20c571aa@f6g2000yqa.googlegroups.com> On Jul 21, 9:03?am, Michele Simionato wrote: > On Jul 20, 11:38?pm, "kak... at gmail.com" wrote: > > > Hi to all, > > I 'm writing a linux console app with sockets. It's basically a client > > app that fires commands in a server. > > For example: > > $log user 55 > > $sessions list > > $server list etc. > > What i want is, after entering some commands, to press the up arrow > > key and see the previous commands that i have executed. > > Any hints? Any examples? > > > Antonis > > You may find interesting to look at the source code for plac (http:// > micheles.googlecode.com/hg/plac/doc/plac_adv.html). The readline > support (including command history and autocompletion) is implemented > in the ReadlineInput class (seehttp://code.google.com/p/micheles/source/browse/plac/plac_ext.py). > If you just want command history you can use rlwrap (http:// > freshmeat.net/projects/rlwrap). That's great! thank you so much Michele! Antonis From __peter__ at web.de Wed Jul 21 04:16:42 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Jul 2010 10:16:42 +0200 Subject: How to treat the first or last item differently References: Message-ID: Terry Reedy wrote: > It makes sense to separate last detection from item processing so last > detection can be put in a library module and reused. Here's an extension of your idea that puts the detection of both the first and the last item into a generator: def mark_first(items): items = iter(items) yield True, next(items) for item in items: yield False, item def mark_last(items): items = iter(items) prev = next(items) for cur in items: yield False, prev prev = cur yield True, prev def mark_ends(items): return ((head, tail, item) for head, (tail, item) in mark_first(mark_last(items))) for items in "", "a", "ab", "abc": print list(items), "-->", list(mark_ends(items)) for first, last, item in mark_ends("abc"): if first: print "first", if last: print "last", print item It may not be the most efficient approach, but it looks clean. From stefan_ml at behnel.de Wed Jul 21 04:26:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 10:26:03 +0200 Subject: Exposing buffer interface for non-extension types? In-Reply-To: References: <422bfcff-9f85-4960-9647-7a752d8a8a62@d16g2000yqb.googlegroups.com> Message-ID: Ken Watford, 21.07.2010 03:04: >>> Currently, I can expose the NumPy array interface (using either >>> __array_interface__ or __array_struct__) for any class, extension or >>> otherwise. But I can't find any reference to python-side interfacing >>> for PEP 3118. SWIG makes an extension module for your wrapped code, >>> but not extension *types*, so the classes it produces are pure-python >>> with methods added in from the extension module. >> >> Try using Cython instead, it has native support for the buffer protocol. > > I've used Cython before, and I generally like it. But its purpose is > slightly different than SWIG's, and does not particularly meet my > current project's needs. >[...] > As a part of SWIG-wrapping a larger C++ project, I'm producing some > wrappings for Blitz++ arrays. Right, support for C++ templates in Cython isn't as good yet as it could be, although there has been some work in that direction. Contributions are welcome. However, note that you can write the tiny bit of plain C++ glue code necessary to access the Blitz++ arrays, and then use Cython to wrap that and to implement the buffer interface and all the other wrapper code. C++ support by itself is pretty good in Cython 0.13. (to be released soon, get it from here: http://hg.cython.org/cython-closures ) Stefan From massi_srb at msn.com Wed Jul 21 04:55:18 2010 From: massi_srb at msn.com (Massi) Date: Wed, 21 Jul 2010 01:55:18 -0700 (PDT) Subject: SQLalchemy+py2exe+pymssql error Message-ID: <433760cb-e55f-4778-a357-0649aa8b9f71@x21g2000yqa.googlegroups.com> Hi everyone, I'm trying to build an executable with py2exe. My script uses SQLalchemy and pymssql with python 2.6. Here is my setup file: from distutils.core import setup import py2exe manifest = """ myProgram """ setup(name="MyProg", windows=[{"script": "MyProg.py", "other_resources": [(24,1,manifest)]}], options={"py2exe": {"includes":[ "sqlalchemy.dialects.mssql", "pymssql", "_mssql"]}} ) The executable is successfully built up, but when I run the program I get the following error message: Exception in thread Thread-3: Traceback (most recent call last): File "threading.pyc", line 532, in __bootstrap_inner File "threading.pyc", line 484, in run File "MyProg.py", line 166, in DatabaseSetup File "sqlalchemy\engine\__init__.pyc", line 241, in create_engine File "sqlalchemy\engine\strategies.pyc", line 60, in create File "sqlalchemy\dialects\mssql\pymssql.pyc", line 61, in dbapi File "pymssql.pyc", line 12, in File "pymssql.pyc", line 10, in __load File "_mssql.pxd", line 10, in init pymssql (pymssql.c:7364) File "_mssql.pyc", line 12, in File "_mssql.pyc", line 10, in __load File "_mssql.pyx", line 36, in init _mssql (_mssql.c:14941) ImportError: No module named uuid Can anyone point me out what I am doing wrong? Thanks you in advance! From bluefisher80 at gmail.com Wed Jul 21 04:56:44 2010 From: bluefisher80 at gmail.com (Jim Qiu) Date: Wed, 21 Jul 2010 16:56:44 +0800 Subject: source install of python2.7 and rpm install of cx_Oracle collision Message-ID: Hi all, I make installed python 2.7 from source, and also installed the RPM version of cx_Oracle for python 2.7. But ldd tells me : #ldd cx_Oracle.so libpython2.7.so.1.0 => not found I find out that only libpython2.7.a generated when I install python2.7, who can tell me what I need to do ? I want a libpython2.7.so.1.0 generated when I install python. I am not familiar with GCC and .so .a stuff. Best regards, Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Jul 21 05:58:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 21 Jul 2010 11:58:41 +0200 Subject: Exposing buffer interface for non-extension types? References: Message-ID: <20100721115841.49d25acc@pitrou.net> On Tue, 20 Jul 2010 18:09:22 -0400 Ken Watford wrote: > Is there any way to expose the PEP 3118 buffer interface for objects > that aren't extension types? > > Currently, I can expose the NumPy array interface (using either > __array_interface__ or __array_struct__) for any class, extension or > otherwise. But I can't find any reference to python-side interfacing > for PEP 3118. There is none, but feel free to make a proposal on python-ideas if you think there's an use case for it. Regards Antoine. From fetchinson at googlemail.com Wed Jul 21 06:02:09 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 21 Jul 2010 12:02:09 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: > I make installed python 2.7 from source, and also installed the RPM version > of cx_Oracle for python 2.7. > > But ldd tells me : > #ldd cx_Oracle.so > libpython2.7.so.1.0 => not found > > I find out that only libpython2.7.a generated when I install python2.7, who > can tell me what I need to do ? I want a libpython2.7.so.1.0 generated when > > > I install python. > > I am not familiar with GCC and .so .a stuff. In this case I'd recommend removing the source install of python 2.7, install it from rpm, followed by installing cx_Oracle from rpm. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kaklis at gmail.com Wed Jul 21 08:36:21 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 05:36:21 -0700 (PDT) Subject: Sorting a list created from a parsed xml message Message-ID: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Hi pythonistas, >From the subject of my message it's clear that i get an xml message from a socket, i parse it and the result is a list like the one that follows: ID_Col 4 Server ak ip OFFLINE 29 Server and2 ip OFFLINE 5 Proxy l34e ip OFFLINE 6 Proxy barc ip ONLINE 41 Proxy proxy-2 ip ONLINE 53 Server server-4 ip ONLINE 52 Server server-3 ip ONLINE What i want is to print this list sorted by ID_Col? Any Suggestions? Antonis K. From holger.brunck at keymile.com Wed Jul 21 08:57:28 2010 From: holger.brunck at keymile.com (Holger brunck) Date: Wed, 21 Jul 2010 14:57:28 +0200 Subject: detect endianness of a binary with python Message-ID: <4C46EEB8.6070702@keymile.com> Hi all, I use python 2.5 and I am looking for a possibility to determine a file type. Especially the endianness of a file is needed for me. Is there a way to detect this easily in python? Something like the "file" utility for linux would be very helpfull. Any help is appreciated. Best regards Holger Brunck From stefan_ml at behnel.de Wed Jul 21 08:58:53 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 14:58:53 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Message-ID: kaklis at gmail.com, 21.07.2010 14:36: > From the subject of my message it's clear that i get an xml message > from a socket, Not at all, but now that you say it... > i parse it and the result is a list like the one that > follows: > ID_Col > 4 Server ak ip OFFLINE > > 29 Server and2 ip OFFLINE > > 5 Proxy l34e ip OFFLINE > > 6 Proxy barc ip ONLINE > > 41 Proxy proxy-2 ip ONLINE > > 53 Server server-4 ip ONLINE > > 52 Server server-3 ip ONLINE Doesn't look like a Python list to me... > What i want is to print this list sorted by ID_Col? > Any Suggestions? Assuming that the above is supposed to represent a list of tuples, you can use the .sort() method on the list and pass operator.itemgetter(0) as 'key' argument (see the sort() method and the operator module). Stefan From kaklis at gmail.com Wed Jul 21 09:04:16 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 06:04:16 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> Message-ID: <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> On Jul 21, 8:58?am, Stefan Behnel wrote: > kak... at gmail.com, 21.07.2010 14:36: > > > From the subject of my message it's clear that i get an xml message > > from a socket, > > Not at all, but now that you say it... > > > > > i parse it and the result is a list like the one that > > follows: > > ID_Col > > 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > > 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > > 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > > 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > > 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > > 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > > 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > Doesn't look like a Python list to me... > > > What i want is to print this list sorted by ID_Col? > > Any Suggestions? > > Assuming that the above is supposed to represent a list of tuples, you can > use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > argument (see the sort() method and the operator module). > > Stefan No it is not a Python list at all. This the way i print the parsed items 'like a list'. But i want them to be sorted. From neilc at norwich.edu Wed Jul 21 09:15:25 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 21 Jul 2010 13:15:25 GMT Subject: An ODBC interface for Python 3? Message-ID: <8aoa7dFuu2U1@mid.individual.net> A quick web search yielded no current support for the ODBC interface for Python 3. I'd like to get a simple "tracer bullet" up and running ASAP. I need to connect to an MSSQL database from Windows XP/2000, using an ODBC interface. Is this a case where I'll need to go back to Python 2.6? -- Neil Cerutti From kaklis at gmail.com Wed Jul 21 09:38:26 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 21 Jul 2010 06:38:26 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> Message-ID: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> On Jul 21, 9:04?am, "kak... at gmail.com" wrote: > On Jul 21, 8:58?am, Stefan Behnel wrote: > > > > > kak... at gmail.com, 21.07.2010 14:36: > > > > From the subject of my message it's clear that i get an xml message > > > from a socket, > > > Not at all, but now that you say it... > > > > i parse it and the result is a list like the one that > > > follows: > > > ID_Col > > > 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > > > 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > > > 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > > > 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > > > 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > > > 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > > > 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > > Doesn't look like a Python list to me... > > > > What i want is to print this list sorted by ID_Col? > > > Any Suggestions? > > > Assuming that the above is supposed to represent a list of tuples, you can > > use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > > argument (see the sort() method and the operator module). > > > Stefan > > No it is not a Python list at all. This the way i print the parsed > items 'like a list'. > But i want them to be sorted. Well i did this: SortedServers = [] for session in sessions: for IP in session.getElementsByTagName("ipAddress"): for iphn in session.getElementsByTagName("hostName"): tempTuple = session.getAttribute("id"), session.getAttribute("type"), iphn.childNodes[0].data, IP.childNodes[0].data, session.getAttribute("status") SortedServers.append(tempTuple) Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) for item in Sorted: print item but the list is still unsorted and with u' in front of each item (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') How do i remove the u' Antonis From stefan_ml at behnel.de Wed Jul 21 09:49:57 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Jul 2010 15:49:57 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: kaklis at gmail.com, 21.07.2010 15:38: > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: >> On Jul 21, 8:58 am, Stefan Behnel wrote: >> >> >> >>> kak... at gmail.com, 21.07.2010 14:36: >> >>>> From the subject of my message it's clear that i get an xml message >>>> from a socket, >> >>> Not at all, but now that you say it... >> >>>> i parse it and the result is a list like the one that >>>> follows: >>>> ID_Col >>>> 4 Server ak ip OFFLINE >> >>>> 29 Server and2 ip OFFLINE >> >>>> 5 Proxy l34e ip OFFLINE >> >>>> 6 Proxy barc ip ONLINE >> >>>> 41 Proxy proxy-2 ip ONLINE >> >>>> 53 Server server-4 ip ONLINE >> >>>> 52 Server server-3 ip ONLINE >> >>> Doesn't look like a Python list to me... >> >>>> What i want is to print this list sorted by ID_Col? >>>> Any Suggestions? >> >>> Assuming that the above is supposed to represent a list of tuples, you can >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' >>> argument (see the sort() method and the operator module). >> >>> Stefan >> >> No it is not a Python list at all. This the way i print the parsed >> items 'like a list'. >> But i want them to be sorted. > > Well i did this: > > SortedServers = [] > > for session in sessions: > for IP in session.getElementsByTagName("ipAddress"): > for iphn in session.getElementsByTagName("hostName"): > tempTuple = session.getAttribute("id"), > session.getAttribute("type"), iphn.childNodes[0].data, > IP.childNodes[0].data, session.getAttribute("status") > > SortedServers.append(tempTuple) > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) > for item in Sorted: > print item > > but the list is still unsorted and with u' in front of each item > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') It seems you want to sort the list numerically. In that case, use int(SortedServers[0]) as the key. Sorting by string values will sort the list lexicographically. > How do i remove the u' You should read the Python tutorial, specifically the sections about strings. Then, read the sections on lists and sequences. In short: Don't care about the "u'" prefix, that's just fine. Stefan From mail at timgolden.me.uk Wed Jul 21 09:51:56 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 21 Jul 2010 14:51:56 +0100 Subject: An ODBC interface for Python 3? In-Reply-To: <8aoa7dFuu2U1@mid.individual.net> References: <8aoa7dFuu2U1@mid.individual.net> Message-ID: <4C46FB7C.7080508@timgolden.me.uk> On 21/07/2010 2:15 PM, Neil Cerutti wrote: > A quick web search yielded no current support for the ODBC > interface for Python 3. > > I'd like to get a simple "tracer bullet" up and running ASAP. I > need to connect to an MSSQL database from Windows XP/2000, using > an ODBC interface. > > Is this a case where I'll need to go back to Python 2.6? > pyodbc has a branch which supports Py3k. I've installed it and it worked ok. Can't get hold of the web at the moment, but I'm sure you'll be able to find it. TJG From neilc at norwich.edu Wed Jul 21 09:58:58 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 21 Jul 2010 13:58:58 GMT Subject: An ODBC interface for Python 3? References: <8aoa7dFuu2U1@mid.individual.net> Message-ID: <8aocp1Fm37U1@mid.individual.net> On 2010-07-21, Tim Golden wrote: > On 21/07/2010 2:15 PM, Neil Cerutti wrote: >> A quick web search yielded no current support for the ODBC >> interface for Python 3. >> >> I'd like to get a simple "tracer bullet" up and running ASAP. I >> need to connect to an MSSQL database from Windows XP/2000, using >> an ODBC interface. >> >> Is this a case where I'll need to go back to Python 2.6? > > pyodbc has a branch which supports Py3k. I've installed it and > it worked ok. Can't get hold of the web at the moment, but I'm > sure you'll be able to find it. Thanks, Tim. I did see that support for pyodbc for Python 3 was really close to being released. There's odbc support using pywin32's odbc module as well, which should be more than sufficient. My web search skillz apparently were not up to snuff this morning. -- Neil Cerutti From invalid at invalid.invalid Wed Jul 21 10:02:16 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 21 Jul 2010 14:02:16 +0000 (UTC) Subject: detect endianness of a binary with python References: Message-ID: On 2010-07-21, Holger brunck wrote: > I use python 2.5 and I am looking for a possibility to determine a > file type. Especially the endianness of a file is needed for me. Is > there a way to detect this easily in python? Only if you already know what's going to be in the file. > Something like the "file" utility for linux would be very helpfull. > > Any help is appreciated. You're going to have to describe in detail what's in the file before anybody can help. -- Grant Edwards grant.b.edwards Yow! A shapely CATHOLIC at SCHOOLGIRL is FIDGETING gmail.com inside my costume.. From brandon.harris at reelfx.com Wed Jul 21 10:42:23 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 09:42:23 -0500 Subject: Multiline regex In-Reply-To: References: Message-ID: <4C47074F.4090507@reelfx.com> I'm trying to read in and parse an ascii type file that contains information that can span several lines. Example: createNode animCurveTU -n "test:master_globalSmooth"; setAttr ".tan" 9; setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; setAttr -s 4 ".kit[3]" 10; setAttr -s 4 ".kot[3]" 10; createNode animCurveTU -n "test:master_res"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; I'm wanting to grab the information out in chunks, so createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; would be what my regex would grab. I'm currently only able to grab out the first line and part of the second line, but no more. regex is as follows my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") I've run several variations of this, but none return me all of the expected information. Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? Brandon L. Harris From torriem at gmail.com Wed Jul 21 10:44:57 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 21 Jul 2010 08:44:57 -0600 Subject: detect endianness of a binary with python In-Reply-To: References: Message-ID: <4C4707E9.9030201@gmail.com> On 07/21/2010 08:02 AM, Grant Edwards wrote: > On 2010-07-21, Holger brunck wrote: > >> I use python 2.5 and I am looking for a possibility to determine a >> file type. Especially the endianness of a file is needed for me. Is >> there a way to detect this easily in python? > > Only if you already know what's going to be in the file. > >> Something like the "file" utility for linux would be very helpfull. >> >> Any help is appreciated. > > You're going to have to describe in detail what's in the file before > anybody can help. There is a python module called "magic" that uses the same engine as file to determine a file type. It's part of the "find" source code: http://www.darwinsys.com/file/ On Fedora I can just yum install python-magic to get it. From daniel at stutzbachenterprises.com Wed Jul 21 10:47:08 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 09:47:08 -0500 Subject: ANN: blist 1.2.0 Message-ID: The blist package contains several container types to supplement those built-in to Python. These types closely mirror the built-in types' methods, so the learning curve is close to zero. The package includes: - blist: a list type with O(log n) insertions, deletes, and slices and other performance enhancements - btuple: a tuple type with O(log) slices - sorteddict: a dict type that efficiently keeps keys in sorted order - sortedlist: a list type that efficiently keeps the items sorted order - sortedset: an indexable set type that efficiently keeps the items sorted order - weaksortedlist, weaksortedset: weak reference versions of sortedlist and sortedset What's new? ----------- - blist.sort() is now *substantially* faster than list.sort() when using int or float keys (O(n) vs. O(n log n)) - The sortedset, sortedlist, and sorteddict types have been revamped for better compatibility with the standard library's types. - Comprehensive reference documentation is now available at http://stutzbachenterprises.com/blist/ - Numerous other speed improvements Links ----- - blist vs. list performance comparison: http://stutzbachenterprises.com/performance-blist - Documentation: http://stutzbachenterprises.com/blist/ - Download: http://pypi.python.org/pypi/blist/ - Source repository: http://github.com/DanielStutzbach/blist - Issue tracker: http://github.com/DanielStutzbach/blist/issues -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Wed Jul 21 11:04:04 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 21 Jul 2010 11:04:04 -0400 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: Slurp the entire file into a string and pick out the fields you need. Sent from my iPhone 4. On Jul 21, 2010, at 10:42 AM, Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the expected information. > > Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? > > Brandon L. Harris > > > -- > http://mail.python.org/mailman/listinfo/python-list From brandon.harris at reelfx.com Wed Jul 21 11:06:14 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:06:14 -0500 Subject: Multiline regex In-Reply-To: References: <4C47074F.4090507@reelfx.com> Message-ID: <4C470CE6.2030306@reelfx.com> what do you mean by slurp the entire file? I'm trying to use regular expressions because line by line parsing will be too slow. And example file would have somewhere in the realm of 6 million lines of code. Brandon L. Harris Rodrick Brown wrote: > Slurp the entire file into a string and pick out the fields you need. > > Sent from my iPhone 4. > > On Jul 21, 2010, at 10:42 AM, Brandon Harris wrote: > > >> I'm trying to read in and parse an ascii type file that contains information that can span several lines. >> Example: >> >> createNode animCurveTU -n "test:master_globalSmooth"; >> setAttr ".tan" 9; >> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; >> setAttr -s 4 ".kit[3]" 10; >> setAttr -s 4 ".kot[3]" 10; >> createNode animCurveTU -n "test:master_res"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> I'm wanting to grab the information out in chunks, so >> >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> would be what my regex would grab. >> I'm currently only able to grab out the first line and part of the second line, but no more. >> regex is as follows >> >> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") >> >> I've run several variations of this, but none return me all of the expected information. >> >> Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification? >> >> Brandon L. Harris >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From eknath.iyer at gmail.com Wed Jul 21 11:13:43 2010 From: eknath.iyer at gmail.com (Eknath Venkataramani) Date: Wed, 21 Jul 2010 20:43:43 +0530 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Do you have to use only regex? If not, I'd certainly suggest 'pyparsing'. It's a pleasure to use and very easy on the eye too, if you know what I mean. > I'm wanting to grab the information out in chunks, so > -- Eknath Venkataramani -------------- next part -------------- An HTML attachment was scrubbed... URL: From brandon.harris at reelfx.com Wed Jul 21 11:14:43 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:14:43 -0500 Subject: Multiline regex In-Reply-To: References: <4C47074F.4090507@reelfx.com> Message-ID: <4C470EE3.4060708@reelfx.com> At the moment I'm trying to stick with built in python modules to create tools for a much larger pipeline on multiple OSes. Brandon L. Harris Eknath Venkataramani wrote: > > > On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris > > wrote: > > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > > Do you have to use only regex? If not, I'd certainly suggest > 'pyparsing'. It's a pleasure to use and very easy on the eye too, if > you know what I mean. > > I'm wanting to grab the information out in chunks, so > > > -- > Eknath Venkataramani From andreas.tawn at ubisoft.com Wed Jul 21 11:15:42 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 17:15:42 +0200 Subject: Multiline regex In-Reply-To: <4C47074F.4090507@reelfx.com> References: <4C47074F.4090507@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the > second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the > expected information. > > Is there something special that needs to be done to have the regexp > grab > any number of the setAttr lines without specification? > > Brandon L. Harris Aren't you making life too complicated for yourself? blocks = [] for line in yourFile: if line.startswith("createNode"): if currentBlock: blocks.append(currentBlock) currentBlock = [line] else: currentBlock.append(line) blocks.append(currentBlock) Cheers, Drea From __peter__ at web.de Wed Jul 21 11:16:04 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Jul 2010 17:16:04 +0200 Subject: Multiline regex References: Message-ID: Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: > > createNode animCurveTU -n "test:master_globalSmooth"; > setAttr ".tan" 9; > setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; > setAttr -s 4 ".kit[3]" 10; > setAttr -s 4 ".kot[3]" 10; > createNode animCurveTU -n "test:master_res"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > I'm wanting to grab the information out in chunks, so > > createNode animCurveTU -n "test:master_faceRig"; > setAttr ".tan" 9; > setAttr ".ktv[0]" 103 0; > setAttr ".kot[0]" 5; > > would be what my regex would grab. > I'm currently only able to grab out the first line and part of the > second line, but no more. > regex is as follows > > my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") > > I've run several variations of this, but none return me all of the > expected information. > > Is there something special that needs to be done to have the regexp grab > any number of the setAttr lines without specification? Groups are marked with parens (...) not brackets [...]. >>> text = """\ ... createNode animCurveTU -n "test:master_globalSmooth"; ... setAttr ".tan" 9; ... setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; ... setAttr -s 4 ".kit[3]" 10; ... setAttr -s 4 ".kot[3]" 10; ... createNode animCurveTU -n "test:master_res"; ... setAttr ".tan" 9; ... setAttr ".ktv[0]" 103 0; ... setAttr ".kot[0]" 5; ... createNode animCurveTU -n "test:master_faceRig"; ... setAttr ".tan" 9; ... setAttr ".ktv[0]" 103 0; ... setAttr ".kot[0]" 5; ... """ >>> for m in re.compile("(createNode animCurve.*\n(\s*setAttr.*\n)*)").finditer(text): ... print m.group(1) ... print "-" * 40 ... createNode animCurveTU -n "test:master_globalSmooth"; setAttr ".tan" 9; setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; setAttr -s 4 ".kit[3]" 10; setAttr -s 4 ".kot[3]" 10; ---------------------------------------- createNode animCurveTU -n "test:master_res"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; ---------------------------------------- createNode animCurveTU -n "test:master_faceRig"; setAttr ".tan" 9; setAttr ".ktv[0]" 103 0; setAttr ".kot[0]" 5; ---------------------------------------- Peter From nagle at animats.com Wed Jul 21 11:17:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 21 Jul 2010 08:17:36 -0700 Subject: Accumulate function in python In-Reply-To: <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> Message-ID: <4c470fa3$0$1583$742ec2ed@news.sonic.net> On 7/19/2010 9:56 AM, dhruvbird wrote: > On Jul 19, 9:12 pm, Brian Victor wrote: >> dhruvbird wrote: >> Having offered this, I don't recall ever seeing reduce used in real >> python code, and explicit iteration is almost always preferred. > > Yes, even I have noticed that reduce is a tad under-used function. Yes, I had a use case for it once, but it wasn't worth the trouble. "map" is often useful, but "reduce", not so much. Python isn't really a functional language. There's no bias toward functional solutions, lambdas aren't very general, and the performance isn't any better. Nor is any concurrency provided by "map" or "reduce". So there's no win in trying to develop cute one-liners. John Nagle From holger.brunck at keymile.com Wed Jul 21 11:29:14 2010 From: holger.brunck at keymile.com (Holger brunck) Date: Wed, 21 Jul 2010 17:29:14 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C46EEB8.6070702@keymile.com> References: <4C46EEB8.6070702@keymile.com> Message-ID: <4C47124A.10405@keymile.com> >> Something like the "file" utility for linux would be very helpfull. >> >> Any help is appreciated. >You're going to have to describe in detail what's in the file before >anybody can help. We are creating inside our buildsystem for an embedded system a cram filesystem image. Later on inside our build process we have to check the endianness, because it could be Little Endian or big endian (arm or ppc). The output of the "file" tool is for a little endian cramfs image: : Linux Compressed ROM File System data, little endian size 1875968 version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files It would be possible to execute ret = os.system("file | grep "little endian") and evaluate the return code. But I don't like to evaluate a piped system command. If there is an way without using the os.system command this would be great. Best regards Holger From solipsis at pitrou.net Wed Jul 21 11:32:50 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 21 Jul 2010 17:32:50 +0200 Subject: ANN: blist 1.2.0 References: Message-ID: <20100721173250.2d666f99@pitrou.net> On Wed, 21 Jul 2010 09:47:08 -0500 Daniel Stutzbach wrote: > > What's new? > ----------- > > - blist.sort() is now *substantially* faster than list.sort() when using int > or float keys (O(n) vs. O(n log n)) Are you using some kind of radix sort? Could it be contributed back into the standard list type? Regards Antoine. From brandon.harris at reelfx.com Wed Jul 21 11:42:11 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:42:11 -0500 Subject: Multiline regex In-Reply-To: <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4C471553.9060500@reelfx.com> I could make it that simple, but that is also incredibly slow and on a file with several million lines, it takes somewhere in the league of half an hour to grab all the data. I need this to grab data from many many file and return the data quickly. Brandon L. Harris Andreas Tawn wrote: >> I'm trying to read in and parse an ascii type file that contains >> information that can span several lines. >> Example: >> >> createNode animCurveTU -n "test:master_globalSmooth"; >> setAttr ".tan" 9; >> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0; >> setAttr -s 4 ".kit[3]" 10; >> setAttr -s 4 ".kot[3]" 10; >> createNode animCurveTU -n "test:master_res"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> I'm wanting to grab the information out in chunks, so >> >> createNode animCurveTU -n "test:master_faceRig"; >> setAttr ".tan" 9; >> setAttr ".ktv[0]" 103 0; >> setAttr ".kot[0]" 5; >> >> would be what my regex would grab. >> I'm currently only able to grab out the first line and part of the >> second line, but no more. >> regex is as follows >> >> my_regexp =e.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*") >> >> I've run several variations of this, but none return me all of the >> expected information. >> >> Is there something special that needs to be done to have the regexp >> grab >> any number of the setAttr lines without specification? >> >> Brandon L. Harris >> > > Aren't you making life too complicated for yourself? > > blocks =] > for line in yourFile: > if line.startswith("createNode"): > if currentBlock: > blocks.append(currentBlock) > currentBlock =line] > else: > currentBlock.append(line) > blocks.append(currentBlock) > > Cheers, > > Drea > > From andreas.tawn at ubisoft.com Wed Jul 21 11:55:48 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 17:55:48 +0200 Subject: Multiline regex In-Reply-To: <4C471553.9060500@reelfx.com> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> > I could make it that simple, but that is also incredibly slow and on a > file with several million lines, it takes somewhere in the league of > half an hour to grab all the data. I need this to grab data from many > many file and return the data quickly. > > Brandon L. Harris That's surprising. I just made a file with 13 million lines of your data (447Mb) and read it with my code. It took a little over 36 seconds. There must be something different in your set up or the real data you've got. Cheers, Drea From brandon.harris at reelfx.com Wed Jul 21 11:57:35 2010 From: brandon.harris at reelfx.com (Brandon Harris) Date: Wed, 21 Jul 2010 10:57:35 -0500 Subject: Multiline regex In-Reply-To: <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> Message-ID: <4C4718EF.7050202@reelfx.com> Could it be that there isn't just that type of data in the file? there are many different types, that is just one that I'm trying to grab. Brandon L. Harris Andreas Tawn wrote: >> I could make it that simple, but that is also incredibly slow and on a >> file with several million lines, it takes somewhere in the league of >> half an hour to grab all the data. I need this to grab data from many >> many file and return the data quickly. >> >> Brandon L. Harris >> > > That's surprising. > > I just made a file with 13 million lines of your data (447Mb) and read it with my code. It took a little over 36 seconds. There must be something different in your set up or the real data you've got. > > Cheers, > > Drea > From nanothermite911fbibustards at gmail.com Wed Jul 21 12:10:14 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 09:10:14 -0700 (PDT) Subject: Please, stop spamming References: Message-ID: <8a4273c7-5f55-440a-880b-7fd25969567b@w30g2000yqw.googlegroups.com> On Jul 14, 7:38?pm, Daniel Valio wrote: > Indeed, you will make Usenet an old history that your father talked > about on the early days of the Internet. Really, you are destroying > the Internet with useless spams about naked famous woman, or Viagra, > Cialis et alia. > You are making the internet look like a big stupid useless spammed > thing. Stop it! > That should be a Lisp group, not a Hey-you-may-spam-here-as-you-want- > to group! [snip] > Thanks in advance for the comprehension. > From Brazil, Daniel Valio. Daniel, This spam is by CIA, MOSSAD, AIPAC, ZIONISTS to HIDE a slight mention of their crimes. Ignore it, and continue, if you want to success. I agree with someone that they carried out 911 to destroy FREEDOMS. One paradigm of these ODIOUS CRIMINALS is to blame what they do on others and with a VIGOR to lie so it appears a truth. These BUSTARDS have the knowhow, time and resources which ordinary people dont have. These CRIMINALS are SNAKES feeding on our tax payer money. The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From daniel at stutzbachenterprises.com Wed Jul 21 12:15:53 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 11:15:53 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: <20100721173250.2d666f99@pitrou.net> References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Wed, Jul 21, 2010 at 10:32 AM, Antoine Pitrou wrote: > Are you using some kind of radix sort? > Could it be contributed back into the standard list type? Yes and yes. I have a few mostly-complete patches on the tracker that I need to polish off, as well as several easy-to-fix bugs that I need to take care of. After that I plan to work on porting my sort optimizations back to the standard list type. Here's a performance comparison of sorting with blist versus 3.1's list: http://stutzbachenterprises.com/performance-blist/sort-random-list -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.tawn at ubisoft.com Wed Jul 21 12:27:14 2010 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 21 Jul 2010 18:27:14 +0200 Subject: Multiline regex In-Reply-To: <4C4718EF.7050202@reelfx.com> References: <4C47074F.4090507@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C76958@PDC-MAIL-CMS01.ubisoft.org> <4C471553.9060500@reelfx.com> <654D9D97DA51AD479973BC2D5578603C06C1C769AC@PDC-MAIL-CMS01.ubisoft.org> <4C4718EF.7050202@reelfx.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C06C1C769E8@PDC-MAIL-CMS01.ubisoft.org> >>> I could make it that simple, but that is also incredibly slow and on >>> a file with several million lines, it takes somewhere in the league of >>> half an hour to grab all the data. I need this to grab data from >>> many many file and return the data quickly. >>> >>> Brandon L. Harris >>> >> That's surprising. >> >> I just made a file with 13 million lines of your data (447Mb) and >> read it with my code. It took a little over 36 seconds. There must be >> something different in your set up or the real data you've got. >> >> Cheers, >> >> Drea >> > Could it be that there isn't just that type of data in the file? there > are many different types, that is just one that I'm trying to grab. > > Brandon L. Harris I don't see why it would make such a difference. If your data looks like... \t \t \t Just change this line... if line.startswith("createNode"): to... if not line.startswith("\t"): and it won't care what sort of data the file contains. Processing that data after you've collected it will still take a while, but that's the same whichever method you use to read it. Cheers, Drea p.s. Just noticed I hadn't pre-declared the currentBlock list. From jeremy at jeremysanders.net Wed Jul 21 12:56:16 2010 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Wed, 21 Jul 2010 17:56:16 +0100 Subject: Multiline regex References: <4C47074F.4090507@reelfx.com> Message-ID: Brandon Harris wrote: > I'm trying to read in and parse an ascii type file that contains > information that can span several lines. > Example: What about something like this (you need re.MULTILINE): In [16]: re.findall('^([^ ].*\n([ ].*\n)+)', a, re.MULTILINE) Out[16]: [('createNode animCurveTU -n "test:master_globalSmooth";\n setAttr ".tan" 9;\n setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;\n setAttr -s 4 ".kit[3]" 10;\n setAttr -s 4 ".kot[3]" 10;\n', ' setAttr -s 4 ".kot[3]" 10;\n'), ('createNode animCurveTU -n "test:master_res";\n setAttr ".tan" 9;\n setAttr ".ktv[0]" 103 0;\n setAttr ".kot[0]" 5;\n', ' setAttr ".kot[0]" 5;\n'), ('createNode animCurveTU -n "test:master_faceRig";\n setAttr ".tan" 9;\n setAttr ".ktv[0]" 103 0;\n', ' setAttr ".ktv[0]" 103 0;\n')] If you blocks start without a space and subsequent lines with a space. Jeremy From sla29970 at gmail.com Wed Jul 21 13:27:28 2010 From: sla29970 at gmail.com (Steve Allen) Date: Wed, 21 Jul 2010 10:27:28 -0700 (PDT) Subject: convert time to UTC seconds since epoch References: <4C45F87C.1040607@yandex.ru> Message-ID: <7be79f8d-edaa-42ca-9a5a-fa938972fd77@m17g2000prl.googlegroups.com> On Jul 20, 6:57?pm, Chris Rebert wrote: [regarding trust of POSIX vis a vis leap seconds] > I'm not saying they necessarily should, but they're standardized and > the `time` module is based on POSIX/Unix-ish assumptions; not > following POSIX would be inconsistent and problematic. > Breaking standards is bad, M'Kay? Standards are good. When it comes to leap seconds there can be no current implementation which satisfies everyone because of this http://www.ucolick.org/~sla/leapsecs/epochtime.html Until the delegates to ITU-R SG7 produce a better recommendation there is going to be chaotic disregard of the standard where folks with different needs choose different practical implementations. From wxjmfauth at gmail.com Wed Jul 21 14:13:31 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 21 Jul 2010 11:13:31 -0700 (PDT) Subject: Inconsistency in the format docstring (2.7). Message-ID: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> Small inconsistency in the format.__doc__ >>> sys.version 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] >>> ''.format.__doc__ S.format(*args, **kwargs) -> unicode >>> type('{}'.format(999)) >>> type('{}'.format('abc?')) From thomas at jollans.com Wed Jul 21 15:06:38 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 21 Jul 2010 21:06:38 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C47124A.10405@keymile.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: <4C47453E.7030203@jollans.com> On 07/21/2010 05:29 PM, Holger brunck wrote: > >>> Something like the "file" utility for linux would be very helpfull. >>> >>> Any help is appreciated. > >> You're going to have to describe in detail what's in the file before >> anybody can help. > > We are creating inside our buildsystem for an embedded system a cram filesystem > image. Later on inside our build process we have to check the endianness, > because it could be Little Endian or big endian (arm or ppc). > > The output of the "file" tool is for a little endian cramfs image: > : Linux Compressed ROM File System data, little endian size 1875968 > version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > > It would be possible to execute > ret = os.system("file | grep "little endian") > and evaluate the return code. > But I don't like to evaluate a piped system command. If there is an way without > using the os.system command this would be great. Files don't, as such, have a detectable endianess. 0x23 0x41 could mean either 0x4123 or 0x2341 - there's no way of knowing. The "file" utility also doensn't really know about endianess (well, maybe it does swap bytes here and there, but that's an implementation detail) - it just knows about file types. It knows what a little-endian cramfs image looks like, and what a big-endian cramfs image looks like. And as they're different, it can tell them apart. If you're only interested in a couple of file types, it shouldn't be too difficult to read the first few bytes/words with the struct module and apply your own heuristics. Open the files in question in a hex editor and try to figure out how to tell them apart! From python at mrabarnett.plus.com Wed Jul 21 15:54:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 21 Jul 2010 20:54:34 +0100 Subject: detect endianness of a binary with python In-Reply-To: <4C47453E.7030203@jollans.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> <4C47453E.7030203@jollans.com> Message-ID: <4C47507A.5080205@mrabarnett.plus.com> Thomas Jollans wrote: > On 07/21/2010 05:29 PM, Holger brunck wrote: >>>> Something like the "file" utility for linux would be very helpfull. >>>> >>>> Any help is appreciated. >>> You're going to have to describe in detail what's in the file before >>> anybody can help. >> We are creating inside our buildsystem for an embedded system a cram filesystem >> image. Later on inside our build process we have to check the endianness, >> because it could be Little Endian or big endian (arm or ppc). >> >> The output of the "file" tool is for a little endian cramfs image: >> : Linux Compressed ROM File System data, little endian size 1875968 >> version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files >> >> It would be possible to execute >> ret = os.system("file | grep "little endian") >> and evaluate the return code. >> But I don't like to evaluate a piped system command. If there is an way without >> using the os.system command this would be great. > > Files don't, as such, have a detectable endianess. 0x23 0x41 could mean > either 0x4123 or 0x2341 - there's no way of knowing. > > The "file" utility also doensn't really know about endianess (well, > maybe it does swap bytes here and there, but that's an implementation > detail) - it just knows about file types. It knows what a little-endian > cramfs image looks like, and what a big-endian cramfs image looks like. > And as they're different, it can tell them apart. > > If you're only interested in a couple of file types, it shouldn't be too > difficult to read the first few bytes/words with the struct module and > apply your own heuristics. Open the files in question in a hex editor > and try to figure out how to tell them apart! If you have control over the file format then you could ensure that there's a double-byte value such as 0xFF00 at a certain offset. That will tell you the endianness of the file. From gdamjan at gmail.com Wed Jul 21 15:56:37 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 21 Jul 2010 21:56:37 +0200 Subject: Pydev 1.6.0 Released References: Message-ID: > Pydev 1.6.0 has been released > > Details on Pydev: http://pydev.org > Details on its development: http://pydev.blogspot.com The supposed feature to start a console in which the contents of the current editor window are automatically "exec"ed /available still doesn't work for me. I'm talking about this: http://www.pydev.org/manual_adv_interactive_console.html Pressing Ctrl-Alt-Enter, a interactive console opens but my class defined in the editor window is not available. -- ?????? ((( http://damjan.softver.org.mk/ ))) Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. - Antoine de Saint-Exup?ry From nanothermite911fbibustards at gmail.com Wed Jul 21 16:21:53 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 13:21:53 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? Message-ID: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From guandalino at gmail.com Wed Jul 21 17:06:55 2010 From: guandalino at gmail.com (guandalino) Date: Wed, 21 Jul 2010 14:06:55 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) References: Message-ID: On 20 Lug, 21:24, Terry Reedy wrote: Hi Terry, thanks for your reply. > > ====================================================================== > > ERROR: test_file (__main__.HandlerTests) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > ? ?File "test_urllib2.py", line 711, in test_file > > ? ? ?h.file_open, Request(url)) [cut] > You could insert a print to find what url caused a problem. Output: file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp file:///file_does_not_exist.txt file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp Offending line is the the 4th. > This is in unittest.py. It says that this test case *should* fail, but > with a different error (urllib.error.URLError) than the one you got > (gaierror). > > > ? ?File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, > > in file_open > > ? ? ?return self.open_local_file(req) > > ? ?File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, > > in open_local_file > > ? ? ?(not port and socket.gethostbyname(host) in self.get_names()): > > gaierror: [Errno -5] No address associated with hostname > > gaierror comes from socket.gethostbyname When I print the value of the variable 'host' in urllib2.py line 1301 I get this: somerandomhost.ontheinternet.com. This is why socket.gethostbyname(host) raises gaierror -5, there is no address associated to somerandomhost.ontheinternet.com. Instead the values that 'host' takes for the other urls are localhost or 127.0.0.1, both valid for gethostbyname(). Any hint? Thanks. From tjreedy at udel.edu Wed Jul 21 18:27:36 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 18:27:36 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/21/2010 12:15 PM, Daniel Stutzbach wrote: > Here's a performance comparison of sorting with blist versus 3.1's list: > http://stutzbachenterprises.com/performance-blist/sort-random-list Question related to possible addition of radix sort to lists: These tests use random numbers with a constant, relatively high density of 25%, which is favorable to radix sort. What if you do the same test with a constant range of, say, 1000000000 (1 billion) or even a trillion or quadrillion. Or how about sorting a thousand 128bit ip6 addresses? Which wins for that? list.sort is (near) linear for lists that are mostly ordered. I think Tim's writeup about this in in the source. For instance, if one extends a sorted with 1% random additions and resorts, list.sort will skip the sorted part, sort the additions, and merge them back in. Radix sort ignores pre-existing order. So either a lot of comparitive profiling would be needed for auto-selection of sort method, or it should be user selectable. Does your radix sort meet the stability guarantee of list.sort? If not, a separate .rsort method would be needed anyway. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jul 21 18:50:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 18:50:16 -0400 Subject: Inconsistency in the format docstring (2.7). In-Reply-To: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> References: <1b0aad03-b675-4f21-a9b2-41c98caa3efb@k39g2000yqb.googlegroups.com> Message-ID: On 7/21/2010 2:13 PM, jmfauth wrote: > Small inconsistency in the format.__doc__ > >>>> sys.version > 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] >>>> ''.format.__doc__ > S.format(*args, **kwargs) -> unicode > > >>>> type('{}'.format(999)) > >>>> type('{}'.format('abc?')) > Thank you for reporting this. Forwarded to the tracker as http://bugs.python.org/issue9328 -- Terry Jan Reedy From daniel at stutzbachenterprises.com Wed Jul 21 18:56:55 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 21 Jul 2010 17:56:55 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy wrote: > These tests use random numbers with a constant, relatively high density of > 25%, which is favorable to radix sort. What if you do the same test with a > constant range of, say, 1000000000 (1 billion) or even a trillion or > quadrillion. Or how about sorting a thousand 128bit ip6 addresses? Which > wins for that? > blist switches to radix sort only if the keys contain only floats or only integers that fit into a C long. If the integers get too big, it reverts to timsort. When using a sort key, the decorate-sort-undecorate pattern requires touching every object once before the sort. The check for a consistent type is done inexpensively during the decorate phase. Here's an example result with a density of only 1%, where the radix sort is around 4 times as fast: otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' 'y.sort(key=float)' 100 loops, best of 3: 12.4 msec per loop otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s 'import random' -s 'x = [random.randrange(10000*100) for i in range(10000)]' 'y = blist(x)' 'y.sort(key=float)' 100 loops, best of 3: 3.4 msec per loop And a density of 0.01%: otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' 'y.sort(key=float)' 100 loops, best of 3: 12 msec per loop otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s 'import random' -s 'x = [random.randrange(10000*10000) for i in range(10000)]' 'y = blist(x)' 'y.sort(key=float)' 100 loops, best of 3: 3.52 msec per loop > list.sort is (near) linear for lists that are mostly ordered. I think Tim's > writeup about this in in the source. For instance, if one extends a sorted > with 1% random additions and resorts, list.sort will skip the sorted part, > sort the additions, and merge them back in. Radix sort ignores pre-existing > order. So either a lot of comparitive profiling would be needed for > auto-selection of sort method, or it should be user selectable. > I've tested exactly that scenario. For already-ordered lists, radix sort and timsort tie. > Does your radix sort meet the stability guarantee of list.sort? > Yes. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 21 19:13:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Jul 2010 19:13:21 -0400 Subject: urllib2 test fails (2.7, linux) In-Reply-To: References: Message-ID: On 7/21/2010 5:06 PM, guandalino wrote: > On 20 Lug, 21:24, Terry Reedy wrote: > > Hi Terry, thanks for your reply. > >>> ====================================================================== >>> ERROR: test_file (__main__.HandlerTests) >>> ---------------------------------------------------------------------- >>> Traceback (most recent call last): >>> File "test_urllib2.py", line 711, in test_file >>> h.file_open, Request(url)) > [cut] >> You could insert a print to find what url caused a problem. > > Output: > file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp > file:///file_does_not_exist.txt > file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp > file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp > Offending line is the the 4th. Ah. I did not see anything like that in 3.1 test_urllib2. Either I just simply missed it, or it is obscured, or it was removed because it causes failures;-). >> This is in unittest.py. It says that this test case *should* fail, but >> with a different error (urllib.error.URLError) than the one you got >> (gaierror). >> >>> File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269, >>> in file_open >>> return self.open_local_file(req) >>> File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301, >>> in open_local_file >>> (not port and socket.gethostbyname(host) in self.get_names()): >>> gaierror: [Errno -5] No address associated with hostname >> >> gaierror comes from socket.gethostbyname > > When I print the value of the variable 'host' in urllib2.py line 1301 > I get this: somerandomhost.ontheinternet.com. This is why > socket.gethostbyname(host) raises gaierror -5, there is no address > associated to somerandomhost.ontheinternet.com. Instead the values > that 'host' takes for the other urls are localhost or 127.0.0.1, both > valid for gethostbyname(). > > Any hint? Remove the offending fake url. If you want to investigate the history of the file, go to http://svn.python.org/view/python/branches/release27-maint/Lib/test/test_urllib2.py?view=log If you do not get an answer here, file a bug report. If you can, put orsenthil,benjamin.peterson,ezio.melotti on the nosy list, as they are recent committers to this file. Say I said to do so if you want. Add tjreedy also so I can see responses and learn too. -- Terry Jan Reedy From prologic at shortcircuit.net.au Wed Jul 21 19:16:04 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jul 2010 09:16:04 +1000 Subject: [ann] Hatta 1.4.0 wiki engine released In-Reply-To: References: Message-ID: On Wed, Jul 21, 2010 at 6:01 PM, Radomir Dopieralski wrote: > I'm proud to announce release 1.4.0 of Hatta wiki engine. Congrats. cheers James -- -- James Mills -- -- "Problems are solved by method" From Space998 at hotmail.com Wed Jul 21 19:31:02 2010 From: Space998 at hotmail.com (spudnik) Date: Wed, 21 Jul 2010 16:31:02 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: thermite is not what you think, it is; it's primary use is for dismantling steel frameworks, piece by piece, just as they were welded -- see the report by MIT's Head Welder. thus: there, you've hit upon the self-same absurdity of Newton's "theory" of corpuscles, vis-a-vu waves of light in the non-vacuum of space (unconsciously .-) thus quoth: Does every dust speck have gravitons? ?And if not, how do the specks know... "which way the mass is"? --BP's cap&trade "free-er trade nostrum" is before Senate! http://tarpley.net/online-books/george-bush-the-unauthorized-biography/chapter-8-the-permian-basin-gang/ From steve-REMOVE-THIS at cybersource.com.au Wed Jul 21 20:25:58 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 00:25:58 GMT Subject: Multiline regex References: <4C47074F.4090507@reelfx.com> Message-ID: <4c479016$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 10:06:14 -0500, Brandon Harris wrote: > what do you mean by slurp the entire file? I'm trying to use regular > expressions because line by line parsing will be too slow. And example > file would have somewhere in the realm of 6 million lines of code. And you think trying to run a regex over all 6 million lines at once will be faster? I think you're going to be horribly, horribly disappointed. And then on Wed, 21 Jul 2010 10:42:11 -0500, Brandon Harris wrote: > I could make it that simple, but that is also incredibly slow and on a > file with several million lines, it takes somewhere in the league of > half an hour to grab all the data. I need this to grab data from many > many file and return the data quickly. What do you mean "grab" all the data? If all you mean is read the file, then 30 minutes to read ~ 100MB of data is incredibly slow and you're probably doing something wrong, or you're reading it over a broken link with very high packet loss, or something. If you mean read the data AND parse it, then whether that is "incredibly slow" or "amazingly fast" depends entirely on how complicated your parser needs to be. If *all* you mean is "read the file and group the lines, for later processing", then I would expect it to take well under a minute to group millions of lines. Here's a simulation I ran, using 2001000 lines of text based on the examples you gave. It grabs the blocks, as required, but does no further parsing of them. def merge(lines): """Join multiple lines into a single block.""" accumulator = [] for line in lines: if line.lower().startswith('createnode'): if accumulator: yield ''.join(accumulator) accumulator = [] accumulator.append(line) if accumulator: yield ''.join(accumulator) def test(): import time t = time.time() count = 0 f = open('/steve/test.junk') for block in merge(f): # do some make-work n = sum([1 for c in block if c in '1234567890']) count += 1 print "Processed %d blocks from 2M+ lines." % count print "Time taken:", time.time() - t, "seconds" And the result on a low-end PC: >>> test() Processed 1000 blocks from 2M+ lines. Time taken: 17.4497909546 seconds -- Steven From invalid at invalid.invalid Wed Jul 21 22:31:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 22 Jul 2010 02:31:54 +0000 (UTC) Subject: detect endianness of a binary with python References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: On 2010-07-21, Thomas Jollans wrote: >> It would be possible to execute ret = os.system("file | >> grep "little endian") and evaluate the return code. But I don't like >> to evaluate a piped system command. If there is an way without using >> the os.system command this would be great. > > Files don't, as such, have a detectable endianess. 0x23 0x41 could mean > either 0x4123 or 0x2341 - there's no way of knowing. > > The "file" utility also doensn't really know about endianess (well, > maybe it does swap bytes here and there, but that's an implementation > detail) - it just knows about file types. It knows what a little-endian > cramfs image looks like, and what a big-endian cramfs image looks like. > And as they're different, it can tell them apart. > > If you're only interested in a couple of file types, it shouldn't be too > difficult to read the first few bytes/words with the struct module and > apply your own heuristics. Open the files in question in a hex editor > and try to figure out how to tell them apart! And by looking at the rules that "file" uses for the two file types that matter, one should be able to figure out how to implement something in Python. Or one can use the Python "magic" module as previously suggested: http://pypi.python.org/pypi/python-magic/ -- Grant From nagle at animats.com Wed Jul 21 22:45:24 2010 From: nagle at animats.com (John Nagle) Date: Wed, 21 Jul 2010 19:45:24 -0700 Subject: Did class inheritance from "dict" work in early Python? Message-ID: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Did class inheritance from "dict" work in early Python? Or did that only start working when "new objects" came in? John Nagle From me+list/python at ixokai.io Wed Jul 21 23:11:37 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 21 Jul 2010 20:11:37 -0700 Subject: Did class inheritance from "dict" work in early Python? In-Reply-To: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> References: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Message-ID: <4C47B6E9.8010409@ixokai.io> On 7/21/10 7:45 PM, John Nagle wrote: > Did class inheritance from "dict" work in early Python? Or did > that only start working when "new objects" came in? The latter, that's why UserDict (and UserList) was added. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From steve-REMOVE-THIS at cybersource.com.au Wed Jul 21 23:34:01 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 03:34:01 GMT Subject: Did class inheritance from "dict" work in early Python? References: <4c47b0d7$0$1594$742ec2ed@news.sonic.net> Message-ID: <4c47bc29$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 19:45:24 -0700, John Nagle wrote: > Did class inheritance from "dict" work in early Python? Or did that > only start working when "new objects" came in? Only with the introduction of new-style classes and "object" in version 2.2. http://www.python.org/download/releases/2.2.3/descrintro/#subclassing Before that the technique of choice was to use automatic delegation, e.g. see the UserDict module. -- Steven From nanothermite911fbibustards at gmail.com Thu Jul 22 00:16:26 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:16:26 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: You shall see CIA / Mossad / AIPAC / CRIMINAL PRIVATE KROLL/BLACKWATER/ gstatic.com bustards start spamming to drown 911 truth. their spam is about VIAGRA/DIAZEPAM/VALIUM/SEX etc. They hate our freedoms. They sent anthrax. They did 911. They put the blame on arabs but they are the ones as FORENSIC proves WITHOUT ANY DOUBT !!! White crime rate is 5 times Asian per capita in the USA. On Jul 21, 1:21?pm, nanothermite911fbibustards wrote: > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > israelis and what is the status of FORENSIC evidence and trace of NANO > THERMITE in WTC dust ? > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA From nanothermite911fbibustards at gmail.com Thu Jul 22 00:24:50 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:24:50 -0700 (PDT) Subject: please come and help to defend against ISLAM , bring physicists to refute their calculation on speed of light and wormholes References: <49ecfb9d-fc4b-4b1d-b8fb-2bbcb15d07a6@m35g2000prn.googlegroups.com> Message-ID: <4905e445-215c-4dd2-8000-15b40700a827@s17g2000prh.googlegroups.com> On Jul 21, 9:23?pm, nanothermite911fbibustards wrote: > http://www.speed-light.info/angels_speed_of_light.htm From nanothermite911fbibustards at gmail.com Thu Jul 22 00:35:41 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 21:35:41 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: <9b6a9f32-333c-4e2a-a621-47f7770bb88e@x20g2000pro.googlegroups.com> On Jul 21, 9:16?pm, nanothermite911fbibustards wrote: > You shall see CIA / Mossad / AIPAC / CRIMINAL PRIVATE KROLL/BLACKWATER/ > gstatic.com bustards start spamming to drown 911 truth. their spam is > about VIAGRA/DIAZEPAM/VALIUM/SEX etc. > > They hate our freedoms. They sent anthrax. They did 911. They put the > blame on arabs but they are the ones as FORENSIC proves WITHOUT ?ANY > DOUBT !!! > > White crime rate is 5 times Asian per capita in the USA. > > On Jul 21, 1:21?pm, nanothermite911fbibustards wrote: > > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > > israelis and what is the status of FORENSIC evidence and trace of NANO > > THERMITE in WTC dust ? > > Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX > MAILER ??? Where are the 4 blackboxes, where are the 5 dancing > israelis and what is the status of FORENSIC evidence and trace of NANO > THERMITE in WTC dust ? > > The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE > is UNACCEPTABLE. > > ===== > > http://www.youtube.com/watch?v=lX18zUp6WPY > > http://www.youtube.com/watch?v=XQapkVCx1HI > > http://www.youtube.com/watch?v=tXJ-k-iOg0M > > Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? > Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did > you release the 5 dancing Israelis compromising the whole 911 > investigation ? If the Dubai Police can catch Mossad Murderers and put > the videos and Iranian Police can why cant you put the Pentagon > Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and > puting on INTERNATIONAL MEDIA a day after catching him without > TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did > you have to LIE about Dr Afiya Siddiqui and torture that Innocent > little mother of 3 and smashing the skull of her one child ? > > http://www.youtube.com/watch?v=DhMcii8smxkhttp://www.youtube.com/watch?v=0SZ2lxDJmdg > > There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian > courts. > > FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but > only because he was a white. They got away with MURDER of thousands of > Non-whites in all parts of the world. > > Daily 911 news :http://911blogger.com > > http://www.youtube.com/watch?v=tRfhUezbKLw > > http://www.youtube.com/watch?v=x7kGZ3XPEm4 > > http://www.youtube.com/watch?v=lX18zUp6WPY > > Conclusion : FBI bustards are RACIST and INcompetent. They could > neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they > cover them up - whichever was their actual goal or task. > > SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across > tbe board, esp the whites/jew on the top. > > FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and > UNPATRIOTIC Act > FBI bustards failed to prevent ROMAN POLANSKY from absconding to > europe and rapes. > FBI bustards failed to prevent OKLAHOMA Now Germany -- not a shot had been fired on the German soil. Not an enemy soldier had crossed the border into Germany. And yet, here was Germany offering England peace terms. They offered England a negotiated peace on what the lawyers call a status quo ante basis. That means: ?Let's call the war off, and let everything be as it was before the war started.? Well, England, in the summer of 1916 was considering that. Seriously! They had no choice. It was either accepting this negotiated peace that Germany was magnanimously offering them, or going on with the war and being totally defeated. While that was going on, the Zionists in Germany, who represented the Zionists from Eastern Europe, went to the British War Cabinet and -- I am going to be brief because this is a long story, but I have all the documents to prove any statement that I make if anyone here is curious, or doesn't believe what I'm saying is at all possible -- the Zionists in London went to the British war cabinet and they said: ?Look here. You can yet win this war. You don't have to give up. You don't have to accept the negotiated peace offered to you now by Germany. You can win this war if the United States will come in as your ally.? The United States was not in the war at that time. We were fresh; we were young; we were rich; we were powerful. They [Zionists] told England: ?We will guarantee to bring the United States into the war as your ally, to fight with you on your side, if you will promise us Palestine after you win the war.? In other words, they made this deal: ?We will get the United States into this war as your ally. The price you must pay us is Palestine after you have won the war and defeated Germany, Austria- Hungary, and Turkey.? Now England had as much right to promise Palestine to anybody, as the United States would have to promise Japan to Ireland for any reason whatsoever. It's absolutely absurd that Great Britain -- that never had any connection or any interest or any right in what is known as Palestine -- should offer it as coin of the realm to pay the Zionists for bringing the United States into the war. However, they made that promise, in October of 1916. October, nineteen hundred and sixteen. And shortly after that -- I don't know how many here remember it -- the United States, which was almost totally pro-German -- totally pro-German -- because the newspapers here were controlled by Jews, the bankers were Jews, all the media of mass communications in this country were controlled by Jews, and they were pro-German because their people, in the majority of cases came from Germany, and they wanted to see Germany lick the Czar. The Jews didn't like the Czar, and they didn't want Russia to win this war. So the German bankers -- the German-Jews -- Kuhn Loeb and the other big banking firms in the United States refused to finance France or England to the extent of one dollar. They stood aside and they said: ?As long as France and England are tied up with Russia, not one cent!? But they poured money into Germany, they fought with Germany against Russia, trying to lick the Czarist regime. Now those same Jews, when they saw the possibility of getting Palestine, they went to England and they made this deal. At that time, everything changed, like the traffic light that changes from red to green. Where the newspapers had been all pro-German, where they'd been telling the people of the difficulties that Germany was having fighting Great Britain commercially and in other respects, all of a sudden the Germans were no good. They were villains. They were Huns. They were shooting Red Cross nurses. They were cutting off babies' hands. And they were no good. Well, shortly after that, Mr. Wilson declared war on Germany. The Zionists in London sent these cables to the United States, to Justice Brandeis: ?Go to work on President Wilson. We're getting from England what we want. Now you go to work, and you go to work on President Wilson and get the United States into the war." And that did happen. That's how the United States got into the war. We had no more interest in it; we had no more right to be in it than we have to be on the moon tonight instead of in this room. Now the war -- World War One -- in which the United States participated had absolutely no reason to be our war. We went in there -- we were railroaded into it -- if I can be vulgar, we were suckered into -- that war merely so that the Zionists of the world could obtain Palestine. Now, that is something that the people in the United States have never been told. They never knew why we went into World War One. Now, what happened? After we got into the war, the Zionists went to Great Britain and they said: ?Well, we performed our part of the agreement. Let's have something in writing that shows that you are going to keep your bargain and give us Palestine after you win the war.? Because they didn't know whether the war would last another year or another ten years. So they started to work out a receipt. The receipt took the form of a letter, and it was worded in very cryptic language so that the world at large wouldn't know what it was all about. And that was called the Balfour Declaration. The Balfour Declaration was merely Great Britain's promise to pay the Zionists what they had agreed upon as a consideration for getting the United States into the war. So this great Balfour Declaration, that you hear so much about, is just as phony as a three dollar bill. And I don't think I could make it more emphatic than that. Now, that is where all the trouble started. The United States went in the war. The United States crushed Germany. We went in there, and it's history. You know what happened. Now, when the war was ended, and the Germans went to Paris, to the Paris Peace Conference in 1919, there were 117 Jews there, as a delegation representing the Jews, headed by Bernard Baruch. I was there: I ought to know. Now what happened? The Jews at that peace conference, when they were cutting up Germany and parceling out Europe to all these nations that claimed a right to a certain part of European territory, the Jews said, ?How about Palestine for us?? And they produced, for the first time to the knowledge of the Germans, this Balfour Declaration. So the Germans, for the first time realized, ?Oh, that was the game! That's why the United States came into the war.? And the Germans for the first time realized that they were defeated, they suffered this terrific reparation that was slapped onto them, because the Zionists wanted Palestine and they were determined to get it at any cost. Now, that brings us to another very interesting point. When the Germans realized this, they naturally resented it. Up to that time, the Jews had never been better off in any country in the world than they had been in Germany. You had Mr. Rathenau there, who was maybe 100 times as important in industry and finance as is Bernard Baruch in this country. You had Mr. Balin, who owned the two big steamship lines, the North German Lloyd's and the Hamburg-American Lines. You had Mr. Bleichroder, who was the banker for the Hohenzollern family. You had the Warburgs in Hamburg, who were the big merchant bankers -- the biggest in the world. The Jews were doing very well in Germany. No question about that. Now, the Germans felt: ?Well, that was quite a sellout.? It was a sellout that I can best compare -- suppose the United States was at war today with the Soviet Union. And we were winning. And we told the Soviet Union: ?Well, let's quit. We offer you peace terms. Let's forget the whole thing.? And all of a sudden Red China came into the war as an ally of the Soviet Union. And throwing them into the war brought about our defeat. A crushing defeat, with reparations the likes of which man's imagination cannot encompass. Imagine, then, after that defeat, if we found out that it was the Chinese in this country, our Chinese citizens, who all the time we thought they were loyal citizens working with us, were selling us out to the Soviet Union and that it was through them that Red China was brought into the war against us. How would we feel, in the United States against Chinese? I don't think that one of them would dare show his face on any street. There wouldn't be lampposts enough, convenient, to take care of them. Imagine how we would feel. Well, that's how the Germans felt towards these Jews. "We've been so nice to them"; and from 1905 on, when the first Communist revolution in Russia failed, and the Jews had to scramble out of Russia, they all went to Germany. And Germany gave them refuge. And they were treated very nicely. And here they sold Germany down the river for no reason at all other than they wanted Palestine as a so- called ?Jewish commonwealth.? Now, Nahum Sokolow -- all the great leaders, the big names that you read about in connection with Zionism today -- they, in 1919, 1920, '21, '22, and '23, they wrote in all their papers -- and the press was filled with their statements -- that "the feeling against the Jews in Germany is due to the fact that they realized that this great defeat was brought about by our intercession and bringing the United States into the war against them." From e.datateam at gmail.com Thu Jul 22 01:43:00 2010 From: e.datateam at gmail.com (E-DataTeam) Date: Wed, 21 Jul 2010 22:43:00 -0700 (PDT) Subject: solution manual & test bank Message-ID: <92fffa19-09dd-4efa-82f0-266792453997@d17g2000yqb.googlegroups.com> Hi! we are GetSolution team Our mission supplying solution manuals , test banks , to students all over the world if you need any solutions manual or test bank just email us This is partial list of our solutions, if the solution you want isn't on the list, do not give up, just contact us. WwW.GetSolutionTeam.CoM Note: all solutions manual in soft copy that mean in Adobe Acrobat Reader (PDF ) format. to get the solution manual you want please send message to getsolution at hotmail.com getsolution(at)hotmail.com replace (at) to @ please don't post your request here to get the solutions please send like that: hi my name is Jone i want to get this solutions manual/ test bank: "A First Course In Probability Solution Manual,Ross 6th " How much is it to know how u can get the solutions please visit our website www.GetSolutionTeam.com " We Have Live Support On The WebSite" This is partial list of our solutions, if the solution you want isn't on the list, do not give up, just contact us. From nanothermite911fbibustards at gmail.com Thu Jul 22 02:15:34 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Wed, 21 Jul 2010 23:15:34 -0700 (PDT) Subject: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO THERMITE in WTC dust ? References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> Message-ID: <444e75c2-9b8d-4d56-9e4a-96b4b33c82c0@q35g2000yqn.googlegroups.com> On Jul 21, 4:31?pm, spudnik wrote: > thermite is not what you think, it is; > it's primary use is for dismantling steel frameworks, > piece by piece, just as they were welded -- > see the report by MIT's Head Welder. > > thus: > there, you've hit upon the self-same absurdity > of Newton's "theory" of corpuscles, vis-a-vu waves of light > in the non-vacuum of space (unconsciously .-) > > thus quoth: > Does every dust speck have gravitons? ?And if not, how do the specks > know... "which way the mass is"? > > --BP's cap&trade "free-er trade nostrum" is before Senate!http://tarpley.net/online-books/george-bush-the-unauthorized-biograph... Whats the qualification of you a faceless, spooooky bustard ? unlike HONORABLE Professor Dr Steven Jones, who sacrificed his job and career at BYU - Brigham Young University . Whats your sacrifice to show your conviction from your ODIOUS and PUTRID mouth ? From fulviocasali at gmail.com Thu Jul 22 02:26:35 2010 From: fulviocasali at gmail.com (fulv) Date: Wed, 21 Jul 2010 23:26:35 -0700 (PDT) Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters Message-ID: I get the following error: File "", line 1, in ? File "/Users/fulvio/plone/seiu_new/buildout/eggs/z3c.saconfig-0.11- py2.4.egg/z3c/saconfig/utility.py", line 164, in __call__ _ENGINES[self._key] = engine = sqlalchemy.create_engine( File "/Users/fulvio/plone/seiu_new/buildout/eggs/SQLAlchemy-0.6.3- py2.4.egg/sqlalchemy/engine/__init__.py", line 244, in create_engine return strategy.create(*args, **kwargs) TypeError: create() takes exactly 2 non-keyword arguments (150 given) Basically, args and kwargs come as the return values from my overridden function configuration(): args, kw = self.configuration() _ENGINES[self._key] = engine = sqlalchemy.create_engine( *args, **kw) This is what I'm returning from configuration(): args = (connection_string) kwargs = {'echo' : True, 'encoding' : 'cp1252'} return args, kwargs In other words, args is a list containing just one string. It seems to me that create_engine is interpreting that as a list of 150 characters. Any suggestions, on what I'm doing wrong? Thanks! Fulvio From girish.cfc at gmail.com Thu Jul 22 02:35:32 2010 From: girish.cfc at gmail.com (Girish) Date: Wed, 21 Jul 2010 23:35:32 -0700 (PDT) Subject: Unzip File un Python 5.5 Message-ID: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Hello All, I am using Python 2.5. How do I extract all the files and directories in a zip file? Thanks in advance.. -Girish From nopsidy at gmail.com Thu Jul 22 02:49:27 2010 From: nopsidy at gmail.com (nopsidy) Date: Thu, 22 Jul 2010 01:49:27 -0500 Subject: Unzip File un Python 5.5 In-Reply-To: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> References: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Message-ID: hi, hope this helps. http://www.google.com/search?hl=en&q=unzip+file+in+python -------------- next part -------------- An HTML attachment was scrubbed... URL: From prologic at shortcircuit.net.au Thu Jul 22 02:53:05 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 22 Jul 2010 16:53:05 +1000 Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters In-Reply-To: References: Message-ID: On Thu, Jul 22, 2010 at 4:26 PM, fulv wrote: > ?args = (connection_string) Replace this with: args = (connection_string,) NOTE: The trailing , (comma) indicating that this _is_ a tuple. cheers James -- -- James Mills -- -- "Problems are solved by method" From ben+python at benfinney.id.au Thu Jul 22 02:56:05 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 22 Jul 2010 16:56:05 +1000 Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters References: Message-ID: <87zkxk57ju.fsf@benfinney.id.au> fulv writes: > return strategy.create(*args, **kwargs) > TypeError: create() takes exactly 2 non-keyword arguments (150 given) > > Basically, args and kwargs come as the return values from my > overridden function configuration(): > > args, kw = self.configuration() > _ENGINES[self._key] = engine = > sqlalchemy.create_engine( > *args, **kw) (As a side note: Please use a mail client that won't wrap your lines incorrectly like the above. That might mean not using Google Mail.) > This is what I'm returning from configuration(): > > args = (connection_string) > kwargs = {'echo' : True, 'encoding' : 'cp1252'} > return args, kwargs > > In other words, args is a list containing just one string. No, it isn't. The syntax you've used merely puts parentheses around the object ?connection_string?; parentheses don't make a list. So, when you use the argument unpacking syntax, the string gets unpacked into its component characters, as you noticed. You might have meant ?a tuple containing just one string?. But parentheses don't make a tuple either. To make a tuple, use commas. You may put parentheses around the tuple to distinguish it from surrounding syntax, and because commas are used in various other places, sometimes you need to. But never forget that it's the commas that make the tuple, not the parentheses. args = (connection_string,) kwargs = {'echo': True, 'encoding': 'cp1252'} return args, kwargs I hope that helps. -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From steve-REMOVE-THIS at cybersource.com.au Thu Jul 22 03:21:53 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 22 Jul 2010 07:21:53 GMT Subject: Unzip File un Python 5.5 References: <78437b59-7062-451b-aebd-12acf13e4955@z30g2000prg.googlegroups.com> Message-ID: <4c47f191$0$28658$c3e8da3@news.astraweb.com> On Wed, 21 Jul 2010 23:35:32 -0700, Girish wrote: > Hello All, > > I am using Python 2.5. How do I extract all the files and directories in > a zip file? import zipfile z = zipfile.ZipFile("test.zip", mode="r") for internal_filename in z.namelist(): contents = z.read(internal_filename) open(internal_filename, 'w').write(contents) z.close() Or upgrade to Python 2.6 and use the extractall method: http://docs.python.org/library/zipfile.html#zipfile.ZipFile.extractall -- Steven From aimeixu at amazon.com Thu Jul 22 04:14:14 2010 From: aimeixu at amazon.com (aimeixu) Date: Thu, 22 Jul 2010 16:14:14 +0800 Subject: an error about DJANGO_SETTINGS_MODULE Message-ID: <4C47FDD6.1080800@amazon.com> Hi, I use python Django framework to make a bookmark website, when I clicked login button on the user login page .and I import "from django.contrib.auth.models import User" in the console,It will occur the following error: >>> from django.contrib.auth.models import User Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/django/contrib/auth/models.py", line 6, in ? from django.db import models File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, in ? if not settings.DATABASES: File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 276, in __getattr__ self._setup() File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 38, in _setup raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE) ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined. 'cause I am a newbie to python .Please help me find out where the error is and how to solve this problem. Thanks a lot. Best Wishes, From clp2 at rebertia.com Thu Jul 22 05:21:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jul 2010 02:21:29 -0700 Subject: an error about DJANGO_SETTINGS_MODULE In-Reply-To: <4C47FDD6.1080800@amazon.com> References: <4C47FDD6.1080800@amazon.com> Message-ID: On Thu, Jul 22, 2010 at 1:14 AM, aimeixu wrote: > Hi, > I use python Django framework to make a bookmark website, when I clicked > ?login button on ?the user login page .and I ?import "from > django.contrib.auth.models import User" in the console,It will occur the > following error: >>>> from django.contrib.auth.models import User > Traceback (most recent call last): > ?File "", line 1, in ? > ?File "/usr/lib/python2.4/site-packages/django/contrib/auth/models.py", line > 6, in ? > ? from django.db import models > ?File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, in > ? > ? if not settings.DATABASES: > ?File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line > 276, in __getattr__ > ? self._setup() > ?File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 38, > in _setup > ? raise ImportError("Settings cannot be imported, because environment > variable %s is undefined." % ENVIRONMENT_VARIABLE) > ImportError: Settings cannot be imported, because environment variable > DJANGO_SETTINGS_MODULE is undefined. > 'cause I am a newbie to python .Please help me find out where the error is > and how to solve this problem. Thanks a lot. The Django-specific mailinglist may be found at: http://groups.google.com/group/django-users You are more likely to get a [better] answer if you ask there. Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Thu Jul 22 05:38:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 22 Jul 2010 11:38:23 +0200 Subject: detect endianness of a binary with python In-Reply-To: <4C47124A.10405@keymile.com> References: <4C46EEB8.6070702@keymile.com> <4C47124A.10405@keymile.com> Message-ID: >>> Something like the "file" utility for linux would be very helpfull. >>> >>> Any help is appreciated. > >>You're going to have to describe in detail what's in the file before >>anybody can help. > > We are creating inside our buildsystem for an embedded system a cram > filesystem > image. Later on inside our build process we have to check the endianness, > because it could be Little Endian or big endian (arm or ppc). > > The output of the "file" tool is for a little endian cramfs image: > : Linux Compressed ROM File System data, little endian size > 1875968 > version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > > It would be possible to execute > ret = os.system("file | grep "little endian") > and evaluate the return code. > But I don't like to evaluate a piped system command. If there is an way > without > using the os.system command this would be great. > Please see http://pypi.python.org/pypi/python-magic HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From pdwjfndjbdgfyg at gmail.com Thu Jul 22 05:41:09 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Thu, 22 Jul 2010 02:41:09 -0700 (PDT) Subject: REAL HOT VIDEOS Message-ID: <2686d7b5-cc89-4db6-bb6e-97be373d55bd@l25g2000prn.googlegroups.com> hot kisses http://hotvidos.blogspot.com/2010/07/hot-kisses.html hot lip kiss http://hotvidos.blogspot.com/2010/07/hot-lip-kiss.html katrina kaif hot videos http://hotvidos.blogspot.com/2010/07/katrina-kaif-hot-videos.html bollywood hot vieos http://hotvidos.blogspot.com/2010/07/bollywood-hot-vieos.html tollywood hot vieos http://hotvidos.blogspot.com/2010/07/tollywood-hot-vieos.html tamil hot videos http://hotvidos.blogspot.com/2010/07/tamil-hot-videos.html mallu hot videos http://hotvidos.blogspot.com/2010/07/mallu-hot-videos.html real hot videos http://hotvidos.blogspot.com/2010/07/real-hot-videos.html hollywood hot videos http://hotvidos.blogspot.com/2010/07/hollywood-hot-videos.html From kwutzke at web.de Thu Jul 22 07:03:05 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 22 Jul 2010 04:03:05 -0700 (PDT) Subject: Visitor pattern and separating iteration Message-ID: Hello, I'm referring to http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9ba9816fe4fd55# I'm currently implementing what looks like a promising solution. I have one problem though. My code generator isn't awfully complex, but still I have problems trying to figure out where to put the iteration code. Ideally, this should be in the classes the generator operates on. Take the following Python code from my generator class: def handleMethod(self, method): # generate indent depending on object depth in tree indent = self.generateIndent(method) # "public final" modifierString = "" i = 0 for modifier in method.getModifiers(): if i > 0: modifierString += " " modifierString += modifier i += 1 # "String firstName, String lastName" parameterString = "" i = 0 for parameter in method.getParameters(): if i > 0: parameterString += ", " parameterString += parameter.getType() + " " + parameter.getName() i += 1 code = indentString + modifierString + " " + (method.getReturnType() is None and "" or method.getReturnType() + " ") + method.getName() + "(" + parameterString + ")" code += "\n{" # here the statements should go code += "\n}" return code The place where the statements should go would require an iteration over the statements. When looking at other code samples, you often see def accept(self, visitor): for child in self.getChildren(): child.accept(visitor) visitor.visitMyClass(self) Now, I am wondering how separation of iteration and actual code generation can be done in my situation. def accept(self, generator): for child in self.getChildren(): child.accept(generator) generator.handleMethod(self) I could of course add a parameter to handleMethod which would be the generated code for the statements, but is that design of any good use then? I'm rather tempted to ditch the idea of separating iteration and code generation, but then the use of the visitor pattern becomes more and more questionable. What is it I'm missing? Karsten From kwutzke at web.de Thu Jul 22 07:11:57 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Thu, 22 Jul 2010 04:11:57 -0700 (PDT) Subject: Visitor pattern and separating iteration References: Message-ID: <45c17022-1a95-4081-9107-6caad1531e01@f33g2000yqe.googlegroups.com> > ? ? ? ? # "public final" > ? ? ? ? modifierString = "" > > ? ? ? ? i = 0 > > ? ? ? ? for modifier in method.getModifiers(): > ? ? ? ? ? ? if i > 0: > ? ? ? ? ? ? ? ? modifierString += " " > ? ? ? ? ? ? modifierString += modifier > > ? ? ? ? ? ? i += 1 > And please don't comment on the code itself, as I'm just starting to learn the Python API. The above should be modifierString = " ".join(method.getModifiers()) Thanks Karsten From kaklis at gmail.com Thu Jul 22 08:54:58 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Thu, 22 Jul 2010 05:54:58 -0700 (PDT) Subject: Convert Unix timestamp to Readable Date/time Message-ID: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> Well i have the following number 1279796174846 i did the following: mdate = 1279796174846 tempStr = str(mdate) tempStr2 = tempStr[:-3] tempInt = int(tempStr2) print "Last Login :", datetime.datetime.fromtimestamp(tempInt) that prints out: 2010-07-22 06:56:14 But when i check my answer at http://www.onlineconversion.com/unix_time.htm i got: Thu, 22 Jul 2010 10:56:14 GMT which is what i want. What am i doing wrong? Thanks Antonis From clp2 at rebertia.com Thu Jul 22 09:01:47 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Jul 2010 06:01:47 -0700 Subject: Convert Unix timestamp to Readable Date/time In-Reply-To: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> References: <855bde26-1609-4ae3-95c1-82ae278da37c@k39g2000yqb.googlegroups.com> Message-ID: On Thu, Jul 22, 2010 at 5:54 AM, kaklis at gmail.com wrote: > Well i have the following number 1279796174846 > ?i did the following: > > mdate = 1279796174846 > tempStr = str(mdate) > tempStr2 = tempStr[:-3] > tempInt = int(tempStr2) > print "Last Login :", datetime.datetime.fromtimestamp(tempInt) > > that prints out: 2010-07-22 06:56:14 > But when i check my answer at http://www.onlineconversion.com/unix_time.htm > > i got: ? ?Thu, 22 Jul 2010 10:56:14 GMT which is what i want. > What am i doing wrong? >From http://docs.python.org/library/datetime.html (emphases added): """ classmethod datetime.fromtimestamp(timestamp[, tz]) Return the ***local*** date and time corresponding to the POSIX timestamp [...] """ vs. """ classmethod datetime.utcfromtimestamp(timestamp)? Return the ***UTC*** datetime corresponding to the POSIX timestamp [...] """ IOW, read the fine docs. Cheers, Chris -- http://blog.rebertia.com From jbbrown at sunflower.kuicr.kyoto-u.ac.jp Thu Jul 22 10:51:54 2010 From: jbbrown at sunflower.kuicr.kyoto-u.ac.jp (J.B. Brown) Date: Thu, 22 Jul 2010 23:51:54 +0900 Subject: Sun Grid Engine / NFS and Python shell execution question Message-ID: Hello everyone, and thanks for your time to read this. For quite some time, I have had a problem using Python's shell execution facilities in combination with a cluster computer environment (such as Sun Grid Engine (SGE)). In particular, I wish to repeatedly execute a number of commands in sub-shells or pipes within a single function, and the repeated execution is depending on the previous execution, so just writing a brute force script file and executing commands is not an option for me. To isolate and exemplify my problem, I have created three files: (1) one which exemplifies the spirit of the code I wish to execute in Python (2) one which serves as the SGE execution script file, and actually calls python to execute the code in (1) (3) a simple shell script which executes (2) a sufficient number of times that it fills all processors on my computing cluster and leaves an additional number of jobs in the queue. Here is the spirit of the experiment/problem: generateTest.py: ---------------------------------------------- # Constants numParallelJobs = 100 testCommand = "continue" #"os.popen( \"clear\" )" loopSize = "1000" # First, write file with test script. pythonScript = file( "testScript.py", "w" ) pythonScript.write( """ import os for i in range( 0, """ + loopSize + """ ): for j in range( 0, """ + loopSize + """ ): for k in range( 0, """ + loopSize + """ ): for l in range( 0, """ + loopSize + """ ): """ + testCommand + """ """ ) pythonScript.close() # Second, write SGE script file to execute the Python script. sgeScript = file( "testScript.sge", "w" ) sgeScript.write ( """ #$ -cwd #$ -N pythonTest #$ -e /export/home/jbbrown/errorLog #$ -o /export/home/jbbrown/outputLog python testScript.py """ ) sgeScript.close() # Finally, write script to run SGE script a specified number of times. import os launchScript = file( "testScript.sh", "w" ) for i in range( 0, numParallelJobs ): launchScript.write( "qsub testScript.sge" + os.linesep ) launchScript.close() ---------------------------------------------- Now, let's assume that I have about 50 processors available across 8 compute nodes, with one NFS-mounted disk. If I run the code as above, simply executing Python "continue" statements and do nothing, the cluster head node reports no serious NFS daemon load. However - if I change the code to use the os.popen() call shown as a comment above, or use os.system(), the NFS daemon load on my system skyrockets within seconds of distributing the jobs to the compute nodes -- even though I'm doing nothing but executing the clear screen command, which technically doesn't pipe any output to the location for logging stdout. Even if I change the SGE script file to redirect standard output and error to explicitly go to /dev/null, I still have the same problem. I believe the source of this problem is that os.popen() or os.system() calls spawn subshells which then reference my shell resource files (.zshrc, .cshrc, .bashrc, etc.). But I don't see an alternative to os.popen{234} or os.system(). os.exec*() cannot solve my problem, because it transfers execution to that program and stops executing the script which called os.exec*(). Without having to rewrite a considerable amount of code (which performs cross validation by repeatedly executing in a subshell) in terms of a shell script language filled with a large number of conditional statements, does anyone know of a way to execute external programs in the middle of a script without referencing the shell resource file located on an NFS mounted directory? I have read through the >help(os) documentation repeatedly, but just can't find a solution. Even a small lead or thought would be greatly appreciated. With thanks from humid Kyoto, J.B. Brown From python at mrabarnett.plus.com Thu Jul 22 11:31:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 22 Jul 2010 16:31:55 +0100 Subject: Sun Grid Engine / NFS and Python shell execution question In-Reply-To: References: Message-ID: <4C48646B.40101@mrabarnett.plus.com> J.B. Brown wrote: > Hello everyone, and thanks for your time to read this. > > For quite some time, I have had a problem using Python's shell > execution facilities in combination with a cluster computer > environment (such as Sun Grid Engine (SGE)). > In particular, I wish to repeatedly execute a number of commands in > sub-shells or pipes within a single function, and the repeated > execution is depending on the previous execution, so just writing a > brute force script file and executing commands is not an option for > me. > > To isolate and exemplify my problem, I have created three files: > (1) one which exemplifies the spirit of the code I wish to execute in Python > (2) one which serves as the SGE execution script file, and actually > calls python to execute the code in (1) > (3) a simple shell script which executes (2) a sufficient number of > times that it fills all processors on my computing cluster and leaves > an additional number of jobs in the queue. > > Here is the spirit of the experiment/problem: > generateTest.py: > ---------------------------------------------- > # Constants > numParallelJobs = 100 > testCommand = "continue" #"os.popen( \"clear\" )" > loopSize = "1000" > > # First, write file with test script. > pythonScript = file( "testScript.py", "w" ) > pythonScript.write( > """ > import os > for i in range( 0, """ + loopSize + """ ): > for j in range( 0, """ + loopSize + """ ): > for k in range( 0, """ + loopSize + """ ): > for l in range( 0, """ + loopSize + """ ): > """ + testCommand + """ > """ ) > pythonScript.close() > > # Second, write SGE script file to execute the Python script. > sgeScript = file( "testScript.sge", "w" ) > sgeScript.write ( > """ > #$ -cwd > #$ -N pythonTest > #$ -e /export/home/jbbrown/errorLog > #$ -o /export/home/jbbrown/outputLog > python testScript.py > """ ) > sgeScript.close() > > # Finally, write script to run SGE script a specified number of times. > import os > launchScript = file( "testScript.sh", "w" ) > for i in range( 0, numParallelJobs ): > launchScript.write( "qsub testScript.sge" + os.linesep ) > launchScript.close() > > ---------------------------------------------- > > Now, let's assume that I have about 50 processors available across 8 > compute nodes, with one NFS-mounted disk. > If I run the code as above, simply executing Python "continue" > statements and do nothing, the cluster head node reports no serious > NFS daemon load. > > However - if I change the code to use the os.popen() call shown as a > comment above, or use os.system(), > the NFS daemon load on my system skyrockets within seconds of > distributing the jobs to the compute nodes -- even though I'm doing > nothing but executing the clear screen command, which technically > doesn't pipe any output to the location for logging stdout. > Even if I change the SGE script file to redirect standard output and > error to explicitly go to /dev/null, I still have the same problem. > > I believe the source of this problem is that os.popen() or os.system() > calls spawn subshells which then reference my shell resource files > (.zshrc, .cshrc, .bashrc, etc.). > But I don't see an alternative to os.popen{234} or os.system(). > os.exec*() cannot solve my problem, because it transfers execution to > that program and stops executing the script which called os.exec*(). > > Without having to rewrite a considerable amount of code (which > performs cross validation by repeatedly executing in a subshell) in > terms of a shell script language filled with a large number of > conditional statements, does anyone know of a way to execute external > programs in the middle of a script without referencing the shell > resource file located on an NFS mounted directory? > I have read through the >help(os) documentation repeatedly, but just > can't find a solution. > > Even a small lead or thought would be greatly appreciated. > Have you looked at the 'subprocess' module? From fulviocasali at gmail.com Thu Jul 22 12:01:58 2010 From: fulviocasali at gmail.com (fulv) Date: Thu, 22 Jul 2010 09:01:58 -0700 (PDT) Subject: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters References: Message-ID: <42e580ef-f9b3-4305-b531-860ecc46e999@y32g2000prc.googlegroups.com> Thank you all! Really appreciate the quick help! From burton at userful.com Thu Jul 22 12:12:51 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 22 Jul 2010 10:12:51 -0600 Subject: Improper Backtraces in Exec'd Code Message-ID: Hello, I have written an importing extension along the lines of PEP 302 (http://www.python.org/dev/peps/pep-0302/) and have run into a bit of a problem with stack backtraces after exceptions. When I run code with the using my importing extension, backtraces come up looking like this: Traceback (most recent call last): File "", line 134, in File "", line 9, in File "", line 7, in a File "", line 4, in b TypeError What I'm having a problem with is that the file names are no longer being printed during the backtrace. The following code is from my importer function load_module: try: mod = sys.modules[module_name] already_in_sys_modules = True except KeyError: mod = sys.modules.setdefault(module_name, imp.new_module(module_name)) already_in_sys_modules = False mod.__file__ = "%s" % module_path mod.__loader__ = self if is_package: mod.__path__ = [ module_path ] mod.__dict__['__file__'] = module_path try: exec code in mod.__dict__ except: import traceback print traceback.format_exc(5) print "ERROR: could not load module: %s" % module_path if not already_in_sys_modules: del sys.modules[module_name] mod = None As shown in PEP 302, I am setting the mod.__file__ variable and as my own idea I set __file__ in mod.__dict__. Niether of these steps seem to set the file properly in the backtrace. So the question here is, where does the backtrace printing module get it's __file__ parameters from, or what am I missing to set it properly? Thanks in advance. -- Burton Samograd From nils at ccsg.de Thu Jul 22 12:19:25 2010 From: nils at ccsg.de (Nils Ruettershoff) Date: Thu, 22 Jul 2010 18:19:25 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: <4C486F8D.6020902@ccsg.de> Hi Jim, Jim Qiu wrote: > > I make installed python 2.7 from source, and also installed the RPM > version of cx_Oracle for python 2.7. > > But ldd tells me : > #ldd cx_Oracle.so > libpython2.7.so.1.0 => not found > > I find out that only libpython2.7.a generated when I install > python2.7, who can tell me what I need to do ? I want a > libpython2.7.so.1.0 generated when > [...] Due to the fact that you have compiled python from source, the python library is not in the defaul library path. Due to that the lib can't be found. As a quick workourd you can extend the LD_LIBRARY_PATH variable with the path and check if cx_Orcacle get now the lib. Lets assume you "installed" python at /opt/Python2.7a, then you need to extend the variable in this way: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/Python2.7a/lib" afterwards do the ldd again and check if the lib could be found now. If not, you've got the wrong path. Now you need to perist the changed library path. For this, you need to be root: 1. echo "/opt/Python2.7a/lib" > /etc/ld.so.conf.d/Pathon2.7a.conf 2. refresh your shared library cache with "ldconfig" Now you OS knows the new library location. But this is not clean. As Daniel mention, you should try to get a rpm. Otherwise you may get in trouble, if you install a newer Python2.7 version and forget to maintain you library paths. Cheers, Nils From nils at ccsg.de Thu Jul 22 12:39:46 2010 From: nils at ccsg.de (Nils Ruettershoff) Date: Thu, 22 Jul 2010 18:39:46 +0200 Subject: source install of python2.7 and rpm install of cx_Oracle collision In-Reply-To: References: Message-ID: <4C487452.7040303@ccsg.de> Hi Jim, Jim Qiu wrote: [...] > I find out that only libpython2.7.a generated when I install > python2.7, who can tell me what I need to do ? I want a > libpython2.7.so.1.0 generated when > I've didn't read your complete mail... In addition to the steps I've described in my other mail, you need to the "configure" script, that you like to have shared libraries. So you need to add --enable-shared to your configure call: ./configure --prefix=/opt/Python2.7a --enable-shared Now you got the shared libraries in the lib folder. Cheers, Nils From thomas at jollans.com Thu Jul 22 12:56:03 2010 From: thomas at jollans.com (Thomas Jollans) Date: Thu, 22 Jul 2010 18:56:03 +0200 Subject: Sorting a list created from a parsed xml message In-Reply-To: <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: <4C487823.4080003@jollans.com> On 07/21/2010 03:38 PM, kaklis at gmail.com wrote: > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: >> On Jul 21, 8:58 am, Stefan Behnel wrote: >> >> >> >>> kak... at gmail.com, 21.07.2010 14:36: >> >>>> From the subject of my message it's clear that i get an xml message >>>> from a socket, >> >>> Not at all, but now that you say it... >> >>>> i parse it and the result is a list like the one that >>>> follows: >>>> ID_Col >>>> 4 Server ak ip OFFLINE >> >>>> 29 Server and2 ip OFFLINE >> >>>> 5 Proxy l34e ip OFFLINE >> >>>> 6 Proxy barc ip ONLINE >> >>>> 41 Proxy proxy-2 ip ONLINE >> >>>> 53 Server server-4 ip ONLINE >> >>>> 52 Server server-3 ip ONLINE >> >>> Doesn't look like a Python list to me... >> >>>> What i want is to print this list sorted by ID_Col? >>>> Any Suggestions? >> >>> Assuming that the above is supposed to represent a list of tuples, you can >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' >>> argument (see the sort() method and the operator module). >> >>> Stefan >> >> No it is not a Python list at all. This the way i print the parsed >> items 'like a list'. >> But i want them to be sorted. > > Well i did this: > > SortedServers = [] > > for session in sessions: > for IP in session.getElementsByTagName("ipAddress"): > for iphn in session.getElementsByTagName("hostName"): > tempTuple = session.getAttribute("id"), > session.getAttribute("type"), iphn.childNodes[0].data, > IP.childNodes[0].data, session.getAttribute("status") Please try to persuade your mail client to not mess up python code, if you could. It would make this *so* much easier to read > > SortedServers.append(tempTuple) > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) Anyway, let's look at that key function of yours: key=lambda id: SortedServers[0] translated to traditional function syntax: def key(id): return SortedServers[0] No matter which item sorted() examines, the key it sorts by is always the same (the first item of the WHOLE LIST). You want something more like this: def key(row): return row[0] ergo, what you want, all in all, is either of these: Sorted = sorted(SortedServers, key=(lambda row: row[0])) # option 1 SortedServers.sort(key=(lambda row: row[0])) # option 2 option 2, the in-place sort, might be faster. (and, as Stefan noted, as you probably want a numeric sort, you'll want your key to be an int) > for item in Sorted: > print item > > but the list is still unsorted and with u' in front of each item > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') > > How do i remove the u' > > Antonis From __peter__ at web.de Thu Jul 22 13:00:43 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Jul 2010 19:00:43 +0200 Subject: Improper Backtraces in Exec'd Code References: Message-ID: Burton Samograd wrote: > Hello, > > I have written an importing extension along the lines of PEP 302 > (http://www.python.org/dev/peps/pep-0302/) and have run into a bit of a > problem with stack backtraces after exceptions. > > When I run code with the using my importing extension, backtraces come > up looking like this: > > Traceback (most recent call last): > File "", line 134, in > File "", line 9, in > File "", line 7, in a > File "", line 4, in b > TypeError > > What I'm having a problem with is that the file names are no longer > being printed during the backtrace. The following code is from my > importer function load_module: > > try: > mod = sys.modules[module_name] > already_in_sys_modules = True > except KeyError: > mod = sys.modules.setdefault(module_name, > imp.new_module(module_name)) > already_in_sys_modules = False > mod.__file__ = "%s" % module_path > mod.__loader__ = self > if is_package: > mod.__path__ = [ module_path ] > mod.__dict__['__file__'] = module_path > try: > exec code in mod.__dict__ > except: > import traceback > print traceback.format_exc(5) > print "ERROR: could not load module: %s" % module_path > if not already_in_sys_modules: > del sys.modules[module_name] > mod = None > > As shown in PEP 302, I am setting the mod.__file__ variable and as my > own idea I set __file__ in mod.__dict__. Niether of these steps seem to > set the file properly in the backtrace. > > So the question here is, where does the backtrace printing module get > it's __file__ parameters from, or what am I missing to set it properly? > > Thanks in advance. > > -- > Burton Samograd exec code implicitly compiles code with "" as the filename. The filename is stored in f.func_code.co_filename and it is read-only. >> exec "def f(x): return f(x-1) if x else 1/0" >>> f(3) Traceback (most recent call last): File "", line 1, in File "", line 1, in f File "", line 1, in f File "", line 1, in f File "", line 1, in f ZeroDivisionError: integer division or modulo by zero If you make the compilation step explicit you can pass a filename: >>> exec compile("def f(x): return f(x-1) if x else 1/0", "yadda.py", "exec") >>> f(3) Traceback (most recent call last): File "", line 1, in File "yadda.py", line 1, in f File "yadda.py", line 1, in f File "yadda.py", line 1, in f File "yadda.py", line 1, in f ZeroDivisionError: integer division or modulo by zero Of course the offending line isn't quoted because there is no file "yadda.py" on my harddisk. But I can change that: >>> with open("yadda.py", "w") as out: print >> out, "I was fooled!" ... >>> f(3) Traceback (most recent call last): File "", line 1, in File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! File "yadda.py", line 1, in f I was fooled! ZeroDivisionError: integer division or modulo by zero Peter From johannes.black at gmail.com Thu Jul 22 13:47:26 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 22 Jul 2010 10:47:26 -0700 (PDT) Subject: pycrypto rsa string decryption Message-ID: I have an encrypted string and a key string (512 bits long). After studying the pycrypto documentation I still don't get how to read the private key and decrypt the string. - read the 512 bit string as private key - decrypt the encrypted string with rsa Any short code example how to do that? Greetings and thanks From burton at userful.com Thu Jul 22 13:48:38 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 22 Jul 2010 11:48:38 -0600 Subject: Improper Backtraces in Exec'd Code References: Message-ID: Peter Otten <__peter__ at web.de> writes: > If you make the compilation step explicit you can pass a filename: > >>>> exec compile("def f(x): return f(x-1) if x else 1/0", "yadda.py", > "exec") The works great. Problem solved. Thanks. -- Burton Samograd From Space998 at hotmail.com Thu Jul 22 15:25:29 2010 From: Space998 at hotmail.com (spudnik) Date: Thu, 22 Jul 2010 12:25:29 -0700 (PDT) Subject: trace of NANO THERMITE in WTC dust -- and almost no asbestos, because the scare stopped it from being used (and the buildings might not have collapsed, if it was) References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> <444e75c2-9b8d-4d56-9e4a-96b4b33c82c0@q35g2000yqn.googlegroups.com> Message-ID: <54a8c42f-1632-40cf-8eb0-fee14f32ea9b@k1g2000prl.googlegroups.com> I know what Thermite (TM) is, and I didn't even googol it. > Whats the qualification of you a faceless, spooooky bustard ? unlike > HONORABLE Professor Dr Steven Jones, who sacrificed his job and career > at BYU ?- Brigham Young University . Whats your sacrifice to show your > conviction from your ODIOUS and PUTRID mouth ? thus: if the entagnlement of two Newtonian rocks o'light, could traansmit information, then it would be some thing, but they are actually nor photons per se. thus: more folks should know about this quantumization! > I no longer accept redshift as a Doppler motion and > that would have huge consequence to a Tifft quantization. --BP's next bailout of Wall St. and "the City" (of London, gated community & financial district), or the last, if nothing is left of the USA. http://tarpley.net/online-books/george-bush-the-unauthorized-biography/chapter-8-the-permian-basin From hobson42 at gmaiil.com Thu Jul 22 16:25:56 2010 From: hobson42 at gmaiil.com (Ian) Date: Thu, 22 Jul 2010 21:25:56 +0100 Subject: Visitor pattern and separating iteration In-Reply-To: References: Message-ID: <4C48A954.8060803@gmaiil.com> Hi Karsten, On 22/07/2010 12:03, Karsten Wutzke wrote: > What is it I'm missing? > I think you are making it more complicated than it really is. The visitor pattern is about bringing all the little bits that would otherwise be scattered all over many node classes into one visitor class. For code generation this means that all the code generation is done in your visitor class. For pretty-printing you have another visitor class. For code optimization a third visitor class. If there is only one sequence in which the nodes should be visited, then you can build it in to the nodes of the tree. If you need to visit your nodes in different orders you might be better off building a separated tree-walker class for each order. Thus you might have a post-order-walker for use with the code generating visitor, and a in-order-walker for a pretty-printing visitor. The optimizing walker may need to take different routes through the tree depending upon what it finds. For example, it may compute the value of the RHS of an assignment before computing the address of the LHS, so it can make better use of registers. Here the visitor class itself needs to do the walking. Regards Ian From breamoreboy at yahoo.co.uk Thu Jul 22 16:35:59 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 22 Jul 2010 21:35:59 +0100 Subject: Visitor pattern and separating iteration In-Reply-To: References: Message-ID: On 22/07/2010 12:03, Karsten Wutzke wrote: > Hello, > > I'm referring to > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/4f9ba9816fe4fd55# > > I'm currently implementing what looks like a promising solution. I > have one problem though. My code generator isn't awfully complex, but > still I have problems trying to figure out where to put the iteration > code. Ideally, this should be in the classes the generator operates > on. Take the following Python code from my generator class: > > def handleMethod(self, method): > > # generate indent depending on object depth in tree > indent = self.generateIndent(method) > > # "public final" > modifierString = "" > > i = 0 > > for modifier in method.getModifiers(): > if i> 0: > modifierString += " " > modifierString += modifier > > i += 1 > > # "String firstName, String lastName" > parameterString = "" > > i = 0 > > for parameter in method.getParameters(): > if i> 0: > parameterString += ", " > parameterString += parameter.getType() + " " + > parameter.getName() > > i += 1 > > code = indentString + modifierString + " " + > (method.getReturnType() is None and "" or method.getReturnType() + " > ") + method.getName() + "(" + parameterString + ")" > > code += "\n{" > > # here the statements should go > > code += "\n}" > > return code > > The place where the statements should go would require an iteration > over the statements. When looking at other code samples, you often see > > def accept(self, visitor): > for child in self.getChildren(): > child.accept(visitor) > > visitor.visitMyClass(self) > > Now, I am wondering how separation of iteration and actual code > generation can be done in my situation. > > def accept(self, generator): > for child in self.getChildren(): > child.accept(generator) > > generator.handleMethod(self) > > I could of course add a parameter to handleMethod which would be the > generated code for the statements, but is that design of any good use > then? I'm rather tempted to ditch the idea of separating iteration and > code generation, but then the use of the visitor pattern becomes more > and more questionable. > > What is it I'm missing? > > Karsten I suggest you google for "python patterns alex martelli". From what I've read, he's forgotten more about Python and/or patterns than most of us will ever know. HTH. Mark Lawrence. From smallpox911 at gmail.com Thu Jul 22 17:40:50 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 22 Jul 2010 14:40:50 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Message-ID: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Stallman took over his EMACS Oracle's Larry Ellison, took over his SUN-JAVA Steve Jobs has Apple A free competitor to Oracle must be there to limit this fiend from taking over the world. There was VICIOUS propaganda against Microsoft's, Bill Gates. 1981 Gosling Emacs by James Gosling written in C; with "Mocklisp" as its extension language. / | 1983 / | / Unipress Emacs (6-may-83) / $395 commercial product. http://nighthacks.com/roller/jag/ \begin{quotation} When Sun folks get together and bullshit about their theories of why Sun died, the one that comes up most often is another one of these supplier disasters. Towards the end of the DotCom bubble, we introduced the UltraSPARC-II. Total killer product for large datacenters. We sold lots. But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. Not very often, but often enough to be problems for customers. Sun customers were used to uptimes of years. The US-II was giving uptimes of weeks. We couldn't even figure out if it was a hardware problem or a software problem - Solaris had to be updated for the new machine, so it could have been a kernel problem. But nothing was reproducible. We'd get core dumps and spend hours pouring over them. Some were just crazy, showing values in registers that were simply impossible given the preceeding instructions. We tried everything. Replacing processor boards. Replacing backplanes. It was deeply random. It's very randomness suggested that maybe it was a physics problem: maybe it was alpha particles or cosmic rays. Maybe it was machines close to nuclear power plants. One site experiencing problems was near Fermilab. We actually mapped out failures geographically to see if they correlated to such particle sources. Nope. In desperation, a bright hardware engineer decided to measure the radioactivity of the systems themselves. Bingo! Particles! But from where? Much detailed scanning and it turned out that the packaging of the cache ram chips we were using was noticeably radioactive. We switched suppliers and the problem totally went away. After two years of tearing out hair out, we had a solution. \end{quotation} [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - for them ??? ] \begin{quotation} Despite being "blissfully unemployed", I've been remarkably busy. Some of my time has been taken up by job hunting, some by a fun geek project (more on that in a later post), but an awful lot has been taken up talking to people about life at Oracle. They need a place to vent, and I try to be a good listener. The exodus has been a thundering stampede. Pretty soon, all Larry will have left is an IP portfolio. Perhaps that's all he wanted: there's precious little evidence that he was interested in any of the people. Early on after quitting, I kept waking up in the middle of the night having nightmares about composing screeching blog entries. They would have been fun, but pointless. I decided that it was finally time to do some real relaxing and spend some quality time with a beach and an ocean - I figured I needed to do it before the poison that BP's been dumping kills much more. I had a great time. Got back last night. Feeling hugely better. \end{quotation} From smallpox911 at gmail.com Thu Jul 22 17:47:28 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 22 Jul 2010 14:47:28 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. References: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> Message-ID: <4ca2a6ca-4be2-4d74-ad16-79b701f034ac@q12g2000yqj.googlegroups.com> On Jul 22, 2:40?pm, small Pox wrote: > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > Stallman took over his EMACS > Oracle's Larry Ellison, took over his SUN-JAVA > Steve Jobs has Apple > > A free competitor to Oracle must be there to limit this fiend from > taking over the world. > > There was VICIOUS propaganda against Microsoft's, Bill Gates. > > 1981 ? ? ? ? ? ? ? Gosling Emacs > ? ? ? ? ? ? ? ? ? ?by James Gosling > ? ? ? ? ? ? ? ? ? ?written in C; with "Mocklisp" > ? ? ? ? ? ? ? ? ? ?as its extension language. > ? ? ? ? ? ? ? ? ? ? ? ?/ ? ? ?| > 1983 ? ? ? ? ? ? ? / ? ? ? | > ? ? ? ? ? ? ? ? ? ? ?/ ? Unipress Emacs (6-may-83) > ? ? ? ? ? ? ? ? ? ? / ? ?$395 commercial product. > > http://nighthacks.com/roller/jag/ > > \begin{quotation} > When Sun folks get together and bullshit about their theories of why > Sun died, the one that comes up most often is another one of these > supplier disasters. Towards the end of the DotCom bubble, we > introduced the UltraSPARC-II. Total killer product for large > datacenters. We sold lots. But then reports started coming in of odd > failures. Systems would crash strangely. We'd get crashes in > applications. All applications. Crashes in the kernel. Not very often, > but often enough to be problems for customers. Sun customers were used > to uptimes of years. The US-II was giving uptimes of weeks. We > couldn't even figure out if it was a hardware problem or a software > problem - Solaris had to be updated for the new machine, so it could > have been a kernel problem. But nothing was reproducible. We'd get > core dumps and spend hours pouring over them. Some were just crazy, > showing values in registers that were simply impossible given the > preceeding instructions. We tried everything. Replacing processor > boards. Replacing backplanes. It was deeply random. It's very > randomness suggested that maybe it was a physics problem: maybe it was > alpha particles or cosmic rays. Maybe it was machines close to nuclear > power plants. One site experiencing problems was near Fermilab. We > actually mapped out failures geographically to see if they correlated > to such particle sources. Nope. In desperation, a bright hardware > engineer decided to measure the radioactivity of the systems > themselves. Bingo! Particles! But from where? Much detailed scanning > and it turned out that the packaging of the cache ram chips we were > using was noticeably radioactive. We switched suppliers and the > problem totally went away. After two years of tearing out hair out, we > had a solution. > \end{quotation} > > [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - > for them ??? ] > > \begin{quotation} > Despite being "blissfully unemployed", I've been remarkably busy. Some > of my time has been taken up by job hunting, some by a fun geek > project (more on that in a later post), but an awful lot has been > taken up talking to people about life at Oracle. They need a place to > vent, and I try to be a good listener. The exodus has been a > thundering stampede. Pretty soon, all Larry will have left is an IP > portfolio. Perhaps that's all he wanted: there's precious little > evidence that he was interested in any of the people. Early on after > quitting, I kept waking up in the middle of the night having > nightmares about composing screeching blog entries. They would have > been fun, but pointless. I decided that it was finally time to do some > real relaxing and spend some quality time with a beach and an ocean - > I figured I needed to do it before the poison that BP's been dumping > kills much more. I had a great time. Got back last night. Feeling > hugely better. > \end{quotation} Watch the VIDEO Thou Shall WIN by DECEPTION - VICTOR OSTROVSKY Press TV-News Analysis-Israel Lebanon Spies-07-16-2010(Part1) http://vodpod.com/watch/4042625-press-tv-news-analysis-israel-lebanon-spies-07-16-2010part1 From nanothermite911fbibustards at gmail.com Thu Jul 22 18:07:55 2010 From: nanothermite911fbibustards at gmail.com (nanothermite911fbibustards) Date: Thu, 22 Jul 2010 15:07:55 -0700 (PDT) Subject: James Gosling the Creator of EMACS and JAVA - leaves ORACLE - But then reports started coming in of odd failures. Systems would crash strangely. We'd get crashes in applications. All applications. Crashes in the kernel. References: <162a0bfb-ad44-48be-a233-3c7dd7e10a62@d17g2000yqb.googlegroups.com> Message-ID: <2e05c1c5-cf8e-480e-9ed8-828739fe3f0e@r27g2000yqb.googlegroups.com> On Jul 22, 2:40?pm, small Pox wrote: > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > But then reports started coming in of odd failures. Systems would > crash strangely. We'd get crashes in applications. All applications. > Crashes in the kernel. > > Stallman took over his EMACS > Oracle's Larry Ellison, took over his SUN-JAVA > Steve Jobs has Apple > > A free competitor to Oracle must be there to limit this fiend from > taking over the world. > > There was VICIOUS propaganda against Microsoft's, Bill Gates. > > 1981 ? ? ? ? ? ? ? Gosling Emacs > ? ? ? ? ? ? ? ? ? ?by James Gosling > ? ? ? ? ? ? ? ? ? ?written in C; with "Mocklisp" > ? ? ? ? ? ? ? ? ? ?as its extension language. > ? ? ? ? ? ? ? ? ? ? ? ?/ ? ? ?| > 1983 ? ? ? ? ? ? ? / ? ? ? | > ? ? ? ? ? ? ? ? ? ? ?/ ? Unipress Emacs (6-may-83) > ? ? ? ? ? ? ? ? ? ? / ? ?$395 commercial product. > > http://nighthacks.com/roller/jag/ > > \begin{quotation} > When Sun folks get together and bullshit about their theories of why > Sun died, the one that comes up most often is another one of these > supplier disasters. Towards the end of the DotCom bubble, we > introduced the UltraSPARC-II. Total killer product for large > datacenters. We sold lots. But then reports started coming in of odd > failures. Systems would crash strangely. We'd get crashes in > applications. All applications. Crashes in the kernel. Not very often, > but often enough to be problems for customers. Sun customers were used > to uptimes of years. The US-II was giving uptimes of weeks. We > couldn't even figure out if it was a hardware problem or a software > problem - Solaris had to be updated for the new machine, so it could > have been a kernel problem. But nothing was reproducible. We'd get > core dumps and spend hours pouring over them. Some were just crazy, > showing values in registers that were simply impossible given the > preceeding instructions. We tried everything. Replacing processor > boards. Replacing backplanes. It was deeply random. It's very > randomness suggested that maybe it was a physics problem: maybe it was > alpha particles or cosmic rays. Maybe it was machines close to nuclear > power plants. One site experiencing problems was near Fermilab. We > actually mapped out failures geographically to see if they correlated > to such particle sources. Nope. In desperation, a bright hardware > engineer decided to measure the radioactivity of the systems > themselves. Bingo! Particles! But from where? Much detailed scanning > and it turned out that the packaging of the cache ram chips we were > using was noticeably radioactive. We switched suppliers and the > problem totally went away. After two years of tearing out hair out, we > had a solution. > \end{quotation} > > [ ??? DID MOSSAD DO IT FOR THEIR BROTHERS - VICTORY IS BY DECEPTION - > for them ??? ] > > \begin{quotation} > Despite being "blissfully unemployed", I've been remarkably busy. Some > of my time has been taken up by job hunting, some by a fun geek > project (more on that in a later post), but an awful lot has been > taken up talking to people about life at Oracle. They need a place to > vent, and I try to be a good listener. The exodus has been a > thundering stampede. Pretty soon, all Larry will have left is an IP > portfolio. Perhaps that's all he wanted: there's precious little > evidence that he was interested in any of the people. Early on after > quitting, I kept waking up in the middle of the night having > nightmares about composing screeching blog entries. They would have > been fun, but pointless. I decided that it was finally time to do some > real relaxing and spend some quality time with a beach and an ocean - > I figured I needed to do it before the poison that BP's been dumping > kills much more. I had a great time. Got back last night. Feeling > hugely better. > \end{quotation} Watch the VIDEO Thou Shall WIN by DECEPTION - VICTOR OSTROVSKY Press TV-News Analysis-Israel Lebanon Spies-07-16-2010(Part1) http://vodpod.com/watch/4042625-press-tv-news-analysis-israel-lebanon-spies-07-16-2010part1 http://vodpod.com/watch/3996570-press-tv-news-analysis-us-nukes-for-israel-07-08-2010part2 ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY ISRAELI Tools of the trade http://www.youtube.com/watch?v=saJdgGZz5iY From tjreedy at udel.edu Thu Jul 22 18:25:07 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jul 2010 18:25:07 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/21/2010 6:56 PM, Daniel Stutzbach wrote: > On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy > wrote: > > These tests use random numbers with a constant, relatively high > density of 25%, which is favorable to radix sort. What if you do the > same test with a constant range of, say, 1000000000 (1 billion) or > even a trillion or quadrillion. Or how about sorting a thousand > 128bit ip6 addresses? Which wins for that? > blist switches to radix sort only if the keys contain only floats or > only integers that fit into a C long. If the integers get too big, it > reverts to timsort. > > When using a sort key, the decorate-sort-undecorate pattern requires > touching every object once before the sort. The check for a consistent > type is done inexpensively during the decorate phase. And it is pretty cheap even when there is no decorate phase. > Here's an example result with a density of only 1%, where the radix sort > is around 4 times as fast: > > otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = > [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' > 'y.sort(key=float)' > 100 loops, best of 3: 12.4 msec per loop > > otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s > 'import random' -s 'x = [random.randrange(10000*100) for i in > range(10000)]' 'y = blist(x)' 'y.sort(key=float)' > 100 loops, best of 3: 3.4 msec per loop > And a density of 0.01%: > > otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = > [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' > 'y.sort(key=float)' > 100 loops, best of 3: 12 msec per loop > > otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s > 'import random' -s 'x = [random.randrange(10000*10000) for i in > range(10000)]' 'y = blist(x)' 'y.sort(key=float)' > 100 loops, best of 3: 3.52 msec per loop Looks good so far. I would like to see that repeated all the way down to range(10) to make sure people doing millions of small sorts were not getting screwed. > list.sort is (near) linear for lists that are mostly ordered. I > think Tim's writeup about this in in the source. For instance, if > one extends a sorted with 1% random additions and resorts, list.sort > will skip the sorted part, sort the additions, and merge them back > in. Radix sort ignores pre-existing order. So either a lot of > comparitive profiling would be needed for auto-selection of sort > method, or it should be user selectable. > I've tested exactly that scenario. For already-ordered lists, radix > sort and timsort tie. Tim tested about 7 list structure scenarios with a range of lengths. If you post a patch, I would request that you do the same. Have you run a patched version against test_sort.py? I believe it mostly tests lists of small ints, so radix methods would mostly be switched in. If it were added and the switching were internal, new test cases would be needed to test test timsort. >> Does your radix sort meet the stability guarantee of list.sort? > Yes. Great. There is, of course, a test for that in the suite. -- Terry Jan Reedy From wherespythonmonks at gmail.com Thu Jul 22 18:34:11 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 22 Jul 2010 18:34:11 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4C3A0F79.8070502@ixokai.io> References: <4C3A0F79.8070502@ixokai.io> Message-ID: Okay -- so I promised that I would try the namespace mangling approach, and here's what I have come up with: Approach #1: Pass in the variables to be swapped as strings. (boring) >>> import sys >>> def swap(n1,n2): ... try: ... raise RuntimeException() ... except: ... e,b,t = sys.exc_info() ... ldict = t.tb_frame.f_back.f_locals ... t = ldict[n1]; ... ldict[n1] = ldict[n2] ... ldict[n2] = t ... >>> x = 'A' >>> y = 'B' >>> id(x) 47946650437696 >>> id(y) 47946649710192 >>> swap('x','y') >>> print id(x) 47946649710192 >>> print id(y) 47946650437696 >>> print x,y B A Approach #2: Allow the user to pass in arbitrary objects, takes the id, infer what the variable in by hashing all possible objects, and then apply the swap operation above. >>> def swap2(o1,o2): ... try: ... raise RuntimeException() ... except: ... e,b,t = sys.exc_info() ... ldict = t.tb_frame.f_back.f_locals ... iddict = dict( (id(v), k ) for k,v in ldict.items() ) ... # print id(o1), id(o2) ... n1 = iddict[id(o1)] ... n2 = iddict[id(o2)] ... t = ldict[n1]; ... ldict[n1] = ldict[n2] ... ldict[n2] = t ... >>> print x,y B A >>> swap2(x,y) >>> print x,y A B >>> Now, I want to make the above codes more "Pythonic" -- is there a way to: 1. Get the function's arguments from the perspective of the caller? def f(x): print "caller's view of x = %s" % callersview(x) Then, f(1+2+3) would yield: caller's view of x = 1 + 2 + 3 2. Is there a better way to loopup by id? I'm not very familiar with sys.exc_info, but creating the id->name hash each time seems like overkill. 3. Is there a reference on all the special variables, like __foo__? 4. Is there any work on deparsing (like Perl's deparse) lambda functions to inline algebra and get a performance gain? Thanks again for your input, W ( from Perl-hacker to Python Programmer ) On Sun, Jul 11, 2010 at 2:37 PM, Stephen Hansen wrote: > On 7/11/10 10:48 AM, wheres pythonmonks wrote: >> I'm an old Perl-hacker, and am trying to Dive in Python. ?I have some >> easy issues (Python 2.6) >> which probably can be answered in two seconds: >> >> 1. ?Why is it that I cannot use print in booleans?? ?e.g.: >>>>> True and print "It is true!" > > Because print is a statement. Statements have to start lines. If you > want to do this, use a function-- in Python 2.6 either via "from > __future__ import print_function" or writing your own, even if its just > a very thing wrapper around the print statement. > >> 2. ?How can I write a function, "def swap(x,y):..." so that "x = 3; y >> = 7; swap(x,y);" given x=7,y=3?? >> (I want to use Perl's Ref "\" operator, or C's &). >> (And if I cannot do this [other than creating an Int class], is this >> behavior limited to strings, >> ?tuples, and numbers) > > You can't do that*. Its not limited to any certain type of objects. You > can't manipulate calling scopes: if you really want to do that sort of > explicit namespace mangling, use dictionaries (or objects, really) as > the namespace to mangle and pass them around. > >> 3. ?Why might one want to store "strings" as "objects" in numpy >> arrays? ?(Maybe they wouldn't)? > > I don't use numpy. No idea. > >> 4. ?Is there a way for me to make some function-definitions explicitly >> module-local? > > In what sense? If you prepend them with an underscore, the function > won't be imported with "from x import *". You can also explicitly > control what is imported in that way with a module-level __all__ attribute. > > Now that won't stop someone from doing "import x" and > "x._your_private_function" but Python doesn't believe in enforicng > restrictions. > >> (Actually related to Q3 below: Is there a way to create an anonymous scope?) > > No. You can create a limited anonymous function with lambda, but note it > takes only an expression-- no statements in it. > >> 5. Is there a way for me to introduce a indention-scoped variables in python? >> See for example: http://evanjones.ca/python-pitfall-scope.html > > No. Python only has three scopes historically; local, global, and > builtin. Then post-2.2(ish, I forget) limited nested scoping -- but only > with nested functions, and you can't (until Python 3) re-bind variables > in outer scopes (though you can modify them if they are mutable objects). > > Python's scoping is very basic (we generally think this is a good thing; > others are never happy with it) and is not fully lexical scoped. > >> 6. ?Is there a Python Checker that enforces Strunk and White and is >> bad English grammar anti-python? ?(Only half joking) >> http://www.python.org/dev/peps/pep-0008/ > > Check out pylint and/or pychecker, which do various style-based > checking. If you're asking for something else, I can't pierce your > sarcasm to figure out what. > > -- > > ? Stephen Hansen > ? ... Also: Ixokai > ? ... Mail: me+list/python (AT) ixokai (DOT) io > ? ... Blog: http://meh.ixokai.io/ > > * Yes, I know its actually possible, to manipulate outer/calling scopes > with frame hacking. This is dangerous / bad / an implementation detail > that one should not rely on or use, generally speaking. If you need to > do this you're writing Java or Perl or C in Python, instead of writing > Python in Python, so are probably doing all kinds of things that are > slow / bad / dangerous / just not taking advantage of Python's strengths. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From breamoreboy at yahoo.co.uk Thu Jul 22 19:02:52 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 23 Jul 2010 00:02:52 +0100 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 22/07/2010 23:25, Terry Reedy wrote: > On 7/21/2010 6:56 PM, Daniel Stutzbach wrote: >> On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy > > wrote: >> >> These tests use random numbers with a constant, relatively high >> density of 25%, which is favorable to radix sort. What if you do the >> same test with a constant range of, say, 1000000000 (1 billion) or >> even a trillion or quadrillion. Or how about sorting a thousand >> 128bit ip6 addresses? Which wins for that? > >> blist switches to radix sort only if the keys contain only floats or >> only integers that fit into a C long. If the integers get too big, it >> reverts to timsort. >> >> When using a sort key, the decorate-sort-undecorate pattern requires >> touching every object once before the sort. The check for a consistent >> type is done inexpensively during the decorate phase. > > And it is pretty cheap even when there is no decorate phase. > >> Here's an example result with a density of only 1%, where the radix sort >> is around 4 times as fast: >> >> otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = >> [random.randrange(10000*100) for i in range(10000)]' 'y = list(x)' >> 'y.sort(key=float)' >> 100 loops, best of 3: 12.4 msec per loop >> >> otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s >> 'import random' -s 'x = [random.randrange(10000*100) for i in >> range(10000)]' 'y = blist(x)' 'y.sort(key=float)' >> 100 loops, best of 3: 3.4 msec per loop > >> And a density of 0.01%: >> >> otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x = >> [random.randrange(10000*10000) for i in range(10000)]' 'y = list(x)' >> 'y.sort(key=float)' >> 100 loops, best of 3: 12 msec per loop >> >> otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s >> 'import random' -s 'x = [random.randrange(10000*10000) for i in >> range(10000)]' 'y = blist(x)' 'y.sort(key=float)' >> 100 loops, best of 3: 3.52 msec per loop > > Looks good so far. I would like to see that repeated all the way down to > range(10) to make sure people doing millions of small sorts were not > getting screwed. > >> list.sort is (near) linear for lists that are mostly ordered. I >> think Tim's writeup about this in in the source. For instance, if >> one extends a sorted with 1% random additions and resorts, list.sort >> will skip the sorted part, sort the additions, and merge them back >> in. Radix sort ignores pre-existing order. So either a lot of >> comparitive profiling would be needed for auto-selection of sort >> method, or it should be user selectable. >> I've tested exactly that scenario. For already-ordered lists, radix >> sort and timsort tie. > > Tim tested about 7 list structure scenarios with a range of lengths. If > you post a patch, I would request that you do the same. > > Have you run a patched version against test_sort.py? I believe it mostly > tests lists of small ints, so radix methods would mostly be switched in. > > If it were added and the switching were internal, new test cases would > be needed to test test timsort. > >>> Does your radix sort meet the stability guarantee of list.sort? >> Yes. > > Great. There is, of course, a test for that in the suite. > Can I please book front row tickets for the shoot out between the reigning heavyweight champ Timbot and the challenger, the up and coming Danbot? :) Kindest regards. Mark Lawrence. From nyamatongwe+thunder at gmail.com Thu Jul 22 19:19:37 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 23 Jul 2010 09:19:37 +1000 Subject: Sun Grid Engine / NFS and Python shell execution question In-Reply-To: References: Message-ID: <7m42o.1390$FH2.1317@viwinnwfe02.internal.bigpond.com> J.B. Brown: > I believe the source of this problem is that os.popen() or os.system() > calls spawn subshells which then reference my shell resource files > (.zshrc, .cshrc, .bashrc, etc.). > But I don't see an alternative to os.popen{234} or os.system(). > os.exec*() cannot solve my problem, because it transfers execution to > that program and stops executing the script which called os.exec*(). Call fork then call exec from the new process. Search the web for "fork exec" to find examples in C. Neil From daniel at stutzbachenterprises.com Thu Jul 22 19:22:14 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 22 Jul 2010 18:22:14 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Thu, Jul 22, 2010 at 5:25 PM, Terry Reedy wrote: > Looks good so far. I would like to see that repeated all the way down to > range(10) to make sure people doing millions of small sorts were not getting > screwed. > I only use the radix sort for n > 40. :-) > Have you run a patched version against test_sort.py? I believe it mostly > tests lists of small ints, so radix methods would mostly be switched in. > For testing purposes, I maintain a private fork of Python where I've replaced the built-in list with blist. I then run Python's test suite as a way of testing blist. So, yes, all of the tests have been run. :-) However, since I only use radix for n > 40, many of the tests have not actually tested the radix sort. > If it were added and the switching were internal, new test cases would be > needed to test test timsort. That's a good point. It's tempting to add an undocumented parameter to blist.sort that selects the sorting algorithm to use, to make it make it easier to test multiple algorithms. There are probably several different ways to achieve a similar effect. Do you mind if we table that discussion until I actually have a patch? -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From guandalino at gmail.com Thu Jul 22 19:22:48 2010 From: guandalino at gmail.com (guandalino) Date: Thu, 22 Jul 2010 16:22:48 -0700 (PDT) Subject: urllib2 test fails (2.7, linux) References: Message-ID: On 22 Lug, 01:13, Terry Reedy wrote: [cut] > > Any hint? > > Remove the offending fake url. This makes tests to pass, but I have concrete reasons to think that urllib2 is really broken on my system. Btw, a(nother) weird thing is that I wrote a standalone test file based on test_urllib2.py and the test that there failed now passes. import unittest, urllib2 class Test(unittest.TestCase): def runTest(self): h = urllib2.FileHandler() urls = ( "file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/ test/%40test_29416_tmp", "file:///file_does_not_exist.txt", "file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/ python2.7/test/@test_29416_tmp", "file://somerandomhost.ontheinternet.com/home/home/redt/ sandbox/2.7/lib/python2.7/test/@test_29416_tmp",) for url in urls: self.assertRaises(urllib2.URLError, h.file_open, urllib2.Request(url)) print "PASSED" PASSED PASSED PASSED PASSED <-- this doesn't pass in test_urllib2 because gaierror is raised instead of URLError. I'm going to file an issue on python's bug tracker. Just the last thing to be sure it's not my fault... My system already had Python installed system wide (2.5.2) and I did the new installation in my home directory. To "activate" the new interpreter I added /home/redt/ sandbox/2.7/bin as first element in PATH. PYTHONPATH is empty. python - V gives 2.7. Is it OK or new and old pythons step on each other's foot? Thanks again, best regards. From tjreedy at udel.edu Thu Jul 22 19:52:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Jul 2010 19:52:10 -0400 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On 7/22/2010 7:22 PM, Daniel Stutzbach wrote: > On Thu, Jul 22, 2010 at 5:25 PM, Terry Reedy That's a good point. It's tempting to add an undocumented parameter to > blist.sort that selects the sorting algorithm to use, to make it make it > easier to test multiple algorithms. There are probably several > different ways to achieve a similar effect. Do you mind if we table > that discussion until I actually have a patch? Definitely. That will not be my decision. Since you seem serious about this, I decided to give you a preview of the questions to expect, and suggest some to answer in your initial filing. Another sort of issue will be code maintainability. Two algorithms is potentially more problems than one. To me, that partly depends on how well factored the current code is. It would be best is rsort were a switch replacement for timsort after all preparations (such as decorate) were done. I will leave that for you to address when you file. And that is about all I can think of. -- Terry Jan Reedy From me+list/python at ixokai.io Thu Jul 22 19:59:02 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 22 Jul 2010 16:59:02 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4C48DB46.2070000@ixokai.io> On 7/22/10 3:34 PM, wheres pythonmonks wrote: > Now, I want to make the above codes more "Pythonic" -- is there a way to: > > 1. Get the function's arguments from the perspective of the caller? > > def f(x): > print "caller's view of x = %s" % callersview(x) > > Then, f(1+2+3) would yield: > caller's view of x = 1 + 2 + 3 No. You can use frame hacking to dig up the locals of the calling frame as you did (such a horrible abuse of the poor language :)), there's no way to determine with any accuracy what exactly they decided to pass into you to get 'x'. I.e., I'm pretty sure its impossible to tell the difference between: x = 3 f(x) And: x = 3 f(3) From within f()'s perspective. This kind of thing gets asked a lot when people don't understand Python's name binding and object passing characteristics and come from other languages. It especially surprises people sometimes to learn that: x = 30000 f(x) f(30000) That in this case, 'f' will receive two completely different objects-- different id's and all. And yet: x = 3 f(x) f(3) In this case, each call will receive the exact same object. > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. Do you mean given a certain 'id', look up what object it is? No there's no way to do that. An id in Python is just informational, and an implementation detail. The language doesn't provide any meaningful tools you can use with them. I mean there's gc.get_objects(), but that doesn't return everything. > 3. Is there a reference on all the special variables, like __foo__? http://docs.python.org/reference/datamodel.html > 4. Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? There's nothing like that which I'm aware of. You can use projects like numpy or cython to get performance gain in important areas. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From pavlovevidence at gmail.com Thu Jul 22 20:12:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jul 2010 17:12:59 -0700 (PDT) Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> Message-ID: <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> On Jul 22, 3:34?pm, wheres pythonmonks wrote: > Okay -- so I promised that I would try the namespace mangling > approach, and here's what I have come up with: > > Approach #1: ?Pass in the variables to be swapped as strings. ?(boring) > > >>> import sys > >>> def swap(n1,n2): > > ... ?try: > ... ? raise RuntimeException() > ... ?except: > ... ? e,b,t = sys.exc_info() > ... ?ldict = t.tb_frame.f_back.f_locals > ... ?t = ldict[n1]; > ... ?ldict[n1] = ldict[n2] > ... ?ldict[n2] = t > ...>>> x = 'A' > >>> y = 'B' > >>> id(x) > 47946650437696 > >>> id(y) > 47946649710192 > >>> swap('x','y') > >>> print id(x) > 47946649710192 > >>> print id(y) > 47946650437696 > >>> print x,y > > B A Have you tried calling this swap inside a function? I bet you haven't. def test(): x = "A" y = "B" swap("x","y") print x,y > Approach #2: ?Allow the user to pass in arbitrary objects, takes the > id, infer what the variable in by hashing all possible objects, and > then apply the swap operation above. > > >>> def swap2(o1,o2): > > ... ?try: > ... ? raise RuntimeException() > ... ?except: > ... ? e,b,t = sys.exc_info() > ... ?ldict = t.tb_frame.f_back.f_locals > ... ?iddict = dict( (id(v), k ) for k,v in ldict.items() ) > ... ?# print id(o1), id(o2) > ... ?n1 = iddict[id(o1)] > ... ?n2 = iddict[id(o2)] > ... ?t = ldict[n1]; > ... ?ldict[n1] = ldict[n2] > ... ?ldict[n2] = t > ... > > >>> print x,y > B A > >>> swap2(x,y) > >>> print x,y > A B Same question. > Now, I want to make the above codes more "Pythonic" It's simply not possible (let alone Pythonic), in general, to rebind variables in the namespace of the caller. You were able to do it for a very limited circumstance, when the calling namespace was module-level. It doesn't work when the calling namespace is a function. This is true in Python 2 and 3. IMO, even if it could work, the very act of rebinding variables in another namespace is unPythonic. About the only time I've resorted to it is some metaprogramming tasks, and even then I give the functions that do it very explicit names, and I still feel dirty. > -- is there a way to: > > 1. ?Get the function's arguments from the perspective of the caller? > > def f(x): > ? print "caller's view of x = %s" % callersview(x) > > Then, f(1+2+3) would yield: > caller's view of x = 1 + 2 + 3 Nope, other than inspecting the caller's frame. > 2. ?Is there a better way to loopup by id? ?I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. Looking up by id is a bad idea in general. Objects associated with an id can be destroyed, and id be reused. So if you're storing an id, by the time you get to it it could be a different object, or an object that no longer exists. > 3. ?Is there a reference on all the special variables, like __foo__? Python Language Reference > 4. ?Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? psyco (q.g.) might help, not sure if it'll help much for lambdas, though. > Thanks again for your input, > > W > > ( from Perl-hacker to Python Programmer ) No offense, but you seem like you're still tying to be a hacker. If that's what you want, fine, but generally speaking (and particularly for Python), you are going to have a better experience if you do it the language's way. And just to throw this out there, based on your questions I think it's possible that Ruby would fit your style better. (It lets you play fast and loose with namespaces and code blocks and such.) Carl Banks From fabiofz at gmail.com Thu Jul 22 20:47:51 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 22 Jul 2010 21:47:51 -0300 Subject: Pydev 1.6.0 Released In-Reply-To: References: Message-ID: > > The supposed feature to start a console in which the contents of the > current editor window are automatically "exec"ed /available still > doesn't work for me. > > I'm talking about this: > http://www.pydev.org/manual_adv_interactive_console.html > > Pressing Ctrl-Alt-Enter, a interactive console opens but my class > defined in the editor window is not available. The first time Ctrl-Alt-Enter is used, it should open the console, if you want to make the execfile, you have to do Ctrl-Alt-Enter with a console already open. Cheers, Fabio From domingo.aguilera at gmail.com Thu Jul 22 20:57:32 2010 From: domingo.aguilera at gmail.com (batok) Date: Thu, 22 Jul 2010 17:57:32 -0700 (PDT) Subject: Brief guide to using virtualenv and wxpython Message-ID: This Brief guide to using virtualenv with wxpython , written with sphinx may be helpful for you. If your dev platform is mac os x. The documented process is about python 2.7 , wxpython 2.8.11 and virtualenv. http://bit.ly/bwdWCR From navkirats at gmail.com Thu Jul 22 21:30:11 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Fri, 23 Jul 2010 07:00:11 +0530 Subject: Sending HTTP headers via plain sockets Message-ID: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> Hi Guys, I am very new to python and I am trying to send HTTP headers for redirection using sockets in python 3, but in vain. If I use the meta tag REFRESH method the redirection works. Please advise what I am missing, below is the snippet of my code: hostsock is the socket object print('Redirecting client') hostsock.send("""HTTP/1.1 301 Moved Permanently Location: http://www.example.com"") I have been up all night trying to figure this one out : ( I would be grateful if someone could point me in the right direction Regards, Nav From navkirats at gmail.com Thu Jul 22 22:26:49 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Fri, 23 Jul 2010 07:56:49 +0530 Subject: Sending HTTP headers via plain sockets In-Reply-To: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> References: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> Message-ID: <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> Aaah figured it out...!! It was elementary, I was lacking the carriage return and line feed characters at the end of the status and header line. Here is how I solved it: hostsock.send(b'HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.example.com\r\n' ) Regards, Nav On 23-Jul-2010, at 7:00 AM, Navkirat Singh wrote: > Hi Guys, > > I am very new to python and I am trying to send HTTP headers for > redirection using sockets in python 3, but in vain. If I use the > meta tag REFRESH method the redirection works. Please advise what I > am missing, below is the snippet of my code: > > hostsock is the socket object > > > print('Redirecting client') > hostsock.send("""HTTP/1.1 301 Moved Permanently > Location: http://www.example.com"") > > > I have been up all night trying to figure this one out : ( I would > be grateful if someone could point me in the right direction > > Regards, > Nav From python at mrabarnett.plus.com Thu Jul 22 22:33:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Jul 2010 03:33:34 +0100 Subject: Sending HTTP headers via plain sockets In-Reply-To: <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> References: <896A3EC5-09ED-4617-B13B-AB024C1E00F8@gmail.com> <77161541-7B73-46CC-A13B-9CE55B0034F6@gmail.com> Message-ID: <4C48FF7E.3080307@mrabarnett.plus.com> Navkirat Singh wrote: > Aaah figured it out...!! > > It was elementary, I was lacking the carriage return and line feed > characters at the end of the status and header line. Here is how I > solved it: > > hostsock.send(b'HTTP/1.1 301 Moved Permanently\r\nLocation: > http://www.example.com\r\n') > > Regards, > Nav > You might want to note that the .send method doesn't guarantee to send all the bytes, so you might want to use .sendall instead (it's in the documentation). > On 23-Jul-2010, at 7:00 AM, Navkirat Singh wrote: > >> Hi Guys, >> >> I am very new to python and I am trying to send HTTP headers for >> redirection using sockets in python 3, but in vain. If I use the meta >> tag REFRESH method the redirection works. Please advise what I am >> missing, below is the snippet of my code: >> >> hostsock is the socket object >> >> >> print('Redirecting client') >> hostsock.send("""HTTP/1.1 301 Moved Permanently >> Location: http://www.example.com"") >> >> >> I have been up all night trying to figure this one out : ( I would be >> grateful if someone could point me in the right direction >> >> Regards, >> Nav > From wherespythonmonks at gmail.com Thu Jul 22 22:47:11 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 22 Jul 2010 22:47:11 -0400 Subject: Easy questions from a python beginner In-Reply-To: <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: Thanks for pointing out that swap (and my swap2) don't work everywhere -- is there a way to get it to work inside functions? "No offense, but you seem like you're still tying to be a hacker. If that's what you want, fine, but generally speaking (and particularly for Python), you are going to have a better experience if you do it the language's way." None taken, but I always think that it is the language's job to express my thoughts... I don't like to think that my thoughts are somehow constrained by the language. The truth is that I don't intend to use these approaches in anything serious. However, I've been known to do some metaprogramming from time to time. In a recent application, I pass in a list of callables (lambdas) to be evaluated repeatedly. Clearly, a superior solution is to pass a single lambda that returns a list. [Less function call dispatches] However, it might be more efficient to avoid the function call overhead completely and pass-in a string which is substituted into a string code block, compiled, and executed. W On Thu, Jul 22, 2010 at 8:12 PM, Carl Banks wrote: > On Jul 22, 3:34?pm, wheres pythonmonks > wrote: >> Okay -- so I promised that I would try the namespace mangling >> approach, and here's what I have come up with: >> >> Approach #1: ?Pass in the variables to be swapped as strings. ?(boring) >> >> >>> import sys >> >>> def swap(n1,n2): >> >> ... ?try: >> ... ? raise RuntimeException() >> ... ?except: >> ... ? e,b,t = sys.exc_info() >> ... ?ldict = t.tb_frame.f_back.f_locals >> ... ?t = ldict[n1]; >> ... ?ldict[n1] = ldict[n2] >> ... ?ldict[n2] = t >> ...>>> x = 'A' >> >>> y = 'B' >> >>> id(x) >> 47946650437696 >> >>> id(y) >> 47946649710192 >> >>> swap('x','y') >> >>> print id(x) >> 47946649710192 >> >>> print id(y) >> 47946650437696 >> >>> print x,y >> >> B A > > Have you tried calling this swap inside a function? ?I bet you > haven't. > > def test(): > ? ?x = "A" > ? ?y = "B" > ? ?swap("x","y") > ? ?print x,y > > >> Approach #2: ?Allow the user to pass in arbitrary objects, takes the >> id, infer what the variable in by hashing all possible objects, and >> then apply the swap operation above. >> >> >>> def swap2(o1,o2): >> >> ... ?try: >> ... ? raise RuntimeException() >> ... ?except: >> ... ? e,b,t = sys.exc_info() >> ... ?ldict = t.tb_frame.f_back.f_locals >> ... ?iddict = dict( (id(v), k ) for k,v in ldict.items() ) >> ... ?# print id(o1), id(o2) >> ... ?n1 = iddict[id(o1)] >> ... ?n2 = iddict[id(o2)] >> ... ?t = ldict[n1]; >> ... ?ldict[n1] = ldict[n2] >> ... ?ldict[n2] = t >> ... >> >> >>> print x,y >> B A >> >>> swap2(x,y) >> >>> print x,y >> A B > > Same question. > > >> Now, I want to make the above codes more "Pythonic" > > It's simply not possible (let alone Pythonic), in general, to rebind > variables in the namespace of the caller. > > You were able to do it for a very limited circumstance, when the > calling namespace was module-level. ?It doesn't work when the calling > namespace is a function. ?This is true in Python 2 and 3. > > IMO, even if it could work, the very act of rebinding variables in > another namespace is unPythonic. ?About the only time I've resorted to > it is some metaprogramming tasks, and even then I give the functions > that do it very explicit names, and I still feel dirty. > > >> -- is there a way to: >> >> 1. ?Get the function's arguments from the perspective of the caller? >> >> def f(x): >> ? print "caller's view of x = %s" % callersview(x) >> >> Then, f(1+2+3) would yield: >> caller's view of x = 1 + 2 + 3 > > Nope, other than inspecting the caller's frame. > >> 2. ?Is there a better way to loopup by id? ?I'm not very familiar with >> sys.exc_info, but creating the id->name hash each time seems like >> overkill. > > Looking up by id is a bad idea in general. ?Objects associated with an > id can be destroyed, and id be reused. ?So if you're storing an id, by > the time you get to it it could be a different object, or an object > that no longer exists. > > >> 3. ?Is there a reference on all the special variables, like __foo__? > > Python Language Reference > > >> 4. ?Is there any work on deparsing (like Perl's deparse) lambda >> functions to inline algebra and get a performance gain? > > psyco (q.g.) might help, not sure if it'll help much for lambdas, > though. > >> Thanks again for your input, >> >> W >> >> ( from Perl-hacker to Python Programmer ) > > No offense, but you seem like you're still tying to be a hacker. ?If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way. > > And just to throw this out there, based on your questions I think it's > possible that Ruby would fit your style better. ?(It lets you play > fast and loose with namespaces and code blocks and such.) > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > From hellomarch at gmail.com Thu Jul 22 23:18:43 2010 From: hellomarch at gmail.com (march) Date: Thu, 22 Jul 2010 20:18:43 -0700 (PDT) Subject: Where is the man page of python library Message-ID: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> Hi, guys. As a regular user of python, I am often annoyed by the fact that the official python docementation is too short and too simple to satisfy my requirement. While working with socket, I want to know every detail about every API. I can easilly achieve that by reading man page if the language is C. But It seems that the Python story is different. For the interface recv(), all I got is only three sentences. " Receive data from the socket. The return value is a string representing the data received. The maximum amount of data to be received at once is specified by bufsize. " http://docs.python.org/library/socket.html#socket.socket.recv What if the call fail? What if the peer close the socket? What is the difference between blocking and non-blocking socket? How could I get the errno or exception? All the answers are "No comment". I hate this documentation! guys, where could I turn to for help? Thanks in advance. From steve at REMOVE-THIS-cybersource.com.au Thu Jul 22 23:45:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 03:45:22 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4c491052$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 18:34:11 -0400, wheres pythonmonks wrote: > Okay -- so I promised that I would try the namespace mangling approach, > and here's what I have come up with: > > Approach #1: Pass in the variables to be swapped as strings. (boring) Boring and slow and stupid. It makes an interesting trick to prove it can (almost) be done, but for production use? No way. There is nothing that *needs* call-by-reference that can't be done just as effectively using a slightly different approach. This approach also has the fatal flaw that not all objects have names, or have only one name. In Python, objects are often anonymous, and the standard Python idiom for swapping works fine for them: a = [1, 2, 3, "d", 5] b = ["a", "b", "c", 4, "e"] a[3], b[3] = b[3], a[3] I expect your hack to choke and die if you try swapping anonymous objects. [snip successful test of swapping using named globals] As Carl already pointed out, this doesn't work outside of the global scope. This demonstrates an interesting lesson re testing. It's not enough to test these hacks with names in the global scope. You also need to test them with names in a local and nested scope, and in classes. [...] > Now, I want to make the above codes more "Pythonic" The way to make them more Pythonic is to avoid them like the plague. One of the differences in philosophy between Perl and Python is that Python doesn't approve of doing things just because you can. There is very little interest in or respect given to hacking Python. We're programmers, not hackers, and we look for the most simple way to do things, not the gnarliest or trickiest or least obvious way. (Any yet, as a general rule, neither does Python particular get in your way. We have a saying: we're all adults here, if you want to shoot yourself in the foot, go right ahead.) Occasionally, *very* occasionally, that makes it hard to do something that would be simple in another language. But much rarer than you might think, and a lot of popular programming idioms are work-arounds that are simply not needed in Python. E.g. call-by-reference itself was a work- around to prevent unnecessary copying of large data structures like arrays in languages like Algol and Pascal (or so I understand). When Java guys come here and start asking how to implement design patterns in Python, 9 times out of 10 the answer is "you don't need it" rather than "you can't do it". It's not quite true that we consider "hack" to be a pejorative, we're certainly true of the positive uses of the word. But as a general rule the Python community looks rather askance at anything that might be described as a hack. We're far more likely to describe something as a dirty hack than a cool, nifty or amazing hack. It's not true, as some folks say, that there is "only one way to do it" in Python. But the Python ideal is for there to be "one obvious way to do it". If there's an obvious way, why would you look for an obscure, tricky hack? You better have a good reason for not using the obvious way, because writing the code is the *smallest* part of the job. You need to test it, and debug it, and maintain it, and they're all much, much harder. > is there a way to: > > 1. Get the function's arguments from the perspective of the caller? I don't understand the question. If the caller passes arg = [1,2,3], then both the caller and the called function agree that the argument is the list [1,2,3]. Both caller and callee see the same list. It would be a pretty strange programming language where the called function saw something different from what the caller passed... > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. No. > 3. Is there a reference on all the special variables, like __foo__? If you're talking about "magic methods" and special attributes, like obj.__len__, then you should read this: http://docs.python.org/reference/datamodel.html This may also be helpful: http://www.ironpythoninaction.com/magic-methods.html If you're talking about special globals like __name__, I don't think there are any others. __name__ is (confusingly) documented here: http://docs.python.org/library/__main__.html > 4. Is there any work on deparsing (like Perl's deparse) lambda > functions to inline algebra and get a performance gain? No. How would you do that? If I have something like this: def my_func(arg): return some_class(1, 2, 3, callback=lambda x: arg.method(x)) how would you inline that? *Where* would you inline that? Perhaps you're thinking that lambdas are commonly used like this: def my_func(args): f = lambda a, b, c: 3*a + 4*b -2*c results = [] for x in args: results.append(f(2, x, 3)) results.append(f(x, x**2, x**3) return results then, yes, that lambda could be inlined. But that's a rare and uncommon use for lambdas, and some would say unpythonic. Even if you could inline it, CPython isn't big on micro-optimizations. It's generally considered that the extra complexity and risk of bugs isn't worth the tiny performance gain. Simplicity itself is a virtue, and many optimizations tend to be anything but simple, if not dirty hacks. -- Steven From f2h2d2 at gmail.com Thu Jul 22 23:51:43 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Thu, 22 Jul 2010 20:51:43 -0700 (PDT) Subject: TOLERANCE IN ISLAM Message-ID: <2839481a-d0f3-4433-b95e-070840d6275a@t2g2000yqe.googlegroups.com> TOLERANCE IN ISLAM http://www.islamhouse.com/s/9661 Tolerance In Islam TOLERANCE IN ISLAM In Spain under the Umayyads and in Baghdad under the Abbasid Khalifas, Christians and Jews, equally with Muslims, were admitted to the Schools and universities - not only that, but were boarded and lodged in hostels at the cost of the state. When the Moors were driven out of Spain, the Christian conquerors held a terrific persecution of the Jews. Those who were fortunate enough to escape fled, some of them to Morocco and many hundreds to the Turkish empire, where their descendants still live in separate communities, and still speak among themselves an antiquated form of Spanish. The Muslim empire was a refuge for all those who fled from persecution by the Inquisition. The Western Christians, till the arrival of the Encyclopaedists in the eighteenth century, did not know and did not care to know, what the Muslim believed, nor did the Western Christian seek to know the views of Eastern Christians with regard to them. The Christian Church was already split in two, and in the end, it came to such a pass that the Eastern Christians, as Gibbon shows, preferred Muslim rule, which allowed them to practice their own form of religion and adhere to their peculiar dogmas, to the rule of fellow Christians who would have made them Roman Catholics or wiped them out. For the Muslims, Judaism, Christianity and Islam are but three forms of one religion, which, in its original purity, was the religion of Abraham: Al-Islam, that perfect Self-Surrender to the Will of God, which is the basis of Theocracy. The Jews, in their religion, after Moses, limited God's mercy to their chosen nation and thought of His kingdom as the dominion of their race. Even Christ himself, as several of his sayings show, declared that he was sent only to the lost sheep of the House of Israel and seemed to regard his mission as to the Hebrews only; and it was only after a special vision vouchsafed to St. Peter that his followers in after days considered themselves authorized to preach the Gospel to the Gentiles. The Christians limited God?s mercy to those who believed certain dogmas. Every one who failed to hold the dogmas was an outcast or a miscreant, to be persecuted for his or her soul?s good. In Islam only is manifest the real nature of the Kingdom of God. The two verses (2:255-256) of the Qur?an are supplementary. Where there is that realization of the majesty and dominion of Allah (SWT), there is no compulsion in religion. Men choose their path - allegiance or opposition - and it is sufficient punishment for those who oppose that they draw further and further away from the light of truth. In Egypt the Copts were on terms of closest friendship with the Muslims in the first centuries of the Muslim conquest, and they are on terms at closest friendship with the Muslims at the present day. In Syria the various Christian communities lived on terms of closest friendship with the Muslims in the first centuries of the Muslim conquest, and they are on terms of closest friendship with the Muslims at the present day, openly preferring Muslim domination to a foreign yoke.... >From the expulsion of the Moriscos dates the degradation and decline of Spain. San Fernando was really wiser and more patriotic in his tolerance to conquered Seville, Murcia and Toledo than was the later king who, under the guise of Holy warfare, captured Grenada and let the Inquisition work its will upon the Muslims and the Jews. And the modern Balkan States and Greece are born under a curse. It may even prove that the degradation and decline of European civilization will be dated from the day when so-called civilized statesmen agreed to the inhuman policy of Czarist Russia and gave their sanction to the crude fanaticism of the Russian Church. There is no doubt but that, in the eyes of history, religious toleration is the highest evidence of culture in a people. Let no Muslim, when looking on the ruin of the Muslim realm which was compassed through the agency of those very peoples whom the Muslims had tolerated and protected through the centuries when Western Europe thought it a religious duty to exterminate or forcibly convert all peoples of another faith than theirs - let no Muslim, seeing this, imagine that toleration is a weakness in Islam. It is the greatest strength of Islam because it is the attitude of truth. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 00:07:20 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 04:07:20 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> Message-ID: <4c491577$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > Hi, guys. > > As a regular user of python, I am often annoyed by the fact that the > official python docementation is too short and too simple to satisfy my > requirement. Python is a volunteer effort. If the docs don't suit your requirements, we're grateful for patches. > While working with socket, I want to know every detail about every API. > I can easilly achieve that by reading man page if the language is C. But > It seems that the Python story is different. Python is open source. Where the documentation is silent, the ultimate authority is the source code. Particularly if the code is a thin wrapper around the C library, which I expect (but don't know for sure) the socket code will be. > For the interface recv(), all I got is only three sentences. " > Receive data from the socket. The return value is a string representing > the data received. The maximum amount of data to be received at once is > specified by bufsize. " > http://docs.python.org/library/socket.html#socket.socket.recv > > What if the call fail? You will get an exception, just like the page says: All errors raise exceptions. The normal exceptions for invalid argument types and out-of-memory conditions can be raised; errors related to socket or address semantics raise the error socket.error. > What if the peer close the socket? You will get an exception, just like the Fine Manual says. > What is the > difference between blocking and non-blocking socket? Python isn't a tutor for basic programming concepts like sockets. That's what Google is for :) But having said that, the documentation does explain the difference: In non-blocking mode, if a recv() call doesn?t find any data, or if a send() call can?t immediately dispose of the data, a error exception is raised; in blocking mode, the calls block until they can proceed. http://docs.python.org/library/socket.html#socket.socket.setblocking > How could I get the errno or exception? You get the exception the same way you get *every* exception: by catching it with a try...except block. If you don't know that, you need to learn the basics and not blame the documentation. Untested, but this probably will work: try: something_involving_sockets() except socket.error, e: if len(e.args) == 1: print "Error message is:", e.args[0] else: print "errno =", e.args[0] print "Error message is:", e.args[1] > All the answers are "No comment". > > I hate this documentation! Don't blame the documentation for your failure to read it. It's true that it could be improved, but most of your questions were answered by the page you linked to. -- Steven From me+list/python at ixokai.io Fri Jul 23 00:23:05 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 22 Jul 2010 21:23:05 -0700 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4C491929.3020108@ixokai.io> On 7/22/10 7:47 PM, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? > > "No offense, but you seem like you're still tying to be a hacker. If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way." > > None taken, but I always think that it is the language's job to > express my thoughts... I don't like to think that my thoughts are > somehow constrained by the language. The thing is, every language is adept at expressing different kinds of abstractions. They have different goals and ways of encouraging certain types of solutions while discouraging (and many times simply not even trying to offer support for) others: you're going up against those 'discouraged' very, very hard-- and you're going to hit a wall :) The Python language does constrain your expressiveness in these sorts of areas, and there's no way around it. If that doesn't suit you-- you're free to use another language which works better to how your brain works. Ruby actually might be a very good suggestion. I don't mean this as a 'Deal with it or f- off, loser' statement. :) I mean that Python uses a very simple model in how it handles namespaces, calling and similar -- a lot of what seems completely natural to express in other languages is either slow, convoluted, complicated or flatly impossible here. On purpose. But, for those things that aren't expressed easily in Python, there's almost always a *different way* to express the actual need and intention-- in a way that is elegant and direct, in Python. You can't do it the other way "Pythonic", because "Pythonic" is to *not* do it that way. To not do things like try to treat variables as if they had box-like-behavior. > The truth is that I don't intend to use these approaches in anything > serious. However, I've been known to do some metaprogramming from > time to time. Depending on how you define "metaprogramming", Python is pretty notoriously ill-suited towards the task (more, its basically considered a feature it doesn't let you go there) -- or, it allows you to do vast amounts of stuff with its few dark magic hooks. I've never had a satisfying definition of metaprogramming that more then 50% of any group agree with, so I'm not sure which you're looking for. :) Python allows you to easily override nearly all operations and interactions between objects, construct classes, instances and such at runtime and modify them at any time. If metaprogramming is this to you, basically runtime tweaking and modification of classes types objects and the like, Python's good to go. But! What it doesn't let you do is get clever with syntax and write a sort of "simplified" or domain specific language to achieve certain sorts of repetitive tasks quickly. You always end up writing normal Python that looks like all other Python. You just might have a few more __methods__ and learn some dark magic like metaclasses and descriptors and decorators. (Not that -all- uses of such are dark magic, but when you start combining those your code can start to resemble a magic spell doing unholy things-- like my library with classes that have argument-based method overloading, so x.test("hi") and x.test("hi", 2) call two totally different functions. Not that I'll ever admit to having written the beast, nor that I actually did more then use it for pure proof of concept, and neither shall I willingly ever show anyone the monstrosity). > In a recent application, I pass in a list of callables (lambdas) to be > evaluated repeatedly. > Clearly, a superior solution is to pass a single lambda that returns a > list. [Less function call dispatches] > However, it might be more efficient to avoid the function call > overhead completely and pass-in a string which is substituted into a > string code block, compiled, and executed. This is the kind of "metaprogramming" where Python says nyet, that first kind I mentioned about being Notoriously Ill Suited. You can do things like compile code dynamically, generate up bytecode even, but it'll never be more efficient. Use a generator instead. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From hellomarch at gmail.com Fri Jul 23 01:24:39 2010 From: hellomarch at gmail.com (march) Date: Thu, 22 Jul 2010 22:24:39 -0700 (PDT) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Steven, thank you for your reply. It is true that I didn't read the document with enough carefulness. some of my questions are answered in the page I post the link of. Some are not. But the documentation is poor. You need to read throughout the entire page, hoping to find what you need about one single API, and you might fail. I don't think "Python is a volunteer effort" can justify the poor documentation. Linux, glibc are based on volunteer effort too, and they has good documentations. I am not blaming those volunteers who devote their precious time to this language. It will be good if the python communities get more people who like to write documentation. Anyway, thank you again. On Jul 23, 12:07?pm, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > > Hi, guys. > > > As a regular user of python, I am often annoyed by the fact that the > > official python docementation is too short and too simple to satisfy my > > requirement. > > Python is a volunteer effort. If the docs don't suit your requirements, > we're grateful for patches. > > > While working with socket, I want to know every detail about every API. > > I can easilly achieve that by reading man page if the language is C. But > > It seems that the Python story is different. > > Python is open source. Where the documentation is silent, the ultimate > authority is the source code. Particularly if the code is a thin wrapper > around the C library, which I expect (but don't know for sure) the socket > code will be. > > > For the interface recv(), all I got is only three sentences. " > > Receive data from the socket. The return value is a string representing > > the data received. The maximum amount of data to be received at once is > > specified by bufsize. " > >http://docs.python.org/library/socket.html#socket.socket.recv > > > What if the call fail? > > You will get an exception, just like the page says: > > ? ? All errors raise exceptions. The normal exceptions for > ? ? invalid argument types and out-of-memory conditions can be > ? ? raised; errors related to socket or address semantics raise > ? ? the error socket.error. > > > What if the peer close the socket? > > You will get an exception, just like the Fine Manual says. > > > What is the > > difference between blocking and non-blocking socket? > > Python isn't a tutor for basic programming concepts like sockets. That's > what Google is for :) > > But having said that, the documentation does explain the difference: > > ? ? In non-blocking mode, if a recv() call doesn?t find any data, > ? ? or if a send() call can?t immediately dispose of the data, > ? ? a error exception is raised; in blocking mode, the calls block > ? ? until they can proceed. > > http://docs.python.org/library/socket.html#socket.socket.setblocking > > > How could I get the errno or exception? > > You get the exception the same way you get *every* exception: by catching > it with a try...except block. If you don't know that, you need to learn > the basics and not blame the documentation. > > Untested, but this probably will work: > > try: > ? ? something_involving_sockets() > except socket.error, e: > ? ? if len(e.args) == 1: > ? ? ? ? print "Error message is:", e.args[0] > ? ? else: > ? ? ? ? print "errno =", e.args[0] > ? ? ? ? print "Error message is:", e.args[1] > > > All the answers are "No comment". > > > I hate this documentation! > > Don't blame the documentation for your failure to read it. It's true that > it could be improved, but most of your questions were answered by the > page you linked to. > > -- > Steven From timr at probo.com Fri Jul 23 01:44:55 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 22 Jul 2010 22:44:55 -0700 Subject: detect endianness of a binary with python References: <4C46EEB8.6070702@keymile.com> Message-ID: Holger brunck wrote: > >We are creating inside our buildsystem for an embedded system a cram filesystem >image. Later on inside our build process we have to check the endianness, >because it could be Little Endian or big endian (arm or ppc). > >The output of the "file" tool is for a little endian cramfs image: >: Linux Compressed ROM File System data, little endian size 1875968 >version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files > >It would be possible to execute >ret = os.system("file | grep "little endian") >and evaluate the return code. I wouldn't use os.system with grep and evaluate the return code. Instead I'd use subprocess.Popen("file ") and read the text output of the commdn directly. By parsing that string, I can extract all kinds of interesting information. That is an entirely Unix-like way of doing things. Don't reinvent the wheel when there's a tool that already does what you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From daniel at stutzbachenterprises.com Fri Jul 23 01:52:28 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 23 Jul 2010 00:52:28 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: <20100721173250.2d666f99@pitrou.net> Message-ID: On Thu, Jul 22, 2010 at 6:52 PM, Terry Reedy wrote: > Another sort of issue will be code maintainability. Two algorithms is > potentially more problems than one. To me, that partly depends on how well > factored the current code is. > Two algorithms is more code than one algorithm. No way around that. :-) Radix sort is a relatively simple sorting algorithm, so the extra complexity is not too bad. Once I have a patch ready, others can decide if the additional complexity is worth the performance boost. > It would be best is rsort were a switch replacement for timsort after all > preparations (such as decorate) were done. > Yes, that's pretty much what I have in mind. In pseudo-code: sort: decorate() if all_correct_type and n > 40: radix_sort() else timsort() undecorate() > And that is about all I can think of. Thank you for the thoughts. I appreciate them! -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Fri Jul 23 02:26:57 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 22 Jul 2010 23:26:57 -0700 (PDT) Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: On Jul 22, 7:47?pm, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? Impossible without hacking the interpreter. > "No offense, but you seem like you're still tying to be a hacker. ?If > that's what you want, fine, but generally speaking (and particularly > for Python), you are going to have a better experience if you do it > the language's way." > > None taken, but I always think that it is the language's job to > express my thoughts... I don't. In fact whenever I investigate new languages I make an effort to accommodate its thinking, I find I learn a lot more than I would by it into my preconceived thinking. YMMV. >?I don't like to think that my thoughts are > somehow constrained by the language. And yet your previous thoughts seem oddly constrained by Perl.... If you really want a language that can accommodate any thought you could possibly have, you should check out Lisp. (defmacro swap (a b) '(let ((t1 ,a) (t2 ,b)) (setq ,b t1) (setq ,a t2))) hygiene-left-as-an-exercise-ly yr's, Carl Banks From girish.cfc at gmail.com Fri Jul 23 02:54:23 2010 From: girish.cfc at gmail.com (Girish) Date: Thu, 22 Jul 2010 23:54:23 -0700 (PDT) Subject: Change Encoding in Py 2.5 Message-ID: Hello, Is ter a way to change default encoding in py 2.5 ? Thanks, Girish.. From stefan_ml at behnel.de Fri Jul 23 03:18:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jul 2010 09:18:47 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: References: Message-ID: Girish, 23.07.2010 08:54: > Is ter a way to change default encoding in py 2.5 ? Yes, but it's highly discouraged. If you tell us why you want to do it, we may be able to point to a better way to get what you want. Stefan From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 03:19:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 07:19:38 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: <4c494289$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 22:24:39 -0700, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. some > of my questions are answered in the page I post the link of. Some are > not. > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. Of course the documentation can be improved. Nobody thinks it is perfect. But the Python documentation is actually pretty good compared to a lot of things out there. Perhaps you're spoilt from reading first class documentation and haven't had to struggle with fifteenth class documentation. > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on volunteer effort too, and they > has good documentations. You missed my point. Python is a volunteer effort. If you think the documentation is poor, what are YOU doing to fix that, apart from complaining? We welcome patches to the documentation. If you don't know how to write a patch file, that's okay too. What suggestions do you have for fixing the docs? If people agree that your suggestions are good, *and* they care enough to make the effort, then somebody *might* generate a bug report for it, which eventually *might* lead to somebody producing a patch. But if you want to increase the chances, you need to be active and not just an armchair critic. Write the patch. If you can't write the patch, at least raise a bug report with a suggestion for fixing it. > I am not blaming those volunteers who devote their precious time to this > language. It will be good if the python communities get more people who > like to write documentation. Volunteers are welcome. The first step is to suggest an improvement to the docs, not just complain that they're not good enough. How would you fix the docs for socket.recv? -- Steven From breamoreboy at yahoo.co.uk Fri Jul 23 03:20:03 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 23 Jul 2010 08:20:03 +0100 Subject: Where is the man page of python library In-Reply-To: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: [Fix top posting] > > On Jul 23, 12:07 pm, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: >>> Hi, guys. >> >>> As a regular user of python, I am often annoyed by the fact that the >>> official python docementation is too short and too simple to satisfy my >>> requirement. >> >> Python is a volunteer effort. If the docs don't suit your requirements, >> we're grateful for patches. >> >>> While working with socket, I want to know every detail about every API. >>> I can easilly achieve that by reading man page if the language is C. But >>> It seems that the Python story is different. >> >> Python is open source. Where the documentation is silent, the ultimate >> authority is the source code. Particularly if the code is a thin wrapper >> around the C library, which I expect (but don't know for sure) the socket >> code will be. >> >>> For the interface recv(), all I got is only three sentences. " >>> Receive data from the socket. The return value is a string representing >>> the data received. The maximum amount of data to be received at once is >>> specified by bufsize. " >>> http://docs.python.org/library/socket.html#socket.socket.recv >> >>> What if the call fail? >> >> You will get an exception, just like the page says: >> >> All errors raise exceptions. The normal exceptions for >> invalid argument types and out-of-memory conditions can be >> raised; errors related to socket or address semantics raise >> the error socket.error. >> >>> What if the peer close the socket? >> >> You will get an exception, just like the Fine Manual says. >> >>> What is the >>> difference between blocking and non-blocking socket? >> >> Python isn't a tutor for basic programming concepts like sockets. That's >> what Google is for :) >> >> But having said that, the documentation does explain the difference: >> >> In non-blocking mode, if a recv() call doesn?t find any data, >> or if a send() call can?t immediately dispose of the data, >> a error exception is raised; in blocking mode, the calls block >> until they can proceed. >> >> http://docs.python.org/library/socket.html#socket.socket.setblocking >> >>> How could I get the errno or exception? >> >> You get the exception the same way you get *every* exception: by catching >> it with a try...except block. If you don't know that, you need to learn >> the basics and not blame the documentation. >> >> Untested, but this probably will work: >> >> try: >> something_involving_sockets() >> except socket.error, e: >> if len(e.args) == 1: >> print "Error message is:", e.args[0] >> else: >> print "errno =", e.args[0] >> print "Error message is:", e.args[1] >> >>> All the answers are "No comment". >> >>> I hate this documentation! >> >> Don't blame the documentation for your failure to read it. It's true that >> it could be improved, but most of your questions were answered by the >> page you linked to. >> >> -- >> Steven > On 23/07/2010 06:24, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. > some of my questions are answered in the page I post the link of. Some > are not. > > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. > > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on volunteer effort too, and > they has good documentations. > > I am not blaming those volunteers who devote their precious time to > this language. It will be good if the python communities get more > people who like to write documentation. > > Anyway, thank you again. > I'll be on the Python issue tracker later today. I look forward to seeing your first of many contributions to the "poor" Python documentation. Pigs might fly? :) Kindest regards. Mark Lawrence. From debatem1 at gmail.com Fri Jul 23 04:03:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 23 Jul 2010 01:03:34 -0700 Subject: Where is the man page of python library In-Reply-To: <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: On Thu, Jul 22, 2010 at 10:24 PM, march wrote: > Steven, thank you for your reply. > > It is true that I didn't read the document with enough carefulness. > some of my questions are answered in the page I post the link of. Some > are not. > > But the documentation is poor. You need to read throughout the entire > page, hoping to find what you need about one single API, and you might > fail. > > I don't think "Python is a volunteer effort" can justify the poor > documentation. Linux, glibc are based on ?volunteer effort too, and > they has good documentations. > > I am not blaming those volunteers who devote their precious time to > this language. It will be good if the python communities get more > people who like to write documentation. > > Anyway, thank you again. Two things: 1) don't top post, it's bad form. 2) I'd be happy to help you through the process of getting your doc changes written and onto the tracker. Others more capable than myself have offered their help once things reach that stage. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:10:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:10:11 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4c494e62$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > Thanks for pointing out that swap (and my swap2) don't work everywhere > -- is there a way to get it to work inside functions? Not in CPython. In IronPython or Jython, maybe, I don't know enough about them. But even if you got it to work, it would be an implementation- dependent trick. [...] > I always think that it is the language's job to express > my thoughts... Ha, no, it's the language's job to execute algorithms. If it did so in a way that is similar to the way people think, that would be scary. Have you *seen* the way most people think??? *wink* > I don't like to think that my thoughts are somehow > constrained by the language. Whether you "like" to think that way, or not, thoughts are influenced and constrained by language. While I don't accept the strong form of the Sapir-Whorf hypothesis (that some thoughts are *impossible* due to lack of language to express them, a position which has been discredited), a weaker form is almost certainly correct. Language influences thought. Turing Award winner and APL creator Kenneth E. Iverson gave a lecture about this theme, "Notation as a tool of thought", and argued that more powerful notations aided thinking about computer algorithms. Paul Graham also discusses similar ideas, such as the "blub paradox". Graham argues that the typical programmer is "satisfied with whatever language they happen to use, because it dictates the way they think about programs". We see this all the time, with people trying to write Java in Python, Perl in Python, and Ruby in Python. And Yukihiro Matsumoto has said that one of his inspirations for creating Ruby was the science fiction novel Babel-17, which in turn is based on the Sapir-Whorf Hypothesis. > The truth is that I don't intend to use these approaches in anything > serious. However, I've been known to do some metaprogramming from time > to time. > > In a recent application, I pass in a list of callables (lambdas) to be > evaluated repeatedly. Are you aware that lambdas are just functions? The only differences between a "lambda" and a function created with def is that lambda is syntactically limited to a single expression, and that functions created with lambda are anonymous (they don't have a name, or at least, not a meaningful name). > Clearly, a superior solution is to pass a single lambda that returns a > list. I don't see why you say this is a superior solution, mostly because you haven't explained what the problem is. > [Less function call dispatches] How? You have to generate the list at some point. Whether you do it like this: functions = (sin, cos, tan) data = (2.3, 4.5, 1.2) result = [f(x) for f, x in zip(functions, data)] or like this: result = (lambda x, y, z: return (sin(x), cos(y), tan(z)) )(2.3, 4.5, 1.2) you still end up with the same number of function calls (four). Any execution time will almost certainly be dominated by the work done inside the lambda (sin, cos and tan) rather than the infrastructure. And unless you have profiled your code, you would be surprised as to where the bottlenecks are. Your intuitions from Perl will not guide you well in Python -- it's a different language, and the bottlenecks are different. > However, it might be more > efficient to avoid the function call overhead completely and pass-in a > string which is substituted into a string code block, compiled, and > executed. See, that's *exactly* what I mean about intuitions. No no no no!!! Using exec or eval in Python code is almost certainly a *pessimation*, not an optimization! I expect this will be an order of magnitude slower to parse, compile and execute a string than it is to execute a function. Using exec or friends to avoid the overhead of function calls is like pushing your car to work to avoid the overhead of having to get in and out of the car. But of course, don't take my word for it. Write your code and profile it, see where the bottlenecks are. I might be wrong. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:24:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:24:34 GMT Subject: Change Encoding in Py 2.5 References: Message-ID: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 09:18:47 +0200, Stefan Behnel wrote: > Girish, 23.07.2010 08:54: >> Is ter a way to change default encoding in py 2.5 ? > > Yes, but it's highly discouraged. If you tell us why you want to do it, > we may be able to point to a better way to get what you want. I think it is discouraged because it *will* break things in the standard library and builtins. It's discouraged in the same way that pouring sugar into the petrol tank of your car is discouraged. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 04:26:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 08:26:31 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4d4ed277-d451-4d9b-aac2-8e047f09c2a0@k1g2000prl.googlegroups.com> Message-ID: <4c495237$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 08:20:03 +0100, Mark Lawrence wrote: > [Fix top posting] While you were fixing the top posting, did you bother to trim any unnecessary quoting? Let me scroll down and see... ... why no, no you didn't. I'm not a religious man, but the verse about the mote in your brother's eye might be appropriate about now. It's one thing to make a point about another's social faux pas, and other to make an equally big one yourself while doing so. -- Steven From hv at tbz-pariv.de Fri Jul 23 04:45:32 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 23 Jul 2010 10:45:32 +0200 Subject: non-blocking IO EAGAIN on write Message-ID: <8at354F51tU1@mid.individual.net> Hi, I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) on write(). My working code looks like this. But I am unsure how many bytes have been written to the pipe if I get an EAGAIN IOError. Up to now I retry with the same chunk. If I get EAGAIN can I just sleep, and then retry with the same data chunk? pipe=subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=-1) fcntl.fcntl(pipe.stdin, fcntl.F_SETFL, os.O_NONBLOCK) .... chunk_size=1024 while select.select([], [pipe.stdin], [], 5): check_timeout() chunk=fd.read(chunk_size) for i_eagain in range(10): try: pipe.stdin.write(chunk) except IOError, exc: if exc.errno==errno.EAGAIN: logging.info('write to pipe %s EAGAIN. I will try again i=%s. %s' % (cmd, i_eagain, exc)) time.sleep(.3) continue logging.error('write to pipe %s failed: %s' % (cmd, exc), exc_info=True) raise break # write was successful (default) else: raise Exception('Too many EAGAIN on write %s %s' % (cmd, exc), exc_info=True) Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 05:05:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 09:05:21 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> Message-ID: <4c495b50$0$28634$c3e8da3@news.astraweb.com> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: > On 7/22/10 7:47 PM, wheres pythonmonks wrote: [...] >> The truth is that I don't intend to use these approaches in anything >> serious. However, I've been known to do some metaprogramming from time >> to time. > > Depending on how you define "metaprogramming", Python is pretty > notoriously ill-suited towards the task (more, its basically considered > a feature it doesn't let you go there) -- or, it allows you to do vast > amounts of stuff with its few dark magic hooks. I've never had a > satisfying definition of metaprogramming that more then 50% of any group > agree with, so I'm not sure which you're looking for. :) I disagree strongly at your characterisation that Python is notorious for being ill-suited towards metaprogramming. I'd say the complete opposite -- what is considered dark and scary metaprogramming tasks in other languages is considered too ordinary to even mention in Python. If you have a class that defines a single member (or attribute in Python terminology) "spam", and you want to add a second "ham" to a specific instance, such a thing is either deep, dark metaprogramming in some languages, if not outright impossible. In Python it is not even noteworthy: instance.ham = "something" # *yawns* Recently there was a thread started by some Java or C++ refugee who was distressed about attribute access in Python, because it made metaprogramming frighteningly easy: http://mail.python.org/pipermail/python-list/2010-June/1248029.html My response at the time was: Python makes metaprogramming *easy*: http://mail.python.org/pipermail/python-list/2010-June/1248053.html I can't imagine how he would have reacted if we had showed him how easy it is to monkey-patch built-in functions... [...] > But! What it doesn't let you do is get clever with syntax and write a > sort of "simplified" or domain specific language to achieve certain > sorts of repetitive tasks quickly. You always end up writing normal > Python that looks like all other Python. Exactly... 90% of the time that you think you want a DSL, Python beat you to it. It is true that other languages (like Lisp, or Forth) allow you to write your own syntax. That's incredibly powerful, but it also has serious costs. If you can define your own syntax, that means every piece of code you look at is potentially a different language. -- Steven From qq263020776 at gmail.com Fri Jul 23 05:18:41 2010 From: qq263020776 at gmail.com (nu) Date: Fri, 23 Jul 2010 02:18:41 -0700 (PDT) Subject: make a folder to .nsi file(which finally will convert to .exe) use python Message-ID: <54269fe3-085c-4360-93eb-866223a0bcca@v35g2000prn.googlegroups.com> Has any python liberary can make a folder to .nsi file? Thanks From duncan.booth at invalid.invalid Fri Jul 23 05:26:02 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Jul 2010 09:26:02 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > >> Thanks for pointing out that swap (and my swap2) don't work everywhere >> -- is there a way to get it to work inside functions? Consider languages where you can easily write a swap function (or any other function that updates its arguments). e.g. consider C or C#. For C your function must take pointers to the variables, so when you call swap you have to make this explicit by taking the address of each variable: foo(&x, &y); For C# the function takes references to the variables. Again you have to also make this explicit at the point of call by prefixing the argument with 'ref': foo(ref x, ref y); Python is really no different: if you want a function to rebind its arguments you have to make that explicit at the point of call. The only difference is that in Python you make the rebinding explicit by assigning to the names: x, y = foo(x, y) -- Duncan Booth http://kupuguy.blogspot.com From wherespythonmonks at gmail.com Fri Jul 23 05:28:05 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 23 Jul 2010 05:28:05 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c494e62$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: Funny... just spent some time with timeit: I wonder why I am passing in strings if the callback overhead is so light... More funny: it looks like inline (not passed in) lambdas can cause python to be more efficient! >>> import random >>> d = [ (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in xrange(0,1000000) ] >>> def A1(): j = [ lambda t: (t[2]*t[1],t[2]**2+5) for t in d ] >>> def A2(): j = [ (t[2]*t[1],t[2]**2+5) for t in d ] >>> def A3(l): j = [ l(t) for t in d] >>> import timeit >>> timeit.timeit('A1()','from __main__ import A1,d',number=10); 2.2185971572472454 >>> timeit.timeit('A2()','from __main__ import A2,d',number=10); 7.2615454749912942 >>> timeit.timeit('A3(lambda t: (t[2]*t[1],t[2]**2+5))','from __main__ import A3,d',number=10); 9.4334241349350947 So: in-line lambda possible speed improvement. in-line tuple is slow, passed-in callback, slowest yet? Is this possibly right? Hopefully someone can spot the bug? W On Fri, Jul 23, 2010 at 4:10 AM, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote: > >> Thanks for pointing out that swap (and my swap2) don't work everywhere >> -- is there a way to get it to work inside functions? > > Not in CPython. In IronPython or Jython, maybe, I don't know enough about > them. But even if you got it to work, it would be an implementation- > dependent trick. > > [...] >> I always think that it is the language's job to express >> my thoughts... > > Ha, no, it's the language's job to execute algorithms. If it did so in a > way that is similar to the way people think, that would be scary. Have > you *seen* the way most people think??? > > *wink* > > >> I don't like to think that my thoughts are somehow >> constrained by the language. > > > Whether you "like" to think that way, or not, thoughts are influenced and > constrained by language. While I don't accept the strong form of the > Sapir-Whorf hypothesis (that some thoughts are *impossible* due to lack > of language to express them, a position which has been discredited), a > weaker form is almost certainly correct. Language influences thought. > > Turing Award winner and APL creator Kenneth E. Iverson gave a lecture > about this theme, "Notation as a tool of thought", and argued that more > powerful notations aided thinking about computer algorithms. > > Paul Graham also discusses similar ideas, such as the "blub paradox". > Graham argues that the typical programmer is "satisfied with whatever > language they happen to use, because it dictates the way they think about > programs". We see this all the time, with people trying to write Java in > Python, Perl in Python, and Ruby in Python. > > And Yukihiro Matsumoto has said that one of his inspirations for creating > Ruby was the science fiction novel Babel-17, which in turn is based on > the Sapir-Whorf Hypothesis. > > > >> The truth is that I don't intend to use these approaches in anything >> serious. ?However, I've been known to do some metaprogramming from time >> to time. >> >> In a recent application, I pass in a list of callables (lambdas) to be >> evaluated repeatedly. > > Are you aware that lambdas are just functions? The only differences > between a "lambda" and a function created with def is that lambda is > syntactically limited to a single expression, and that functions created > with lambda are anonymous (they don't have a name, or at least, not a > meaningful name). > > >> Clearly, a superior solution is to pass a single lambda that returns a >> list. > > I don't see why you say this is a superior solution, mostly because you > haven't explained what the problem is. > > >> [Less function call dispatches] > > How? You have to generate the list at some point. Whether you do it like > this: > > functions = (sin, cos, tan) > data = (2.3, 4.5, 1.2) > result = [f(x) for f, x in zip(functions, data)] > > or like this: > > result = (lambda x, y, z: return (sin(x), cos(y), tan(z)) > ? ?)(2.3, 4.5, 1.2) > > you still end up with the same number of function calls (four). Any > execution time will almost certainly be dominated by the work done inside > the lambda (sin, cos and tan) rather than the infrastructure. And unless > you have profiled your code, you would be surprised as to where the > bottlenecks are. Your intuitions from Perl will not guide you well in > Python -- it's a different language, and the bottlenecks are different. > > >> However, it might be more >> efficient to avoid the function call overhead completely and pass-in a >> string which is substituted into a string code block, compiled, and >> executed. > > See, that's *exactly* what I mean about intuitions. No no no no!!! Using > exec or eval in Python code is almost certainly a *pessimation*, not an > optimization! I expect this will be an order of magnitude slower to > parse, compile and execute a string than it is to execute a function. > Using exec or friends to avoid the overhead of function calls is like > pushing your car to work to avoid the overhead of having to get in and > out of the car. > > But of course, don't take my word for it. Write your code and profile it, > see where the bottlenecks are. I might be wrong. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From dirknbr at gmail.com Fri Jul 23 06:14:11 2010 From: dirknbr at gmail.com (dirknbr) Date: Fri, 23 Jul 2010 03:14:11 -0700 (PDT) Subject: Unicode error Message-ID: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> I am having some problems with unicode from json. This is the error I get UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in position 61: ordinal not in range(128) I have kind of developped this but obviously it's not nice, any better ideas? try: text=texts[i] text=text.encode('latin-1') text=text.encode('utf-8') except: text=' ' Dirk From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 06:42:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 10:42:26 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: <4c497212$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 03:14:11 -0700, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) > > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' Don't write bare excepts, always catch the error you want and nothing else. As you've written it, the result of encoding with latin-1 is thrown away, even if it succeeds. text = texts[i] # Don't hide errors here. try: text = text.encode('latin-1') except UnicodeEncodeError: try: text = text.encode('utf-8') except UnicodeEncodeError: text = ' ' do_something_with(text) Another thing you might consider is setting the error handler: text = text.encode('utf-8', errors='ignore') Other error handlers are 'strict' (the default), 'replace' and 'xmlcharrefreplace'. -- Steven From clp2 at rebertia.com Fri Jul 23 06:45:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Jul 2010 03:45:19 -0700 Subject: Unicode error In-Reply-To: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: On Fri, Jul 23, 2010 at 3:14 AM, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) Please include the full Traceback and the actual code that's causing the error! We aren't mind readers. This error basically indicates that you're incorrectly mixing byte strings and Unicode strings somewhere. Cheers, Chris -- http://blog.rebertia.com From dirknbr at gmail.com Fri Jul 23 06:56:15 2010 From: dirknbr at gmail.com (dirknbr) Date: Fri, 23 Jul 2010 03:56:15 -0700 (PDT) Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: To give a bit of context. I am using twython which is a wrapper for the JSON API search=twitter.searchTwitter(s,rpp=100,page=str(it),result_type='recent',lang='en') for u in search[u'results']: ids.append(u[u'id']) texts.append(u[u'text']) This is where texts comes from. When I then want to write texts to a file I get the unicode error. Dirk From __peter__ at web.de Fri Jul 23 07:20:19 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Jul 2010 13:20:19 +0200 Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: wheres pythonmonks wrote: > Funny... just spent some time with timeit: > > I wonder why I am passing in strings if the callback overhead is so > light... > > More funny: it looks like inline (not passed in) lambdas can cause > python to be more efficient! >>>> import random >>>> d = [ (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in >>>> xrange(0,1000000) ] def A1(): j = [ lambda t: (t[2]*t[1],t[2]**2+5) for >>>> t in d ] > >>>> def A2(): j = [ (t[2]*t[1],t[2]**2+5) for t in d ] > >>>> def A3(l): j = [ l(t) for t in d] > >>>> import timeit >>>> timeit.timeit('A1()','from __main__ import A1,d',number=10); > 2.2185971572472454 >>>> timeit.timeit('A2()','from __main__ import A2,d',number=10); > 7.2615454749912942 >>>> timeit.timeit('A3(lambda t: (t[2]*t[1],t[2]**2+5))','from __main__ >>>> import A3,d',number=10); > 9.4334241349350947 > > So: in-line lambda possible speed improvement. in-line tuple is slow, > passed-in callback, slowest yet? > > Is this possibly right? > > Hopefully someone can spot the bug? A1() makes a lot of lambdas but doesn't invoke them. Once that is fixed A1() is indeed slower than A2(): >>> from timeit import timeit >>> import random >>> d = [(random.choice("AB"), x, random.gauss(0, 1)) for x in xrange(10**6)] >>> def A1(d=d): return [(lambda t: (t[2]*t[1],t[2]**2+5))(t) for t in d] ... >>> def A2(d=d): return [(t[2]*t[1], t[2]**2+5) for t in d] ... >>> assert A1() == A2() >>> timeit("A1()", "from __main__ import A1", number=10) 14.275790929794312 >>> timeit("A2()", "from __main__ import A2", number=10) 10.31659197807312 Peter From davea at ieee.org Fri Jul 23 07:35:57 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 07:35:57 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C497E9D.4070105@ieee.org> Duncan Booth wrote: > > Consider languages where you can easily write a swap function (or any other > function that updates its arguments). e.g. consider C or C#. > > For C your function must take pointers to the variables, so when you call > swap you have to make this explicit by taking the address of each variable: > > foo(&x, &y); > > For C# the function takes references to the variables. Again you have to > also make this explicit at the point of call by prefixing the argument with > 'ref': > > foo(ref x, ref y); > > Python is really no different: if you want a function to rebind its > arguments you have to make that explicit at the point of call. The only > difference is that in Python you make the rebinding explicit by assigning > to the names: > > x, y = foo(x, y) > > > I don't disagree with the overall point, but C has references (or at least C++ does, I don't think I've written any pure C code since 1992). If the function is declared to take references, the caller doesn't do a thing differently. void foo(int &a, int &b); is called by foo(x, y), and the function may indeed swap the arguments. If I recall correctly, pascal is the same way. The called function declares byref, and the caller doesn't do anything differently. DaveA From davea at ieee.org Fri Jul 23 07:44:03 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 07:44:03 -0400 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C498083.6080908@ieee.org> wheres pythonmonks wrote: > Funny... just spent some time with timeit: > > I wonder why I am passing in strings if the callback overhead is so light... > > More funny: it looks like inline (not passed in) lambdas can cause > python to be more efficient! > >>>> import random >>>> d = (['A','B'][random.randint(0,1)],x,random.gauss(0,1)) for x in xrange(0,1000000) ] >>>> def A1(): j = lambda t: (t[2]*t[1],t[2]**2+5) for t in d ] >>>> > > >>>> def A2(): j = (t[2]*t[1],t[2]**2+5) for t in d ] >>>> > > But A1() gives a different result. It builds a list of function objects. It doesn't actually do any of those multiplies. In fact, I don't even think it would get the same answers if you then looped through it, calling the functions it stored. DaveA From kwutzke at web.de Fri Jul 23 08:07:53 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Fri, 23 Jul 2010 05:07:53 -0700 (PDT) Subject: Visitor pattern and separating iteration References: Message-ID: On 22 Jul., 22:25, Ian wrote: > Hi Karsten, > > On 22/07/2010 12:03, Karsten Wutzke wrote:> What is it I'm missing? > > I think you are making it more complicated than it really is. > > The visitor pattern is about bringing all the little bits that would > otherwise be scattered all over > many node classes into one visitor class. For code generation this means > that all the code generation is done > in your visitor class. For pretty-printing you have another visitor > class. For code optimization a third > visitor class. > > If there is only one sequence in which the nodes should be visited, then > you can build it > in to the nodes of the tree. > > If you need to visit your nodes in different orders you might be better > off building a separated > tree-walker class for each order. Thus you might have a > post-order-walker for use with the code > generating visitor, and a in-order-walker for a pretty-printing visitor. > > The optimizing walker may need to take different routes through the tree > depending > upon what it finds. For example, it may compute the value of the RHS of > an assignment > before computing the address of the LHS, so it can make better use of > registers. Here the > visitor class itself needs to do the walking. > > Regards > > Ian My objects to iterate over are plain object-structures, composites. I have only one code generation pass, so generating code and then pretty printing is not intended/possible. I have many user options to configure the code generation. The visitor pattern is ideal for that matter, because I can keep the options in the generator rather than scatter all the options into the object classes' accessor methods. (making me think the visitor is just right and not more complicated than needed) I was just curious about separating the iteration code into the object classes, because GoF said "The main reason to put the traversal strategy in the visitor is to implement a *particular complex* traversal, one that depends on the results of the operations on the object structure." My code generator isn't really THAT complex (I thought), but reviewing the latter part of the quote makes me believe I was wrong. Code generation always depends on the previous results, that is the children of a composite in the object structure. Now that I realized it, I feel great about traversing in the visitor. Python just has a few consequences that makes creating common interfaces/abstract classes a little unusual. I'm just starting to really love Python (or its API), though I don't feel I've already discovered the core what it is really about. Best regards Karsten From franco at grex.org Fri Jul 23 09:10:16 2010 From: franco at grex.org (francogrex) Date: Fri, 23 Jul 2010 15:10:16 +0200 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: In article <16a7e301-2e85-47eb-971e-79acc4e076a6 at b35g2000yqi. googlegroups.com>, gnuist006 at gmail.com says... >This makes some sense. He replied on the newsgroup in a lengthy post >that there are sufficient resources out there giving hint that no one >need help me out. Then I was called "lazy" in one email and tersely >given JUST the last name of an author who has many books each many >100s pages, when I asked for a relevant book, as if i am a scholar in >the field, although he did spend lots of words on irrelevant and >unbeneficial things which diminished my enthusiasm. Now, I find out >from you that he has/had a business concern or interest in a company >that is writing/wrote lisp interpreter in C. Correct me if I am making >an error. I dont want to think deprecatingly of any good soul but this >is what i experienced. No, you're not making a bad judgement. He's not the only one who treats newcomers with disrespect and scorn. Unfortunately many so-called experts in the field look down on newbies and mistreat them (in any programming language forum), forgetting in the process that they were also at a certain time newbies until someone gentle and nice enough teachers took the trouble to educate them. On the other hand there are less neurotic experts out there who are glad to help out someone learning. It's like in some universities, you have the bad "professors" who are freaks (probably they have a lot of problems at home, their wives screwing all the males on the block, daughters drug addicts etc) and want to take their hatred out on you, and you have the good and mentally stable professors who actually deserve their title. From lists at cheimes.de Fri Jul 23 09:26:26 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 23 Jul 2010 15:26:26 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> References: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> Message-ID: > I think it is discouraged because it *will* break things in the standard > library and builtins. It's discouraged in the same way that pouring sugar > into the petrol tank of your car is discouraged. Mythbusters have tested this urban legend. In their test the engine run better with sugar. [1] Christian [1] http://mythbustersresults.com/episode15 From stefan_ml at behnel.de Fri Jul 23 09:59:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Jul 2010 15:59:58 +0200 Subject: Change Encoding in Py 2.5 In-Reply-To: References: <4c4951c2$0$28634$c3e8da3@news.astraweb.com> Message-ID: Christian Heimes, 23.07.2010 15:26: >> I think it is discouraged because it *will* break things in the standard >> library and builtins. It's discouraged in the same way that pouring sugar >> into the petrol tank of your car is discouraged. > > Mythbusters have tested this urban legend. In their test the engine run > better with sugar. [1] "Did you blow up your car testing that out?" - "No, I just read comp.lang.python." Stefan From invalid at invalid.invalid Fri Jul 23 10:26:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 23 Jul 2010 14:26:27 +0000 (UTC) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 2010-07-23, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 20:18:43 -0700, march wrote: > >> Hi, guys. >> >> As a regular user of python, I am often annoyed by the fact that the >> official python docementation is too short and too simple to satisfy my >> requirement. > > Python is a volunteer effort. If the docs don't suit your requirements, > we're grateful for patches. > >> While working with socket, I want to know every detail about every API. >> I can easilly achieve that by reading man page if the language is C. But >> It seems that the Python story is different. > > Python is open source. Where the documentation is silent, the ultimate > authority is the source code. Particularly if the code is a thin wrapper > around the C library, which I expect (but don't know for sure) the socket > code will be. > > >> For the interface recv(), all I got is only three sentences. " >> Receive data from the socket. The return value is a string representing >> the data received. The maximum amount of data to be received at once is >> specified by bufsize. " >> http://docs.python.org/library/socket.html#socket.socket.recv >> >> What if the call fail? > > You will get an exception, just like the page says: > > All errors raise exceptions. The normal exceptions for > invalid argument types and out-of-memory conditions can be > raised; errors related to socket or address semantics raise > the error socket.error. > > >> What if the peer close the socket? > > You will get an exception, Nope. You read a value of "". > just like the Fine Manual says. If it does say that, it needs to be fixed. >> I hate this documentation! Then quit bitching and submit a patch. > Don't blame the documentation for your failure to read it. It's true > that it could be improved, but most of your questions were answered > by the page you linked to. -- Grant Edwards grant.b.edwards Yow! I am having FUN... at I wonder if it's NET FUN or gmail.com GROSS FUN? From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 10:49:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 23 Jul 2010 14:49:10 GMT Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c49abe6$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 14:26:27 +0000, Grant Edwards wrote: >>> What if the peer close the socket? >> >> You will get an exception, > > Nope. You read a value of "". Thank you for the correction. >> just like the Fine Manual says. > > If it does say that, it needs to be fixed. No, I apparently just made it up. -- Steven From rantingrick at gmail.com Fri Jul 23 11:42:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 23 Jul 2010 08:42:52 -0700 (PDT) Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> Message-ID: <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> On Jul 23, 9:49?am, Steven D'Aprano wrote: > On Fri, 23 Jul 2010 14:26:27 +0000, Grant Edwards wrote: > > If it does say that, it needs to be fixed. > > No, I apparently just made it up. Yes and i'll bet you've *never* just "made up" anything to scaffold your arguments? . Since this trait is one of the major personality flaws of the deeply religious... are you *sure* your *not* a religious man Steven? We've also seen our fair share of haughty arrogance and sanctimoniousness from time to time. Just observations really. Sorry, i guess I just wanted to put a big neon sign around your mistake. Of course now we both have our eyes poked out! In the land of the blind, the one eyed man is king! ;-) From robert.kern at gmail.com Fri Jul 23 11:44:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jul 2010 10:44:51 -0500 Subject: detect endianness of a binary with python In-Reply-To: References: <4C46EEB8.6070702@keymile.com> Message-ID: On 7/23/10 12:44 AM, Tim Roberts wrote: > I wouldn't use os.system with grep and evaluate the return code. Instead > I'd use subprocess.Popen("file") and read the text output of the > commdn directly. By parsing that string, I can extract all kinds of > interesting information. Small correction: subprocess.Popen(["file", our_image_filename]) -- 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 prologic at shortcircuit.net.au Fri Jul 23 12:09:09 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Sat, 24 Jul 2010 02:09:09 +1000 Subject: Where is the man page of python library In-Reply-To: <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> Message-ID: On Sat, Jul 24, 2010 at 1:42 AM, rantingrick wrote: > In the land of the blind, the one eyed man is king! ;-) RIck, your comments don't really help the situation. Really. -- -- James Mills -- -- "Problems are solved by method" From me+list/python at ixokai.io Fri Jul 23 12:22:16 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 23 Jul 2010 09:22:16 -0700 Subject: Easy questions from a python beginner In-Reply-To: <4c495b50$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c495b50$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C49C1B8.5060500@ixokai.io> On 7/23/10 2:05 AM, Steven D'Aprano wrote: > On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: > >> On 7/22/10 7:47 PM, wheres pythonmonks wrote: > [...] >>> The truth is that I don't intend to use these approaches in anything >>> serious. However, I've been known to do some metaprogramming from time >>> to time. >> >> Depending on how you define "metaprogramming", Python is pretty >> notoriously ill-suited towards the task (more, its basically considered >> a feature it doesn't let you go there) -- or, it allows you to do vast >> amounts of stuff with its few dark magic hooks. I've never had a >> satisfying definition of metaprogramming that more then 50% of any group >> agree with, so I'm not sure which you're looking for. :) > > I disagree strongly at your characterisation that Python is notorious for > being ill-suited towards metaprogramming. I'd say the complete opposite > -- what is considered dark and scary metaprogramming tasks in other > languages is considered too ordinary to even mention in Python. I rather think you missed my point entirely. 'Depending on how you define "metaprogramming"' The 'Depending' was the most important part of that sentence. You go on to talk about runtime modification of classes and the like. That, Python lets you do quite readily, and then go on to do crazy amounts of without any significant effort. That's one definition of metaprogramming. That one Python does well. The other involves things like macros, or things where you basically write a new sub-language in the language itself to achieve some commonly desired task more efficiently (or just more succinctly). That's another definition of metaprogramming: where its not so much structures (classes, etc) which are modified at runtime (which Python lets you do readily), but the syntax or semantics of the language itself. That Python isn't game for. > [...] >> But! What it doesn't let you do is get clever with syntax and write a >> sort of "simplified" or domain specific language to achieve certain >> sorts of repetitive tasks quickly. You always end up writing normal >> Python that looks like all other Python. > > Exactly... 90% of the time that you think you want a DSL, Python beat you > to it. Yet, that is a branch of what is considered metaprogramming that the OP seems to be asking for, that we do not offer any sort of real support for. I was making this distinction. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From thomas at jollans.com Fri Jul 23 12:27:47 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 18:27:47 +0200 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: <4C49C303.4010106@jollans.com> On 07/23/2010 12:56 PM, dirknbr wrote: > To give a bit of context. I am using twython which is a wrapper for > the JSON API > > > search=twitter.searchTwitter(s,rpp=100,page=str(it),result_type='recent',lang='en') > for u in search[u'results']: > ids.append(u[u'id']) > texts.append(u[u'text']) > > This is where texts comes from. > > When I then want to write texts to a file I get the unicode error. So your data is unicode? Good. Well, files are just streams of bytes, so to write unicode data to one you have to encode it. Since Python can't know which encoding you want to use (utf-8, by the way, if you ask me), you have to do it manually. something like: outfile.write(text.encode('utf-8')) From jim.hefferon at gmail.com Fri Jul 23 13:01:00 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 10:01:00 -0700 (PDT) Subject: time between now and the next 2:30 am? Message-ID: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> How can I calculate how much time is between now and the next 2:30 am? Naturally I want the system to worry about leap years, etc. Thanks, Jim From neilc at norwich.edu Fri Jul 23 13:06:11 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Jul 2010 17:06:11 GMT Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> Message-ID: <8au0g3FmmoU1@mid.individual.net> On 2010-07-23, Jim wrote: > How can I calculate how much time is between now and the next > 2:30 am? Naturally I want the system to worry about leap > years, etc. You need the datetime module. Specifically, a datetime and timedelta object. -- Neil Cerutti From thomas at jollans.com Fri Jul 23 13:13:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 19:13:45 +0200 Subject: Easy questions from a python beginner In-Reply-To: References: <4C3A0F79.8070502@ixokai.io> Message-ID: <4C49CDC9.1000108@jollans.com> On 07/23/2010 12:34 AM, wheres pythonmonks wrote: > 2. Is there a better way to loopup by id? I'm not very familiar with > sys.exc_info, but creating the id->name hash each time seems like > overkill. I just had the most horrendous idea. Really, looking up objects by ID, or even swapping two objects, isn't that difficult if you do some C black magic. Don't try this in front of the kids. I wrote a little module, called "hell": Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> from hell import swap, getptr >>> dir >>> len >>> swap(dir, len) >>> dir >>> len >>> a = "this was a" >>> b = "this was b, hell yeah" >>> (a, b, id(a), id(b)) ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>> tpl = (a, b, id(a), id(b)) >>> tpl ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>> swap(a, b) >>> tpl ('this was b, hell yeah', 'this was a', 32417752, 32418144) >>> getptr(32417752) 'this was b, hell yeah' >>> The code is below. Use it under the terms of the WTFPL version 2. (http://sam.zoy.org/wtfpl/) -- Thomas PS: all of this is a very BAD IDEA. But interesting, in a way. ################# setup.py ############ from distutils.core import setup, Extension hellmodule = Extension('hell', sources = ['hellmodule.c']) setup (name = 'hellmodule', version = '0.1-apocalypse', description = 'Functions from hell. Never ever use.', ext_modules = [hellmodule]) ################# hellmodule.c ############## #define PY_SSIZE_T_CLEAN #include static PyObject *swap(PyObject *self, PyObject *args); static PyObject *getptr(PyObject *self, PyObject *args); static PyMethodDef hell_methods[] = { {"swap", &swap, METH_VARARGS, ""}, {"getptr", &getptr, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef hell_module = { PyModuleDef_HEAD_INIT, "hell", /* module name */ "functions from hell. never use.", /* doc */ -1, hell_methods }; PyMODINIT_FUNC PyInit_hell(void) { return PyModule_Create(&hell_module); } static PyObject * swap(PyObject *self, PyObject *args) { PyObject *obj1, *obj2; Py_ssize_t len; PyObject *temp; if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) { return NULL; } len = obj1->ob_type->tp_basicsize; if (obj2->ob_type->tp_basicsize != len) { PyErr_SetString(PyExc_TypeError, "types have different sizes (incompatible)"); return NULL; } temp = PyMem_Malloc(len); memcpy(temp, obj1, len); memcpy(obj1, obj2, len); memcpy(obj2, temp, len); obj2->ob_refcnt = obj1->ob_refcnt; obj1->ob_refcnt = temp->ob_refcnt; Py_INCREF(Py_None); return Py_None; } static PyObject * getptr(PyObject *self, PyObject *args) { unsigned long lId; PyObject *retv; if (!PyArg_ParseTuple(args, "k", &lId)) { return NULL; } retv = (PyObject*) lId; Py_INCREF(retv); return retv; } From thomas at jollans.com Fri Jul 23 14:07:34 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 20:07:34 +0200 Subject: Easy questions from a python beginner In-Reply-To: <4C49CDC9.1000108@jollans.com> References: <4C3A0F79.8070502@ixokai.io> <4C49CDC9.1000108@jollans.com> Message-ID: <4C49DA66.7020707@jollans.com> On 07/23/2010 07:13 PM, Thomas Jollans wrote: > On 07/23/2010 12:34 AM, wheres pythonmonks wrote: >> 2. Is there a better way to loopup by id? I'm not very familiar with >> sys.exc_info, but creating the id->name hash each time seems like >> overkill. > > I just had the most horrendous idea. Really, looking up objects by ID, > or even swapping two objects, isn't that difficult if you do some C > black magic. Don't try this in front of the kids. > > I wrote a little module, called "hell": > > Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) > [GCC 4.4.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> from hell import swap, getptr >>>> dir > >>>> len > >>>> swap(dir, len) >>>> dir > >>>> len > >>>> a = "this was a" >>>> b = "this was b, hell yeah" >>>> (a, b, id(a), id(b)) > ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>>> tpl = (a, b, id(a), id(b)) >>>> tpl > ('this was a', 'this was b, hell yeah', 32417752, 32418144) >>>> swap(a, b) >>>> tpl > ('this was b, hell yeah', 'this was a', 32417752, 32418144) >>>> getptr(32417752) > 'this was b, hell yeah' >>>> The great thing about this is that it can illustrate, in a very perverse manner, some lovely facets of Python. For example: combined hash and equality checks when accessing sets and dicts: Python 3.1.2 (release31-maint, Jul 8 2010, 09:18:08) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from hell import swap >>> s1 = 'string1' >>> s2 = 'string2' >>> s = {s1, s2} >>> swap(s1, s2) >>> s {'string1', 'string2'} >>> s1 in s False >>> s2 in s False >>> s1 in list(s) True >>> s2 in list(s) True >>> From smono927 at gmail.com Fri Jul 23 14:30:08 2010 From: smono927 at gmail.com (SeanMon) Date: Fri, 23 Jul 2010 11:30:08 -0700 (PDT) Subject: Function closure inconsistency Message-ID: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): x += 1 return x return g1 def f2(): x = [] def g(): x.append(0) return x return g a = f1() b = f2() a() #UnboundLocalError: local variable 'x' referenced before assignment b() #No error, [0] returned b() #No error, [0, 0] returned From benjamin.kaplan at case.edu Fri Jul 23 14:49:52 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 11:49:52 -0700 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: On Fri, Jul 23, 2010 at 11:30 AM, SeanMon wrote: > > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > ? ?x = 0 > ? ?def g(): > ? ? ? ?x += 1 > ? ? ? ?return x > ? ?return g1 > > def f2(): > ? ?x = [] > ? ?def g(): > ? ? ? ?x.append(0) > ? ? ? ?return x > ? ?return g > > a = f1() > b = f2() > > a() #UnboundLocalError: local variable 'x' referenced before > assignment > b() #No error, [0] returned > b() #No error, [0, 0] returned > -- It's not closure related at all. Same thing happens at the module level. x = 0 def f1() : ?? x += 1 #gives UnboundLocalError x = [] def f2() : ?? x.append(1) #succeeds. The reason for it is that if you have any assignments to the variable in the function, Python creates a new local variable for it. x += 1 is an assignment, not a modification. Python 2.x allows you to assign to the global scope (using the global keyword) but support for assigning to the outer function's scope wasn't added until Python 3 (with the nonlocal keyword) def f1(): ?? x = 0 ?? def g(): ???????nonlocal x ?????? x += 1 ?????? return x ?? return g1 > > http://mail.python.org/mailman/listinfo/python-list From emmynoether3 at gmail.com Fri Jul 23 15:06:34 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Fri, 23 Jul 2010 12:06:34 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. Message-ID: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> Title Portable LISP interpreter Creator/Author Cox, L.A. Jr. ; Taylor, W.P. Publication Date 1978 May 31 OSTI Identifier OSTI ID: 7017786 Report Number(s) UCRL-52417 DOE Contract Number W-7405-ENG-48 Resource Type Technical Report Research Org California Univ., Livermore (USA). Lawrence Livermore Lab. Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; PROGRAMMING LANGUAGES Description/Abstract A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. Country of Publication United States Language English Format Medium: X; Size: Pages: 21 Availability Dep. NTIS, PC A02/MF A01. System Entry Date 2008 Feb 12 From jim.hefferon at gmail.com Fri Jul 23 15:44:12 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 12:44:12 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: <576fe427-b7a4-47d2-adf5-45f04d6dc905@w30g2000yqw.googlegroups.com> Thanks; I'll have a look, and a think. Jim From davea at ieee.org Fri Jul 23 15:51:45 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 23 Jul 2010 15:51:45 -0400 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: <4C49F2D1.7070106@ieee.org> SeanMon wrote: > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > x = 0 > def g(): > x += 1 > return x > return g1 > > def f2(): > x = [] > def g(): > x.append(0) > return x > return g > > a = f1() > b = f2() > > a() #UnboundLocalError: local variable 'x' referenced before > assignment > b() #No error, [0] returned > b() #No error, [0, 0] returned > > Your example is more complex than needed. The symptom doesn't need a function closure. >>> def g(): ... x += 1 ... return x ... >>> g() Traceback (most recent call last): File "", line 1, in File "", line 2, in g UnboundLocalError: local variable 'x' referenced before assignment >>> def f(): ... x.append(0) ... return x ... >>> x = [3,5] >>> f() [3, 5, 0] >>> The difference between the functions is that in the first case, x is reassigned; therefore it's a local. But it's not defined before that line, so you get the ref before assign error. In the second case, append() is an in-place operation, and doesn't create a local variable. DaveA From python at bdurham.com Fri Jul 23 16:35:56 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 23 Jul 2010 16:35:56 -0400 Subject: Light-weight/very-simple version control under Windows using Python? Message-ID: <1279917356.23092.1386443203@webmail.messagingengine.com> I have some very simple use cases[1] for adding some version control capabilities to a product I'm working on. My product uses simple, text (UTF-8) based scripts that are independent of one another. I would like to "version control" these scripts on behalf of my users. By version control, I mean *very-simple* version control with no branching or merging - just the ability to store, list and restore a specific version of a file. The data store should be a local file with the ability to upsize to a multi-user database in the future. I'm looking for recommendations on possible solutions: 1. Use an existing version control utility. There are lots of options here(!), any recommendations on a light weight, open source one that xcopy installs under Windows with lots of command line options? 2. Interface to a hosted version control system (SaaS) that provides a RESTful API. Any recommendations here? 3. Build this capability myself using Python and Python's DBI layer to store files in a local SQLite database at first (but with the ability to upsize to a real client server database in the future). Seems like a fun project to work on, but also smells like I'd be re-inventing the wheel with very little value added other than simpler deployment? Any suggestions appreciated. Malcolm [1] Here's my use cases: 1. Check a file in with optional comment and username; ideally get a version number that can be used to reference this specific check-in in the future. 2. Get a history listing of all checkins for a specific file (version number, timestamp, file size, user, comment) 3. Check out a specific version of a file by version number. 4. Delete checked-in versions by version number, date range, and/or username. 5. (Optional) Diff 2 versions of a file by version number and return diff in richly formatted format that visually shows changes via color and font effects (strikethru) (I'm thinking of using BeyondCompare for this if not present in a simple version control tool) From thomas at jollans.com Fri Jul 23 16:49:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Fri, 23 Jul 2010 22:49:40 +0200 Subject: Light-weight/very-simple version control under Windows using Python? In-Reply-To: <1279917356.23092.1386443203@webmail.messagingengine.com> References: <1279917356.23092.1386443203@webmail.messagingengine.com> Message-ID: <4C4A0064.6050709@jollans.com> On 07/23/2010 10:35 PM, python at bdurham.com wrote: > 1. Use an existing version control utility. There are lots of options > here(!), any recommendations on a light weight, open source one that > xcopy installs under Windows with lots of command line options? You could just go with Mercurial, you know. Very popular, powerful, portable, distributed (so you need no server infrastructure...), free software of course, and written in Python, so interfacing it from Python isn't that hard. It also scales up and down very well, so you can easily change your mind about what you want it to do later if you want to. > 1. Check a file in with optional comment and username; ideally > get a version number that can be used to reference this specific > check-in in the future. trivial. > 2. Get a history listing of all checkins for a specific file > (version number, timestamp, file size, user, comment) trivial as in that's the whole point. > 3. Check out a specific version of a file by version number. Mercurial, and the other distributed VCS, don't technically track changes to files, they track changes to the whole repository (think "directory" if you're not acquainted with DVCS) -- as with any other existing solution you might use, you'll have to think a bit more on its (whatever tool you end up using) terms. > 4. Delete checked-in versions by version number, date range, > and/or username. Do you really want to do this? It's possible, even with Mercurial, but do you really want to create history just to delete it later? Think about it. > 5. (Optional) Diff 2 versions of a file by version number and > return diff in richly formatted format that visually shows > changes via color and font effects (strikethru) (I'm thinking > of using BeyondCompare for this if not present in a simple > version control tool) Yeah, just look for a nice graphical diff tool. KDiff3 springs to mind, I think that's what comes bundled with TortoiseHg on Windows. From gneuner2 at comcast.net Fri Jul 23 17:10:02 2010 From: gneuner2 at comcast.net (George Neuner) Date: Fri, 23 Jul 2010 17:10:02 -0400 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: On Fri, 23 Jul 2010 15:10:16 +0200, francogrex wrote: >Unfortunately many so-called experts in the field look down >on newbies and mistreat them (in any programming language forum), >forgetting in the process that they were also at a certain time >newbies until some gentle and nice enough teachers took the >trouble to educate them. I don't think it's accurate to say that [some] experts really "scorn" newbies, but I do agree that newbies are occasionally mistreated. One thing newbies have to realize is that on Usenet you are quite likely to be talking to people who were there at the beginning and, of necessity, are largely self educated in whatever the subject matter might be. Many - I'd even say most - are happy to clarify understanding and help with complicated problems, but there is a general expectation that newbies have some basic research skills and that they have tried to solve their problem before asking for help. Unfortunately, there is a small percentage of people who think Usenet and other online forums are for answering homework questions or for digging out of a jam at work. Getting help depends a lot on how the question is asked: strident pleas for quick help or demands for an answer are immediate red flags, but so are questions that begin with "X is crap, why can't I do ..." and even seemingly polite questions that are vague or unfocused (possibly indicating little or no thought behind them) or posts which are directed to a large number of groups (such as this thread we're in now). And, of course, in the language forums, drawing comparisons to non-subject languages is generally considered rude except when done to illustrate a relevant discussion point. Introducing irrelevant comparisons, deliberately proselytizing X in a Y group or doing a lot of complaining about the subject language is bound to attract disdain. As the Internet has grown, the absolute number of people in that "small percentage" has grown as well. A newbie can simply be unlucky enough to ask a question at the wrong time. If there has been a recent rash of problem posts then experts may accidentally respond negatively to a legitimate question. Of course, there are cross-cultural issues too. Many of the technical groups are English-language. English, even when polite, can seem harsh and/or abrupt to non-native speakers. On the whole, moderated groups are more conducive to helping newbies because the moderator(s) filter obvious red flag posts. And, finally, newbies themselves should realize that experts are donating time to answer questions and do get frustrated answering the same questions over and over. They should not be offended by "cold" responses that direct them to FAQs or that just give links to study material. Newbies who need hand-holding or warm welcoming responses filled with detail should go find a tutor. > ... you have the bad "professors" who are freaks >(probably they have a lot of problems at home, their wives >screwing all the males on the block, daughters drug addicts etc) >and want to take their hatred out on you, Unquestionably, there are experts who need their dosages adjusted. But the same can be said for some percentage of other users too. OTOH, newbies often aren't in the position to know who is an expert ... obviously, anyone able to correctly answer their question knows more about that specific issue. That doesn't necessarily qualify the responder as an "expert". Some people get defensive at the edges of their comfort zones. Just some thoughts. YMMV. George From daniel at stutzbachenterprises.com Fri Jul 23 17:26:59 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 23 Jul 2010 16:26:59 -0500 Subject: ANN: blist 1.2.0 In-Reply-To: References: Message-ID: On Wed, Jul 21, 2010 at 9:47 AM, Daniel Stutzbach < daniel at stutzbachenterprises.com> wrote: > What's new? > ----------- > > - blist.sort() is now *substantially* faster than list.sort() when using > int or float keys (O(n) vs. O(n log n)) > - The sortedset, sortedlist, and sorteddict types have been revamped for > better compatibility with the standard library's types. > - Comprehensive reference documentation is now available at > http://stutzbachenterprises.com/blist/ > - Numerous other speed improvements > Quick addendum: I just uploaded blist 1.2.1 which fixes a compilation error on BSD-derived systems (notably MacOS X). -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Jul 23 17:27:56 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 23 Jul 2010 22:27:56 +0100 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: On Fri, 23 Jul 2010 10:45:32 +0200, Thomas Guettler wrote: > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN > (Resource temporarily unavailable) on write(). My working code looks > like this. But I am unsure how many bytes have been written to the pipe > if I get an EAGAIN IOError. It should be zero; that's how the underlying system calls behave. If any bytes are read/written, the number of bytes are returned. The call only blocks (or fails with EAGAIN if non-blocking I/O is enabled) if it isn't possible to read/write any data. From nobody at nowhere.com Fri Jul 23 17:46:46 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 23 Jul 2010 22:46:46 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > Don't write bare excepts, always catch the error you want and nothing > else. That advice would make more sense if it was possible to know which exceptions could be raised. In practice, that isn't possible, as the documentation seldom provides this information. Even for the built-in classes, the documentation is weak in this regard; for less important modules and third-party libraries, it's entirely absent. From thomas at jollans.com Fri Jul 23 18:04:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 00:04:40 +0200 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4C4A11F8.3020905@jollans.com> On 07/23/2010 11:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. > In practice, at least in Python, it tends to be better to work the "other way around": first, write code without exception handlers. Test. If you get an exception, there are really two possible reactions: 1. "WHAT??" => This shouldn't be happening. Rather than catching everything, fix your code, or think it through until you reach conclusion #2 below. 2. "Ah, yes. Of course. I should check for that." => No problem! You're staring at a traceback right now, so you know the exception raised. If you know there should be an exception, but you don't know which one, it should be trivial to create condition in which the exception arises, should it not? Then, you can handle it properly, without resorting to guesswork or over-generalisations. From benjamin.kaplan at case.edu Fri Jul 23 18:04:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 15:04:46 -0700 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, Jul 23, 2010 at 2:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. > You still don't want to use bare excepts.People tend to get rather annoyed when you handle KeyboardInterrupts and SystemExits like you would a UnicodeError. Use Exception if you don't know what exceptions can be raised. From tjreedy at udel.edu Fri Jul 23 18:08:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:08:52 -0400 Subject: Easy questions from a python beginner In-Reply-To: <4c494e62$0$28634$c3e8da3@news.astraweb.com> References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c494e62$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 7/23/2010 4:10 AM, Steven D'Aprano wrote: > Using exec or friends to avoid the overhead of function calls is like > pushing your car to work to avoid the overhead of having to get in and > out of the car. And, of course, exec *is* a function call (explicitly in 3.x, but somewhere also in the innards of 2.x). Thanks for the laugh of the day. -- Terry Jan Reedy From f2h2d2 at gmail.com Fri Jul 23 18:14:08 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Fri, 23 Jul 2010 15:14:08 -0700 (PDT) Subject: Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ Message-ID: <233c48c4-2eb5-43a6-bedc-7a396d31228a@w12g2000yqj.googlegroups.com> Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ The Qur?an tells us a lot of wonderful things about Jesus. As a result, believers in the Qur?an love Jesus, honour him, and believe in him. In fact, no Muslim can be a Muslim unless he or she believes in Jesus, on whom be peace. The Qur?an says that Jesus was born of a virgin, that he spoke while he was still only a baby, that he healed the blind and the leper by God?s leave, and that he raised the dead by God?s leave. What then is the significance of these miracles? First, the virgin birth. God demonstrates his power to create in every way. God created everyone we know from a man and a woman. But how about Adam, on whom be peace? God created him from neither a man nor a woman. And Eve from only a man, but not a woman. And, finally, to complete the picture, God created Jesus from a woman, but not a man. What about the other miracles? These were to show that Jesus was not acting on his own behalf, but that he was backed by God. The Qur?an specifies that these miracles were performed by God?s leave. This may be compared to the Book of Acts in the Bible, chapter 2, verse 22, where it says that the miracles were done by God to show that he approved of Jesus. Also, note that Jesus himself is recorded in the Gospel of John to have said, ?I can do nothing of my own authority? (5:30). The miracles, therefore, were done not by his own authority, but by God?s authority. What did Jesus teach? The Qur?an tells us that Jesus came to teach the same basic message which was taught by previous prophets from God?that we must shun every false god and worship only the one true God. Jesus taught that he is the servant and messenger of that one true God, the God of Abraham. These Quranic teachings can be compared with the Bible ( Mark 10:18; Matthew 26:39; John 14:28, 17:3, and 20:17) where Jesus teaches that the one he worshipped is the only true God. See also Matthew 12:18; Acts 3:13, and 4:27 where we find that his disciples knew him as Servant of God. The Qur?an tells us that some of the Israelites rejected Jesus, and conspired to kill him, but Allah (God) rescued Jesus and raised him to Himself. Allah will cause Jesus to descend again, at which time Jesus will confirm his true teachings and everyone will believe in him as he is and as the Qur?an teaches about him. Jesus is the Messiah. He is a word from Allah, and a spirit from Him. He is honoured in this world and in the hereafter, and he is one of those brought nearest to Allah. Jesus was a man who spoke the truth which he heard from God. This can be compared with the Gospel According to John where Jesus says to the Israelites: ?You are determined to kill me, a man who has told you the truth that I heard from God? (John 8:40). The Virgin Birth of Jesus Muslims believe in the virgin birth of Jesus. When the angels announced to Mary (peace be upon her) about Allah?s promise that she will have a son, she was surprised, since she was a virgin. ?How can this be?? she thought. She was reminded that it is easy for Allah to create whatever he wills. She said: My Lord! How can I have a child when no mortal hath touched me? He said: So (it will be). Allah createth what He will. If He decreeth a thing, He saith unto it only: Be! and it is (Qur?an 3:47). It is not difficult for Allah to do anything he wants. He can create a child with both human parents or only one. No miracle is beyond His power. After all, He had created Adam (peace be upon him) from neither a man nor a woman. He created the rest of us from both man and woman. What is so hard if Allah decides to create a human being from a woman only? He only commands ?Be!? and it occurs. Some people think that since Jesus, peace be upon him, had no human father then God must be his father. The Qur?an rejects this view. The position of Jesus with Allah is comparable to the position of Adam with Allah. Just because Adam had no human parent does not mean we should call him the Son of God. Lo! the likeness of Jesus with Allah is as the likeness of Adam. He created him from dust, then He said unto him: Be! and he is. (Qur?an 3:59). According to the Qur?an, everyone except Allah are His servants. And they say: the Beneficent hath taken unto Himself a Son. Assuredly ye utter a disastrous thing, whereby almost the heavens are torn, and the earth is split asunder and the mountains fall to ruins, that ye ascribe to the Beneficent a son, when it is not meet for (the Majesty of) the Beneficent that He should chose a son. There is none in the heavens and the earth but cometh unto the Beneficent as a slave. (Qur?an 19:88-93) The Miracles of Jesus According to the Qur?an, Jesus, on whom be peace, performed the following miracles by Allah?s leave: 1. Spoke while he was only a baby. 2. Healed those born blind. 3. Healed the lepers. 4. Revived the dead. 5. Breathed life into a bird made of clay. In the Qur?an Allah quotes Jesus, peace be upon him, as saying: Lo! I come unto you with a sign from your Lord. Lo! I fashion for you out of clay the likeness of a bird, and I breathe into it and it is a bird by Allah?s leave. I heal him who was born blind, and the leper, and I raise the dead, by Allah?s leave. And I announce to you what you eat and what you store up in your houses. Lo! herein verily is a portent for you if you are to be believers. And (I come) confirming that which was before me of the Torah, and to make lawful some of that which was forbidden unto you. I come unto you with a sign from your Lord, so keep your duty to Allah and obey me. Lo! Allah is my Lord and your Lord, so worship Him. That is a straight path. (Qur?an 3: 49-51). Again, in the Qur?an Allah tells us about the situation on the Day of Judgement: In the day when Allah gathers together the messengers and says: What was your response (from mankind)? they say: We have no knowledge. Lo! Thou, only Thou art the Knower of Things Hidden. When Allah says: O Jesus, son of Mary! Remember My favour unto you and unto your mother; how I strengthened you with the holy Spirit, so that you spoke unto mankind in the cradle as in maturity; and how I taught you the ******ure and Wisdom and the Torah and the Gospel; and how you did shape of clay as it were the likeness of a bird by My permission, and did blow upon it and it was a bird by My permission, and you did heal him who was born blind and the leper by My permission . . . (Qur?an 5:109-110) Not all of these miracles are recorded in the canonical gospels, the four gospels contained in the Christian Bible. The fact that Jesus spoke while he was yet a baby is not written anywhere in the Bible. This should not be surprising, because none of the Gospels can claim to recover every single event in the life of Jesus. Instead, the gospel According to John seeks to emphasize that the events were too many to record. Similarly, the miracle of breathing life into a bird made of clay is not attested by the Christian Bible. This too should not make us wonder. It is obvious that the writers of the gospels could write down only the tradition that was available to them. Furthermore, they could not write down everything they knew about Jesus for they were writing on papyrus material that were very limited in length. What is worthy to notice here is that the Prophet Muhammad, may peace and the blessings of Allah be upon him, was honest enough to promulgate this information about Jesus. The religion taught by God through Muhammad would deny the divinity of Jesus. Any human being, therefore, who wished to deny the divinity of Jesus would have tried to belittle Jesus. Since Christians looked upon the miracles of Jesus as a proof of his divinity, we might expect that any human being who tries to deny the divinity of Jesus would not have informed people of miracles not previously known to them. He might have even tried to deny some of the miracles recorded in the canonical gospels. On the other hand, the prophet Muhammad honestly conveyed the message delivered to him from Allah. (May the peace and blessings of Allah be upon him.) Allah tells us the truth without fear. Human beings trying to win followers tell us only what is conducive to winning us over. They usually withhold information that could lead to opposite conclusions. On the other hand, Allah informs us about the miracles of Jesus even if people use this information to support their prior commitment to the doctrine of the divinity of Jesus. Allah does not need to win worshippers. Those who worship Allah does so for their own good. And those who worship false gods do so to their own detriment. What Allah emphasizes, though, is that the miracles of Jesus do not prove he was divine. The miracles he performed were a sign, a proof, that he was God?s messenger. He performed them with God?s help and permission. Those who use his miracles as proof of his divinity would choose to forget the following sayings of Jesus: I can of my own authority do nothing. (John 5:30) They also forget the declaration of Peter: Jesus of Nazareth, a man approved of God among you by miracles and wonders and signs, which God did by him in the midst of you, as ye yourselves know. (Acts 2:22 KJV). These passages suggest that Jesus did not do miracles on his own. These, rather were accomplished by God?s leave. Allah reminds us of this. Jesus also constantly repeated to his audience that the miracles he performed were by God?s leave. ------------------------------------------------------------------------------------------------------------------------------------------------------------ The True Message of Jesus Christ ????? ???? ?????? ?????? ?????? ????? ????? ???? ??????? The True Message of Jesus Christ Auther: Dr. Bilal Philips *******: Introduction Chapter One: The ******ures Authentic Manu******s Contradictions Chapter Two: The Person A Man "Evidence"For Jesus Divinity Chapter Three: The Message Chapter Four: The Way Conclusion Bibliography CHAPTER TWO: JESUS, THE PERSON As has been shown in the previous chapter, the Biblical ******ures, both New and Old Testaments, are unreliable sources and cannot, therefore, be used as an authentic means of knowing the truth about the man called Jesus Christ or about his mission and message. However, a close examination of these ******ures in the light of Qur?aanic verses will reveal some of the truths about Jesus that have survived in the Bible. A Messenger Throughout the Qur?aan, Jesus is identified fundamentally as a Messenger of God. In Chapter as-Saff (61):6, God quotes Jesus as follows: { ?????? ????? ?????? ????? ???????? ???????? ??????????? ?????? ??????? ????? ?????????? ?????????? ?????? ?????? ??????? ???? ??????????? } ?And [remember] when Jesus, son of Mary, said: ?O Children of Israel, I am the messenger of Allaah sent to you, confirming the Torah [which came] before me.? There are many verses in the New Testament supporting the messengership / prophethood of Jesus. The following are only a few: In Matthew 21:11, the people of his time are recorded as referring to Jesus as a prophet: ?And the crowds said, ?This is the prophet Jesus of Nazareth of Galilee.? ? In Mark, 6:4, it is stated that Jesus referred to himself as a prophet: ?And Jesus said to them, ?A prophet is not without honour, except in his own country, and among his own kin, and in his own house.? ? In the following verses, Jesus is referred to as having been sent as a messenger is sent. In Matthew 10:40, Jesus was purported to have said: ?He that receiveth you receiveth me, and he that receiveth me receiveth him that sent me.? In John 17:3, Jesus is also quoted as saying: ?And this is life eternal, that they might know thee the only true God, and Jesus Christ, whom thou hast sent.? [1] ==================== A Man The Qur?aanic revelation not only affirms Jesus? prophethood, but it also clearly denies Jesus? divinity. In Chapter al-Maa?idah, (5): 75, God points out that Jesus ate food, which is a human act, obviously not befitting to God. { ??? ?????????? ????? ???????? ?????? ??????? ???? ?????? ???? ???????? ????????? ????????? ?????????? ?????? ??????????? ?????????? ??????? ?????? ????????? ?????? ????????? ????? ??????? ?????? ???????????} ?The Messiah, Son of Mary, was no more than a messenger and many messengers passed away before him. His mother was exceedingly truthful, and they both ate food. See how I have made the signs clear for them, yet see how they are deluded.? There are numerous accounts in the New Testament which also deny Jesus? divinity. For example, in Matthew 19:17, Jesus responded to one who addressed him as ?O good master?, saying: ?Why callest thou me good? There is none good but one, that is God.? If he rejected being called ?good?, [2] and stated that only God is truly good, he clearly implies that he is not God. In John 14:28, Jesus was saying: ?The Father is greater than I.? By stating that the ?Father? is greater than himself, Jesus distinguishes himself from God. Also in John 20:17, Jesus told Mary Magdalene to tell his followers: ?I ascend unto my Father and your Father; and to my God and your God.? Jesus? reference to God as ?my Father and your Father? further emphasizes the distinction between himself and God. Furthermore, by referring to God as ?his God?, he left no room for anyone to intelligently claim that he was God. Even in some of the writings of Paul, which the Church has taken to be sacred, Jesus is referred to as a ?man?, distinct and different from God. In 1st Timothy, 2:5, Paul writes: ?For there is one God, and one mediator between God and men, the man Christ Jesus.? There are also verses in the Qur?aan which confirm Prophet Muhammad?s humanity, in order to prevent his followers from elevating him to a divine or semi-divine status, as was done to Prophet Jesus. For example, in Chapter al-Kahf (18):110, Allaah instructs the Prophet Muhammad (e) to inform all who hear his message: { ???? ???????? ?????? ?????? ?????????? ?????? ??????? ???????? ?????????? ????? ??????? } ?Say: ?Indeed, I am only a man like you to whom it has been revealed that your God is only one God.? ? In Chapter al-A?raaf (7):187, Allaah also directed Prophet Muhammad (e) to acknowledge that the time of the Judgement is known only to God. {????????????? ???? ?????????? ???????? ?????????? ???? ???????? ????????? ?????? ?????? ??? ??????????? ??????????? ?????? ???? } ?They ask you about the Final Hour: 'When will its apointed time be?? Say: ?Knowledge of it is with my Lord. None can reveal its time besides Him.? ? In the Gospel according to Mark 13:31-32, Jesus is also reported to have denied having knowledge of when the final hour of this world would be, saying: ?Heaven and the earth shall pass away but my word shall not pass away, but of that day or hour no man knoweth, neither the angels in the heaven nor the Son but the Father.? One of the attributes of God is omniscience, knowledge of all things. Therefore, his denial of knowledge of the Day of Judgement is also a denial of divinity, for one who does not know the time of the final hour cannot possibly be God .[3] An Immaculate Conception The Qur?aan confirms the Biblical story of Jesus? virgin birth. However, in the Qur?aanic account of Jesus? birth, Mary was an unmarried maiden whose life was dedicated to the worship of God by her mother. While she was worshipping in a place of religious seclusion, angels came and informed her of her impending pregnancy. { ???? ??????? ???????????? ??? ???????? ????? ????? ??????????? ?????????? ?????? ??????? ??????????? ?????? ????? ???????? ???????? ??? ????????? ?? ?????????? ?????? ??????????????} ?When the angels said: ?O Mary, indeed Allaah gives you glad tidings of a Word from Him, whose name will be the Messiah, Jesus the son of Mary. He will be honored in this world and the next and will be of those close to Allaah.? ? Qur?aan, (3):45 { ??????? ????? ?????? ??????? ??? ?????? ?????? ??????????? ?????? ????? ???????? ????? ???????? ??? ??????? ????? ????? ??????? ?????????? ??????? ???? ???? ????????? } ?She said: ?O my Lord, how can I have a son when no man has touched me?? He said: ?Even so?Allaah creates what He wishes. When He decrees something, He only has to say to it: ?Be!? and it is.? ? Qur?aan, (3): 47 However, the Qur?aan clarifies that Jesus? virgin birth did not change the state of his humanity. His creation was like the creation of Aadam, who had neither father nor mother. { ????? ?????? ?????? ?????? ????? ???????? ????? ???????? ???? ??????? ????? ????? ???? ???? ????????? } ?Surely, the example of Jesus, in Allaah?s sight, is like that of Aadam. He created him from dust and said: ?Be!? and he was.? Qur?aan, (3):59 The Miracles The Qur?aanic account of Jesus? ministry confirms most[4] of his miracles mentioned in the Bible and identifies some not mentioned in the Bible. For example, the Qur?aan informs that Jesus was a messenger of God from his birth, and his first miracle was speaking as a child in the cradle. After Mary had given birth to Jesus, people accused her of fornication. Instead of responding to their accusations, she pointed to her newly born child: { ??????????? ???????? ??????? ?????? ????????? ???? ????? ??? ????????? ???????? ????? ?????? ?????? ????? ???????? ?????????? ??????????? ????????} ?[When] she pointed to him, they asked, ?How can we talk to a child in the cradle?? He [Jesus] said: ?Indeed, I am a servant of Allaah. He gave me the ******ure and made me a prophet.? ? Qur?aan, (19):29-30 Among his other miracles of bringing the dead back to life, healing lepers, and making the blind see, the Qur?aan records another miracle not mentioned in the Bible. Prophet Jesus fashioned birds out of clay, blew on them and they flew away, living birds. But the point which is emphasized throughout the Qur?aan is that whenever Jesus performed a miracle, he informed the people that it was by God?s permission. He made it clear to his followers that he was not doing the miracles by himself, in the same way that the earlier Prophets made it clear to those around them. Unfortunately, those who claim divinity for Jesus, usually hold up his miracles as evidence. However, other prophets were recorded to have done the same or similar miracles in the Old Testament. Jesus fed 5,000 people with five loaves of bread and two fishes. Elisha fed 100 people with twenty barley loaves and a few ears of corn (II Kings 4:44) Jesus healed lepers. Elisha cured Naaman the leper (II Kings 5:14). Jesus caused the blind to see. Elisha caused the blind to see (II Kings 6:17&20). Jesus raised the dead. Elijah did the same (I Kings 17:22). So did Elisha (II Kings 4:34). Even Elisha?s bones could restore the dead (II Kings 13:21). Jesus walked on water. Moses and his people crossed the dead sea (Exodus 14:22). There are also ****s in the New Testament which confirm that Jesus did not act on his own. Jesus is quoted in John 5:30, as saying: ?I can of mine own self do nothing...? and in Luke 11:20, as saying, ?But if I with the finger of God cast out devils, no doubt the Kingdom of God is come upon you.? In Acts 2:22, Paul writes: ?Men of Israel, hear these words: Jesus of Nazareth, a man attested to you by God with mighty works and wonders and signs which God did through him in your midst, as you yourselves know...? Is the message of Prophet Jesus to the worlds or the children of Israel only? http://www.imanway.com/vb/showthread...5500 # post85500 Jesus said, "I am the way and no one up to the father except through me" http://www.imanway.com/vb/showthread...2091 # post92091 The Bible itself shows a lack of Christ's crucifixion and that no one else has the heart http://www.imanway.com/vb/showthread...2282 # post82282 Gospel of Judas (to prove that the heart of Jesus Christ peace be upon him) http://www.imanway.com/vb/showthread.php?t=14478 Do you send Christ to be crucified? http://www.imanway.com/vb/showthread.php?t=2588 Proof of the prophethood of the Prophet Jesus in the Bible http://www.imanway.com/vb/showthread.php?t=2610 Meaning of the word "Christ" http://www.imanway.com/vb/showthread.php?t=2607 Jesus between Islam and Christianity http://www.imanway.com/vb/showthread.php?t=13716 Prophet Jesus peace be upon him (Abdullah) in the Qur'an and the Bible http://www.imanway.com/vb/showthread.php?t=10772 Paul is the invention of modern Christianity and destroyed the original message of Christ http://www.imanway.com/vb/showthread...0361 # post80361 Confessions of the Christians themselves not credible Gospels http://www.imanway.com/vb/showthread.php?t=2626 Christian scholars recognize contradictory texts in the Bible http://www.imanway.com/vb/showthread.php?t=2625 Description of God (exalted above what they attribute) in the Bible http://www.imanway.com/vb/showthread.php?t=2640 Muslims pray as the Prophet Jesus prayed http://www.imanway.com/vb/showthread.php?t=2656 Muslim Peace Xlam prophet Jesus peace be upon him http://www.imanway.com/vb/showthread.php?t=2655 Who is the "Emmanuel" (Emmanuel: God with us means) Christians believe that Jesus Christ but it is only the name of another person, the name of a person shows God's help us and not the fact (that God is with us and us in the form of human being) http://www.imanway.com/vb/showthread.php?t=2653 Who is the "Melchizedek" or the king of peace (not the prophet Jesus given that he mentioned (the guide was born)) http://www.imanway.com/vb/showthread.php?t=2652 Is the Bible the Word of God? (Sheikh Ahmed Deedat God's mercy) http://jamaat.net/bible/BibleIntro.html Recognition of the founder of Christianity distorted (Paul) twisting the Bible http://www.imanway.com/vb/showthread.php?t=2623 Destruction of the principles and instructions of the prophet Jesus peace be upon him Graphically http://www.imanway.com/vb/showthread.php?t=2622 History of the foundation, "Trinity or Triangulation" http://www.imanway.com/vb/showthread.php?t=2621 Random evidence of modern Christian thought http://www.imanway.com/vb/showthread.php?t=2620 Prophet Jesus did not say never "was the right", he was calling to worship God alone (according to the Bible) http://www.imanway.com/vb/showthread.php?t=2619 Erroneous translation of the Bible word for "worship of Christ" http://www.imanway.com/vb/showthread.php?t=2618 What the Bible says the sin of Adam? http://www.imanway.com/vb/showthread...3994 # post83994 Who forgives sins? http://www.imanway.com/vb/showthread.php?t=2617 Lifting of the prophet Jesus does not indicate his divinity http://www.imanway.com/vb/showthread.php?t=2616 What about the previous nations that have not contemporary with Jesus Christ? Has not been invited to the faith and the Trinity Steel http://www.imanway.com/vb/showthread.php?t=2615 Evidence to refute the divinity of Christ, peace be upon him http://www.imanway.com/vb/showthread.php?t=2614 God calls Christ "Abdi (according to the Gospel)" so it is not unreasonable to have his son and call him so http://www.imanway.com/vb/showthread.php?t=2613 May God, "Isa (as they claim)," he prayed for himself? http://www.imanway.com/vb/showthread.php?t=2612 Code is "Da Vinci" http://www.imanway.com/vb/showthread.php?t=15166 Discuss the idea of "text from the Bible" Itallon the divinity of Christ http://www.imanway.com/vb/showthread.php?t=2608 The word "father" in the Bible did not mean the real father of Christ and the directory as stated more than one person http://www.imanway.com/vb/showthread.php?t=2605 Miracles of the Prophet Jesus does not indicate his divinity and the evidence that more than a prophet had miracles http://www.imanway.com/vb/showthread.php?t=2604 Some churches believe in the Prophethood of Jesus Christ peace be upon him http://www.imanway.com/vb/showthread.php?t=2603 Refute the idea of the Trinity scientifically (analogy with water, ice and steam) http://www.imanway.com/vb/showthread.php?t=2602 Logical analysis http://www.imanway.com/vb/showthread.php?t=2599 Discuss the idea of triangulation and the greatest sin http://www.imanway.com/vb/showthread.php?t=2598 How the son of God? (I ask forgiveness from God) http://www.imanway.com/vb/showthread.php?t=2589 How mixed with polytheistic religion Christianity ideas? http://www.imanway.com/vb/showthread.php?t=2586 Questions from a Christian to Sheikh Mohammed Locket http://www.imanway.com/vb/showthread...0169 # post80169 Answer Question: Why do Muslims hate Jesus http://www.imanway.com/vb/showthread.php?t=16150 What Jesus said about the celebration of Christmas? http://www.imanway.com/vb/showthread...2283 # post92283 From tjreedy at udel.edu Fri Jul 23 18:21:06 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:21:06 -0400 Subject: Function closure inconsistency In-Reply-To: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> References: <863372cf-8230-4929-9f1a-1021eb85fc6c@c10g2000yqi.googlegroups.com> Message-ID: On 7/23/2010 2:30 PM, SeanMon wrote: > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): > x = 0 > def g(): In 3.x, add nonlocal x > x += 1 > return x > return g1 You meant g def f1(): x = 0 def g(): nonlocal x x += 1 return x return g f=f1() print(f()) print(f()) print(f()) print(f()) 1 2 3 4 -- Terry Jan Reedy From tjreedy at udel.edu Fri Jul 23 18:27:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 23 Jul 2010 18:27:50 -0400 Subject: Unicode error In-Reply-To: References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On 7/23/2010 5:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. I intend to bring that issue up on pydev list sometime. But in the meanwhile, once you get an error, you know what it is. You can intentionally feed code bad data and see what you get. And then maybe add a test to make sure your code traps such errors. -- Terry Jan Reedy From db3l.net at gmail.com Fri Jul 23 18:43:31 2010 From: db3l.net at gmail.com (David Bolen) Date: Fri, 23 Jul 2010 18:43:31 -0400 Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: Neil Cerutti writes: > On 2010-07-23, Jim wrote: >> How can I calculate how much time is between now and the next >> 2:30 am? Naturally I want the system to worry about leap >> years, etc. > > You need the datetime module. Specifically, a datetime and > timedelta object. Although it sounds like the question is to derive the timedelta value, so it's not known up front. That's a little trickier since you'd need to construct the datetime object for "next 2:30 am" to subtract "now" from to get the delta. But that requires knowing when the next day is, thus dealing with month endings. Could probably use the built-in calendar module to help with that though. For the OP, you might also take a peek at the dateutil third party module, and its relativedelta support, which can simplify the creation of the "next 2:30 am" datetime object. Your case could be handled by something like: from datetime import datetime from dateutil.relativedelta import relativedelta target = datetime.now() + relativedelta(days=+1, hour=2, minute=30, second=0, microsecond=0) remaining = target - datetime.now() This ends up with target being a datetime instance for the next day at 2:30am, and remaining being a timedelta object representing the time remaining, at least as of the moment of its calculation. Note that relativedelta leaves fields alone that aren't specified, so since datetime.now() includes down to microseconds, I clear those explicitly). Since you really only need the date, you could also use datetime.date.today() instead as the basis of the calculation and then not need second/microsecond parameters to relativedelta. -- David From lists at cheimes.de Fri Jul 23 19:24:33 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 24 Jul 2010 01:24:33 +0200 Subject: time between now and the next 2:30 am? In-Reply-To: References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: > Your case could be handled by something like: > > from datetime import datetime > from dateutil.relativedelta import relativedelta > > target = datetime.now() + relativedelta(days=+1, hour=2, minute=30, > second=0, microsecond=0) > remaining = target - datetime.now() You don't need the dateutil package for the trick: >>> dt = datetime(2010, 1, 1, 1, 0) >>> str(dt) '2010-01-01 01:00:00' >>> next = dt.replace(hour=2, minute=30) >>> next - dt datetime.timedelta(0, 5400) >>> (next - dt).seconds 5400 >>> dt = datetime(2010, 1, 1, 3, 0) >>> next = dt.replace(hour=2, minute=30) >>> next - dt datetime.timedelta(-1, 84600) >>> (next - dt).seconds 84600 From jim.hefferon at gmail.com Fri Jul 23 19:36:43 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 23 Jul 2010 16:36:43 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> Message-ID: <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Thank you again to everyone; I greatly appreciate the help. I ended with essentially what Christian advised and it seems to work fine. FWIW, below is the rouine (I couldn't figure out how to do it without the kludgy x variable). The background is that this is a Django context processor that makes available the time until the next 2:30 because that is when the web site is rebuilt. I hope the code isn't too much mangled by the online editor, Jim ............................................................................. import time, datetime from django.conf import settings WARNING_MINS=10 # How many mins before update time should start warning? WARNING_SECS=60*WARNING_MINS def current_time_processor(req): """Add current time information to the Context """ # Calculate time until the next 2:30 am x=datetime.datetime(2010,7,23) # actual date doesn't matter? dt_localtime=x.fromtimestamp(time.time()) dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=settings.UPDATE_TIME_MINS,second=0,microsecond=0) dd_diff=dt_twothirty-dt_localtime secs_until_twothirty=dd_diff.seconds if secs_until_twothirty Hey Everyone, I had a question, programming sockets, what are the things that would degrade performance and what steps could help in a performance boost? I would also appreciate being pointed to some formal documentation or article. I am new to this. Warm regards, Nav From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:52 +0000 (UTC) Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: > Is there a more idiomatic way of loading in a configuration file > that's python code ... Is it really a good idea to have a configuration language that?s Turing- complete? From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:53 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: In message , Tim Harig wrote: > On 2010-07-05, Lawrence D'Oliveiro > wrote: >> >> I?ve never come across any system where you could string together >> multiple GUI apps, or even multiple GUI operations in the same app, in >> any sensible or effective way at all. GUIs just aren???t designed to work >> that way. > > You can if they are designed to be used externally. COM is an execellent > example of this ... But COM is an IPC architecture, which has nothing to do with GUI apps. Conflating the two leads to precisely the sort of inflexibility that is characteristic of GUIs. For example, things happening with the GUI on-screen while a script is running that are at best distracting to the user, or at worst vulnerable to breaking if the user accidentally presses a key or clicks in the wrong place. > I have worked with complex business process automation centered around > Excel and I have automated some really ugly AJAX style web based > applications that would only work inside of IE6 by accessing IE through > its COM interface. If those apps really were using AJAX, then why did you need to script a Web browser at all? You could just make direct HTTP requests to retrieve the data. > Automating GUI applications requires interal access to the program through > some kind of interface ... Some kind of interface that bypasses the GUI. This is why so many Open Source apps are structured as a GUI front end to a completely separate command-line tool (e.g. MPlayer). That way a script can use the latter without having to go through the former. From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:54 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: In message , Robert Kern wrote: > There are also utilities for mounting ISOs directly without burning them > to a physical disk. You need special utilities to do this?? From ldo at geek-central.gen.new_zealand Fri Jul 23 20:08:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 24 Jul 2010 00:08:55 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <034b84d2-19ac-42dc-8a9b-ed4e4ad98a7f@s9g2000yqd.googlegroups.com> Message-ID: In message , Michael Torrie wrote: > While it's possible to set up pipes and spawn programs in parallel to > operate on the pipes, in practice it's simpler to tell subprocess.Popen > to use a shell and then just rely on Bash's very nice syntax for setting > up the pipeline. Just be careful about properly escaping any special characters in the file names. See my other thread about escaping data, where some respondents have expressed a strong allergy to any form of embedding one language inside another. From robert.kern at gmail.com Fri Jul 23 20:31:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Jul 2010 19:31:37 -0500 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: > In message, Robert Kern > wrote: > >> There are also utilities for mounting ISOs directly without burning them >> to a physical disk. > > You need special utilities to do this?? On at least some versions of Windows, Yes. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From python at mrabarnett.plus.com Fri Jul 23 20:52:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 01:52:10 +0100 Subject: time between now and the next 2:30 am? In-Reply-To: <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Message-ID: <4C4A393A.6050807@mrabarnett.plus.com> Jim wrote: > Thank you again to everyone; I greatly appreciate the help. I ended > with essentially what Christian advised and it seems to work fine. > FWIW, below is the rouine (I couldn't figure out how to do it without > the kludgy x variable). The background is that this is a Django > context processor that makes available the time until the next 2:30 > because that is when the web site is rebuilt. > > I hope the code isn't too much mangled by the online editor, > Jim > > ............................................................................. > > import time, datetime > from django.conf import settings > > WARNING_MINS=10 # How many mins before update time should start > warning? > WARNING_SECS=60*WARNING_MINS > > def current_time_processor(req): > """Add current time information to the Context > """ > # Calculate time until the next 2:30 am > x=datetime.datetime(2010,7,23) # actual date doesn't matter? > dt_localtime=x.fromtimestamp(time.time()) > Why not: dt_localtime = datetime.datetime.now() > dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=settings.UPDATE_TIME_MINS,second=0,microsecond=0) You're changing the time of day, but not the date. You might want to add a day to the shutdown time if it's earlier than the current time. > dd_diff=dt_twothirty-dt_localtime > secs_until_twothirty=dd_diff.seconds > if secs_until_twothirty w='This site shuts down every night at %02d:%02d local time, > to refresh the database. There are fewer than %d minutes until that > shutdown. If you have not completed your work when the site shuts > down then you will lose your work.' % > (settings.UPDATE_TIME_HOURS,settings.UPDATE_TIME_MINS,WARNING_MINS,) > else: > w=None > return {'CURRENT_LOCAL_TIME': time.asctime(time.localtime()), > 'TIME_WARNING':w} From ben+python at benfinney.id.au Fri Jul 23 20:53:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 24 Jul 2010 10:53:35 +1000 Subject: loading configuration files that are themselves python References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> Message-ID: <87mxth66pc.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: > > > Is there a more idiomatic way of loading in a configuration file > > that's python code ... > > Is it really a good idea to have a configuration language that?s Turing- > complete? I think not. Configuration files should be read as data; they should be declarative only, not executable languages. That way, a different program can read and parse them without having to be a parser for an entire programming language. As illustration of this point, I present the chronic headaches of the Python ?setup.py? file. It tries to be both setup program *and* configuration file, with the consequence that in the general case it's impossible to get configuration information without executing the setup program. Recent work (lots of it!) by the Distutils team has gone into separating the concerns so that the configuration data is all in a non-executable data file; that work is ongoing, and it's been a hard lesson to learn. -- \ ?If [a technology company] has confidence in their future | `\ ability to innovate, the importance they place on protecting | _o__) their past innovations really should decline.? ?Gary Barnett | Ben Finney From python at mrabarnett.plus.com Fri Jul 23 21:04:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 02:04:51 +0100 Subject: Socket performance In-Reply-To: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> Message-ID: <4C4A3C33.80407@mrabarnett.plus.com> Navkirat Singh wrote: > Hey Everyone, > > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? I > would also appreciate being pointed to some formal documentation or > article. > > I am new to this. > Interleaving processing and sending/receiving might reduce throughput because when you're processing the socket is idle (depending on how much buffering there is). You could do the socket stuff in another thread so that it's not waiting for the processing to finish while there is data available, and use a queue to transfer the data between that thread and the processing thread. From navkirats at gmail.com Fri Jul 23 22:22:53 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sat, 24 Jul 2010 07:52:53 +0530 Subject: Socket performance In-Reply-To: <4C4A3C33.80407@mrabarnett.plus.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> <4C4A3C33.80407@mrabarnett.plus.com> Message-ID: <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> Thanks for the info : ). I will look into it ! Right now I am having a strange problem. I am trying to use cookies and the import function returns an error: I am using python 3: from http import cookies importError: No module named http Is it my configuration or has something changed since the documentation was written? Sorry I might be asking too many question, I am pretty new to this stuff and kinda feel lost here and there : ( Thanks, Nav On 24-Jul-2010, at 6:34 AM, MRAB wrote: > Navkirat Singh wrote: >> Hey Everyone, >> I had a question, programming sockets, what are the things that >> would degrade performance and what steps could help in a >> performance boost? I would also appreciate being pointed to some >> formal documentation or article. >> I am new to this. > Interleaving processing and sending/receiving might reduce throughput > because when you're processing the socket is idle (depending on how > much > buffering there is). You could do the socket stuff in another thread > so > that it's not waiting for the processing to finish while there is data > available, and use a queue to transfer the data between that thread > and > the processing thread. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From darkrho at gmail.com Fri Jul 23 22:42:28 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 23 Jul 2010 22:42:28 -0400 Subject: understanding the mro (long) Message-ID: TL;DR: if you want to stay sane, don't inherit two classes that share same inheritance graph I recently got puzzled by a bug from a legacy lib (ClientForm) which have this code: class ParseError(sgmllib.SGMLParseError, HTMLParser.HTMLParseError, ): pass And fails because takes __init__ from sgmllib and __str__ from HTMLParser where __str__ uses attributes set by HTMLParser's init. At first look, I thought was just matter to swap the inherit classes. But a deeper look take me to the python's mro reading: http://www.python.org/download/releases/2.3/mro/ And to reproduce the error I code this: class Foo(object): def __init__(self, msg): self.msg = msg def __str__(self): return 'Foo: ' + self.msg class Bar(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return 'Bar: ' + self.msg class A(Exception): pass class B(RuntimeError): pass class AFoo(A, Foo): pass class ABar(A, Bar): pass class BFoo(B, Foo): pass class BBar(B, Bar): pass print AFoo('ok') # ok print ABar('ok') # Bar: ok print BFoo('ok') # ok print BBar('fail') # AttributeError: ... not attribute 'msg' # EOF After running the code I was still confused. So I read carefully again the mro stuff. And ended doing this inheritance tree: object (__init__, __str__) | \ | Foo (__init__, __str__) | BaseException (__init__, __str__) | | | Exception (__init__) / | \ A | Bar (__init__, __str__) | StandardError (__init__) | | | RuntimeError (__init__) / B Then I figure out the method resolution following the inheritance graph: * AFoo(A, Foo): __init__ from Exception __str__ from BaseException * ABar(A, Bar): __init__ from Bar __str__ from Bar * BFoo(B, Foo): __init__ from RuntimeError __str__ from BaseException * BBar(B, Bar): __init__ from RuntimeError __str__ from Bar Finally everything make sense. And make think about be careful when doing multiple inheritance. Any thoughts? ~Rolando From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 22:44:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 02:44:15 GMT Subject: Easy questions from a python beginner References: <4C3A0F79.8070502@ixokai.io> <2a635610-bcf7-4b3f-b7e0-d2a1b574fc2d@d37g2000yqm.googlegroups.com> <4c495b50$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4a537e$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 09:22:16 -0700, Stephen Hansen wrote: > On 7/23/10 2:05 AM, Steven D'Aprano wrote: >> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote: >> >>> On 7/22/10 7:47 PM, wheres pythonmonks wrote: >> [...] >>>> The truth is that I don't intend to use these approaches in anything >>>> serious. However, I've been known to do some metaprogramming from >>>> time to time. >>> >>> Depending on how you define "metaprogramming", Python is pretty >>> notoriously ill-suited towards the task (more, its basically >>> considered a feature it doesn't let you go there) -- or, it allows you >>> to do vast amounts of stuff with its few dark magic hooks. I've never >>> had a satisfying definition of metaprogramming that more then 50% of >>> any group agree with, so I'm not sure which you're looking for. :) >> >> I disagree strongly at your characterisation that Python is notorious >> for being ill-suited towards metaprogramming. I'd say the complete >> opposite -- what is considered dark and scary metaprogramming tasks in >> other languages is considered too ordinary to even mention in Python. > > I rather think you missed my point entirely. > > 'Depending on how you define "metaprogramming"' > > The 'Depending' was the most important part of that sentence. Well, I suppose some folks might like to define words any way they like, so that "cat" means a reptile with no legs and "lunch time" means the thing you do in the shower, but I prefer to stick with common definitions. And the common definition of metaprogramming is that it is "programming about programming" -- programming where the data you are processing is itself programming code and data structures. http://en.wikipedia.org/wiki/Metaprogramming I did not miss your proviso, nor did I miss the fact that there are some metaprogramming techniques that Python is not very good at, such as runtime modification of syntax. I wrote: "It is true that other languages (like Lisp, or Forth) allow you to write your own syntax. That's incredibly powerful, but it also has serious costs. If you can define your own syntax, that means every piece of code you look at is potentially a different language." But what makes you think that the OP is trying to do that? There's nothing in his comments to indicate that to me. Perhaps I missed something. > You go on > to talk about runtime modification of classes and the like. That, Python > lets you do quite readily, and then go on to do crazy amounts of without > any significant effort. > > That's one definition of metaprogramming. That one Python does well. No, it's not a *definition* of metaprogramming. It is an aspect of metaprogramming, in the same way that roasting food is not a definition of cooking, it is one out of many cooking techniques. > The other involves things like macros, or things where you basically > write a new sub-language in the language itself to achieve some commonly > desired task more efficiently (or just more succinctly). That's another > definition of metaprogramming: where its not so much structures > (classes, etc) which are modified at runtime (which Python lets you do > readily), but the syntax or semantics of the language itself. That > Python isn't game for. You can't modify Python's syntax at runtime, but you can create DSLs in Python quite readily provided you accept the limitation of Python's syntax. There was even a tutorial at PyCon about it: http://us.pycon.org/2010/tutorials/jensen_languages/ Although he doesn't use the term "DSL" anywhere in his essay, Guido's essay on creating graphs in Python essentially describes a DSL for graphs: http://www.python.org/doc/essays/graphs/ In the Python Cookbook, Paul Dubois also gives an "application-specific- language" for graphs in a section called "Using Python Itself as a Little Language". Yes, it's limited to Python syntax, but it's still a DSL. And of course there are applications like Cheetah: http://www.cheetahtemplate.org/ Python doesn't go all the way like Forth or Lisp, but there aren't very many metaprogramming techniques you can't do it in. -- Steven From python at mrabarnett.plus.com Fri Jul 23 22:48:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Jul 2010 03:48:39 +0100 Subject: Socket performance In-Reply-To: <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> References: <78AA6981-FB69-4B8C-8798-68298DB0F091@gmail.com> <4C4A3C33.80407@mrabarnett.plus.com> <9DE19979-D279-4A14-85D8-0E5863C0C6CD@gmail.com> Message-ID: <4C4A5487.9030900@mrabarnett.plus.com> Navkirat Singh wrote: > Thanks for the info : ). I will look into it ! Right now I am having a > strange problem. I am trying to use cookies and the import function > returns an error: > > I am using python 3: > > from http import cookies > > *importError:* No module named http > > Is it my configuration or has something changed since the documentation > was written? Sorry I might be asking too many question, I am pretty new > to this stuff and kinda feel lost here and there : ( > It works for me (Python 3.1.2). From invalid at invalid.invalid Fri Jul 23 23:05:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 24 Jul 2010 03:05:12 +0000 (UTC) Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: On 2010-07-24, Lawrence D'Oliveiro wrote: > In message , Robert Kern > wrote: > >> There are also utilities for mounting ISOs directly without burning >> them to a physical disk. > > You need special utilities to do this?? Not if the OS and VFS are competently designed. In Linux all you need to do is this: mount -o loop /path/to/file.iso /mount/point Apparently you've got to jump through all sorts of hoops using 3rd party software to do something analgous in MS Windows. -- Grant From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 23:09:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 03:09:06 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4a5951$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 22:46:46 +0100, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +0000, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice, that isn't possible, as the > documentation seldom provides this information. Even for the built-in > classes, the documentation is weak in this regard; for less important > modules and third-party libraries, it's entirely absent. Aside: that's an awfully sweeping generalisation for all third-party libraries. Yes, the documentation is sometimes weak, but that doesn't stop you from being sensible. Catching any exception, no matter what, whether you've heard of it or seen it before or not, is almost never a good idea. The two problems with bare excepts are: * They mask user generated keyboard interrupts, which is rude. * They hide unexpected errors and disguise them as expected errors. You want unexpected errors to raise an exception as early as possible, because they probably indicate a bug in your code, and the earlier you see the exception, the easier it is to debug. And even if they don't indicate a bug in your code, but merely an under- documented function, it's still better to find out what that is rather than sweep it under the carpet. You will have learned something new ("oh, the httplib functions can raise socket.error as well can they?") which makes you a better programmer, you have the opportunity to improve the documentation, you might want to handle it differently ("should I try again, or just give up now, or reset the flubbler?"). If you decide to just mask the exception, rather than handle it in some other way, it is easy enough to add an extra check to the except clause. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 23 23:15:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 03:15:31 GMT Subject: understanding the mro (long) References: Message-ID: <4c4a5ad3$0$28634$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 22:42:28 -0400, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph > > I recently got puzzled by a bug from a legacy lib (ClientForm) which > have this code: [...] > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? Wow. Nice work, thanks for taking the time for documenting this publicly. -- Steven From eldiener at tropicsoft.invalid Fri Jul 23 23:17:19 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 23 Jul 2010 23:17:19 -0400 Subject: Multiple versions of Python coexisting in the same OS Message-ID: Are there any documents about multiple versionsof Python coexisting in the same OS ( Windows in my case ) and what pitfalls to look out for ? I have already run into a number of them. I installed Python 2.7 and 3.1.2 into completely folders, but immediately ran into serious problems executing a Python script. The first problem is that just invoking Python will start whichever version is first in the PATH, and this is true from the command line or internally in a Python script. The second problem is that invoking a script ( some xxx.py ) will start whichever version of Python is associated with the .py extension. The third problem is if some software expects its scripts, which it puts in some Python subdirectory to be in the PATH. There may be other considerations but overall having to versions coexisting has turned out to be a big headache involving both changes in the PATH and in the .py association. Does anybody know of other things to look out for ? From zzbbaadd at aol.com Sat Jul 24 00:27:45 2010 From: zzbbaadd at aol.com (TheFlyingDutchman) Date: Fri, 23 Jul 2010 21:27:45 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> Message-ID: <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> On Jul 23, 12:06?pm, Emmy Noether wrote: > Title ? Portable LISP interpreter > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > Publication Date ? ? ? ?1978 May 31 > OSTI Identifier OSTI ID: 7017786 > Report Number(s) ? ? ? ?UCRL-52417 > DOE Contract Number ? ? W-7405-ENG-48 > Resource Type ? Technical Report > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > Lab. > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > PROGRAMMING LANGUAGES > Description/Abstract ? ?A portable LISP interpreter that includes all the > major list-processing functions is described. A complete, annotated > listing of the program's code, written in PASCAL, is included. > Country of Publication ?United States > Language ? ? ? ?English > Format ?Medium: X; Size: Pages: 21 > Availability ? ?Dep. NTIS, PC A02/MF A01. > System Entry Date ? ? ? 2008 Feb 12 Is this available online? If only in hardcopy form, do they lend it out? From benjamin.kaplan at case.edu Sat Jul 24 00:28:55 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 23 Jul 2010 21:28:55 -0700 Subject: understanding the mro (long) In-Reply-To: References: Message-ID: On Fri, Jul 23, 2010 at 7:42 PM, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph > > I recently got puzzled by a bug from a legacy lib (ClientForm) > which have this code: > > ? ?class ParseError(sgmllib.SGMLParseError, > ? ? ? ? ? ? ? ? ? ? HTMLParser.HTMLParseError, > ? ? ? ? ? ? ? ? ? ? ): > ? ? ? ?pass > > And fails because takes __init__ from sgmllib and __str__ from HTMLParser > where __str__ uses attributes set by HTMLParser's init. > > At first look, I thought was just matter to swap the inherit classes. > But a deeper > look take me to the python's mro reading: > http://www.python.org/download/releases/2.3/mro/ > > And to reproduce the error I code this: > > class Foo(object): > ? ?def __init__(self, msg): > ? ? ? ?self.msg = msg > > ? ?def __str__(self): > ? ? ? ?return 'Foo: ' + self.msg > > class Bar(Exception): > ? ?def __init__(self, msg): > ? ? ? ?self.msg = msg > > ? ?def __str__(self): > ? ? ? ?return 'Bar: ' + self.msg > > class A(Exception): > ? ?pass > > class B(RuntimeError): > ? ?pass > > class AFoo(A, Foo): pass > class ABar(A, Bar): pass > > class BFoo(B, Foo): pass > class BBar(B, Bar): pass > > print AFoo('ok') # ok > print ABar('ok') # Bar: ok > > print BFoo('ok') # ok > print BBar('fail') # AttributeError: ... not attribute 'msg' > > # EOF > > After running the code I was still confused. So I read carefully again > the mro stuff. And ended doing this inheritance tree: > > ? ? ? object (__init__, __str__) > ? ? ? ? ?| ? ?\ > ? ? ? ? ?| ? ?Foo (__init__, __str__) > ? ? ? ? ?| > ?BaseException (__init__, __str__) > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ?Exception (__init__) > ? ? / ? ?| ? ? \ > ? ?A ? ?| ? ? Bar (__init__, __str__) > ? ? ? ? ?| > ?StandardError (__init__) > ? ? ? ? ?| > ? ? ? ? ?| > ? ? ? ? ?| > ? ?RuntimeError (__init__) > ? ?/ > ? B > > Then I figure out the method resolution following the inheritance graph: > ?* AFoo(A, Foo): > ? ?__init__ from Exception > ? ?__str__ ?from BaseException > > ?* ABar(A, Bar): > ? ?__init__ from Bar > ? ?__str__ ?from Bar > > ?* BFoo(B, Foo): > ? ?__init__ from RuntimeError > ? ?__str__ ?from BaseException > > ?* BBar(B, Bar): > ? ?__init__ from RuntimeError > ? ?__str__ ?from Bar > > > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? > Two things: First of all, avoid multiple inheritance if you can. It's usually unnecessary in Python because of duck typing (unless you need to inherit the actual behavior and not just a list of methods), and as you've noticed, the MRO gets messy. And second, not to in any way diminish the work you did tracing out the inheritance tree and working through the inheritance, but Python has easier ways of doing it :) >>> BBar.__mro__ (, , , , , , , ) >>> '__str__' in BBar.__dict__ False >>> '__str__' in Bar.__dict__ True >>> for cls in BBar.__mro__ : if '__str__' in cls.__dict__ : print cls break > ~Rolando > -- > http://mail.python.org/mailman/listinfo/python-list > From kushal.kumaran+python at gmail.com Sat Jul 24 00:32:08 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 24 Jul 2010 10:02:08 +0530 Subject: non-blocking IO EAGAIN on write In-Reply-To: <8at354F51tU1@mid.individual.net> References: <8at354F51tU1@mid.individual.net> Message-ID: On Fri, Jul 23, 2010 at 2:15 PM, Thomas Guettler wrote: > Hi, > > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) > on write(). My working code looks like this. But I am unsure how many bytes have been written to the > pipe if I get an EAGAIN IOError. Up to now I retry with the same chunk. > > If I get EAGAIN can I just sleep, and then retry with the same data chunk? > > pipe=subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=-1) > fcntl.fcntl(pipe.stdin, fcntl.F_SETFL, os.O_NONBLOCK) > .... > chunk_size=1024 > ? ? ? ?while select.select([], [pipe.stdin], [], 5): Please read the documentation of the select.select function. You are not using it correctly. After the call returns, you need to check whether the descriptor you are interested in is actually ready. If select reaches your timeout, it will simply return three empty lists, and your write will get EAGAIN. In general, after select has told you a descriptor is ready, the first write after that should always succeed. BTW, from the documentation of file objects, it seems write always wants to write the entire string you give it, since it does not return anything. In that case, you might want to get the descriptor for the file object (using pipe.fileno()) and use that for writing. > -- regards, kushal From darkrho at gmail.com Sat Jul 24 00:43:19 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Sat, 24 Jul 2010 00:43:19 -0400 Subject: understanding the mro (long) In-Reply-To: References: Message-ID: On Sat, Jul 24, 2010 at 12:28 AM, Benjamin Kaplan wrote: [...] > > And second, not to in any way diminish the work you did tracing out > the inheritance tree and working through the inheritance, but Python > has easier ways of doing it :) > >>>> BBar.__mro__ > (, , 'exceptions.RuntimeError'>, , '__main__.Bar'>, , 'exceptions.BaseException'>, ) Yes, actually I looked at __mro__ to confirm that I was right. >>>> '__str__' in BBar.__dict__ > False >>>> '__str__' in Bar.__dict__ > True I see! I couldn't figure out how to find if a method is defined within given class. >>>> for cls in BBar.__mro__ : > ? ? ? ?if '__str__' in cls.__dict__ : > ? ? ? ? ? ? ? ?print cls > ? ? ? ? ? ? ? ?break > > > This is good one! It could save time figuring out where a method comes from. Anyway, was a good exercise to figure out the mro by hand :) Thanks for your comments Benjamin and Steven. ~Rolando From usernet at ilthio.net Sat Jul 24 01:24:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 24 Jul 2010 05:24:18 +0000 (UTC) Subject: Python as a scripting language. Alternative to bash script? References: <4c28e2a3$0$1592$742ec2ed@news.sonic.net> Message-ID: On 2010-07-24, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: > >> On 2010-07-05, Lawrence D'Oliveiro >> wrote: >>> >>> I???ve never come across any system where you could string together >>> multiple GUI apps, or even multiple GUI operations in the same app, in >>> any sensible or effective way at all. GUIs just aren???t designed to work >>> that way. >> >> You can if they are designed to be used externally. COM is an execellent >> example of this ... > > But COM is an IPC architecture, which has nothing to do with GUI apps. Not exactly. IPC allows you to send and receive information from another process; but, it doesn't give you internal access to the process. COM is much closer to an OO style of RPC. > Conflating the two leads to precisely the sort of inflexibility that is > characteristic of GUIs. For example, things happening with the GUI on-screen > while a script is running that are at best distracting to the user, or at > worst vulnerable to breaking if the user accidentally presses a key or > clicks in the wrong place. COM object have a visibility property that determines whether or not they are displayed to the user. >> I have worked with complex business process automation centered around >> Excel and I have automated some really ugly AJAX style web based >> applications that would only work inside of IE6 by accessing IE through >> its COM interface. > > If those apps really were using AJAX, then why did you need to script a Web > browser at all? You could just make direct HTTP requests to retrieve the > data. The first and primary reason was that the application server required a client side SSL certificate. We didn't have access to a certificate that we could get to work Python's SSL or HTTPS modules. The second reason was that we had considerable difficulty figuring out how the server side interfaces worked from the slew of horrible Javascript. You really have to have seen it to know just what a mess this really was. Every call was literally wrapped in dozens of almost identical wrapper functions that you had to follow to attempt to figure out what was going on. Parts of the rendered form which looked like text field entries really weren't until a series of events took place to change them. They were used as flags indicating the state of various information. I really can't overstate how ugly this application really was. I was working on trying to figure out the serverside interface while my partner was trying to get an open SSL connection. By the time he gave up trying to convert our key to something we could use, I decided it was simpler just to use COM and internet explorer. It worked pretty well. >> Automating GUI applications requires interal access to the program through >> some kind of interface ... > > Some kind of interface that bypasses the GUI. This is why so many Open > Source apps are structured as a GUI front end to a completely separate > command-line tool (e.g. MPlayer). That way a script can use the latter > without having to go through the former. Which is great where the a separate backend exists. That isn't the case for a *huge* number of GUI applications; but, You don't always get to pick what you are going to need to automate. From michele.simionato at gmail.com Sat Jul 24 02:32:35 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 23 Jul 2010 23:32:35 -0700 (PDT) Subject: understanding the mro (long) References: Message-ID: On Jul 24, 4:42?am, Rolando Espinoza La Fuente wrote: > Finally everything make sense. And make think about be careful when > doing multiple inheritance. > > Any thoughts? > > ~Rolando I am not fond of multiple inheritance either and I wrote at length about the dangers of it. If you do not know it already, you may be interested in reading my "Mixins considered harmful" series http://www.artima.com/weblogs/viewpost.jsp?thread=246341 (together with any blog posts on super and related subjects). From dummey at gmail.com Sat Jul 24 02:33:55 2010 From: dummey at gmail.com (Dummey) Date: Fri, 23 Jul 2010 23:33:55 -0700 (PDT) Subject: 'as' keyword - when/how to use it Message-ID: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> I am having the hardest time trying to find documentation on proper use of the 'as' keyword (aside from . I initially thought that I would be allowed to do something such as: import shared.util as util The as statement seems to be causing a lot of ''module' object has no attribute'. Is it safe to assume that this is not the way to use it? From nagle at animats.com Sat Jul 24 03:11:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 00:11:09 -0700 Subject: time between now and the next 2:30 am? In-Reply-To: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> Message-ID: <4c4a921e$0$1661$742ec2ed@news.sonic.net> On 7/23/2010 10:01 AM, Jim wrote: > How can I calculate how much time is between now and the next 2:30 > am? Naturally I want the system to worry about leap years, etc. > > Thanks, > Jim DAYSECS = 24*60*60 GOALSECS = (2*60 + 30)*60 now = (GOALSECS + DAYSECS - (int(time.time()) % DAYSECS)) % DAYSECS This is for UT; the adjustment for timezone should be obvious. John Nagle From lacrima.maxim at gmail.com Sat Jul 24 03:47:04 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sat, 24 Jul 2010 00:47:04 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? Message-ID: Hi! I have two super classes: class SuperClass1(object): def __init__(self, word): print word class SuperClass2(object): def __init__(self, word, word2): print word, word2 Also I have subclass of these classes: class SubClass(SuperClass1, SuperClass2): def __init__(self): pass I have two questions. 1) Inside __init__ of SubClass how can I firstly call __init__ of SuperClass1, and then __init__ of SuperClass2, using builtin super() function. 2) Why should I use super() at all, if it is very easy to call methods of super class like this: class SubClass(SuperClass1, SuperClass2): def __init__(self): SuperClass1.__init__(self, 'Python') SuperClass2.__init__(self, 'Hello', 'world') Thanks in advance. From raymond.hettinger at gmail.com Sat Jul 24 04:20:40 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Sat, 24 Jul 2010 01:20:40 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: Message-ID: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> On Jul 24, 12:47?am, Lacrima wrote: > Hi! > > I have two super classes: > > class SuperClass1(object): > ? ? def __init__(self, word): > ? ? ? ? print word > > class SuperClass2(object): > ? ? def __init__(self, word, word2): > ? ? ? ? print word, word2 > > Also I have subclass of these classes: > > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self): > ? ? ? ? pass > > I have two questions. > 1) Inside __init__ of SubClass how can I firstly call __init__ of > SuperClass1, and then __init__ of SuperClass2, using builtin super() > function. I would write it like this: class SuperClass1(object): def __init__(self, **kwds): word = kwds.pop('word') print word super(SuperClass1, self).__init__(**kwds) class SuperClass2(object): def __init__(self, **kwds): word1 = kwds.pop('word1') word2 = kwds.pop('word2') print word1, word2 super(SuperClass2, self).__init__(**kwds) class SubClass(SuperClass1, SuperClass2): def __init__(self, **kwds): super(SubClass, self).__init__(**kwds) SubClass(word='Python', word1='Hello', word2='World') > 2) Why should I use super() at all, if it is very easy to call methods > of super class like this: > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self): > ? ? ? ? SuperClass1.__init__(self, 'Python') > ? ? ? ? SuperClass2.__init__(self, 'Hello', 'world') That works just fine in this case. The challenge arises in "diamond diagrams" such as A->B A->C B->D C->D where both B and C are written independently of D and both need to call A's __init__ but that method should only be called once (not once by B and again by C). In that case, the super() pattern shown above will let each parent's method be called exactly once and guarantee that parents are called before grandparents and guarantee that the left-to-right ordering of multiple bases is respected. Raymond From franco at grex.org Sat Jul 24 04:56:42 2010 From: franco at grex.org (francogrex) Date: Sat, 24 Jul 2010 10:56:42 +0200 Subject: C interpreter in Lisp/scheme/python References: <9969f3c0-73e3-48e8-b4df-734c64bd00c0@t10g2000yqg.googlegroups.com> <16a7e301-2e85-47eb-971e-79acc4e076a6@b35g2000yqi.googlegroups.com> Message-ID: In article , gneuner2 at comcast.net says... >I don't think it's accurate to say that [some] experts really "scorn" >newbies, but I do agree that newbies are occasionally mistreated. > >One thing newbies have to realize is that on Usenet you are quite >likely to be talking to people who were there at the beginning and, of >necessity, are largely self educated in whatever the subject matter >might be. Many - I'd even say most - are happy to clarify >understanding and help with complicated problems, but there is a >general expectation that newbies have some basic research skills and >that they have tried to solve their problem before asking for help. > >Unfortunately, there is a small percentage of people who think Usenet >and other online forums are for answering homework questions or for >digging out of a jam at work. Getting help depends a lot on how the >question is asked: strident pleas for quick help or demands for an >answer are immediate red flags, but so are questions that begin with >"X is crap, why can't I do ..." and even seemingly polite questions >that are vague or unfocused (possibly indicating little or no thought >behind them) or posts which are directed to a large number of groups >(such as this thread we're in now). > >And, of course, in the language forums, drawing comparisons to >non-subject languages is generally considered rude except when done to >illustrate a relevant discussion point. Introducing irrelevant >comparisons, deliberately proselytizing X in a Y group or doing a lot >of complaining about the subject language is bound to attract disdain. > >As the Internet has grown, the absolute number of people in that >"small percentage" has grown as well. A newbie can simply be unlucky >enough to ask a question at the wrong time. If there has been a >recent rash of problem posts then experts may accidentally respond >negatively to a legitimate question. > >Of course, there are cross-cultural issues too. Many of the technical >groups are English-language. English, even when polite, can seem >harsh and/or abrupt to non-native speakers. > >On the whole, moderated groups are more conducive to helping newbies >because the moderator(s) filter obvious red flag posts. > >And, finally, newbies themselves should realize that experts are >donating time to answer questions and do get frustrated answering the >same questions over and over. They should not be offended by "cold" >responses that direct them to FAQs or that just give links to study >material. Newbies who need hand-holding or warm welcoming responses >filled with detail should go find a tutor. > > >> ... you have the bad "professors" who are freaks >>(probably they have a lot of problems at home, their wives >>screwing all the males on the block, daughters drug addicts etc) >>and want to take their hatred out on you, > >Unquestionably, there are experts who need their dosages adjusted. But >the same can be said for some percentage of other users too. > >OTOH, newbies often aren't in the position to know who is an expert >... obviously, anyone able to correctly answer their question knows >more about that specific issue. That doesn't necessarily qualify the >responder as an "expert". Some people get defensive at the edges of >their comfort zones. > > >Just some thoughts. YMMV. >George Yes I agree, you expressed the thought better than I did. Then let's not go on with this thread any further and let the newsgroups carry on programming language support and discussions. Thanks From tjreedy at udel.edu Sat Jul 24 04:57:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jul 2010 04:57:09 -0400 Subject: 'as' keyword - when/how to use it In-Reply-To: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> Message-ID: On 7/24/2010 2:33 AM, Dummey wrote: > I am having the hardest time trying to find documentation on proper > use of the 'as' keyword (aside from . I initially thought that I would > be allowed to do something such as: > > import shared.util as util > > The as statement seems to be causing a lot of ''module' object has no > attribute'. Is it safe to assume that this is not the way to use it? Give an example of real code raising an exception when importing from the stdlib and the corresponding error traceback in its entirety. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Jul 24 06:25:07 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 11:25:07 +0100 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 24/07/2010 04:17, Edward Diener wrote: > Are there any documents about multiple versionsof Python coexisting in > the same OS ( Windows in my case ) and what pitfalls to look out for ? I > have already run into a number of them. I installed Python 2.7 and 3.1.2 > into completely folders, but immediately ran into serious problems > executing a Python script. > > The first problem is that just invoking Python will start whichever > version is first in the PATH, and this is true from the command line or > internally in a Python script. > > The second problem is that invoking a script ( some xxx.py ) will start > whichever version of Python is associated with the .py extension. > > The third problem is if some software expects its scripts, which it puts > in some Python subdirectory to be in the PATH. > > There may be other considerations but overall having to versions > coexisting has turned out to be a big headache involving both changes in > the PATH and in the .py association. > > Does anybody know of other things to look out for ? I found this only yesterday and found it extremely helpful, find the post by Gabriel Genellina. http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx HTH. Mark Lawrence From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 06:44:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 10:44:40 GMT Subject: 'as' keyword - when/how to use it References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> Message-ID: <4c4ac418$0$28641$c3e8da3@news.astraweb.com> On Fri, 23 Jul 2010 23:33:55 -0700, Dummey wrote: > I am having the hardest time trying to find documentation on proper use > of the 'as' keyword (aside from . I initially thought that I would be > allowed to do something such as: > > import shared.util as util > > The as statement seems to be causing a lot of ''module' object has no > attribute'. Is it safe to assume that this is not the way to use it? It works for me. >>> import math as spam >>> spam >>> import email.mime.text as ham >>> ham My guess is that you are trying to import individual objects from a module using the package dot notation: >>> import math.sin as eggs Traceback (most recent call last): File "", line 1, in ImportError: No module named sin -- Steven From lacrima.maxim at gmail.com Sat Jul 24 06:56:05 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sat, 24 Jul 2010 03:56:05 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> Message-ID: <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> On Jul 24, 11:20?am, Raymond Hettinger wrote: > On Jul 24, 12:47?am, Lacrima wrote: > > > > > Hi! > > > I have two super classes: > > > class SuperClass1(object): > > ? ? def __init__(self, word): > > ? ? ? ? print word > > > class SuperClass2(object): > > ? ? def __init__(self, word, word2): > > ? ? ? ? print word, word2 > > > Also I have subclass of these classes: > > > class SubClass(SuperClass1, SuperClass2): > > ? ? def __init__(self): > > ? ? ? ? pass > > > I have two questions. > > 1) Inside __init__ of SubClass how can I firstly call __init__ of > > SuperClass1, and then __init__ of SuperClass2, using builtin super() > > function. > > I would write it like this: > > class SuperClass1(object): > ? ? def __init__(self, **kwds): > ? ? ? ? word = kwds.pop('word') > ? ? ? ? print word > ? ? ? ? super(SuperClass1, self).__init__(**kwds) > > class SuperClass2(object): > ? ? def __init__(self, **kwds): > ? ? ? ? word1 = kwds.pop('word1') > ? ? ? ? word2 = kwds.pop('word2') > ? ? ? ? print word1, word2 > ? ? ? ? super(SuperClass2, self).__init__(**kwds) > > class SubClass(SuperClass1, SuperClass2): > ? ? def __init__(self, **kwds): > ? ? ? ? super(SubClass, self).__init__(**kwds) > > SubClass(word='Python', word1='Hello', word2='World') > > > 2) Why should I use super() at all, if it is very easy to call methods > > of super class like this: > > class SubClass(SuperClass1, SuperClass2): > > ? ? def __init__(self): > > ? ? ? ? SuperClass1.__init__(self, 'Python') > > ? ? ? ? SuperClass2.__init__(self, 'Hello', 'world') > > That works just fine in this case. > The challenge arises in "diamond diagrams" > such as A->B ?A->C ?B->D ?C->D where both B and C > are written independently of D and both need to call > A's __init__ but that method should only be called > once (not once by B and again by C). > > In that case, the super() pattern shown above will > let each parent's method be called exactly once > and guarantee that parents are called before grandparents > and guarantee that the left-to-right ordering of multiple > bases is respected. > > Raymond Hi, Raymond! Thank you for your answer. Some things are still not clear. Your example works great. But if I remove "super(SuperClass1, self).__init__(**kwds)" from SuperClass1's __init__, the example stops working. That is when I instantiate SubClass only __init__ of SuperClass1 is called and __init__ of SuperClass2 is omitted, i.e. only 'Python' is printed. Why is it so? So as I understand every parent should necessarily call super() at the end of its __init__ method in order for things to work properly. But what if SuperClass1 is from third party library? Then I can't modify it to follow this convention, that is when I instantiate my SubClass only __init__ from SuperClass1 will be called, and __init__ from SuperClass2 will be omitted. How to deal with that? My post is quite intricate, but this is because of my English. Sorry. Looking forward for help. Thank you. From jim.hefferon at gmail.com Sat Jul 24 07:21:40 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 24 Jul 2010 04:21:40 -0700 (PDT) Subject: time between now and the next 2:30 am? References: <308aabdd-d62f-4be0-bad1-9b23dd74eedc@f6g2000yqa.googlegroups.com> <8au0g3FmmoU1@mid.individual.net> <26fc15b1-9ce0-441e-b2b4-1611e018b052@5g2000yqz.googlegroups.com> Message-ID: <08e71b61-49bc-4cdf-a1fb-97a59cb56418@d17g2000yqb.googlegroups.com> On Jul 23, 8:52?pm, MRAB wrote: > > dt_twothirty=dt_localtime.replace(hour=settings.UPDATE_TIME_HOURS,minute=se ttings.UPDATE_TIME_MINS,second=0,microsecond=0) > > You're changing the time of day, but not the date. You might want to add > a day to the shutdown time if it's earlier than the current time. I started out by finding the right date (I used a less-than test and toordinal and fromordinal() ). However, after some trials, I came to believe that I don't need to find the right date. The part of that calculation I need, and later refer to, is the .seconds attribute. I perceive that the way TimeDelta objects are laid out, the seconds attribute will be the same, regardless of whether I calculate it using 2:30 today or first finding which is the right date and using its 2:30. That is, as I understood it, if it is now 2:29 then the .seconds attribute will be 60. If it is now 2:31 then the .seconds attribute will be 24*60*60-60. I believe this holds regardless of which day I use. >>> import time,datetime >>> x=datetime.datetime(2010,7,23) >>> dt_localtime=x.fromtimestamp(time.time()) >>> dt_localtime datetime.datetime(2010, 7, 24, 7, 17, 46, 122642) >>> dt_twothirty=dt_localtime.replace(hour=2,minute=30,second=0,microsecond=0) >>> print dt_twothirty 2010-07-24 02:30:00 >>> dd_diff=dt_twothirty-dt_localtime >>> print dd_diff -1 day, 19:12:13.877358 >>> dt_tomorrow_twothirty=dt_localtime.replace(day=25,hour=2,minute=30,second=0,microsecond=0) >>> print dt_tomorrow_twothirty 2010-07-25 02:30:00 >>> dd_tomorrow_diff=dt_tomorrow_twothirty-dt_localtime >>> print dd_tomorrow_diff 19:12:13.877358 Tested it, of course. Not that I haven't gotten things wrong in the past, even though I tested them. :-} Jim From roy at panix.com Sat Jul 24 07:25:09 2010 From: roy at panix.com (Roy Smith) Date: Sat, 24 Jul 2010 07:25:09 -0400 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: In article , Kushal Kumaran wrote: > In general, after select has told you a descriptor is ready, the > first write after that should always succeed. I used to think that too. Over the last few years, I've been maintaining a large hunk of cross-platform C++ code which makes heavy use of select(), with both UDP and TCP sockets. I've seen lots of strange behavior. For the moment, assume we're talking about a single-threaded program. This simplifies things a lot. If you write (pseudo-code): select(fd) write(fd) when the select indicates fd is ready, it's not really saying, "The following i/o call will succeed". What it's saying is, "The following i/o call won't block". It could return an error, as long as it returns it immediately. Consider, for example, a write on a TCP connection. You are sitting in a select(), when the other side closes the connection. The select() should return, and the write should then immediately fail. If you're tempted to say that the select() should return some sort of error, consider the case where the remote end closes the connection after the select() returns but before your process gets to execute the following write() call. We also saw a case where (due to what we consider a kernel bug), a received UDP packet with a checksum error would cause the select() to wake up, *then* notice the checksum error and discard the packet, and thus the following read() would block. The bottom line is if you really want to make sure you never block in an I/O call, put your descriptor into non-blocking mode, and treat select() as a *hint*. A way to ask the kernel, "Tell me when you think it might be a good idea to try polling this descriptor again". From franco at grex.org Sat Jul 24 08:45:52 2010 From: franco at grex.org (francogrex) Date: Sat, 24 Jul 2010 14:45:52 +0200 Subject: Are those features still the same? Message-ID: Hi, I'm not a Python programmer but I'm interested in it and I found this table from Norvig that dates for some years (I re-posted it temporarily on my site below to take it out of context a little). I'm not interested in any comparisons only in the Python features ( last column), can someone whether the information in the Python features column is still correct today. Thanks http://francoatgrex.tripod.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 09:06:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 24 Jul 2010 13:06:38 GMT Subject: Are those features still the same? References: Message-ID: <4c4ae55e$0$11117$c3e8da3@news.astraweb.com> On Sat, 24 Jul 2010 14:45:52 +0200, francogrex wrote: > Hi, I'm not a Python programmer but I'm interested in it and I found > this table from Norvig that dates for some years (I re-posted it > temporarily on my site below to take it out of context a little). I'm > not interested in any comparisons only in the Python features ( last > column), can someone whether the information in the Python features > column is still correct today. Thanks > > http://francoatgrex.tripod.com/ I could quibble on a few minor wordings, but yes, it is broadly correct. -- Steven From __peter__ at web.de Sat Jul 24 09:14:12 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 15:14:12 +0200 Subject: Are those features still the same? References: Message-ID: francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks The original page is here: http://norvig.com/python-lisp.html Yes, the table is fairly up-to-date and general enough to stay up-to-date for the next few years. Peter From thomas at jollans.com Sat Jul 24 09:19:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 15:19:33 +0200 Subject: Are those features still the same? In-Reply-To: References: Message-ID: <4C4AE865.3010503@jollans.com> On 07/24/2010 02:45 PM, francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks Mostly all true, with a few changes and inaccuracies. And a definite bias towards the LISP. (and the author didn't even specify a dialect on lisp. My my...) > "Support heterogeneous lists" ==> "Yes (array)" This is nonsense, and has always been. Python lists (not arrays) have always been heterogeneous. They store objects and don't care about the type. Python arrays (from the array module) are homogeneous, and limited to storing numerical data. Quite a different beast. > "Number of implementations" ==> [...]branches[...] I wouldn't cann Jython a branch. You could say that there are currently two major branches of the Python language, and the CPython interpreter: Python 2.x and Python 3.x. There are a number of implementations of Python, the big names being CPython, Jython, IronPython, and PyPy > Data types: Python 2's int and long (there called integer and bignum) are now (Python 3.x) a single type. Again, the author of the table reveals that he is is a lisp programmer only passingly acquainted with Python: Python lists are *not* arrays. They are (linked) lists. They're not identical to lisp (cons'd) lists, but they are, nonetheless, lists, not arrays. > Exceptions: string exceptions, as demonstrated in the table, are gone in Python 3. > "no other control structures" now that's a bit hard on Python. Technically true perhaps, but the author could have mentioned generators somewhere. > function application apply is gone in Python 3.x -- use the fn(*args) syntax instead. Also, execfile("file.py") is NOT identical to import file. > other high-order functions Check out itertools and functools. (std library) > "close over writable var" Can be done in Python 3.x with the nonlocal keyword. Also, to a point, objects have always supported the same behaviour, with a twist. > FEATURES > "quotation" The way this is presented doesn't really fit with Python. Very lisp way to look at quotation. > "operations on arrays" ahem. From brian at sweetapp.com Sat Jul 24 09:48:06 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 24 Jul 2010 23:48:06 +1000 Subject: Are those features still the same? In-Reply-To: <4C4AE865.3010503@jollans.com> References: <4C4AE865.3010503@jollans.com> Message-ID: On 24 Jul 2010, at 23:19, Thomas Jollans wrote: >> "Support heterogeneous lists" ==> "Yes (array)" > > This is nonsense, and has always been. > Python lists (not arrays) have always been heterogeneous. They store > objects and don't care about the type. Python arrays (from the array > module) are homogeneous, and limited to storing numerical data. > Quite a > different beast. He means that Python lists are implemented using arrays, not that the Python "array" module provides the functionality. Cheers, Brian From __peter__ at web.de Sat Jul 24 09:56:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 15:56:31 +0200 Subject: Are those features still the same? References: Message-ID: Thomas Jollans wrote: >> "Support heterogeneous lists" ==> "Yes (array)" > > This is nonsense, and has always been. I think you are misunderstanding that statement. Python's list stores its items in a continuous chunk of memory, a layout that is called array in common CS terminology as opposed to lists which are typically linked lists. Peter From thomas at jollans.com Sat Jul 24 10:11:06 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 16:11:06 +0200 Subject: Are those features still the same? In-Reply-To: References: <4C4AE865.3010503@jollans.com> Message-ID: <4C4AF47A.2050902@jollans.com> On 07/24/2010 03:48 PM, Brian Quinlan wrote: > > On 24 Jul 2010, at 23:19, Thomas Jollans wrote: >>> "Support heterogeneous lists" ==> "Yes (array)" >> >> This is nonsense, and has always been. >> Python lists (not arrays) have always been heterogeneous. They store >> objects and don't care about the type. Python arrays (from the array >> module) are homogeneous, and limited to storing numerical data. Quite a >> different beast. > > He means that Python lists are implemented using arrays, not that the > Python "array" module provides the functionality. Oh dear, and all this time I thought python lists where implemented as lists, without ever checking the code. From be.krul at gmail.com Sat Jul 24 10:17:54 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:17:54 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Jul 17, 10:40?pm, Stephen Hansen wrote: > On 7/17/10 10:01 PM, be.krul wrote: > > > why is this group being spammed? > > Because while God created the Internet, the Devil twisted it by creating > spammers. > > What do you expect? Adam just didn't pay enough attention when Eve made > him a waldorf salad; we descendants of Seth have gone and tried to > devour not only the knowledge of good and evil but all knowledge of all > things, most notably breasts. > > Of course there'd be a dire consequence for our hubris. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload Interesting, I thought Al Gore creted Internet!? From be.krul at gmail.com Sat Jul 24 10:20:11 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:20:11 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> On Jul 17, 10:09?pm, Chris Rebert wrote: > On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > > why is this group being spammed? > > Because that's what happens in unmoderated USENET newsgroups. > > Cheers, > Chris I thought this group can be moderated, but turns out this is USENET Group.. From be.krul at gmail.com Sat Jul 24 10:21:35 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:21:35 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <874ofx9xbx.fsf@benfinney.id.au> Message-ID: <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> On Jul 17, 10:24?pm, Ben Finney wrote: > "be.krul" writes: > > why is this group being spammed? > > What kind of answer are you looking for? Are you asking about the > motives of spammers, or the technical explanation for how the spam > arrives, or something else? > > -- > ?\ ? ? ? ? ? ? ? ? ? ?The best ad-libs are rehearsed.? ?Graham Kennedy | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney Why not moderate this group? From be.krul at gmail.com Sat Jul 24 10:24:18 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:24:18 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <7150244a-749b-4f0d-93b1-fbf67f487d9c@q21g2000prm.googlegroups.com> On Jul 17, 10:57?pm, "Alf P. Steinbach /Usenet" wrote: > * be.krul, on 18.07.2010 07:01: > > > why is this group being spammed? > > It depends a little on what you're asking, e.g. technical versus motivation. > > But I'll answer about something you probably didn't mean to ask, namely what > human trait enables and almost forces that kind of behavior. > > And I believe it is the same trait that let hypnotists do funny TV-shows with > quite normal folks behaving in ridiculous ways, the same trait that causes wars, > the same trait that causes religion, the same trait that holds back science so > that "paradigm shifts" only occur when new generations take over, a trait that > /makes/ your feet start moving to the rhythm when you hear the right kind of > music, and so on. Namely the instinctual drive to fit in in a social group by > sharing that group's behavior and values. This instinct is possibly stronger > than the sex drive, e.g., wars are seldom fought over sex ("surrender, and give > us sex!", no, that's not it, it's "surrender, and become part of us!"). > > Consider, there would be almost no spam if spamming didn't pay. > > And the only way that spam can pay is if there are at least some suckers with > good money. > > And the only way that there can be a reasonable number of suckers of such > monumental stupidity, who also have good money, is, as I see it, if intelligence > and good sense is not a requirement for succeeding in society. > > But what is required, then, for succeeding in society? > > Some of it is no doubt blind chance, but I believe that the main requirement is > simply one of fitting in, conformance. Thus, if my hypothesis is right, almost > any idiot can rise to any level of responsibility and social standing simply by > fitting in, conforming. This idiot then has good money and might be one of the > suckers responding to spam. > > Cheers, > > - Alf > > -- > blog at Alf - You re my next hero! Who could answer so eloquently. From be.krul at gmail.com Sat Jul 24 10:32:30 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:32:30 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> On Jul 17, 10:01?pm, "be.krul" wrote: > why is this group being spammed? What I was asking is why not moderate the group. this is the only Python group I could find.. But maybe owner of this group do no care in that case we *all* get spammed! From thomas at jollans.com Sat Jul 24 10:39:33 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 24 Jul 2010 16:39:33 +0200 Subject: why is this group being spammed? In-Reply-To: <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> Message-ID: <4C4AFB25.4030003@jollans.com> On 07/24/2010 04:20 PM, be.krul wrote: > On Jul 17, 10:09 pm, Chris Rebert wrote: >> On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: >>> why is this group being spammed? >> >> Because that's what happens in unmoderated USENET newsgroups. >> >> Cheers, >> Chris > > I thought this group can be moderated, but turns out this is USENET > Group.. What did you think it was? From be.krul at gmail.com Sat Jul 24 10:54:26 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 07:54:26 -0700 (PDT) Subject: Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ References: <233c48c4-2eb5-43a6-bedc-7a396d31228a@w12g2000yqj.googlegroups.com> Message-ID: <0c9eef2e-050f-4739-8492-2703cd5fdec4@x1g2000prc.googlegroups.com> On Jul 23, 3:14?pm, nais-saudi wrote: > Jesus in the Glorious Qur'an ------ The True Message of Jesus Christ > > The Qur?an tells us a lot of wonderful things about Jesus. As a > result, believers in the Qur?an love Jesus, honour him, and believe in > him. In fact, no Muslim can be a Muslim unless he or she believes in > Jesus, on whom be peace. > > The Qur?an says that Jesus was born of a virgin, that he spoke while > he was still only a baby, that he healed the blind and the leper by > God?s leave, and that he raised the dead by God?s leave. > > What then is the significance of these miracles? First, the virgin > birth. God demonstrates his power to create in every way. God created > everyone we know from a man and a woman. But how about Adam, on whom > be peace? God created him from neither a man nor a woman. And Eve from > only a man, but not a woman. And, finally, to complete the picture, > God created Jesus from a woman, but not a man. > > What about the other miracles? These were to show that Jesus was not > acting on his own behalf, but that he was backed by God. The Qur?an > specifies that these miracles were performed by God?s leave. This may > be compared to the Book of Acts in the Bible, chapter 2, verse 22, > where it says that the miracles were done by God to show that he > approved of Jesus. Also, note that Jesus himself is recorded in the > Gospel of John to have said, ?I can do nothing of my own > authority? (5:30). The miracles, therefore, were done not by his own > authority, but by God?s authority. > > What did Jesus teach? The Qur?an tells us that Jesus came to teach the > same basic message which was taught by previous prophets from God?that > we must shun every false god and worship only the one true God. Jesus > taught that he is the servant and messenger of that one true God, the > God of Abraham. These Quranic teachings can be compared with the Bible > ( Mark 10:18; Matthew 26:39; John 14:28, 17:3, and 20:17) where Jesus > teaches that the one he worshipped is the only true God. See also > Matthew 12:18; Acts 3:13, and 4:27 where we find that his disciples > knew him as Servant of God. > > The Qur?an tells us that some of the Israelites rejected Jesus, and > conspired to kill him, but Allah (God) rescued Jesus and raised him to > Himself. Allah will cause Jesus to descend again, at which time Jesus > will confirm his true teachings and everyone will believe in him as he > is and as the Qur?an teaches about him. > > Jesus is the Messiah. He is a word from Allah, and a spirit from Him. > He is honoured in this world and in the hereafter, and he is one of > those brought nearest to Allah. > > Jesus was a man who spoke the truth which he heard from God. This can > be compared with the Gospel According to John where Jesus says to the > Israelites: ?You are determined to kill me, a man who has told you the > truth that I heard from God? (John 8:40). > > The Virgin Birth of Jesus > Muslims believe in the virgin birth of Jesus. When the angels > announced to Mary (peace be upon her) about Allah?s promise that she > will have a son, she was surprised, since she was a virgin. ?How can > this be?? she thought. She was reminded that it is easy for Allah to > create whatever he wills. > > She said: My Lord! How can I have a child when no mortal hath touched > me? He said: So (it will be). Allah createth what He will. If He > decreeth a thing, He saith unto it only: Be! and it is (Qur?an 3:47). > > It is not difficult for Allah to do anything he wants. He can create a > child with both human parents or only one. No miracle is beyond His > power. After all, He had created Adam (peace be upon him) from neither > a man nor a woman. He created the rest of us from both man and woman. > What is so hard if Allah decides to create a human being from a woman > only? He only commands ?Be!? and it occurs. > > Some people think that since Jesus, peace be upon him, had no human > father then God must be his father. The Qur?an rejects this view. The > position of Jesus with Allah is comparable to the position of Adam > with Allah. Just because Adam had no human parent does not mean we > should call him the Son of God. > > Lo! the likeness of Jesus with Allah is as the likeness of Adam. He > created him from dust, then He said unto him: Be! and he is. (Qur?an > 3:59). > > According to the Qur?an, everyone except Allah are His servants. > > And they say: the Beneficent hath taken unto Himself a Son. Assuredly > ye utter a disastrous thing, whereby almost the heavens are torn, and > the earth is split asunder and the mountains fall to ruins, that ye > ascribe to the Beneficent a son, when it is not meet for (the Majesty > of) the Beneficent that He should chose a son. There is none in the > heavens and the earth but cometh unto the Beneficent as a slave. > (Qur?an 19:88-93) > > The Miracles of Jesus > According to the Qur?an, Jesus, on whom be peace, performed the > following miracles by Allah?s leave: > > 1. Spoke while he was only a baby. > 2. Healed those born blind. > 3. Healed the lepers. > 4. Revived the dead. > 5. Breathed life into a bird made of clay. > > In the Qur?an Allah quotes Jesus, peace be upon him, as saying: > > Lo! I come unto you with a sign from your Lord. Lo! I fashion for you > out of clay the likeness of a bird, and I breathe into it and it is a > bird by Allah?s leave. I heal him who was born blind, and the leper, > and I raise the dead, by Allah?s leave. And I announce to you what you > eat and what you store up in your houses. Lo! herein verily is a > portent for you if you are to be believers. > And (I come) confirming that which was before me of the Torah, and to > make lawful some of that which was forbidden unto you. I come unto you > with a sign from your Lord, so keep your duty to Allah and obey me. > Lo! Allah is my Lord and your Lord, so worship Him. That is a straight > path. (Qur?an 3: 49-51). > > Again, in the Qur?an Allah tells us about the situation on the Day of > Judgement: > > In the day when Allah gathers together the messengers and says: What > was your response (from mankind)? they say: We have no knowledge. Lo! > Thou, only Thou art the Knower of Things Hidden. > When Allah says: O Jesus, son of Mary! Remember My favour unto you and > unto your mother; how I strengthened you with the holy Spirit, so that > you spoke unto mankind in the cradle as in maturity; and how I taught > you the ******ure and Wisdom and the Torah and the Gospel; and how you > did shape of clay as it were the likeness of a bird by My permission, > and did blow upon it and it was a bird by My permission, and you did > heal him who was born blind and the leper by My permission . . . > (Qur?an 5:109-110) > > Not all of these miracles are recorded in the canonical gospels, the > four gospels contained in the Christian Bible. > > The fact that Jesus spoke while he was yet a baby is not written > anywhere in the Bible. This should not be surprising, because none of > the Gospels can claim to recover every single event in the life of > Jesus. Instead, the gospel According to John seeks to emphasize that > the events were too many to record. > > Similarly, the miracle of breathing life into a bird made of clay is > not attested by the Christian Bible. This too should not make us > wonder. It is obvious that the writers of the gospels could write down > only the tradition that was available to them. Furthermore, they could > not write down everything they knew about Jesus for they were writing > on papyrus material that were very limited in length. > > What is worthy to notice here is that the Prophet Muhammad, may peace > and the blessings of Allah be upon him, was honest enough to > promulgate this information about Jesus. The religion taught by God > through Muhammad would deny the divinity of Jesus. Any human being, > therefore, who wished to deny the divinity of Jesus would have tried > to belittle Jesus. Since Christians looked upon the miracles of Jesus > as a proof of his divinity, we might expect that any human being who > tries to deny the divinity of Jesus would not have informed people of > miracles not previously known to them. He might have even tried to > deny some of the miracles recorded in the canonical gospels. On the > other hand, the prophet Muhammad honestly conveyed the message > delivered to him from Allah. (May the peace and blessings of Allah be > upon him.) > > Allah tells us the truth without fear. Human beings trying to win > followers tell us only what is conducive to winning us over. They > usually withhold information that could lead to opposite conclusions. > On the other hand, Allah informs us about the miracles of Jesus even > if people use this information to support their prior commitment to > the doctrine of the divinity of Jesus. Allah does not need to win > worshippers. Those who worship Allah does so for their own good. And > those who worship false gods do so to their own detriment. > > What Allah emphasizes, though, is that the miracles of Jesus do not > prove he was divine. The miracles he performed were a sign, a proof, > that he was God?s messenger. He performed them with God?s help and > permission. Those who use his miracles as proof of his divinity would > choose to forget the following sayings of Jesus: > > I can of my own authority do nothing. (John 5:30) > > They also forget the declaration of Peter: > > Jesus of Nazareth, a man approved of God among you by miracles and > wonders and signs, which God did by him in the midst of you, as ye > yourselves know. (Acts 2:22 KJV). > > These passages suggest that Jesus did not do miracles on his own. > These, rather were accomplished by God?s leave. Allah reminds us of > this. Jesus also constantly repeated to his audience that the miracles > he performed were by God?s leave. > > ------------------------------------------------------------------------------------------------------------------------------------------------------------ > > ?The True Message of Jesus Christ > ????? ???? ?????? ?????? > > ?????? ????? ????? ???? ??????? > > The True Message of Jesus Christ > > Auther: Dr. Bilal Philips > > *******: > > Introduction > > Chapter One: The ******ures > > Authentic Manu******s > > Contradictions > > Chapter Two: The Person > > A Man > > "Evidence"For Jesus Divinity > > Chapter Three: The Message > > Chapter Four: The Way > > Conclusion > > Bibliography > > CHAPTER TWO: JESUS, THE PERSON > > As has been shown in the previous chapter, the Biblical ******ures, > both New and Old Testaments, are unreliable sources and cannot, > therefore, be used as an authentic means of knowing the truth about > the man called Jesus Christ or about his mission and message. However, > a close examination of these ******ures in the light of Qur?aanic > verses will reveal some of the truths about Jesus that have survived > in the Bible. > > A Messenger > > Throughout the Qur?aan, Jesus is identified fundamentally as a > Messenger of God. In Chapter as-Saff (61):6, God quotes Jesus as > follows: > > { ?????? ????? ?????? ????? ???????? ???????? ??????????? ?????? > ??????? ????? ?????????? ?????????? ?????? ?????? ??????? ???? > ??????????? } > > ?And [remember] when Jesus, son of Mary, said: ?O Children of Israel, > I am the messenger of Allaah sent to you, confirming the Torah [which > came] before me.? > > There are many verses in the New Testament supporting the > messengership / prophethood of Jesus. The following are only a few: In > Matthew 21:11, the people of his time are recorded as referring to > Jesus as a prophet: ?And the crowds said, ?This is the prophet Jesus > of Nazareth of Galilee.? ? In Mark, 6:4, it is stated that Jesus > referred to himself as a prophet: ?And Jesus said to them, ?A prophet > is not without honour, except in his own country, and among his own > kin, and in his own house.? ? In the following verses, Jesus is > referred to as having been sent as a messenger is sent. In Matthew > 10:40, Jesus was purported to have said: ?He that receiveth you > receiveth me, and he that receiveth me receiveth him that sent me.? In > John 17:3, Jesus is also quoted as saying: ?And this is life eternal, > that they might know thee the only true God, and Jesus Christ, whom > thou hast sent.? [1] > > ==================== > > A Man > > The Qur?aanic revelation not only affirms Jesus? prophethood, but it > also clearly denies Jesus? divinity. In Chapter al-Maa?idah, (5): 75, > God points out that Jesus ate food, which is a human act, obviously > not befitting to God. > > { ??? ?????????? ????? ???????? ?????? ??????? ???? ?????? ???? > ???????? ????????? ????????? ?????????? ?????? ??????????? ?????????? > ??????? ?????? ????????? ?????? ????????? ????? ??????? ?????? > ???????????} > > ?The Messiah, Son of Mary, was no more than a messenger and many > messengers passed away before him. His mother was exceedingly > truthful, and they both ate food. See how I have made the signs clear > for them, yet see how they are deluded.? > > There are numerous accounts in the New Testament which also deny > Jesus? divinity. > > For example, in Matthew 19:17, Jesus responded to one who addressed > him as ?O good master?, saying: ?Why callest thou me good? There is > none good but one, that is God.? If he rejected being called ?good?, > [2] and stated that only God is truly good, he clearly implies that he > is not God. > > In John 14:28, Jesus was saying: ?The Father is greater than I.? By > stating that the ?Father? is greater than himself, Jesus distinguishes > himself from God. Also in John 20:17, Jesus told Mary Magdalene to > tell his followers: ?I ascend unto my Father and your Father; and to > my God and your God.? Jesus? reference to God as ?my Father and your > Father? further emphasizes the distinction between himself and God. > Furthermore, by referring to God as ?his God?, he left no room for > anyone to intelligently claim that he was God. > > Even in some of the writings of Paul, which the Church has taken to be > sacred, Jesus is referred to as a ?man?, distinct and different from > God. In 1st Timothy, 2:5, Paul writes: ?For there is one God, and one > mediator between God and men, the man Christ Jesus.? > > There are also verses in the Qur?aan which confirm Prophet Muhammad?s > humanity, in order to prevent his followers from elevating him to a > divine or semi-divine status, as was done to Prophet Jesus. For > example, in Chapter al-Kahf (18):110, Allaah instructs the Prophet > Muhammad (e) to inform all who hear his message: > > { ???? ???????? ?????? ?????? ?????????? ?????? ??????? ???????? > ?????????? ????? ??????? } > > ?Say: ?Indeed, I am only a man like you to whom it has been revealed > that your God is only one God.? ? > > In Chapter al-A?raaf (7):187, Allaah also directed Prophet Muhammad > (e) to acknowledge that the time of the Judgement is known only to > God. > > {????????????? ???? ?????????? ???????? ?????????? ???? ???????? > ????????? ?????? ?????? ??? ??????????? ??????????? ?????? ???? } > > ?They ask you about the Final Hour: 'When will its apointed time be?? > Say: ?Knowledge of it is with my Lord. None can reveal its time > besides Him.? ? > > In the Gospel according to Mark 13:31-32, Jesus is also reported to > have denied having knowledge of when the final hour of this world > would be, saying: ?Heaven and the earth shall pass away but my word > shall not pass away, but of that day or hour no man knoweth, neither > the angels in the heaven nor the Son but the Father.? One of the > attributes of God is omniscience, knowledge of all things. Therefore, > his denial of knowledge of the Day of Judgement is also a denial of > divinity, for one who does not know the time of the final hour cannot > possibly be God .[3] > > An Immaculate Conception > > The Qur?aan confirms the Biblical story of Jesus? virgin birth. > However, in the Qur?aanic account of Jesus? birth, Mary was an > unmarried maiden whose life was dedicated to the worship of God by her > mother. While she was worshipping in a place of religious seclusion, > angels came and informed her of her impending pregnancy. > > { ???? ??????? ???????????? ??? ???????? ????? ????? ??????????? > ?????????? ?????? ??????? ??????????? ?????? ????? ???????? ???????? > ??? ????????? ?? ?????????? ?????? ??????????????} > > ?When the angels said: ?O Mary, indeed Allaah gives you glad tidings > of a Word from Him, whose name will be the Messiah, Jesus the son of > Mary. He will be honored in this world and the next and will be of > those close to Allaah.? ? Qur?aan, (3):45 > > { ??????? ????? ?????? ??????? ??? ?????? ?????? ??????????? ?????? > ????? ???????? ????? ???????? ??? ??????? ????? ????? ??????? > ?????????? ??????? ???? ???? ????????? } > > ?She said: ?O my Lord, how can I have a son when no man has touched > me?? He said: ?Even so?Allaah creates what He wishes. When He decrees > something, He only has to say to it: ?Be!? and it is.? ? Qur?aan, (3): > 47 > > However, the Qur?aan clarifies that Jesus? virgin birth did not change > the state of his humanity. His creation was like the creation of > Aadam, who had neither father nor mother. > > { ????? ?????? ?????? ?????? ????? ???????? ????? ???????? ???? > ??????? ????? ????? ???? ???? ????????? } > > ?Surely, the example of Jesus, in Allaah?s sight, is like that of > Aadam. He created him from dust and said: ?Be!? and he was.? Qur?aan, > (3):59 > > The Miracles > > The Qur?aanic account of Jesus? ministry confirms most[4] of his > miracles mentioned in the Bible and identifies some not mentioned in > the Bible. For example, the Qur?aan informs that Jesus was a messenger > of God from his birth, and his first miracle was speaking as a child > in the cradle. After Mary had given birth to Jesus, people accused her > of fornication. Instead of responding to their accusations, she > pointed to her newly born child: > > { ??????????? ???????? ??????? ?????? ????????? ???? ????? ??? > ????????? ???????? ????? ?????? ?????? ????? ???????? ?????????? > ??????????? ????????} > > ?[When] she pointed to him, they asked, ?How can we talk to a child in > the cradle?? He [Jesus] said: ?Indeed, I am a servant of Allaah. He > gave me the ******ure and made me a prophet.? ? > > Qur?aan, (19):29-30 > > Among his other miracles of bringing the dead back to life, healing > lepers, and making the blind see, the Qur?aan records another miracle > not mentioned in the Bible. Prophet Jesus fashioned birds out of clay, > blew on them and they flew away, living birds. But the point which is > emphasized throughout the Qur?aan is that whenever Jesus performed a > miracle, he informed the people that it was by God?s permission. He > made it clear to his followers that he was not doing the miracles by > himself, in the same way that the earlier Prophets made it clear to > those around them. > > Unfortunately, those who claim divinity for Jesus, usually hold up his > miracles as evidence. However, other prophets were recorded to have > done the same or similar miracles in the Old Testament. > > Jesus fed 5,000 people with five loaves of bread and two fishes. > Elisha fed 100 people with twenty barley loaves and a few ears of corn > (II Kings 4:44) > > Jesus healed lepers. > Elisha cured Naaman the leper (II Kings 5:14). > > Jesus caused the blind to see. > Elisha caused the blind to see (II Kings 6:17&20). > > Jesus raised the dead. > Elijah did the same (I Kings 17:22). So did Elisha (II Kings 4:34). > Even Elisha?s bones could restore the dead (II Kings 13:21). > > Jesus walked on water. > Moses and his people crossed the dead sea (Exodus 14:22). > > There are also ****s in the New Testament which confirm that Jesus did > not act on his own. Jesus is quoted in John 5:30, as saying: ?I can of > mine own self do nothing...? and in Luke 11:20, as saying, ?But if I > with the finger of God cast out devils, no doubt the Kingdom of God is > come upon you.? In Acts 2:22, Paul writes: ?Men of Israel, hear these > words: Jesus of Nazareth, a man attested to you by God with mighty > works and wonders and signs which God did through him in your midst, > as you yourselves know...? > > Is the message of Prophet Jesus to the worlds or the children of > Israel only?http://www.imanway.com/vb/showthread...5500# post85500 > > Jesus said, "I am the way and no one up to the father except through > me"http://www.imanway.com/vb/showthread...2091# post92091 > > The Bible itself shows a lack of Christ's crucifixion and that no one > else has the hearthttp://www.imanway.com/vb/showthread...2282# post82282 > > Gospel of Judas (to prove that the heart of Jesus Christ peace be upon > him)http://www.imanway.com/vb/showthread.php?t=14478 > > Do you send Christ to be crucified?http://www.imanway.com/vb/showthread.php?t=2588 > > Proof of the prophethood of the Prophet Jesus in the Biblehttp://www.imanway.com/vb/showthread.php?t=2610 > > Meaning of the word "Christ"http://www.imanway.com/vb/showthread.php?t=2607 > > Jesus between Islam and Christianityhttp://www.imanway.com/vb/showthread.php?t=13716 > > Prophet Jesus peace be upon him (Abdullah) in the Qur'an and the > Biblehttp://www.imanway.com/vb/showthread.php?t=10772 > > Paul is the invention of modern Christianity and destroyed the > original message of Christhttp://www.imanway.com/vb/showthread...0361# post80361 > > Confessions of the Christians themselves not credible Gospelshttp://www.imanway.com/vb/showthread.php?t=2626 > > Christian scholars recognize contradictory texts in the Biblehttp://www.imanway.com/vb/showthread.php?t=2625 > > Description of God (exalted above what they attribute) in the Biblehttp://www.imanway.com/vb/showthread.php?t=2640 > > Muslims pray as the Prophet Jesus prayedhttp://www.imanway.com/vb/showthread.php?t=2656 > > Muslim Peace Xlam prophet Jesus peace be upon himhttp://www.imanway.com/vb/showthread.php?t=2655 > > Who is the "Emmanuel" (Emmanuel: God with us means) Christians believe > that Jesus Christ but it is only the name of another person, the name > of a person shows God's help us and not the fact (that God is with us > and us in the form of human being)http://www.imanway.com/vb/showthread.php?t=2653 > > Who is the "Melchizedek" or the king of peace (not the prophet Jesus > given that he mentioned (the guide was born))http://www.imanway.com/vb/showthread.php?t=2652 > > Is the Bible the Word of God? (Sheikh Ahmed Deedat God's mercy)http://jamaat.net/bible/BibleIntro.html > > Recognition of the founder of Christianity distorted (Paul) twisting > the Biblehttp://www.imanway.com/vb/showthread.php?t=2623 > > Destruction of the principles and instructions of the prophet Jesus > peace be upon him Graphicallyhttp://www.imanway.com/vb/showthread.php?t=2622 > > History of the foundation, "Trinity or Triangulation"http://www.imanway.com/vb/showthread.php?t=2621 > > Random evidence of modern Christian thoughthttp://www.imanway.com/vb/showthread.php?t=2620 > > Prophet Jesus did not say never "was the right", he was calling to > worship God alone (according to the Bible)http://www.imanway.com/vb/showthread.php?t=2619 > > Erroneous translation of the Bible word for "worship of Christ"http://www.imanway.com/vb/showthread.php?t=2618 > > What the Bible says the sin of Adam?http://www.imanway.com/vb/showthread...3994# post83994 > > Who forgives sins?http://www.imanway.com/vb/showthread.php?t=2617 > > Lifting of the prophet Jesus does not indicate his divinityhttp://www.imanway.com/vb/showthread.php?t=2616 > > What about the previous nations that have not contemporary with Jesus > Christ? Has not been invited to the faith and the Trinity Steelhttp://www.imanway.com/vb/showthread.php?t=2615 > > Evidence to refute the divinity of Christ, peace be upon himhttp://www.imanway.com/vb/showthread.php?t=2614 > > God calls Christ "Abdi (according to the Gospel)" so it is not > unreasonable to have his son and call him sohttp://www.imanway.com/vb/showthread.php?t=2613 > > May God, "Isa (as they claim)," he prayed for himself?http://www.imanway.com/vb/showthread.php?t=2612 > > Code is "Da Vinci"http://www.imanway.com/vb/showthread.php?t=15166 > > Discuss the idea of "text from the Bible" Itallon the divinity of > Christhttp://www.imanway.com/vb/showthread.php?t=2608 > > The word "father" in the Bible did not mean the real father of Christ > and the directory as stated more than one personhttp://www.imanway.com/vb/showthread.php?t=2605 > > Miracles of the Prophet Jesus does not indicate his divinity and the > evidence that more than a prophet had miracleshttp://www.imanway.com/vb/showthread.php?t=2604 > > Some churches believe in the Prophethood of Jesus Christ peace be upon > himhttp://www.imanway.com/vb/showthread.php?t=2603 > > Refute the idea of the Trinity scientifically (analogy with water, ice > and steam)http://www.imanway.com/vb/showthread.php?t=2602 > > Logical analysishttp://www.imanway.com/vb/showthread.php?t=2599 > > Discuss the idea of triangulation and the greatest sinhttp://www.imanway.com/vb/showthread.php?t=2598 > > How the son of God? (I ask forgiveness from God)http://www.imanway.com/vb/showthread.php?t=2589 > > How mixed with polytheistic religion Christianity ideas?http://www.imanway.com/vb/showthread.php?t=2586 > > Questions from a Christian to Sheikh Mohammed Lockethttp://www.imanway.com/vb/showthread...0169# post80169 > > Answer Question: Why do Muslims hate Jesushttp://www.imanway.com/vb/showthread.php?t=16150 > > What Jesus said about the celebration of Christmas?http://www.imanway.com/vb/showthread...2283# post92283 Religion kills! From raynald.levesque at gmail.com Sat Jul 24 10:59:40 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 07:59:40 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) Message-ID: Hi I am working on a program that generates various pdf files in the / results folder. "scenario1.pdf" results from scenario1 "scenario2.pdf" results from scenario2 etc Once I am happy with scenario1.pdf and scenario2.pdf files, I would like to save them in the /check folder. Now after having developed/modified the program to produce scenario3.pdf, I would like to be able to re-generate files /results/scenario1.pdf /results/scenario2.pdf and compare them with /check/scenario1.pdf /check/scenario2.pdf I tried using the md5 module to compare these files but md5 reports differences even though the code has *not* changed at all. Is there a way to compare 2 pdf files generated at different time but identical in every other respect and validate by program that the files are identical (for all practical purposes)? From be.krul at gmail.com Sat Jul 24 11:05:12 2010 From: be.krul at gmail.com (be.krul) Date: Sat, 24 Jul 2010 08:05:12 -0700 (PDT) Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <77ccbb8b-adc5-44d3-b7b6-ef42ca455750@i18g2000pro.googlegroups.com> Message-ID: <6e53d2d0-1a13-4a44-9585-995ff422cdd5@x1g2000prc.googlegroups.com> On Jul 24, 7:39?am, Thomas Jollans wrote: > On 07/24/2010 04:20 PM, be.krul wrote: > > > On Jul 17, 10:09 pm, Chris Rebert wrote: > >> On Sat, Jul 17, 2010 at 10:01 PM, be.krul wrote: > >>> why is this group being spammed? > > >> Because that's what happens in unmoderated USENET newsgroups. > > >> Cheers, > >> Chris > > > I thought this group can be moderated, but turns out this is USENET > > Group.. > > What did you think it was? Because i joined from Goggle Groups and not the Usenet Client. From REMpeteOVE at petezilla.co.uk Sat Jul 24 11:38:52 2010 From: REMpeteOVE at petezilla.co.uk (Peter Chant) Date: Sat, 24 Jul 2010 16:38:52 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: <8b0fogF90cU2@mid.individual.net> rlevesque wrote: > Is there a way to compare 2 pdf files generated at different time but > identical in every other respect and validate by program that the > files are identical (for all practical purposes)? I wonder, do the PDFs have a timestamp within them from when they are created? That would ruin your MD5 plan. Pete -- http://www.petezilla.co.uk From __peter__ at web.de Sat Jul 24 11:50:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 17:50:31 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: rlevesque wrote: > Hi > > I am working on a program that generates various pdf files in the / > results folder. > > "scenario1.pdf" results from scenario1 > "scenario2.pdf" results from scenario2 > etc > > Once I am happy with scenario1.pdf and scenario2.pdf files, I would > like to save them in the /check folder. > > Now after having developed/modified the program to produce > scenario3.pdf, I would like to be able to re-generate > files > /results/scenario1.pdf > /results/scenario2.pdf > > and compare them with > /check/scenario1.pdf > /check/scenario2.pdf > > I tried using the md5 module to compare these files but md5 reports > differences even though the code has *not* changed at all. > > Is there a way to compare 2 pdf files generated at different time but > identical in every other respect and validate by program that the > files are identical (for all practical purposes)? Here's a naive approach, but it may be good enough for your purpose. I've printed the same small text into 1.pdf and 2.pdf (Bad practice warning: this session is slightly doctored; I hope I haven't introduced an error) >>> a = open("1.pdf").read() >>> b = open("2.pdf").read() >>> diff = [i for i, (x, y) in enumerate(zip(a, c)) if x != y] >>> len(diff) 2 >>> diff [160, 161] >>> a[150:170] '0100724151412)\n>>\nen' >>> a[140:170] 'nDate (D:20100724151412)\n>>\nen' >>> a[130:170] ')\n/CreationDate (D:20100724151412)\n>>\nen' OK, let's ignore "lines" starting with "/CreationDate " for our custom comparison function: >>> def equal_pdf(fa, fb): ... with open(fa) as a: ... with open(fb) as b: ... for la, lb in izip_longest(a, b, fillvalue=""): ... if la != lb: ... if not la.startswith("/CreationDate "): return False ... if not lb.startswith("/CreationDate "): return False ... return True ... >>> from itertools import izip_longest >>> equal_pdf("1.pdf", "2.pdf") True Peter From paulgtd at gmail.com Sat Jul 24 11:56:01 2010 From: paulgtd at gmail.com (Peo) Date: Sat, 24 Jul 2010 08:56:01 -0700 (PDT) Subject: Library versions Message-ID: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Hi, I'm writing a library for doing sysadmin tasks at my workplace. These kind of scripts have a tendency to live for decades and I want to make sure that I don't break anything when I'm updating the library. My current plan is to call the library something like 'foo1' and import it into scripts like 'import foo1 as foo'. Releases that change the API would be installed as 'foo2', 'foo3' and so on. This works fine but it will be quite difficult to create new releases (documentation and library code are littered with references to 'foo1'). Is there some other smart way to do acheive this? Thanks / Paul From brian.mingus at Colorado.EDU Sat Jul 24 11:59:22 2010 From: brian.mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 24 Jul 2010 09:59:22 -0600 Subject: why is this group being spammed? In-Reply-To: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On Sat, Jul 17, 2010 at 11:01 PM, be.krul wrote: > why is this group being spammed? > -- > http://mail.python.org/mailman/listinfo/python-list > Here's a few of theories: 1) This isn't a strong enough community to warrant a group of people who moderate the list and make sure spam doesn't come through 2) Thousands of python hackers aren't smart enough to figure out how to stop spam 3) Whenever people post threads asking why this list is getting spammed they get heckled 4) Uber leet old skool script kiddies read the list through some mechanism that allows them to get rid of the spam, unlike the other 99% of us. -------------- next part -------------- An HTML attachment was scrubbed... URL: From be.krul at gmail.com Sat Jul 24 12:43:55 2010 From: be.krul at gmail.com (nero janick) Date: Sat, 24 Jul 2010 09:43:55 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: Brian, would you like to volunteer? On Sat, Jul 24, 2010 at 8:59 AM, Brian J Mingus wrote: > > > On Sat, Jul 17, 2010 at 11:01 PM, be.krul wrote: > >> why is this group being spammed? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Here's a few of theories: > > 1) This isn't a strong enough community to warrant a group of people who > moderate the list and make sure spam doesn't come through > 2) Thousands of python hackers aren't smart enough to figure out how to > stop spam > 3) Whenever people post threads asking why this list is getting spammed > they get heckled > 4) Uber leet old skool script kiddies read the list through some mechanism > that allows them to get rid of the spam, unlike the other 99% of us. > -- \|||||/ ( ~ ~ ) @( 0 0 )@ ( C ) \ \_/ / |___| | | -------------- next part -------------- An HTML attachment was scrubbed... URL: From raynald.levesque at gmail.com Sat Jul 24 12:49:56 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 09:49:56 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) References: Message-ID: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> On Jul 24, 11:50?am, Peter Otten <__pete... at web.de> wrote: > rlevesque wrote: > > Hi > > > I am working on a program that generates various pdf files in the / > > results folder. > > > "scenario1.pdf" ?results from scenario1 > > "scenario2.pdf" results from scenario2 > > etc > > > Once I am happy with scenario1.pdf and scenario2.pdf files, I would > > like to save them in the /check folder. > > > Now after having developed/modified the program to produce > > scenario3.pdf, I would like to be able to re-generate > > files > > /results/scenario1.pdf > > /results/scenario2.pdf > > > and compare them with > > /check/scenario1.pdf > > /check/scenario2.pdf > > > I tried using the md5 module to compare these files but md5 reports > > differences even though the code has *not* changed at all. > > > Is there a way to compare 2 pdf files generated at different time but > > identical in every other respect and validate by program that the > > files are identical (for all practical purposes)? > > Here's a naive approach, but it may be good enough for your purpose. > I've printed the same small text into 1.pdf and 2.pdf > > (Bad practice warning: this session is slightly doctored; I hope I haven't > introduced an error) > > >>> a = open("1.pdf").read() > >>> b = open("2.pdf").read() > >>> diff = [i for i, (x, y) in enumerate(zip(a, c)) if x != y] > >>> len(diff) > 2 > >>> diff > [160, 161] > >>> a[150:170] > > '0100724151412)\n>>\nen'>>> a[140:170] > > 'nDate (D:20100724151412)\n>>\nen'>>> a[130:170] > > ')\n/CreationDate (D:20100724151412)\n>>\nen' > > OK, let's ignore "lines" starting with "/CreationDate " for our custom > comparison function: > > >>> def equal_pdf(fa, fb): > > ... ? ? with open(fa) as a: > ... ? ? ? ? ? ? with open(fb) as b: > ... ? ? ? ? ? ? ? ? ? ? for la, lb in izip_longest(a, b, fillvalue=""): > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? if la != lb: > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not la.startswith("/CreationDate > "): return False > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if not lb.startswith("/CreationDate > "): return False > ... ? ? ? ? ? ? ? ? ? ? return True > ...>>> from itertools import izip_longest > >>> equal_pdf("1.pdf", "2.pdf") > > True > > Peter Thanks a lot Peter. Unfortunately there is an other pair of values that does not match and it is not obvious to me how to exclude it (as is done with the " / CreationDate" pair). To illustrate the problem, I have modified your code as follows: def equal_pdf(fa, fb): idx=0 with open(fa) as a: with open(fb) as b: for la, lb in izip_longest(a, b, fillvalue=""): idx+=1 #print idx if la != lb: #if not la.startswith(" /CreationDate"): print "***", idx , la,'\n',lb #return False print "Last idx:",idx return True from itertools import izip_longest file1='K/results/Test2.pdf' file1c='K:/check/Test2.pdf' print equal_pdf(file1, file1c) I got the following output: *** 237 /CreationDate (D:20100724123129+05'00') /CreationDate (D:20100724122802+05'00') *** 324 [(,\315'\347\003_\253\325\365\265\006\)J\216\252\215) (, \315'\347\003_\253\325\365\265\006\)J\216\252\215)] [(~s\211VIA\3426}\242XuV2\302\002) (~s\211VIA \3426}\242XuV2\302\002)] Last idx: 331 True As you can see, there are 331 pair comparisons and 2 of the comparisons do not match. Your code correctly handles the " /CreationDate" pair but the other one does not have a common element that can be used to handle it. :-( As additional information in case it matters, the first pair compared equals '%PDF-1.4\n' and the pdf document is created using reportLab. One hope I have is that item 324 which is near to the last item (331) could be part of the 'trailing code' of the pdf file and might not reflect actual differences between the 2 files. In other words, maybe it would be sufficient for me to check all but the last 8 pairs... From __peter__ at web.de Sat Jul 24 13:34:36 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 24 Jul 2010 19:34:36 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: rlevesque wrote: > Unfortunately there is an other pair of values that does not match and > it is not obvious to me how to exclude it (as is done with the " / > CreationDate" pair). > and the pdf document is created using reportLab. I dug into the reportlab source and in reportlab/rl_config.py found the line invariant= 0 #produces repeatable,identical PDFs with same timestamp info (for regression testing) I suggest that you edit that file or add from reportlab import rl_config rl_config.invariant = True to your code. Peter From raynald.levesque at gmail.com Sat Jul 24 14:09:13 2010 From: raynald.levesque at gmail.com (rlevesque) Date: Sat, 24 Jul 2010 11:09:13 -0700 (PDT) Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: On Jul 24, 1:34?pm, Peter Otten <__pete... at web.de> wrote: > rlevesque wrote: > > Unfortunately there is an other pair of values that does not match and > > it is not obvious to me how to exclude it (as is done with the " / > > CreationDate" pair). > > and the pdf document is created using reportLab. > > I dug into the reportlab source and in > > reportlab/rl_config.py > > found the line > > invariant= ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? #produces > repeatable,identical PDFs with same timestamp info (for regression testing) > > I suggest that you edit that file or add > > from reportlab import rl_config > rl_config.invariant = True > > to your code. > > Peter WOW!! You are good! Your suggested solution works perfectly. Given your expertise I will not be able to 'repay' you by helping on Python problems but if you ever need help with SPSS related problems I will be pleased to provide the assistance you need. (I am the author of "SPSS Programming and Data Management" published by SPSS Inc. (an IBM company)) Regards, Raynald Levesque www.spsstools.net From nagle at animats.com Sat Jul 24 14:23:49 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 11:23:49 -0700 Subject: non-blocking IO EAGAIN on write In-Reply-To: <8at354F51tU1@mid.individual.net> References: <8at354F51tU1@mid.individual.net> Message-ID: <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> On 7/23/2010 1:45 AM, Thomas Guettler wrote: > Hi, > > I use non-blocking io to check for timeouts. Sometimes I get EAGAIN (Resource temporarily unavailable) > on write(). My working code looks like this. But I am unsure how many bytes have been written to the > pipe if I get an EAGAIN IOError. At the OS level, if you get EAGAIN, no bytes have been written. If you get EOK from a non-blocking request, you must check the number of bytes written to see if everything was written. You may have to write more after an EOK. Ref: http://www.opengroup.org/onlinepubs/009695399/functions/write.html "If the O_NONBLOCK flag is set, write() shall not block the thread. If some data can be written without blocking the thread, write() shall write what it can and return the number of bytes written. Otherwise, it shall return -1 and set errno to [EAGAIN]." At the Python level, it's different. http://docs.python.org/library/stdtypes.html#file-objects says that "file.write(s)" returns nothing. If a non-blocking write can't complete, you get an "io.BlockingIOError" exception (ref "http://docs.python.org/release/3.0.1/library/io.html") from which you can retrieve the number of bytes written. This is only in Python 3.x, and may not be working right (ref "http://bugs.python.org/issue7786"). It's unclear what happens in this situation in Python 2.x, but it's probably not what you wanted to happen. However, "socket.send(s)" returns the number of bytes sent. "send" and "recv" do work on pipes (with problems; see "http://bugs.python.org/issue5573"). So use "send", not "write", and pay attention to the number of bytes sent. > If I get EAGAIN can I just sleep, and then retry with the same data chunk? Yes. But if you've filled the pipe, you may have to wait until the program reading from the pipe reads more. This can take however long the other program needs. Incidentally, "select" apparently doesn't work on pipes under Windows. Since your code isn't doing anything else while waiting for a write to complete on the pipe, why use non-blocking I/O at all? (I know, the Python I/O timeout logic is broken in some versions. You're probably working around that.) John Nagle From pavlovevidence at gmail.com Sat Jul 24 14:57:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jul 2010 11:57:33 -0700 (PDT) Subject: Library versions References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: On Jul 24, 8:56?am, Peo wrote: > Hi, > > I'm writing a library for doing sysadmin tasks at my workplace. These > kind of > scripts have a tendency to live for decades and I want to make sure > that I don't break anything when I'm updating the library. > > My current plan is to call the library something like 'foo1' and > import it into > scripts like 'import foo1 as foo'. Releases that change the API would > be installed > as 'foo2', 'foo3' and so on. This works fine but it will be quite > difficult > to create new releases (documentation and library code are littered > with > references to 'foo1'). > > Is there some other smart way to do acheive this? The typical way to do this is to delegate responsibility to load the most recent release to another module. Create a module called foo.py, and it have it import all the objects from the most recent release module. IOW, you should have a foo.py module that looks like this: from foo1 import * Which you update whenever there's a new release. Then in your code you simply use: import foo This is, incidentally, one of the few cases where it's recommended to use from module import *. Carl Banks From breamoreboy at yahoo.co.uk Sat Jul 24 15:16:26 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 20:16:26 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: On 24/07/2010 18:01, Dennis Lee Bieber wrote: > On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" > declaimed the following in gmane.comp.python.general: > >> But maybe owner of this group do no care in that case we *all* get >> spammed! > > There is NO OWNER of comp.lang.python; and turning a comp.* group > into moderated takes a fairly long time assuming you can find someone > willing to be the moderators -- what would likely happen is that > comp.lang.python.moderated would be created and then take a few months > to be picked up by the servers, and a few more months for the real users > to leave comp.lang.python to use it. > > Oh, and also the hassle of the mailing-list<>usenet gateway (does it > pass traffic to both groups, drop the existing one, etc.). And readers > on Google may still see spam if Google takes posts stuff before it > passes through the moderation board. For the benefit of those who might have missed it, I'll repeat that I'm reading this from gmane.comp.python.general and see little or no spam. Regards. Mark Lawrence. From hujia06 at gmail.com Sat Jul 24 15:22:33 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 15:22:33 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: Hi, can I subscribe this by gmail? On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence wrote: > On 24/07/2010 18:01, Dennis Lee Bieber wrote: > >> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >> declaimed the following in gmane.comp.python.general: >> >> But maybe owner of this group do no care in that case we *all* get >>> spammed! >>> >> >> There is NO OWNER of comp.lang.python; and turning a comp.* group >> into moderated takes a fairly long time assuming you can find someone >> willing to be the moderators -- what would likely happen is that >> comp.lang.python.moderated would be created and then take a few months >> to be picked up by the servers, and a few more months for the real users >> to leave comp.lang.python to use it. >> >> Oh, and also the hassle of the mailing-list<>usenet gateway (does >> it >> pass traffic to both groups, drop the existing one, etc.). And readers >> on Google may still see spam if Google takes posts stuff before it >> passes through the moderation board. >> > > For the benefit of those who might have missed it, I'll repeat that I'm > reading this from gmane.comp.python.general and see little or no spam. > > Regards. > > Mark Lawrence. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Jul 24 15:23:38 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 24 Jul 2010 12:23:38 -0700 (PDT) Subject: understanding the mro (long) References: Message-ID: On Jul 23, 7:42?pm, Rolando Espinoza La Fuente wrote: > TL;DR: if you want to stay sane, don't inherit two classes that share > same inheritance graph [snip rest] If you want to stay sane, don't inherit from ANY class unless A. you own it, or B. it's explicitly documented as supporting inheritance Furthermore, if you want to stay sane, don't mulitply inherit from any class unless A. you own it, or B. it's explicitly documented as supporting MULTIPLE inheritance Inheritance is always risky if you don't know what you're inheriting from. Carl Banks From hujia06 at gmail.com Sat Jul 24 15:28:06 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 15:28:06 -0400 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: I subscribe for this mailing list at http://mail.python.org/mailman/listinfo/python-list On Sat, Jul 24, 2010 at 3:22 PM, Jia Hu wrote: > Hi, can I subscribe this by gmail? > > On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence wrote: > >> On 24/07/2010 18:01, Dennis Lee Bieber wrote: >> >>> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >>> declaimed the following in gmane.comp.python.general: >>> >>> But maybe owner of this group do no care in that case we *all* get >>>> spammed! >>>> >>> >>> There is NO OWNER of comp.lang.python; and turning a comp.* group >>> into moderated takes a fairly long time assuming you can find someone >>> willing to be the moderators -- what would likely happen is that >>> comp.lang.python.moderated would be created and then take a few months >>> to be picked up by the servers, and a few more months for the real users >>> to leave comp.lang.python to use it. >>> >>> Oh, and also the hassle of the mailing-list<>usenet gateway (does >>> it >>> pass traffic to both groups, drop the existing one, etc.). And readers >>> on Google may still see spam if Google takes posts stuff before it >>> passes through the moderation board. >>> >> >> For the benefit of those who might have missed it, I'll repeat that I'm >> reading this from gmane.comp.python.general and see little or no spam. >> >> Regards. >> >> Mark Lawrence. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dummey at gmail.com Sat Jul 24 16:00:40 2010 From: dummey at gmail.com (Dummey) Date: Sat, 24 Jul 2010 13:00:40 -0700 (PDT) Subject: 'as' keyword - when/how to use it References: <211c684a-39d1-4bda-834d-048c5e783bc2@w15g2000pro.googlegroups.com> <4c4ac418$0$28641$c3e8da3@news.astraweb.com> Message-ID: On Jul 24, 3:44?am, Steven D'Aprano wrote: > On Fri, 23 Jul 2010 23:33:55 -0700, Dummey wrote: > > I am having the hardest time trying to find documentation on proper use > > of the 'as' keyword (aside from . I initially thought that I would be > > allowed to do something such as: > > > import shared.util as util > > > The as statement seems to be causing a lot of ''module' object has no > > attribute'. Is it safe to assume that this is not the way to use it? > > It works for me. > > >>> import math as spam > >>> spam > > >>> import email.mime.text as ham > >>> ham > > > > My guess is that you are trying to import individual objects from a > module using the package dot notation: > > >>> import math.sin as eggs > > Traceback (most recent call last): > ? File "", line 1, in > ImportError: No module named sin > > -- > Steven I was being an idiot and doing a circular import. I erroneously thought it was the "as" part of the statement. For some reason, removing the "as" part of the statement remove/delayed the error from popping up which made me thought it was the culprit. Thanks for the help. From chrisj at puffin.com Sat Jul 24 16:17:21 2010 From: chrisj at puffin.com (Chris Jewell) Date: Sat, 24 Jul 2010 13:17:21 -0700 Subject: Where is the man page of python library References: <1aa22cd4-0b09-4480-b22b-2ac8c1eb4917@t13g2000prf.googlegroups.com> <4c491577$0$28634$c3e8da3@news.astraweb.com> <4c49abe6$0$28634$c3e8da3@news.astraweb.com> <72556b6e-239a-4d3d-bcad-a246abd85756@d17g2000yqb.googlegroups.com> Message-ID: <7r1vasiqi6.fsf@puffin.com> rantingrick writes: > On Jul 23, 9:49?am, Steven D'Aprano In the land of the blind, the one eyed man is king! ;-) "... And across the way, in the country of the witless, the half-wit is king." Richard Mitchell (a/k/a The Undeground Grammarian.) http://www.sourcetext.com/grammarian/graves-of-academe/01.htm -- Chris Jewell chrisj at puffin.com PO Box 1396 Gualala CA USA 95445-1396 From sjmachin at lexicon.net Sat Jul 24 18:37:26 2010 From: sjmachin at lexicon.net (John Machin) Date: Sat, 24 Jul 2010 22:37:26 +0000 (UTC) Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> Message-ID: dirknbr gmail.com> writes: > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' As Steven has pointed out, if the .encode('latin-1') works, the result is thrown away. This would be very fortunate. It appears that your goal was to encode the text in latin1 if possible, otherwise in UTF-8, with no indication of which encoding was used. Your second posting confirmed that you were doing this in a loop, ending up with the possibility that your output file would have records with mixed encodings. Did you consider what a programmer writing code to READ your output file would need to do, e.g. attempt to decode each record as UTF-8 with a fall-back to latin1??? Did you consider what would be the result of sending a stream of mixed-encoding text to a display device? As already advised, the short answer to avoid all of that hassle; just encode in UTF-8. From emmynoether3 at gmail.com Sat Jul 24 18:42:41 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 24 Jul 2010 15:42:41 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> Message-ID: On Jul 23, 9:27?pm, TheFlyingDutchman wrote: > On Jul 23, 12:06?pm, Emmy Noether wrote: > > > > > Title ? Portable LISP interpreter > > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date ? ? ? ?1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) ? ? ? ?UCRL-52417 > > DOE Contract Number ? ? W-7405-ENG-48 > > Resource Type ? Technical Report > > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract ? ?A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication ?United States > > Language ? ? ? ?English > > Format ?Medium: X; Size: Pages: 21 > > Availability ? ?Dep. NTIS, PC A02/MF A01. > > System Entry Date ? ? ? 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? I am glad to share with everyone. However its useless without the ability to compile and run. Also with text, its easy to read and discuss the code which has a listing of 900 lines. I have already spent 4 hours scanning/processing to a stage where I got a decent OCR which needs hand-verification of pages. I need 4 or 8 volunteers depending on whether one want to do two pages each or 1 page each. Its an hour of joyful work each for two pages. Explanation are good quality. We will re-write to C, python etc. It must be edited in emacs in fundamental mode to override pascal mode indentation. Go to pascal mode periodically to colorize to indicate errors, and then revert before inserting anything. Stay close to the original page. Email me to receive image and initial ocr and lots of fixes I did by hand for more than 4hrs. Send only plain text message or it goes to spam. Then we share with everyone here or put it on some site. E.N. From emmynoether3 at gmail.com Sat Jul 24 18:43:44 2010 From: emmynoether3 at gmail.com (Emmy Noether) Date: Sat, 24 Jul 2010 15:43:44 -0700 (PDT) Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> Message-ID: <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> On Jul 23, 9:27?pm, TheFlyingDutchman wrote: > On Jul 23, 12:06?pm, Emmy Noether wrote: > > > > > Title ? Portable LISP interpreter > > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date ? ? ? ?1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) ? ? ? ?UCRL-52417 > > DOE Contract Number ? ? W-7405-ENG-48 > > Resource Type ? Technical Report > > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract ? ?A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication ?United States > > Language ? ? ? ?English > > Format ?Medium: X; Size: Pages: 21 > > Availability ? ?Dep. NTIS, PC A02/MF A01. > > System Entry Date ? ? ? 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? Are you willing to do some work on this ? On Jul 23, 9:27 pm, TheFlyingDutchman wrote: > On Jul 23, 12:06 pm, Emmy Noether wrote: > > > > > Title Portable LISP interpreter > > Creator/Author Cox, L.A. Jr. ; Taylor, W.P. > > Publication Date 1978 May 31 > > OSTI Identifier OSTI ID: 7017786 > > Report Number(s) UCRL-52417 > > DOE Contract Number W-7405-ENG-48 > > Resource Type Technical Report > > Research Org California Univ., Livermore (USA). Lawrence Livermore > > Lab. > > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND > > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; > > PROGRAMMING LANGUAGES > > Description/Abstract A portable LISP interpreter that includes all the > > major list-processing functions is described. A complete, annotated > > listing of the program's code, written in PASCAL, is included. > > Country of Publication United States > > Language English > > Format Medium: X; Size: Pages: 21 > > Availability Dep. NTIS, PC A02/MF A01. > > System Entry Date 2008 Feb 12 > > Is this available online? If only in hardcopy form, do they lend it > out? I am glad to share with everyone. However its useless without the ability to compile and run. Also with text, its easy to read and discuss the code which has a listing of 900 lines. I have already spent 4 hours scanning/processing to a stage where I got a decent OCR which needs hand-verification of pages. I need 4 or 8 volunteers depending on whether one want to do two pages each or 1 page each. Its an hour of joyful work each for two pages. Explanation are good quality. We will re-write to C, python etc. It must be edited in emacs in fundamental mode to override pascal mode indentation. Go to pascal mode periodically to colorize to indicate errors, and then revert before inserting anything. Stay close to the original page. Email me to receive image and initial ocr and lots of fixes I did by hand for more than 4hrs. Send only plain text message or it goes to spam. Then we share with everyone here or put it on some site. E.N. From breamoreboy at yahoo.co.uk Sat Jul 24 18:46:05 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 24 Jul 2010 23:46:05 +0100 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: On 24/07/2010 20:28, Jia Hu wrote: > I subscribe for this mailing list at > http://mail.python.org/mailman/listinfo/python-list > I read through Thunderbird on Windows direct to gmane.comp.python.general. I'm no expert on such things, but assume that they are simply better [or less profitable :)] at filtering spam than the diabolical google groups. I'm unsure as to how the main mailing list that is given above works, I'm sure that someone more knowledgable than myself will soon let us know. Regards. Mark Lawrence. From navkirats at gmail.com Sat Jul 24 19:07:16 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 04:37:16 +0530 Subject: Multiprocessing zombie processes Message-ID: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Hi, I have been meddling around with forking and multiprocessing. Now both of them spawn new processes from parent (atleast from what I have understood). I have been able to reproduce a zombie state in a fork with: import os,time print('before fork',os.getpid()) pid = os.fork() if pid: print('child: ',pid) time.sleep(120) Now doing a ps ax | grep I can find a zombie child process, but I am not being able to reproduce the same with multiprocessing. Am I missing something? Or multiprocessing does not have the zombie problem? Regards, Nav From navkirats at gmail.com Sat Jul 24 19:11:39 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 04:41:39 +0530 Subject: Multiprocessing zombie processes In-Reply-To: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. Nav On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: > Hi, > > I have been meddling around with forking and multiprocessing. Now both of them spawn new processes from parent (atleast from what I have understood). I have been able to reproduce a zombie state in a fork with: > > import os,time > > print('before fork',os.getpid()) > > pid = os.fork() > > if pid: > print('child: ',pid) > time.sleep(120) > > Now doing a ps ax | grep I can find a zombie child process, but I am not being able to reproduce the same with multiprocessing. Am I missing something? Or multiprocessing does not have the zombie problem? > > Regards, > Nav From tjreedy at udel.edu Sat Jul 24 19:30:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Jul 2010 19:30:56 -0400 Subject: Are those features still the same? In-Reply-To: References: Message-ID: On 7/24/2010 8:45 AM, francogrex wrote: > Hi, I'm not a Python programmer but I'm > interested in it and I found this table from > Norvig that dates for some years (I re-posted > it temporarily on my site below to take it out > of context a little). I'm not interested in > any comparisons only in the Python features ( > last column), can someone whether the > information in the Python features column is > still correct today. Thanks > > http://francoatgrex.tripod.com/ As other have said, mostly, but I would change the following: Number of implementations should be "Many, one main' add Set ............?? set() before Hashtable/dict change Function entry to def f(x): return x+x \n lambda x: x+x or even remove mention of lambda. Anyone who thinks the table is the whole story and tries Python without knowing about def will think Python braindead. Other loops: '## works on any sequence ' change sequence to iterable. Assignment: add x,*y = 1,2,3 Add augmented assignment: x += 1 "No other control structures" is simply wrong. 'and' and 'or' are control structures as much as if-else expressions. Ditto for list/set/dict comprehensions and generator expressions. Comments "## hash mark to end of line" just one hash mark Someone mentioned apply, execfile is now(3.x) exec(open()) "No other higher-order functions built-in" wrong. func.partial, decorators, others mentioned 'No keywords on map/reduce/filter' ?? I do not know what these are, but I suspect Python can produce the same effect somehow. this looks like some lisp detail picked out as something Python does not directly have. Someone mention nonlocal to write enclosed vars. Compilation is an implementation, not a language feature. There have been lisp inerpreters in the past, if not now, and there are Python compilers now, if not in the past. Declarations Standard Python has 2, the Cython dialect has 'declarations for efficiency' just as do some lisp dialects. Quotation: lambda quotes an entire expression, and is used for one of the same purposes as list quotation, to suppress immediate execution. Lisp has one The Python equivalent of (cons x y) should just be the direct equivalent y.append(x). Python grows and shrinks list as the 'tail', lisp at the 'head'. Or, the lisp column should include the O(n) lisp code equivalent to [x]+y. The python equivalent (car x) is x.pop(). That for (cdr x) is x.pop();x, which is O(1), not O(n). Again, if the table ha the O(n) way to operate on a Python list as the 'wrong' end, it should have the same slow way to operate on the 'wrong' end of a lisp list. What that would show is that it is a lot easier to operation on the 'wrong' end of a Python list that the 'wrong' end of a Lisp list. Comparing the wrong Python way with the right Lisp way is unfair if not dishonest. -- Terry Jan Reedy From clp2 at rebertia.com Sat Jul 24 19:38:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 24 Jul 2010 16:38:29 -0700 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: > OK I wanted zombie processes > Now lets see how I can handle them. "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." Cheers, Chris -- Most people try to /avoid/ making zombies. From navkirats at gmail.com Sat Jul 24 19:43:01 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 05:13:01 +0530 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> I want to kill Zombies....so first I have to create them...simple law of nature.... On 25-Jul-2010, at 5:08 AM, Chris Rebert wrote: > On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: >> OK I wanted zombie processes > >> Now lets see how I can handle them. > > "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." > > Cheers, > Chris > -- > Most people try to /avoid/ making zombies. From john at castleamber.com Sat Jul 24 19:45:03 2010 From: john at castleamber.com (John Bokma) Date: Sat, 24 Jul 2010 18:45:03 -0500 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: <871vasla0w.fsf@castleamber.com> "be.krul" writes: > On Jul 17, 10:01?pm, "be.krul" wrote: >> why is this group being spammed? > > What I was asking is why not moderate the group. this is the only > Python group I could find.. Controlling spam starts by you! Report it. And certainly don't reply to spam by qouting the entire (religious) spam message. Moron. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From thomas at jollans.com Sat Jul 24 19:51:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 01:51:37 +0200 Subject: Multiprocessing zombie processes In-Reply-To: <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> <61D736DA-1186-4BC1-99DB-51D3A625CD2E@gmail.com> Message-ID: <4C4B7C89.8070503@jollans.com> On 07/25/2010 01:43 AM, Navkirat Singh wrote: > I want to kill Zombies....so first I have to create them...simple law of nature.... You can't kill a zombie. That's why we call them zombies, as opposed to, say, daemons. > > > On 25-Jul-2010, at 5:08 AM, Chris Rebert wrote: > >> On Sat, Jul 24, 2010 at 4:11 PM, Navkirat Singh wrote: >>> OK I wanted zombie processes >> >>> Now lets see how I can handle them. >> >> "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. Frankenstein." >> >> Cheers, >> Chris >> -- >> Most people try to /avoid/ making zombies. > From cs at zip.com.au Sat Jul 24 19:55:00 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 25 Jul 2010 09:55:00 +1000 Subject: Multiprocessing zombie processes In-Reply-To: References: Message-ID: <20100724235500.GA19364@cskk.homeip.net> [ Please don't top post. Post below so that things read like a conversation. (And trim excess quoted junk.) It doesn't take long and makes things a lot easier for your readers. ] On 25Jul2010 04:41, Navkirat Singh wrote: | On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: | > I have been meddling around with forking and multiprocessing. Now | > both of them spawn new processes from parent (atleast from what I have | > understood). I have been able to reproduce a zombie state in a fork with: | > | > import os,time | > print('before fork',os.getpid()) | > pid = os.fork() | > if pid: | > print('child: ',pid) | > time.sleep(120) | > | > Now doing a ps ax | grep I can find a zombie child process, | > but I am not being able to reproduce the same with multiprocessing. Am | > I missing something? Or multiprocessing does not have the zombie problem? | | OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. A zombie process is a fairly common thing and nothing to panic about usually. When you have a normal, running process it has an entry in the system process table (that "ps" shows) that points at it and shows its state. When a process exits, its exit status (exit code, whether it exited normally or from a signal, and if so which signal, some stats) _remain_ in the process table as a record of the exit status. This is shown as a "zombie" process in "ps" - a process which has exited and whose exit status is hanging around waiting to be collected. After the process' parent has issued a wait() call to collect the status the process slot if released and the :zombie" is gone. In your fork() example above, if that's the whole program, the child exits immediately and the parent has not waited for it. If the parent exits without waiting for all its children, the init process (process 1) inherits them, and it collects the statuses. Having a few zombies lying around isn't a disaster provided your program does get around to waiting for them at some point (or if your main program is short lived, so they get reaped by init after it exits). It's only a process table slot after all - little memory is needed for it. A program that spawns a lot of children and never waits for them _is_ bad in the long run. Process ids are often 2-byte integers on many systems for it's quite feasible to fill the table, and depending on the kernel's process table implementation a big process table might have other performance side effects. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I'm behind a corporate Exchange Server which seems to have changed recently to converting everything it sees to HTML. How embarrassing. - Dan Espen From debatem1 at gmail.com Sat Jul 24 20:03:45 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 24 Jul 2010 17:03:45 -0700 Subject: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included. In-Reply-To: <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> References: <006adcc5-9b71-44d2-91b4-9a82e895aeb1@k19g2000yqc.googlegroups.com> <3616c873-bc13-4bb1-a7d9-fd3357f9f2b1@y32g2000prc.googlegroups.com> <0f93f21b-7ff1-4946-a55b-2cae80753989@w30g2000yqw.googlegroups.com> Message-ID: On Sat, Jul 24, 2010 at 3:43 PM, Emmy Noether wrote: > On Jul 23, 9:27?pm, TheFlyingDutchman wrote: >> On Jul 23, 12:06?pm, Emmy Noether wrote: >> >> >> >> > Title ? Portable LISP interpreter >> > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. >> > Publication Date ? ? ? ?1978 May 31 >> > OSTI Identifier OSTI ID: 7017786 >> > Report Number(s) ? ? ? ?UCRL-52417 >> > DOE Contract Number ? ? W-7405-ENG-48 >> > Resource Type ? Technical Report >> > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore >> > Lab. >> > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND >> > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; >> > PROGRAMMING LANGUAGES >> > Description/Abstract ? ?A portable LISP interpreter that includes all the >> > major list-processing functions is described. A complete, annotated >> > listing of the program's code, written in PASCAL, is included. >> > Country of Publication ?United States >> > Language ? ? ? ?English >> > Format ?Medium: X; Size: Pages: 21 >> > Availability ? ?Dep. NTIS, PC A02/MF A01. >> > System Entry Date ? ? ? 2008 Feb 12 >> >> Is this available online? If only in hardcopy form, do they lend it >> out? > > Are you willing to do some work on this ? > > On Jul 23, 9:27 pm, TheFlyingDutchman wrote: >> On Jul 23, 12:06 pm, Emmy Noether wrote: >> >> >> >> > Title ? Portable LISP interpreter >> > Creator/Author ?Cox, L.A. Jr. ; Taylor, W.P. >> > Publication Date ? ? ? ?1978 May 31 >> > OSTI Identifier OSTI ID: 7017786 >> > Report Number(s) ? ? ? ?UCRL-52417 >> > DOE Contract Number ? ? W-7405-ENG-48 >> > Resource Type ? Technical Report >> > Research Org ? ?California Univ., Livermore (USA). Lawrence Livermore >> > Lab. >> > Subject 99 GENERAL AND MISCELLANEOUS//MATHEMATICS, COMPUTING, AND >> > INFORMATION SCIENCE; COMPUTER CODES; L CODES; COMPUTERS; PROGRAMMING; >> > PROGRAMMING LANGUAGES >> > Description/Abstract ? ?A portable LISP interpreter that includes all the >> > major list-processing functions is described. A complete, annotated >> > listing of the program's code, written in PASCAL, is included. >> > Country of Publication ?United States >> > Language ? ? ? ?English >> > Format ?Medium: X; Size: Pages: 21 >> > Availability ? ?Dep. NTIS, PC A02/MF A01. >> > System Entry Date ? ? ? 2008 Feb 12 >> >> Is this available online? If only in hardcopy form, do they lend it >> out? > > I am glad to share with everyone. However its useless without the > ability to compile and run. Also with text, its easy to read and > discuss the code which has a listing of 900 lines. > > I have already spent 4 hours scanning/processing to a stage where I > got a decent OCR which needs hand-verification of pages. I need 4 or 8 > volunteers depending on whether one want to do two pages each or 1 > page each. Its an hour of joyful work each for two pages. Explanation > are good quality. We will re-write to C, python etc. > > It must be edited in emacs in fundamental mode to override pascal mode > indentation. Go to pascal mode periodically to colorize to indicate > errors, and then revert before inserting anything. Stay close to the > original page. > > Email me to receive image and initial ocr and lots of fixes I did by > hand for more than 4hrs. Send only plain text message or it goes to > spam. > > Then we share with everyone here or put it on some site. Why is this on python-list? Geremy Condra From navkirats at gmail.com Sat Jul 24 21:01:23 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 06:31:23 +0530 Subject: Multiprocessing zombie processes In-Reply-To: <20100724235500.GA19364@cskk.homeip.net> References: <20100724235500.GA19364@cskk.homeip.net> Message-ID: <942DBAA4-1A29-4770-B4B2-26B143628E36@gmail.com> On 25-Jul-2010, at 5:25 AM, Cameron Simpson wrote: > [ Please don't top post. Post below so that things read like a > conversation. (And trim excess quoted junk.) It doesn't take long and > makes things a lot easier for your readers. ] > > On 25Jul2010 04:41, Navkirat Singh wrote: > | On 25-Jul-2010, at 4:37 AM, Navkirat Singh wrote: > | > I have been meddling around with forking and multiprocessing. Now > | > both of them spawn new processes from parent (atleast from what I have > | > understood). I have been able to reproduce a zombie state in a fork with: > | > > | > import os,time > | > print('before fork',os.getpid()) > | > pid = os.fork() > | > if pid: > | > print('child: ',pid) > | > time.sleep(120) > | > > | > Now doing a ps ax | grep I can find a zombie child process, > | > but I am not being able to reproduce the same with multiprocessing. Am > | > I missing something? Or multiprocessing does not have the zombie problem? > | > | OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. > > A zombie process is a fairly common thing and nothing to panic about > usually. > > When you have a normal, running process it has an entry in the > system process table (that "ps" shows) that points at it and shows its > state. > > When a process exits, its exit status (exit code, whether it exited > normally or from a signal, and if so which signal, some stats) _remain_ > in the process table as a record of the exit status. This is shown as a > "zombie" process in "ps" - a process which has exited and whose exit > status is hanging around waiting to be collected. > > After the process' parent has issued a wait() call to collect the status > the process slot if released and the :zombie" is gone. > > In your fork() example above, if that's the whole program, the child > exits immediately and the parent has not waited for it. > > If the parent exits without waiting for all its children, the init > process (process 1) inherits them, and it collects the statuses. > > Having a few zombies lying around isn't a disaster provided your program > does get around to waiting for them at some point (or if your main > program is short lived, so they get reaped by init after it exits). > It's only a process table slot after all - little memory is needed for > it. > > A program that spawns a lot of children and never waits for them _is_ > bad in the long run. Process ids are often 2-byte integers on many > systems for it's quite feasible to fill the table, and depending on the > kernel's process table implementation a big process table might have other > performance side effects. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > I'm behind a corporate Exchange Server which seems to have > changed recently to converting everything it sees to HTML. > How embarrassing. - Dan Espen Thanks a lot for all the information. It cleared a lot of my doubts. Nav From gelonida at gmail.com Sat Jul 24 21:05:53 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 03:05:53 +0200 Subject: pyqt Error with qtdesigner button groups Message-ID: Hi, I have have a layout with qt designer, which contains radio buttons. Now I want to add three buttons into a button group. doing this manually works fine with manually I mean adding a few lines in my widget class. example: bg = self.buttongroup = Qg.QButtonGroup() bg.addButton(self.radioButton, 1) bg.addButton(self.radioButton_2, 2) bg.addButton(self.radioButton_3, 3) When I try to create a button group from qt designer, then python code is created which fails when running: How I create a button group with qtdesigner. - I select my three radio buttons - I right click in the object inspector and select "Assign to Button Group" -> "New Button Group" I create my python file with pyuic4 -o mywidget.py -x mywidget.ui When I try to use my widget I receive follwoing error: Traceback (most recent call last): . . . line 37 self.QtGui.QApplication.translate("FormGridState", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(FormGridState) SyntaxError: can't assign to function call The generated code lines for the buttongroup look like: self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(Form1) self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8).setObjectName("QtGui.QApplication.translate(\"Form1\", \"buttonGroup\", None, QtGui.QApplication.UnicodeUTF8)") self.QtGui.QApplication.translate("Form1", "buttonGroup", None, QtGui.QApplication.UnicodeUTF8).addButton(self.radioButton) Am I doing something wrong or is this a bug? I'm running ubuntu 10.4 , and python 2.6 From ldo at geek-central.gen.new_zealand Sat Jul 24 21:15:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 25 Jul 2010 13:15:55 +1200 Subject: Socket performance References: Message-ID: In message , Navkirat Singh wrote: > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? Remember the old saying, ?premature optimization is the root of all evil?. Have you actually got some code working properly first, before worrying about how good or bad its performance is? -- Lawrence trying not to say ?performant? :) From greg.ewing at canterbury.ac.nz Sat Jul 24 21:58:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 25 Jul 2010 13:58:00 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> Message-ID: <8b1jgbFgbdU1@mid.individual.net> Lacrima wrote: > But what if SuperClass1 is from third party library? If it hasn't been designed for super(), then you can't use super() with it. super() only works when *every* class in the hierarchy has been designed with it in mind. -- Greg From navkirats at gmail.com Sat Jul 24 22:16:09 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 07:46:09 +0530 Subject: Socket performance In-Reply-To: References: Message-ID: <7CA752B1-75A4-4101-AD8D-970C11E477AF@gmail.com> On 25-Jul-2010, at 6:45 AM, Lawrence D'Oliveiro wrote: > In message > , Navkirat Singh wrote: > >> I had a question, programming sockets, what are the things that would >> degrade performance and what steps could help in a performance boost? > > Remember the old saying, ?premature optimization is the root of all evil?. > > Have you actually got some code working properly first, before worrying > about how good or bad its performance is? > > -- > Lawrence > trying not to say ?performant? :) > -- > http://mail.python.org/mailman/listinfo/python-list I agree with you, it was just for the sake of knowledge. Its always good to have a map right? From eldiener at tropicsoft.invalid Sat Jul 24 22:40:58 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sat, 24 Jul 2010 22:40:58 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/24/2010 6:25 AM, Mark Lawrence wrote: > On 24/07/2010 04:17, Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >> have already run into a number of them. I installed Python 2.7 and 3.1.2 >> into completely folders, but immediately ran into serious problems >> executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line or >> internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will start >> whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it puts >> in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes in >> the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > I found this only yesterday and found it extremely helpful, find the > post by Gabriel Genellina. > > http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx I found the solutions too exotic for actual use, and completely ineffectual for the cases I originally cited. The people in that thread seem to have completely forgotten that Python can be invoked externally and internally both through executing 'python(w) xxx' and through executing a file with the file extension(s) associated with Python. They seem to have forgotten this can be within scripts or any other program using Python, both written by themselves and by others, and not just by their typing 'python(w) xxx' somewhere. Their solutions seem to believe that only they will externally be i9nvoking Python and only for their own written scripts, as opposed to the many libraries using Python as well as the Python distribution itself. The best solution is some program which changes the PATH and the Python file type associations depending on which version of Python one wants to use on one's own system when more than one Python version must coexist with others. I will probably write such a program for myself. Are the .py and .pyc extensions the only ones which are associated with Python or are there others, for a normal Python installation in Windows ? From eldiener at tropicsoft.invalid Sat Jul 24 22:46:14 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sat, 24 Jul 2010 22:46:14 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/24/2010 6:25 AM, Mark Lawrence wrote: > On 24/07/2010 04:17, Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >> have already run into a number of them. I installed Python 2.7 and 3.1.2 >> into completely folders, but immediately ran into serious problems >> executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line or >> internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will start >> whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it puts >> in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes in >> the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > I found this only yesterday and found it extremely helpful, find the > post by Gabriel Genellina. > > http://www.eggheadcafe.com/software/aspnet/35716114/maintain-2-versions-of-py.aspx I found the solutions too exotic for actual use, and completely ineffectual for the cases I originally cited. The people in that thread seem to have completely forgotten that Python can be invoked externally and internally both through executing 'python(w) xxx' and through executing a file with the file extension(s) associated with Python. They seem to have forgotten this can be within scripts or any other program using Python, both written by themselves and by others, and not just by their typing 'python(w) xxx' somewhere. Their solutions seem to believe that only they will externally be i9nvoking Python and only for their own written scripts, as opposed to the many libraries using Python as well as the Python distribution itself. The best solution is some program which changes the PATH and the Python file type associations depending on which version of Python one wants to use on one's own system when more than one Python version must coexist with others. I will probably write such a program for myself. Are the .py and .pyc extensions the only ones which are associated with Python or are there others, for a normal Python installation in Windows ? From hujia06 at gmail.com Sat Jul 24 23:01:32 2010 From: hujia06 at gmail.com (Jia Hu) Date: Sat, 24 Jul 2010 23:01:32 -0400 Subject: numpy installation Message-ID: Hello: I tried to install numpy 1.4.1 from source under ubuntu following instruction at http://docs.scipy.org/doc/numpy/user/install.html I type "" python setup.py build ?help-fcompiler "" and it says gnu95 is found. Then I run ""python setup.py build ?fcompiler=gnu95"". There is error. Does anyone know how to fix it?? Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdwjfndjbdgfyg at gmail.com Sat Jul 24 23:35:27 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Sat, 24 Jul 2010 20:35:27 -0700 (PDT) Subject: SUPER HOT VIDOES Message-ID: FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From steve at REMOVE-THIS-cybersource.com.au Sat Jul 24 23:48:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 03:48:27 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> Message-ID: <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 13:58:00 +1200, Gregory Ewing wrote: > Lacrima wrote: > >> But what if SuperClass1 is from third party library? > > If it hasn't been designed for super(), then you can't use super() with > it. > > super() only works when *every* class in the hierarchy has been designed > with it in mind. That incorrect. You can certainly use super() with classic classes in the hierarchy, and super() didn't even exist when they were created. >>> class Parent: ... def method(self, arg): ... return repr(arg) ... >>> class Classic(Parent): ... def method(self, arg): ... return "argument was %s" % Parent.method(self, arg) ... >>> class New(object, Classic): ... def method(self, arg): ... return super(New, self).method(arg).upper() ... >>> x = New() >>> x.method('spam') "ARGUMENT WAS 'SPAM'" The problem isn't super(), and people who give glib advise "don't use super()" are just compounding the problem. The problem is with multiple inheritance where methods have different method signatures. If you don't change the method signatures, super() will work fine. Advising people not to use super() might make people feel virtuous, but it doesn't do anything to help the reader write non-buggy MI hierarchies. It pushes the effort of dealing with multiple inheritance onto them, forcing them to re-implement the MRO, probably badly. Can you re- implement the C3 algorithm? Have you even heard of it? If you answer No to either of those questions, chances are high that trying to deal with the MRO manually will lead to worse bugs than using super(). Should you use super()? 1. If you're doing multiple inheritance with metaclasses, you MUST use super(). 2. If you're using single inheritance only, and never modify method signatures, there is no reason not to use super(). 3. If you're using mixins, you should use super(). 4. If you never modify method signatures, then you should use super(). 5. If you do modify method signatures, you shouldn't do that (except possibly in constructors, and even there only cautiously). But if you do it anyway, then you should use super() *except* in the methods where you modify the signature. 6. If you don't use super(), chances are that your class hierarchy is still buggy, but instead of failing loudly and noisily with an exception, it's silently giving the wrong results. 7. If you can avoid multiple inheritance in favour of another technique (such as composition), you should strongly consider that. -- Steven From kushal.kumaran at gmail.com Sun Jul 25 00:22:30 2010 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Sun, 25 Jul 2010 09:52:30 +0530 Subject: non-blocking IO EAGAIN on write In-Reply-To: References: <8at354F51tU1@mid.individual.net> Message-ID: <1280031750.3257.10.camel@Nokia-N900> ----- Original message ----- > In article , >? Kushal Kumaran wrote: > > > In general, after select has told you a descriptor is ready, the > > first write after that should always succeed. > > > > Consider, for example, a write on a TCP connection.? You are sitting in > a select(), when the other side closes the connection.? The select() > should return, and the write should then immediately fail.? If you're > tempted to say that the select() should return some sort of error, > consider the case where the remote end closes the connection after the > select() returns but before your process gets to execute the following > write() call. > > We also saw a case where (due to what we consider a kernel bug), a > received UDP packet with a checksum error would cause the select() to > wake up, *then* notice the checksum error and discard the packet, and > thus the following read() would block. > > Thanks Roy. That was educational. -- regards, kushal -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Jul 25 01:03:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 24 Jul 2010 22:03:48 -0700 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On Sat, Jul 24, 2010 at 7:40 PM, Edward Diener wrote: > On 7/24/2010 6:25 AM, Mark Lawrence wrote: >> On 24/07/2010 04:17, Edward Diener wrote: >>> Are there any documents about multiple versionsof Python coexisting in >>> the same OS ( Windows in my case ) and what pitfalls to look out for ? I >>> have already run into a number of them. I installed Python 2.7 and 3.1.2 >>> into completely folders, but immediately ran into serious problems >>> executing a Python script. > The best solution is some program which changes the PATH and the Python file > type associations depending on which version of Python one wants to use on > one's own system when more than one Python version must coexist with others. > I will probably write such a program for myself. > > Are the .py and .pyc extensions the only ones which are associated with > Python or are there others, for a normal Python installation in Windows ? There's also .pyw Cheers, Chris From nagle at animats.com Sun Jul 25 01:50:25 2010 From: nagle at animats.com (John Nagle) Date: Sat, 24 Jul 2010 22:50:25 -0700 Subject: Socket performance In-Reply-To: References: Message-ID: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> On 7/23/2010 5:06 PM, Navkirat Singh wrote: > Hey Everyone, > > I had a question, programming sockets, what are the things that would > degrade performance and what steps could help in a performance boost? I > would also appreciate being pointed to some formal documentation or > article. 1. When writing to a TCP socket, write everything you have to write with one "send" or "write" operation if at all possible. Don't write a little at a time. That results in sending small packets, because sockets are "flushed" after each write. 2. Wait for input from multiple sources by using "select". (But be aware that "select" doesn't work for Windows pipes.) John Nagle From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 02:20:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 06:20:07 GMT Subject: Multiple versions of Python coexisting in the same OS References: Message-ID: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> On Sat, 24 Jul 2010 22:03:48 -0700, Chris Rebert wrote: >> Are the .py and .pyc extensions the only ones which are associated with >> Python or are there others, for a normal Python installation in Windows >> ? > > There's also .pyw Also .pyo .py = Python source code, usually associated with command line Python .pyc = Python byte code .pyo = Python optimized byte code .pyw = is Windows only, and shouldn't open a console window. -- Steven From cournape at gmail.com Sun Jul 25 04:00:24 2010 From: cournape at gmail.com (David Cournapeau) Date: Sun, 25 Jul 2010 17:00:24 +0900 Subject: numpy installation In-Reply-To: References: Message-ID: Hi Jia, On Sun, Jul 25, 2010 at 12:01 PM, Jia Hu wrote: > Hello: > > I tried to install numpy 1.4.1 from source under ubuntu following > instruction at http://docs.scipy.org/doc/numpy/user/install.html > I type "" python setup.py build ?help-fcompiler ""? and it says gnu95 is > found. Then I run ""python setup.py build ?fcompiler=gnu95"". There is > error. Please state the full error. Saying that there is an error is generally unhelpful. Also, you are more likely to receive good information on the numpy ML: http://www.scipy.org/Mailing_Lists David From ph4nut at gmail.com Sun Jul 25 04:05:43 2010 From: ph4nut at gmail.com (Twilight) Date: Sun, 25 Jul 2010 01:05:43 -0700 (PDT) Subject: Hi to the group Message-ID: <28189699-e4ed-4283-a436-3a95e6d9c0b7@a4g2000prm.googlegroups.com> I am new for Python & Django,willling to join yours! From ph4nut at gmail.com Sun Jul 25 04:05:49 2010 From: ph4nut at gmail.com (Twilight) Date: Sun, 25 Jul 2010 01:05:49 -0700 (PDT) Subject: Hi to the group Message-ID: I am new for Python & Django,willling to join yours! From franco at grex.org Sun Jul 25 05:02:40 2010 From: franco at grex.org (francogrex) Date: Sun, 25 Jul 2010 11:02:40 +0200 Subject: Are those features still the same? References: Message-ID: Terry Reedy wrote: >As other have said, mostly, but I would change the following... Thanks for all those who replied. I know these are not all the features but some of them and again this is not a comparison but a little taste of what python offers today, and the replies were very informative. By the way Peter Norvig is not biased, he works for Google research and is a supporter of programming in any language, especially in Python. From ldo at geek-central.gen.new_zealand Sun Jul 25 05:50:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 25 Jul 2010 21:50:47 +1200 Subject: Library versions References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: In message <2cb0c88b-58ea-4704-8578-2ebd766f1269 at t10g2000yqg.googlegroups.com>, Peo wrote: > My current plan is to call the library something like 'foo1' and > import it into scripts like 'import foo1 as foo'. Releases that change the > API would be installed as 'foo2', 'foo3' and so on. This works fine but it > will be quite difficult to create new releases (documentation and library > code are littered with references to 'foo1'). I don?t understand why this is a problem. The references to ?foo1? are because it is ?foo1? that implements those facilities, is it not? When ?foo2? comes along, you will introduce that name where specifying the facilities specific to it, will you not? Where both modules provide the same facilities, you will have to mention both names, and only in those cases. I don?t see how you can possibly short-cut this process and still produce correct documentation. From gelonida at gmail.com Sun Jul 25 06:07:10 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 12:07:10 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: Hi Edward, On 07/25/2010 04:40 AM, Edward Diener wrote: > I found the solutions too exotic for actual use, and completely > ineffectual for the cases I originally cited. The people in that thread > seem to have completely forgotten that Python can be invoked externally > and internally both through executing 'python(w) xxx' and through > executing a file with the file extension(s) associated with Python. They > seem to have forgotten this can be within scripts or any other program > using Python, both written by themselves and by others, and not just by > their typing 'python(w) xxx' somewhere. Their solutions seem to believe > that only they will externally be i9nvoking Python and only for their > own written scripts, as opposed to the many libraries using Python as > well as the Python distribution itself. > > The best solution is some program which changes the PATH and the Python > file type associations depending on which version of Python one wants to > use on one's own system when more than one Python version must coexist > with others. I will probably write such a program for myself. > Hi Edward, changing the path and is perfect for people who use consoles. (under linux there's virtuelenv for his and it's great) changing the file association is perfect for people who'd know at which time they want to use which version of python. The usecase, that I'm nore aware of however is somethig like having some scripts / directories, that should use one version of python and others that shoud use another. In unix you do this normally with the 'shebang line' ( e.g. #!/usr/bin/env/python2.6 ) There the windows solution could be something like a small 'pystarter' program, which would decide depending on the file's location / the file's first line which python should be started. From roy at panix.com Sun Jul 25 08:22:13 2010 From: roy at panix.com (Roy Smith) Date: Sun, 25 Jul 2010 08:22:13 -0400 Subject: Socket performance References: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> Message-ID: In article <4c4bd0b1$0$1624$742ec2ed at news.sonic.net>, John Nagle wrote: > 1. When writing to a TCP socket, write everything you have to write > with one "send" or "write" operation if at all possible. > Don't write a little at a time. That results in sending small > packets, because sockets are "flushed" after each write. There's nothing that guarantees that a single write won't be split into multiple packets, nor that multiple writes won't be coalesced into a single packet. Or any combination of splitting and coalescing that the kernel feels like. That being said, for any sane implementation, what John says is true most of the time, and is indeed a reasonable optimization. Just don't depend on it being true all the time. The most common case where it will not be true is if you're trying to send a large amount of data and exceed the MTU of the network. Then you are certain to get fragmentation. Depending on what you're doing, this can be a point of networking trivia, or it can be the difference between your application working and not working. If you're just streaming data from one place to another, you don't have to worry about it. But, if you're doing some sort of interactive protocol where you send a command, wait for a respond, send another command, etc, you really do need to be aware of how this works. Let's say you're writing something like a HTTP client. You send a bunch of headers, then expect to get back something like "200 OK\r\n", or "404 Not Found\r\n". You can't just do a read() on the socket and then examine the string to see if the first three characters are "200" or "404", because (regardless of how the server sent them), it is legal for your read() to return just a single character (i.e. "2"), and then for the next read() to get "00 OK\r\n". You need to do buffering inside your application which keeps doing read() until you find the "\r\n" (and stops there, even if the read() returned more data beyond that). From eldiener at tropicsoft.invalid Sun Jul 25 08:46:56 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 08:46:56 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 6:07 AM, Gelonida wrote: > Hi Edward, > > On 07/25/2010 04:40 AM, Edward Diener wrote: > >> I found the solutions too exotic for actual use, and completely >> ineffectual for the cases I originally cited. The people in that thread >> seem to have completely forgotten that Python can be invoked externally >> and internally both through executing 'python(w) xxx' and through >> executing a file with the file extension(s) associated with Python. They >> seem to have forgotten this can be within scripts or any other program >> using Python, both written by themselves and by others, and not just by >> their typing 'python(w) xxx' somewhere. Their solutions seem to believe >> that only they will externally be i9nvoking Python and only for their >> own written scripts, as opposed to the many libraries using Python as >> well as the Python distribution itself. >> >> The best solution is some program which changes the PATH and the Python >> file type associations depending on which version of Python one wants to >> use on one's own system when more than one Python version must coexist >> with others. I will probably write such a program for myself. >> > Hi Edward, > > changing the path and is perfect for people who use consoles. > (under linux there's virtuelenv for his and it's great) > > changing the file association is perfect for people who'd know at which > time they want to use which version of python. The problem with this is that you forget that a script can invoke Python internally. So whether one uses the console or file association method of invoking Python externally, any already written script can use either internally. > > The usecase, that I'm nore aware of however is somethig like having some > scripts / directories, that should use one version of python > and others that shoud use another. > In unix you do this normally with the 'shebang line' > ( e.g. #!/usr/bin/env/python2.6 ) > > There the windows solution could be something like a small 'pystarter' > program, which would decide depending on the file's location / the > file's first line which python should be started. This does not work when Python is invoked internally via a file association. That was the point of my saying that the simple solutions do not work. From as at sci.fi Sun Jul 25 08:47:07 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 25 Jul 2010 15:47:07 +0300 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: python at bdurham.com writes: > 1. Use an existing version control utility. There are lots of options > here(!), any recommendations on a light weight, open source one that > xcopy installs under Windows with lots of command line options? Personally, I like RCS. It seems fulfil your requirements. You can get it for Windows from http://www.cs.purdue.edu/homes/trinkle/RCS/. From eldiener at tropicsoft.invalid Sun Jul 25 08:48:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 08:48:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> References: <4c4bd797$0$28669$c3e8da3@news.astraweb.com> Message-ID: On 7/25/2010 2:20 AM, Steven D'Aprano wrote: > On Sat, 24 Jul 2010 22:03:48 -0700, Chris Rebert wrote: > >>> Are the .py and .pyc extensions the only ones which are associated with >>> Python or are there others, for a normal Python installation in Windows >>> ? >> >> There's also .pyw > > Also .pyo > > .py = Python source code, usually associated with command line Python > .pyc = Python byte code > .pyo = Python optimized byte code > .pyw = is Windows only, and shouldn't open a console window. Thanks ! I had forgotten about .pyo and .pyw under Windows. From navkirats at gmail.com Sun Jul 25 08:50:32 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Sun, 25 Jul 2010 18:20:32 +0530 Subject: Socket performance In-Reply-To: References: <4c4bd0b1$0$1624$742ec2ed@news.sonic.net> Message-ID: <80A20735-F648-454C-81E1-26B057D6D9FA@gmail.com> On 25-Jul-2010, at 5:52 PM, Roy Smith wrote: > In article <4c4bd0b1$0$1624$742ec2ed at news.sonic.net>, > John Nagle wrote: > >> 1. When writing to a TCP socket, write everything you have to write >> with one "send" or "write" operation if at all possible. >> Don't write a little at a time. That results in sending small >> packets, because sockets are "flushed" after each write. > > There's nothing that guarantees that a single write won't be split into > multiple packets, nor that multiple writes won't be coalesced into a > single packet. Or any combination of splitting and coalescing that the > kernel feels like. > > That being said, for any sane implementation, what John says is true > most of the time, and is indeed a reasonable optimization. Just don't > depend on it being true all the time. The most common case where it > will not be true is if you're trying to send a large amount of data and > exceed the MTU of the network. Then you are certain to get > fragmentation. > > Depending on what you're doing, this can be a point of networking > trivia, or it can be the difference between your application working and > not working. If you're just streaming data from one place to another, > you don't have to worry about it. But, if you're doing some sort of > interactive protocol where you send a command, wait for a respond, send > another command, etc, you really do need to be aware of how this works. > > Let's say you're writing something like a HTTP client. You send a bunch > of headers, then expect to get back something like "200 OK\r\n", or "404 > Not Found\r\n". You can't just do a read() on the socket and then > examine the string to see if the first three characters are "200" or > "404", because (regardless of how the server sent them), it is legal for > your read() to return just a single character (i.e. "2"), and then for > the next read() to get "00 OK\r\n". You need to do buffering inside > your application which keeps doing read() until you find the "\r\n" (and > stops there, even if the read() returned more data beyond that). > -- > http://mail.python.org/mailman/listinfo/python-list Thanks John, Roy. I really appreciate your valuable input. I have made a note of what you have said and will implement keeping the same in mind : ) Nav From nobody at nowhere.com Sun Jul 25 08:52:33 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 25 Jul 2010 13:52:33 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > But in the > meanwhile, once you get an error, you know what it is. You can > intentionally feed code bad data and see what you get. And then maybe > add a test to make sure your code traps such errors. That doesn't really help with exceptions which are triggered by external factors rather than explicit inputs. Also, if you're writing libraries (rather than self-contained programs), you have no control over the arguments. Coupled with the fact that duck typing is quite widely advocated in Python circles, you're stuck with the possibility that any method call on any argument can raise any exception. This is even true for calls to standard library functions or methods of standard classes if you're passing caller-supplied objects as arguments. From thomas at jollans.com Sun Jul 25 10:03:48 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 16:03:48 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C4444.6060104@jollans.com> On 07/25/2010 02:46 PM, Edward Diener wrote: > The problem with this is that you forget that a script can invoke Python > internally. So whether one uses the console or file association method > of invoking Python externally, any already written script can use either > internally. Maybe it's just me, but I think that a script that does this is quite simply badly written: it *will* break on systems that have multiple Python versions. If you let .py scripts specify which interpreter they'd like to be run with in the first line, with some sort of pystarter script that you map to the file extensions (or by using UNIX), this should work equally well no matter if the script being run by a script or by a user. If you invoke the Python interpreter directly, you should NEVER EVER assume that the interpreter is in a certain place, or on the PATH. It's a stupid idea: what if it's not? Instead, if you really must, invoke sys.executable instead of guessing. Obviously, Windows doesn't have fork(), but still, I don't see any reason to leave the comfort of your own running interpreter: you can use runpy to run python scripts. If you want them to run in the background, you can use threads, or, if you require (or want) separate processes, use multiprocessing. From news1234 at free.fr Sun Jul 25 10:31:20 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 16:31:20 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4c4c4ab8$0$8087$426a74cc@news.free.fr> On 07/25/2010 02:46 PM, Edward Diener wrote: > On 7/25/2010 6:07 AM, Gelonida wrote: >> There the windows solution could be something like a small 'pystarter' >> program, which would decide depending on the file's location / the >> file's first line which python should be started. > > This does not work when Python is invoked internally via a file > association. That was the point of my saying that the simple solutions > do not work. I'm not sure I understand. The ida is of course, that the file association would point to the pystarter and that pystarter would depending on directory / first line of the script identify the correct executable to be started with. Perhaps you could once more explain, what your intended solution would be. From gelonida at gmail.com Sun Jul 25 10:40:31 2010 From: gelonida at gmail.com (Gelonida) Date: Sun, 25 Jul 2010 16:40:31 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 07/25/2010 02:46 PM, Edward Diener wrote: > On 7/25/2010 6:07 AM, Gelonida wrote: >> Hi Edward, >> >> There the windows solution could be something like a small 'pystarter' >> program, which would decide depending on the file's location / the >> file's first line which python should be started. > > This does not work when Python is invoked internally via a file > association. That was the point of my saying that the simple solutions > do not work. What do you mean with invoking python internally? call another python script? from a python script. You could start it again via a pystarter. or just with python (assuming the starter adapts the path) The problem, that I currently encounter are some scripts, which want to use python UNO (open office delivers ther own version of python) and others which want to use libraries of my 'normal' python. having the file association point to a python starter and let the python starter choose could be an option. However I never tried so far. the fast and easy option is to just have specific file suffixes for the open office python scripts (like e.g ) .oopy From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 10:47:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 14:47:11 GMT Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> Message-ID: <4c4c4e6f$0$11094$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 13:52:33 +0100, Nobody wrote: > On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > >> But in the >> meanwhile, once you get an error, you know what it is. You can >> intentionally feed code bad data and see what you get. And then maybe >> add a test to make sure your code traps such errors. > > That doesn't really help with exceptions which are triggered by external > factors rather than explicit inputs. Huh? What do you mean by "external factors"? Do you mean like power supply fluctuations, cosmic rays flipping bits in memory, bad hardware? You can't defend against that, not without specialist fault-tolerant hardware, so just don't worry about it. If you mean external factors like "the network goes down" or "the disk is full", you can still test for those with appropriate test doubles (think "stunt doubles", only for testing) such as stubs or mocks. It's a little bit more work (sometimes a lot more work), but it can be done. Or don't worry about it. Release early, release often, and take lots of logs. You'll soon learn what exceptions can happen and what can't. Your software is still useful even when it's not perfect, and there's always time for another bug fix release. > Also, if you're writing libraries (rather than self-contained programs), > you have no control over the arguments. You can't control what the caller passes to you, but once you have it, you have total control over it. You can reject it with an exception, stick it inside a wrapper object, convert it to something else, deal with it as best you can, or just ignore it. > Coupled with the fact that duck > typing is quite widely advocated in Python circles, you're stuck with > the possibility that any method call on any argument can raise any > exception. This is even true for calls to standard library functions or > methods of standard classes if you're passing caller-supplied objects as > arguments. That's a gross exaggeration. It's true that some methods could in theory raise any exception, but in practice most exceptions are vanishingly rare. And it isn't even remotely correct that "any" method could raise anything. If you can get something other than NameError, ValueError or TypeError by calling "spam".index(arg), I'd like to see it. Frankly, it sounds to me that you're over-analysing all the things that "could" go wrong rather than focusing on the things that actually do go wrong. That's your prerogative, of course, but I don't think you'll get much support for it here. -- Steven From targetsmart at gmail.com Sun Jul 25 11:03:06 2010 From: targetsmart at gmail.com (targetsmart) Date: Sun, 25 Jul 2010 08:03:06 -0700 (PDT) Subject: Compare two nested dictionaries Message-ID: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Hi, I am trying to compare two nested dictionaries, I want to know what is the exact difference between them. I tried this solution ... s1 = set(result1) s2 = set(result2) print s1 - s2 but it doesn't seem show any difference, but assert result1 == result2 fails could someone help me to find out the difference the two nested dictionaries. Any help is greatly appreciated. Thanks, Vivek. From kwutzke at web.de Sun Jul 25 11:41:56 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Sun, 25 Jul 2010 08:41:56 -0700 (PDT) Subject: Constructor call in the same class? Message-ID: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> What's wrong with: class Enum(RootFragment): __jpaTypes = { # complete! 'CascadeType': Enum("javax.persistence.CascadeType"), 'DiscriminatorType': Enum("javax.persistence.DiscriminatorType"), 'EnumType': Enum("javax.persistence.EnumType"), 'FetchType': Enum("javax.persistence.FetchType"), 'FlushModeType': Enum("javax.persistence.FlushModeType"), 'GenerationType': Enum("javax.persistence.GenerationType"), 'InheritanceType': Enum("javax.persistence.InheritanceType"), 'LockModeType': Enum("javax.persistence.LockModeType"), 'PersistenceContextType': Enum("javax.persistence.PersistenceContextType"), 'TemporalType': Enum("javax.persistence.TemporalType"), } # constructor def __init__(self, package, modifiers, name, superInterfaces = [], annotations = [], innerClasses = [], properties = [], methods = []): RootFragment.__init__(self, packageName, modifiers, "enum", name, superInterfaces, annotations, innerClasses, properties, methods) ? I get 'CascadeType': Enum("javax.persistence.CascadeType"), NameError: name 'Enum' is not defined What's wrong with calling a constructor in a dict initializer? How do I solve this? Karsten From thomas at jollans.com Sun Jul 25 11:53:01 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 17:53:01 +0200 Subject: Constructor call in the same class? In-Reply-To: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> References: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> Message-ID: <4C4C5DDD.3010004@jollans.com> On 07/25/2010 05:41 PM, Karsten Wutzke wrote: > What's wrong with: > > class Enum(RootFragment): > __jpaTypes = { > # complete! > 'CascadeType': Enum("javax.persistence.CascadeType"), > 'DiscriminatorType': > Enum("javax.persistence.DiscriminatorType"), > 'EnumType': Enum("javax.persistence.EnumType"), > 'FetchType': Enum("javax.persistence.FetchType"), > 'FlushModeType': Enum("javax.persistence.FlushModeType"), > 'GenerationType': Enum("javax.persistence.GenerationType"), > 'InheritanceType': Enum("javax.persistence.InheritanceType"), > 'LockModeType': Enum("javax.persistence.LockModeType"), > 'PersistenceContextType': > Enum("javax.persistence.PersistenceContextType"), > 'TemporalType': Enum("javax.persistence.TemporalType"), > } > > # constructor > def __init__(self, package, modifiers, name, superInterfaces = [], > annotations = [], innerClasses = [], properties = [], > methods = []): > RootFragment.__init__(self, packageName, modifiers, "enum", > name, superInterfaces, annotations, innerClasses, properties, methods) > > > ? > > I get > > 'CascadeType': Enum("javax.persistence.CascadeType"), > > NameError: name 'Enum' is not defined well, within the class statement, it's not defined. So you can't call Enum yet. You have to create your dict somewhere else. You can either set it from outside: class Enum(RootFragment): ... Enum._jpaTypes = { ... } Or, do exactly the same thing, but within a class method: class Enum(bla): @classmethod def contruct_jpatypes(cls): cls.__jpaTypes = { ... } Enum.construct_jpatypes() > > What's wrong with calling a constructor in a dict initializer? How do > I solve this? > > Karsten From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 12:21:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Jul 2010 16:21:14 GMT Subject: Compare two nested dictionaries References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Message-ID: <4c4c647a$0$11094$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 08:03:06 -0700, targetsmart wrote: > Hi, > I am trying to compare two nested dictionaries, I want to know what is > the exact difference between them. I tried this solution > > ... > s1 = set(result1) > s2 = set(result2) > print s1 - s2 > > but it doesn't seem show any difference, but > > assert result1 == result2 > fails > > could someone help me to find out the difference the two nested > dictionaries. Have you tried printing them and just looking for the differences? Calling set() on a dictionary will create a set from the keys only: >>> d1 = {"a": 1, "b": 2} >>> d2 = {"a": 1, "b": 999} >>> set(d1) == set(d2) True >>> d1 == d2 False If you want to know the difference between two dictionaries, you have to consider: (1) Keys that are in the first dict, but not the second; (2) Keys that are in the second dict, but not the first; and (3) Keys which are in both dicts, but have different values. -- Steven From news1234 at free.fr Sun Jul 25 12:30:30 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 18:30:30 +0200 Subject: Compare two nested dictionaries In-Reply-To: <4c4c647a$0$11094$c3e8da3@news.astraweb.com> References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> <4c4c647a$0$11094$c3e8da3@news.astraweb.com> Message-ID: <4c4c66a6$0$6823$426a74cc@news.free.fr> Hi, On 07/25/2010 06:21 PM, Steven D'Aprano wrote: > On Sun, 25 Jul 2010 08:03:06 -0700, targetsmart wrote: > >> Hi, >> I am trying to compare two nested dictionaries, I want to know what is >> the exact difference between them. I tried this solution >> >> ... >> s1 = set(result1) >> s2 = set(result2) >> print s1 - s2 >> I think you want to have the symmetric difference: try s1 ^ s2 >> but it doesn't seem show any difference, but >> From kwutzke at web.de Sun Jul 25 12:30:43 2010 From: kwutzke at web.de (Karsten Wutzke) Date: Sun, 25 Jul 2010 09:30:43 -0700 (PDT) Subject: Constructor call in the same class? References: <1404d94f-8db7-4999-822a-5ee0b864b921@s9g2000yqd.googlegroups.com> Message-ID: > > You have to create your dict somewhere else. You can either set it from > outside: > > class Enum(RootFragment): > ? ? ... > > Enum._jpaTypes = { ... } > THANKS for the quick help. Karsten From python at rcn.com Sun Jul 25 13:02:52 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 25 Jul 2010 10:02:52 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> Message-ID: <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> On Jul 24, 3:56?am, Lacrima wrote: > Thank you for your answer. You're welcome. > Some things are still not clear. Your example works great. But if I > remove "super(SuperClass1, self).__init__(**kwds)" from SuperClass1's > __init__, the example stops working. That is when I instantiate > SubClass only __init__ of SuperClass1 is called and __init__ of > SuperClass2 is omitted, i.e. only 'Python' is printed. Why is it so? > > So as I understand every parent should necessarily call super() at the > end of its __init__ method in order for things to work properly. Yes. That's correct. Python's super() was designed to support cooperative multiple inheritance. The "cooperative" part means that every class implementing the target method (such as __init__ in your example) needs to call super() in order to trigger the next method in the sequence (the method resolution order or MRO). > But what if SuperClass1 is from third party library? . . . > How to deal with that? Then, the odds are that that class isn't "cooperating". You can either wrap the third-party library to add a super() call or you can switch to an alternate design using composition instead of inheritance. Raymond P.S. Outside of the simple case of single inheritance, the one key to understanding super() is to forget about the concept of parent classes. Instead, super() is all about the MRO which is computed dynamically (unknowable at the time a class is written). Every class in the MRO implementing the target method *must* call super() to give the next class in the MRO a chance to run. IOW, using super() means "I'm in the MRO and I got a chance to run; now the next class in the MRO gets its chance." Since the MRO is only knowable at runtime, the sole job of super() is to figure out which is "the next class in the MRO". From python at rcn.com Sun Jul 25 13:20:01 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 25 Jul 2010 10:20:01 -0700 (PDT) Subject: Compare two nested dictionaries References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> <4c4c647a$0$11094$c3e8da3@news.astraweb.com> Message-ID: [targetsmart] > > I am trying to compare two nested dictionaries, I want to know what is > > the exact difference between them. I tried this solution [Steven D'Aprano] > If you want to know the difference between two dictionaries, you have to > consider: > > (1) Keys that are in the first dict, but not the second; > > (2) Keys that are in the second dict, but not the first; and > > (3) Keys which are in both dicts, but have different values. Steven, thanks for the excellent specification. Here's the code: s1 = set(d1) s2 = set(d2) first_not_second = s1 - s2 second_not_first = s2 - s1 difference_values = set(k for k in s1 & s2 if d1[k] != d2[k]) If the values are hashable, an alternate approach is: s1 = set(d1.items()) s2 = set(d2.items()) first_not_second = s1 - s2 second_not_first = s2 - s1 Raymond From joel.goldstick at columbuswebmakers.com Sun Jul 25 13:51:07 2010 From: joel.goldstick at columbuswebmakers.com (Joel Goldstick) Date: Sun, 25 Jul 2010 13:51:07 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C798B.6030100@columbuswebmakers.com> Edward Diener wrote: > Are there any documents about multiple versionsof Python coexisting in > the same OS ( Windows in my case ) and what pitfalls to look out for ? I > have already run into a number of them. I installed Python 2.7 and 3.1.2 > into completely folders, but immediately ran into serious problems > executing a Python script. > > The first problem is that just invoking Python will start whichever > version is first in the PATH, and this is true from the command line or > internally in a Python script. > > The second problem is that invoking a script ( some xxx.py ) will start > whichever version of Python is associated with the .py extension. > > The third problem is if some software expects its scripts, which it puts > in some Python subdirectory to be in the PATH. > > There may be other considerations but overall having to versions > coexisting has turned out to be a big headache involving both changes in > the PATH and in the .py association. > > Does anybody know of other things to look out for ? There is this: http://pypi.python.org/pypi/virtualenv We have a good group in NYC for python and django. That's where I learned about virtualevn. I admit I'm not fully up to speed on it, but it lets you set up multiple 'virtual environments' for python to do exactly what I think you are asking about Joel Goldstick From zooko at zooko.com Sun Jul 25 14:07:51 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Sun, 25 Jul 2010 12:07:51 -0600 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On Wed, Jul 7, 2010 at 3:32 AM, Jonathan Hartley wrote: > > I presume this problem would go away if future versions of Python > itself were compiled on Windows with something like MinGW gcc. You might want to track issue3871. Roumen Petrov has done a lot of work to make CPython compilable with mingw on Windows, as well as to make it possible to compile CPython on a different operating system and produce a CPython executable for Windows (cross-compile). And by the way, I've usually had success building my native extension modules with mingw. I understand (vaguely) that if a native extension module needs to pass FILE*'s or C++ iostreams back and forth to different extension modules or the the core CPython interpreter then this could lead to segfaults, but none of my extension modules need to do that. I would suggest that people try to build their native extension modules with mingw, and if it doesn't work report a bug (to mingw project and to the Python project) so that we can track more precisely what the issues are. Regards, Zooko http://bugs.python.org/issue3871# cross and native build of python for mingw32 with distutils From gd.usenet at spamfence.net Sun Jul 25 14:42:27 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 25 Jul 2010 20:42:27 +0200 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: python at bdurham.com wrote: >I have some very simple use cases[1] for adding some version control >capabilities to a product I'm working on. My product uses simple, text >(UTF-8) based scripts that are independent of one another. I would like >to "version control" these scripts on behalf of my users. By version >control, I mean *very-simple* version control with no branching or >merging - just the ability to store, list and restore a specific version >of a file. The data store should be a local file with the ability to >upsize to a multi-user database in the future. > >I'm looking for recommendations on possible solutions: > >1. Use an existing version control utility. There are lots of options >here(!), any recommendations on a light weight, open source one that >xcopy installs under Windows with lots of command line options? > >2. Interface to a hosted version control system (SaaS) that provides a >RESTful API. Any recommendations here? > >3. Build this capability myself using Python and Python's DBI layer to >store files in a local SQLite database at first (but with the ability to >upsize to a real client server database in the future). Seems like a fun >project to work on, but also smells like I'd be re-inventing the wheel >with very little value added other than simpler deployment? > >Any suggestions appreciated. Use Mercurial (). It is written in python, can be extended by python modules/packages and can be used by python programs directly. >1. Check a file in with optional comment and username; ideally >get a version number that can be used to reference this specific >check-in in the future. That's a basic task in mercurial (as probably in every version control system). >2. Get a history listing of all checkins for a specific file >(version number, timestamp, file size, user, comment) Also avalilable. I am not sure about file size and comment, but if you have the list of version numbers, you can extract this info from the repository easily. >3. Check out a specific version of a file by version number. See point 1. >4. Delete checked-in versions by version number, date range, >and/or username. I've never tried it with mercurial. There are a remove and a forget command. Maybe, one could use the rebase extension. But deleting changesets from a repository usually is a bad idea. >5. (Optional) Diff 2 versions of a file by version number and >return diff in richly formatted format that visually shows >changes via color and font effects (strikethru) (I'm thinking >of using BeyondCompare for this if not present in a simple >version control tool) Also available. Regards, G?nther From eldiener at tropicsoft.invalid Sun Jul 25 15:12:54 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:12:54 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 1:51 PM, Joel Goldstick wrote: > Edward Diener wrote: >> Are there any documents about multiple versionsof Python coexisting in >> the same OS ( Windows in my case ) and what pitfalls to look out for ? >> I have already run into a number of them. I installed Python 2.7 and >> 3.1.2 into completely folders, but immediately ran into serious >> problems executing a Python script. >> >> The first problem is that just invoking Python will start whichever >> version is first in the PATH, and this is true from the command line >> or internally in a Python script. >> >> The second problem is that invoking a script ( some xxx.py ) will >> start whichever version of Python is associated with the .py extension. >> >> The third problem is if some software expects its scripts, which it >> puts in some Python subdirectory to be in the PATH. >> >> There may be other considerations but overall having to versions >> coexisting has turned out to be a big headache involving both changes >> in the PATH and in the .py association. >> >> Does anybody know of other things to look out for ? > > There is this: > http://pypi.python.org/pypi/virtualenv It appears to be only for Linux. From eldiener at tropicsoft.invalid Sun Jul 25 15:19:53 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:19:53 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 10:03 AM, Thomas Jollans wrote: > On 07/25/2010 02:46 PM, Edward Diener wrote: >> The problem with this is that you forget that a script can invoke Python >> internally. So whether one uses the console or file association method >> of invoking Python externally, any already written script can use either >> internally. > > Maybe it's just me, but I think that a script that does this is quite > simply badly written: it *will* break on systems that have multiple > Python versions. Whether it is badly written or not in your opinion it is legal and happens all the time. Are you going to refuse to use any script, no matter for what library or for what purpose, that internally invokes Python either through a 'python' command or through a file with a Python extension ? And how would you find out if a script did this or not ? Are going to search every script in every distribution and library to determine if it does this ? And when you find out a script does this, what will you do ? Be real. saying you do not like scripts that internally invoke Python does not solve anything if you have multiple coexisting versions of Python installed. From thomas at jollans.com Sun Jul 25 15:27:57 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:27:57 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C903D.9070902@jollans.com> On 07/25/2010 09:12 PM, Edward Diener wrote: > On 7/25/2010 1:51 PM, Joel Goldstick wrote: >> There is this: >> http://pypi.python.org/pypi/virtualenv > > It appears to be only for Linux. I don't know where you get that impression from. I don't know how well it works on which platforms, but the fact that there is a "Note for Windows:" does suggest that it does work on windows. From thomas at jollans.com Sun Jul 25 15:32:30 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:32:30 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: <4C4C914E.307@jollans.com> On 07/25/2010 09:19 PM, Edward Diener wrote: > On 7/25/2010 10:03 AM, Thomas Jollans wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> The problem with this is that you forget that a script can invoke Python >>> internally. So whether one uses the console or file association method >>> of invoking Python externally, any already written script can use either >>> internally. >> >> Maybe it's just me, but I think that a script that does this is quite >> simply badly written: it *will* break on systems that have multiple >> Python versions. > > Whether it is badly written or not in your opinion it is legal and > happens all the time. Are you going to refuse to use any script, no > matter for what library or for what purpose, that internally invokes > Python either through a 'python' command or through a file with a Python > extension ? And how would you find out if a script did this or not ? Are > going to search every script in every distribution and library to > determine if it does this ? And when you find out a script does this, > what will you do ? > > Be real. saying you do not like scripts that internally invoke Python > does not solve anything if you have multiple coexisting versions of > Python installed. I doubt many scripts do it. The fact of the matter is: many systems have multiple Python versions installed in parallel, and it probably will break somewhere, which will get noticed, and probably fixed. If a script uses sys.executable instead of "python", there is no problem, at all. From eldiener at tropicsoft.invalid Sun Jul 25 15:33:00 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 15:33:00 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c4ab8$0$8087$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> Message-ID: On 7/25/2010 10:31 AM, News123 wrote: > On 07/25/2010 02:46 PM, Edward Diener wrote: >> On 7/25/2010 6:07 AM, Gelonida wrote: > >>> There the windows solution could be something like a small 'pystarter' >>> program, which would decide depending on the file's location / the >>> file's first line which python should be started. >> >> This does not work when Python is invoked internally via a file >> association. That was the point of my saying that the simple solutions >> do not work. > > I'm not sure I understand. The ida is of course, that the file > association would point to the pystarter and that pystarter would > depending on directory / first line of the script > identify the correct executable to be started with. > > > > Perhaps you could once more explain, what your intended solution would be. How does a 'pystarter' program know where the file's location is which is being invoked ? As to the first file line this is completely unrealistic. What are you going to do, alter the first file line of every script in a Python distribution and every script in every library installed in a Python distribution ? Sorry, but a less intrusive solution is much better and much less of a headache to say the least. My intended solution would be a simple program which understands where each co-existing Python distribution is installed on a system and what the "name" of that distribution is. Then you tell the program which Python distribution should be the current one by its "name", the current one meaning the distribution which you want to be invoked at any given time. The program then changes the PATH so that any references to the Python directory and its subdirectories point to the "name" Python directory tree, and changes the file associations so that the "name" Python executables handle the Python associations. This does have the weakness that I can not use more than one Python distribution while Python is executing scripts. But I can personally live with that since I have never encountered a situation where I must use more than one Python distribution at the same time. From lists at cheimes.de Sun Jul 25 15:39:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 25 Jul 2010 21:39:59 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4C4C914E.307@jollans.com> References: <4C4C914E.307@jollans.com> Message-ID: Am 25.07.2010 21:32, schrieb Thomas Jollans: > If a script uses sys.executable instead of "python", there is no > problem, at all. It's true that sys.executable is the best way if you have to start a new Python interpreter. However sys.executable may not be set for NT services. So there may be a problem after all. From thomas at jollans.com Sun Jul 25 15:48:14 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 21:48:14 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4C94FE.2060109@jollans.com> On 07/25/2010 09:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. Interesting. Does the multiprocessing module still work in that scenario? From news1234 at free.fr Sun Jul 25 16:04:35 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:04:35 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4c4c98d4$0$8275$426a74cc@news.free.fr> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. sys.executable will not work with scripts converted with py2exe, as sys.executable will not be the executable of the python interpreter, but with the main executable's name. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. > From thomas at jollans.com Sun Jul 25 16:18:27 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 22:18:27 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c98d4$0$8275$426a74cc@news.free.fr> References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> Message-ID: <4C4C9C13.3050404@jollans.com> On 07/25/2010 10:04 PM, News123 wrote: > sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>> If a script uses sys.executable instead of "python", there is no >>> problem, at all. > > > sys.executable will not work with scripts converted with py2exe, > as sys.executable will not be the executable of the python interpreter, > but with the main executable's name. Well, but a script converted with py2exe can't really ever assume that there is a Python interpreter, at all. From news1234 at free.fr Sun Jul 25 16:22:33 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:22:33 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> Message-ID: <4c4c9d09$0$5331$426a74cc@news.free.fr> On 07/25/2010 09:33 PM, Edward Diener wrote: > On 7/25/2010 10:31 AM, News123 wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> On 7/25/2010 6:07 AM, Gelonida wrote: > > How does a 'pystarter' program know where the file's location is which > is being invoked ? the file's location would be somewhere in sys.argv probably in sys.argv[1]. converting it to an abs path would return a directory which the python file belongs to. > As to the first file line this is completely > unrealistic. What are you going to do, alter the first file line of > every script in a Python distribution and every script in every library > installed in a Python distribution ? Sorry, but a less intrusive > solution is much better and much less of a headache to say the least. > Well I would at least do it for all of my self written scripts. It could allow a soft transition from 2.6 to 2.7 to 3.0 without having to upgrade all scripts at the same time. > My intended solution would be a simple program which understands where > each co-existing Python distribution is installed on a system and what > the "name" of that distribution is. Then you tell the program which > Python distribution should be the current one by its "name", the current > one meaning the distribution which you want to be invoked at any given > time. The program then changes the PATH so that any references to the > Python directory and its subdirectories point to the "name" Python > directory tree, and changes the file associations so that the "name" > Python executables handle the Python associations. > > This does have the weakness that I can not use more than one Python > distribution while Python is executing scripts. But I can personally > live with that since I have never encountered a situation where I must > use more than one Python distribution at the same time. > I guess it's rather difficult to find a solution which suits all. The above minor weakness, that you mention would be a killer for me. Currently I'm looking for solutions, where I can start python scripts requireing different python versions at the same time. Currently I'm staring the scripts manually from two different cmd line windows with a different path name and an explicit python call, Thus my idea of having a pystarter with a config file mentioning which directories (tools) should use which python executable From news1234 at free.fr Sun Jul 25 16:26:34 2010 From: news1234 at free.fr (News123) Date: Sun, 25 Jul 2010 22:26:34 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> Message-ID: <4c4c9dfa$0$23878$426a74cc@news.free.fr> On 07/25/2010 10:18 PM, Thomas Jollans wrote: > On 07/25/2010 10:04 PM, News123 wrote: >> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>> If a script uses sys.executable instead of "python", there is no >>>> problem, at all. >> >> >> sys.executable will not work with scripts converted with py2exe, >> as sys.executable will not be the executable of the python interpreter, >> but with the main executable's name. > > Well, but a script converted with py2exe can't really ever assume that > there is a Python interpreter, at all. true :-) However, why I thought about this is, that I write sometimes python code, which tries to call other python files. later on for distribution I use py2exe. Therefore I use wrapper functions, which will work in either case. The wrapper could use sys.executable in 'python mode' and had to call the exe file in 'py2exe mode' From python at mrabarnett.plus.com Sun Jul 25 16:39:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Jul 2010 21:39:14 +0100 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9d09$0$5331$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: <4C4CA0F2.3010203@mrabarnett.plus.com> News123 wrote: > On 07/25/2010 09:33 PM, Edward Diener wrote: >> On 7/25/2010 10:31 AM, News123 wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> On 7/25/2010 6:07 AM, Gelonida wrote: > >> How does a 'pystarter' program know where the file's location is which >> is being invoked ? > the file's location would be somewhere in sys.argv > probably in sys.argv[1]. > converting it to an abs path would return a directory which the python > file belongs to. > > >> As to the first file line this is completely >> unrealistic. What are you going to do, alter the first file line of >> every script in a Python distribution and every script in every library >> installed in a Python distribution ? Sorry, but a less intrusive >> solution is much better and much less of a headache to say the least. >> > Well I would at least do it for all of my self written scripts. > > It could allow a soft transition from 2.6 to 2.7 to 3.0 without having > to upgrade all scripts at the same time. > >> My intended solution would be a simple program which understands where >> each co-existing Python distribution is installed on a system and what >> the "name" of that distribution is. Then you tell the program which >> Python distribution should be the current one by its "name", the current >> one meaning the distribution which you want to be invoked at any given >> time. The program then changes the PATH so that any references to the >> Python directory and its subdirectories point to the "name" Python >> directory tree, and changes the file associations so that the "name" >> Python executables handle the Python associations. > > >> This does have the weakness that I can not use more than one Python >> distribution while Python is executing scripts. But I can personally >> live with that since I have never encountered a situation where I must >> use more than one Python distribution at the same time. >> > > I guess it's rather difficult to find a solution which suits all. > > The above minor weakness, that you mention would be a killer for me. > > Currently I'm looking for solutions, where I can start python scripts > requireing different python versions at the same time. > > Currently I'm staring the scripts manually from two different cmd line > windows with a different path name and an explicit python call, > > Thus my idea of having a pystarter with a config file > mentioning which directories (tools) should use which python executable > I think that's the wrong way round. A pystarter should ask the _tool_ which version of Python it needs. From eldiener at tropicsoft.invalid Sun Jul 25 17:09:00 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:09:00 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: Message-ID: On 7/25/2010 3:32 PM, Thomas Jollans wrote: > On 07/25/2010 09:19 PM, Edward Diener wrote: >> On 7/25/2010 10:03 AM, Thomas Jollans wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> The problem with this is that you forget that a script can invoke Python >>>> internally. So whether one uses the console or file association method >>>> of invoking Python externally, any already written script can use either >>>> internally. >>> >>> Maybe it's just me, but I think that a script that does this is quite >>> simply badly written: it *will* break on systems that have multiple >>> Python versions. >> >> Whether it is badly written or not in your opinion it is legal and >> happens all the time. Are you going to refuse to use any script, no >> matter for what library or for what purpose, that internally invokes >> Python either through a 'python' command or through a file with a Python >> extension ? And how would you find out if a script did this or not ? Are >> going to search every script in every distribution and library to >> determine if it does this ? And when you find out a script does this, >> what will you do ? >> >> Be real. saying you do not like scripts that internally invoke Python >> does not solve anything if you have multiple coexisting versions of >> Python installed. > > I doubt many scripts do it. The fact of the matter is: many systems have > multiple Python versions installed in parallel, and it probably will > break somewhere, which will get noticed, and probably fixed. > > If a script uses sys.executable instead of "python", there is no > problem, at all. What a script uses to internally invoke Python I can not control. My solution seeks to be non-intrusive and lets me run a particular version of Python, among the co-existing versions installed, at any given time. I believe that is the best I can do. I neither can control, nor do I want to control, all of the Python scripts installed on my system, nor can I worry how they may internally invoke Python. But I do want to be able to say, at any given time, that when I run Python a particular version, amidst the co-existing ones on my system, needs to be executed and therafter all internally executed modules use that version. Trying to make rules for scripts, such as telling scripts they must use sys.executable, is pursuing an imaginary solution that can not work unless one is theoretically willing to manually inspect and change all Python scripts in some way. To me any intrusive changes to actual scripts is no solution at all. From eldiener at tropicsoft.invalid Sun Jul 25 17:10:47 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:10:47 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 3:39 PM, Christian Heimes wrote: > Am 25.07.2010 21:32, schrieb Thomas Jollans: >> If a script uses sys.executable instead of "python", there is no >> problem, at all. > > It's true that sys.executable is the best way if you have to start a new > Python interpreter. However sys.executable may not be set for NT > services. So there may be a problem after all. > Once you start instrusively changing scripts to find a solution to multiple versions of Python co-existing in one system, you are heading down a path of endless problems. From eldiener at tropicsoft.invalid Sun Jul 25 17:19:04 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:19:04 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9d09$0$5331$426a74cc@news.free.fr> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: On 7/25/2010 4:22 PM, News123 wrote: > On 07/25/2010 09:33 PM, Edward Diener wrote: >> On 7/25/2010 10:31 AM, News123 wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> On 7/25/2010 6:07 AM, Gelonida wrote: > >> >> How does a 'pystarter' program know where the file's location is which >> is being invoked ? > the file's location would be somewhere in sys.argv > probably in sys.argv[1]. > converting it to an abs path would return a directory which the python > file belongs to. > > >> As to the first file line this is completely >> unrealistic. What are you going to do, alter the first file line of >> every script in a Python distribution and every script in every library >> installed in a Python distribution ? Sorry, but a less intrusive >> solution is much better and much less of a headache to say the least. >> > Well I would at least do it for all of my self written scripts. > > It could allow a soft transition from 2.6 to 2.7 to 3.0 without having > to upgrade all scripts at the same time. Intrusively changing scripts is a path to Python hell. > >> My intended solution would be a simple program which understands where >> each co-existing Python distribution is installed on a system and what >> the "name" of that distribution is. Then you tell the program which >> Python distribution should be the current one by its "name", the current >> one meaning the distribution which you want to be invoked at any given >> time. The program then changes the PATH so that any references to the >> Python directory and its subdirectories point to the "name" Python >> directory tree, and changes the file associations so that the "name" >> Python executables handle the Python associations. > > >> >> This does have the weakness that I can not use more than one Python >> distribution while Python is executing scripts. But I can personally >> live with that since I have never encountered a situation where I must >> use more than one Python distribution at the same time. >> > > I guess it's rather difficult to find a solution which suits all. > > The above minor weakness, that you mention would be a killer for me. > > Currently I'm looking for solutions, where I can start python scripts > requireing different python versions at the same time. If you need that, then of course my intended solution would not work. > > Currently I'm staring the scripts manually from two different cmd line > windows with a different path name and an explicit python call, If you start scripts and point to a specific version of Python, this works in my solution also. But if an internal call to Python exists thwre is always a problem. > > Thus my idea of having a pystarter with a config file > mentioning which directories (tools) should use which python executable Well, good luck ! I don;t know how this is resolved for you when some scripts executes 'python xxx yyy' or 'someScript.py yyy'. From eldiener at tropicsoft.invalid Sun Jul 25 17:21:55 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 17:21:55 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4c9dfa$0$23878$426a74cc@news.free.fr> References: <4C4C914E.307@jollans.com> <4c4c98d4$0$8275$426a74cc@news.free.fr> <4c4c9dfa$0$23878$426a74cc@news.free.fr> Message-ID: On 7/25/2010 4:26 PM, News123 wrote: > On 07/25/2010 10:18 PM, Thomas Jollans wrote: >> On 07/25/2010 10:04 PM, News123 wrote: >>> sOn 07/25/2010 09:39 PM, Christian Heimes wrote: >>>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>>> If a script uses sys.executable instead of "python", there is no >>>>> problem, at all. >>> >>> >>> sys.executable will not work with scripts converted with py2exe, >>> as sys.executable will not be the executable of the python interpreter, >>> but with the main executable's name. >> >> Well, but a script converted with py2exe can't really ever assume that >> there is a Python interpreter, at all. > > true :-) > > > However, why I thought about this is, that > I write sometimes python code, which tries to call other python files. > > later on for distribution I use py2exe. > > Therefore I use wrapper functions, which will work in either case. > > The wrapper could use sys.executable in 'python mode' > and had to call the exe file in 'py2exe mode' > You can control what you do but how are you going to control what any givemn script does ? Attempting to intrusively change potentially every script in a distribution in any way is a path to Python hell IMO. From thomas at jollans.com Sun Jul 25 17:57:45 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sun, 25 Jul 2010 23:57:45 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4CB359.5040900@jollans.com> On 07/25/2010 11:10 PM, Edward Diener wrote: > On 7/25/2010 3:39 PM, Christian Heimes wrote: >> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>> If a script uses sys.executable instead of "python", there is no >>> problem, at all. >> >> It's true that sys.executable is the best way if you have to start a new >> Python interpreter. However sys.executable may not be set for NT >> services. So there may be a problem after all. >> > > Once you start instrusively changing scripts to find a solution to > multiple versions of Python co-existing in one system, you are heading > down a path of endless problems. What exactly is it that you're afraid to change? The standard library? There's certainly no need to change that in any way! Your own code? That'd just be nonsense. Someone else's then. Is there any problem at all when you start it with a specific Python interpreter? I expect that there probably isn't. If there is, if the code makes ANY assumptions about where to find a Python interpreter on your system, I would consider that a serious bug that should be reported. If it's only one or two affected lines of code, why not change them? There's nothing intrusive or wrong about fixing something on your own computer! If it turns out that you'd have to change a lot of code to make it work, THAT's the time to think about a complex workaround, like writing a batch file that sets up an environment in which it works, for that program. Otherwise, I don't think it's worth the effort. I'm on a Linux system with multiple Python interpreters. (Almost) all installed Python programs work with the system default interpreter (CPython 2.6). Those that don't have been fitted with shebang lines like "#!/usr/bin/python2.5". This tells the OS to use a different interpreter, like the pystarter script solution proposed in this very thread. From cournape at gmail.com Sun Jul 25 18:05:06 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 26 Jul 2010 07:05:06 +0900 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <67e9147d-9a4a-41f1-a011-eebbc96301ea@q12g2000yqj.googlegroups.com> Message-ID: On Mon, Jul 26, 2010 at 3:07 AM, Zooko O'Whielacronx wrote: > > I would suggest that people try to build their native extension > modules with mingw, and if it doesn't work report a bug (to mingw > project and to the Python project) so that we can track more precisely > what the issues are. To be clear, building extensions with mingw for the official python works well. Numpy and scipy official binaries have been built with mingw for years. There are problems for 64 bits binaries, though David From sonicrules1234 at gmail.com Sun Jul 25 20:08:47 2010 From: sonicrules1234 at gmail.com (Westly Ward) Date: Sun, 25 Jul 2010 17:08:47 -0700 Subject: Python acting weird Message-ID: x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder", "name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py", "compressed":False, "contents":"blahblahfilecontents"}]}]} print x def setindict(dictionary, keys, value) : if len(keys) == 1 : if keys[0].isdigit() and int(keys[0]) == len(dictionary) : dictionary.append(keys[0]) else : dictionary[keys[0]] = value else : dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value) return dictionary a = x.copy() print id(a), id(x) y = setindict(a, ["data", 0, "data", 0, "compressed"], True) if y == x : print True else : print False print x print a How are x and a are ending up the same? I would think .copy() would make it completely seperate. From clp2 at rebertia.com Sun Jul 25 20:29:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 25 Jul 2010 17:29:33 -0700 Subject: Python acting weird In-Reply-To: References: Message-ID: On Sun, Jul 25, 2010 at 5:08 PM, Westly Ward wrote: > x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder", > "name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py", > "compressed":False, "contents":"blahblahfilecontents"}]}]} > print x > def setindict(dictionary, keys, value) : > ? ?if len(keys) == 1 : > ? ? ? ?if keys[0].isdigit() and int(keys[0]) == len(dictionary) ?: > ? ? ? ? ? ?dictionary.append(keys[0]) > ? ? ? ?else : > ? ? ? ? ? ?dictionary[keys[0]] = value > ? ?else : > ? ? ? ?dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value) > ? ?return dictionary > a = x.copy() > > print id(a), id(x) > y = setindict(a, ["data", 0, "data", 0, "compressed"], True) > if y == x : > ? ?print True > > else : > ? ?print False > print x > print a > > How are x and a are ending up the same? ?I would think .copy() would > make it completely seperate. Nope, .copy() only makes a "shallow" copy of the outermost dict, not a recursive "deep" copy; the 2 dictionaries initially point to the *exact* same objects for their keys and values. a = x.copy() assert x is not a # wouldn't be much of a copy otherwise assert x["data"] is a["data"] # no recursive copying though # separate dicts, so rebinding the items of one doesn't affect the other x[42] = 12 assert 42 not in a # mutating the items in one does affect the other however x["data"].append(7) assert a["data"].pop() == 7 # remember that x[y] = z === x.__setitem__(y, z) # so we can write a similar example thusly: x["data"][0] = 8 assert a["data"][0] == 8 # again, rebinding at the outermost level is independent x["data"] = 99 assert a["data"] != x["data"] For a deep copy, use copy.deepcopy() in the std lib: http://docs.python.org/library/copy.html#copy.deepcopy Cheers, Chris -- http://blog.rebertia.com From greg.ewing at canterbury.ac.nz Sun Jul 25 20:30:08 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 26 Jul 2010 12:30:08 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> Message-ID: <8b42njFemaU1@mid.individual.net> Raymond Hettinger wrote: > Every class > in the MRO implementing the target method *must* call super() to give > the next class in the MRO a chance to run. EXCEPT for the last one, which must NOT call super! The posted example happens to work because object has a default __init__ method that does nothing. But this is not generally true of other methods, which means you need a "terminating" class at the end of the MRO whose methods don't call super. -- Greg From eldiener at tropicsoft.invalid Sun Jul 25 20:40:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 20:40:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 5:57 PM, Thomas Jollans wrote: > On 07/25/2010 11:10 PM, Edward Diener wrote: >> On 7/25/2010 3:39 PM, Christian Heimes wrote: >>> Am 25.07.2010 21:32, schrieb Thomas Jollans: >>>> If a script uses sys.executable instead of "python", there is no >>>> problem, at all. >>> >>> It's true that sys.executable is the best way if you have to start a new >>> Python interpreter. However sys.executable may not be set for NT >>> services. So there may be a problem after all. >>> >> >> Once you start instrusively changing scripts to find a solution to >> multiple versions of Python co-existing in one system, you are heading >> down a path of endless problems. > > What exactly is it that you're afraid to change? I do not want to intrusively change any script that has been installed as part of Python. I shouldn't even have to know about the code in these scripts other than what good documentation tells me in how to use them. That's not to say having source is worthless. I am just not going to change source to get a version of Python to work properly when I have 2 or more versions installed in their own separate folders. > > The standard library? There's certainly no need to change that in any way! So if a standard library module ( or distributed library ) executes a call internally to 'python xxx yyy' or executes a call internally to 'someScript.py yyy', you're fine with multiple co-existing versions of Python on your system ? Because under Windows the first call will look for the python.exe first found in the PATH while the second call will find the python.exe associated with the .py extension. And it does not matter in either case what version of the multiple installed versions of Python which are on my system is currently executing that script. And please don't say that there is some sort of guarantee that no library or installation would invoke Python in such a way as opposed to the normal 'import AScript.py' method of using functionality in Python scripts. From steve at REMOVE-THIS-cybersource.com.au Sun Jul 25 20:41:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 00:41:25 GMT Subject: Multiple versions of Python coexisting in the same OS References: Message-ID: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> On Sun, 25 Jul 2010 15:19:53 -0400, Edward Diener wrote: > On 7/25/2010 10:03 AM, Thomas Jollans wrote: >> On 07/25/2010 02:46 PM, Edward Diener wrote: >>> The problem with this is that you forget that a script can invoke >>> Python internally. So whether one uses the console or file association >>> method of invoking Python externally, any already written script can >>> use either internally. >> >> Maybe it's just me, but I think that a script that does this is quite >> simply badly written: it *will* break on systems that have multiple >> Python versions. > > Whether it is badly written or not in your opinion it is legal and > happens all the time. Yes, people write poorly written, buggy scripts all the time. Just because code is legal syntax doesn't mean it does what is intended, or that what is intended is sensible. If you have multiple versions of Python installed, and you call "python somescript.py" without knowing *which* Python will be called, it is neither sensible nor does it do what you intend. End of story. This is no different from calling any other application without knowing what version you will get, then relying on features that are only available in some versions. It is just buggy code. > Are you going to refuse to use any script, no > matter for what library or for what purpose, that internally invokes > Python either through a 'python' command or through a file with a Python > extension ? And how would you find out if a script did this or not ? Are > going to search every script in every distribution and library to > determine if it does this ? And when you find out a script does this, > what will you do ? Treat it like any script with a bug: fix the bug, stop using the script, or determine a work-around that masks the bug. All three are acceptable, the third being the least acceptable because it just leaves a bug waiting to bite you again in the future. > Be real. saying you do not like scripts that internally invoke Python > does not solve anything if you have multiple coexisting versions of > Python installed. No, it solves it completely. Treat it as a bug, and fix it. If you're not willing to treat it as a bug, then uninstall all but one of the Python versions, and the problem goes away. You might have a different problem, namely that some scripts stop working, but now the solution is obvious and straight-forward: fix the scripts that aren't working. Or rename the Python applications, so that scripts can easily call the right version without getting confused. Trying to make some brittle, Do-What-I-Mean solution for trying to auto- magically select between Python versions is pursuing a path of endless problems. Any solution that doesn't fix the actual problem, namely that the scripts are buggy, is at best just a work-around and at worst is no solution at all. -- Steven From ben+python at benfinney.id.au Sun Jul 25 21:04:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 26 Jul 2010 11:04:27 +1000 Subject: Light-weight/very-simple version control under Windows using Python? References: Message-ID: <87tynn3vfo.fsf@benfinney.id.au> "G?nther Dietrich" writes: > python at bdurham.com wrote: > > >I have some very simple use cases[1] for adding some version control > >capabilities to a product I'm working on. [?] > >I'm looking for recommendations on possible solutions: > > > >1. Use an existing version control utility. [?] > Use Mercurial (). It is written in > python, can be extended by python modules/packages and can be used by > python programs directly. Either of Mercurial or Bazaar will be good choices for the requirements specified. All of G?nther's comments (including those I trimmed in this reply) apply equally to both Mercurial and Bazaar. You might like to ask questions in each of the support forums for those tools for more information. -- \ ?To punish me for my contempt of authority, Fate has made me an | `\ authority myself.? ?Albert Einstein, 1930-09-18 | _o__) | Ben Finney From drobinow at gmail.com Sun Jul 25 22:42:52 2010 From: drobinow at gmail.com (David Robinow) Date: Sun, 25 Jul 2010 22:42:52 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener wrote: > On 7/25/2010 5:57 PM, Thomas Jollans wrote: > So if a standard library module ( or distributed library ) executes a call > internally to 'python xxx yyy' or executes a call internally to > 'someScript.py yyy', you're fine with multiple co-existing versions of > Python on your system ? > > Because under Windows the first call will look for the python.exe first > found in the PATH while the second call will find the python.exe associated > with the .py extension. And it does not matter in either case what version > of the multiple installed versions of Python which are on my system is > currently executing that script. > > And please don't say that there is some sort of guarantee that no library or > installation would invoke Python in such a way as opposed to the normal > 'import AScript.py' method of using functionality in Python scripts. Edward, I'm having a really hard time understanding your problem. Could you give an example of some real code that is causing you difficulty? From eldiener at tropicsoft.invalid Sun Jul 25 23:08:16 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Sun, 25 Jul 2010 23:08:16 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> References: <4c4cd9b5$0$11091$c3e8da3@news.astraweb.com> Message-ID: On 7/25/2010 8:41 PM, Steven D'Aprano wrote: > On Sun, 25 Jul 2010 15:19:53 -0400, Edward Diener wrote: > >> On 7/25/2010 10:03 AM, Thomas Jollans wrote: >>> On 07/25/2010 02:46 PM, Edward Diener wrote: >>>> The problem with this is that you forget that a script can invoke >>>> Python internally. So whether one uses the console or file association >>>> method of invoking Python externally, any already written script can >>>> use either internally. >>> >>> Maybe it's just me, but I think that a script that does this is quite >>> simply badly written: it *will* break on systems that have multiple >>> Python versions. >> >> Whether it is badly written or not in your opinion it is legal and >> happens all the time. > > Yes, people write poorly written, buggy scripts all the time. Just > because code is legal syntax doesn't mean it does what is intended, or > that what is intended is sensible. > > If you have multiple versions of Python installed, and you call "python > somescript.py" without knowing *which* Python will be called, it is > neither sensible nor does it do what you intend. End of story. Somebody is supplying you with a Python script and internally invoking Python again. But that somebody does not have to be myself. I am neither buying "End of story" nor that invoking Python internally is an error. But if you believe it to be then you can root out all such Python code, or correct it as you like. Even with co-existing versions of Python installed I have better things to do with my time and therefore will pursue a solution that will work for me in the face of such code. From michele.simionato at gmail.com Sun Jul 25 23:53:17 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 25 Jul 2010 20:53:17 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: Message-ID: <96c84ffc-b264-4226-802f-97bea8b9fd43@t2g2000yqe.googlegroups.com> Everything you ever wanted to know about super is collected here: http://micheles.googlecode.com/hg/artima/python/super.pdf M.S. From benjamin.kaplan at case.edu Sun Jul 25 23:54:30 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 25 Jul 2010 20:54:30 -0700 Subject: why is this group being spammed? In-Reply-To: References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <0de49d86-8f22-4d10-a142-8b65a181424a@n19g2000prf.googlegroups.com> Message-ID: Python-list is comp.lang.python turned into mailing list form. gmane is python-list turned back into a newsgroup. The reason it gets less spam is because it's behind the mailing list's spam filters. Both the mailing list and gmane should see the same amount of spam. which is way less than the original newsgroup/Google Group sees. On Sat, Jul 24, 2010 at 12:28 PM, Jia Hu wrote: > I subscribe for this mailing list at > http://mail.python.org/mailman/listinfo/python-list > > On Sat, Jul 24, 2010 at 3:22 PM, Jia Hu wrote: >> >> Hi, can I subscribe this by gmail? >> >> On Sat, Jul 24, 2010 at 3:16 PM, Mark Lawrence >> wrote: >>> >>> On 24/07/2010 18:01, Dennis Lee Bieber wrote: >>>> >>>> On Sat, 24 Jul 2010 07:32:30 -0700 (PDT), "be.krul" >>>> declaimed the following in gmane.comp.python.general: >>>> >>>>> But maybe owner of this group do no care in that case we *all* get >>>>> spammed! >>>> >>>> ? ? ? ?There is NO OWNER of comp.lang.python; and turning a comp.* group >>>> into moderated takes a fairly long time assuming you can find someone >>>> willing to be the moderators -- what would likely happen is that >>>> comp.lang.python.moderated would be created and then take a few months >>>> to be picked up by the servers, and a few more months for the real users >>>> to leave comp.lang.python to use it. >>>> >>>> ? ? ? ?Oh, and also the hassle of the mailing-list<>usenet gateway (does >>>> it >>>> pass traffic to both groups, drop the existing one, etc.). And readers >>>> on Google may still see spam if Google takes posts stuff before it >>>> passes through the moderation board. >>> >>> For the benefit of those who might have missed it, I'll repeat that I'm >>> reading this from gmane.comp.python.general and see little or no spam. >>> >>> Regards. >>> >>> Mark Lawrence. >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From gunnyt100 at gmail.com Mon Jul 26 00:02:17 2010 From: gunnyt100 at gmail.com (gunny secondclass) Date: Sun, 25 Jul 2010 21:02:17 -0700 (PDT) Subject: Free dell laptops offered by bill gates foundation Message-ID: Free dell laptops offered by bill gates foundation?.no need money? No need registration fee?.no need transport charges?..details available on my blog. if you want to get free laptop, click A DELL IMAGE at the TOP Side of my BLOG. .then open full detais. Get it free 100% and enjoy. First 10,000 people only.hurry up. my blog is http://freelaptopsandfreewebhosting.blogspot.com/ From tazimkolhar at gmail.com Mon Jul 26 00:02:55 2010 From: tazimkolhar at gmail.com (tazimk) Date: Sun, 25 Jul 2010 21:02:55 -0700 (PDT) Subject: obtaining pid of child process Message-ID: Hi, I am using python's multiprocessing module to spawn new process as follows : import multiprocessing import os d = multiprocessing.Process(target=os.system,args=('iostat 2 > a.txt',)) d.start() I want to obtain pid of iostat command or the command executed using multiprocessing module When I execute : d.pid it gives me pid of subshell in which this command is running . Any help will be valuable . Thanks in advance From nobody at nowhere.com Mon Jul 26 00:27:50 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 26 Jul 2010 05:27:50 +0100 Subject: Unicode error References: <44aaebca-d5b2-4efa-a9e8-83a29dc159d3@k19g2000yqc.googlegroups.com> <4c497212$0$28634$c3e8da3@news.astraweb.com> <4c4c4e6f$0$11094$c3e8da3@news.astraweb.com> Message-ID: On Sun, 25 Jul 2010 14:47:11 +0000, Steven D'Aprano wrote: >>> But in the >>> meanwhile, once you get an error, you know what it is. You can >>> intentionally feed code bad data and see what you get. And then maybe >>> add a test to make sure your code traps such errors. >> >> That doesn't really help with exceptions which are triggered by external >> factors rather than explicit inputs. > > Huh? What do you mean by "external factors"? I mean this: > If you mean external factors like "the network goes down" or "the disk is > full", > you can still test for those with appropriate test doubles (think > "stunt doubles", only for testing) such as stubs or mocks. It's a little > bit more work (sometimes a lot more work), but it can be done. I'd say "a lot" is more often the case. >> Also, if you're writing libraries (rather than self-contained programs), >> you have no control over the arguments. > > You can't control what the caller passes to you, but once you have it, > you have total control over it. Total control insofar as you can wrap all method calls in semi-bare excepts (i.e. catch any Exception but not Interrupt). >> Coupled with the fact that duck >> typing is quite widely advocated in Python circles, you're stuck with >> the possibility that any method call on any argument can raise any >> exception. This is even true for calls to standard library functions or >> methods of standard classes if you're passing caller-supplied objects as >> arguments. > > That's a gross exaggeration. It's true that some methods could in theory > raise any exception, but in practice most exceptions are vanishingly > rare. Now *that* is a gross exaggeration. Exceptions are by their nature exceptional, in some sense of the word. But a substantial part of Python development is playing whac-a-mole with exceptions. Write code, run code, get traceback, either fix the cause (LBYL) or handle the exception (EAFP), wash, rinse, repeat. > And it isn't even remotely correct that "any" method could raise > anything. If you can get something other than NameError, ValueError or > TypeError by calling "spam".index(arg), I'd like to see it. How common is it to call methods on a string literal in real-world code? It's far, far more common to call methods on an argument or expression whose value could be any "string-like object" (e.g. UserString or a str subclass). IOW, it's "almost" correct that any method can raise any exception. The fact that the number of counter-examples is non-zero doesn't really change this. Even an isinstance() check won't help, as nothing prohibits a subclass from raising exceptions which the original doesn't. Even using "type(x) == sometype" doesn't help if x's methods involve calling methods of user-supplied values (unless those methods are wrapped in catch-all excepts). Java's checked exception mechanism was based on real-world experience of the pitfalls of abstract types. And that experience was gained in environments where interface specifications were far more detailed than is the norm in the Python world. > Frankly, it sounds to me that you're over-analysing all the things that > "could" go wrong rather than focusing on the things that actually do go > wrong. See Murphy's Law. > That's your prerogative, of course, but I don't think you'll get > much support for it here. Alas, I suspect that you're correct. Which is why I don't advocate using Python for "serious" software. Neither the language nor its "culture" are amenable to robustness. From clp2 at rebertia.com Mon Jul 26 00:29:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 25 Jul 2010 21:29:09 -0700 Subject: obtaining pid of child process In-Reply-To: References: Message-ID: On Sun, Jul 25, 2010 at 9:02 PM, tazimk wrote: > Hi, > > I am using python's multiprocessing module to spawn new process > > as follows : > > import multiprocessing > import os > d = multiprocessing.Process(target=os.system,args=('iostat 2 > > a.txt',)) > d.start() > > I want to obtain pid of iostat command or the command executed using > multiprocessing module `multiprocessing` isn't the best module for this; use `subprocess` instead: from subprocess import Popen, PIPE process = Popen(["iostat"], stderr=open("a.txt", 'w'), stdout=PIPE) print("the PID is", process.pid) `multiprocessing` is used for parallelism in Python code, as an alternative to threads. `subprocess` is used for running external commands, as a preferred alternative to os.system() among other things. Cheers, Chris -- http://blog.rebertia.com From eldiener at tropicsoft.invalid Mon Jul 26 00:36:47 2010 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Mon, 26 Jul 2010 00:36:47 -0400 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 7/25/2010 10:42 PM, David Robinow wrote: > On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener > wrote: >> On 7/25/2010 5:57 PM, Thomas Jollans wrote: >> So if a standard library module ( or distributed library ) executes a call >> internally to 'python xxx yyy' or executes a call internally to >> 'someScript.py yyy', you're fine with multiple co-existing versions of >> Python on your system ? >> >> Because under Windows the first call will look for the python.exe first >> found in the PATH while the second call will find the python.exe associated >> with the .py extension. And it does not matter in either case what version >> of the multiple installed versions of Python which are on my system is >> currently executing that script. >> >> And please don't say that there is some sort of guarantee that no library or >> installation would invoke Python in such a way as opposed to the normal >> 'import AScript.py' method of using functionality in Python scripts. > Edward, I'm having a really hard time understanding your problem. > Could you give an example of some real code that is causing you > difficulty? I start a Python script for version X by going to X's root directory and invoking 'python someScript.py' from the command line. Does that not sound reasonable ? In SomeScript.py there is an internal call to 'python someOtherScript.y someParameters'. But the call invokes another version of Python because it is that version which is in the PATH. Or in SomeScript.py there is an internal call to 'someOtherScript.py someParameters'. But the call invokes another version of Python because the .py extension is associated with a different version. My solution is that I will write some code which sets a particular version of Python as the current version for a particular time, meaning that version will be in the PATH and associated with Python extensions. The way I do not have to worry when I externally invoke Python from the command line that internal calls are going to some other version. From animator333 at gmail.com Mon Jul 26 01:32:57 2010 From: animator333 at gmail.com (King) Date: Sun, 25 Jul 2010 22:32:57 -0700 (PDT) Subject: Undo-Redo, copy instance, custom events and a problem Message-ID: <9e3b430e-c672-4ea9-8fd0-79f852732ec3@g6g2000pro.googlegroups.com> Hi, I am developing an app using wxPython. The Undo-Redo implementation is based on storing pre & post state of an attribute. You store the instance before changing the value and store the instance after changing the values. While undoing or redoing, you copy/replace the current state with stored once. For color attribute as soon as you choose a color, here is the code: # Custom Event evt = ValueChangeEvent(EVT_COLOR_CHANGED.typeId, self.GetId()) # Store Pre State evt.SetPreState(copy.copy(self.attribute)) # Change the newly selected color self.attribute.setValue(R,G,B) # Store Post State evt.SetPostState(copy.copy(self.attribute)) # Throw Custom Event self.GetEventHandler().ProcessEvent(evt) Both states are copied as new instance with correct values. The problem is when this event is getting fired. evt.GetPreState().GetValue() is showing the post color value. Although GetPreState() & GetPostState() are showing two different instances but I have no idea why values are not coming/stored correctly. Some where in between is messed up and post-state values are copied in pre-state. On a side note, self.attribute.setValue takes three floating values for R,G & B colors but stored them as a text. Similarly self.attribute.getValue() converts text into float and returns. Is there anything related to scope or something? Cheers Prashant From steve-REMOVE-THIS at cybersource.com.au Mon Jul 26 01:34:00 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 05:34:00 GMT Subject: Multiple versions of Python coexisting in the same OS References: <4C4C914E.307@jollans.com> Message-ID: <4c4d1e48$0$11102$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 00:36:47 -0400, Edward Diener wrote: > On 7/25/2010 10:42 PM, David Robinow wrote: [...] >> Edward, I'm having a really hard time understanding your problem. Could >> you give an example of some real code that is causing you difficulty? > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? No it doesn't, it's a very unreasonable thing to do. If you have multiple versions of Python, you should name them appropriately so you can launch the appropriate version from any directory: python26 someScript.py # calls python31 secondScript.py internally python31 anotherScript.py # calls python25 thirdScript.py internally etc. Or give the full path to the executable: C:\Programs\python26\python.exe someScript.py # calls C:\Programs\python31\python.exe secondScript.py internally If a script doesn't do this, then the script should be treated as buggy. > In SomeScript.py there is an internal call to 'python someOtherScript.y > someParameters'. That's a pretty dodgy thing to do in the first place, unless you can guarantee that there's only one executable called python. Otherwise, how do you know which one will be called? You can't easily predict which one will be called, so don't do it unless you want your scripts to call arbitrary executables. > But the call invokes another version of Python because > it is that version which is in the PATH. Or in SomeScript.py there is an > internal call to 'someOtherScript.py someParameters'. But the call > invokes another version of Python because the .py extension is > associated with a different version. Exactly. The root of your problem is that there are multiple executables called "python" and you don't know which one you will get. So don't do that. > My solution is that I will write some code which sets a particular > version of Python as the current version for a particular time, meaning > that version will be in the PATH and associated with Python extensions. /facepalm > The way I do not have to worry when I externally invoke Python from the > command line that internal calls are going to some other version. Good luck with that. -- Steven From gelonida at gmail.com Mon Jul 26 03:24:08 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:24:08 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> Message-ID: >> >> Thus my idea of having a pystarter with a config file >> mentioning which directories (tools) should use which python executable > > Well, good luck ! I don;t know how this is resolved for you when some > scripts executes 'python xxx yyy' or 'someScript.py yyy'. both could be resolved with a python starter if one wanted. call the python starter python.exe and put it first in the path. set the python file associations to the python starter. By the way: Something similiar (not identical) has been used for linux hosts in big companies in order to easily switch between different projects. (which potentilly had different versions of development tools) instead of having multiple .cshrc / .bashrc files the first entry of path has been set to /_WRAPPER_/bin (or something similiar) in this directory one found a wrapper script for each tool to be wrapped. ( one script, many symlinks for each tool) the wrapper script took a global setup, the project name and a private setup to finally call the the desired script. What is missing is to choose the executable depending on the script to be called. If one has a wrapper this could be added. Just a question of style, whether the decision which script to be called should come from the - user - a config file ( No script to be intrusively changed, what Edward seems to prefer ) - some coding in the script or the tool's directory ( which MRAB seems to prefer ) From gelonida at gmail.com Mon Jul 26 03:26:27 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:26:27 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: <4C4CA0F2.3010203@mrabarnett.plus.com> References: <4c4c4ab8$0$8087$426a74cc@news.free.fr> <4c4c9d09$0$5331$426a74cc@news.free.fr> <4C4CA0F2.3010203@mrabarnett.plus.com> Message-ID: On 07/25/2010 10:39 PM, MRAB wrote: > News123 wrote: >> Thus my idea of having a pystarter with a config file >> mentioning which directories (tools) should use which python executable >> > I think that's the wrong way round. A pystarter should ask the _tool_ > which version of Python it needs. Hm, it's dfifficult to think about a solution satisfying everyone. Edward seems to insist on a non intrusive solution, where no script is changed (thus my idea of a config file) I personally would probably add information to all of my self written scripts and create a config file for all other tools (or add a marker file n the path of these tools) From peterwfh2000 at gmail.com Mon Jul 26 03:36:03 2010 From: peterwfh2000 at gmail.com (PETER WONG F H (+971 50 8320722)) Date: Mon, 26 Jul 2010 00:36:03 -0700 (PDT) Subject: JBR , RENT TO OWN or BUY WITH NO MONEY DOWN ,050-8320722 Message-ID: <34039719-d1e6-4a08-bda0-734865f79a4b@d8g2000yqf.googlegroups.com> JBR , RENT TO OWN or BUY WITH NO MONEY DOWN ,050-8320722 JBR Lower market price AED800per/sqft 2 unit (3Bed + Maid) (1800sqft to 3000sqft) +Transfer Fee 2 % + Broker Fee 2% For a program which helped hundreds of tenants in DUBAI/UAE become homeowners who had NO MONEY for the down payment and legal fees? We at REAL ESTATE BROKER take great pleasure in extending our warmest welcome in what will prove to be the first step in owning your own home. Even on a starter home the costs of the down payment, surveys, appraisals, land transfer FEES, legal fees and other disbursements can easily amount to AED10,000 or AED12,000. If you find it impossible to save that amount of money while paying rent in addition to all your other day-to-day expenses this program may be the solution you've been looking for. Why RENT when you can OWN. Peter Wong F.H ??? (????RERA BRN: 8866) Mob ?? : +971 50 83 20 722 E-mail ?? : peterwfh2000 at gmail.com Website : http://groups.google.com/group/dubai-property-club From gelonida at gmail.com Mon Jul 26 03:45:45 2010 From: gelonida at gmail.com (Gelonida) Date: Mon, 26 Jul 2010 09:45:45 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: On 07/26/2010 06:36 AM, Edward Diener wrote: > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? Do you have an example of two (not self written) applications requiring to change the python file association in order to be working? I never had problems with this, so would be curious about the tools to avoid. Apart from that my suggestion for you would be: Don't write a tool. Just create one .bat file for each sript to be started. The bat file should set the python search path. This should cover 90% of existing python scripts. (If you want, you could write a tool to create the bat files) Now the second problem. if a python script starts another python file without calling python.exe but via the file associations, then above solution would not be sufficient/ you had to additionally change the file associations, (which can easily be done from a bat file as well if you insist. The commands you need are 'assoc' and 'ftype') But does this really happen to you? Please note: Trying to develop a solution, which believes that you will never have two concurrent applications requiring two differnt python versions sounds a little dangerous. From hv at tbz-pariv.de Mon Jul 26 04:56:48 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Mon, 26 Jul 2010 10:56:48 +0200 Subject: non-blocking IO EAGAIN on write In-Reply-To: <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> References: <8at354F51tU1@mid.individual.net> <4c4b2fc5$0$1586$742ec2ed@news.sonic.net> Message-ID: <8b50u2F8ijU1@mid.individual.net> John Nagle wrote: > On 7/23/2010 1:45 AM, Thomas Guettler wrote: >> Hi, >> >> I use non-blocking io to check for timeouts. Sometimes I get EAGAIN >> (Resource temporarily unavailable) >> on write(). My working code looks like this. But I am unsure how many >> bytes have been written to the >> pipe if I get an EAGAIN IOError. .... > Since your code isn't doing anything else while waiting for a > write to complete on the pipe, why use non-blocking I/O at all? > > (I know, the Python I/O timeout logic is broken in some versions. > You're probably working around that.) I want to handle timeouts. The app runs on linux, but I don't want to use signals, since it is in a wsgi context: http://code.google.com/p/modwsgi/wiki/ApplicationIssues > .. As a general rule therefore, no WSGI application component should > attempt to register its own signal handlers. > The hint of Kushal was right: The timeout was reached, and I didn't check the result of the select call. -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 06:20:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 12:20:59 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> Message-ID: <4c4d618b$0$9222$426a74cc@news.free.fr> dmitrey a ?crit : (snip) > This doesn't stack with the following issue: sometimes user can write > in code "myObject.size = (some integer value)" and then it will be > involved in future calculations as ordinary fixed value; if user > doesn't supply it, but myObject.size is involved in calculations, then > the oofun is created to behave like similar numpy.array attribute. IOW, you want a default value for the size if it has not been specified by the user, so you can safely use this attribute in computations. The more straightforward solution is to define this attribute (with the default value) in the initialiser, ie: class MyClass(object): def __init__(self, x, y): self.x = x self.y = y self.size = Whatever() If you don't want to create as many Whatever instances as MyClass instances, you can create a single Whatever instance before defining your class: DEFAULT_WHATEVER = Whathever() class MyClass(object): def __init__(self, x, y): self.x = x self.y = y self.size = DEFAULT_WHATEVER HTH From san82moon at gmail.com Mon Jul 26 06:25:19 2010 From: san82moon at gmail.com (lee) Date: Mon, 26 Jul 2010 03:25:19 -0700 (PDT) Subject: ValueError: invalid literal for int(): Message-ID: Hi, I have a value, partintid = int(Screw plugg (91_10 -> untitled)) but i get ValueError: invalid literal for int(): Screw plugg (91_10 - > untitled) any help? - Sunny From ldo at geek-central.gen.new_zealand Mon Jul 26 06:30:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 26 Jul 2010 22:30:34 +1200 Subject: Multiprocessing zombie processes References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: In message , Chris Rebert wrote: > "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. > Frankenstein." > > Most people try to /avoid/ making zombies. Is there some connection between Frankenstein and zombies? From clp2 at rebertia.com Mon Jul 26 06:40:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 03:40:39 -0700 Subject: Multiprocessing zombie processes In-Reply-To: References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: On Mon, Jul 26, 2010 at 3:30 AM, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> "Paging Dr. Frankenstein. Dr. Frankenstein to the lab. Paging Dr. >> Frankenstein." >> >> Most people try to /avoid/ making zombies. > > Is there some connection between Frankenstein and zombies? His monster is zombie-ish; it's made of reanimated corpse parts. It's also mentioned in Wikipedia's "Zombie" article as influencing future works about the undead. Cheers, Chris -- Not a perfect comedic reference, I admit. From duncan.booth at invalid.invalid Mon Jul 26 06:55:28 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Jul 2010 10:55:28 GMT Subject: hasattr + __getattr__: I think this is Python bug References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > If you don't want to create as many Whatever instances as MyClass > instances, you can create a single Whatever instance before defining > your class: > > DEFAULT_WHATEVER = Whathever() > > class MyClass(object): > def __init__(self, x, y): > self.x = x > self.y = y > self.size = DEFAULT_WHATEVER > > Or you could create the default as a class attribute and it can be overridden in those instances which need a different value. class MyClass(object): size = Whatever() def __init__(self, x, y): self.x = x self.y = y -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Mon Jul 26 06:55:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 03:55:46 -0700 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: > Hi, > > I have a value, > > partintid = int(Screw plugg ?(91_10 -> untitled)) > > but i get ValueError: invalid literal for int(): Screw plugg ?(91_10 - >> untitled) > any help? That is most certainly not your actual exact code, since it has a few SyntaxErrors and thus Python would have bailed-out long before it ever got the chance to raise ValueError. Please copy-and-paste the *actual exact code* and exact error message. Also, next time say what the desired output/behavior you're seeking is. That being said, if your code is (as I suspect) in actuality: partintid = int("Screw plugg ?(91_10 -> untitled)") then I would agree with int() and say that that string is nowhere close to representing an integer (how precisely is "Screw" to be interpreted as an integer, pray tell?); so what's so surprising about getting an error when trying to convert it to one? I suspect you're trying to extract 91 or 10 from the string. Use string methods[1] to parse the desired numerical section out of the string, and then pass the resulting numerical string to int(), which will accept it without error and properly convert it. If you want more detailed help, please provide a specification of typical input strings and desired output integers. [1]: http://docs.python.org/library/stdtypes.html#string-methods Regards, Chris -- http://blog.rebertia.com From san82moon at gmail.com Mon Jul 26 07:03:19 2010 From: san82moon at gmail.com (Sunny chilgod) Date: Mon, 26 Jul 2010 16:33:19 +0530 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: Hi Chris, Thanks for your help. but i need to to convert the whole string to int. heres my full code, ptid = 'item_01bom' so item_01bom is a field name in form, so i get its value, partintid = int(form[ptid]). # the value of form[ptid] is 'Screw plugg (91_10 - untitled)' Hence i get the error. hope i am clear now. - Sunny On Mon, Jul 26, 2010 at 4:25 PM, Chris Rebert wrote: > On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: > > Hi, > > > > I have a value, > > > > partintid = int(Screw plugg (91_10 -> untitled)) > > > > but i get ValueError: invalid literal for int(): Screw plugg (91_10 - > >> untitled) > > any help? > > That is most certainly not your actual exact code, since it has a few > SyntaxErrors and thus Python would have bailed-out long before it ever > got the chance to raise ValueError. Please copy-and-paste the *actual > exact code* and exact error message. > Also, next time say what the desired output/behavior you're seeking is. > > That being said, if your code is (as I suspect) in actuality: > > partintid = int("Screw plugg (91_10 -> untitled)") > > then I would agree with int() and say that that string is nowhere > close to representing an integer (how precisely is "Screw" to be > interpreted as an integer, pray tell?); so what's so surprising about > getting an error when trying to convert it to one? > > I suspect you're trying to extract 91 or 10 from the string. Use > string methods[1] to parse the desired numerical section out of the > string, and then pass the resulting numerical string to int(), which > will accept it without error and properly convert it. > > If you want more detailed help, please provide a specification of > typical input strings and desired output integers. > > [1]: http://docs.python.org/library/stdtypes.html#string-methods > > Regards, > Chris > -- > http://blog.rebertia.com > -- All that we are is the result of what we have thought. The mind is everything. What we think we become. Regards, Sunny -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jul 26 07:12:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 04:12:33 -0700 Subject: ValueError: invalid literal for int(): In-Reply-To: References: Message-ID: > On Mon, Jul 26, 2010 at 4:25 PM, Chris Rebert wrote: >> On Mon, Jul 26, 2010 at 3:25 AM, lee wrote: >> > Hi, >> > >> > I have a value, >> > >> > partintid = int(Screw plugg ?(91_10 -> untitled)) >> > >> > but i get ValueError: invalid literal for int(): Screw plugg ?(91_10 - >> >> untitled) >> > any help? >> I suspect you're trying to extract 91 or 10 from the string. Use >> string methods[1] to parse the desired numerical section out of the >> string, and then pass the resulting numerical string to int(), which >> will accept it without error and properly convert it. >> >> If you want more detailed help, please provide a specification of >> typical input strings and desired output integers. >> >> [1]: http://docs.python.org/library/stdtypes.html#string-methods On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod wrote: > Hi Chris, > Thanks for your help. but i need to to convert the whole string to int. > heres my full code, > ptid = 'item_01bom' > so item_01bom is a field name in form, so i get its value, > partintid = int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg > ?(91_10 -?untitled)' > Hence i get the error. hope i am clear now. Nope, still vague. Which is your desired value for partintid: 91? 10? 9110? "91_10"? Something else? Also, not to be unfriendly, but just note for future reference that top-posting ( http://en.wikipedia.org/wiki/Top-posting ) is generally avoided on this mailinglist/newsgroup. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 07:30:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 11:30:31 GMT Subject: ValueError: invalid literal for int(): References: Message-ID: <4c4d71d7$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 04:12:33 -0700, Chris Rebert wrote: > On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod > wrote: >> Hi Chris, >> Thanks for your help. but i need to to convert the whole string to int. >> heres my full code, >> ptid = 'item_01bom' >> so item_01bom is a field name in form, so i get its value, partintid = >> int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg >> ?(91_10 -?untitled)' >> Hence i get the error. hope i am clear now. > > Nope, still vague. Which is your desired value for partintid: 91? 10? > 9110? "91_10"? Something else? Well, if you interpret 'Screw plugg (91_10 -?untitled)' as a base-256 number, the correct answer is: 147,334,663,384,405,567,160,096,068,524,905,866,724,622,858,761,848,595,862,392,584,788,047,651,881 Obviously. -- Steven From san82moon at gmail.com Mon Jul 26 07:50:09 2010 From: san82moon at gmail.com (lee) Date: Mon, 26 Jul 2010 04:50:09 -0700 (PDT) Subject: ValueError: invalid literal for int(): References: <4c4d71d7$0$11091$c3e8da3@news.astraweb.com> Message-ID: <9ac06e96-fc15-4d95-bb7f-301fd18579b0@o7g2000prg.googlegroups.com> On Jul 26, 4:30?pm, Steven D'Aprano wrote: > On Mon, 26 Jul 2010 04:12:33 -0700, Chris Rebert wrote: > > On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod > > wrote: > >> Hi Chris, > >> Thanks for your help. but i need to to convert the whole string to int. > >> heres my full code, > >> ptid = 'item_01bom' > >> so item_01bom is a field name in form, so i get its value, partintid = > >> int(form[ptid]). ?# the value of?form[ptid] is 'Screw plugg > >> ?(91_10 -?untitled)' > >> Hence i get the error. hope i am clear now. > > > Nope, still vague. Which is your desired value for partintid: 91? 10? > > 9110? "91_10"? Something else? > > Well, if you interpret 'Screw plugg (91_10 -?untitled)' as a base-256 > number, the correct answer is: > > 147,334,663,384,405,567,160,096,068,524,905,866,724,622,858,761,848,595,862,392,584,788,047,651,881 > > Obviously. > > -- > Steven Hi, i got the value wrong. sorry for the mistake. i get a int value like "01", so no issue converting it to integer. thanks. From michele.simionato at gmail.com Mon Jul 26 08:03:29 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 26 Jul 2010 05:03:29 -0700 (PDT) Subject: Multiprocessing zombie processes References: <0FCB72F5-30EB-41E3-97E4-AAAE2E39A22B@gmail.com> Message-ID: <722b4c73-e23f-4671-a74e-673c155eafe6@l14g2000yql.googlegroups.com> On Jul 25, 1:11?am, Navkirat Singh wrote: > OK I wanted zombie processes and have been able to regenerate them with multiprocessing. Now lets see how I can handle them. The multiprocessing docs say: """ Joining zombie processes On Unix when a process finishes but has not been joined it becomes a zombie. There should never be very many because each time a new process starts (or active_children() is called) all completed processes which have not yet been joined will be joined. Also calling a finished process?s Process.is_alive() will join the process. Even so it is probably good practice to explicitly join all the processes that you start. """ From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 09:07:49 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 15:07:49 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> Message-ID: <4c4d88a4$0$9187$426a74cc@news.free.fr> Duncan Booth a ?crit : > Bruno Desthuilliers wrote: > >> If you don't want to create as many Whatever instances as MyClass >> instances, you can create a single Whatever instance before defining >> your class: >> >> DEFAULT_WHATEVER = Whathever() >> >> class MyClass(object): >> def __init__(self, x, y): >> self.x = x >> self.y = y >> self.size = DEFAULT_WHATEVER >> >> > > Or you could create the default as a class attribute from the OP: """ I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. """ so this solution won't obviously work in this case !-) Also and FWIW, I wouldn't advocate this solution if the "default" class attribute is of a mutable type. From bruno.42.desthuilliers at websiteburo.invalid Mon Jul 26 09:14:49 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 26 Jul 2010 15:14:49 +0200 Subject: why is this group being spammed? In-Reply-To: <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> <874ofx9xbx.fsf@benfinney.id.au> <63c4457d-3dd0-4cbb-9a79-5fe22f54283d@p11g2000prf.googlegroups.com> Message-ID: <4c4d8a48$0$2793$426a74cc@news.free.fr> be.krul a ?crit : > > Why not moderate this group? This is a hi-traffic group, so it would require a huge team of moderators. From bayofbengal2011 at gmail.com Mon Jul 26 09:39:30 2010 From: bayofbengal2011 at gmail.com (paypal) Date: Mon, 26 Jul 2010 06:39:30 -0700 (PDT) Subject: I GOT $2,000 FROM ' PAYPAL' Message-ID: <03cc2893-eae9-4d8e-89ad-0f90aac123d5@u38g2000prh.googlegroups.com> I GOT $2,000 FROM ' PAYPAL' At http://veryhotguru.co.cc i have hidden the PayPal Form link in an image. in that website On Top Side Above search box , click on image and enter your PayPal id And Your name. From burton at userful.com Mon Jul 26 11:47:08 2010 From: burton at userful.com (Burton Samograd) Date: Mon, 26 Jul 2010 09:47:08 -0600 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: Grant Edwards writes: > On 2010-07-24, Lawrence D'Oliveiro wrote: >> In message , Robert Kern >> wrote: >> >>> There are also utilities for mounting ISOs directly without burning >>> them to a physical disk. >> >> You need special utilities to do this?? > > Not if the OS and VFS are competently designed. In Linux all you need > to do is this: > > mount -o loop /path/to/file.iso /mount/point > > Apparently you've got to jump through all sorts of hoops using 3rd > party software to do something analgous in MS Windows. In Windows you use DaemonTools. -- Burton Samograd From robin at reportlab.com Mon Jul 26 11:57:58 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 26 Jul 2010 16:57:58 +0100 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C4DB086.2060008@chamonix.reportlab.co.uk> On 26/07/2010 16:47, Burton Samograd wrote: > Grant Edwards writes: > >> On 2010-07-24, Lawrence D'Oliveiro wrote: >>> In message, Robert Kern >>> wrote: >>> >>>> There are also utilities for mounting ISOs directly without burning >>>> them to a physical disk. >>> >>> You need special utilities to do this?? >> >> Not if the OS and VFS are competently designed. In Linux all you need >> to do is this: >> >> mount -o loop /path/to/file.iso /mount/point >> >> Apparently you've got to jump through all sorts of hoops using 3rd >> party software to do something analgous in MS Windows. > > In Windows you use DaemonTools. > > -- > Burton Samograd > I use VCdControlTool.exe which is some kind of M$ utility, but perhaps that doesn't work for everyone. -- Robin Becker From ethan at stoneleaf.us Mon Jul 26 12:20:06 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 26 Jul 2010 09:20:06 -0700 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <8b42njFemaU1@mid.individual.net> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: <4C4DB5B6.3050209@stoneleaf.us> Gregory Ewing wrote: > Raymond Hettinger wrote: >> Every class >> in the MRO implementing the target method *must* call super() to give >> the next class in the MRO a chance to run. > > EXCEPT for the last one, which must NOT call super! > > The posted example happens to work because object has > a default __init__ method that does nothing. But this > is not generally true of other methods, which means you > need a "terminating" class at the end of the MRO whose > methods don't call super. Speaking of new-style classes only, don't they all end in object? And if the MRO is only known at run-time, how is one to know at code-time whether your (new-style) class is at the end of the line? ~Ethan~ From ethan at stoneleaf.us Mon Jul 26 12:47:19 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 26 Jul 2010 09:47:19 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4d88a4$0$9187$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> Message-ID: <4C4DBC17.4050805@stoneleaf.us> Bruno Desthuilliers wrote: > Duncan Booth a ?crit : >> Bruno Desthuilliers wrote: >> >>> If you don't want to create as many Whatever instances as MyClass >>> instances, you can create a single Whatever instance before defining >>> your class: >>> >>> DEFAULT_WHATEVER = Whathever() >>> >>> class MyClass(object): >>> def __init__(self, x, y): >>> self.x = x >>> self.y = y >>> self.size = DEFAULT_WHATEVER >>> >>> >> >> Or you could create the default as a class attribute > > from the OP: > """ > I have a class (FuncDesigner oofun) that has no attribute "size", but > it is overloaded in __getattr__, so if someone invokes > "myObject.size", it is generated (as another oofun) and connected to > myObject as attribute. > """ > > so this solution won't obviously work in this case !-) > > Also and FWIW, I wouldn't advocate this solution if the "default" class > attribute is of a mutable type. Well, it is Monday, so I may be missing something obvious, but what is the effective difference between these two solutions? ~Ethan~ From albert.tresens at gmail.com Mon Jul 26 12:54:23 2010 From: albert.tresens at gmail.com (alberttresens) Date: Mon, 26 Jul 2010 09:54:23 -0700 (PDT) Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? Message-ID: <29268605.post@talk.nabble.com> Hi, I am trying to get the creation time of a file to be able to correlate it's content timestamps with other log files. In order to get the creation time of the file one a Linux machine i used: return os.lstat(logFile)[ST_CTIME] That returns to me something like: 1279620166 I would like to know the meaning of this number. Is it in seconds since the epoch? Or is some other respresentation? Thanks, Albert -- View this message in context: http://old.nabble.com/What-does-the-output-of-return-os.lstat%28logFile%29-ST_CTIME--mean--tp29268605p29268605.html Sent from the Python - python-list mailing list archive at Nabble.com. From nagle at animats.com Mon Jul 26 13:08:43 2010 From: nagle at animats.com (John Nagle) Date: Mon, 26 Jul 2010 10:08:43 -0700 Subject: Compare two nested dictionaries In-Reply-To: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> References: <4db33541-3d3f-401e-aded-d6159ac75aca@u31g2000pru.googlegroups.com> Message-ID: <4c4dc11a$0$1619$742ec2ed@news.sonic.net> On 7/25/2010 8:03 AM, targetsmart wrote: > Hi, > I am trying to compare two nested dictionaries, I want to know what is > the exact difference between them. d1 = {'a' : 1, 'b' : 2, 'c': 3 } d2 = {'a' : 1, 'b' : 3, 'd': 4 } diff = dict(set(d1.items()) - set(d2.items())) print (diff) {'c': 3, 'b': 2} That's the true "difference", with all entries in d1 not identically in d2 listed. Is that what you wanted? John Nagle From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 13:15:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 17:15:13 GMT Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? References: Message-ID: <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote: > Hi, > I am trying to get the creation time of a file to be able to correlate > it's content timestamps with other log files. In order to get the > creation time of the file one a Linux machine i used: You're out of luck. Neither Unix nor Linux store the creation time of files, at least not on any file system I know of. It stores three timestamps: mtime, ctime, and atime. atime is the simple one -- it is "access time", or when the file was last read. mtime is "modification time" -- it is when the file *contents* were last changed. But ctime is NOT creation time, as many people imagine. It is "change time", and it changes whenever EITHER the file contents are changed, OR when the file metadata (permissions, owner, name, etc.) change. So any time mtime changes, so does ctime. But not visa versa. > return os.lstat(logFile)[ST_CTIME] > > That returns to me something like: 1279620166 > > I would like to know the meaning of this number. Is it in seconds since > the epoch? Yes. -- Steven From albert.tresens at gmail.com Mon Jul 26 13:24:25 2010 From: albert.tresens at gmail.com (alberttresens) Date: Mon, 26 Jul 2010 10:24:25 -0700 (PDT) Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? In-Reply-To: <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> References: <29268605.post@talk.nabble.com> <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> Message-ID: <29268871.post@talk.nabble.com> Hi, thanks for the reply. But what i am more concerned about, as I am trying to correlate logs, is what is the timestamp: 1279620166 mean? Is it seconds since the epoch or the ISO time in seconds? Any idea? Thanks a lot!! Steven D'Aprano-7 wrote: > > On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote: > >> Hi, >> I am trying to get the creation time of a file to be able to correlate >> it's content timestamps with other log files. In order to get the >> creation time of the file one a Linux machine i used: > > You're out of luck. Neither Unix nor Linux store the creation time of > files, at least not on any file system I know of. It stores three > timestamps: mtime, ctime, and atime. > > atime is the simple one -- it is "access time", or when the file was last > read. > > mtime is "modification time" -- it is when the file *contents* were last > changed. > > But ctime is NOT creation time, as many people imagine. It is "change > time", and it changes whenever EITHER the file contents are changed, OR > when the file metadata (permissions, owner, name, etc.) change. > > So any time mtime changes, so does ctime. But not visa versa. > > >> return os.lstat(logFile)[ST_CTIME] >> >> That returns to me something like: 1279620166 >> >> I would like to know the meaning of this number. Is it in seconds since >> the epoch? > > Yes. > > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://old.nabble.com/What-does-the-output-of-return-os.lstat%28logFile%29-ST_CTIME--mean--tp29268605p29268871.html Sent from the Python - python-list mailing list archive at Nabble.com. From thomas at jollans.com Mon Jul 26 13:37:31 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 26 Jul 2010 19:37:31 +0200 Subject: Multiple versions of Python coexisting in the same OS In-Reply-To: References: <4C4C914E.307@jollans.com> Message-ID: <4C4DC7DB.2070102@jollans.com> On 07/26/2010 06:36 AM, Edward Diener wrote: > On 7/25/2010 10:42 PM, David Robinow wrote: >> On Sun, Jul 25, 2010 at 8:40 PM, Edward Diener >> wrote: >>> On 7/25/2010 5:57 PM, Thomas Jollans wrote: >>> So if a standard library module ( or distributed library ) executes a >>> call >>> internally to 'python xxx yyy' or executes a call internally to >>> 'someScript.py yyy', you're fine with multiple co-existing versions of >>> Python on your system ? >>> >>> Because under Windows the first call will look for the python.exe first >>> found in the PATH while the second call will find the python.exe >>> associated >>> with the .py extension. And it does not matter in either case what >>> version >>> of the multiple installed versions of Python which are on my system is >>> currently executing that script. >>> >>> And please don't say that there is some sort of guarantee that no >>> library or >>> installation would invoke Python in such a way as opposed to the normal >>> 'import AScript.py' method of using functionality in Python scripts. >> Edward, I'm having a really hard time understanding your problem. >> Could you give an example of some real code that is causing you >> difficulty? > > I start a Python script for version X by going to X's root directory and > invoking 'python someScript.py' from the command line. Does that not > sound reasonable ? yeah, well, sort of. But for a system installation, not really. When hacking on the interpreter, this makes sense. Otherwise - not so much. > > In SomeScript.py there is an internal call to 'python someOtherScript.y > someParameters'. Is that a fact? Where on earth did you get this "SomeScript.py"? From thomas at jollans.com Mon Jul 26 14:13:40 2010 From: thomas at jollans.com (Thomas Jollans) Date: Mon, 26 Jul 2010 20:13:40 +0200 Subject: What does the output of return os.lstat(logFile)[ST_CTIME] mean? In-Reply-To: <29268871.post@talk.nabble.com> References: <29268605.post@talk.nabble.com> <4c4dc2a0$0$11091$c3e8da3@news.astraweb.com> <29268871.post@talk.nabble.com> Message-ID: <4C4DD054.50308@jollans.com> On 07/26/2010 07:24 PM, alberttresens wrote: > > Hi, thanks for the reply. Alas, you didn't actually read it: > > But what i am more concerned about, as I am trying to correlate logs, is > what is the timestamp: > 1279620166 mean? > Is it seconds since the epoch or the ISO time in seconds? > > Any idea? > > Thanks a lot!! > [...] >>> I would like to know the meaning of this number. Is it in seconds since >>> the epoch? >> >> Yes. You quoted the answer to your question in the same e-mail. fascinating. A little side note: >> atime is the simple one -- it is "access time", or when the file was >> last read. You should never rely on this, though: some file systems don't store this (I think) and many users/sysadmins actually disable this (mount -o noatime) for performance reasons. (Also, on an SSD, I imagine enabling atime, and with it many, many additional writes, could noticeably detriment disk lifetime) From theran at gmail.com Mon Jul 26 14:36:16 2010 From: theran at gmail.com (Louis Theran) Date: Mon, 26 Jul 2010 11:36:16 -0700 (PDT) Subject: distutils question - building universal modules on OS X? Message-ID: Is there a standard recipe for getting distutils to built universal .so files for modules that have C/C++ source? From robert.kern at gmail.com Mon Jul 26 14:49:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 13:49:55 -0500 Subject: distutils question - building universal modules on OS X? In-Reply-To: References: Message-ID: On 7/26/10 1:36 PM, Louis Theran wrote: > Is there a standard recipe for getting distutils to built > universal .so files for modules that have C/C++ source? If your Python was built to be Universal, it will automatically use the same architecture flags to build the extension modules Universal. -- 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 philip at semanchuk.com Mon Jul 26 15:22:14 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 26 Jul 2010 15:22:14 -0400 Subject: Binary compatibility across Python versions? Message-ID: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Hi all, Does Python guarantee binary compatibility across major, minor and/or micro versions? I looked through the docs and even with Google's help I wasn't able to find any official statements on this subject. Specifically, I'm concerned with binaries created by SWIG for a C++ library that our project uses. We'd like to ship precompiled binaries for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it is sufficient to create binaries for each Python for each platform (3 * 2 == 6 total precompiled binaries). Thanks for any advice and pointers to official documentation on the subject. Cheers Philip From python at mrabarnett.plus.com Mon Jul 26 15:40:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 26 Jul 2010 20:40:30 +0100 Subject: Binary compatibility across Python versions? In-Reply-To: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: <4C4DE4AE.6060103@mrabarnett.plus.com> Philip Semanchuk wrote: > Hi all, > Does Python guarantee binary compatibility across major, minor and/or > micro versions? I looked through the docs and even with Google's help I > wasn't able to find any official statements on this subject. > > > Specifically, I'm concerned with binaries created by SWIG for a C++ > library that our project uses. We'd like to ship precompiled binaries > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > is sufficient to create binaries for each Python for each platform (3 * > 2 == 6 total precompiled binaries). > > Thanks for any advice and pointers to official documentation on the > subject. > There are differences between minor versions, but not, so far as I'm aware, between micro versions (and I'd be surprised if there were). From lists at cheimes.de Mon Jul 26 15:45:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 26 Jul 2010 21:45:05 +0200 Subject: Binary compatibility across Python versions? In-Reply-To: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: > Specifically, I'm concerned with binaries created by SWIG for a C++ > library that our project uses. We'd like to ship precompiled binaries > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > is sufficient to create binaries for each Python for each platform (3 > * 2 == 6 total precompiled binaries). For each platforms you have to provide binaries for the major CPU architectures (X86 and X64_86), too. Users or distributions may compile Python with UCS-2 or UCS-4 unicode width. That makes eight different binaries for Linux (two version * two archs * UCS2/4). Although most distributions follow the LSB standards, binaries aren't necessary ABI compatible. C++ binaries tend to break more often than C binaries. Have fun ;) Christian From robert.kern at gmail.com Mon Jul 26 15:46:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 14:46:22 -0500 Subject: Binary compatibility across Python versions? In-Reply-To: <4C4DE4AE.6060103@mrabarnett.plus.com> References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> <4C4DE4AE.6060103@mrabarnett.plus.com> Message-ID: On 7/26/10 2:40 PM, MRAB wrote: > Philip Semanchuk wrote: >> Hi all, >> Does Python guarantee binary compatibility across major, minor and/or micro >> versions? I looked through the docs and even with Google's help I wasn't able >> to find any official statements on this subject. >> >> >> Specifically, I'm concerned with binaries created by SWIG for a C++ library >> that our project uses. We'd like to ship precompiled binaries for Linux, OS X >> and Windows for Python 2.5 and 2.6. I'm hoping that it is sufficient to create >> binaries for each Python for each platform (3 * 2 == 6 total precompiled >> binaries). >> >> Thanks for any advice and pointers to official documentation on the subject. >> > There are differences between minor versions, but not, so far as I'm > aware, between micro versions (and I'd be surprised if there were). As a matter of policy, micro versions are binary-compatible. It's a bug if a micro revision breaks binary compatibility. -- 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 dhruvbird at gmail.com Mon Jul 26 16:24:28 2010 From: dhruvbird at gmail.com (dhruvbird) Date: Mon, 26 Jul 2010 13:24:28 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: On Jul 21, 8:17?pm, John Nagle wrote: > On 7/19/2010 9:56 AM, dhruvbird wrote: > > > On Jul 19, 9:12 pm, Brian Victor ?wrote: > >> dhruvbird wrote: > >> Having offered this, I don't recall ever seeing reduce used in real > >> python code, and explicit iteration is almost always preferred. > > > Yes, even I have noticed that reduce is a tad under-used function. > > ? ? ?Yes, I had a use case for it once, but it wasn't worth the trouble. > "map" is often useful, but "reduce", not so much. > > ? ? ?Python isn't really a functional language. ?There's no bias toward > functional solutions, lambdas aren't very general, and the performance > isn't any better. ?Nor is any concurrency provided by "map" or "reduce". > So there's no win in trying to develop cute one-liners. Yes agreed. However, there is: 1. now scope for optimization (for example returning generators instead of lists) at every stage if using functions -- these functions can be internally changed as long as the external guarantees they provide remain essentially unchanged. 2. readability wins because you express your intent (operations) rather than anything else. For example, if I want the product of the square roots of all odd integers in an array, I can say: answer = reduce(product, map(math.sqrt, filter(lambda x: x%2 == 0, some_array_with_ints))) While I agree that python may not have been initially seen as a functional language, it is powerful and flexible enough to be one or at least decently support such paradigms. Regards, -Dhruv. From nad at acm.org Mon Jul 26 17:19:02 2010 From: nad at acm.org (Ned Deily) Date: Mon, 26 Jul 2010 14:19:02 -0700 Subject: Binary compatibility across Python versions? References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: In article , Christian Heimes wrote: > [Philip Semanchuk wrote:] > > Specifically, I'm concerned with binaries created by SWIG for a C++ > > library that our project uses. We'd like to ship precompiled binaries > > for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping that it > > is sufficient to create binaries for each Python for each platform (3 > > * 2 == 6 total precompiled binaries). > For each platforms you have to provide binaries for the major CPU > architectures (X86 and X64_86), too. Users or distributions may compile > Python with UCS-2 or UCS-4 unicode width. That makes eight different > binaries for Linux (two version * two archs * UCS2/4). Although most > distributions follow the LSB standards, binaries aren't necessary ABI > compatible. C++ binaries tend to break more often than C binaries. And, on OS X, there are various Python binary distributions in common use: the Apple-supplied Pythons (2.5 for OS X 10.5, 2.6 & 2.5 for 10.6), the python.org OS X installers for 10.5 and 10.6, plus the ActiveState and EPD ones. It would likely be difficult to ship one binary extension that would easily work, if at all, with the most common ones. For instance, the Apple-supplied Python 2.6 is built with gcc 4.2, uses the 10.6 ABI (SDK deployment target), and x86_64 / i386 / ppc architectures (default 64-bit on capable machines). The python.org 2.6 uses gcc 4.0, the 10.4u ABI, and is 32-bit only (i386 / ppc) -- Ned Deily, nad at acm.org From pengyu.ut at gmail.com Mon Jul 26 17:52:06 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 16:52:06 -0500 Subject: python terminology on classes Message-ID: Hi I'm still kind of confused about the terminology on classes in python. Could you please let me know what the equivalent terms for the following C++ terms? constructor destructor member function member variable virtual member function function I think that C++ "function" is equivalent to python "function" and C++ "member function" is equivalent to python "method". But I couldn't locate where the original definitions of the corresponding python terms in the manual as these term appear many times. Could you please point me where to look for the definition of these python corresponding terms? -- Regards, Peng From 4g4trz802 at sneakemail.com Mon Jul 26 18:16:49 2010 From: 4g4trz802 at sneakemail.com (Michael Hoffman) Date: Mon, 26 Jul 2010 15:16:49 -0700 Subject: Updating path.py Message-ID: I have been using Jason Orendorff's path.py module for a long time. It is very useful. The only problem is that Python 2.6 deprecates the md5 module it imports, so I (and others using my software) now get this warning whenever they start, which is a little annoying. /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead The original web page is gone, and e-mails to the author have gone unanswered. It has a "public domain" license so I could easily fork it and make this small change. The question is what is the best way to do that and ensure continuity with the previous versions. Can I (or someone else) take over the PyPI entry in question? Other suggestions? Many thanks, Michael Hoffman From pengyu.ut at gmail.com Mon Jul 26 18:20:09 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 17:20:09 -0500 Subject: python styles: why Use spaces around arithmetic operators? Message-ID: This webpage http://www.python.org/dev/peps/pep-0008/ recommends the following. It looks to me that both styles are fine. Could anybody let me know what the rationale is behind this recommendation? - Use spaces around arithmetic operators: Yes: i = i + 1 submitted += 1 x = x * 2 - 1 hypot2 = x * x + y * y c = (a + b) * (a - b) No: i=i+1 submitted +=1 x = x*2 - 1 hypot2 = x*x + y*y c = (a+b) * (a-b) -- Regards, Peng From robert.kern at gmail.com Mon Jul 26 18:39:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Jul 2010 17:39:56 -0500 Subject: Updating path.py In-Reply-To: References: Message-ID: On 7/26/10 5:16 PM, Michael Hoffman wrote: > I have been using Jason Orendorff's path.py module for a long time. It is very > useful. The only problem is that Python 2.6 deprecates the md5 module it > imports, so I (and others using my software) now get this warning whenever they > start, which is a little annoying. > > /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > > The original web page is gone, and e-mails to the author have gone unanswered. > It has a "public domain" license so I could easily fork it and make this small > change. The question is what is the best way to do that and ensure continuity > with the previous versions. Can I (or someone else) take over the PyPI entry in > question? Other suggestions? You cannot "take over" a project on PyPI. You can only fork the project with a new name. In fact, this has already been done: http://pypi.python.org/pypi/forked-path/0.1 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From thomas at jollans.com Mon Jul 26 19:00:50 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 27 Jul 2010 01:00:50 +0200 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: <4C4E13A2.4080804@jollans.com> On 07/27/2010 12:20 AM, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? Beauty is in the eye of the beholder, even when we call it "coding style". There is no rationale, except if you accept "easier to read", "looks better", or "that's what Guido has been doing for years". > > - Use spaces around arithmetic operators: > > Yes: > > i = i + 1 > submitted += 1 > x = x * 2 - 1 > hypot2 = x * x + y * y > c = (a + b) * (a - b) > > No: > > i=i+1 > submitted +=1 > x = x*2 - 1 > hypot2 = x*x + y*y > c = (a+b) * (a-b) > From rantingrick at gmail.com Mon Jul 26 19:06:22 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jul 2010 16:06:22 -0700 (PDT) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: On Jul 26, 5:20?pm, Peng Yu wrote: > This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? The rational is simple. Guido is God and if you don't follow his words then you will be tortured. His favorite means is by forcing you to wear Dutch wooden shoes every day whist programming Ruby! ;-) From martin.hellwig at dcuktec.org Mon Jul 26 19:15:05 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 27 Jul 2010 00:15:05 +0100 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: On 07/27/10 00:06, rantingrick wrote: > On Jul 26, 5:20 pm, Peng Yu wrote: >> This webpagehttp://www.python.org/dev/peps/pep-0008/recommends the >> following. It looks to me that both styles are fine. Could anybody let >> me know what the rationale is behind this recommendation? > > The rational is simple. Guido is God and if you don't follow his words > then you will be tortured. His favorite means is by forcing you to > wear Dutch wooden shoes every day whist programming Ruby! ;-) Wat is er mis met klompen? -- mph From thomas at jollans.com Mon Jul 26 19:15:08 2010 From: thomas at jollans.com (Thomas Jollans) Date: Tue, 27 Jul 2010 01:15:08 +0200 Subject: python terminology on classes In-Reply-To: References: Message-ID: <4C4E16FC.5000005@jollans.com> On 07/26/2010 11:52 PM, Peng Yu wrote: > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? > > constructor constructor. This consists of the class constructor method, __new__, and of the instance initialization method, __init__ In practice, __init__ is really "the constructor". http://docs.python.org/py3k/reference/datamodel.html#object.__new__ > destructor destructor. http://docs.python.org/py3k/reference/datamodel.html#object.__del__ > member function method. Look for "instance method" below > member variable attribute, instance attribute, instance variable. > virtual member function all methods are virtual. > function function. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python > terms in the manual as these term appear many times. Could you please > point me where to look for the definition of these python > corresponding terms? http://docs.python.org/py3k/reference/datamodel.html should answer all your questions. From justin2009smith at gmail.com Mon Jul 26 19:19:59 2010 From: justin2009smith at gmail.com (Justin Smith) Date: Mon, 26 Jul 2010 16:19:59 -0700 (PDT) Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> Message-ID: <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Seeking industry expert candidates I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I am currently seeking candidates to fill Tech Positions for multiple A- List Clients: ? Quality Assurance Engineer, ? Senior Data Engineer, Search Experience ? Senior Software Development Engineer, UX / UI ? Software Dev Engineer ? Software Dev TEST Engineer ? Software Development Manager, ? Sr Applications Engineer ? Strong Linux Systems Administrator ? SR Technical PM, - ? Web Designer/Developer ? strong tech and art background ? Business Analyst, Many of our Clients work within a Linux environment. For greatest impact, on your resume highlight relevant skills and technologies used in an environment supported by Linux, languages that show you understand and know object oriented development, have experience with high volume sites that are notable and are continually learning new skills. Hot List that gets our attention ? LAMP Stack Experience, Linux, Perl and Java/JavaScript Experts that are current in the use and show expertise. Microsoft environment and dot net technologies are not added attractors to many of our clients. If you are interested in these roles, send me your resume, cover letter highlighting noteworthy skills and projects with expected base salary to justin.smith at expresspros.com and I can submit it ASAP. Justin(dot)Smith(at)ExpressPros(dot)com DO FEEL FREE TO REFER this on to a friend or colleague with strong skills as well. Qualifications: - Computer Science degree or equivalent work experience (5+ years). - Expert level fluency in at least one mainstream object-oriented programming language (C++, Java, Ruby, Python). - Proven coding skills in C++ and or Java on Unix/Linux platforms is a must. - Experience with MySQL or Oracle databases a plus. - Linux or LAMP Stack experience preferred. - Experience with HTML5, XML, XSD, WSDL, and SOAP and a history working with web client software - Experience with scalable distributed systems is a positive. Added value attractors if the qualifications are available: + Experience with the iPhone SDK and Objective-C. ? published app that is stable, engaging + Experience with the BlackBerry SDK and/or J2ME. ? published app that is stable, engaging + Experience with the Android SDK. ? published app that is stable, engaging If you are interested in these roles, send me your resume, cover letter highlighting noteworthy skills and projects with expected base salary to justin.smith at expresspros.com and I can submit it ASAP. Justin(dot)Smith(at)ExpressPros(dot)com DO FEEL FREE TO REFER this on to a friend or colleague with strong skills as well. On Jul 1, 7:18?am, Stephen Hansen wrote: > On 7/1/10 3:03 AM, Jean-Michel Pichavant wrote: > > > Re is part of the python standard library, for some purpose I guess. > > No, *really*? > > So all those people who have been advocating its useless and shouldn't > be are already too late? > > Damn. > > Well, there goes *that* whole crusade we were all out on. Since we can't > destroy re, maybe we can go club baby seals. > > -- > > ? ? ... Stephen Hansen > ? ? ... Also: Ixokai > ? ? ... Mail: me+list/python (AT) ixokai (DOT) io > ? ? ... Blog:http://meh.ixokai.io/ From rantingrick at gmail.com Mon Jul 26 19:24:16 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 26 Jul 2010 16:24:16 -0700 (PDT) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: > Martin wrote: > > Wat is er mis met klompen? Well specifically their made from wood and wood is a very hard substance. Also i did not go into detail but he makes sure to pick shoes that are three sizes too small. You know a good podiatrist can be tough to come by in these times. It's a pretty severe punishment if you ask me. From rhodri at wildebst.demon.co.uk Mon Jul 26 19:29:43 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 27 Jul 2010 00:29:43 +0100 Subject: python terminology on classes References: Message-ID: On Mon, 26 Jul 2010 22:52:06 +0100, Peng Yu wrote: > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? Seriously, we can't keep doing your thinking for you. The answers to all your questions are section 9 of the tutorial. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 19:31:23 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jul 2010 23:31:23 GMT Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? > > - Use spaces around arithmetic operators: Because it looks better and is easier to read. Operators are small (single characters) and sometimes need space around them to stand out. > i=i+1 See? It's hideously ugly and cramped. It's much worse if you use larger names: sensiblynamedvariable=sensiblynamedvariable+1 But use your common sense. I usually group powers, multiplications and divisions, and separate additions and subtractions: y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2 And unary + and - operators should always be grouped with their operand: y = -2 # not "- 2" -- Steven From python.list at tim.thechases.com Mon Jul 26 19:31:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Jul 2010 18:31:29 -0500 Subject: python terminology on classes In-Reply-To: <4C4E16FC.5000005@jollans.com> References: <4C4E16FC.5000005@jollans.com> Message-ID: <4C4E1AD1.5040600@tim.thechases.com> On 07/26/10 18:15, Thomas Jollans wrote: >> destructor > > http://docs.python.org/py3k/reference/datamodel.html#object.__del__ One small caveat -- IIRC, in Java/C++ the destructor is guaranteed to be called with a certain amount of context. I find Python's __del__ almost useless since things it may rely upon can arbitrarily be destroyed before the __del__ is called. -tkc From pengyu.ut at gmail.com Mon Jul 26 19:36:12 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 26 Jul 2010 18:36:12 -0500 Subject: How to capture all the environment variables from shell? Message-ID: Hi, R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm not sure what it does when os module is imported. But it seems that os.environ doesn't capture all the environment variable from the shell. Could anybody let me know what is the correct way to inherent all the environment variables form the shell? $ echo $R_HOME /opt/R-2.11.1 $ cat main.py #!/usr/bin/env python import os print os.environ['R_HOME'] $ ./main.py Traceback (most recent call last): File "./main.py", line 5, in print os.environ['R_HOME'] File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ raise KeyError(key) KeyError: 'R_HOME' -- Regards, Peng From clp2 at rebertia.com Mon Jul 26 20:02:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 26 Jul 2010 17:02:06 -0700 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: On Mon, Jul 26, 2010 at 4:36 PM, Peng Yu wrote: > Hi, > > R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm > not sure what it does when os module is imported. But it seems that > os.environ doesn't capture all the environment variable from the > shell. Could anybody let me know what is the correct way to inherent > all the environment variables form the shell? > > $ echo $R_HOME > /opt/R-2.11.1 > $ cat main.py > #!/usr/bin/env python > > import os > > print os.environ['R_HOME'] > $ ./main.py > Traceback (most recent call last): > ?File "./main.py", line 5, in > ? ?print os.environ['R_HOME'] > ?File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ > ? ?raise KeyError(key) > KeyError: 'R_HOME' You need to "export R_HOME" in bash (probably in your .bashrc or .bash_profile). See http://www.ibm.com/developerworks/library/l-bash.html#N10074 Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Jul 26 20:02:57 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 27 Jul 2010 01:02:57 +0100 Subject: How to capture all the environment variables from shell? References: Message-ID: On Tue, 27 Jul 2010 00:36:12 +0100, Peng Yu wrote: > R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm > not sure what it does when os module is imported. But it seems that > os.environ doesn't capture all the environment variable from the > shell. Could anybody let me know what is the correct way to inherent > all the environment variables form the shell? os.environ does capture all the environment that the shell passes to it. In this case, you haven't exported R_HOME, so the shell doesn't export it, so os.environ has no chance to capture it. rhodri at gnudebst:~$ HELLO=world rhodri at gnudebst:~$ echo $HELLO world rhodri at gnudebst:~$ export HELLO rhodri at gnudebst:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ['HELLO'] 'world' -- Rhodri James *-* Wildebeest Herder to the Masses From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 20:04:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 00:04:22 GMT Subject: python terminology on classes References: Message-ID: <4c4e2286$0$11091$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 16:52:06 -0500, Peng Yu wrote: > Could you please let me know what the equivalent terms for the following > C++ terms? > > constructor > destructor > member function > member variable > virtual member function > function (1) Python new-style classes have a constructor __new__ and an initialiser __init__. Some people describe both as constructors, but that's strictly incorrect because the instance has already been constructed by the time __init__ is called. (Old-style classes don't have __new__, only __init__.) (2) Python destructors are called __del__ , but you shouldn't use them unless you really know what you are doing. (3) "Member functions" are methods. (4) "Member variables" are attributes. If you have to distinguish between attributes which live on the instance from one that lives on the class, "instance attribute" and "class attribute". (5) I believe that all methods in Python are virtual. (6) Function. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python terms > in the manual as these term appear many times. Could you please point me > where to look for the definition of these python corresponding terms? I believe you are right, but I can't find a definition of C++ "member function" that makes sense. Can you please point me where to look for the definition of these C++ terms? I don't believe the Python Language Reference explicitly defines terms such as "attribute" and "method", but the tutorial may help: http://docs.python.org/tutorial/classes.html Quote: In C++ terminology, all class members (including the data members) are public, and all member functions are virtual. Note: although the docs occasionally use the term "members" for attributes, it is considered more standard to use "attribute" or "method" unless discussing data types defined at the C layer. -- Steven From cs at zip.com.au Mon Jul 26 20:06:02 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 27 Jul 2010 10:06:02 +1000 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: <20100727000602.GA22711@cskk.homeip.net> On 26Jul2010 18:36, Peng Yu wrote: | R_HOME is set in my shell (bash). But os.environ doesn't have it. I'm | not sure what it does when os module is imported. But it seems that | os.environ doesn't capture all the environment variable from the | shell. Could anybody let me know what is the correct way to inherent | all the environment variables form the shell? | | $ echo $R_HOME | /opt/R-2.11.1 | $ cat main.py | #!/usr/bin/env python | | import os | | print os.environ['R_HOME'] | $ ./main.py | Traceback (most recent call last): | File "./main.py", line 5, in | print os.environ['R_HOME'] | File "/opt/Python-2.6.5/lib/python2.6/UserDict.py", line 22, in __getitem__ | raise KeyError(key) | KeyError: 'R_HOME' Sounds like R_HOME is not exported. Try these in your shell: set | grep R_HOME export | grep R_HOME Then, presuming it shows only in the first command: export R_HOME and then try your python script again. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It is an approved maxim in war, never to do what the enemy wishes you to do, for this reason alone, that he desires it. - Napoleon From steve at REMOVE-THIS-cybersource.com.au Mon Jul 26 20:09:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 00:09:17 GMT Subject: python terminology on classes References: Message-ID: <4c4e23ac$0$11091$c3e8da3@news.astraweb.com> On Tue, 27 Jul 2010 01:15:08 +0200, Thomas Jollans wrote: > http://docs.python.org/py3k/reference/datamodel.html should answer all > your questions. It should, but as far as I can tell it doesn't. If it defines "attribute" or "method", I can't find it. -- Steven From python at rcn.com Mon Jul 26 20:46:11 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 26 Jul 2010 17:46:11 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: <6273b6b0-6c3a-4cca-9ac3-3d7b96819862@x24g2000pro.googlegroups.com> [Ethan Furman] > Speaking of new-style classes only, don't they all end in object? ?And > if the MRO is only known at run-time, how is one to know at code-time > whether your (new-style) class is at the end of the line? That is a bit of a PITA. One way of handling it is to design your diamond so that only one class inherits from object and that class doesn't use super(). Or you can wrap the super call in a try/except AttributeError. Cooperative multiple inheritance isn't pretty -- which is just another good reason to use composition rather that inheritance. Raymond From debatem1 at gmail.com Mon Jul 26 21:55:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 26 Jul 2010 18:55:34 -0700 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> References: <4c4e1acb$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jul 26, 2010 at 4:31 PM, Steven D'Aprano wrote: > On Mon, 26 Jul 2010 17:20:09 -0500, Peng Yu wrote: > >> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the >> following. It looks to me that both styles are fine. Could anybody let >> me know what the rationale is behind this recommendation? >> >> ? ? - Use spaces around arithmetic operators: > > Because it looks better and is easier to read. Operators are small > (single characters) and sometimes need space around them to stand out. > >> ? ? ? ? ? i=i+1 > > See? It's hideously ugly and cramped. It's much worse if you use larger > names: > > sensiblynamedvariable=sensiblynamedvariable+1 > > But use your common sense. I usually group powers, multiplications and > divisions, and separate additions and subtractions: > > y = 2*x + 1 - (3*x - 4/(2 + x**2))**-2 > > And unary + and - operators should always be grouped with their operand: > > y = -2 ?# not "- 2" This is the rule that I use, with the exception that I will generally explicitly parenthesize the numerator in a division, since my eyes frequently gloss over the / symbol for some reason. Geremy Condra From steveo at syslang.net Mon Jul 26 22:26:27 2010 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Jul 2010 22:26:27 -0400 Subject: How to capture all the environment variables from shell? In-Reply-To: References: Message-ID: <4C4E43D3.9070203@syslang.net> On 07/26/10 20:02, quoth Chris Rebert: > On Mon, Jul 26, 2010 at 4:36 PM, Peng Yu wrote: > > You need to "export R_HOME" in bash (probably in your .bashrc or > .bash_profile). See > http://www.ibm.com/developerworks/library/l-bash.html#N10074 Please! Never export anything from your .bashrc unless you really know what you're doing. Almost all exports should be done in your .bash_profile -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Mon Jul 26 22:35:24 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 26 Jul 2010 19:35:24 -0700 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: <4C4E45EC.8030509@ixokai.io> On 7/26/10 3:20 PM, Peng Yu wrote: > This webpage http://www.python.org/dev/peps/pep-0008/ recommends the > following. It looks to me that both styles are fine. Could anybody let > me know what the rationale is behind this recommendation? PEP8 is a style guide. Parts of style guides are rational judgements and decisions based on experience and can certainly be "explained" or justified, but parts are just... personal taste. Style is part rational thought and part intuition, and in the latter -- people will disagree quite a bit. There's no right or wrong there. There isn't always a rationale. Guido finds "x=a+1" less readable then "x = a + 1". Originally he wrote this down with other anecdotal little tidbits up into an eassy and posted it on the python.org website. Eventually, others decided that his intuitive sense of style actually tended to be rather spot on for them too (why wouldn't it, since that same sense of style brought Python into existence and most of us quite like it), and so that guide and some others were codified into PEP8, and tweaked from time to time. PEP8 is only a "rule" for the stdlib, and only for new code in the stdlib at that -- and its only really a rule to encourage consistency and maintainability, not because its objectively The Right Way To Code. Personally, while I agree with much of it, I disagree in several points and ignore PEP8 whenever it suits me (most notably on line length rules, and for a long time on methodNamingSchemes, but lately I've found I'm coming_around). -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From python at bdurham.com Mon Jul 26 22:41:53 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 26 Jul 2010 22:41:53 -0400 Subject: Python 2.7 for Windows: Same version of MS VC runtime as Python 2.6? Message-ID: <1280198513.5040.1386886575@webmail.messagingengine.com> Python 2.7 for Windows: Does Python 2.7 for Windows use the same version of the MS VC runtime as Python 2.6? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Jul 26 22:42:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Jul 2010 21:42:24 -0500 Subject: How to capture all the environment variables from shell? In-Reply-To: <4C4E43D3.9070203@syslang.net> References: <4C4E43D3.9070203@syslang.net> Message-ID: <4C4E4790.6030604@tim.thechases.com> On 07/26/10 21:26, Steven W. Orr wrote: > Please! Never export anything from your .bashrc unless you > really know what you're doing. Almost all exports should be > done in your .bash_profile Could you elaborate on your reasoning why (or why-not)? I've found that my .bash_profile doesn't get evaluated when I crank up another terminal window, while my bashrc does. Thus I tend to put my exports in my ~/.bashrc so they actually take effect in my shell... -tkc From steve-REMOVE-THIS at cybersource.com.au Mon Jul 26 23:01:04 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 27 Jul 2010 03:01:04 GMT Subject: How to capture all the environment variables from shell? References: Message-ID: <4c4e4bf0$0$11110$c3e8da3@news.astraweb.com> On Mon, 26 Jul 2010 22:26:27 -0400, Steven W. Orr wrote: > Please! Never export anything from your .bashrc unless you really know > what you're doing. Almost all exports should be done in your > .bash_profile Would you like to explain why, or should we just trust you? -- Steven From ben+python at benfinney.id.au Mon Jul 26 23:26:46 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Jul 2010 13:26:46 +1000 Subject: Why are String Formatted Queries Considered So Magical? References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Message-ID: <87pqy94nbd.fsf@benfinney.id.au> Justin Smith writes: > Seeking industry expert candidates Please don't reply in an existing thread with an unrelated message. If you want to start a new discussion, compose a new message, not a reply. For job advertisements, please don't use this forum at all; instead use the Python Jobs Board . -- \ ?We are stuck with technology when what we really want is just | `\ stuff that works.? ?Douglas Adams | _o__) | Ben Finney From urban.yoga.journeys at gmail.com Tue Jul 27 00:15:15 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Mon, 26 Jul 2010 21:15:15 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code Message-ID: 0 down vote favorite i've written a tool in python where you enter a title, content, then tags, and the entry is then saved in a pickle file. it was mainly designed for copy-paste functionality (you spot a piece of code you like on the net, copy it, and paste it into the program), not really for handwritten content, though it does that with no problem. i mainly did it because i'm always scanning through my pdf files, books, or the net for some coding example of solution that i'd already seen before, and it just seemed logical to have something where you could just put the content in, give it a title and tags, and just look it up whenever you needed to. i realize there are sites online that handle this ex. http://snippets.dzone.com, but i'm not always online when i code. i also admit that i didn't really look to see if anyone had written a desktop app, the project seemed like a fun thing to do so here i am. it wasn't designed with millions of entries in mind, so i just use a pickle file to serialize the data instead of one of the database APIs. the query is also very basic, only title and tags and no ranking based on the query. there is an issue that i can't figure out, when you are at the list of entries there's a try, except clause where it tries to catch a valid index (integer). if you enter an inavlid integer, it will ask you to enter a valid one, but it doesn't seem to be able to assign it to the variable. if you enter a valid integer straightaway, there are no problems and the entry will display. anyway let me know what you guys think. this is coded for python3. main file: #!usr/bin/python from archive_functions import Entry, choices, print_choice, entry_query import os def main(): choice = '' while choice != "5": os.system('clear') print("Mo's Archive, please select an option") print('====================') print('1. Enter an entry') print('2. Lookup an entry') print('3. Display all entries') print('4. Delete an entry') print('5. Quit') print('====================') choice = input(':') if choice == "1": entry = Entry() entry.get_data() entry.save_data() elif choice == "2": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "3": queryset = 'all' result = entry_query('entry.pickle', queryset) if result: print_choice(result, choices(result)) elif choice == "4": queryset = input('Enter title or tag query: ') result = entry_query('entry.pickle', queryset) if result: entry = result[choices(result)] entry.del_data() else: os.system('clear') print('No Match! Please try another query') pause = input('\npress [Enter] to continue...') elif choice == "5": break else: input('please enter a valid choice...') main() if __name__ == "__main__": main() archive_functions.py: #!/bin/usr/python import sys import pickle import os import re class Entry(): def get_data(self): self.title = input('enter a title: ') print('enter the code, press ctrl-d to end: ') self.code = sys.stdin.readlines() self.tags = input('enter tags: ') def save_data(self): with open('entry.pickle', 'ab') as f: pickle.dump(self, f) def del_data(self): with open('entry.pickle', 'rb') as f: data_list = [] while True: try: entry = pickle.load(f) if self.title == entry.title: continue data_list.append(entry) except: break with open('entry.pickle', 'wb') as f: pass with open('entry.pickle', 'ab') as f: for data in data_list: data.save_data() def entry_query(file, queryset): '''returns a list of objects matching the query''' result = [] try: with open(file, 'rb') as f: entry = pickle.load(f) os.system('clear') if queryset == "all": while True: try: result.append(entry) entry = pickle.load(f) except: return result break while True: try: if re.search(queryset, entry.title) or re.search(queryset, entry.tags): result.append(entry) entry = pickle.load(f) else: entry = pickle.load(f) except: return result break except: print('no entries in file, please enter an entry first') pause = input('\nPress [Enter] to continue...') def choices(list_result): '''takes a list of objects and returns the index of the selected object''' os.system('clear') index = 0 for entry in list_result: print('{}. {}'.format(index, entry.title)) index += 1 try: choice = int(input('\nEnter choice: ')) return choice except: pause = input('\nplease enter a valid choice') choices(list_result) def print_choice(list_result, choice): '''takes a list of objects and an index and displays the index of the list''' os.system('clear') print('===================') print(list_result[choice].title) print('===================') for line in list_result[choice].code: print(line, end="") print('\n\n') back_to_choices(list_result) def back_to_choices(list_result): print('1. Back to entry list') print('2. Back to Main Menu') choice = input(':') if choice == "1": print_choice(list_result, choices(list_result)) elif choice == "2": pass else: print('\nplease enter a valid choice') back_to_choices(list_result) From mithrandiragainwiki at mailinator.com Tue Jul 27 00:27:41 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Mon, 26 Jul 2010 21:27:41 -0700 Subject: why is this group being spammed? References: <334170d5-a336-4506-bda1-279b40908e31@k1g2000prl.googlegroups.com> Message-ID: On 07/18/2010 03:58 PM, Edward A. Falk wrote: > In article<334170d5-a336-4506-bda1-279b40908e31 at k1g2000prl.googlegroups.com>, > be.krul wrote: >> why is this group being spammed? > > They're *all* being spammed. Why? Because they can, and because Google > doesn't care. > Not only does Google not care, but they've made Usenet more accessible to the general public. How is that bad? You go back in time, before Google bought out Deja News, and ask the average Tom, Dick, or Harry if they knew what Usenet was. Their response probably would have been "No" or "Maybe..." or "Isn't that dead?" Now more people know about Usenet and don't have to go through the hassle of finding a free server (or paying), getting a reliable newsreader (Thunderbird, XNews, etc.), and learning posting "COME TO MY WEBSITE!!111!!" anywhere (except misc.test) will get you mocked and ridiculed. ;) Now there's nothing wrong with making a newsserver publicly available and free, but when you maintain it like a throw-away blog, allowing child porn, spam, et al., you might as well kiss customer trust goodbye. Welcome to the Age of Google! :) A nice little page that I found that, unfortunately, is dead, has some info on Google Groups: http://web.archive.org/web/20080124152054/http://improve-usenet.org/ -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." From ldo at geek-central.gen.new_zealand Tue Jul 27 02:55:54 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 27 Jul 2010 18:55:54 +1200 Subject: non-blocking IO EAGAIN on write References: <8at354F51tU1@mid.individual.net> Message-ID: In message , Roy Smith wrote: > Consider, for example, a write on a TCP connection. You are sitting in > a select(), when the other side closes the connection. The select() > should return, and the write should then immediately fail. Remember that select can return 3 different sets of file objects. I?ve yet to see a use for the third one. From ldo at geek-central.gen.new_zealand Tue Jul 27 02:58:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 27 Jul 2010 18:58:26 +1200 Subject: Are those features still the same? References: Message-ID: In message , francogrex wrote: > By the way Peter Norvig is not biased, he works for Google research and is > a supporter of programming in any language, especially in Python. Bias doesn?t have to be a conscious thing. From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:17:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:17:27 +0200 Subject: python terminology on classes In-Reply-To: References: Message-ID: <4c4e8801$0$14554$426a74cc@news.free.fr> Peng Yu a ?crit : > Hi > > I'm still kind of confused about the terminology on classes in python. > > Could you please let me know what the equivalent terms for the > following C++ terms? C++ and Python having very different semantics and object models, there's not necessarily a straight one to one mapping. > > constructor Python uses a smalltalk-like 2 phases instanciation / initialisation scheme. First the "proper" construction (__new__) is called with the class object as first argument, and it must return an unintialised instance of the class. Then the initialiser (__init__) is called on this instance. Now one usually only implements the initialiser, as the default object.__new__ method does what you would expect, so you'll often see people qualifying __init__ as the constructor. > destructor Python has no real destructor. You can implement a __del__ method that will _eventually_ be called before the instance gets garbage-collected, but you'd rather not rely on it. Also, implementing this method will prevent cycle detection. > member function => method. Note that Python's "methods" are really thin wrappers around function objects that are attributes of the class object. You'll find more on this here: http://wiki.python.org/moin/FromFunctionToMethod > member variable => Attribute > virtual member function All Python's methods are virtual. > function => function !-) Note that in Python, functions and classes are objects. > I think that C++ "function" is equivalent to python "function" and C++ > "member function" is equivalent to python "method". But I couldn't > locate where the original definitions of the corresponding python > terms in the manual as these term appear many times. Could you please > point me where to look for the definition of these python > corresponding terms? You just cannot directly translate C++ into Python, and while there are similarities trying to write C++ in Python will not get you very far. From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:21:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:21:30 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> Message-ID: <4c4e88f4$0$14554$426a74cc@news.free.fr> Ethan Furman a ?crit : > Bruno Desthuilliers wrote: >> Duncan Booth a ?crit : (snip) >>> Or you could create the default as a class attribute >> >> from the OP: >> """ >> I have a class (FuncDesigner oofun) that has no attribute "size", but >> it is overloaded in __getattr__, so if someone invokes >> "myObject.size", it is generated (as another oofun) and connected to >> myObject as attribute. >> """ >> >> so this solution won't obviously work in this case !-) >> >> Also and FWIW, I wouldn't advocate this solution if the "default" >> class attribute is of a mutable type. > > Well, it is Monday, so I may be missing something obvious, but what is > the effective difference between these two solutions? Now it's Tuesday !-) Ok, let's see: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... whatever = Foo() ... Traceback (most recent call last): File "", line 1, in File "", line 2, in Foo NameError: name 'Foo' is not defined >>> From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 03:28:26 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 09:28:26 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4e88f4$0$14554$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> Message-ID: <4c4e8a95$0$24098$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Ethan Furman a ?crit : >> Bruno Desthuilliers wrote: >>> Duncan Booth a ?crit : > (snip) > >>>> Or you could create the default as a class attribute >>> >>> from the OP: >>> """ >>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>> it is overloaded in __getattr__, so if someone invokes >>> "myObject.size", it is generated (as another oofun) and connected to >>> myObject as attribute. >>> """ >>> >>> so this solution won't obviously work in this case !-) >>> >>> Also and FWIW, I wouldn't advocate this solution if the "default" >>> class attribute is of a mutable type. >> >> Well, it is Monday, so I may be missing something obvious, but what is >> the effective difference between these two solutions? > If you meant "what is the difference between creating the "whatever" attribute with a default value in the initializer and creating it on demand in the __getattr__ hook", the main difference is that in the first case, the instance is garanteed to have this attribute, so you get rid of "hasattr" checks (and the unwanted side effects) or, worse, direct check of the instance __dict__. Except for a couple of corner case, client code shouldn't have to worry about this kind of things - this breaks encapsulation. From __peter__ at web.de Tue Jul 27 04:23:20 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 10:23:20 +0200 Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: mo reina wrote: > i've written a tool in python where you enter a title, content, then > tags, and the entry is then saved in a pickle file. it was mainly > designed for copy-paste functionality (you spot a piece of code you > like on the net, copy it, and paste it into the program), not really > for handwritten content, though it does that with no problem. > > i mainly did it because i'm always scanning through my pdf files, > books, or the net for some coding example of solution that i'd already > seen before, and it just seemed logical to have something where you > could just put the content in, give it a title and tags, and just look > it up whenever you needed to. > > i realize there are sites online that handle this ex. > http://snippets.dzone.com, but i'm not always online when i code. i also > admit that i didn't really look to see if anyone had written a desktop > app, the project seemed like a fun thing to do so here i am. > > it wasn't designed with millions of entries in mind, so i just use a > pickle file to serialize the data instead of one of the database APIs. > the query is also very basic, only title and tags and no ranking based > on the query. > > there is an issue that i can't figure out, when you are at the list of > entries there's a try, except clause where it tries to catch a valid > index (integer). if you enter an inavlid integer, it will ask you to > enter a valid one, but it doesn't seem to be able to assign it to the > variable. if you enter a valid integer straightaway, there are no > problems and the entry will display. > > anyway let me know what you guys think. this is coded for python3. > def choices(list_result): > '''takes a list of objects and returns the index of the selected > object''' > os.system('clear') > index = 0 > for entry in list_result: > print('{}. {}'.format(index, entry.title)) > index += 1 > try: > choice = int(input('\nEnter choice: ')) > return choice > except: > pause = input('\nplease enter a valid choice') > choices(list_result) When the exception is triggered you call choices() recursively but discard the result. Therefore you get Python's default, None, which is not a valid index. Change the last line to return choices(list_result) for a minimal fix. However, I suggest that you use a while loop instead of the recursion: def choices(list_result): while True: os.system('clear') for index, entry in enumerate(list_result): print('{}. {}'.format(index, entry.title)) try: choice = int(input('\nEnter choice: ')) if 0 <= choice < len(list_result): return choice except ValueError: pass input('\nplease enter a valid choice') I've also added a test for the integer range and replaced the bare except with a more specific one. I recommend that you never use bare excepts because they can hide unexpected exceptions and lead to nasty bugs. You should also remove the recursive call of main(). Its only effect is that when you enter an invalid choice twice you will have to enter "5" twice to really exit your script. Peter From __peter__ at web.de Tue Jul 27 04:37:08 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 10:37:08 +0200 Subject: Checking that 2 pdf are identical (md5 a solution?) References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: rlevesque wrote: > On Jul 24, 1:34 pm, Peter Otten <__pete... at web.de> wrote: >> rlevesque wrote: >> > Unfortunately there is an other pair of values that does not match and >> > it is not obvious to me how to exclude it (as is done with the " / >> > CreationDate" pair). >> > and the pdf document is created using reportLab. >> >> I dug into the reportlab source and in >> >> reportlab/rl_config.py >> >> found the line >> >> invariant= 0 #produces >> repeatable,identical PDFs with same timestamp info (for regression >> testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) Relax! Assistance on c.l.py is free as in beer ;) If you feel you have to give something back pick a question you can answer, doesn't matter who's asking. Given that I can't answer the majority of questions posted here chances are that I learn something from your response, too. Peter From kaklis at gmail.com Tue Jul 27 05:58:14 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 02:58:14 -0700 (PDT) Subject: Sorting a list created from a parsed xml message References: <961f1364-773a-499c-8742-1468b16d9842@w35g2000prd.googlegroups.com> <51dc5047-dca7-451c-9c4f-3bc1d279e6c2@k1g2000prl.googlegroups.com> <05a09bc1-4762-43bb-9363-c032eb049dc1@n8g2000prh.googlegroups.com> Message-ID: On Jul 22, 12:56?pm, Thomas Jollans wrote: > On 07/21/2010 03:38 PM, kak... at gmail.com wrote: > > > > > On Jul 21, 9:04 am, "kak... at gmail.com" wrote: > >> On Jul 21, 8:58 am, Stefan Behnel wrote: > > >>> kak... at gmail.com, 21.07.2010 14:36: > > >>>> From the subject of my message it's clear that i get an xml message > >>>> from a socket, > > >>> Not at all, but now that you say it... > > >>>> i parse it and the result is a list like the one that > >>>> follows: > >>>> ID_Col > >>>> 4 ? ?Server ? ? ? ?ak ? ? ? ? ? ? ?ip ? ? ?OFFLINE > > >>>> 29 ? ? ?Server ? ? and2 ? ?ip ? ? ?OFFLINE > > >>>> 5 ? ?Proxy ? ? ? ? l34e ? ? ? ? ip OFFLINE > > >>>> 6 ? ? ? ? ? ?Proxy ? ? ? ? barc ? ? ? ? ? ?ip ? ? ?ONLINE > > >>>> 41 ? ? ? ? ? Proxy ? ? ? ? proxy-2 ? ? ? ? ip ? ? ?ONLINE > > >>>> 53 ? ? ? ? ? Server ? ? ? ?server-4 ? ? ? ?ip ? ? ?ONLINE > > >>>> 52 ? ? ? ? ? Server ? ? ? ?server-3 ? ? ? ?ip ? ? ?ONLINE > > >>> Doesn't look like a Python list to me... > > >>>> What i want is to print this list sorted by ID_Col? > >>>> Any Suggestions? > > >>> Assuming that the above is supposed to represent a list of tuples, you can > >>> use the .sort() method on the list and pass operator.itemgetter(0) as 'key' > >>> argument (see the sort() method and the operator module). > > >>> Stefan > > >> No it is not a Python list at all. This the way i print the parsed > >> items 'like a list'. > >> But i want them to be sorted. > > > Well i did this: > > > SortedServers = [] > > > for session in sessions: > > ? ? for IP in session.getElementsByTagName("ipAddress"): > > ? ? ? ? ?for iphn in session.getElementsByTagName("hostName"): > > ? ? ? ? ? ? ? tempTuple = session.getAttribute("id"), > > session.getAttribute("type"), iphn.childNodes[0].data, > > IP.childNodes[0].data, session.getAttribute("status") > > Please try to persuade your mail client to not mess up python code, if > you could. It would make this *so* much easier to read > > > > > ? ? ? ? ? ? ? SortedServers.append(tempTuple) > > > Sorted = sorted(SortedServers, key=lambda id: SortedServers[0]) > > Anyway, let's look at that key function of yours: > > key=lambda id: SortedServers[0] > > translated to traditional function syntax: > > def key(id): > ? ? return SortedServers[0] > > No matter which item sorted() examines, the key it sorts by is always > the same (the first item of the WHOLE LIST). > You want something more like this: > > def key(row): > ? ? return row[0] > > ergo, what you want, all in all, is either of these: > > Sorted = sorted(SortedServers, key=(lambda row: row[0])) # option 1 > SortedServers.sort(key=(lambda row: row[0])) ? ? ? ? ? ? # option 2 > > option 2, the in-place sort, might be faster. > > (and, as Stefan noted, as you probably want a numeric sort, you'll want > your key to be an int) > > > for item in Sorted: > > ? ? ?print item > > > but the list is still unsorted and with u' in front of each item > > > (u'4', u'Server', u'aika74', u'ip', u'OFFLINE') > > (u'29', u'Server', u'ando', u'ip2', u'OFFLINE') > > > How do i remove the u' > > > Antonis > > Thank you so much for your detailed response! Antonis K. From kaklis at gmail.com Tue Jul 27 06:17:36 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 03:17:36 -0700 (PDT) Subject: parsing different xml messages Message-ID: Hello, I receive the following different Xml Messages from a socket: 5a62ded 101 Angie online Some IP Server server-1 is going down for redeploy! Which is the best way to make a distinction between them so that every time my app receives the one or the other, parse them correctly? Thanks Antonis K. From nobody at nowhere.com Tue Jul 27 06:21:29 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 27 Jul 2010 11:21:29 +0100 Subject: How to capture all the environment variables from shell? References: <4C4E43D3.9070203@syslang.net> Message-ID: On Mon, 26 Jul 2010 21:42:24 -0500, Tim Chase wrote: >> Please! Never export anything from your .bashrc unless you >> really know what you're doing. Almost all exports should be >> done in your .bash_profile > > Could you elaborate on your reasoning why (or why-not)? I've > found that my .bash_profile doesn't get evaluated when I crank up > another terminal window, while my bashrc does. Thus I tend to > put my exports in my ~/.bashrc so they actually take effect in my > shell... Ideally, whichever program spawns the terminal window should have all of the environment settings from your ~/.profile (although you may have to explicitly source it from e.g. ~/.xsession), so it shouldn't be necessary to export them again. Using ~/.bashrc is a band-aid in case your desktop session doesn't already have your environment settings. But it only works for shells (and only for bash shells, and only for interactive bash shells), while your environment settings should be available to everything, regardless of whether it was spawned from an interactive bash shell or from some other program. Also, if you update environment variables with e.g.: export PATH=$PATH:/usr/local/bin any nested shells end up getting multiple updates. From tania786786 at gmail.com Tue Jul 27 06:21:34 2010 From: tania786786 at gmail.com (tania tani) Date: Tue, 27 Jul 2010 03:21:34 -0700 (PDT) Subject: $$$$ YOU ARE JUST ONE CLICK TO MAKE DOLLAR ITS FREE Message-ID: http://www.bigextracash.com/aft/9b6cc578.html also click here to see and enjoy http://sitetalk.com/imranraza From urban.yoga.journeys at gmail.com Tue Jul 27 06:29:07 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Tue, 27 Jul 2010 03:29:07 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: > mo reina wrote: > > i've written a tool in python where you enter a title, content, then > > tags, and the entry is then saved in a pickle file. it was mainly > > designed for copy-paste functionality (you spot a piece of code you > > like on the net, copy it, and paste it into the program), not really > > for handwritten content, though it does that with no problem. > > > i mainly did it because i'm always scanning through my pdf files, > > books, or the net for some coding example of solution that i'd already > > seen before, and it just seemed logical to have something where you > > could just put the content in, give it a title and tags, and just look > > it up whenever you needed to. > > > i realize there are sites online that handle this ex. > >http://snippets.dzone.com, but i'm not always online when i code. i also > > admit that i didn't really look to see if anyone had written a desktop > > app, the project seemed like a fun thing to do so here i am. > > > it wasn't designed with millions of entries in mind, so i just use a > > pickle file to serialize the data instead of one of the database APIs. > > the query is also very basic, only title and tags and no ranking based > > on the query. > > > there is an issue that i can't figure out, when you are at the list of > > entries there's a try, except clause where it tries to catch a valid > > index (integer). if you enter an inavlid integer, it will ask you to > > enter a valid one, but it doesn't seem to be able to assign it to the > > variable. if you enter a valid integer straightaway, there are no > > problems and the entry will display. > > > anyway let me know what you guys think. this is coded for python3. > > def choices(list_result): > > ? ? '''takes a list of objects and returns the index of the selected > > object''' > > ? ? os.system('clear') > > ? ? index = 0 > > ? ? for entry in list_result: > > ? ? ? ? print('{}. {}'.format(index, entry.title)) > > ? ? ? ? index += 1 > > ? ? try: > > ? ? ? ? choice = int(input('\nEnter choice: ')) > > ? ? ? ? return choice > > ? ? except: > > ? ? ? ? pause = input('\nplease enter a valid choice') > > ? ? ? ? choices(list_result) > > When the exception is triggered you call choices() recursively but discard > the result. Therefore you get Python's default, None, which is not a valid > index. Change the last line to > > return choices(list_result) > > for a minimal fix. However, I suggest that you use a while loop instead of > the recursion: > > def choices(list_result): > ? ? while True: > ? ? ? ? os.system('clear') > ? ? ? ? for index, entry in enumerate(list_result): > ? ? ? ? ? ? print('{}. {}'.format(index, entry.title)) > ? ? ? ? try: > ? ? ? ? ? ? choice = int(input('\nEnter choice: ')) > ? ? ? ? ? ? if 0 <= choice < len(list_result): > ? ? ? ? ? ? ? ? return choice > ? ? ? ? except ValueError: > ? ? ? ? ? ? pass > ? ? ? ? input('\nplease enter a valid choice') > > I've also added a test for the integer range and replaced the bare except > with a more specific one. I recommend that you never use bare excepts > because they can hide unexpected exceptions and lead to nasty bugs. > > You should also remove the recursive call of main(). Its only effect is that > when you enter an invalid choice twice you will have to enter "5" twice to > really exit your script. > > Peter hi peter, i noticed the issue you mentioned but don't understand why they happen. for example, when the function is called in the case of an exception, the variable choice is re-assigned to whatever the next input is, so why is the default None assigned instead? and what' s the difference between just calling the function again (the variable list_result remains unchanged) and using a return statement? i also don' t understand what happens when main is called recursively, the variable choice should be re-assigned to whatever the next input is, and yet it seems that in the first call, after an invalid choice, it doesn't assign the input to the variable. thanks for taking the time to post and review the code by the way, i really appreciate it From stefan_ml at behnel.de Tue Jul 27 06:30:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 12:30:48 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 12:17: > I receive the following different Xml Messages from a socket: From a bare socket? TCP? UDP? Or what else? > Which is the best way to make a distinction between them so that every > time my app receives the one or the other, parse them correctly? Use an application level protocol? Stefan From debatem1 at gmail.com Tue Jul 27 06:54:07 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 27 Jul 2010 03:54:07 -0700 Subject: Accumulate function in python In-Reply-To: <4c470fa3$0$1583$742ec2ed@news.sonic.net> References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote: > On 7/19/2010 9:56 AM, dhruvbird wrote: >> >> On Jul 19, 9:12 pm, Brian Victor ?wrote: >>> >>> dhruvbird wrote: > >>> Having offered this, I don't recall ever seeing reduce used in real >>> python code, and explicit iteration is almost always preferred. >> >> Yes, even I have noticed that reduce is a tad under-used function. > > ? ?Yes, I had a use case for it once, but it wasn't worth the trouble. > "map" is often useful, but "reduce", not so much. > > ? ?Python isn't really a functional language. ?There's no bias toward > functional solutions, lambdas aren't very general, and the performance > isn't any better. ?Nor is any concurrency provided by "map" or "reduce". > So there's no win in trying to develop cute one-liners. Too bad about the lack of concurrency, would be many places where that would be nice. Geremy Condra From me at here.com Tue Jul 27 07:07:09 2010 From: me at here.com (whitey) Date: Tue, 27 Jul 2010 11:07:09 GMT Subject: newb Message-ID: hi all. am totally new to python and was wondering if there are any newsgroups that are there specifically for beginners. i have bought a book for $2 called "learn to program using python" by alan gauld. starting to read it but it was written in 2001. presuming that the commands and info would still be valid? any websites or books that are a must for beginners? any input would be much appreciated...cheers From hanycv80 at gmail.com Tue Jul 27 07:13:53 2010 From: hanycv80 at gmail.com (=?windows-1256?B?KioqKioq48rd3Nzc3Nzc3MfG3Nzc3Nzc4SoqKioqKg==?=) Date: Tue, 27 Jul 2010 04:13:53 -0700 (PDT) Subject: Enjoy Thousands Of Tips and Trikes Message-ID: <2be45a25-7c77-4e0d-8a6b-b7b7cf7076ab@t19g2000vbf.googlegroups.com> Very Nice Tips and Trikes I am sure you are going to love it. Financing Information http://www.netcafee.com/finance/index.php Preparing For Your Vacation http://www.netcafee.com/travel/index.php Buying A Fuel-Efficient Car http://www.netcafee.com/car/index.php Computer Help http://www.netcafee.com/computer/index.php Shopping Online http://www.netcafee.com/shopping/index.php Using Online Video Websites to Promote Your Business http://www.netcafee.com/video/index.php Have Fun..... From sjmachin at lexicon.net Tue Jul 27 07:15:32 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 27 Jul 2010 04:15:32 -0700 (PDT) Subject: newb References: Message-ID: On Jul 27, 9:07?pm, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers 2001 is rather old. Most of what you'll want is on the web. See http://wiki.python.org/moin/BeginnersGuide From stefan_ml at behnel.de Tue Jul 27 07:16:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 13:16:59 +0200 Subject: Accumulate function in python In-Reply-To: References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> <7476be43-a677-4829-af6a-283caf03a2fb@h40g2000pro.googlegroups.com> <4c470fa3$0$1583$742ec2ed@news.sonic.net> Message-ID: geremy condra, 27.07.2010 12:54: > On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote: >> On 7/19/2010 9:56 AM, dhruvbird wrote: >>> >>> On Jul 19, 9:12 pm, Brian Victor wrote: >>>> >>>> dhruvbird wrote: >> >>>> Having offered this, I don't recall ever seeing reduce used in real >>>> python code, and explicit iteration is almost always preferred. >>> >>> Yes, even I have noticed that reduce is a tad under-used function. >> >> Yes, I had a use case for it once, but it wasn't worth the trouble. >> "map" is often useful, but "reduce", not so much. >> >> Python isn't really a functional language. There's no bias toward >> functional solutions, lambdas aren't very general, and the performance >> isn't any better. Nor is any concurrency provided by "map" or "reduce". >> So there's no win in trying to develop cute one-liners. > > Too bad about the lack of concurrency, would be many places where that > would be nice. Besides the many places where the current properties match just fine, there are some places where concurrency would be helpful. So I wouldn't call it "lack" of concurrency, as that seems to imply that it's a missing feature in what both builtins are targeted to provide. Just use one of the map-reduce frameworks that are out there if you need concurrency in one way or another. Special needs are not what builtins are there for. Stefan From roy at panix.com Tue Jul 27 07:48:24 2010 From: roy at panix.com (Roy Smith) Date: Tue, 27 Jul 2010 07:48:24 -0400 Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: In article , Stephen Hansen wrote: > PEP8 is a style guide. Parts of style guides are rational judgements and > decisions based on experience and can certainly be "explained" or > justified, but parts are just... personal taste. Style is part rational > thought and part intuition, and in the latter -- people will disagree > quite a bit. There's no right or wrong there. There isn't always a > rationale. I strongly suggest that ALL Python projects adopt PEP-8. Here's why. Style, at one level, doesn't really matter. Yet, it's something people get worked up over. If you add up all the time people have wasted arguing about stupid shit like indenting and where the braces go (in languages that have them) and how to spell variable names, we could have sent a man to Mars and had time left over to solve P = NP. I don't agree with PEP-8 100%, but it's perfectly reasonable. Avoiding all that time wasting arguing about trivia like variableName vs VariableName vs variable_name more than pays me back for any minor arguments I might have with the style. If everybody in the entire world uses the same style, then as people and code move around from project to project, everybody benefits by fitting in better. As the old-time press pythonistas would say, "PEP-8 and be there". From robin at reportlab.com Tue Jul 27 07:55:47 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 27 Jul 2010 12:55:47 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) In-Reply-To: References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: <4C4EC943.50600@chamonix.reportlab.co.uk> .......... >> repeatable,identical PDFs with same timestamp info (for regression testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) > > Regards, ...... if you have any more reportlab related queries you can also get free advice on the reportlab mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users -- Robin Becker From robin at reportlab.com Tue Jul 27 07:55:47 2010 From: robin at reportlab.com (Robin Becker) Date: Tue, 27 Jul 2010 12:55:47 +0100 Subject: Checking that 2 pdf are identical (md5 a solution?) In-Reply-To: References: <58d8ce50-35b1-4a0a-8588-ed7c19a7d349@w30g2000yqw.googlegroups.com> Message-ID: <4C4EC943.50600@chamonix.reportlab.co.uk> .......... >> repeatable,identical PDFs with same timestamp info (for regression testing) >> >> I suggest that you edit that file or add >> >> from reportlab import rl_config >> rl_config.invariant = True >> >> to your code. >> >> Peter > > WOW!! You are good! > Your suggested solution works perfectly. > > Given your expertise I will not be able to 'repay' you by helping on > Python problems but if you ever need help with SPSS related problems I > will be pleased to provide the assistance you need. > (I am the author of "SPSS Programming and Data Management" published > by SPSS Inc. (an IBM company)) > > Regards, ...... if you have any more reportlab related queries you can also get free advice on the reportlab mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users -- Robin Becker From kaklis at gmail.com Tue Jul 27 07:58:16 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 04:58:16 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: On Jul 27, 6:30?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 12:17: > > > I receive the following different Xml Messages from a socket: > > ?From a bare socket? TCP? UDP? Or what else? > > > Which is the best way to make a distinction between them so that every > > time my app receives the one or the other, parse them correctly? > > Use an application level protocol? > > Stefan >From a tcp socket using the twisted framework. Application level protocol... Such as? From __peter__ at web.de Tue Jul 27 08:06:34 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 27 Jul 2010 14:06:34 +0200 Subject: Personal archive tool, looking for suggestions on improving the code References: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> Message-ID: mo reina wrote: > On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: >> mo reina wrote: >> > i've written a tool in python where you enter a title, content, then >> > tags, and the entry is then saved in a pickle file. it was mainly >> > designed for copy-paste functionality (you spot a piece of code you >> > like on the net, copy it, and paste it into the program), not really >> > for handwritten content, though it does that with no problem. >> >> > i mainly did it because i'm always scanning through my pdf files, >> > books, or the net for some coding example of solution that i'd already >> > seen before, and it just seemed logical to have something where you >> > could just put the content in, give it a title and tags, and just look >> > it up whenever you needed to. >> >> > i realize there are sites online that handle this ex. >> >http://snippets.dzone.com, but i'm not always online when i code. i also >> > admit that i didn't really look to see if anyone had written a desktop >> > app, the project seemed like a fun thing to do so here i am. >> >> > it wasn't designed with millions of entries in mind, so i just use a >> > pickle file to serialize the data instead of one of the database APIs. >> > the query is also very basic, only title and tags and no ranking based >> > on the query. >> >> > there is an issue that i can't figure out, when you are at the list of >> > entries there's a try, except clause where it tries to catch a valid >> > index (integer). if you enter an inavlid integer, it will ask you to >> > enter a valid one, but it doesn't seem to be able to assign it to the >> > variable. if you enter a valid integer straightaway, there are no >> > problems and the entry will display. >> >> > anyway let me know what you guys think. this is coded for python3. >> > def choices(list_result): >> > '''takes a list of objects and returns the index of the selected >> > object''' >> > os.system('clear') >> > index = 0 >> > for entry in list_result: >> > print('{}. {}'.format(index, entry.title)) >> > index += 1 >> > try: >> > choice = int(input('\nEnter choice: ')) >> > return choice >> > except: >> > pause = input('\nplease enter a valid choice') >> > choices(list_result) >> >> When the exception is triggered you call choices() recursively but >> discard the result. Therefore you get Python's default, None, which is >> not a valid index. Change the last line to >> >> return choices(list_result) >> >> for a minimal fix. However, I suggest that you use a while loop instead >> of the recursion: >> >> def choices(list_result): >> while True: >> os.system('clear') >> for index, entry in enumerate(list_result): >> print('{}. {}'.format(index, entry.title)) >> try: >> choice = int(input('\nEnter choice: ')) >> if 0 <= choice < len(list_result): >> return choice >> except ValueError: >> pass >> input('\nplease enter a valid choice') >> >> I've also added a test for the integer range and replaced the bare except >> with a more specific one. I recommend that you never use bare excepts >> because they can hide unexpected exceptions and lead to nasty bugs. >> >> You should also remove the recursive call of main(). Its only effect is >> that when you enter an invalid choice twice you will have to enter "5" >> twice to really exit your script. >> >> Peter > > hi peter, i noticed the issue you mentioned but don't understand why > they happen. > > for example, when the function is called in the case of an exception, > the variable choice is re-assigned to whatever the next input is, so > why is the default None assigned instead? and what' s the difference > between just calling the function again (the variable list_result > remains unchanged) and using a return statement? If you have a function def f(): return 42 and just call it from another function def g(): f() the result of f() is evaluated but immediately discarded. If you want to use it inside g() you have to assign it to a variable def g(): x = f() y = x * x print y and if you want to use it outside g() you can return it. def g(): return f() For recursion the same rules apply, only with the same function as f and g. Here's a simple example for you to work out the program flow: >>> def r1(n): ... print "entering level", n ... if n == 5: ... print "limit reached" ... print "exiting level", n ... print "returning 42" ... return 42 ... else: ... print "recursing" ... r1(n+1) ... print "exiting level", n ... print "(implicitly) returning None" ... >>> r1(0) entering level 0 recursing entering level 1 recursing entering level 2 recursing entering level 3 recursing entering level 4 recursing entering level 5 limit reached exiting level 5 returning 42 exiting level 4 (implicitly) returning None exiting level 3 (implicitly) returning None exiting level 2 (implicitly) returning None exiting level 1 (implicitly) returning None exiting level 0 (implicitly) returning None Try to change r1() to return the value from the innermost call (i. e. 42) to the outside world. Once you have understood what is going on you should be able to see what's wrong with your program. Peter From stefan_ml at behnel.de Tue Jul 27 08:14:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 14:14:39 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 13:58: > On Jul 27, 6:30 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 12:17: >> >>> I receive the following different Xml Messages from a socket: >> >> From a bare socket? TCP? UDP? Or what else? >> >>> Which is the best way to make a distinction between them so that every >>> time my app receives the one or the other, parse them correctly? >> >> Use an application level protocol? >> >> Stefan > >> From a tcp socket using the twisted framework. >> Application level protocol... Such as? Depends on what you *can* use. Do you control the sending side? Note: giving better details helps others in giving better answers. Stefan From kaklis at gmail.com Tue Jul 27 08:26:11 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 05:26:11 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: On Jul 27, 8:14?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 13:58: > > > > > On Jul 27, 6:30 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 12:17: > > >>> I receive the following different Xml Messages from a socket: > > >> ? From a bare socket? TCP? UDP? Or what else? > > >>> Which is the best way to make a distinction between them so that every > >>> time my app receives the one or the other, parse them correctly? > > >> Use an application level protocol? > > >> Stefan > > >> From a tcp socket using the twisted framework. > >> Application level protocol... Such as? > > Depends on what you *can* use. Do you control the sending side? > > Note: giving better details helps others in giving better answers. > > Stefan Well yes you are right! I can't control the sending side. The app i'm writing just accepts incoming xml messages. Like the ones above. When i receive a message I parse it and print the information. I know how to parse both xml messages. What i want is to distinguish them so that i can trigger the appropriate parsing method. A.K. From stefan_ml at behnel.de Tue Jul 27 08:41:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 14:41:59 +0200 Subject: parsing different xml messages In-Reply-To: References: Message-ID: kaklis at gmail.com, 27.07.2010 14:26: > On Jul 27, 8:14 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 13:58: >> >>> On Jul 27, 6:30 am, Stefan Behnel wrote: >>>> kak... at gmail.com, 27.07.2010 12:17: >> >>>>> I receive the following different Xml Messages from a socket: >> >>>> From a bare socket? TCP? UDP? Or what else? >> >>>>> Which is the best way to make a distinction between them so that every >>>>> time my app receives the one or the other, parse them correctly? >> >>>> Use an application level protocol? >> >>>> From a tcp socket using the twisted framework. >>>> Application level protocol... Such as? >> >> Depends on what you *can* use. Do you control the sending side? >> >> Note: giving better details helps others in giving better answers. > > Well yes you are right! > I can't control the sending side. > The app i'm writing just accepts incoming xml messages. Like the ones > above. > When i receive a message I parse it and print the information. > I know how to parse both xml messages. > What i want is to distinguish them so that i can trigger the > appropriate parsing method. Do they come in concatenated or one per connection? Stefan From kaklis at gmail.com Tue Jul 27 08:43:13 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 05:43:13 -0700 (PDT) Subject: parsing different xml messages References: Message-ID: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> On Jul 27, 8:41?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 14:26: > > > > > On Jul 27, 8:14 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 13:58: > > >>> On Jul 27, 6:30 am, Stefan Behnel wrote: > >>>> kak... at gmail.com, 27.07.2010 12:17: > > >>>>> I receive the following different Xml Messages from a socket: > > >>>> ? ?From a bare socket? TCP? UDP? Or what else? > > >>>>> Which is the best way to make a distinction between them so that every > >>>>> time my app receives the one or the other, parse them correctly? > > >>>> Use an application level protocol? > > >>>> ?From a tcp socket using the twisted framework. > >>>> Application level protocol... Such as? > > >> Depends on what you *can* use. Do you control the sending side? > > >> Note: giving better details helps others in giving better answers. > > > Well yes you are right! > > I can't control the sending side. > > The app i'm writing just accepts incoming xml messages. Like the ones > > above. > > When i receive a message I parse it and print the information. > > I know how to parse both xml messages. > > What i want is to distinguish them so that i can trigger the > > appropriate parsing method. > > Do they come in concatenated or one per connection? > > Stefan one per connection. From fetchinson at googlemail.com Tue Jul 27 08:54:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jul 2010 14:54:42 +0200 Subject: Why is there no platform independent way of clearing a terminal? Message-ID: Hi folks, If I'm only interested in linux and windows I know I can do ################################ import os import platform if platform.system( ) == 'Linux': clear = 'clear' else: clear = 'cls' os.system( clear ) ################################ or something equivalent using os.name and friends, but was wondering why there is no platform independent way (i.e. the platform dependence is taken care of by the python stdlib) of clearing a terminal. Sure, there are many different terminals and many different operating systems but in many areas python managed to hide all these complexities behind a well defined API. Why was clearing a terminal left out? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From stefan_ml at behnel.de Tue Jul 27 09:06:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Jul 2010 15:06:44 +0200 Subject: parsing different xml messages In-Reply-To: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> References: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> Message-ID: kaklis at gmail.com, 27.07.2010 14:43: > On Jul 27, 8:41 am, Stefan Behnel wrote: >> kak... at gmail.com, 27.07.2010 14:26: >> >>> On Jul 27, 8:14 am, Stefan Behnel wrote: >>>> kak... at gmail.com, 27.07.2010 13:58: >> >>>>> On Jul 27, 6:30 am, Stefan Behnel wrote: >>>>>> kak... at gmail.com, 27.07.2010 12:17: >> >>>>>>> I receive the following different Xml Messages from a socket: >> >>>>>> From a bare socket? TCP? UDP? Or what else? >> >>>>>>> Which is the best way to make a distinction between them so that every >>>>>>> time my app receives the one or the other, parse them correctly? >> >>>>>> Use an application level protocol? >> >>>>>> From a tcp socket using the twisted framework. >>>>>> Application level protocol... Such as? >> >>>> Depends on what you *can* use. Do you control the sending side? >> >>>> Note: giving better details helps others in giving better answers. >> >>> Well yes you are right! >>> I can't control the sending side. >>> The app i'm writing just accepts incoming xml messages. Like the ones >>> above. >>> When i receive a message I parse it and print the information. >>> I know how to parse both xml messages. >>> What i want is to distinguish them so that i can trigger the >>> appropriate parsing method. >> >> Do they come in concatenated or one per connection? >> >> Stefan > > one per connection. Ah, ok, then just parse the message using (c)ElementTree and look at the name of the first child below the root node (assuming that both messages were supposed to have the same root node, as you may have wanted to indicate in your original posting). A dict dispatch to a function or method will do just fine. Stefan From kaklis at gmail.com Tue Jul 27 09:10:53 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 27 Jul 2010 06:10:53 -0700 (PDT) Subject: parsing different xml messages References: <039e5daf-3d2f-4963-94ea-eacb49635f42@k10g2000vbd.googlegroups.com> Message-ID: <3fe7d57c-cd8f-45b9-81d4-39dbab88c26b@c16g2000vbp.googlegroups.com> On Jul 27, 9:06?am, Stefan Behnel wrote: > kak... at gmail.com, 27.07.2010 14:43: > > > > > On Jul 27, 8:41 am, Stefan Behnel wrote: > >> kak... at gmail.com, 27.07.2010 14:26: > > >>> On Jul 27, 8:14 am, Stefan Behnel wrote: > >>>> kak... at gmail.com, 27.07.2010 13:58: > > >>>>> On Jul 27, 6:30 am, Stefan Behnel wrote: > >>>>>> kak... at gmail.com, 27.07.2010 12:17: > > >>>>>>> I receive the following different Xml Messages from a socket: > > >>>>>> ? ? From a bare socket? TCP? UDP? Or what else? > > >>>>>>> Which is the best way to make a distinction between them so that every > >>>>>>> time my app receives the one or the other, parse them correctly? > > >>>>>> Use an application level protocol? > > >>>>>> ? From a tcp socket using the twisted framework. > >>>>>> Application level protocol... Such as? > > >>>> Depends on what you *can* use. Do you control the sending side? > > >>>> Note: giving better details helps others in giving better answers. > > >>> Well yes you are right! > >>> I can't control the sending side. > >>> The app i'm writing just accepts incoming xml messages. Like the ones > >>> above. > >>> When i receive a message I parse it and print the information. > >>> I know how to parse both xml messages. > >>> What i want is to distinguish them so that i can trigger the > >>> appropriate parsing method. > > >> Do they come in concatenated or one per connection? > > >> Stefan > > > one per connection. > > Ah, ok, then just parse the message using (c)ElementTree and look at the > name of the first child below the root node (assuming that both messages > were supposed to have the same root node, as you may have wanted to > indicate in your original posting). A dict dispatch to a function or method > will do just fine. > > Stefan ok that's great, thanks Stefan i'll try it. Antonis From davea at ieee.org Tue Jul 27 09:35:22 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 27 Jul 2010 09:35:22 -0400 Subject: newb In-Reply-To: References: Message-ID: <4C4EE09A.8060105@ieee.org> whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers > > Welcome to the forum, Newsgroup: Send Tutor mailing list submissions to tutor at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-request at python.org For an updated Alan Gauld tutorial: the Learn to Program web site http://www.alan-g.me.uk/ The python.org website is a wealth of information, and also contains links to many other python-oriented sites. Before installing python, consider whether you want version 2.x or 3.x. The language changed a bit at 3.x, and while you're learning, you want a tutorial that matches the version you're running. Easiest way to recognize a particular script as being one or the other is if it has a print statement. print is a statement in version 1.x and 2.x, and is a function in version 3. Any recent tutorial will tell you which it's targeting, but since version 3 is only a year or so old, older tutorials or sample code might well not mention it. DaveA From sturlamolden at yahoo.no Tue Jul 27 09:51:21 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 27 Jul 2010 06:51:21 -0700 (PDT) Subject: Accumulate function in python References: <94c7c397-d644-4909-8b4b-709a9728901e@y21g2000pro.googlegroups.com> Message-ID: On 19 Jul, 13:18, dhruvbird wrote: > Hello, > ? I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > ? And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > ? What is the best way (or pythonic way) to get this. At least for large arrays, this is the kind of task where NumPy will help. >>> import numpy as np >>> np.cumsum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]) array([ 0, 1, 3, 4, 5, 5, 5, 7, 10]) From dirknbr at gmail.com Tue Jul 27 10:00:53 2010 From: dirknbr at gmail.com (dirknbr) Date: Tue, 27 Jul 2010 07:00:53 -0700 (PDT) Subject: Urrlib2 IncompleteRead error Message-ID: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> I am running urllib2.request and get this response when I do the read. Any ideas what causes this? return response.read() File "C:\Python26\lib\socket.py", line 329, in read data = self._sock.recv(rbufsize) File "C:\Python26\lib\httplib.py", line 518, in read return self._read_chunked(amt) File "C:\Python26\lib\httplib.py", line 561, in _read_chunked raise IncompleteRead(''.join(value)) IncompleteRead: IncompleteRead(3235 bytes read) Dirk From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 10:02:23 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 16:02:23 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: Message-ID: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Daniel Fetchinson a ?crit : > Hi folks, > > If I'm only interested in linux and windows I know I can do > > ################################ > import os > import platform > > if platform.system( ) == 'Linux': > clear = 'clear' > else: > clear = 'cls' > > os.system( clear ) > ################################ > > or something equivalent using os.name and friends, but was wondering > why there is no platform independent way (i.e. the platform dependence > is taken care of by the python stdlib) of clearing a terminal. Sure, > there are many different terminals and many different operating > systems but in many areas python managed to hide all these > complexities behind a well defined API. > > Why was clearing a terminal left out? > What you're talking about is a shell, not a terminal (a terminal is a physical device). And the shell is not necessarily part of the OS itself (there's no shortage of shells for unices / linux systems), so it doesn't belong to the os or platform modules. FWIW, I can't tell for sure since I never used any other shell than bash, but I'm not sure your above code is garanteed to work on each and any possible unix shell. From gberbeglia at gmail.com Tue Jul 27 10:04:56 2010 From: gberbeglia at gmail.com (gerardob) Date: Tue, 27 Jul 2010 07:04:56 -0700 (PDT) Subject: string manipulation. Message-ID: <29276755.post@talk.nabble.com> I am trying to read an xml using minidom from python library xml.dom This is the xml file: --------------------------------- AB 100 2 ---------------------------------- This is the python code: -------------------------------- from xml.dom import minidom doc= minidom.parse("example.xml") resources_section = doc.getElementsByTagName('resources') list_resources = resources_section[0].getElementsByTagName('resource') for r in list_resources: name = r.childNodes[0].nodeValue print name print len(name) --------------------------------- The problem is that the nodeValue stored in the variable 'name' is not "AB" (what i want) but instead it is a string that has length of 8 and it seems it include the tabs and/or other things. How can i get the string "AB" without the other stuff? Thanks. -- View this message in context: http://old.nabble.com/string-manipulation.-tp29276755p29276755.html Sent from the Python - python-list mailing list archive at Nabble.com. From j.reid at mail.cryst.bbk.ac.uk Tue Jul 27 10:06:52 2010 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 27 Jul 2010 15:06:52 +0100 Subject: Check in interpreter if running a debug version of python Message-ID: Can I check in the interpreter if I am running a debug version of python? I don't mean if __debug__ is set, I want to know if python was compiled in debug mode. Thanks, John. From neilc at norwich.edu Tue Jul 27 10:14:36 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Jul 2010 14:14:36 GMT Subject: string manipulation. References: Message-ID: <8b87ucFtlmU1@mid.individual.net> On 2010-07-27, gerardob wrote: > > I am trying to read an xml using minidom from python library xml.dom > > This is the xml file: > --------------------------------- > > > > AB > 100 > > 2 > > > > > ---------------------------------- > This is the python code: > -------------------------------- > from xml.dom import minidom > doc= minidom.parse("example.xml") > resources_section = doc.getElementsByTagName('resources') > list_resources = resources_section[0].getElementsByTagName('resource') > > for r in list_resources: > name = r.childNodes[0].nodeValue > print name > print len(name) > --------------------------------- > The problem is that the nodeValue stored in the variable 'name' is not "AB" > (what i want) but instead it is a string that has length of 8 and it seems > it include the tabs and/or other things. > How can i get the string "AB" without the other stuff? Check out the strip member function. name = r.childNodes[0].nodeValue.strip() -- Neil Cerutti From lists at cheimes.de Tue Jul 27 10:25:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jul 2010 16:25:44 +0200 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: > Can I check in the interpreter if I am running a debug version of > python? I don't mean if __debug__ is set, I want to know if python was > compiled in debug mode. Python has multiple flavors of debug builds. hasattr(sys, "gettotalrefcount") is only available if Py_REF_DEBUG is enabled. This should be sufficient to detect the most used debug variant. Christian From metolone+gmane at gmail.com Tue Jul 27 10:30:41 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 27 Jul 2010 07:30:41 -0700 Subject: string manipulation. References: <29276755.post@talk.nabble.com> Message-ID: "gerardob" wrote in message news:29276755.post at talk.nabble.com... > > I am trying to read an xml using minidom from python library xml.dom > > This is the xml file: > --------------------------------- > > > > AB > 100 > > 2 > > > > > ---------------------------------- > This is the python code: > -------------------------------- > from xml.dom import minidom > doc= minidom.parse("example.xml") > resources_section = doc.getElementsByTagName('resources') > list_resources = resources_section[0].getElementsByTagName('resource') > > for r in list_resources: > name = r.childNodes[0].nodeValue > print name > print len(name) > --------------------------------- > The problem is that the nodeValue stored in the variable 'name' is not > "AB" > (what i want) but instead it is a string that has length of 8 and it seems > it include the tabs and/or other things. > How can i get the string "AB" without the other stuff? > Thanks. Whitespace in XML is significant. If the file was: AB100 2 You would just read 'AB'. If you don't control the XML file, then: print name.strip() will remove leading and trailing whitespace. -Mark From invalid at invalid.invalid Tue Jul 27 10:32:52 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 27 Jul 2010 14:32:52 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: On 2010-07-27, Bruno Desthuilliers wrote: > Daniel Fetchinson a ?crit : >> Hi folks, >> >> If I'm only interested in linux and windows I know I can do >> >> ################################ >> import os >> import platform >> >> if platform.system( ) == 'Linux': >> clear = 'clear' >> else: >> clear = 'cls' >> >> os.system( clear ) >> ################################ >> >> or something equivalent using os.name and friends, but was wondering >> why there is no platform independent way (i.e. the platform dependence >> is taken care of by the python stdlib) of clearing a terminal. Sure, >> there are many different terminals and many different operating >> systems but in many areas python managed to hide all these >> complexities behind a well defined API. >> >> Why was clearing a terminal left out? >> > > What you're talking about is a shell, not a terminal (a terminal is a > physical device). No, what he's talking about is clearing a terminal (or a terminal emulator). They both work the same, the only difference is whether the terminal software is running on dedicated hardware or on general-purpose hardware. > And the shell is not necessarily part of the OS itself > (there's no shortage of shells for unices / linux systems), so it > doesn't belong to the os or platform modules. True, but clearing a terminal or terminal emulator has nothing to do with the shell. It's done using an in-band control/escape sequence that's indepedent of the shell being used. His example accomplishes this using an executable named 'clear' which knows how to use terminfo/termcap (I forget which one) to send the proper escape sequence to the terminal. > FWIW, I can't tell for sure since I never used any other shell than > bash, but I'm not sure your above code is garanteed to work on each > and any possible unix shell. Again, the shell is irrelevent. -- Grant Edwards grant.b.edwards Yow! Zippy's brain cells at are straining to bridge gmail.com synapses ... From python at bdurham.com Tue Jul 27 10:33:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:33:06 -0400 Subject: Best practice way to open files in Python 2.6+? Message-ID: <1280241186.27454.1386974299@webmail.messagingengine.com> What is the best practice way to open files in Python 2.6+ It looks like there are at least 3 different ways to open files: - built-in open() - io.open() - codecs.open() It seems like io.open() combines the best of the built-in open() and the codecs open(). Am I missing any obvious drawbacks to using io.open() except for backwards compatibility? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Jul 27 10:36:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:36:36 -0400 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? Message-ID: <1280241396.28353.1386974575@webmail.messagingengine.com> Windows: How can I detect whether a Python app/script is running in console/GUI mode? By app I mean a script compiled to an exe via py2exe or similar. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From phil at riverbankcomputing.com Tue Jul 27 10:36:55 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 27 Jul 2010 15:36:55 +0100 Subject: Why is there no platform independent way of clearing a =?UTF-8?Q?terminal=3F?= In-Reply-To: <4c4ee6e8$0$20965$426a74cc@news.free.fr> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: <67f0a4af61f6f83afccff2af8bfc0b94@localhost> On Tue, 27 Jul 2010 16:02:23 +0200, Bruno Desthuilliers wrote: > Daniel Fetchinson a ?crit : >> Hi folks, >> >> If I'm only interested in linux and windows I know I can do >> >> ################################ >> import os >> import platform >> >> if platform.system( ) == 'Linux': >> clear = 'clear' >> else: >> clear = 'cls' >> >> os.system( clear ) >> ################################ >> >> or something equivalent using os.name and friends, but was wondering >> why there is no platform independent way (i.e. the platform dependence >> is taken care of by the python stdlib) of clearing a terminal. Sure, >> there are many different terminals and many different operating >> systems but in many areas python managed to hide all these >> complexities behind a well defined API. >> >> Why was clearing a terminal left out? >> > > What you're talking about is a shell, not a terminal (a terminal is a > physical device). And the shell is not necessarily part of the OS itself > (there's no shortage of shells for unices / linux systems), so it > doesn't belong to the os or platform modules. > > FWIW, I can't tell for sure since I never used any other shell than > bash, but I'm not sure your above code is garanteed to work on each and > any possible unix shell. Sorry, but that is completely wrong - the shell is irrelevant. "clear" is just a normal command line program that queries the termcap/terminfo database (possibly via the curses library) for the terminal specific sequence of characters that will clear the screen. It then writes those characters to stdout. The terminal, or (more usually these days) terminal emulator, then interprets those characters and takes the appropriate action. I'm not sure what the POSIX status of the clear command is, but I'd be surprised if it wasn't present on a UNIX/Linux system of any vintage. Phil From brian.curtin at gmail.com Tue Jul 27 10:42:21 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:42:21 -0500 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: On Tue, Jul 27, 2010 at 09:06, John Reid wrote: > Can I check in the interpreter if I am running a debug version of python? I > don't mean if __debug__ is set, I want to know if python was compiled in > debug mode. > > Thanks, > John. Starting with Python 2.7 and 3.2 you can do this: >>> sysconfig.get_config_var("Py_DEBUG") 1 (returns None if the var doesn't exist) -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Tue Jul 27 10:44:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 27 Jul 2010 16:44:10 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> Message-ID: <4c4ef0b2$0$5752$426a34cc@news.free.fr> Grant Edwards a ?crit : > On 2010-07-27, Bruno Desthuilliers wrote: >> Daniel Fetchinson a ?crit : (snip) >>> Why was clearing a terminal left out? >>> >> What you're talking about is a shell, not a terminal (a terminal is a >> physical device). > > No, what he's talking about is clearing a terminal (or a terminal > emulator). They both work the same, the only difference is whether > the terminal software is running on dedicated hardware or on > general-purpose hardware. (snip) I stand corrected. From urban.yoga.journeys at gmail.com Tue Jul 27 10:48:43 2010 From: urban.yoga.journeys at gmail.com (mo reina) Date: Tue, 27 Jul 2010 07:48:43 -0700 (PDT) Subject: Personal archive tool, looking for suggestions on improving the code References: <73b7b53d-61b4-400d-8653-52b5fd363004@r10g2000vbc.googlegroups.com> Message-ID: <1bb1168b-6db0-49d8-9707-3b72ece5229c@o12g2000vbc.googlegroups.com> On Jul 27, 2:06?pm, Peter Otten <__pete... at web.de> wrote: > mo reina wrote: > > On 27 Lug, 10:23, Peter Otten <__pete... at web.de> wrote: > >> mo reina wrote: > >> > i've written a tool in python where you enter a title, content, then > >> > tags, and the entry is then saved in a pickle file. it was mainly > >> > designed for copy-paste functionality (you spot a piece of code you > >> > like on the net, copy it, and paste it into the program), not really > >> > for handwritten content, though it does that with no problem. > > >> > i mainly did it because i'm always scanning through my pdf files, > >> > books, or the net for some coding example of solution that i'd already > >> > seen before, and it just seemed logical to have something where you > >> > could just put the content in, give it a title and tags, and just look > >> > it up whenever you needed to. > > >> > i realize there are sites online that handle this ex. > >> >http://snippets.dzone.com, but i'm not always online when i code. i also > >> > admit that i didn't really look to see if anyone had written a desktop > >> > app, the project seemed like a fun thing to do so here i am. > > >> > it wasn't designed with millions of entries in mind, so i just use a > >> > pickle file to serialize the data instead of one of the database APIs. > >> > the query is also very basic, only title and tags and no ranking based > >> > on the query. > > >> > there is an issue that i can't figure out, when you are at the list of > >> > entries there's a try, except clause where it tries to catch a valid > >> > index (integer). if you enter an inavlid integer, it will ask you to > >> > enter a valid one, but it doesn't seem to be able to assign it to the > >> > variable. if you enter a valid integer straightaway, there are no > >> > problems and the entry will display. > > >> > anyway let me know what you guys think. this is coded for python3. > >> > def choices(list_result): > >> > '''takes a list of objects and returns the index of the selected > >> > object''' > >> > os.system('clear') > >> > index = 0 > >> > for entry in list_result: > >> > print('{}. {}'.format(index, entry.title)) > >> > index += 1 > >> > try: > >> > choice = int(input('\nEnter choice: ')) > >> > return choice > >> > except: > >> > pause = input('\nplease enter a valid choice') > >> > choices(list_result) > > >> When the exception is triggered you call choices() recursively but > >> discard the result. Therefore you get Python's default, None, which is > >> not a valid index. Change the last line to > > >> return choices(list_result) > > >> for a minimal fix. However, I suggest that you use a while loop instead > >> of the recursion: > > >> def choices(list_result): > >> while True: > >> os.system('clear') > >> for index, entry in enumerate(list_result): > >> print('{}. {}'.format(index, entry.title)) > >> try: > >> choice = int(input('\nEnter choice: ')) > >> if 0 <= choice < len(list_result): > >> return choice > >> except ValueError: > >> pass > >> input('\nplease enter a valid choice') > > >> I've also added a test for the integer range and replaced the bare except > >> with a more specific one. I recommend that you never use bare excepts > >> because they can hide unexpected exceptions and lead to nasty bugs. > > >> You should also remove the recursive call of main(). Its only effect is > >> that when you enter an invalid choice twice you will have to enter "5" > >> twice to really exit your script. > > >> Peter > > > hi peter, i noticed the issue you mentioned but don't understand why > > they happen. > > > for example, when the function is called in the case of an exception, > > the variable choice is re-assigned to whatever the next input is, so > > why is the default None assigned instead? ?and what' s the difference > > between just calling the function again (the variable list_result > > remains unchanged) and using a return statement? > > If you have a function > > def f(): > ? ? return 42 > > and just call it from another function > > def g(): > ? ? f() > > the result of f() is evaluated but immediately discarded. If you want to use > it inside g() you have to assign it to a variable > > def g(): > ? ? x = f() > ? ? y = x * x > ? ? print y > > and if you want to use it outside g() you can return it. > > def g(): > ? ?return f() > > For recursion the same rules apply, only with the same function as f and g. > Here's a simple example for you to work out the program flow: > > >>> def r1(n): > > ... ? ? print "entering level", n > ... ? ? if n == 5: > ... ? ? ? ? ? ? print "limit reached" > ... ? ? ? ? ? ? print "exiting level", n > ... ? ? ? ? ? ? print "returning 42" > ... ? ? ? ? ? ? return 42 > ... ? ? else: > ... ? ? ? ? ? ? print "recursing" > ... ? ? ? ? ? ? r1(n+1) > ... ? ? print "exiting level", n > ... ? ? print "(implicitly) returning None" > ...>>> r1(0) > > entering level 0 > recursing > entering level 1 > recursing > entering level 2 > recursing > entering level 3 > recursing > entering level 4 > recursing > entering level 5 > limit reached > exiting level 5 > returning 42 > exiting level 4 > (implicitly) returning None > exiting level 3 > (implicitly) returning None > exiting level 2 > (implicitly) returning None > exiting level 1 > (implicitly) returning None > exiting level 0 > (implicitly) returning None > > Try to change r1() to return the value from the innermost call (i. e. 42) to > the outside world. Once you have understood what is going on you should be > able to see what's wrong with your program. > > Peter ok i think i understand, the variable from the second function call is returned but not assigned to any variable. since the function was called by another function and not the main function, it returns the variable to the first function instead of the main function. From brian.curtin at gmail.com Tue Jul 27 10:54:08 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:54:08 -0500 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: <1280241186.27454.1386974299@webmail.messagingengine.com> References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:33, wrote: > What is the best practice way to open files in Python 2.6+ > > It looks like there are at least 3 different ways to open files: > - built-in open() > - io.open() > - codecs.open() > > It seems like io.open() combines the best of the built-in open() and the > codecs open(). Am I missing any obvious drawbacks to using io.open() except > for backwards compatibility? > > Thank you, > Malcolm > As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also 3.0, don't know). I don't know your use cases or what you get or don't get from any of those options, but the future is io.open. >>> io.open is open True -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Tue Jul 27 10:57:42 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 27 Jul 2010 16:57:42 +0200 Subject: Best practice way to open files in Python 2.6+? References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: <20100727165742.264f4b7d@pitrou.net> On Tue, 27 Jul 2010 10:33:06 -0400 python at bdurham.com wrote: > What is the best practice way to open files in Python 2.6+ > > It looks like there are at least 3 different ways to open files: > - built-in open() > - io.open() > - codecs.open() > It seems like io.open() combines the best of the built-in open() > and the codecs open(). Am I missing any obvious drawbacks to > using io.open() except for backwards compatibility? io.open() is quite slow in 2.6, although the performance issues are fixed in 2.7 (and in 3.1). io.open() is much stricter in what types it accepts and emits. Files opened in text mode, for example, will return unicode strings when reading and will only accept unicode strings for write(). (similarly, files opened in binary mode will only accept bytestrings for write()) Regards Antoine. From brian.curtin at gmail.com Tue Jul 27 10:58:13 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 09:58:13 -0500 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: <1280241396.28353.1386974575@webmail.messagingengine.com> References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:36, wrote: > Windows: How can I detect whether a Python app/script is running in > console/GUI mode? By app I mean a script compiled to an exe via py2exe or > similar. > > Thank you, > Malcolm > I don't remember much about py2exe, but you could check if ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) or just python.exe (regular console). -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Jul 27 10:59:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 27 Jul 2010 10:59:42 -0400 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: References: <1280241186.27454.1386974299@webmail.messagingengine.com> Message-ID: <1280242782.1710.1386978505@webmail.messagingengine.com> Brian, > As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also 3.0, don't know). I don't know your use cases or > what you get or don't get from any of those options, but the future is io.open. > > >>> io.open is open > True Under Python 2.6.4 (Windows), "io.open is open" returns False. Retrieving help() on io.open and open() reinforces that these are 2 different implementations of open. My use case is reading and writing UTF-8 text files with universal newline support. I believe that the following io.open() parameter list is what I should be using: # mode set to 'rt' (read) or 'wt' (write) io.open( file, mode, encoding='utf-8', errors='ignore', newline=None ) Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Tue Jul 27 11:09:28 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Tue, 27 Jul 2010 10:09:28 -0500 Subject: Best practice way to open files in Python 2.6+? In-Reply-To: <1280242782.1710.1386978505@webmail.messagingengine.com> References: <1280241186.27454.1386974299@webmail.messagingengine.com> <1280242782.1710.1386978505@webmail.messagingengine.com> Message-ID: On Tue, Jul 27, 2010 at 09:59, wrote: > Brian, > > Under Python 2.6.4 (Windows), "io.open is open" returns False. Retrieving > help() on io.open and open() reinforces that these are 2 different > implementations of open. > > My use case is reading and writing UTF-8 text files with universal newline > support. I believe that the following io.open() parameter list is what I > should be using: > > # mode set to 'rt' (read) or 'wt' (write) > io.open( file, mode, encoding='utf-8', errors='ignore', newline=None ) > > Malcolm > Precisely. I was just showing that in 3.x they are the same because one uses the other, and that reason might be enough for you to consider io.open. Your usage of io.open looks fine to me. If it works for you, keep doing it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Tue Jul 27 11:18:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 27 Jul 2010 17:18:44 +0200 Subject: Check in interpreter if running a debug version of python In-Reply-To: References: Message-ID: > Starting with Python 2.7 and 3.2 you can do this: > >>>> sysconfig.get_config_var("Py_DEBUG") > 1 > > (returns None if the var doesn't exist) IIRC sysconfig.get_config_var() still depends on parsing the pyconfig.h file. This won't work on Windows because we are using project and config settings of VisualStudio. From harijay at gmail.com Tue Jul 27 11:22:15 2010 From: harijay at gmail.com (harijay) Date: Tue, 27 Jul 2010 08:22:15 -0700 (PDT) Subject: multicpu bzip2 using os.system or queue using python script Message-ID: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> I want to quickly bzip2 compress several hundred gigabytes of data using my 8 core , 16 GB ram workstation. Currently I am using a simple python script to compress a whole directory tree using bzip2 and a system call coupled to an os.walk call. I see that the bzip2 only uses a single cpu while the other cpus remain relatively idle. I am a newbie in queue and threaded processes . But I am wondering how I can implement this such that I can have four bzip2 running threads (actually I guess os.system threads ), each using probably their own cpu , that deplete files from a queue as they bzip them. Thanks for your suggestions in advance hari My single thread script is pasted here . import os import sys for roots, dirlist , filelist in os.walk(os.curdir): for file in [os.path.join(roots,filegot) for filegot in filelist]: if "bz2" not in file: print "Compressing %s" % (file) os.system("bzip2 %s" % file) print ":DONE" From mail at timgolden.me.uk Tue Jul 27 11:36:20 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 27 Jul 2010 16:36:20 +0100 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: <4C4EFCF4.9000302@timgolden.me.uk> On 27/07/2010 15:58, Brian Curtin wrote: > On Tue, Jul 27, 2010 at 09:36, wrote: > >> Windows: How can I detect whether a Python app/script is running in >> console/GUI mode? By app I mean a script compiled to an exe via py2exe or >> similar. >> >> Thank you, >> Malcolm >> > > I don't remember much about py2exe, but you could check if > ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) > or just python.exe (regular console). Don't know whether it's foolproof, but I suspect that checking whether win32console.GetConsoleWindow () returns zero is probably not a bad approach. TJG From emile at fenx.com Tue Jul 27 11:42:00 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 27 Jul 2010 08:42:00 -0700 Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? In-Reply-To: <1280241396.28353.1386974575@webmail.messagingengine.com> References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: On 7/27/2010 7:36 AM python at bdurham.com said... > Windows: How can I detect whether a Python app/script is running > in console/GUI mode? By app I mean a script compiled to an exe > via py2exe or similar. > Once you've got an exe, you'll need to know the name you're looking for. There are several utilities available -- I use pslist from sysinternals, but there are others out there like process explorer, WMIC or tasklist. You could translate the VB found at http://support.microsoft.com/kb/187913 and use win32. You could program a pid file into your exe and check that. One cheap trick is to create a file and keep it open while your process runs. From the outside, if the file is missing or you can erase the file, you're process isn't active. This relies on windows requiring exclusive access to delete a file which it does, and doesn't rely on the presence of a particular windows version or installation of a third party utility. HTH, Emile From john at castleamber.com Tue Jul 27 11:47:31 2010 From: john at castleamber.com (John Bokma) Date: Tue, 27 Jul 2010 10:47:31 -0500 Subject: Personal archive tool, looking for suggestions on improving the code References: Message-ID: <877hkh9bak.fsf@castleamber.com> mo reina writes: > i mainly did it because i'm always scanning through my pdf files, > books, or the net for some coding example of solution that i'd already > seen before, and it just seemed logical to have something where you > could just put the content in, give it a title and tags, and just look > it up whenever you needed to. Ages ago I wrote something like this in Perl, but now I use a local install of MediaWiki to keep notes, interesting links, code snippets, etc. One of the advantages is that I can reach it from each computer connected to my LAN, even virtual ones. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From nitinpawar432 at gmail.com Tue Jul 27 11:56:41 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 21:26:41 +0530 Subject: Urrlib2 IncompleteRead error In-Reply-To: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: Hi, Check if the webpage you are trying to access is redirecting the page to some other page? or the timeout is too less for the request to finish Thanks, Nitin On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: > I am running urllib2.request and get this response when I do the read. > Any ideas what causes this? > > return response.read() > File "C:\Python26\lib\socket.py", line 329, in read > data = self._sock.recv(rbufsize) > File "C:\Python26\lib\httplib.py", line 518, in read > return self._read_chunked(amt) > File "C:\Python26\lib\httplib.py", line 561, in _read_chunked > raise IncompleteRead(''.join(value)) > IncompleteRead: IncompleteRead(3235 bytes read) > > Dirk > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From TCalhoon at ochca.com Tue Jul 27 12:35:32 2010 From: TCalhoon at ochca.com (Calhoon, Tom) Date: Tue, 27 Jul 2010 09:35:32 -0700 Subject: Orange County, California Python User Group Message-ID: Dan: I am an instructor at Cal State Fullerton, and we are looking for a few industry leaders that would be willing to server on an advisory board for a Python programming class series. If you have a minute to talk or know of someone who is interested, please give me a call. Thanks Tom Calhoon (714) 834-6632 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dirknbr at gmail.com Tue Jul 27 12:39:50 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Tue, 27 Jul 2010 17:39:50 +0100 Subject: Urrlib2 IncompleteRead error In-Reply-To: References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: Thanks, I don't think it's redirecting, how can I increase the timeout? On 27 July 2010 16:56, Nitin Pawar wrote: > Hi, > > Check if the webpage you are trying to access is redirecting the page to > some other page? > or the timeout is too less for the request to finish > > > Thanks, > Nitin > > On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: > >> I am running urllib2.request and get this response when I do the read. >> Any ideas what causes this? >> >> return response.read() >> File "C:\Python26\lib\socket.py", line 329, in read >> data = self._sock.recv(rbufsize) >> File "C:\Python26\lib\httplib.py", line 518, in read >> return self._read_chunked(amt) >> File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >> raise IncompleteRead(''.join(value)) >> IncompleteRead: IncompleteRead(3235 bytes read) >> >> Dirk >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Nitin Pawar > > -- http://twitter.com/dirknbr http://maximum-likely.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Jul 27 12:46:11 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 27 Jul 2010 09:46:11 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4e8a95$0$24098$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> Message-ID: <4C4F0D53.5010107@stoneleaf.us> Bruno Desthuilliers wrote: > Bruno Desthuilliers a ?crit : >> Ethan Furman a ?crit : >>> Bruno Desthuilliers wrote: >>>> Duncan Booth a ?crit : >> (snip) >> >>>>> Or you could create the default as a class attribute >>>> >>>> from the OP: >>>> """ >>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>> it is overloaded in __getattr__, so if someone invokes >>>> "myObject.size", it is generated (as another oofun) and connected to >>>> myObject as attribute. >>>> """ >>>> >>>> so this solution won't obviously work in this case !-) >>>> >>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>> class attribute is of a mutable type. >>> >>> Well, it is Monday, so I may be missing something obvious, but what >>> is the effective difference between these two solutions? >> > > If you meant "what is the difference between creating the "whatever" > attribute with a default value in the initializer and creating it on > demand in the __getattr__ hook", the main difference is that in the > first case, the instance is garanteed to have this attribute, so you get > rid of "hasattr" checks (and the unwanted side effects) or, worse, > direct check of the instance __dict__. Except for a couple of corner > case, client code shouldn't have to worry about this kind of things - > this breaks encapsulation. Yay Tuesday! :D What I meant was what is the difference between: [Bruno Desthuilliers] > DEFAULT_WHATEVER = Whathever() > class MyClass(object): > def __init__(self, x, y): > self.size = DEFAULT_WHATEVER and [Duncan Booth] > class MyClass(object): > size = Whatever() > def __init__(self, x, y): > ... in both cases the object ends up with a size attribute and no further need of __getattr__. Of course, the warning about having a mutable object as a class attribute stands. To phrase it another way, why does your solution (Bruno) work, but Duncan's "obviously won't"? ~Ethan~ From nitinpawar432 at gmail.com Tue Jul 27 12:46:41 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 22:16:41 +0530 Subject: Urrlib2 IncompleteRead error In-Reply-To: References: <4c0a0495-4728-40f9-ba2e-660466129a06@v23g2000vbi.googlegroups.com> Message-ID: import socket # timeout in seconds timeout = 10 socket.setdefaulttimeout(timeout) On Tue, Jul 27, 2010 at 10:09 PM, Dirk Nachbar wrote: > Thanks, I don't think it's redirecting, how can I increase the timeout? > > > On 27 July 2010 16:56, Nitin Pawar wrote: > >> Hi, >> >> Check if the webpage you are trying to access is redirecting the page to >> some other page? >> or the timeout is too less for the request to finish >> >> >> Thanks, >> Nitin >> >> On Tue, Jul 27, 2010 at 7:30 PM, dirknbr wrote: >> >>> I am running urllib2.request and get this response when I do the read. >>> Any ideas what causes this? >>> >>> return response.read() >>> File "C:\Python26\lib\socket.py", line 329, in read >>> data = self._sock.recv(rbufsize) >>> File "C:\Python26\lib\httplib.py", line 518, in read >>> return self._read_chunked(amt) >>> File "C:\Python26\lib\httplib.py", line 561, in _read_chunked >>> raise IncompleteRead(''.join(value)) >>> IncompleteRead: IncompleteRead(3235 bytes read) >>> >>> Dirk >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> >> -- >> Nitin Pawar >> >> > > > -- > http://twitter.com/dirknbr > http://maximum-likely.blogspot.com > > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Jul 27 12:58:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 27 Jul 2010 18:58:14 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <67f0a4af61f6f83afccff2af8bfc0b94@localhost> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: >>> Hi folks, >>> >>> If I'm only interested in linux and windows I know I can do >>> >>> ################################ >>> import os >>> import platform >>> >>> if platform.system( ) == 'Linux': >>> clear = 'clear' >>> else: >>> clear = 'cls' >>> >>> os.system( clear ) >>> ################################ >>> >>> or something equivalent using os.name and friends, but was wondering >>> why there is no platform independent way (i.e. the platform dependence >>> is taken care of by the python stdlib) of clearing a terminal. Sure, >>> there are many different terminals and many different operating >>> systems but in many areas python managed to hide all these >>> complexities behind a well defined API. >>> >>> Why was clearing a terminal left out? >>> >> >> What you're talking about is a shell, not a terminal (a terminal is a >> physical device). And the shell is not necessarily part of the OS itself > >> (there's no shortage of shells for unices / linux systems), so it >> doesn't belong to the os or platform modules. >> >> FWIW, I can't tell for sure since I never used any other shell than >> bash, but I'm not sure your above code is garanteed to work on each and >> any possible unix shell. > > Sorry, but that is completely wrong - the shell is irrelevant. > > "clear" is just a normal command line program that queries the > termcap/terminfo database (possibly via the curses library) for the > terminal specific sequence of characters that will clear the screen. It > then writes those characters to stdout. The terminal, or (more usually > these days) terminal emulator, then interprets those characters and takes > the appropriate action. > > I'm not sure what the POSIX status of the clear command is, but I'd be > surprised if it wasn't present on a UNIX/Linux system of any vintage. After getting the technicalities out of the way, maybe I should have asked: Is it only me or others would find a platform independent python API to clear the terminal useful? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From nagle at animats.com Tue Jul 27 13:02:47 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 10:02:47 -0700 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <4c4ef0b2$0$5752$426a34cc@news.free.fr> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <4c4ef0b2$0$5752$426a34cc@news.free.fr> Message-ID: <4c4f1135$0$1672$742ec2ed@news.sonic.net> On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote: > Grant Edwards a ?crit : >> On 2010-07-27, Bruno Desthuilliers >> wrote: >>> Daniel Fetchinson a ?crit : > (snip) >>>> Why was clearing a terminal left out? >>>> >>> What you're talking about is a shell, not a terminal (a terminal is a >>> physical device). >> >> No, what he's talking about is clearing a terminal (or a terminal >> emulator). They both work the same, the only difference is whether >> the terminal software is running on dedicated hardware or on >> general-purpose hardware. > > (snip) > > I stand corrected. I immediately thought of using the "curses" module, but that's UNIX-only, or at least it's not in the ActiveState Python distro. John Nagle From invalid at invalid.invalid Tue Jul 27 13:13:33 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 27 Jul 2010 17:13:33 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: On 2010-07-27, Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? I write a lot of command-line programs, and I can't remember the last time time I wanted to clear a terminal. But then again, pretty much all of my programs are designed so that they can be used as filters. About 10 years ago I did need to do a text-mode UI (menus, popups, text-entry, etc.), and I used newt. -- Grant Edwards grant.b.edwards Yow! Is a tattoo real, like at a curb or a battleship? gmail.com Or are we suffering in Safeway? From python at mrabarnett.plus.com Tue Jul 27 13:26:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 18:26:54 +0100 Subject: multicpu bzip2 using os.system or queue using python script In-Reply-To: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> References: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> Message-ID: <4C4F16DE.9020700@mrabarnett.plus.com> harijay wrote: > I want to quickly bzip2 compress several hundred gigabytes of data > using my 8 core , 16 GB ram workstation. > Currently I am using a simple python script to compress a whole > directory tree using bzip2 and a system call coupled to an os.walk > call. > > I see that the bzip2 only uses a single cpu while the other cpus > remain relatively idle. > > I am a newbie in queue and threaded processes . But I am wondering how > I can implement this such that I can have four bzip2 running threads > (actually I guess os.system threads ), each using probably their own > cpu , that deplete files from a queue as they bzip them. > > > Thanks for your suggestions in advance > [snip] Try this: import os import sys from threading import Thread, Lock from Queue import Queue def report(message): mutex.acquire() print message sys.stdout.flush() mutex.release() class Compressor(Thread): def __init__(self, in_queue, out_queue): Thread.__init__(self) self.in_queue = in_queue self.out_queue = out_queue def run(self): while True: path = self.in_queue.get() sys.stdout.flush() if path is None: break report("Compressing %s" % path) os.system("bzip2 %s" % path) report("Done %s" % path) self.out_queue.put(path) in_queue = Queue() out_queue = Queue() mutex = Lock() THREAD_COUNT = 4 worker_list = [] for i in range(THREAD_COUNT): worker = Compressor(in_queue, out_queue) worker.start() worker_list.append(worker) for roots, dirlist, filelist in os.walk(os.curdir): for file in [os.path.join(roots, filegot) for filegot in filelist]: if "bz2" not in file: in_queue.put(file) for i in range(THREAD_COUNT): in_queue.put(None) for worker in worker_list: worker.join() From nagle at animats.com Tue Jul 27 13:28:19 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 10:28:19 -0700 Subject: python terminology on classes In-Reply-To: <4c4e8801$0$14554$426a74cc@news.free.fr> References: <4c4e8801$0$14554$426a74cc@news.free.fr> Message-ID: <4c4f1731$0$1602$742ec2ed@news.sonic.net> On 7/27/2010 12:17 AM, Bruno Desthuilliers wrote: >> destructor > > Python has no real destructor. You can implement a __del__ method that > will _eventually_ be called before the instance gets garbage-collected, > but you'd rather not rely on it. Also, implementing this method will > prevent cycle detection. That's not correct. The Python language reference is at "http://docs.python.org/reference/datamodel.html". In CPython, either __del__ will be called when the reference count goes to zero, or it won't be called at all. The garbage collector that backs up the reference counting system doesn't delete objects with __del__ methods, because of the usual problems with deletion from a garbage collector. The defined semantics are that loop-free structures are deleted properly, but loops with one object that has a __del__ hang around forever. You can use weak pointers to avoid loops. IronPython and ShedSkin are garbage-collected implementations which have quite different __del__ semantics. That's considered non-standard. In C++, the RAII approach is popular and recommended. In C++, it's routine to create local objects which, when they go out of scope, close a file, unlock a lock, or close a window. It's also widely used in Python, but it's now somewhat deprecated. Python 2.6 has a recently added "with" clause, borrowed from LISP, for associating actions with scopes. This is supported for files and locks, but setting your own object up for "with" requires adding special methods to the object. "with" is less convenient and more limited than RAII, but that's the direction Python is going. This may be in preparation for a move to a real garbage collector. John Nagle From 4g4trz802 at sneakemail.com Tue Jul 27 13:28:38 2010 From: 4g4trz802 at sneakemail.com (Michael Hoffman) Date: Tue, 27 Jul 2010 10:28:38 -0700 Subject: Updating path.py References: Message-ID: Robert Kern wrote: > On 7/26/10 5:16 PM, Michael Hoffman wrote: >> I have been using Jason Orendorff's path.py module for a long time. It >> is very >> useful. The only problem is that Python 2.6 deprecates the md5 module it >> imports, so I (and others using my software) now get this warning >> whenever they >> start, which is a little annoying. >> >> /homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: >> >> DeprecationWarning: the md5 module is deprecated; use hashlib instead >> >> The original web page is gone, and e-mails to the author have gone >> unanswered. >> It has a "public domain" license so I could easily fork it and make >> this small >> change. The question is what is the best way to do that and ensure >> continuity >> with the previous versions. Can I (or someone else) take over the PyPI >> entry in >> question? Other suggestions? > > You cannot "take over" a project on PyPI. You can only fork the project > with a new name. In fact, this has already been done: > > http://pypi.python.org/pypi/forked-path/0.1 Great, I'll start by trying that, I was hoping someone already had a solution. Thanks. From a.j.romanista at gmail.com Tue Jul 27 13:36:24 2010 From: a.j.romanista at gmail.com (ata.jaf) Date: Tue, 27 Jul 2010 10:36:24 -0700 (PDT) Subject: suitable py2app. Message-ID: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> Hi, I'm looking for a suitable tutorial for "py2app". I googled it but couldn't find anything. Can you help me please? Thanks Ata From nitinpawar432 at gmail.com Tue Jul 27 13:56:00 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Tue, 27 Jul 2010 23:26:00 +0530 Subject: suitable py2app. In-Reply-To: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> References: <744e466d-40c8-4a20-97cc-c8973aa369a9@c38g2000vba.googlegroups.com> Message-ID: see if this helps http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html On Tue, Jul 27, 2010 at 11:06 PM, ata.jaf wrote: > Hi, > I'm looking for a suitable tutorial for "py2app". I googled it but > couldn't find anything. > Can you help me please? > Thanks > Ata > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Jul 27 14:01:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Jul 2010 14:01:00 -0400 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: On 7/27/2010 12:58 PM, Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? One problem is, Where would you put it? The OS module is for system calls, mostly based on posix. The system call involved in clearing a terminal is a write string call. *nix puts terminal control in a separate library. Another is, what next? clear_line? Pretty soon, we are back to curses. Still another problem is that most of us do not have terminals; we have screens and use them as such. OS-independent full-screen graphics/game libraries have clear screen commands. Similary, GUI systems have means of clearing text and canvas widgets, but should not be able to clear the whole screen. The turtle module has a clear command for its canvas, which would be the same regardless of underlying gui. So we already have several OS independent clear commands. On Windows, the DOS clr command only works withing a text-mode command window (once called a dos window). The same thing (os.system('clr') within an IDLE shell uselessly flashes a blank command window, which then disappears. Yeah, it is too bad windows did not use the obvious 'clear' like everyone? else. If command windows still imitate or can be set to imitate ansi terminals, then I would think curses is your best bet. -- Terry Jan Reedy From martin at address-in-sig.invalid Tue Jul 27 14:02:37 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 27 Jul 2010 18:02:37 +0000 (UTC) Subject: pyodbc problem Message-ID: I have a small problem: I can't get pyodbc to connect to a PostgreSQL database. All it does is spit out a malformed error message. When I run this: ============================================== import pyodbc dsn = pyodbc.dataSources() print "Data sources: %s" % dsn conn = pyodbc.connect(dsn="marchive") print "ODBC connection: %s" % conn ============================================== I get this: ============================================== [kiwi at zappa python]$ python dsncheck.py Data sources: {'ma': 'PostgreSQL', 'marchive': 'PostgreSQL'} Traceback (most recent call last): File "dsncheck.py", line 6, in conn = pyodbc.connect(dsn="marchive") pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)') ============================================== so the data source exists and is evidently found by connect(), whiuch seems unable to make sense of it. The pgsql module works well, but I would prefer to use ODBC because its not so closely bound to a single RDBMS. unixODBC, which I understand underlies pyodbc, works OK too: ============================================== [kiwi at zappa python]$ isql marchive marchive n/a +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> select count(*) from address; +---------------------+ | count | +---------------------+ | 32 | +---------------------+ SQLRowCount returns 1 1 rows fetched SQL> quit ============================================== Questions: - Why does pyodbc blow up when its apparently trying to talk to unixODBC? - What does this mean: pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)') I'm new to Python, though not to Linux, PostgreSQL, ODBC, C or Java. My rig and software: Linux: Fedora 12 Where I'm running Python and ODBC, Lenovo Thinkpad R61i: Core Duo. Fedora 10 Where PostgreSQL is installed, IBM NetVista: Pentium III. PostgreSQL: 8.3.8 Python: 2.6.2 pyodbc 2.1.5-3.fc12 ) By yum from RH repository unixODBC 2.2.14-11.fc12 ) -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From harijay at gmail.com Tue Jul 27 14:10:34 2010 From: harijay at gmail.com (harijay) Date: Tue, 27 Jul 2010 11:10:34 -0700 (PDT) Subject: multicpu bzip2 using os.system or queue using python script References: <6d8a9b63-3bf0-4368-a3ad-ef0baeb7200e@k10g2000vbd.googlegroups.com> Message-ID: <11ca89e7-5210-4676-b042-e645d5824092@t1g2000vbd.googlegroups.com> Thanks a tonne..That code works perfectly and also shows me how to think of using queue and threads in my python programs Hari On Jul 27, 1:26?pm, MRAB wrote: > harijay wrote: > > I want to quickly bzip2 compress several hundred gigabytes of data > > using my 8 core , 16 GB ram workstation. > > Currently I am using a simple python script to compress a whole > > directory tree using bzip2 and a system call coupled to an os.walk > > call. > > > I see that the bzip2 only uses a single cpu while the other cpus > > remain relatively idle. > > > I am a newbie in queue and threaded processes . But I am wondering how > > I can implement this such that I can have four bzip2 running threads > > (actually I guess os.system threads ), each using probably their own > > cpu , that deplete files from a queue as they bzip them. > > > Thanks for your suggestions in advance > > [snip] > Try this: > > import os > import sys > from threading import Thread, Lock > from Queue import Queue > > def report(message): > ? ? ?mutex.acquire() > ? ? ?print message > ? ? ?sys.stdout.flush() > ? ? ?mutex.release() > > class Compressor(Thread): > ? ? ?def __init__(self, in_queue, out_queue): > ? ? ? ? ?Thread.__init__(self) > ? ? ? ? ?self.in_queue = in_queue > ? ? ? ? ?self.out_queue = out_queue > ? ? ?def run(self): > ? ? ? ? ?while True: > ? ? ? ? ? ? ?path = self.in_queue.get() > ? ? ? ? ? ? ?sys.stdout.flush() > ? ? ? ? ? ? ?if path is None: > ? ? ? ? ? ? ? ? ?break > ? ? ? ? ? ? ?report("Compressing %s" % path) > ? ? ? ? ? ? ?os.system("bzip2 %s" % path) > ? ? ? ? ? ? ?report("Done %s" % ?path) > ? ? ? ? ? ? ?self.out_queue.put(path) > > in_queue = Queue() > out_queue = Queue() > mutex = Lock() > > THREAD_COUNT = 4 > > worker_list = [] > for i in range(THREAD_COUNT): > ? ? ?worker = Compressor(in_queue, out_queue) > ? ? ?worker.start() > ? ? ?worker_list.append(worker) > > for roots, dirlist, filelist in os.walk(os.curdir): > ? ? ?for file in [os.path.join(roots, filegot) for filegot in filelist]: > ? ? ? ? ?if "bz2" not in file: > ? ? ? ? ? ? ?in_queue.put(file) > > for i in range(THREAD_COUNT): > ? ? ?in_queue.put(None) > > for worker in worker_list: > ? ? ?worker.join() From kevinar18 at hotmail.com Tue Jul 27 14:24:07 2010 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Tue, 27 Jul 2010 14:24:07 -0400 Subject: Which multiprocessing methods use shared memory? Message-ID: The multiprocessing module has 4 methods for sharing data between processes: Queues Pipes Shared Memory Map Server Process Which of these use shared memory? I understand that the 3rd (Shared Memory Map) does, but what about Queues? Thanks, Kevin _________________________________________________________________ The New Busy is not the old busy. Search, chat and e-mail from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3 From nagle at animats.com Tue Jul 27 14:40:16 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 11:40:16 -0700 Subject: Why are String Formatted Queries Considered So Magical? (Spammer analysis) In-Reply-To: <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> Message-ID: <4c4f280e$0$1612$742ec2ed@news.sonic.net> On 7/26/2010 4:19 PM, Justin Smith wrote: > Seeking industry expert candidates > > I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I > am currently seeking candidates to fill Tech Positions for multiple A- > List Clients: Spammer detected. Injection-Info: r27g2000yqb.googlegroups.com; posting-host=63.170.35.94; posting-account=XlBkJgkAAAC7JNUw8ZEYCvz12vv6mGCK Reverse DNS: "franchisevpn.expresspersonnel.com" Site analysis: Domain "www.expresspersonnel.com" redirected to different domain "www.expresspros.com" Site analysis: From Secure certificate (Secure certificate, high confidence) Express Personnel Services, Inc. Oklahoma City, OK UNITED STATES Oklahoma corporation search: EXPRESS SERVICES, INC. Filing Number: 2400436307 Name Type: Legal Name Status: In Existence Corp type: Foreign For Profit Business Corporation Jurisdiction: COLORADO Formation Date: 28 Aug 1985 Colorado corporation search: ID: 19871524232 Name: EXPRESS SERVICES, INC. Principal Street Address: 8516 NW Expressway, Oklahoma City, OK 73162, United States Target coordinates: 35.56973,-97.668001 Corporate class: Franchiser From kevinar18 at hotmail.com Tue Jul 27 15:12:02 2010 From: kevinar18 at hotmail.com (Kevin Ar18) Date: Tue, 27 Jul 2010 15:12:02 -0400 Subject: Which multiprocessing methods use shared memory? Message-ID: I'm not sure my previous message went through (I wasn't subscribe), so I'm gonna try again. The multiprocessing module has 4 methods for sharing data between processes: Queues Pipes Shared Memory Map Server Process Which of these use shared memory? I understand that the 3rd (Shared Memory Map) does, but what about Queues? Thanks, Kevin _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 From python at mrabarnett.plus.com Tue Jul 27 15:30:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 20:30:12 +0100 Subject: Which multiprocessing methods use shared memory? In-Reply-To: References: Message-ID: <4C4F33C4.8000007@mrabarnett.plus.com> Kevin Ar18 wrote: > I'm not sure my previous message went through (I wasn't subscribe), so I'm gonna try again. > > The multiprocessing module has 4 methods for sharing data between processes: > Queues > Pipes > Shared Memory Map > Server Process > > Which of these use shared memory? > > I understand that the 3rd (Shared Memory Map) does, but what about Queues? > The documentation says: """class multiprocessing.Queue([maxsize]) Returns a process shared queue implemented using a pipe and a few locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe.""" From jyoung79 at kc.rr.com Tue Jul 27 16:45:32 2010 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Tue, 27 Jul 2010 20:45:32 +0000 Subject: tkinter unicode question Message-ID: <20100727204532.R7GMZ.27213.root@cdptpa-web20-z02> Just curious if anyone could shed some light on this? I'm using tkinter, but I can't seem to get certain unicode characters to show in the label for Python 3. In my test, the label and button will contain the same 3 characters - a Greek Alpha, a Greek Omega with a circumflex and soft breathing accent, and then a Greek Alpha with a soft breathing accent. For Python 2.6, this works great: # -*- coding: utf-8 -*- from Tkinter import * root = Tk() Label(root, text=u'\u03B1 \u1F66 \u1F00').pack() Button(root, text=u'\u03B1 \u1F66 \u1F00').pack() root.mainloop() However, for Python 3.1.2, the button gets the correct characters, but the label only displays the first Greek Alpha character. The other 2 characters look like Chinese characters followed by an empty box. Here's the code for Python 3: # -*- coding: utf-8 -*- from tkinter import * root = Tk() Label(root, text='\u03B1 \u1F66 \u1F00').pack() Button(root, text='\u03B1 \u1F66 \u1F00').pack() root.mainloop() I've done some research and am wondering if it is because Python 2.6 comes with tk version 8.5, while Python 3.1.2 comes with tk version 8.4? I'm running this on OS X 10.6.4. Here's a link I found that mentions this same problem: http://www.mofeel.net/871-comp-lang-python/5879.aspx If I need to upgrade tk to 8.5, is it best to upgrade it or just install 'tiles'? From my readings it looks like upgrading to 8.5 can be a pain due to OS X still pointing back to 8.4. I haven't tried it yet in case someone might have an easier solution. Thanks for looking at my question. Jay From john at castleamber.com Tue Jul 27 16:52:05 2010 From: john at castleamber.com (John Bokma) Date: Tue, 27 Jul 2010 15:52:05 -0500 Subject: Why are String Formatted Queries Considered So Magical? (Spammer analysis) References: <14e44c9c-04d9-452d-b544-498adfaf7d40@d8g2000yqf.googlegroups.com> <4c2ba96e$0$28647$c3e8da3@news.astraweb.com> <4C2C416D.4010507@ixokai.io> <4C2C67EC.5070905@sequans.com> <4036da8f-6290-4adf-985c-912b6eae50e9@r27g2000yqb.googlegroups.com> <4c4f280e$0$1612$742ec2ed@news.sonic.net> Message-ID: <87iq40bqbu.fsf@castleamber.com> John Nagle writes: > On 7/26/2010 4:19 PM, Justin Smith wrote: >> Seeking industry expert candidates >> >> I?m Justin Smith, Director of Tech Recruiting at Express Seattle. I >> am currently seeking candidates to fill Tech Positions for multiple A- >> List Clients: > > Spammer detected. But did you report it? (If so, it helps if you state so). > Injection-Info: r27g2000yqb.googlegroups.com; > posting-host=63.170.35.94; http://www.spamcop.net/sc?track=63.170.35.94 -> looks like abuse goes to the spammer... A whois gives sprint.net, so you could contact abuse at sprint.net (see: http://whois.domaintools.com/63.170.35.94 ) [snip address etc.] Spammers don't care about that. Best course of action, based on my experience, is to contact abuse at googlegroups.com (now and then it actually works), and sprint.net. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mrjean1 at gmail.com Tue Jul 27 17:01:39 2010 From: mrjean1 at gmail.com (MrJean1) Date: Tue, 27 Jul 2010 14:01:39 -0700 (PDT) Subject: Windows: How to detect whether a Python app/script is running in console/GUI mode? References: <1280241396.28353.1386974575@webmail.messagingengine.com> Message-ID: <4786847f-6834-4fb8-8aff-10656c442994@y32g2000prc.googlegroups.com> On Jul 27, 8:36?am, Tim Golden wrote: > On 27/07/2010 15:58, Brian Curtin wrote: > > > On Tue, Jul 27, 2010 at 09:36, ?wrote: > > >> Windows: How can I detect whether a Python app/script is running in > >> console/GUI mode? By app I mean a script compiled to an exe via py2exe or > >> similar. > > >> Thank you, > >> Malcolm > > > I don't remember much about py2exe, but you could check if > > ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs) > > or just python.exe (regular console). > > Don't know whether it's foolproof, but I suspect that > checking whether win32console.GetConsoleWindow () > returns zero is probably not a bad approach. > > TJG ? ? Executables built with py2exe have an attribute sys.frozen and its value is 'console_exe' for console applications or 'windows_exe' for GUI applications. See for example . /Jean From usernet at ilthio.net Tue Jul 27 17:12:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 27 Jul 2010 21:12:50 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <4c4ef0b2$0$5752$426a34cc@news.free.fr> <4c4f1135$0$1672$742ec2ed@news.sonic.net> Message-ID: On 2010-07-27, John Nagle wrote: > On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote: >> Grant Edwards a ?crit : >>> On 2010-07-27, Bruno Desthuilliers >>> wrote: >>>> Daniel Fetchinson a ?crit : >> (snip) >>>>> Why was clearing a terminal left out? >>>>> >>>> What you're talking about is a shell, not a terminal (a terminal is a >>>> physical device). >>> >>> No, what he's talking about is clearing a terminal (or a terminal >>> emulator). They both work the same, the only difference is whether >>> the terminal software is running on dedicated hardware or on >>> general-purpose hardware. >> >> (snip) >> >> I stand corrected. > > I immediately thought of using the "curses" module, but that's > UNIX-only, or at least it's not in the ActiveState Python distro. pdcurses: http://pdcurses.sourceforge.net/ is a cross platform curses implementation that is available for Windows. I wonder how difficult it would be to embed into the Python curses module as a backup for systems where curses is not natively available. This would allow Python to provide cross platform charactor mode manipulation. From nad at acm.org Tue Jul 27 17:24:16 2010 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jul 2010 14:24:16 -0700 Subject: tkinter unicode question References: <20100727204532.R7GMZ.27213.root@cdptpa-web20-z02> Message-ID: In article <20100727204532.R7GMZ.27213.root at cdptpa-web20-z02>, wrote: > Just curious if anyone could shed some light on this? I'm using > tkinter, but I can't seem to get certain unicode characters to > show in the label for Python 3. > > In my test, the label and button will contain the same 3 > characters - a Greek Alpha, a Greek Omega with a circumflex and > soft breathing accent, and then a Greek Alpha with a soft > breathing accent. > > For Python 2.6, this works great: > > # -*- coding: utf-8 -*- > from Tkinter import * > root = Tk() > Label(root, text=u'\u03B1 \u1F66 \u1F00').pack() > Button(root, text=u'\u03B1 \u1F66 \u1F00').pack() > root.mainloop() > > However, for Python 3.1.2, the button gets the correct characters, > but the label only displays the first Greek Alpha character. > The other 2 characters look like Chinese characters followed by > an empty box. Here's the code for Python 3: > > # -*- coding: utf-8 -*- > from tkinter import * > root = Tk() > Label(root, text='\u03B1 \u1F66 \u1F00').pack() > Button(root, text='\u03B1 \u1F66 \u1F00').pack() > root.mainloop() > > I've done some research and am wondering if it is > because Python 2.6 comes with tk version 8.5, while Python 3.1.2 > comes with tk version 8.4? I'm running this on OS X 10.6.4. Most likely. Apparently you're using the Apple-supplied Python 2.6 which, as you say, uses Tk 8.5. If you had installed the python.org 2.6, it would likely fail for you in the same way as 3.1, since both use Tk 8.4. (They both fail for me.) > If I need to upgrade tk to 8.5, is it best to upgrade it or just > install 'tiles'? From my readings it looks like upgrading to > 8.5 can be a pain due to OS X still pointing back to 8.4. I > haven't tried it yet in case someone might have an easier > solution. OS X 10.6 comes with both Tk 8.4 and 8.5. The problem is that the Python Tkinter(2.6) or tkinter(3.1) is linked at build time, not install time, to one or the other. You would need to at least rebuild and relink tkinter for 3.1 to use Tk 8.5, which means downloading and building Python from source. New releases of python.org installers are now coming in two varieties: the second will be only for 10.6 or later and will link with Tk 8.5. The next new release of Python 3 is likely months away, though. In the meantime, a simpler solution might be to download and install the ActiveState Python 3.1 for OS X which does use Tk 8.5. And your test case works for me with it. -- Ned Deily, nad at acm.org From krdean at gmail.com Tue Jul 27 17:36:59 2010 From: krdean at gmail.com (kBob) Date: Tue, 27 Jul 2010 14:36:59 -0700 (PDT) Subject: urllib timeout Message-ID: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> I created a script to access weather satellite imagery fron NOAA's ADDS. It worked fine until recently with Python 2.6. The company changed the Internet LAN connections to "Accept Automatic settings" and "Use automatic configuration script" How do you get urllib.urlopen to use the the "automatic script" configuration? This code worked recently, until the company implemented these LAN connections... SAT_URL = "http://adds.aviationweather.gov/data/satellite/ latest_BWI_vis.jpg" satpic = urllib.urlopen(SAT_URL, proxies=0 ) satimg = satpic.read() Kelly Dean Fort Collins, CO From philip at semanchuk.com Tue Jul 27 17:44:32 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 27 Jul 2010 17:44:32 -0400 Subject: Binary compatibility across Python versions? In-Reply-To: References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> Message-ID: <0A4C9B21-6EFF-461A-B15C-415D1408DD88@semanchuk.com> On Jul 26, 2010, at 5:19 PM, Ned Deily wrote: > In article , > Christian Heimes wrote: >> [Philip Semanchuk wrote:] >>> Specifically, I'm concerned with binaries created by SWIG for a C++ >>> library that our project uses. We'd like to ship precompiled >>> binaries >>> for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping >>> that it >>> is sufficient to create binaries for each Python for each platform >>> (3 >>> * 2 == 6 total precompiled binaries). >> For each platforms you have to provide binaries for the major CPU >> architectures (X86 and X64_86), too. Users or distributions may >> compile >> Python with UCS-2 or UCS-4 unicode width. That makes eight different >> binaries for Linux (two version * two archs * UCS2/4). Although most >> distributions follow the LSB standards, binaries aren't necessary ABI >> compatible. C++ binaries tend to break more often than C binaries. > > And, on OS X, there are various Python binary distributions in common > use: the Apple-supplied Pythons (2.5 for OS X 10.5, 2.6 & 2.5 for > 10.6), > the python.org OS X installers for 10.5 and 10.6, plus the ActiveState > and EPD ones. It would likely be difficult to ship one binary > extension > that would easily work, if at all, with the most common ones. For > instance, the Apple-supplied Python 2.6 is built with gcc 4.2, uses > the > 10.6 ABI (SDK deployment target), and x86_64 / i386 / ppc > architectures > (default 64-bit on capable machines). The python.org 2.6 uses gcc > 4.0, > the 10.4u ABI, and is 32-bit only (i386 / ppc) Thanks to all who replied on this topic. A little more background -- these binaries are just a convenience for our users and we don't have to cover every possible permutation of Python, only the ones we think will be most common in our user base. That said, thanks to the things you pointed out, I'm beginning to think that our users might be such a varied group that precompiled binaries might not be worth the trouble. Ned, I'm on Mac and I was under the impression that the deployment target compiler option would control how the resulting binary (in this case, Python) called OS X but it wouldn't have any affect on how other code (like our library) called Python. Is that not the case? Thanks Philip From lie.1296 at gmail.com Tue Jul 27 18:13:14 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 28 Jul 2010 05:13:14 +0700 Subject: newb In-Reply-To: References: Message-ID: On Tue, 27 Jul 2010 11:07:09 GMT, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. Yes, Python Tutor list is specifically aimed for beginners. You can access it by subscribing to either tutor at python.org or gmane.comp.python.tutor > would still be valid? Mostly yes. However I'd recommend getting a more updated book especially if you're a beginner. From python at mrabarnett.plus.com Tue Jul 27 18:23:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 23:23:25 +0100 Subject: urllib timeout In-Reply-To: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <4C4F5C5D.3020007@mrabarnett.plus.com> kBob wrote: > > I created a script to access weather satellite imagery fron NOAA's > ADDS. > > It worked fine until recently with Python 2.6. > > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" > > How do you get urllib.urlopen to use the the "automatic script" > configuration? > > This code worked recently, until the company implemented these LAN > connections... > > SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > latest_BWI_vis.jpg" > satpic = urllib.urlopen(SAT_URL, proxies=0 ) > satimg = satpic.read() > For the record, I got: >>> import urllib >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\urllib.py", line 79, in urlopen opener = FancyURLopener(proxies=proxies) File "C:\Python26\lib\urllib.py", line 617, in __init__ URLopener.__init__(self, *args, **kwargs) File "C:\Python26\lib\urllib.py", line 129, in __init__ assert hasattr(proxies, 'has_key'), "proxies must be a mapping" AssertionError: proxies must be a mapping However, urllib.urlretrieve(...) works. From nad at acm.org Tue Jul 27 18:25:54 2010 From: nad at acm.org (Ned Deily) Date: Tue, 27 Jul 2010 15:25:54 -0700 Subject: Binary compatibility across Python versions? References: <3CEC8DB9-234A-4A64-A96A-408E2908E5CD@semanchuk.com> <0A4C9B21-6EFF-461A-B15C-415D1408DD88@semanchuk.com> Message-ID: In article <0A4C9B21-6EFF-461A-B15C-415D1408DD88 at semanchuk.com>, Philip Semanchuk wrote: [...] > Thanks to all who replied on this topic. A little more background -- > these binaries are just a convenience for our users and we don't have > to cover every possible permutation of Python, only the ones we think > will be most common in our user base. That said, thanks to the things > you pointed out, I'm beginning to think that our users might be such a > varied group that precompiled binaries might not be worth the trouble. > > Ned, I'm on Mac and I was under the impression that the deployment > target compiler option would control how the resulting binary (in this > case, Python) called OS X but it wouldn't have any affect on how other > code (like our library) called Python. Is that not the case? Even if your extension modules and libraries don't make a lot of system calls, I think it's a bit of a crap shoot since there are no guarantees of compatibility among the various popular distributions and there are the gcc-4.0 vs -4.2 and the arch differences. You'd have to try the various combinations and/or limit the configurations you support. The bottom line is that many (most?) package developers have given up on trying to supply binary distributions for OS X. Since Apple supplies the necessary developer tools for free with recent OS X releases and in most cases Distutils does the right thing, the burden on end users isn't particularly onerous (see, for example, http://appscript.sourceforge.net/py-appscript/install.html). Now, adding SWIG and C++ to the mix may result in a different answer. I don't have any practical experience with them to have an opnion. Good luck! -- Ned Deily, nad at acm.org From krdean at gmail.com Tue Jul 27 18:43:44 2010 From: krdean at gmail.com (kBob) Date: Tue, 27 Jul 2010 15:43:44 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> On Jul 27, 4:23?pm, MRAB wrote: > kBob wrote: > > > ?I created a script to access weather satellite imagery fron NOAA's > > ADDS. > > > ?It worked fine until recently with Python 2.6. > > > ?The company changed the Internet LAN connections to "Accept Automatic > > settings" and "Use automatic configuration script" > > > ?How do you get urllib.urlopen to use the the "automatic script" > > configuration? > > > ?This code worked recently, until the company implemented these LAN > > connections... > > > ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > latest_BWI_vis.jpg" > > ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > ? ? satimg = satpic.read() > > For the record, I got: > > ?>>> import urllib > ?>>> SAT_URL = > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > ? ? ?opener = FancyURLopener(proxies=proxies) > ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > ? ? ?URLopener.__init__(self, *args, **kwargs) > ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > AssertionError: proxies must be a mapping > > However, urllib.urlretrieve(...) works.- Hide quoted text - > > - Show quoted text - I saw that, but I still get the same error time out error ... >>> import urllib >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" >>> SAT_FILE = "latest_BWI_vis.jpg" >>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) Traceback (most recent call last): File "", line 1, in File "c:\python26\lib\urllib.py", line 93, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "c:\python26\lib\urllib.py", line 237, in retrieve fp = self.open(url, data) File "c:\python26\lib\urllib.py", line 205, in open return getattr(self, name)(url) File "c:\python26\lib\urllib.py", line 344, in open_http h.endheaders() File "c:\python26\lib\httplib.py", line 904, in endheaders self._send_output() File "c:\python26\lib\httplib.py", line 776, in _send_output self.send(msg) File "c:\python26\lib\httplib.py", line 735, in send self.connect() File "c:\python26\lib\httplib.py", line 716, in connect self.timeout) File "c:\python26\lib\socket.py", line 514, in create_connection raise error, msg IOError: [Errno socket error] [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or establis hed connection failed because connected host has failed to respond Kelly From python at mrabarnett.plus.com Tue Jul 27 18:56:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 27 Jul 2010 23:56:01 +0100 Subject: urllib timeout In-Reply-To: <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> Message-ID: <4C4F6401.9090209@mrabarnett.plus.com> kBob wrote: > On Jul 27, 4:23 pm, MRAB wrote: >> kBob wrote: >> >>> I created a script to access weather satellite imagery fron NOAA's >>> ADDS. >>> It worked fine until recently with Python 2.6. >>> The company changed the Internet LAN connections to "Accept Automatic >>> settings" and "Use automatic configuration script" >>> How do you get urllib.urlopen to use the the "automatic script" >>> configuration? >>> This code worked recently, until the company implemented these LAN >>> connections... >>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/ >>> latest_BWI_vis.jpg" >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) >>> satimg = satpic.read() >> For the record, I got: >> >> >>> import urllib >> >>> SAT_URL = >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" >> >>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Python26\lib\urllib.py", line 79, in urlopen >> opener = FancyURLopener(proxies=proxies) >> File "C:\Python26\lib\urllib.py", line 617, in __init__ >> URLopener.__init__(self, *args, **kwargs) >> File "C:\Python26\lib\urllib.py", line 129, in __init__ >> assert hasattr(proxies, 'has_key'), "proxies must be a mapping" >> AssertionError: proxies must be a mapping >> >> However, urllib.urlretrieve(...) works.- Hide quoted text - >> >> - Show quoted text - > > I saw that, but I still get the same error time out error ... > >>>> import urllib >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" >>>> SAT_FILE = "latest_BWI_vis.jpg" >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > Traceback (most recent call last): > File "", line 1, in > File "c:\python26\lib\urllib.py", line 93, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "c:\python26\lib\urllib.py", line 237, in retrieve > fp = self.open(url, data) > File "c:\python26\lib\urllib.py", line 205, in open > return getattr(self, name)(url) > File "c:\python26\lib\urllib.py", line 344, in open_http > h.endheaders() > File "c:\python26\lib\httplib.py", line 904, in endheaders > self._send_output() > File "c:\python26\lib\httplib.py", line 776, in _send_output > self.send(msg) > File "c:\python26\lib\httplib.py", line 735, in send > self.connect() > File "c:\python26\lib\httplib.py", line 716, in connect > self.timeout) > File "c:\python26\lib\socket.py", line 514, in create_connection > raise error, msg > IOError: [Errno socket error] [Errno 10060] A connection attempt > failed because > the connected party did not properly respond after a period of time, > or establis > hed connection failed because connected host has failed to respond > It should be like this: SAT_URL = "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" SAT_FILE = r"C:\latest_BWI_vis.jpg" urllib.urlretrieve(SAT_URL, SAT_FILE) From tim_grove at sil.org Tue Jul 27 19:12:23 2010 From: tim_grove at sil.org (Timothy W. Grove) Date: Wed, 28 Jul 2010 00:12:23 +0100 Subject: subprocess module under python 2.7 Message-ID: <4C4F67D7.5090905@sil.org> I am using the following code to hide the console window when launching a subprocess under Windows. startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE self.mplayer = Popen(args, bufsize=0, #unbufferred stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False, universal_newlines=True, startupinfo=startupinfo ) This worked okay in using the subprocess module under python 2.6, but under python 2.7 I get the error: Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyo", line 530, in __bootstrap_inner File "gui\mplayer_ctrl.pyo", line 93, in run AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW' Anything changed between python versions to account for this? Best regards, Tim From clp2 at rebertia.com Tue Jul 27 19:36:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 27 Jul 2010 16:36:02 -0700 Subject: subprocess module under python 2.7 In-Reply-To: <4C4F67D7.5090905@sil.org> References: <4C4F67D7.5090905@sil.org> Message-ID: On Tue, Jul 27, 2010 at 4:12 PM, Timothy W. Grove wrote: > I am using the following code to hide the console window when launching a > subprocess under Windows. > > ? ? ? startupinfo = subprocess.STARTUPINFO() > ? ? ? startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW > ? ? ? startupinfo.wShowWindow = subprocess.SW_HIDE > > ? ? ? self.mplayer = Popen(args, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?bufsize=0, #unbufferred > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stdin=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stdout=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?stderr=PIPE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?close_fds=False, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?universal_newlines=True, > ? ? ? ? ? ? ? ? ? ? ? ? ? ?startupinfo=startupinfo > ? ? ? ? ? ? ? ? ? ? ? ? ? ?) > > This worked okay in using the subprocess module under python 2.6, but under > python 2.7 I get the error: > > Exception in thread Thread-1: > Traceback (most recent call last): > ?File "threading.pyo", line 530, in __bootstrap_inner > ?File "gui\mplayer_ctrl.pyo", line 93, in run > AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW' > > Anything changed between python versions to account for this? Yes, apparently the code importing that stuff got removed: http://svn.python.org/view/python/tags/r27/Lib/subprocess.py?r1=79064&r2=82504 FWIW, STARTUPINFO(), STARTF_USESHOWWINDOW, and SW_HIDE were/are undocumented in both Python versions and thus shouldn't be relied upon. They can be accessed via Python's win32-specific modules instead (see diff). Cheers, Chris -- http://blog.rebertia.com From thomas at jollans.com Tue Jul 27 19:41:20 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 01:41:20 +0200 Subject: Are those features still the same? In-Reply-To: References: Message-ID: <4C4F6EA0.7000505@jollans.com> On 07/25/2010 11:02 AM, francogrex wrote: > Terry Reedy wrote: >> As other have said, mostly, but I would change the following... > > Thanks for all those who replied. I know these are not all the features but > some of them and again this is not a comparison but a little taste of what > python offers today, and the replies were very informative. By the way Peter > Norvig is not biased, he works for Google research and is a supporter of > programming in any language, especially in Python. > Had I known the table was headed with "Python for Lisp programmers", I would have responded differently - but you chose to hide that ;-) From memilanuk at gmail.com Tue Jul 27 20:33:10 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Tue, 27 Jul 2010 17:33:10 -0700 Subject: newb In-Reply-To: References: Message-ID: On 7/27/10 4:07 AM, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers Alan Gauld posts fairly regularly over on the python-tutor mailing list, as well as here. He has newer material on his website @ http://www.alan-g.me.uk/, and if you google 'python tutorial' you'll probably find more material than you can shake a stick at - from web pages to books (both online and dead-tree) to You-Tube videos. One book that helps me out quite a bit is John Zelle's "Python Programming: An Introduction to Computer Science". Just be aware there is a first edition (covers python 2.x) and a newer second edition (python 3.x) - both available from Amazon. From mithrandiragainwiki at mailinator.com Tue Jul 27 22:19:59 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Tue, 27 Jul 2010 19:19:59 -0700 Subject: newb References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/27/2010 04:07 AM, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. presuming that the > commands and info would still be valid? any websites or books that are a > must for beginners? any input would be much appreciated...cheers It may also depend on which version of Python you wish to use. Since you're a "newb", I'd probably suggest starting off with Python 3. The version in your book is probably version 2.*. The difference is minor, but, when you're starting off (I assume with computer languages in general?) the difference in syntax can kick you where it hurts. Programs that work with Python 2.*, may not work with Python 3. However, I suggest Python 3 since it seems to be the "code of tomorrow." It may also depend on what you wish to do with your knowledge of Python (applications, games, web frameworks, etc.) If you want to make games, I suggest also learning about pyGame. As for book versus website, I started off with, as others have mentioned, learning online. Not only is it free, but the boundary between page and screen is broken. Note though that some off-sites (Wikibooks for instance) may not be complete in their writing. Python.org has a wealth of knowledge about almost everything involving Python. However, *some* of the documentation there may not be suitable for absolute beginners. There are several links there to other good websites for those with no experience in coding, all the way up to a ridiculously complicated level. I highly suggest poking around there. If you wish to read a book instead, try: http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002/ Or go to your local library and poke there. :) Good luck! - -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. - From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW -----END PGP SIGNATURE----- From mithrandiragainwiki at mailinator.com Tue Jul 27 22:26:27 2010 From: mithrandiragainwiki at mailinator.com (Mithrandir) Date: Tue, 27 Jul 2010 19:26:27 -0700 Subject: Are those features still the same? References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/26/2010 11:58 PM, Lawrence D'Oliveiro wrote: > In message , francogrex wrote: > >> By the way Peter Norvig is not biased, he works for Google research and is >> a supporter of programming in any language, especially in Python. > > Bias doesn?t have to be a conscious thing. Correct. It just has to have a rainbow logo and own half the internet. :) - -- People should read more. https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All that is gold does not glitter, not all those who wander are lost; the old that is strong does not wither, deep roots are not reached by the frost. - From the ashes a fire shall be woken, a light from the shadows shall spring; renewed shall be blade that was broken, the crownless again shall be king." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJMT5VTAAoJEKo37V1xH7gTobAH/1QY0SN6BulkNO3QUFrzg5cO OkeDTbTmI4BJ1M/hmkECU+T76KfnkQ13NobLroWt/UJU8YA4lOQ6KsJU/EsR/27n TFrUxs3gDVeWyiKdSbWtVSZ7b7BJ8Tr41hMPkA1wyK85qJW5mA19h0hndqs/BRtg j2GWPLNv9wx7+v0gQnv7ZgSQJHSlRvp8oi016QVl3W7OcO6B0rgwWx4i1hxz/oij Wd1jF5wwhtgw/0durTFFVt7mR31l3/6zz2WrwvC9fQkSKNQ0oaNgKXZOtctWVdcV XNm+W9I9Sx70F1qO+VfFrHIRJ+kzjCf6/48bumaygol4MnbLIJ3lJ1BNIESIFAg= =iv9B -----END PGP SIGNATURE----- From f2h2d2 at gmail.com Tue Jul 27 22:54:34 2010 From: f2h2d2 at gmail.com (nais-saudi) Date: Tue, 27 Jul 2010 19:54:34 -0700 (PDT) Subject: The Miracle and Challenge of the Quran Message-ID: The Miracle and Challenge of the Quran ---------------------------------------------------------------------------?--- http://www.youtube.com/watch?v=m3A8R...layer_embedded http://www.youtube.com/watch?v=m3A8R...layer_embedded ---------------------------------------------------------------------------?--------------------------------------- Do you know Islam ? Try VISIT THESE SITES ISLAM RELIGION http://www.islamreligion.com/ SCIENE ISLAM http://www.islamreligion.com/ YOUTUBE ISLAM http://youtubeislam.com/ BIBLE ISLAM http://www.bibleislam.com/ MINISTRY OF AWKAF http://www.islamic-council.org/ ISLAM WORD http://islamworld.net/ ISLAM HOUSE http://www.islamhouse.com/ SUNNAH ONLINE http://www.sunnahonline.com/ilm/dawah/index.htm ---------------------------------------------------------------------------?-------------------------------------- The Miracle and Challenge of the Quran With an introduction by Magdy Abd Al-SHafy The Holy Quran is a miracle that beggars de******ion , words fail to describe this miracle , it is a miracle in the full sense of the term . Different specialists , according to the branch of science they are specialized in , find it miraculous . Prophet Mohummed said commenting on the Holy Quran saying " it unfolds the secrets of the nations that preceded you , and secrets of the future treasured in it " It is the Holy Book that Jinnee , on hearing to it , did not leave their place till they believed in it . It is the book which unbelievers gave positive witness to . Dr. Keith L. Moore is a Professor of Anatomy and Cell Biology, University of Toronto, Toronto, Canada. He is a world renowned scientist and a distinguished researcher in the fields of anatomy and embryology, he has published more than 150 research articles, chapters and books in this field. He is the author of several medical ****books, such as the widely used and acclaimed "The Developing Human: Clinically oriented Embryology" (now in it's fifth edition, and translated into eight different languages), "Before We Are Born" and "Clinically Oriented Anatomy." He has also recently co-authored "Qur'an and Modern Science, Correlation Studies." Dr. Moore is the recipient of numerous awards and honors, including, in 1984, the J.C.B. Grant Award, which is the highest honor granted by the Canadian Association of Anatomists. He has served in many academic and administrative positions, including the President of the Canadian Association of Anatomists, 1968-1970. Let us see what Dr. Moore's opinion is on the scientific statements regarding embryology to be found in the Qur'an: Dr. Moore was contacted by a Muslim scholar by the name of Abdul- Majeed Azzindani. He was asked to participate in a three-year study of around twenty-five verses of the Qur'an and the Sunnah (sayings of Muhammad, pbuh) which speak about embryology, and to determine the their correspondence to modern scientific discoveries. Dr. Moore's conclusion regarding this matter was: "For the past three years, I have worked with the Embryology Committee of King Abdulaziz University in Jeddah, Saudi Arabia, helping them to interpret the many statements in the Qur'an and the Sunnah referring to human reproduction and prenatal development. At first I was astonished by the accuracy of the statements that were recorded in the seventh century AD, before the science of embryology was established. Although I was aware of the glorious history of Muslim scientists in the 10th century AD, and of some of their contributions to Medicine, I knew nothing about the religious facts and beliefs contained in the Qur'an and Sunnah. It is important for Islamic and other students to understand the meaning of these Qur'anic statements about human development, based on current scientific knowledge. The interpretations of the "verses" in the Qur'an and the Sunnah, translated by Shaikh Azzindani, are to the best of my knowledge accurate." >From the forward of "The Developing Human: Clinically oriented Embryology," third edition, by Dr. Keith L. Moore. The Qur'an and the Sunnah of the prophet Muhammad (Sallalahu Alayhi Wa Salam) provide a very detailed de******ion of the microscopic development of the human embryo from a mere sperm drop up to the stage of a completely formed human being. It is well known that microscopes were not developed until the sixteenth century AD, and even at that were very crude in design. Zacharias Janssen is credited with having invented the compound microscope in about 1590. With it, remarkable scientific discoveries were made in the 17th and 18th centuries. The Dutch naturalist Anthony van Leeuwenhoek produced lenses powerful enough to prove that many tiny creatures are not spontaneously generated but come from eggs. Before this period, theories on human reproduction ran rampant. Some scientist believed that the menstrual blood itself developed into the fetus. Later on, a new theory was developed wherein the sperm drop was popularly believed to contain a completely developed miniature human (homunculus) which later grew to the size of a baby. The science of embryology as we know it today did not discover many of the detailed aspects of human development which are taken for granted today until only about twenty years ago, or 1973 to be precise. Now we must ask the question: where did Muhammad (Sallalahu Alayhi Wasallam) get such detailed knowledge of the microscopic development of the human embryo in the 6th century AD without a microscope, technical training, a laboratory of any kind, or even the ability to write his own name? The only logical conclusion is that it came from exactly where he claimed it did. From the one who created mankind, God Almighty! Prof. Moore has since given numerous lectures on the topic of embryology in the Qur'an. He is quoted in one of these lectures as saying: "It is clear to me that these statements must have come to Muhammad from God, or Allah, because most of this knowledge was not discovered until many centuries later. This proves to me that Muhammad must have been a messenger of God, or Allah." Prof. Moore was so impressed with the Qur'anic classification of the stages of development of the human embryo, that he suggested the adoption of the Qur'anic system in place of the system currently in use by scientists today. Prof. Moore said: "Because the staging of the human embryo is complex owing to the continuous process of change during development. It is therefore suggested that a new system of classification could be developed using the terms mentioned in the Qur'an and the Sunnah. The proposed system is simple, comprehensive, and conforms with present embryological knowledge." When Dr. Moore first presented his findings in Toronto it caused quite a stir throughout Canada. It was on the front pages of some of the newspapers across Canada . One newspaper reporter asked Professor Moore, "Don't you think That maybe the Arabs might have known about these things - the de******ion of the embryo, its appearance and how it changes and grows? Maybe there were not scientists, but maybe they did some crude dissections on their own - carved up people and examined these things." Professor Morre immediately pointed out to him, however, that he had missed a very important point. All of the slides of the embryo that Dr. Moore had based his study upon had come from pictures taken through a microscope. He said, "It does not matter if someone had tried to discover embryology fourteen centuries ago, they could not have seen it!." Dr. Moore taunted, "Maybe fourteen centuries ago someone secretly had a microscope and did this research, making no mistakes anywhere. Then he somehow taught Muhammad and convinced him to put this information in his book. Then he destroyed his equipment and kept it a secret forever?. Do you believe that? You really should not unless you bring some proof because it is such a ridiculous theory." When he was asked "How do you explain this information in the Qur'an?" Dr. Moore's reply was, "It could only have been divinely revealed ????? ?????? ??? ??? ??????? The Effect of Prayer on the Human Body By : Dr Noha abo-krysha Translated By : Nassim Dhaher Revised By Magdy Abd Al-Shafy In fact , prayer is a strong connection to God . In prayer , one can find many meanings that beggar de******ion , man can find out the basic reason behind his existence . Allah the Exalted says in the Holy Quran what means : { Those who believe, and whose hearts find satisfaction in the remembrance of Allah. for without doubt in the remembrance of Allah do hearts find satisfaction} Sura Arraadverse28 God also says in the Holy Quran what means :{78-Establish regular prayers - at the sun's decline till the darkness of the night, and the morning prayer and reading: for the prayer and reading in the morning carry their testimony. 79-And pray in the small watches of the morning: (it would be) an additional prayer (or spiritual profit) for thee: soon will thy Lord raise thee to a Station of Praise and Glory!} Sura Al-israa verses 78,79 Prophet Mohammad (peace and blessings of Allah be upon him) used to say , when somthing distress him : (Oh Bilal(the prayer caller ), call for the prayer, relax us by it) [Sunan Abi Dawud] The Scientific Study It has become clear , through the results of several studies, the great effect that prayer and devotion have on brain stability and mode of function, and it has also become clear that several changes occur in the body ;among these is the effect that happens during blood systematization to certain parts in the brain prayer effect on cerebral activities This research was carried out by Dr. Newberg, the assistant Professor at X-Ray division of the Pennsylvania University Medical Center, on a group of faithful people who have faith in God , practice their prayers and come from different religious backgrounds. This as done using Single Photon C.T. scan that shows the flow of blood in the cerebrum using colors which are based on brain activity where the color Red represents high activity and Yellow and Green represent low activity. The First Image The image shows the brain before meditation and prayer(on the left) and during prayer (on the right) where we see that during the envolvement in prayers and meditation, blood flow has increased , frontal lobe region is responsible for controlling emotions and agitations in humans and a region also important for the acquisition and practice of complicated percetion-movement abilities. Terms used in the image Baseline: normal state without meditation Meditation: as name implies The Second Image The image shows a a blood flow decline in the the Parietal lobe at the region where humans sense their time and space limits. It was concluded from these results that during prayer, contemplation and seeking Allah, the limits of self-conciousness dissapear and a feeling of peace and freedom starts in the person and one feels closer to Allah in a way that no words can describe. Verses from The Quran Many are the verses that talked about the importance of prayer (Assalat), devotion and praise Allah the Almighty. The Quran has made a link between patience and prayer to make sure one does not get agitated. Allah The Exalted Says in the Holy Quran what means: {Nay, seek (Allah's) help with patient perseverance and prayer: It is indeed hard, except to those who bring a lowly spirit} SuraAl-Baqara verse 45 There are other verses that linked between prayer and tranquility. Allah The Exalted Says: {When ye pass (Congregational) prayers, celebrate Allah?s praises, standing, sitting down, or lying down on your sides; but when ye are free from danger, set up Regular Prayers: For such prayers are enjoined on believers at stated times.} Sura An-Nisa verse 103 {Successful indeed are the believers , Who are humble in their prayers} Sura Al Muminun verses 1,2 Results It becomes clear after these verses of the Noble Quran and scientific studies the importance of prayer in the life of the faithful, and the importance of devotion and glorification during the application of those prayers. From here the wisdom of Islam is apparent in focusing on the danger of ceasing to do the prayers. If experiments show stability of the brain during prayers for non- Muslims who don?t even read Al-Quran during their prayers, How then is it when one prays to Allah and reads the Book of Allah? Undoubtedly the stability will be greater. We remember this noble verse that confirms the importance of the channels of communication towards Allah, ie ,piety, submission, heart purification, and putting things in Allah?s command. Allah The Exalted Says in the Holy Quran what means: {Be guardians of your prayers, and of the midmost prayer, and stand up with devotion to Allah.} Sura Al-Baqara verse 238 Let us remember also the supplication of Prophet Abraham (peace be upon him) My Lord! Make me to establish proper worship, and some of my posterity (also); our Lord! and accept my prayer. Our Lord! Forgive me and my parents and believers on the day when the account is cast. ???? ???? ?????? ?? ?????? What does the Holy Quran say about Iron ? By Magdy Abd Al-Shafy The Holy Quran , the last revealed Holy book, carries within its holy verses the evidence toits Divine source . Among the many mitacles that the holy Quran contain is the scientific miracles , more than 1400 years ago , The Holy Quran gives scientific facts that have been discovered already and now are scientifically established . When the Holy Quran gives such facts it adds many dimensions to the question of faith in God ; in addition to the faith dimension there is a spiritual dimension that Only Moslems and reasonable non -moslems can feel . The Holy Quran stands in the face of the atheism claims . The other Holy books , being distorted and pregnant with scientific errors that may feed sckepticism , are no longer able to face atheism . Atheism are breeding and taking people away from the right path . The Holy Quran , being the most authenticated book , can be the challanger - No one can believe that a book with such astounding scientific miracles that revealed 1400 years ago can be man-mad . Such facts lead you to believe in God and to believe that the Holy Quran is God's book ...it is up to you to decide ......... Now to our scientific miracle The Holy Quran ststes in one of its Holy verses that ( iron ) we send down from high skies , i.e, it is not formed in the ground . That what science has aleady discovered . Let's read this short verse . God says in the Holy Quran what means "And We sent down iron in which there lies great force and which has many uses for mankind.... (Surat al-Hadid: 25) Modern astronomical findings have disclosed that the ****l of iron found in our world has come down from the giant stars in outer space. The Holy Quran verse used The Arabic word " Anzlna " which could be rendered " and we sent down " . Iron needs so high temperature to be formed ; Professor Armstrong works at NASA, otherwise known as the National Aeronautics and Space Administration, where he is a well-known scientist here. He was asked about Iron and how it was formed. He explained how all the elements in the earth were formed. He stated that the scientists have come only recently to discover the relevant facts about that formation process. He said that the energy of the early solar system was not sufficient to produce elemental Iron. In calculating the energy required to form one atom of iron, it was found to be about four times as much as the energy of the entire solar system. In other words, the entire energy of the earth or the moon or the planet Mars or any other planet is not sufficient to form one new atom of iron, even the energy of the entire solar system is not sufficient for that. That is why Professor Armstrong said that the scientists believe that iron is an extraterrestrial that was sent to earth and not formed therein. Unlike most of ****ls , iron needs so high temperature to be formed . such high temperature is found no where in our solar system . "Nova" and "supernova. Temperature in the Sun is inadequate for the formation of iron. The sun has a surface temperature of 6,000 degrees Celsius, and a core temperature of approximately 20 million degrees. Iron can only be produced in much larger stars than the Sun, where the temperature reaches a few hundred million degrees. When the amount of iron exceeds a certain level in a star, the star can no longer accommodate it, and it eventually explodes in what is called a "nova" or a "supernova." These explosions make it possible for iron to be given off into space. All this shows that iron did not form on the Earth, but was carried from Supernovas, and was "sent down," as stated in the verse. It is clear that this fact could not have been known in the 7th century, when the Qur'an was revealed. Nevertheless, this fact is related in the Qur'an, the Word of Allah, Who encompasses all things in His infinite knowledge. Science says that iron and other materials were attracted to the earh when enetered the earth garvity field ; iron fell down on the earth as if it were rain . the earth at that time was like ash , not completely solid as it is now . Iron found its way deep to the core of the earth . And We sent down iron in which there lies great force and which has many uses for mankind.... what is meant by ( and in which there lies great force and which has many uses for mankind.... In his book Nature's Destiny, the well-known microbiologist Michael Denton Of all the ****ls there is none more essential to life than iron. It is the accumulation of iron in the center of a star which triggers a supernova explosion and the subsequent scattering of the vital atoms of life throughout the cosmos. It was the drawing by gravity of iron atoms to the center of the primeval earth that generated the heat which caused the initial chemical differentiation of the earth, the outgassing of the early atmosphere, and ultimately the formation of the hydrosphere. It is molten iron in the center of the earth which, acting like a gigantic dynamo, generates the earth's magnetic field, which in turn creates the Van Allen radiation belts that shield the earth's surface from destructive high-energy-penetrating cosmic radiation and preserve the crucial ozone layer from cosmic ray destruction? in this connection the Holy Quran , to show God's blessings , in another verse which implies anew scientific miracle says " And we have made the heavens as a canopy well guarded: yet do they turn away from the Signs which these things (point to)!( Al-Anbyaa :32 ) Without the iron atom, there would be no carbon-based life in the cosmos; no supernovae, no heating of the primitive earth, no atmosphere or hydrosphere. There would be no protective magnetic field, no Van Allen radiation belts, no ozone layer, no ****l to make hemoglobin [in human blood], no ****l to tame the reactivity of oxygen, and no oxidative ****bolism. The intriguing and intimate relationship between life and iron, between the red color of blood and the dying of some distant star, not only indicates the relevance of ****ls to biology but also the biocentricity of the cosmos? This account clearly indicates the importance of the iron atom. The fact that particular attention is drawn to iron in the Qur'an also emphasises the importance of the element. In addition, there is another hidden truth in the Qur'an which draws attention to the importance of iron: Surat al-Hadid 25, which refers to iron, contains two rather interesting mathematical codes. "Al- Hadid" is the 57th sura in the Qur'an. The abjad of the word "Al- Hadid" in Arabic, when the numerological values of its letters are added up, is also 57. The numerological value of the word "hadid" alone is 26. And 26 is the atomic number of iron. Moreover, iron oxide particles were used in a cancer treatment in recent months and positive developments were observed. A team led by Dr. Andreas Jordan, at the world famous Charit? Hospital in Germany, succeeded in destroying cancer cells with this new technique developed for the treatment of cancer-magnetic fluid hyperthermia (high temperature magnetic liquid). As a result of this technique, first performed on the 26-year-old Nikolaus H., no new cancer cells were observed in the patient in the following three months. This method of treatment can be summarised as follows: 1. A liquid containing iron oxide particles is injected into the tumour by means of a special syringe. These particles spread throughout the tumour cells. This liquid consists of thousands of millions of particles, 1,000 times smaller than the red blood corpuscles, of iron oxide in 1 cm3 that can easily flow through all blood vessels.42 2. The patient is then placed in a machine with a powerful magnetic field. 3. This magnetic field, applied externally, begins to set the iron particles in the tumour in motion. During this time the temperature in the tumour containing the iron oxide particles rises by up to 45 degrees. In a few minutes the cancer cells, unable to protect themselves from the heat, are either weakened or destroyed. The tumour may then be completely eradicated with subsequent chemotherapy.43 In this treatment it is only the cancer cells that are affected by the magnetic field, since only they contain the iron oxide particles. The spread of this technique is a major development in the treatment of this potentially lethal disease. In the treatment of such a widespread disease as cancer, the use of the expression "iron in which there lies great force and which has many uses for mankind" (Qur'an, 57:25) in the Qur'an is particularly noteworthy. Indeed, in that verse, the Qur'an may be indicating the benefits of iron for human health. (Allah knows best.) From pengyu.ut at gmail.com Tue Jul 27 23:26:09 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 27 Jul 2010 22:26:09 -0500 Subject: Where is the help page for re.MatchObject? Message-ID: I know the library reference webpage for re.MatchObject is at http://docs.python.org/library/re.html#re.MatchObject But I don't find such a help page in python help(). Does anybody know how to get it in help()? >>> help(re.MatchObject) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'MatchObject' -- Regards, Peng From steveo at syslang.net Tue Jul 27 23:31:03 2010 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 27 Jul 2010 23:31:03 -0400 Subject: How to capture all the environment variables from shell? In-Reply-To: <4C4E4790.6030604@tim.thechases.com> References: <4C4E43D3.9070203@syslang.net> <4C4E4790.6030604@tim.thechases.com> Message-ID: <4C4FA477.6000308@syslang.net> On 07/26/10 22:42, quoth Tim Chase: > On 07/26/10 21:26, Steven W. Orr wrote: >> Please! Never export anything from your .bashrc unless you >> really know what you're doing. Almost all exports should be >> done in your .bash_profile > > Could you elaborate on your reasoning why (or why-not)? I've found that > my .bash_profile doesn't get evaluated when I crank up another terminal > window, while my bashrc does. Thus I tend to put my exports in my > ~/.bashrc so they actually take effect in my shell... > > -tkc > > I'm happy to elaborate, but people should feel free to stop me if they're not interested. The topic is bash: When you log in you get your .bash_profile and not the .bashrc. Subshells get the .bashrc and not the .bash_profile. If you set your envvars in your .bash_profile then you don't need to reset them in subshells because they all get inherited. (Inheritance of envvars is, after all, the reason that they are envvars and not just local variables.) The way you get your .bashrc to happen at login time is that you have to make it happen yourself. In your .bash_profile, just say this: . ~/.bashrc The one time that you should set an envvar in your .bashrc is when you are not an interactive shell. In that case you can set your PATH var in your .bashrc by first testing to see if you're interactive: In your .bashrc just say: [[ -z "$PS1" ]] && set_PATH_cmds # Of course, note that set_PATH_cmds is not a subprocess. It has to # be either a PATH= or function that accomplishes the same thing. This solves the problem of things like ssh somemachine cmd where cmd is something that you would only find on your PATH if you properly logged in. As far as X goes, I am starting from the premise that your X session will be set up to cause your .bash_profile to happen at login time. One last note: If you say something like export PATH=$PATH:/usr/local/bin then re-sourcing your .bash_profile will cause your PATH value to double up. That's why I set my PATH variable explicitly. After that, I encourage people to set up their PATH variables so that they are broken into four distinct sections in the following order. (The idea is to make your stuff override the system supplied stuff.) (The stuff below is just an example.) USERPERSONAL=~/bin:~/share/bin MACHINESPECIALS=/usr/local/bin:/usr/local/share/bin OPTIONALADDONS=/opt/Adobe/Reader9/bin:/opt/openoffice.org3/program VENDORPATHS=/bin:/usr/bin:/usr/X11R6/bin PATH=${USERPERSONAL}:${MACHINESPECIALS}:${OPTIONALADDONS}:${VENDORPATHS} -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: From jeff at newz-china.org Tue Jul 27 23:56:32 2010 From: jeff at newz-china.org (Jeff Ro) Date: Wed, 28 Jul 2010 11:56:32 +0800 Subject: About " python " Internet intellectual Property Issue Message-ID: (If you are not in charge of this , please transfer this urgent email to your CEO. Thanks ) Dear CEO, We are a leading internet solutions organization in Asia, and we have something urgent to confirm with you. Yesterday we received a formal application from a company called " Yower Investment Co., Ltd". They were trying to apply for " python" as Brand Name and following Domain Names through our organization: www.python.com.hk www.python.tm After our initial examination, we found that the Brand Name and Domain Names above are similar to yours. These days we have been dealing with it. Now we hope to get your affirmation. If your company did not authorize the aforesaid company to register these, please contact us as soon as possible. In addition, we hereby declare that time limit for this issue is 7 workdays. If your company don?t respond within the time limit, we will unconditionally approve the application submitted by Yower Investment Co., Ltd. Best Regards, Jeff Ro Senior Examinant 2010-07-23 -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Wed Jul 28 01:26:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 27 Jul 2010 22:26:21 -0700 Subject: Which multiprocessing methods use shared memory? In-Reply-To: References: Message-ID: <4c4fbf7b$0$1616$742ec2ed@news.sonic.net> On 7/27/2010 12:30 PM, MRAB wrote: > Kevin Ar18 wrote: >> I'm not sure my previous message went through (I wasn't subscribe), so >> I'm gonna try again. >> >> The multiprocessing module has 4 methods for sharing data between >> processes: >> Queues >> Pipes >> Shared Memory Map >> Server Process >> >> Which of these use shared memory? >> >> I understand that the 3rd (Shared Memory Map) does, but what about >> Queues? >> > The documentation says: > > """class multiprocessing.Queue([maxsize]) > Returns a process shared queue implemented using a pipe and a few > locks/semaphores. When a process first puts an item on the queue a > feeder thread is started which transfers objects from a buffer into the > pipe.""" Python's "shared memory" between processes is un-Pythonic. You can't share Python object, only C objects. The locking mechanisms are very limited, and slow; locking actually takes place via messages over pipes. There's no dynamic allocation in the shared area. Realistically, if you're using Python, you're not that concerned about compute speed. So don't bother with shared memory, which is a performance optimization. John Nagle From eckhardt at satorlaser.com Wed Jul 28 03:08:24 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jul 2010 09:08:24 +0200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> Message-ID: <8k15i7-jhs.ln1@satorlaser.homedns.org> Daniel Fetchinson wrote: > After getting the technicalities out of the way, maybe I should have > asked: > > Is it only me or others would find a platform independent python API > to clear the terminal useful? There are two kinds of programs: 1. Those that process input to output. If one of those suddenly started by clearing my screen, I'd just dump it. Also, if output is redirected to a file or piped into another program, that is basically useless or even hurting, since you then end up with control sequences in the file. 2. Those that provide a text-based interactive UI. Those typically not only clear the screen, but also control its whole layout and content, so there you don't only need ways to clear the screen but also to position the cursor or draw boxes etc. In that case you need a full "curses" library. Summary: No, I don't see the need for such an API. Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From sjmachin at lexicon.net Wed Jul 28 03:16:55 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jul 2010 00:16:55 -0700 (PDT) Subject: Where is the help page for re.MatchObject? References: Message-ID: <0863ebe2-4910-4693-8539-39633e652845@s24g2000pri.googlegroups.com> On Jul 28, 1:26?pm, Peng Yu wrote: > I know the library reference webpage for re.MatchObject is athttp://docs.python.org/library/re.html#re.MatchObject > > But I don't find such a help page in python help(). Does anybody know > how to get it in help()? Yes, but it doesn't tell you very much: | >>> import re | >>> help(re.match('x', 'x')) | Help on SRE_Match object: | | class SRE_Match(__builtin__.object) | | >>> From jbbrown at sunflower.kuicr.kyoto-u.ac.jp Wed Jul 28 03:41:38 2010 From: jbbrown at sunflower.kuicr.kyoto-u.ac.jp (J.B. Brown) Date: Wed, 28 Jul 2010 16:41:38 +0900 Subject: python styles: why Use spaces around arithmetic operators? In-Reply-To: References: Message-ID: I personally prefer to be slightly excessive in the amount of spacing I used, especially when parentheses are involved. In no way do I assert that my code style is right for all situations, but here are a few examples of my personal style. --- myTuple = ( 1, 2, 3, 4, 5 ) # Comment about what this tuple will conceptually represent or store. myTuple2 = ( 1, 2, 3*myFunc(4), 4*myFunc2( "text arg" ), ) # Yes, I leave the tailing comma for spacing and to remind myself it is a tuple/list. textFieldWidth = 80 / numFields # Balance width of fields fileObject.write( "My text goes here. Value of some function = " + str( someFunc( argList ) ) ) # Write out results. --- Combining my code style with the parenthesis/brace/bracket highlighting feature of Vi/Vim makes it easy for me to figure out if I have closed all braces, and additionally what is the context in which I am nesting functions or arguments. Again, this is just my preference, but it emerged over time after many hours of development and debugging on remote machines where only a terminal environment and a text-based editor are available. Even in my comments, in which I _strongly_ believe in a minimum of 1 comment line per 3 code lines (1:3) though I often code 1:2 or 1:1, I use the parenthesis style above. Example: # The true positive rate of an experiment is calculated as: TPR = [ TP / ( TP + FN ) ] . Just food for thought. J.B. Brown Kyoto University From bruno.42.desthuilliers at websiteburo.invalid Wed Jul 28 03:48:26 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jul 2010 09:48:26 +0200 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> Message-ID: <4c4fe0bf$0$29093$426a74cc@news.free.fr> Ethan Furman a ?crit : > Bruno Desthuilliers wrote: >> Bruno Desthuilliers a ?crit : >>> Ethan Furman a ?crit : >>>> Bruno Desthuilliers wrote: >>>>> Duncan Booth a ?crit : >>> (snip) >>> >>>>>> Or you could create the default as a class attribute >>>>> >>>>> from the OP: >>>>> """ >>>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>>> it is overloaded in __getattr__, so if someone invokes >>>>> "myObject.size", it is generated (as another oofun) and connected to >>>>> myObject as attribute. >>>>> """ >>>>> >>>>> so this solution won't obviously work in this case !-) >>>>> >>>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>>> class attribute is of a mutable type. >>>> >>>> Well, it is Monday, so I may be missing something obvious, but what >>>> is the effective difference between these two solutions? >>> >> >> If you meant "what is the difference between creating the "whatever" >> attribute with a default value in the initializer and creating it on >> demand in the __getattr__ hook", the main difference is that in the >> first case, the instance is garanteed to have this attribute, so you >> get rid of "hasattr" checks (and the unwanted side effects) or, worse, >> direct check of the instance __dict__. Except for a couple of corner >> case, client code shouldn't have to worry about this kind of things - >> this breaks encapsulation. > > Yay Tuesday! :D > > What I meant was what is the difference between: > > [Bruno Desthuilliers] > > DEFAULT_WHATEVER = Whathever() > > class MyClass(object): > > def __init__(self, x, y): > > self.size = DEFAULT_WHATEVER > > and > > [Duncan Booth] > > class MyClass(object): > > size = Whatever() > > def __init__(self, x, y): > > ... > > in both cases the object ends up with a size attribute and no further > need of __getattr__. Of course, the warning about having a mutable > object as a class attribute stands. Indeed. > To phrase it another way, why does your solution (Bruno) work, but > Duncan's "obviously won't"? As it is written (and assuming the name "Whatever" is bound to a callable !-)), Duncan's code would work, even if it might not be the safest solution in the case of a mutable type. The problem here is that the OP stated that the "size" attribute was to be of the same type as the host class, so the code would look something like: class MyClass(object): size = MyClass() which will raise a NameError, since MyClass is not yet defined when "size=MyClass()" is executed. From tartley at tartley.com Wed Jul 28 05:49:25 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 02:49:25 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 I don't know much, but just in case the following is useful to anyone: There is a Windows program called 'ansicon', which when installed (run with '-i'), will modify all future Windows cmd shells to correctly intercept and interpret ANSI escape codes for colors, cursor movement, and: \e[#J ED: Erase Display which I presume is what is under discussion here. I understand there are other historical ANSI drivers which were responsible for achieving a similar thing under Windows, but this is the method I currently use (on XP) and am very happy with. Also, and probably less usefully, personally I do wish Python provided a cross platform mechanism for simple terminal control like clearing and colored text. Since ANSI codes are used everywhere except Windows, it would make sense to base such a system on them. So I started a pure Python implementation of a crude ANSI driver, on PyPI as 'colorama'. It does nothing on non-windows systems, but on Windows it patches sys.stdout with a stream-like object, in order to filter out ANSI codes and convert them into Win32 terminal control calls. It currently only works with colors and brightness, but I would love to extend it to cover other ANSI codes such as 'clear screen'. It is doubtless riddled with errors and misunderstandings, and I would love any feedback helping me do a better job. Best regards, Jonathan From lijia.jasperlee at gmail.com Wed Jul 28 06:10:00 2010 From: lijia.jasperlee at gmail.com (jia li) Date: Wed, 28 Jul 2010 18:10:00 +0800 Subject: Python parsing XML file problem with SAX Message-ID: I have an XML file with hundreds of elements. What's strange is only one of there elements could not be parsed correctly: REVERSE_INULL Dispose_ParameterList Dispose_ParameterList UNINSPECTED 146 1/146MMSLib_LinkedList.c I printed the data in "characters(self, data)" and after parsing. The result is one "\r\n" is inserted after "1/" and "146MMSLib_LinkedList.c" for the latter. But if I make my XML file only this element left, it could parse correctly. My script below: class CoverityErrorHandler(ContentHandler): def __init__(self): self.is_num = False self.num = "" self.is_func = False self.function = "" self.is_file = False self.filename = "" self.is_Report = False self.report = "" self.is_Checker = False self.checker = "" self.is_unmangled_func = False self.unmangled_func= "" self.is_Status = False self.Status = "" self.mapping = {} def startElement(self, name, attributes): if name == "num": self.is_num = True elif name == "unmangled_function": self.is_unmangled_func = True elif name == "checker": self.is_Checker = True elif name == "file": self.is_file = True elif name == "home": self.is_Report = True elif name == "function": self.is_func = True elif name == "status": self.is_Status = True def characters(self, data): if self.is_num: self.num = data elif self.is_func: self.function = data elif self.is_Checker: self.checker = data elif self.is_file: self.filename = data elif self.is_Report: self.report = data; print self.report; elif self.is_unmangled_func: self.unmangled_func = data elif self.is_Status: self.Status = data def endElement(self, name): if name == "error": self.mapping[self.num] = CoverityError(self.checker, self.filename, self.function, self.report) elif name == "num": self.is_num = False elif name == "unmangled_function": self.is_unmangled_func = False elif name == "checker": self.is_Checker = False elif name == "file": self.is_file = False elif name == "home": self.is_Report = False elif name == "function": self.is_func = False elif name == "status": self.is_Status = False Please any expert help to have a look. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Jul 28 06:48:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Jul 2010 12:48:54 +0200 Subject: Python parsing XML file problem with SAX In-Reply-To: References: Message-ID: jia li, 28.07.2010 12:10: > I have an XML file with hundreds of elements. > > What's strange is only one of there elements could not be parsed correctly: > > REVERSE_INULL > Dispose_ParameterList > Dispose_ParameterList > UNINSPECTED > 146 > 1/146MMSLib_LinkedList.c > > > I printed the data in "characters(self, data)" and after parsing. The result > is one "\r\n" is inserted after "1/" and "146MMSLib_LinkedList.c" for the > latter. > > But if I make my XML file only this element left, it could parse correctly. First of all: don't use SAX. Use ElementTree's iterparse() function. That will shrink you code down to a simple loop in a few lines. Then, the problem is likely that you are getting separate events for text nodes. The "\r\n" most likely only occurs due to your print statement, I doubt that it's really in the data returned from SAX. Again: using ElementTree instead of SAX will avoid this kind of problem. Stefan From fetchinson at googlemail.com Wed Jul 28 07:23:52 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 28 Jul 2010 13:23:52 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <8k15i7-jhs.ln1@satorlaser.homedns.org> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: >> After getting the technicalities out of the way, maybe I should have >> asked: >> >> Is it only me or others would find a platform independent python API >> to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. Okay, that makes perfect sense, thanks for the exaplanation! I'll just live with the platform.system( ) check for this particular problem then. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Wed Jul 28 07:25:51 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 28 Jul 2010 13:25:51 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <73a959d2-e8e1-414c-8e2d-3593758d68b7@g19g2000yqc.googlegroups.com> Message-ID: >> > After getting the technicalities out of the way, maybe I should have >> > asked: >> >> > Is it only me or others would find a platform independent python API >> > to clear the terminal useful? > I don't know much, but just in case the following is useful to anyone: > > There is a Windows program called 'ansicon', which when installed (run > with '-i'), will modify all future Windows cmd shells to correctly > intercept and interpret ANSI escape codes for colors, cursor movement, > and: > > \e[#J ED: Erase Display > > which I presume is what is under discussion here. I understand there > are other historical ANSI drivers which were responsible for achieving > a similar thing under Windows, but this is the method I currently use > (on XP) and am very happy with. > > Also, and probably less usefully, personally I do wish Python provided > a cross platform mechanism for simple terminal control like clearing > and colored text. Since ANSI codes are used everywhere except Windows, > it would make sense to base such a system on them. So I started a pure > Python implementation of a crude ANSI driver, on PyPI as 'colorama'. > It does nothing on non-windows systems, but on Windows it patches > sys.stdout with a stream-like object, in order to filter out ANSI > codes and convert them into Win32 terminal control calls. It currently > only works with colors and brightness, but I would love to extend it > to cover other ANSI codes such as 'clear screen'. It is doubtless > riddled with errors and misunderstandings, and I would love any > feedback helping me do a better job. Thanks, I didn't know about 'colorama' before but it surely looks promising! I'll look into it for future reference, once in a while I like having pretty output without the hassle of 'curses' or other complicated stuff. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From chenxiangmei89 at gmail.com Wed Jul 28 08:20:18 2010 From: chenxiangmei89 at gmail.com (cntrade08) Date: Wed, 28 Jul 2010 05:20:18 -0700 (PDT) Subject: Shox Allegria Glow, Shox FSM, Shox Dendara, Shox 45, Shox Propulsion, Shox XT,Shox Vivacity. (http://www.cntrade09.com) Message-ID: For more information,please contact karen, MSN:cntrade088 at hotmail.com Minimum order is one,factory price also! Paypal payment free shipping,ship time will take 4-7 working days. Shox TW,Shox Saya+,Shox Arraw+,Shox Pursuit+,Shox Turbo V+5,Shox NZ,Shox Turbo+IV 4,Shox Spotlight,Shox Saikano+,Shox Fleet,Shox Turn & Go,Shox Junga II 2,Shox Q'Vida,Shox Junga,Shox TL 4,Shox Monster,Shox TL 3,Shox Turb OH+SL,Shox TL 2,Shox CL,Shox TL,Shox Cognescenti,Shox Explodine,Shox R4,Nike Shox Basketball,Shox Disobey,Shox Turbo. Shox Go,Shox 2:40,Shox Respond,Shox Warrior,Shox Ride 2,Shox Glamour SW & SW II,Shox Andalucia,Shox Rhythmic,Shox Aprisa,Shox Energia,Shox Ride & Plus,Shox Allegria Glow,Shox FSM,Shox Dendara,Shox 45,Shox 2:45,Shox Legend Trainer,Shox VC,Shox Rollin,Shox BB4,Shox Bella IL,Shox Basketball,Shox Turbo OZ,Shox Electric,Shox TR,Shox D,Shox Propulsion,Shox XT,Shox Vivacity. (http:// www.cntrade09.com) Zoom Moire+,Nike Trainer Huarache,Nike Free Trainer 5.0, 7.0,Nike Air Tech Challenge - Andre Agassi,Nike Presto & Chanjo,Training & Running Shoes,Barry Sanders Zoom Turf,Basketball Shoes. www.cntrade09.com From me at here.com Wed Jul 28 08:50:47 2010 From: me at here.com (whitey) Date: Wed, 28 Jul 2010 12:50:47 GMT Subject: newb References: Message-ID: On Tue, 27 Jul 2010 19:19:59 -0700, Mithrandir wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 07/27/2010 04:07 AM, whitey wrote: >> hi all. am totally new to python and was wondering if there are any >> newsgroups that are there specifically for beginners. i have bought a >> book for $2 called "learn to program using python" by alan gauld. >> starting to read it but it was written in 2001. presuming that the >> commands and info would still be valid? any websites or books that are >> a must for beginners? any input would be much appreciated...cheers > > It may also depend on which version of Python you wish to use. Since > you're a "newb", I'd probably suggest starting off with Python 3. The > version in your book is probably version 2.*. The difference is minor, > but, when you're starting off (I assume with computer languages in > general?) the difference in syntax can kick you where it hurts. Programs > that work with Python 2.*, may not work with Python 3. However, I > suggest Python 3 since it seems to be the "code of tomorrow." > > It may also depend on what you wish to do with your knowledge of Python > (applications, games, web frameworks, etc.) If you want to make games, I > suggest also learning about pyGame. > > As for book versus website, I started off with, as others have > mentioned, learning online. Not only is it free, but the boundary > between page and screen is broken. Note though that some off-sites > (Wikibooks for instance) may not be complete in their writing. > Python.org has a wealth of knowledge about almost everything involving > Python. However, *some* of the documentation there may not be suitable > for absolute beginners. There are several links there to other good > websites for those with no experience in coding, all the way up to a > ridiculously complicated level. I highly suggest poking around there. > > If you wish to read a book instead, try: > http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/ dp/1435455002/ > Or go to your local library and poke there. :) > > Good luck! > > - -- > People should read more. > https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All > that is gold does not glitter, > not all those who wander are lost; > the old that is strong does not wither, deep roots are not reached by > the frost. - From the ashes a fire shall be woken, a light from the > shadows shall spring; renewed shall be blade that was broken, the > crownless again shall be king." > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI > 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH > yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim > Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw > pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 > x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW > -----END PGP SIGNATURE----- thank you all for the info. will definately check out your suggested links, really excited about learning to code and hopefully in the near future will be able to contribute somehow to the community. see you around... From wherespythonmonks at gmail.com Wed Jul 28 09:15:24 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Wed, 28 Jul 2010 09:15:24 -0400 Subject: Nice way to cast a homogeneous tuple Message-ID: A new python convert is now looking for a replacement for another perl idiom. In particular, since Perl is weakly typed, I used to be able to use unpack to unpack sequences from a string, that I could then use immediately as integers. In python, I find that when I use struct.unpack I tend to get strings. (Maybe I am using it wrong?) def f(x,y,z): print x+y+z; f( *struct.unpack('2s2s2s','123456')) 123456 (the plus concatenates the strings returned by unpack) But what I want is: f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) 102 But this seems too complicated. I see two resolutions: 1. There is a way using unpack to get out string-formatted ints? 2. There is something like map(lambda x: int(x).... without all the lambda function call overhead. (e.g., cast tuple)? [And yes: I know I can write my own "cast_tuple" function -- that's not my point. My point is that I want a super-native python inline solution like (hopefully shorter than) my "map" version above. I don't like defining trivial functions.] W From airscorp at otenet.gr Wed Jul 28 09:27:58 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Wed, 28 Jul 2010 16:27:58 +0300 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C50305E.3010603@otenet.gr> On 07/28/2010 04:15 PM, wheres pythonmonks wrote: > > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > But this seems too complicated. > > > Well, you don't need the lambda at all int === lambda x: int(x) So just write It's like writing: def myint(x): return int(x) Nick, Warm thanks to Steven D' Aprano who taught me that just yesterday in the Tutor list ;) From airscorp at otenet.gr Wed Jul 28 09:31:14 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Wed, 28 Jul 2010 16:31:14 +0300 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4C50305E.3010603@otenet.gr> References: <4C50305E.3010603@otenet.gr> Message-ID: <4C503122.3060208@otenet.gr> Ep, that missing line should be: On 07/28/2010 04:27 PM, Nick Raptis wrote: > On 07/28/2010 04:15 PM, wheres pythonmonks wrote: >> >> f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) >> 102 >> >> But this seems too complicated. >> >> > Well, you don't need the lambda at all > int === lambda x: int(x) > > So just write > f( *map(int, struct.unpack('2s2s2s', '123456'))) Pretty compact now, isn't it? > It's like writing: > def myint(x): > return int(x) > > > Nick, > > Warm thanks to Steven D' Aprano who taught me that just yesterday in > the Tutor list ;) From duncan.booth at invalid.invalid Wed Jul 28 09:31:21 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Jul 2010 13:31:21 GMT Subject: Nice way to cast a homogeneous tuple References: Message-ID: wheres pythonmonks wrote: > 2. There is something like map(lambda x: int(x).... without all the > lambda function call overhead. (e.g., cast tuple)? Yes there is: "lambda x: int(x)" is just a roundabout way of writing "int" -- Duncan Booth http://kupuguy.blogspot.com From wherespythonmonks at gmail.com Wed Jul 28 09:35:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Wed, 28 Jul 2010 09:35:52 -0400 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4C503122.3060208@otenet.gr> References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: Thanks ... I thought int was a type-cast (like in C++) so I assumed I couldn't reference it. On Wed, Jul 28, 2010 at 9:31 AM, Nick Raptis wrote: > Ep, that missing line should be: > > On 07/28/2010 04:27 PM, Nick Raptis wrote: >> >> On 07/28/2010 04:15 PM, wheres pythonmonks wrote: >>> >>> f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) >>> 102 >>> >>> But this seems too complicated. >>> >>> >> Well, you don't need the lambda at all >> int ? === ? ?lambda x: int(x) >> >> So just write >> > f( *map(int, struct.unpack('2s2s2s', '123456'))) > > Pretty compact now, isn't it? > >> It's like writing: >> def myint(x): >> ? ?return int(x) >> >> >> Nick, >> >> Warm thanks to Steven D' Aprano who taught me that just yesterday in the >> Tutor list ;) > > -- > http://mail.python.org/mailman/listinfo/python-list > From hexamorph at gmx.net Wed Jul 28 09:47:17 2010 From: hexamorph at gmx.net (Hexamorph) Date: Wed, 28 Jul 2010 15:47:17 +0200 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C5034E5.6080208@gmx.net> wheres pythonmonks wrote: > A new python convert is now looking for a replacement for another perl idiom. > > In particular, since Perl is weakly typed, I used to be able to use > unpack to unpack sequences from a string, that I could then use > immediately as integers. > > In python, I find that when I use struct.unpack I tend to get strings. > (Maybe I am using it wrong?) > > def f(x,y,z): print x+y+z; > > f( *struct.unpack('2s2s2s','123456')) > 123456 > > (the plus concatenates the strings returned by unpack) > > But what I want is: > > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > But this seems too complicated. > > I see two resolutions: > > 1. There is a way using unpack to get out string-formatted ints? > > 2. There is something like map(lambda x: int(x).... without all the > lambda function call overhead. (e.g., cast tuple)? > [And yes: I know I can write my own "cast_tuple" function -- that's > not my point. My point is that I want a super-native python inline > solution like (hopefully shorter than) my "map" version above. I > don't like defining trivial functions.] > > W In [31]: import re In [32]: sum(int(x) for x in re.findall("..", s)) Out[32]: 102 To get a tuple instead of the sum, just do: In [33]: tuple(int(x) for x in re.findall("..", s)) Out[33]: (12, 34, 56) From eckhardt at satorlaser.com Wed Jul 28 09:58:29 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 28 Jul 2010 15:58:29 +0200 Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <5lp5i7-f5u.ln1@satorlaser.homedns.org> wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Hopefully somebody correct me if I explain this badly, but I'll take a shot... Firstly, "int" is a class. Python doesn't make a distinction between builtin types and class types like C++, where you e.g. can't derive from builtin types. Secondly, the class is callable like a function. When called, it creates an instance of that class. Therefore, when you create an object it has a similar syntax as when calling a function. Lastly, classes are not special. Like any variable or function they can be referenced by a name or by multiple names, and thus be passed as parameters to a function. Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.42.desthuilliers at websiteburo.invalid Wed Jul 28 10:11:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 28 Jul 2010 16:11:22 +0200 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <4c503a7d$0$29585$426a34cc@news.free.fr> wheres pythonmonks a ?crit : > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Python has no C/C++ like "type-cast". "int" is the builtin integer type, and instanciating an object in Python is done by calling it's type. Remember that in Python, everything (at least everything you can bind to a name) is an object (including functions, types etc), and that functions are just one kind of callable objects (types - aka "classes" -, methods and a few other builtin objects are callable too, and you can of course define your own callable type). HTH From python.list at tim.thechases.com Wed Jul 28 10:14:06 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Jul 2010 09:14:06 -0500 Subject: Nice way to cast a homogeneous tuple In-Reply-To: References: Message-ID: <4C503B2E.7050902@tim.thechases.com> On 07/28/10 08:15, wheres pythonmonks wrote: > f( *map(lambda x: int(x), struct.unpack('2s2s2s','123456'))) > 102 > > 1. There is a way using unpack to get out string-formatted ints? well, you can use >>> s = '123456' >>> [int(s[i:i+2]) for i in range(0, len(s), 2)] [12, 34, 56] >>> f(*_) 102 While your "f()" is just a boring placeholder I assume, you could also write that as sum(int(s[i:i+2]) for i in range(0, len(s), 2)) and skip creating f() altogether if all it does is add its arguments. -tkc From steve at REMOVE-THIS-cybersource.com.au Wed Jul 28 10:32:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jul 2010 14:32:22 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> Message-ID: <4c503f75$0$11091$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > couldn't reference it. Python doesn't have type-casts in the sense of "tell the compiler to treat object of type A as type B instead". The closest Python has to that is that if you have an instance of class A, you can do this: a = A() # make an instance of class A a.__class__ = B # tell it that it's now class B and hope that it won't explode when you try to use it :/ I make that seem like a dangerous thing to do, but it's not really. There actually are sensible use-cases for such a thing, you can't do it to built-ins (which would be dangerous!), and the worst that will happen with classes written in Python is they'll raise an exception when you try calling a method, rather than dump core. Otherwise, all type conversions in Python create a new instance of the new type, and the conversion functions themselves (int, str, etc.) are actual type objects which you can pass around to functions: >>> type(int) Calling int(x) calls the int constructor with argument x, and returns a new int object. (In the *specific* case of int, it will sometimes cache small integers and re-use the same one multiple times, but don't count on that behaviour since it's an implementation-specific optimization.) -- Steven From krdean at gmail.com Wed Jul 28 11:11:41 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 08:11:41 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> Message-ID: <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> On Jul 27, 4:56?pm, MRAB wrote: > kBob wrote: > > On Jul 27, 4:23 pm, MRAB wrote: > >> kBob wrote: > > >>> ?I created a script to access weather satellite imagery fron NOAA's > >>> ADDS. > >>> ?It worked fine until recently with Python 2.6. > >>> ?The company changed the Internet LAN connections to "Accept Automatic > >>> settings" and "Use automatic configuration script" > >>> ?How do you get urllib.urlopen to use the the "automatic script" > >>> configuration? > >>> ?This code worked recently, until the company implemented these LAN > >>> connections... > >>> ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > >>> latest_BWI_vis.jpg" > >>> ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > >>> ? ? satimg = satpic.read() > >> For the record, I got: > > >> ?>>> import urllib > >> ?>>> SAT_URL = > >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > >> ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > >> Traceback (most recent call last): > >> ? ?File "", line 1, in > >> ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > >> ? ? ?opener = FancyURLopener(proxies=proxies) > >> ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > >> ? ? ?URLopener.__init__(self, *args, **kwargs) > >> ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > >> ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > >> AssertionError: proxies must be a mapping > > >> However, urllib.urlretrieve(...) works.- Hide quoted text - > > >> - Show quoted text - > > > I saw that, but I still get the same error time out error ... > > >>>> import urllib > >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" > >>>> SAT_FILE = "latest_BWI_vis.jpg" > >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > > Traceback (most recent call last): > > ? File "", line 1, in > > ? File "c:\python26\lib\urllib.py", line 93, in urlretrieve > > ? ? return _urlopener.retrieve(url, filename, reporthook, data) > > ? File "c:\python26\lib\urllib.py", line 237, in retrieve > > ? ? fp = self.open(url, data) > > ? File "c:\python26\lib\urllib.py", line 205, in open > > ? ? return getattr(self, name)(url) > > ? File "c:\python26\lib\urllib.py", line 344, in open_http > > ? ? h.endheaders() > > ? File "c:\python26\lib\httplib.py", line 904, in endheaders > > ? ? self._send_output() > > ? File "c:\python26\lib\httplib.py", line 776, in _send_output > > ? ? self.send(msg) > > ? File "c:\python26\lib\httplib.py", line 735, in send > > ? ? self.connect() > > ? File "c:\python26\lib\httplib.py", line 716, in connect > > ? ? self.timeout) > > ? File "c:\python26\lib\socket.py", line 514, in create_connection > > ? ? raise error, msg > > IOError: [Errno socket error] [Errno 10060] A connection attempt > > failed because > > the connected party did not properly respond after a period of time, > > or establis > > hed connection failed because connected host has failed to respond > > It should be like this: > > SAT_URL = > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > SAT_FILE = r"C:\latest_BWI_vis.jpg" > urllib.urlretrieve(SAT_URL, SAT_FILE)- Hide quoted text - > > - Show quoted text - It doesn't matter, the same error 10060 appears . The connection problem has to do with the proxy settings. In order for me to use Internet Explorer, the LAN's Automatic configuration must be turned on and use a script found on the company's proxy server. I was wondering how to get urllib.urlopen to access the script on the proxy server. Thanks for your help. Kelly From emile at fenx.com Wed Jul 28 11:22:33 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 28 Jul 2010 08:22:33 -0700 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: On 7/28/2010 4:23 AM Daniel Fetchinson said... > > Okay, that makes perfect sense, thanks for the exaplanation! > I'll just live with the platform.system( ) check for this particular > problem then. > If all else fails, repeating 24 (or 40,60?) lines feeds clears the screen cross platform. Emile From tartley at tartley.com Wed Jul 28 11:45:46 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 08:45:46 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > Daniel Fetchinson wrote: > > After getting the technicalities out of the way, maybe I should have > > asked: > > > Is it only me or others would find a platform independent python API > > to clear the terminal useful? > > There are two kinds of programs: > 1. Those that process input to output. If one of those suddenly started by > clearing my screen, I'd just dump it. Also, if output is redirected to a > file or piped into another program, that is basically useless or even > hurting, since you then end up with control sequences in the file. > > 2. Those that provide a text-based interactive UI. Those typically not only > clear the screen, but also control its whole layout and content, so there > you don't only need ways to clear the screen but also to position the > cursor or draw boxes etc. In that case you need a full "curses" library. > > Summary: No, I don't see the need for such an API. > > Cheers! > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 Hey, Your point seems good and I don't mean to contradict, but out of interest, what do you think about an example like the following: I want to write a quick script which, notices whenever I save my source code, and re-runs the unit tests, displaying the output. I think I'd like it to clear the terminal before each re-run of the tests, so that it's immediately obvious what is output from the current run, as opposed to previous runs. Then I can keep my editor focussed, but leave that running in a terminal and trust it to simply display the current output from my tests. I did dash off a quick and dirty version of this once which did a system 'clear' or 'cls' depending on the platform, but to my dismay I found that on Windows this caused focus to jump briefly to the terminal every time it ran 'clear' (!), making it extremely annoying in use. So I wished there had been a simple cross-platform way to clear the terminal. (this, and printing colored text, was my initial use case for starting 'colorama') Is this a silly desire of mine, or simply an uncommon edge case that therefore isn't really significant? Best regards, Jonathan From pavlovevidence at gmail.com Wed Jul 28 11:47:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 28 Jul 2010 08:47:52 -0700 (PDT) Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Jul 28, 7:32?am, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > > couldn't reference it. > > Python doesn't have type-casts in the sense of "tell the compiler to > treat object of type A as type B instead". The closest Python has to that > is that if you have an instance of class A, you can do this: > > a = A() ?# make an instance of class A > a.__class__ = B ?# tell it that it's now class B > > and hope that it won't explode when you try to use it :/ Type casts in C and non-pathlogical C++ don't modify the object they are casting. int (and str, float, etc.) is the closest thing to a type cast in Python. Carl Banks From tartley at tartley.com Wed Jul 28 12:01:38 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 09:01:38 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Jul 28, 4:45?pm, Jonathan Hartley wrote: > On Jul 28, 8:08?am, Ulrich Eckhardt wrote: > > > > > Daniel Fetchinson wrote: > > > After getting the technicalities out of the way, maybe I should have > > > asked: > > > > Is it only me or others would find a platform independent python API > > > to clear the terminal useful? > > > There are two kinds of programs: > > 1. Those that process input to output. If one of those suddenly started by > > clearing my screen, I'd just dump it. Also, if output is redirected to a > > file or piped into another program, that is basically useless or even > > hurting, since you then end up with control sequences in the file. > > > 2. Those that provide a text-based interactive UI. Those typically not only > > clear the screen, but also control its whole layout and content, so there > > you don't only need ways to clear the screen but also to position the > > cursor or draw boxes etc. In that case you need a full "curses" library. > > > Summary: No, I don't see the need for such an API. > > > Cheers! > > > Uli > > > -- > > Sator Laser GmbH > > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > Hey, > > Your point seems good and I don't mean to contradict, but out of > interest, what do you think about an example like the following: > > I want to write a quick script which, notices whenever I save my > source code, and re-runs the unit tests, displaying the output. I > think I'd like it to clear the terminal before each re-run of the > tests, so that it's immediately obvious what is output from the > current run, as opposed to previous runs. Then I can keep my editor > focussed, but leave that running in a terminal and trust it to simply > display the current output from my tests. > > I did dash off a quick and dirty version of this once which did a > system 'clear' or 'cls' depending on the platform, but to my dismay I > found that on Windows this caused focus to jump briefly to the > terminal every time it ran 'clear' (!), making it extremely annoying > in use. So I wished there had been a simple cross-platform way to > clear the terminal. (this, and printing colored text, was my initial > use case for starting 'colorama') > > Is this a silly desire of mine, or simply an uncommon edge case that > therefore isn't really significant? > > Best regards, > > ? Jonathan Oh, plus, while we're on this subject: Am I right that curses in Python stdlib doesn't work on Windows, and there is currently no simple way to fix this? Also, is it crazy to imagine that if colorama was pushed through to completion (ie. to support a majority of the relevant ANSI codes) then Python's stdlib curses module, unmodified, would suddenly just work on Windows? (after a call to 'colorama.init()') I presume these ideas are oversimplifications or just plain wrong. If anyone would care to correct my misunderstandings, I'd be very grateful. From neilc at norwich.edu Wed Jul 28 12:06:06 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Jul 2010 16:06:06 GMT Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <8bb2reF616U1@mid.individual.net> On 2010-07-28, Jonathan Hartley wrote: > I want to write a quick script which, notices whenever I save > my source code, and re-runs the unit tests, displaying the > output. I think I'd like it to clear the terminal before each > re-run of the tests, so that it's immediately obvious what is > output from the current run, as opposed to previous runs. Then > I can keep my editor focussed, but leave that running in a > terminal and trust it to simply display the current output from > my tests. Perhaps emailing the tests to yourself would be a good solution. Every tme the tests ran, you'd get a new email containing the results. -- Neil Cerutti From krdean at gmail.com Wed Jul 28 12:30:26 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 09:30:26 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> Message-ID: <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> On Jul 28, 9:11?am, kBob wrote: > On Jul 27, 4:56?pm, MRAB wrote: > > > > > > > kBob wrote: > > > On Jul 27, 4:23 pm, MRAB wrote: > > >> kBob wrote: > > > >>> ?I created a script to access weather satellite imagery fron NOAA's > > >>> ADDS. > > >>> ?It worked fine until recently with Python 2.6. > > >>> ?The company changed the Internet LAN connections to "Accept Automatic > > >>> settings" and "Use automatic configuration script" > > >>> ?How do you get urllib.urlopen to use the the "automatic script" > > >>> configuration? > > >>> ?This code worked recently, until the company implemented these LAN > > >>> connections... > > >>> ? ? SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > >>> latest_BWI_vis.jpg" > > >>> ? ? satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > >>> ? ? satimg = satpic.read() > > >> For the record, I got: > > > >> ?>>> import urllib > > >> ?>>> SAT_URL = > > >> "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > > >> ?>>> satpic = urllib.urlopen(SAT_URL, proxies=0 ) > > >> Traceback (most recent call last): > > >> ? ?File "", line 1, in > > >> ? ?File "C:\Python26\lib\urllib.py", line 79, in urlopen > > >> ? ? ?opener = FancyURLopener(proxies=proxies) > > >> ? ?File "C:\Python26\lib\urllib.py", line 617, in __init__ > > >> ? ? ?URLopener.__init__(self, *args, **kwargs) > > >> ? ?File "C:\Python26\lib\urllib.py", line 129, in __init__ > > >> ? ? ?assert hasattr(proxies, 'has_key'), "proxies must be a mapping" > > >> AssertionError: proxies must be a mapping > > > >> However, urllib.urlretrieve(...) works.- Hide quoted text - > > > >> - Show quoted text - > > > > I saw that, but I still get the same error time out error ... > > > >>>> import urllib > > >>>> SAT_URL = "http://adds.aviationweather.gov/data/satellite/" > > >>>> SAT_FILE = "latest_BWI_vis.jpg" > > >>>> satimg = urllib.urlretrieve( SAT_URL, SAT_FILE ) > > > Traceback (most recent call last): > > > ? File "", line 1, in > > > ? File "c:\python26\lib\urllib.py", line 93, in urlretrieve > > > ? ? return _urlopener.retrieve(url, filename, reporthook, data) > > > ? File "c:\python26\lib\urllib.py", line 237, in retrieve > > > ? ? fp = self.open(url, data) > > > ? File "c:\python26\lib\urllib.py", line 205, in open > > > ? ? return getattr(self, name)(url) > > > ? File "c:\python26\lib\urllib.py", line 344, in open_http > > > ? ? h.endheaders() > > > ? File "c:\python26\lib\httplib.py", line 904, in endheaders > > > ? ? self._send_output() > > > ? File "c:\python26\lib\httplib.py", line 776, in _send_output > > > ? ? self.send(msg) > > > ? File "c:\python26\lib\httplib.py", line 735, in send > > > ? ? self.connect() > > > ? File "c:\python26\lib\httplib.py", line 716, in connect > > > ? ? self.timeout) > > > ? File "c:\python26\lib\socket.py", line 514, in create_connection > > > ? ? raise error, msg > > > IOError: [Errno socket error] [Errno 10060] A connection attempt > > > failed because > > > the connected party did not properly respond after a period of time, > > > or establis > > > hed connection failed because connected host has failed to respond > > > It should be like this: > > > SAT_URL = > > "http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg" > > SAT_FILE = r"C:\latest_BWI_vis.jpg" > > urllib.urlretrieve(SAT_URL, SAT_FILE)- Hide quoted text - > > > - Show quoted text - > > It doesn't matter, the same error 10060 appears . > > The connection problem has to do with the proxy settings. > > ?In order for me to use Internet Explorer, the LAN's Automatic > configuration must be turned on and use a script found on the > company's proxy server. I was wondering how to get urllib.urlopen to > access the script on the proxy server. > > Thanks for your help. > > Kelly- Hide quoted text - > > - Show quoted text - OK, looks like I need to start a new thread..... How to get urllib to work with a Web Proxy Auto-Discovery Protocol (WPAD)? Kelly From thomas at jollans.com Wed Jul 28 12:47:28 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 18:47:28 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <4C505F20.6010103@jollans.com> On 07/28/2010 06:01 PM, Jonathan Hartley wrote: > > Oh, plus, while we're on this subject: > > Am I right that curses in Python stdlib doesn't work on Windows, and > there is currently no simple way to fix this? > > Also, is it crazy to imagine that if colorama was pushed through to > completion (ie. to support a majority of the relevant ANSI codes) then > Python's stdlib curses module, unmodified, would suddenly just work on > Windows? (after a call to 'colorama.init()') > > I presume these ideas are oversimplifications or just plain wrong. If > anyone would care to correct my misunderstandings, I'd be very > grateful. Correct: it's not THAT simple. Python's curses module is a (I'm not sure how thin) wrapper around the good old UNIX curses (ncurses, ...) library. This is written in C, not Python, so it doesn't use Python's sys.stdout object to do I/O. I haven't had a look at colorama, but it sounds like it hooks into sys.stdout, or Python file objects anyway. Far, far above the layer curses does I/O on. So, if you ported a normal curses library to Windows, colorama wouldn't help you a bit. It might be possible to write a curses-compatible library that works with cmd.exe. Maybe. But, even if it's possible, I don't think it's easy, and I especially don't think it would be particularly rewarding. Also, I just stumbled upon http://adamv.com/dev/python/curses/ -- this is probably the only reasonable way to get a useful curses API on Windows: forget the DOS box. From schrabacke at web.de Wed Jul 28 12:57:42 2010 From: schrabacke at web.de (hardi) Date: Wed, 28 Jul 2010 09:57:42 -0700 (PDT) Subject: Linear nterpolation in 3D Message-ID: <29288748.post@talk.nabble.com> Hi, I'm trying to interpolate a 3D data (from the pic attached) with the interp2d command. What I have, are three vectors f, z, A (x, y, z respectively, A is the percentage data given on the isolines). I first put the f and z in a meshgrid and afterwards in the griddata to get a 3D-grid then started to interpolate. I plotted the the data after gridding, and I observed that almost all nodes are ignored. Do you have any idea how to prepare data to the interp2d command? my code so far is: import numpy as np from mpl_toolkits.mplot3d import axes3d from scipy.interpolate import interp2d import matplotlib.pyplot as plt from matplotlib import mlab plt.clf() fig = plt.figure(1) ax = axes3d.Axes3D(fig) #read data (ff,ZZ,A,a) = np.loadtxt("accuracy-map.txt", unpack=True) f=np.log10(ff) z=np.log10(ZZ) ##grid everything fgrid, zgrid=np.meshgrid(f,z) #define grid ef=np.linspace(min(f), max(f), len(f)) ez=np.linspace(min(z), max(z), len(f)) Agrid=mlab.griddata(f,z,A, ef,ez) int2d=interp2d(fgrid, zgrid, Agrid, kind='linear') ax.plot(f, z, A, 'ok', markerfacecolor='w') ax.plot_surface(fgrid, zgrid, Agrid) ax.set_xlim3d((min(f), max(f))) ax.set_ylim3d(min(z), max(z)) ax.set_zlim3d(0,100) plt.show() http://old.nabble.com/file/p29288748/novo-error.pdf novo-error.pdf -- View this message in context: http://old.nabble.com/Linear-nterpolation-in-3D-tp29288748p29288748.html Sent from the Python - python-list mailing list archive at Nabble.com. From ethan at stoneleaf.us Wed Jul 28 12:59:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Jul 2010 09:59:01 -0700 Subject: hasattr + __getattr__: I think this is Python bug In-Reply-To: <4c4fe0bf$0$29093$426a74cc@news.free.fr> References: <29b87963-23b8-47d5-92c3-2f176a92bb74@s9g2000yqd.googlegroups.com> <4c4d618b$0$9222$426a74cc@news.free.fr> <4c4d88a4$0$9187$426a74cc@news.free.fr> <4c4e88f4$0$14554$426a74cc@news.free.fr> <4c4e8a95$0$24098$426a74cc@news.free.fr> <4c4fe0bf$0$29093$426a74cc@news.free.fr> Message-ID: <4C5061D5.7070802@stoneleaf.us> Bruno Desthuilliers wrote: > Ethan Furman a ?crit : >> Bruno Desthuilliers wrote: >>> Bruno Desthuilliers a ?crit : >>>> Ethan Furman a ?crit : >>>>> Bruno Desthuilliers wrote: >>>>>> Duncan Booth a ?crit : >>>> (snip) >>>> >>>>>>> Or you could create the default as a class attribute >>>>>> >>>>>> from the OP: >>>>>> """ >>>>>> I have a class (FuncDesigner oofun) that has no attribute "size", but >>>>>> it is overloaded in __getattr__, so if someone invokes >>>>>> "myObject.size", it is generated (as another oofun) and connected to >>>>>> myObject as attribute. >>>>>> """ >>>>>> >>>>>> so this solution won't obviously work in this case !-) >>>>>> >>>>>> Also and FWIW, I wouldn't advocate this solution if the "default" >>>>>> class attribute is of a mutable type. >>>>> >>>>> Well, it is Monday, so I may be missing something obvious, but what >>>>> is the effective difference between these two solutions? >>>> >>> >>> If you meant "what is the difference between creating the "whatever" >>> attribute with a default value in the initializer and creating it on >>> demand in the __getattr__ hook", the main difference is that in the >>> first case, the instance is garanteed to have this attribute, so you >>> get rid of "hasattr" checks (and the unwanted side effects) or, >>> worse, direct check of the instance __dict__. Except for a couple of >>> corner case, client code shouldn't have to worry about this kind of >>> things - this breaks encapsulation. >> >> Yay Tuesday! :D >> >> What I meant was what is the difference between: >> >> [Bruno Desthuilliers] >> > DEFAULT_WHATEVER = Whathever() >> > class MyClass(object): >> > def __init__(self, x, y): >> > self.size = DEFAULT_WHATEVER >> >> and >> >> [Duncan Booth] >> > class MyClass(object): >> > size = Whatever() >> > def __init__(self, x, y): >> > ... >> >> in both cases the object ends up with a size attribute and no further >> need of __getattr__. Of course, the warning about having a mutable >> object as a class attribute stands. > > Indeed. > >> To phrase it another way, why does your solution (Bruno) work, but >> Duncan's "obviously won't"? > > As it is written (and assuming the name "Whatever" is bound to a > callable !-)), Duncan's code would work, even if it might not be the > safest solution in the case of a mutable type. > > The problem here is that the OP stated that the "size" attribute was to > be of the same type as the host class, so the code would look something > like: > > class MyClass(object): > size = MyClass() > > which will raise a NameError, since MyClass is not yet defined when > "size=MyClass()" is executed. Ah ha! I *knew* I was missing something. Thank you for the explanation. So the correct methods, then, would be to either include the size attribute in the __init__, or add it to the class /after/ the class was defined. I feel much better now... slightly silly, but better. ;) ~Ethan~ From tartley at tartley.com Wed Jul 28 13:02:52 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 28 Jul 2010 10:02:52 -0700 (PDT) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Jul 28, 5:47?pm, Thomas Jollans wrote: > On 07/28/2010 06:01 PM, Jonathan Hartley wrote: > > > > > Oh, plus, while we're on this subject: > > > Am I right that curses in Python stdlib doesn't work on Windows, and > > there is currently no simple way to fix this? > > > Also, is it crazy to imagine that if colorama was pushed through to > > completion (ie. to support a majority of the relevant ANSI codes) then > > Python's stdlib curses module, unmodified, would suddenly just work on > > Windows? (after a call to 'colorama.init()') > > > I presume these ideas are oversimplifications or just plain wrong. If > > anyone would care to correct my misunderstandings, I'd be very > > grateful. > > Correct: it's not THAT simple. > > Python's curses module is a (I'm not sure how thin) wrapper around the > good old UNIX curses (ncurses, ...) library. This is written in C, not > Python, so it doesn't use Python's sys.stdout object to do I/O. > > I haven't had a look at colorama, but it sounds like it hooks into > sys.stdout, or Python file objects anyway. Far, far above the layer > curses does I/O on. So, if you ported a normal curses library to > Windows, colorama wouldn't help you a bit. > > It might be possible to write a curses-compatible library that works > with cmd.exe. Maybe. But, even if it's possible, I don't think it's > easy, and I especially don't think it would be particularly rewarding. > > Also, I just stumbled uponhttp://adamv.com/dev/python/curses/-- this > is probably the only reasonable way to get a useful curses API on > Windows: forget the DOS box. > ncurses ... is written in C, not > Python, so it doesn't use Python's sys.stdout object to do I/O. Ah, I should have spotted that. Of course. Thanks for the enlightenment. And Neil Cerutti, I think I'll just email the whole source tree to myself, and have a script that scans my inbox, unzips source trees and runs their tests. Much nicer. :-) From thomas at jollans.com Wed Jul 28 13:31:37 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 19:31:37 +0200 Subject: Why is there no platform independent way of clearing a terminal? In-Reply-To: References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <4C506979.4030809@jollans.com> On 07/28/2010 07:02 PM, Jonathan Hartley wrote: > On Jul 28, 5:47 pm, Thomas Jollans wrote: >> On 07/28/2010 06:01 PM, Jonathan Hartley wrote: >> >> >> >>> Oh, plus, while we're on this subject: >> >>> Am I right that curses in Python stdlib doesn't work on Windows, and >>> there is currently no simple way to fix this? >> >>> Also, is it crazy to imagine that if colorama was pushed through to >>> completion (ie. to support a majority of the relevant ANSI codes) then >>> Python's stdlib curses module, unmodified, would suddenly just work on >>> Windows? (after a call to 'colorama.init()') >> >>> I presume these ideas are oversimplifications or just plain wrong. If >>> anyone would care to correct my misunderstandings, I'd be very >>> grateful. >> >> Correct: it's not THAT simple. >> >> Python's curses module is a (I'm not sure how thin) wrapper around the >> good old UNIX curses (ncurses, ...) library. This is written in C, not >> Python, so it doesn't use Python's sys.stdout object to do I/O. >> >> I haven't had a look at colorama, but it sounds like it hooks into >> sys.stdout, or Python file objects anyway. Far, far above the layer >> curses does I/O on. So, if you ported a normal curses library to >> Windows, colorama wouldn't help you a bit. >> >> It might be possible to write a curses-compatible library that works >> with cmd.exe. Maybe. But, even if it's possible, I don't think it's >> easy, and I especially don't think it would be particularly rewarding. >> >> Also, I just stumbled uponhttp://adamv.com/dev/python/curses/-- this >> is probably the only reasonable way to get a useful curses API on >> Windows: forget the DOS box. > > > >> ncurses ... is written in C, not >> Python, so it doesn't use Python's sys.stdout object to do I/O. > > Ah, I should have spotted that. Of course. Thanks for the > enlightenment. > > And Neil Cerutti, I think I'll just email the whole source tree to > myself, and have a script that scans my inbox, unzips source trees and > runs their tests. Much nicer. :-) use version control! Use mercurial, commit often, and add a commit-hook that runs tests. Then you can even set up a separate repository that your script automatically pushes your changes to if they pass the tests cleanly. From clp2 at rebertia.com Wed Jul 28 14:06:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 11:06:20 -0700 Subject: Linear nterpolation in 3D In-Reply-To: <29288748.post@talk.nabble.com> References: <29288748.post@talk.nabble.com> Message-ID: On Wed, Jul 28, 2010 at 9:57 AM, hardi wrote: > Hi, > > I'm trying to interpolate a 3D data (from the pic attached) with the > interp2d command. What I have, are three vectors f, z, A (x, y, z > respectively, A is the percentage data given on the isolines). I first put > the f and z in a meshgrid and afterwards in the griddata to get a 3D-grid > then started to interpolate. I plotted the the data after gridding, and I > observed that almost all nodes are ignored. > Do you have any idea how to prepare data to the interp2d command? Since interp2d() is part of SciPy, you may have better luck asking on the SciPy-specific mailinglist: http://mail.scipy.org/mailman/listinfo/scipy-user Cheers, Chris From clp2 at rebertia.com Wed Jul 28 14:11:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 11:11:20 -0700 Subject: urllib timeout In-Reply-To: <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <54cd5b29-72c2-4b78-aa71-6c6bf54c051a@q21g2000prm.googlegroups.com> <8b93d00d-1417-4bbb-8bea-f4b9b9a41933@u4g2000prn.googlegroups.com> <241d0188-241c-4f7a-a513-340ff424ef6e@x24g2000pro.googlegroups.com> Message-ID: On Wed, Jul 28, 2010 at 9:30 AM, kBob wrote: > On Jul 28, 9:11?am, kBob wrote: >> The connection problem has to do with the proxy settings. >> >> ?In order for me to use Internet Explorer, the LAN's Automatic >> configuration must be turned on and use a script found on the >> company's proxy server. I was wondering how to get urllib.urlopen to >> access the script on the proxy server. >> >> Thanks for your help. >> >> Kelly- Hide quoted text - >> >> - Show quoted text - > > OK, looks like I need to start a new thread..... > > ?How to get urllib to work with a Web Proxy Auto-Discovery Protocol > (WPAD)? Would this be of any help?: http://code.google.com/p/pacparser/ Cheers, Chris From joe at goldthwaites.com Wed Jul 28 14:32:44 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 11:32:44 -0700 Subject: Ascii to Unicode. Message-ID: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Hi, I've got an Ascii file with some latin characters. Specifically \xe1 and \xfc. I'm trying to import it into a Postgresql database that's running in Unicode mode. The Unicode converter chokes on those two characters. I could just manually replace those to characters with something valid but if any other invalid characters show up in later versions of the file, I'd like to handle them correctly. I've been playing with the Unicode stuff and I found out that I could convert both those characters correctly using the latin1 encoder like this; import unicodedata s = '\xe1\xfc' print unicode(s,'latin1') The above works. When I try to convert my file however, I still get an error; import unicodedata input = file('ascii.csv', 'r') output = file('unicode.csv','w') for line in input.xreadlines(): output.write(unicode(line,'latin1')) input.close() output.close() Traceback (most recent call last): File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ output.write(unicode(line,'latin1')) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 295: ordinal not in range(128) I'm stuck using Python 2.4.4 which may be handling the strings differently depending on if they're in the program or coming from the file. I just haven't been able to figure out how to get the Unicode conversion working from the file data. Can anyone explain what is going on? From neilc at norwich.edu Wed Jul 28 14:37:15 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Jul 2010 18:37:15 GMT Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: <8bbbmrFvakU1@mid.individual.net> On 2010-07-28, Jonathan Hartley wrote: > And Neil Cerutti, I think I'll just email the whole source tree > to myself, and have a script that scans my inbox, unzips source > trees and runs their tests. Much nicer. :-) Don't forget to clear the screen, though. That ties the whole program together. -- Neil Cerutti From nagle at animats.com Wed Jul 28 14:44:37 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 11:44:37 -0700 Subject: urllib timeout In-Reply-To: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: <4c507a92$0$1643$742ec2ed@news.sonic.net> On 7/27/2010 2:36 PM, kBob wrote: > > > I created a script to access weather satellite imagery fron NOAA's > ADDS. > > It worked fine until recently with Python 2.6. > > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" > > How do you get urllib.urlopen to use the the "automatic script" > configuration? > > This code worked recently, until the company implemented these LAN > connections... > > SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > latest_BWI_vis.jpg" Try https://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg The aviationweather.gov site will accept a HTTPS request. Maybe that will bypass whatever lame web proxy is in the way. John Nagle From python at mrabarnett.plus.com Wed Jul 28 15:20:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 28 Jul 2010 20:20:33 +0100 Subject: Ascii to Unicode. In-Reply-To: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> References: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Message-ID: <4C508301.4020001@mrabarnett.plus.com> Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) > > input.close() > output.close() > > Traceback (most recent call last): > File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) > > I'm stuck using Python 2.4.4 which may be handling the strings differently > depending on if they're in the program or coming from the file. I just > haven't been able to figure out how to get the Unicode conversion working > from the file data. > > Can anyone explain what is going on? > What you need to remember is that files contain bytes. When you say "ASCII file" what you mean is that the file contains bytes which represent text encoded as ASCII, and such a file by definition can't contain bytes outside the range 0-127. Therefore your file isn't an ASCII file. So then you've decided to treat it as a file containing bytes which represent text encoded as Latin-1. You're reading bytes from a file, decoding them to Unicode, and then trying to write them to a file, but the output file expects bytes (did I say that files contain bytes? :-)), so it's trying to encode back to bytes using the default encoding, which is ASCII. u'\xe1' can't be encoded as ASCII, therefore UnicodeEncodeError is raised. From thomas at jollans.com Wed Jul 28 15:21:46 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 21:21:46 +0200 Subject: Ascii to Unicode. In-Reply-To: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> References: <124F1C2D3A8047B3BDF0374060C94F2B@NewMBP> Message-ID: <4C50834A.30900@jollans.com> On 07/28/2010 08:32 PM, Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') output is still a binary file - there are no unicode files. You need to encode the text somehow. > Traceback (most recent call last): > File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) by default, Python tries to encode strings using ASCII. This, obviously, won't work here. Do you know which encoding your database expects ? I'd assume it'd understand UTF-8. Everybody uses UTF-8. > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) unicode(line, 'latin1') is unicode, you need it to be a UTF-8 bytestring: unicode(line, 'latin1').encode('utf-8') or: line.decode('latin1').encode('utf-8') From nagle at animats.com Wed Jul 28 15:29:36 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 12:29:36 -0700 Subject: Ascii to Unicode. In-Reply-To: References: Message-ID: <4c50851c$0$1677$742ec2ed@news.sonic.net> On 7/28/2010 11:32 AM, Joe Goldthwaite wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > > import unicodedata > > s = '\xe1\xfc' > print unicode(s,'latin1') > > > The above works. When I try to convert my file however, I still get an > error; > > import unicodedata > > input = file('ascii.csv', 'r') > output = file('unicode.csv','w') > > for line in input.xreadlines(): > output.write(unicode(line,'latin1')) > > input.close() > output.close() > Try this, which will get you a UTF-8 file, the usual standard for Unicode in a file. for rawline in input : unicodeline = unicode(line,'latin1') # Latin-1 to Unicode output.write(unicodeline.encode('utf-8')) # Unicode to as UTF-8 John Nagle From thomas at jollans.com Wed Jul 28 15:40:23 2010 From: thomas at jollans.com (Thomas Jollans) Date: Wed, 28 Jul 2010 21:40:23 +0200 Subject: Ascii to Unicode. In-Reply-To: <4c50851c$0$1677$742ec2ed@news.sonic.net> References: <4c50851c$0$1677$742ec2ed@news.sonic.net> Message-ID: <4C5087A7.6000300@jollans.com> On 07/28/2010 09:29 PM, John Nagle wrote: > for rawline in input : > unicodeline = unicode(line,'latin1') # Latin-1 to Unicode > output.write(unicodeline.encode('utf-8')) # Unicode to as UTF-8 you got your blocks wrong. From usernet at ilthio.net Wed Jul 28 16:28:04 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 28 Jul 2010 20:28:04 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On 2010-07-28, Thomas Jollans wrote: > It might be possible to write a curses-compatible library that works > with cmd.exe. Maybe. But, even if it's possible, I don't think it's > easy, and I especially don't think it would be particularly rewarding. http://pdcurses.sourceforge.net/ It would be rewarding as it would make writing cross-platform charactor mode applications possible. Using curses for the interface makes a lot of sense because it is already supported by almost every Unix/POSIX platorm, so re-implementation is only required for those odd platforms (Windows) where it does not exist natively,; because well documented on the internet and in print; and because a huge number of people are already familiar with its API. If licensing permits, I don't think it would be too difficult difficult to embed something like pdcurses into the existing curses module to use as a backup for platforms where curses does not already exist. If not, there cannot be much difference to writing a terminal emulator that runs inside the windows console and there are a *huge* number of terminal emulators available for ansi/vt100 terminals. Add a termcap database mechanism and an embedded emulator can easily convert the excape codes into actions for the console. From martin at address-in-sig.invalid Wed Jul 28 16:28:23 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Wed, 28 Jul 2010 20:28:23 +0000 (UTC) Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: On Wed, 28 Jul 2010 09:01:38 -0700, Jonathan Hartley wrote: > Also, is it crazy to imagine that if colorama was pushed through to > completion (ie. to support a majority of the relevant ANSI codes) then > Python's stdlib curses module, unmodified, would suddenly just work on > Windows? (after a call to 'colorama.init()') > Curses was originally built on top of termcap, a much simpler and more primitive library. Its abilities are: - read the termcap database to find and load the capability list of the terminal identified as the TERM environment variable. - write a named capability to the screen. If the capability isn't defined for the current terminal its silently ignored. - fill in x, y and write the cursor movement string - thats about it. Its easy enough to find termcap databases. They're just text files containing a block of attribute values for each terminal, normally including ANSI terminals, Linux consoles, X-terms etc. They are also fairly easy to parse, even in vanilla C, so parsing one on Python should be a breeze. Termcap format specs and lists of standard attribute names are easy enough to find too. IOW, if you extend colorama to read its codes from a termcap database you'll have a basic but easily portable character console handler that can at least clear the screen, move the cursor and, if the screen has the capability, change the colour of characters or make them bold/dim/blink etc. To give you an idea of how complex this is, I've re-implemented termcap in Java for my own purposes. It amounts to 1100 lines of fairly well spaced and commented Java or about 340 statements, which were estimated by counting lines containing semicolons. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From debatem1 at gmail.com Wed Jul 28 17:39:27 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 14:39:27 -0700 Subject: newb In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 5:50 AM, whitey wrote: > On Tue, 27 Jul 2010 19:19:59 -0700, Mithrandir wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> On 07/27/2010 04:07 AM, whitey wrote: >>> hi all. am totally new to python and was wondering if there are any >>> newsgroups that are there specifically for beginners. i have bought a >>> book for $2 called "learn to program using python" by alan gauld. >>> starting to read it but it was written in 2001. presuming that the >>> commands and info would still be valid? any websites or books that are >>> a must for beginners? any input would be much appreciated...cheers >> >> It may also depend on which version of Python you wish to use. Since >> you're a "newb", I'd probably suggest starting off with Python 3. The >> version in your book is probably version 2.*. The difference is minor, >> but, when you're starting off (I assume with computer languages in >> general?) the difference in syntax can kick you where it hurts. Programs >> that work with Python 2.*, may not work with Python 3. However, I >> suggest Python 3 since it seems to be the "code of tomorrow." >> >> It may also depend on what you wish to do with your knowledge of Python >> (applications, games, web frameworks, etc.) If you want to make games, I >> suggest also learning about pyGame. >> >> As for book versus website, I started off with, as others have >> mentioned, learning online. Not only is it free, but the boundary >> between page and screen is broken. Note though that some off-sites >> (Wikibooks for instance) may not be complete in their writing. >> Python.org has a wealth of knowledge about almost everything involving >> Python. However, *some* of the documentation there may not be suitable >> for absolute beginners. There are several links there to other good >> websites for those with no experience in coding, all the way up to a >> ridiculously complicated level. I highly suggest poking around there. >> >> If you wish to read a book instead, try: >> http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/ > dp/1435455002/ >> Or go to your local library and poke there. :) >> >> Good luck! >> >> - -- >> People should read more. >> https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain "All >> that is gold does not glitter, >> not all those who wander are lost; >> the old that is strong does not wither, deep roots are not reached by >> the frost. - From the ashes a fire shall be woken, a light from the >> shadows shall spring; renewed shall be blade that was broken, the >> crownless again shall be king." >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.10 (GNU/Linux) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ >> >> iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI >> 7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH >> yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim >> Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw >> pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2 >> x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E= =cEZW >> -----END PGP SIGNATURE----- > > thank you all for the info. will definately check out your suggested > links, really excited about learning to code and hopefully in the near > future will be able to contribute somehow to the community. see you > around... If you're new to programming overall, you might want to check out project euler too. Geremy Condra From sjmachin at lexicon.net Wed Jul 28 17:39:42 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 28 Jul 2010 14:39:42 -0700 (PDT) Subject: Ascii to Unicode. References: Message-ID: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> On Jul 29, 4:32?am, "Joe Goldthwaite" wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc. ?I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manually replace those to characters with something valid but > if any other invalid characters show up in later versions of the file, I'd > like to handle them correctly. > > I've been playing with the Unicode stuff and I found out that I could > convert both those characters correctly using the latin1 encoder like this; > > ? ? ? ? import unicodedata > > ? ? ? ? s = '\xe1\xfc' > ? ? ? ? print unicode(s,'latin1') > > The above works. ?When I try to convert my file however, I still get an > error; > > ? ? ? ? import unicodedata > > ? ? ? ? input = file('ascii.csv', 'r') > ? ? ? ? output = file('unicode.csv','w') > > ? ? ? ? for line in input.xreadlines(): > ? ? ? ? ? ? ? ? output.write(unicode(line,'latin1')) > > ? ? ? ? input.close() > ? ? ? ? output.close() > > Traceback (most recent call last): > ? File "C:\Users\jgold\CloudmartFiles\UnicodeTest.py", line 10, in __main__ > ? ? output.write(unicode(line,'latin1')) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position > 295: ordinal not in range(128) > > I'm stuck using Python 2.4.4 which may be handling the strings differently > depending on if they're in the program or coming from the file. ?I just > haven't been able to figure out how to get the Unicode conversion working > from the file data. > > Can anyone explain what is going on? Hello hello ... you are running on Windows; the likelihood that you actually have data encoded in latin1 is very very small. Follow MRAB's answer but replace "latin1" by "cp1252". From krdean at gmail.com Wed Jul 28 17:44:04 2010 From: krdean at gmail.com (kBob) Date: Wed, 28 Jul 2010 14:44:04 -0700 (PDT) Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> <4c507a92$0$1643$742ec2ed@news.sonic.net> Message-ID: <9147d851-d195-49d5-ad1b-ec1160324c71@u4g2000prn.googlegroups.com> On Jul 28, 12:44?pm, John Nagle wrote: > On 7/27/2010 2:36 PM, kBob wrote: > > > > > > > > > ? I created a script to access weather satellite imagery fron NOAA's > > ADDS. > > > ? It worked fine until recently with Python 2.6. > > > ? The company changed the Internet LAN connections to "Accept Automatic > > settings" and "Use automatic configuration script" > > > ? How do you get urllib.urlopen to use the the "automatic script" > > configuration? > > > ? This code worked recently, until the company implemented these LAN > > connections... > > > ? ? ?SAT_URL = "http://adds.aviationweather.gov/data/satellite/ > > latest_BWI_vis.jpg" > > ? ?Try > > https://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg > > ? ?The aviationweather.gov site will accept a HTTPS request. > > ? ?Maybe that will bypass whatever lame web proxy is in the way. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle- Hide quoted text - > > - Show quoted text - Same error - 10060. Thanks for the suggestion. Kelly From robert.faryabi at gmail.com Wed Jul 28 17:57:02 2010 From: robert.faryabi at gmail.com (Robert Faryabi) Date: Wed, 28 Jul 2010 17:57:02 -0400 Subject: Tabular Package: importing file Message-ID: Hi there; I'm using Tabular Package for manipulating tab-delimited data. There is a small problem that I cannot get my head around it. When I construct my tabarray from file, the black fields are replaced by "nan". Does any one knows how to just keep them as empty string (ie. ' ')? Thanks, -R -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jul 28 18:16:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Jul 2010 18:16:18 -0400 Subject: python terminology on classes In-Reply-To: <4c4f1731$0$1602$742ec2ed@news.sonic.net> References: <4c4e8801$0$14554$426a74cc@news.free.fr> <4c4f1731$0$1602$742ec2ed@news.sonic.net> Message-ID: On 7/27/2010 1:28 PM, John Nagle wrote: > Python 2.6 has a recently added "with" clause, borrowed from > LISP, for associating actions with scopes. This is supported for > files and locks, but setting your own object up for "with" > requires adding special methods to the object. "with" is less > convenient and more limited than RAII, but that's the direction > Python is going. This may be in preparation for a move to a real > garbage collector. I do not remember that being stated as part of the rationale for 'with', but just today someone noted that since 'with' replace most uses of deterministic refcount gc, there is not more scope for changing things, at least for builtin and user classes, as opposed to C-extension classes. -- Terry Jan Reedy From joe at goldthwaites.com Wed Jul 28 18:58:01 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 15:58:01 -0700 Subject: Ascii to Unicode. Message-ID: Thanks to all of you who responded. I guess I was working from the wrong premise. I was thinking that a file could write any kind of data and that once I had my Unicode string, I could just write it out with a standard file.write() operation. What is actually happening is the file.write() operation was generating the error until I re-encoded the string as utf-8. This is what worked; import unicodedata input = file('ascii.csv', 'rb') output = file('unicode.csv','wb') for line in input.xreadlines(): unicodestring = unicode(line, 'latin1') output.write(unicodestring.encode('utf-8')) # This second encode is what I was missing. input.close() output.close() A number of you pointed out what I was doing wrong but I couldn't understand it until I realized that the write operation didn't work until it was using a properly encoded Unicode string. I thought I was getting the error on the initial latin Unicode conversion not in the write operation. This still seems odd to me. I would have thought that the unicode function would return a properly encoded byte stream that could then simply be written to disk. Instead it seems like you have to re-encode the byte stream to some kind of escaped Ascii before it can be written back out. Thanks to all of you who took the time to respond. I really do appreciate it. I think with my mental block, I couldn't have figure it out without your help. From joe at goldthwaites.com Wed Jul 28 19:00:26 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed, 28 Jul 2010 16:00:26 -0700 Subject: Ascii to Unicode. In-Reply-To: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> References: <88afbb65-6d70-4621-88f4-e6ba9ff37289@k1g2000prl.googlegroups.com> Message-ID: > Hello hello ... you are running on Windows; the likelihood that you > actually have data encoded in latin1 is very very small. Follow MRAB's > answer but replace "latin1" by "cp1252". I think you're right. The database I'm working with is a US zip code database. It gets updated monthly. The problem fields are some city names in Puerto Rico. I thought I had tried the cp1252 codec and that it didn't work. I tried it again and it works now so I was doing something else wrong. I agree that's probably what I should be using. Both latin1 and cp1252 produce the same output for the two characters I'm having the trouble with but I changed it to cp1252 anyway. I think it will avoid problems in the future Thanks John. From jgaynor at ncsa.uiuc.edu Wed Jul 28 19:41:37 2010 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Wed, 28 Jul 2010 18:41:37 -0500 (CDT) Subject: Newbie question regarding SSL and certificate verification Message-ID: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Hi, I am making a first large project in python and am having quite a bit of difficulty unscrambling various python versions and what they can/cannot do. To wit, I must communicate with certain services via https and am required to perform certificate verification on them. The problem is that I also have to do this under CentOS 5.5 which only uses python 2.4 as its default -- this is not negotiable. As near as I can tell from reading various posts, the https client does not do verification and there is no low-level SSL support to provide a workaround. Near as I can tell from reading, 2.6 does include this. Am I getting this right? Is there a simple way to do this? More to the point, I need to know pretty darn quick if this is impossible so we can try and plan for it. So the quick question: Has anyone done certificate verification using 2.4 and if so, how? Thanks! From debatem1 at gmail.com Wed Jul 28 21:26:05 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 18:26:05 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey Gaynor wrote: > Hi, > > I am making a first large project in python and am having quite a bit of difficulty unscrambling various python versions and what they can/cannot do. To wit, I must communicate with certain services via https and am required to perform ?certificate verification on them. > > The problem is that I also have to do this under CentOS 5.5 which only uses python 2.4 as its default -- this is not negotiable. As near as I can tell from reading various posts, the https client does not do verification and there is no low-level SSL ?support to provide a workaround. Near as I can tell from reading, 2.6 does include this. Am I getting this right? Is there a simple way to do this? More to the point, I need to know pretty darn quick if this is impossible so we can try and plan for it. > > So the quick question: Has anyone done certificate ?verification using 2.4 and if so, how? > > Thanks! M2Crypto is the way to go here. I think there's an example on their site. Geremy Condra From navkirats at gmail.com Wed Jul 28 21:47:17 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 07:17:17 +0530 Subject: Performance ordered dictionary vs normal dictionary Message-ID: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> Hi guys, I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? Regards, N4v From navkirats at gmail.com Wed Jul 28 22:00:34 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 07:30:34 +0530 Subject: Function parameter scope Message-ID: Hi, I had another question: What is the scope of a parameter passed to a function? I know its a very basic question, but I am just sharpening my basics :) def func_something(x) return print(x+1); Does x become a local variable or does it stay as a module scoped variable? Though I think its local, but just want to be sure. Thanks, Nav From clp2 at rebertia.com Wed Jul 28 22:01:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 19:01:10 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 6:47 PM, Navkirat Singh wrote: > Hi guys, > > I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? Your question is rather vague. Define "book keeping". Why do you feel an OrderedDict might be useful in solving your problem? Cheers, Chris From clp2 at rebertia.com Wed Jul 28 22:05:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 19:05:53 -0700 Subject: Function parameter scope In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 7:00 PM, Navkirat Singh wrote: > Hi, > > I had another question: > > What is the scope of ?a parameter passed to a function? I know its a very basic question, but I am just sharpening my basics :) > > def func_something(x) > > ? ? ? ?return print(x+1); > > Does x become a local variable or does it stay as a module scoped variable? > > Though I think its local, but just want to be sure. Yes, it's indeed local. Also, you may wish to instead direct similar basic questions to the Python Tutor mailinglist in the future: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://blog.rebertia.com From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 22:45:26 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 02:45:26 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c50eb46$0$28664$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > On Jul 28, 7:32?am, Steven D'Aprano cybersource.com.au> wrote: >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: >> > Thanks ... I thought int was a type-cast (like in C++) so I assumed I >> > couldn't reference it. >> >> Python doesn't have type-casts in the sense of "tell the compiler to >> treat object of type A as type B instead". The closest Python has to >> that is that if you have an instance of class A, you can do this: >> >> a = A() ?# make an instance of class A a.__class__ = B ?# tell it that >> it's now class B >> >> and hope that it won't explode when you try to use it :/ > > Type casts in C and non-pathlogical C++ don't modify the object they are > casting. > > int (and str, float, etc.) is the closest thing to a type cast in > Python. Perhaps I have been misinformed, but my understanding of C type-casts is that (where possible), a cast like `int(var)` merely tells the compiler to temporarily disregard the type of var and treat it as if it were an int. In other words, it's a compiler instruction rather than a conversion function. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 22:51:42 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 02:51:42 GMT Subject: Function parameter scope References: Message-ID: <4c50ecbe$0$28664$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 07:30:34 +0530, Navkirat Singh wrote: > Hi, > > I had another question: > > What is the scope of a parameter passed to a function? I know its a > very basic question, but I am just sharpening my basics :) > > def func_something(x) > return print(x+1); > > Does x become a local variable or does it stay as a module scoped > variable? > > Though I think its local, but just want to be sure. Yes, x is local. However, be careful that Python does not make a copy of arguments passed to functions. So the local name refers to the same underlying object as the global name, and *modifications* to the *object* will be seen everywhere. But *reassignments* to the *name* are only seen locally. def test(local_name): print(local_name) local_name = 2 print(local_name) print(global_name) global_name = 1 test(global_name) => prints 1, 2, 1. def test(local_name): print(local_name) local_name.append(2) print(local_name) print(global_name) global_name = [1] test(global_name) => prints [1], [1, 2], [1, 2]. -- Steven From steve-REMOVE-THIS at cybersource.com.au Wed Jul 28 23:27:05 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 03:27:05 GMT Subject: Ascii to Unicode. References: Message-ID: <4c50f508$0$28664$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 15:58:01 -0700, Joe Goldthwaite wrote: > This still seems odd to me. I would have thought that the unicode > function would return a properly encoded byte stream that could then > simply be written to disk. Instead it seems like you have to re-encode > the byte stream to some kind of escaped Ascii before it can be written > back out. I'm afraid that's not even wrong. The unicode function returns a unicode string object, not a byte-stream, just as the list function returns a sequence of objects, not a byte-stream. Perhaps this will help: http://www.joelonsoftware.com/articles/Unicode.html Summary: ASCII is not a synonym for bytes, no matter what some English-speakers think. ASCII is an encoding from bytes like \x41 to characters like "A". Unicode strings are a sequence of code points. A code point is a number, implemented in some complex fashion that you don't need to care about. Each code point maps conceptually to a letter; for example, the English letter A is represented by the code point U+0041 and the Arabic letter Ain is represented by the code point U+0639. You shouldn't make any assumptions about the size of each code-point, or how they are put together. You shouldn't expect to write code points to a disk and have the result make sense, any more than you could expect to write a sequence of tuples or sets or dicts to disk in any sensible fashion. You have to serialise it to bytes first, and that's what the encode method does. Decode does the opposite, taking bytes and creating unicode strings from them. For historical reasons -- backwards compatibility with files already created, back in the Bad Old Days before unicode -- there are a whole slew of different encodings available. There is no 1:1 mapping between bytes and strings. If all you have are the bytes, there is literally no way of knowing what string they represent (although sometimes you can guess). You need to know what the encoding used was, or take a guess, or make repeated decodings until something doesn't fail and hope that's the right one. As a general rule, Python will try encoding/decoding using the ASCII encoding unless you tell it differently. Any time you are writing to disk, you need to serialise the objects, regardless of whether they are floats, or dicts, or unicode strings. -- Steven From sturlamolden at yahoo.no Thu Jul 29 00:06:13 2010 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 28 Jul 2010 21:06:13 -0700 (PDT) Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: On 29 Jul, 03:47, Navkirat Singh wrote: > I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? It depends on the problem. A dictionary is a hash table. An ordered dictionary is a binary search tree (BST). Those are different data structures. The main things to note is that: - Access is best-case O(1) for the hash table and O(log n) for the BST. - Worst case behavior is for access is O(n) for both. The pathologic conditions are excessive collisions (hash) or an unbalanced tree (BST). In pathologic cases they both converge towards a linked list. - Searches are only meaningful for == and != for a hash table, but BST searches are also meaningful for >, <, <=, and >=. For this reason, databases are often implemented as BSTs. - A BST can be more friendly to cache than a hash table, particularly when they are large. (Remember that O(1) can be slower than O(log n). Big-O only says how run-time scales with n.) That said, I have not compared ordered dicts with normal dicts, as I still use 2.6. From navkirats at gmail.com Thu Jul 29 00:22:36 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 09:52:36 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: On 29-Jul-2010, at 9:36 AM, sturlamolden wrote: > On 29 Jul, 03:47, Navkirat Singh wrote: > >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Those are different data > structures. > > The main things to note is that: > > - Access is best-case O(1) for the hash table and O(log n) for the > BST. > > - Worst case behavior is for access is O(n) for both. The pathologic > conditions are excessive collisions (hash) or an unbalanced tree > (BST). In pathologic cases they both converge towards a linked list. > > - Searches are only meaningful for == and != for a hash table, but BST > searches are also meaningful for >, <, <=, and >=. For this reason, > databases are often implemented as BSTs. > > - A BST can be more friendly to cache than a hash table, particularly > when they are large. (Remember that O(1) can be slower than O(log n). > Big-O only says how run-time scales with n.) > > That said, I have not compared ordered dicts with normal dicts, as I > still use 2.6. > > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list Thanks for the insight. I am still in the thinking stage, so will let you know as and when I get down to implementation of my idea. Thanks for your time. : ) Regards, Nav From nagle at animats.com Thu Jul 29 01:08:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 22:08:57 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: <4c510ce5$0$1587$742ec2ed@news.sonic.net> On 7/28/2010 6:26 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey > Gaynor wrote: >> Hi, >> >> I am making a first large project in python and am having quite a >> bit of difficulty unscrambling various python versions and what >> they can/cannot do. To wit, I must communicate with certain >> services via https and am required to perform certificate >> verification on them. >> >> The problem is that I also have to do this under CentOS 5.5 which >> only uses python 2.4 as its default -- this is not negotiable. As >> near as I can tell from reading various posts, the https client >> does not do verification and there is no low-level SSL support to >> provide a workaround. Near as I can tell from reading, 2.6 does >> include this. Am I getting this right? Is there a simple way to do >> this? More to the point, I need to know pretty darn quick if this >> is impossible so we can try and plan for it. >> >> So the quick question: Has anyone done certificate verification >> using 2.4 and if so, how? >> >> Thanks! > > M2Crypto is the way to go here. I think there's an example on their > site. M2Crypto does that job quite well. Installing M2Crypto tends to be painful if you have to build it, though. See if you can find a pre- built version. You then need a "cacert.pem" file, with the root certificates you're going to trust. You can get one from http://curl.haxx.se/docs/caextract.html which converts Mozilla's format to a .pem file once a week. The actual Mozilla source file is at http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt but M2Crypto needs it in .pem format. The new Python SSL module in 2.6 and later has a huge built-in security hole - it doesn't verify the domain against the certificate. As someone else put it, this means "you get to talk securely with your attacker." As long as the site or proxy has some valid SSL cert, any valid SSL cert copied from anywhere, the new Python SSL module will tell you everything is just fine. John Nagle From debatem1 at gmail.com Thu Jul 29 01:23:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 28 Jul 2010 22:23:48 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <4c510ce5$0$1587$742ec2ed@news.sonic.net> References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: On Wed, Jul 28, 2010 at 10:08 PM, John Nagle wrote: > On 7/28/2010 6:26 PM, geremy condra wrote: >> >> On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey >> Gaynor ?wrote: >>> >>> Hi, >>> >>> I am making a first large project in python and am having quite a >>> bit of difficulty unscrambling various python versions and what >>> they can/cannot do. To wit, I must communicate with certain >>> services via https and am required to perform ?certificate >>> verification on them. >>> >>> The problem is that I also have to do this under CentOS 5.5 which >>> only uses python 2.4 as its default -- this is not negotiable. As >>> near as I can tell from reading various posts, the https client >>> does not do verification and there is no low-level SSL ?support to >>> provide a workaround. Near as I can tell from reading, 2.6 does >>> include this. Am I getting this right? Is there a simple way to do >>> this? More to the point, I need to know pretty darn quick if this >>> is impossible so we can try and plan for it. >>> >>> So the quick question: Has anyone done certificate ?verification >>> using 2.4 and if so, how? >>> >>> Thanks! >> >> M2Crypto is the way to go here. I think there's an example on their >> site. > > ? M2Crypto does that job quite well. ?Installing M2Crypto tends to be > painful if you have to build it, though. ?See if you can find a pre- > built version. > > ? You then need a "cacert.pem" file, with the root certificates you're > going to trust. ?You can get one from > > ? ? ? ?http://curl.haxx.se/docs/caextract.html > > which converts Mozilla's format to a .pem file once a week. > The actual Mozilla source file is at > > http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt > > ? but M2Crypto needs it in .pem format. > > ? The new Python SSL module in 2.6 and later has a huge built-in > security hole - it doesn't verify the domain against the > certificate. ?As someone else put it, this means "you get to > talk securely with your attacker." As long as the site or proxy > has some valid SSL cert, any valid SSL cert copied from anywhere, > the new Python SSL module will tell you everything is just fine. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle Did anything ever come of the discussion that you and Antoine had? Geremy Condra PS- the quote is due to Justin Samuel From nagle at animats.com Thu Jul 29 01:45:19 2010 From: nagle at animats.com (John Nagle) Date: Wed, 28 Jul 2010 22:45:19 -0700 Subject: Nice way to cast a homogeneous tuple In-Reply-To: <4c503f75$0$11091$c3e8da3@news.astraweb.com> References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c51156b$0$1604$742ec2ed@news.sonic.net> On 7/28/2010 7:32 AM, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> Thanks ... I thought int was a type-cast (like in C++) so I assumed I >> couldn't reference it. > > Python doesn't have type-casts in the sense of "tell the compiler to > treat object of type A as type B instead". The closest Python has to that > is that if you have an instance of class A, you can do this: > > a = A() # make an instance of class A > a.__class__ = B # tell it that it's now class B > > and hope that it won't explode when you try to use it :/ > > I make that seem like a dangerous thing to do, but it's not really. There > actually are sensible use-cases for such a thing, you can't do it to > built-ins (which would be dangerous!), and the worst that will happen > with classes written in Python is they'll raise an exception when you try > calling a method, rather than dump core. The main use for that sort of thing is in constructing objects without their cooperation. "copy" and "pickle" do that, as they build up objects without running their initializers. Arguably, that would be better done with a built-in function for creating arbitrary objects. Something like: x = new_object("classname", (("attr1", val1), ("attr2", val2))) to create a new object in one atomic operation. Storing into "__class__" may not be portable across Python implementations. The implications for multiple inheritance are difficult. It's really a hack for CPython. John Nagle From antonyjeevaraj at rediffmail.com Thu Jul 29 02:04:56 2010 From: antonyjeevaraj at rediffmail.com (jameser) Date: Wed, 28 Jul 2010 23:04:56 -0700 (PDT) Subject: CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME Message-ID: <5dea4918-cce8-4a0c-b9f3-09540b6e90c9@z34g2000pro.googlegroups.com> CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME Work with online free cpa network learn how to work from your home by using cpa offers Great payout methods( cheque,paypal,wire transfer) No investment Earn from $2-$44 per lead EARN $5 PER REFERRED AFFILIATES Awesome earnings get paid for your honest work Join as a free member and get paid to your bank account To join the Network follow the link http://timmyurl.com/awesomeearnings Get paid for real work from online From clp2 at rebertia.com Thu Jul 29 02:05:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 23:05:29 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: On Wed, Jul 28, 2010 at 9:06 PM, sturlamolden wrote: > On 29 Jul, 03:47, Navkirat Singh wrote: >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Er, if you're talking about collections.OrderedDict specifically, you're wrong. It's quite clearly implemented using a regular dictionary (i.e. hash table) and auxiliary list: See http://bugs.python.org/file13231/od7.diff from http://bugs.python.org/issue5397 Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Thu Jul 29 02:11:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 28 Jul 2010 23:11:14 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh wrote: > Sorry, I might have been a bit vague: > (Also, I am new to pythong) > I am trying to do construct my own web session tracking algorithm for a web > server (which also I have constructed). The book keeping is for the session > information I track. The dictionary object will do this for me. I was > initially using a plain dictionary object, but I read this in the > documentation that made me think about the question I asked :- Does your program actually make use of the ordering? If so, then yes, using OrderedDict is obviously preferable (Why reimplement something needlessly?). If not, then why bother with the extra complication? (You are aware that the "ordered" in OrderedDict means that its keys are ordered, and not that, say, a list containing OrderedDicts can be sorted, right?) Cheers, Chris -- http://blog.rebertia.com From navkirats at gmail.com Thu Jul 29 02:18:37 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 11:48:37 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: <63EF7177-0A96-461E-BDD5-520FC1186EF0@gmail.com> On 29-Jul-2010, at 11:41 AM, Chris Rebert wrote: > On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh wrote: >> Sorry, I might have been a bit vague: >> (Also, I am new to pythong) >> I am trying to do construct my own web session tracking algorithm for a web >> server (which also I have constructed). The book keeping is for the session >> information I track. The dictionary object will do this for me. I was >> initially using a plain dictionary object, but I read this in the >> documentation that made me think about the question I asked :- > > Does your program actually make use of the ordering? If so, then yes, > using OrderedDict is obviously preferable (Why reimplement something > needlessly?). If not, then why bother with the extra complication? > > (You are aware that the "ordered" in OrderedDict means that its keys > are ordered, and not that, say, a list containing OrderedDicts can be > sorted, right?) > > Cheers, > Chris > -- > http://blog.rebertia.com I am still in the analysis phase/experimental phase and the need might arise. Hence, I just wanted to know my options. If a collections object will improve performance than an ordinary dictionary, then yes I would like to go with the OrderedDict. Thanks, Nav From steve-REMOVE-THIS at cybersource.com.au Thu Jul 29 02:24:36 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 06:24:36 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c51156b$0$1604$742ec2ed@news.sonic.net> Message-ID: <4c511ea4$0$11117$c3e8da3@news.astraweb.com> On Wed, 28 Jul 2010 22:45:19 -0700, John Nagle wrote: [...] >> if you have an instance of class A, you can do this: >> >> a = A() # make an instance of class A >> a.__class__ = B # tell it that it's now class B >> >> and hope that it won't explode when you try to use it :/ [...] > The main use for that sort of thing is in constructing objects > without their cooperation. "copy" and "pickle" do that, as they build > up objects without running their initializers. True, but there are other use-cases as well, such as the recipe for ring buffer which made it into the Python Cookbook. I think this is it: http://code.activestate.com/recipes/68429-ring-buffer/ > Storing into "__class__" > may not be portable across Python implementations. The implications for > multiple inheritance are difficult. It's really a hack for CPython. I believe that it is intended as a language feature, not an implementation-specific hack: http://bytes.com/topic/python/answers/449635-assigning-self-__class__ While it's an advanced technique that isn't terribly common, I don't see any reason to avoid it. -- Steven From eckhardt at satorlaser.com Thu Jul 29 03:21:37 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 09:21:37 +0200 Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> Message-ID: <1pm7i7-473.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Perhaps I have been misinformed, but my understanding of C type-casts is > that (where possible), a cast like `int(var)` merely tells the compiler > to temporarily disregard the type of var and treat it as if it were an > int. In other words, it's a compiler instruction rather than a conversion > function. You are misinformed. The result of a cast in C or C++ behaves as if a temporary was created: int x = 0; unsigned(x)--; // invalid, compiler error Now, where this distinction gets blurred is when you are casting pointers: (*(unsigned*)&x)--; or, in C++, references: reinterpret_cast(x)--; Technically, these are still invalid though, only that they give you undefined behaviour at runtime instead of a compiler error, but those are already very fine details of the according standards. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From eckhardt at satorlaser.com Thu Jul 29 03:25:23 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 09:25:23 +0200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> <8bb2reF616U1@mid.individual.net> Message-ID: <30n7i7-473.ln1@satorlaser.homedns.org> Neil Cerutti wrote: > Perhaps emailing the tests to yourself would be a good solution. > Every tme the tests ran, you'd get a new email containing the > results. Nice idea, only that it's even less portable and requires manual setup... ;^) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From anand.shashwat at gmail.com Thu Jul 29 03:49:31 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 29 Jul 2010 13:19:31 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: Message-ID: > > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). Those are different data > structures. > > The main things to note is that: > > - Access is best-case O(1) for the hash table and O(log n) for the > BST. > > - Worst case behavior is for access is O(n) for both. The pathologic > conditions are excessive collisions (hash) or an unbalanced tree > (BST). In pathologic cases they both converge towards a linked list. > > - Searches are only meaningful for == and != for a hash table, but BST > searches are also meaningful for >, <, <=, and >=. For this reason, > databases are often implemented as BSTs. > > - A BST can be more friendly to cache than a hash table, particularly > when they are large. (Remember that O(1) can be slower than O(log n). > Big-O only says how run-time scales with n.) > > Thanks, this was really insightful :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From raymond.hettinger at gmail.com Thu Jul 29 04:12:38 2010 From: raymond.hettinger at gmail.com (Raymond Hettinger) Date: Thu, 29 Jul 2010 01:12:38 -0700 (PDT) Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: On Jul 28, 6:47?pm, Navkirat Singh wrote: > I was wondering what would be better to do some medium > to heavy book keeping in memory - Ordered Dictionary > or a plain simple Dictionary object?? The current implementation of OrderedDict is based on regular dictionaries, so it performance cannot be better than a regular dictionary for the usual mapping operations. Some accessor methods like __getitem__(), __len__(), __contains__(), and get() are pass throughs, so their performance is the same. Most of the rest of the methods are order aware and are slower by a constant factor. So, if you don't need the ordering feature, then you're better-off with a regular dictionary. A potential future implementation for OrderedDict written in C would have nearly identical performance as regular dicts for most operations and slightly improved performance for iteration. Raymond From steve-REMOVE-THIS at cybersource.com.au Thu Jul 29 04:28:26 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 08:28:26 GMT Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> <1pm7i7-473.ln1@satorlaser.homedns.org> Message-ID: <4c513baa$0$11120$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 09:21:37 +0200, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: >> Perhaps I have been misinformed, but my understanding of C type-casts >> is that (where possible), a cast like `int(var)` merely tells the >> compiler to temporarily disregard the type of var and treat it as if it >> were an int. In other words, it's a compiler instruction rather than a >> conversion function. > > You are misinformed. The result of a cast in C or C++ behaves as if a > temporary was created: Fair enough. Thank you. -- Steven From pdwjfndjbdgfyg at gmail.com Thu Jul 29 04:42:34 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Thu, 29 Jul 2010 01:42:34 -0700 (PDT) Subject: HOT BEST YOUTH VIDEOS Message-ID: <81e337f9-fae9-42cb-8399-ae914f8c24be@q21g2000prm.googlegroups.com> FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From hniksic at xemacs.org Thu Jul 29 05:20:17 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 29 Jul 2010 11:20:17 +0200 Subject: Performance ordered dictionary vs normal dictionary References: Message-ID: <87y6cuejam.fsf@busola.homelinux.net> sturlamolden writes: > On 29 Jul, 03:47, Navkirat Singh wrote: > >> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? > > It depends on the problem. A dictionary is a hash table. An ordered > dictionary is a binary search tree (BST). The ordered dictionary shipped with Python is also a hash table, with an internal list to keep track of item order. The one thing not mentioned in the thread is that ordered dict's deletion is O(n), which might impact "heavy bookkeeping". As Raymond said, where order doesn't matter, it's best to stick with dict. From jeanmichel at sequans.com Thu Jul 29 05:35:05 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 11:35:05 +0200 Subject: loading configuration files that are themselves python In-Reply-To: <87mxth66pc.fsf@benfinney.id.au> References: <7j8w5tylmw.fsf@rapun.sel.cam.ac.uk> <87mxth66pc.fsf@benfinney.id.au> Message-ID: <4C514B49.4070607@sequans.com> Ben Finney wrote: > Lawrence D'Oliveiro writes: > > >> In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote: >> >> >>> Is there a more idiomatic way of loading in a configuration file >>> that's python code ... >>> >> Is it really a good idea to have a configuration language that?s Turing- >> complete? >> > > I think not. Configuration files should be read as data; they should be > declarative only, not executable languages. That way, a different > program can read and parse them without having to be a parser for an > entire programming language. > For local non distributed applications, configuration files written in python are just fine. JM From jeanmichel at sequans.com Thu Jul 29 05:43:14 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 11:43:14 +0200 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> Message-ID: <4C514D32.8040807@sequans.com> Robert Kern wrote: > On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: >> In message, >> Robert Kern >> wrote: >> >>> There are also utilities for mounting ISOs directly without burning >>> them >>> to a physical disk. >> >> You need special utilities to do this?? > > On at least some versions of Windows, Yes. > You need the "mount" utility with Linux. JM From jkordani at intlogsys.com Thu Jul 29 05:47:13 2010 From: jkordani at intlogsys.com (Joshua Kordani) Date: Thu, 29 Jul 2010 05:47:13 -0400 Subject: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP In-Reply-To: <4C514D32.8040807@sequans.com> References: <91295.91066.qm@web120510.mail.ne1.yahoo.com> <4C514D32.8040807@sequans.com> Message-ID: <4C514E21.5040409@intlogsys.com> Jean-Michel Pichavant wrote: > Robert Kern wrote: >> On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: >>> In message, >>> Robert Kern >>> wrote: >>> >>>> There are also utilities for mounting ISOs directly without burning >>>> them >>>> to a physical disk. >>> >>> You need special utilities to do this?? >> >> On at least some versions of Windows, Yes. >> > You need the "mount" utility with Linux. > > JM On Windows see Daemon-tools lite. free, easy, no spyware. From jeanmichel at sequans.com Thu Jul 29 06:08:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 12:08:54 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> Message-ID: <4C515336.4030807@sequans.com> Steven D'Aprano wrote: > On Sun, 25 Jul 2010 13:58:00 +1200, Gregory Ewing wrote: > > >> Lacrima wrote: >> >> >>> But what if SuperClass1 is from third party library? >>> >> If it hasn't been designed for super(), then you can't use super() with >> it. >> >> super() only works when *every* class in the hierarchy has been designed >> with it in mind. >> > > > That incorrect. You can certainly use super() with classic classes in the > hierarchy, and super() didn't even exist when they were created. > > > >>>> class Parent: >>>> > ... def method(self, arg): > ... return repr(arg) > ... > >>>> class Classic(Parent): >>>> > ... def method(self, arg): > ... return "argument was %s" % Parent.method(self, arg) > ... > >>>> class New(object, Classic): >>>> > ... def method(self, arg): > ... return super(New, self).method(arg).upper() > ... > >>>> x = New() >>>> x.method('spam') >>>> > "ARGUMENT WAS 'SPAM'" > > > The problem isn't super(), and people who give glib advise "don't use > super()" are just compounding the problem. The problem is with multiple > inheritance where methods have different method signatures. If you don't > change the method signatures, super() will work fine. > > Advising people not to use super() might make people feel virtuous, but > it doesn't do anything to help the reader write non-buggy MI hierarchies. > It pushes the effort of dealing with multiple inheritance onto them, > forcing them to re-implement the MRO, probably badly. Can you re- > implement the C3 algorithm? Have you even heard of it? If you answer No > to either of those questions, chances are high that trying to deal with > the MRO manually will lead to worse bugs than using super(). > > Should you use super()? > > 1. If you're doing multiple inheritance with metaclasses, you MUST use > super(). > > 2. If you're using single inheritance only, and never modify method > signatures, there is no reason not to use super(). > > 3. If you're using mixins, you should use super(). > > 4. If you never modify method signatures, then you should use super(). > > 5. If you do modify method signatures, you shouldn't do that (except > possibly in constructors, and even there only cautiously). But if you do > it anyway, then you should use super() *except* in the methods where you > modify the signature. > > 6. If you don't use super(), chances are that your class hierarchy is > still buggy, but instead of failing loudly and noisily with an exception, > it's silently giving the wrong results. > > 7. If you can avoid multiple inheritance in favour of another technique > (such as composition), you should strongly consider that. > > > > I think you're missing the point that super for most of us is a dangerous guess game. It makes implicit what would *really* need to be explicit. class Base1(object): def foo(self): print 'Base1' class Base2(object): def foo(self): print 'Base1' class Sub(Base1, Base2): def foo(self): # which base version to call ??? # choice A # use super an pray that it will do what I need (better know exactly how the MRO works) # also pray that further readers know as much as I do about super # choice B # use explicit calls so I can choose which algorithm I want to use, calling Base1, Base2 or both of them # If the choice is too difficult, that means one thing => my inheritance design is crap => rewrite it properly. Super is known for being required for diamond inheritance, and this reputation is well earned. Outside this scope, super's not required. JM From navkirats at gmail.com Thu Jul 29 06:18:41 2010 From: navkirats at gmail.com (Navkirat Singh) Date: Thu, 29 Jul 2010 15:48:41 +0530 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: <87y6cuejam.fsf@busola.homelinux.net> References: <87y6cuejam.fsf@busola.homelinux.net> Message-ID: On 29-Jul-2010, at 2:50 PM, Hrvoje Niksic wrote: > sturlamolden writes: > >> On 29 Jul, 03:47, Navkirat Singh wrote: >> >>> I was wondering what would be better to do some medium to heavy book keeping in memory - Ordered Dictionary or a plain simple Dictionary object?? >> >> It depends on the problem. A dictionary is a hash table. An ordered >> dictionary is a binary search tree (BST). > > The ordered dictionary shipped with Python is also a hash table, with an > internal list to keep track of item order. > > The one thing not mentioned in the thread is that ordered dict's > deletion is O(n), which might impact "heavy bookkeeping". As Raymond > said, where order doesn't matter, it's best to stick with dict. > -- > http://mail.python.org/mailman/listinfo/python-list Thanks that was an excellent point : ) From eckhardt at satorlaser.com Thu Jul 29 07:50:25 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 29 Jul 2010 13:50:25 +0200 Subject: Ascii to Unicode. References: Message-ID: <1h68i7-534.ln1@satorlaser.homedns.org> Joe Goldthwaite wrote: > import unicodedata > > input = file('ascii.csv', 'rb') > output = file('unicode.csv','wb') > > for line in input.xreadlines(): > unicodestring = unicode(line, 'latin1') > output.write(unicodestring.encode('utf-8')) # This second encode > is what I was missing. Actually, I see two problems here: 1. "ascii.csv" is not an ASCII file but a Latin-1 encoded file, so there starts the first confusion. 2. "unicode.csv" is not a "Unicode" file, because Unicode is not a file format. Rather, it is a UTF-8 encoded file, which is one encoding of Unicode. This is the second confusion. > A number of you pointed out what I was doing wrong but I couldn't > understand it until I realized that the write operation didn't work until > it was using a properly encoded Unicode string. The write function wants bytes! Encoding a string in your favourite encoding yields bytes. > This still seems odd to me. I would have thought that the unicode > function would return a properly encoded byte stream that could then > simply be written to disk. No, unicode() takes a byte stream and decodes it according to the given encoding. You then get an internal representation of the string, a unicode object. This representation typically resembles UCS2 or UCS4, which are more suitable for internal manipulation than UTF-8. This object is a string btw, so typical stuff like concatenation etc are supported. However, the internal representation is a sequence of Unicode codepoints but not a guaranteed sequence of bytes which is what you want in a file. > Instead it seems like you have to re-encode the byte stream to some > kind of escaped Ascii before it can be written back out. As mentioned above, you have a string. For writing, that string needs to be transformed to bytes again. Note: You can also configure a file to read one encoding or write another. You then get unicode objects from the input which you can feed to the output. The important difference is that you only specify the encoding in one place and it will probably even be more performant. I'd have to search to find you the according library calls though, but starting point is http://docs.python.org. Good luck! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From imran.raza460 at gmail.com Thu Jul 29 07:50:48 2010 From: imran.raza460 at gmail.com (tania) Date: Thu, 29 Jul 2010 04:50:48 -0700 (PDT) Subject: WHAT A CHICAGO SEX ON THE ROAD.ENJOY IT Message-ID: <5fa23dd2-fa90-4a12-875e-fec7cca47c7b@y32g2000prc.googlegroups.com> http://www.bigextracash.com/aft/9b6cc578.html also click here to see and enjoy From williamj at tenbase2.com Thu Jul 29 08:12:30 2010 From: williamj at tenbase2.com (William Johnston) Date: Thu, 29 Jul 2010 08:12:30 -0400 Subject: write xml to txt encoding Message-ID: <002101cb2f17$5318d240$f94a76c0$@com> Hello, I have a Python app that parses XML files and then writes to text files. However, the output text file is "sometimes" encoded in some Asian language. Here is my code: encoding = "iso-8859-1" clean_sent = nltk.clean_html(sent.text) clean_sent = clean_sent.encode(encoding, "ignore"); I also tried "UTF-8" encoding, but received the same results. Any suggestions? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nt_mahmood at yahoo.com Thu Jul 29 08:34:01 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Thu, 29 Jul 2010 05:34:01 -0700 (PDT) Subject: measuring a function time Message-ID: <831343.82061.qm@web50006.mail.re2.yahoo.com> Hi, I want to measure a function run time. I read http://docs.python.org/library/time.html?but I?am confused and don't know which one is suitable. I don't?know is daylight timing important or not.... or is?Y2K issue important for my case or not....?I also don't know how epoch time is related to my work. I just want to do this (pseudocode): start_time = get_current_time; function(); end_time = get_current_time; print (end_time - start_time) the output?should be 7600 (s) for example. What is the best and easiest way to do that? Thanks, ? // Naderan *Mahmood; -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Thu Jul 29 08:42:58 2010 From: landimatte at gmail.com (Matteo Landi) Date: Thu, 29 Jul 2010 14:42:58 +0200 Subject: measuring a function time In-Reply-To: <831343.82061.qm@web50006.mail.re2.yahoo.com> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: This should be enough >>>import time >>>tic = time.time() >>>function() >>>toc = time.time() >>>print toc - tic On Thu, Jul 29, 2010 at 2:34 PM, Mahmood Naderan wrote: > Hi, > I want to measure a function run time. I read > http://docs.python.org/library/time.html?but I?am confused and don't know > which one is suitable. I don't?know is daylight timing important or not.... > or is?Y2K issue important for my case or not....?I also don't know how epoch > time is related to my work. > > I just want to do this (pseudocode): > start_time = get_current_time; > function(); > end_time = get_current_time; > print (end_time - start_time) > > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? > > Thanks, > > // Naderan *Mahmood; > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From goon12 at gmail.com Thu Jul 29 08:45:23 2010 From: goon12 at gmail.com (Joe Riopel) Date: Thu, 29 Jul 2010 08:45:23 -0400 Subject: measuring a function time In-Reply-To: <831343.82061.qm@web50006.mail.re2.yahoo.com> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? Take a look at time.clock() http://docs.python.org/library/time.html#time.clock "this is the function to use for benchmarking Python or timing algorithms." From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 08:48:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 12:48:46 GMT Subject: measuring a function time References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <4c5178ae$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > This should be enough > >>>>import time >>>>tic = time.time() >>>>function() >>>>toc = time.time() >>>>print toc - tic You're typing that in the interactive interpreter, which means the timer is counting the seconds while you're typing subsequent commands. At the very least, you need to put that code into a function. More importantly, the above technique is acceptable if function() is very long-running (multiple seconds, at least). If it is quick, or a code- snippet, the time you measure will be dominated by random chance. The best way to time small code snippets and fast functions is with the timeit module. -- Steven From stefan_ml at behnel.de Thu Jul 29 08:54:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 29 Jul 2010 14:54:54 +0200 Subject: write xml to txt encoding In-Reply-To: <002101cb2f17$5318d240$f94a76c0$@com> References: <002101cb2f17$5318d240$f94a76c0$@com> Message-ID: William Johnston, 29.07.2010 14:12: > I have a Python app that parses XML files and then writes to text files. XML or HTML? > However, the output text file is "sometimes" encoded in some Asian language. > > Here is my code: > > > encoding = "iso-8859-1" > > clean_sent = nltk.clean_html(sent.text) > > clean_sent = clean_sent.encode(encoding, "ignore"); > > > I also tried "UTF-8" encoding, but received the same results. What result? Maybe the NLTK cannot determine the encoding of the HTML file (because the file is broken and/or doesn't correctly specify its own encoding) and thus fails to decode it? Stefan From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 08:55:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 12:55:53 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> Message-ID: <4c517a58$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 12:08:54 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> That incorrect. You can certainly use super() with classic classes in >> the hierarchy, and super() didn't even exist when they were created. >> The problem isn't super(), and people who give glib advise "don't use >> super()" are just compounding the problem. The problem is with multiple >> inheritance where methods have different method signatures. If you >> don't change the method signatures, super() will work fine. [...] > I think you're missing the point that super for most of us is a > dangerous guess game. It makes implicit what would *really* need to be > explicit. No, I'm not missing the point. I'm *disagreeing* with the point. I'm saying that for simple inheritance hierarchies, super() does no harm, and it is *required* for most complex inheritance hierarchies. Given that, why not use it? I suppose that, if you're inheriting from an existing class which doesn't use super(), there may be issues (although I'm not convinced that those issues go away if you avoid super!) but for a new class under your control, there are no negatives to super() that didn't already exist with the nature of multiple inheritance. There is, as far as I can tell, ONE use-case where super() must be avoided, and that is a use-case that is discouraged for other reasons: where you change the method signature. If you're changing the method signature, you're already in dubious territory and better know what you're doing. You're violating the Liskov Substitution Principle, and if so, you better have a good reason. (I'm a bit skeptical about the LSP, but many people much smarter than I think it's virtually gospel, so who knows?) But either way, if you change the method signature, you're going to have problems somewhere unless you've really careful. The problems with super() are merely symptoms of that change. If you don't change the method signature, then I don't believe super() does any harm, regardless of whether you have single inheritance or multiple inheritance, whether it is a diamond diagram or not. The worst that can be said about it is that super()'s signature is hard to understand. I would argue that your argument about "explicit" and "implicit" is incorrect. You shouldn't want to explicitly specify which class you are inheriting from, at least not under normal circumstances. It is enough to say that you are inheriting behaviour. If you have a Widget class, and you find yourself explicitly calling methods by *named* superclasses, you're probably doing something wrong. It should always be possible to insert a class higher up the hierarchy, or rename a grandparent, without effecting your class. (Obviously you can't expect to rename an immediate parent class.) super() is just as explicit as len(), or str.upper(). It says, explicitly, that it will call the method belonging to one or more superclass of the given class. That's no more implicit than mylist[5] is implicit merely because you didn't have to walk the list by hand. > class Base1(object): > def foo(self): > print 'Base1' > > > class Base2(object): > def foo(self): > print 'Base1' > > > class Sub(Base1, Base2): > def foo(self): > # which base version to call ??? > # choice A > # use super an pray that it will do what I need (better > know exactly how the MRO works) But the point is, super() knows exactly how the MRO works, so you don't have to. > # also pray that further readers know as much as I do > about super Now that's just silly. Do you write all your classes for the lowest common denominator? Do you assume all you users are ignorant? If you subclass dict, do you feel the need to "pray" that your users won't try to use mutable objects as keys? If you avoid super(), do you "pray" that your users won't try to use your class in a multiple inheritance situation, and have a buggy class? I bet you don't. If they misuse your class, that's their responsibility. > # choice B > # use explicit calls so I can choose which algorithm I > want to use, calling Base1, Base2 or both of them That's a fair point. super() uses the standard MRO algorithm, it isn't a "Do What I Mean" mind- reading function. If you want an unusual MRO, then you're responsible for managing it yourself. Go right ahead, this is Python and you have all the tools to do so. Nothing forces you to inherit behaviour from the superclasses at all -- super() is designed for overloading (extending) the behaviour of methods, and so the assumption is that you want to call the method in each superclass. But if you're overriding the method instead, or doing something unusual, then you're in charge. > # If the choice is too difficult, that means one thing > => my inheritance design is crap => rewrite it properly. > > Super is known for being required for diamond inheritance, and this > reputation is well earned. Outside this scope, super's not required. Of course it's not required. Nor does it do any harm. Far from it -- your single inheritance subclass might be just what another user needs for a multiple inheritance class, and by not using super(), you ruin it for him. -- Steven From nt_mahmood at yahoo.com Thu Jul 29 09:38:08 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Thu, 29 Jul 2010 06:38:08 -0700 (PDT) Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <810979.37037.qm@web50005.mail.re2.yahoo.com> Thanks, the first method worked. However clock() doesn't. tic = time.time() time.sleep( 2 ) toc = time.time() print toc - tic ? Result: 2.00269889832 >Take a look at time.clock() tic = time.clock() time.sleep( 2 ) toc = time.clock() print toc - tic ? result: 0.0 >More importantly, the above technique is acceptable if function() is very >long-running (multiple seconds, at least). yes, the code is long running. Thanks // Naderan *Mahmood; ________________________________ From: Matteo Landi To: Mahmood Naderan Cc: python mailing list Sent: Thu, July 29, 2010 5:12:58 PM Subject: Re: measuring a function time This should be enough >>>import time >>>tic = time.time() >>>function() >>>toc = time.time() >>>print toc - tic On Thu, Jul 29, 2010 at 2:34 PM, Mahmood Naderan wrote: > Hi, > I want to measure a function run time. I read > http://docs.python.org/library/time.html?but I?am confused and don't know > which one is suitable. I don't?know is daylight timing important or not.... > or is?Y2K issue important for my case or not....?I also don't know how epoch > time is related to my work. > > I just want to do this (pseudocode): > start_time = get_current_time; > function(); > end_time = get_current_time; > print (end_time - start_time) > > the output?should be 7600 (s) for example. What is the best and easiest way > to do that? > > Thanks, > > // Naderan *Mahmood; > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgaynor at ncsa.uiuc.edu Thu Jul 29 10:07:08 2010 From: jgaynor at ncsa.uiuc.edu (Jeffrey Gaynor) Date: Thu, 29 Jul 2010 09:07:08 -0500 (CDT) Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Thank you! This is what I was looking for. A final question -- how widely is M2Crypto used? Since I will have to now pitch to our group that this is preferable the first questions they will ask are about stability, who is using it and how secure is it really, especially since it is at version 0.20.2 (i.e. no major release yet). Thanks again! Jeff ----- Original Message ----- From: "John Nagle" To: python-list at python.org Sent: Thursday, July 29, 2010 12:08:57 AM Subject: Re: Newbie question regarding SSL and certificate verification On 7/28/2010 6:26 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey > Gaynor wrote: >> Hi, >> >> I am making a first large project in python and am having quite a >> bit of difficulty unscrambling various python versions and what >> they can/cannot do. To wit, I must communicate with certain >> services via https and am required to perform certificate >> verification on them. >> >> The problem is that I also have to do this under CentOS 5.5 which >> only uses python 2.4 as its default -- this is not negotiable. As >> near as I can tell from reading various posts, the https client >> does not do verification and there is no low-level SSL support to >> provide a workaround. Near as I can tell from reading, 2.6 does >> include this. Am I getting this right? Is there a simple way to do >> this? More to the point, I need to know pretty darn quick if this >> is impossible so we can try and plan for it. >> >> So the quick question: Has anyone done certificate verification >> using 2.4 and if so, how? >> >> Thanks! > > M2Crypto is the way to go here. I think there's an example on their > site. M2Crypto does that job quite well. Installing M2Crypto tends to be painful if you have to build it, though. See if you can find a pre- built version. You then need a "cacert.pem" file, with the root certificates you're going to trust. You can get one from http://curl.haxx.se/docs/caextract.html which converts Mozilla's format to a .pem file once a week. The actual Mozilla source file is at http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt but M2Crypto needs it in .pem format. The new Python SSL module in 2.6 and later has a huge built-in security hole - it doesn't verify the domain against the certificate. As someone else put it, this means "you get to talk securely with your attacker." As long as the site or proxy has some valid SSL cert, any valid SSL cert copied from anywhere, the new Python SSL module will tell you everything is just fine. John Nagle -- http://mail.python.org/mailman/listinfo/python-list From darcy at druid.net Thu Jul 29 10:43:39 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 29 Jul 2010 10:43:39 -0400 Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> Message-ID: <20100729104339.ab45755a.darcy@druid.net> On Thu, 29 Jul 2010 08:45:23 -0400 Joe Riopel wrote: > On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: > > the output?should be 7600 (s) for example. What is the best and easiest way > > to do that? > > Take a look at time.clock() I don't know if that's what he wants. The clock() method returns processor time, not wall time. Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 Type "help", "copyright", "credits" or "license" for more information. >>> from time import time, clock, sleep >>> t = time() >>> print time() - t, clock() 0.000596046447754 0.03 >>> sleep(3) >>> print time() - t, clock() 3.03474903107 0.03 >>> x = open("BIGFILE").read() >>> print time() - t, clock() 10.2008538246 1.42 -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From drobinow at gmail.com Thu Jul 29 10:54:39 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 29 Jul 2010 10:54:39 -0400 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: On Thu, Jul 29, 2010 at 10:07 AM, Jeffrey Gaynor wrote: > ... > A final question -- how widely is M2Crypto used? Since I will have to now pitch to our group that this is preferable the first questions they will ask are about stability, who is using it and how secure is it really, especially since it is at version 0.20.2 (i.e. no major release yet). I know very little about security, but one thing I think I know. Never use security software version 1.0 or greater. It was written by an author insufficiently paranoid. From lists at cheimes.de Thu Jul 29 11:03:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 29 Jul 2010 17:03:07 +0200 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: > I know very little about security, but one thing I think I know. Never > use security software version 1.0 or greater. It was written by an > author insufficiently paranoid. OpenSSL 1.0.0a was released about a month ago. ;) From pavlovevidence at gmail.com Thu Jul 29 11:29:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 29 Jul 2010 08:29:01 -0700 (PDT) Subject: Nice way to cast a homogeneous tuple References: <4C50305E.3010603@otenet.gr> <4C503122.3060208@otenet.gr> <4c503f75$0$11091$c3e8da3@news.astraweb.com> <4c50eb46$0$28664$c3e8da3@news.astraweb.com> Message-ID: <38592ade-2116-4122-b915-5177c2851601@y32g2000prc.googlegroups.com> On Jul 28, 7:45?pm, Steven D'Aprano wrote: > On Wed, 28 Jul 2010 08:47:52 -0700, Carl Banks wrote: > > On Jul 28, 7:32?am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Wed, 28 Jul 2010 09:35:52 -0400, wheres pythonmonks wrote: > >> > Thanks ... I thought int was a type-cast (like in C++) so I assumed I > >> > couldn't reference it. > > >> Python doesn't have type-casts in the sense of "tell the compiler to > >> treat object of type A as type B instead". The closest Python has to > >> that is that if you have an instance of class A, you can do this: > > >> a = A() ?# make an instance of class A a.__class__ = B ?# tell it that > >> it's now class B > > >> and hope that it won't explode when you try to use it :/ > > > Type casts in C and non-pathlogical C++ don't modify the object they are > > casting. > > > int (and str, float, etc.) is the closest thing to a type cast in > > Python. > > Perhaps I have been misinformed, but my understanding of C type-casts is > that (where possible), a cast like `int(var)` (int)var > merely tells the compiler > to temporarily disregard the type of var and treat it as if it were an > int. In other words, it's a compiler instruction rather than a conversion > function. Even if it did, it would still be temporary. The type of the variable remains unchanged. But it doesn't disregard the original type: type casts try to preserve semantic value. (double)1 returns 1.0, which is not only a different bit pattern but a different size. That's exactly what float() does in Python. Carl Banks From nagle at animats.com Thu Jul 29 12:08:32 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 09:08:32 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <4c51a77c$0$1675$742ec2ed@news.sonic.net> On 7/28/2010 10:23 PM, geremy condra wrote: > On Wed, Jul 28, 2010 at 10:08 PM, John Nagle wrote: >> On 7/28/2010 6:26 PM, geremy condra wrote: >>> >>> On Wed, Jul 28, 2010 at 4:41 PM, Jeffrey >>> Gaynor wrote: > >> The new Python SSL module in 2.6 and later has a huge built-in >> security hole - it doesn't verify the domain against the >> certificate. As someone else put it, this means "you get to >> talk securely with your attacker." As long as the site or proxy >> has some valid SSL cert, any valid SSL cert copied from anywhere, >> the new Python SSL module will tell you everything is just fine. >> >> John Nagle > > Did anything ever come of the discussion that you and Antoine had? > > Geremy Condra > > PS- the quote is due to Justin Samuel I had to write my own domain check. Did anyone re-open the bug report on that issue? John Nagle From solipsis at pitrou.net Thu Jul 29 12:13:27 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 29 Jul 2010 18:13:27 +0200 Subject: Newbie question regarding SSL and certificate verification References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> Message-ID: <20100729181327.74211dc6@pitrou.net> On Wed, 28 Jul 2010 22:23:48 -0700 geremy condra wrote: > > > > ? The new Python SSL module in 2.6 and later has a huge built-in > > security hole - it doesn't verify the domain against the > > certificate. ?As someone else put it, this means "you get to > > talk securely with your attacker." As long as the site or proxy > > has some valid SSL cert, any valid SSL cert copied from anywhere, > > the new Python SSL module will tell you everything is just fine. > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > > Did anything ever come of the discussion that you and Antoine had? As I wrote in http://bugs.python.org/issue1589, I would support adding the necessary function(s) to the SSL module, and have urllib (and other stdlib modules) support them. Someone needs to write a patch, though. Regards Antoine. From jimgardener at gmail.com Thu Jul 29 12:51:13 2010 From: jimgardener at gmail.com (jimgardener) Date: Thu, 29 Jul 2010 09:51:13 -0700 (PDT) Subject: solving Tix problem in ubuntu jaunty Message-ID: <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20@q21g2000prm.googlegroups.com> hi, recently I switched to ubuntu jaunty and installed python 2.6.I installed lib-tk so that I can work on my gui apps using Tix and Tkinter.But ,it seems that the python version in jaunty ships a buggy tix version which gives a 'TclError:unknown color' error message (this happens when I try to use FileSelectBox in Tix). I tried to find if the installation is proper by >>root=Tix.Tk() >>root.tk.eval('package require Tix') This outputs the string '8.4' How do I correct the problem?I downloaded the source Tix8.4.3-src.tar from sourceforge site.Can somebody tell me how I can install this so I can use the bug free Tix from python2.6> thanks jim From jeanmichel at sequans.com Thu Jul 29 13:29:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 29 Jul 2010 19:29:24 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c517a58$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C51BA74.2050105@sequans.com> Steven D'Aprano wrote: > [snip] > > super() is just as explicit as len(), or str.upper(). It says, > explicitly, that it will call the method belonging to one or more > superclass of the given class. > Come on Steven, you're better than this :) . Everybody can accurately guess what len and upper are doing without looking at the documentation. No one can guess for super without closely looking at the documention, or even at some good articles on the net which try to clear things up about super. And note there is no such article about len or upper. As someone already said in this list, the main problem with super is that it tends to refer to the superclass method while in fact it calls the next MRO method. "mro" would have been the proper name for "super". JM From joe at goldthwaites.com Thu Jul 29 13:48:16 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 29 Jul 2010 10:48:16 -0700 Subject: Ascii to Unicode. In-Reply-To: <4c50f508$0$28664$c3e8da3@news.astraweb.com> References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> Message-ID: <5A04846ED83745A8A99A944793792810@NewMBP> Hi Steven, I read through the article you referenced. I understand Unicode better now. I wasn't completely ignorant of the subject. My confusion is more about how Python is handling Unicode than Unicode itself. I guess I'm fighting my own misconceptions. I do that a lot. It's hard for me to understand how things work when they don't function the way I *think* they should. Here's the main source of my confusion. In my original sample, I had read a line in from the file and used the unicode function to create a unicodestring object; unicodestring = unicode(line, 'latin1') What I thought this step would do is translate the line to an internal Unicode representation. The problem character \xe1 would have been translated into a correct Unicode representation for the accented "a" character. Next I tried to write the unicodestring object to a file thusly; output.write(unicodestring) I would have expected the write function to request the byte string from the unicodestring object and simply write that byte string to a file. I thought that at this point, I should have had a valid Unicode latin1 encoded file. Instead get an error that the character \xe1 is invalid. The fact that the \xe1 character is still in the unicodestring object tells me it wasn't translated into whatever python uses for its internal Unicode representation. Either that or the unicodestring object returns the original string when it's asked for a byte stream representation. Instead of just writing the unicodestring object, I had to do this; output.write(unicodestring.encode('utf-8')) This is doing what I thought the other steps were doing. It's translating the internal unicodestring byte representation to utf-8 and writing it out. It still seems strange and I'm still not completely clear as to what is going on at the byte stream level for each of these steps. From pdl5000 at yahoo.com Thu Jul 29 13:57:05 2010 From: pdl5000 at yahoo.com (Paul Lemelle) Date: Thu, 29 Jul 2010 10:57:05 -0700 (PDT) Subject: stdout of external program. Message-ID: <958992.74508.qm@web52905.mail.re2.yahoo.com> HELP! :) I am trying to output the following program's output to either a file or variable, how can this be done? # Writing the output to a standard argv argument #1/usr/bin/python import sys for arg in sys.argv: ? print arg #END Thanks, Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at goldthwaites.com Thu Jul 29 13:59:48 2010 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu, 29 Jul 2010 10:59:48 -0700 Subject: Ascii to Unicode. In-Reply-To: <1h68i7-534.ln1@satorlaser.homedns.org> References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: Hi Ulrich, Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a few characters above the 128 range that are causing Postgresql Unicode errors. Those characters work fine in the Windows world but they're not the correct byte representation for Unicode. What I'm attempting to do is translate those upper range characters into the correct Unicode representations so that they look the same in the Postgresql database as they did in the CSV file. I wrote up the source of my confusion to Steven so I won't duplicate it here. You're comment on defining the encoding of the file directly instead of using functions to encode and decode the data lead me to the codecs module. Using it, I can define the encoding a file open time and then just read and write the lines. I ended up with this; import codecs input = codecs.open('ascii.csv', encoding='cp1252') output = codecs.open('unicode.csv', mode='wb', encoding='utf-8') output.writelines(input.readlines()) input.close() output.close() This is doing exactly the same thing but it's much clearer to me. Readlines translates the input using the cp1252 codec and writelines encodes it to utf-8 and writes it out. And as you mentioned, it's probably higher performance. I haven't tested that but since both programs do the job in seconds, performance isn't and issue. Thanks again to everyone who posted. I really do appreciate it. From shailendra.vikas at gmail.com Thu Jul 29 14:08:17 2010 From: shailendra.vikas at gmail.com (Shailendra) Date: Thu, 29 Jul 2010 14:08:17 -0400 Subject: Multiprocessing taking too much time Message-ID: Hi All, I have a following situation. ==================PSUDO CODE START================== class holds_big_array: ? ? big_array ?#has a big array ? ? def get_some_element(self, cond) # return some data from the array from the big array ==================PSUDO CODE END==================== I wanted to use multiprocessing module to parallelise calling "get_some_element". I used following kind of code ==================PSUDO CODE START================== pool = Pool(processes=2) holder =holds_big_array() #class instantiation def callback_f(result): ? ? ? ? ?do something with result loop many times ? ?pool.apply_async(holder.get_some_element,args,callback=callback_f) pool.close() pool.join() ==================PSUDO CODE END==================== Note: Had to do something to enable instance method being pickled... I tested this with less than realistic size of big_array . My parallel version works much slower than than the normal serial version (10-20 sec vs 7-8 min). I was wonder what could be the possible reason. Is it something to do that it is a instance method and some locking will make other process wait for the locks. Any idea how to trace where the program is spending time? Let me know if the information give is inadequate. Thanks in advance. Shailendra Vikas From wherespythonmonks at gmail.com Thu Jul 29 14:12:09 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 29 Jul 2010 14:12:09 -0400 Subject: default behavior Message-ID: Why is the default value of an int zero? >>> x = int >>> print x >>> x() 0 >>> How do I build an "int1" type that has a default value of 1? [Hopefully no speed penalty.] I am thinking about applications with collections.defaultdict. What if I want to make a defaultdict of defaultdicts of lists? [I guess my Perl background is showing -- I miss auto-vivification.] W From ethan at stoneleaf.us Thu Jul 29 14:14:24 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Jul 2010 11:14:24 -0700 Subject: Ascii to Unicode. In-Reply-To: <5A04846ED83745A8A99A944793792810@NewMBP> References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: <4C51C500.8000206@stoneleaf.us> Joe Goldthwaite wrote: > Hi Steven, > > I read through the article you referenced. I understand Unicode better now. > I wasn't completely ignorant of the subject. My confusion is more about how > Python is handling Unicode than Unicode itself. I guess I'm fighting my own > misconceptions. I do that a lot. It's hard for me to understand how things > work when they don't function the way I *think* they should. > > Here's the main source of my confusion. In my original sample, I had read a > line in from the file and used the unicode function to create a > unicodestring object; > > unicodestring = unicode(line, 'latin1') > > What I thought this step would do is translate the line to an internal > Unicode representation. The problem character \xe1 would have been > translated into a correct Unicode representation for the accented "a" > character. Correct. At this point you have unicode string. > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from the > unicodestring object and simply write that byte string to a file. I thought > that at this point, I should have had a valid Unicode latin1 encoded file. > Instead get an error that the character \xe1 is invalid. Here's the problem -- there is no byte string representing the unicode string, they are completely different. There are dozens of different possible encodings to go from unicode to a byte-string (of which UTF-8 is one such possibility). > The fact that the \xe1 character is still in the unicodestring object tells > me it wasn't translated into whatever python uses for its internal Unicode > representation. Either that or the unicodestring object returns the > original string when it's asked for a byte stream representation. Wrong. It so happens that some of the unicode points are the same as some (but not all) of the ascii and upper-ascii values. When you attempt to write a unicode string without specifying which encoding you want, python falls back to ascii (not upper-ascii) so any character outside the 0-127 range is going to raise an error. > Instead of just writing the unicodestring object, I had to do this; > > output.write(unicodestring.encode('utf-8')) > > This is doing what I thought the other steps were doing. It's translating > the internal unicodestring byte representation to utf-8 and writing it out. > It still seems strange and I'm still not completely clear as to what is > going on at the byte stream level for each of these steps. Don't think of unicode as a byte stream. It's a bunch of numbers that map to a bunch of symbols. The byte stream only comes into play when you want to send unicode somewhere (file, socket, etc) and you then have to encode the unicode into bytes. Hope this helps! ~Ethan~ From jkordani at intlogsys.com Thu Jul 29 14:17:25 2010 From: jkordani at intlogsys.com (Joshua Kordani) Date: Thu, 29 Jul 2010 14:17:25 -0400 Subject: Multiprocessing taking too much time In-Reply-To: References: Message-ID: <4C51C5B5.3050400@intlogsys.com> The first thing that is generically tried when wishing to measure how long certain parts take is to record your own time snapshots in the code yourself. take the current time before an operation, take it after, subract, report it to yourself. Also, try working with an array that is actually big, so that you can see meaningful differences in approaches. Shailendra wrote: > Hi All, > I have a following situation. > ==================PSUDO CODE START================== > class holds_big_array: > big_array #has a big array > > def get_some_element(self, cond) # return some data from the array > from the big array > ==================PSUDO CODE END==================== > I wanted to use multiprocessing module to parallelise calling > "get_some_element". I used following kind of code > > ==================PSUDO CODE START================== > pool = Pool(processes=2) > holder =holds_big_array() #class instantiation > def callback_f(result): > do something with result > loop many times > pool.apply_async(holder.get_some_element,args,callback=callback_f) > pool.close() > pool.join() > ==================PSUDO CODE END==================== > Note: Had to do something to enable instance method being pickled... > > I tested this with less than realistic size of big_array . My parallel > version works much slower than than the normal serial version (10-20 > sec vs 7-8 min). I was wonder what could be the possible reason. Is it > something to do that it is a instance method and some locking will > make other process wait for the locks. Any idea how to trace where the > program is spending time? > > Let me know if the information give is inadequate. > > Thanks in advance. > Shailendra Vikas From no.email at nospam.invalid Thu Jul 29 14:18:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 29 Jul 2010 11:18:39 -0700 Subject: default behavior References: Message-ID: <7xeiem2lts.fsf@ruckus.brouhaha.com> wheres pythonmonks writes: > How do I build an "int1" type that has a default value of 1? > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. You can supply an arbitary function to collections.defaultdict. It doesn't have to be a class. E.g. d = collections.defaultdict(lambda: 1) will do what you are asking. From carey.tilden at gmail.com Thu Jul 29 14:18:41 2010 From: carey.tilden at gmail.com (Carey Tilden) Date: Thu, 29 Jul 2010 11:18:41 -0700 Subject: Ascii to Unicode. In-Reply-To: References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: On Thu, Jul 29, 2010 at 10:59 AM, Joe Goldthwaite wrote: > Hi Ulrich, > > Ascii.csv isn't really a latin-1 encoded file. ?It's an ascii file with a > few characters above the 128 range that are causing Postgresql Unicode > errors. ?Those characters work fine in the Windows world but they're not the > correct byte representation for Unicode. What I'm attempting to do is > translate those upper range characters into the correct Unicode > representations so that they look the same in the Postgresql database as > they did in the CSV file. Having bytes outside of the ASCII range means, by definition, that the file is not ASCII encoded. ASCII only defines bytes 0-127. Bytes outside of that range mean either the file is corrupt, or it's in a different encoding. In this case, you've been able to determine the correct encoding (latin-1) for those errant bytes, so the file itself is thus known to be in that encoding. Carey From ethan at stoneleaf.us Thu Jul 29 14:34:18 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Jul 2010 11:34:18 -0700 Subject: Ascii to Unicode. In-Reply-To: References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: <4C51C9AA.6070704@stoneleaf.us> Joe Goldthwaite wrote: > Hi Ulrich, > > Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a > few characters above the 128 range . . . It took me a while to get this point too (if you already have "gotten it", I apologize, but the above comment leads me to believe you haven't). *Every* file is an encoded file... even your UTF-8 file is encoded using the UTF-8 format. Someone correct me if I'm wrong, but I believe lower-ascii (0-127) matches up to the first 128 Unicode code points, so while those first 128 code-points translate easily to ascii, ascii is still an encoding, and if you have characters higher than 127, you don't really have an ascii file -- you have (for example) a cp1252 file (which also, not coincidentally, shares the first 128 characters/code points with ascii). Hopefully I'm not adding to the confusion. ;) ~Ethan~ From wherespythonmonks at gmail.com Thu Jul 29 14:35:06 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Thu, 29 Jul 2010 14:35:06 -0400 Subject: default behavior In-Reply-To: <7xeiem2lts.fsf@ruckus.brouhaha.com> References: <7xeiem2lts.fsf@ruckus.brouhaha.com> Message-ID: Thanks. I presume this will work for my nested example as well. Thanks again. On Thu, Jul 29, 2010 at 2:18 PM, Paul Rubin wrote: > wheres pythonmonks writes: >> How do I build an "int1" type that has a default value of 1? >> [Hopefully no speed penalty.] >> I am thinking about applications with collections.defaultdict. > > You can supply an arbitary function to collections.defaultdict. > It doesn't have to be a class. ?E.g. > > ? ?d = collections.defaultdict(lambda: 1) > > will do what you are asking. > -- > http://mail.python.org/mailman/listinfo/python-list > From airscorp at otenet.gr Thu Jul 29 14:43:05 2010 From: airscorp at otenet.gr (Nick Raptis) Date: Thu, 29 Jul 2010 21:43:05 +0300 Subject: default behavior In-Reply-To: References: Message-ID: <4C51CBB9.4010909@otenet.gr> On 07/29/2010 09:12 PM, wheres pythonmonks wrote: > How do I build an "int1" type that has a default value of 1? You mean something like: >>> x = int() >>> x 0 >>> def myint(value=1): ... return int(value) ... >>> myint() 1 >>> That's ugly on so many levels.. Anyway, basic types (and almost everything else) in Python are classes. You can always subclass them to do whatever you like > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. > What if I want to make a defaultdict of defaultdicts of lists? [I > guess my Perl background is showing -- I miss auto-vivification.] > > > Ah, python is no perl. Then again, perl is no python either. ----- Random pseudo-Confucius quote Have fun, Nick From nagle at animats.com Thu Jul 29 15:04:33 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:04:33 -0700 Subject: Multiprocessing taking too much time In-Reply-To: References: Message-ID: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> On 7/29/2010 11:08 AM, Shailendra wrote: > Hi All, > I have a following situation. > ==================PSUDO CODE START================== > class holds_big_array: > big_array #has a big array > > def get_some_element(self, cond) # return some data from the array > from the big array > ==================PSUDO CODE END==================== > I wanted to use multiprocessing module to parallelise calling > "get_some_element". I used following kind of code > > ==================PSUDO CODE START================== > pool = Pool(processes=2) > holder =holds_big_array() #class instantiation > def callback_f(result): > do something with result > loop many times > pool.apply_async(holder.get_some_element,args,callback=callback_f) > pool.close() > pool.join() > ==================PSUDO CODE END==================== > Note: Had to do something to enable instance method being pickled... > > I tested this with less than realistic size of big_array . My parallel > version works much slower than than the normal serial version (10-20 > sec vs 7-8 min). I was wonder what could be the possible reason. It's hard to tell from your "PSUDO CODE", but it looks like each access to the "big array" involves calling another process. Calling a function in another process is done by creating an object to contain the request, running it through "pickle" to convert it to a stream of bytes, sending the stream of bytes through a socket or pipe to the other process, running the byte stream through "unpickle" to create an object like the original one, but in a different process, and calling a function on the newly created object in the receiving process. This entire sequence has to be done again in reverse to get a reply back. This is hundreds of times slower than a call to a local function. The "multiprocessing module" is not a replacement for thread-level parallelism. It looks like it is, but it isn't. It's only useful for big tasks which require large amounts of computation and little interprocess communication. Appropriately-sized tasks to send out to another process are things like "parse large web page" or "compress video file", not "access element of array". John Nagle From nagle at animats.com Thu Jul 29 15:17:14 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:17:14 -0700 Subject: Ascii to Unicode. In-Reply-To: References: Message-ID: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> On 7/28/2010 3:58 PM, Joe Goldthwaite wrote: > This still seems odd to me. I would have thought that the unicode function > would return a properly encoded byte stream that could then simply be > written to disk. Instead it seems like you have to re-encode the byte stream > to some kind of escaped Ascii before it can be written back out. Here's what's really going on. Unicode strings within Python have to be indexable. So the internal representation of Unicode has (usually) two bytes for each character, so they work like arrays. UTF-8 is a stream format for Unicode. It's slightly compressed; each character occupies 1 to 4 bytes, and the base ASCII characters (0..127 only, not 128..255) occupy one byte each. The format is described in "http://en.wikipedia.org/wiki/UTF-8". A UTF-8 file or stream has to be parsed from the beginning to keep track of where each Unicode character begins. So it's not a suitable format for data being actively worked on in memory; it can't be easily indexed. That's why it's necessary to convert to UTF-8 before writing to a file or socket. John Nagle From robert.kern at gmail.com Thu Jul 29 15:19:42 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Jul 2010 14:19:42 -0500 Subject: Tabular Package: importing file In-Reply-To: References: Message-ID: On 7/28/10 4:57 PM, Robert Faryabi wrote: > Hi there; > > I'm using Tabular Package for manipulating tab-delimited data. > There is a small problem that I cannot get my head around it. > > When I construct my tabarray from file, the black fields are replaced by "nan". > Does any one knows how to just keep them as empty string (ie. ' ')? If you want the other values to be actual numbers instead of strings containing numerical values, then no, you cannot keep the blank fields as empty strings. There may be an option to have tabular parse the data into an object array, in which all of the items will be Python objects. Then you could mix and match the types. You will find better luck asking questions about tabular on the numpy-discussion mailing list. tabular is built on numpy, so many of your questions will really be questions about how numpy behaves. Also, the tabular authors hang out there. http://www.scipy.org/Mailing_Lists -- 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 Thu Jul 29 15:28:18 2010 From: nagle at animats.com (John Nagle) Date: Thu, 29 Jul 2010 12:28:18 -0700 Subject: default behavior In-Reply-To: References: Message-ID: <4c51d64e$0$1609$742ec2ed@news.sonic.net> On 7/29/2010 11:12 AM, wheres pythonmonks wrote: > Why is the default value of an int zero? > >>>> x = int >>>> print x > >>>> x() > 0 >>>> > > How do I build an "int1" type that has a default value of 1? >>> class int1(object) : ... def __init__(self) : ... self.val = 1 ... def __call__(self) : ... return(self.val) ... >>> x = int1() >>> x() 1 This isn't useful; you'd also have to define all the numeric operators for this type. And then there are mixed-type conversion issues. Inheriting from "int" is not too helpful, because you can't assign to the value of the base class. "self=1" won't do what you want. [Hopefully no speed penalty.] In your dreams. Although all numbers in CPython are "boxed", so there's more of a speed penalty with "int" itself than you might expect. There are some C libraries for handling large arrays if you really need to crunch numbers. John Nagle From bjracine at glosten.com Thu Jul 29 15:39:01 2010 From: bjracine at glosten.com (Benjamin J. Racine) Date: Thu, 29 Jul 2010 12:39:01 -0700 Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) Message-ID: I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. I am not seeing how this might be done. Many thanks for your help... Ben Racine From lists at cheimes.de Thu Jul 29 15:40:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 29 Jul 2010 21:40:16 +0200 Subject: default behavior In-Reply-To: <4c51d64e$0$1609$742ec2ed@news.sonic.net> References: <4c51d64e$0$1609$742ec2ed@news.sonic.net> Message-ID: > Inheriting from "int" is not too helpful, because you can't assign > to the value of the base class. "self=1" won't do what you want. It's useful if you remember that you can set the default value by overwriting __new__. >>> class int1(int): ... def __new__(cls, value=1): ... return super(int1, cls).__new__(cls, value) ... >>> int1() 1 >>> int1(1) 1 >>> int1(2) 2 >>> int1(0) 0 From bjracine at glosten.com Thu Jul 29 15:43:28 2010 From: bjracine at glosten.com (Benjamin J. Racine) Date: Thu, 29 Jul 2010 12:43:28 -0700 Subject: measuring a function time In-Reply-To: <20100729104339.ab45755a.darcy@druid.net> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <20100729104339.ab45755a.darcy@druid.net> Message-ID: I just use ipython's functions (that are themselves just calls to the time module functions) for timing my functions... Enter: %timeit? or %time At the Ipython command prompt to get started. Ben R. On Jul 29, 2010, at 7:43 AM, D'Arcy J.M. Cain wrote: > On Thu, 29 Jul 2010 08:45:23 -0400 > Joe Riopel wrote: >> On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: >>> the output should be 7600 (s) for example. What is the best and easiest way >>> to do that? >> >> Take a look at time.clock() > > I don't know if that's what he wants. The clock() method returns > processor time, not wall time. > > Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) > [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 > Type "help", "copyright", "credits" or "license" for more information. >>>> from time import time, clock, sleep >>>> t = time() >>>> print time() - t, clock() > 0.000596046447754 0.03 >>>> sleep(3) >>>> print time() - t, clock() > 3.03474903107 0.03 >>>> x = open("BIGFILE").read() >>>> print time() - t, clock() > 10.2008538246 1.42 > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Thu Jul 29 15:46:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 29 Jul 2010 20:46:43 +0100 Subject: Ascii to Unicode. In-Reply-To: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> References: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> Message-ID: <4C51DAA3.4050201@mrabarnett.plus.com> John Nagle wrote: > On 7/28/2010 3:58 PM, Joe Goldthwaite wrote: >> This still seems odd to me. I would have thought that the unicode >> function >> would return a properly encoded byte stream that could then simply be >> written to disk. Instead it seems like you have to re-encode the byte >> stream >> to some kind of escaped Ascii before it can be written back out. > > Here's what's really going on. > > Unicode strings within Python have to be indexable. So the internal > representation of Unicode has (usually) two bytes for each character, > so they work like arrays. > > UTF-8 is a stream format for Unicode. It's slightly compressed; > each character occupies 1 to 4 bytes, and the base ASCII characters > (0..127 only, not 128..255) occupy one byte each. The format is > described in "http://en.wikipedia.org/wiki/UTF-8". A UTF-8 file or > stream has to be parsed from the beginning to keep track of where each > Unicode character begins. So it's not a suitable format for > data being actively worked on in memory; it can't be easily indexed. > Not entirely correct. The advantage of UTF-8 is that although different codepoints might be encoded into different numbers of bytes it's easy to tell whether a particular byte is the first in its sequence, so you don't have to parse from the start of the file. It is true, however, it can't be easily indexed. > That's why it's necessary to convert to UTF-8 before writing > to a file or socket. > From debatem1 at gmail.com Thu Jul 29 17:22:24 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 29 Jul 2010 14:22:24 -0700 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: <20100729181327.74211dc6@pitrou.net> References: <1367795556.172624.1280360497965.JavaMail.root@zimbra-1.ncsa.uiuc.edu> <4c510ce5$0$1587$742ec2ed@news.sonic.net> <20100729181327.74211dc6@pitrou.net> Message-ID: On Thu, Jul 29, 2010 at 9:13 AM, Antoine Pitrou wrote: > On Wed, 28 Jul 2010 22:23:48 -0700 > geremy condra wrote: >> > >> > ? The new Python SSL module in 2.6 and later has a huge built-in >> > security hole - it doesn't verify the domain against the >> > certificate. ?As someone else put it, this means "you get to >> > talk securely with your attacker." As long as the site or proxy >> > has some valid SSL cert, any valid SSL cert copied from anywhere, >> > the new Python SSL module will tell you everything is just fine. >> > >> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle >> >> Did anything ever come of the discussion that you and Antoine had? > > As I wrote in http://bugs.python.org/issue1589, I would support adding > the necessary function(s) to the SSL module, and have urllib (and other > stdlib modules) support them. Someone needs to write a patch, though. > > Regards > > Antoine. Hmm, my understanding at the time was that there had been a decision to just adapt Heikki Toivonen's M2Crypto code, if that's just looking for someone to turn it into a patch I'll see if I can't find the time next week. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 18:43:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 22:43:43 GMT Subject: default behavior References: Message-ID: <4c52041e$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 21:43:05 +0300, Nick Raptis wrote: > On 07/29/2010 09:12 PM, wheres pythonmonks wrote: >> How do I build an "int1" type that has a default value of 1? > You mean something like: > >>> x = int() > >>> x > 0 > >>> def myint(value=1): > ... return int(value) > ... > >>> myint() > 1 > >>> > >>> > That's ugly on so many levels.. Why do you think it's ugly? It's a function that returns an int, and it provides a default value which is different from the default value of the int constructor. It's a really simple function, and it has an equally simple implementation, and it's an obvious way to do it. Not the *one* obvious way, because subclassing int is equally obvious, but still obvious. -- Steven From anushkaphotos at rediffmail.com Thu Jul 29 19:16:14 2010 From: anushkaphotos at rediffmail.com (anushkaphotos at rediffmail.com) Date: Thu, 29 Jul 2010 16:16:14 -0700 (PDT) Subject: ANUSHKA HOT PICTURES FOR BOLLYWOOD FANS Message-ID: ANUSHKA HOT PICTURES FOR BOLLYWOOD FANS ------------------------------------- http://sites.google.com/site/anushkaphotosalert From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 19:31:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 23:31:17 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c520f45$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> [snip] >> >> super() is just as explicit as len(), or str.upper(). It says, >> explicitly, that it will call the method belonging to one or more >> superclass of the given class. >> > Come on Steven, you're better than this :) . Everybody can accurately > guess what len and upper are doing without looking at the documentation. > No one can guess for super without closely looking at the documention, > or even at some good articles on the net which try to clear things up > about super. And note there is no such article about len or upper. super() is complex because the problem it is solving is a hard problem. That doesn't make it implicit, any more than (say) itertools.groupby() is implicit just because it's complex, or urllib2.request() is implicit just because some people don't know much about web protocols and have to read articles about it to learn. > As someone already said in this list, the main problem with super is > that it tends to refer to the superclass method while in fact it calls > the next MRO method. Why do you think that is a problem? That's what it is supposed to do, because that's what is needed to correctly implement multiple inheritance. > "mro" would have been the proper name for "super". That's your opinion. In any case, whether super() was called super() or mro() or aardvark() makes no difference to the functionality or whether it is useful. -- Steven From aahz at pythoncraft.com Thu Jul 29 19:38:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 29 Jul 2010 16:38:30 -0700 Subject: Possible to include \n chars in doctest code samples or output? References: <1279228462.13146.1385097561@webmail.messagingengine.com> <4C3F7D23.2060204@jollans.com> <4c3ff6f7$0$11101$c3e8da3@news.astraweb.com> Message-ID: In article <4c3ff6f7$0$11101$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >Remember that doctests aren't intended for a comprehensive test suite. WDYM not intended? Disagree with Tim Peters much? ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From steve at REMOVE-THIS-cybersource.com.au Thu Jul 29 19:49:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Jul 2010 23:49:40 GMT Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: <4c521394$0$11091$c3e8da3@news.astraweb.com> On Thu, 29 Jul 2010 11:14:24 -0700, Ethan Furman wrote: > Don't think of unicode as a byte stream. It's a bunch of numbers that > map to a bunch of symbols. Not only are Unicode strings a bunch of numbers ("code points", in Unicode terminology), but the numbers are not necessarily all the same width. The full Unicode system allows for 1,114,112 characters, far more than will fit in a two-byte code point. The Basic Multilingual Plane (BMP) includes the first 2**16 (65536) of those characters, or code points U+0000 through U+FFFF; there are a further 16 supplementary planes of 2**16 characters each, or code points U+10000 through U+10FFFF. As I understand it (and I welcome corrections), some implementations of Unicode only support the BMP and use a fixed-width implementation of 16- bit characters for efficiency reasons. Supporting the entire range of code points would require either a fixed-width of 21-bits (which would then probably be padded to four bytes), or a more complex variable-width implementation. It looks to me like Python uses a 16-bit implementation internally, which leads to some rather unintuitive results for code points in the supplementary place... >>> c = chr(2**18) >>> c '\U00040000' >>> len(c) 2 -- Steven From rodrick.brown at gmail.com Thu Jul 29 19:53:33 2010 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 29 Jul 2010 19:53:33 -0400 Subject: measuring a function time In-Reply-To: References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <20100729104339.ab45755a.darcy@druid.net> Message-ID: <81F19B09-0D5F-46A3-B7B3-6AFAC31C8ED6@gmail.com> Someone should port Perl's Benchmark.pm module to python that's such a useful module to measure a functions execution time and CPU usage. Sent from my iPhone 4. On Jul 29, 2010, at 3:43 PM, "Benjamin J. Racine" wrote: > I just use ipython's functions (that are themselves just calls to the time module functions) for timing my functions... > > Enter: > %timeit? > or > %time > > At the Ipython command prompt to get started. > > Ben R. > > On Jul 29, 2010, at 7:43 AM, D'Arcy J.M. Cain wrote: > >> On Thu, 29 Jul 2010 08:45:23 -0400 >> Joe Riopel wrote: >>> On Thu, Jul 29, 2010 at 8:34 AM, Mahmood Naderan wrote: >>>> the output should be 7600 (s) for example. What is the best and easiest way >>>> to do that? >>> >>> Take a look at time.clock() >> >> I don't know if that's what he wants. The clock() method returns >> processor time, not wall time. >> >> Python 2.6.5 (r265:79063, Jul 8 2010, 16:01:18) >> [GCC 4.1.3 20080704 prerelease (NetBSD nb2 20081120)] on netbsd5 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from time import time, clock, sleep >>>>> t = time() >>>>> print time() - t, clock() >> 0.000596046447754 0.03 >>>>> sleep(3) >>>>> print time() - t, clock() >> 3.03474903107 0.03 >>>>> x = open("BIGFILE").read() >>>>> print time() - t, clock() >> 10.2008538246 1.42 >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolves >> http://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From metolone+gmane at gmail.com Thu Jul 29 20:43:07 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 29 Jul 2010 17:43:07 -0700 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> Message-ID: "Joe Goldthwaite" wrote in message news:5A04846ED83745A8A99A944793792810 at NewMBP... > Hi Steven, > > I read through the article you referenced. I understand Unicode better > now. > I wasn't completely ignorant of the subject. My confusion is more about > how > Python is handling Unicode than Unicode itself. I guess I'm fighting my > own > misconceptions. I do that a lot. It's hard for me to understand how > things > work when they don't function the way I *think* they should. > > Here's the main source of my confusion. In my original sample, I had read > a > line in from the file and used the unicode function to create a > unicodestring object; > > unicodestring = unicode(line, 'latin1') > > What I thought this step would do is translate the line to an internal > Unicode representation. Correct. > The problem character \xe1 would have been > translated into a correct Unicode representation for the accented "a" > character. Which just so happens to be u'\xe1', which probably adds to your confusion later :^) The first 256 Unicode code points map to latin1. > > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from > the > unicodestring object and simply write that byte string to a file. I > thought > that at this point, I should have had a valid Unicode latin1 encoded file. > Instead get an error that the character \xe1 is invalid. Incorrect. The unicodestring object doesn't save the original byte string, so there is nothing to "request". > The fact that the \xe1 character is still in the unicodestring object > tells > me it wasn't translated into whatever python uses for its internal Unicode > representation. Either that or the unicodestring object returns the > original string when it's asked for a byte stream representation. Both incorrect. As I mentioned earlier, the first Unicode code points map to latin1. It *was* translated to a Unicode code point whose value (but not internal representation!) is the same as latin1. > Instead of just writing the unicodestring object, I had to do this; > > output.write(unicodestring.encode('utf-8')) This is exactly what you need to do...explicitly encode the Unicode string into a byte string. > This is doing what I thought the other steps were doing. It's translating > the internal unicodestring byte representation to utf-8 and writing it > out. > It still seems strange and I'm still not completely clear as to what is > going on at the byte stream level for each of these steps. I'm surprised that by now no one has mentioned the codecs module. You original stated you are using Python 2.4.4, which I looked up and does support the codecs module. import codecs infile = codecs.open('ascii.csv,'r','latin1') outfile = codecs.open('unicode.csv','w','utf-8') for line in infile: outfile.write(line) infile.close() outfile.close() As you can see, codecs.open takes a parameter for the encoding of the file. Lines read are automatically decoded into Unicode; Unicode lines written are automatically encoded into a byte stream. -Mark From cappy2112 at gmail.com Thu Jul 29 20:54:22 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Thu, 29 Jul 2010 17:54:22 -0700 (PDT) Subject: Enabling/Disabling remote desktop - programmatically Message-ID: <2cd40dd7-4aeb-4839-9aa8-acacf71568b2@y12g2000prb.googlegroups.com> I've already posted this in the Python W32 list, but didn't get what I'm looking for. I want to know how to disable Remote Desktop after logging to into a remote machine, to prevent subsequent logins by other users logging me out. I currently have a Windows XP system configured for coworkers to connect to using VPN & remote desktop, so they can get diagnostic data for test failures. I can disable Remote Desktop manually in Ctrl Panel, but have to navigate through several screens to do this. If I could do this using Python it would be very convenient. Have any of the Windows users on this list done this? Thanks From cappy2112 at gmail.com Thu Jul 29 20:58:17 2010 From: cappy2112 at gmail.com (Cappy2112) Date: Thu, 29 Jul 2010 17:58:17 -0700 (PDT) Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) References: Message-ID: <8ea2aad6-f3af-4b87-ac62-5a779a8021da@m17g2000prl.googlegroups.com> On Jul 29, 12:39?pm, "Benjamin J. Racine" wrote: > I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. > > I am not seeing how this might be done. ?Many thanks for your help... > > Ben Racine Ben You can actually use the sys module to do this, with just a few lines of code. This article shows you how http://www.doughellmann.com/PyMOTW/sys/tracing.html From nobody at nowhere.com Fri Jul 30 00:56:12 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 30 Jul 2010 05:56:12 +0100 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> <5A04846ED83745A8A99A944793792810@NewMBP> <4c521394$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Thu, 29 Jul 2010 23:49:40 +0000, Steven D'Aprano wrote: > It looks to me like Python uses a 16-bit implementation internally, It typically uses the platform's wchar_t, which is 16-bit on Windows and (typically) 32-bit on Unix. IIRC, it's possible to build Python with 32-bit Unicode on Windows, but that will be inefficient (because it has to convert to/from 16-bit when calling Windows API functions) and will break any C modules which pass the pointer to the internal buffer directly to API functions. From greg.ewing at canterbury.ac.nz Fri Jul 30 03:35:52 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 19:35:52 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c517a58$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bfd5uF9gqU1@mid.individual.net> Steven D'Aprano wrote: > super() is just as explicit as len(), or str.upper(). It says, > explicitly, that it will call the method belonging to one or more > superclass of the given class. That's not strictly true. It will call a method belonging to some class in the mro of self, but that class is not necessarily in the base list of the class mentioned in the super() call. It's possible for a super() call to go "sideways" in the inheritance graph. -- Greg From greg.ewing at canterbury.ac.nz Fri Jul 30 03:37:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 19:37:29 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c520f45$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bfd8tF9gqU2@mid.individual.net> Steven D'Aprano wrote: > On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > >>"mro" would have been the proper name for "super". > > That's your opinion. In any case, whether super() was called super() or > mro() or aardvark() makes no difference to the functionality or whether > it is useful. I think the point is that the name is misleading, because it makes it *sound* like it's going to call a method in a superclass, when it fact it might not. -- Greg From greg.ewing at canterbury.ac.nz Fri Jul 30 04:04:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 30 Jul 2010 20:04:42 +1200 Subject: Newbie question regarding SSL and certificate verification In-Reply-To: References: <4c510ce5$0$1587$742ec2ed@news.sonic.net> <857915511.177957.1280412428748.JavaMail.root@zimbra-1.ncsa.uiuc.edu> Message-ID: <8bfes1Fiu1U1@mid.individual.net> David Robinow wrote: > Never > use security software version 1.0 or greater. It was written by an > author insufficiently paranoid. Hmmm. So to get people to trust your security software, you should start with version 0.0 and increment by 0.0000001 for each release. :-) -- Greg From gelonida at gmail.com Fri Jul 30 04:10:13 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 10:10:13 +0200 Subject: how to build same executabl with and without console output Message-ID: Hi, What I'd like to achieve ideally is to create a py2exe program, which will only display a window (so 'compiled' as 'windows'-application) if called normally. however if being called with the option --debug it should display the graphical window plus a debug console where I can print to. Is there any trick in adding a console window to an application, that was built as 'windows' application? If above is not possible: Is there any way to compile the same python script (myprog.py) from one py2exe script into once a 'windows' executable (myprog.exe) and once into a 'console' executable (myprog_debug.exe)? TIA From __peter__ at web.de Fri Jul 30 04:40:51 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 10:40:51 +0200 Subject: default behavior References: Message-ID: wheres pythonmonks wrote: > How do I build an "int1" type that has a default value of 1? > [Hopefully no speed penalty.] > I am thinking about applications with collections.defaultdict. >>> from collections import defaultdict >>> d = defaultdict(1 .conjugate) >>> d["x"] += 2 >>> d["x"] 3 Isn't that beautiful? Almost like home;) It is also fast: $ python -m timeit -s"one = lambda: 1" "one()" 1000000 loops, best of 3: 0.213 usec per loop $ python -m timeit -s"one = 1 .conjugate" "one()" 10000000 loops, best of 3: 0.0972 usec per loop Micro-optimisation, the best excuse for ugly code... Peter From jimmy at retzlaff.com Fri Jul 30 05:00:37 2010 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Fri, 30 Jul 2010 02:00:37 -0700 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 1:10 AM, Gelonida wrote: > What I'd like to achieve ideally is to create a py2exe program, > which > will only display a window (so 'compiled' as 'windows'-application) if > called normally. > > however if being called with the option --debug it should display the > graphical window plus a debug console where I can print to. > > Is there any trick in adding a console window to an application, > that was built as 'windows' application? > > If above is not possible: > > Is there any way to compile the same python script (myprog.py) from one > py2exe script into once a 'windows' executable (myprog.exe) and once > into a 'console' executable (myprog_debug.exe)? I can't think of an easy way to achieve the first approach - I've always taken the second approach. The advanced example included with py2exe has an example of how to do this. Look at all the occurrences of test_wx in the following link to see all the pieces involved: http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup This uses an alternate form of the "windows" and "console" arguments where each target is an object with specially named member variables rather than a string that names the .py file (this string is one of the member variables). This is necessary so you can give different names to the console version and the windows version. Jimmy From jeanmichel at sequans.com Fri Jul 30 05:00:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 11:00:50 +0200 Subject: stdout of external program. In-Reply-To: <958992.74508.qm@web52905.mail.re2.yahoo.com> References: <958992.74508.qm@web52905.mail.re2.yahoo.com> Message-ID: <4C5294C2.9090704@sequans.com> Paul Lemelle wrote: > HELP! :) > > I am trying to output the following program's output to either a file > or variable, how can this be done? > > # Writing the output to a standard argv argument > > #1/usr/bin/python > > import sys > > for arg in sys.argv: > print arg > > #END > > Thanks, > Paul > > Hi Paul, after reading 4 times your post, I still don't see what you want to achieve. What are you calling a variable ? an os variable ? import sys file = open('testfile.txt', 'w') file.write(str(sys.argv)) file.close() second hit when googling your question: http://docs.python.org/tutorial/inputoutput.html JM From jeanmichel at sequans.com Fri Jul 30 05:09:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 11:09:20 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c520f45$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C5296C0.4070403@sequans.com> Steven D'Aprano wrote: > On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > > > [snip] >> As someone already said in this list, the main problem with super is >> that it tends to refer to the superclass method while in fact it calls >> the next MRO method. >> > > Why do you think that is a problem? That's what it is supposed to do, > because that's what is needed to correctly implement multiple inheritance. > > > >> "mro" would have been the proper name for "super". >> > > That's your opinion. In any case, whether super() was called super() or > mro() or aardvark() makes no difference to the functionality or whether > it is useful. > > > > I have no problem with dogs nor cats, however I have problem with cats called dogs and dogs called cats as I'm dealing with industrial programming, not litterature nor poetry. JM From duncan.booth at invalid.invalid Fri Jul 30 05:57:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Jul 2010 09:57:46 GMT Subject: default behavior References: Message-ID: Peter Otten <__peter__ at web.de> wrote: >>>> from collections import defaultdict >>>> d = defaultdict(1 .conjugate) >>>> d["x"] += 2 >>>> d["x"] > 3 > > Isn't that beautiful? Almost like home;) > > It is also fast: > > $ python -m timeit -s"one = lambda: 1" "one()" > 1000000 loops, best of 3: 0.213 usec per loop > $ python -m timeit -s"one = 1 .conjugate" "one()" > 10000000 loops, best of 3: 0.0972 usec per loop > > Micro-optimisation, the best excuse for ugly code... > Nice one, but if you are going to micro-optimise why not save a few keystrokes while you're at it and use '1 .real' instead? -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Fri Jul 30 06:21:39 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 12:21:39 +0200 Subject: default behavior References: Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >>>>> from collections import defaultdict >>>>> d = defaultdict(1 .conjugate) >>>>> d["x"] += 2 >>>>> d["x"] >> 3 >> >> Isn't that beautiful? Almost like home;) >> >> It is also fast: >> >> $ python -m timeit -s"one = lambda: 1" "one()" >> 1000000 loops, best of 3: 0.213 usec per loop >> $ python -m timeit -s"one = 1 .conjugate" "one()" >> 10000000 loops, best of 3: 0.0972 usec per loop >> >> Micro-optimisation, the best excuse for ugly code... >> > > Nice one, but if you are going to micro-optimise why not save a few > keystrokes while you're at it and use '1 .real' instead? >>> 1 .real 1 >>> 1 .conjugate >>> 1 .conjugate() real is a property, not a method. conjugate() was the first one that worked that was not __special__. I think it has the added benefit that it's likely to confuse the reader... Peter From duncan.booth at invalid.invalid Fri Jul 30 06:56:23 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 30 Jul 2010 10:56:23 GMT Subject: default behavior References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > real is a property, not a method. conjugate() was the first one that > worked that was not __special__. I think it has the added benefit that > it's likely to confuse the reader... > Ah, silly me, I should have realised that. Yes, micro-optimisations that are also micro-obfuscations are always the best. :^) -- Duncan Booth http://kupuguy.blogspot.com From ldo at geek-central.gen.new_zealand Fri Jul 30 07:16:47 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 30 Jul 2010 23:16:47 +1200 Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: In message , J.B. Brown wrote: > I personally prefer to be slightly excessive in the amount of spacing > I used, especially when parentheses are involved. > > myTuple = ( 1, 2, 3, 4, 5 ) Parentheses are punctuation. Why not leave spaces around the commas as well, to be consistent? myTuple = ( 1 , 2 , 3 , 4 , 5 ) T,FTFY. From python at bdurham.com Fri Jul 30 07:29:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 30 Jul 2010 07:29:48 -0400 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: <1280489388.15025.1387504783@webmail.messagingengine.com> > Is there any trick in adding a console window to an application, that was built as 'windows' application? I was recently wondering the same thing myself. My research indicates that its not possible to have a single Windows application that can run in both console and GUI ("Windows") modes. Here are 2 links that explain this in more detail. Malcolm From ldo at geek-central.gen.new_zealand Fri Jul 30 07:46:41 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 30 Jul 2010 23:46:41 +1200 Subject: Normalizing A Vector Message-ID: Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize it (scale all components by the same factor) so its magnitude is 1. The usual way is something like this: L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) V = (V[0] / L, V[1] / L, V[2] / L) What I don?t like is having that intermediate variable L leftover after the computation. Here?s how to do it in one step: V = tuple \ ( x / math.sqrt ( reduce(lambda a, b : a + b, (y * y for y in V), 0) ) for x in V ) which, incidentally, also works for vectors with dimensions other than 3. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 07:49:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 11:49:01 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> Message-ID: <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 19:35:52 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> super() is just as explicit as len(), or str.upper(). It says, >> explicitly, that it will call the method belonging to one or more >> superclass of the given class. > > That's not strictly true. It will call a method belonging to some class > in the mro of self, but that class is not necessarily in the base list > of the class mentioned in the super() call. Yes, that's what I said. super() can visit any superclass of the given class, not just one of the immediate base class(es). That's why it's called super() rather than base() or parent(). It would be rather pointless if super() was limited to just the base classes. > It's possible for a super() > call to go "sideways" in the inheritance graph. I doubt that very much. A class F can't inherit behaviour from a class E merely by virtue of them both being subclasses of the same hierarchy. If it did, that would be... disturbing. Example: E inherits from D. D inherits from C and B. C and B both inherit from A. F also inherits from C. F and E are "sideways" to each other (sibling classes?), but they don't inherit from each other. Perhaps you're referring to the angled lines in a diagram such as: A / \ C B \ / D / \ E F F and E don't inherit from each other, because they are sidewards to each other (they are not in each other's MRO). Regardless of the angles we draw the lines, all of D, C, B, A are above E (and F). Or downwards if you prefer to reverse the diagram. Yes, a super call might jog left from C to B, but only when being called from one of the lower classes D-F. That's still an upwards call relative to the originator, not sidewards. -- Steven From wherespythonmonks at gmail.com Fri Jul 30 07:59:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 07:59:52 -0400 Subject: default behavior In-Reply-To: References: Message-ID: Instead of defaultdict for hash of lists, I have seen something like: m={}; m.setdefault('key', []).append(1) Would this be preferred in some circumstances? Also, is there a way to upcast a defaultdict into a dict? I have also heard some people use exceptions on dictionaries to catch key existence, so passing in a defaultdict (I guess) could be hazardous to health. Is this true? W On Fri, Jul 30, 2010 at 6:56 AM, Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: >> real is a property, not a method. conjugate() was the first one that >> worked that was not __special__. I think it has the added benefit that >> it's likely to confuse the reader... >> > Ah, silly me, I should have realised that. > > Yes, micro-optimisations that are also micro-obfuscations are always the > best. :^) > > -- > Duncan Booth http://kupuguy.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 08:04:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 12:04:21 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> Message-ID: <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > > >>>"mro" would have been the proper name for "super". >> >> That's your opinion. In any case, whether super() was called super() or >> mro() or aardvark() makes no difference to the functionality or whether >> it is useful. > > I think the point is that the name is misleading, because it makes it > *sound* like it's going to call a method in a superclass, when it fact > it might not. I'm not sure I understand your point here. If you call super() from a method that doesn't exist in any superclass, then you are correct, it won't call a method in a superclass, and will raise AttributeError. But in the more sensible case that you only call super() when there is actually something to inherit, then of course it calls the method in a superclass. It certainly doesn't call methods from arbitrary unrelated classes, only those which are in the MRO. That is, superclasses. If Z is below A in the hierarchy, then we have no difficulty in identifying Z as a subclass of A, and likewise we should have no problem with identifying A as *a* (and not "the") superclass of Z, no matter how distant they are or how tangled the DIG between them. The exception would be if you could have loops in the class hierarchy, in which case the concepts of super- and sub-classes breaks down completely. But even if some other languages allowed that, Python doesn't, so we're safe. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 08:19:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jul 2010 12:19:52 GMT Subject: default behavior References: Message-ID: <4c52c368$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote: > Instead of defaultdict for hash of lists, I have seen something like: > > > m={}; m.setdefault('key', []).append(1) > > Would this be preferred in some circumstances? Sure, why not? Whichever you prefer. setdefault() is a venerable old technique, dating back to Python 2.0, and not a newcomer like defaultdict. > Also, is there a way to upcast a defaultdict into a dict? "Upcast"? Surely it is downcasting. Or side-casting. Or type-casting. Whatever. *wink* Whatever it is, the answer is Yes: >>> from collections import defaultdict as dd >>> x = dd(int) >>> x[1] = 'a' >>> x defaultdict(, {1: 'a'}) >>> dict(x) {1: 'a'} > I have also heard some people use > exceptions on dictionaries to catch key existence, so passing in a > defaultdict (I guess) could be hazardous to health. Is this true? Yes, it is true that some people use exceptions on dicts to catch key existence. The most common reason to do so is to catch the non-existence of a key so you can add it: try: mydict[x] = mydict[x] + 1 except KeyError: mydict[x] = 1 If mydict is a defaultdict with the appropriate factory, then the change is perfectly safe because mydict[x] will not raise an exception when x is missing, but merely return 0, so it will continue to work as expected and all is good. Of course, if you pass it an defaultdict with an *inappropriate* factory, you'll get an error. So don't do that :) Seriously, you can't expect to just randomly replace a variable with some arbitrarily different variable and expect it to work. You need to know what the code is expecting, and not break those expectations too badly. And now you have at least three ways of setting missing values in a dict. And those wacky Perl people say that Python's motto is "only one way to do it" :) -- Steven From V.vanBeveren at rijnhuizen.nl Fri Jul 30 08:22:33 2010 From: V.vanBeveren at rijnhuizen.nl (Vincent van Beveren) Date: Fri, 30 Jul 2010 14:22:33 +0200 Subject: The untimely dimise of a weak-reference Message-ID: <2926F4BC94217A43A2D21792DE88189339C58B6372@ex1.rijnh.nl> Hi everyone, I was working with weak references in Python, and noticed that it was impossible to create a weak-reference of bound methods. Here is a little python 3.0 program to prove my point: import weakref print("Creating object...") class A(object): def b(self): print("I am still here") a = A() def d(r): print("Aaah! Weakref lost ref") print("Creating weak reference") r = weakref.ref(a.b, d) print("Oh, wait, its already gone!") print("Ref == None, cause of untimely demise: %s" % r()) print("Object is still alive: %s" % a) print("Function is still exists: %s" % a.b) print("See:") a.b() I also tried this in Python 2.5 and 2.6 (with minor modifications to the syntax of course), and it yielded the exact same behavior. Why is this, and is there anything I can do about it? I wish to reference these bound functions, but I do not want to keep them in memory once the object they belong to is no longer referenced. Regards, Vincent van Beveren ___ Ing. V. van Beveren Software Engineer,?FOM Rijnhuizen E: V.vanBeveren at rijnhuizen.nl From hniksic at xemacs.org Fri Jul 30 08:28:59 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 30 Jul 2010 14:28:59 +0200 Subject: measuring a function time References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> Message-ID: <87tynhdugk.fsf@busola.homelinux.net> Steven D'Aprano writes: > On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > >> This should be enough >> >>>>>import time >>>>>tic = time.time() >>>>>function() >>>>>toc = time.time() >>>>>print toc - tic > > You're typing that in the interactive interpreter, which means the > timer is counting the seconds while you're typing subsequent > commands. At the very least, you need to put that code into a > function. Or, trivially improved as follows: >>> t0 = time.time(); function(); t1 = time.time() >>> print t1 - t0 This technique, while nowhere nearly as thorough as the timeit module, still gives useful results for simple measurements. From __peter__ at web.de Fri Jul 30 08:33:49 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 14:33:49 +0200 Subject: default behavior References: Message-ID: wheres pythonmonks wrote: > Instead of defaultdict for hash of lists, I have seen something like: > > > m={}; m.setdefault('key', []).append(1) > > Would this be preferred in some circumstances? In some circumstances, sure. I just can't think of them at the moment. Maybe if your code has to work in Python 2.4. > Also, is there a way to upcast a defaultdict into a dict? dict(some_defaultdict) > I have also > heard some people use exceptions on dictionaries to catch key > existence, so passing in a defaultdict (I guess) could be hazardous to > health. Is this true? A problem could arise when you swap a "key in dict" test with a "try...except KeyError". This would be an implementation detail for a dict but affect the contents of a defaultdict: >>> from collections import defaultdict >>> def update(d): ... for c in "abc": ... try: d[c] ... except KeyError: d[c] = c ... >>> d = defaultdict(lambda:"-") >>> update(d) >>> d defaultdict( at 0x7fd4ce32a320>, {'a': '-', 'c': '-', 'b': '-'}) >>> def update2(d): ... for c in "abc": ... if c not in d: ... d[c] = c ... >>> d = defaultdict(lambda:"-") >>> update2(d) >>> d defaultdict( at 0x7fd4ce32a6e0>, {'a': 'a', 'c': 'c', 'b': 'b'}) Peter From wherespythonmonks at gmail.com Fri Jul 30 08:34:52 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 08:34:52 -0400 Subject: default behavior In-Reply-To: <4c52c368$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: Sorry, doesn't the following make a copy? >>>> from collections import defaultdict as dd >>>> x = dd(int) >>>> x[1] = 'a' >>>> x > defaultdict(, {1: 'a'}) >>>> dict(x) > {1: 'a'} > > I was hoping not to do that -- e.g., actually reuse the same underlying data. Maybe dict(x), where x is a defaultdict is smart? I agree that a defaultdict is safe to pass to most routines, but I guess I could imagine that a try/except block is used in a bit of code where on the key exception (when the value is absent) populates the value with a random number. In that application, a defaultdict would have no random values. Besides a slightly different favor, does the following have applications not covered by defaultdict? m.setdefault('key', []).append(1) I think I am unclear on the difference between that and: m['key'] = m.get('key',[]).append(1) Except that the latter works for immutable values as well as containers. On Fri, Jul 30, 2010 at 8:19 AM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 07:59:52 -0400, wheres pythonmonks wrote: > >> Instead of defaultdict for hash of lists, I have seen something like: >> >> >> m={}; m.setdefault('key', []).append(1) >> >> Would this be preferred in some circumstances? > > Sure, why not? Whichever you prefer. > > setdefault() is a venerable old technique, dating back to Python 2.0, and > not a newcomer like defaultdict. > > >> Also, is there a way to upcast a defaultdict into a dict? > > "Upcast"? Surely it is downcasting. Or side-casting. Or type-casting. > Whatever. *wink* > > Whatever it is, the answer is Yes: > >>>> from collections import defaultdict as dd >>>> x = dd(int) >>>> x[1] = 'a' >>>> x > defaultdict(, {1: 'a'}) >>>> dict(x) > {1: 'a'} > > > >> I have also heard some people use >> exceptions on dictionaries to catch key existence, so passing in a >> defaultdict (I guess) could be hazardous to health. ?Is this true? > > Yes, it is true that some people use exceptions on dicts to catch key > existence. The most common reason to do so is to catch the non-existence > of a key so you can add it: > > try: > ? ?mydict[x] = mydict[x] + 1 > except KeyError: > ? ?mydict[x] = 1 > > > If mydict is a defaultdict with the appropriate factory, then the change > is perfectly safe because mydict[x] will not raise an exception when x is > missing, but merely return 0, so it will continue to work as expected and > all is good. > > Of course, if you pass it an defaultdict with an *inappropriate* factory, > you'll get an error. So don't do that :) Seriously, you can't expect to > just randomly replace a variable with some arbitrarily different variable > and expect it to work. You need to know what the code is expecting, and > not break those expectations too badly. > > And now you have at least three ways of setting missing values in a dict. > And those wacky Perl people say that Python's motto is "only one way to > do it" :) > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From hniksic at xemacs.org Fri Jul 30 08:38:32 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 30 Jul 2010 14:38:32 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> Message-ID: <87pqy5du0n.fsf@busola.homelinux.net> Gregory Ewing writes: > I think the point is that the name is misleading, because it makes it > *sound* like it's going to call a method in a superclass, when it fact > it might not. That is indeed confusing to some people, especially those who refuse to to accept the notion that "superclass" means the same as "next in MRO", maintaining instead that superclass refers to one of the base classes, their bases, etc. -- IMO a defensible position. super might have better been called next_in_mro, next_method, or next_class, except those are harder to type, and way less catchy than "super". The Dylan and CLOS operator that super is most closely based on is called (call-)next-method. From jeanmichel at sequans.com Fri Jul 30 08:43:07 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 14:43:07 +0200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C52C8DB.8060305@sequans.com> Steven D'Aprano wrote: > On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote: > > >> Steven D'Aprano wrote: >> >>> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: >>> >> > >> >>>> "mro" would have been the proper name for "super". >>>> >>> That's your opinion. In any case, whether super() was called super() or >>> mro() or aardvark() makes no difference to the functionality or whether >>> it is useful. >>> >> I think the point is that the name is misleading, because it makes it >> *sound* like it's going to call a method in a superclass, when it fact >> it might not. >> > > I'm not sure I understand your point here. If you call super() from a > method that doesn't exist in any superclass, then you are correct, it > won't call a method in a superclass, and will raise AttributeError. > > But in the more sensible case that you only call super() when there is > actually something to inherit, then of course it calls the method in a > superclass. It certainly doesn't call methods from arbitrary unrelated > classes, only those which are in the MRO. That is, superclasses. > > If Z is below A in the hierarchy, then we have no difficulty in > identifying Z as a subclass of A, and likewise we should have no problem > with identifying A as *a* (and not "the") superclass of Z, no matter how > distant they are or how tangled the DIG between them. > > The exception would be if you could have loops in the class hierarchy, in > which case the concepts of super- and sub-classes breaks down completely. > But even if some other languages allowed that, Python doesn't, so we're > safe. > > > > Quoting Michele's article (I think he's still hanging around this list) "Readers familiar will single inheritance languages, such as Java or Smalltalk, will have a clear concept of superclass in mind. This concept, however, has /no useful meaning/ in Python or in other multiple inheritance languages". the complete article on super: http://www.artima.com/weblogs/viewpost.jsp?thread=236275 super is a strange name for something that makes no sense in python (talking about superclass here). It doesn't take away the usefulness of super, but it's a proof that you can ruin a good feature with a bad name. JM From durga.disc at gmail.com Fri Jul 30 08:48:09 2010 From: durga.disc at gmail.com (Durga D) Date: Fri, 30 Jul 2010 05:48:09 -0700 (PDT) Subject: Basic Information about Python Message-ID: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Hi All, I am new to python based application developement. I am using Windows XP. 1. Can I create desktop application (just hello world program) with Python language like exe in VC++? 2. If First statement is Yes, Can I include this application with my existing setup(assume 10 MB) for windows? 3. If Second statement is Yes, What will be the setup size? Thank in advance. Regards, Durga. From ldo at geek-central.gen.new_zealand Fri Jul 30 08:51:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:51:30 +1200 Subject: Ascii to Unicode. References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: In message , Joe Goldthwaite wrote: > Ascii.csv isn't really a latin-1 encoded file. It's an ascii file with a > few characters above the 128 range that are causing Postgresql Unicode > errors. Those characters work fine in the Windows world but they're not > the correct byte representation for Unicode. In other words, the encoding you want to decode from in this case is windows-1252. From ldo at geek-central.gen.new_zealand Fri Jul 30 08:52:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:52:36 +1200 Subject: Ascii to Unicode. References: <4c51d3b6$0$1638$742ec2ed@news.sonic.net> Message-ID: In message <4c51d3b6$0$1638$742ec2ed at news.sonic.net>, John Nagle wrote: > UTF-8 is a stream format for Unicode. It's slightly compressed ... ?Variable-length? is not the same as ?compressed?. Particularly if you?re mainly using non-Roman scripts... From ldo at geek-central.gen.new_zealand Fri Jul 30 08:54:44 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:54:44 +1200 Subject: Ascii to Unicode. References: <4c50f508$0$28664$c3e8da3@news.astraweb.com> Message-ID: In message , Joe Goldthwaite wrote: > Next I tried to write the unicodestring object to a file thusly; > > output.write(unicodestring) > > I would have expected the write function to request the byte string from > the unicodestring object and simply write that byte string to a file. Encoded according to which encoding? From ldo at geek-central.gen.new_zealand Fri Jul 30 08:56:53 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 00:56:53 +1200 Subject: solving Tix problem in ubuntu jaunty References: <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20@q21g2000prm.googlegroups.com> Message-ID: In message <7cbe39d0-cac8-41d8-b80a-a148ac4b7b20 at q21g2000prm.googlegroups.com>, jimgardener wrote: > How do I correct the problem? From ldo at geek-central.gen.new_zealand Fri Jul 30 09:03:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 01:03:46 +1200 Subject: urllib timeout References: <43f464f9-3f8a-4bec-8d06-930092d5a936@g6g2000pro.googlegroups.com> Message-ID: In message <43f464f9-3f8a-4bec-8d06-930092d5a936 at g6g2000pro.googlegroups.com>, kBob wrote: > The company changed the Internet LAN connections to "Accept Automatic > settings" and "Use automatic configuration script" Look at that configuration script, figure out what it?s returning for a proxy, and put that into your Python script. From jeanmichel at sequans.com Fri Jul 30 09:04:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 15:04:31 +0200 Subject: Basic Information about Python In-Reply-To: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Message-ID: <4C52CDDF.7000906@sequans.com> Durga D wrote: > Hi All, > > I am new to python based application developement. I am using > Windows XP. > > 1. Can I create desktop application (just hello world program) with > Python > language like exe in VC++? > yes http://www.py2exe.org/ > 2. If First statement is Yes, Can I include this application with > my > existing setup(assume 10 MB) for windows? > you mean include it in a windows installer ? If so yes. > 3. If Second statement is Yes, What will be the setup size? > > > Thank in advance. > > Regards, > Durga. > > JM From __peter__ at web.de Fri Jul 30 09:06:00 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 15:06 +0200 Subject: The untimely dimise of a weak-reference References: Message-ID: Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here is a little > python 3.0 program to prove my point: > > import weakref > > print("Creating object...") > class A(object): > > def b(self): > print("I am still here") > > a = A() > > def d(r): > print("Aaah! Weakref lost ref") > > print("Creating weak reference") > > r = weakref.ref(a.b, d) The instance doesn't keep a reference of its bound method. Rather the bound method keeps a reference of its instance. Every time you say a.b you get a different bound method. What do you think should keep it alive? > print("Oh, wait, its already gone!") > print("Ref == None, cause of untimely demise: %s" % r()) > print("Object is still alive: %s" % a) > print("Function is still exists: %s" % a.b) > print("See:") > a.b() > > I also tried this in Python 2.5 and 2.6 (with minor modifications to the > syntax of course), and it yielded the exact same behavior. Why is this, > and is there anything I can do about it? I wish to reference these bound > functions, but I do not want to keep them in memory once the object they > belong to is no longer referenced. I fear you have to manage the methods' lifetime explicitly. Peter From ed at leafe.com Fri Jul 30 09:11:29 2010 From: ed at leafe.com (Ed Leafe) Date: Fri, 30 Jul 2010 09:11:29 -0400 Subject: combined functionality of ipython's %whos and pdb's next (without a resource heavy IDE) In-Reply-To: References: Message-ID: <654B798C-D98A-4856-8692-088FD6245A91@leafe.com> On Jul 29, 2010, at 3:39 PM, Benjamin J. Racine wrote: > I am trying to combine the ability to move line-by-line through the code as is done with pdb's "next" function with ipython's ability to list all variables at once... without the use of a full-fledged IDE. > > I am not seeing how this might be done. Many thanks for your help... Check out PuDB - I use it all the time. http://pypi.python.org/pypi/pudb Intro screencast is at http://vimeo.com/5255125 -- Ed Leafe From wherespythonmonks at gmail.com Fri Jul 30 09:12:51 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Fri, 30 Jul 2010 09:12:51 -0400 Subject: pylint scores Message-ID: I am starting to use pylint to look at my code and I see that it gives a rating. What values do experienced python programmers get on code not targeting the benchmark? I wrote some code, tried to keep it under 80 characters per line, reasonable variable names, and I got: 0.12 / 10. Is this a good score for one not targeting the benchmark? (pylint running in default mode) Somewhat related: Is the backslash the only way to extend arguments to statements over multiple lines? (e.g.) >>> def f(x,y,z): return(x+y+z); ... >>> f(1,2, ... 3) 6 >>> assert f(1,2,3)>0, File "", line 1 assert f(1,2,3)>0, ^ SyntaxError: invalid syntax >>> In the above, I could split the arguments to f (I guess b/c of the parens) but not for assert. I could use a backslash, but I find this ugly -- it that my only (best?) option? [I really like to assert my code to correctness and I like using the second argument to assert, but this resulted in a lot of long lines that I was unable to break except with an ugly backslash.] W From roland.hedberg at adm.umu.se Fri Jul 30 09:21:58 2010 From: roland.hedberg at adm.umu.se (Roland Hedberg) Date: Fri, 30 Jul 2010 15:21:58 +0200 Subject: Problem with Elementtree and XMLSchem instance type Message-ID: <4C52D1F6.7020209@adm.umu.se> Hi! I have the following XML snippet: .... This part after parsing with Elementtree gives me an Element instance with the following properties: > tree.tag {urn:oasis:names:tc:SAML:2.0:metadata}RoleDescriptor > tree.keys() ['{http://www.w3.org/2001/XMLSchema-instance}type'] > tree['{http://www.w3.org/2001/XMLSchema-instance}type'] fed:SecurityTokenServiceType And there is the problem, I've lost the coupling between the prefix 'fed' and the namespace "http://docs.oasis-open.org/wsfed/federation/200706". Is there any way I can get at the prefix <-> namespace mapping from an Element instance ? I've read the documentation I can find and there is nothing that tells me how to get at the mapping. If I print the Element instance the prefix 'fed' is replace by 'ns0' or something like that. Definitely something that has no connection to the original 'fed'. -- Roland From pdwjfndjbdgfyg at gmail.com Fri Jul 30 09:30:37 2010 From: pdwjfndjbdgfyg at gmail.com (097) Date: Fri, 30 Jul 2010 06:30:37 -0700 (PDT) Subject: HOT SEXY VIDEOS X Message-ID: FOR BETS HOT VIDEOS http://verysexyhotvideos.blogspot.com/ super hot lip kiss http://hotvideosfreesee.blogspot.com/2010/06/super-hot-lip-kiss.html hot lip kiss 12 http://hotvideosfreesee.blogspot.com/2010/06/hot-lip-kiss-12.html super lip kiss 567 http://hotvideosfreesee.blogspot.com/2010/06/super-lip-kiss-567.html super supr lip kiss232 http://hotvideosfreesee.blogspot.com/2010/06/super-supr-lip-kiss232.html sexy lip kiss 7890 http://hotvideosfreesee.blogspot.com/2010/06/sexy-lip-kiss-7890.html supe r hot kiss op http://hotvideosfreesee.blogspot.com/2010/06/supe-r-hot-kiss-op.html From __peter__ at web.de Fri Jul 30 09:45:37 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 15:45:37 +0200 Subject: pylint scores References: Message-ID: wheres pythonmonks wrote: > I am starting to use pylint to look at my code and I see that it gives a > rating. What values do experienced python programmers get on code not > targeting the benchmark? > > I wrote some code, tried to keep it under 80 characters per line, > reasonable variable names, and I got: > > 0.12 / 10. > > Is this a good score for one not targeting the benchmark? (pylint > running in default mode) No. About 5 is typically OK for undocumented code. I've heard. Ratings do not always make sense: $ for f in /usr/lib/python2.6/{glob,csv,doctest,collections}.py; do echo $f; pylint 2>/dev/null $f | grep "Your code has"; done /usr/lib/python2.6/glob.py Your code has been rated at 8.54/10 /usr/lib/python2.6/csv.py Your code has been rated at 6.45/10 /usr/lib/python2.6/doctest.py Your code has been rated at 7.77/10 /usr/lib/python2.6/collections.py Your code has been rated at -4.71/10 $ For mainstream code you can easily reach 10 by adding bogus docstrings and pointless long variable names, i. e. you can get higher scores for lower code quality. Peter PS: My favourite wtf message is "too few public methods" From alain at dpt-info.u-strasbg.fr Fri Jul 30 09:46:14 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 30 Jul 2010 15:46:14 +0200 Subject: Normalizing A Vector References: Message-ID: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Lawrence D'Oliveiro writes: > Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize > it (scale all components by the same factor) so its magnitude is 1. > > The usual way is something like this: > > L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > V = (V[0] / L, V[1] / L, V[2] / L) > > What I don?t like is having that intermediate variable L leftover after the > computation. Well, it also guarantees that the square root is computed once. > Here?s how to do it in one step: > > V = tuple \ > ( x / math.sqrt > ( > reduce(lambda a, b : a + b, (y * y for y in V), 0) > ) > for x in V > ) > > which, incidentally, also works for vectors with dimensions other than 3. And how many times does it call math.sqrt? (That's actually not easy to test. Does any insider know the answer? Does the compiler hoist the math.sqrt(...) out of the implicit loop? I guess not, because it can't assert that reduce has no side effect.) Your best bet is to define a function that does the normalization. Your (local) name will disappear at the end of the call. If you want it to work for any vector size: def norm(V): L = math.sqrt( sum( [x**2 for x in V] ) ) return [ x/L for x in V ] If you do a lot of such computations, have a look at numpy. -- Alain. From davea at ieee.org Fri Jul 30 09:51:08 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 30 Jul 2010 09:51:08 -0400 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: <1280489388.15025.1387504783@webmail.messagingengine.com> References: <1280489388.15025.1387504783@webmail.messagingengine.com> Message-ID: <4C52D8CC.6040104@ieee.org> python at bdurham.com wrote: >> Is there any trick in adding a console window to an application, that was built as 'windows' application? >> > > I was recently wondering the same thing myself. My research indicates > that its not possible to have a single Windows application that can run > in both console and GUI ("Windows") modes. > > Here are 2 links that explain this in more detail. > > > > > Malcolm > > Since we're talking MS Windows here, see: http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx You can access the AllocConsole and related functions with the win32 module: win32console This module is part of the win32 extensions, and also part of ActivePython distribution. DaveA From durga.disc at gmail.com Fri Jul 30 09:55:33 2010 From: durga.disc at gmail.com (Durga D) Date: Fri, 30 Jul 2010 06:55:33 -0700 (PDT) Subject: Basic Information about Python References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> Message-ID: <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Hi JM, Thanks alot for your prompt response. If I include into windows setup, what will be setup size (assume before include 10 MB)? i mean, python supporting dlls/libs size for python exe. Regards, Durga. On Jul 30, 6:04?pm, Jean-Michel Pichavant wrote: > Durga D wrote: > > Hi All, > > > ? I am new to python based application developement. I am using > > Windows XP. > > > ? 1. Can I create desktop application (just hello world program) with > > Python > > language like exe in VC++? > > yeshttp://www.py2exe.org/> ? 2. If First statement is Yes, Can I include this application with > > my > > existing setup(assume 10 MB) for windows? > > you mean include it in a windows installer ? If so yes. > > > ? 3. If Second statement is Yes, What will be the setup size? > > > ? Thank in advance. > > > Regards, > > Durga. > > JM From V.vanBeveren at rijnhuizen.nl Fri Jul 30 10:06:17 2010 From: V.vanBeveren at rijnhuizen.nl (Vincent van Beveren) Date: Fri, 30 Jul 2010 16:06:17 +0200 Subject: The untimely dimise of a weak-reference In-Reply-To: References: Message-ID: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> Hi Peter, I did not know the object did not keep track of its bound methods. What advantage is there in creating a new bound method object each time its referenced? It seems kind of expensive. Regards, Vincent -----Original Message----- From: Peter Otten [mailto:__peter__ at web.de] Sent: vrijdag 30 juli 2010 15:06 To: python-list at python.org Subject: Re: The untimely dimise of a weak-reference Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here is a little > python 3.0 program to prove my point: > > import weakref > > print("Creating object...") > class A(object): > > def b(self): > print("I am still here") > > a = A() > > def d(r): > print("Aaah! Weakref lost ref") > > print("Creating weak reference") > > r = weakref.ref(a.b, d) The instance doesn't keep a reference of its bound method. Rather the bound method keeps a reference of its instance. Every time you say a.b you get a different bound method. What do you think should keep it alive? > print("Oh, wait, its already gone!") > print("Ref == None, cause of untimely demise: %s" % r()) > print("Object is still alive: %s" % a) > print("Function is still exists: %s" % a.b) > print("See:") > a.b() > > I also tried this in Python 2.5 and 2.6 (with minor modifications to the > syntax of course), and it yielded the exact same behavior. Why is this, > and is there anything I can do about it? I wish to reference these bound > functions, but I do not want to keep them in memory once the object they > belong to is no longer referenced. I fear you have to manage the methods' lifetime explicitly. Peter From __peter__ at web.de Fri Jul 30 10:18:39 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 16:18:39 +0200 Subject: The untimely dimise of a weak-reference References: Message-ID: Vincent van Beveren wrote: > I did not know the object did not keep track of its bound methods. What > advantage is there in creating a new bound method object each time its > referenced? It seems kind of expensive. While I didn't measure it I suppose that it saves a lot of memory. Peter From marduk at letterboxes.org Fri Jul 30 10:20:19 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 30 Jul 2010 10:20:19 -0400 Subject: measuring a function time In-Reply-To: <87tynhdugk.fsf@busola.homelinux.net> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> <87tynhdugk.fsf@busola.homelinux.net> Message-ID: <1280499619.659223.3.camel@paska> On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote: > Steven D'Aprano writes: > > > On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: > > > >> This should be enough > >> > >>>>>import time > >>>>>tic = time.time() > >>>>>function() > >>>>>toc = time.time() > >>>>>print toc - tic > > > > You're typing that in the interactive interpreter, which means the > > timer is counting the seconds while you're typing subsequent > > commands. At the very least, you need to put that code into a > > function. > > Or, trivially improved as follows: > > >>> t0 = time.time(); function(); t1 = time.time() > >>> print t1 - t0 I'll just throw this out. I sometimes use a decorator to keep track of a functions execution times: def timed_function(f): """Function decorator that records the execution time of a function""" import time def funct(*args, **kwargs): __starttime = time.time() result = f(*args, **kwargs) __endtime = time.time() funct.runtime = __endtime - __starttime return result return funct Then >>> from goodies import timed_function >>> from time import sleep >>> @timed_function ... def test(n): ... sleep(n) ... >>> test(4) >>> test.runtime 4.003864049911499 Works for simple stuff anyway. -a From eliben at gmail.com Fri Jul 30 10:24:34 2010 From: eliben at gmail.com (Eli Bendersky) Date: Fri, 30 Jul 2010 17:24:34 +0300 Subject: Basic Information about Python In-Reply-To: <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Message-ID: On Fri, Jul 30, 2010 at 16:55, Durga D wrote: > Hi JM, > > Thanks alot for your prompt response. > > If I include into windows setup, what will be setup size (assume > before include 10 MB)? i mean, python supporting dlls/libs size for > python exe. > IIRC, the size of a simple "hello world" script packed with py2exe or PyInstaller is around 2-3 MB. If you use large GUI libraries (like PyQt or wxPython) it goes up to 6-10MB, and so on (more libraries -> larger .exe) Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri Jul 30 10:44:15 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 30 Jul 2010 16:44:15 +0200 Subject: The untimely dimise of a weak-reference In-Reply-To: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> References: <2926F4BC94217A43A2D21792DE88189339C58B6373@ex1.rijnh.nl> Message-ID: Am 30.07.2010 16:06, schrieb Vincent van Beveren: > I did not know the object did not keep track of its bound methods. What advantage is there in creating a new bound method object each time its referenced? It seems kind of expensive. Instances of a class have no means of storing the bound method object. The or unbound bound method is a simple and small wrapper that keeps a reference to the class, "self" and the function object. Python keeps a pool of empty method objects in a free list. The creation of a new bound method just takes a few pointer assignments and three INCREFs. Christian From python at mrabarnett.plus.com Fri Jul 30 10:50:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jul 2010 15:50:56 +0100 Subject: measuring a function time In-Reply-To: <1280499619.659223.3.camel@paska> References: <831343.82061.qm@web50006.mail.re2.yahoo.com> <4c5178ae$0$11091$c3e8da3@news.astraweb.com> <87tynhdugk.fsf@busola.homelinux.net> <1280499619.659223.3.camel@paska> Message-ID: <4C52E6D0.3040503@mrabarnett.plus.com> Albert Hopkins wrote: > On Fri, 2010-07-30 at 14:28 +0200, Hrvoje Niksic wrote: >> Steven D'Aprano writes: >> >>> On Thu, 29 Jul 2010 14:42:58 +0200, Matteo Landi wrote: >>> >>>> This should be enough >>>> >>>>>>> import time >>>>>>> tic = time.time() >>>>>>> function() >>>>>>> toc = time.time() >>>>>>> print toc - tic >>> You're typing that in the interactive interpreter, which means the >>> timer is counting the seconds while you're typing subsequent >>> commands. At the very least, you need to put that code into a >>> function. >> Or, trivially improved as follows: >> >>>>> t0 = time.time(); function(); t1 = time.time() >>>>> print t1 - t0 > > I'll just throw this out. I sometimes use a decorator to keep track of > a functions execution times: > > > def timed_function(f): > """Function decorator that records the execution time of a > function""" > import time > def funct(*args, **kwargs): > __starttime = time.time() > result = f(*args, **kwargs) > __endtime = time.time() > funct.runtime = __endtime - __starttime > > return result > return funct > > Then > > >>> from goodies import timed_function > >>> from time import sleep > >>> @timed_function > ... def test(n): > ... sleep(n) > ... > >>> test(4) > >>> test.runtime > 4.003864049911499 > > Works for simple stuff anyway. > That won't work very well for functions which don't run for long. You could fix that by adding a counter for the number of times it's run and the total time. From pdl5000 at yahoo.com Fri Jul 30 12:19:32 2010 From: pdl5000 at yahoo.com (Paul Lemelle) Date: Fri, 30 Jul 2010 09:19:32 -0700 (PDT) Subject: Access stdout from external program. Message-ID: <771014.43405.qm@web52907.mail.re2.yahoo.com> JM, Thanks for the response.? I am trying to capture the stdout of a program from another program. Example, I want to launch the below program from a second python script then capture the first's program stdout to a file or variable. Is this possible? Thanks again, Paul Paul Lemelle wrote: > HELP! :) > > I am trying to output the following program's output to either a file > or variable, how can this be done? > > # Writing the output to a standard argv argument > > #1/usr/bin/python > > import sys > > for arg in sys.argv: >?? print arg > > #END > > Thanks, > Paul > > Hi Paul, after reading 4 times your post, I still don't see what you want to achieve. What are you calling a variable ? an os variable ? import sys file = open('testfile.txt', 'w') file.write(str(sys.argv)) file.close() second hit when googling your question: http://docs.python.org/tutorial/inputoutput.html JM -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Jul 30 12:28:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 30 Jul 2010 18:28:30 +0200 Subject: Access stdout from external program. In-Reply-To: <771014.43405.qm@web52907.mail.re2.yahoo.com> References: <771014.43405.qm@web52907.mail.re2.yahoo.com> Message-ID: <4C52FDAE.6060803@sequans.com> Paul Lemelle wrote: > JM, > > Thanks for the response. > > I am trying to capture the stdout of a program from another program. > Example, I want to launch the below program from a second python > script then capture the first's program stdout to a file or variable. > > Is this possible? > > Thanks again, > Paul > use the subprocess module. import subprocess proc = subprocess.Popen(['echo', 'Hello World'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = proc.communicate() print out >> Hello World more details here http://docs.python.org/library/subprocess.html JM From python at rcn.com Fri Jul 30 12:34:13 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 30 Jul 2010 09:34:13 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <98887867-d317-46e1-8bd0-75359ccb43b1@w15g2000pro.googlegroups.com> <8b42njFemaU1@mid.individual.net> Message-ID: On Jul 25, 5:30?pm, Gregory Ewing wrote: > Raymond Hettinger wrote: > > Every class > > in the MRO implementing the target method *must* call super() to give > > the next class in the MRO a chance to run. > > EXCEPT for the last one, which must NOT call super! > > The posted example happens to work because object has > a default __init__ method that does nothing. But this > is not generally true of other methods, which means you > need a "terminating" class at the end of the MRO whose > methods don't call super. That is an important point and it is what Guido does in his examples: http://www.python.org/download/releases/2.2.3/descrintro/#cooperation The design options are: * if overriding a method provided by object() such as __init__(), __getattribute__() or __setattr__(), then you should call super() in each class that overrides or extends those methods. * if you know the whole class structure in advance, you call super() in every class except the last one -- that is what Guido does in the save() example. * if you don't know the whole class structure in advance, then you can't be sure which is that last class in the mro with the target method, so you need to wrap the super() call in a try / except AttributeError Raymond From kevinlcarlson at gmail.com Fri Jul 30 13:09:12 2010 From: kevinlcarlson at gmail.com (kevinlcarlson) Date: Fri, 30 Jul 2010 10:09:12 -0700 (PDT) Subject: Basic Information about Python References: <95e7b9a6-af55-4c61-88b3-ad6470e0845b@i19g2000pro.googlegroups.com> <98cfeeb8-03fc-46a8-ac87-840d168f1df5@v6g2000prd.googlegroups.com> Message-ID: <6ba18e21-b415-49f9-b96e-159d92e9b4a7@v32g2000prd.googlegroups.com> On Jul 30, 6:55?am, Durga D wrote: > Hi JM, > > ? ?Thanks alot for your prompt response. > > ? ?If I include into windows setup, what will be setup size (assume > before include 10 MB)? i mean, python supporting dlls/libs size for > python exe. > > Regards, > Durga. > > On Jul 30, 6:04?pm, Jean-Michel Pichavant > wrote: > > > Durga D wrote: > > > Hi All, > > > > ? I am new to python based application developement. I am using > > > Windows XP. > > > > ? 1. Can I create desktop application (just hello world program) with > > > Python > > > language like exe in VC++? > > > yeshttp://www.py2exe.org/> ? 2. If First statement is Yes, Can I include this application with > > > my > > > existing setup(assume 10 MB) for windows? > > > you mean include it in a windows installer ? If so yes. > > > > ? 3. If Second statement is Yes, What will be the setup size? > > > > ? Thank in advance. > > > > Regards, > > > Durga. > > > JM > > I use Pyinstaller with good results. The Python runtime dll is about two megs, plus a few others depending on what imports you are using. For example, using wxPython to create a Windows app will add several files totaling several megs. You can then simply copy the distribution file directory to the target machine, or use any good installer software. http://www.pyinstaller.org/ From subhakolkata1234 at gmail.com Fri Jul 30 13:23:44 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 30 Jul 2010 10:23:44 -0700 (PDT) Subject: Two minor questions on Class Message-ID: Dear Group, Hope everyone is fine. I was trying some examples of Python class. I took the following example from Ubuntu forum[http://ubuntuforums.org/ showthread.php?t=578930] class Person(object): def _init_(self,name,age): self.name=name self.age=age as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am getting the following error: >>> p=Person('Subha',40) Traceback (most recent call last): File "", line 1, in p=Person('Subha',40) TypeError: object.__new__() takes no parameters My question is, why the error is coming? Any problem in writing it? Can arguments be passed to class (other than inheritance) directly like this? As I was practising some early examples on class, does Python exist with any built in class, like the rich library of built in functions? Any good URL to learn examples? If any one can help, I would be grateful. As I pasted the code from GUI to notepad, there may be slight indentation problem, sorry for the same. Thanks in advance, Best Regards, Subhabrata. From nt_mahmood at yahoo.com Fri Jul 30 13:24:10 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 10:24:10 -0700 (PDT) Subject: how python works Message-ID: <953403.23661.qm@web50003.mail.re2.yahoo.com> I want to know how python?executes a .py file.?Sometimes when I run a file,?I get an error that?there is a syntax error. This shows that the parser read and parse the whole file. Sometimes?in the middle of the run I get an error that?another line has problem. So how does it work? if it doesn't compile and read line by line them why some times I get error?just before run? ? // Naderan *Mahmood; -------------- next part -------------- An HTML attachment was scrubbed... URL: From shashank.sunny.singh at gmail.com Fri Jul 30 13:36:28 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Fri, 30 Jul 2010 23:06:28 +0530 Subject: Two minor questions on Class In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 10:53 PM, joy99 wrote: > class Person(object): > def _init_(self,name,age): > self.name=name > self.age=age > > constructor has double underscores (both as prefix and suffix) __init__ -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jul 30 13:48:58 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 30 Jul 2010 19:48:58 +0200 Subject: Two minor questions on Class References: Message-ID: joy99 wrote: > class Person(object): > def _init_(self,name,age): > self.name=name > self.age=age > > as i wrote the code using IDLE on WinXP SP2, with Python2.6.5, I am > getting the following error: > > >>> p=Person('Subha',40) > > Traceback (most recent call last): > File "", line 1, in > p=Person('Subha',40) > TypeError: object.__new__() takes no parameters > > My question is, why the error is coming? Any problem in writing it? The so-called special methods in Python start with two underscores and end with two underscores, i. e. the initializer is called __init__ not _init_ > If any one can help, I would be grateful. As I pasted the code from > GUI to notepad, there may be slight indentation problem, sorry for the > same. It looks fine here. Peter From nagle at animats.com Fri Jul 30 14:04:52 2010 From: nagle at animats.com (John Nagle) Date: Fri, 30 Jul 2010 11:04:52 -0700 Subject: Use cases for "setattr" in existing code Message-ID: <4C531444.6010103@animats.com> I've been looking at existing code, using Google Code search, to see what use cases for "setattr" are actually used in production code. High-performance implementations like Shed Skin try to avoid dynamic creation of attributes, so it's worth seeing where this feature is used in production. 1. Copying "setattr" is used by "copy" and "pickle" to construct new objects without calling their constructors. This is seen only in code which also uses the CPython feature that the class of an object can be changed by storing into the "__class__" attribute. 2. Proxying A local object is being created as a proxy for some remote object. This shows up in the Python shim for Remember the Milk, in the wrapper for a restricted execution shell "rexec.py" 3. Representation of some other data structure. This is typically seen where some XML or JSON structure has been translated into a tree of Python objects, and attribute access is being used to access the data from the original object. This can result in name clashes with existing attributes and keywords. Used by BeautifulSoup. 4. Ordered dictionaries "odict.py" uses "setattr", but with the comment "FIXME", noting that unrestricted "setattr" can break the built-in attributes. 5. Enums The Google Wave API uses "setattr" in StringEnum, which creates an enumeration-like object. 6. Test platforms "setattr" is used in "Mocker" to insert shim objects for test purposes. This is a special case of proxying. Note that in all the above cases, "setattr" is being used during (or even prior to) object construction. It's rarely used on "live" objects. For the above cases, a mechanism for constructing general objects would do the job. Something like attrdict = { 'a' : 1, 'b' : 2 } obj = make_object('classname', attrdict) There are clearly use cases for dynamic object construction, but modifying the structure of an object after creation is quite rare. John Nagle From burton at userful.com Fri Jul 30 14:06:56 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 30 Jul 2010 12:06:56 -0600 Subject: how python works References: <953403.23661.qm@web50003.mail.re2.yahoo.com> Message-ID: Mahmood Naderan writes: > I want to know how python executes a .py file. Sometimes when I run a > file, I get an error that there is a syntax error. This shows that the > parser read and parse the whole file. Sometimes in the middle of the > run I get an error that another line has problem. So how does it work? > if it doesn't compile and read line by line them why some times I get > error just before run? Python first complies the file, which will find any syntax errors that you have in your code. If there are any, then it will stop there before executing the resulting compiled code. If the compilation is successful, it will then run the code, where you might have run-time errors, which are code with a proper syntax but errors during execution. -- Burton Samograd From nt_mahmood at yahoo.com Fri Jul 30 14:16:53 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 11:16:53 -0700 (PDT) Subject: how python works In-Reply-To: References: <953403.23661.qm@web50003.mail.re2.yahoo.com> Message-ID: <930269.70649.qm@web50002.mail.re2.yahoo.com> So is it a compiler or interpreter? ? // Naderan *Mahmood; ________________________________ From: Burton Samograd To: python-list at python.org Sent: Fri, July 30, 2010 10:36:56 PM Subject: Re: how python works Mahmood Naderan writes: > I want to know how python executes a .py file. Sometimes when I run a > file, I get an error that there is a syntax error. This shows that the > parser read and parse the whole file. Sometimes in the middle of the > run I get an error that another line has problem. So how does it work? > if it doesn't compile and read line by line them why some times I get > error just before run? Python first complies the file, which will find any syntax errors that you have in your code.? If there are any, then it will stop there before executing the resulting compiled code.? If the compilation is successful, it will then run the code, where you might have run-time errors, which are code with a proper syntax but errors during execution. -- Burton Samograd -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Fri Jul 30 14:17:58 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 30 Jul 2010 19:17:58 +0100 Subject: Library versions In-Reply-To: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> References: <2cb0c88b-58ea-4704-8578-2ebd766f1269@t10g2000yqg.googlegroups.com> Message-ID: <4C531756.3040401@simplistix.co.uk> Peo wrote: > Is there some other smart way to do acheive this? Just turn them info python packages, and use buildout, pip or some other python package management tool to create the versions. You may, of course, just be able to svn the lot of them... (then you don't need to worry about numbering them at all) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From burton at userful.com Fri Jul 30 14:25:37 2010 From: burton at userful.com (Burton Samograd) Date: Fri, 30 Jul 2010 12:25:37 -0600 Subject: how python works References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> Message-ID: Mahmood Naderan writes: > So is it a compiler or interpreter? There's a compiler that compiles python to bytecode which is then interpreted. This saves the interpreter from having to re-parse the code at run time. So, it's an interpreter that compiles the code first. -- Burton Samograd From clp2 at rebertia.com Fri Jul 30 14:37:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 30 Jul 2010 11:37:00 -0700 Subject: Normalizing A Vector In-Reply-To: References: Message-ID: On Fri, Jul 30, 2010 at 4:46 AM, Lawrence D'Oliveiro wrote: > Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize > it (scale all components by the same factor) so its magnitude is 1. > > The usual way is something like this: > > ? ?L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > ? ?V = (V[0] / L, V[1] / L, V[2] / L) > > What I don?t like is having that intermediate variable L leftover after the > computation. Here?s how to do it in one step: I suppose you'd be a fan of the proposed "given"/"where" statement then (but its prognosis isn't great): http://www.python.org/dev/peps/pep-3150/ Cheers, Chris -- http://blog.rebertia.com From me+list/python at ixokai.io Fri Jul 30 14:43:27 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 30 Jul 2010 11:43:27 -0700 Subject: how python works In-Reply-To: <930269.70649.qm@web50002.mail.re2.yahoo.com> References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> Message-ID: <4C531D4F.7080108@ixokai.io> On 7/30/10 11:16 AM, Mahmood Naderan wrote: > So is it a compiler or interpreter? Neither/both, depending on your definition of either word. It does not compile to machine code: it compiles to byte code (which it then usually, but not always, stores in a pyc file alongside the py file). It does not interpret the Python code on the fly, it is a VM which "interprets" the byte code. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From dieterbest at gmail.com Fri Jul 30 15:15:14 2010 From: dieterbest at gmail.com (Dieter) Date: Fri, 30 Jul 2010 12:15:14 -0700 (PDT) Subject: ImportError: No module named binascii Message-ID: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Hi there, I installed python 2.7 from the tar ball on python.org. the installation was pretty uneventful. However, I need to run someone elses python code and get the error message ImportError: No module named binascii Any recommendations how to correct this? Is there another tar file somewhere that I can download to install this missing module? Thanks a lot in advance. From news1234 at free.fr Fri Jul 30 15:18:15 2010 From: news1234 at free.fr (News123) Date: Fri, 30 Jul 2010 21:18:15 +0200 Subject: pylint scores In-Reply-To: References: Message-ID: <4C532577.8010906@free.fr> On 07/30/2010 03:12 PM, wheres pythonmonks wrote: > I am starting to use pylint to look at my code and I see that it gives a rating. > What values do experienced python programmers get on code not > targeting the benchmark? > > I wrote some code, tried to keep it under 80 characters per line, > reasonable variable names, and I got: > > 0.12 / 10. > > Is this a good score for one not targeting the benchmark? (pylint > running in default mode) > It's not a goodf core, but arrives easily if you never ran pylint before. With very little effort you should be able to be above 5 with a little more effort above 7 > Somewhat related: Is the backslash the only way to extend arguments > to statements over multiple lines? (e.g.) if you have an opening parenthesis, or bracked, then you don't need a backslash so instead of if longlonglonglonglonglonglonglongvar == \ otherlonglonglonglongvar: you could also write: if (longlonglonglonglonglonglonglongvar == otherlonglonglonglongvar): same works of course with asserts. > >>>> def f(x,y,z): return(x+y+z); > ... >>>> f(1,2, > ... 3) > 6 >>>> assert f(1,2,3)>0, > File "", line 1 > assert f(1,2,3)>0, > ^ > SyntaxError: invalid syntax >>>> > > In the above, I could split the arguments to f (I guess b/c of the > parens) but not for assert. I could use a backslash, but I find this > ugly -- it that my only (best?) option? > > [I really like to assert my code to correctness and I like using the > second argument to assert, but this resulted in a lot of long lines > that I was unable to break except with an ugly backslash.] > > W From nt_mahmood at yahoo.com Fri Jul 30 15:19:18 2010 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Fri, 30 Jul 2010 12:19:18 -0700 (PDT) Subject: how python works In-Reply-To: <4C531D4F.7080108@ixokai.io> References: <953403.23661.qm@web50003.mail.re2.yahoo.com> <930269.70649.qm@web50002.mail.re2.yahoo.com> <4C531D4F.7080108@ixokai.io> Message-ID: <687136.2977.qm@web50003.mail.re2.yahoo.com> >Neither/both, depending on your definition of either word. It does not >compile to machine code: it compiles to byte code (which it then >usually, but not always, stores in a pyc file alongside the py file). It >does not interpret the Python code on the fly, it is a VM which >"interprets" the byte code. >So, it's an interpreter that compiles the code first. Thanks. I got it. ? // Naderan *Mahmood; ________________________________ From: Stephen Hansen To: python-list at python.org Sent: Fri, July 30, 2010 11:13:27 PM Subject: Re: how python works On 7/30/10 11:16 AM, Mahmood Naderan wrote: > So is it a compiler or interpreter? Neither/both, depending on your definition of either word. It does not compile to machine code: it compiles to byte code (which it then usually, but not always, stores in a pyc file alongside the py file). It does not interpret the Python code on the fly, it is a VM which "interprets" the byte code. -- ? Stephen Hansen ? ... Also: Ixokai ? ... Mail: me+list/python (AT) ixokai (DOT) io ? ... Blog: http://meh.ixokai.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Fri Jul 30 15:26:27 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 21:26:27 +0200 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: <4C52D8CC.6040104@ieee.org> References: <1280489388.15025.1387504783@webmail.messagingengine.com> <4C52D8CC.6040104@ieee.org> Message-ID: Hi, On 07/30/2010 03:51 PM, Dave Angel wrote: > python at bdurham.com wrote: >>> Is there any trick in adding a console window to an application, that >>> was built as 'windows' application? ,,, >>> Since we're talking MS Windows here, see: > > http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx > > You can access the AllocConsole and related functions with the win32 > module: > win32console > > This module is part of the win32 extensions, and also part of > ActivePython distribution. > Thanks a lot for your answer I'll check this out. From aahz at pythoncraft.com Fri Jul 30 15:26:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Jul 2010 12:26:42 -0700 Subject: py2app with weave fails References: <4f6430e5-31ea-450d-a2b9-56442a7141fa@k19g2000yqc.googlegroups.com> Message-ID: In article <4f6430e5-31ea-450d-a2b9-56442a7141fa at k19g2000yqc.googlegroups.com>, Soren wrote: > >I'm trying to create a standalone app using py2app, but it seems no >matter what I do I get this error: Try pythonmac-sig at python.org -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan From gelonida at gmail.com Fri Jul 30 15:27:48 2010 From: gelonida at gmail.com (Gelonida) Date: Fri, 30 Jul 2010 21:27:48 +0200 Subject: [Py2exe-users] how to build same executabl with and without console output In-Reply-To: References: Message-ID: On 07/30/2010 11:00 AM, Jimmy Retzlaff wrote: > On Fri, Jul 30, 2010 at 1:10 AM, Gelonida wrote: >> What I'd like to achieve ideally is to create a py2exe program, >> which >> will only display a window (so 'compiled' as 'windows'-application) if >> called normally. >> ... >> >> Is there any way to compile the same python script (myprog.py) from one >> py2exe script into once a 'windows' executable (myprog.exe) and once >> into a 'console' executable (myprog_debug.exe)? > > I can't think of an easy way to achieve the first approach - I've > always taken the second approach. The advanced example included with > py2exe has an example of how to do this. Look at all the occurrences > of test_wx in the following link to see all the pieces involved: > > http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup > > This uses an alternate form of the "windows" and "console" arguments > where each target is an object with specially named member variables > rather than a string that names the .py file (this string is one of > the member variables). This is necessary so you can give different > names to the console version and the windows version. > Thanks, I'll read thorugh it. From Space998 at hotmail.com Fri Jul 30 15:30:11 2010 From: Space998 at hotmail.com (spudnik) Date: Fri, 30 Jul 2010 12:30:11 -0700 (PDT) Subject: trace of Thermite (tm) at WTC, almost no asbestos: if the main beams had been clad, they mightn't have weakened enough to collapse! References: <0265d1a2-e8c3-428f-85f4-51ce0aa68e0a@t10g2000yqg.googlegroups.com> <9b6a9f32-333c-4e2a-a621-47f7770bb88e@x20g2000pro.googlegroups.com> Message-ID: <36e42adf-cd1e-4387-8d65-3170b3fa7799@h17g2000pri.googlegroups.com> here are some speeches about the British World Wars, collected in one book on http://tarpley.net: How the Venetian System Was Transplanted Into England New Federalist, June 3, 1996 The British Empire Bid for Undisputed World Domination, 1850-1870 Schiller Institute Food For Peace Conference, Chicago, February 22-23, 1992 Lord Palmerston?s Multicultural Human Zoo ICLC Conference, February 20, 1994 King Edward VII: Evil Demiurge of the Triple Entente and World War 1 ICLC Conference, February, 1995 Sir Edward Grey Turned Sarajevo Crisis Into War Printed in The American Almanac, March, 1995 The Versailles Thesis: The Roots of WWI, and WWII Conference Speech by Webster Tarpley, Schiller Institute Food For Peace Conference, Chicago, Illinois, February 22-23, 1992. The Versailles Treaty: The War Guilt Clause Printed in the American Almanac, March, 1995 British Financial Warfare: 1929; 1931-33; How The City Of London Created The Great Depression thus: we aren't all einsteinians; you are the one, who insists upon his reification of the corpuscle, which is just a willy-nilly, mere interpretation of "quantum of light," vis-a-vu Planck's great idea and the electonic trace in the photo-electrical effect.... well, his and Infeld's acoustic fridge was pretty cool! thus: there are two 3d versions of the pythag.thm., each with different dimensional attributes. iff you don't study Fermat's numbertheorie, you're up Shitz Creek without a paddle; however, it is better to start with his "reconstruction of Euclid's porisms," although they are just planar (synthetic geometry: see "Geometrical Fragments," belowsville .-) > NO! thus: and, the other half d'oil evaporates, as has been shown of late (again) in the newspapers. Congress and the Administration are a bit behind, in using Iran Oil's big blow-out in the Gulf, to leverage BP's cap&trade nostrum; eh? a-yup: Such microbes have been found in every ocean of the world sampled, from the Arctic to Antarctica. But there are reasons to think that the process may occur more quickly in the Gulf than in other oceans. --les ducs d'oil! http://tarpley.net/online-books/ --Light, A History! http://wlym.com/~animations/fermat/index.html From python at mrabarnett.plus.com Fri Jul 30 16:06:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 30 Jul 2010 21:06:52 +0100 Subject: ImportError: No module named binascii In-Reply-To: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> References: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Message-ID: <4C5330DC.1030606@mrabarnett.plus.com> Dieter wrote: > Hi there, > > I installed python 2.7 from the tar ball on python.org. the > installation was pretty uneventful. However, I need to run someone > elses python code and get the error message > > ImportError: No module named binascii > > Any recommendations how to correct this? Is there another tar file > somewhere that I can download to install this missing module? > > Thanks a lot in advance. > There isn't a separate binascii module. Have you tried: >>> import binascii at the Python prompt? That works for me (Windows XP) and will show whether it's missing somehow. From davea at ieee.org Fri Jul 30 17:04:08 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 30 Jul 2010 17:04:08 -0400 Subject: ImportError: No module named binascii In-Reply-To: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> References: <72c4c9a1-3831-4f8e-b2fa-efe2882a4434@y12g2000prb.googlegroups.com> Message-ID: <4C533E48.1080609@ieee.org> Dieter wrote: > Hi there, > > I installed python 2.7 from the tar ball on python.org. the > installation was pretty uneventful. However, I need to run someone > elses python code and get the error message > > ImportError: No module named binascii > > Any recommendations how to correct this? Is there another tar file > somewhere that I can download to install this missing module? > > Thanks a lot in advance. > > > You should include the whole error message, including the traceback. But perhaps first you should try importing binascii yourself, in the interpreter. DaveA From rui.vapps at gmail.com Fri Jul 30 18:03:04 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 30 Jul 2010 15:03:04 -0700 (PDT) Subject: os.fork on linux defunct Message-ID: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> I'm running python 2.4 on linux. I use python os.fork run tcpdump, but after I kill the forked process (tcpdump) in linux it shows defunct here is the code: #!/usr/bin/python import time, os class Test: def fork(self): self.pid=os.fork() if self.pid=0: args=['tcpdump', '-i', 'eth0', 'port', '80' ''] os.execl("/usr/sbin/tcpdump", *args) os._exit(0) def kill(self): os.kill(self.pid, 15) if __name__=='__main__': while True: test=Test() test.fork() time.sleep(2) test.kill() time.sleep(30) after I call kill() it will kill tcpdump (capture will stop) but on linux, ps shows tcpdump as defunct process what am I missing? thanks for any help. From rui.vapps at gmail.com Fri Jul 30 18:09:28 2010 From: rui.vapps at gmail.com (Ray) Date: Fri, 30 Jul 2010 15:09:28 -0700 (PDT) Subject: os.fork on linux defunct References: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> Message-ID: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> On Jul 30, 6:03?pm, Ray wrote: > I'm running python 2.4 on linux. I use python os.fork run tcpdump, but > after I kill the forked process (tcpdump) in linux it shows defunct > > here is the code: > > #!/usr/bin/python > import time, os > class Test: > ? ? def fork(self): > ? ? ? ? self.pid=os.fork() > ? ? ? ? if self.pid=0: > ? ? ? ? ? ? args=['tcpdump', '-i', 'eth0', 'port', '80' ''] > ? ? ? ? ? ? os.execl("/usr/sbin/tcpdump", *args) > ? ? ? ? ? ? os._exit(0) > ? ? def kill(self): > ? ? ? ? os.kill(self.pid, 15) > if __name__=='__main__': > ? ? while True: > ? ? ? ? test=Test() > ? ? ? ? test.fork() > ? ? ? ? time.sleep(2) > ? ? ? ? test.kill() > ? ? ? ? time.sleep(30) > > after I call kill() it will kill tcpdump (capture will stop) but on > linux, ps shows tcpdump as defunct process > what am I missing? > > thanks for any help. I think I found it. need to call os.wait() From ajuffali at yahoo.com Fri Jul 30 19:52:51 2010 From: ajuffali at yahoo.com (AJ) Date: Fri, 30 Jul 2010 16:52:51 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 Message-ID: Dear users, I have written a sample program that ran correctly with earlier than Mac OS 10.6. The answer field Label does not align correctly. I downloaded the latest Python 2.7 release but still did not solve the problem. Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" #!/usr/bin/env python from Tkinter import * from tkMessageBox import * import sys win = Tk() #win.tk.call('console', 'hide') try: win.tk.call('after','idle','console','hide') except TclError: pass ScreenX = win.winfo_screenwidth() ScreenY = win.winfo_screenheight() ScreenX = (ScreenX/2) - 250 ScreenY = (ScreenY/2) - 200 win.geometry('500x300%+d%+d' %(ScreenX, ScreenY)) win.title("'Place' Geometry Test") win.resizable(width=False, height=False) FirstN = StringVar() SecondN = StringVar() Answer = StringVar() Verd12 = ("Verdana","11") Verd16 = ("Verdana","16") Verd25 = ("Verdana","25") Sys16 = ("System" ,"16") #----------------- AboutDialog ---------------------------- class AboutDialog(Toplevel): def __init__(self, parent): Toplevel.__init__(self, parent) self.configure(bg = 'white', borderwidth=3) self.geometry('200x300%+d%+d' %(ScreenX, ScreenY)) self.title('About...') self.resizable(height=FALSE, width=FALSE) self.transient(parent) self.grab_set() self.protocol("WM_DELETE_WINDOW", self.OkToExit) self.parent = parent self.FillDialog() self.Btn.focus_set() self.bind('',self.OkToExit) self.bind('',self.OkToExit) self.bind('', Done) self.bind('', Done) self.wait_window() def FillDialog(self): self.AboutText = "\n\n\nPlace Geometry Test\n\nBy\n\nAmin Aljuffali" self.Lbl = Label(self, text=self.AboutText, font=Verd16, bg = 'white') self.Lbl.pack(side=TOP) self.Lb2 = Label(self, text="April 1, 2007", height = 1, font=Verd12, bg = 'white') self.Lb2.pack(side=TOP) self.Lb3 = Label(self, text=" ", height = 3, font=Verd12, bg = 'white') self.Lb3.pack(side=TOP) self.Btn = Button(self, text='Done', font=Sys16, width=8, height=1, command=self.OkToExit) self.Btn.pack(side=TOP) self.Lb4 = Label(self, text=" ", height = 3, font=Verd12, bg = 'white') self.Lb4.pack(side=BOTTOM) self.update() def OkToExit(self, event=None): self.destroy() #---------------------------------------------------------- def ShowDialog(): AboutDialog(win) def done(): win.destroy() win.quit def Done(e): win.destroy() win.quit def CheckAlfanumeric(x): if x == '': return False for ch in x: if ch not in['.','-','+','0','1','2','3','4','5','6','7','8','9','e','E']: return False return True def Multiply(): #global FirstN, SecondN, Answer try: a = FirstN.get().strip() if not CheckAlfanumeric(a): raise ValueError b = SecondN.get().strip() if not CheckAlfanumeric(b): raise ValueError FirstN.set(a) SecondN.set(b) Answer.set(str(float(a) * float(b))) except ValueError: showwarning("Warning...","Input Error!") return def MakeToplevelMenu(topwin): top = Menu(topwin) topwin.config(menu=top) if sys.platform == 'darwin' and '.app' in sys.executable: application = Menu(top, name='apple') application.add_command(label='About...', command=ShowDialog, underline=0) top.add_cascade(label='PlaceTest', menu=application, underline=0) fileMenu = Menu(top, tearoff=0) fileMenu.add_command(label='Exit', command=done, underline=0) top.add_cascade(label='File', menu=fileMenu, underline=0) helpMenu = Menu(top, tearoff=0) helpMenu.add_command(label='About...', command=ShowDialog, underline=0) top.add_cascade(label='Help', menu=helpMenu, underline=0) return MakeToplevelMenu(win) L1 = Label(win, text='Multiply Two Numbers', font=Verd25, bg = 'white') L2 = Label(win, text='First Number:', font=Verd16, bg = 'white') L3 = Label(win, text='Second Number:', font=Verd16, bg = 'white') L4 = Label(win, text='', textvariable=Answer, font=Sys16, bg = 'white', bd=1, width=20, height=1, anchor=W, relief=SOLID) L5 = Label(win, text='Written by Amin Aljuffali', font=Verd12,padx=2, bg = 'white', anchor=W, relief=FLAT) B1 = Button(win, text='Multiply', font=Sys16, width=19, height=1, command=Multiply) B2 = Button(win, text='Quit', font=Sys16, width=19, height=1, command=done) F1 = Frame(win, relief=FLAT, bd=0, bg='#336699') F2 = Frame(win, relief=FLAT, bd=0, bg='#336699') F3 = Frame(win, relief=FLAT, bd=0, bg='#336699') E1 = Entry(win, textvariable=FirstN, relief=SOLID, font=Sys16, bg = 'white',bd=1) E2 = Entry(win, textvariable=SecondN, relief=SOLID, font=Sys16, bg = 'white', bd=1) win.bind('', Done) win.bind('', Done) F1.place(relx=0.0,rely=0.01, anchor=NW, width=600, height=5) L1.place(relx=0.5,rely=0.09, anchor=CENTER) F2.place(relx=0.0,rely=0.16, anchor=NW, width=600, height=5) E1.place(relx=0.32,rely=0.32, anchor=W) E2.place(relx=0.32,rely=0.44, anchor=W) L2.place(relx=0.3,rely=0.32, anchor=E) L3.place(relx=0.3,rely=0.44, anchor=E) L4.place(relx=0.32,rely=0.56, anchor=W) B1.place(relx=0.525,rely=0.69, anchor=CENTER) B2.place(relx=0.525,rely=0.81, anchor=CENTER) F3.place(relx=0.0,rely=0.9, anchor=W, width=600, height=5) L5.place(relx=0.01,rely=0.95, anchor=W) E1.focus_set() win.update() win.mainloop() sys.exit(0) From rantingrick at gmail.com Fri Jul 30 20:07:24 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 30 Jul 2010 17:07:24 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> On Jul 30, 6:52?pm, AJ wrote: > Dear users, > > I have written a sample program that ran correctly with earlier than > Mac OS 10.6. The answer field Label does not align correctly. I > downloaded the latest Python 2.7 release but still did not solve the > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" DO YOURSELF A HUGE FAVOR AJ... Learn how to use the "pack" and "grid" geometry managers available in Tkinter before it's too late. Well, unless of course your a sadist. In that case just ignore my post completely. 8^O http://effbot.org/tkinterbook/tkinter-index.htm#introduction From cs at zip.com.au Fri Jul 30 20:39:24 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 31 Jul 2010 10:39:24 +1000 Subject: os.fork on linux defunct In-Reply-To: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> References: <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> Message-ID: <20100731003924.GA17823@cskk.homeip.net> On 30Jul2010 15:09, Ray wrote: | On Jul 30, 6:03?pm, Ray wrote: | > I'm running python 2.4 on linux. I use python os.fork run tcpdump, but | > after I kill the forked process (tcpdump) in linux it shows defunct [...] | > after I call kill() it will kill tcpdump (capture will stop) but on | > linux, ps shows tcpdump as defunct process | > what am I missing? | > thanks for any help. | | I think I found it. need to call os.wait() Yep. "defunct" == "zombie". See: http://code.activestate.com/lists/python-list/580569/ Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Talk is the bastard redheaded stepchild of email and the telephone. - Geoff Miller, geoffm at purplehaze.Corp.Sun.COM From drsalists at gmail.com Fri Jul 30 20:48:52 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 17:48:52 -0700 Subject: pylint scores In-Reply-To: <4C532577.8010906@free.fr> References: <4C532577.8010906@free.fr> Message-ID: On Fri, Jul 30, 2010 at 12:18 PM, News123 wrote: > On 07/30/2010 03:12 PM, wheres pythonmonks wrote: > > I am starting to use pylint to look at my code and I see that it gives a > rating. > > What values do experienced python programmers get on code not > > targeting the benchmark? > > > > I wrote some code, tried to keep it under 80 characters per line, > > reasonable variable names, and I got: > > > > 0.12 / 10. > > > > Is this a good score for one not targeting the benchmark? (pylint > > running in default mode) > > > It's not a goodf core, but arrives easily if you never ran pylint before. > With very little effort you should be able to be above 5 > with a little more effort above 7 > > > > Somewhat related: Is the backslash the only way to extend arguments > > to statements over multiple lines? (e.g.) > > if you have an opening parenthesis, or bracked, then you don't need a > backslash > > so instead of > if longlonglonglonglonglonglonglongvar == \ > otherlonglonglonglongvar: > > you could also write: > > if (longlonglonglonglonglonglonglongvar == > otherlonglonglonglongvar): > > > same works of course with asserts. > > > > >>>> def f(x,y,z): return(x+y+z); > > ... > >>>> f(1,2, > > ... 3) > > 6 > >>>> assert f(1,2,3)>0, > > File "", line 1 > > assert f(1,2,3)>0, > > ^ > > SyntaxError: invalid syntax > >>>> > > > > In the above, I could split the arguments to f (I guess b/c of the > > parens) but not for assert. I could use a backslash, but I find this > > ugly -- it that my only (best?) option? > > > > [I really like to assert my code to correctness and I like using the > > second argument to assert, but this resulted in a lot of long lines > > that I was unable to break except with an ugly backslash.] > > > > W > > IMO, the important thing about pylint's scoring is that it's but one way of many of producing good Python code. However, it's also one of the easier ways of producing good python code. I personally like to get my scores up near 10, by annotating in comments about the few things that pylint flags that I can't just code around. This requires jumping through some slightly silly hoops (EG the previously mentioned "too few public methods", which my various container classes always trip over), but going through this process is worthwhile for highlighting the hoops pylint can detect that -aren't- so silly. The one thing I like to leave unfixed is FIXME's - otherwise my preference would be to go for a score of 10 for production code. I also like to create a ./this-pylint script for my various projects, that have global overrides - things like identifier rules, line length, and... I don't get blanks instead of tabs. Blanks are fine if you don't understand tabs (or think someone in the future who doesn't understand tabs will need to work on your code), but tabs allow everyone to see code indented the way -they- want to see it, not just the way the original author wanted to see it. This script (./this-pylint) will also save output from the test in a text file, for make (or other dependency handling program) to use to avoid re-pylint'ing unmodified code. It'll give an error typically, if pytlint detects any errors other than FIXME's (excluding ones, as I mentioned before, that have a comment disabling the warning, of course). I'm more than a little sad that pylint doesn't seem to be moving to python 3 in any big hurry. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Jul 30 20:52:29 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 12:52:29 +1200 Subject: os.fork on linux defunct References: <7ff4853b-26b5-49f5-932d-0d4487c68383@a4g2000prm.googlegroups.com> <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d@q16g2000prf.googlegroups.com> Message-ID: In message <77a879cc-94ab-4e2a-a4af-a6945a5b8e9d at q16g2000prf.googlegroups.com>, Ray wrote: > I think I found it. need to call os.wait() The rule on Unix/Linux systems is: ?always remember to gobble your zombie children?. From anushkaphotos1 at rediffmail.com Fri Jul 30 20:58:10 2010 From: anushkaphotos1 at rediffmail.com (ANUSHKA) Date: Fri, 30 Jul 2010 17:58:10 -0700 (PDT) Subject: Anushka for Shape FX Hot Shot Thigh Gel Message-ID: Anushka for Shape FX Hot Shot Thigh Gel ************************************** http://sites.google.com/site/anushkaphotosalert From cousinstanley at gmail.com Fri Jul 30 21:00:00 2010 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sat, 31 Jul 2010 01:00:00 +0000 (UTC) Subject: python styles: why Use spaces around arithmetic operators? References: Message-ID: > Parentheses are punctuation. Why not leave spaces around the commas as well, > to be consistent? > > myTuple = ( 1 , 2 , 3 , 4 , 5 ) Personally, I do use this particular style with commas as I find it more readable to my old and tired eyes .... Mandate m o r e whitespace .... :-) -- Stanley C. Kitching Human Being Phoenix, Arizona From drsalists at gmail.com Fri Jul 30 21:12:47 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 18:12:47 -0700 Subject: Multiprocessing taking too much time In-Reply-To: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> References: <4c51d0bd$0$1644$742ec2ed@news.sonic.net> Message-ID: On Thu, Jul 29, 2010 at 12:04 PM, John Nagle wrote: > On 7/29/2010 11:08 AM, Shailendra wrote: > >> Hi All, >> I have a following situation. >> ==================PSUDO CODE START================== >> class holds_big_array: >> big_array #has a big array >> >> def get_some_element(self, cond) # return some data from the array >> from the big array >> ==================PSUDO CODE END==================== >> I wanted to use multiprocessing module to parallelise calling >> "get_some_element". I used following kind of code >> >> ==================PSUDO CODE START================== >> pool = Pool(processes=2) >> holder =holds_big_array() #class instantiation >> def callback_f(result): >> do something with result >> loop many times >> pool.apply_async(holder.get_some_element,args,callback=callback_f) >> pool.close() >> pool.join() >> ==================PSUDO CODE END==================== >> Note: Had to do something to enable instance method being pickled... >> >> I tested this with less than realistic size of big_array . My parallel >> version works much slower than than the normal serial version (10-20 >> sec vs 7-8 min). I was wonder what could be the possible reason.\ > > I think the place to start when code is slow, is usually to use a profiler. However, in this case it's likely as you say, a pickling issue. > It's hard to tell from your "PSUDO CODE", but it looks like each > access to the "big array" involves calling another process. > > Calling a function in another process is done by creating an > object to contain the request, running it through "pickle" to convert > it to a stream of bytes, sending the stream of bytes through a socket or > pipe to the other process, running the byte stream through "unpickle" to > create an object like the original one, but in a different process, and > calling a function on the newly created object in the receiving process. > This entire sequence has to be done again in reverse > to get a reply back. > > This is hundreds of times slower than a call to a local function. > > The "multiprocessing module" is not a replacement for thread-level > parallelism. It looks like it is, but it isn't. It's only useful for > big tasks which require large amounts of computation and little > interprocess communication. Appropriately-sized tasks to send out > to another process are things like "parse large web page" or > "compress video file", not "access element of array". Well, multiprocessing'll replace threading in many scenarios, including some where CPython's threading isn't very useful. The O.P. might look into storing their array in shared memory - multiprocessing facilitates that pretty well. Or, as John has suggested, chunk up the work into larger pieces than individual array accesses. HTH. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jul 30 22:06:27 2010 From: sjmachin at lexicon.net (John Machin) Date: Fri, 30 Jul 2010 19:06:27 -0700 (PDT) Subject: Ascii to Unicode. References: <1h68i7-534.ln1@satorlaser.homedns.org> Message-ID: <9ea0e0e4-ad04-4d3c-b289-011cf5146e8f@p22g2000pre.googlegroups.com> On Jul 30, 4:18?am, Carey Tilden wrote: > In this case, you've been able to determine the > correct encoding (latin-1) for those errant bytes, so the file itself > is thus known to be in that encoding. The most probably "correct" encoding is, as already stated, and agreed by the OP to be, cp1252. From greg.ewing at canterbury.ac.nz Fri Jul 30 22:25:39 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 31 Jul 2010 14:25:39 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bhfcaF6ftU1@mid.individual.net> Steven D'Aprano wrote: > A > / \ > C B > \ / > D > / \ > E F > > Yes, a super call might jog left from > C to B, but only when being called from one of the lower classes D-F. > That's still an upwards call relative to the originator, not sidewards. But it's not an upward call relative to the class mentioned in the super() call, which is why I say it's misleading. -- Greg From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:07:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:07:25 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> <8bhfcaF6ftU1@mid.individual.net> Message-ID: <4c53936d$0$11091$c3e8da3@news.astraweb.com> On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> A >> / \ >> C B >> \ / >> D >> / \ >> E F >> >> Yes, a super call might jog left from C to B, but only when being >> called from one of the lower classes D-F. That's still an upwards call >> relative to the originator, not sidewards. > > But it's not an upward call relative to the class mentioned in the > super() call, which is why I say it's misleading. Which class would that be? I think I'm going to need an example that demonstrates what you mean, because I can't make heads or tails of it. Are you suggesting that a call to super(C, self).method() from within C might call B.method(self)? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:08:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:08:44 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <4c52bfc4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c5393bb$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 14:43:07 +0200, Jean-Michel Pichavant wrote: > Quoting Michele's article (I think he's still hanging around this list) > > "Readers familiar will single inheritance languages, such as Java or > Smalltalk, will have a clear concept of superclass in mind. This > concept, however, has /no useful meaning/ in Python or in other multiple > inheritance languages". I have read Michelle Simionato's articles on super in Python. He has taught me a lot. But on that specific matter, I think he is wrong. Of course, he is right to say that the concept of *the* superclass is meaningless in a MI language like Python. If MyClass inherits method spam() from class A, and inherits method ham() from class B, which is "the" superclass of MyClass? But Michelle is wrong to conclude that the problem lies with the concept of *superclass*. The problem lies with the idea that there is ONE superclass. By dismissing the entire concept, he is throwing out the baby with the bathwater. The useful, and I would argue *correct*, concept of superclass is very simple. It is a reflection of subclass: if Z is a subclass of A, then A is a superclass of Z. This follows e.g. superset and subset. We don't have any problem understanding that a class can have many subclasses. Why the resistance to the idea that a class can have many superclasses? Even in a single inheritance language, if we had a class hierarchy A -> B -> C -> ... -> Y -> Z it makes perfect sense to describe *all* of A-Y as superclasses of Z, just as we describe all of B-Z as subclasses of A. -- Steven From greg.ewing at canterbury.ac.nz Fri Jul 30 23:11:30 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 31 Jul 2010 15:11:30 +1200 Subject: The untimely dimise of a weak-reference In-Reply-To: References: Message-ID: <8bhi2fFifjU1@mid.individual.net> Vincent van Beveren wrote: > I was working with weak references in Python, and noticed that it > was impossible to create a weak-reference of bound methods. > is there anything I can do about it? You can create your own wrapper that keeps a weak reference to the underlying object. Here's an example. import weakref class weakmethod(object): def __init__(self, bm): self.ref = weakref.ref(bm.im_self) self.func = bm.im_func def __call__(self, *args, **kwds): obj = self.ref() if obj is None: raise ValueError("Calling dead weak method") self.func(obj, *args, **kwds) if __name__ == "__main__": class A(object): def foo(self): print "foo method called on", self a = A() m = weakmethod(a.foo) m() del a m() From ian.g.kelly at gmail.com Fri Jul 30 23:40:21 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 30 Jul 2010 21:40:21 -0600 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <87pqy5du0n.fsf@busola.homelinux.net> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: On Fri, Jul 30, 2010 at 6:38 AM, Hrvoje Niksic wrote: > Gregory Ewing writes: > >> I think the point is that the name is misleading, because it makes it >> *sound* like it's going to call a method in a superclass, when it fact >> it might not. > > That is indeed confusing to some people, especially those who refuse to > to accept the notion that "superclass" means the same as "next in MRO", > maintaining instead that superclass refers to one of the base classes, > their bases, etc. -- IMO a defensible position. > > super might have better been called next_in_mro, next_method, or > next_class, except those are harder to type, and way less catchy than > "super". ?The Dylan and CLOS operator that super is most closely based > on is called (call-)next-method. I have to chime in and agree that the name "super" is problematic. I'm reading this thread with a sense of alarm because I apparently never read the super() documentation too closely (why would I? "Oh, it just accesses an attribute from a superclass. Moving on.") and have been writing code for the past four years under the impression that super() will always refer to a superclass of the current class. Fortunately, I don't use multiple inheritance often, and when I do I prefer to write the superclasses explicitly (perhaps because of the same misconception), so I probably haven't really abused it terribly. On a tangent, is it just me, or is the super() documentation incorrect, or at least unclear? Quoting from the first two paragraphs: super(type[, object-or-type]) Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped. The __mro__ attribute of the type lists the method resolution search order used by both getattr() and super(). The attribute is dynamic and can change whenever the inheritance hierarchy is updated. In the first paragraph, "type" refers to "type", the first parameter in the function signature. In the second paragraph, "type" refers to the type instance or the type of the object passed as the second argument. If it also referred to the first parameter, then super() would always access a superclass as I initially thought; I wonder if this might have been partially responsible for my confusion. Cheers, Ian From ajuffali at yahoo.com Fri Jul 30 23:45:12 2010 From: ajuffali at yahoo.com (AJ) Date: Fri, 30 Jul 2010 20:45:12 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> Message-ID: <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> On Jul 30, 5:07?pm, rantingrick wrote: > On Jul 30, 6:52?pm, AJ wrote: > > > Dear users, > > > I have written a sample program that ran correctly with earlier than > > Mac OS 10.6. The answer field Label does not align correctly. I > > downloaded the latest Python 2.7 release but still did not solve the > > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" > > DO YOURSELF A HUGE FAVOR AJ... Learn how to use the "pack" and "grid" > geometry managers available in Tkinter before it's too late. Well, > unless of course your a sadist. In that case just ignore my post > completely. 8^O > > http://effbot.org/tkinterbook/tkinter-index.htm#introduction I know the pack and grid. They do not allow me to position my widget the way I want. You have to go back to first grade and relearn the phrase ?If you have nothing nice to say do not say anything at all?. From steve at REMOVE-THIS-cybersource.com.au Fri Jul 30 23:47:49 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 03:47:49 GMT Subject: default behavior References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c539ce4$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote: > Sorry, doesn't the following make a copy? > >>>>> from collections import defaultdict as dd x = dd(int) >>>>> x[1] = 'a' >>>>> x >> defaultdict(, {1: 'a'}) >>>>> dict(x) >> {1: 'a'} >> >> >> > > I was hoping not to do that -- e.g., actually reuse the same underlying > data. It does re-use the same underlying data. >>> from collections import defaultdict as dd >>> x = dd(list) >>> x[1].append(1) >>> x defaultdict(, {1: [1]}) >>> y = dict(x) >>> x[1].append(42) >>> y {1: [1, 42]} Both the defaultdict and the dict are referring to the same underlying key:value pairs. The data itself isn't duplicated. If they are mutable items, a change to one will affect the other (because they are the same item). An analogy for C programmers would be that creating dict y from dict y merely copies the pointers to the keys and values, it doesn't copy the data being pointed to. (That's pretty much what the CPython implementation does. Other implementations may do differently, so long as the visible behaviour remains the same.) > Maybe dict(x), where x is a defaultdict is smart? I agree that a > defaultdict is safe to pass to most routines, but I guess I could > imagine that a try/except block is used in a bit of code where on the > key exception (when the value is absent) populates the value with a > random number. In that application, a defaultdict would have no random > values. If you want a defaultdict with a random default value, it is easy to provide: >>> import random >>> z = dd(random.random) >>> z[2] += 0 >>> z defaultdict(, {2: 0.30707092626033605}) The point which I tried to make, but obviously failed, is that any piece of code has certain expectations about the data it accepts. If take a function that expects an int between -2 and 99, and instead decide to pass a Decimal between 100 and 150, then you'll have problems: if you're lucky, you'll get an exception, if you're unlucky, it will silently give the wrong results. Changing a dict to a defaultdict is no different. If you have code that *relies* on getting a KeyError for missing keys: def who_is_missing(adict): for person in ("Fred", "Barney", "Wilma", "Betty"): try: adict[person] except KeyError: print person, "is missing" then changing adict to a defaultdict will cause the function to misbehave. That's not unique to dicts and defaultdicts. > Besides a slightly different favor, does the following have applications > not covered by defaultdict? > > m.setdefault('key', []).append(1) defaultdict calls a function of no arguments to provide a default value. That means, in practice, it almost always uses the same default value for any specific dict. setdefault takes an argument when you call the function. So you can provide anything you like at runtime. > I think I am unclear on the difference between that and: > > m['key'] = m.get('key',[]).append(1) Have you tried it? I guess you haven't, or you wouldn't have thought they did the same thing. Hint -- what does [].append(1) return? -- Steven From drsalists at gmail.com Sat Jul 31 00:18:20 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 30 Jul 2010 21:18:20 -0700 Subject: Performance ordered dictionary vs normal dictionary In-Reply-To: References: <899AA0B8-A382-4B07-BC1B-7E9704F42A66@gmail.com> <8E369CBF-A2D2-406C-8AD6-22A85258D449@gmail.com> Message-ID: On Wed, Jul 28, 2010 at 11:11 PM, Chris Rebert wrote: > On Wed, Jul 28, 2010 at 8:12 PM, Navkirat Singh > wrote: > > Sorry, I might have been a bit vague: > > (Also, I am new to pythong) > > I am trying to do construct my own web session tracking algorithm for a > web > > server (which also I have constructed). The book keeping is for the > session > > information I track. The dictionary object will do this for me. I was > > initially using a plain dictionary object, but I read this in the > > documentation that made me think about the question I asked :- > > Does your program actually make use of the ordering? If so, then yes, > using OrderedDict is obviously preferable (Why reimplement something > needlessly?). If not, then why bother with the extra complication? > > (You are aware that the "ordered" in OrderedDict means that its keys > are ordered, and not that, say, a list containing OrderedDicts can be > sorted, right?) Actually, a collections.OrderedDict saves things not in key order, but in chronological order: $ /usr/local/python27/bin/python Python 2.7rc1 (r27rc1:81772, Jun 10 2010, 14:28:26) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import collections >>> d = collections.OrderedDict() >>> d OrderedDict() >>> d[5] = 'a' >>> d[3] = 'b' >>> d[8] = 'c' >>> print d.keys() [5, 3, 8] >>> If you want things saved in key order, you might try my treap or duptreap module: http://stromberg.dnsalias.org/~dstromberg/treap/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From wherespythonmonks at gmail.com Sat Jul 31 01:02:47 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sat, 31 Jul 2010 01:02:47 -0400 Subject: default behavior In-Reply-To: <4c539ce4$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> Message-ID: > > Hint -- what does [].append(1) return? > Again, apologies from a Python beginner. It sure seems like one has to do gymnastics to get good behavior out of the core-python: Here's my proposed fix: m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) Yuck! So I guess I'll use defaultdict with upcasts to dict as needed. On a side note: does up-casting always work that way with shared (common) data from derived to base? (I mean if the data is part of base's interface, will b = base(child) yield a new base object that shares data with the child?) Thanks again from a Perl-to-Python convert! W On Fri, Jul 30, 2010 at 11:47 PM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 08:34:52 -0400, wheres pythonmonks wrote: > >> Sorry, doesn't the following make a copy? >> >>>>>> from collections import defaultdict as dd x = dd(int) >>>>>> x[1] = 'a' >>>>>> x >>> defaultdict(, {1: 'a'}) >>>>>> dict(x) >>> {1: 'a'} >>> >>> >>> >> >> I was hoping not to do that -- e.g., actually reuse the same underlying >> data. > > > It does re-use the same underlying data. > >>>> from collections import defaultdict as dd >>>> x = dd(list) >>>> x[1].append(1) >>>> x > defaultdict(, {1: [1]}) >>>> y = dict(x) >>>> x[1].append(42) >>>> y > {1: [1, 42]} > > Both the defaultdict and the dict are referring to the same underlying > key:value pairs. The data itself isn't duplicated. If they are mutable > items, a change to one will affect the other (because they are the same > item). An analogy for C programmers would be that creating dict y from > dict y merely copies the pointers to the keys and values, it doesn't copy > the data being pointed to. > > (That's pretty much what the CPython implementation does. Other > implementations may do differently, so long as the visible behaviour > remains the same.) > > > >> Maybe dict(x), where x is a defaultdict is smart? ?I agree that a >> defaultdict is safe to pass to most routines, but I guess I could >> imagine that a try/except block is used in a bit of code where on the >> key exception (when the value is absent) ?populates the value with a >> random number. ?In that application, a defaultdict would have no random >> values. > > If you want a defaultdict with a random default value, it is easy to > provide: > >>>> import random >>>> z = dd(random.random) >>>> z[2] += 0 >>>> z > defaultdict(, {2: > 0.30707092626033605}) > > > The point which I tried to make, but obviously failed, is that any piece > of code has certain expectations about the data it accepts. If take a > function that expects an int between -2 and 99, and instead decide to > pass a Decimal between 100 and 150, then you'll have problems: if you're > lucky, you'll get an exception, if you're unlucky, it will silently give > the wrong results. Changing a dict to a defaultdict is no different. > > If you have code that *relies* on getting a KeyError for missing keys: > > def who_is_missing(adict): > ? ?for person in ("Fred", "Barney", "Wilma", "Betty"): > ? ? ? ?try: > ? ? ? ? ? ?adict[person] > ? ? ? ?except KeyError: > ? ? ? ? ? ?print person, "is missing" > > then changing adict to a defaultdict will cause the function to > misbehave. That's not unique to dicts and defaultdicts. > > > >> Besides a slightly different favor, does the following have applications >> not covered by defaultdict? >> >> m.setdefault('key', []).append(1) > > defaultdict calls a function of no arguments to provide a default value. > That means, in practice, it almost always uses the same default value for > any specific dict. > > setdefault takes an argument when you call the function. So you can > provide anything you like at runtime. > > >> I think I am unclear on the difference between that and: >> >> m['key'] = m.get('key',[]).append(1) > > Have you tried it? I guess you haven't, or you wouldn't have thought they > did the same thing. > > Hint -- what does [].append(1) return? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From xahlee at gmail.com Sat Jul 31 01:47:21 2010 From: xahlee at gmail.com (Xah Lee) Date: Fri, 30 Jul 2010 22:47:21 -0700 (PDT) Subject: have you read emacs manual cover to cover?; (was Do we need a "Stevens" book?) References: <093d461d-5402-4226-80d5-6e3d8df2b922@j8g2000yqd.googlegroups.com> <35282104-5b51-4ba4-8745-4fae239ce0ee@q21g2000prm.googlegroups.com> Message-ID: <63e9cab8-17da-4f1a-b055-e172a3ffeb47@o7g2000prg.googlegroups.com> cleaned up and extended my previous post. Sentences and ideas made more precise and detailed. ? Emacs Idolization: Have You Read the Emacs Manual From Cover to Cover? http://xahlee.org/emacs/emacs_manual_cover_to_cover.html plain text version follows: -------------------------------------------------- Thien-Thi Nguyen wrote: Why does the search start with Google (and continue with other downstream, non-terminating, whirlpool-shaped, out of date, referenda)? Why not go to the source? The Emacs Lisp manual, the Emacs Lisp code, the Emacs customization facility, the Emacs *scratch* buffer, the Emacs! Elena wrote: Surprisingly enough - or not? - it seems few users do read the manuals... I'm guilty of this too (and Emacs' manuals will be my reading on my next vacations). I always thought of doing this, but it never happened. Not the emacs manual, nor the elisp manual. Over the past 12 years of using emacs daily, i have read perhaps 1/3 of the emacs manual and 1/2 elisp manual, counted in a accumulative way. However, i have read cover to cover, word for word, systematically in a continued setting, several programing lang or software manuals. Some of these software are quite more deeper than emacs. Here they are from my recollection. (Note: emacs manual for emacs 22 is 589 pages in printed form, and elisp manual for emacs 21 is 900 pages.) ------------------------- Microsoft Word Manual Microsoft Word manual i think i've read most of it in about 1992. Though, i can't remember i actually read the manual systematically or just become expert by using and scanning it when needed. (i stopped using Microsoft Word about 1998.) ------------------------- HP-28S Advanced Scientific Calculator HP-28S Advanced Scientific Calculator manual. (2 books) I read cover to cover, twice, in about 1991. In fact this is how i learned programing, my first computer language, and the first i mastered. (See: HP-28S Advanced Scientific Calculator and Xah Lee's Computing Experience Bio. ) ------------------------- The Mathematica Book Mathematica manual (aka the Mathematica Book amazon ). I've read it 3 times in separate years, systematically, from cover to cover. This all happened in 1990s. Note that Mathematica the language, the subject it deals with, is inherently a order of magnitude more complex than emacs. The Mathematica book is 1381 pages, 3 kilograms. Heavy enough to hit someone to cause concussion. This 4th edition published in 1999, is the last printed edition. They no longer print it nor come with the software. Note how commercial orgs have adopted changes with the changing industry. ------------------------- The Perl Book The Perl Book. I've read basically cover to cover in about 1998, 1999. (yes, i own the printed book. The printed book aka The Camel Book is edited version of Perl's man pages. Actually i've read all major perl books from 1997 to ~2000. (See: Pathetically Elational Regex Language (PERL)) ------------------------- PHP manual The PHP manual (online). Roughly read reasonably all of it in about a week, in 2005. (scanned in detail on parts that do not require detailed understanding at first.) ------------------------- MySQL manual MySQL manual, online. Read it at the same time i read PHP manual from cover to cover, in 2005. Took me about week or two. I've been working with SQL or variants daily in a day job during 1998 to 2002, but haven't touched it for 2 years. So this reading is to brush up my SQL, as well as first time comprehensive reading of MySQL documentation in particular. ------------------------- Habit of Reading Manuals Reading manuals systematically is kinda a habit, developed from early 1990s as part of a method to study English, and also somewhat a old- fashioned and stubburn mindset of wanting to learn everything from ground up, throughly, and from the original source. Reading manuals, is also how i learned most of my proprograming. Just about any software, language, OS, i used from about 1991 to about early 2000s, i tried to read their manuals systematically from cover to cover, not missing any word. This mentality and its severity, very gradually declined over the past 20 years. Today, i do not take the pain to systematically read their manuals of any new software i have to learn. (if it exists at all; or isn't some haphazard wiki, or random notes by student joe (such as Python's docs. See: Python Documentation Problems).) (other manuals i've read quite a lot for example: vast unix man pages, Apache 1.x, Sun Microsystem's Solaris (3 volumes) (2000), Scheme R4RS (1998), Java, Microsoft's JScript (~2005), Python (~2005), Mac OS X Server official doc from Apple, ... (See: Examples Of Quality Documentation In The Computing Industry) ) ================================= Is Emacs Godsend? Elena wrote: Emacs is too much a complex (not difficult) and powerful software to be used by intuition alone, unlike many softwares we are used to. This is simply not true. For example, from personal experience, Blender, Second Life both are more complex than emacs, both for learning it, as well in terms of effort or complexity of their implementation, as well as inherent complexity by the nature of what these software's purpose. Second Life i've been using for about 3 years now. (See: A Photographic Tour of Life in Second Life.) Blender i started to learn this year... but quite too complex and difficult to get started. I'd say, Blender or Second Life, each, are a order magnitude more complex and rich than emacs. Either considered from simple use aspect, or in-depth use aspect such as coding in their scripting languages to use them fully. (akin to coding emacs lisp.) Also, depending on what you mean by use... for example, if you take perspective of emacs lisp as a language, then, compared to programing Java, C, C++, all are quite deeper than elisp and takes longer to explore before reaching diminishing returns. If you take the perspective of emacs as programing framework for creating applications such as file manager, ftp client, irc client, mp3 manager, etc, then, compared to proper software frameworks such as Mac OS and Windows, both are a order far more complex, of bottomless learning depth, as well far more powerful. ================================= Emacs Cult and Idolization Am writing this because i want to dispel the cult phenomenon surrounding emacs. On the net we often hear some magical qualities about emacs, but i think if you look at it seriously, usually much of it are not scientifically meaningful. Since this issue kept cropping up in my mind over the past ~5 years, in argument with many old-time emacs users, i thought about the question: whether there is any superiority or god-like quality about emacs that we can actually claim and be justified. I think to that question we need to be concrete and specific. If a claim is made concrete, then its veracity can be more easily judged. For examples, the following i think can be reasonably claimed: * Emacs is the most suitable tool for text manipulation tasks that are complex and not-well-defined and requires interactive human watch. (See: Why Emacs is Still so Useful Today.) * Emacs is most flexible, customizable, user extensible text editor. * Emacs is the most well known and widely used editor that has a embedded programing language for text editing. * The Emacs system with Emacs Lisp is probably the most versatile computer language for text processing. (See: Text Processing: Elisp vs Perl.) The above claims are still not so precise, but are items i think can be reasonably justified. Or can be made more precise, so that the sum of them can make sense, and conclude that emacs is quite powerful and versatile. On the other hand, the following i think are in the category of myths: * ? Emacs manual would rank among the top 100 best in today's software. * ? Emacs's keyboard system is among the better designed, in its efficiency, or extensibility, or consistency, or ergonomics. * ? Emacs keyboard shortcuts and the way they are mapped to emacs's text manipulation commands, is a very efficient system. (e.g. ratio of number of commands to call over arbitrary text manipulation tasks) * ? Emacs is among the top one thousand major software today. * ? Emacs and system is among the top one thousand software with respect to the software's power, or versatility, or usefulness. * ? Emacs's implementation considered as a software project today is among the top one thousand software in terms of complexity, size, or achievement. ... There are a lot such myths going around different communities. In perl community, it's filled to the brim about how perl is everything and great. In the Common Lisp community, you hear fantastic things about lisp being the god of all programing languages, while they almost never mention emacs lisp as a language, and if they do, it's all sneer and spits and attacks to no ends. In the Scheme community, likewise you hear how it is the most beautiful, the most elegant, and the most powerful, of all, with its call-cc and tail recursion and whatnot. ( See: Scheme & Failure and Language, Purity, Cult, and Deception ) In unix community, which is usually hated by lispers of any faction, you hear how unix is the most versatile, the greatness of its ?Unix philosophy? and ?KISS? principles. (See: The Nature of the Unix Philosophy.) Likewise, there's also commercially generated myths, e.g. Java, about how it solves all cross-platform problems, and how OOP solves the world's programing problems, etc. (See: What are OOP's Jargons and Complexities) All these spur from communities that developed certain cult following. Ultimately, it's more harmful than good. What i'd like to say, is that, yes i love emacs and you love emacs. However, when praising, be concrete and specific on what you like about it, and avoid idolization. Because, idolization cultivates cult- like mindset, and that is ultimately damaging. Xah ? http://xahlee.org/ ? From nagle at animats.com Sat Jul 31 03:50:09 2010 From: nagle at animats.com (John Nagle) Date: Sat, 31 Jul 2010 00:50:09 -0700 Subject: Normalizing A Vector In-Reply-To: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <4c53d5ac$0$1665$742ec2ed@news.sonic.net> On 7/30/2010 6:46 AM, Alain Ketterlin wrote: > Does the compiler hoist the math.sqrt(...) out of the implicit loop? Global optimization in Python? Not in CPython. The program might redefine math.sqrt from another thread while the program is running, which would invalidate the hoisting of the function. That has to be supported. Shed Skin might do it, but it restricts the language and doesn't allow the full dynamism of Python. John Nagle From __peter__ at web.de Sat Jul 31 03:55:48 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 31 Jul 2010 09:55:48 +0200 Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: AJ wrote: > I have written a sample program that ran correctly with earlier than > Mac OS 10.6. The answer field Label does not align correctly. I > downloaded the latest Python 2.7 release but still did not solve the > problem. Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" The underlying Tcl/Tk is more likely to be the cause of your problem, so you'd have to look at that. I'm on Linux with Python2.6 and Tcl/Tk 8.5, and don't see a misalignment. Stab in the dark: try creating L4 with explicit padding: L4 = Label(..., padx=0) Peter PS: Rantingrick is right; you should use one of the other geometry managers From marky1991 at gmail.com Sat Jul 31 03:56:37 2010 From: marky1991 at gmail.com (Mark Young) Date: Sat, 31 Jul 2010 03:56:37 -0400 Subject: Tkinter Label alignment problem using OS 10.6 In-Reply-To: <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> References: <72b4f327-78ba-449c-94cf-62940da54015@g35g2000yqa.googlegroups.com> <2434e1c1-3a18-4627-b162-96686f7d051e@x21g2000yqa.googlegroups.com> Message-ID: That seems a bit harsh. Place, in general, isn't as useful as pack and grid. Yelling at him for suggesting you use them is unnecessary. When I looked at when your script generates, I don't see why you couldn't just use grid. I can fairly easily see a grid layout. But, I guess it's supposed to be a place test anyway. Anyway, how are you expecting it to be aligned? How is it aligned on your computer? When I ran the script, it lined up with the first and second number entries, as I would expect. -------------- next part -------------- An HTML attachment was scrubbed... URL: From landimatte at gmail.com Sat Jul 31 05:04:49 2010 From: landimatte at gmail.com (Matteo Landi) Date: Sat, 31 Jul 2010 11:04:49 +0200 Subject: pylint scores In-Reply-To: References: <4C532577.8010906@free.fr> Message-ID: What are the messages one should really care about while evaluating its code using pylint? It's easy to get 5 scored with a "lot of public methods" or bad named variables such as 'x' or 'y' .. Have you got any config file to share? On Sat, Jul 31, 2010 at 2:48 AM, Dan Stromberg wrote: > > On Fri, Jul 30, 2010 at 12:18 PM, News123 wrote: >> >> On 07/30/2010 03:12 PM, wheres pythonmonks wrote: >> > I am starting to use pylint to look at my code and I see that it gives a >> > rating. >> > What values do experienced python programmers get on code not >> > targeting the benchmark? >> > >> > I wrote some code, tried to keep it under 80 characters per line, >> > reasonable variable names, and I got: >> > >> > 0.12 / 10. >> > >> > Is this a good score for one not targeting the benchmark? ?(pylint >> > running in default mode) >> > >> It's not a goodf core, but arrives easily if you never ran pylint before. >> With very little effort you should be able to be above 5 >> with a little more effort above 7 >> >> >> > Somewhat related: ?Is the backslash the only way to extend arguments >> > to statements over multiple lines? ?(e.g.) >> >> if you have an opening parenthesis, or bracked, then you don't need a >> backslash >> >> so instead of >> if longlonglonglonglonglonglonglongvar == \ >> ? ? ? ?otherlonglonglonglongvar: >> >> you could also write: >> >> if (longlonglonglonglonglonglonglongvar == >> ? ? ? ?otherlonglonglonglongvar): >> >> >> same works of course with asserts. >> >> > >> >>>> def f(x,y,z): return(x+y+z); >> > ... >> >>>> f(1,2, >> > ... 3) >> > 6 >> >>>> assert f(1,2,3)>0, >> > ? File "", line 1 >> > ? ? assert f(1,2,3)>0, >> > ? ? ? ? ? ? ? ? ? ? ?^ >> > SyntaxError: invalid syntax >> >>>> >> > >> > In the above, I could split the arguments to f (I guess b/c of the >> > parens) but not for assert. ?I could use a backslash, but I find this >> > ugly -- it that my only (best?) option? >> > >> > [I really like to assert my code to correctness and I like using the >> > second argument to assert, but this resulted in a lot of long lines >> > that I was unable to break except with an ugly backslash.] >> > >> > W >> > IMO, the important thing about pylint's scoring is that it's but one way of > many of producing good Python code. ?However, it's also one of the easier > ways of producing good python code. > I personally like to get my scores up near 10, by annotating in comments > about the few things that pylint flags that I can't just code around. ?This > requires jumping through some slightly silly hoops (EG the previously > mentioned "too few public methods", which my various container classes > always trip over), but going through this process is worthwhile for > highlighting the hoops pylint can detect that -aren't- so silly. > The one thing I like to leave unfixed is FIXME's - otherwise my preference > would be to go for a score of 10 for production code. > I also like to create a ./this-pylint script for my various projects, that > have global overrides - things like identifier rules, line length, and... ?I > don't get blanks instead of tabs. ?Blanks are fine if you don't understand > tabs (or think someone in the future who doesn't understand tabs will need > to work on your code), but tabs allow everyone to see code indented the way > -they- want to see it, not just the way the original author wanted to see > it. > This script (./this-pylint) will also save output from the test in a text > file, for make (or other dependency handling program) to use to avoid > re-pylint'ing unmodified code. ?It'll give an error typically, if pytlint > detects any errors other than FIXME's (excluding ones, as I mentioned > before, that have a comment disabling the warning, of course). > I'm more than a little sad that pylint doesn't seem to be moving to python 3 > in any big hurry. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Matteo Landi http://www.matteolandi.net/ From siraj.ansari88 at gmail.com Sat Jul 31 05:21:54 2010 From: siraj.ansari88 at gmail.com (SIRAJ ANSARI) Date: Sat, 31 Jul 2010 02:21:54 -0700 (PDT) Subject: "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ Message-ID: <04916d7c-dc72-422e-9b35-3053903e28f0@h17g2000pri.googlegroups.com> "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ "SEXY THAI GIRLS" "SEXY CHINESE GIRLS" "SEXY BOLLYWOOD GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY JAPANESE GIRLS" "SEXY VIETNAM GIRLS" "SEXY HONG KONG GIRLS" "SEXY INDIAN GIRLS" "SEXY PAKISTANI GIRLS" ON http://6ygirls4u.blogspot.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Jul 31 05:55:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 09:55:22 GMT Subject: default behavior References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4c53f30a$0$11091$c3e8da3@news.astraweb.com> On Sat, 31 Jul 2010 01:02:47 -0400, wheres pythonmonks wrote: >> Hint -- what does [].append(1) return? >> >> > Again, apologies from a Python beginner. It sure seems like one has to > do gymnastics to get good behavior out of the core-python: > > Here's my proposed fix: > > m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) > > Yuck! Yuk is right. What's wrong with the simple, straightforward solution? L = m.get('key', []) L.append(1) m['key'] = L Not everything needs to be a one-liner. But if you insist on making it a one-liner, that's what setdefault and defaultdict are for. > So I guess I'll use defaultdict with upcasts to dict as needed. You keep using that term "upcast". I have no idea what you think it means, so I have no idea whether or not Python does it. Perhaps you should explain what you think "upcasting" is. > On a side note: does up-casting always work that way with shared > (common) data from derived to base? (I mean if the data is part of > base's interface, will b = base(child) yield a new base object that > shares data with the child?) Of course not. It depends on the implementation of the class. -- Steven From srini605 at gmail.com Sat Jul 31 06:13:26 2010 From: srini605 at gmail.com (srinivasan munisamy) Date: Sat, 31 Jul 2010 15:43:26 +0530 Subject: Get perl method documentation in python wrapper Message-ID: Hi, I would like to get the documentation of a perl method inside python wrapper. To say it with example, there is a perl module ?X.pm?. It has a method ?print_hello()?. x.py is a wrapper module over X.pm. when I say x.print_hello.__doc__ then I need to get the documentation of X::print_hello. The main reason why i want to do that i do not want to re-write the whole documentation again in python. Is there a way to do that? Thanks, Srini -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sat Jul 31 06:15:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 31 Jul 2010 22:15:57 +1200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: In message <877hkdhyl5.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Lawrence D'Oliveiro writes: > >> What I don?t like is having that intermediate variable L leftover after >> the computation. > > Well, it also guarantees that the square root is computed once. OK, this version should solve that problem, without requiring any new language features: V = tuple \ ( x / l for x in V for l in (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), 0)),) ) From steve at REMOVE-THIS-cybersource.com.au Sat Jul 31 06:22:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Jul 2010 10:22:40 GMT Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > I have to chime in and agree that the name "super" is problematic. I'm > reading this thread with a sense of alarm because I apparently never > read the super() documentation too closely (why would I? "Oh, it just > accesses an attribute from a superclass. Moving on.") and have been > writing code for the past four years under the impression that super() > will always refer to a superclass of the current class. In Python 2.x, super() doesn't know what the current class is. You have to explicitly tell it. If you tell it a lie, surprising things will happen. Assuming you accurately tell it the current class, can you give an example where super() doesn't refer to a superclass of the current class? [...] > On a tangent, is it just me, or is the super() documentation incorrect, > or at least unclear? Quoting from the first two paragraphs: Yes, it's a bit unclear, because it's a complex function for dealing with a complicated situation. But if you have single inheritance, it's simple. Anywhere you would write class C(B): def method(self, *args): B.method(*args) you can write class C(B): def method(self, *args): super(C, self).method(*args) and it will Just Work. > super(type[, object-or-type]) > > Return a proxy object that delegates method calls to a parent or > sibling class of type. I think that the bit about sibling class refers to super(type, type2) calls, rather than the super(type, instance) calls which I've been discussing. I've never needed, and don't understand, the two type version of super(), so I can't comment on it. -- Steven From navegadorjhom2 at hotmail.com Sat Jul 31 06:33:07 2010 From: navegadorjhom2 at hotmail.com (jhom) Date: Sat, 31 Jul 2010 03:33:07 -0700 (PDT) Subject: Electronic purchase with the latest technology know this fantastic store you make your purchase and receive in five days at home buy to resell or use propio Message-ID: <0c898159-94ac-4a19-98ca-4e83e8d4a948@l14g2000yql.googlegroups.com> Electronic purchase with the latest technology know this fantastic store you make your purchase and receive in five days at home buy to resell or use propio http://www.internationaleletronicos.com/ From thomas at jollans.com Sat Jul 31 06:44:15 2010 From: thomas at jollans.com (Thomas Jollans) Date: Sat, 31 Jul 2010 12:44:15 +0200 Subject: Normalizing A Vector In-Reply-To: References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <4C53FE7F.4020900@jollans.com> On 07/31/2010 12:15 PM, Lawrence D'Oliveiro wrote: >reduce(lambda a, b : a + b, (y * y for y in V), 0)) > This is a lot more verbose than it has to be, and probably slower too. firstly: (lambda a,b: a+b) is equivalent to operator.add. ==> reduce(operator.add, (y*y for y in V), 0) However - reduce with operator.add ? we have a special name for this: ==> sum(y*y for y in V) From alain at dpt-info.u-strasbg.fr Sat Jul 31 07:18:04 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 31 Jul 2010 13:18:04 +0200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> Message-ID: <87sk2zhpcj.fsf@dpt-info.u-strasbg.fr> Lawrence D'Oliveiro writes: >>> What I don?t like is having that intermediate variable L leftover after >>> the computation. >> >> Well, it also guarantees that the square root is computed once. > > OK, this version should solve that problem, without requiring any new > language features: > > V = tuple \ > ( > x > / > l > for x in V > for l in > (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), 0)),) > ) You got the order wrong (it has to be for l ... for x ...) You're kind of lucky here, because the arglist to tuple() provides a scope that hides x and l. Be careful if you ever change tuple(...) to [...], because x and l would leak to the outer scope (with python 2.*). In the general case for L in [...some-expr...]: ... whatever doesn't hide L. Python doesn't provide a "let" construct (? la Lisp or *ML). -- Alain. From homeusenet4 at brianhv.org Sat Jul 31 09:29:25 2010 From: homeusenet4 at brianhv.org (Brian Victor) Date: Sat, 31 Jul 2010 13:29:25 +0000 (UTC) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <8bfd5uF9gqU1@mid.individual.net> <4c52bc2d$0$11091$c3e8da3@news.astraweb.com> <8bhfcaF6ftU1@mid.individual.net> <4c53936d$0$11091$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >> >>> A >>> / \ >>> C B >>> \ / >>> D >>> / \ >>> E F >>> >>> Yes, a super call might jog left from C to B, but only when being >>> called from one of the lower classes D-F. That's still an upwards call >>> relative to the originator, not sidewards. >> >> But it's not an upward call relative to the class mentioned in the >> super() call, which is why I say it's misleading. > > Which class would that be? > > I think I'm going to need an example that demonstrates what you mean, > because I can't make heads or tails of it. Are you suggesting that a call > to super(C, self).method() from within C might call B.method(self)? Yes, it would. class A(object): def test_mro(self): print "In A" class B(A): def test_mro(self): print "In B" super(B, self).test_mro() raise Exception() class C(A): def test_mro(self): print "In C" super(C, self).test_mro() class D(C, B): def test_mro(self): print "In D" super(D, self).test_mro() D().test_mro() Notice the exception being raised in B. This results in the following traceback: Traceback (most recent call last): File "mro.py", line 21, in D().test_mro() File "mro.py", line 19, in test_mro super(D, self).test_mro() File "mro.py", line 14, in test_mro super(C, self).test_mro() File "mro.py", line 9, in test_mro raise Exception() Exception Since the idea of super() as I understand it is to make sure every class in an object's hierarchy gets its method called, there's really no way to implement super() in a way that didn't involve a non-superclass being called by some class's super() call. -- Brian From wherespythonmonks at gmail.com Sat Jul 31 11:00:53 2010 From: wherespythonmonks at gmail.com (wheres pythonmonks) Date: Sat, 31 Jul 2010 11:00:53 -0400 Subject: default behavior In-Reply-To: <4c53f30a$0$11091$c3e8da3@news.astraweb.com> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4c539ce4$0$11091$c3e8da3@news.astraweb.com> <4c53f30a$0$11091$c3e8da3@news.astraweb.com> Message-ID: I think of an upcast as casting to the base-class (casting up the inheritance tree). http://en.wiktionary.org/wiki/upcast But really, what I am thinking of doing is overriding the virtual methods of a derived class with the base class behavior in an object that I can then pass into methods that are base/derived agnostic. defaultdict is the way to go. W Sadly, there are guidelines that I program by that are perhaps anti-pythonic: 1. Don't use "extra" variables in code. Don't use global variables. Keep the scopes of local variables at a minimum to reduce state (the exception being for inner loops) or variables explicitly identified as part of the algorithm before implementation. [In python, just about everything is a variable which is terrifying to me. I never want the Alabama version of math.pi i.e., http://www.snopes.com/religion/pi.asp, or math.sin being "666".] 2. Use built-in functions/features as much as possible, as this are the most tested. Don't roll your own -- you're not that good, instead master the language. (How often do I invent a noun in English? Not even "upcast"!) [Plus, guys with phds probably already did what you need.] Use only very well known libraries -- numpy is okay (I hope!) for example. An exception can be made while interfacing external data, because others who create data may not have abided by rule #2. In most cases (except gui programming, which again tackles the external interfacing program) the more heavy-weight your API, the more wrong you are. 3. In interpreted languages, avoid function calls, unless the function does something significant. [e.g., Functional call overhead tends to be worse that a dictionary lookup -- and yes I used timeit, the overhead can be 100%.] Small functions and methods (and callbacks) hamper good interpreted code. When writing functions, make them operate on lists/dicts. It is because of the above that I stopped writing object-oriented Perl. So I want "big" functions that do a lot of work with few variable names. Ideally, I'd create only variables that are relevant based on the description of the algorithm. [Oh yeah, real programming is done before the implementation in python or C++.] My problems are compounded by the lack of indention-based scope, but I see this as simply enforcing the full use of functional-programming approaches. On Sat, Jul 31, 2010 at 5:55 AM, Steven D'Aprano wrote: > On Sat, 31 Jul 2010 01:02:47 -0400, wheres pythonmonks wrote: > > >>> Hint -- what does [].append(1) return? >>> >>> >> Again, apologies from a Python beginner. ?It sure seems like one has to >> do gymnastics to get good behavior out of the core-python: >> >> Here's my proposed fix: >> >> ?m['key'] = (lambda x: x.append(1) or x)(m.get('key',[])) >> >> Yuck! > > Yuk is right. What's wrong with the simple, straightforward solution? > > L = m.get('key', []) > L.append(1) > m['key'] = L > > > Not everything needs to be a one-liner. But if you insist on making it a > one-liner, that's what setdefault and defaultdict are for. > > > >> So I guess I'll use defaultdict with upcasts to dict as needed. > > You keep using that term "upcast". I have no idea what you think it > means, so I have no idea whether or not Python does it. Perhaps you > should explain what you think "upcasting" is. > > >> On a side note: ?does up-casting always work that way with shared >> (common) data from derived to base? ?(I mean if the data is part of >> base's interface, will ?b = base(child) yield a new base object that >> shares data with the child?) > > Of course not. It depends on the implementation of the class. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From rt8396 at gmail.com Sat Jul 31 11:04:22 2010 From: rt8396 at gmail.com (r) Date: Sat, 31 Jul 2010 08:04:22 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <0962c07c-87ff-4618-9aec-707fb1a413f4@u26g2000yqu.googlegroups.com> On Jul 31, 2:55?am, Peter Otten <__pete... at web.de> wrote: > PS: Rantingrick is right; you should use one of the other geometry managers Incidentally I was actually writing a version of the OP's script using the grid manager when i found his nasty response. So I think i'll just keep it for me self now. Good luck AJ. ;-) From lists at cheimes.de Sat Jul 31 11:08:11 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jul 2010 17:08:11 +0200 Subject: default behavior In-Reply-To: References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: Am 30.07.2010 14:34, schrieb wheres pythonmonks: > I was hoping not to do that -- e.g., actually reuse the same > underlying data. Maybe dict(x), where x is a defaultdict is smart? I > agree that a defaultdict is safe to pass to most routines, but I guess > I could imagine that a try/except block is used in a bit of code where > on the key exception (when the value is absent) populates the value > with a random number. In that application, a defaultdict would have > no random values. defaultdict not only behaves like an ordinary dict except for missing keys, it's also a subclass of Python's builtin dict type. You are able to use a defaultdict just like a normal dict all over Python. You can also provide your own custom implementation of a defaultdict that fits your needs. All you have to do is subclass dict and implement a __missing__ method. See http://docs.python.org/library/stdtypes.html?highlight=__missing__#mapping-types-dict Christian From conversationalhypnosis.101 at gmail.com Sat Jul 31 12:59:36 2010 From: conversationalhypnosis.101 at gmail.com (Bolaleman) Date: Sat, 31 Jul 2010 09:59:36 -0700 (PDT) Subject: International IT Consultant Jobs from 14 Countries Message-ID: Looking for IT consultant jobs? Maybe you find your new job in the USA, Canada, Australia, India or in Europe using this IT consultant job database: http://2ajobguide.com/consulting_IT_job_database.aspx This service is free and you can apply directly without intermediates. From jjposner at optimum.net Sat Jul 31 13:31:35 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 31 Jul 2010 13:31:35 -0400 Subject: default behavior In-Reply-To: References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> Message-ID: <4C545DF7.6040104@optimum.net> On 7/31/2010 11:08 AM, Christian Heimes wrote: > ... All you have to do is subclass dict and implement a > __missing__ method. See > http://docs.python.org/library/stdtypes.html?highlight=__missing__#mapping-types-dict > Caveat -- there's another description of defaultdict here: http://docs.python.org/library/collections.html#collections.defaultdict ... and it's bogus. This other description claims that __missing__ is a method of defaultdict, not of dict. This might cause considerable confusion, leading the reader to suspect that __missing__ and default_factory fight it out for the right to supply a default value. (__missing__ would win -- I tried it.) The truth, as Christian says above and as Raymond Hettinger recently pointed out [1], is that __missing__ is used to *define* defaultdict as a subclass of dict -- it's not used *by* defaultdict. -John [1] http://mail.python.org/pipermail/python-list/2010-July/1248896.html From lists at cheimes.de Sat Jul 31 14:00:08 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 31 Jul 2010 20:00:08 +0200 Subject: default behavior In-Reply-To: <4C545DF7.6040104@optimum.net> References: <4c52c368$0$11091$c3e8da3@news.astraweb.com> <4C545DF7.6040104@optimum.net> Message-ID: > The truth, as Christian says above and as Raymond Hettinger recently > pointed out [1], is that __missing__ is used to *define* defaultdict as > a subclass of dict -- it's not used *by* defaultdict. Your answer is confusing even me. ;) Let me try an easier to understand explanation. defaultdict *implements* __missing__() to provide the default dict behavior. You don't have to subclass from defaultdict to get the __missing__() feature. It's part of the dict interface since Python 2.5. Christian From hjtoi-better-remove-before-reply at comcast.net Sat Jul 31 14:06:39 2010 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Sat, 31 Jul 2010 11:06:39 -0700 Subject: Newbie question regarding SSL and certificate verification References: Message-ID: Jeffrey Gaynor wrote: > A final question -- how widely is M2Crypto used? Since I will have to now pitch >to our group that this is preferable the first questions they will ask are about >stability, who is using it and how secure is it really, especially since it is >at version 0.20.2 (i.e. no major release yet). The M2Crypto homepage lists dozens of applications and libraries that use M2Crypto. Additionally I believe certain Linux distros use it as more or less required piece. I know it has been used at some of the world's most largest companies. As for version number, that is pretty much irrelevant in open source. Take a look at the number and frequency of releases, how long the project has existed and so forth, and community around the project. M2Crypto is over 7 years old, has had at least one release a year, and although it doesn't have a large community around it, most of the changes over the last few years have been submitted by someone else than the maintainer. -- Heikki Toivonen - http://heikkitoivonen.net From ian.g.kelly at gmail.com Sat Jul 31 14:16:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 31 Jul 2010 12:16:07 -0600 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: On Sat, Jul 31, 2010 at 4:22 AM, Steven D'Aprano wrote: > On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > >> I have to chime in and agree that the name "super" is problematic. I'm >> reading this thread with a sense of alarm because I apparently never >> read the super() documentation too closely (why would I? ?"Oh, it just >> accesses an attribute from a superclass. ?Moving on.") and have been >> writing code for the past four years under the impression that super() >> will always refer to a superclass of the current class. > > In Python 2.x, super() doesn't know what the current class is. You have > to explicitly tell it. If you tell it a lie, surprising things will > happen. > > Assuming you accurately tell it the current class, can you give an > example where super() doesn't refer to a superclass of the current class? Brian gave a good example, so I refer you to that. >> On a tangent, is it just me, or is the super() documentation incorrect, >> or at least unclear? ?Quoting from the first two paragraphs: > > Yes, it's a bit unclear, because it's a complex function for dealing with > a complicated situation. But if you have single inheritance, it's simple. > Anywhere you would write > > class C(B): > ? ?def method(self, *args): > ? ? ? ?B.method(*args) > > you can write > > class C(B): > ? ?def method(self, *args): > ? ? ? ?super(C, self).method(*args) > > > and it will Just Work. Until somebody else comes along and creates class E that inherits from both C and D and also uses super(), and now suddenly the super() call in C becomes equivalent to "D.method(*args)" instead for instances of E, potentially with unexpected results. Or worse, E.method incorrectly calls both C.method and D.method explicitly, and now D.method gets invoked twice, once implicitly from C.method, and once explicitly from E.method. I realize that it is the responsibility of the person writing class E to make sure they're working with class C correctly, but in order for them to do that, ultimately every method in class C should be documented as to whether it calls super() or not, and if so whether it is designed only for single inheritance or with the MRO in mind. That really shouldn't be necessary, and in my current view from a maintenance perspective, best practice is to only use super() in the multiple-inheritance scenarios it was specifically designed for >> super(type[, object-or-type]) >> >> ? ? Return a proxy object that delegates method calls to a parent or >> sibling class of type. > > I think that the bit about sibling class refers to super(type, type2) > calls, rather than the super(type, instance) calls which I've been > discussing. I've never needed, and don't understand, the two type version > of super(), so I can't comment on it. I understand the two-type version works the same way, but is intended for class methods, like so: class A(object): @classmethod def f(cls, *args): print "A.f" class B(A): @classmethod def f(cls, *args): print "B.f" return super(B, cls).f(*args) class C(A): @classmethod def f(cls, *args): print "C.f" return super(C, cls).f(*args) class D(B, C): @classmethod def f(cls, *args): print "D.f" return super(D, cls).f(*args) Cheers, Ian From ajuffali at yahoo.com Sat Jul 31 14:54:38 2010 From: ajuffali at yahoo.com (AJ) Date: Sat, 31 Jul 2010 11:54:38 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: Message-ID: <7f0a4cd5-195a-4d3f-9f52-7f357a7432a9@b4g2000pra.googlegroups.com> On Jul 31, 12:55?am, Peter Otten <__pete... at web.de> wrote: > AJ wrote: > > I have written a sample program that ran correctly with earlier than > > Mac OS 10.6. The answer field Label does not align correctly. I > > downloaded the latest Python 2.7 release but still did not solve the > > problem. ?Look for line "L4.place(relx=0.32,rely=0.56, anchor=W)" > > The underlying Tcl/Tk is more likely to be the cause of your problem, so > you'd have to look at that. > > I'm on Linux with Python2.6 and Tcl/Tk 8.5, and don't see a misalignment. > > Stab in the dark: try creating L4 with explicit padding: > > L4 = Label(..., padx=0) > > Peter > > PS: Rantingrick is right; you should use one of the other geometry managers Thank you Peter. I?ve tried the padding but it does not solve the issue. It only does it with Mac OS 10.6. it works fine with Windows and Linux and earlier Mac OS than 10.6. To write professional GUI one needs to have full control over the placement of the Widgets. Some programmers have switched to wxPython because of this issue and I am trying not to. From ajuffali at yahoo.com Sat Jul 31 15:05:09 2010 From: ajuffali at yahoo.com (AJ) Date: Sat, 31 Jul 2010 12:05:09 -0700 (PDT) Subject: Tkinter Label alignment problem using OS 10.6 References: <0962c07c-87ff-4618-9aec-707fb1a413f4@u26g2000yqu.googlegroups.com> Message-ID: On Jul 31, 8:04?am, r wrote: > On Jul 31, 2:55?am, Peter Otten <__pete... at web.de> wrote: > > > PS: Rantingrick is right; you should use one of the other geometry managers > > Incidentally I was actually writing a version of the OP's script using > the grid manager when i found his nasty response. So I think i'll just > keep it for me self now. Good luck AJ. ;-) Thank you. Do not let it get to you. There are some people like that. If you have an idea or need help do not be distracted by this. Just post it and hope someone can help you. This is more beneficial for you and others who have the same questions and some day you may be helping others. Cheers! From legard4d at gmail.com Sat Jul 31 15:09:15 2010 From: legard4d at gmail.com (legard_new) Date: Sat, 31 Jul 2010 12:09:15 -0700 (PDT) Subject: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem Message-ID: <70faf0b4-fead-49ac-bf18-e182fd63bbff@j8g2000yqd.googlegroups.com> Hello, I have a problem with calling Callback function with Python. I have a DLL file. Below is a description in documentation. FUNCTION Callback Arguments: Callback ID integer read-only, immediate value CBackProc address read-only, immediate value Returns: status The Callback routine registers the callback routine for notification of a link state change. The callback procedure provided by the application must accept one parameter: the address of the structure containing the data. CallbackID An integer identifying the callback routine being provided to the API. Can be one of 1 or 2. CBackProc The address of the callback procedure that the API will execute. This procedure must accept one parameter, of type LinkStateStruct, passed by reference. LinkStateStruct read-only, by reference OldState: byte NewState byte The routine will return one of the following error codes: 1 - The callback address was successfully registered by the API. 2 - The API has not been initialised. 3 - The CallbackID value was not recognised as a valid link state callback. Here is my little code in Python: from ctypes import * class LinkStateStruct(Structure): _fields_ = [("OldState", c_byte), ("NewState", c_byte)] demoapi=windll.LoadLibrary("D:\\DEMO.dll") #DECLARE CALLBACK FUNCTION g_HLSC = CFUNCTYPE(c_int, POINTER(LinkStateStruct)) def py_g_HLSC(x): print "CALLBACK__py_g_HLSC_FIRED->", x return 0 g__HLSC = g_HLSC(py_g_HLSC) status=demoapi.Callback(1,g__HLSC) print "Status=",status My result is: Status= 1 But Callback function is not executed. If think that i call g__HLSC witohout paramter that in document "The callback procedure provided by the application must accept one parameter: the address of the structure containing the data.". I don't now how to do. Please help. Best regards, Gregory From timr at probo.com Sat Jul 31 15:45:45 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 31 Jul 2010 12:45:45 -0700 Subject: Normalizing A Vector References: Message-ID: Lawrence D'Oliveiro wrote: > >Say a vector V is a tuple of 3 numbers, not all zero. You want to normalize >it (scale all components by the same factor) so its magnitude is 1. > >The usual way is something like this: > > L = math.sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]) > V = (V[0] / L, V[1] / L, V[2] / L) > >What I don?t like is having that intermediate variable L leftover after the >computation. Here?s how to do it in one step: > > V = tuple \ > ( > x > / > math.sqrt > ( > reduce(lambda a, b : a + b, (y * y for y in V), 0) > ) > for x in V > ) > >which, incidentally, also works for vectors with dimensions other than 3. What is the matter with having a temporary variable hang around? It's only one double, and it far better performance than the one you posted. As far as I know, Python doesn't do common subexpression elimination, which means the version you posted is doing to run the entire magnitude computation once for every element in V. A better solution would be to put this in a function: def Normalize(V): L = math.sqrt( sum(a*a for a in V) ) return (a/L for a in V) Now the temporary goes away at the end of the function. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From metolone+gmane at gmail.com Sat Jul 31 16:22:48 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sat, 31 Jul 2010 13:22:48 -0700 Subject: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem References: <70faf0b4-fead-49ac-bf18-e182fd63bbff@j8g2000yqd.googlegroups.com> Message-ID: "legard_new" wrote in message news:70faf0b4-fead-49ac-bf18-e182fd63bbff at j8g2000yqd.googlegroups.com... > Hello, > > I have a problem with calling Callback function with Python. I have a > DLL file. > > Below is a description in documentation. > FUNCTION Callback > Arguments: Callback ID integer read-only, immediate value > CBackProc address read-only, immediate value > Returns: status > The Callback routine registers the callback routine for > notification of a link state change. > The callback procedure provided by the application must accept one > parameter: > the address of the structure containing the data. > > CallbackID An integer identifying the callback routine being > provided to the API. Can be one of 1 or 2. > CBackProc The address of the callback procedure that the API will > execute. > > This procedure must accept one parameter, of type LinkStateStruct, > passed by reference. > > LinkStateStruct read-only, by reference > OldState: byte > NewState byte > > The routine will return one of the following error codes: > 1 - The callback address was successfully registered by the API. > 2 - The API has not been initialised. > 3 - The CallbackID value was not recognised as a valid link state > callback. > > Here is my little code in Python: > > from ctypes import * > class LinkStateStruct(Structure): > _fields_ = [("OldState", c_byte), > ("NewState", c_byte)] > demoapi=windll.LoadLibrary("D:\\DEMO.dll") > #DECLARE CALLBACK FUNCTION > g_HLSC = CFUNCTYPE(c_int, POINTER(LinkStateStruct)) > def py_g_HLSC(x): > print "CALLBACK__py_g_HLSC_FIRED->", x > return 0 > g__HLSC = g_HLSC(py_g_HLSC) > status=demoapi.Callback(1,g__HLSC) > print "Status=",status > > My result is: > Status= 1 > > But Callback function is not executed. If think that i call g__HLSC > witohout paramter that in document "The callback procedure > > provided by the application must accept one parameter: the address of > the structure containing the data.". I don't now how to do. I don't see anything wrong with your declarations. It indicates you registered the callback successfully. Since the callback sounds like it monitors changes in "link state" maybe it isn't changing. Perhaps you need to call another function that causes this change. Here's a DLL I wrote to test your code, but I added a ChangeLinkState function. When I call it after running your code the callback gets called, so your code is working properly. (Compiled with Visual Studio 2008 "cl /MD /LD demo.c" typedef unsigned char BYTE; typedef struct tagLINKSTATE { BYTE OldState, NewState; } LINKSTATE; typedef int (*CB)(LINKSTATE*); CB g_cb; BYTE g_linkState; __declspec(dllexport) int __stdcall Callback(int a,CB cb) { g_cb = cb; return 1; } __declspec(dllexport) void __stdcall ChangeLinkState(BYTE newState) { LINKSTATE state; state.OldState = g_linkState; state.NewState = newState; g_linkState = newState; g_cb(&state); } -Mark From charlesj at sonic.net Sat Jul 31 17:07:50 2010 From: charlesj at sonic.net (Charles Jo) Date: Sat, 31 Jul 2010 21:07:50 -0000 Subject: Google job leads Message-ID: Dear Colleagues, I recently started a recruiter project at Google and am working with Partner Solutions Organization and recruiting Technical Account Managers for the group so I am actively networking with those who may know great software engineers with client-facing experience (or wanting to move in that direction) for career-defining opportunities. If there are individuals and organizations that I should reach out to, please do let me know -- my office contact information is below. Google office: Charles Jo Sales Recruiter, Google 650.253.0375 office 408.668.4226 cell charlesjo at google.com Feedback is always welcome! Best, Charles --? Message sent by: Charles Jo 408.668.4226 charlesj at sonic.net http://bit.ly/zooqdesk http://www.linkedin.com/in/charlesjo http://twitter.com/charlesjo http://www.facebook.com/profile.php?id=603461791 From oswald_eppers at hotmail.com Sat Jul 31 17:32:35 2010 From: oswald_eppers at hotmail.com (David) Date: Sat, 31 Jul 2010 14:32:35 -0700 (PDT) Subject: HCL Jobs database Message-ID: <3015a62e-c54b-4f81-aa59-91f1e69a5f80@m1g2000yqo.googlegroups.com> If you are looking for Jobs at HCL America Inc. ("HCL Jobs") check out http://2ajobguide.com/hcl_jobs.aspx You?ll get free access to a comprehensive database of HCL jobs and you can apply directly online without intermediates. From greg.ewing at canterbury.ac.nz Sat Jul 31 21:13:18 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Aug 2010 13:13:18 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: <4c53f96f$0$11091$c3e8da3@news.astraweb.com> References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: <8bjvglFl4U1@mid.individual.net> Steven D'Aprano wrote: > Assuming you accurately tell it the current class, can you give an > example where super() doesn't refer to a superclass of the current class? I think we're all confusing each other in this discussion by not being clear enough about what we mean by the "current class". In a call super(C, self), there are two possible things it could mean: the class C, or the type of self. Obviously it will return some class in the mro of self, but as Brian Victor's example demonstrates, it *doesn't* necessarily return a class in the mro of C. -- Greg From greg.ewing at canterbury.ac.nz Sat Jul 31 21:18:04 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Aug 2010 13:18:04 +1200 Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? In-Reply-To: References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> Message-ID: <8bjvpjF202U1@mid.individual.net> Ian Kelly wrote: > super(type[, object-or-type]) > > ... > > The __mro__ attribute of the type lists the method resolution > search order used by both getattr() and super(). The attribute is > dynamic and can change whenever the inheritance hierarchy is updated. That explanation does seem to be rather confusing. It would certainly confuse *me* if I didn't already know what super() did. +1 on getting this part of the docs re-written to be several times clearer. -- Greg From ldo at geek-central.gen.new_zealand Sat Jul 31 21:41:08 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:41:08 +1200 Subject: Normalizing A Vector References: <877hkdhyl5.fsf@dpt-info.u-strasbg.fr> <87sk2zhpcj.fsf@dpt-info.u-strasbg.fr> Message-ID: In message <87sk2zhpcj.fsf at dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Lawrence D'Oliveiro writes: > >> V = tuple \ >> ( >> x >> / >> l >> for x in V >> for l in >> (math.sqrt(reduce(lambda a, b : a + b, (y * y for y in V), >> 0)),) >> ) > > You got the order wrong (it has to be for l ... for x ...) No, I deliberately put it in that order to ensure that the value for l can only ever be evaulated once. > You're kind of lucky here, because the arglist to tuple() provides a > scope that hides x and l. Be careful if you ever change tuple(...) to > [...], because x and l would leak to the outer scope (with python 2.*). Interesting. However, using ?list( ... )? instead of ?[ ... ]? also prevents the leakage. From ldo at geek-central.gen.new_zealand Sat Jul 31 21:52:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:52:13 +1200 Subject: Problem with Elementtree and XMLSchem instance type References: Message-ID: In message , Roland Hedberg wrote: > And there is the problem, I've lost the coupling between the prefix > 'fed' and the namespace > "http://docs.oasis-open.org/wsfed/federation/200706". Why is this a problem? From ldo at geek-central.gen.new_zealand Sat Jul 31 21:56:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:56:52 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: Message-ID: In message , Daniel Fetchinson wrote: > Sure, there are many different terminals and many different operating > systems but in many areas python managed to hide all these complexities > behind a well defined API. Once upon a time, there were indeed many different kinds of actual physical terminals. However, they are all extinct now. All that?s left is software emulations. And the one emulation they all have in common is the DEC VT100. So just assume you?re displaying on one of those: sys.stdout.write("\x1b[2J") From ldo at geek-central.gen.new_zealand Sat Jul 31 21:59:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 13:59:55 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> <6e6bf2ea-7d98-4af8-8613-6320a8a2d1cc@5g2000yqz.googlegroups.com> Message-ID: In message , Tim Harig wrote: > It would be rewarding as it would make writing cross-platform charactor > mode applications possible. I thought Windows users were allergic to command lines. From ldo at geek-central.gen.new_zealand Sat Jul 31 22:01:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 01 Aug 2010 14:01:13 +1200 Subject: Why is there no platform independent way of clearing a terminal? References: <4c4ee6e8$0$20965$426a74cc@news.free.fr> <67f0a4af61f6f83afccff2af8bfc0b94@localhost> <8k15i7-jhs.ln1@satorlaser.homedns.org> Message-ID: In message , Emile van Sebille wrote: > If all else fails, repeating 24 (or 40,60?) lines feeds clears the > screen cross platform. Depending on the height of the terminal window... From rashadkm at gmail.com Sat Jul 31 22:49:46 2010 From: rashadkm at gmail.com (Rashad) Date: Sat, 31 Jul 2010 19:49:46 -0700 (PDT) Subject: python and swig Message-ID: <4e1bddbf-23ff-40c4-94d1-af2fbcc32721@g21g2000prn.googlegroups.com> I have a swig object of type int* (an integer array) how to covert this swig object to python list now : print self.buffer[0] gives swig object of type int* i want to access the elements of array self.buffer[0] like print self.buffer[0][0] , self.buffer[0][1], self.buffer[0][2] etc... From pavlovevidence at gmail.com Sat Jul 31 22:52:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 19:52:05 -0700 (PDT) Subject: Docstrings and PEP 3174 Message-ID: PEP 3174 got me to thinking. There is now a subdirectory to deposit as many *.pyc files as you want without cluttering the source directory (never mind the default case). Which means you can pretty much write files with impunity. So I was wondering: what about a separate file just for docstrings. __doc__ would become a descriptor that loads the docstring from the file whenever it is referenced. The vast majority of the time docstrings just take up memory and do nothing, so why not lazy load those things? Yes I know you can use the -OO switch to omit docstrings--but who does that anyway? I know I never use -O because I don't know if the people who wrote the library code I'm using were careful enough not to perform general checks with assert or to avoid relying on the docstring's presense. Yeah, it's probably a miniscule optimization, but whatever, I'm just throwing it out there. Carl Banks From pavlovevidence at gmail.com Sat Jul 31 23:48:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 20:48:40 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> Message-ID: <34301a26-e5d4-43ab-ac46-e07f9c0cd10b@p11g2000prf.googlegroups.com> On Jul 31, 11:16?am, Ian Kelly wrote: > On Sat, Jul 31, 2010 at 4:22 AM, Steven D'Aprano > > > > wrote: > > On Fri, 30 Jul 2010 21:40:21 -0600, Ian Kelly wrote: > > >> I have to chime in and agree that the name "super" is problematic. I'm > >> reading this thread with a sense of alarm because I apparently never > >> read the super() documentation too closely (why would I? ?"Oh, it just > >> accesses an attribute from a superclass. ?Moving on.") and have been > >> writing code for the past four years under the impression that super() > >> will always refer to a superclass of the current class. > > > In Python 2.x, super() doesn't know what the current class is. You have > > to explicitly tell it. If you tell it a lie, surprising things will > > happen. > > > Assuming you accurately tell it the current class, can you give an > > example where super() doesn't refer to a superclass of the current class? > > Brian gave a good example, so I refer you to that. > > > > >> On a tangent, is it just me, or is the super() documentation incorrect, > >> or at least unclear? ?Quoting from the first two paragraphs: > > > Yes, it's a bit unclear, because it's a complex function for dealing with > > a complicated situation. But if you have single inheritance, it's simple. > > Anywhere you would write > > > class C(B): > > ? ?def method(self, *args): > > ? ? ? ?B.method(*args) > > > you can write > > > class C(B): > > ? ?def method(self, *args): > > ? ? ? ?super(C, self).method(*args) > > > and it will Just Work. > > Until somebody else comes along and creates class E that inherits from > both C and D and also uses super(), and now suddenly the super() call > in C becomes equivalent to "D.method(*args)" instead for instances of > E, potentially with unexpected results. ?Or worse, E.method > incorrectly calls both C.method and D.method explicitly, and now > D.method gets invoked twice, once implicitly from C.method, and once > explicitly from E.method. > > I realize that it is the responsibility of the person writing class E > to make sure they're working with class C correctly, but in order for > them to do that, ultimately every method in class C should be > documented as to whether it calls super() or not, and if so whether it > is designed only for single inheritance or with the MRO in mind. ?That > really shouldn't be necessary, I was with you up to here. It's *manifestly* necessary. One cannot inherit from a class reliably without knowing how it's implemented. Knowing the interface is not enough. This is not limited to multiple inheritance; it happens with single inheritance as well, just less often. It's not limited to Python, this is true of Java, C++, and every other OOP language I know of. Take list. Say you want a singly inherit from list to implement some kind of observer that emits a signal every time an item is set. How do you do it? You can't tell by looking at the interface. Do you only have to override __setattr__? Or do you also have to override other methods (insert, append, etc)? That depends on whether insert et al. call __setattr__ or operate at a lower level. You can't tell simply by looking at the interface. You have to have knowledge of the internals of list. It's the same problem with multiple inheritance, only exacerbated. The issues with super is a new dimension, but it's the same problem: you have to know what you're inheriting from. This is a fundamental issue with all inheritance. The problem, in my mind, is that people use inheritance for stuff that doesn't need it. class MyFoo(SomebodyElsesFoo): def my_tacked_on_method(self): self.call_this_method() self.then_call_that_method() Unnecessary and risky. Do this: my_tacked_on_function(foo): foo.call_this_method() foo.then_call_that_method() The only reason to inherit in a situation like this is if you need polymorphism (you want to pass your MyFoo to a function that operates on objects that define a my_tacked_on_method). A lot Michele Simionato's objections to inheritance are based on the idea that you don't necessarily know what you're inheriting from. I say, if you don't know what you're inheriting from, you shouldn't be inheriting. I say this as a strong proponent of inheritance and multiple inheritance in particular. I believe it's the best way in general for objects of different types to share large portions of their behavior. But it has its place. When you have a class you that don't anything about the implementation of, that is NOT the place for inheritance. In that case you should either use composition, or learn what it is you're inheriting from and take responsibility if the owner changes it. Or just don't try to share behavior. My view of inheritance is a lot like the orthodox Catholic view of sex. To Catholics, sex between married people is a wonderful, holy thing. To me, inheriting from classes you know the implementation of is a wonderful, holy thing. But, sex outside of marriage, and inheriting from classes you don't know, is deadly sin and you will burn in Hell. > and in my current view from a > maintenance perspective, best practice is to only use super() in the > multiple-inheritance scenarios it was specifically designed for I use super() exclusively for all types of inheritance, unless I'm inheriting from a class I know uses old form (which is none of mine, and I only rarely inherit from classes I don't own). Carl Banks From pavlovevidence at gmail.com Sat Jul 31 23:54:35 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 31 Jul 2010 20:54:35 -0700 (PDT) Subject: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all? References: <89d63586-735b-4a39-910f-ef5b23ee9397@s17g2000prh.googlegroups.com> <54124b97-a1cb-49e9-9958-fd015bd62079@5g2000yqz.googlegroups.com> <8b1jgbFgbdU1@mid.individual.net> <4c4bb40b$0$28669$c3e8da3@news.astraweb.com> <4c517a58$0$11091$c3e8da3@news.astraweb.com> <4c520f45$0$11091$c3e8da3@news.astraweb.com> <8bfd8tF9gqU2@mid.individual.net> <87pqy5du0n.fsf@busola.homelinux.net> <4c53f96f$0$11091$c3e8da3@news.astraweb.com> <34301a26-e5d4-43ab-ac46-e07f9c0cd10b@p11g2000prf.googlegroups.com> Message-ID: <7e09f51e-6334-44e1-ada4-e95b9e4609d9@q21g2000prm.googlegroups.com> On Jul 31, 8:48?pm, Carl Banks wrote: > When you have a class you that don't anything about the implementation > of, that is NOT the place for inheritance. And, just to be clear, if the class is explicity documented as being subclassable and the documentation states the proper procedure for doing so, that counts as "knowing about the implementation"--even if you don't know the exact implementation, you do have sufficient knowledge. I just don't want someone following up saying, "Well I think it's ok to inherit from a class you know nothing about if it's documented properly." I agree, and that is knowing something about it. Carl Banks